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-140-gbf07c0b


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-140-gbf07c0b
Date: Sat, 09 Oct 2010 14:06:38 +0000

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

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

The branch, master has been updated
       via  bf07c0b891aad29dd8eb45ff3c1b1ea8c23e7dce (commit)
       via  f3188dcc18d8de1192c87e7e0284800e9488b976 (commit)
      from  37d7cd77d34cd4bf8d267b3010d923845fe74308 (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 bf07c0b891aad29dd8eb45ff3c1b1ea8c23e7dce
Author: Sergey Poznyakoff <address@hidden>
Date:   Sat Oct 9 16:58:21 2010 +0300

    Fix copyleft notices to follow the GNU standards.

commit f3188dcc18d8de1192c87e7e0284800e9488b976
Author: Sergey Poznyakoff <address@hidden>
Date:   Sat Oct 9 13:06:58 2010 +0300

    Reorganize libmailutils directory structure.
    
    * configure.ac (AC_CONFIG_FILES): Add libmailutils/ subdirs.
    * include/mailutils/Makefile.am: Update references to libmailutils.
    * po/POTFILES.in: Likewise.
    * libmailutils/.gitignore: Update.
    * libmailutils/Makefile.am: Use convenience libraries in subdirs.
    
    * libmailutils/string/Makefile.am: New file.
    * libmailutils/cstrcasecmp.c: Move to libmailutils/string.
    * libmailutils/cstrlower.c: Likewise.
    * libmailutils/cstrupper.c: Likewise.
    * libmailutils/strltrim.c: Likewise.
    * libmailutils/strskip.c: Likewise.
    * libmailutils/stripws.c: Likewise.
    * libmailutils/strrtrim.c: Likewise.
    * libmailutils/asnprintf.c: Likewise.
    * libmailutils/asprintf.c: Likewise.
    * libmailutils/muctype.c: Likewise.
    * libmailutils/vasnprintf.c: Likewise.
    * libmailutils/mkfilename.c: Likewise.
    
    * libmailutils/stream/Makefile.am: New file.
    * libmailutils/dbgstream.c: Move to libmailutils/stream.
    * libmailutils/file_stream.c: Likewise.
    * libmailutils/fltstream.c: Likewise.
    * libmailutils/iostream.c: Likewise.
    * libmailutils/mapfile_stream.c: Likewise.
    * libmailutils/memory_stream.c: Likewise.
    * libmailutils/message_stream.c: Likewise.
    * libmailutils/prog_stream.c: Likewise.
    * libmailutils/rdcache_stream.c: Likewise.
    * libmailutils/socket_stream.c: Likewise.
    * libmailutils/stdio_stream.c: Likewise.
    * libmailutils/stream.c: Likewise.
    * libmailutils/stream_printf.c: Likewise.
    * libmailutils/stream_vprintf.c: Likewise.
    * libmailutils/streamcpy.c: Likewise.
    * libmailutils/streamref.c: Likewise.
    * libmailutils/tcp.c: Likewise.
    * libmailutils/temp_file_stream.c: Likewise.
    * libmailutils/xscript-stream.c
    
    * libmailutils/cfg/Makefile.am: New file.
    * libmailutils/cfg/.gitignore: New file.
    * libmailutils/cfg_driver.c: Move to libmailutils/cfg/driver.c.
    * libmailutils/cfg_format.c: Move to libmailutils/cfg/format.c.
    * libmailutils/cfg_lexer.l: Move to libmailutils/cfg/lexer.l.
    * libmailutils/cfg_parser.y: Move to libmailutils/cfg/parser.y.
    * libmailutils/gocs.c: Move to libmailutils/cfg/gocs.c.
    
    * libmailutils/diag/Makefile.am: New file.
    * libmailutils/diag/.gitignore: New file.
    * libmailutils/debug.c: Move to libmailutils/diag.
    * libmailutils/diag.c: Likewise.
    * libmailutils/gdebug.c: Likewise.
    * libmailutils/errors: Likewise.
    * libmailutils/muerrno.cin: Likewise.
    * libmailutils/syslog.c: Likewise.
    * libmailutils/dbgstderr.c: Likewise.
    * libmailutils/dbgsyslog.c: Likewise.
    
    * libmailutils/address/Makefile.am: New file.
    * libmailutils/address.c: Move to libmailutils/address.
    * libmailutils/parse822.c: Likewise.
    
    * libmailutils/mailbox/Makefile.am: New file.
    * libmailutils/mailbox.c: Move to libmailutils/mailbox.
    * libmailutils/mbx_default.c: Likewise.
    * libmailutils/mbxitr.c: Likewise.
    * libmailutils/attribute.c: Likewise.
    * libmailutils/body.c: Likewise.
    * libmailutils/envelope.c: Likewise.
    * libmailutils/folder.c: Likewise.
    * libmailutils/hdritr.c: Likewise.
    * libmailutils/header.c: Likewise.
    * libmailutils/message.c: Likewise.
    * libmailutils/msgscan.c: Likewise.
    
    * libmailutils/mailer/Makefile.am: New file.
    * libmailutils/mailer.c: Move to libmailutils/mailer.
    * libmailutils/progmailer.c: Likewise.
    
    * libmailutils/mime/Makefile.am: New file.
    * libmailutils/attachment.c: Move to libmailutils/mime.
    * libmailutils/mime.c: Likewise.
    * libmailutils/mimehdr.c: Likewise.
    
    * libmailutils/server/Makefile.am: New file.
    * libmailutils/acl.c: Move to libmailutils/server.
    * libmailutils/server.c: Likewise.
    * libmailutils/msrv.c: Likewise.
    * libmailutils/ipsrv.c: Likewise.
    
    * libmailutils/auth/Makefile.am: New file.
    * libmailutils/auth.c: Move to libmailutils/auth.
    * libmailutils/mu_auth.c: Likewise.
    * libmailutils/system.c: Likewise.
    
    * libmailutils/base/Makefile.am: New file.
    * libmailutils/base/.gitignore: New file.
    * libmailutils/alloc.c: Move to libmailutils/base.
    * libmailutils/amd.c: Likewise.
    * libmailutils/argcv.c: Likewise.
    * libmailutils/assoc.c: Likewise.
    * libmailutils/daemon.c: Likewise.
    * libmailutils/date.c: Likewise.
    * libmailutils/fgetpwent.c: Likewise.
    * libmailutils/freeitem.c: Likewise.
    * libmailutils/getpass.c: Likewise.
    * libmailutils/iterator.c: Likewise.
    * libmailutils/kwd.c: Likewise.
    * libmailutils/list.c: Likewise.
    * libmailutils/listlist.c: Likewise.
    * libmailutils/locale.c: Likewise.
    * libmailutils/locker.c: Likewise.
    * libmailutils/mailcap.c: Likewise.
    * libmailutils/md5.c: Likewise.
    * libmailutils/monitor.c: Likewise.
    * libmailutils/munre.c: Likewise.
    * libmailutils/mutil.c: Likewise.
    * libmailutils/nls.c: Likewise.
    * libmailutils/nullrec.c: Likewise.
    * libmailutils/observer.c: Likewise.
    * libmailutils/opool.c: Likewise.
    * libmailutils/parsedate.y: Likewise.
    * libmailutils/permstr.c: Likewise.
    * libmailutils/property.c: Likewise.
    * libmailutils/registrar.c: Likewise.
    * libmailutils/refcount.c: Likewise.
    * libmailutils/rfc2047.c: Likewise.
    * libmailutils/sha1.c: Likewise.
    * libmailutils/secret.c: Likewise.
    * libmailutils/ticket.c: Likewise.
    * libmailutils/url.c: Likewise.
    * libmailutils/vartab.c: Likewise.
    * libmailutils/version.c: Likewise.
    * libmailutils/wicket.c: Likewise.

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

Summary of changes:
 Makefile.am                                  |   29 +-
 am/config_paths.m4                           |    6 +-
 am/db2.m4                                    |    4 +-
 am/debug.m4                                  |    2 +-
 am/enable.m4                                 |    8 +-
 am/gsasl.m4                                  |    3 +-
 am/tls.m4                                    |    3 +-
 bootstrap.conf                               |   18 +-
 cmc/cmc_act_on.c                             |    4 +-
 cmc/cmc_free.c                               |    4 +-
 cmc/cmc_list.c                               |    4 +-
 cmc/cmc_logoff.c                             |    4 +-
 cmc/cmc_logon.c                              |    4 +-
 cmc/cmc_look_up.c                            |    4 +-
 cmc/cmc_query_config.c                       |    4 +-
 cmc/cmc_read.c                               |    4 +-
 cmc/cmc_send.c                               |    4 +-
 cmc/cmc_send_documents.c                     |    4 +-
 cmc/xcmc.h                                   |    4 +-
 comsat/Makefile.am                           |   29 +-
 comsat/action.c                              |    4 +-
 comsat/comsat.c                              |    4 +-
 comsat/comsat.h                              |    4 +-
 config/Makefile.am                           |   29 +-
 config/mailutils-config.c                    |    4 +-
 config/mailutils.m4                          |    4 +-
 configure.ac                                 |   17 +-
 doc/Makefile.am                              |   29 +-
 doc/man/Makefile.am                          |   29 +-
 doc/texinfo/Makefile.am                      |   29 +-
 dotlock/Makefile.am                          |   27 +-
 dotlock/dotlock.c                            |    4 +-
 examples/Makefile.am                         |   29 +-
 examples/aclck.c                             |    4 +-
 examples/addr.c                              |    4 +-
 examples/base64.c                            |    4 +-
 examples/config/Makefile.am                  |   29 +-
 examples/config/mailutils.schema             |    2 +-
 examples/cpp/Makefile.am                     |   29 +-
 examples/cpp/addr.cc                         |    8 +-
 examples/cpp/http.cc                         |    8 +-
 examples/cpp/iconv.cc                        |    8 +-
 examples/cpp/listop.cc                       |    8 +-
 examples/cpp/lsf.cc                          |    4 +-
 examples/cpp/mailcap.cc                      |    8 +-
 examples/cpp/mimetest.cc                     |    4 +-
 examples/cpp/msg-send.cc                     |    4 +-
 examples/cpp/murun.cc                        |    8 +-
 examples/cpp/sfrom.cc                        |    8 +-
 examples/cpp/url-parse.cc                    |    8 +-
 examples/header.c                            |    4 +-
 examples/http.c                              |    4 +-
 examples/iconv.c                             |    4 +-
 examples/lsf.c                               |    4 +-
 examples/msg-send.c                          |    4 +-
 examples/mta.c                               |    4 +-
 examples/muauth.c                            |    4 +-
 examples/mucat.c                             |    4 +-
 examples/muemail.c                           |    4 +-
 examples/murun.c                             |    4 +-
 examples/musocio.c                           |    4 +-
 examples/nntpclient.c                        |    4 +-
 examples/numaddr.c                           |    5 +-
 examples/pop3client.c                        |    4 +-
 examples/python/Makefile.am                  |   27 +-
 examples/python/addr.py                      |    4 +-
 examples/python/auth.py                      |    4 +-
 examples/python/iconv.py                     |    4 +-
 examples/python/lsf.py                       |    4 +-
 examples/python/mailcap.py                   |    4 +-
 examples/python/mimetest.py                  |    4 +-
 examples/python/msg-send.py                  |    4 +-
 examples/python/sfrom.py                     |    4 +-
 examples/python/url-parse.py                 |    4 +-
 examples/scheme/Makefile.am                  |   27 +-
 examples/scheme/reply.scm                    |    3 +-
 examples/sfrom.c                             |    4 +-
 frm/Makefile.am                              |   29 +-
 frm/common.c                                 |    4 +-
 frm/frm.c                                    |    4 +-
 frm/frm.h                                    |    4 +-
 frm/from.c                                   |    4 +-
 frm/tests/Makefile.am                        |    2 +-
 frm/tests/testsuite.at                       |    2 +-
 guimb/Makefile.am                            |   29 +-
 guimb/collect.c                              |    4 +-
 guimb/guimb.h                                |    4 +-
 guimb/main.c                                 |    4 +-
 guimb/scm/Makefile.am                        |   29 +-
 guimb/scm/mimeheader.scm                     |    3 +-
 guimb/scm/numaddr.scm                        |    3 +-
 guimb/scm/redirect.scm                       |    3 +-
 guimb/scm/reject.scm                         |    3 +-
 guimb/scm/sieve-core.scm                     |    3 +-
 guimb/scm/sieve.scm.in                       |    3 +-
 guimb/scm/vacation.scm                       |    3 +-
 guimb/util.c                                 |    4 +-
 imap4d/Makefile.am                           |   29 +-
 imap4d/append.c                              |    4 +-
 imap4d/auth_gsasl.c                          |    4 +-
 imap4d/auth_gss.c                            |    4 +-
 imap4d/authenticate.c                        |    4 +-
 imap4d/bye.c                                 |    4 +-
 imap4d/capability.c                          |    4 +-
 imap4d/check.c                               |    4 +-
 imap4d/close.c                               |    4 +-
 imap4d/commands.c                            |    4 +-
 imap4d/copy.c                                |    4 +-
 imap4d/create.c                              |    4 +-
 imap4d/delete.c                              |    4 +-
 imap4d/examine.c                             |    4 +-
 imap4d/expunge.c                             |    4 +-
 imap4d/fetch.c                               |    4 +-
 imap4d/id.c                                  |    4 +-
 imap4d/idle.c                                |    4 +-
 imap4d/imap4d.c                              |    4 +-
 imap4d/imap4d.h                              |    4 +-
 imap4d/io.c                                  |    4 +-
 imap4d/list.c                                |    4 +-
 imap4d/login.c                               |    4 +-
 imap4d/logout.c                              |    4 +-
 imap4d/lsub.c                                |    4 +-
 imap4d/namespace.c                           |    4 +-
 imap4d/noop.c                                |    4 +-
 imap4d/parsebuf.c                            |    4 +-
 imap4d/preauth.c                             |    4 +-
 imap4d/rename.c                              |    4 +-
 imap4d/search.c                              |    4 +-
 imap4d/select.c                              |    4 +-
 imap4d/signal.c                              |    4 +-
 imap4d/starttls.c                            |    4 +-
 imap4d/status.c                              |    4 +-
 imap4d/store.c                               |    4 +-
 imap4d/subscribe.c                           |    4 +-
 imap4d/sync.c                                |    4 +-
 imap4d/testsuite/Makefile.am                 |   27 +-
 imap4d/testsuite/imap4d/IDEF0955.exp         |    8 +-
 imap4d/testsuite/imap4d/IDEF0956.exp         |    8 +-
 imap4d/testsuite/imap4d/anystate.exp         |    8 +-
 imap4d/testsuite/imap4d/append.exp           |    8 +-
 imap4d/testsuite/imap4d/create.exp           |    8 +-
 imap4d/testsuite/imap4d/examine.exp          |    8 +-
 imap4d/testsuite/imap4d/expunge.exp          |    8 +-
 imap4d/testsuite/imap4d/fetch.exp            |    8 +-
 imap4d/testsuite/imap4d/list.exp             |    8 +-
 imap4d/testsuite/imap4d/search.exp           |    8 +-
 imap4d/testsuite/imap4d/x.exp                |    8 +-
 imap4d/testsuite/lib/imap4d.exp              |    8 +-
 imap4d/uid.c                                 |    4 +-
 imap4d/unsubscribe.c                         |    4 +-
 imap4d/util.c                                |    4 +-
 include/Makefile.am                          |   29 +-
 include/mailutils/Makefile.am                |   31 +-
 include/mailutils/address.h                  |    5 +-
 include/mailutils/alloc.h                    |    5 +-
 include/mailutils/argcv.h                    |    5 +-
 include/mailutils/assoc.h                    |    5 +-
 include/mailutils/attribute.h                |    5 +-
 include/mailutils/auth.h                     |    5 +-
 include/mailutils/body.h                     |    5 +-
 include/mailutils/cfg.h                      |    4 +-
 include/mailutils/cpp/Makefile.am            |   26 +-
 include/mailutils/cpp/address.h              |    9 +-
 include/mailutils/cpp/attribute.h            |    9 +-
 include/mailutils/cpp/body.h                 |    9 +-
 include/mailutils/cpp/debug.h                |    9 +-
 include/mailutils/cpp/envelope.h             |    9 +-
 include/mailutils/cpp/error.h                |    9 +-
 include/mailutils/cpp/filter.h               |    9 +-
 include/mailutils/cpp/folder.h               |    9 +-
 include/mailutils/cpp/header.h               |    9 +-
 include/mailutils/cpp/iterator.h             |    9 +-
 include/mailutils/cpp/list.h                 |    9 +-
 include/mailutils/cpp/mailbox.h              |    9 +-
 include/mailutils/cpp/mailcap.h              |    9 +-
 include/mailutils/cpp/mailer.h               |    9 +-
 include/mailutils/cpp/mailutils.h            |    9 +-
 include/mailutils/cpp/message.h              |    9 +-
 include/mailutils/cpp/mime.h                 |    9 +-
 include/mailutils/cpp/mutil.h                |    9 +-
 include/mailutils/cpp/pop3.h                 |    9 +-
 include/mailutils/cpp/registrar.h            |    9 +-
 include/mailutils/cpp/secret.h               |    9 +-
 include/mailutils/cpp/sieve.h                |    9 +-
 include/mailutils/cpp/stream.h               |    9 +-
 include/mailutils/cpp/url.h                  |    9 +-
 include/mailutils/daemon.h                   |    5 +-
 include/mailutils/debug.hm4                  |    5 +-
 include/mailutils/diag.h                     |    5 +-
 include/mailutils/envelope.h                 |    5 +-
 include/mailutils/errno.hin                  |    5 +-
 include/mailutils/error.h                    |    5 +-
 include/mailutils/filter.h                   |    5 +-
 include/mailutils/folder.h                   |    5 +-
 include/mailutils/gocs.h                     |    5 +-
 include/mailutils/gsasl.h                    |    5 +-
 include/mailutils/guile.h                    |    5 +-
 include/mailutils/header.h                   |    5 +-
 include/mailutils/io.h                       |    5 +-
 include/mailutils/iterator.h                 |    5 +-
 include/mailutils/ldap.h                     |    5 +-
 include/mailutils/libargp.h                  |    5 +-
 include/mailutils/libcfg.h                   |    5 +-
 include/mailutils/list.h                     |    5 +-
 include/mailutils/locker.h                   |    5 +-
 include/mailutils/mailbox.h                  |    5 +-
 include/mailutils/mailcap.h                  |    5 +-
 include/mailutils/mailer.h                   |    5 +-
 include/mailutils/md5.h                      |    3 +-
 include/mailutils/message.h                  |    5 +-
 include/mailutils/mime.h                     |    5 +-
 include/mailutils/monitor.h                  |    5 +-
 include/mailutils/mu_auth.h                  |    5 +-
 include/mailutils/mutil.h                    |    5 +-
 include/mailutils/nls.h                      |    5 +-
 include/mailutils/nntp.h                     |    5 +-
 include/mailutils/observer.h                 |    5 +-
 include/mailutils/opool.h                    |    5 +-
 include/mailutils/pam.h                      |    5 +-
 include/mailutils/parse822.h                 |    5 +-
 include/mailutils/pop3.h                     |    5 +-
 include/mailutils/progmailer.h               |    5 +-
 include/mailutils/property.h                 |    5 +-
 include/mailutils/python.h                   |    5 +-
 include/mailutils/radius.h                   |    5 +-
 include/mailutils/refcount.h                 |    5 +-
 include/mailutils/registrar.h                |    5 +-
 include/mailutils/secret.h                   |    5 +-
 include/mailutils/sha1.h                     |    3 +-
 include/mailutils/sieve.h                    |    5 +-
 include/mailutils/sql.h                      |    5 +-
 include/mailutils/sys/Makefile.am            |   27 +-
 include/mailutils/sys/amd.h                  |    5 +-
 include/mailutils/sys/attribute.h            |    5 +-
 include/mailutils/sys/auth.h                 |    5 +-
 include/mailutils/sys/body.h                 |    5 +-
 include/mailutils/sys/debug.h                |    5 +-
 include/mailutils/sys/envelope.h             |    5 +-
 include/mailutils/sys/filter.h               |    5 +-
 include/mailutils/sys/folder.h               |    5 +-
 include/mailutils/sys/header.h               |    5 +-
 include/mailutils/sys/imap.h                 |    5 +-
 include/mailutils/sys/iterator.h             |    5 +-
 include/mailutils/sys/list.h                 |    5 +-
 include/mailutils/sys/mailbox.h              |    5 +-
 include/mailutils/sys/mailer.h               |    5 +-
 include/mailutils/sys/message.h              |    5 +-
 include/mailutils/sys/mime.h                 |    5 +-
 include/mailutils/sys/monitor.h              |    5 +-
 include/mailutils/sys/nntp.h                 |    5 +-
 include/mailutils/sys/observer.h             |    5 +-
 include/mailutils/sys/pop3.h                 |    5 +-
 include/mailutils/sys/property.h             |    5 +-
 include/mailutils/sys/registrar.h            |    5 +-
 include/mailutils/sys/url.h                  |    5 +-
 include/mailutils/syslog.h                   |    5 +-
 include/mailutils/tls.h                      |    5 +-
 include/mailutils/types.hin                  |    5 +-
 include/mailutils/url.h                      |    5 +-
 include/mailutils/version.h                  |    5 +-
 lib/Makefile.am                              |   29 +-
 lib/mailcap.c                                |    4 +-
 lib/mu_asprintf.h                            |    8 +-
 lib/mu_dbm.c                                 |    4 +-
 lib/mu_dbm.h                                 |    4 +-
 lib/mu_umaxtostr.c                           |    5 +-
 lib/muaux.h                                  |    4 +-
 lib/signal.c                                 |    4 +-
 lib/strexit.c                                |    4 +-
 lib/tcpwrap.c                                |    4 +-
 lib/tcpwrap.h                                |    4 +-
 lib/userprivs.c                              |    4 +-
 lib/utmp.c                                   |    6 +-
 libmailutils/.gitignore                      |    8 -
 libmailutils/Makefile.am                     |  218 +---
 libmailutils/address.c                       |  595 --------
 libmailutils/address/Makefile.am             |   24 +
 libmailutils/address/address.c               |  594 ++++++++
 libmailutils/address/parse822.c              | 2039 +++++++++++++++++++++++++
 libmailutils/amd.c                           | 2033 -------------------------
 libmailutils/argcv.c                         |  549 -------
 libmailutils/asnprintf.c                     |   40 -
 libmailutils/asprintf.c                      |   42 -
 libmailutils/assoc.c                         |  529 -------
 libmailutils/attachment.c                    |  461 ------
 libmailutils/attribute.c                     |  470 ------
 libmailutils/auth.c                          |  164 --
 libmailutils/auth/Makefile.am                |   25 +
 libmailutils/auth/auth.c                     |  163 ++
 libmailutils/auth/mu_auth.c                  |  538 +++++++
 libmailutils/auth/system.c                   |  159 ++
 libmailutils/base/.gitignore                 |    1 +
 libmailutils/base/Makefile.am                |   80 +
 libmailutils/{ => base}/alloc.c              |    0
 libmailutils/base/amd.c                      | 2032 +++++++++++++++++++++++++
 libmailutils/base/argcv.c                    |  548 +++++++
 libmailutils/base/assoc.c                    |  527 +++++++
 libmailutils/base/daemon.c                   |  188 +++
 libmailutils/base/date.c                     |  244 +++
 libmailutils/base/fgetpwent.c                |  162 ++
 libmailutils/base/freeitem.c                 |   28 +
 libmailutils/{ => base}/getpass.c            |    0
 libmailutils/base/iterator.c                 |  283 ++++
 libmailutils/{ => base}/kwd.c                |    0
 libmailutils/base/list.c                     |  692 +++++++++
 libmailutils/base/listlist.c                 |  138 ++
 libmailutils/base/locale.c                   |  241 +++
 libmailutils/base/locker.c                   | 1026 +++++++++++++
 libmailutils/base/mailcap.c                  |  739 ++++++++++
 libmailutils/base/md5.c                      |  453 ++++++
 libmailutils/base/monitor.c                  |  281 ++++
 libmailutils/base/munre.c                    |   92 ++
 libmailutils/base/mutil.c                    | 1535 +++++++++++++++++++
 libmailutils/base/nls.c                      |   61 +
 libmailutils/{ => base}/nullrec.c            |    0
 libmailutils/base/observer.c                 |  238 +++
 libmailutils/base/opool.c                    |  446 ++++++
 libmailutils/base/parsedate.y                | 1205 +++++++++++++++
 libmailutils/base/permstr.c                  |  127 ++
 libmailutils/base/property.c                 |  191 +++
 libmailutils/base/refcount.c                 |  107 ++
 libmailutils/base/registrar.c                |  442 ++++++
 libmailutils/base/rfc2047.c                  |  313 ++++
 libmailutils/base/secret.c                   |  134 ++
 libmailutils/base/sha1.c                     |  417 ++++++
 libmailutils/base/ticket.c                   |  244 +++
 libmailutils/base/url.c                      | 1139 ++++++++++++++
 libmailutils/{ => base}/vartab.c             |    0
 libmailutils/base/version.c                  |  187 +++
 libmailutils/base/wicket.c                   |  356 +++++
 libmailutils/body.c                          |  417 ------
 libmailutils/cfg/.gitignore                  |    3 +
 libmailutils/cfg/Makefile.am                 |   54 +
 libmailutils/cfg/driver.c                    |  754 ++++++++++
 libmailutils/cfg/format.c                    |  395 +++++
 libmailutils/cfg/gocs.c                      |  396 +++++
 libmailutils/cfg/lexer.l                     |  405 +++++
 libmailutils/cfg/parser.y                    | 1839 +++++++++++++++++++++++
 libmailutils/cfg_driver.c                    |  754 ----------
 libmailutils/cfg_format.c                    |  395 -----
 libmailutils/cfg_lexer.l                     |  405 -----
 libmailutils/cfg_parser.y                    | 1839 -----------------------
 libmailutils/crlfdot.c                       |  336 -----
 libmailutils/daemon.c                        |  189 ---
 libmailutils/date.c                          |  245 ---
 libmailutils/dbgstderr.c                     |   36 -
 libmailutils/dbgsyslog.c                     |   34 -
 libmailutils/debug.c                         |  299 ----
 libmailutils/diag.c                          |  179 ---
 libmailutils/diag/.gitignore                 |    1 +
 libmailutils/diag/Makefile.am                |   42 +
 libmailutils/diag/dbgstderr.c                |   35 +
 libmailutils/diag/dbgsyslog.c                |   33 +
 libmailutils/diag/debug.c                    |  298 ++++
 libmailutils/diag/diag.c                     |  178 +++
 libmailutils/diag/errors                     |   94 ++
 libmailutils/diag/gdebug.c                   |  262 ++++
 libmailutils/diag/muerrno.cin                |   65 +
 libmailutils/diag/muerror.c                  |  116 ++
 libmailutils/diag/syslog.c                   |  145 ++
 libmailutils/dot.c                           |  268 ----
 libmailutils/envelope.c                      |  181 ---
 libmailutils/errors                          |   96 --
 libmailutils/fgetpwent.c                     |  163 --
 libmailutils/filter.c                        |  194 ---
 libmailutils/filter/Makefile.am              |   33 +
 libmailutils/{ => filter}/base64.c           |    0
 libmailutils/{ => filter}/binflt.c           |    0
 libmailutils/filter/crlfdot.c                |  335 +++++
 libmailutils/{ => filter}/crlfflt.c          |    0
 libmailutils/filter/dot.c                    |  267 ++++
 libmailutils/filter/filter.c                 |  193 +++
 libmailutils/filter/filter_iconv.c           |  481 ++++++
 libmailutils/filter/fromflt.c                |  282 ++++
 libmailutils/{ => filter}/linelenflt.c       |    0
 libmailutils/{ => filter}/qpflt.c            |    0
 libmailutils/filter_iconv.c                  |  482 ------
 libmailutils/folder.c                        |  511 -------
 libmailutils/freeitem.c                      |   29 -
 libmailutils/fromflt.c                       |  283 ----
 libmailutils/gdebug.c                        |  263 ----
 libmailutils/gocs.c                          |  397 -----
 libmailutils/hdritr.c                        |  162 --
 libmailutils/header.c                        | 1222 ---------------
 libmailutils/iterator.c                      |  284 ----
 libmailutils/list.c                          |  693 ---------
 libmailutils/listlist.c                      |  139 --
 libmailutils/locale.c                        |  242 ---
 libmailutils/locker.c                        | 1027 -------------
 libmailutils/mailbox.c                       |  819 -----------
 libmailutils/mailbox/Makefile.am             |   33 +
 libmailutils/mailbox/attribute.c             |  469 ++++++
 libmailutils/mailbox/body.c                  |  416 ++++++
 libmailutils/mailbox/envelope.c              |  180 +++
 libmailutils/mailbox/folder.c                |  510 +++++++
 libmailutils/mailbox/hdritr.c                |  161 ++
 libmailutils/mailbox/header.c                | 1221 +++++++++++++++
 libmailutils/mailbox/mailbox.c               |  818 +++++++++++
 libmailutils/mailbox/mbx_default.c           |  453 ++++++
 libmailutils/mailbox/mbxitr.c                |  159 ++
 libmailutils/mailbox/message.c               | 1293 ++++++++++++++++
 libmailutils/{ => mailbox}/msgscan.c         |    0
 libmailutils/mailcap.c                       |  740 ----------
 libmailutils/mailer.c                        |  698 ---------
 libmailutils/mailer/Makefile.am              |   24 +
 libmailutils/mailer/mailer.c                 |  697 +++++++++
 libmailutils/mailer/progmailer.c             |  313 ++++
 libmailutils/mbx_default.c                   |  454 ------
 libmailutils/mbxitr.c                        |  160 --
 libmailutils/md5.c                           |  454 ------
 libmailutils/message.c                       | 1294 ----------------
 libmailutils/message_stream.c                |  440 ------
 libmailutils/mime.c                          | 1071 --------------
 libmailutils/mime/Makefile.am                |   25 +
 libmailutils/mime/attachment.c               |  460 ++++++
 libmailutils/mime/mime.c                     | 1070 ++++++++++++++
 libmailutils/{ => mime}/mimehdr.c            |    0
 libmailutils/monitor.c                       |  282 ----
 libmailutils/mu_auth.c                       |  539 -------
 libmailutils/muerrno.cin                     |   65 -
 libmailutils/muerror.c                       |  117 --
 libmailutils/munre.c                         |   93 --
 libmailutils/mutil.c                         | 1536 -------------------
 libmailutils/nls.c                           |   62 -
 libmailutils/observer.c                      |  239 ---
 libmailutils/opool.c                         |  446 ------
 libmailutils/parse822.c                      | 2040 --------------------------
 libmailutils/parsedate.y                     | 1206 ---------------
 libmailutils/permstr.c                       |  128 --
 libmailutils/progmailer.c                    |  314 ----
 libmailutils/property.c                      |  192 ---
 libmailutils/refcount.c                      |  107 --
 libmailutils/registrar.c                     |  443 ------
 libmailutils/rfc2047.c                       |  314 ----
 libmailutils/secret.c                        |  135 --
 libmailutils/server/Makefile.am              |   26 +
 libmailutils/{ => server}/acl.c              |    0
 libmailutils/{ => server}/ipsrv.c            |    0
 libmailutils/{ => server}/msrv.c             |    0
 libmailutils/{ => server}/server.c           |    0
 libmailutils/sha1.c                          |  418 ------
 libmailutils/size_max.h                      |   31 -
 libmailutils/stream/Makefile.am              |   41 +
 libmailutils/{ => stream}/dbgstream.c        |    0
 libmailutils/{ => stream}/file_stream.c      |    0
 libmailutils/{ => stream}/fltstream.c        |    0
 libmailutils/{ => stream}/iostream.c         |    0
 libmailutils/{ => stream}/mapfile_stream.c   |    0
 libmailutils/{ => stream}/memory_stream.c    |    0
 libmailutils/stream/message_stream.c         |  438 ++++++
 libmailutils/{ => stream}/prog_stream.c      |    0
 libmailutils/{ => stream}/rdcache_stream.c   |    0
 libmailutils/{ => stream}/socket_stream.c    |    0
 libmailutils/{ => stream}/stdio_stream.c     |    0
 libmailutils/{ => stream}/stream.c           |    0
 libmailutils/{ => stream}/stream_printf.c    |    0
 libmailutils/{ => stream}/stream_vprintf.c   |    0
 libmailutils/{ => stream}/streamcpy.c        |    0
 libmailutils/{ => stream}/streamref.c        |    0
 libmailutils/stream/tcp.c                    |  362 +++++
 libmailutils/{ => stream}/temp_file_stream.c |    0
 libmailutils/{ => stream}/xscript-stream.c   |    0
 libmailutils/string/Makefile.am              |   34 +
 libmailutils/string/asnprintf.c              |   39 +
 libmailutils/string/asprintf.c               |   40 +
 libmailutils/{ => string}/cstrcasecmp.c      |    0
 libmailutils/{ => string}/cstrlower.c        |    0
 libmailutils/{ => string}/cstrupper.c        |    0
 libmailutils/{ => string}/mkfilename.c       |    0
 libmailutils/{ => string}/muctype.c          |    0
 libmailutils/{ => string}/stripws.c          |    0
 libmailutils/{ => string}/strltrim.c         |    0
 libmailutils/{ => string}/strrtrim.c         |    0
 libmailutils/{ => string}/strskip.c          |    0
 libmailutils/string/vasnprintf.c             |   86 ++
 libmailutils/syslog.c                        |  145 --
 libmailutils/system.c                        |  160 --
 libmailutils/tcp.c                           |  363 -----
 libmailutils/tests/Makefile.am               |    2 +-
 libmailutils/tests/addr.c                    |    4 +-
 libmailutils/tests/address.at                |    2 +-
 libmailutils/tests/argcv.at                  |    2 +-
 libmailutils/tests/argcv.c                   |    4 +-
 libmailutils/tests/base64d.at                |    2 +-
 libmailutils/tests/base64e.at                |    2 +-
 libmailutils/tests/decode2047.at             |    2 +-
 libmailutils/tests/decode2047.c              |    4 +-
 libmailutils/tests/encode2047.at             |    2 +-
 libmailutils/tests/encode2047.c              |    4 +-
 libmailutils/tests/fltst.c                   |    4 +-
 libmailutils/tests/fromflt.at                |    2 +-
 libmailutils/tests/list.at                   |    2 +-
 libmailutils/tests/listop.c                  |    4 +-
 libmailutils/tests/mailcap.at                |    2 +-
 libmailutils/tests/mailcap.c                 |    4 +-
 libmailutils/tests/testsuite.at              |    2 +-
 libmailutils/tests/url-parse.c               |    4 +-
 libmailutils/tests/url.at                    |    2 +-
 libmailutils/ticket.c                        |  245 ---
 libmailutils/url.c                           | 1140 --------------
 libmailutils/vasnprintf.c                    |   87 --
 libmailutils/version.c                       |  189 ---
 libmailutils/wicket.c                        |  357 -----
 libmu_argp/Makefile.am                       |    4 +-
 libmu_argp/auth.c                            |    5 +-
 libmu_argp/cmdline.c                         |    5 +-
 libmu_argp/cmdline.h                         |    5 +-
 libmu_argp/common.c                          |    5 +-
 libmu_argp/mu_argp.c                         |    5 +-
 libmu_argp/muinit.c                          |    5 +-
 libmu_argp/sieve.c                           |    5 +-
 libmu_argp/tls.c                             |    5 +-
 libmu_auth/Makefile.am                       |   29 +-
 libmu_auth/gsasl.c                           |    5 +-
 libmu_auth/ldap.c                            |    5 +-
 libmu_auth/pam.c                             |    5 +-
 libmu_auth/radius.c                          |    5 +-
 libmu_auth/sql.c                             |    5 +-
 libmu_auth/sql.h                             |    5 +-
 libmu_auth/tls.c                             |    5 +-
 libmu_auth/virtual.c                         |    5 +-
 libmu_cfg/Makefile.am                        |    4 +-
 libmu_cfg/acl.c                              |    4 +-
 libmu_cfg/auth.c                             |    4 +-
 libmu_cfg/common.c                           |    4 +-
 libmu_cfg/gsasl.c                            |    4 +-
 libmu_cfg/init.c                             |    4 +-
 libmu_cfg/ldap.c                             |    4 +-
 libmu_cfg/pam.c                              |    4 +-
 libmu_cfg/radius.c                           |    4 +-
 libmu_cfg/sieve.c                            |    4 +-
 libmu_cfg/sql.c                              |    4 +-
 libmu_cfg/tls.c                              |    4 +-
 libmu_cfg/virtdomain.c                       |    4 +-
 libmu_cpp/Makefile.am                        |   29 +-
 libmu_cpp/address.cc                         |    9 +-
 libmu_cpp/attribute.cc                       |    9 +-
 libmu_cpp/body.cc                            |    9 +-
 libmu_cpp/debug.cc                           |    9 +-
 libmu_cpp/envelope.cc                        |    9 +-
 libmu_cpp/filter.cc                          |    9 +-
 libmu_cpp/folder.cc                          |    9 +-
 libmu_cpp/header.cc                          |    9 +-
 libmu_cpp/iterator.cc                        |    9 +-
 libmu_cpp/list.cc                            |    9 +-
 libmu_cpp/mailbox.cc                         |    9 +-
 libmu_cpp/mailcap.cc                         |    9 +-
 libmu_cpp/mailer.cc                          |    9 +-
 libmu_cpp/message.cc                         |    9 +-
 libmu_cpp/mime.cc                            |    9 +-
 libmu_cpp/mutil.cc                           |    9 +-
 libmu_cpp/pop3.cc                            |    9 +-
 libmu_cpp/registrar.cc                       |    9 +-
 libmu_cpp/secret.cc                          |    9 +-
 libmu_cpp/sieve.cc                           |    9 +-
 libmu_cpp/stream.cc                          |    9 +-
 libmu_cpp/url.cc                             |    9 +-
 libmu_scm/Makefile.am                        |   29 +-
 libmu_scm/mailutils.scm.in                   |    3 +-
 libmu_scm/mu_address.c                       |    5 +-
 libmu_scm/mu_body.c                          |    5 +-
 libmu_scm/mu_dbgport.c                       |    5 +-
 libmu_scm/mu_guile.c                         |    5 +-
 libmu_scm/mu_logger.c                        |    5 +-
 libmu_scm/mu_mailbox.c                       |    5 +-
 libmu_scm/mu_message.c                       |    5 +-
 libmu_scm/mu_mime.c                          |    5 +-
 libmu_scm/mu_port.c                          |    5 +-
 libmu_scm/mu_scm.c                           |    5 +-
 libmu_scm/mu_scm.h                           |    5 +-
 libmu_scm/mu_util.c                          |    5 +-
 libmu_sieve/Makefile.am                      |   29 +-
 libmu_sieve/actions.c                        |    5 +-
 libmu_sieve/comparator.c                     |    5 +-
 libmu_sieve/conf.c                           |    5 +-
 libmu_sieve/extensions/Makefile.am           |   29 +-
 libmu_sieve/extensions/list.c                |    5 +-
 libmu_sieve/extensions/moderator.c           |    5 +-
 libmu_sieve/extensions/pipe.c                |    5 +-
 libmu_sieve/extensions/spamd.c               |    5 +-
 libmu_sieve/extensions/timestamp.c           |    5 +-
 libmu_sieve/extensions/vacation.c            |    5 +-
 libmu_sieve/load.c                           |    5 +-
 libmu_sieve/prog.c                           |    5 +-
 libmu_sieve/register.c                       |    5 +-
 libmu_sieve/relational.c                     |    5 +-
 libmu_sieve/require.c                        |    5 +-
 libmu_sieve/runtime.c                        |    5 +-
 libmu_sieve/sieve-priv.h                     |    5 +-
 libmu_sieve/sieve.l                          |    5 +-
 libmu_sieve/sieve.y                          |    5 +-
 libmu_sieve/tests.c                          |    5 +-
 libmu_sieve/util.c                           |    5 +-
 libproto/Makefile.am                         |   27 +-
 libproto/imap/Makefile.am                    |   29 +-
 libproto/imap/folder.c                       |    5 +-
 libproto/imap/mbox.c                         |    5 +-
 libproto/imap/url.c                          |    5 +-
 libproto/maildir/Makefile.am                 |   29 +-
 libproto/maildir/folder.c                    |    5 +-
 libproto/maildir/maildir.h                   |    5 +-
 libproto/maildir/mbox.c                      |    5 +-
 libproto/mailer/Makefile.am                  |   27 +-
 libproto/mailer/mbox.c                       |    5 +-
 libproto/mailer/sendmail.c                   |    5 +-
 libproto/mailer/smtp.c                       |    5 +-
 libproto/mbox/Makefile.am                    |   29 +-
 libproto/mbox/folder.c                       |    5 +-
 libproto/mbox/mbox.c                         |    5 +-
 libproto/mbox/mbox0.h                        |    5 +-
 libproto/mbox/mboxscan.c                     |    5 +-
 libproto/mh/Makefile.am                      |   29 +-
 libproto/mh/folder.c                         |    5 +-
 libproto/mh/mbox.c                           |    5 +-
 libproto/nntp/Makefile.am                    |   29 +-
 libproto/nntp/folder.c                       |    5 +-
 libproto/nntp/mbox.c                         |    5 +-
 libproto/nntp/nntp0.h                        |    5 +-
 libproto/nntp/nntp_article.c                 |    5 +-
 libproto/nntp/nntp_body.c                    |    5 +-
 libproto/nntp/nntp_carrier.c                 |    5 +-
 libproto/nntp/nntp_connect.c                 |    5 +-
 libproto/nntp/nntp_create.c                  |    5 +-
 libproto/nntp/nntp_date.c                    |    5 +-
 libproto/nntp/nntp_debug.c                   |    5 +-
 libproto/nntp/nntp_destroy.c                 |    5 +-
 libproto/nntp/nntp_disconnect.c              |    5 +-
 libproto/nntp/nntp_group.c                   |    5 +-
 libproto/nntp/nntp_head.c                    |    5 +-
 libproto/nntp/nntp_help.c                    |    5 +-
 libproto/nntp/nntp_ihave.c                   |    5 +-
 libproto/nntp/nntp_iterator.c                |    7 +-
 libproto/nntp/nntp_last.c                    |    5 +-
 libproto/nntp/nntp_list_active.c             |    5 +-
 libproto/nntp/nntp_list_distribpats.c        |    5 +-
 libproto/nntp/nntp_list_distributions.c      |    5 +-
 libproto/nntp/nntp_list_extensions.c         |    5 +-
 libproto/nntp/nntp_list_newsgroups.c         |    5 +-
 libproto/nntp/nntp_list_times.c              |    5 +-
 libproto/nntp/nntp_mode_reader.c             |    5 +-
 libproto/nntp/nntp_newgroups.c               |    5 +-
 libproto/nntp/nntp_newnews.c                 |    5 +-
 libproto/nntp/nntp_next.c                    |    5 +-
 libproto/nntp/nntp_post.c                    |    5 +-
 libproto/nntp/nntp_quit.c                    |    5 +-
 libproto/nntp/nntp_readline.c                |    5 +-
 libproto/nntp/nntp_response.c                |    5 +-
 libproto/nntp/nntp_sendline.c                |    5 +-
 libproto/nntp/nntp_stat.c                    |    5 +-
 libproto/nntp/nntp_stream.c                  |    5 +-
 libproto/nntp/nntp_timeout.c                 |    5 +-
 libproto/nntp/url.c                          |    5 +-
 libproto/pop/Makefile.am                     |   29 +-
 libproto/pop/folder.c                        |    5 +-
 libproto/pop/mbox.c                          |    5 +-
 libproto/pop/pop3_apop.c                     |    5 +-
 libproto/pop/pop3_capa.c                     |    5 +-
 libproto/pop/pop3_capatst.c                  |    5 +-
 libproto/pop/pop3_carrier.c                  |    5 +-
 libproto/pop/pop3_connect.c                  |    5 +-
 libproto/pop/pop3_create.c                   |    5 +-
 libproto/pop/pop3_dele.c                     |    5 +-
 libproto/pop/pop3_destroy.c                  |    5 +-
 libproto/pop/pop3_disconnect.c               |    5 +-
 libproto/pop/pop3_iterator.c                 |    7 +-
 libproto/pop/pop3_list.c                     |    5 +-
 libproto/pop/pop3_list_cmd.c                 |    5 +-
 libproto/pop/pop3_lista.c                    |    5 +-
 libproto/pop/pop3_listas.c                   |    5 +-
 libproto/pop/pop3_noop.c                     |    5 +-
 libproto/pop/pop3_pass.c                     |    5 +-
 libproto/pop/pop3_quit.c                     |    5 +-
 libproto/pop/pop3_rdlist.c                   |    5 +-
 libproto/pop/pop3_readline.c                 |    5 +-
 libproto/pop/pop3_response.c                 |    5 +-
 libproto/pop/pop3_retr.c                     |    5 +-
 libproto/pop/pop3_rset.c                     |    5 +-
 libproto/pop/pop3_sendline.c                 |    5 +-
 libproto/pop/pop3_stat.c                     |    5 +-
 libproto/pop/pop3_stls.c                     |    5 +-
 libproto/pop/pop3_stream.c                   |    5 +-
 libproto/pop/pop3_timeout.c                  |    5 +-
 libproto/pop/pop3_top.c                      |    5 +-
 libproto/pop/pop3_trace.c                    |    5 +-
 libproto/pop/pop3_uidl.c                     |    5 +-
 libproto/pop/pop3_uidl_cmd.c                 |    5 +-
 libproto/pop/pop3_uidla.c                    |    5 +-
 libproto/pop/pop3_uidlas.c                   |    5 +-
 libproto/pop/pop3_user.c                     |    5 +-
 libproto/pop/url.c                           |    5 +-
 maidag/Makefile.am                           |    6 +-
 maidag/deliver.c                             |    4 +-
 maidag/forward.c                             |    4 +-
 maidag/guile.c                               |    4 +-
 maidag/lmtp.c                                |    4 +-
 maidag/maidag.c                              |    4 +-
 maidag/maidag.h                              |    4 +-
 maidag/mailquota.c                           |    4 +-
 maidag/python.c                              |    4 +-
 maidag/script.c                              |    4 +-
 maidag/sieve.c                               |    4 +-
 maidag/tests/Makefile.am                     |    2 +-
 maidag/util.c                                |    4 +-
 mail/Makefile.am                             |   29 +-
 mail/alias.c                                 |    4 +-
 mail/alt.c                                   |    4 +-
 mail/cd.c                                    |    4 +-
 mail/copy.c                                  |    4 +-
 mail/decode.c                                |    4 +-
 mail/delete.c                                |    4 +-
 mail/dp.c                                    |    4 +-
 mail/echo.c                                  |    4 +-
 mail/edit.c                                  |    4 +-
 mail/eq.c                                    |    4 +-
 mail/escape.c                                |    4 +-
 mail/exit.c                                  |    4 +-
 mail/file.c                                  |    4 +-
 mail/folders.c                               |    4 +-
 mail/followup.c                              |    4 +-
 mail/from.c                                  |    4 +-
 mail/headers.c                               |    4 +-
 mail/help.c                                  |    4 +-
 mail/hold.c                                  |    4 +-
 mail/if.c                                    |    4 +-
 mail/inc.c                                   |    4 +-
 mail/list.c                                  |    4 +-
 mail/mail.c                                  |    7 +-
 mail/mail.h                                  |    4 +-
 mail/mailline.c                              |    4 +-
 mail/mbox.c                                  |    4 +-
 mail/msgset.y                                |    4 +-
 mail/next.c                                  |    4 +-
 mail/page.c                                  |    4 +-
 mail/pipe.c                                  |    4 +-
 mail/previous.c                              |    4 +-
 mail/print.c                                 |    4 +-
 mail/quit.c                                  |    4 +-
 mail/reply.c                                 |    4 +-
 mail/retain.c                                |    4 +-
 mail/save.c                                  |    4 +-
 mail/send.c                                  |    4 +-
 mail/set.c                                   |    4 +-
 mail/setenv.c                                |    4 +-
 mail/shell.c                                 |    4 +-
 mail/size.c                                  |    4 +-
 mail/source.c                                |    4 +-
 mail/summary.c                               |    4 +-
 mail/table.c                                 |    4 +-
 mail/tag.c                                   |    4 +-
 mail/testsuite/Makefile.am                   |   27 +-
 mail/testsuite/if.mail                       |    8 +-
 mail/testsuite/lib/mail.exp                  |    8 +-
 mail/testsuite/mail/alias.exp                |    8 +-
 mail/testsuite/mail/folder.exp               |    8 +-
 mail/testsuite/mail/if.exp                   |    8 +-
 mail/testsuite/mail/read.exp                 |    8 +-
 mail/testsuite/mail/send.exp                 |    8 +-
 mail/testsuite/mail/tag.exp                  |    8 +-
 mail/testsuite/mail/write.exp                |    8 +-
 mail/testsuite/mail/z.exp                    |    8 +-
 mail/testsuite/makespool                     |    3 +-
 mail/top.c                                   |    4 +-
 mail/touch.c                                 |    4 +-
 mail/unalias.c                               |    4 +-
 mail/undelete.c                              |    4 +-
 mail/unset.c                                 |    4 +-
 mail/util.c                                  |    4 +-
 mail/version.c                               |    4 +-
 mail/visual.c                                |    4 +-
 mail/write.c                                 |    4 +-
 mail/z.c                                     |    4 +-
 mapi/MAPIAddress.c                           |    4 +-
 mapi/MAPIDeleteMail.c                        |    4 +-
 mapi/MAPIDetails.c                           |    4 +-
 mapi/MAPIFindNext.c                          |    4 +-
 mapi/MAPIFreeBuffer.c                        |    4 +-
 mapi/MAPILogoff.c                            |    4 +-
 mapi/MAPILogon.c                             |    4 +-
 mapi/MAPIReadMail.c                          |    4 +-
 mapi/MAPISaveMail.c                          |    4 +-
 mapi/MAPISendDocuments.c                     |    4 +-
 mapi/MAPISendMail.c                          |    4 +-
 mapi/Makefile.am                             |   27 +-
 mapi/mapi.h                                  |    4 +-
 messages/Makefile.am                         |   29 +-
 messages/messages.c                          |    4 +-
 messages/tests/Makefile.am                   |    2 +-
 messages/tests/testsuite.at                  |    2 +-
 mh/Makefile.am                               |   29 +-
 mh/ali.c                                     |    4 +-
 mh/anno.c                                    |    4 +-
 mh/burst.c                                   |    4 +-
 mh/comp.c                                    |    4 +-
 mh/compcommon.c                              |    4 +-
 mh/fmtcheck.c                                |    4 +-
 mh/folder.c                                  |    4 +-
 mh/forw.c                                    |    4 +-
 mh/inc.c                                     |    4 +-
 mh/install-mh.c                              |    4 +-
 mh/mailutils-mh.eli                          |    3 +-
 mh/mark.c                                    |    4 +-
 mh/mh.h                                      |    4 +-
 mh/mh_alias.l                                |    4 +-
 mh/mh_alias.y                                |    4 +-
 mh/mh_argp.c                                 |    7 +-
 mh/mh_ctx.c                                  |    4 +-
 mh/mh_fmtgram.y                              |    4 +-
 mh/mh_format.c                               |    4 +-
 mh/mh_format.h                               |    4 +-
 mh/mh_getopt.c                               |    4 +-
 mh/mh_getopt.h                               |    4 +-
 mh/mh_global.c                               |    4 +-
 mh/mh_init.c                                 |    4 +-
 mh/mh_list.c                                 |    4 +-
 mh/mh_msgset.c                               |    4 +-
 mh/mh_sequence.c                             |    4 +-
 mh/mh_stream.c                               |    4 +-
 mh/mh_whatnow.c                              |    4 +-
 mh/mh_whom.c                                 |    4 +-
 mh/mhl.c                                     |    4 +-
 mh/mhn.c                                     |    4 +-
 mh/mhparam.c                                 |    4 +-
 mh/mhpath.c                                  |    4 +-
 mh/pick.c                                    |    4 +-
 mh/pick.h                                    |    4 +-
 mh/pick.y                                    |    4 +-
 mh/refile.c                                  |    4 +-
 mh/repl.c                                    |    4 +-
 mh/rmf.c                                     |    4 +-
 mh/rmm.c                                     |    4 +-
 mh/scan.c                                    |    4 +-
 mh/send.c                                    |    4 +-
 mh/sortm.c                                   |    4 +-
 mh/whatnow.c                                 |    4 +-
 mh/whom.c                                    |    4 +-
 mimeview/Makefile.am                         |   27 +-
 mimeview/mimetypes.l                         |    4 +-
 mimeview/mimetypes.y                         |    4 +-
 mimeview/mimeview.c                          |    4 +-
 mimeview/mimeview.h                          |    4 +-
 movemail/Makefile.am                         |   29 +-
 movemail/movemail.c                          |    4 +-
 mu-aux/Makefile.am                           |   29 +-
 mu-aux/debugdef.m4                           |    6 +-
 mu-aux/generr.awk                            |    8 +-
 mu-aux/gylwrap                               |    3 +-
 mu-aux/texify.sed                            |    6 +-
 mu/Makefile.am                               |    4 +-
 paths                                        |    6 +-
 po/POTFILES.in                               |   38 +-
 pop3d/Makefile.am                            |   29 +-
 pop3d/bulletin.c                             |    4 +-
 pop3d/expire.c                               |    4 +-
 pop3d/extra.c                                |    4 +-
 pop3d/lock.c                                 |    4 +-
 pop3d/logindelay.c                           |    4 +-
 pop3d/pop3d.c                                |    4 +-
 pop3d/pop3d.h                                |    4 +-
 pop3d/popauth.c                              |    4 +-
 pop3d/signal.c                               |    4 +-
 pop3d/stat.c                                 |    4 +-
 pop3d/testsuite/Makefile.am                  |   27 +-
 pop3d/testsuite/lib/pop3d.exp                |    8 +-
 pop3d/testsuite/pop3d/read.exp               |    8 +-
 python/Makefile.am                           |   27 +-
 python/libmu_py/Makefile.am                  |   27 +-
 python/libmu_py/address.c                    |    9 +-
 python/libmu_py/attribute.c                  |    9 +-
 python/libmu_py/auth.c                       |    9 +-
 python/libmu_py/body.c                       |    9 +-
 python/libmu_py/c_api.c                      |    9 +-
 python/libmu_py/debug.c                      |    9 +-
 python/libmu_py/envelope.c                   |    9 +-
 python/libmu_py/error.c                      |    9 +-
 python/libmu_py/filter.c                     |    9 +-
 python/libmu_py/folder.c                     |    9 +-
 python/libmu_py/header.c                     |    9 +-
 python/libmu_py/libmu_py.c                   |    9 +-
 python/libmu_py/libmu_py.h                   |    9 +-
 python/libmu_py/list.c                       |    9 +-
 python/libmu_py/mailbox.c                    |    9 +-
 python/libmu_py/mailcap.c                    |    9 +-
 python/libmu_py/mailer.c                     |    9 +-
 python/libmu_py/message.c                    |    9 +-
 python/libmu_py/mime.c                       |    9 +-
 python/libmu_py/nls.c                        |    9 +-
 python/libmu_py/registrar.c                  |    9 +-
 python/libmu_py/script.c                     |    9 +-
 python/libmu_py/secret.c                     |    9 +-
 python/libmu_py/sieve.c                      |    9 +-
 python/libmu_py/stream.c                     |    9 +-
 python/libmu_py/url.c                        |    9 +-
 python/libmu_py/util.c                       |    9 +-
 python/mailutils/Makefile.am                 |   27 +-
 python/mailutils/__init__.py                 |    4 +-
 python/mailutils/address.py                  |    7 +-
 python/mailutils/attribute.py                |    7 +-
 python/mailutils/auth.py                     |    7 +-
 python/mailutils/body.py                     |    7 +-
 python/mailutils/debug.py                    |    7 +-
 python/mailutils/envelope.py                 |    7 +-
 python/mailutils/error.py                    |    7 +-
 python/mailutils/filter.py                   |    7 +-
 python/mailutils/folder.py                   |    7 +-
 python/mailutils/header.py                   |    7 +-
 python/mailutils/mailbox.py                  |    7 +-
 python/mailutils/mailcap.py                  |    7 +-
 python/mailutils/mailer.py                   |    7 +-
 python/mailutils/message.py                  |    7 +-
 python/mailutils/mime.py                     |    7 +-
 python/mailutils/nls.py                      |    7 +-
 python/mailutils/registrar.py                |    7 +-
 python/mailutils/secret.py                   |    7 +-
 python/mailutils/sieve.py                    |    7 +-
 python/mailutils/stream.py                   |    7 +-
 python/mailutils/url.py                      |    7 +-
 python/mailutils/util.py                     |    7 +-
 readmsg/Makefile.am                          |   29 +-
 readmsg/msglist.c                            |    4 +-
 readmsg/readmsg.c                            |    4 +-
 readmsg/readmsg.h                            |    4 +-
 readmsg/tests/Makefile.am                    |    2 +-
 readmsg/tests/all.at                         |    2 +-
 readmsg/tests/hdr.at                         |    2 +-
 readmsg/tests/nohdr.at                       |    2 +-
 readmsg/tests/testsuite.at                   |    2 +-
 readmsg/tests/twomsg.at                      |    2 +-
 readmsg/tests/weed.at                        |    2 +-
 sieve/Makefile.am                            |   27 +-
 sieve/sieve.c                                |    4 +-
 sieve/tests/Makefile.am                      |    2 +-
 sieve/tests/action.at                        |    2 +-
 sieve/tests/address.at                       |    2 +-
 sieve/tests/allof.at                         |    2 +-
 sieve/tests/anyof.at                         |    2 +-
 sieve/tests/compile.at                       |    2 +-
 sieve/tests/envelope.at                      |    2 +-
 sieve/tests/exists.at                        |    2 +-
 sieve/tests/ext.at                           |    2 +-
 sieve/tests/false.at                         |    2 +-
 sieve/tests/header.at                        |    2 +-
 sieve/tests/i-casemap.at                     |    2 +-
 sieve/tests/i-numeric.at                     |    2 +-
 sieve/tests/i-octet.at                       |    2 +-
 sieve/tests/mul-addr.at                      |    2 +-
 sieve/tests/not.at                           |    2 +-
 sieve/tests/redirect.at                      |    2 +-
 sieve/tests/reject.at                        |    2 +-
 sieve/tests/relational.at                    |    2 +-
 sieve/tests/size.at                          |    2 +-
 sieve/tests/testsuite.at                     |    2 +-
 sieve/tests/true.at                          |    2 +-
 sieve/tests/version.at                       |    2 +-
 sql/Makefile.am                              |   25 +-
 sql/mysql.c                                  |    5 +-
 sql/odbc.c                                   |    5 +-
 sql/postgres.c                               |    5 +-
 sql/sql.c                                    |    5 +-
 testsuite/Makefile.am                        |    2 +-
 testsuite/lib/mailutils.exp                  |    8 +-
 testsuite/mbdel.at                           |    2 +-
 testsuite/mbdel.c                            |    2 +-
 testsuite/mime.at                            |    2 +-
 testsuite/mimetest.c                         |    4 +-
 testsuite/smtpsend.c                         |    2 +-
 testsuite/testsuite.at                       |    2 +-
 testsuite/testsuite.inc                      |    2 +-
 967 files changed, 36443 insertions(+), 37485 deletions(-)
 delete mode 100644 libmailutils/address.c
 create mode 100644 libmailutils/address/Makefile.am
 create mode 100644 libmailutils/address/address.c
 create mode 100644 libmailutils/address/parse822.c
 delete mode 100644 libmailutils/amd.c
 delete mode 100644 libmailutils/argcv.c
 delete mode 100644 libmailutils/asnprintf.c
 delete mode 100644 libmailutils/asprintf.c
 delete mode 100644 libmailutils/assoc.c
 delete mode 100644 libmailutils/attachment.c
 delete mode 100644 libmailutils/attribute.c
 delete mode 100644 libmailutils/auth.c
 create mode 100644 libmailutils/auth/Makefile.am
 create mode 100644 libmailutils/auth/auth.c
 create mode 100644 libmailutils/auth/mu_auth.c
 create mode 100644 libmailutils/auth/system.c
 create mode 100644 libmailutils/base/.gitignore
 create mode 100644 libmailutils/base/Makefile.am
 rename libmailutils/{ => base}/alloc.c (100%)
 create mode 100644 libmailutils/base/amd.c
 create mode 100644 libmailutils/base/argcv.c
 create mode 100644 libmailutils/base/assoc.c
 create mode 100644 libmailutils/base/daemon.c
 create mode 100644 libmailutils/base/date.c
 create mode 100644 libmailutils/base/fgetpwent.c
 create mode 100644 libmailutils/base/freeitem.c
 rename libmailutils/{ => base}/getpass.c (100%)
 create mode 100644 libmailutils/base/iterator.c
 rename libmailutils/{ => base}/kwd.c (100%)
 create mode 100644 libmailutils/base/list.c
 create mode 100644 libmailutils/base/listlist.c
 create mode 100644 libmailutils/base/locale.c
 create mode 100644 libmailutils/base/locker.c
 create mode 100644 libmailutils/base/mailcap.c
 create mode 100644 libmailutils/base/md5.c
 create mode 100644 libmailutils/base/monitor.c
 create mode 100644 libmailutils/base/munre.c
 create mode 100644 libmailutils/base/mutil.c
 create mode 100644 libmailutils/base/nls.c
 rename libmailutils/{ => base}/nullrec.c (100%)
 create mode 100644 libmailutils/base/observer.c
 create mode 100644 libmailutils/base/opool.c
 create mode 100644 libmailutils/base/parsedate.y
 create mode 100644 libmailutils/base/permstr.c
 create mode 100644 libmailutils/base/property.c
 create mode 100644 libmailutils/base/refcount.c
 create mode 100644 libmailutils/base/registrar.c
 create mode 100644 libmailutils/base/rfc2047.c
 create mode 100644 libmailutils/base/secret.c
 create mode 100644 libmailutils/base/sha1.c
 create mode 100644 libmailutils/base/ticket.c
 create mode 100644 libmailutils/base/url.c
 rename libmailutils/{ => base}/vartab.c (100%)
 create mode 100644 libmailutils/base/version.c
 create mode 100644 libmailutils/base/wicket.c
 delete mode 100644 libmailutils/body.c
 create mode 100644 libmailutils/cfg/.gitignore
 create mode 100644 libmailutils/cfg/Makefile.am
 create mode 100644 libmailutils/cfg/driver.c
 create mode 100644 libmailutils/cfg/format.c
 create mode 100644 libmailutils/cfg/gocs.c
 create mode 100644 libmailutils/cfg/lexer.l
 create mode 100644 libmailutils/cfg/parser.y
 delete mode 100644 libmailutils/cfg_driver.c
 delete mode 100644 libmailutils/cfg_format.c
 delete mode 100644 libmailutils/cfg_lexer.l
 delete mode 100644 libmailutils/cfg_parser.y
 delete mode 100644 libmailutils/crlfdot.c
 delete mode 100644 libmailutils/daemon.c
 delete mode 100644 libmailutils/date.c
 delete mode 100644 libmailutils/dbgstderr.c
 delete mode 100644 libmailutils/dbgsyslog.c
 delete mode 100644 libmailutils/debug.c
 delete mode 100644 libmailutils/diag.c
 create mode 100644 libmailutils/diag/.gitignore
 create mode 100644 libmailutils/diag/Makefile.am
 create mode 100644 libmailutils/diag/dbgstderr.c
 create mode 100644 libmailutils/diag/dbgsyslog.c
 create mode 100644 libmailutils/diag/debug.c
 create mode 100644 libmailutils/diag/diag.c
 create mode 100644 libmailutils/diag/errors
 create mode 100644 libmailutils/diag/gdebug.c
 create mode 100644 libmailutils/diag/muerrno.cin
 create mode 100644 libmailutils/diag/muerror.c
 create mode 100644 libmailutils/diag/syslog.c
 delete mode 100644 libmailutils/dot.c
 delete mode 100644 libmailutils/envelope.c
 delete mode 100644 libmailutils/errors
 delete mode 100644 libmailutils/fgetpwent.c
 delete mode 100644 libmailutils/filter.c
 create mode 100644 libmailutils/filter/Makefile.am
 rename libmailutils/{ => filter}/base64.c (100%)
 rename libmailutils/{ => filter}/binflt.c (100%)
 create mode 100644 libmailutils/filter/crlfdot.c
 rename libmailutils/{ => filter}/crlfflt.c (100%)
 create mode 100644 libmailutils/filter/dot.c
 create mode 100644 libmailutils/filter/filter.c
 create mode 100644 libmailutils/filter/filter_iconv.c
 create mode 100644 libmailutils/filter/fromflt.c
 rename libmailutils/{ => filter}/linelenflt.c (100%)
 rename libmailutils/{ => filter}/qpflt.c (100%)
 delete mode 100644 libmailutils/filter_iconv.c
 delete mode 100644 libmailutils/folder.c
 delete mode 100644 libmailutils/freeitem.c
 delete mode 100644 libmailutils/fromflt.c
 delete mode 100644 libmailutils/gdebug.c
 delete mode 100644 libmailutils/gocs.c
 delete mode 100644 libmailutils/hdritr.c
 delete mode 100644 libmailutils/header.c
 delete mode 100644 libmailutils/iterator.c
 delete mode 100644 libmailutils/list.c
 delete mode 100644 libmailutils/listlist.c
 delete mode 100644 libmailutils/locale.c
 delete mode 100644 libmailutils/locker.c
 delete mode 100644 libmailutils/mailbox.c
 create mode 100644 libmailutils/mailbox/Makefile.am
 create mode 100644 libmailutils/mailbox/attribute.c
 create mode 100644 libmailutils/mailbox/body.c
 create mode 100644 libmailutils/mailbox/envelope.c
 create mode 100644 libmailutils/mailbox/folder.c
 create mode 100644 libmailutils/mailbox/hdritr.c
 create mode 100644 libmailutils/mailbox/header.c
 create mode 100644 libmailutils/mailbox/mailbox.c
 create mode 100644 libmailutils/mailbox/mbx_default.c
 create mode 100644 libmailutils/mailbox/mbxitr.c
 create mode 100644 libmailutils/mailbox/message.c
 rename libmailutils/{ => mailbox}/msgscan.c (100%)
 delete mode 100644 libmailutils/mailcap.c
 delete mode 100644 libmailutils/mailer.c
 create mode 100644 libmailutils/mailer/Makefile.am
 create mode 100644 libmailutils/mailer/mailer.c
 create mode 100644 libmailutils/mailer/progmailer.c
 delete mode 100644 libmailutils/mbx_default.c
 delete mode 100644 libmailutils/mbxitr.c
 delete mode 100644 libmailutils/md5.c
 delete mode 100644 libmailutils/message.c
 delete mode 100644 libmailutils/message_stream.c
 delete mode 100644 libmailutils/mime.c
 create mode 100644 libmailutils/mime/Makefile.am
 create mode 100644 libmailutils/mime/attachment.c
 create mode 100644 libmailutils/mime/mime.c
 rename libmailutils/{ => mime}/mimehdr.c (100%)
 delete mode 100644 libmailutils/monitor.c
 delete mode 100644 libmailutils/mu_auth.c
 delete mode 100644 libmailutils/muerrno.cin
 delete mode 100644 libmailutils/muerror.c
 delete mode 100644 libmailutils/munre.c
 delete mode 100644 libmailutils/mutil.c
 delete mode 100644 libmailutils/nls.c
 delete mode 100644 libmailutils/observer.c
 delete mode 100644 libmailutils/opool.c
 delete mode 100644 libmailutils/parse822.c
 delete mode 100644 libmailutils/parsedate.y
 delete mode 100644 libmailutils/permstr.c
 delete mode 100644 libmailutils/progmailer.c
 delete mode 100644 libmailutils/property.c
 delete mode 100644 libmailutils/refcount.c
 delete mode 100644 libmailutils/registrar.c
 delete mode 100644 libmailutils/rfc2047.c
 delete mode 100644 libmailutils/secret.c
 create mode 100644 libmailutils/server/Makefile.am
 rename libmailutils/{ => server}/acl.c (100%)
 rename libmailutils/{ => server}/ipsrv.c (100%)
 rename libmailutils/{ => server}/msrv.c (100%)
 rename libmailutils/{ => server}/server.c (100%)
 delete mode 100644 libmailutils/sha1.c
 delete mode 100644 libmailutils/size_max.h
 create mode 100644 libmailutils/stream/Makefile.am
 rename libmailutils/{ => stream}/dbgstream.c (100%)
 rename libmailutils/{ => stream}/file_stream.c (100%)
 rename libmailutils/{ => stream}/fltstream.c (100%)
 rename libmailutils/{ => stream}/iostream.c (100%)
 rename libmailutils/{ => stream}/mapfile_stream.c (100%)
 rename libmailutils/{ => stream}/memory_stream.c (100%)
 create mode 100644 libmailutils/stream/message_stream.c
 rename libmailutils/{ => stream}/prog_stream.c (100%)
 rename libmailutils/{ => stream}/rdcache_stream.c (100%)
 rename libmailutils/{ => stream}/socket_stream.c (100%)
 rename libmailutils/{ => stream}/stdio_stream.c (100%)
 rename libmailutils/{ => stream}/stream.c (100%)
 rename libmailutils/{ => stream}/stream_printf.c (100%)
 rename libmailutils/{ => stream}/stream_vprintf.c (100%)
 rename libmailutils/{ => stream}/streamcpy.c (100%)
 rename libmailutils/{ => stream}/streamref.c (100%)
 create mode 100644 libmailutils/stream/tcp.c
 rename libmailutils/{ => stream}/temp_file_stream.c (100%)
 rename libmailutils/{ => stream}/xscript-stream.c (100%)
 create mode 100644 libmailutils/string/Makefile.am
 create mode 100644 libmailutils/string/asnprintf.c
 create mode 100644 libmailutils/string/asprintf.c
 rename libmailutils/{ => string}/cstrcasecmp.c (100%)
 rename libmailutils/{ => string}/cstrlower.c (100%)
 rename libmailutils/{ => string}/cstrupper.c (100%)
 rename libmailutils/{ => string}/mkfilename.c (100%)
 rename libmailutils/{ => string}/muctype.c (100%)
 rename libmailutils/{ => string}/stripws.c (100%)
 rename libmailutils/{ => string}/strltrim.c (100%)
 rename libmailutils/{ => string}/strrtrim.c (100%)
 rename libmailutils/{ => string}/strskip.c (100%)
 create mode 100644 libmailutils/string/vasnprintf.c
 delete mode 100644 libmailutils/syslog.c
 delete mode 100644 libmailutils/system.c
 delete mode 100644 libmailutils/tcp.c
 delete mode 100644 libmailutils/ticket.c
 delete mode 100644 libmailutils/url.c
 delete mode 100644 libmailutils/vasnprintf.c
 delete mode 100644 libmailutils/version.c
 delete mode 100644 libmailutils/wicket.c

diff --git a/Makefile.am b/Makefile.am
index 7c403d6..3558c92 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
-##   2009, 2010 Free Software Foundation, Inc.
+## This file is part of GNU Mailutils
+## Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+## 2009, 2010 Free Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 ACLOCAL_AMFLAGS = -I m4 -I am -I gint
 
diff --git a/am/config_paths.m4 b/am/config_paths.m4
index 1d3ea9e..89e1f37 100644
--- a/am/config_paths.m4
+++ b/am/config_paths.m4
@@ -5,18 +5,18 @@ dnl
 dnl Written by Miles Bader <address@hidden> and
 dnl Sergey Poznyakoff <address@hidden>
 dnl
-dnl This program is free software; you can redistribute it and/or modify
+dnl GNU Mailutils is free software; you can redistribute it and/or modify
 dnl it under the terms of the GNU General Public License as published by
 dnl the Free Software Foundation; either version 3, or (at your option)
 dnl any later version.
 dnl
-dnl This program is distributed in the hope that it will be useful,
+dnl GNU Mailutils is distributed in the hope that it will be useful,
 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 dnl GNU General Public License for more details.
 dnl
 dnl You should have received a copy of the GNU General Public License
-dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
+dnl along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 dnl
 
 dnl MU_CONFIG_PATHS -- Configure system paths for use by programs
diff --git a/am/db2.m4 b/am/db2.m4
index fa305ce..8c3ee8e 100644
--- a/am/db2.m4
+++ b/am/db2.m4
@@ -12,9 +12,7 @@ dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See 
the
 dnl GNU General Public License for more details.
 dnl 
 dnl You should have received a copy of the GNU General Public License along
-dnl with GNU Mailutils; if not, write to the Free Software Foundation,
-dnl Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-dnl
+dnl with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 AH_TEMPLATE(BDB2_CURSOR_LASTARG,
             [Last argument to the cursor member of Berkeley 2 DB structure])
diff --git a/am/debug.m4 b/am/debug.m4
index ff64ba8..9b84bba 100644
--- a/am/debug.m4
+++ b/am/debug.m4
@@ -5,7 +5,7 @@ dnl This file is free software; as a special exception the 
author gives
 dnl unlimited permission to copy and/or distribute it, with or without
 dnl modifications, as long as this notice is preserved.
 dnl
-dnl This program is distributed in the hope that it will be useful, but
+dnl GNU Mailutils is distributed in the hope that it will be useful, but
 dnl WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
 dnl implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 dnl
diff --git a/am/enable.m4 b/am/enable.m4
index e531c98..0596812 100644
--- a/am/enable.m4
+++ b/am/enable.m4
@@ -2,20 +2,18 @@ dnl This file is part of GNU mailutils.
 dnl Copyright (C) 2002, 2005, 2007, 2009, 2010 Free Software Foundation,
 dnl Inc.
 dnl
-dnl This program is free software; you can redistribute it and/or modify
+dnl GNU Mailutils is free software; you can redistribute it and/or modify
 dnl it under the terms of the GNU General Public License as published by
 dnl the Free Software Foundation; either version 3 of the License, or
 dnl (at your option) any later version.
 dnl
-dnl This program is distributed in the hope that it will be useful,
+dnl GNU Mailutils is distributed in the hope that it will be useful,
 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 dnl GNU General Public License for more details.
 dnl
 dnl You should have received a copy of the GNU General Public License
-dnl along with this program; if not, write to the Free Software Foundation,
-dnl Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-dnl
+dnl along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 dnl MU_ENABLE_SUPPORT(feature, [action-if-true], [action-if-false],
 dnl                   [default-value])
diff --git a/am/gsasl.m4 b/am/gsasl.m4
index 3ce16f0..88e0b28 100644
--- a/am/gsasl.m4
+++ b/am/gsasl.m4
@@ -12,8 +12,7 @@ dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See 
the
 dnl GNU General Public License for more details.
 dnl 
 dnl You should have received a copy of the GNU General Public License along
-dnl with GNU Mailutils; if not, write to the Free Software Foundation,
-dnl Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+dnl with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 dnl
 AC_DEFUN([MU_CHECK_GSASL],
 [AC_CACHE_CHECK([whether to use GNU SASL library],
diff --git a/am/tls.m4 b/am/tls.m4
index 8bcf191..23ed7ea 100644
--- a/am/tls.m4
+++ b/am/tls.m4
@@ -12,8 +12,7 @@ dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See 
the
 dnl GNU General Public License for more details.
 dnl 
 dnl You should have received a copy of the GNU General Public License along
-dnl with GNU Mailutils; if not, write to the Free Software Foundation,
-dnl Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+dnl with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 dnl
 AC_DEFUN([MU_CHECK_TLS],
 [
diff --git a/bootstrap.conf b/bootstrap.conf
index df7f359..52a1552 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -1,22 +1,20 @@
-# Bootstrap configuration.
-
+# Bootstrap configuration for GNU Mailutils.
+#
 # Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation,
 # Inc.
-
-# This program is free software; you can redistribute it and/or modify
+#
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3, or (at your option)
 # any later version.
-
-# This program is distributed in the hope that it will be useful,
+#
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
-
+#
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301, USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 gnulib_name=libmuaux
 
diff --git a/cmc/cmc_act_on.c b/cmc/cmc_act_on.c
index 3abd286..1f5f208 100644
--- a/cmc/cmc_act_on.c
+++ b/cmc/cmc_act_on.c
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/xcmc.h>
 
diff --git a/cmc/cmc_free.c b/cmc/cmc_free.c
index 31a7bdb..b3731d3 100644
--- a/cmc/cmc_free.c
+++ b/cmc/cmc_free.c
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/xcmc.h>
 
diff --git a/cmc/cmc_list.c b/cmc/cmc_list.c
index f831e7d..1b7478e 100644
--- a/cmc/cmc_list.c
+++ b/cmc/cmc_list.c
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/xcmc.h>
 
diff --git a/cmc/cmc_logoff.c b/cmc/cmc_logoff.c
index 4b56f1b..847e2f4 100644
--- a/cmc/cmc_logoff.c
+++ b/cmc/cmc_logoff.c
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/xcmc.h>
 
diff --git a/cmc/cmc_logon.c b/cmc/cmc_logon.c
index 9dc33d7..414b528 100644
--- a/cmc/cmc_logon.c
+++ b/cmc/cmc_logon.c
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/xcmc.h>
 
diff --git a/cmc/cmc_look_up.c b/cmc/cmc_look_up.c
index 2aecbd4..3f841cf 100644
--- a/cmc/cmc_look_up.c
+++ b/cmc/cmc_look_up.c
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/xcmc.h>
 
diff --git a/cmc/cmc_query_config.c b/cmc/cmc_query_config.c
index 5d10ae3..491850f 100644
--- a/cmc/cmc_query_config.c
+++ b/cmc/cmc_query_config.c
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/xcmc.h>
 
diff --git a/cmc/cmc_read.c b/cmc/cmc_read.c
index 7add8ea..03cb98f 100644
--- a/cmc/cmc_read.c
+++ b/cmc/cmc_read.c
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/xcmc.h>
 
diff --git a/cmc/cmc_send.c b/cmc/cmc_send.c
index 80ced54..9d1513e 100644
--- a/cmc/cmc_send.c
+++ b/cmc/cmc_send.c
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/xcmc.h>
 
diff --git a/cmc/cmc_send_documents.c b/cmc/cmc_send_documents.c
index c4da56b..5217c04 100644
--- a/cmc/cmc_send_documents.c
+++ b/cmc/cmc_send_documents.c
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/xcmc.h>
 
diff --git a/cmc/xcmc.h b/cmc/xcmc.h
index c960873..c0fceb7 100644
--- a/cmc/xcmc.h
+++ b/cmc/xcmc.h
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _XCMC_H
 #define _XCMC_H
diff --git a/comsat/Makefile.am b/comsat/Makefile.am
index e218e65..752aed3 100644
--- a/comsat/Makefile.am
+++ b/comsat/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2001, 2002, 2007, 2009, 2010 Free Software
-##   Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2001, 2002, 2007, 2009, 2010 Free Software
+## Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   GNU Mailutils is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with GNU Mailutils; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 INCLUDES = @MU_APP_COMMON_INCLUDES@ 
 
diff --git a/comsat/action.c b/comsat/action.c
index 738521c..afba30f 100644
--- a/comsat/action.c
+++ b/comsat/action.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "comsat.h"
 #include <mailutils/io.h>
diff --git a/comsat/comsat.c b/comsat/comsat.c
index 0b511fa..373998f 100644
--- a/comsat/comsat.c
+++ b/comsat/comsat.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "comsat.h"
 #define MU_CFG_COMPATIBILITY /* This source uses deprecated cfg interfaces */
diff --git a/comsat/comsat.h b/comsat/comsat.h
index de4abb9..df4a19c 100644
--- a/comsat/comsat.h
+++ b/comsat/comsat.h
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/config/Makefile.am b/config/Makefile.am
index 986a234..b850f7f 100644
--- a/config/Makefile.am
+++ b/config/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software
-##   Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software
+## Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 INCLUDES = @MU_APP_COMMON_INCLUDES@ 
 
diff --git a/config/mailutils-config.c b/config/mailutils-config.c
index ccf55ab..6a34497 100644
--- a/config/mailutils-config.c
+++ b/config/mailutils-config.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/config/mailutils.m4 b/config/mailutils.m4
index 055d56c..4e8bb47 100644
--- a/config/mailutils.m4
+++ b/config/mailutils.m4
@@ -5,13 +5,13 @@ dnl modify it under the terms of the GNU General Public 
License as
 dnl published by the Free Software Foundation; either version 3, or (at
 dnl your option) any later version.
 dnl
-dnl This program is distributed in the hope that it will be useful, but
+dnl GNU Mailutils is distributed in the hope that it will be useful, but
 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 dnl General Public License for more details.
 dnl
 dnl You should have received a copy of the GNU General Public License
-dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
+dnl along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 dnl AM_GNU_MAILUTILS(minversion, link-req, [act-if-found], [ac-if-not-found])
 dnl                      $1         $2           $3              $4
diff --git a/configure.ac b/configure.ac
index 2068a9a..c7a627d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -14,12 +14,11 @@ dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
See the
 dnl GNU General Public License for more details.
 dnl
 dnl You should have received a copy of the GNU General Public License along
-dnl with GNU Mailutils; if not, write to the Free Software Foundation,
-dnl Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+dnl with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 AC_PREREQ(2.63)
 AC_INIT([GNU Mailutils], [2.2.90], address@hidden, [mailutils])
-AC_CONFIG_SRCDIR([libmailutils/mailbox.c])
+AC_CONFIG_SRCDIR([libmailutils/mailbox/mailbox.c])
 AC_CONFIG_AUX_DIR([build-aux])
 AM_INIT_AUTOMAKE([gnits 1.11 dist-bzip2 dist-xz std-options silent-rules])
 AC_CONFIG_HEADERS([config.h])
@@ -1377,6 +1376,18 @@ AC_CONFIG_FILES([
  maidag/Makefile
  mail/Makefile
  mail/testsuite/Makefile
+ libmailutils/auth/Makefile
+ libmailutils/base/Makefile
+ libmailutils/address/Makefile
+ libmailutils/cfg/Makefile
+ libmailutils/diag/Makefile
+ libmailutils/filter/Makefile
+ libmailutils/mailbox/Makefile
+ libmailutils/mailer/Makefile
+ libmailutils/mime/Makefile
+ libmailutils/server/Makefile
+ libmailutils/string/Makefile
+ libmailutils/stream/Makefile
  libmailutils/Makefile
  messages/Makefile
  mh/Makefile
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 878bb83..4fa4fea 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2000, 2001, 2002, 2007, 2009, 2010 Free Software
-##   Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2000, 2001, 2002, 2007, 2009, 2010 Free Software
+## Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 SUBDIRS = texinfo man
 EXTRA_DIST = ChangeLog.CVS rfc/README
diff --git a/doc/man/Makefile.am b/doc/man/Makefile.am
index e2689a2..acd4cf5 100644
--- a/doc/man/Makefile.am
+++ b/doc/man/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2001, 2002, 2003, 2004, 2007, 2010 Free Software
-##   Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2001, 2002, 2003, 2004, 2007, 2010 Free Software
+## Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 man_MANS = pop3d.1 imap4d.1 popauth.1 mail.1
 EXTRA_DIST = $(man_MANS)
diff --git a/doc/texinfo/Makefile.am b/doc/texinfo/Makefile.am
index 2142053..1bbe196 100644
--- a/doc/texinfo/Makefile.am
+++ b/doc/texinfo/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2001, 2002, 2003, 2004, 2006, 2007, 2009, 2010 Free
-##   Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2001, 2002, 2003, 2004, 2006, 2007, 2009, 2010 Free
+## Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 info_TEXINFOS = mailutils.texi 
 
diff --git a/dotlock/Makefile.am b/dotlock/Makefile.am
index 820066a..f9aeb48 100644
--- a/dotlock/Makefile.am
+++ b/dotlock/Makefile.am
@@ -1,21 +1,18 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2002, 2007, 2009, 2010 Free Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2002, 2007, 2009, 2010 Free Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 INCLUDES = @MU_APP_COMMON_INCLUDES@ 
 
diff --git a/dotlock/dotlock.c b/dotlock/dotlock.c
index d561d18..84d322e 100644
--- a/dotlock/dotlock.c
+++ b/dotlock/dotlock.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/examples/Makefile.am b/examples/Makefile.am
index e4c5eb9..1addf44 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2002, 2003, 2004, 2007, 2008, 2009, 2010 Free
-##   Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2002, 2003, 2004, 2007, 2008, 2009, 2010 Free
+## Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 if MU_COND_SUPPORT_POP
   POP3CLIENT = pop3client
diff --git a/examples/aclck.c b/examples/aclck.c
index 713a955..d4d9b95 100644
--- a/examples/aclck.c
+++ b/examples/aclck.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/examples/addr.c b/examples/addr.c
index aae456a..009e13e 100644
--- a/examples/addr.c
+++ b/examples/addr.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/examples/base64.c b/examples/base64.c
index 1f54ea7..deadfd2 100644
--- a/examples/base64.c
+++ b/examples/base64.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/examples/config/Makefile.am b/examples/config/Makefile.am
index 83983a8..5d51206 100644
--- a/examples/config/Makefile.am
+++ b/examples/config/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2004, 2005, 2007, 2008, 2010 Free Software
-##   Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2004, 2005, 2007, 2008, 2010 Free Software
+## Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 EXTRA_DIST = \
  dot.biffrc\
diff --git a/examples/config/mailutils.schema b/examples/config/mailutils.schema
index d0f2b9c..f61bd36 100644
--- a/examples/config/mailutils.schema
+++ b/examples/config/mailutils.schema
@@ -7,7 +7,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
diff --git a/examples/cpp/Makefile.am b/examples/cpp/Makefile.am
index 8176c6c..d06b0fb 100644
--- a/examples/cpp/Makefile.am
+++ b/examples/cpp/Makefile.am
@@ -1,22 +1,19 @@
-##   Process this file with GNU Automake to create Makefile.in
+## This file is part of GNU Mailutils.
+## Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software
+## Foundation, Inc.
 ##
-##   Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software
-##   Foundation, Inc.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
-##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 MU_CXX_EXAMPLES_LIST = \
  addr\
diff --git a/examples/cpp/addr.cc b/examples/cpp/addr.cc
index c861c0c..6fde214 100644
--- a/examples/cpp/addr.cc
+++ b/examples/cpp/addr.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA
-*/
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <iostream>
 #include <cstring>
diff --git a/examples/cpp/http.cc b/examples/cpp/http.cc
index f523951..7e0d2e8 100644
--- a/examples/cpp/http.cc
+++ b/examples/cpp/http.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA
-*/
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /* This is an example program to illustrate the use of stream functions.
    It connects to a remote HTTP server and prints the contents of its
diff --git a/examples/cpp/iconv.cc b/examples/cpp/iconv.cc
index e94c47b..9889b3c 100644
--- a/examples/cpp/iconv.cc
+++ b/examples/cpp/iconv.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA
-*/
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <iostream>
 #include <cstdlib>
diff --git a/examples/cpp/listop.cc b/examples/cpp/listop.cc
index 994b79c..01bab7b 100644
--- a/examples/cpp/listop.cc
+++ b/examples/cpp/listop.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA
-*/
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <iostream>
 #include <cstdlib>
diff --git a/examples/cpp/lsf.cc b/examples/cpp/lsf.cc
index 306ee97..68a9a49 100644
--- a/examples/cpp/lsf.cc
+++ b/examples/cpp/lsf.cc
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <iostream>
 #include <cstdlib>
diff --git a/examples/cpp/mailcap.cc b/examples/cpp/mailcap.cc
index d1a0f45..9dcf90d 100644
--- a/examples/cpp/mailcap.cc
+++ b/examples/cpp/mailcap.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA
-*/
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <iostream>
 #include <cstdlib>
diff --git a/examples/cpp/mimetest.cc b/examples/cpp/mimetest.cc
index 2215b94..4eae88b 100644
--- a/examples/cpp/mimetest.cc
+++ b/examples/cpp/mimetest.cc
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <iostream>
 #include <cstdlib>
diff --git a/examples/cpp/msg-send.cc b/examples/cpp/msg-send.cc
index 79b300d..76bac8c 100644
--- a/examples/cpp/msg-send.cc
+++ b/examples/cpp/msg-send.cc
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <iostream>
 #include <cstdlib>
diff --git a/examples/cpp/murun.cc b/examples/cpp/murun.cc
index 6dc1e1a..b9133b1 100644
--- a/examples/cpp/murun.cc
+++ b/examples/cpp/murun.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA
-*/
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <iostream>
 #include <mailutils/cpp/mailutils.h>
diff --git a/examples/cpp/sfrom.cc b/examples/cpp/sfrom.cc
index 590b07e..779f42c 100644
--- a/examples/cpp/sfrom.cc
+++ b/examples/cpp/sfrom.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA
-*/
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <iostream>
 #include <cstdlib>
diff --git a/examples/cpp/url-parse.cc b/examples/cpp/url-parse.cc
index 3c01181..b0dd0af 100644
--- a/examples/cpp/url-parse.cc
+++ b/examples/cpp/url-parse.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010 Free Software
    Foundation, Inc.
 
@@ -14,10 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA
-*/
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <iostream>
 #include <vector>
diff --git a/examples/header.c b/examples/header.c
index 63733f8..1d6c790 100644
--- a/examples/header.c
+++ b/examples/header.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/examples/http.c b/examples/http.c
index 44666e5..f44339a 100644
--- a/examples/http.c
+++ b/examples/http.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* This is an example program to illustrate the use of stream functions.
    It connects to a remote HTTP server and prints the contents of its
diff --git a/examples/iconv.c b/examples/iconv.c
index 7876dc6..6a03349 100644
--- a/examples/iconv.c
+++ b/examples/iconv.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/examples/lsf.c b/examples/lsf.c
index 3998c58..936c572 100644
--- a/examples/lsf.c
+++ b/examples/lsf.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/examples/msg-send.c b/examples/msg-send.c
index 46dd82a..321f5f5 100644
--- a/examples/msg-send.c
+++ b/examples/msg-send.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/examples/mta.c b/examples/mta.c
index d53e97f..705a2b0 100644
--- a/examples/mta.c
+++ b/examples/mta.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* This is a "fake" mta designed for testing purposes. It imitates
    sendmail sending and daemon modes. It does not actually send anything,
diff --git a/examples/muauth.c b/examples/muauth.c
index c771ebf..a80cda8 100644
--- a/examples/muauth.c
+++ b/examples/muauth.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/examples/mucat.c b/examples/mucat.c
index 92f55eb..094e454 100644
--- a/examples/mucat.c
+++ b/examples/mucat.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/examples/muemail.c b/examples/muemail.c
index 6bceb25..b2635cb 100644
--- a/examples/muemail.c
+++ b/examples/muemail.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/examples/murun.c b/examples/murun.c
index c4f822f..71e2a10 100644
--- a/examples/murun.c
+++ b/examples/murun.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/examples/musocio.c b/examples/musocio.c
index 31ca7d3..ca49501 100644
--- a/examples/musocio.c
+++ b/examples/musocio.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/examples/nntpclient.c b/examples/nntpclient.c
index 4c7722f..19fec3d 100644
--- a/examples/nntpclient.c
+++ b/examples/nntpclient.c
@@ -16,9 +16,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>  
diff --git a/examples/numaddr.c b/examples/numaddr.c
index 9a5bea0..8e0345d 100644
--- a/examples/numaddr.c
+++ b/examples/numaddr.c
@@ -13,9 +13,8 @@
    GNU Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with GNU Mailutils; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   License along with GNU Mailutils.  If not, see
+   <http://www.gnu.org/licenses/>. */; 
 
 /*  This is an example on how to write extension tests for GNU sieve.
     It provides test "numaddr".
diff --git a/examples/pop3client.c b/examples/pop3client.c
index 87f0c44..f2d81a3 100644
--- a/examples/pop3client.c
+++ b/examples/pop3client.c
@@ -16,9 +16,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>  
diff --git a/examples/python/Makefile.am b/examples/python/Makefile.am
index 4f816ee..d87bf90 100644
--- a/examples/python/Makefile.am
+++ b/examples/python/Makefile.am
@@ -1,21 +1,18 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 EXTRA_DIST = \
  addr.py\
diff --git a/examples/python/addr.py b/examples/python/addr.py
index 2b844ed..99399da 100644
--- a/examples/python/addr.py
+++ b/examples/python/addr.py
@@ -12,9 +12,7 @@
 #  GNU General Public License for more details.
 #
 #  You should have received a copy of the GNU General Public License
-#  along with GNU Mailutils; if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-#  MA 02110-1301 USA
+#  along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 import sys
 from mailutils import address
diff --git a/examples/python/auth.py b/examples/python/auth.py
index e1e1c07..1312e7b 100644
--- a/examples/python/auth.py
+++ b/examples/python/auth.py
@@ -12,9 +12,7 @@
 #  GNU General Public License for more details.
 #
 #  You should have received a copy of the GNU General Public License
-#  along with GNU Mailutils; if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-#  MA 02110-1301 USA
+#  along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 import sys
 import getopt
diff --git a/examples/python/iconv.py b/examples/python/iconv.py
index 3e36381..d1d77c9 100644
--- a/examples/python/iconv.py
+++ b/examples/python/iconv.py
@@ -12,9 +12,7 @@
 #  GNU General Public License for more details.
 #
 #  You should have received a copy of the GNU General Public License
-#  along with GNU Mailutils; if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-#  MA 02110-1301 USA
+#  along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 import sys
 from mailutils import stream
diff --git a/examples/python/lsf.py b/examples/python/lsf.py
index 6bd9b03..56d4fc3 100644
--- a/examples/python/lsf.py
+++ b/examples/python/lsf.py
@@ -12,9 +12,7 @@
 #  GNU General Public License for more details.
 #
 #  You should have received a copy of the GNU General Public License
-#  along with GNU Mailutils; if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-#  MA 02110-1301 USA
+#  along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 import sys
 from mailutils import folder
diff --git a/examples/python/mailcap.py b/examples/python/mailcap.py
index ca70dce..956ffc9 100644
--- a/examples/python/mailcap.py
+++ b/examples/python/mailcap.py
@@ -12,9 +12,7 @@
 #  GNU General Public License for more details.
 #
 #  You should have received a copy of the GNU General Public License
-#  along with GNU Mailutils; if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-#  MA 02110-1301 USA
+#  along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 from mailutils import stream, mailcap
 
diff --git a/examples/python/mimetest.py b/examples/python/mimetest.py
index 471a052..7ec6ee2 100644
--- a/examples/python/mimetest.py
+++ b/examples/python/mimetest.py
@@ -12,9 +12,7 @@
 #  GNU General Public License for more details.
 #
 #  You should have received a copy of the GNU General Public License
-#  along with GNU Mailutils; if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-#  MA 02110-1301 USA
+#  along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 import sys
 import getopt
diff --git a/examples/python/msg-send.py b/examples/python/msg-send.py
index ce339b0..cbca586 100644
--- a/examples/python/msg-send.py
+++ b/examples/python/msg-send.py
@@ -12,9 +12,7 @@
 #  GNU General Public License for more details.
 #
 #  You should have received a copy of the GNU General Public License
-#  along with GNU Mailutils; if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-#  MA 02110-1301 USA
+#  along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 import sys
 import getopt
diff --git a/examples/python/sfrom.py b/examples/python/sfrom.py
index d942870..3c461a7 100644
--- a/examples/python/sfrom.py
+++ b/examples/python/sfrom.py
@@ -12,9 +12,7 @@
 #  GNU General Public License for more details.
 #
 #  You should have received a copy of the GNU General Public License
-#  along with GNU Mailutils; if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-#  MA 02110-1301 USA
+#  along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 import sys
 from mailutils import *
diff --git a/examples/python/url-parse.py b/examples/python/url-parse.py
index d331f0e..0ea8a12 100644
--- a/examples/python/url-parse.py
+++ b/examples/python/url-parse.py
@@ -12,9 +12,7 @@
 #  GNU General Public License for more details.
 #
 #  You should have received a copy of the GNU General Public License
-#  along with GNU Mailutils; if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-#  MA 02110-1301 USA
+#  along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 import sys
 from mailutils import url
diff --git a/examples/scheme/Makefile.am b/examples/scheme/Makefile.am
index 5e4baeb..121f595 100644
--- a/examples/scheme/Makefile.am
+++ b/examples/scheme/Makefile.am
@@ -1,21 +1,18 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2004, 2007, 2010 Free Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2004, 2007, 2010 Free Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 EXTRA_DIST = reply.scm
 
diff --git a/examples/scheme/reply.scm b/examples/scheme/reply.scm
index d246249..68d1d79 100644
--- a/examples/scheme/reply.scm
+++ b/examples/scheme/reply.scm
@@ -13,8 +13,7 @@
 ;;;; GNU General Public License for more details.
 ;;;; 
 ;;;; You should have received a copy of the GNU General Public License along
-;;;; with GNU Mailutils; if not, write to the Free Software Foundation,
-;;;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+;;;; with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; This is a simple Guile program that generates automatic reply to 
 ;;; incoming mail messages.
diff --git a/examples/sfrom.c b/examples/sfrom.c
index 8e6384c..930a8ac 100644
--- a/examples/sfrom.c
+++ b/examples/sfrom.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/frm/Makefile.am b/frm/Makefile.am
index fdb1bfb..03d7703 100644
--- a/frm/Makefile.am
+++ b/frm/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2010 Free
-##   Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2010 Free
+## Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 INCLUDES = @MU_APP_COMMON_INCLUDES@ 
 
diff --git a/frm/common.c b/frm/common.c
index 901c774..a604a2d 100644
--- a/frm/common.c
+++ b/frm/common.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <frm.h>
 
diff --git a/frm/frm.c b/frm/frm.c
index f978560..fdd43c1 100644
--- a/frm/frm.c
+++ b/frm/frm.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <frm.h>
 
diff --git a/frm/frm.h b/frm/frm.h
index 38ce39e..24d59ef 100644
--- a/frm/frm.h
+++ b/frm/frm.h
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/frm/from.c b/frm/from.c
index 6b9fdf8..d86cfea 100644
--- a/frm/from.c
+++ b/frm/from.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <frm.h>
 
diff --git a/frm/tests/Makefile.am b/frm/tests/Makefile.am
index b548c51..d587c2f 100644
--- a/frm/tests/Makefile.am
+++ b/frm/tests/Makefile.am
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/frm/tests/testsuite.at b/frm/tests/testsuite.at
index 1a3e6f0..b2d8558 100644
--- a/frm/tests/testsuite.at
+++ b/frm/tests/testsuite.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/guimb/Makefile.am b/guimb/Makefile.am
index 273371f..b288042 100644
--- a/guimb/Makefile.am
+++ b/guimb/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2001, 2002, 2007, 2009, 2010 Free Software
-##   Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2001, 2002, 2007, 2009, 2010 Free Software
+## Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 INCLUDES = @MU_APP_COMMON_INCLUDES@ @GUILE_INCLUDES@ 
 
diff --git a/guimb/collect.c b/guimb/collect.c
index 532fc47..342e593 100644
--- a/guimb/collect.c
+++ b/guimb/collect.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "guimb.h"
 
diff --git a/guimb/guimb.h b/guimb/guimb.h
index 1cae077..d1fc759 100644
--- a/guimb/guimb.h
+++ b/guimb/guimb.h
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #if defined(HAVE_CONFIG_H)
 # include <config.h>
diff --git a/guimb/main.c b/guimb/main.c
index f08d450..4a3f39e 100644
--- a/guimb/main.c
+++ b/guimb/main.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "guimb.h"
 #include "mailutils/libargp.h"
diff --git a/guimb/scm/Makefile.am b/guimb/scm/Makefile.am
index 6c0c708..2d70b08 100644
--- a/guimb/scm/Makefile.am
+++ b/guimb/scm/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2001, 2002, 2006, 2007, 2009, 2010 Free Software
-##   Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2001, 2002, 2006, 2007, 2009, 2010 Free Software
+## Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 MU_GUILE_SIEVE_SCRIPTS_X=sieve.scm
 bin_SCRIPTS = sieve.scm
diff --git a/guimb/scm/mimeheader.scm b/guimb/scm/mimeheader.scm
index a354694..9543e22 100644
--- a/guimb/scm/mimeheader.scm
+++ b/guimb/scm/mimeheader.scm
@@ -13,8 +13,7 @@
 ;;;; GNU General Public License for more details.
 ;;;; 
 ;;;; You should have received a copy of the GNU General Public License along
-;;;; with GNU Mailutils; if not, write to the Free Software Foundation,
-;;;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+;;;; with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;;; This module provides GNU extension test "mimeheader".
 
diff --git a/guimb/scm/numaddr.scm b/guimb/scm/numaddr.scm
index 40032fd..6854556 100644
--- a/guimb/scm/numaddr.scm
+++ b/guimb/scm/numaddr.scm
@@ -13,8 +13,7 @@
 ;;;; GNU General Public License for more details.
 ;;;; 
 ;;;; You should have received a copy of the GNU General Public License along
-;;;; with GNU Mailutils; if not, write to the Free Software Foundation,
-;;;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+;;;; with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 ;;;; This module provides GNU extension test "numaddr".
 
diff --git a/guimb/scm/redirect.scm b/guimb/scm/redirect.scm
index ade16d6..dd62b76 100644
--- a/guimb/scm/redirect.scm
+++ b/guimb/scm/redirect.scm
@@ -13,8 +13,7 @@
 ;;;; GNU General Public License for more details.
 ;;;; 
 ;;;; You should have received a copy of the GNU General Public License along
-;;;; with GNU Mailutils; if not, write to the Free Software Foundation,
-;;;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+;;;; with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;;; This module provides sieve's "redirect" action.
 
diff --git a/guimb/scm/reject.scm b/guimb/scm/reject.scm
index b399193..0447ad1 100644
--- a/guimb/scm/reject.scm
+++ b/guimb/scm/reject.scm
@@ -13,8 +13,7 @@
 ;;;; GNU General Public License for more details.
 ;;;; 
 ;;;; You should have received a copy of the GNU General Public License along
-;;;; with GNU Mailutils; if not, write to the Free Software Foundation,
-;;;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+;;;; with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;;; This module provides sieve's "reject" action.
 
diff --git a/guimb/scm/sieve-core.scm b/guimb/scm/sieve-core.scm
index f5f335c..be61adb 100644
--- a/guimb/scm/sieve-core.scm
+++ b/guimb/scm/sieve-core.scm
@@ -13,8 +13,7 @@
 ;;;; GNU General Public License for more details.
 ;;;; 
 ;;;; You should have received a copy of the GNU General Public License along
-;;;; with GNU Mailutils; if not, write to the Free Software Foundation,
-;;;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+;;;; with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;;; This module provides core functionality for the sieve scripts.
 
diff --git a/guimb/scm/sieve.scm.in b/guimb/scm/sieve.scm.in
index 68f0e49..23fd9eb 100644
--- a/guimb/scm/sieve.scm.in
+++ b/guimb/scm/sieve.scm.in
@@ -16,8 +16,7 @@
 ;;;; GNU General Public License for more details.
 ;;;; 
 ;;;; You should have received a copy of the GNU General Public License along
-;;;; with GNU Mailutils; if not, write to the Free Software Foundation,
-;;;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+;;;; with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 ;;;;
 
 ;;;; This is a Sieve to Scheme translator.
diff --git a/guimb/scm/vacation.scm b/guimb/scm/vacation.scm
index 3e28729..f493c48 100644
--- a/guimb/scm/vacation.scm
+++ b/guimb/scm/vacation.scm
@@ -13,8 +13,7 @@
 ;;;; GNU General Public License for more details.
 ;;;; 
 ;;;; You should have received a copy of the GNU General Public License along
-;;;; with GNU Mailutils; if not, write to the Free Software Foundation,
-;;;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+;;;; with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;;; This module provides "vacation" extension
 
diff --git a/guimb/util.c b/guimb/util.c
index 71a6769..8eb8c0d 100644
--- a/guimb/util.c
+++ b/guimb/util.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "guimb.h"
 
diff --git a/imap4d/Makefile.am b/imap4d/Makefile.am
index 3c06e97..1202289 100644
--- a/imap4d/Makefile.am
+++ b/imap4d/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2007, 2008, 2009,
-##   2010 Free Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2007, 2008, 2009,
+## 2010 Free Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   GNU Mailutils is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with GNU Mailutils; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 INCLUDES = @MU_APP_COMMON_INCLUDES@ @MU_AUTHINCS@ @SERV_AUTHINCS@ 
 SUBDIRS = testsuite
diff --git a/imap4d/append.c b/imap4d/append.c
index 3ec431c..f610cff 100644
--- a/imap4d/append.c
+++ b/imap4d/append.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/auth_gsasl.c b/imap4d/auth_gsasl.c
index 8b11ad9..0c09d2c 100644
--- a/imap4d/auth_gsasl.c
+++ b/imap4d/auth_gsasl.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 #include <gsasl.h>
diff --git a/imap4d/auth_gss.c b/imap4d/auth_gss.c
index 28ce74a..11f0745 100644
--- a/imap4d/auth_gss.c
+++ b/imap4d/auth_gss.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /*
   GSSAPI authentication for imap (rfc 1731). 
diff --git a/imap4d/authenticate.c b/imap4d/authenticate.c
index 166294c..5be6c3f 100644
--- a/imap4d/authenticate.c
+++ b/imap4d/authenticate.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/bye.c b/imap4d/bye.c
index 16b67df..e592d6e 100644
--- a/imap4d/bye.c
+++ b/imap4d/bye.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/capability.c b/imap4d/capability.c
index 02b5664..1bd4df7 100644
--- a/imap4d/capability.c
+++ b/imap4d/capability.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/check.c b/imap4d/check.c
index 4713a94..40964d2 100644
--- a/imap4d/check.c
+++ b/imap4d/check.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/close.c b/imap4d/close.c
index 49ede1c..07501c5 100644
--- a/imap4d/close.c
+++ b/imap4d/close.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/commands.c b/imap4d/commands.c
index a40c623..a96c31c 100644
--- a/imap4d/commands.c
+++ b/imap4d/commands.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/copy.c b/imap4d/copy.c
index ad61fb3..f59fb72 100644
--- a/imap4d/copy.c
+++ b/imap4d/copy.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/create.c b/imap4d/create.c
index 918926a..6ccf081 100644
--- a/imap4d/create.c
+++ b/imap4d/create.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 #include <unistd.h>
diff --git a/imap4d/delete.c b/imap4d/delete.c
index 11f78be..678c2e7 100644
--- a/imap4d/delete.c
+++ b/imap4d/delete.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/examine.c b/imap4d/examine.c
index cd4d669..705f86a 100644
--- a/imap4d/examine.c
+++ b/imap4d/examine.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/expunge.c b/imap4d/expunge.c
index 46df985..8d88647 100644
--- a/imap4d/expunge.c
+++ b/imap4d/expunge.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/fetch.c b/imap4d/fetch.c
index 34860ff..d0475cf 100644
--- a/imap4d/fetch.c
+++ b/imap4d/fetch.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 #include <ctype.h>
diff --git a/imap4d/id.c b/imap4d/id.c
index 2561a1a..d141b3a 100644
--- a/imap4d/id.c
+++ b/imap4d/id.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* Implementation of ID extension (RFC 2971) */
 
diff --git a/imap4d/idle.c b/imap4d/idle.c
index fde91ab..0e4f812 100644
--- a/imap4d/idle.c
+++ b/imap4d/idle.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/imap4d.c b/imap4d/imap4d.c
index 90a6252..c80af2b 100644
--- a/imap4d/imap4d.c
+++ b/imap4d/imap4d.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 #ifdef WITH_GSASL
diff --git a/imap4d/imap4d.h b/imap4d/imap4d.h
index 30b32e1..2e54f66 100644
--- a/imap4d/imap4d.h
+++ b/imap4d/imap4d.h
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifndef _IMAP4D_H
 #define _IMAP4D_H 1
diff --git a/imap4d/io.c b/imap4d/io.c
index 14959da..0de6464 100644
--- a/imap4d/io.c
+++ b/imap4d/io.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/list.c b/imap4d/list.c
index 8f1dc6d..1c545c0 100644
--- a/imap4d/list.c
+++ b/imap4d/list.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 #include <dirent.h>
diff --git a/imap4d/login.c b/imap4d/login.c
index e14649c..1da89e5 100644
--- a/imap4d/login.c
+++ b/imap4d/login.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/logout.c b/imap4d/logout.c
index 4ce2d52..e3dffc5 100644
--- a/imap4d/logout.c
+++ b/imap4d/logout.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/lsub.c b/imap4d/lsub.c
index 6ae650e..d743c3c 100644
--- a/imap4d/lsub.c
+++ b/imap4d/lsub.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/namespace.c b/imap4d/namespace.c
index 335a909..b864d6e 100644
--- a/imap4d/namespace.c
+++ b/imap4d/namespace.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/noop.c b/imap4d/noop.c
index cfbafd5..1f91ec5 100644
--- a/imap4d/noop.c
+++ b/imap4d/noop.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/parsebuf.c b/imap4d/parsebuf.c
index 028b57a..7eab2f3 100644
--- a/imap4d/parsebuf.c
+++ b/imap4d/parsebuf.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/preauth.c b/imap4d/preauth.c
index b876ea8..1584df4 100644
--- a/imap4d/preauth.c
+++ b/imap4d/preauth.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* Preauth support for imap4d */
 
diff --git a/imap4d/rename.c b/imap4d/rename.c
index a7a65cb..bab035f 100644
--- a/imap4d/rename.c
+++ b/imap4d/rename.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/search.c b/imap4d/search.c
index 9e4a904..96e4fed 100644
--- a/imap4d/search.c
+++ b/imap4d/search.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/select.c b/imap4d/select.c
index 2897870..2e35dd8 100644
--- a/imap4d/select.c
+++ b/imap4d/select.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/signal.c b/imap4d/signal.c
index d71138e..2a0053a 100644
--- a/imap4d/signal.c
+++ b/imap4d/signal.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #define __USE_MISC
 #include "imap4d.h"
diff --git a/imap4d/starttls.c b/imap4d/starttls.c
index f71d135..5ca9484 100644
--- a/imap4d/starttls.c
+++ b/imap4d/starttls.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/status.c b/imap4d/status.c
index a462829..b572a33 100644
--- a/imap4d/status.c
+++ b/imap4d/status.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/store.c b/imap4d/store.c
index e8d592d..44cd80c 100644
--- a/imap4d/store.c
+++ b/imap4d/store.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/subscribe.c b/imap4d/subscribe.c
index e694636..49feb90 100644
--- a/imap4d/subscribe.c
+++ b/imap4d/subscribe.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/sync.c b/imap4d/sync.c
index c4a5268..5901a53 100644
--- a/imap4d/sync.c
+++ b/imap4d/sync.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 #include <mailutils/observer.h>
diff --git a/imap4d/testsuite/Makefile.am b/imap4d/testsuite/Makefile.am
index 5f3a9ee..aa5c344 100644
--- a/imap4d/testsuite/Makefile.am
+++ b/imap4d/testsuite/Makefile.am
@@ -1,21 +1,18 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2002, 2007, 2008, 2010 Free Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2002, 2007, 2008, 2010 Free Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 AUTOMAKE_OPTIONS = dejagnu
 DEJATOOL = imap4d
diff --git a/imap4d/testsuite/imap4d/IDEF0955.exp 
b/imap4d/testsuite/imap4d/IDEF0955.exp
index 10e97f5..c9d0769 100644
--- a/imap4d/testsuite/imap4d/IDEF0955.exp
+++ b/imap4d/testsuite/imap4d/IDEF0955.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2005, 2007, 2008, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 # Mailutils versions prior to 0.6.1 allowed to use any numbers in message
 # sets, even those greater than the maximum id (message number or uid),
diff --git a/imap4d/testsuite/imap4d/IDEF0956.exp 
b/imap4d/testsuite/imap4d/IDEF0956.exp
index 09dabe7..63016ed 100644
--- a/imap4d/testsuite/imap4d/IDEF0956.exp
+++ b/imap4d/testsuite/imap4d/IDEF0956.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2005, 2007, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 # Mailutils versions prior to 0.6.1 missed check for integer overflow
 # in fetch_io. 
diff --git a/imap4d/testsuite/imap4d/anystate.exp 
b/imap4d/testsuite/imap4d/anystate.exp
index 7e9ef7f..f1e4dd9 100644
--- a/imap4d/testsuite/imap4d/anystate.exp
+++ b/imap4d/testsuite/imap4d/anystate.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2002, 2007, 2008, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 imap4d_start 
 
diff --git a/imap4d/testsuite/imap4d/append.exp 
b/imap4d/testsuite/imap4d/append.exp
index c635be3..e87b746 100644
--- a/imap4d/testsuite/imap4d/append.exp
+++ b/imap4d/testsuite/imap4d/append.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2002, 2007, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 # 6.3.11. APPEND Command
 #   Arguments:  mailbox name
diff --git a/imap4d/testsuite/imap4d/create.exp 
b/imap4d/testsuite/imap4d/create.exp
index 4c38351..5cd1c1d 100644
--- a/imap4d/testsuite/imap4d/create.exp
+++ b/imap4d/testsuite/imap4d/create.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2002, 2007, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 # 6.3.3.  CREATE Command
 #   Arguments:  mailbox name
diff --git a/imap4d/testsuite/imap4d/examine.exp 
b/imap4d/testsuite/imap4d/examine.exp
index a77a1b7..cde587f 100644
--- a/imap4d/testsuite/imap4d/examine.exp
+++ b/imap4d/testsuite/imap4d/examine.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2002, 2007, 2008, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 imap4d_start 
 imap4d_auth "user!passwd" "guessme"
diff --git a/imap4d/testsuite/imap4d/expunge.exp 
b/imap4d/testsuite/imap4d/expunge.exp
index d8b84eb..cc114c2 100644
--- a/imap4d/testsuite/imap4d/expunge.exp
+++ b/imap4d/testsuite/imap4d/expunge.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2002, 2007, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 # 6.4.3.  EXPUNGE Command
 #   Arguments:  none
diff --git a/imap4d/testsuite/imap4d/fetch.exp 
b/imap4d/testsuite/imap4d/fetch.exp
index 005282f..dc04bf3 100644
--- a/imap4d/testsuite/imap4d/fetch.exp
+++ b/imap4d/testsuite/imap4d/fetch.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2002, 2007, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 # 6.4.5.  FETCH Command
 # Arguments:  message set
diff --git a/imap4d/testsuite/imap4d/list.exp b/imap4d/testsuite/imap4d/list.exp
index 6cf551c..9233194 100644
--- a/imap4d/testsuite/imap4d/list.exp
+++ b/imap4d/testsuite/imap4d/list.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2002, 2005, 2007, 2008, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 imap4d_start 
 imap4d_auth "user!passwd" "guessme"
diff --git a/imap4d/testsuite/imap4d/search.exp 
b/imap4d/testsuite/imap4d/search.exp
index 4ae413a..8741bdb 100644
--- a/imap4d/testsuite/imap4d/search.exp
+++ b/imap4d/testsuite/imap4d/search.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2002, 2007, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 # 6.4.4.  SEARCH Command
 # Arguments:  OPTIONAL [CHARSET] specification
diff --git a/imap4d/testsuite/imap4d/x.exp b/imap4d/testsuite/imap4d/x.exp
index f0e6754..6c747b8 100644
--- a/imap4d/testsuite/imap4d/x.exp
+++ b/imap4d/testsuite/imap4d/x.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2002, 2007, 2008, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 imap4d_start 
 
diff --git a/imap4d/testsuite/lib/imap4d.exp b/imap4d/testsuite/lib/imap4d.exp
index 213c5ef..55285f5 100644
--- a/imap4d/testsuite/lib/imap4d.exp
+++ b/imap4d/testsuite/lib/imap4d.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2002, 2005, 2007, 2008, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 source $top_srcdir/testsuite/lib/mailutils.exp
     
diff --git a/imap4d/uid.c b/imap4d/uid.c
index e4e5859..954451d 100644
--- a/imap4d/uid.c
+++ b/imap4d/uid.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/unsubscribe.c b/imap4d/unsubscribe.c
index 9132095..fb17bd8 100644
--- a/imap4d/unsubscribe.c
+++ b/imap4d/unsubscribe.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/imap4d/util.c b/imap4d/util.c
index 73d4031..956ddc4 100644
--- a/imap4d/util.c
+++ b/imap4d/util.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "imap4d.h"
 
diff --git a/include/Makefile.am b/include/Makefile.am
index 4fabc9d..fcb8338 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1,21 +1,18 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2000, 2002, 2007, 2010 Free Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2000, 2002, 2007, 2010 Free Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 SUBDIRS=mailutils
-EXTRA_DIST=confpaths.h.in
\ No newline at end of file
+EXTRA_DIST=confpaths.h.in
diff --git a/include/mailutils/Makefile.am b/include/mailutils/Makefile.am
index 13e4490..5b94709 100644
--- a/include/mailutils/Makefile.am
+++ b/include/mailutils/Makefile.am
@@ -1,26 +1,23 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009,
-##   2010 Free Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009,
+## 2010 Free Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   GNU Mailutils is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with GNU Mailutils; if not, write to the Free Software
-##   Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 BUILT_SOURCES=errno.h debug.h
 EXTRA_DIST=errno.hin debug.hm4 types.hin
-errno.h: $(top_srcdir)/libmailutils/errors errno.hin
+errno.h: $(top_srcdir)/libmailutils/diag/errors errno.hin
        $(AM_V_GEN)$(AWK) -f $(mu_aux_dir)/generr.awk $^ > $@
 
 debug.h: $(mu_aux_dir)/debugdef.m4 debug.hm4
diff --git a/include/mailutils/address.h b/include/mailutils/address.h
index 1ae0a48..be006a8 100644
--- a/include/mailutils/address.h
+++ b/include/mailutils/address.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_ADDRESS_H
 #define _MAILUTILS_ADDRESS_H
diff --git a/include/mailutils/alloc.h b/include/mailutils/alloc.h
index 27ab193..ff2c95e 100644
--- a/include/mailutils/alloc.h
+++ b/include/mailutils/alloc.h
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_ALLOC_H
 #define _MAILUTILS_ALLOC_H
diff --git a/include/mailutils/argcv.h b/include/mailutils/argcv.h
index 3dff1e5..dd9482f 100644
--- a/include/mailutils/argcv.h
+++ b/include/mailutils/argcv.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _ARGCV_H
 #define _ARGCV_H 1
diff --git a/include/mailutils/assoc.h b/include/mailutils/assoc.h
index a3faea8..32c8076 100644
--- a/include/mailutils/assoc.h
+++ b/include/mailutils/assoc.h
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_ASSOC_H
 #define _MAILUTILS_ASSOC_H
diff --git a/include/mailutils/attribute.h b/include/mailutils/attribute.h
index c8c066f..922ebd2 100644
--- a/include/mailutils/attribute.h
+++ b/include/mailutils/attribute.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_ATTRIBUTE_H
 #define _MAILUTILS_ATTRIBUTE_H
diff --git a/include/mailutils/auth.h b/include/mailutils/auth.h
index 84c6cc1..72bfa51 100644
--- a/include/mailutils/auth.h
+++ b/include/mailutils/auth.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_AUTH_H
 #define _MAILUTILS_AUTH_H
diff --git a/include/mailutils/body.h b/include/mailutils/body.h
index d935d00..2a116e8 100644
--- a/include/mailutils/body.h
+++ b/include/mailutils/body.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_BODY_H
 #define _MAILUTILS_BODY_H
diff --git a/include/mailutils/cfg.h b/include/mailutils/cfg.h
index 3fc7220..a9c5ddb 100644
--- a/include/mailutils/cfg.h
+++ b/include/mailutils/cfg.h
@@ -6,13 +6,13 @@
    published by the Free Software Foundation; either version 3, or (at
    your option) any later version.
 
-   This program is distributed in the hope that it will be useful, but
+   GNU Mailutils is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifndef _MAILUTILS_CFG_H
diff --git a/include/mailutils/cpp/Makefile.am 
b/include/mailutils/cpp/Makefile.am
index d9be44b..0f9ec82 100644
--- a/include/mailutils/cpp/Makefile.am
+++ b/include/mailutils/cpp/Makefile.am
@@ -1,20 +1,18 @@
-##   Process this file with GNU Automake to create Makefile.in
+## This file is part of GNU Mailutils.
+## Copyright (C) 2004, 2007, 2009, 2010 Free Software Foundation, Inc.
 ##
-##   Copyright (C) 2004, 2007, 2009, 2010 Free Software Foundation, Inc.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   GNU Mailutils is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
-##
-##   You should have received a copy of the GNU General Public License
-##   along with GNU Mailutils; if not, write to the Free Software
-##   Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 cppincludedir=$(pkgincludedir)/cpp
 cppinclude_HEADERS = \
diff --git a/include/mailutils/cpp/address.h b/include/mailutils/cpp/address.h
index 71e7913..f752f07 100644
--- a/include/mailutils/cpp/address.h
+++ b/include/mailutils/cpp/address.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_ADDRESS_H
 #define _MUCPP_ADDRESS_H
diff --git a/include/mailutils/cpp/attribute.h 
b/include/mailutils/cpp/attribute.h
index 64135d2..a205bad 100644
--- a/include/mailutils/cpp/attribute.h
+++ b/include/mailutils/cpp/attribute.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_ATTRIBUTE_H
 #define _MUCPP_ATTRIBUTE_H
diff --git a/include/mailutils/cpp/body.h b/include/mailutils/cpp/body.h
index 06e99ef..7115779 100644
--- a/include/mailutils/cpp/body.h
+++ b/include/mailutils/cpp/body.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_BODY_H
 #define _MUCPP_BODY_H
diff --git a/include/mailutils/cpp/debug.h b/include/mailutils/cpp/debug.h
index 68e7488..15db126 100644
--- a/include/mailutils/cpp/debug.h
+++ b/include/mailutils/cpp/debug.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_DEBUG_H
 #define _MUCPP_DEBUG_H
diff --git a/include/mailutils/cpp/envelope.h b/include/mailutils/cpp/envelope.h
index df33c92..9af1d72 100644
--- a/include/mailutils/cpp/envelope.h
+++ b/include/mailutils/cpp/envelope.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_ENVELOPE_H
 #define _MUCPP_ENVELOPE_H
diff --git a/include/mailutils/cpp/error.h b/include/mailutils/cpp/error.h
index 1806188..eec5362 100644
--- a/include/mailutils/cpp/error.h
+++ b/include/mailutils/cpp/error.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_ERROR_H
 #define _MUCPP_ERROR_H
diff --git a/include/mailutils/cpp/filter.h b/include/mailutils/cpp/filter.h
index 08d75d4..ea8283d 100644
--- a/include/mailutils/cpp/filter.h
+++ b/include/mailutils/cpp/filter.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_FILTER_H
 #define _MUCPP_FILTER_H
diff --git a/include/mailutils/cpp/folder.h b/include/mailutils/cpp/folder.h
index f80b6de..ea004ab 100644
--- a/include/mailutils/cpp/folder.h
+++ b/include/mailutils/cpp/folder.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_FOLDER_H
 #define _MUCPP_FOLDER_H
diff --git a/include/mailutils/cpp/header.h b/include/mailutils/cpp/header.h
index a302305..7f17a7c 100644
--- a/include/mailutils/cpp/header.h
+++ b/include/mailutils/cpp/header.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_HEADER_H
 #define _MUCPP_HEADER_H
diff --git a/include/mailutils/cpp/iterator.h b/include/mailutils/cpp/iterator.h
index 9c5dc7d..b03ca1b 100644
--- a/include/mailutils/cpp/iterator.h
+++ b/include/mailutils/cpp/iterator.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_ITERATOR_H
 #define _MUCPP_ITERATOR_H
diff --git a/include/mailutils/cpp/list.h b/include/mailutils/cpp/list.h
index c579b69..504f5a2 100644
--- a/include/mailutils/cpp/list.h
+++ b/include/mailutils/cpp/list.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_LIST_H
 #define _MUCPP_LIST_H
diff --git a/include/mailutils/cpp/mailbox.h b/include/mailutils/cpp/mailbox.h
index 42df080..fe2db9d 100644
--- a/include/mailutils/cpp/mailbox.h
+++ b/include/mailutils/cpp/mailbox.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_MAILBOX_H
 #define _MUCPP_MAILBOX_H
diff --git a/include/mailutils/cpp/mailcap.h b/include/mailutils/cpp/mailcap.h
index 435cbde..05c7379 100644
--- a/include/mailutils/cpp/mailcap.h
+++ b/include/mailutils/cpp/mailcap.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_MAILCAP_H
 #define _MUCPP_MAILCAP_H
diff --git a/include/mailutils/cpp/mailer.h b/include/mailutils/cpp/mailer.h
index 46bb8ef..b4be0f0 100644
--- a/include/mailutils/cpp/mailer.h
+++ b/include/mailutils/cpp/mailer.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_MAILER_H
 #define _MUCPP_MAILER_H
diff --git a/include/mailutils/cpp/mailutils.h 
b/include/mailutils/cpp/mailutils.h
index 9689f6c..d5e820d 100644
--- a/include/mailutils/cpp/mailutils.h
+++ b/include/mailutils/cpp/mailutils.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/cpp/address.h>
 #include <mailutils/cpp/attribute.h>
diff --git a/include/mailutils/cpp/message.h b/include/mailutils/cpp/message.h
index bdd50af..cd408d4 100644
--- a/include/mailutils/cpp/message.h
+++ b/include/mailutils/cpp/message.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_MESSAGE_H
 #define _MUCPP_MESSAGE_H
diff --git a/include/mailutils/cpp/mime.h b/include/mailutils/cpp/mime.h
index 1ced7b4..b3afcda 100644
--- a/include/mailutils/cpp/mime.h
+++ b/include/mailutils/cpp/mime.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_MIME_H
 #define _MUCPP_MIME_H
diff --git a/include/mailutils/cpp/mutil.h b/include/mailutils/cpp/mutil.h
index 6222442..c64d9a7 100644
--- a/include/mailutils/cpp/mutil.h
+++ b/include/mailutils/cpp/mutil.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_MUTIL_H
 #define _MUCPP_MUTIL_H
diff --git a/include/mailutils/cpp/pop3.h b/include/mailutils/cpp/pop3.h
index bd288e5..bff72cd 100644
--- a/include/mailutils/cpp/pop3.h
+++ b/include/mailutils/cpp/pop3.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_POP3_H
 #define _MUCPP_POP3_H
diff --git a/include/mailutils/cpp/registrar.h 
b/include/mailutils/cpp/registrar.h
index ba9de52..e6e639d 100644
--- a/include/mailutils/cpp/registrar.h
+++ b/include/mailutils/cpp/registrar.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_REGISTRAR_H
 #define _MUCPP_REGISTRAR_H
diff --git a/include/mailutils/cpp/secret.h b/include/mailutils/cpp/secret.h
index ab4ea50..20afdfb 100644
--- a/include/mailutils/cpp/secret.h
+++ b/include/mailutils/cpp/secret.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_SECRET_H
 #define _MUCPP_SECRET_H
diff --git a/include/mailutils/cpp/sieve.h b/include/mailutils/cpp/sieve.h
index c7b1ae1..c1814b8 100644
--- a/include/mailutils/cpp/sieve.h
+++ b/include/mailutils/cpp/sieve.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_SIEVE_H
 #define _MUCPP_SIEVE_H
diff --git a/include/mailutils/cpp/stream.h b/include/mailutils/cpp/stream.h
index 5b67b58..5f53e7b 100644
--- a/include/mailutils/cpp/stream.h
+++ b/include/mailutils/cpp/stream.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_STREAM_H
 #define _MUCPP_STREAM_H
diff --git a/include/mailutils/cpp/url.h b/include/mailutils/cpp/url.h
index 7f218e4..dd7d065 100644
--- a/include/mailutils/cpp/url.h
+++ b/include/mailutils/cpp/url.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010 Free Software
    Foundation, Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MUCPP_URL_H
 #define _MUCPP_URL_H
diff --git a/include/mailutils/daemon.h b/include/mailutils/daemon.h
index 49c43c5..2aca128 100644
--- a/include/mailutils/daemon.h
+++ b/include/mailutils/daemon.h
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_DAEMON_H
 #define _MAILUTILS_DAEMON_H
diff --git a/include/mailutils/debug.hm4 b/include/mailutils/debug.hm4
index 7682d25..097fb2f 100644
--- a/include/mailutils/debug.hm4
+++ b/include/mailutils/debug.hm4
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_DEBUG_H
 #define _MAILUTILS_DEBUG_H
diff --git a/include/mailutils/diag.h b/include/mailutils/diag.h
index 3f3695c..1c0b595 100644
--- a/include/mailutils/diag.h
+++ b/include/mailutils/diag.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_DIAG_H
 #define _MAILUTILS_DIAG_H
diff --git a/include/mailutils/envelope.h b/include/mailutils/envelope.h
index 7d0f439..3c17de8 100644
--- a/include/mailutils/envelope.h
+++ b/include/mailutils/envelope.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_ENVELOPE_H
 # define _MAILUTILS_ENVELOPE_H
diff --git a/include/mailutils/errno.hin b/include/mailutils/errno.hin
index 306f345..81e53e6 100644
--- a/include/mailutils/errno.hin
+++ b/include/mailutils/errno.hin
@@ -14,9 +14,8 @@
    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, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301  USA  */
+   License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_ERRNO_H
 #define _MAILUTILS_ERRNO_H     1
diff --git a/include/mailutils/error.h b/include/mailutils/error.h
index 4b3afe3..b3b24b3 100644
--- a/include/mailutils/error.h
+++ b/include/mailutils/error.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_ERROR_H
 #define _MAILUTILS_ERROR_H
diff --git a/include/mailutils/filter.h b/include/mailutils/filter.h
index d9c53ca..3ee19be 100644
--- a/include/mailutils/filter.h
+++ b/include/mailutils/filter.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_FILTER_H
 #define _MAILUTILS_FILTER_H
diff --git a/include/mailutils/folder.h b/include/mailutils/folder.h
index b16dc47..6e5fc7f 100644
--- a/include/mailutils/folder.h
+++ b/include/mailutils/folder.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_FOLDER_H
 # define _MAILUTILS_FOLDER_H
diff --git a/include/mailutils/gocs.h b/include/mailutils/gocs.h
index 80d9cbe..91530b9 100644
--- a/include/mailutils/gocs.h
+++ b/include/mailutils/gocs.h
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_GOCS_H
 #define _MAILUTILS_GOCS_H
diff --git a/include/mailutils/gsasl.h b/include/mailutils/gsasl.h
index be5f2bb..e1948f1 100644
--- a/include/mailutils/gsasl.h
+++ b/include/mailutils/gsasl.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_GSASL_H
 #define _MAILUTILS_GSASL_H
diff --git a/include/mailutils/guile.h b/include/mailutils/guile.h
index 1db5b8a..2628e11 100644
--- a/include/mailutils/guile.h
+++ b/include/mailutils/guile.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MU_SCM_H
 #define _MU_SCM_H
diff --git a/include/mailutils/header.h b/include/mailutils/header.h
index 57a1107..fe617fb 100644
--- a/include/mailutils/header.h
+++ b/include/mailutils/header.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_HEADER_H
 #define _MAILUTILS_HEADER_H
diff --git a/include/mailutils/io.h b/include/mailutils/io.h
index 6dff003..e9c862d 100644
--- a/include/mailutils/io.h
+++ b/include/mailutils/io.h
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_IO_H
 #define _MAILUTILS_IO_H
diff --git a/include/mailutils/iterator.h b/include/mailutils/iterator.h
index 815b605..d67c063 100644
--- a/include/mailutils/iterator.h
+++ b/include/mailutils/iterator.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_ITERATOR_H
 #define _MAILUTILS_ITERATOR_H
diff --git a/include/mailutils/ldap.h b/include/mailutils/ldap.h
index cd167cf..66a8620 100644
--- a/include/mailutils/ldap.h
+++ b/include/mailutils/ldap.h
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_LDAP_H
 #define _MAILUTILS_LDAP_H
diff --git a/include/mailutils/libargp.h b/include/mailutils/libargp.h
index c0317be..586d74a 100644
--- a/include/mailutils/libargp.h
+++ b/include/mailutils/libargp.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_LIBARGP_H
 #define _MAILUTILS_LIBARGP_H
diff --git a/include/mailutils/libcfg.h b/include/mailutils/libcfg.h
index d8600ed..5333b0d 100644
--- a/include/mailutils/libcfg.h
+++ b/include/mailutils/libcfg.h
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_LIBCFG_H
 #define _MAILUTILS_LIBCFG_H
diff --git a/include/mailutils/list.h b/include/mailutils/list.h
index d8d1c91..fdf7615 100644
--- a/include/mailutils/list.h
+++ b/include/mailutils/list.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_LIST_H
 #define _MAILUTILS_LIST_H
diff --git a/include/mailutils/locker.h b/include/mailutils/locker.h
index da9b3b1..0147944 100644
--- a/include/mailutils/locker.h
+++ b/include/mailutils/locker.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_LOCKER_H
 #define _MAILUTILS_LOCKER_H
diff --git a/include/mailutils/mailbox.h b/include/mailutils/mailbox.h
index 74d3407..298e6e8 100644
--- a/include/mailutils/mailbox.h
+++ b/include/mailutils/mailbox.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_MAILBOX_H
 #define _MAILUTILS_MAILBOX_H
diff --git a/include/mailutils/mailcap.h b/include/mailutils/mailcap.h
index b6998d1..ed00296 100644
--- a/include/mailutils/mailcap.h
+++ b/include/mailutils/mailcap.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_MAILCAP_H
 #define _MAILUTILS_MAILCAP_H
diff --git a/include/mailutils/mailer.h b/include/mailutils/mailer.h
index 5463d30..f42f0eb 100644
--- a/include/mailutils/mailer.h
+++ b/include/mailutils/mailer.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_MAILER_H
 #define _MAILUTILS_MAILER_H
diff --git a/include/mailutils/md5.h b/include/mailutils/md5.h
index d6933e4..3471683 100644
--- a/include/mailutils/md5.h
+++ b/include/mailutils/md5.h
@@ -15,8 +15,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_MD5_H
 #define _MAILUTILS_MD5_H 1
diff --git a/include/mailutils/message.h b/include/mailutils/message.h
index 14df6f6..09c7c9e 100644
--- a/include/mailutils/message.h
+++ b/include/mailutils/message.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_MESSAGE_H
 #define _MAILUTILS_MESSAGE_H
diff --git a/include/mailutils/mime.h b/include/mailutils/mime.h
index cd70682..fa82ed3 100644
--- a/include/mailutils/mime.h
+++ b/include/mailutils/mime.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_MIME_H
 #define _MAILUTILS_MIME_H
diff --git a/include/mailutils/monitor.h b/include/mailutils/monitor.h
index 4e170da..0ba6881 100644
--- a/include/mailutils/monitor.h
+++ b/include/mailutils/monitor.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_MONITOR_H
 #define _MAILUTILS_MONITOR_H
diff --git a/include/mailutils/mu_auth.h b/include/mailutils/mu_auth.h
index 7453d30..978ad93 100644
--- a/include/mailutils/mu_auth.h
+++ b/include/mailutils/mu_auth.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_MU_AUTH_H
 #define _MAILUTILS_MU_AUTH_H
diff --git a/include/mailutils/mutil.h b/include/mailutils/mutil.h
index 86d2243..1953971 100644
--- a/include/mailutils/mutil.h
+++ b/include/mailutils/mutil.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_MUTIL_H
 #define _MAILUTILS_MUTIL_H
diff --git a/include/mailutils/nls.h b/include/mailutils/nls.h
index c84a772..9617d0b 100644
--- a/include/mailutils/nls.h
+++ b/include/mailutils/nls.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_NLS_H
 #define _MAILUTILS_NLS_H
diff --git a/include/mailutils/nntp.h b/include/mailutils/nntp.h
index d16fb54..d509877 100644
--- a/include/mailutils/nntp.h
+++ b/include/mailutils/nntp.h
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_NNTP_H
 #define _MAILUTILS_NNTP_H
diff --git a/include/mailutils/observer.h b/include/mailutils/observer.h
index ffb9ea5..f4d6dc9 100644
--- a/include/mailutils/observer.h
+++ b/include/mailutils/observer.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_OBSERVER_H
 #define _MAILUTILS_OBSERVER_H
diff --git a/include/mailutils/opool.h b/include/mailutils/opool.h
index 49b1b02..f8b56e6 100644
--- a/include/mailutils/opool.h
+++ b/include/mailutils/opool.h
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_OPOOL_H
 #define _MAILUTILS_OPOOL_H
diff --git a/include/mailutils/pam.h b/include/mailutils/pam.h
index 207bb23..40dca1d 100644
--- a/include/mailutils/pam.h
+++ b/include/mailutils/pam.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_PAM_H
 #define _MAILUTILS_PAM_H
diff --git a/include/mailutils/parse822.h b/include/mailutils/parse822.h
index 2105539..b212d18 100644
--- a/include/mailutils/parse822.h
+++ b/include/mailutils/parse822.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 /**
 * Parses syntatic elements defined in RFC 822.
diff --git a/include/mailutils/pop3.h b/include/mailutils/pop3.h
index 53d6c16..ebea5d8 100644
--- a/include/mailutils/pop3.h
+++ b/include/mailutils/pop3.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_POP3_H
 #define _MAILUTILS_POP3_H
diff --git a/include/mailutils/progmailer.h b/include/mailutils/progmailer.h
index e9a82c3..47c1280 100644
--- a/include/mailutils/progmailer.h
+++ b/include/mailutils/progmailer.h
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_PROGMAILER_H
 #define _MAILUTILS_PROGMAILER_H
diff --git a/include/mailutils/property.h b/include/mailutils/property.h
index e57bba4..1fb7334 100644
--- a/include/mailutils/property.h
+++ b/include/mailutils/property.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */; 
 
 #ifndef _MAILUTILS_PROPERTY_H
 #define _MAILUTILS_PROPERTY_H
diff --git a/include/mailutils/python.h b/include/mailutils/python.h
index 9bd32dd..81348fb 100644
--- a/include/mailutils/python.h
+++ b/include/mailutils/python.h
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_PYTHON_H
 #define _MAILUTILS_PYTHON_H
diff --git a/include/mailutils/radius.h b/include/mailutils/radius.h
index a62cddc..1ce4c24 100644
--- a/include/mailutils/radius.h
+++ b/include/mailutils/radius.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_RADIUS_H
 #define _MAILUTILS_RADIUS_H
diff --git a/include/mailutils/refcount.h b/include/mailutils/refcount.h
index 2c8d287..40f4c9a 100644
--- a/include/mailutils/refcount.h
+++ b/include/mailutils/refcount.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_REFCOUNT_H
 #define _MAILUTILS_REFCOUNT_H
diff --git a/include/mailutils/registrar.h b/include/mailutils/registrar.h
index 91a3acf..2042966 100644
--- a/include/mailutils/registrar.h
+++ b/include/mailutils/registrar.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_REGISTRAR_H
 #define _MAILUTILS_REGISTRAR_H
diff --git a/include/mailutils/secret.h b/include/mailutils/secret.h
index a97c968..6cb5c33 100644
--- a/include/mailutils/secret.h
+++ b/include/mailutils/secret.h
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SECRET_H
 #define _MAILUTILS_SECRET_H
diff --git a/include/mailutils/sha1.h b/include/mailutils/sha1.h
index fecb294..c4624af 100644
--- a/include/mailutils/sha1.h
+++ b/include/mailutils/sha1.h
@@ -14,8 +14,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SHA1_H
 # define _MAILUTILS_SHA1_H 1
diff --git a/include/mailutils/sieve.h b/include/mailutils/sieve.h
index f89d409..7f17f57 100644
--- a/include/mailutils/sieve.h
+++ b/include/mailutils/sieve.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_LIBSIEVE_H
 #define _MAILUTILS_LIBSIEVE_H
diff --git a/include/mailutils/sql.h b/include/mailutils/sql.h
index 84672a2..8c9d975 100644
--- a/include/mailutils/sql.h
+++ b/include/mailutils/sql.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SQL_H
 #define _MAILUTILS_SQL_H
diff --git a/include/mailutils/sys/Makefile.am 
b/include/mailutils/sys/Makefile.am
index 74a732c..90610cd 100644
--- a/include/mailutils/sys/Makefile.am
+++ b/include/mailutils/sys/Makefile.am
@@ -1,21 +1,18 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2002, 2007, 2009, 2010 Free Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2002, 2007, 2009, 2010 Free Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 sysincludedir=$(pkgincludedir)/sys
 sysinclude_HEADERS = \
diff --git a/include/mailutils/sys/amd.h b/include/mailutils/sys/amd.h
index 52f0395..2f921a3 100644
--- a/include/mailutils/sys/amd.h
+++ b/include/mailutils/sys/amd.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYS_AMD_H
 # define _MAILUTILS_SYS_AMD_H
diff --git a/include/mailutils/sys/attribute.h 
b/include/mailutils/sys/attribute.h
index 83e1f11..9a244c9 100644
--- a/include/mailutils/sys/attribute.h
+++ b/include/mailutils/sys/attribute.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYS_ATTRIBUTE_H
 # define _MAILUTILS_SYS_ATTRIBUTE_H
diff --git a/include/mailutils/sys/auth.h b/include/mailutils/sys/auth.h
index 0a4308d..e24c364 100644
--- a/include/mailutils/sys/auth.h
+++ b/include/mailutils/sys/auth.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYS_AUTH_H
 # define _MAILUTILS_SYS_AUTH_H
diff --git a/include/mailutils/sys/body.h b/include/mailutils/sys/body.h
index 7ec58e3..a7be7eb 100644
--- a/include/mailutils/sys/body.h
+++ b/include/mailutils/sys/body.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYS_BODY_H
 # define _MAILUTILS_SYS_BODY_H
diff --git a/include/mailutils/sys/debug.h b/include/mailutils/sys/debug.h
index 30ac959..ee26e16 100644
--- a/include/mailutils/sys/debug.h
+++ b/include/mailutils/sys/debug.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYS_DEBUG_H
 # define _MAILUTILS_SYS_DEBUG_H
diff --git a/include/mailutils/sys/envelope.h b/include/mailutils/sys/envelope.h
index fe4689a..037524f 100644
--- a/include/mailutils/sys/envelope.h
+++ b/include/mailutils/sys/envelope.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYS_ENVELOPE_H
 # define _MAILUTILS_SYS_ENVELOPE_H
diff --git a/include/mailutils/sys/filter.h b/include/mailutils/sys/filter.h
index ceceb78..5eb91f5 100644
--- a/include/mailutils/sys/filter.h
+++ b/include/mailutils/sys/filter.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYS_FILTER_H
 #define _MAILUTILS_SYS_FILTER_H
diff --git a/include/mailutils/sys/folder.h b/include/mailutils/sys/folder.h
index 912fb87..53b909d 100644
--- a/include/mailutils/sys/folder.h
+++ b/include/mailutils/sys/folder.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYS_FOLDER_H
 # define _MAILUTILS_SYS_FOLDER_H
diff --git a/include/mailutils/sys/header.h b/include/mailutils/sys/header.h
index 1898509..ac4be3c 100644
--- a/include/mailutils/sys/header.h
+++ b/include/mailutils/sys/header.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _HEADER0_H
 #define _HEADER0_H
diff --git a/include/mailutils/sys/imap.h b/include/mailutils/sys/imap.h
index bbad6e5..6bb154d 100644
--- a/include/mailutils/sys/imap.h
+++ b/include/mailutils/sys/imap.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYS_IMAP_H
 # define _MAILUTILS_SYS_IMAP_H
diff --git a/include/mailutils/sys/iterator.h b/include/mailutils/sys/iterator.h
index 5b5475f..2eaf4d5 100644
--- a/include/mailutils/sys/iterator.h
+++ b/include/mailutils/sys/iterator.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYS_ITERATOR_H
 # define _MAILUTILS_SYS_ITERATOR_H
diff --git a/include/mailutils/sys/list.h b/include/mailutils/sys/list.h
index 2e9f83a..abe5b70 100644
--- a/include/mailutils/sys/list.h
+++ b/include/mailutils/sys/list.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYS_LIST_H
 # define _MAILUTILS_SYS_LIST_H
diff --git a/include/mailutils/sys/mailbox.h b/include/mailutils/sys/mailbox.h
index fe36269..0b57fe0 100644
--- a/include/mailutils/sys/mailbox.h
+++ b/include/mailutils/sys/mailbox.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYS_MAILBOX_H
 # define _MAILUTILS_SYS_MAILBOX_H
diff --git a/include/mailutils/sys/mailer.h b/include/mailutils/sys/mailer.h
index b9413a3..4bd2381 100644
--- a/include/mailutils/sys/mailer.h
+++ b/include/mailutils/sys/mailer.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYS_MAILER_H
 # define _MAILUTILS_SYS_MAILER_H
diff --git a/include/mailutils/sys/message.h b/include/mailutils/sys/message.h
index 5e96d85..53f3672 100644
--- a/include/mailutils/sys/message.h
+++ b/include/mailutils/sys/message.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MESSAGE0_H
 #define _MESSAGE0_H
diff --git a/include/mailutils/sys/mime.h b/include/mailutils/sys/mime.h
index ce30042..e99766e 100644
--- a/include/mailutils/sys/mime.h
+++ b/include/mailutils/sys/mime.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYS_MIME_H
 #define _MAILUTILS_SYS_MIME_H
diff --git a/include/mailutils/sys/monitor.h b/include/mailutils/sys/monitor.h
index 2d76265..122eb81 100644
--- a/include/mailutils/sys/monitor.h
+++ b/include/mailutils/sys/monitor.h
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYS_MONITOR_H
 # define _MAILUTILS_SYS_MONITOR_H
diff --git a/include/mailutils/sys/nntp.h b/include/mailutils/sys/nntp.h
index 5b28ad5..8d0dbc8 100644
--- a/include/mailutils/sys/nntp.h
+++ b/include/mailutils/sys/nntp.h
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYS_NNTP_H
 #define _MAILUTILS_SYS_NNTP_H
diff --git a/include/mailutils/sys/observer.h b/include/mailutils/sys/observer.h
index 7aede1c..6cccd9c 100644
--- a/include/mailutils/sys/observer.h
+++ b/include/mailutils/sys/observer.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYS_OBSERVER_H
 # define _MAILUTILS_SYS_OBSERVER_H
diff --git a/include/mailutils/sys/pop3.h b/include/mailutils/sys/pop3.h
index 6d4b588..96d8d61 100644
--- a/include/mailutils/sys/pop3.h
+++ b/include/mailutils/sys/pop3.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYS_POP3_H
 #define _MAILUTILS_SYS_POP3_H
diff --git a/include/mailutils/sys/property.h b/include/mailutils/sys/property.h
index 4faac9c..cbc090f 100644
--- a/include/mailutils/sys/property.h
+++ b/include/mailutils/sys/property.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYS_PROPERTY_H
 # define _MAILUTILS_SYS_PROPERTY_H
diff --git a/include/mailutils/sys/registrar.h 
b/include/mailutils/sys/registrar.h
index 8b3d83d..535e5ce 100644
--- a/include/mailutils/sys/registrar.h
+++ b/include/mailutils/sys/registrar.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYS_REGISTRAR_H
 # define _MAILUTILS_SYS_REGISTRAR_H
diff --git a/include/mailutils/sys/url.h b/include/mailutils/sys/url.h
index 8e300ba..095a111 100644
--- a/include/mailutils/sys/url.h
+++ b/include/mailutils/sys/url.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYS_URL_H
 # define _MAILUTILS_SYS_URL_H
diff --git a/include/mailutils/syslog.h b/include/mailutils/syslog.h
index 34554f9..3abeea8 100644
--- a/include/mailutils/syslog.h
+++ b/include/mailutils/syslog.h
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYSLOG_H
 #define _MAILUTILS_SYSLOG_H
diff --git a/include/mailutils/tls.h b/include/mailutils/tls.h
index dc630a2..bedd9fd 100644
--- a/include/mailutils/tls.h
+++ b/include/mailutils/tls.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_TLS_H
 #define _MAILUTILS_TLS_H
diff --git a/include/mailutils/types.hin b/include/mailutils/types.hin
index 5917c7f..a3f3ca6 100644
--- a/include/mailutils/types.hin
+++ b/include/mailutils/types.hin
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_TYPES_H
 #define _MAILUTILS_TYPES_H
diff --git a/include/mailutils/url.h b/include/mailutils/url.h
index ca0dcb3..1531d0d 100644
--- a/include/mailutils/url.h
+++ b/include/mailutils/url.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_URL_H
 #define _MAILUTILS_URL_H       1
diff --git a/include/mailutils/version.h b/include/mailutils/version.h
index 60468c1..566d735 100644
--- a/include/mailutils/version.h
+++ b/include/mailutils/version.h
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_VERSION_H
 #define _MAILUTILS_VERSION_H
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 4f7ad17..1e584d8 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 1999, 2000, 2001, 2002, 2005, 2007, 2008, 2009, 2010
-##   Free Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 1999, 2000, 2001, 2002, 2005, 2007, 2008, 2009, 2010
+## Free Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 include gnulib.mk
 
diff --git a/lib/mailcap.c b/lib/mailcap.c
index 4a05484..fd1c40a 100644
--- a/lib/mailcap.c
+++ b/lib/mailcap.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/lib/mu_asprintf.h b/lib/mu_asprintf.h
index 9a70cec..0f893e9 100644
--- a/lib/mu_asprintf.h
+++ b/lib/mu_asprintf.h
@@ -1,5 +1,4 @@
-/*
-   Copyright (C) 2007, 2010 Free Software Foundation, Inc.
+/* Copyright (C) 2007, 2010 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU Library General Public License as published by
@@ -12,9 +11,8 @@
    GNU Library General Public License for more details.
 
    You should have received a copy of the GNU Library General
-   Public License along with GNU Mailutils; if not, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with GNU Mailutils.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef MUASPRINTF_H
 #define MUASPRINTF_H
diff --git a/lib/mu_dbm.c b/lib/mu_dbm.c
index f18cda8..7638b4d 100644
--- a/lib/mu_dbm.c
+++ b/lib/mu_dbm.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/lib/mu_dbm.h b/lib/mu_dbm.h
index 45b868c..bec1756 100644
--- a/lib/mu_dbm.h
+++ b/lib/mu_dbm.h
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #if defined(WITH_GDBM)
 
diff --git a/lib/mu_umaxtostr.c b/lib/mu_umaxtostr.c
index c3e9e91..8d86c3f 100644
--- a/lib/mu_umaxtostr.c
+++ b/lib/mu_umaxtostr.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #if HAVE_CONFIG_H
 # include <config.h>
diff --git a/lib/muaux.h b/lib/muaux.h
index 4e27a55..efd037a 100644
--- a/lib/muaux.h
+++ b/lib/muaux.h
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 int mu_switch_to_privs (uid_t uid, gid_t gid, mu_list_t retain_groups);
 void mu_set_signals (RETSIGTYPE (*handler) (int signo), int *sigv, int sigc);
diff --git a/lib/signal.c b/lib/signal.c
index 8ce2108..bd92e1c 100644
--- a/lib/signal.c
+++ b/lib/signal.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/lib/strexit.c b/lib/strexit.c
index 7f1d01c..d3021b9 100644
--- a/lib/strexit.c
+++ b/lib/strexit.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/lib/tcpwrap.c b/lib/tcpwrap.c
index 21e6310..001fc9c 100644
--- a/lib/tcpwrap.c
+++ b/lib/tcpwrap.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/lib/tcpwrap.h b/lib/tcpwrap.h
index af2d188..9ac0337 100644
--- a/lib/tcpwrap.h
+++ b/lib/tcpwrap.h
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/types.h>
 
diff --git a/lib/userprivs.c b/lib/userprivs.c
index 0a51dd9..2185777 100644
--- a/lib/userprivs.c
+++ b/lib/userprivs.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/lib/utmp.c b/lib/utmp.c
index a9e00be..f6fb96b 100644
--- a/lib/utmp.c
+++ b/lib/utmp.c
@@ -12,10 +12,8 @@ WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 General Public License for more details.
 
-You should have received a copy of the GNU General Public
-Licensealong with this program; if not, write to the Free
-SoftwareFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-MA 02110-1301 USA. */
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmailutils/.gitignore b/libmailutils/.gitignore
index 8ce64ea..048e16e 100644
--- a/libmailutils/.gitignore
+++ b/libmailutils/.gitignore
@@ -4,13 +4,5 @@
 .libs
 Makefile
 Makefile.in
-T
-_*
 .gdbinit
-mailutils-config
-parsedate.c
 *y.output
-muerrno.c
-cfg_lexer.c
-cfg_parser.c
-cfg_parser.h
diff --git a/libmailutils/Makefile.am b/libmailutils/Makefile.am
index 07a0a4e..f13085f 100644
--- a/libmailutils/Makefile.am
+++ b/libmailutils/Makefile.am
@@ -1,188 +1,42 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009,
-##   2010 Free Software Foundation, Inc.
-##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
-##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
-##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
-
-INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I${top_srcdir}/libmailutils
-
-YLWRAP = $(SHELL) $(mu_aux_dir)/gylwrap
-AM_YFLAGS=-vt
-AM_LFLAGS=-dvp
-
-SUBDIRS = . tests 
+# GNU Mailutils -- a suite of utilities for electronic mail
+# Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 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/>.
+
+SUBDIRS = auth base address cfg diag filter mailbox mailer mime\
+ server string stream . tests 
 
 lib_LTLIBRARIES = libmailutils.la
 
-localedir = $(datadir)/locale
-AM_CPPFLAGS = \
- -DSYSCONFDIR=\"$(sysconfdir)\"\
- -DSITE_VIRTUAL_PWDDIR=\"@address@hidden"\
- -DLOCALEDIR=\"$(localedir)\"
-
-EXTRA_DIST = \
- errors\
- muerrno.cin\
- parsedate.y\
- fgetpwent.c\
- cfg_lexer.l\
- cfg_parser.y\
- cfg_parser.h
-
-libmailutils_la_SOURCES = \
- acl.c\
- address.c\
- alloc.c\
- amd.c\
- argcv.c\
- asnprintf.c\
- asprintf.c\
- assoc.c\
- attachment.c\
- attribute.c\
- auth.c\
- base64.c\
- binflt.c\
- body.c\
- cstrcasecmp.c\
- cfg_driver.c\
- cfg_format.c\
- cfg_lexer.c\
- cfg_parser.c\
- crlfdot.c\
- crlfflt.c\
- cstrlower.c\
- cstrupper.c\
- daemon.c\
- date.c\
- dbgstderr.c\
- dbgstream.c\
- dbgsyslog.c\
- debug.c\
- diag.c\
- dot.c\
- envelope.c\
- fgetpwent.c\
- file_stream.c\
- filter.c\
- filter_iconv.c\
- fltstream.c\
- folder.c\
- freeitem.c\
- fromflt.c\
- gdebug.c\
- getpass.c\
- gocs.c\
- hdritr.c\
- header.c\
- iostream.c\
- iterator.c\
- ipsrv.c\
- kwd.c\
- linelenflt.c\
- list.c\
- listlist.c\
- locale.c\
- locker.c\
- mailbox.c\
- mailcap.c\
- mailer.c\
- mapfile_stream.c\
- mbx_default.c\
- mbxitr.c\
- md5.c\
- message.c\
- memory_stream.c\
- message_stream.c\
- mime.c\
- mimehdr.c\
- mkfilename.c\
- monitor.c\
- msgscan.c\
- msrv.c\
- mu_auth.c\
- muctype.c\
- munre.c\
- mutil.c\
- muerror.c\
- muerrno.c\
- nls.c\
- nullrec.c\
- observer.c\
- opool.c\
- parse822.c\
- parsedate.c\
- permstr.c\
- progmailer.c\
- prog_stream.c\
- property.c\
- qpflt.c\
- rdcache_stream.c\
- registrar.c\
- refcount.c\
- rfc2047.c\
- sha1.c\
- secret.c\
- server.c\
- socket_stream.c\
- stdio_stream.c\
- stream.c\
- stream_printf.c\
- stream_vprintf.c\
- streamcpy.c\
- streamref.c\
- strltrim.c\
- strskip.c\
- stripws.c\
- strrtrim.c\
- syslog.c\
- system.c\
- temp_file_stream.c\
- ticket.c\
- tcp.c\
- url.c\
- vartab.c\
- vasnprintf.c\
- version.c\
- wicket.c\
- xscript-stream.c
- 
-BUILT_SOURCES = parsedate.c muerrno.c cfg_parser.c cfg_parser.h cfg_lexer.c
-MOSTLYCLEANFILES=
-
-parsedate.c: $(srcdir)/parsedate.y
-       $(YLWRAP) "$(YACC) $(AM_YFLAGS)" $< \
-                 y.tab.c parsedate.c y.output parsedate.y.output \
-                  -- -yy pd_yy
-
-cfg_parser.c cfg_parser.h: $(srcdir)/cfg_parser.y
-       $(YLWRAP) "$(YACC) $(AM_YFLAGS) -d" $< \
-                 y.tab.c cfg_parser.c y.tab.h cfg_parser.h \
-                  y.output cfg_parser.y.output \
-                  -- -yy mu_cfg_yy
-
-cfg_lexer.c: $(srcdir)/cfg_lexer.l cfg_parser.h
-       $(YLWRAP) "$(LEX) $(AM_LFLAGS) $(LFLAGS)" \
-                  $(srcdir)/cfg_lexer.l lex.yy.c cfg_lexer.c \
-                  -- -yy mu_cfg_yy
-
-muerrno.c: errors muerrno.cin
-       $(AWK) -f $(mu_aux_dir)/generr.awk $^ > $@
+libmailutils_la_SOURCES =  
+
+libmailutils_la_LIBADD = \
+ @address@hidden
+ auth/libauth.la\
+ base/libbase.la\
+ address/libaddress.la\
+ cfg/libcfg.la\
+ diag/libdiag.la\
+ filter/libfilter.la\
+ mailbox/libmailbox.la\
+ mailer/libmailer.la\
+ mime/libmime.la\
+ server/libserver.la\
+ string/libstring.la\
+ stream/libstream.la
 
-libmailutils_la_LIBADD = @MU_COMMON_LIBRARIES@
 libmailutils_la_LDFLAGS = -version-info @VI_CURRENT@:@VI_REVISION@:@VI_AGE@
 
diff --git a/libmailutils/address.c b/libmailutils/address.c
deleted file mode 100644
index cd151c1..0000000
--- a/libmailutils/address.c
+++ /dev/null
@@ -1,595 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <string.h>
-
-#include <sys/types.h>
-
-#include <mailutils/errno.h>
-#include <mailutils/mutil.h>
-#include <mailutils/parse822.h>
-#include <mailutils/address.h>
-#include <mailutils/cstr.h>
-
-/* Get email addresses from rfc822 address.  */
-int
-mu_address_create_hint (mu_address_t *a, const char *s, mu_address_t hint,
-                       int hflags)
-{
-  /* 'a' must exist, and can't already have been initialized
-   */
-  int status;
-
-  if (!a)
-    return MU_ERR_OUT_PTR_NULL;
-
-  if (!s)
-    return EINVAL;
-
-  *a = NULL;
-  status = mu_parse822_address_list (a, s, hint, hflags);
-  if (status == 0)
-    {
-      /* And address-list may contain 0 addresses but parse correctly.
-       */
-      if (!*a)
-       return MU_ERR_EMPTY_ADDRESS;
-
-      (*a)->addr = strdup (s);
-      if (!(*a)->addr)
-       {
-         mu_address_destroy (a);
-         return ENOMEM;
-       }
-    }
-  return status;
-}
-
-int
-mu_address_create (mu_address_t *a, const char *s)
-{
-  struct mu_address hint;
-  const char *d;
-  mu_get_user_email_domain (&d);
-  hint.domain = (char*) d;
-  return mu_address_create_hint (a, s, &hint, MU_ADDR_HINT_DOMAIN);
-}
-
-/* Get email addresses from array of rfc822 addresses.
-   FIXME: No hints? */
-int
-mu_address_createv (mu_address_t *a, const char *sv[], size_t len)
-{
-  int status = 0;
-  size_t buflen = 0;
-  char *buf = 0;
-  size_t i;
-
-  if (!a)
-    return MU_ERR_OUT_PTR_NULL;
-
-  if (!sv)
-    return EINVAL;
-
-  if (len == (size_t) - 1)
-    {
-      const char **vp = sv;
-
-      len = 0;
-
-      for (len = 0; *vp; vp++, len++)
-       ;
-    }
-
-  if (len == 0)
-    return EINVAL;
-
-  for (i = 0; i < len; i++)
-    {
-      /* NULL strings are allowed */
-      if (sv[i])
-       buflen += strlen (sv[i]);
-    }
-
-  buflen += (len - 1) * strlen (", ");
-  buflen += 1;                 /* Termination null.  */
-
-  buf = malloc (buflen);
-
-  if (!buf)
-    return ENOMEM;
-
-  for (i = 0, buf[0] = '\0'; i < len; i++)
-    {
-      if (i != 0)
-       strcat (buf, ", ");
-
-      if (sv[i])
-       strcat (buf, sv[i]);
-    }
-
-  status = mu_address_create (a, buf);
-
-  free (buf);
-
-  return status;
-}
-
-void
-mu_address_destroy (mu_address_t *paddress)
-{
-  if (paddress && *paddress)
-    {
-      mu_address_t address = *paddress;
-      mu_address_t current;
-      for (; address; address = current)
-       {
-         if (address->addr)
-           free (address->addr);
-         if (address->comments)
-           free (address->comments);
-         if (address->personal)
-           free (address->personal);
-         if (address->email)
-           free (address->email);
-         if (address->local_part)
-           free (address->local_part);
-         if (address->domain)
-           free (address->domain);
-         if (address->route)
-           free (address->route);
-         current = address->next;
-         free (address);
-       }
-      *paddress = NULL;
-    }
-}
-
-int
-mu_address_concatenate (mu_address_t to, mu_address_t *from)
-{
-  if (!to || !from || !*from)
-    return EINVAL;
-
-  while (to->next)
-    to = to->next;
-
-  assert (to && !to->next);
-
-  to->next = *from;
-  *from = NULL;
-
-  /* discard the current string cache as it is now inaccurate */
-  if (to->addr)
-    {
-      free (to->addr);
-      to->addr = NULL;
-    }
-
-  to = to->next;
-
-  /* only the first address must have a cache */
-  if (to->addr)
-    {
-      free (to->addr);
-      to->addr = NULL;
-    }
-
-  return 0;
-}
-
-mu_address_t 
-_address_get_nth (mu_address_t addr, size_t no)
-{
-  int i;
-  
-  for (i = 1; addr; addr = addr->next, i++)
-    if (i == no)
-      break;
-  return addr;
-}
-
-int
-mu_address_get_nth (mu_address_t addr, size_t no, mu_address_t *pret)
-{
-  mu_address_t subaddr = _address_get_nth (addr, no);
-  if (!subaddr)
-    return MU_ERR_NOENT;
-  *pret = mu_address_dup (subaddr);
-  return 0;
-}
-
-
-/* General accessors: */
-#define AC4(a,b,c,d) a ## b ## c ## d
-#define ACCESSOR(action,field) AC4(mu_address_,action,_,field)
-
-#define DECL_SET(field)                                                        
\
-int                                                                    \
-ACCESSOR(set, field) (mu_address_t addr, size_t no, const char *buf)   \
-{                                                                      \
-  char *s;                                                             \
-  mu_address_t subaddr;                                                        
\
-                                                                       \
-  if (addr == NULL)                                                    \
-    return EINVAL;                                                     \
-                                                                       \
-  subaddr = _address_get_nth (addr, no);                               \
-  if (!subaddr)                                                                
\
-    return MU_ERR_NOENT;                                               \
-                                                                       \
-  s = strdup (buf);                                                    \
-  if (!s)                                                              \
-    return errno;                                                      \
-                                                                       \
-  free (subaddr->field);                                               \
-  subaddr->field = s;                                                  \
-                                                                       \
-  return 0;                                                            \
-}
-
-#define DECL_SGET(field)                                               \
-int                                                                    \
-ACCESSOR(sget,field) (mu_address_t addr, size_t no, char const **sptr) \
-{                                                                      \
-  mu_address_t subaddr;                                                        
\
-                                                                       \
-  if (addr == NULL)                                                    \
-    return EINVAL;                                                     \
-                                                                       \
-  subaddr = _address_get_nth (addr, no);                               \
-  if (!subaddr)                                                                
\
-    return MU_ERR_NOENT;                                               \
-  *sptr = subaddr->field;                                              \
-  return 0;                                                            \
-}
-
-#define DECL_GET(field)                                                        
  \
-int                                                                      \
-ACCESSOR(get,field) (mu_address_t addr, size_t no, char *buf, size_t len, \
-                    size_t *n)                                           \
-{                                                                        \
-  size_t i;                                                              \
-  const char *str;                                                       \
-  int status = ACCESSOR(sget, field) (addr, no, &str);                   \
-                                                                         \
-  if (status)                                                            \
-    return status;                                                       \
-                                                                         \
-  i = mu_cpystr (buf, str, len);                                         \
-  if (n)                                                                 \
-    *n = i;                                                              \
-  return 0;                                                              \
-}
-
-#define DECL_AGET(field)                                               \
-int                                                                    \
-ACCESSOR(aget, field) (mu_address_t addr, size_t no, char **buf)       \
-{                                                                      \
-  const char *str;                                                     \
-  int status = ACCESSOR(sget, field) (addr, no, &str);                 \
-                                                                       \
-  if (status)                                                          \
-    return status;                                                     \
-                                                                       \
-  if (str)                                                             \
-    {                                                                  \
-      *buf = strdup (str);                                             \
-      if (!*buf)                                                       \
-       status = ENOMEM;                                                \
-    }                                                                  \
-  else                                                                 \
-    *buf = NULL;                                                       \
-  return status;                                                       \
-}
-
-#define DECL_ACCESSORS(field)                  \
-DECL_SET(field)                                        \
-DECL_SGET(field)                               \
-DECL_GET(field)                                        \
-DECL_AGET(field)          
-
-
-
-/* Personal part */
-DECL_ACCESSORS(personal)
-/* Comments */
-DECL_ACCESSORS(comments)
-/* Email */
-DECL_ACCESSORS(email)     
-/* Local part */
-DECL_ACCESSORS(local_part)
-/* Domain */
-DECL_ACCESSORS(domain)
-/* Route */
-DECL_ACCESSORS(route)
-
-
-
-#define format_char(c) do {\
- if (buflen) \
-   {\
-      *buf++ = c;\
-      buflen--;\
-   }\
- else\
-   rc++;\
-} while(0) 
-
-#define format_string(str) do {\
- if (buflen) \
-   {\
-      int n = snprintf (buf, buflen, "%s", str);\
-      buf += n;\
-      buflen -= n;\
-   }\
- else\
-   rc += strlen (str);\
-} while (0)
-     
-size_t
-mu_address_format_string (mu_address_t addr, char *buf, size_t buflen)
-{
-  int rc = 0;
-  int comma = 0;
-  
-  for (;addr; addr = addr->next)
-    {
-      if (addr->email)
-       {
-         int space = 0;
-
-         if (comma)
-           format_char (',');
-         
-         if (addr->personal)
-           {
-             format_char ('"');
-             format_string (addr->personal);
-             format_char ('"');
-             space++;
-           }
-         
-         if (addr->comments)
-           {
-             if (space)
-               format_char (' ');
-             format_char ('(');
-             format_string (addr->comments);
-             format_char (')');
-             space++;
-           }
-         
-         if (space)
-           format_char (' ');
-         format_char ('<');
-         format_string (addr->email);
-         format_char ('>');
-         comma++;
-       }
-    }
-  format_char (0);
-  return rc;
-}
-
-static int
-_address_is_group (mu_address_t addr)
-{
-  if (addr->personal && !addr->local_part && !addr->domain)
-    return 1;
-  return 0;
-}
-
-static int
-_address_is_email (mu_address_t addr)
-{
-  if (addr->email)
-    return 1;
-  return 0;
-}
-
-static int
-_address_is_unix_mailbox (mu_address_t addr)
-{
-  if (addr->local_part && !addr->email)
-    return 1;
-  return 0;
-}
-
-int
-mu_address_is_group (mu_address_t addr, size_t no, int *yes)
-{
-  mu_address_t subaddr;
-  
-  if (addr == NULL)
-    return EINVAL;
-
-  subaddr = _address_get_nth (addr, no);
-  if (!subaddr)
-    return MU_ERR_NOENT;
-  
-  if (yes)
-    *yes = _address_is_group (subaddr);
-  return 0;
-}
-
-int
-mu_address_to_string (mu_address_t addr, char *buf, size_t len, size_t *n)
-{
-  size_t i;
-  if (addr == NULL)
-    return EINVAL;
-  if (buf)
-    *buf = '\0';
-
-  if (!addr->addr)
-    {
-      i = mu_address_format_string (addr, NULL, 0);
-      addr->addr = malloc (i + 1);
-      if (!addr->addr)
-       return ENOMEM;
-      mu_address_format_string (addr, addr->addr, i+1);
-    }
-      
-  i = mu_cpystr (buf, addr->addr, len);
-  if (n)
-    *n = i;
-  return 0;
-}
-
-int
-mu_address_get_count (mu_address_t addr, size_t *pcount)
-{
-  size_t j;
-  for (j = 0; addr; addr = addr->next, j++)
-    ;
-  if (pcount)
-    *pcount = j;
-  return 0;
-}
-
-int
-mu_address_get_group_count (mu_address_t addr, size_t *pcount)
-{
-  size_t j;
-  for (j = 0; addr; addr = addr->next)
-    {
-      if (_address_is_group (addr))
-       j++;
-    }
-  if (pcount)
-    *pcount = j;
-  return 0;
-}
-
-int
-mu_address_get_email_count (mu_address_t addr, size_t *pcount)
-{
-  size_t j;
-  for (j = 0; addr; addr = addr->next)
-    {
-      if (_address_is_email (addr))
-       j++;
-    }
-  if (pcount)
-    *pcount = j;
-  return 0;
-}
-
-int
-mu_address_get_unix_mailbox_count (mu_address_t addr, size_t *pcount)
-{
-  size_t j;
-  for (j = 0; addr; addr = addr->next)
-    {
-      if (_address_is_unix_mailbox (addr))
-       j++;
-    }
-  if (pcount)
-    *pcount = j;
-  return 0;
-}
-
-int
-mu_address_contains_email (mu_address_t addr, const char *email)
-{
-  for (; addr; addr = addr->next)
-    if (mu_c_strcasecmp (addr->email, email) == 0)
-      return 1;
-  return 0;
-}
-
-mu_address_t
-mu_address_dup (mu_address_t src)
-{
-  mu_address_t dst = calloc (1, sizeof (*dst));
-
-  if (!dst)
-    return NULL;
-
-  /* FIXME: How about:
-    if (src->addr)
-      dst->addr = strdup (src->addr);
-    ?
-  */
-  if (src->comments)
-    dst->comments = strdup (src->comments);
-  if (src->personal)
-    dst->personal = strdup (src->personal);
-  if (src->email)
-    dst->email = strdup (src->email);
-  if (src->local_part)
-    dst->local_part = strdup (src->local_part);
-  if (src->domain)
-    dst->domain = strdup (src->domain);
-  if (src->route)
-    dst->route = strdup (src->route);
-
-  return dst;
-}
-  
-int
-mu_address_union (mu_address_t *a, mu_address_t b)
-{
-  mu_address_t last = NULL;
-    
-  if (!a || !b)
-    return EINVAL;
-
-  if (!*a)
-    {
-      *a = mu_address_dup (b);
-      if (!*a)
-       return ENOMEM;
-      last = *a;
-      b = b->next;
-    }
-  else
-    {
-      if ((*a)->addr)
-       {
-         free ((*a)->addr);
-         (*a)->addr = NULL;
-       }
-      for (last = *a; last->next; last = last->next)
-       ;
-    }
-
-  for (; b; b = b->next)
-    if (!mu_address_contains_email (*a, b->email))
-      {
-       mu_address_t next = mu_address_dup (b);
-       if (!next)
-         return ENOMEM;
-       last->next = next;
-       last = next;
-      }
-  return 0;
-}
-  
diff --git a/libmailutils/address/Makefile.am b/libmailutils/address/Makefile.am
new file mode 100644
index 0000000..525fcc1
--- /dev/null
+++ b/libmailutils/address/Makefile.am
@@ -0,0 +1,24 @@
+# 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/>.
+
+noinst_LTLIBRARIES = libaddress.la
+
+libaddress_la_SOURCES = \
+ address.c\
+ parse822.c
+
+INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
diff --git a/libmailutils/address/address.c b/libmailutils/address/address.c
new file mode 100644
index 0000000..0bdd93e
--- /dev/null
+++ b/libmailutils/address/address.c
@@ -0,0 +1,594 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 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/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <string.h>
+
+#include <sys/types.h>
+
+#include <mailutils/errno.h>
+#include <mailutils/mutil.h>
+#include <mailutils/parse822.h>
+#include <mailutils/address.h>
+#include <mailutils/cstr.h>
+
+/* Get email addresses from rfc822 address.  */
+int
+mu_address_create_hint (mu_address_t *a, const char *s, mu_address_t hint,
+                       int hflags)
+{
+  /* 'a' must exist, and can't already have been initialized
+   */
+  int status;
+
+  if (!a)
+    return MU_ERR_OUT_PTR_NULL;
+
+  if (!s)
+    return EINVAL;
+
+  *a = NULL;
+  status = mu_parse822_address_list (a, s, hint, hflags);
+  if (status == 0)
+    {
+      /* And address-list may contain 0 addresses but parse correctly.
+       */
+      if (!*a)
+       return MU_ERR_EMPTY_ADDRESS;
+
+      (*a)->addr = strdup (s);
+      if (!(*a)->addr)
+       {
+         mu_address_destroy (a);
+         return ENOMEM;
+       }
+    }
+  return status;
+}
+
+int
+mu_address_create (mu_address_t *a, const char *s)
+{
+  struct mu_address hint;
+  const char *d;
+  mu_get_user_email_domain (&d);
+  hint.domain = (char*) d;
+  return mu_address_create_hint (a, s, &hint, MU_ADDR_HINT_DOMAIN);
+}
+
+/* Get email addresses from array of rfc822 addresses.
+   FIXME: No hints? */
+int
+mu_address_createv (mu_address_t *a, const char *sv[], size_t len)
+{
+  int status = 0;
+  size_t buflen = 0;
+  char *buf = 0;
+  size_t i;
+
+  if (!a)
+    return MU_ERR_OUT_PTR_NULL;
+
+  if (!sv)
+    return EINVAL;
+
+  if (len == (size_t) - 1)
+    {
+      const char **vp = sv;
+
+      len = 0;
+
+      for (len = 0; *vp; vp++, len++)
+       ;
+    }
+
+  if (len == 0)
+    return EINVAL;
+
+  for (i = 0; i < len; i++)
+    {
+      /* NULL strings are allowed */
+      if (sv[i])
+       buflen += strlen (sv[i]);
+    }
+
+  buflen += (len - 1) * strlen (", ");
+  buflen += 1;                 /* Termination null.  */
+
+  buf = malloc (buflen);
+
+  if (!buf)
+    return ENOMEM;
+
+  for (i = 0, buf[0] = '\0'; i < len; i++)
+    {
+      if (i != 0)
+       strcat (buf, ", ");
+
+      if (sv[i])
+       strcat (buf, sv[i]);
+    }
+
+  status = mu_address_create (a, buf);
+
+  free (buf);
+
+  return status;
+}
+
+void
+mu_address_destroy (mu_address_t *paddress)
+{
+  if (paddress && *paddress)
+    {
+      mu_address_t address = *paddress;
+      mu_address_t current;
+      for (; address; address = current)
+       {
+         if (address->addr)
+           free (address->addr);
+         if (address->comments)
+           free (address->comments);
+         if (address->personal)
+           free (address->personal);
+         if (address->email)
+           free (address->email);
+         if (address->local_part)
+           free (address->local_part);
+         if (address->domain)
+           free (address->domain);
+         if (address->route)
+           free (address->route);
+         current = address->next;
+         free (address);
+       }
+      *paddress = NULL;
+    }
+}
+
+int
+mu_address_concatenate (mu_address_t to, mu_address_t *from)
+{
+  if (!to || !from || !*from)
+    return EINVAL;
+
+  while (to->next)
+    to = to->next;
+
+  assert (to && !to->next);
+
+  to->next = *from;
+  *from = NULL;
+
+  /* discard the current string cache as it is now inaccurate */
+  if (to->addr)
+    {
+      free (to->addr);
+      to->addr = NULL;
+    }
+
+  to = to->next;
+
+  /* only the first address must have a cache */
+  if (to->addr)
+    {
+      free (to->addr);
+      to->addr = NULL;
+    }
+
+  return 0;
+}
+
+mu_address_t 
+_address_get_nth (mu_address_t addr, size_t no)
+{
+  int i;
+  
+  for (i = 1; addr; addr = addr->next, i++)
+    if (i == no)
+      break;
+  return addr;
+}
+
+int
+mu_address_get_nth (mu_address_t addr, size_t no, mu_address_t *pret)
+{
+  mu_address_t subaddr = _address_get_nth (addr, no);
+  if (!subaddr)
+    return MU_ERR_NOENT;
+  *pret = mu_address_dup (subaddr);
+  return 0;
+}
+
+
+/* General accessors: */
+#define AC4(a,b,c,d) a ## b ## c ## d
+#define ACCESSOR(action,field) AC4(mu_address_,action,_,field)
+
+#define DECL_SET(field)                                                        
\
+int                                                                    \
+ACCESSOR(set, field) (mu_address_t addr, size_t no, const char *buf)   \
+{                                                                      \
+  char *s;                                                             \
+  mu_address_t subaddr;                                                        
\
+                                                                       \
+  if (addr == NULL)                                                    \
+    return EINVAL;                                                     \
+                                                                       \
+  subaddr = _address_get_nth (addr, no);                               \
+  if (!subaddr)                                                                
\
+    return MU_ERR_NOENT;                                               \
+                                                                       \
+  s = strdup (buf);                                                    \
+  if (!s)                                                              \
+    return errno;                                                      \
+                                                                       \
+  free (subaddr->field);                                               \
+  subaddr->field = s;                                                  \
+                                                                       \
+  return 0;                                                            \
+}
+
+#define DECL_SGET(field)                                               \
+int                                                                    \
+ACCESSOR(sget,field) (mu_address_t addr, size_t no, char const **sptr) \
+{                                                                      \
+  mu_address_t subaddr;                                                        
\
+                                                                       \
+  if (addr == NULL)                                                    \
+    return EINVAL;                                                     \
+                                                                       \
+  subaddr = _address_get_nth (addr, no);                               \
+  if (!subaddr)                                                                
\
+    return MU_ERR_NOENT;                                               \
+  *sptr = subaddr->field;                                              \
+  return 0;                                                            \
+}
+
+#define DECL_GET(field)                                                        
  \
+int                                                                      \
+ACCESSOR(get,field) (mu_address_t addr, size_t no, char *buf, size_t len, \
+                    size_t *n)                                           \
+{                                                                        \
+  size_t i;                                                              \
+  const char *str;                                                       \
+  int status = ACCESSOR(sget, field) (addr, no, &str);                   \
+                                                                         \
+  if (status)                                                            \
+    return status;                                                       \
+                                                                         \
+  i = mu_cpystr (buf, str, len);                                         \
+  if (n)                                                                 \
+    *n = i;                                                              \
+  return 0;                                                              \
+}
+
+#define DECL_AGET(field)                                               \
+int                                                                    \
+ACCESSOR(aget, field) (mu_address_t addr, size_t no, char **buf)       \
+{                                                                      \
+  const char *str;                                                     \
+  int status = ACCESSOR(sget, field) (addr, no, &str);                 \
+                                                                       \
+  if (status)                                                          \
+    return status;                                                     \
+                                                                       \
+  if (str)                                                             \
+    {                                                                  \
+      *buf = strdup (str);                                             \
+      if (!*buf)                                                       \
+       status = ENOMEM;                                                \
+    }                                                                  \
+  else                                                                 \
+    *buf = NULL;                                                       \
+  return status;                                                       \
+}
+
+#define DECL_ACCESSORS(field)                  \
+DECL_SET(field)                                        \
+DECL_SGET(field)                               \
+DECL_GET(field)                                        \
+DECL_AGET(field)          
+
+
+
+/* Personal part */
+DECL_ACCESSORS(personal)
+/* Comments */
+DECL_ACCESSORS(comments)
+/* Email */
+DECL_ACCESSORS(email)     
+/* Local part */
+DECL_ACCESSORS(local_part)
+/* Domain */
+DECL_ACCESSORS(domain)
+/* Route */
+DECL_ACCESSORS(route)
+
+
+
+#define format_char(c) do {\
+ if (buflen) \
+   {\
+      *buf++ = c;\
+      buflen--;\
+   }\
+ else\
+   rc++;\
+} while(0) 
+
+#define format_string(str) do {\
+ if (buflen) \
+   {\
+      int n = snprintf (buf, buflen, "%s", str);\
+      buf += n;\
+      buflen -= n;\
+   }\
+ else\
+   rc += strlen (str);\
+} while (0)
+     
+size_t
+mu_address_format_string (mu_address_t addr, char *buf, size_t buflen)
+{
+  int rc = 0;
+  int comma = 0;
+  
+  for (;addr; addr = addr->next)
+    {
+      if (addr->email)
+       {
+         int space = 0;
+
+         if (comma)
+           format_char (',');
+         
+         if (addr->personal)
+           {
+             format_char ('"');
+             format_string (addr->personal);
+             format_char ('"');
+             space++;
+           }
+         
+         if (addr->comments)
+           {
+             if (space)
+               format_char (' ');
+             format_char ('(');
+             format_string (addr->comments);
+             format_char (')');
+             space++;
+           }
+         
+         if (space)
+           format_char (' ');
+         format_char ('<');
+         format_string (addr->email);
+         format_char ('>');
+         comma++;
+       }
+    }
+  format_char (0);
+  return rc;
+}
+
+static int
+_address_is_group (mu_address_t addr)
+{
+  if (addr->personal && !addr->local_part && !addr->domain)
+    return 1;
+  return 0;
+}
+
+static int
+_address_is_email (mu_address_t addr)
+{
+  if (addr->email)
+    return 1;
+  return 0;
+}
+
+static int
+_address_is_unix_mailbox (mu_address_t addr)
+{
+  if (addr->local_part && !addr->email)
+    return 1;
+  return 0;
+}
+
+int
+mu_address_is_group (mu_address_t addr, size_t no, int *yes)
+{
+  mu_address_t subaddr;
+  
+  if (addr == NULL)
+    return EINVAL;
+
+  subaddr = _address_get_nth (addr, no);
+  if (!subaddr)
+    return MU_ERR_NOENT;
+  
+  if (yes)
+    *yes = _address_is_group (subaddr);
+  return 0;
+}
+
+int
+mu_address_to_string (mu_address_t addr, char *buf, size_t len, size_t *n)
+{
+  size_t i;
+  if (addr == NULL)
+    return EINVAL;
+  if (buf)
+    *buf = '\0';
+
+  if (!addr->addr)
+    {
+      i = mu_address_format_string (addr, NULL, 0);
+      addr->addr = malloc (i + 1);
+      if (!addr->addr)
+       return ENOMEM;
+      mu_address_format_string (addr, addr->addr, i+1);
+    }
+      
+  i = mu_cpystr (buf, addr->addr, len);
+  if (n)
+    *n = i;
+  return 0;
+}
+
+int
+mu_address_get_count (mu_address_t addr, size_t *pcount)
+{
+  size_t j;
+  for (j = 0; addr; addr = addr->next, j++)
+    ;
+  if (pcount)
+    *pcount = j;
+  return 0;
+}
+
+int
+mu_address_get_group_count (mu_address_t addr, size_t *pcount)
+{
+  size_t j;
+  for (j = 0; addr; addr = addr->next)
+    {
+      if (_address_is_group (addr))
+       j++;
+    }
+  if (pcount)
+    *pcount = j;
+  return 0;
+}
+
+int
+mu_address_get_email_count (mu_address_t addr, size_t *pcount)
+{
+  size_t j;
+  for (j = 0; addr; addr = addr->next)
+    {
+      if (_address_is_email (addr))
+       j++;
+    }
+  if (pcount)
+    *pcount = j;
+  return 0;
+}
+
+int
+mu_address_get_unix_mailbox_count (mu_address_t addr, size_t *pcount)
+{
+  size_t j;
+  for (j = 0; addr; addr = addr->next)
+    {
+      if (_address_is_unix_mailbox (addr))
+       j++;
+    }
+  if (pcount)
+    *pcount = j;
+  return 0;
+}
+
+int
+mu_address_contains_email (mu_address_t addr, const char *email)
+{
+  for (; addr; addr = addr->next)
+    if (mu_c_strcasecmp (addr->email, email) == 0)
+      return 1;
+  return 0;
+}
+
+mu_address_t
+mu_address_dup (mu_address_t src)
+{
+  mu_address_t dst = calloc (1, sizeof (*dst));
+
+  if (!dst)
+    return NULL;
+
+  /* FIXME: How about:
+    if (src->addr)
+      dst->addr = strdup (src->addr);
+    ?
+  */
+  if (src->comments)
+    dst->comments = strdup (src->comments);
+  if (src->personal)
+    dst->personal = strdup (src->personal);
+  if (src->email)
+    dst->email = strdup (src->email);
+  if (src->local_part)
+    dst->local_part = strdup (src->local_part);
+  if (src->domain)
+    dst->domain = strdup (src->domain);
+  if (src->route)
+    dst->route = strdup (src->route);
+
+  return dst;
+}
+  
+int
+mu_address_union (mu_address_t *a, mu_address_t b)
+{
+  mu_address_t last = NULL;
+    
+  if (!a || !b)
+    return EINVAL;
+
+  if (!*a)
+    {
+      *a = mu_address_dup (b);
+      if (!*a)
+       return ENOMEM;
+      last = *a;
+      b = b->next;
+    }
+  else
+    {
+      if ((*a)->addr)
+       {
+         free ((*a)->addr);
+         (*a)->addr = NULL;
+       }
+      for (last = *a; last->next; last = last->next)
+       ;
+    }
+
+  for (; b; b = b->next)
+    if (!mu_address_contains_email (*a, b->email))
+      {
+       mu_address_t next = mu_address_dup (b);
+       if (!next)
+         return ENOMEM;
+       last->next = next;
+       last = next;
+      }
+  return 0;
+}
+  
diff --git a/libmailutils/address/parse822.c b/libmailutils/address/parse822.c
new file mode 100644
index 0000000..6dc95b9
--- /dev/null
+++ b/libmailutils/address/parse822.c
@@ -0,0 +1,2039 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2005, 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/>. */
+
+/*
+
+FIXME: what is the status of this TODO list?
+
+Things to consider:
+
+  - When parsing phrase, should I ignore non-ascii, or replace with a
+    '?' character? Right now parsing fails.
+
+    --> Should ignore non-ascii, it is unicode or iso8892-1.
+
+  - Are comments allowed in domain-literals?
+
+  - Need a way to mark the *end* of a group. Maybe add a field to _mu_address,
+    int group_end;, so if you care, you can search for the end of
+    a group with address_is_group_end();
+
+    --> Groups no longer show up in the mu_address_t list.
+
+  - Need a way to parse ",,,", it's a valid address-list, it just doesn't
+    have any addresses.
+
+  - The personal for ""Sam"" <address@hidden> is "Sam", and for 
"'address@hidden'" <address@hidden>
+    is 'address@hidden', should I strip those outside parentheses, or is that
+    too intrusive? Maybe an apps business if it wants to?
+
+  - Should we do best effort parsing, so parsing "address@hidden, foo@"
+    gets one address, or just say it is or it isn't in RFC format?
+    Right now we're strict, we'll see how it goes.
+
+  - parse Received: field?
+
+  - test for memory leaks on malloc failure
+
+  - fix the realloc, try a struct _string { char* b, size_t sz };
+
+The lexer finds consecutive sequences of characters, so it should
+define:
+
+struct parse822_token_t {
+    const char* b;  // beginning of token
+    const char* e;  // one past end of token
+}
+typedef struct parse822_token_t TOK;
+
+Then I can have str_append_token(), and the lexer functions can
+look like:
+
+int mu_parse822_atom(const char** p, const char* e, TOK* atom);
+
+Just a quick thought, I'll have to see how many functions that will
+actually help.
+
+  - get example addresses from rfc2822, and from the perl code.
+*/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <assert.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <time.h>
+
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/cctype.h>
+#include <mailutils/cstr.h>
+#include <mailutils/errno.h>
+#include <mailutils/parse822.h>
+#include <mailutils/address.h>
+
+#ifdef EOK
+# undef EOK
+#endif
+
+#define EOK    0
+#define EPARSE MU_ERR_BAD_822_FORMAT
+
+/*
+ * Some convenience functions for dealing with dynamically re-sized
+ * strings.
+ */
+
+static int
+str_append_n (char **to, const char *from, size_t n)
+{
+  size_t l = 0;
+
+  /* if not to, then silently discard data */
+  if (!to)
+    {
+      return EOK;
+    }
+
+  if (*to)
+    {
+      char *bigger;
+
+      l = strlen (*to);
+
+      bigger = realloc (*to, l + n + 1);
+
+      if (!bigger)
+       {
+         return ENOMEM;
+       }
+
+      *to = bigger;
+    }
+  else
+    {
+      *to = malloc (n + 1);
+    }
+
+  strncpy (&to[0][l], from, n);
+
+  /* strncpy is lame, nul terminate our buffer */
+
+  to[0][l + n] = 0;
+
+  return EOK;
+}
+
+static int
+str_append (char **to, const char *from)
+{
+  if (!from)
+    return 0;
+  return str_append_n (to, from, strlen (from));
+}
+
+static int
+str_append_char (char **to, char c)
+{
+  return str_append_n (to, &c, 1);
+}
+
+static int
+str_append_range (char **to, const char *b, const char *e)
+{
+  return str_append_n (to, b, e - b);
+}
+
+static void
+str_free (char **s)
+{
+  if (s && *s)
+    {
+      free (*s);
+      *s = 0;
+    }
+}
+
+/*
+ * Character Classification - could be rewritten in a C library
+ * independent way, my system's C library matches the RFC
+ * definitions. I don't know if that's guaranteed.
+ *  
+ * Note that all return values are:
+ *   1 -> TRUE
+ *   0 -> FALSE
+ * This may be appear different than the 0 == success return
+ * values of the other functions, but I was getting lost in
+ * boolean arithmetic.
+ */
+int
+mu_parse822_is_char (char c)
+{
+  return mu_isascii (c);
+}
+
+int
+mu_parse822_is_digit (char c)
+{
+  /* digit = <any ASCII decimal digit> */
+
+  return mu_isdigit ((unsigned) c);
+}
+
+int
+mu_parse822_is_ctl (char c)
+{
+  return mu_iscntrl ((unsigned) c) || c == 127 /* DEL */ ;
+}
+
+int
+mu_parse822_is_space (char c)
+{
+  return c == ' ';
+}
+
+int
+mu_parse822_is_htab (char c)
+{
+  return c == '\t';
+}
+
+int
+mu_parse822_is_lwsp_char (char c)
+{
+  return mu_parse822_is_space (c) || mu_parse822_is_htab (c);
+}
+
+int
+mu_parse822_is_special (char c)
+{
+  return strchr ("()<>@,;:\\\".[]", c) ? 1 : 0;
+}
+
+int
+parse822_is_atom_char_ex (char c)
+{
+  return !mu_parse822_is_special (c)
+    && !mu_parse822_is_space (c)
+    && !mu_parse822_is_ctl (c);
+}
+
+int
+mu_parse822_is_atom_char (char c)
+{
+  return mu_parse822_is_char (c) && parse822_is_atom_char_ex (c);
+}
+
+int
+mu_parse822_is_q_text (char c)
+{
+  return
+    mu_parse822_is_char (c) &&
+    c != '"' &&
+    c != '\\' &&
+    c != '\r';
+}
+
+int
+mu_parse822_is_d_text (char c)
+{
+  return
+    mu_parse822_is_char (c) &&
+    c != '[' &&
+    c != ']' &&
+    c != '\\' &&
+    c != '\r';
+}
+/*
+ * SMTP's version of qtext, called <q> in the RFC 821 syntax,
+ * also excludes <LF>.
+ */
+int
+mu_parse822_is_smtp_q (char c)
+{
+  return
+    mu_parse822_is_q_text (c) &&
+    c != '\n';
+}
+
+/***** From RFC 822, 3.3 Lexical Tokens *****/
+
+int
+mu_parse822_skip_nl (const char **p, const char *e)
+{
+  /* Here we consider a new-line (NL) to be either a bare LF, or
+   * a CRLF pair as required by the RFC.
+   */
+  const char *s = *p;
+
+  if ((&s[1] < e) && s[0] == '\r' && s[1] == '\n')
+    {
+      *p += 2;
+
+      return EOK;
+    }
+
+  if ((&s[0] < e) && s[0] == '\n')
+    {
+      *p += 1;
+
+      return EOK;
+    }
+
+  return EPARSE;
+}
+
+int
+mu_parse822_skip_lwsp_char (const char **p, const char *e)
+{
+  if (*p < e && mu_parse822_is_lwsp_char (**p))
+    {
+      *p += 1;
+      return EOK;
+    }
+  return EPARSE;
+}
+
+int
+mu_parse822_skip_lwsp (const char **p, const char *e)
+{
+  /*
+   * linear-white-space = 1*([[CR]LF] LWSP-char)
+   *
+   *   We interpret a bare LF as identical to the canonical CRLF
+   *   line ending, I don't know another way since on a Unix system
+   *   all CRLF will be translated to the local convention, a bare
+   *   LF, and thus we can not deal with bare NLs in the message.
+   */
+  int space = 0;
+
+  while (*p != e)
+    {
+      const char *save = *p;
+
+      if (mu_parse822_skip_lwsp_char (p, e) == EOK)
+       {
+         space = 1;
+         continue;
+       }
+      if (mu_parse822_skip_nl (p, e) == EOK)
+       {
+         if (mu_parse822_skip_lwsp_char (p, e) == EOK)
+           {
+             continue;
+           }
+         *p = save;
+         return EPARSE;
+       }
+      break;
+    }
+  return space ? EOK : EPARSE;
+}
+
+int
+mu_parse822_skip_comments (const char **p, const char *e)
+{
+  int status;
+
+  while ((status = mu_parse822_comment (p, e, 0)) == EOK)
+    ;
+
+  return EOK;
+}
+
+int
+mu_parse822_digits (const char **p, const char *e, int min, int max, int 
*digits)
+{
+  const char *save = *p;
+
+  int i = 0;
+
+  assert (digits);
+
+  *digits = 0;
+
+  while (*p < e && mu_parse822_is_digit (**p))
+    {
+      *digits = *digits * 10 + **p - '0';
+      *p += 1;
+      ++i;
+      if (max != 0 && i == max)
+       {
+         break;
+       }
+    }
+  if (i < min)
+    {
+      *p = save;
+      return EPARSE;
+    }
+
+  return EOK;
+}
+
+int
+mu_parse822_special (const char **p, const char *e, char c)
+{
+  mu_parse822_skip_lwsp (p, e);        /* not comments, they start with a 
special... */
+
+  if ((*p != e) && **p == c)
+    {
+      *p += 1;
+      return EOK;
+    }
+  return EPARSE;
+}
+
+int
+mu_parse822_comment (const char **p, const char *e, char **comment)
+{
+  /* comment = "(" *(ctext / quoted-pair / comment) ")"
+   * ctext = <any char except "(", ")", "\", & CR, including lwsp>
+   */
+  const char *save = *p;
+  int rc;
+
+  if ((rc = mu_parse822_special (p, e, '(')))
+    {
+      return rc;
+    }
+
+  while (*p != e)
+    {
+      char c = **p;
+
+      if (c == ')')
+       {
+         *p += 1;
+         return EOK;           /* found end-of-comment */
+       }
+      else if (c == '(')
+       {
+         rc = mu_parse822_comment (p, e, comment);
+       }
+      else if (c == '\\')
+       {
+         rc = mu_parse822_quoted_pair (p, e, comment);
+       }
+      else if (c == '\r')
+       {
+         /* invalid character... */
+         *p += 1;
+       }
+      else if (mu_parse822_is_char (c))
+       {
+         rc = str_append_char (comment, c);
+         *p += 1;
+       }
+      else
+       {
+         /* invalid character... */
+         *p += 1;
+       }
+      if (rc != EOK)
+       break;
+    }
+
+  if (*p == e)
+    {
+      rc = EPARSE;             /* end-of-comment not found */
+    }
+
+  *p = save;
+
+  assert (rc != EOK);
+
+  return rc;
+}
+
+int
+mu_parse822_atom (const char **p, const char *e, char **atom)
+{
+  /* atom = 1*<an atom char> */
+
+  const char *save = *p;
+  int rc = EPARSE;
+
+  mu_parse822_skip_comments (p, e);
+
+  save = *p;
+
+  while ((*p != e) && (**p == '.' || mu_parse822_is_atom_char (**p)))
+    {
+      rc = str_append_char (atom, **p);
+      *p += 1;
+      if (rc != EOK)
+       {
+         *p = save;
+         break;
+       }
+    }
+  return rc;
+}
+
+int
+parse822_atom_ex (const char **p, const char *e, char **atom)
+{
+  /* atom = 1*<an atom char> */
+  const char *ptr;
+  int rc;
+
+  mu_parse822_skip_comments (p, e);
+
+  for (ptr = *p; (ptr != e) && parse822_is_atom_char_ex (*ptr); ptr++)
+    ;
+  if (ptr - *p == 0)
+    return EPARSE;
+  rc = str_append_n (atom, *p, ptr - *p);
+  if (rc == 0)
+    *p = ptr;
+  return rc;
+}
+
+int
+mu_parse822_quoted_pair (const char **p, const char *e, char **qpair)
+{
+  /* quoted-pair = "\" char */
+
+  int rc;
+
+  /* need TWO characters to be available */
+  if ((e - *p) < 2)
+    return EPARSE;
+
+  if (**p != '\\')
+    return EPARSE;
+
+  if ((rc = str_append_char (qpair, *(*p + 1))))
+    return rc;
+
+  *p += 2;
+
+  return EOK;
+}
+
+int
+mu_parse822_quoted_string (const char **p, const char *e, char **qstr)
+{
+  /* quoted-string = <"> *(qtext/quoted-pair) <">
+   * qtext = char except <">, "\", & CR, including lwsp-char
+   */
+
+  const char *save = *p;
+  int rc;
+
+  mu_parse822_skip_comments (p, e);
+
+  save = *p;
+
+  if ((rc = mu_parse822_special (p, e, '"')))
+    return rc;
+
+  while (*p != e)
+    {
+      char c = **p;
+
+      if (c == '"')
+       {
+         *p += 1;
+         return EOK;           /* found end-of-qstr */
+       }
+      else if (c == '\\')
+       {
+         rc = mu_parse822_quoted_pair (p, e, qstr);
+       }
+      else if (c == '\r')
+       {
+         /* invalid character... */
+         *p += 1;
+       }
+      else if (mu_parse822_is_char (c))
+       {
+         rc = str_append_char (qstr, c);
+         *p += 1;
+       }
+      else
+       {
+         /* invalid character... */
+         *p += 1;
+       }
+      if (rc)
+       {
+         *p = save;
+         str_free (qstr);
+         return rc;
+       }
+    }
+  *p = save;
+  str_free (qstr);
+  return EPARSE;               /* end-of-qstr not found */
+}
+
+int
+mu_parse822_word (const char **p, const char *e, char **word)
+{
+  /* word = atom / quoted-string */
+
+  const char *save = *p;
+  int rc = EOK;
+
+  mu_parse822_skip_comments (p, e);
+
+  save = *p;
+
+  {
+    char *qstr = 0;
+    if ((rc = mu_parse822_quoted_string (p, e, &qstr)) == EOK && qstr)
+      {
+       rc = str_append (word, qstr);
+
+       str_free (&qstr);
+
+       if (rc != EOK)
+         *p = save;
+
+       return rc;
+      }
+    assert (qstr == NULL);
+  }
+
+  if (rc != EPARSE)
+    {
+      /* it's fatal */
+      return rc;
+    }
+
+  /* Necessary because the quoted string could have found
+   * a partial string (invalid syntax). Thus reset, the atom
+   * will fail to if the syntax is invalid.
+   * We use parse822_atom_ex to allow for non-rfc-compliant atoms:
+   *
+   * "Be liberal in what you accept, and conservative in what you send."
+   */
+
+  {
+    char *atom = 0;
+    if (parse822_atom_ex (p, e, &atom) == EOK)
+      {
+       rc = str_append (word, atom);
+
+       str_free (&atom);
+
+       if (rc != EOK)
+         *p = save;
+
+       return rc;
+      }
+    assert (atom == NULL);
+  }
+
+  return EPARSE;
+}
+
+/* Some mailers do not quote personal part even if it contains dot.
+   Try to be smart about it.
+*/
+       
+int
+parse822_word_dot (const char **p, const char *e, char **word)
+{
+  int rc = mu_parse822_word (p, e, word);
+  for (;rc == 0 && (*p != e) && **p == '.'; ++*p)
+    rc = str_append (word, ".");
+  return rc;
+}
+
+int
+mu_parse822_phrase (const char **p, const char *e, char **phrase)
+{
+  /* phrase = 1*word */
+
+  const char *save = *p;
+  int rc;
+
+  if ((rc = parse822_word_dot (p, e, phrase)))
+    return rc;
+
+  /* ok, got the 1 word, now append all the others we can */
+  {
+    char *word = 0;
+
+    while ((rc = parse822_word_dot (p, e, &word)) == EOK)
+      {
+       rc = str_append_char (phrase, ' ');
+
+       if (rc == EOK)
+         rc = str_append (phrase, word);
+
+       str_free (&word);
+
+       if (rc != EOK)
+         break;
+      }
+    assert (word == NULL);
+    if (rc == EPARSE)
+      rc = EOK;                        /* its not an error to find no more 
words */
+  }
+  if (rc)
+    *p = save;
+
+  return rc;
+}
+
+/***** From RFC 822, 6.1 Address Specification Syntax *****/
+
+static mu_address_t
+new_mb (void)
+{
+  return calloc (1, sizeof (struct mu_address));
+}
+
+static char *
+addr_field_by_mask (mu_address_t addr, int mask)
+{
+  switch (mask)                                                
+    {
+    case MU_ADDR_HINT_ADDR:
+      return addr->addr;
+         
+    case MU_ADDR_HINT_COMMENTS:                                
+      return addr->comments;                                   
+         
+    case MU_ADDR_HINT_PERSONAL:                                
+      return addr->personal;                                   
+
+    case MU_ADDR_HINT_EMAIL:
+      return addr->email;
+
+    case MU_ADDR_HINT_LOCAL:
+      return addr->local_part;
+      
+    case MU_ADDR_HINT_DOMAIN:                          
+      return addr->domain;                                     
+
+    case MU_ADDR_HINT_ROUTE:
+      return addr->route;
+    }
+  return NULL;
+}                                                      
+
+static char *
+get_val (mu_address_t hint, int hflags, char *value, int mask, int *memflag)
+{
+  if (!value && hint && (hflags & mask))
+    {
+      char *p = addr_field_by_mask (hint, mask);
+      if (p)                                                   
+       {
+         if (memflag)
+           *memflag |= mask;
+         value = strdup (p);
+       }
+    }
+  return value;
+}
+
+static void
+addr_free_fields (mu_address_t a, int memflag)
+{
+  char *p;
+  
+  if ((p = addr_field_by_mask (a, memflag & MU_ADDR_HINT_ADDR)))
+    free (p);
+  if ((p = addr_field_by_mask (a, memflag & MU_ADDR_HINT_COMMENTS)))
+    free (p);
+  if ((p = addr_field_by_mask (a, memflag & MU_ADDR_HINT_PERSONAL)))
+    free (p);
+  if ((p = addr_field_by_mask (a, memflag & MU_ADDR_HINT_EMAIL)))
+    free (p);
+  if ((p = addr_field_by_mask (a, memflag & MU_ADDR_HINT_LOCAL)))
+    free (p);
+  if ((p = addr_field_by_mask (a, memflag & MU_ADDR_HINT_DOMAIN)))
+    free (p);
+  if ((p = addr_field_by_mask (a, memflag & MU_ADDR_HINT_ROUTE)))
+    free (p);
+}
+
+static int
+fill_mb (mu_address_t *pa,
+        char *comments, char *personal, char *local, char *domain,
+        mu_address_t hint, int hflags)
+{
+  int rc = EOK;
+  mu_address_t a;
+  int memflag = 0;
+
+  a = new_mb ();
+
+  if (!a)
+    return ENOMEM;
+
+  a->comments = get_val (hint, hflags, comments, MU_ADDR_HINT_COMMENTS,
+                        &memflag);
+  a->personal = get_val (hint, hflags, personal, MU_ADDR_HINT_PERSONAL,
+                        &memflag);
+
+  domain = get_val (hint, hflags, domain, MU_ADDR_HINT_DOMAIN,
+                   &memflag);
+  local = get_val (hint, hflags, local, MU_ADDR_HINT_LOCAL,
+                  &memflag);
+  do
+    {
+      /* loop exists only to break out of */
+      if (!local)
+       /* no email to construct */
+       break;
+
+      if ((rc = mu_parse822_quote_local_part (&a->email, local)))
+       break;
+      if (domain)
+       {
+         if ((rc = str_append (&a->email, "@")))
+           break;
+         if ((rc = str_append (&a->email, domain)))
+           break;
+       }
+    }
+  while (0);
+
+  a->local_part = local;
+  a->domain = domain;
+
+  if (rc != EOK)
+    {
+      addr_free_fields (a, memflag);
+      /* note that the arguments have NOT been freed, we only own
+       * them on success. */
+      free (a);
+    }
+  else
+    *pa = a;
+
+  return rc;
+}
+
+int
+mu_parse822_address_list (mu_address_t *a, const char *s,
+                         mu_address_t hint, int hflags)
+{
+  /* address-list = #(address) */
+
+  const char **p = &s;
+  const char *e = &s[strlen (s)];
+  int rc = EOK;
+  mu_address_t *n = a;         /* the next address we'll be creating */
+
+  rc = mu_parse822_address (p, e, n, hint, hflags);
+
+  /* A list may start with a leading <,>, we'll find out if
+   * that's not the case at the top of the while, but give
+   * this a conditional OK unless there was some other kind
+   * of error.
+   */
+  if (rc != EOK && rc != EPARSE)
+    {
+      return rc;
+    }
+  while (*p < e)
+    {
+      mu_parse822_skip_comments (p, e);
+
+      /* An address can contain a group, so an entire
+       * list of addresses may have been appended, or no
+       * addresses at all. Walk to the end.
+       */
+      while (*n)
+       {
+         n = &(*n)->next;
+       }
+
+      /* Remember that ',,address@hidden' is a valid list! So, we must find
+       * the <,>, but the address after it can be empty.
+       */
+      if ((rc = mu_parse822_special (p, e, ',')))
+       {
+         break;
+       }
+      mu_parse822_skip_comments (p, e);
+
+      rc = mu_parse822_address (p, e, n, hint, hflags);
+
+      if (rc == EOK || rc == EPARSE)
+       {
+         /* that's cool, it may be a <,>, we'll find out if it isn't
+          * at the top of the loop
+          */
+         rc = EOK;
+       }
+      else
+       {
+         /* anything else is a fatal error, break out */
+         break;
+       }
+    }
+
+  if (rc)
+    {
+      mu_address_destroy (a);
+    }
+
+  return rc;
+}
+
+int
+mu_parse822_address (const char **p, const char *e, mu_address_t *a,
+                    mu_address_t hint, int hflags)
+{
+  /* address = mailbox / group / unix-mbox */
+
+  int rc;
+
+  if ((rc = mu_parse822_mail_box (p, e, a, hint, hflags)) == EPARSE)
+    {
+      if ((rc = mu_parse822_group (p, e, a, hint, hflags)) == EPARSE)
+       {
+         rc = mu_parse822_unix_mbox (p, e, a, hint, hflags);
+       }
+    }
+
+  if (rc == 0 && *a && !(*a)->route)
+    (*a)->route = get_val (hint, hflags, NULL, MU_ADDR_HINT_ROUTE, NULL);
+
+  return rc;
+}
+
+/* No longer put groups into an address node, it wasn't useful, was
+ * troublesome, and since there wasn't an end-group marker, wasn't
+ * even conceivably useful.
+ */
+#undef ADD_GROUPS
+int
+mu_parse822_group (const char **p, const char *e, mu_address_t *a,
+                  mu_address_t hint, int hflags)
+{
+  /* group = phrase ":" [#mailbox] ";" */
+
+  const char *save = *p;
+  mu_address_t *asave = a;             /* so we can destroy these if parsing 
fails */
+  int rc;
+  char *phrase = 0;
+
+  mu_parse822_skip_comments (p, e);
+
+  *p = save;
+
+  if ((rc = mu_parse822_phrase (p, e, &phrase)))
+    {
+      return rc;
+    }
+
+  mu_parse822_skip_comments (p, e);
+
+  if ((rc = mu_parse822_special (p, e, ':')))
+    {
+      *p = save;
+      str_free (&phrase);
+      return rc;
+    }
+#ifdef ADD_GROUPS
+  /* fake up an address node for the group's descriptive phrase, if
+   * it fails, clean-up will happen after the loop
+   */
+  if ((rc = fill_mb (a, 0, phrase, 0, 0, hint, hflags)) == EOK)
+    {
+      a = &(*a)->next;
+    }
+  else
+    {
+      str_free (&phrase);
+    }
+#else
+  str_free (&phrase);
+#endif
+
+  /* Basically, on each loop, we may find a mailbox, but we must find
+   * a comma after the mailbox, otherwise we've popped off the end
+   * of the list.
+   */
+  while (!rc)
+    {
+      mu_parse822_skip_comments (p, e);
+
+      /* it's ok not be a mailbox, but other errors are fatal */
+      rc = mu_parse822_mail_box (p, e, a, hint, hflags);
+      if (rc == EOK)
+       {
+         a = &(*a)->next;
+
+         mu_parse822_skip_comments (p, e);
+       }
+      else if (rc != EPARSE)
+       {
+         break;
+       }
+
+      if ((rc = mu_parse822_special (p, e, ',')))
+       {
+         /* the commas aren't optional */
+         break;
+       }
+    }
+  if (rc == EPARSE)
+    {
+      rc = EOK;                        /* ok, as long as we find the ";" next 
*/
+    }
+
+  if (rc || (rc = mu_parse822_special (p, e, ';')))
+    {
+      *p = save;
+
+      mu_address_destroy (asave);
+    }
+
+  return rc;
+}
+
+int
+mu_parse822_mail_box (const char **p, const char *e, mu_address_t *a,
+                     mu_address_t hint, int hflags)
+{
+  /* mailbox =
+   *     addr-spec [ "(" comment ")" ] /
+   *     [phrase] route-addr
+   *
+   *  Note: we parse the ancient comment on the right since
+   *    it's such "common practice". :-(
+   *  Note: phrase is called display-name in drums.
+   *  Note: phrase is optional in drums, though not in RFC 822.
+   */
+  const char *save = *p;
+  int rc;
+
+  /* -> addr-spec */
+  if ((rc = mu_parse822_addr_spec (p, e, a, hint, hflags)) == EOK)
+    {
+      mu_parse822_skip_lwsp (p, e);
+
+      /* yuck. */
+      if ((rc = mu_parse822_comment (p, e, &(*a)->personal)) == EPARSE)
+       {
+         rc = EOK;
+         /* cool if there's no comment, */
+       }
+      /* but if something else is wrong, destroy the address */
+      if (rc)
+       {
+         mu_address_destroy (a);
+         *p = save;
+       }
+
+      return rc;
+    }
+
+  /* -> phrase route-addr */
+  {
+    char *phrase = 0;
+
+    rc = mu_parse822_phrase (p, e, &phrase);
+
+    if (rc != EPARSE && rc != EOK)
+      {
+       return rc;
+      }
+
+    if ((rc = mu_parse822_route_addr (p, e, a, hint, hflags)) == EOK)
+      {
+       /* add the phrase */
+       (*a)->personal = phrase;
+
+       return EOK;
+      }
+    /* some internal error, fail out */
+    str_free (&phrase);
+    *p = save;
+
+    return rc;
+  }
+
+  return rc;
+}
+
+int
+mu_parse822_route_addr (const char **p, const char *e, mu_address_t *a,
+                       mu_address_t hint, int hflags)
+{
+  /* route-addr = "<" [route] addr-spec ">" */
+
+  const char *save = *p;
+  char *route = NULL;
+  int rc;
+  int memflag = 0;
+  
+  mu_parse822_skip_comments (p, e);
+
+  if ((rc = mu_parse822_special (p, e, '<')))
+    {
+      *p = save;
+
+      return rc;
+    }
+  if (!(rc = mu_parse822_special (p, e, '>')))
+    {
+      if ((rc = fill_mb (a, 0, 0, 0, 0, hint, hflags)) == EOK)
+       rc = str_append (&(*a)->email, "");
+       
+      return rc;
+    }
+
+  mu_parse822_route (p, e, &route);
+
+  if ((rc = mu_parse822_addr_spec (p, e, a, hint, hflags)))
+    {
+      *p = save;
+
+      str_free (&route);
+
+      return rc;
+    }
+
+  (*a)->route = get_val (hint, hflags, route, MU_ADDR_HINT_ROUTE,
+                        &memflag);
+
+  mu_parse822_skip_comments (p, e);
+
+  if ((rc = mu_parse822_special (p, e, '>')))
+    {
+      *p = save;
+
+      mu_address_destroy (a);
+
+      return rc;
+    }
+
+  return EOK;
+}
+
+int
+mu_parse822_route (const char **p, const char *e, char **route)
+{
+  /* route = 1#("@" domain ) ":" */
+
+  const char *save = *p;
+  char *accumulator = 0;
+  int rc = EOK;
+
+  for (;;)
+    {
+      mu_parse822_skip_comments (p, e);
+
+      if ((rc = mu_parse822_special (p, e, '@')))
+       {
+         break;
+       }
+
+      if ((rc = str_append (&accumulator, "@")))
+       {
+         break;
+       }
+
+      mu_parse822_skip_comments (p, e);
+
+      if ((rc = mu_parse822_domain (p, e, &accumulator)))
+       {
+         /* it looked like a route, but there's no domain! */
+         break;
+       }
+
+      mu_parse822_skip_comments (p, e);
+
+      if ((rc = mu_parse822_special (p, e, ',')) == EPARSE)
+       {
+         /* no more routes, but we got one so its ok */
+         rc = EOK;
+         break;
+       }
+      if ((rc = str_append (&accumulator, ", ")))
+       {
+         break;
+       }
+    }
+
+  mu_parse822_skip_comments (p, e);
+
+  if (!rc)
+    {
+      rc = mu_parse822_special (p, e, ':');
+    }
+
+  if (!rc)
+    {
+      rc = str_append (route, accumulator);
+    }
+  if (rc)
+    {
+      *p = save;
+    }
+  str_free (&accumulator);
+  return rc;
+}
+
+int
+mu_parse822_addr_spec (const char **p, const char *e, mu_address_t *a,
+                      mu_address_t hint, int hflags)
+{
+  /* addr-spec = local-part "@" domain */
+
+  const char *save = *p;
+  char *local_part = 0;
+  char *domain = 0;
+  int rc;
+
+  rc = mu_parse822_local_part (p, e, &local_part);
+
+  mu_parse822_skip_comments (p, e);
+
+  if (!rc)
+    {
+      rc = mu_parse822_special (p, e, '@');
+      
+      if (!rc)
+       {
+         rc = mu_parse822_domain (p, e, &domain);
+
+         if (!rc)
+           rc = fill_mb (a, 0, 0, local_part, domain, hint, hflags);
+       }
+    }
+  
+  if (rc)
+    {
+      *p = save;
+      str_free (&local_part);
+      str_free (&domain);
+    }
+  return rc;
+}
+
+int
+mu_parse822_unix_mbox (const char **p, const char *e, mu_address_t *a,
+                      mu_address_t hint, int hflags)
+{
+  /* unix-mbox = atom */
+
+  const char *save = *p;
+  char *mbox = 0;
+  int rc;
+
+  mu_parse822_skip_comments (p, e);
+
+  rc = mu_parse822_atom (p, e, &mbox);
+
+  if (!rc)
+    rc = fill_mb (a, 0, 0, mbox, 0, hint, hflags);
+
+  if (rc)
+    {
+      *p = save;
+      str_free (&mbox);
+    }
+  return rc;
+}
+
+int
+mu_parse822_local_part (const char **p, const char *e, char **local_part)
+{
+  /* local-part = word *("." word)
+   *
+   * Note: rewrite as ->  word ["." local-part]
+   */
+
+  const char *save = *p;
+  const char *save2 = *p;
+  int rc;
+
+  mu_parse822_skip_comments (p, e);
+
+  if ((rc = mu_parse822_word (p, e, local_part)))
+    {
+      *p = save;
+      return rc;
+    }
+  /* We've got a local-part, but keep looking for more. */
+
+  mu_parse822_skip_comments (p, e);
+
+  /* If we get a parse error, we roll back to save2, but if
+   * something else failed, we have to roll back to save.
+   */
+  save2 = *p;
+
+  rc = mu_parse822_special (p, e, '.');
+
+  if (!rc)
+    {
+      char *more = 0;
+      if ((rc = mu_parse822_local_part (p, e, &more)) == EOK)
+       {
+         /* append more */
+         if ((rc = str_append (local_part, ".")) == EOK)
+           {
+             rc = str_append (local_part, more);
+           }
+       }
+      str_free (&more);
+    }
+
+  if (rc == EPARSE)
+    {
+      /* if we didn't get more ("." word) pairs, that's ok */
+      *p = save2;
+      rc = EOK;
+    }
+  if (rc)
+    {
+      /* if anything else failed, that's real */
+      *p = save;
+      str_free (local_part);
+    }
+  return rc;
+}
+
+int
+mu_parse822_domain (const char **p, const char *e, char **domain)
+{
+  /* domain = sub-domain *("." sub-domain)
+   *
+   * Note: rewrite as -> sub-domain ("." domain)
+   */
+
+  const char *save = *p;
+  const char *save2 = 0;
+  int rc;
+
+  mu_parse822_skip_comments (p, e);
+
+  if ((rc = mu_parse822_sub_domain (p, e, domain)))
+    {
+      *p = save;
+      return rc;
+    }
+
+
+  /* We save before skipping comments to preserve the comment
+   * at the end of a domain, the addr-spec may want to abuse it
+   * for a personal name.
+   */
+  save2 = *p;
+
+  /* we've got the 1, keep looking for more */
+
+  mu_parse822_skip_comments (p, e);
+
+  rc = mu_parse822_special (p, e, '.');
+
+  if (!rc)
+    {
+      char *more = 0;
+      if ((rc = mu_parse822_domain (p, e, &more)) == EOK)
+       {
+         if ((rc = str_append (domain, ".")) == EOK)
+           {
+             rc = str_append (domain, more);
+           }
+       }
+      str_free (&more);
+    }
+  if (rc == EPARSE)
+    {
+      /* we didn't parse more ("." sub-domain) pairs, that's ok */
+      *p = save2;
+      rc = EOK;
+    }
+
+  if (rc)
+    {
+      /* something else failed, roll it all back */
+      *p = save;
+      str_free (domain);
+    }
+  return rc;
+}
+
+int
+mu_parse822_sub_domain (const char **p, const char *e, char **sub_domain)
+{
+  /* sub-domain = domain-ref / domain-literal
+   */
+
+  int rc;
+
+  if ((rc = mu_parse822_domain_ref (p, e, sub_domain)) == EPARSE)
+    rc = mu_parse822_domain_literal (p, e, sub_domain);
+
+  return rc;
+}
+
+int
+mu_parse822_domain_ref (const char **p, const char *e, char **domain_ref)
+{
+  /* domain-ref = atom */
+
+  return mu_parse822_atom (p, e, domain_ref);
+}
+
+int
+mu_parse822_d_text (const char **p, const char *e, char **dtext)
+{
+  /* d-text = 1*dtext
+   *
+   * Note: dtext is only defined as a character class in
+   *  RFC822, but this definition is more useful for
+   *  slurping domain literals.
+   */
+
+  const char *start = *p;
+  int rc = EOK;
+
+  while (*p < e && mu_parse822_is_d_text (**p))
+    {
+      *p += 1;
+    }
+
+  if (start == *p)
+    {
+      return EPARSE;
+    }
+
+  if ((rc = str_append_range (dtext, start, *p)))
+    {
+      *p = start;
+    }
+
+  return rc;
+}
+
+int
+mu_parse822_domain_literal (const char **p, const char *e, char 
**domain_literal)
+{
+  /* domain-literal = "[" *(dtext / quoted-pair) "]" */
+
+  const char *save = *p;
+  char *literal = 0;
+  int rc;
+
+  if ((rc = mu_parse822_special (p, e, '[')))
+    {
+      return rc;
+    }
+  if ((rc = str_append_char (&literal, '[')))
+    {
+      *p = save;
+      return rc;
+    }
+
+  while ((rc = mu_parse822_d_text (p, e, &literal)) == EOK ||
+        (rc = mu_parse822_quoted_pair (p, e, &literal)) == EOK)
+    {
+      /* Eat all of this we can get! */
+    }
+  if (rc == EPARSE)
+    {
+      rc = EOK;
+    }
+  if (!rc)
+    {
+      rc = mu_parse822_special (p, e, ']');
+    }
+  if (!rc)
+    {
+      rc = str_append_char (&literal, ']');
+    }
+  if (!rc)
+    {
+      rc = str_append (domain_literal, literal);
+    }
+
+  str_free (&literal);
+
+  if (rc)
+    {
+      *p = save;
+    }
+  return rc;
+}
+
+/***** From RFC 822, 5.1 Date and Time Specification Syntax *****/
+
+int
+mu_parse822_day (const char **p, const char *e, int *day)
+{
+  /* day = "Mon" / "Tue" / "Wed" / "Thu" / "Fri" / "Sat" / "Sun" */
+
+  const char *days[] = {
+    "Sun",
+    "Mon",
+    "Tue",
+    "Wed",
+    "Thu",
+    "Fri",
+    "Sat",
+    NULL
+  };
+
+  int d;
+
+  mu_parse822_skip_comments (p, e);
+
+  if ((e - *p) < 3)
+    return EPARSE;
+
+  for (d = 0; days[d]; d++)
+    {
+      if (mu_c_strncasecmp (*p, days[d], 3) == 0)
+       {
+         *p += 3;
+         if (day)
+           *day = d;
+         return EOK;
+       }
+    }
+  return EPARSE;
+}
+
+int
+mu_parse822_date (const char **p, const char *e, int *day, int *mon, int *year)
+{
+  /* date = 1*2DIGIT month 2*4DIGIT
+   * month =  "Jan"  /  "Feb" /  "Mar"  /  "Apr"
+   *       /  "May"  /  "Jun" /  "Jul"  /  "Aug"
+   *       /  "Sep"  /  "Oct" /  "Nov"  /  "Dec"
+   */
+
+  const char *mons[] = {
+    "Jan",
+    "Feb",
+    "Mar",
+    "Apr",
+    "May",
+    "Jun",
+    "Jul",
+    "Aug",
+    "Sep",
+    "Oct",
+    "Nov",
+    "Dec",
+    NULL
+  };
+
+  const char *save = *p;
+  int rc = EOK;
+  int m = 0;
+  int yr = 0;
+  const char *yrbeg = 0;
+
+  mu_parse822_skip_comments (p, e);
+
+  if ((rc = mu_parse822_digits (p, e, 1, 2, day)))
+    {
+      *p = save;
+      return rc;
+    }
+
+  mu_parse822_skip_comments (p, e);
+
+  if ((e - *p) < 3)
+    return EPARSE;
+
+  for (m = 0; mons[m]; m++)
+    {
+      if (mu_c_strncasecmp (*p, mons[m], 3) == 0)
+       {
+         *p += 3;
+         if (mon)
+           *mon = m;
+         break;
+       }
+    }
+
+  if (!mons[m])
+    {
+      *p = save;
+      return EPARSE;
+    }
+
+  mu_parse822_skip_comments (p, e);
+
+  /* We need to count how many digits their were, and adjust the
+   * interpretation of the year accordingly. This is from RFC 2822,
+   * Section 4.3, Obsolete Date and Time. */
+  yrbeg = *p;
+
+  if ((rc = mu_parse822_digits (p, e, 2, 4, &yr)))
+    {
+      *p = save;
+      return rc;
+    }
+
+  /* rationalize year to four digit, then adjust to tz notation */
+  switch (*p - yrbeg)
+    {
+    case 2:
+      if (yr >= 0 && yr <= 49)
+       {
+         yr += 2000;
+         break;
+       }
+    case 3:
+      yr += 1900;
+      break;
+    }
+
+  if (year)
+    *year = yr - 1900;
+
+  return EOK;
+}
+
+int
+mu_parse822_time (const char **p, const char *e,
+              int *hour, int *min, int *sec, int *tz, const char **tz_name)
+{
+  /* time        =  hour zone
+   * hour        =  2DIGIT ":" 2DIGIT [":" 2DIGIT] ; 00:00:00 - 23:59:59
+   * zone        =  "UT"  / "GMT"           ; Universal Time
+   *                                        ; North American : UT
+   *             /  "EST" / "EDT"           ;  Eastern:  - 5/ - 4
+   *             /  "CST" / "CDT"           ;  Central:  - 6/ - 5
+   *             /  "MST" / "MDT"           ;  Mountain: - 7/ - 6
+   *             /  "PST" / "PDT"           ;  Pacific:  - 8/ - 7
+   *             /  1ALPHA                  ; RFC 822 was wrong, RFC 2822
+   *                                        ; says treat these all as -0000.
+   *             / ( ("+" / "-") 4DIGIT )   ; Local differential
+   *                                        ;  hours+min. (HHMM)
+   */
+
+  struct
+  {
+    const char *tzname;
+    int tz;
+  }
+  tzs[] =
+  {
+    { "UT",   0 * 60 * 60 },
+    { "UTC",  0 * 60 * 60 },
+    { "GMT",  0 * 60 * 60 },
+    { "EST", -5 * 60 * 60 },
+    { "EDT", -4 * 60 * 60 },
+    { "CST", -6 * 60 * 60 },
+    { "CDT", -5 * 60 * 60 },
+    { "MST", -7 * 60 * 60 },
+    { "MDT", -6 * 60 * 60 },
+    { "PST", -8 * 60 * 60 },
+    { "PDT", -7 * 60 * 60 },
+    { NULL, 0}
+  };
+
+  const char *save = *p;
+  int rc = EOK;
+  int z = 0;
+  char *zone = NULL;
+
+  mu_parse822_skip_comments (p, e);
+
+  if ((rc = mu_parse822_digits (p, e, 1, 2, hour)))
+    {
+      *p = save;
+      return rc;
+    }
+
+  if ((rc = mu_parse822_special (p, e, ':')))
+    {
+      *p = save;
+      return rc;
+    }
+
+  if ((rc = mu_parse822_digits (p, e, 1, 2, min)))
+    {
+      *p = save;
+      return rc;
+    }
+
+  if ((rc = mu_parse822_special (p, e, ':')))
+    {
+      *sec = 0;
+    }
+  else if ((rc = mu_parse822_digits (p, e, 1, 2, sec)))
+    {
+      *p = save;
+      return rc;
+    }
+
+  mu_parse822_skip_comments (p, e);
+
+  if ((rc = mu_parse822_atom (p, e, &zone)))
+    {
+      /* zone is optional */
+      if (tz)
+       *tz = 0;
+      return EOK;
+    }
+
+  /* see if it's a timezone */
+  for (; tzs[z].tzname; z++)
+    {
+      if (mu_c_strcasecmp (zone, tzs[z].tzname) == 0)
+       break;
+    }
+  if (tzs[z].tzname)
+    {
+      if (tz_name)
+       *tz_name = tzs[z].tzname;
+
+      if (tz)
+       *tz = tzs[z].tz;
+    }
+  else if (strlen (zone) > 5 || strlen (zone) < 4)
+    {
+      if (*tz)
+       *tz = 0; /* Assume UTC */
+    }
+  else
+    {
+      /* zone = ( + / - ) hhmm */
+      int hh;
+      int mm;
+      int sign;
+      char *zp = zone;
+
+      switch (zp[0])
+       {
+       case '-':
+         sign = -1;
+         zp++;
+         break;
+       case '+':
+         sign = +1;
+         zp++;
+         break;
+       default:
+         sign = 1;
+         break;
+       }
+
+      if (strspn (zp, "0123456789") == 4)
+       {
+      /* convert to seconds from UTC */
+      hh = (zone[1] - '0') * 10 + (zone[2] - '0');
+      mm = (zone[3] - '0') * 10 + (zone[4] - '0');
+       }
+      else
+       {
+         hh = mm = 0; /* Consider equivalent to -0000 */
+       }
+      if (tz)
+       *tz = sign * (hh * 60 * 60 + mm * 60);
+    }
+
+  str_free (&zone);
+
+  return EOK;
+}
+
+#if 0
+For reference, especially the for the required range and values of the
+integer fields.
+
+struct tm
+{
+  int tm_sec;                  /* Seconds.     [0-60] (1 leap second) */
+  int tm_min;                  /* Minutes.     [0-59] */
+  int tm_hour;                 /* Hours.       [0-23] */
+  int tm_mday;                 /* Day.         [1-31] */
+  int tm_mon;                  /* Month.       [0-11] */
+  int tm_year;                 /* Year - 1900.  */
+  int tm_wday;                 /* Day of week. [0-6] */
+  int tm_yday;                 /* Days in year.[0-365] */
+  int tm_isdst;                        /* DST.         [-1/0/1]*/
+
+  int tm_gmtoff;        /* Seconds east of UTC. */
+  const char *tm_zone; /* Timezone abbreviation.  */
+};
+#endif
+
+int
+mu_parse822_date_time (const char **p, const char *e, struct tm *tm,
+                      struct mu_timezone *tz)
+{
+  /* date-time = [ day "," ] date time */
+
+  const char *save = *p;
+  int rc = 0;
+
+  int wday = 0;
+
+  int mday = 0;
+  int mon = 0;
+  int year = 0;
+
+  int hour = 0;
+  int min = 0;
+  int sec = 0;
+
+  int tzoffset = 0;
+  const char *tz_name = 0;
+
+  if ((rc = mu_parse822_day (p, e, &wday)))
+    {
+      if (rc != EPARSE)
+       return rc;
+    }
+  else
+    {
+      /* If we got a day, we MUST have a ','. */
+      mu_parse822_skip_comments (p, e);
+
+      if ((rc = mu_parse822_special (p, e, ',')))
+       {
+         *p = save;
+         return rc;
+       }
+    }
+
+  if ((rc = mu_parse822_date (p, e, &mday, &mon, &year)))
+    {
+      *p = save;
+      return rc;
+    }
+  if ((rc = mu_parse822_time (p, e, &hour, &min, &sec, &tzoffset, &tz_name)))
+    {
+      *p = save;
+      return rc;
+    }
+
+  if (tm)
+    {
+      memset (tm, 0, sizeof (*tm));
+
+      tm->tm_wday = wday;
+
+      tm->tm_mday = mday;
+      tm->tm_mon = mon;
+      tm->tm_year = year;
+
+      tm->tm_hour = hour;
+      tm->tm_min = min;
+      tm->tm_sec = sec;
+
+#ifdef HAVE_STRUCT_TM_TM_ISDST
+      tm->tm_isdst = -1;       /* unknown whether it's dst or not */
+#endif
+#ifdef HAVE_STRUCT_TM_TM_GMTOFF
+      tm->tm_gmtoff = tzoffset;
+#endif
+#ifdef HAVE_STRUCT_TM_TM_ZONE
+      tm->tm_zone = (char*) tz_name;
+#endif
+    }
+
+  if (tz)
+    {
+      tz->utc_offset = tzoffset;
+      tz->tz_name = tz_name;
+    }
+
+  return EOK;
+}
+
+/***** From RFC 822, 3.2 Header Field Definitions *****/
+
+int
+mu_parse822_field_name (const char **p, const char *e, char **fieldname)
+{
+  /* field-name = 1*<any char, excluding ctls, space, and ":"> ":" */
+
+  const char *save = *p;
+
+  char *fn = NULL;
+
+  while (*p != e)
+    {
+      char c = **p;
+
+      if (!mu_parse822_is_char (c))
+       break;
+
+      if (mu_parse822_is_ctl (c))
+       break;
+      if (mu_parse822_is_space (c))
+       break;
+      if (c == ':')
+       break;
+
+      str_append_char (&fn, c);
+      *p += 1;
+    }
+  /* must be at least one char in the field name */
+  if (!fn)
+    {
+      *p = save;
+      return EPARSE;
+    }
+  mu_parse822_skip_comments (p, e);
+
+  if (!mu_parse822_special (p, e, ':'))
+    {
+      *p = save;
+      if (fn)
+       free (fn);
+      return EPARSE;
+    }
+
+  *fieldname = fn;
+
+  return EOK;
+}
+
+int
+mu_parse822_field_body (const char **p, const char *e, char **fieldbody)
+{
+  /* field-body = *text [CRLF lwsp-char field-body] */
+
+  /*const char *save = *p; */
+
+  char *fb = NULL;
+
+  for (;;)
+    {
+      const char *eol = *p;
+      while (eol != e)
+       {
+         /*char c = *eol; */
+         if (eol[0] == '\r' && (eol + 1) != e && eol[1] == '\n')
+           break;
+         ++eol;
+       }
+      str_append_range (&fb, *p, eol);
+      *p = eol;
+      if (eol == e)
+       break;                  /* no more, so we're done */
+
+      /*assert(p[0] == '\r'); */
+      /*assert(p[1] == '\n'); */
+
+      *p += 2;
+
+      if (*p == e)
+       break;                  /* no more, so we're done */
+
+      /* check if next line is a continuation line */
+      if (**p != ' ' && **p != '\t')
+       break;
+    }
+
+  *fieldbody = fb;
+
+  return EOK;
+}
+
+/***** RFC 822 Quoting Functions *****/
+
+int
+mu_parse822_quote_string (char **quoted, const char *raw)
+{
+  /* quoted-string = <"> *(qtext/quoted-pair) <">
+   *
+   * So double quote the string, and back quote anything that
+   * isn't qtext.
+   */
+
+  int rc = EOK;
+  const char *s;
+
+  if (!raw || !quoted || *quoted)
+    {
+      return EINVAL;
+    }
+
+  s = raw;
+
+  rc = str_append_char (quoted, '"');
+
+  while (!rc && *s)
+    {
+      if (!mu_parse822_is_q_text (*s))
+       {
+         rc = str_append_char (quoted, '\\');
+       }
+
+      if (!rc)
+       {
+         rc = str_append_char (quoted, *s);
+       }
+      ++s;
+    }
+
+  if (!rc)
+    {
+      rc = str_append_char (quoted, '"');
+    }
+
+  if (rc)
+    {
+      str_free (quoted);
+    }
+  return rc;
+}
+
+int
+mu_parse822_quote_local_part (char **quoted, const char *raw)
+{
+  /* local-part = word * ("." word)
+   * word = atom / quoted-string
+   *
+   * So, if any character isn't a "." or an atom character, we quote
+   * the whole thing as a string, for simplicity, otherwise just
+   * copy it.
+   */
+
+  const char *s = 0;
+
+  if (!raw || !quoted || *quoted)
+    {
+      return EINVAL;
+    }
+  s = raw;
+
+  while (*s)
+    {
+      if (*s != '.' && !mu_parse822_is_atom_char (*s))
+       {
+         return mu_parse822_quote_string (quoted, raw);
+       }
+      ++s;
+    }
+
+  /* if we don't have to quote it, just copy it over */
+
+  return str_append (quoted, raw);
+}
+
diff --git a/libmailutils/amd.c b/libmailutils/amd.c
deleted file mode 100644
index a5dac3f..0000000
--- a/libmailutils/amd.c
+++ /dev/null
@@ -1,2033 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
-   2008, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-/* Mailutils Abstract Mail Directory Layer 
-   First draft by Sergey Poznyakoff.
-   Thanks Tang Yong Ping <address@hidden> for initial
-   patch (although not used here).
-
-   This module provides basic support for "MH" and "Maildir" formats. */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <sys/types.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <time.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-#include <dirent.h>
-
-#ifdef WITH_PTHREAD
-# ifdef HAVE_PTHREAD_H
-#  ifndef _XOPEN_SOURCE
-#   define _XOPEN_SOURCE  500
-#  endif
-#  include <pthread.h>
-# endif
-#endif
-
-#include <string.h>
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
-#endif
-
-#include <mailutils/cctype.h>
-#include <mailutils/cstr.h>
-#include <mailutils/attribute.h>
-#include <mailutils/body.h>
-#include <mailutils/debug.h>
-#include <mailutils/envelope.h>
-#include <mailutils/error.h>
-#include <mailutils/errno.h>
-#include <mailutils/header.h>
-#include <mailutils/locker.h>
-#include <mailutils/message.h>
-#include <mailutils/mutil.h>
-#include <mailutils/property.h>
-#include <mailutils/stream.h>
-#include <mailutils/url.h>
-#include <mailutils/observer.h>
-#include <mailutils/sys/stream.h>
-#include <mailutils/sys/mailbox.h>
-#include <mailutils/sys/registrar.h>
-#include <mailutils/sys/url.h>
-#include <mailutils/sys/amd.h>
-
-static void amd_destroy (mu_mailbox_t mailbox);
-static int amd_open (mu_mailbox_t, int);
-static int amd_close (mu_mailbox_t);
-static int amd_get_message (mu_mailbox_t, size_t, mu_message_t *);
-static int amd_quick_get_message (mu_mailbox_t mailbox, mu_message_qid_t qid,
-                                 mu_message_t *pmsg);
-static int amd_append_message (mu_mailbox_t, mu_message_t);
-static int amd_messages_count (mu_mailbox_t, size_t *);
-static int amd_messages_recent (mu_mailbox_t, size_t *);
-static int amd_message_unseen (mu_mailbox_t, size_t *);
-static int amd_expunge (mu_mailbox_t);
-static int amd_sync (mu_mailbox_t);
-static int amd_uidnext (mu_mailbox_t mailbox, size_t *puidnext);
-static int amd_uidvalidity (mu_mailbox_t, unsigned long *);
-static int amd_scan (mu_mailbox_t, size_t, size_t *);
-static int amd_is_updated (mu_mailbox_t);
-static int amd_get_size (mu_mailbox_t, mu_off_t *);
-
-static int amd_body_size (mu_body_t body, size_t *psize);
-static int amd_body_lines (mu_body_t body, size_t *plines);
-
-static int amd_header_fill (void *data, char **pbuf, size_t *plen);
-
-static int amd_get_attr_flags (mu_attribute_t attr, int *pflags);
-static int amd_set_attr_flags (mu_attribute_t attr, int flags);
-static int amd_unset_attr_flags (mu_attribute_t attr, int flags);
-
-static void _amd_message_delete (struct _amd_data *amd,
-                                struct _amd_message *msg);
-static int amd_pool_open (struct _amd_message *mhm);
-static int amd_pool_open_count (struct _amd_data *amd);
-static void amd_pool_flush (struct _amd_data *amd);
-static struct _amd_message **amd_pool_lookup (struct _amd_message *mhm);
-
-static int amd_envelope_date (mu_envelope_t envelope, char *buf, size_t len,
-                             size_t *psize);
-static int amd_envelope_sender (mu_envelope_t envelope, char *buf, size_t len,
-                               size_t *psize);
-static int amd_remove_mbox (mu_mailbox_t mailbox);
-
-
-static int amd_body_stream_read (mu_stream_t str, char *buffer,
-                                size_t buflen,
-                                size_t *pnread);
-static int amd_body_stream_readdelim (mu_stream_t is,
-                                     char *buffer, size_t buflen,
-                                     int delim,
-                                     size_t *pnread);
-static int amd_body_stream_size (mu_stream_t str, mu_off_t *psize);
-static int amd_body_stream_seek (mu_stream_t str, mu_off_t off, 
-                                mu_off_t *presult);
-
-struct _amd_body_stream
-{
-  struct _mu_stream stream;
-  mu_body_t body;
-  mu_off_t off;
-};
-
-
-/* Operations on message array */
-
-/* Perform binary search for message MSG on a segment of message array
-   of AMD between the indexes FIRST and LAST inclusively.
-   If found, return 0 and store index of the located entry in the
-   variable PRET. Otherwise, return 1 and place into PRET index of
-   the nearest array element that is less than MSG (in the sense of
-   amd->msg_cmp)
-   Indexes are zero-based. */
-   
-static int
-amd_msg_bsearch (struct _amd_data *amd, mu_off_t first, mu_off_t last,
-                struct _amd_message *msg,
-                mu_off_t *pret)
-{
-  mu_off_t mid;
-  int rc;
-
-  if (last < first)
-    return 1;
-  
-  mid = (first + last) / 2;
-  rc = amd->msg_cmp (amd->msg_array[mid], msg);
-  if (rc > 0)
-    return amd_msg_bsearch (amd, first, mid-1, msg, pret);
-  *pret = mid;
-  if (rc < 0)
-    return amd_msg_bsearch (amd, mid+1, last, msg, pret);
-  /* else */
-  return 0;
-}
-
-/* Search for message MSG in the message array of AMD.
-   If found, return 0 and store index of the located entry in the
-   variable PRET. Otherwise, return 1 and place into PRET index of
-   the array element that is less than MSG (in the sense of
-   amd->msg_cmp)
-   Index returned in PRET is 1-based, so *PRET == 0 means that MSG
-   is less than the very first element of the message array.
-
-   In other words, when amd_msg_lookup() returns 1, the value in *PRET
-   can be regarded as a 0-based index of the array slot where MSG can
-   be inserted */
-
-int
-amd_msg_lookup (struct _amd_data *amd, struct _amd_message *msg,
-                size_t *pret)
-{
-  int rc;
-  mu_off_t i;
-  
-  if (amd->msg_count == 0)
-    {
-      *pret = 0;
-      return 1;
-    }
-  
-  rc = amd->msg_cmp (msg, amd->msg_array[0]);
-  if (rc < 0)
-    {
-      *pret = 0;
-      return 1;
-    }
-  else if (rc == 0)
-    {
-      *pret = 1;
-      return 0;
-    }
-  
-  rc = amd->msg_cmp (msg, amd->msg_array[amd->msg_count - 1]);
-  if (rc > 0)
-    {
-      *pret = amd->msg_count;
-      return 1;
-    }
-  else if (rc == 0)
-    {
-      *pret = amd->msg_count;
-      return 0;
-    }
-  
-  rc = amd_msg_bsearch (amd, 0, amd->msg_count - 1, msg, &i);
-  *pret = i + 1;
-  return rc;
-}
-
-#define AMD_MSG_INC 64
-
-/* Prepare the message array for insertion of a new message
-   at position INDEX (zero based), by moving its contents
-   one slot to the right. If necessary, expand the array by
-   AMD_MSG_INC */
-int
-amd_array_expand (struct _amd_data *amd, size_t index)
-{
-  if (amd->msg_count == amd->msg_max)
-    {
-      struct _amd_message **p;
-      
-      amd->msg_max += AMD_MSG_INC; /* FIXME: configurable? */
-      p = realloc (amd->msg_array, amd->msg_max * amd->msg_size);
-      if (!p)
-       {
-         amd->msg_max -= AMD_MSG_INC;
-         return ENOMEM;
-       }
-      amd->msg_array = p;
-    }
-  memmove (&amd->msg_array[index+1], &amd->msg_array[index],
-          (amd->msg_count-index) * amd->msg_size);
-  amd->msg_count++;
-  return 0;
-}
-
-/* Shrink the message array by removing element at INDEX-1 and
-   shifting left by one position all the elements on the right of
-   it. */
-int
-amd_array_shrink (struct _amd_data *amd, size_t index)
-{
-  memmove (&amd->msg_array[index-1], &amd->msg_array[index],
-          (amd->msg_count-index) * amd->msg_size);
-  amd->msg_count--;
-  return 0;
-}
-
-
-int
-amd_init_mailbox (mu_mailbox_t mailbox, size_t amd_size,
-                 struct _amd_data **pamd) 
-{
-  int status;
-  struct _amd_data *amd;
-
-  if (mailbox == NULL)
-    return MU_ERR_MBX_NULL;
-  if (amd_size < sizeof (*amd))
-    return EINVAL;
-
-  amd = mailbox->data = calloc (1, amd_size);
-  if (mailbox->data == NULL)
-    return ENOMEM;
-
-  /* Back pointer.  */
-  amd->mailbox = mailbox;
-
-  status = mu_url_aget_path (mailbox->url, &amd->name);
-  if (status)
-    {
-      free (amd);
-      mailbox->data = NULL;
-      return status;
-    }
-
-  /* Overloading the defaults.  */
-  mailbox->_destroy = amd_destroy;
-
-  mailbox->_open = amd_open;
-  mailbox->_close = amd_close;
-
-  /* Overloading of the entire mailbox object methods.  */
-  mailbox->_get_message = amd_get_message;
-  mailbox->_quick_get_message = amd_quick_get_message;
-  mailbox->_append_message = amd_append_message;
-  mailbox->_messages_count = amd_messages_count;
-  mailbox->_messages_recent = amd_messages_recent;
-  mailbox->_message_unseen = amd_message_unseen;
-  mailbox->_expunge = amd_expunge;
-  mailbox->_sync = amd_sync;
-  mailbox->_uidvalidity = amd_uidvalidity;
-  mailbox->_uidnext = amd_uidnext;
-
-  mailbox->_scan = amd_scan;
-  mailbox->_is_updated = amd_is_updated;
-
-  mailbox->_get_size = amd_get_size;
-  mailbox->_remove = amd_remove_mbox;
-  
-  MU_DEBUG1 (mailbox->debug, MU_DEBUG_TRACE1, "amd_init(%s)\n", amd->name);
-  *pamd = amd;
-  return 0;
-}
-
-static void
-amd_destroy (mu_mailbox_t mailbox)
-{
-  struct _amd_data *amd = mailbox->data;
-  size_t i;
-  
-  if (!amd)
-    return;
-
-  amd_pool_flush (amd);
-  mu_monitor_wrlock (mailbox->monitor);
-  for (i = 0; i < amd->msg_count; i++)
-    {
-      mu_message_destroy (&amd->msg_array[i]->message, amd->msg_array[i]);
-      free (amd->msg_array[i]);
-    }
-  free (amd->msg_array);
-       
-  if (amd->name)
-    free (amd->name);
-
-  free (amd);
-  mailbox->data = NULL;
-  mu_monitor_unlock (mailbox->monitor);
-}
-
-static int
-amd_open (mu_mailbox_t mailbox, int flags)
-{
-  struct _amd_data *amd = mailbox->data;
-  struct stat st;
-
-  mailbox->flags = flags;
-  if (stat (amd->name, &st) < 0)
-    {
-      if ((flags & MU_STREAM_CREAT) && errno == ENOENT)
-       {
-         int rc;
-         int perms = mu_stream_flags_to_mode (flags, 1);
-         if (mkdir (amd->name, S_IRUSR|S_IWUSR|S_IXUSR|perms))
-           return errno;
-         if (stat (amd->name, &st) < 0)
-           return errno;
-         if (amd->create && (rc = amd->create (amd, flags)))
-           return rc;
-       }
-      else
-       return errno;
-    }
-  
-  if (!S_ISDIR (st.st_mode))
-    return EINVAL;
-
-  if (mailbox->locker == NULL)
-    mu_locker_create (&mailbox->locker, "/dev/null", 0);
-  
-  return 0;
-}
-
-static int
-amd_close (mu_mailbox_t mailbox)
-{
-  struct _amd_data *amd;
-  int i;
-    
-  if (!mailbox)
-    return MU_ERR_MBX_NULL;
-
-  amd = mailbox->data;
-  
-  /* Destroy all cached data */
-  amd_pool_flush (amd);
-  mu_monitor_wrlock (mailbox->monitor);
-  for (i = 0; i < amd->msg_count; i++)
-    {
-      mu_message_destroy (&amd->msg_array[i]->message, amd->msg_array[i]);
-      free (amd->msg_array[i]);
-    }
-  free (amd->msg_array);
-  amd->msg_array = NULL;
-
-  amd->msg_count = 0; /* number of messages in the list */
-  amd->msg_max = 0;   /* maximum message buffer capacity */
-
-  amd->uidvalidity = 0;
-  mu_monitor_unlock (mailbox->monitor);
-  
-  return 0;
-}
-
-static int
-amd_message_qid (mu_message_t msg, mu_message_qid_t *pqid)
-{
-  struct _amd_message *mhm = mu_message_get_owner (msg);
-  
-  return mhm->amd->cur_msg_file_name (mhm, pqid);
-}
-
-struct _amd_message *
-_amd_get_message (struct _amd_data *amd, size_t msgno)
-{
-  msgno--;
-  if (msgno >= amd->msg_count)
-    return NULL;
-  return amd->msg_array[msgno];
-}
-
-static int
-_amd_attach_message (mu_mailbox_t mailbox, struct _amd_message *mhm,
-                    mu_message_t *pmsg)
-{
-  int status;
-  mu_message_t msg;
-
-  /* Check if we already have it.  */
-  if (mhm->message)
-    {
-      if (pmsg)
-       *pmsg = mhm->message;
-      return 0;
-    }
-
-  /* Get an empty message struct.  */
-  status = mu_message_create (&msg, mhm);
-  if (status != 0)
-    return status;
-
-  /* Set the header.  */
-  {
-    mu_header_t header = NULL;
-    status = mu_header_create (&header, NULL, 0);
-    if (status != 0)
-      {
-       mu_message_destroy (&msg, mhm);
-       return status;
-      }
-    mu_header_set_fill (header, amd_header_fill, msg);
-    /*FIXME:
-    mu_header_set_get_fvalue (header, amd_header_get_fvalue, msg);
-    */
-    mu_message_set_header (msg, header, mhm);
-  }
-
-  /* Set the attribute.  */
-  {
-    mu_attribute_t attribute;
-    status = mu_attribute_create (&attribute, msg);
-    if (status != 0)
-      {
-       mu_message_destroy (&msg, mhm);
-       return status;
-      }
-    mu_attribute_set_get_flags (attribute, amd_get_attr_flags, msg);
-    mu_attribute_set_set_flags (attribute, amd_set_attr_flags, msg);
-    mu_attribute_set_unset_flags (attribute, amd_unset_attr_flags, msg);
-    mu_message_set_attribute (msg, attribute, mhm);
-  }
-
-  /* Prepare the body.  */
-  {
-    mu_body_t body = NULL;
-    struct _amd_body_stream *str;
-    
-    if ((status = mu_body_create (&body, msg)) != 0)
-      return status;
-
-    str = (struct _amd_body_stream *)
-              _mu_stream_create (sizeof (*str),
-                                mailbox->flags | MU_STREAM_SEEK | 
-                                _MU_STR_OPEN);
-    if (!str)
-      {
-       mu_body_destroy (&body, msg);
-       mu_message_destroy (&msg, mhm);
-       return ENOMEM;
-      }
-    str->stream.read = amd_body_stream_read;
-    str->stream.readdelim = amd_body_stream_readdelim;
-    str->stream.size = amd_body_stream_size;
-    str->stream.seek = amd_body_stream_seek;
-    mu_body_set_stream (body, (mu_stream_t) str, msg);
-    mu_body_clear_modified (body);
-    mu_body_set_size (body, amd_body_size, msg);
-    mu_body_set_lines (body, amd_body_lines, msg);
-    mu_message_set_body (msg, body, mhm);
-    str->body = body;
-  }
-
-  /* Set the envelope.  */
-  {
-    mu_envelope_t envelope = NULL;
-    status = mu_envelope_create (&envelope, msg);
-    if (status != 0)
-      {
-       mu_message_destroy (&msg, mhm);
-       return status;
-      }
-    mu_envelope_set_sender (envelope, amd_envelope_sender, msg);
-    mu_envelope_set_date (envelope, amd_envelope_date, msg);
-    mu_message_set_envelope (msg, envelope, mhm);
-  }
-
-  /* Set the UID.  */
-  if (mhm->amd->message_uid)
-    mu_message_set_uid (msg, mhm->amd->message_uid, mhm);
-  mu_message_set_qid (msg, amd_message_qid, mhm);
-  
-  /* Attach the message to the mailbox mbox data.  */
-  mhm->message = msg;
-  mu_message_set_mailbox (msg, mailbox, mhm);
-
-  /* Some of mu_message_set_ functions above mark message as modified.
-     Undo it now.
-
-     FIXME: Marking message as modified is not always appropriate. Find
-     a better way. */
-     
-  mu_message_clear_modified (msg);
-
-  if (pmsg)
-    *pmsg = msg;
-
-  return 0;
-}
-
-static int
-amd_get_message (mu_mailbox_t mailbox, size_t msgno, mu_message_t *pmsg)
-{
-  int status;
-  struct _amd_data *amd = mailbox->data;
-  struct _amd_message *mhm;
-
-  /* Sanity checks.  */
-  if (pmsg == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  if (amd == NULL)
-    return EINVAL;
-
-  /* If we did not start a scanning yet do it now.  */
-  if (amd->msg_count == 0)
-    {
-      status = amd->scan0 (mailbox, 1, NULL, 0);
-      if (status != 0)
-       return status;
-    }
-
-  if ((mhm = _amd_get_message (amd, msgno)) == NULL)
-    return EINVAL;
-  return _amd_attach_message (mailbox, mhm, pmsg);
-}
-
-static int
-amd_quick_get_message (mu_mailbox_t mailbox, mu_message_qid_t qid,
-                      mu_message_t *pmsg)
-{
-  int status;
-  struct _amd_data *amd = mailbox->data;
-  if (amd->msg_count)
-    {
-      mu_message_qid_t vqid;
-      mu_message_t msg = amd->msg_array[0]->message;
-      status = mu_message_get_qid (msg, &vqid);
-      if (status)
-       return status;
-      status = strcmp (qid, vqid);
-      free (vqid);
-      if (status)
-       return MU_ERR_EXISTS;
-      *pmsg = msg;
-    }
-  else if (amd->qfetch)
-    {
-      status = amd->qfetch (amd, qid);
-      if (status)
-       return status;
-      return _amd_attach_message (mailbox, amd->msg_array[0], pmsg);
-    }
-  
-  return ENOSYS;
-}
-
-static FILE *
-_amd_tempfile(struct _amd_data *amd, char **namep)
-{
-  int fd = mu_tempfile (amd->name, namep);
-  if (fd == -1)
-      return NULL;
-  return fdopen (fd, "w");
-}
-
-static int
-_amd_delim (char *str)
-{
-  if (str[0] == '-')
-    {
-      for (; *str == '-'; str++)
-       ;
-      for (; *str == ' ' || *str == '\t'; str++)
-       ;
-    }
-  return str[0] == '\n';
-}
-
-static int
-_amd_message_save (struct _amd_data *amd, struct _amd_message *mhm,
-                  int expunge)
-{
-  mu_stream_t stream = NULL;
-  char *name = NULL, *buf = NULL, *msg_name, *old_name;
-  size_t n;
-  size_t bsize;
-  size_t nlines, nbytes;
-  size_t new_body_start, new_header_lines;
-  FILE *fp;
-  mu_message_t msg = mhm->message;
-  mu_header_t hdr;
-  int status;
-  mu_attribute_t attr;
-  mu_body_t body;
-  const char *sbuf;
-  mu_envelope_t env = NULL;
-  char statbuf[MU_STATUS_BUF_SIZE];
-
-  status = mu_message_size (msg, &bsize);
-  if (status)
-    return status;
-
-  status = amd->new_msg_file_name (mhm, mhm->attr_flags, expunge, &msg_name);
-  if (status)
-    return status;
-  if (!msg_name)
-    {
-      /* Unlink the original file */
-      char *old_name;
-      status = amd->cur_msg_file_name (mhm, &old_name);
-      free (msg_name);
-      if (status == 0 && unlink (old_name))
-       status = errno;
-      free (old_name);
-      return status;
-    }      
-    
-  fp = _amd_tempfile (mhm->amd, &name);
-  if (!fp)
-    {
-      free (msg_name);
-      return errno;
-    }
-
-  /* Try to allocate large buffer */
-  for (; bsize > 1; bsize /= 2)
-    if ((buf = malloc (bsize)))
-      break;
-
-  if (!bsize)
-    {
-      unlink (name);
-      free (name);
-      free (msg_name);
-      return ENOMEM;
-    }
-
-  /* Copy flags */
-  mu_message_get_header (msg, &hdr);
-  mu_header_get_streamref (hdr, &stream);
-  status = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
-  if (status)
-    {
-      /* FIXME: Provide a common exit point for all error
-        cases */
-      unlink (name);
-      free (name);
-      free (msg_name);
-      mu_stream_destroy (&stream);
-      return status;
-    }
-      
-  nlines = nbytes = 0;
-  while ((status = mu_stream_readline (stream, buf, bsize, &n)) == 0
-        && n != 0)
-    {
-      if (_amd_delim (buf))
-       break;
-
-      if (!(mu_c_strncasecmp (buf, "status:", 7) == 0
-           || mu_c_strncasecmp (buf, "x-imapbase:", 11) == 0
-           || mu_c_strncasecmp (buf, "x-uid:", 6) == 0
-           || mu_c_strncasecmp (buf, 
-                MU_HEADER_ENV_DATE ":", sizeof (MU_HEADER_ENV_DATE)) == 0
-           || mu_c_strncasecmp (buf, 
-                MU_HEADER_ENV_SENDER ":", sizeof (MU_HEADER_ENV_SENDER)) == 0))
-       {
-         nlines++;
-         nbytes += fprintf (fp, "%s", buf);
-       }
-    }
-  mu_stream_destroy (&stream);
-  
-  /* Add imapbase */
-  if (!(amd->mailbox->flags & MU_STREAM_APPEND)
-      && amd->next_uid
-      && (!amd->msg_array || (amd->msg_array[0] == mhm))) /*FIXME*/
-    {
-      nbytes += fprintf (fp, "X-IMAPbase: %lu %u\n",
-                        (unsigned long) amd->uidvalidity,
-                        (unsigned) amd->next_uid (amd));
-      nlines++;
-    }
-  
-  mu_message_get_envelope (msg, &env);
-  if (mu_envelope_sget_date (env, &sbuf) == 0)
-    {
-      /* NOTE: buffer might be terminated with \n */
-      while (*sbuf && mu_isspace (*sbuf))
-       sbuf++;
-      nbytes += fprintf (fp, "%s: %s", MU_HEADER_ENV_DATE, sbuf);
-
-      if (*sbuf && sbuf[strlen (sbuf) - 1] != '\n')
-       nbytes += fprintf (fp, "\n");
-      
-      nlines++;
-    }
-         
-  if (mu_envelope_sget_sender (env, &sbuf) == 0)
-    {
-      fprintf (fp, "%s: %s\n", MU_HEADER_ENV_SENDER, sbuf);
-      nlines++;
-    }
-  
-  /* Add status */
-  mu_message_get_attribute (msg, &attr);
-  mu_attribute_to_string (attr, statbuf, sizeof (statbuf), &n);
-  if (n)
-    {
-      nbytes += fprintf (fp, "Status: %s\n", statbuf);
-      nlines++;
-    }
-  nbytes += fprintf (fp, "\n");
-  nlines++;
-  
-  new_header_lines = nlines;
-  new_body_start = nbytes;
-
-  /* Copy message body */
-
-  mu_message_get_body (msg, &body);
-  mu_body_get_streamref (body, &stream);
-  status = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
-  if (status)
-    {
-      unlink (name);
-      free (name);
-      free (msg_name);
-      mu_stream_destroy (&stream);
-      return status;
-    }
-    
-  nlines = 0;
-  while (mu_stream_read (stream, buf, bsize, &n) == 0 && n != 0)
-    {
-      char *p;
-      for (p = buf; p < buf + n; p++)
-       if (*p == '\n')
-         nlines++;
-      fwrite (buf, 1, n, fp);
-      nbytes += n;
-    }
-  mu_stream_destroy (&stream);
-  
-  mhm->header_lines = new_header_lines;
-  mhm->body_start = new_body_start;
-  mhm->body_lines = nlines;
-  mhm->body_end = nbytes;
-
-  free (buf);
-  fclose (fp);
-
-  status = amd->cur_msg_file_name (mhm, &old_name);
-  if (status == 0)
-    {
-      if (rename (name, msg_name))
-       status = errno;
-      else
-       {
-         mode_t perms;
-         
-         perms = mu_stream_flags_to_mode (amd->mailbox->flags, 0);
-         if (perms != 0)
-           {
-             /* It is documented that the mailbox permissions are
-                affected by the current umask, so take it into account
-                here.
-                FIXME: I'm still not sure we should honor umask, though.
-                --gray
-             */
-             mode_t mask = umask (0);
-             chmod (msg_name, (0600 | perms) & ~mask);
-             umask (mask);
-           }
-         if (strcmp (old_name, msg_name))
-           /* Unlink original message */
-           unlink (old_name);
-       }
-      free (old_name);
-      
-      mhm->orig_flags = mhm->attr_flags;
-    }
-  free (msg_name);
-  free (name);
-
-  return status;
-}
-
-static int
-amd_append_message (mu_mailbox_t mailbox, mu_message_t msg)
-{
-  int status;
-  struct _amd_data *amd = mailbox->data;
-  struct _amd_message *mhm;
-
-  if (!mailbox)
-    return MU_ERR_MBX_NULL;
-  if (!msg)
-    return EINVAL;
-
-  mhm = calloc (1, amd->msg_size);
-  if (!mhm)
-    return ENOMEM;
-    
-  /* If we did not start a scanning yet do it now.  */
-  if (amd->msg_count == 0)
-    {
-      status = amd->scan0 (mailbox, 1, NULL, 0);
-      if (status != 0)
-       {
-         free (mhm);
-         return status;
-       }
-    }
-
-  amd->has_new_msg = 1;
-  
-  mhm->amd = amd;
-  if (amd->msg_init_delivery)
-    {
-      status = amd->msg_init_delivery (amd, mhm);
-      if (status)
-       {
-         free (mhm);
-         return status;
-       }
-    }
-  
-  mhm->message = msg;
-  status = _amd_message_save (amd, mhm, 0);
-  if (status)
-    {
-      free (mhm);
-      return status;
-    }
-
-  mhm->message = NULL;
-  /* Insert and re-scan the message */
-  status = _amd_message_insert (amd, mhm);
-  if (status)
-    {
-      free (mhm);
-      return status;
-    }
-
-  if (amd->msg_finish_delivery)
-    status = amd->msg_finish_delivery (amd, mhm, msg);
-  
-  if (status == 0 && mailbox->observable)
-    {
-      char *qid;
-      if (amd->cur_msg_file_name (mhm, &qid) == 0)
-       {
-         mu_observable_notify (mailbox->observable, MU_EVT_MESSAGE_APPEND,
-                               qid);
-         free (qid);
-       }
-    }
-  
-  return status;
-}
-
-static int
-amd_messages_count (mu_mailbox_t mailbox, size_t *pcount)
-{
-  struct _amd_data *amd = mailbox->data;
-
-  if (amd == NULL)
-    return EINVAL;
-
-  if (!amd_is_updated (mailbox))
-    return amd->scan0 (mailbox,  amd->msg_count, pcount, 0);
-
-  if (pcount)
-    *pcount = amd->msg_count;
-
-  return 0;
-}
-
-/* A "recent" message is the one not marked with MU_ATTRIBUTE_SEEN
-   ('O' in the Status header), i.e. a message that is first seen
-   by the current session (see attributes.h) */
-static int
-amd_messages_recent (mu_mailbox_t mailbox, size_t *pcount)
-{
-  struct _amd_data *amd = mailbox->data;
-  size_t count, i;
-
-  /* If we did not start a scanning yet do it now.  */
-  if (amd->msg_count == 0)
-    {
-      int status = amd->scan0 (mailbox, 1, NULL, 0);
-      if (status != 0)
-       return status;
-    }
-  count = 0;
-  for (i = 0; i < amd->msg_count; i++)
-    {
-      if (MU_ATTRIBUTE_IS_UNSEEN(amd->msg_array[i]->attr_flags))
-       count++;
-    }
-  *pcount = count;
-  return 0;
-}
-
-/* An "unseen" message is the one that has not been read yet */
-static int
-amd_message_unseen (mu_mailbox_t mailbox, size_t *pmsgno)
-{
-  struct _amd_data *amd = mailbox->data;
-  size_t i;
-
-  /* If we did not start a scanning yet do it now.  */
-  if (amd->msg_count == 0)
-    {
-      int status = amd->scan0 (mailbox, 1, NULL, 0);
-      if (status != 0)
-       return status;
-    }
-
-  for (i = 0; i < amd->msg_count; i++)
-    {
-      if (MU_ATTRIBUTE_IS_UNREAD(amd->msg_array[0]->attr_flags))
-       {
-         *pmsgno = i + 1;
-         break;
-       }
-    }
-  return 0;
-}
-
-static char *
-make_size_file_name (struct _amd_data *amd)
-{
-  size_t size = strlen (amd->name) + 1 + sizeof (MU_AMD_SIZE_FILE_NAME);
-  char *name = malloc (size);
-  if (name)
-    {
-      strcpy (name, amd->name);
-      strcat (name, "/");
-      strcat (name, MU_AMD_SIZE_FILE_NAME);
-    }
-  return name;
-}
-
-static int
-read_size_file (struct _amd_data *amd, mu_off_t *psize)
-{
-  FILE *fp;
-  int rc;
-  char *name = make_size_file_name (amd);
-  if (!name)
-    return 1;
-  fp = fopen (name, "r");
-  if (fp)
-    {
-      unsigned long size;
-      if (fscanf (fp, "%lu", &size) == 1)
-       {
-         *psize = size;
-         rc = 0;
-       }
-      else
-       rc = 1;
-      fclose (fp);
-    }
-  else
-    rc = 1;
-  free (name);
-  return rc;
-}
-
-static int
-write_size_file (struct _amd_data *amd, mu_off_t size)
-{
-  FILE *fp;
-  int rc;
-  char *name = make_size_file_name (amd);
-  if (!name)
-    return 1;
-  fp = fopen (name, "w");
-  if (fp)
-    {
-      fprintf (fp, "%lu", (unsigned long) size);
-      fclose (fp);
-      rc = 0;
-    }
-  else
-    rc = 1;
-  free (name);
-  return rc;
-}
-      
-static int
-compute_mailbox_size (struct _amd_data *amd, const char *name, mu_off_t *psize)
-{
-  DIR *dir;
-  struct dirent *entry;
-  char *buf;
-  size_t bufsize;
-  size_t dirlen;
-  size_t flen;
-  int status = 0;
-  struct stat sb;
-
-  dir = opendir (name);
-  if (!dir)
-    return errno;
-
-  dirlen = strlen (name);
-  bufsize = dirlen + 32;
-  buf = malloc (bufsize);
-  if (!buf)
-    {
-      closedir (dir);
-      return ENOMEM;
-    }
-  
-  strcpy (buf, name);
-  if (buf[dirlen-1] != '/')
-    buf[++dirlen - 1] = '/';
-         
-  while ((entry = readdir (dir)))
-    {
-      switch (entry->d_name[0])
-       {
-       case '.':
-         break;
-
-       default:
-         flen = strlen (entry->d_name);
-         if (dirlen + flen + 1 > bufsize)
-           {
-             bufsize = dirlen + flen + 1;
-             buf = realloc (buf, bufsize);
-             if (!buf)
-               {
-                 status = ENOMEM;
-                 break;
-               }
-           }
-         strcpy (buf + dirlen, entry->d_name);
-         if (stat (buf, &sb) == 0)
-           {
-             if (S_ISREG (sb.st_mode))
-               *psize += sb.st_size;
-             else if (S_ISDIR (sb.st_mode))
-               compute_mailbox_size (amd, buf, psize);
-           }
-         /* FIXME: else? */
-         break;
-       }
-    }
-
-  free (buf);
-  
-  closedir (dir);
-  return 0;
-}
-
-static int
-amd_remove_mbox (mu_mailbox_t mailbox)
-{
-  int rc;
-  struct _amd_data *amd = mailbox->data;
-  
-  if (!amd->remove)
-    return ENOSYS;
-  rc = amd->remove (amd);
-  if (rc == 0)
-    {
-      char *name = make_size_file_name (amd);
-      if (!name)
-       return ENOMEM;
-      if (unlink (name) && errno != ENOENT)
-       rc = errno;
-      free (name);
-    }
-
-  if (rc == 0)
-    {
-      if (rmdir (amd->name) && errno != ENOENT)
-       {
-         rc = errno;
-         /* POSIX.1-2001 allows EEXIST to be returned if the directory
-            contained entries other than . and .. */
-         if (rc == EEXIST)
-           rc = ENOTEMPTY;
-       }
-    }
-  
-  return rc;
-}
-
-static int
-amd_expunge (mu_mailbox_t mailbox)
-{
-  struct _amd_data *amd = mailbox->data;
-  struct _amd_message *mhm;
-  size_t i;
-  int updated = amd->has_new_msg;
-  
-  if (amd == NULL)
-    return EINVAL;
-
-  if (amd->msg_count == 0)
-    return 0;
-
-  /* Find the first dirty(modified) message.  */
-  for (i = 0; i < amd->msg_count; i++)
-    {
-      mhm = amd->msg_array[i];
-      if ((mhm->attr_flags & MU_ATTRIBUTE_MODIFIED) ||
-         (mhm->attr_flags & MU_ATTRIBUTE_DELETED) ||
-         (mhm->message && mu_message_is_modified (mhm->message)))
-       break;
-    }
-
-  while (i < amd->msg_count)
-    {
-      mhm = amd->msg_array[i];
-      
-      if (mhm->attr_flags & MU_ATTRIBUTE_DELETED)
-       {
-         int rc;
-         char *old_name;
-         char *new_name;
-
-         rc = amd->cur_msg_file_name (mhm, &old_name);
-         if (rc)
-           return rc;
-         rc = amd->new_msg_file_name (mhm, mhm->attr_flags, 1,
-                                      &new_name);
-         if (rc)
-           {
-             free (old_name);
-             return rc;
-           }
-
-         if (new_name)
-           {
-             /* FIXME: It may be a good idea to have a capability flag
-                in struct _amd_data indicating that no actual removal
-                is needed (e.g. for traditional MH). It will allow to
-                bypass lots of no-op code here. */
-             if (strcmp (old_name, new_name))
-               /* Rename original message */
-               rename (old_name, new_name);
-           }
-         else
-           /* Unlink original file */
-           unlink (old_name);
-         
-         free (old_name);
-         free (new_name);
-
-         _amd_message_delete (amd, mhm);
-         updated = 1;
-         /* Do not increase i! */
-       }
-      else
-       {
-         if ((mhm->attr_flags & MU_ATTRIBUTE_MODIFIED)
-             || (mhm->message && mu_message_is_modified (mhm->message)))
-           {
-             _amd_attach_message (mailbox, mhm, NULL);
-             _amd_message_save (amd, mhm, 1);
-             updated = 1;
-           }
-         i++; /* Move to the next message */
-       }
-    }
-
-  if (updated && !amd->mailbox_size)
-    {
-      mu_off_t size = 0;
-      int rc = compute_mailbox_size (amd, amd->name, &size);
-      if (rc == 0)
-       write_size_file (amd, size);
-    }
-  return 0;
-}
-
-static int
-amd_sync (mu_mailbox_t mailbox)
-{
-  struct _amd_data *amd = mailbox->data;
-  struct _amd_message *mhm;
-  size_t i;
-  int updated = amd->has_new_msg;
-  
-  if (amd == NULL)
-    return EINVAL;
-
-  if (amd->msg_count == 0)
-    return 0;
-
-  /* Find the first dirty(modified) message.  */
-  for (i = 0; i < amd->msg_count; i++)
-    {
-      mhm = amd->msg_array[i];
-      if ((mhm->attr_flags & MU_ATTRIBUTE_MODIFIED)
-         || (mhm->message && mu_message_is_modified (mhm->message)))
-       break;
-    }
-
-  for ( ; i < amd->msg_count; i++)
-    {
-      mhm = amd->msg_array[i];
-
-      if ((mhm->attr_flags & MU_ATTRIBUTE_MODIFIED)
-         || (mhm->message && mu_message_is_modified (mhm->message)))
-       {
-         _amd_attach_message (mailbox, mhm, NULL);
-         _amd_message_save (amd, mhm, 0);
-         updated = 1;
-       }
-    }
-
-  if (updated && !amd->mailbox_size)
-    {
-      mu_off_t size = 0;
-      int rc = compute_mailbox_size (amd, amd->name, &size);
-      if (rc == 0)
-       write_size_file (amd, size);
-    }
-
-  return 0;
-}
-
-static int
-amd_uidvalidity (mu_mailbox_t mailbox, unsigned long *puidvalidity)
-{
-  struct _amd_data *amd = mailbox->data;
-  int status = amd_messages_count (mailbox, NULL);
-  if (status != 0)
-    return status;
-  /* If we did not start a scanning yet do it now.  */
-  if (amd->msg_count == 0)
-    {
-      status = amd->scan0 (mailbox, 1, NULL, 0);
-      if (status != 0)
-       return status;
-    }
-  if (puidvalidity)
-    *puidvalidity = amd->uidvalidity;
-  return 0;
-}
-
-static int
-amd_uidnext (mu_mailbox_t mailbox, size_t *puidnext)
-{
-  struct _amd_data *amd = mailbox->data;
-  int status;
-  
-  if (!amd->next_uid)
-    return ENOSYS;
-  status = mu_mailbox_messages_count (mailbox, NULL);
-  if (status != 0)
-    return status;
-  /* If we did not start a scanning yet do it now.  */
-  if (amd->msg_count == 0)
-    {
-      status = amd->scan0 (mailbox, 1, NULL, 0);
-      if (status != 0)
-       return status;
-    }
-   if (puidnext)
-     *puidnext = amd->next_uid (amd);
-  return 0;
-}
-
-/* FIXME: effectively the same as mbox_cleanup */
-void
-amd_cleanup (void *arg)
-{
-  mu_mailbox_t mailbox = arg;
-  mu_monitor_unlock (mailbox->monitor);
-  mu_locker_unlock (mailbox->locker);
-}
-
-/* Insert message msg into the message list on the appropriate position */
-int
-_amd_message_insert (struct _amd_data *amd, struct _amd_message *msg)
-{
-  size_t index;
-
-  if (amd_msg_lookup (amd, msg, &index))
-    {
-      /* Not found. Index is the index of the array cell where msg
-        must be placed */
-      int rc = amd_array_expand (amd, index);
-      if (rc)
-       return rc;
-      amd->msg_array[index] = msg;
-      msg->amd = amd;
-    }
-  else
-    {
-      /*FIXME: Found? Shouldn't happen */
-      return EEXIST;
-    }
-  return 0;
-}
-
-static void
-_amd_message_delete (struct _amd_data *amd, struct _amd_message *msg)
-{
-  size_t index;
-  struct _amd_message **pp;
-
-  if (amd_msg_lookup (amd, msg, &index))
-    {
-      /* FIXME: Not found? */
-      return;
-    }
-
-  msg = _amd_get_message (amd, index);
-
-  pp = amd_pool_lookup (msg);
-  if (pp)
-    *pp = NULL;
-  
-  mu_message_destroy (&msg->message, msg);
-  if (amd->msg_free)
-    amd->msg_free (msg);
-  free (msg);
-  amd_array_shrink (amd, index);
-}
-
-/* Scan given message and fill amd_message_t fields.
-   NOTE: the function assumes mhm->stream != NULL. */
-static int
-amd_scan_message (struct _amd_message *mhm)
-{
-  mu_stream_t stream = mhm->stream;
-  char buf[1024];
-  size_t off;
-  size_t n;
-  int status;
-  int in_header = 1;
-  size_t hlines = 0;
-  size_t blines = 0;
-  size_t body_start = 0;
-  struct stat st;
-  char *msg_name;
-
-  /* Check if the message was modified after the last scan */
-  status = mhm->amd->cur_msg_file_name (mhm, &msg_name);
-  if (status)
-    return status;
-
-  if (stat (msg_name, &st) == 0 && st.st_mtime == mhm->mtime)
-    {
-      /* Nothing to do */
-      free (msg_name);
-      return 0;
-    }
-  free (msg_name);
-
-  off = 0;
-  status = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
-  if (status == 0)
-    while ((status = mu_stream_readline (stream, buf, sizeof (buf), &n)) == 0
-          && n != 0)
-      {
-       if (in_header)
-         {
-           if (buf[0] == '\n')
-             {
-               in_header = 0;
-               body_start = off + 1;
-             }
-           if (buf[n - 1] == '\n')
-             hlines++;
-           
-           /* Process particular attributes */
-           if (mu_c_strncasecmp (buf, "status:", 7) == 0)
-             {
-               int deleted = mhm->attr_flags & MU_ATTRIBUTE_DELETED;
-               mu_string_to_flags (buf, &mhm->attr_flags);
-               mhm->attr_flags |= deleted;
-             }
-           else if (mu_c_strncasecmp (buf, "x-imapbase:", 11) == 0)
-             {
-               char *p;
-               mhm->amd->uidvalidity = strtoul (buf + 11, &p, 10);
-               /* second number is next uid. Ignored */
-             }
-         }
-       else
-         {
-           if (buf[n - 1] == '\n')
-             blines++;
-         }
-       off += n;
-      }
-
-  if (status == 0)
-    {
-      mhm->mtime = st.st_mtime;
-      if (!body_start)
-       body_start = off;
-      mhm->header_lines = hlines;
-      mhm->body_lines = blines;
-      mhm->body_start = body_start;
-      mhm->body_end = off;
-    }
-  return status;
-}
-
-static int
-amd_scan (mu_mailbox_t mailbox, size_t msgno, size_t *pcount)
-{
-  struct _amd_data *amd = mailbox->data;
-
-  if (! amd_is_updated (mailbox))
-    return amd->scan0 (mailbox, msgno, pcount, 1);
-
-  if (pcount)
-    *pcount = amd->msg_count;
-
-  return 0;
-}
-
-/* Is the internal representation of the mailbox up to date.
-   Return 1 if so, 0 otherwise. */
-static int
-amd_is_updated (mu_mailbox_t mailbox)
-{
-  struct stat st;
-  struct _amd_data *amd = mailbox->data;
-
-  if (stat (amd->name, &st) < 0)
-    return 1;
-
-  return amd->mtime == st.st_mtime;
-}
-
-static int
-amd_get_size (mu_mailbox_t mailbox, mu_off_t *psize)
-{
-  struct _amd_data *amd = mailbox->data;
-  if (amd->mailbox_size)
-    return amd->mailbox_size (mailbox, psize);
-  *psize = 0;
-  if (read_size_file (amd, psize))
-    {
-      int rc = compute_mailbox_size (amd, amd->name, psize);
-      if (rc == 0)
-       write_size_file (amd, *psize);
-      return rc;
-    }
-  return 0;
-}
-
-/* Return number of open streams residing in a message pool */
-static int
-amd_pool_open_count (struct _amd_data *amd)
-{
-  int cnt = amd->pool_last - amd->pool_first;
-  if (cnt < 0)
-    cnt += MAX_OPEN_STREAMS;
-  return cnt;
-}
-
-/* Look up a _amd_message in the pool of open messages.
-   If the message is found in the pool, returns the address of
-   the pool slot occupied by it. Otherwise returns NULL. */
-static struct _amd_message **
-amd_pool_lookup (struct _amd_message *mhm)
-{
-  struct _amd_data *amd = mhm->amd;
-  int i;
-
-  for (i = amd->pool_first; i != amd->pool_last; )
-    {
-      if (amd->msg_pool[i] == mhm)
-       return &amd->msg_pool[i];
-      if (++i == MAX_OPEN_STREAMS)
-       i = 0;
-    }
-  return NULL;
-}
-
-/* Open a stream associated with the message mhm. If the stream is
-   already open, do nothing.
-   NOTE: We could have reused the NULL holes in the msg_pool, but
-   that hardly is worth the effort, since the holes appear only when
-   expunging. On the other hand this may be useful when MAX_OPEN_STREAMS
-   size is very big. "Premature optimization is the root of all evil" */
-static int
-amd_pool_open (struct _amd_message *mhm)
-{
-  int status;
-  struct _amd_data *amd = mhm->amd;
-  if (amd_pool_lookup (mhm))
-    return 0;
-  if (amd_pool_open_count(amd) == MAX_OPEN_STREAMS-1)
-    {
-      amd_message_stream_close (amd->msg_pool[amd->pool_first++]);
-      amd->pool_first %= MAX_OPEN_STREAMS;
-    }
-  status = amd_message_stream_open (mhm);
-  if (status)
-    return status;
-  amd->msg_pool[amd->pool_last++] = mhm;
-  amd->pool_last %= MAX_OPEN_STREAMS;
-  return 0;
-}
-
-static void
-amd_pool_flush (struct _amd_data *amd)
-{
-  int i;
-  
-  for (i = amd->pool_first; i != amd->pool_last; )
-    {
-      if (amd->msg_pool[i])
-       amd_message_stream_close (amd->msg_pool[i]);
-      if (++i == MAX_OPEN_STREAMS)
-       i = 0;
-    }
-  amd->pool_first = amd->pool_last = 0;
-}
-
-/* Attach a stream to a given message structure. The latter is supposed
-   to be already added to the open message pool. */
-int
-amd_message_stream_open (struct _amd_message *mhm)
-{
-  struct _amd_data *amd = mhm->amd;
-  char *filename;
-  int status;
-  int flags = MU_STREAM_ALLOW_LINKS;
-
-  status = amd->cur_msg_file_name (mhm, &filename);
-  if (status)
-    return status;
-
-  /* The message should be at least readable */
-  if (amd->mailbox->flags & (MU_STREAM_RDWR|MU_STREAM_WRITE|MU_STREAM_APPEND))
-    flags |= MU_STREAM_RDWR;
-  else 
-    flags |= MU_STREAM_READ;
-  status = mu_file_stream_create (&mhm->stream, filename, flags);
-
-  free (filename);
-
-  if (status != 0)
-    return status;
-
-  /* FIXME: Select buffer size dynamically */
-  mu_stream_set_buffer (mhm->stream, mu_buffer_full, 16384);
-  
-  status = amd_scan_message (mhm);
-
-  return status;
-}
-
-/* Close the stream associated with the given message. */
-void
-amd_message_stream_close (struct _amd_message *mhm)
-{
-  if (mhm)
-    {
-      mu_stream_close (mhm->stream);
-      mhm->stream = NULL;
-    }
-}
-
-void
-amd_check_message (struct _amd_message *mhm)
-{
-  if (mhm->body_end == 0)
-    amd_pool_open (mhm);
-}
-
-/* Reading functions */
-static int
-amd_body_stream_read (mu_stream_t is, char *buffer, size_t buflen,
-                     size_t *pnread)
-{
-  struct _amd_body_stream *amdstr = (struct _amd_body_stream *)is;
-  mu_body_t body = amdstr->body;
-  mu_message_t msg = mu_body_get_owner (body);
-  struct _amd_message *mhm = mu_message_get_owner (msg);
-  size_t nread = 0;
-  int status = 0;
-  mu_off_t ln;
-
-  amd_pool_open (mhm);
-
-  if (buffer == NULL || buflen == 0)
-    {
-      *pnread = nread;
-      return 0;
-    }
-
-  mu_monitor_rdlock (mhm->amd->mailbox->monitor);
-#ifdef WITH_PTHREAD
-  /* read() is cancellation point since we're doing a potentially
-     long operation.  Lets make sure we clean the state.  */
-  pthread_cleanup_push (amd_cleanup, (void *)mhm->amd->mailbox);
-#endif
-
-  ln = mhm->body_end - (mhm->body_start + amdstr->off);
-  if (ln > 0)
-    {
-      nread = ((size_t)ln < buflen) ? (size_t)ln : buflen;
-      status = mu_stream_seek (mhm->stream, mhm->body_start + amdstr->off,
-                              MU_SEEK_SET, NULL);
-      if (status == 0)
-       {
-         status = mu_stream_read (mhm->stream, buffer, nread, &nread);
-         amdstr->off += nread;
-       }
-    }
-
-  *pnread = nread;
-
-  mu_monitor_unlock (mhm->amd->mailbox->monitor);
-#ifdef WITH_PTHREAD
-  pthread_cleanup_pop (0);
-#endif
-
-  return status;
-}
-
-static int
-amd_body_stream_readdelim (mu_stream_t is, char *buffer, size_t buflen,
-                          int delim,
-                          size_t *pnread)
-{
-  struct _amd_body_stream *amdstr = (struct _amd_body_stream *)is;
-  mu_body_t body = amdstr->body;
-  mu_message_t msg = mu_body_get_owner (body);
-  struct _amd_message *mhm = mu_message_get_owner (msg);
-  int status = 0;
-
-  amd_pool_open (mhm);
-
-  if (buffer == NULL || buflen == 0)
-    {
-      if (pnread)
-       *pnread = 0;
-      return 0;
-    }
-
-  mu_monitor_rdlock (mhm->amd->mailbox->monitor);
-#ifdef WITH_PTHREAD
-  /* read() is cancellation point since we're doing a potentially
-     long operation.  Lets make sure we clean the state.  */
-  pthread_cleanup_push (amd_cleanup, (void *)mhm->amd->mailbox);
-#endif
-
-  status = mu_stream_seek (mhm->stream, mhm->body_start + amdstr->off,
-                          MU_SEEK_SET, NULL);
-  if (status == 0)
-    {
-      size_t nread = 0;
-      size_t ln;
-         
-      ln = mhm->body_end - (mhm->body_start + amdstr->off) + 1;
-      if (ln > 0)
-       {
-         size_t rdsize = ((size_t)ln < buflen) ? (size_t)ln : buflen;
-         status = mu_stream_readdelim (mhm->stream, buffer, rdsize,
-                                       delim, &nread);
-         amdstr->off += nread;
-       }
-
-      if (pnread)
-       *pnread = nread;
-    }
-
-  mu_monitor_unlock (mhm->amd->mailbox->monitor);
-#ifdef WITH_PTHREAD
-  pthread_cleanup_pop (0);
-#endif
-
-  return status;
-}
-
-static int
-amd_body_stream_seek (mu_stream_t str, mu_off_t off, mu_off_t *presult)
-{
-  size_t size;
-  struct _amd_body_stream *amdstr = (struct _amd_body_stream *)str;
-  
-  amd_body_size (amdstr->body, &size);
-
-  if (off < 0 || off > size)
-    return ESPIPE;
-
-  amdstr->off = off;
-  if (presult)
-    *presult = off;
-  return 0;
-}
-
-/* Return corresponding sizes */
-
-static int
-amd_body_stream_size (mu_stream_t stream, mu_off_t *psize)
-{
-  mu_body_t body = ((struct _amd_body_stream *)stream)->body;
-  size_t size;
-  int rc = amd_body_size (body, &size);
-  if (rc == 0)
-    *psize = size;
-  return rc;
-}
-
-static int
-amd_body_size (mu_body_t body, size_t *psize)
-{
-  mu_message_t msg = mu_body_get_owner (body);
-  struct _amd_message *mhm = mu_message_get_owner (msg);
-  if (mhm == NULL)
-    return EINVAL;
-  amd_check_message (mhm);
-  if (psize)
-    *psize = mhm->body_end - mhm->body_start;
-  return 0;
-}
-
-static int
-amd_body_lines (mu_body_t body, size_t *plines)
-{
-  mu_message_t msg = mu_body_get_owner (body);
-  struct _amd_message *mhm = mu_message_get_owner (msg);
-  if (mhm == NULL)
-    return EINVAL;
-  amd_check_message (mhm);
-  if (plines)
-    *plines = mhm->body_lines;
-  return 0;
-}
-
-/* Headers */
-static int
-amd_header_fill (void *data, char **pbuf, size_t *plen)
-{
-  char *buffer;
-  size_t len;
-  mu_message_t msg = data;
-  struct _amd_message *mhm = mu_message_get_owner (msg);
-  int status, rc;
-  mu_off_t pos;
-  
-  status = amd_pool_open (mhm);
-  if (status)
-    return status;
-
-  len = mhm->body_start;
-  buffer = malloc (len);
-  if (!buffer)
-    return ENOMEM;
-  
-  status = mu_stream_seek (mhm->stream, 0, MU_SEEK_CUR, &pos);
-  if (status)
-    return status;
-  status = mu_stream_seek (mhm->stream, 0, MU_SEEK_SET, NULL);
-  if (status)
-    return status;
-
-  status = mu_stream_read (mhm->stream, buffer, len, NULL);
-  rc = mu_stream_seek (mhm->stream, pos, MU_SEEK_SET, NULL);
-
-  if (!status)
-    status = rc;
-  
-  if (status)
-    {
-      free (buffer);
-      return status;
-    }
-
-  *plen = len;
-  *pbuf = buffer;
-  return 0;
-}
-
-/* Attributes */
-static int
-amd_get_attr_flags (mu_attribute_t attr, int *pflags)
-{
-  mu_message_t msg = mu_attribute_get_owner (attr);
-  struct _amd_message *mhm = mu_message_get_owner (msg);
-
-  if (mhm == NULL)
-    return EINVAL;
-  if (pflags)
-    *pflags = mhm->attr_flags;
-  return 0;
-}
-
-static int
-amd_set_attr_flags (mu_attribute_t attr, int flags)
-{
-  mu_message_t msg = mu_attribute_get_owner (attr);
-  struct _amd_message *mhm = mu_message_get_owner (msg);
-
-  if (mhm == NULL)
-    return EINVAL;
-  mhm->attr_flags |= flags;
-  return 0;
-}
-
-static int
-amd_unset_attr_flags (mu_attribute_t attr, int flags)
-{
-  mu_message_t msg = mu_attribute_get_owner (attr);
-  struct _amd_message *mhm = mu_message_get_owner (msg);
-
-  if (mhm == NULL)
-    return EINVAL;
-  mhm->attr_flags &= ~flags;
-  return 0;
-}
-
-/* Envelope */
-static int
-amd_envelope_date (mu_envelope_t envelope, char *buf, size_t len,
-                  size_t *psize)
-{
-  mu_message_t msg = mu_envelope_get_owner (envelope);
-  struct _amd_message *mhm = mu_message_get_owner (msg);
-  mu_header_t hdr = NULL;
-  char *date;
-  int status;
-  
-  if (mhm == NULL)
-    return EINVAL;
-
-  if ((status = mu_message_get_header (msg, &hdr)) != 0)
-    return status;
-  if (mu_header_aget_value (hdr, MU_HEADER_ENV_DATE, &date)
-      && mu_header_aget_value (hdr, MU_HEADER_DELIVERY_DATE, &date))
-    return MU_ERR_NOENT;
-  else
-    {
-      time_t t;
-      int rc;
-      
-      /* Convert to ctime format */
-      rc = mu_parse_date (date, &t, NULL); /* FIXME: TZ info is lost */
-      free (date);
-      if (rc)
-       return MU_ERR_NOENT;
-      date = strdup (ctime (&t)); 
-    }
-
-  /* Format:  "sender date" */
-  if (buf && len > 0)
-    {
-      len--; /* Leave space for the null.  */
-      strncpy (buf, date, len);
-      if (strlen (date) < len)
-       {
-         len = strlen (buf);
-         if (buf[len-1] != '\n')
-           buf[len++] = '\n';
-       }
-      buf[len] = '\0';
-    }
-  else
-    len = strlen (date);
-  
-  free (date);
-  
-  if (psize)
-    *psize = len;
-  return 0;
-}
-
-static int
-amd_envelope_sender (mu_envelope_t envelope, char *buf, size_t len, size_t 
*psize)
-{
-  mu_message_t msg = mu_envelope_get_owner (envelope);
-  struct _amd_message *mhm = mu_message_get_owner (msg);
-  mu_header_t hdr = NULL;
-  char *from;
-  int status;
-
-  if (mhm == NULL)
-    return EINVAL;
-
-  if ((status = mu_message_get_header (msg, &hdr)))
-    return status;
-  if ((status = mu_header_aget_value (hdr, MU_HEADER_ENV_SENDER, &from)))
-    return status;
-
-  if (buf && len > 0)
-    {
-      int slen = strlen (from);
-
-      if (len < slen + 1)
-       slen = len - 1;
-      memcpy (buf, from, slen);
-      buf[slen] = 0;
-    }
-  else
-    len = strlen (from);
-
-  if (psize)
-    *psize = len;
-  return 0;
-}
-
-
-int
-amd_remove_dir (const char *name)
-{
-  DIR *dir;
-  struct dirent *ent;
-  char *namebuf;
-  size_t namelen, namesize;
-  int rc = 0;
-  int has_subdirs = 0;
-  
-  namelen = strlen (name);
-  namesize = namelen + 128;
-  namebuf = malloc (namesize);
-  if (!namebuf)
-    return ENOMEM;
-  memcpy (namebuf, name, namelen);
-  if (namebuf[namelen - 1] != '/')
-    namebuf[namelen++] = '/';
-  
-  dir = opendir (name);
-  if (!dir)
-    return errno;
-  while ((ent = readdir (dir)))
-    {
-      struct stat st;
-      size_t len;
-
-      if (strcmp (ent->d_name, ".") == 0 ||
-         strcmp (ent->d_name, "..") == 0)
-       continue;
-      len = strlen (ent->d_name);
-      if (namelen + len >= namesize)
-       {
-         char *p;
-
-         namesize += len + 1;
-         p = realloc (namebuf, namesize);
-         if (!p)
-           {
-             rc = ENOMEM;
-             break;
-           }
-       }
-      strcpy (namebuf + namelen, ent->d_name);
-      if (stat (namebuf, &st) == 0 && S_ISDIR (st.st_mode))
-       {
-         has_subdirs = 1;
-         continue;
-       }
-      
-      if (unlink (namebuf))
-       {
-         rc = errno;
-         mu_diag_output (MU_DIAG_WARNING,
-                         "failed to remove %s: %s",
-                         namebuf, mu_strerror (rc));
-         break;
-       }
-    }
-  closedir (dir);
-  free (namebuf);
-
-  if (rc == 0 && !has_subdirs)
-    {
-      if (rmdir (name))
-       {
-         rc = errno;
-         /* POSIX.1-2001 allows EEXIST to be returned if the directory
-            contained entries other than . and .. */
-         if (rc == EEXIST)
-           rc = ENOTEMPTY;
-       }
-    }
-  return rc;
-}
-
-
diff --git a/libmailutils/argcv.c b/libmailutils/argcv.c
deleted file mode 100644
index 636b9af..0000000
--- a/libmailutils/argcv.c
+++ /dev/null
@@ -1,549 +0,0 @@
-/* argcv.c - simple functions for parsing input based on whitespace
-   Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 2006, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <ctype.h>
-#include <errno.h>
-#include <mailutils/argcv.h>
-
-/* Keep mailutils namespace clean */
-#define argcv_get            mu_argcv_get 
-#define argcv_get_n          mu_argcv_get_n 
-#define argcv_get_np         mu_argcv_get_np 
-#define argcv_string         mu_argcv_string
-#define argcv_free           mu_argcv_free
-#define argv_free            mu_argv_free 
-#define argcv_unquote_char   mu_argcv_unquote_char
-#define argcv_quote_char     mu_argcv_quote_char  
-#define argcv_quoted_length  mu_argcv_quoted_length
-#define argcv_unquote_copy   mu_argcv_unquote_copy 
-#define argcv_quote_copy     mu_argcv_quote_copy     
-
-/*
- * takes a string and splits it into several strings, breaking at ' '
- * command is the string to split
- * the number of strings is placed into argc
- * the split strings are put into argv
- * returns 0 on success, nonzero on failure
- */
-
-#define isws(c) ((c)==' '||(c)=='\t'||(c)=='\n')
-#define isdelim(c,delim) (strchr(delim,(c))!=NULL)
-
-struct argcv_info
-{
-  int len;
-  const char *command;
-  const char *delim;
-  const char *comment;
-  int flags;
-  
-  int start;
-  int end;
-  int save;
-  int finish_pos;
-};
-
-static void
-init_argcv_info (struct argcv_info *ap, int flags,
-                int len, const char *command, const char *delim,
-                const char *comment)
-{
-  memset (ap, 0, sizeof *ap);
-  ap->len = len;
-  ap->command = command;
-  ap->delim = delim;
-  ap->comment = comment;
-  ap->flags = flags;
-}
-
-static int
-argcv_scan (struct argcv_info *ap)
-{
-  int i = 0;
-  int len = ap->len;
-  const char *command = ap->command;
-  const char *delim = ap->delim;
-  const char *comment = ap->comment;
-  
-  for (;;)
-    {
-      i = ap->save;
-
-      if (i >= len)
-       return i + 1;
-
-      /* Skip initial whitespace */
-      while (i < len && isws (command[i]))
-       i++;
-      ap->start = i;
-
-      if (!isdelim (command[i], delim))
-       {
-         while (i < len)
-           {
-             if (command[i] == '\\')
-               {
-                 if (++i == len)
-                   break;
-                 i++;
-                 continue;
-               }
-             
-             if (command[i] == '\'' || command[i] == '"')
-               {
-                 int j;
-                 for (j = i + 1; j < len && command[j] != command[i]; j++)
-                   if (command[j] == '\\')
-                     j++;
-                 if (j < len)
-                   i = j + 1;
-                 else
-                   i++;
-               }
-             else if (isws (command[i]) || isdelim (command[i], delim))
-               break;
-             else
-               i++; /* skip the escaped character */
-           }
-         i--;
-       }
-      else if (!(ap->flags & MU_ARGCV_RETURN_DELIMS))
-       {
-         while (i < len && isdelim (command[i], delim))
-           i++;
-         ap->save = i;
-         continue;
-       }
-      
-
-      ap->end = i;
-      ap->save = ap->finish_pos = i + 1;
-
-      /* If we have a token, and it starts with a comment character, skip
-         to the newline and restart the token search. */
-      if (ap->save <= len)
-       {
-         if (strchr (comment, command[ap->start]) != NULL)
-           {
-             ap->finish_pos = ap->start;
-             i = ap->save;
-             while (i < len && command[i] != '\n')
-               i++;
-
-             ap->save = i;
-             continue;
-           }
-       }
-      break;
-    }
-  return ap->save;
-}
-
-static char quote_transtab[] = "\\\\\"\"a\ab\bf\fn\nr\rt\tv\v";
-
-int
-argcv_unquote_char (int c)
-{
-  char *p;
-
-  for (p = quote_transtab; *p; p += 2)
-    {
-      if (*p == c)
-       return p[1];
-    }
-  return c;
-}
-
-int
-argcv_quote_char (int c)
-{
-  char *p;
-  
-  for (p = quote_transtab + sizeof(quote_transtab) - 2;
-       p > quote_transtab; p -= 2)
-    {
-      if (*p == c)
-       return p[-1];
-    }
-  return -1;
-}
-  
-#define to_num(c) \
-  (isdigit(c) ? c - '0' : (isxdigit(c) ? toupper(c) - 'A' + 10 : 255 ))
-
-static int
-xtonum (int *pval, const char *src, int base, int cnt)
-{
-  int i, val;
-  
-  for (i = 0, val = 0; i < cnt; i++, src++)
-    {
-      int n = *(unsigned char*)src;
-      if (n > 127 || (n = to_num(n)) >= base)
-       break;
-      val = val*base + n;
-    }
-  *pval = val;
-  return i;
-}
-
-size_t
-argcv_quoted_length (const char *str, int *quote)
-{
-  size_t len = 0;
-
-  *quote = 0;
-  for (; *str; str++)
-    {
-      if (*str == ' ')
-       {
-         len++;
-         *quote = 1;
-       }
-      else if (*str == '"')
-       {
-         len += 2;
-         *quote = 1;
-       }
-      else if (*str != '\t' && *str != '\\' && isprint (*str))
-       len++;
-      else if (argcv_quote_char (*str) != -1)
-       len += 2;
-      else
-       len += 4;
-    }
-  return len;
-}
-
-void
-argcv_unquote_copy (char *dst, const char *src, size_t n)
-{
-  int i = 0;
-  int c;
-  int expect_delim = 0; 
-    
-  while (i < n)
-    {
-      switch (src[i])
-       {
-       case '\'':
-       case '"':
-         if (!expect_delim)
-           {
-             const char *p;
-             
-             for (p = src+i+1; *p && *p != src[i]; p++)
-               if (*p == '\\')
-                 p++;
-             if (*p)
-               expect_delim = src[i++];
-             else
-               *dst++ = src[i++];
-           }
-         else if (expect_delim == src[i])
-           ++i;
-         else
-           *dst++ = src[i++];
-         break;
-         
-       case '\\':
-         ++i;
-         if (src[i] == 'x' || src[i] == 'X')
-           {
-             if (n - i < 2)
-               {
-                 *dst++ = '\\';
-                 *dst++ = src[i++];
-               }
-             else 
-               {
-                 int off = xtonum(&c, src + i + 1, 16, 2);
-                 if (off == 0)
-                   {
-                     *dst++ = '\\';
-                     *dst++ = src[i++];
-                   }
-                 else
-                   {
-                     *dst++ = c;
-                     i += off + 1;
-                   }
-               }
-           }
-         else if ((unsigned char)src[i] < 128 && isdigit (src[i]))
-           {
-             if (n - i < 1)
-               {
-                 *dst++ = '\\';
-                 *dst++ = src[i++];
-               }
-             else
-               {
-                 int off = xtonum (&c, src+i, 8, 3);
-                 if (off == 0)
-                   {
-                     *dst++ = '\\';
-                     *dst++ = src[i++];
-                   }
-                 else
-                   {
-                     *dst++ = c;
-                     i += off;
-                   }
-               }
-           }
-         else
-           *dst++ = argcv_unquote_char (src[i++]);
-         break;
-         
-       default:
-         *dst++ = src[i++];
-       }
-    }
-  *dst = 0;
-}
-
-void
-argcv_quote_copy (char *dst, const char *src)
-{
-  for (; *src; src++)
-    {
-      if (*src == '"')
-       {
-         *dst++ = '\\';
-         *dst++ = *src;
-       }
-      else if (*src != '\t' && *src != '\\' && isprint(*src))
-       *dst++ = *src;      
-      else
-       {
-         int c = argcv_quote_char (*src);
-         *dst++ = '\\';
-         if (c != -1)
-           *dst++ = c;
-         else
-           {
-             char tmp[4];
-             snprintf (tmp, sizeof tmp, "%03o", *(unsigned char*)src);
-             memcpy (dst, tmp, 3);
-             dst += 3;
-           }
-       }
-    }
-}
-
-int
-argcv_get_np (const char *command, int len,
-             const char *delim, const char *cmnt,
-             int flags,
-             int *pargc, char ***pargv, char **endp)
-{
-  int i = 0;
-  struct argcv_info info;
-  int argc;
-  char **argv;
-  
-  if (!delim)
-    delim = "";
-  if (!cmnt)
-    cmnt = "";
-
-  init_argcv_info (&info, flags, len, command, delim, cmnt);
-
-  /* Count number of arguments */
-  argc = 0;
-  while (argcv_scan (&info) <= len)
-    argc++;
-
-  argv = calloc ((argc + 1), sizeof (char *));
-  if (argv == NULL)
-    return ENOMEM;
-  
-  i = 0;
-  info.save = 0;
-  for (i = 0; i < argc; i++)
-    {
-      int n;
-      int unquote;
-      
-      argcv_scan (&info);
-
-      if ((command[info.start] == '"' || command[info.end] == '\'')
-         && command[info.end] == command[info.start])
-       {
-         if (info.start < info.end)
-           {
-             info.start++;
-             info.end--;
-           }
-         unquote = 0;
-       }
-      else
-       unquote = 1;
-      
-      n = info.end - info.start + 1;
-      argv[i] = calloc (n + 1,  sizeof (char));
-      if (argv[i] == NULL)
-       {
-         argcv_free (i, argv);
-         return ENOMEM;
-       }
-      if (unquote)
-       argcv_unquote_copy (argv[i], &command[info.start], n);
-      else
-       memcpy (argv[i], &command[info.start], n);
-      argv[i][n] = 0;
-    }
-  argv[i] = NULL;
-
-  *pargc = argc;
-  *pargv = argv;
-  if (endp)
-    *endp = (char*) (command + info.finish_pos);
-  return 0;
-}
-
-int
-argcv_get_n (const char *command, int len, const char *delim, const char *cmnt,
-            int *pargc, char ***pargv)
-{
-  return argcv_get_np (command, len, delim, cmnt, MU_ARGCV_RETURN_DELIMS,
-                      pargc, pargv, NULL);
-}
-
-int
-argcv_get (const char *command, const char *delim, const char *cmnt,
-          int *argc, char ***argv)
-{
-  return argcv_get_n (command, strlen (command), delim, cmnt, argc, argv);
-}
-
-
-/*
- * frees all elements of an argv array
- * argc is the number of elements
- * argv is the array
- */
-void
-argcv_free (int argc, char **argv)
-{
-  if (argc <= 0)
-    return;
-  while (--argc >= 0)
-    if (argv[argc])
-      free (argv[argc]);
-  free (argv);
-}
-
-void
-argv_free (char **argv)
-{
-  int i;
-
-  for (i = 0; argv[i]; i++)
-    free (argv[i]);
-  free (argv);
-}
-
-/* Make a argv an make string separated by ' '.  */
-
-int
-argcv_string (int argc, char **argv, char **pstring)
-{
-  size_t i, j, len;
-  char *buffer;
-
-  /* No need.  */
-  if (pstring == NULL)
-    return EINVAL;
-
-  buffer = malloc (1);
-  if (buffer == NULL)
-    return ENOMEM;
-  *buffer = '\0';
-
-  for (len = i = j = 0; i < argc; i++)
-    {
-      int quote;
-      int toklen;
-
-      toklen = argcv_quoted_length (argv[i], &quote);
-      
-      len += toklen + 2;
-      if (quote)
-       len += 2;
-      
-      buffer = realloc (buffer, len);
-      if (buffer == NULL)
-        return ENOMEM;
-
-      if (i != 0)
-       buffer[j++] = ' ';
-      if (quote)
-       buffer[j++] = '"';
-      argcv_quote_copy (buffer + j, argv[i]);
-      j += toklen;
-      if (quote)
-       buffer[j++] = '"';
-    }
-
-  for (; j > 0 && isspace (buffer[j-1]); j--)
-    ;
-  buffer[j] = 0;
-  if (pstring)
-    *pstring = buffer;
-  return 0;
-}
-
-void
-mu_argcv_remove (int *pargc, char ***pargv,
-                int (*sel) (const char *, void *), void *data)
-{
-  int i, j;
-  int argc = *pargc;
-  char **argv = *pargv;
-  int cnt = 0;
-  
-  for (i = j = 0; i < argc; i++)
-    {
-      if (sel (argv[i], data))
-       {
-         free (argv[i]);
-         cnt++;
-       }
-      else
-       {
-         if (i != j)
-           argv[j] = argv[i];
-         j++;
-       }
-    }
-  if (i != j)
-    argv[j] = NULL;
-  argc -= cnt;
-
-  *pargc = argc;
-  *pargv = argv;
-}
-      
- 
diff --git a/libmailutils/asnprintf.c b/libmailutils/asnprintf.c
deleted file mode 100644
index f8ef543..0000000
--- a/libmailutils/asnprintf.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#if HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <stdarg.h>
-#include <stdio.h>
-
-#include <mailutils/io.h>
-
-int
-mu_asnprintf (char **pbuf, size_t *psize, const char *fmt, ...)
-{
-  int rc;
-  va_list ap;
-
-  va_start (ap, fmt);
-  rc = mu_vasnprintf (pbuf, psize, fmt, ap);
-  va_end (ap);
-  return rc;
-}
-
diff --git a/libmailutils/asprintf.c b/libmailutils/asprintf.c
deleted file mode 100644
index c563bcb..0000000
--- a/libmailutils/asprintf.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#if HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <stdarg.h>
-#include <stdio.h>
-
-#include <mailutils/io.h>
-
-int
-mu_asprintf (char **pbuf, const char *fmt, ...)
-{
-  va_list ap;
-  size_t size;
-  int rc;
-  
-  va_start (ap, fmt);
-  *pbuf = NULL;
-  size = 0;
-  rc = mu_vasnprintf (pbuf, &size, fmt, ap);
-  va_end (ap);
-  return rc;
-}
diff --git a/libmailutils/assoc.c b/libmailutils/assoc.c
deleted file mode 100644
index a0c13a0..0000000
--- a/libmailutils/assoc.c
+++ /dev/null
@@ -1,529 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
-
-   GNU Mailutils is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3, or (at your option)
-   any later version.
-
-   GNU Mailutils is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
-
-#if HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include <mailutils/types.h>
-#include <mailutils/assoc.h>
-#include <mailutils/errno.h>
-#include <mailutils/error.h>
-#include <mailutils/iterator.h>
-#include <mailutils/mutil.h>
-#include <mailutils/cstr.h>
-#include <mailutils/sys/iterator.h>
-
-/* |hash_size| defines a sequence of symbol table sizes. These are prime
-   numbers, the distance between each pair of them grows exponentially,
-   starting from 64. Hardly someone will need more than 16411 symbols, and
-   even if someone will, it is easy enough to add more numbers to the
-   sequence. */
-
-static unsigned int hash_size[] = {
-    37,   101,  229,  487, 1009, 2039, 4091, 8191, 16411
-};
-
-/* |max_rehash| keeps the number of entries in |hash_size| table. */
-static unsigned int max_rehash = sizeof (hash_size) / sizeof (hash_size[0]);
-
-struct _mu_assoc_elem
-{
-  char *name;
-  char data[1];
-};
-
-struct _mu_assoc
-{
-  int flags;
-  unsigned int hash_num;  /* Index to hash_size table */
-  size_t elsize;          /* Size of an element */
-  void *tab;
-  mu_assoc_free_fn free;
-  mu_iterator_t itr;
-};
-
-struct _mu_assoc_elem_align
-{
-  char c;
-  struct _mu_assoc_elem x;
-};
-
-#define __ASSOC_ELEM_ALIGNMENT (mu_offsetof(struct _mu_assoc_elem_align, x))
-
-#define __ASSOC_ELEM_SIZE(a) \
-   ((a)->elsize + mu_offsetof(struct _mu_assoc_elem, data))
-#define __ASSOC_ALIGN(a, b) (((a) + (b) - 1) & ~((b) - 1))
-#define ASSOC_ELEM_SIZE(a) \
-   __ASSOC_ALIGN(__ASSOC_ELEM_SIZE(a),__ASSOC_ELEM_ALIGNMENT)
-
-#define __ASSOC_ELEM(a,p,n) \
- ((struct _mu_assoc_elem*) ((char*) (p) + ASSOC_ELEM_SIZE (a) * n))
-
-#define ASSOC_ELEM(a,n) __ASSOC_ELEM(a,(a)->tab,n)
-
-#define ASSOC_ELEM_INDEX(a,e) \
- (((char*)(e) - (char*)(a)->tab) / ASSOC_ELEM_SIZE (a))
-
-
-static unsigned
-hash (const char *name, unsigned long hash_num)
-{
-  unsigned i;
-       
-  for (i = 0; *name; name++)
-    {
-      i <<= 1;
-      i ^= *(unsigned char*) name;
-    }
-  return i % hash_size[hash_num];
-};
-
-static int
-assoc_lookup_or_install (struct _mu_assoc_elem **elp,
-                        mu_assoc_t assoc, const char *name, int *install);
-
-static int
-assoc_rehash (mu_assoc_t assoc)
-{
-  void *old_tab = assoc->tab;
-  void *new_tab;
-  unsigned int i;
-  unsigned int hash_num = assoc->hash_num + 1;
-  
-  if (hash_num >= max_rehash)
-      return MU_ERR_BUFSPACE;
-
-  new_tab = calloc (hash_size[hash_num], ASSOC_ELEM_SIZE (assoc));
-  assoc->tab = new_tab;
-  if (old_tab)
-    {
-      assoc->hash_num = hash_num;
-      for (i = 0; i < hash_size[hash_num-1]; i++)
-       {
-         struct _mu_assoc_elem *elt = __ASSOC_ELEM (assoc, old_tab, i);
-         if (elt->name)
-           {
-             int tmp;
-             struct _mu_assoc_elem *newp;
-             
-             int rc = assoc_lookup_or_install (&newp, assoc, elt->name, &tmp);
-             if (rc)
-               return rc;
-             newp->name = elt->name;
-             memcpy(newp->data, elt->data, assoc->elsize);
-           }
-       }
-      free (old_tab);
-    }
-  return 0;
-}
-
-static void
-assoc_free_elem (mu_assoc_t assoc, struct _mu_assoc_elem *elem)
-{
-  if (assoc->free)
-    assoc->free (elem->data);
-  if (!(assoc->flags & MU_ASSOC_COPY_KEY))
-    free (elem->name);
-}
-
-static int
-assoc_remove (mu_assoc_t assoc, struct _mu_assoc_elem *elem)
-{
-  unsigned int i, j, r;
-
-  if (!(ASSOC_ELEM (assoc, 0) <= elem
-       && elem < ASSOC_ELEM (assoc, hash_size[assoc->hash_num])))
-    return EINVAL;
-
-  assoc_free_elem (assoc, elem);
-  
-  for (i = ASSOC_ELEM_INDEX (assoc, elem);;)
-    {
-      struct _mu_assoc_elem *p = ASSOC_ELEM (assoc, i);
-      p->name = NULL;
-      j = i;
-
-      do
-       {
-         if (++i >= hash_size[assoc->hash_num])
-           i = 0;
-         p = ASSOC_ELEM (assoc, i);
-         if (!p->name)
-           return 0;
-         r = hash (p->name, assoc->hash_num);
-       }
-      while ((j < r && r <= i) || (i < j && j < r) || (r <= i && i < j));
-
-      if (j != i)
-             memcpy (ASSOC_ELEM (assoc, j), ASSOC_ELEM (assoc, i),
-                     assoc->elsize);
-    }
-  return 0;
-}
-
-#define name_cmp(assoc,a,b) (((assoc)->flags & MU_ASSOC_ICASE) ? \
-                             mu_c_strcasecmp(a,b) : strcmp(a,b))
-
-static int
-assoc_lookup_or_install (struct _mu_assoc_elem **elp,
-                        mu_assoc_t assoc, const char *name, int *install)
-{
-  int rc;
-  unsigned i, pos;
-  struct _mu_assoc_elem *elem;
-  
-  if (!assoc->tab)
-    {
-      if (install)
-       {
-         rc = assoc_rehash (assoc);
-         if (rc)
-           return rc;
-       }
-      else
-       return MU_ERR_NOENT;
-    }
-
-  pos = hash (name, assoc->hash_num);
-
-  for (i = pos; (elem = ASSOC_ELEM (assoc, i))->name;)
-    {
-      if (name_cmp (assoc, elem->name, name) == 0)
-       {
-         if (install)
-           *install = 0;
-         *elp = elem;
-         return 0;
-       }
-      
-      if (++i >= hash_size[assoc->hash_num])
-       i = 0;
-      if (i == pos)
-       break;
-    }
-
-  if (!install)
-    return MU_ERR_NOENT;
-  
-  if (elem->name == NULL)
-    {
-      *install = 1;
-      if (assoc->flags & MU_ASSOC_COPY_KEY)
-       elem->name = (char *) name;
-      else
-       {
-         elem->name = strdup (name);
-         if (!elem->name)
-           return ENOMEM;
-       }
-      *elp = elem;
-      return 0; 
-    }
-
-  if ((rc = assoc_rehash (assoc)) != 0)
-    return rc;
-
-  return assoc_lookup_or_install (elp, assoc, name, install);
-}
-
-int
-mu_assoc_create (mu_assoc_t *passoc, size_t elsize, int flags)
-{
-  mu_assoc_t assoc = calloc (1, sizeof (*assoc));
-  if (!assoc)
-    return ENOMEM;
-  assoc->flags = flags;
-  assoc->elsize = elsize;
-  *passoc = assoc;
-  return 0;
-}
-
-void
-mu_assoc_clear (mu_assoc_t assoc)
-{
-  unsigned i, hs;
-  
-  if (!assoc || !assoc->tab)
-    return;
-
-  hs = hash_size[assoc->hash_num];
-  for (i = 0; i < hs; i++)
-    {
-      struct _mu_assoc_elem *elem = ASSOC_ELEM (assoc, i);
-      if (elem->name)
-       {
-         assoc_free_elem (assoc, elem);
-         elem->name = NULL;
-       }
-    }
-}
-
-void
-mu_assoc_destroy (mu_assoc_t *passoc)
-{
-  mu_assoc_t assoc;
-  if (passoc && (assoc = *passoc) != NULL)
-    {
-      mu_assoc_clear (assoc);
-      free (assoc->tab);
-      free (assoc);
-      *passoc = NULL;
-    }
-}
-
-int
-mu_assoc_set_free (mu_assoc_t assoc, mu_assoc_free_fn fn)
-{
-  if (!assoc)
-    return EINVAL;
-  assoc->free = fn;
-  return 0;
-}
-
-void *
-mu_assoc_ref (mu_assoc_t assoc, const char *name)
-{
-  int rc;
-  static struct _mu_assoc_elem *elp;
-
-  if (!assoc || !name)
-    return NULL;
-  
-  rc = assoc_lookup_or_install (&elp, assoc, name, NULL);
-  if (rc == 0)
-    return elp->data;
-  return NULL;
-}
-
-int
-mu_assoc_install (mu_assoc_t assoc, const char *name, void *value)
-{
-  int rc;
-  int inst;
-  static struct _mu_assoc_elem *elp;
-
-  if (!assoc || !name)
-    return EINVAL;
-
-  rc = assoc_lookup_or_install (&elp, assoc, name, &inst);
-  if (rc)
-    return rc;
-  if (!inst)
-    return MU_ERR_EXISTS;
-  memcpy (elp->data, value, assoc->elsize);
-  return 0;
-}
-
-int
-mu_assoc_ref_install (mu_assoc_t assoc, const char *name, void **pval)
-{
-  int rc;
-  int inst;
-  static struct _mu_assoc_elem *elp;
-
-  if (!assoc || !name)
-    return EINVAL;
-
-  rc = assoc_lookup_or_install (&elp, assoc, name, &inst);
-  if (rc)
-    return rc;
-  *pval = elp->data;
-  return inst ? 0 : MU_ERR_EXISTS;
-}  
-
-int
-mu_assoc_remove (mu_assoc_t assoc, const char *name)
-{
-  int rc;
-  static struct _mu_assoc_elem *elem;
-
-  if (!assoc || !name)
-    return EINVAL;
-  rc = assoc_lookup_or_install (&elem, assoc, name, NULL);
-  if (rc)
-    return rc;
-  return assoc_remove (assoc, elem);
-}
-
-#define OFFSET(s,f) (size_t)(&((s*)0)->f)
-
-int
-mu_assoc_remove_ref (mu_assoc_t assoc, void *data)
-{
-  struct _mu_assoc_elem *elem;
-
-  elem = (struct _mu_assoc_elem *) ((char*)data -
-                                   OFFSET(struct _mu_assoc_elem, data));
-  return assoc_remove (assoc, elem);
-}
-
-
-/* Iterator interface */
-
-struct assoc_iterator
-{
-  mu_assoc_t assoc;
-  unsigned start;
-  unsigned index;
-};
-
-static int
-first (void *owner)
-{
-  struct assoc_iterator *itr = owner;
-  mu_assoc_t assoc = itr->assoc;
-  unsigned hash_max = hash_size[assoc->hash_num];
-  unsigned i;
-  
-  for (i = 0; i < hash_max; i++)
-    if ((ASSOC_ELEM (assoc, i))->name)
-      break;
-  itr->index = i;
-  return 0;
-}
-
-static int
-next (void *owner)
-{
-  struct assoc_iterator *itr = owner;
-  mu_assoc_t assoc = itr->assoc;
-  unsigned hash_max = hash_size[assoc->hash_num];
-  unsigned i;
-  
-  for (i = itr->index + 1; i < hash_max; i++)
-    if ((ASSOC_ELEM (assoc, i))->name)
-      break;
-
-  itr->index = i;
-  return 0;
-}
-
-static int
-getitem (void *owner, void **pret, const void **pkey)
-{
-  struct assoc_iterator *itr = owner;
-  struct _mu_assoc_elem *elem;
-
-  if (itr->index >= hash_size[itr->assoc->hash_num])
-    return EINVAL;
-  elem = ASSOC_ELEM (itr->assoc, itr->index);
-  *pret = elem->data;
-  if (pkey)
-    *pkey = elem->name;
-  return 0;
-}
-
-static int
-finished_p (void *owner)
-{
-  struct assoc_iterator *itr = owner;
-  return itr->index >= hash_size[itr->assoc->hash_num];
-}
-
-static int
-destroy (mu_iterator_t iterator, void *data)
-{
-  struct assoc_iterator *itr = data;
-  mu_iterator_detach (&itr->assoc->itr, iterator);
-  free (data);
-  return 0;
-}
-
-static int
-curitem_p (void *owner, void *item)
-{
-  struct assoc_iterator *itr = owner;
-  mu_assoc_t assoc = itr->assoc;
-  struct _mu_assoc_elem *elem = ASSOC_ELEM (assoc, itr->index);
-  
-  return elem == item;
-}
-
-static int
-assoc_data_dup (void **ptr, void *owner)
-{
-  *ptr = malloc (sizeof (struct assoc_iterator));
-  if (*ptr == NULL)
-    return ENOMEM;
-  memcpy (*ptr, owner, sizeof (struct assoc_iterator));
-  return 0;
-}
-
-int
-mu_assoc_get_iterator (mu_assoc_t assoc, mu_iterator_t *piterator)
-{
-  mu_iterator_t iterator;
-  int status;
-  struct assoc_iterator *itr;
-
-  if (!assoc)
-    return EINVAL;
-
-  itr = calloc (1, sizeof *itr);
-  if (!itr)
-    return ENOMEM;
-  itr->assoc = assoc;
-  itr->index = 0;
-
-  status = mu_iterator_create (&iterator, itr);
-  if (status)
-    {
-      free (itr);
-      return status;
-    }
-
-  mu_iterator_set_first (iterator, first);
-  mu_iterator_set_next (iterator, next);
-  mu_iterator_set_getitem (iterator, getitem);
-  mu_iterator_set_finished_p (iterator, finished_p);
-  mu_iterator_set_curitem_p (iterator, curitem_p);
-  mu_iterator_set_destroy (iterator, destroy);
-  mu_iterator_set_dup (iterator, assoc_data_dup);
-  
-  mu_iterator_attach (&assoc->itr, iterator);
-
-  *piterator = iterator;
-  return 0;
-}  
-
-
-
-int
-mu_assoc_count (mu_assoc_t assoc, size_t *pcount)
-{
-  mu_iterator_t itr;
-  int rc;
-  size_t count = 0;
-  
-  if (!assoc || !pcount)
-    return EINVAL;
-  rc = mu_assoc_get_iterator (assoc, &itr);
-  if (rc)
-    return rc;
-  for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
-       mu_iterator_next (itr))
-    count++;
-  mu_iterator_destroy (&itr);
-  *pcount = count;
-  return 0;
-}
-
diff --git a/libmailutils/attachment.c b/libmailutils/attachment.c
deleted file mode 100644
index c642681..0000000
--- a/libmailutils/attachment.c
+++ /dev/null
@@ -1,461 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#ifdef HAVE_LIBGEN_H
-# include <libgen.h>
-#endif
-
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
-#endif
-
-#include <mailutils/cctype.h>
-#include <mailutils/cstr.h>
-#include <mailutils/body.h>
-#include <mailutils/filter.h>
-#include <mailutils/header.h>
-#include <mailutils/message.h>
-#include <mailutils/stream.h>
-#include <mailutils/errno.h>
-#include <mailutils/mutil.h>
-
-#define BUF_SIZE       2048
-
-struct _mu_mime_io_buffer
-{
-  unsigned int refcnt;
-  char *buf;
-  size_t bufsize;
-  char *charset;
-  mu_header_t hdr;
-  mu_message_t msg;
-  mu_stream_t stream;  /* output file/decoding stream for saving attachment */
-  mu_stream_t fstream; /* output file stream for saving attachment */
-};
-
-#define MSG_HDR "Content-Type: %s; name=%s\nContent-Transfer-Encoding: 
%s\nContent-Disposition: attachment; filename=%s\n\n"
-
-int
-mu_message_create_attachment (const char *content_type, const char *encoding,
-                             const char *filename, mu_message_t *newmsg)
-{
-  mu_header_t hdr;
-  mu_body_t body;
-  mu_stream_t fstream = NULL, tstream = NULL;
-  char *header = NULL, *name = NULL, *fname = NULL;
-  int ret;
-
-  if (newmsg == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  if (filename == NULL)
-    return EINVAL;
-
-  if ((ret = mu_message_create (newmsg, NULL)) == 0)
-    {
-      if (content_type == NULL)
-       content_type = "text/plain";
-      if (encoding == NULL)
-       encoding = "7bit";
-      if ((fname = strdup (filename)) != NULL)
-       {
-         name = strrchr (fname, '/');
-         if (name)
-           name++;
-         else
-           name = fname;
-         if ((header =
-              malloc (strlen (MSG_HDR) + strlen (content_type) +
-                      strlen (name) * 2 + strlen (encoding) + 1)) == NULL)
-           ret = ENOMEM;
-         else
-           {
-             sprintf (header, MSG_HDR, content_type, name, encoding, name);
-             if ((ret = mu_header_create (&hdr, header, strlen (header)))
-                 == 0)
-               {
-                 mu_message_get_body (*newmsg, &body);
-                 if ((ret =
-                      mu_file_stream_create (&fstream, filename,
-                                             MU_STREAM_READ)) == 0)
-                   {
-                     if ((ret =
-                          mu_filter_create (&tstream, fstream, encoding,
-                                            MU_FILTER_ENCODE,
-                                            MU_STREAM_READ)) == 0)
-                       {
-                         mu_body_set_stream (body, tstream, *newmsg);
-                         mu_message_set_header (*newmsg, hdr, NULL);
-                       }
-                   }
-               }
-             free (header);
-           }
-       }
-    }
-  if (ret)
-    {
-      if (*newmsg)
-       mu_message_destroy (newmsg, NULL);
-      if (hdr)
-       mu_header_destroy (&hdr);
-      if (fstream)
-       mu_stream_destroy (&fstream);
-      if (fname)
-       free (fname);
-    }
-  return ret;
-}
-
-int
-mu_mime_io_buffer_create (mu_mime_io_buffer_t *pinfo)
-{
-  mu_mime_io_buffer_t info;
-  
-  if ((info = calloc (1, sizeof (*info))) == NULL)
-    return ENOMEM;
-  info->refcnt = 1;
-  info->bufsize = BUF_SIZE;
-  *pinfo = info;
-  return 0;
-}
-
-void
-mu_mime_io_buffer_set_size (mu_mime_io_buffer_t info, size_t size)
-{
-  info->bufsize = size;
-}
-
-void
-mu_mime_io_buffer_get_size (mu_mime_io_buffer_t info, size_t *psize)
-{
-  *psize = info->bufsize;
-}
-
-int
-mu_mime_io_buffer_set_charset (mu_mime_io_buffer_t info, const char *charset)
-{
-  char *cp = strdup (charset);
-  if (!cp)
-    return ENOMEM;
-  free (info->charset);
-  info->charset = cp;
-  return 0;
-}
-
-void
-mu_mime_io_buffer_sget_charset (mu_mime_io_buffer_t info, const char **charset)
-{
-  *charset = info->charset;
-}
-
-int
-mu_mime_io_buffer_aget_charset (mu_mime_io_buffer_t info, const char **charset)
-{
-  *charset = strdup (info->charset);
-  if (!charset)
-    return ENOMEM;
-  return 0;
-}
-
-void
-mu_mime_io_buffer_destroy (mu_mime_io_buffer_t *pinfo)
-{
-  if (pinfo && *pinfo)
-    {
-      mu_mime_io_buffer_t info = *pinfo;
-      free (info->charset);
-      free (info->buf);
-      free (info);
-      *pinfo = NULL;
-    }
-}
-
-static void
-_attachment_free (struct _mu_mime_io_buffer *info, int free_message)
-{
-  if (free_message)
-    {
-      if (info->msg)
-       mu_message_destroy (&info->msg, NULL);
-      else if (info->hdr)
-       mu_header_destroy (&info->hdr);
-    }
-  info->msg = NULL;
-  info->hdr = NULL;
-  info->stream = NULL;
-  info->fstream = NULL;
-  if (--info->refcnt == 0)
-    {
-      free (info->charset);
-      free (info->buf);
-      free (info);
-    }
-}
-
-static int
-_attachment_setup (mu_mime_io_buffer_t *pinfo, mu_message_t msg,
-                  mu_stream_t *pstream)
-{
-  int ret;
-  mu_body_t body;
-  mu_mime_io_buffer_t info;
-  mu_stream_t stream;
-    
-  if ((ret = mu_message_get_body (msg, &body)) != 0 ||
-      (ret = mu_body_get_streamref (body, &stream)) != 0)
-    return ret;
-  ret = mu_stream_seek (stream, 0, SEEK_SET, NULL);
-  if (ret)
-    return ret;
-  *pstream = stream;
-  if (*pinfo)
-    {
-      info = *pinfo;
-      info->refcnt++;
-    }
-  else
-    {
-      ret = mu_mime_io_buffer_create (&info);
-      if (ret)
-       return ret;
-    }
-  
-  if (!info->buf && ((info->buf = malloc (info->bufsize)) == NULL))
-    {
-      _attachment_free (info, 0);
-      return ENOMEM;
-    }
-  info->msg = msg;
-  *pinfo = info;
-  return 0;
-}
-
-int
-mu_message_save_attachment (mu_message_t msg, const char *filename,
-                           mu_mime_io_buffer_t info)
-{
-  mu_stream_t istream;
-  int ret;
-  size_t size;
-  size_t nbytes;
-  mu_header_t hdr;
-  const char *fname = NULL;
-  char *partname = NULL;
-
-  if (msg == NULL)
-    return EINVAL;
-
-  if ((ret = _attachment_setup (&info, msg, &istream)) != 0)
-    return ret;
-
-  if (ret == 0 && (ret = mu_message_get_header (msg, &hdr)) == 0)
-    {
-      if (filename == NULL)
-       {
-         ret = mu_message_aget_decoded_attachment_name (msg, info->charset,
-                                                        &partname, NULL);
-         if (partname)
-           fname = partname;
-       }
-      else
-       fname = filename;
-      if (fname
-         && (ret =
-             mu_file_stream_create (&info->fstream, fname,
-                                    MU_STREAM_WRITE | MU_STREAM_CREAT)) == 0)
-       {
-         char *content_encoding;
-         char *content_encoding_mem = NULL;
-         
-         mu_header_get_value (hdr, "Content-Transfer-Encoding", NULL, 0,
-                              &size);
-         if (size)
-           {
-             content_encoding_mem = malloc (size + 1);
-             if (content_encoding_mem == NULL)
-               ret = ENOMEM;
-             content_encoding = content_encoding_mem;
-             mu_header_get_value (hdr, "Content-Transfer-Encoding",
-                                  content_encoding, size + 1, 0);
-           }
-         else
-           content_encoding = "7bit";
-         ret =
-           mu_filter_create (&info->stream, istream, content_encoding,
-                             MU_FILTER_DECODE,
-                             MU_STREAM_READ);
-         free (content_encoding_mem);
-       }
-    }
-  if (info->stream && istream)
-    {
-      while (((ret =
-              mu_stream_read (info->stream, info->buf, BUF_SIZE, 
-                              &nbytes)) == 0 && nbytes))
-       {
-         if ((ret =
-              mu_stream_write (info->fstream, info->buf, nbytes, NULL)) != 0)
-           break;
-       }
-    }
-  if (ret != EAGAIN && info)
-    {
-      mu_stream_close (info->fstream);
-      mu_stream_destroy (&info->stream);
-      mu_stream_destroy (&info->fstream);
-    }
-
-  mu_stream_destroy (&istream);
-  _attachment_free (info, ret); /* FIXME: or 0? */
-  
-  /* Free fname if we allocated it. */
-  if (partname)
-    free (partname);
-
-  return ret;
-}
-
-int
-mu_message_encapsulate (mu_message_t msg, mu_message_t *newmsg,
-                       mu_mime_io_buffer_t info)
-{
-  mu_stream_t istream, ostream;
-  const char *header;
-  int ret = 0;
-  size_t nbytes;
-  mu_message_t tmsg = NULL;
-  
-  if (newmsg == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-
-  if (msg == NULL)
-    {
-      mu_header_t hdr;
-      
-      ret = mu_message_create (&tmsg, NULL);
-      if (ret)
-       return ret;
-      msg = tmsg;
-      header =
-       "Content-Type: message/rfc822\nContent-Transfer-Encoding: 7bit\n\n";
-      if ((ret =
-          mu_header_create (&hdr, header, strlen (header))) == 0)
-       ret = mu_message_set_header (msg, hdr, NULL);
-      if (ret)
-       {
-         mu_message_destroy (&msg, NULL);
-         return ret;
-       }
-    }
-      
-  if ((ret = _attachment_setup (&info, msg, &ostream)) != 0)
-    {
-      mu_message_destroy (&tmsg, NULL);
-      return ret;
-    }
-
-  if (ret == 0 && (ret = mu_message_get_streamref (msg, &istream)) == 0)
-    {
-      mu_stream_seek (istream, 0, MU_SEEK_SET, NULL);
-      while (((ret = mu_stream_read (istream, info->buf, BUF_SIZE, 
-                                    &nbytes)) == 0 && nbytes))
-       {
-         if ((ret =
-              mu_stream_write (ostream, info->buf, nbytes, NULL)) != 0)
-           break;
-       }
-      mu_stream_destroy (&istream);
-    }
-  if (ret == 0)
-    *newmsg = info->msg;
-  mu_stream_destroy (&ostream);
-  _attachment_free (info, ret && ret != EAGAIN);
-  return ret;
-}
-
-#define MESSAGE_RFC822_STR "message/rfc822"
-
-int
-mu_message_unencapsulate (mu_message_t msg, mu_message_t *newmsg,
-                         mu_mime_io_buffer_t info)
-{
-  size_t size, nbytes;
-  int ret = 0;
-  mu_header_t hdr;
-  mu_stream_t istream, ostream;
-
-  if (msg == NULL)
-    return EINVAL;
-  if (newmsg == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-
-  if (info == NULL /* FIXME: not needed? */
-      && (ret = mu_message_get_header (msg, &hdr)) == 0)
-    {
-      mu_header_get_value (hdr, "Content-Type", NULL, 0, &size);
-      if (size)
-       {
-         char *content_type;
-         if ((content_type = malloc (size + 1)) == NULL)
-           return ENOMEM;
-         mu_header_get_value (hdr, "Content-Type", content_type, size + 1,
-                              0);
-         ret = mu_c_strncasecmp (content_type, MESSAGE_RFC822_STR,
-                                 sizeof (MESSAGE_RFC822_STR) - 1);
-         free (content_type);
-         if (ret != 0)
-           return EINVAL;
-       }
-      else
-       return EINVAL;
-    }
-  if ((ret = _attachment_setup (&info, msg, &istream)) != 0)
-    return ret;
-  if (info->msg == NULL)
-    ret = mu_message_create (&info->msg, NULL);
-  if (ret == 0)
-    {
-      mu_message_get_streamref (info->msg, &ostream);
-      mu_stream_seek (ostream, 0, MU_SEEK_SET, NULL);
-      while (((ret =
-              mu_stream_read (istream, info->buf, BUF_SIZE, 
-                              &nbytes)) == 0 && nbytes))
-       {
-         if ((ret =
-              mu_stream_write (ostream, info->buf, nbytes, NULL)) != 0)
-           break;
-       }
-      mu_stream_destroy (&ostream);
-    }
-  if (ret == 0)
-    *newmsg = info->msg;
-  mu_stream_destroy (&istream);
-  _attachment_free (info, ret && ret != EAGAIN);
-  return ret;
-}
diff --git a/libmailutils/attribute.c b/libmailutils/attribute.c
deleted file mode 100644
index 3e76855..0000000
--- a/libmailutils/attribute.c
+++ /dev/null
@@ -1,470 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <sys/types.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
-#endif
-
-#include <mailutils/errno.h>
-#include <mailutils/mutil.h>
-#include <mailutils/cstr.h>
-#include <mailutils/sys/attribute.h>
-
-int
-mu_attribute_create (mu_attribute_t *pattr, void *owner)
-{
-  mu_attribute_t attr;
-  if (pattr == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  attr = calloc (1, sizeof(*attr));
-  if (attr == NULL)
-    return ENOMEM;
-  attr->owner = owner;
-  *pattr = attr;
-  return 0;
-}
-
-void
-mu_attribute_destroy (mu_attribute_t *pattr, void *owner)
-{
-  if (pattr && *pattr)
-    {
-      mu_attribute_t attr = *pattr;
-      if (attr->owner == owner)
-       free (*pattr);
-      /* Loose the link */
-      *pattr = NULL;
-    }
-}
-
-void *
-mu_attribute_get_owner (mu_attribute_t attr)
-{
-  return (attr) ? attr->owner : NULL;
-}
-
-int
-mu_attribute_is_modified (mu_attribute_t attr)
-{
-  return (attr) ? attr->flags & MU_ATTRIBUTE_MODIFIED : 0;
-}
-
-int
-mu_attribute_clear_modified (mu_attribute_t attr)
-{
-  if (attr)
-    attr->flags &= ~MU_ATTRIBUTE_MODIFIED;
-  return 0;
-}
-
-int
-mu_attribute_set_modified (mu_attribute_t attr)
-{
-  if (attr)
-    attr->flags |= MU_ATTRIBUTE_MODIFIED;
-  return 0;
-}
-
-int
-mu_attribute_get_flags (mu_attribute_t attr, int *pflags)
-{
-  if (attr == NULL)
-    return EINVAL;
-  if (pflags == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  if (attr->_get_flags)
-    return attr->_get_flags (attr, pflags);
-  *pflags = attr->flags;
-  return 0;
-}
-
-int
-mu_attribute_set_flags (mu_attribute_t attr, int flags)
-{
-  int status = 0;
-  int oflags = 0;
-  
-  if (attr == NULL)
-    return EINVAL;
-
-  /* If the required bits are already set, do not modify anything */
-  mu_attribute_get_flags (attr, &oflags);
-  if ((oflags & flags) == flags)
-    return 0;
-  
-  if (attr->_set_flags)
-    status = attr->_set_flags (attr, flags);
-  else
-    attr->flags |= flags;
-  if (status == 0)
-    mu_attribute_set_modified (attr);
-  return 0;
-}
-
-int
-mu_attribute_unset_flags (mu_attribute_t attr, int flags)
-{
-  int status = 0;
-  int oflags = 0;
-
-  if (attr == NULL)
-    return EINVAL;
-
-  /* If the required bits are already cleared, do not modify anything */
-  mu_attribute_get_flags (attr, &oflags);
-  if ((oflags & flags) == 0)
-    return 0;
-
-  if (attr->_unset_flags)
-    status = attr->_unset_flags (attr, flags);
-  else
-    attr->flags &= ~flags;
-  if (status == 0)
-    mu_attribute_set_modified (attr);
-  return 0;
-}
-
-int
-mu_attribute_set_get_flags (mu_attribute_t attr, int (*_get_flags)
-                        (mu_attribute_t, int *), void *owner)
-{
-  if (attr == NULL)
-    return EINVAL;
-  if (attr->owner != owner)
-    return EACCES;
-  attr->_get_flags = _get_flags;
-  return 0;
-}
-
-int
-mu_attribute_set_set_flags (mu_attribute_t attr, int (*_set_flags)
-                        (mu_attribute_t, int), void *owner)
-{
-  if (attr == NULL)
-    return EINVAL;
-  if (attr->owner != owner)
-    return EACCES;
-  attr->_set_flags = _set_flags;
-  return 0;
-}
-
-int
-mu_attribute_set_unset_flags (mu_attribute_t attr, int (*_unset_flags)
-                        (mu_attribute_t, int), void *owner)
-{
-  if (attr == NULL)
-    return EINVAL;
-  if (attr->owner != owner)
-    return EACCES;
-  attr->_unset_flags = _unset_flags;
-  return 0;
-}
-
-/* We add support for "USER" flag, it is a way for external objects
-   Not being the owner to add custom flags.  */
-int
-mu_attribute_set_userflag (mu_attribute_t attr, int flag)
-{
-  if (attr == NULL)
-    return EINVAL;
-  attr->user_flags |= flag;
-  return 0;
-}
-
-int
-mu_attribute_set_seen (mu_attribute_t attr)
-{
-  return mu_attribute_set_flags (attr, MU_ATTRIBUTE_SEEN);
-}
-
-int
-mu_attribute_set_answered (mu_attribute_t attr)
-{
-  return mu_attribute_set_flags (attr, MU_ATTRIBUTE_ANSWERED);
-}
-
-int
-mu_attribute_set_flagged (mu_attribute_t attr)
-{
-  return mu_attribute_set_flags (attr, MU_ATTRIBUTE_FLAGGED);
-}
-
-int
-mu_attribute_set_read (mu_attribute_t attr)
-{
-  return mu_attribute_set_flags (attr, MU_ATTRIBUTE_READ);
-}
-
-int
-mu_attribute_set_deleted (mu_attribute_t attr)
-{
-  return mu_attribute_set_flags (attr, MU_ATTRIBUTE_DELETED);
-}
-
-int
-mu_attribute_set_draft (mu_attribute_t attr)
-{
-  return mu_attribute_set_flags (attr, MU_ATTRIBUTE_DRAFT);
-}
-
-int
-mu_attribute_set_recent (mu_attribute_t attr)
-{
-  int status = mu_attribute_unset_flags (attr, MU_ATTRIBUTE_READ);
-  if (status == 0)
-    status = mu_attribute_unset_flags (attr, MU_ATTRIBUTE_SEEN);
-  return status;
-}
-
-int
-mu_attribute_is_userflag (mu_attribute_t attr, int flag)
-{
-  if (attr == NULL)
-    return 0;
-  return attr->user_flags & flag;
-}
-
-int
-mu_attribute_is_seen (mu_attribute_t attr)
-{
-  int flags = 0;
-  if (mu_attribute_get_flags (attr, &flags) == 0)
-    return flags & MU_ATTRIBUTE_SEEN;
-  return 0;
-}
-
-int
-mu_attribute_is_answered (mu_attribute_t attr)
-{
-  int flags = 0;
-  if (mu_attribute_get_flags (attr, &flags) == 0)
-    return flags & MU_ATTRIBUTE_ANSWERED;
-  return 0;
-}
-
-int
-mu_attribute_is_flagged (mu_attribute_t attr)
-{
-  int flags = 0;
-  if (mu_attribute_get_flags (attr, &flags) == 0)
-    return flags & MU_ATTRIBUTE_FLAGGED;
-  return 0;
-}
-
-int
-mu_attribute_is_read (mu_attribute_t attr)
-{
-  int flags = 0;
-  if (mu_attribute_get_flags (attr, &flags) == 0)
-    return flags & MU_ATTRIBUTE_READ;
-  return 0;
-}
-
-int
-mu_attribute_is_deleted (mu_attribute_t attr)
-{
-  int flags = 0;
-  if (mu_attribute_get_flags (attr, &flags) == 0)
-    return flags & MU_ATTRIBUTE_DELETED;
-  return 0;
-}
-
-int
-mu_attribute_is_draft (mu_attribute_t attr)
-{
-  int flags = 0;
-  if (mu_attribute_get_flags (attr, &flags) == 0)
-    return flags & MU_ATTRIBUTE_DRAFT;
-  return 0;
-}
-
-int
-mu_attribute_is_recent (mu_attribute_t attr)
-{
-  int flags = 0;
-  if (mu_attribute_get_flags (attr, &flags) == 0)
-    return MU_ATTRIBUTE_IS_UNSEEN(flags);
-  return 0;
-}
-
-int
-mu_attribute_unset_userflag (mu_attribute_t attr, int flag)
-{
-  if (attr == NULL)
-    return 0;
-  attr->user_flags &= ~flag;
-  return 0;
-}
-
-int
-mu_attribute_unset_seen (mu_attribute_t attr)
-{
-  return mu_attribute_unset_flags (attr, MU_ATTRIBUTE_SEEN);
-}
-
-int
-mu_attribute_unset_answered (mu_attribute_t attr)
-{
-  return mu_attribute_unset_flags (attr, MU_ATTRIBUTE_ANSWERED);
-}
-
-int
-mu_attribute_unset_flagged (mu_attribute_t attr)
-{
-  return mu_attribute_unset_flags (attr, MU_ATTRIBUTE_FLAGGED);
-}
-
-int
-mu_attribute_unset_read (mu_attribute_t attr)
-{
-  return mu_attribute_unset_flags (attr, MU_ATTRIBUTE_READ);
-}
-
-int
-mu_attribute_unset_deleted (mu_attribute_t attr)
-{
-  return mu_attribute_unset_flags (attr, MU_ATTRIBUTE_DELETED);
-}
-
-int
-mu_attribute_unset_draft (mu_attribute_t attr)
-{
-  return mu_attribute_unset_flags (attr, MU_ATTRIBUTE_DRAFT);
-}
-
-int
-mu_attribute_unset_recent (mu_attribute_t attr)
-{
-  return mu_attribute_unset_flags (attr, MU_ATTRIBUTE_SEEN);
-}
-
-int
-mu_attribute_is_equal (mu_attribute_t attr, mu_attribute_t attr2)
-{
-  int flags2 = 0, flags = 0;
-  mu_attribute_get_flags (attr, &flags);
-  mu_attribute_get_flags (attr2, &flags2);
-  return flags == flags;
-}
-
-/*   Miscellaneous.  */
-int
-mu_attribute_copy (mu_attribute_t dest, mu_attribute_t src)
-{
-  if (dest == NULL || src == NULL)
-    return EINVAL;
-  /* Can not be a deep copy.  */
-  /* memcpy (dest, src, sizeof (*dest)); */
-  dest->flags = src->flags;
-  return 0;
-}
-
-struct flagtrans
-{
-  int flag;
-  char letter;
-};
-
-/* The two macros below are taken from gnulib module verify.h */
-#define mu_verify_true(R) \
-  (!!sizeof \
-   (struct { unsigned int verify_error_if_negative_size__: (R) ? 1 : -1; }))
-#define mu_verify(R) extern int (* verify_function__ (void)) [mu_verify_true 
(R)]
-
-static struct flagtrans flagtrans[] = {
-  { MU_ATTRIBUTE_SEEN, 'O' },
-  { MU_ATTRIBUTE_ANSWERED, 'A' },
-  { MU_ATTRIBUTE_FLAGGED, 'F' },
-  { MU_ATTRIBUTE_READ, 'R' },
-  { MU_ATTRIBUTE_DELETED, 'd' },
-  { 0 }
-};
-
-/* If cc reports an error in this statement, fix the MU_STATUS_BUF_SIZE
-   declaration in include/mailutils/attribute.h */
-mu_verify (MU_ARRAY_SIZE (flagtrans) == MU_STATUS_BUF_SIZE);
-
-int
-mu_string_to_flags (const char *buffer, int *pflags)
-{
-  const char *sep;
-
-  if (pflags == NULL)
-    return EINVAL;
-
-  /* Set the attribute */
-  if (mu_c_strncasecmp (buffer, "Status:", 7) == 0)
-    {
-      sep = strchr(buffer, ':'); /* pass the ':' */
-      sep++;
-    }
-  else
-    sep = buffer;
-
-  for (; *sep; sep++)
-    {
-      struct flagtrans *ft;
-
-      for (ft = flagtrans; ft->flag; ft++)
-       if (ft->letter == *sep)
-         {
-           *pflags |= ft->flag;
-           break;
-         }
-    }
-  return 0;
-}
-
-/* NOTE: When adding/removing flags, make sure to update the
-   MU_STATUS_BUF_SIZE define in include/mailutils/attribute.h */
-int
-mu_attribute_to_string (mu_attribute_t attr, char *buffer, size_t len,
-                       size_t *pn)
-{
-  int flags = 0;
-  char buf[MU_STATUS_BUF_SIZE];
-  int i;
-  int rc;
-  struct flagtrans *ft;
-  
-  rc = mu_attribute_get_flags (attr, &flags);
-  if (rc)
-    return rc;
-
-  i = 0;
-  for (ft = flagtrans; ft->flag; ft++)
-    if (ft->flag & flags)
-      buf[i++] = ft->letter;
-  buf[i++] = 0;
-
-  i = mu_cpystr (buffer, buf, i);
-  if (pn)
-    *pn = i;
-  return 0;
-}
-
diff --git a/libmailutils/auth.c b/libmailutils/auth.c
deleted file mode 100644
index 2d3e974..0000000
--- a/libmailutils/auth.c
+++ /dev/null
@@ -1,164 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <errno.h>
-#include <sys/types.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include <mailutils/errno.h>
-#include <mailutils/sys/auth.h>
-
-static int
-_authenticate_null (mu_authority_t auth MU_ARG_UNUSED)
-{
-  return 0;
-}
-
-int
-mu_authority_create_null (mu_authority_t *pauthority, void *owner)
-{
-  int rc = mu_authority_create(pauthority, NULL, owner);
-  if (rc)
-    return rc;
-  mu_authority_set_authenticate (*pauthority, _authenticate_null,  owner);
-  return 0;
-}
-
-int
-mu_authority_create (mu_authority_t *pauthority, mu_ticket_t ticket, void 
*owner)
-{
-  mu_authority_t authority;
-  if (pauthority == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  authority = calloc (1, sizeof (*authority));
-  if (authority == NULL)
-    return ENOMEM;
-  authority->ticket = ticket;
-  authority->owner = owner;
-  *pauthority = authority;
-  return 0;
-}
-
-void
-mu_authority_destroy (mu_authority_t *pauthority, void *owner)
-{
-  if (pauthority && *pauthority)
-    {
-      mu_authority_t authority = *pauthority;
-      if (authority->owner == owner)
-       {
-         mu_ticket_destroy (&authority->ticket);
-         mu_list_destroy (&authority->auth_methods);
-         free (authority);
-       }
-      *pauthority = NULL;
-    }
-}
-
-void *
-mu_authority_get_owner (mu_authority_t authority)
-{
-  return (authority) ? authority->owner : NULL;
-}
-
-int
-mu_authority_set_ticket (mu_authority_t authority, mu_ticket_t ticket)
-{
-  if (authority == NULL)
-    return EINVAL;
-  if (authority->ticket)
-    mu_ticket_destroy (&authority->ticket);
-  authority->ticket = ticket;
-  return 0;
-}
-
-int
-mu_authority_get_ticket (mu_authority_t authority, mu_ticket_t *pticket)
-{
-  if (authority == NULL)
-    return EINVAL;
-  if (pticket == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  if (authority->ticket == NULL)
-    {
-      int status = mu_ticket_create (&(authority->ticket), authority);
-      if (status != 0)
-       return status;
-    }
-  *pticket = authority->ticket;
-  return 0;
-}
-
-struct auth_cb
-{
-  int status;
-  mu_authority_t authority;
-};
-
-static int
-try_auth (void *item, void *data)
-{
-  int (*authenticate) (mu_authority_t) = item;
-  struct auth_cb *cb = data;
-  if (authenticate (cb->authority) == 0)
-    {
-      cb->status = 0;
-      return 1;
-    }
-  return 0;
-}
-
-int
-mu_authority_authenticate (mu_authority_t authority)
-{
-  if (authority && authority->auth_methods)
-    {
-      struct auth_cb cb;
-      cb.status = MU_ERR_AUTH_FAILURE;
-      cb.authority = authority;
-      mu_list_do (authority->auth_methods, try_auth, &cb);
-      return cb.status;
-    }
-  return EINVAL;
-}
-
-int
-mu_authority_set_authenticate (mu_authority_t authority,
-                           int (*_authenticate) (mu_authority_t),
-                           void *owner)
-{
-  if (authority == NULL)
-    return EINVAL;
-
-  if (authority->owner != owner)
-    return EACCES;
-  if (!authority->auth_methods)
-    {
-      int rc = mu_list_create (&authority->auth_methods);
-      if (rc)
-       return rc;
-    }
-  mu_list_append (authority->auth_methods, _authenticate);
-  return 0;
-}
diff --git a/libmailutils/auth/Makefile.am b/libmailutils/auth/Makefile.am
new file mode 100644
index 0000000..5a797cd
--- /dev/null
+++ b/libmailutils/auth/Makefile.am
@@ -0,0 +1,25 @@
+# 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/>.
+
+noinst_LTLIBRARIES = libauth.la
+
+libauth_la_SOURCES = \
+ auth.c\
+ mu_auth.c\
+ system.c
+
+INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
diff --git a/libmailutils/auth/auth.c b/libmailutils/auth/auth.c
new file mode 100644
index 0000000..647e32b
--- /dev/null
+++ b/libmailutils/auth/auth.c
@@ -0,0 +1,163 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2005, 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/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <sys/types.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <mailutils/errno.h>
+#include <mailutils/sys/auth.h>
+
+static int
+_authenticate_null (mu_authority_t auth MU_ARG_UNUSED)
+{
+  return 0;
+}
+
+int
+mu_authority_create_null (mu_authority_t *pauthority, void *owner)
+{
+  int rc = mu_authority_create(pauthority, NULL, owner);
+  if (rc)
+    return rc;
+  mu_authority_set_authenticate (*pauthority, _authenticate_null,  owner);
+  return 0;
+}
+
+int
+mu_authority_create (mu_authority_t *pauthority, mu_ticket_t ticket, void 
*owner)
+{
+  mu_authority_t authority;
+  if (pauthority == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  authority = calloc (1, sizeof (*authority));
+  if (authority == NULL)
+    return ENOMEM;
+  authority->ticket = ticket;
+  authority->owner = owner;
+  *pauthority = authority;
+  return 0;
+}
+
+void
+mu_authority_destroy (mu_authority_t *pauthority, void *owner)
+{
+  if (pauthority && *pauthority)
+    {
+      mu_authority_t authority = *pauthority;
+      if (authority->owner == owner)
+       {
+         mu_ticket_destroy (&authority->ticket);
+         mu_list_destroy (&authority->auth_methods);
+         free (authority);
+       }
+      *pauthority = NULL;
+    }
+}
+
+void *
+mu_authority_get_owner (mu_authority_t authority)
+{
+  return (authority) ? authority->owner : NULL;
+}
+
+int
+mu_authority_set_ticket (mu_authority_t authority, mu_ticket_t ticket)
+{
+  if (authority == NULL)
+    return EINVAL;
+  if (authority->ticket)
+    mu_ticket_destroy (&authority->ticket);
+  authority->ticket = ticket;
+  return 0;
+}
+
+int
+mu_authority_get_ticket (mu_authority_t authority, mu_ticket_t *pticket)
+{
+  if (authority == NULL)
+    return EINVAL;
+  if (pticket == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  if (authority->ticket == NULL)
+    {
+      int status = mu_ticket_create (&(authority->ticket), authority);
+      if (status != 0)
+       return status;
+    }
+  *pticket = authority->ticket;
+  return 0;
+}
+
+struct auth_cb
+{
+  int status;
+  mu_authority_t authority;
+};
+
+static int
+try_auth (void *item, void *data)
+{
+  int (*authenticate) (mu_authority_t) = item;
+  struct auth_cb *cb = data;
+  if (authenticate (cb->authority) == 0)
+    {
+      cb->status = 0;
+      return 1;
+    }
+  return 0;
+}
+
+int
+mu_authority_authenticate (mu_authority_t authority)
+{
+  if (authority && authority->auth_methods)
+    {
+      struct auth_cb cb;
+      cb.status = MU_ERR_AUTH_FAILURE;
+      cb.authority = authority;
+      mu_list_do (authority->auth_methods, try_auth, &cb);
+      return cb.status;
+    }
+  return EINVAL;
+}
+
+int
+mu_authority_set_authenticate (mu_authority_t authority,
+                           int (*_authenticate) (mu_authority_t),
+                           void *owner)
+{
+  if (authority == NULL)
+    return EINVAL;
+
+  if (authority->owner != owner)
+    return EACCES;
+  if (!authority->auth_methods)
+    {
+      int rc = mu_list_create (&authority->auth_methods);
+      if (rc)
+       return rc;
+    }
+  mu_list_append (authority->auth_methods, _authenticate);
+  return 0;
+}
diff --git a/libmailutils/auth/mu_auth.c b/libmailutils/auth/mu_auth.c
new file mode 100644
index 0000000..f9f33ca
--- /dev/null
+++ b/libmailutils/auth/mu_auth.c
@@ -0,0 +1,538 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2002, 2004, 2005, 2006, 2007, 2010 Free Software
+   Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <pwd.h>
+#ifdef HAVE_SHADOW_H
+# include <shadow.h>
+#endif
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+#ifdef HAVE_SECURITY_PAM_APPL_H
+# include <security/pam_appl.h>
+#endif
+#ifdef HAVE_CRYPT_H
+# include <crypt.h>
+#endif
+
+#include <mailutils/argcv.h>
+#include <mailutils/list.h>
+#include <mailutils/iterator.h>
+#include <mailutils/mailbox.h>
+#include <mailutils/mu_auth.h>
+#include <mailutils/error.h>
+#include <mailutils/errno.h>
+#include <mailutils/nls.h>
+#include <mailutils/debug.h>
+
+static mu_debug_t mu_auth_debug;
+
+#define S(s) ((s) ? (s) : "(none)")
+#define DEBUG_AUTH(a)                                                         \
+     MU_DEBUG11 (mu_auth_debug, MU_DEBUG_TRACE,                               \
+                       "source=%s, name=%s, passwd=%s, uid=%lu, gid=%lu, "    \
+                       "gecos=%s, dir=%s, shell=%s, mailbox=%s, quota=%lu, "  \
+                       "change_uid=%d\n",                                     \
+                       S ((a)->source),                                       \
+                       S ((a)->name),                                         \
+                       S ((a)->passwd),                                       \
+                       (unsigned long) (a)->uid,                              \
+                       (unsigned long) (a)->gid,                              \
+                       S ((a)->gecos),                                        \
+                       S ((a)->dir),                                          \
+                       S ((a)->shell),                                        \
+                       S ((a)->mailbox),                                      \
+                       (unsigned long) (a)->quota,                            \
+                       (a)->change_uid)
+     
+mu_debug_t
+mu_auth_set_debug (mu_debug_t debug)
+{
+  mu_debug_t prev = mu_auth_debug;
+  mu_auth_debug = debug;
+  return prev;
+}
+
+
+/* memory allocation */
+int 
+mu_auth_data_alloc (struct mu_auth_data **ptr,
+                    const char *name,
+                    const char *passwd,
+                    uid_t uid,
+                    gid_t gid,
+                    const char *gecos,
+                    const char *dir,
+                    const char *shell,
+                    const char *mailbox,
+                    int change_uid)
+{
+  size_t size;
+  char *p;
+  char *tmp_mailbox_name = NULL;
+  
+  if (!name)
+    return EINVAL;
+  if (!passwd)
+    passwd = "x";
+  if (!gecos)
+    gecos = "";
+  if (!dir)
+    dir = "/nonexisting";
+  if (!shell)
+    shell = "/dev/null";
+  if (!mailbox)
+    {
+      int rc = mu_construct_user_mailbox_url (&tmp_mailbox_name, name);
+      if (rc)
+       return rc;
+      mailbox = tmp_mailbox_name;
+    }
+
+  size = sizeof (**ptr) +
+         strlen (name) + 1 +
+         strlen (passwd) + 1 +
+         strlen (gecos) + 1 +
+         strlen (dir) + 1 +
+         strlen (shell) + 1 +
+         strlen (mailbox) + 1;
+  
+  *ptr = calloc (1, size);
+  if (!*ptr)
+    return ENOMEM;
+
+  p = (char *)(*ptr + 1);
+  
+#define COPY(f) \
+  (*ptr)->f = p; \
+  strcpy (p, f); \
+  p += strlen (f) + 1
+  
+  COPY (name);
+  COPY (passwd);
+  COPY (gecos);
+  COPY (dir);
+  COPY (shell);
+  COPY (mailbox);
+  (*ptr)->uid = uid;
+  (*ptr)->gid = gid;
+  (*ptr)->change_uid = change_uid;
+
+  free (tmp_mailbox_name);
+  return 0;
+}
+
+void
+mu_auth_data_set_quota (struct mu_auth_data *ptr, mu_off_t q)
+{
+  ptr->flags |= MU_AF_QUOTA;
+  ptr->quota = q;
+}
+
+void
+mu_auth_data_free (struct mu_auth_data *ptr)
+{
+  free (ptr);
+}
+
+void
+mu_auth_data_destroy (struct mu_auth_data **pptr)
+{
+  if (pptr)
+    {
+      mu_auth_data_free (*pptr);
+      *pptr = NULL;
+    }
+}
+
+/* Generic functions */
+
+struct auth_stack_entry {
+  char *name;        /* for diagnostics purposes */
+  mu_auth_fp fun;
+  void *func_data;
+};
+
+void
+mu_insert_stack_entry (mu_list_t *pflist, struct auth_stack_entry *entry)
+{
+  if (!*pflist && mu_list_create (pflist))
+    return;
+  mu_list_append (*pflist, entry);
+}
+
+int
+mu_auth_runlist (mu_list_t flist, struct mu_auth_data **return_data,
+                 const void *key, void *data)
+{
+  int status = MU_ERR_AUTH_FAILURE;
+  int rc;
+  mu_iterator_t itr;
+
+  if (mu_list_get_iterator (flist, &itr) == 0)
+    {
+      struct auth_stack_entry *ep;
+      
+      for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
+           mu_iterator_next (itr))
+        {
+          mu_iterator_current (itr, (void **)&ep);
+          MU_DEBUG1 (mu_auth_debug, MU_DEBUG_TRACE, "Trying %s...", ep->name);
+          rc = ep->fun (return_data, key, ep->func_data, data);
+          MU_DEBUG2 (mu_auth_debug, MU_DEBUG_TRACE, 
+                     "result: %d=%s\n", rc, mu_strerror (rc));
+          if (rc == 0)
+            {
+              if (return_data)
+                {
+                  struct mu_auth_data *auth = *return_data;
+                  if (auth->source == NULL)
+                    auth->source = ep->name;
+                  DEBUG_AUTH (auth);
+                }
+              status = rc;
+              break;
+            }
+          else if (rc == ENOSYS && status != 0)
+           /* nothing: do not overwrite last meaningful return code */;
+         else if (status != EAGAIN)
+            status = rc;
+        }
+
+      mu_iterator_destroy (&itr);
+    }
+  return status;
+}
+
+int
+mu_auth_nosupport (struct mu_auth_data **return_data MU_ARG_UNUSED,
+                   const void *key MU_ARG_UNUSED,
+                   void *func_data MU_ARG_UNUSED,
+                   void *call_data MU_ARG_UNUSED)
+{
+  return ENOSYS;
+}
+
+/* II. Authorization: retrieving information about user */
+
+static mu_list_t mu_auth_by_name_list, _tmp_auth_by_name_list;
+static mu_list_t mu_auth_by_uid_list, _tmp_auth_by_uid_list;
+
+int
+mu_get_auth (struct mu_auth_data **auth, enum mu_auth_key_type type,
+             const void *key)
+{
+  mu_list_t list;
+  
+  if (!mu_auth_by_name_list)
+    mu_auth_begin_setup ();
+  switch (type)
+    {
+    case mu_auth_key_name:
+      MU_DEBUG1 (mu_auth_debug, MU_DEBUG_TRACE, 
+                 "Getting auth info for user %s\n", 
+                 (char*) key);
+      list = mu_auth_by_name_list;
+      break;
+
+    case mu_auth_key_uid:
+      MU_DEBUG1 (mu_auth_debug, MU_DEBUG_TRACE, 
+                 "Getting auth info for UID %lu\n",
+                (unsigned long) *(uid_t*) key);
+      list = mu_auth_by_uid_list;
+      break;
+
+    default:
+      MU_DEBUG1 (mu_auth_debug, MU_DEBUG_ERROR, 
+                 "Unknown mu_auth_key_type: %d\n", type);
+      return EINVAL;
+    }
+  return mu_auth_runlist (list, auth, key, NULL);
+}
+
+struct mu_auth_data *
+mu_get_auth_by_name (const char *username)
+{
+  struct mu_auth_data *auth = NULL;
+  mu_get_auth (&auth, mu_auth_key_name, username);
+  return auth;
+}
+
+struct mu_auth_data *
+mu_get_auth_by_uid (uid_t uid)
+{
+  struct mu_auth_data *auth = NULL;
+  mu_get_auth (&auth, mu_auth_key_uid, &uid);
+  return auth;
+}
+
+/* III. Authentication: determining the authenticity of a user */
+
+static mu_list_t mu_authenticate_list, _tmp_authenticate_list;
+
+int
+mu_authenticate (struct mu_auth_data *auth_data, const char *pass)
+{
+  if (!auth_data)
+    return EINVAL;
+  MU_DEBUG2 (mu_auth_debug, MU_DEBUG_TRACE, 
+             "mu_authenticate, user %s, source %s\n", 
+             auth_data->name, auth_data->source);
+  if (!mu_authenticate_list)
+    mu_auth_begin_setup ();
+  return mu_auth_runlist (mu_authenticate_list, NULL, auth_data, (void*) pass);
+}
+
+
+/* ************************************************************************* */
+
+struct _module_handler {
+  struct auth_stack_entry authenticate;
+  struct auth_stack_entry auth_by_name;
+  struct auth_stack_entry auth_by_uid;
+};
+
+static mu_list_t module_handler_list;
+
+void
+mu_auth_register_module (struct mu_auth_module *mod)
+{
+  struct _module_handler *entry;
+  
+  if (mod->init)
+    mu_gocs_register (mod->name, mod->init);
+  
+  if (!module_handler_list && mu_list_create (&module_handler_list))
+    abort ();
+
+  entry = malloc (sizeof (*entry));
+  if (!entry)
+    {
+      mu_error ("not enough memory");
+      exit (1);
+    }
+  entry->authenticate.name = mod->name;
+  entry->authenticate.fun  = mod->authenticate;
+  entry->authenticate.func_data = mod->authenticate_data;
+  entry->auth_by_name.name = mod->name;
+  entry->auth_by_name.fun = mod->auth_by_name;
+  entry->auth_by_name.func_data = mod->auth_by_name_data;
+  entry->auth_by_uid.name = mod->name;
+  entry->auth_by_uid.fun = mod->auth_by_uid;
+  entry->auth_by_uid.func_data = mod->auth_by_uid_data;
+    
+  mu_list_append (module_handler_list, entry);
+  
+}
+
+static struct _module_handler *
+_locate (const char *name)
+{
+  struct _module_handler *rp = NULL;
+  mu_iterator_t itr;
+
+  if (mu_list_get_iterator (module_handler_list, &itr) == 0)
+    {
+      struct _module_handler *p;
+      
+      for (mu_iterator_first (itr); !rp && !mu_iterator_is_done (itr);
+           mu_iterator_next (itr))
+        {
+          mu_iterator_current (itr, (void **)&p);
+          if (strcmp (p->authenticate.name, name) == 0)
+            rp = p;
+        }
+
+      mu_iterator_destroy (&itr);
+    }
+  return rp;
+}
+
+static void
+_add_module_list (const char *modlist, int (*fun)(const char *name))
+{
+  int argc;
+  char **argv;
+  int rc, i;
+  
+  rc = mu_argcv_get (modlist, ":", NULL, &argc, &argv);
+  if (rc)
+    {
+      mu_error (_("cannot split line `%s': %s"), modlist, mu_strerror (rc));
+      exit (1);
+    }
+
+  for (i = 0; i < argc; i += 2)
+    {
+      if (fun (argv[i]))
+        {
+          /* Historically,auth functions used ENOENT. We support this
+             return value for backward compatibility. */
+          if (errno == ENOENT || errno == MU_ERR_NOENT)
+            mu_error (_("no such module: %s"), argv[i]);
+          else
+            mu_error (_("failed to add module %s: %s"),
+                      argv[i], strerror (errno));
+          exit (1);
+        }
+    }
+  mu_argcv_free (argc, argv);
+}
+
+
+int
+mu_authorization_add_module (const char *name)
+{
+  struct _module_handler *mod = _locate (name);
+  
+  if (!mod)
+    {
+      errno = MU_ERR_NOENT;
+      return 1;
+    }
+  mu_insert_stack_entry (&_tmp_auth_by_name_list, &mod->auth_by_name);
+  mu_insert_stack_entry (&_tmp_auth_by_uid_list, &mod->auth_by_uid);
+  return 0;
+}
+
+void
+mu_authorization_add_module_list (const char *modlist)
+{
+  _add_module_list (modlist, mu_authorization_add_module);
+}
+
+void
+mu_authorization_clear_list ()
+{
+  mu_list_destroy (&_tmp_auth_by_name_list);
+  mu_list_destroy (&_tmp_auth_by_uid_list);
+}
+
+
+int
+mu_authentication_add_module (const char *name)
+{
+  struct _module_handler *mod = _locate (name);
+
+  if (!mod)
+    {
+      errno = MU_ERR_NOENT;
+      return 1;
+    }
+  mu_insert_stack_entry (&_tmp_authenticate_list, &mod->authenticate);
+  return 0;
+}
+
+void
+mu_authentication_add_module_list (const char *modlist)
+{
+  _add_module_list (modlist, mu_authentication_add_module);
+}
+
+void
+mu_authentication_clear_list ()
+{
+  mu_list_destroy (&_tmp_authenticate_list);
+}
+
+
+/* ************************************************************************ */
+
+/* Setup functions. Note that:
+   1) If libmuath is not linked in, then "generic" and "system" modules
+      are used unconditionally. This provides compatibility with the
+      standard getpw.* functions.
+   2) --authentication and --authorization modify only temporary lists,
+      which get flushed to the main ones when mu_auth_finish_setup() is
+      run. Thus, the default "generic:system" remain in force until
+      argp_parse() exits. */
+   
+void
+mu_auth_begin_setup ()
+{
+  mu_iterator_t itr;
+
+  if (!module_handler_list)
+    {
+      mu_auth_register_module (&mu_auth_generic_module); 
+      mu_auth_register_module (&mu_auth_system_module);
+    }
+  
+  if (!mu_authenticate_list)
+    {
+      if (mu_list_get_iterator (module_handler_list, &itr) == 0)
+        {
+          struct _module_handler *mod;
+          
+          for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
+               mu_iterator_next (itr))
+            {
+              mu_iterator_current (itr, (void **)&mod);
+              mu_insert_stack_entry (&mu_authenticate_list,
+                                     &mod->authenticate);
+            }
+          mu_iterator_destroy (&itr);
+        }
+    }
+
+  if (!mu_auth_by_name_list)
+    {
+      if (mu_list_get_iterator (module_handler_list, &itr) == 0)
+        {
+          struct _module_handler *mod;
+          
+          for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
+               mu_iterator_next (itr))
+            {
+              mu_iterator_current (itr, (void **)&mod);
+              mu_insert_stack_entry (&mu_auth_by_name_list, 
&mod->auth_by_name);
+              mu_insert_stack_entry (&mu_auth_by_uid_list, &mod->auth_by_uid);
+            }
+          mu_iterator_destroy (&itr);
+        }
+    }
+}
+
+void
+mu_auth_finish_setup ()
+{
+  mu_list_destroy (&mu_authenticate_list);
+  mu_list_destroy (&mu_auth_by_name_list);
+  mu_list_destroy (&mu_auth_by_uid_list);
+  
+  mu_authenticate_list = _tmp_authenticate_list;
+  _tmp_authenticate_list = NULL;
+  mu_auth_by_name_list = _tmp_auth_by_name_list;
+  _tmp_auth_by_name_list = NULL;
+  mu_auth_by_uid_list = _tmp_auth_by_uid_list;
+  _tmp_auth_by_uid_list = NULL;
+  
+  mu_auth_begin_setup ();
+}
+
+
diff --git a/libmailutils/auth/system.c b/libmailutils/auth/system.c
new file mode 100644
index 0000000..4e54296
--- /dev/null
+++ b/libmailutils/auth/system.c
@@ -0,0 +1,159 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2002, 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/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <pwd.h>
+#ifdef HAVE_SHADOW_H
+# include <shadow.h>
+#endif
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+#ifdef HAVE_CRYPT_H
+# include <crypt.h>
+#endif
+
+#include <mailutils/list.h>
+#include <mailutils/iterator.h>
+#include <mailutils/mailbox.h>
+#include <mailutils/mu_auth.h>
+#include <mailutils/errno.h>
+
+/* System database */
+static int
+mu_auth_system (struct mu_auth_data **return_data, const struct passwd *pw)
+{
+  char *mailbox_name;
+  int rc;
+  
+  if (!pw)
+    return MU_ERR_AUTH_FAILURE;
+
+  rc = mu_construct_user_mailbox_url (&mailbox_name, pw->pw_name);
+  if (rc)
+    return rc; /* FIXME: Return code is lost */
+  
+  rc = mu_auth_data_alloc (return_data,
+                          pw->pw_name,
+                          pw->pw_passwd,
+                          pw->pw_uid,
+                          pw->pw_gid,
+                          pw->pw_gecos,
+                          pw->pw_dir,
+                          pw->pw_shell,
+                          mailbox_name,
+                          1);
+  free (mailbox_name);
+  return rc;
+}
+
+int
+mu_auth_system_by_name (struct mu_auth_data **return_data,
+                       const void *key,
+                       void *func_data MU_ARG_UNUSED,
+                       void *call_data MU_ARG_UNUSED)
+{
+  if (!key)
+    return EINVAL;
+  return mu_auth_system (return_data, getpwnam (key));
+}
+
+static int
+mu_auth_system_by_uid (struct mu_auth_data **return_data,
+                      const void *key,
+                      void *func_data MU_ARG_UNUSED,
+                      void *call_data MU_ARG_UNUSED)
+{
+  if (!key)
+    return EINVAL;
+  return mu_auth_system (return_data, getpwuid (*(uid_t*) key));
+}
+
+static int
+mu_authenticate_generic (struct mu_auth_data **return_data MU_ARG_UNUSED,
+                        const void *key,
+                        void *func_data MU_ARG_UNUSED,
+                        void *call_data)
+{
+  const struct mu_auth_data *auth_data = key;
+  char *pass = call_data;
+
+  if (!auth_data || !pass)
+    return EINVAL;
+  
+  return auth_data->passwd
+         && strcmp (auth_data->passwd, crypt (pass, auth_data->passwd)) == 0 ?
+          0 : MU_ERR_AUTH_FAILURE;
+}
+
+/* Called only if generic fails */
+static int
+mu_authenticate_system (struct mu_auth_data **return_data MU_ARG_UNUSED,
+                       const void *key,
+                       void *func_data MU_ARG_UNUSED,
+                       void *call_data)
+{
+  const struct mu_auth_data *auth_data = key;
+
+#ifdef HAVE_SHADOW_H
+  char *pass = call_data;
+  
+  if (auth_data)
+    {
+      struct spwd *spw;
+      spw = getspnam (auth_data->name);
+      if (spw)
+       return strcmp (spw->sp_pwdp, crypt (pass, spw->sp_pwdp)) == 0 ?
+               0 : MU_ERR_AUTH_FAILURE;
+    }
+#endif
+  return MU_ERR_AUTH_FAILURE;
+}
+
+
+struct mu_auth_module mu_auth_system_module = {
+  "system",
+  NULL,
+  mu_authenticate_system,
+  NULL,
+  mu_auth_system_by_name,
+  NULL,
+  mu_auth_system_by_uid,
+  NULL
+};
+
+
+struct mu_auth_module mu_auth_generic_module = {
+  "generic",
+  NULL,
+  mu_authenticate_generic,
+  NULL,
+  mu_auth_nosupport,
+  NULL,
+  mu_auth_nosupport,
+  NULL
+};
+
diff --git a/libmailutils/base/.gitignore b/libmailutils/base/.gitignore
new file mode 100644
index 0000000..e3e0cf0
--- /dev/null
+++ b/libmailutils/base/.gitignore
@@ -0,0 +1 @@
+parsedate.c
diff --git a/libmailutils/base/Makefile.am b/libmailutils/base/Makefile.am
new file mode 100644
index 0000000..4bb7acb
--- /dev/null
+++ b/libmailutils/base/Makefile.am
@@ -0,0 +1,80 @@
+# GNU Mailutils -- a suite of utilities for electronic mail
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General
+# Public License along with this library.  If not, see
+# <http://www.gnu.org/licenses/>.
+
+noinst_LTLIBRARIES = libbase.la
+
+libbase_la_SOURCES = \
+ alloc.c\
+ amd.c\
+ argcv.c\
+ assoc.c\
+ daemon.c\
+ date.c\
+ fgetpwent.c\
+ freeitem.c\
+ getpass.c\
+ iterator.c\
+ kwd.c\
+ list.c\
+ listlist.c\
+ locale.c\
+ locker.c\
+ mailcap.c\
+ md5.c\
+ monitor.c\
+ munre.c\
+ mutil.c\
+ nls.c\
+ nullrec.c\
+ observer.c\
+ opool.c\
+ parsedate.c\
+ permstr.c\
+ property.c\
+ registrar.c\
+ refcount.c\
+ rfc2047.c\
+ sha1.c\
+ secret.c\
+ ticket.c\
+ url.c\
+ vartab.c\
+ version.c\
+ wicket.c
+
+localedir = $(datadir)/locale
+AM_CPPFLAGS = \
+ -DSYSCONFDIR=\"$(sysconfdir)\"\
+ -DSITE_VIRTUAL_PWDDIR=\"@address@hidden"\
+ -DLOCALEDIR=\"$(localedir)\"
+
+INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
+
+YLWRAP = $(SHELL) $(mu_aux_dir)/gylwrap
+AM_YFLAGS=-vt
+AM_LFLAGS=-dvp
+
+EXTRA_DIST = parsedate.y
+
+BUILT_SOURCES = parsedate.c
+
+parsedate.c: $(srcdir)/parsedate.y
+       $(YLWRAP) "$(YACC) $(AM_YFLAGS)" $< \
+                 y.tab.c parsedate.c y.output parsedate.y.output \
+                  -- -yy pd_yy
+
+
diff --git a/libmailutils/alloc.c b/libmailutils/base/alloc.c
similarity index 100%
rename from libmailutils/alloc.c
rename to libmailutils/base/alloc.c
diff --git a/libmailutils/base/amd.c b/libmailutils/base/amd.c
new file mode 100644
index 0000000..1a32228
--- /dev/null
+++ b/libmailutils/base/amd.c
@@ -0,0 +1,2032 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+   2008, 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/>. */
+
+/* Mailutils Abstract Mail Directory Layer 
+   First draft by Sergey Poznyakoff.
+   Thanks Tang Yong Ping <address@hidden> for initial
+   patch (although not used here).
+
+   This module provides basic support for "MH" and "Maildir" formats. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <dirent.h>
+
+#ifdef WITH_PTHREAD
+# ifdef HAVE_PTHREAD_H
+#  ifndef _XOPEN_SOURCE
+#   define _XOPEN_SOURCE  500
+#  endif
+#  include <pthread.h>
+# endif
+#endif
+
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/cctype.h>
+#include <mailutils/cstr.h>
+#include <mailutils/attribute.h>
+#include <mailutils/body.h>
+#include <mailutils/debug.h>
+#include <mailutils/envelope.h>
+#include <mailutils/error.h>
+#include <mailutils/errno.h>
+#include <mailutils/header.h>
+#include <mailutils/locker.h>
+#include <mailutils/message.h>
+#include <mailutils/mutil.h>
+#include <mailutils/property.h>
+#include <mailutils/stream.h>
+#include <mailutils/url.h>
+#include <mailutils/observer.h>
+#include <mailutils/sys/stream.h>
+#include <mailutils/sys/mailbox.h>
+#include <mailutils/sys/registrar.h>
+#include <mailutils/sys/url.h>
+#include <mailutils/sys/amd.h>
+
+static void amd_destroy (mu_mailbox_t mailbox);
+static int amd_open (mu_mailbox_t, int);
+static int amd_close (mu_mailbox_t);
+static int amd_get_message (mu_mailbox_t, size_t, mu_message_t *);
+static int amd_quick_get_message (mu_mailbox_t mailbox, mu_message_qid_t qid,
+                                 mu_message_t *pmsg);
+static int amd_append_message (mu_mailbox_t, mu_message_t);
+static int amd_messages_count (mu_mailbox_t, size_t *);
+static int amd_messages_recent (mu_mailbox_t, size_t *);
+static int amd_message_unseen (mu_mailbox_t, size_t *);
+static int amd_expunge (mu_mailbox_t);
+static int amd_sync (mu_mailbox_t);
+static int amd_uidnext (mu_mailbox_t mailbox, size_t *puidnext);
+static int amd_uidvalidity (mu_mailbox_t, unsigned long *);
+static int amd_scan (mu_mailbox_t, size_t, size_t *);
+static int amd_is_updated (mu_mailbox_t);
+static int amd_get_size (mu_mailbox_t, mu_off_t *);
+
+static int amd_body_size (mu_body_t body, size_t *psize);
+static int amd_body_lines (mu_body_t body, size_t *plines);
+
+static int amd_header_fill (void *data, char **pbuf, size_t *plen);
+
+static int amd_get_attr_flags (mu_attribute_t attr, int *pflags);
+static int amd_set_attr_flags (mu_attribute_t attr, int flags);
+static int amd_unset_attr_flags (mu_attribute_t attr, int flags);
+
+static void _amd_message_delete (struct _amd_data *amd,
+                                struct _amd_message *msg);
+static int amd_pool_open (struct _amd_message *mhm);
+static int amd_pool_open_count (struct _amd_data *amd);
+static void amd_pool_flush (struct _amd_data *amd);
+static struct _amd_message **amd_pool_lookup (struct _amd_message *mhm);
+
+static int amd_envelope_date (mu_envelope_t envelope, char *buf, size_t len,
+                             size_t *psize);
+static int amd_envelope_sender (mu_envelope_t envelope, char *buf, size_t len,
+                               size_t *psize);
+static int amd_remove_mbox (mu_mailbox_t mailbox);
+
+
+static int amd_body_stream_read (mu_stream_t str, char *buffer,
+                                size_t buflen,
+                                size_t *pnread);
+static int amd_body_stream_readdelim (mu_stream_t is,
+                                     char *buffer, size_t buflen,
+                                     int delim,
+                                     size_t *pnread);
+static int amd_body_stream_size (mu_stream_t str, mu_off_t *psize);
+static int amd_body_stream_seek (mu_stream_t str, mu_off_t off, 
+                                mu_off_t *presult);
+
+struct _amd_body_stream
+{
+  struct _mu_stream stream;
+  mu_body_t body;
+  mu_off_t off;
+};
+
+
+/* Operations on message array */
+
+/* Perform binary search for message MSG on a segment of message array
+   of AMD between the indexes FIRST and LAST inclusively.
+   If found, return 0 and store index of the located entry in the
+   variable PRET. Otherwise, return 1 and place into PRET index of
+   the nearest array element that is less than MSG (in the sense of
+   amd->msg_cmp)
+   Indexes are zero-based. */
+   
+static int
+amd_msg_bsearch (struct _amd_data *amd, mu_off_t first, mu_off_t last,
+                struct _amd_message *msg,
+                mu_off_t *pret)
+{
+  mu_off_t mid;
+  int rc;
+
+  if (last < first)
+    return 1;
+  
+  mid = (first + last) / 2;
+  rc = amd->msg_cmp (amd->msg_array[mid], msg);
+  if (rc > 0)
+    return amd_msg_bsearch (amd, first, mid-1, msg, pret);
+  *pret = mid;
+  if (rc < 0)
+    return amd_msg_bsearch (amd, mid+1, last, msg, pret);
+  /* else */
+  return 0;
+}
+
+/* Search for message MSG in the message array of AMD.
+   If found, return 0 and store index of the located entry in the
+   variable PRET. Otherwise, return 1 and place into PRET index of
+   the array element that is less than MSG (in the sense of
+   amd->msg_cmp)
+   Index returned in PRET is 1-based, so *PRET == 0 means that MSG
+   is less than the very first element of the message array.
+
+   In other words, when amd_msg_lookup() returns 1, the value in *PRET
+   can be regarded as a 0-based index of the array slot where MSG can
+   be inserted */
+
+int
+amd_msg_lookup (struct _amd_data *amd, struct _amd_message *msg,
+                size_t *pret)
+{
+  int rc;
+  mu_off_t i;
+  
+  if (amd->msg_count == 0)
+    {
+      *pret = 0;
+      return 1;
+    }
+  
+  rc = amd->msg_cmp (msg, amd->msg_array[0]);
+  if (rc < 0)
+    {
+      *pret = 0;
+      return 1;
+    }
+  else if (rc == 0)
+    {
+      *pret = 1;
+      return 0;
+    }
+  
+  rc = amd->msg_cmp (msg, amd->msg_array[amd->msg_count - 1]);
+  if (rc > 0)
+    {
+      *pret = amd->msg_count;
+      return 1;
+    }
+  else if (rc == 0)
+    {
+      *pret = amd->msg_count;
+      return 0;
+    }
+  
+  rc = amd_msg_bsearch (amd, 0, amd->msg_count - 1, msg, &i);
+  *pret = i + 1;
+  return rc;
+}
+
+#define AMD_MSG_INC 64
+
+/* Prepare the message array for insertion of a new message
+   at position INDEX (zero based), by moving its contents
+   one slot to the right. If necessary, expand the array by
+   AMD_MSG_INC */
+int
+amd_array_expand (struct _amd_data *amd, size_t index)
+{
+  if (amd->msg_count == amd->msg_max)
+    {
+      struct _amd_message **p;
+      
+      amd->msg_max += AMD_MSG_INC; /* FIXME: configurable? */
+      p = realloc (amd->msg_array, amd->msg_max * amd->msg_size);
+      if (!p)
+       {
+         amd->msg_max -= AMD_MSG_INC;
+         return ENOMEM;
+       }
+      amd->msg_array = p;
+    }
+  memmove (&amd->msg_array[index+1], &amd->msg_array[index],
+          (amd->msg_count-index) * amd->msg_size);
+  amd->msg_count++;
+  return 0;
+}
+
+/* Shrink the message array by removing element at INDEX-1 and
+   shifting left by one position all the elements on the right of
+   it. */
+int
+amd_array_shrink (struct _amd_data *amd, size_t index)
+{
+  memmove (&amd->msg_array[index-1], &amd->msg_array[index],
+          (amd->msg_count-index) * amd->msg_size);
+  amd->msg_count--;
+  return 0;
+}
+
+
+int
+amd_init_mailbox (mu_mailbox_t mailbox, size_t amd_size,
+                 struct _amd_data **pamd) 
+{
+  int status;
+  struct _amd_data *amd;
+
+  if (mailbox == NULL)
+    return MU_ERR_MBX_NULL;
+  if (amd_size < sizeof (*amd))
+    return EINVAL;
+
+  amd = mailbox->data = calloc (1, amd_size);
+  if (mailbox->data == NULL)
+    return ENOMEM;
+
+  /* Back pointer.  */
+  amd->mailbox = mailbox;
+
+  status = mu_url_aget_path (mailbox->url, &amd->name);
+  if (status)
+    {
+      free (amd);
+      mailbox->data = NULL;
+      return status;
+    }
+
+  /* Overloading the defaults.  */
+  mailbox->_destroy = amd_destroy;
+
+  mailbox->_open = amd_open;
+  mailbox->_close = amd_close;
+
+  /* Overloading of the entire mailbox object methods.  */
+  mailbox->_get_message = amd_get_message;
+  mailbox->_quick_get_message = amd_quick_get_message;
+  mailbox->_append_message = amd_append_message;
+  mailbox->_messages_count = amd_messages_count;
+  mailbox->_messages_recent = amd_messages_recent;
+  mailbox->_message_unseen = amd_message_unseen;
+  mailbox->_expunge = amd_expunge;
+  mailbox->_sync = amd_sync;
+  mailbox->_uidvalidity = amd_uidvalidity;
+  mailbox->_uidnext = amd_uidnext;
+
+  mailbox->_scan = amd_scan;
+  mailbox->_is_updated = amd_is_updated;
+
+  mailbox->_get_size = amd_get_size;
+  mailbox->_remove = amd_remove_mbox;
+  
+  MU_DEBUG1 (mailbox->debug, MU_DEBUG_TRACE1, "amd_init(%s)\n", amd->name);
+  *pamd = amd;
+  return 0;
+}
+
+static void
+amd_destroy (mu_mailbox_t mailbox)
+{
+  struct _amd_data *amd = mailbox->data;
+  size_t i;
+  
+  if (!amd)
+    return;
+
+  amd_pool_flush (amd);
+  mu_monitor_wrlock (mailbox->monitor);
+  for (i = 0; i < amd->msg_count; i++)
+    {
+      mu_message_destroy (&amd->msg_array[i]->message, amd->msg_array[i]);
+      free (amd->msg_array[i]);
+    }
+  free (amd->msg_array);
+       
+  if (amd->name)
+    free (amd->name);
+
+  free (amd);
+  mailbox->data = NULL;
+  mu_monitor_unlock (mailbox->monitor);
+}
+
+static int
+amd_open (mu_mailbox_t mailbox, int flags)
+{
+  struct _amd_data *amd = mailbox->data;
+  struct stat st;
+
+  mailbox->flags = flags;
+  if (stat (amd->name, &st) < 0)
+    {
+      if ((flags & MU_STREAM_CREAT) && errno == ENOENT)
+       {
+         int rc;
+         int perms = mu_stream_flags_to_mode (flags, 1);
+         if (mkdir (amd->name, S_IRUSR|S_IWUSR|S_IXUSR|perms))
+           return errno;
+         if (stat (amd->name, &st) < 0)
+           return errno;
+         if (amd->create && (rc = amd->create (amd, flags)))
+           return rc;
+       }
+      else
+       return errno;
+    }
+  
+  if (!S_ISDIR (st.st_mode))
+    return EINVAL;
+
+  if (mailbox->locker == NULL)
+    mu_locker_create (&mailbox->locker, "/dev/null", 0);
+  
+  return 0;
+}
+
+static int
+amd_close (mu_mailbox_t mailbox)
+{
+  struct _amd_data *amd;
+  int i;
+    
+  if (!mailbox)
+    return MU_ERR_MBX_NULL;
+
+  amd = mailbox->data;
+  
+  /* Destroy all cached data */
+  amd_pool_flush (amd);
+  mu_monitor_wrlock (mailbox->monitor);
+  for (i = 0; i < amd->msg_count; i++)
+    {
+      mu_message_destroy (&amd->msg_array[i]->message, amd->msg_array[i]);
+      free (amd->msg_array[i]);
+    }
+  free (amd->msg_array);
+  amd->msg_array = NULL;
+
+  amd->msg_count = 0; /* number of messages in the list */
+  amd->msg_max = 0;   /* maximum message buffer capacity */
+
+  amd->uidvalidity = 0;
+  mu_monitor_unlock (mailbox->monitor);
+  
+  return 0;
+}
+
+static int
+amd_message_qid (mu_message_t msg, mu_message_qid_t *pqid)
+{
+  struct _amd_message *mhm = mu_message_get_owner (msg);
+  
+  return mhm->amd->cur_msg_file_name (mhm, pqid);
+}
+
+struct _amd_message *
+_amd_get_message (struct _amd_data *amd, size_t msgno)
+{
+  msgno--;
+  if (msgno >= amd->msg_count)
+    return NULL;
+  return amd->msg_array[msgno];
+}
+
+static int
+_amd_attach_message (mu_mailbox_t mailbox, struct _amd_message *mhm,
+                    mu_message_t *pmsg)
+{
+  int status;
+  mu_message_t msg;
+
+  /* Check if we already have it.  */
+  if (mhm->message)
+    {
+      if (pmsg)
+       *pmsg = mhm->message;
+      return 0;
+    }
+
+  /* Get an empty message struct.  */
+  status = mu_message_create (&msg, mhm);
+  if (status != 0)
+    return status;
+
+  /* Set the header.  */
+  {
+    mu_header_t header = NULL;
+    status = mu_header_create (&header, NULL, 0);
+    if (status != 0)
+      {
+       mu_message_destroy (&msg, mhm);
+       return status;
+      }
+    mu_header_set_fill (header, amd_header_fill, msg);
+    /*FIXME:
+    mu_header_set_get_fvalue (header, amd_header_get_fvalue, msg);
+    */
+    mu_message_set_header (msg, header, mhm);
+  }
+
+  /* Set the attribute.  */
+  {
+    mu_attribute_t attribute;
+    status = mu_attribute_create (&attribute, msg);
+    if (status != 0)
+      {
+       mu_message_destroy (&msg, mhm);
+       return status;
+      }
+    mu_attribute_set_get_flags (attribute, amd_get_attr_flags, msg);
+    mu_attribute_set_set_flags (attribute, amd_set_attr_flags, msg);
+    mu_attribute_set_unset_flags (attribute, amd_unset_attr_flags, msg);
+    mu_message_set_attribute (msg, attribute, mhm);
+  }
+
+  /* Prepare the body.  */
+  {
+    mu_body_t body = NULL;
+    struct _amd_body_stream *str;
+    
+    if ((status = mu_body_create (&body, msg)) != 0)
+      return status;
+
+    str = (struct _amd_body_stream *)
+              _mu_stream_create (sizeof (*str),
+                                mailbox->flags | MU_STREAM_SEEK | 
+                                _MU_STR_OPEN);
+    if (!str)
+      {
+       mu_body_destroy (&body, msg);
+       mu_message_destroy (&msg, mhm);
+       return ENOMEM;
+      }
+    str->stream.read = amd_body_stream_read;
+    str->stream.readdelim = amd_body_stream_readdelim;
+    str->stream.size = amd_body_stream_size;
+    str->stream.seek = amd_body_stream_seek;
+    mu_body_set_stream (body, (mu_stream_t) str, msg);
+    mu_body_clear_modified (body);
+    mu_body_set_size (body, amd_body_size, msg);
+    mu_body_set_lines (body, amd_body_lines, msg);
+    mu_message_set_body (msg, body, mhm);
+    str->body = body;
+  }
+
+  /* Set the envelope.  */
+  {
+    mu_envelope_t envelope = NULL;
+    status = mu_envelope_create (&envelope, msg);
+    if (status != 0)
+      {
+       mu_message_destroy (&msg, mhm);
+       return status;
+      }
+    mu_envelope_set_sender (envelope, amd_envelope_sender, msg);
+    mu_envelope_set_date (envelope, amd_envelope_date, msg);
+    mu_message_set_envelope (msg, envelope, mhm);
+  }
+
+  /* Set the UID.  */
+  if (mhm->amd->message_uid)
+    mu_message_set_uid (msg, mhm->amd->message_uid, mhm);
+  mu_message_set_qid (msg, amd_message_qid, mhm);
+  
+  /* Attach the message to the mailbox mbox data.  */
+  mhm->message = msg;
+  mu_message_set_mailbox (msg, mailbox, mhm);
+
+  /* Some of mu_message_set_ functions above mark message as modified.
+     Undo it now.
+
+     FIXME: Marking message as modified is not always appropriate. Find
+     a better way. */
+     
+  mu_message_clear_modified (msg);
+
+  if (pmsg)
+    *pmsg = msg;
+
+  return 0;
+}
+
+static int
+amd_get_message (mu_mailbox_t mailbox, size_t msgno, mu_message_t *pmsg)
+{
+  int status;
+  struct _amd_data *amd = mailbox->data;
+  struct _amd_message *mhm;
+
+  /* Sanity checks.  */
+  if (pmsg == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  if (amd == NULL)
+    return EINVAL;
+
+  /* If we did not start a scanning yet do it now.  */
+  if (amd->msg_count == 0)
+    {
+      status = amd->scan0 (mailbox, 1, NULL, 0);
+      if (status != 0)
+       return status;
+    }
+
+  if ((mhm = _amd_get_message (amd, msgno)) == NULL)
+    return EINVAL;
+  return _amd_attach_message (mailbox, mhm, pmsg);
+}
+
+static int
+amd_quick_get_message (mu_mailbox_t mailbox, mu_message_qid_t qid,
+                      mu_message_t *pmsg)
+{
+  int status;
+  struct _amd_data *amd = mailbox->data;
+  if (amd->msg_count)
+    {
+      mu_message_qid_t vqid;
+      mu_message_t msg = amd->msg_array[0]->message;
+      status = mu_message_get_qid (msg, &vqid);
+      if (status)
+       return status;
+      status = strcmp (qid, vqid);
+      free (vqid);
+      if (status)
+       return MU_ERR_EXISTS;
+      *pmsg = msg;
+    }
+  else if (amd->qfetch)
+    {
+      status = amd->qfetch (amd, qid);
+      if (status)
+       return status;
+      return _amd_attach_message (mailbox, amd->msg_array[0], pmsg);
+    }
+  
+  return ENOSYS;
+}
+
+static FILE *
+_amd_tempfile(struct _amd_data *amd, char **namep)
+{
+  int fd = mu_tempfile (amd->name, namep);
+  if (fd == -1)
+      return NULL;
+  return fdopen (fd, "w");
+}
+
+static int
+_amd_delim (char *str)
+{
+  if (str[0] == '-')
+    {
+      for (; *str == '-'; str++)
+       ;
+      for (; *str == ' ' || *str == '\t'; str++)
+       ;
+    }
+  return str[0] == '\n';
+}
+
+static int
+_amd_message_save (struct _amd_data *amd, struct _amd_message *mhm,
+                  int expunge)
+{
+  mu_stream_t stream = NULL;
+  char *name = NULL, *buf = NULL, *msg_name, *old_name;
+  size_t n;
+  size_t bsize;
+  size_t nlines, nbytes;
+  size_t new_body_start, new_header_lines;
+  FILE *fp;
+  mu_message_t msg = mhm->message;
+  mu_header_t hdr;
+  int status;
+  mu_attribute_t attr;
+  mu_body_t body;
+  const char *sbuf;
+  mu_envelope_t env = NULL;
+  char statbuf[MU_STATUS_BUF_SIZE];
+
+  status = mu_message_size (msg, &bsize);
+  if (status)
+    return status;
+
+  status = amd->new_msg_file_name (mhm, mhm->attr_flags, expunge, &msg_name);
+  if (status)
+    return status;
+  if (!msg_name)
+    {
+      /* Unlink the original file */
+      char *old_name;
+      status = amd->cur_msg_file_name (mhm, &old_name);
+      free (msg_name);
+      if (status == 0 && unlink (old_name))
+       status = errno;
+      free (old_name);
+      return status;
+    }      
+    
+  fp = _amd_tempfile (mhm->amd, &name);
+  if (!fp)
+    {
+      free (msg_name);
+      return errno;
+    }
+
+  /* Try to allocate large buffer */
+  for (; bsize > 1; bsize /= 2)
+    if ((buf = malloc (bsize)))
+      break;
+
+  if (!bsize)
+    {
+      unlink (name);
+      free (name);
+      free (msg_name);
+      return ENOMEM;
+    }
+
+  /* Copy flags */
+  mu_message_get_header (msg, &hdr);
+  mu_header_get_streamref (hdr, &stream);
+  status = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
+  if (status)
+    {
+      /* FIXME: Provide a common exit point for all error
+        cases */
+      unlink (name);
+      free (name);
+      free (msg_name);
+      mu_stream_destroy (&stream);
+      return status;
+    }
+      
+  nlines = nbytes = 0;
+  while ((status = mu_stream_readline (stream, buf, bsize, &n)) == 0
+        && n != 0)
+    {
+      if (_amd_delim (buf))
+       break;
+
+      if (!(mu_c_strncasecmp (buf, "status:", 7) == 0
+           || mu_c_strncasecmp (buf, "x-imapbase:", 11) == 0
+           || mu_c_strncasecmp (buf, "x-uid:", 6) == 0
+           || mu_c_strncasecmp (buf, 
+                MU_HEADER_ENV_DATE ":", sizeof (MU_HEADER_ENV_DATE)) == 0
+           || mu_c_strncasecmp (buf, 
+                MU_HEADER_ENV_SENDER ":", sizeof (MU_HEADER_ENV_SENDER)) == 0))
+       {
+         nlines++;
+         nbytes += fprintf (fp, "%s", buf);
+       }
+    }
+  mu_stream_destroy (&stream);
+  
+  /* Add imapbase */
+  if (!(amd->mailbox->flags & MU_STREAM_APPEND)
+      && amd->next_uid
+      && (!amd->msg_array || (amd->msg_array[0] == mhm))) /*FIXME*/
+    {
+      nbytes += fprintf (fp, "X-IMAPbase: %lu %u\n",
+                        (unsigned long) amd->uidvalidity,
+                        (unsigned) amd->next_uid (amd));
+      nlines++;
+    }
+  
+  mu_message_get_envelope (msg, &env);
+  if (mu_envelope_sget_date (env, &sbuf) == 0)
+    {
+      /* NOTE: buffer might be terminated with \n */
+      while (*sbuf && mu_isspace (*sbuf))
+       sbuf++;
+      nbytes += fprintf (fp, "%s: %s", MU_HEADER_ENV_DATE, sbuf);
+
+      if (*sbuf && sbuf[strlen (sbuf) - 1] != '\n')
+       nbytes += fprintf (fp, "\n");
+      
+      nlines++;
+    }
+         
+  if (mu_envelope_sget_sender (env, &sbuf) == 0)
+    {
+      fprintf (fp, "%s: %s\n", MU_HEADER_ENV_SENDER, sbuf);
+      nlines++;
+    }
+  
+  /* Add status */
+  mu_message_get_attribute (msg, &attr);
+  mu_attribute_to_string (attr, statbuf, sizeof (statbuf), &n);
+  if (n)
+    {
+      nbytes += fprintf (fp, "Status: %s\n", statbuf);
+      nlines++;
+    }
+  nbytes += fprintf (fp, "\n");
+  nlines++;
+  
+  new_header_lines = nlines;
+  new_body_start = nbytes;
+
+  /* Copy message body */
+
+  mu_message_get_body (msg, &body);
+  mu_body_get_streamref (body, &stream);
+  status = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
+  if (status)
+    {
+      unlink (name);
+      free (name);
+      free (msg_name);
+      mu_stream_destroy (&stream);
+      return status;
+    }
+    
+  nlines = 0;
+  while (mu_stream_read (stream, buf, bsize, &n) == 0 && n != 0)
+    {
+      char *p;
+      for (p = buf; p < buf + n; p++)
+       if (*p == '\n')
+         nlines++;
+      fwrite (buf, 1, n, fp);
+      nbytes += n;
+    }
+  mu_stream_destroy (&stream);
+  
+  mhm->header_lines = new_header_lines;
+  mhm->body_start = new_body_start;
+  mhm->body_lines = nlines;
+  mhm->body_end = nbytes;
+
+  free (buf);
+  fclose (fp);
+
+  status = amd->cur_msg_file_name (mhm, &old_name);
+  if (status == 0)
+    {
+      if (rename (name, msg_name))
+       status = errno;
+      else
+       {
+         mode_t perms;
+         
+         perms = mu_stream_flags_to_mode (amd->mailbox->flags, 0);
+         if (perms != 0)
+           {
+             /* It is documented that the mailbox permissions are
+                affected by the current umask, so take it into account
+                here.
+                FIXME: I'm still not sure we should honor umask, though.
+                --gray
+             */
+             mode_t mask = umask (0);
+             chmod (msg_name, (0600 | perms) & ~mask);
+             umask (mask);
+           }
+         if (strcmp (old_name, msg_name))
+           /* Unlink original message */
+           unlink (old_name);
+       }
+      free (old_name);
+      
+      mhm->orig_flags = mhm->attr_flags;
+    }
+  free (msg_name);
+  free (name);
+
+  return status;
+}
+
+static int
+amd_append_message (mu_mailbox_t mailbox, mu_message_t msg)
+{
+  int status;
+  struct _amd_data *amd = mailbox->data;
+  struct _amd_message *mhm;
+
+  if (!mailbox)
+    return MU_ERR_MBX_NULL;
+  if (!msg)
+    return EINVAL;
+
+  mhm = calloc (1, amd->msg_size);
+  if (!mhm)
+    return ENOMEM;
+    
+  /* If we did not start a scanning yet do it now.  */
+  if (amd->msg_count == 0)
+    {
+      status = amd->scan0 (mailbox, 1, NULL, 0);
+      if (status != 0)
+       {
+         free (mhm);
+         return status;
+       }
+    }
+
+  amd->has_new_msg = 1;
+  
+  mhm->amd = amd;
+  if (amd->msg_init_delivery)
+    {
+      status = amd->msg_init_delivery (amd, mhm);
+      if (status)
+       {
+         free (mhm);
+         return status;
+       }
+    }
+  
+  mhm->message = msg;
+  status = _amd_message_save (amd, mhm, 0);
+  if (status)
+    {
+      free (mhm);
+      return status;
+    }
+
+  mhm->message = NULL;
+  /* Insert and re-scan the message */
+  status = _amd_message_insert (amd, mhm);
+  if (status)
+    {
+      free (mhm);
+      return status;
+    }
+
+  if (amd->msg_finish_delivery)
+    status = amd->msg_finish_delivery (amd, mhm, msg);
+  
+  if (status == 0 && mailbox->observable)
+    {
+      char *qid;
+      if (amd->cur_msg_file_name (mhm, &qid) == 0)
+       {
+         mu_observable_notify (mailbox->observable, MU_EVT_MESSAGE_APPEND,
+                               qid);
+         free (qid);
+       }
+    }
+  
+  return status;
+}
+
+static int
+amd_messages_count (mu_mailbox_t mailbox, size_t *pcount)
+{
+  struct _amd_data *amd = mailbox->data;
+
+  if (amd == NULL)
+    return EINVAL;
+
+  if (!amd_is_updated (mailbox))
+    return amd->scan0 (mailbox,  amd->msg_count, pcount, 0);
+
+  if (pcount)
+    *pcount = amd->msg_count;
+
+  return 0;
+}
+
+/* A "recent" message is the one not marked with MU_ATTRIBUTE_SEEN
+   ('O' in the Status header), i.e. a message that is first seen
+   by the current session (see attributes.h) */
+static int
+amd_messages_recent (mu_mailbox_t mailbox, size_t *pcount)
+{
+  struct _amd_data *amd = mailbox->data;
+  size_t count, i;
+
+  /* If we did not start a scanning yet do it now.  */
+  if (amd->msg_count == 0)
+    {
+      int status = amd->scan0 (mailbox, 1, NULL, 0);
+      if (status != 0)
+       return status;
+    }
+  count = 0;
+  for (i = 0; i < amd->msg_count; i++)
+    {
+      if (MU_ATTRIBUTE_IS_UNSEEN(amd->msg_array[i]->attr_flags))
+       count++;
+    }
+  *pcount = count;
+  return 0;
+}
+
+/* An "unseen" message is the one that has not been read yet */
+static int
+amd_message_unseen (mu_mailbox_t mailbox, size_t *pmsgno)
+{
+  struct _amd_data *amd = mailbox->data;
+  size_t i;
+
+  /* If we did not start a scanning yet do it now.  */
+  if (amd->msg_count == 0)
+    {
+      int status = amd->scan0 (mailbox, 1, NULL, 0);
+      if (status != 0)
+       return status;
+    }
+
+  for (i = 0; i < amd->msg_count; i++)
+    {
+      if (MU_ATTRIBUTE_IS_UNREAD(amd->msg_array[0]->attr_flags))
+       {
+         *pmsgno = i + 1;
+         break;
+       }
+    }
+  return 0;
+}
+
+static char *
+make_size_file_name (struct _amd_data *amd)
+{
+  size_t size = strlen (amd->name) + 1 + sizeof (MU_AMD_SIZE_FILE_NAME);
+  char *name = malloc (size);
+  if (name)
+    {
+      strcpy (name, amd->name);
+      strcat (name, "/");
+      strcat (name, MU_AMD_SIZE_FILE_NAME);
+    }
+  return name;
+}
+
+static int
+read_size_file (struct _amd_data *amd, mu_off_t *psize)
+{
+  FILE *fp;
+  int rc;
+  char *name = make_size_file_name (amd);
+  if (!name)
+    return 1;
+  fp = fopen (name, "r");
+  if (fp)
+    {
+      unsigned long size;
+      if (fscanf (fp, "%lu", &size) == 1)
+       {
+         *psize = size;
+         rc = 0;
+       }
+      else
+       rc = 1;
+      fclose (fp);
+    }
+  else
+    rc = 1;
+  free (name);
+  return rc;
+}
+
+static int
+write_size_file (struct _amd_data *amd, mu_off_t size)
+{
+  FILE *fp;
+  int rc;
+  char *name = make_size_file_name (amd);
+  if (!name)
+    return 1;
+  fp = fopen (name, "w");
+  if (fp)
+    {
+      fprintf (fp, "%lu", (unsigned long) size);
+      fclose (fp);
+      rc = 0;
+    }
+  else
+    rc = 1;
+  free (name);
+  return rc;
+}
+      
+static int
+compute_mailbox_size (struct _amd_data *amd, const char *name, mu_off_t *psize)
+{
+  DIR *dir;
+  struct dirent *entry;
+  char *buf;
+  size_t bufsize;
+  size_t dirlen;
+  size_t flen;
+  int status = 0;
+  struct stat sb;
+
+  dir = opendir (name);
+  if (!dir)
+    return errno;
+
+  dirlen = strlen (name);
+  bufsize = dirlen + 32;
+  buf = malloc (bufsize);
+  if (!buf)
+    {
+      closedir (dir);
+      return ENOMEM;
+    }
+  
+  strcpy (buf, name);
+  if (buf[dirlen-1] != '/')
+    buf[++dirlen - 1] = '/';
+         
+  while ((entry = readdir (dir)))
+    {
+      switch (entry->d_name[0])
+       {
+       case '.':
+         break;
+
+       default:
+         flen = strlen (entry->d_name);
+         if (dirlen + flen + 1 > bufsize)
+           {
+             bufsize = dirlen + flen + 1;
+             buf = realloc (buf, bufsize);
+             if (!buf)
+               {
+                 status = ENOMEM;
+                 break;
+               }
+           }
+         strcpy (buf + dirlen, entry->d_name);
+         if (stat (buf, &sb) == 0)
+           {
+             if (S_ISREG (sb.st_mode))
+               *psize += sb.st_size;
+             else if (S_ISDIR (sb.st_mode))
+               compute_mailbox_size (amd, buf, psize);
+           }
+         /* FIXME: else? */
+         break;
+       }
+    }
+
+  free (buf);
+  
+  closedir (dir);
+  return 0;
+}
+
+static int
+amd_remove_mbox (mu_mailbox_t mailbox)
+{
+  int rc;
+  struct _amd_data *amd = mailbox->data;
+  
+  if (!amd->remove)
+    return ENOSYS;
+  rc = amd->remove (amd);
+  if (rc == 0)
+    {
+      char *name = make_size_file_name (amd);
+      if (!name)
+       return ENOMEM;
+      if (unlink (name) && errno != ENOENT)
+       rc = errno;
+      free (name);
+    }
+
+  if (rc == 0)
+    {
+      if (rmdir (amd->name) && errno != ENOENT)
+       {
+         rc = errno;
+         /* POSIX.1-2001 allows EEXIST to be returned if the directory
+            contained entries other than . and .. */
+         if (rc == EEXIST)
+           rc = ENOTEMPTY;
+       }
+    }
+  
+  return rc;
+}
+
+static int
+amd_expunge (mu_mailbox_t mailbox)
+{
+  struct _amd_data *amd = mailbox->data;
+  struct _amd_message *mhm;
+  size_t i;
+  int updated = amd->has_new_msg;
+  
+  if (amd == NULL)
+    return EINVAL;
+
+  if (amd->msg_count == 0)
+    return 0;
+
+  /* Find the first dirty(modified) message.  */
+  for (i = 0; i < amd->msg_count; i++)
+    {
+      mhm = amd->msg_array[i];
+      if ((mhm->attr_flags & MU_ATTRIBUTE_MODIFIED) ||
+         (mhm->attr_flags & MU_ATTRIBUTE_DELETED) ||
+         (mhm->message && mu_message_is_modified (mhm->message)))
+       break;
+    }
+
+  while (i < amd->msg_count)
+    {
+      mhm = amd->msg_array[i];
+      
+      if (mhm->attr_flags & MU_ATTRIBUTE_DELETED)
+       {
+         int rc;
+         char *old_name;
+         char *new_name;
+
+         rc = amd->cur_msg_file_name (mhm, &old_name);
+         if (rc)
+           return rc;
+         rc = amd->new_msg_file_name (mhm, mhm->attr_flags, 1,
+                                      &new_name);
+         if (rc)
+           {
+             free (old_name);
+             return rc;
+           }
+
+         if (new_name)
+           {
+             /* FIXME: It may be a good idea to have a capability flag
+                in struct _amd_data indicating that no actual removal
+                is needed (e.g. for traditional MH). It will allow to
+                bypass lots of no-op code here. */
+             if (strcmp (old_name, new_name))
+               /* Rename original message */
+               rename (old_name, new_name);
+           }
+         else
+           /* Unlink original file */
+           unlink (old_name);
+         
+         free (old_name);
+         free (new_name);
+
+         _amd_message_delete (amd, mhm);
+         updated = 1;
+         /* Do not increase i! */
+       }
+      else
+       {
+         if ((mhm->attr_flags & MU_ATTRIBUTE_MODIFIED)
+             || (mhm->message && mu_message_is_modified (mhm->message)))
+           {
+             _amd_attach_message (mailbox, mhm, NULL);
+             _amd_message_save (amd, mhm, 1);
+             updated = 1;
+           }
+         i++; /* Move to the next message */
+       }
+    }
+
+  if (updated && !amd->mailbox_size)
+    {
+      mu_off_t size = 0;
+      int rc = compute_mailbox_size (amd, amd->name, &size);
+      if (rc == 0)
+       write_size_file (amd, size);
+    }
+  return 0;
+}
+
+static int
+amd_sync (mu_mailbox_t mailbox)
+{
+  struct _amd_data *amd = mailbox->data;
+  struct _amd_message *mhm;
+  size_t i;
+  int updated = amd->has_new_msg;
+  
+  if (amd == NULL)
+    return EINVAL;
+
+  if (amd->msg_count == 0)
+    return 0;
+
+  /* Find the first dirty(modified) message.  */
+  for (i = 0; i < amd->msg_count; i++)
+    {
+      mhm = amd->msg_array[i];
+      if ((mhm->attr_flags & MU_ATTRIBUTE_MODIFIED)
+         || (mhm->message && mu_message_is_modified (mhm->message)))
+       break;
+    }
+
+  for ( ; i < amd->msg_count; i++)
+    {
+      mhm = amd->msg_array[i];
+
+      if ((mhm->attr_flags & MU_ATTRIBUTE_MODIFIED)
+         || (mhm->message && mu_message_is_modified (mhm->message)))
+       {
+         _amd_attach_message (mailbox, mhm, NULL);
+         _amd_message_save (amd, mhm, 0);
+         updated = 1;
+       }
+    }
+
+  if (updated && !amd->mailbox_size)
+    {
+      mu_off_t size = 0;
+      int rc = compute_mailbox_size (amd, amd->name, &size);
+      if (rc == 0)
+       write_size_file (amd, size);
+    }
+
+  return 0;
+}
+
+static int
+amd_uidvalidity (mu_mailbox_t mailbox, unsigned long *puidvalidity)
+{
+  struct _amd_data *amd = mailbox->data;
+  int status = amd_messages_count (mailbox, NULL);
+  if (status != 0)
+    return status;
+  /* If we did not start a scanning yet do it now.  */
+  if (amd->msg_count == 0)
+    {
+      status = amd->scan0 (mailbox, 1, NULL, 0);
+      if (status != 0)
+       return status;
+    }
+  if (puidvalidity)
+    *puidvalidity = amd->uidvalidity;
+  return 0;
+}
+
+static int
+amd_uidnext (mu_mailbox_t mailbox, size_t *puidnext)
+{
+  struct _amd_data *amd = mailbox->data;
+  int status;
+  
+  if (!amd->next_uid)
+    return ENOSYS;
+  status = mu_mailbox_messages_count (mailbox, NULL);
+  if (status != 0)
+    return status;
+  /* If we did not start a scanning yet do it now.  */
+  if (amd->msg_count == 0)
+    {
+      status = amd->scan0 (mailbox, 1, NULL, 0);
+      if (status != 0)
+       return status;
+    }
+   if (puidnext)
+     *puidnext = amd->next_uid (amd);
+  return 0;
+}
+
+/* FIXME: effectively the same as mbox_cleanup */
+void
+amd_cleanup (void *arg)
+{
+  mu_mailbox_t mailbox = arg;
+  mu_monitor_unlock (mailbox->monitor);
+  mu_locker_unlock (mailbox->locker);
+}
+
+/* Insert message msg into the message list on the appropriate position */
+int
+_amd_message_insert (struct _amd_data *amd, struct _amd_message *msg)
+{
+  size_t index;
+
+  if (amd_msg_lookup (amd, msg, &index))
+    {
+      /* Not found. Index is the index of the array cell where msg
+        must be placed */
+      int rc = amd_array_expand (amd, index);
+      if (rc)
+       return rc;
+      amd->msg_array[index] = msg;
+      msg->amd = amd;
+    }
+  else
+    {
+      /*FIXME: Found? Shouldn't happen */
+      return EEXIST;
+    }
+  return 0;
+}
+
+static void
+_amd_message_delete (struct _amd_data *amd, struct _amd_message *msg)
+{
+  size_t index;
+  struct _amd_message **pp;
+
+  if (amd_msg_lookup (amd, msg, &index))
+    {
+      /* FIXME: Not found? */
+      return;
+    }
+
+  msg = _amd_get_message (amd, index);
+
+  pp = amd_pool_lookup (msg);
+  if (pp)
+    *pp = NULL;
+  
+  mu_message_destroy (&msg->message, msg);
+  if (amd->msg_free)
+    amd->msg_free (msg);
+  free (msg);
+  amd_array_shrink (amd, index);
+}
+
+/* Scan given message and fill amd_message_t fields.
+   NOTE: the function assumes mhm->stream != NULL. */
+static int
+amd_scan_message (struct _amd_message *mhm)
+{
+  mu_stream_t stream = mhm->stream;
+  char buf[1024];
+  size_t off;
+  size_t n;
+  int status;
+  int in_header = 1;
+  size_t hlines = 0;
+  size_t blines = 0;
+  size_t body_start = 0;
+  struct stat st;
+  char *msg_name;
+
+  /* Check if the message was modified after the last scan */
+  status = mhm->amd->cur_msg_file_name (mhm, &msg_name);
+  if (status)
+    return status;
+
+  if (stat (msg_name, &st) == 0 && st.st_mtime == mhm->mtime)
+    {
+      /* Nothing to do */
+      free (msg_name);
+      return 0;
+    }
+  free (msg_name);
+
+  off = 0;
+  status = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
+  if (status == 0)
+    while ((status = mu_stream_readline (stream, buf, sizeof (buf), &n)) == 0
+          && n != 0)
+      {
+       if (in_header)
+         {
+           if (buf[0] == '\n')
+             {
+               in_header = 0;
+               body_start = off + 1;
+             }
+           if (buf[n - 1] == '\n')
+             hlines++;
+           
+           /* Process particular attributes */
+           if (mu_c_strncasecmp (buf, "status:", 7) == 0)
+             {
+               int deleted = mhm->attr_flags & MU_ATTRIBUTE_DELETED;
+               mu_string_to_flags (buf, &mhm->attr_flags);
+               mhm->attr_flags |= deleted;
+             }
+           else if (mu_c_strncasecmp (buf, "x-imapbase:", 11) == 0)
+             {
+               char *p;
+               mhm->amd->uidvalidity = strtoul (buf + 11, &p, 10);
+               /* second number is next uid. Ignored */
+             }
+         }
+       else
+         {
+           if (buf[n - 1] == '\n')
+             blines++;
+         }
+       off += n;
+      }
+
+  if (status == 0)
+    {
+      mhm->mtime = st.st_mtime;
+      if (!body_start)
+       body_start = off;
+      mhm->header_lines = hlines;
+      mhm->body_lines = blines;
+      mhm->body_start = body_start;
+      mhm->body_end = off;
+    }
+  return status;
+}
+
+static int
+amd_scan (mu_mailbox_t mailbox, size_t msgno, size_t *pcount)
+{
+  struct _amd_data *amd = mailbox->data;
+
+  if (! amd_is_updated (mailbox))
+    return amd->scan0 (mailbox, msgno, pcount, 1);
+
+  if (pcount)
+    *pcount = amd->msg_count;
+
+  return 0;
+}
+
+/* Is the internal representation of the mailbox up to date.
+   Return 1 if so, 0 otherwise. */
+static int
+amd_is_updated (mu_mailbox_t mailbox)
+{
+  struct stat st;
+  struct _amd_data *amd = mailbox->data;
+
+  if (stat (amd->name, &st) < 0)
+    return 1;
+
+  return amd->mtime == st.st_mtime;
+}
+
+static int
+amd_get_size (mu_mailbox_t mailbox, mu_off_t *psize)
+{
+  struct _amd_data *amd = mailbox->data;
+  if (amd->mailbox_size)
+    return amd->mailbox_size (mailbox, psize);
+  *psize = 0;
+  if (read_size_file (amd, psize))
+    {
+      int rc = compute_mailbox_size (amd, amd->name, psize);
+      if (rc == 0)
+       write_size_file (amd, *psize);
+      return rc;
+    }
+  return 0;
+}
+
+/* Return number of open streams residing in a message pool */
+static int
+amd_pool_open_count (struct _amd_data *amd)
+{
+  int cnt = amd->pool_last - amd->pool_first;
+  if (cnt < 0)
+    cnt += MAX_OPEN_STREAMS;
+  return cnt;
+}
+
+/* Look up a _amd_message in the pool of open messages.
+   If the message is found in the pool, returns the address of
+   the pool slot occupied by it. Otherwise returns NULL. */
+static struct _amd_message **
+amd_pool_lookup (struct _amd_message *mhm)
+{
+  struct _amd_data *amd = mhm->amd;
+  int i;
+
+  for (i = amd->pool_first; i != amd->pool_last; )
+    {
+      if (amd->msg_pool[i] == mhm)
+       return &amd->msg_pool[i];
+      if (++i == MAX_OPEN_STREAMS)
+       i = 0;
+    }
+  return NULL;
+}
+
+/* Open a stream associated with the message mhm. If the stream is
+   already open, do nothing.
+   NOTE: We could have reused the NULL holes in the msg_pool, but
+   that hardly is worth the effort, since the holes appear only when
+   expunging. On the other hand this may be useful when MAX_OPEN_STREAMS
+   size is very big. "Premature optimization is the root of all evil" */
+static int
+amd_pool_open (struct _amd_message *mhm)
+{
+  int status;
+  struct _amd_data *amd = mhm->amd;
+  if (amd_pool_lookup (mhm))
+    return 0;
+  if (amd_pool_open_count(amd) == MAX_OPEN_STREAMS-1)
+    {
+      amd_message_stream_close (amd->msg_pool[amd->pool_first++]);
+      amd->pool_first %= MAX_OPEN_STREAMS;
+    }
+  status = amd_message_stream_open (mhm);
+  if (status)
+    return status;
+  amd->msg_pool[amd->pool_last++] = mhm;
+  amd->pool_last %= MAX_OPEN_STREAMS;
+  return 0;
+}
+
+static void
+amd_pool_flush (struct _amd_data *amd)
+{
+  int i;
+  
+  for (i = amd->pool_first; i != amd->pool_last; )
+    {
+      if (amd->msg_pool[i])
+       amd_message_stream_close (amd->msg_pool[i]);
+      if (++i == MAX_OPEN_STREAMS)
+       i = 0;
+    }
+  amd->pool_first = amd->pool_last = 0;
+}
+
+/* Attach a stream to a given message structure. The latter is supposed
+   to be already added to the open message pool. */
+int
+amd_message_stream_open (struct _amd_message *mhm)
+{
+  struct _amd_data *amd = mhm->amd;
+  char *filename;
+  int status;
+  int flags = MU_STREAM_ALLOW_LINKS;
+
+  status = amd->cur_msg_file_name (mhm, &filename);
+  if (status)
+    return status;
+
+  /* The message should be at least readable */
+  if (amd->mailbox->flags & (MU_STREAM_RDWR|MU_STREAM_WRITE|MU_STREAM_APPEND))
+    flags |= MU_STREAM_RDWR;
+  else 
+    flags |= MU_STREAM_READ;
+  status = mu_file_stream_create (&mhm->stream, filename, flags);
+
+  free (filename);
+
+  if (status != 0)
+    return status;
+
+  /* FIXME: Select buffer size dynamically */
+  mu_stream_set_buffer (mhm->stream, mu_buffer_full, 16384);
+  
+  status = amd_scan_message (mhm);
+
+  return status;
+}
+
+/* Close the stream associated with the given message. */
+void
+amd_message_stream_close (struct _amd_message *mhm)
+{
+  if (mhm)
+    {
+      mu_stream_close (mhm->stream);
+      mhm->stream = NULL;
+    }
+}
+
+void
+amd_check_message (struct _amd_message *mhm)
+{
+  if (mhm->body_end == 0)
+    amd_pool_open (mhm);
+}
+
+/* Reading functions */
+static int
+amd_body_stream_read (mu_stream_t is, char *buffer, size_t buflen,
+                     size_t *pnread)
+{
+  struct _amd_body_stream *amdstr = (struct _amd_body_stream *)is;
+  mu_body_t body = amdstr->body;
+  mu_message_t msg = mu_body_get_owner (body);
+  struct _amd_message *mhm = mu_message_get_owner (msg);
+  size_t nread = 0;
+  int status = 0;
+  mu_off_t ln;
+
+  amd_pool_open (mhm);
+
+  if (buffer == NULL || buflen == 0)
+    {
+      *pnread = nread;
+      return 0;
+    }
+
+  mu_monitor_rdlock (mhm->amd->mailbox->monitor);
+#ifdef WITH_PTHREAD
+  /* read() is cancellation point since we're doing a potentially
+     long operation.  Lets make sure we clean the state.  */
+  pthread_cleanup_push (amd_cleanup, (void *)mhm->amd->mailbox);
+#endif
+
+  ln = mhm->body_end - (mhm->body_start + amdstr->off);
+  if (ln > 0)
+    {
+      nread = ((size_t)ln < buflen) ? (size_t)ln : buflen;
+      status = mu_stream_seek (mhm->stream, mhm->body_start + amdstr->off,
+                              MU_SEEK_SET, NULL);
+      if (status == 0)
+       {
+         status = mu_stream_read (mhm->stream, buffer, nread, &nread);
+         amdstr->off += nread;
+       }
+    }
+
+  *pnread = nread;
+
+  mu_monitor_unlock (mhm->amd->mailbox->monitor);
+#ifdef WITH_PTHREAD
+  pthread_cleanup_pop (0);
+#endif
+
+  return status;
+}
+
+static int
+amd_body_stream_readdelim (mu_stream_t is, char *buffer, size_t buflen,
+                          int delim,
+                          size_t *pnread)
+{
+  struct _amd_body_stream *amdstr = (struct _amd_body_stream *)is;
+  mu_body_t body = amdstr->body;
+  mu_message_t msg = mu_body_get_owner (body);
+  struct _amd_message *mhm = mu_message_get_owner (msg);
+  int status = 0;
+
+  amd_pool_open (mhm);
+
+  if (buffer == NULL || buflen == 0)
+    {
+      if (pnread)
+       *pnread = 0;
+      return 0;
+    }
+
+  mu_monitor_rdlock (mhm->amd->mailbox->monitor);
+#ifdef WITH_PTHREAD
+  /* read() is cancellation point since we're doing a potentially
+     long operation.  Lets make sure we clean the state.  */
+  pthread_cleanup_push (amd_cleanup, (void *)mhm->amd->mailbox);
+#endif
+
+  status = mu_stream_seek (mhm->stream, mhm->body_start + amdstr->off,
+                          MU_SEEK_SET, NULL);
+  if (status == 0)
+    {
+      size_t nread = 0;
+      size_t ln;
+         
+      ln = mhm->body_end - (mhm->body_start + amdstr->off) + 1;
+      if (ln > 0)
+       {
+         size_t rdsize = ((size_t)ln < buflen) ? (size_t)ln : buflen;
+         status = mu_stream_readdelim (mhm->stream, buffer, rdsize,
+                                       delim, &nread);
+         amdstr->off += nread;
+       }
+
+      if (pnread)
+       *pnread = nread;
+    }
+
+  mu_monitor_unlock (mhm->amd->mailbox->monitor);
+#ifdef WITH_PTHREAD
+  pthread_cleanup_pop (0);
+#endif
+
+  return status;
+}
+
+static int
+amd_body_stream_seek (mu_stream_t str, mu_off_t off, mu_off_t *presult)
+{
+  size_t size;
+  struct _amd_body_stream *amdstr = (struct _amd_body_stream *)str;
+  
+  amd_body_size (amdstr->body, &size);
+
+  if (off < 0 || off > size)
+    return ESPIPE;
+
+  amdstr->off = off;
+  if (presult)
+    *presult = off;
+  return 0;
+}
+
+/* Return corresponding sizes */
+
+static int
+amd_body_stream_size (mu_stream_t stream, mu_off_t *psize)
+{
+  mu_body_t body = ((struct _amd_body_stream *)stream)->body;
+  size_t size;
+  int rc = amd_body_size (body, &size);
+  if (rc == 0)
+    *psize = size;
+  return rc;
+}
+
+static int
+amd_body_size (mu_body_t body, size_t *psize)
+{
+  mu_message_t msg = mu_body_get_owner (body);
+  struct _amd_message *mhm = mu_message_get_owner (msg);
+  if (mhm == NULL)
+    return EINVAL;
+  amd_check_message (mhm);
+  if (psize)
+    *psize = mhm->body_end - mhm->body_start;
+  return 0;
+}
+
+static int
+amd_body_lines (mu_body_t body, size_t *plines)
+{
+  mu_message_t msg = mu_body_get_owner (body);
+  struct _amd_message *mhm = mu_message_get_owner (msg);
+  if (mhm == NULL)
+    return EINVAL;
+  amd_check_message (mhm);
+  if (plines)
+    *plines = mhm->body_lines;
+  return 0;
+}
+
+/* Headers */
+static int
+amd_header_fill (void *data, char **pbuf, size_t *plen)
+{
+  char *buffer;
+  size_t len;
+  mu_message_t msg = data;
+  struct _amd_message *mhm = mu_message_get_owner (msg);
+  int status, rc;
+  mu_off_t pos;
+  
+  status = amd_pool_open (mhm);
+  if (status)
+    return status;
+
+  len = mhm->body_start;
+  buffer = malloc (len);
+  if (!buffer)
+    return ENOMEM;
+  
+  status = mu_stream_seek (mhm->stream, 0, MU_SEEK_CUR, &pos);
+  if (status)
+    return status;
+  status = mu_stream_seek (mhm->stream, 0, MU_SEEK_SET, NULL);
+  if (status)
+    return status;
+
+  status = mu_stream_read (mhm->stream, buffer, len, NULL);
+  rc = mu_stream_seek (mhm->stream, pos, MU_SEEK_SET, NULL);
+
+  if (!status)
+    status = rc;
+  
+  if (status)
+    {
+      free (buffer);
+      return status;
+    }
+
+  *plen = len;
+  *pbuf = buffer;
+  return 0;
+}
+
+/* Attributes */
+static int
+amd_get_attr_flags (mu_attribute_t attr, int *pflags)
+{
+  mu_message_t msg = mu_attribute_get_owner (attr);
+  struct _amd_message *mhm = mu_message_get_owner (msg);
+
+  if (mhm == NULL)
+    return EINVAL;
+  if (pflags)
+    *pflags = mhm->attr_flags;
+  return 0;
+}
+
+static int
+amd_set_attr_flags (mu_attribute_t attr, int flags)
+{
+  mu_message_t msg = mu_attribute_get_owner (attr);
+  struct _amd_message *mhm = mu_message_get_owner (msg);
+
+  if (mhm == NULL)
+    return EINVAL;
+  mhm->attr_flags |= flags;
+  return 0;
+}
+
+static int
+amd_unset_attr_flags (mu_attribute_t attr, int flags)
+{
+  mu_message_t msg = mu_attribute_get_owner (attr);
+  struct _amd_message *mhm = mu_message_get_owner (msg);
+
+  if (mhm == NULL)
+    return EINVAL;
+  mhm->attr_flags &= ~flags;
+  return 0;
+}
+
+/* Envelope */
+static int
+amd_envelope_date (mu_envelope_t envelope, char *buf, size_t len,
+                  size_t *psize)
+{
+  mu_message_t msg = mu_envelope_get_owner (envelope);
+  struct _amd_message *mhm = mu_message_get_owner (msg);
+  mu_header_t hdr = NULL;
+  char *date;
+  int status;
+  
+  if (mhm == NULL)
+    return EINVAL;
+
+  if ((status = mu_message_get_header (msg, &hdr)) != 0)
+    return status;
+  if (mu_header_aget_value (hdr, MU_HEADER_ENV_DATE, &date)
+      && mu_header_aget_value (hdr, MU_HEADER_DELIVERY_DATE, &date))
+    return MU_ERR_NOENT;
+  else
+    {
+      time_t t;
+      int rc;
+      
+      /* Convert to ctime format */
+      rc = mu_parse_date (date, &t, NULL); /* FIXME: TZ info is lost */
+      free (date);
+      if (rc)
+       return MU_ERR_NOENT;
+      date = strdup (ctime (&t)); 
+    }
+
+  /* Format:  "sender date" */
+  if (buf && len > 0)
+    {
+      len--; /* Leave space for the null.  */
+      strncpy (buf, date, len);
+      if (strlen (date) < len)
+       {
+         len = strlen (buf);
+         if (buf[len-1] != '\n')
+           buf[len++] = '\n';
+       }
+      buf[len] = '\0';
+    }
+  else
+    len = strlen (date);
+  
+  free (date);
+  
+  if (psize)
+    *psize = len;
+  return 0;
+}
+
+static int
+amd_envelope_sender (mu_envelope_t envelope, char *buf, size_t len, size_t 
*psize)
+{
+  mu_message_t msg = mu_envelope_get_owner (envelope);
+  struct _amd_message *mhm = mu_message_get_owner (msg);
+  mu_header_t hdr = NULL;
+  char *from;
+  int status;
+
+  if (mhm == NULL)
+    return EINVAL;
+
+  if ((status = mu_message_get_header (msg, &hdr)))
+    return status;
+  if ((status = mu_header_aget_value (hdr, MU_HEADER_ENV_SENDER, &from)))
+    return status;
+
+  if (buf && len > 0)
+    {
+      int slen = strlen (from);
+
+      if (len < slen + 1)
+       slen = len - 1;
+      memcpy (buf, from, slen);
+      buf[slen] = 0;
+    }
+  else
+    len = strlen (from);
+
+  if (psize)
+    *psize = len;
+  return 0;
+}
+
+
+int
+amd_remove_dir (const char *name)
+{
+  DIR *dir;
+  struct dirent *ent;
+  char *namebuf;
+  size_t namelen, namesize;
+  int rc = 0;
+  int has_subdirs = 0;
+  
+  namelen = strlen (name);
+  namesize = namelen + 128;
+  namebuf = malloc (namesize);
+  if (!namebuf)
+    return ENOMEM;
+  memcpy (namebuf, name, namelen);
+  if (namebuf[namelen - 1] != '/')
+    namebuf[namelen++] = '/';
+  
+  dir = opendir (name);
+  if (!dir)
+    return errno;
+  while ((ent = readdir (dir)))
+    {
+      struct stat st;
+      size_t len;
+
+      if (strcmp (ent->d_name, ".") == 0 ||
+         strcmp (ent->d_name, "..") == 0)
+       continue;
+      len = strlen (ent->d_name);
+      if (namelen + len >= namesize)
+       {
+         char *p;
+
+         namesize += len + 1;
+         p = realloc (namebuf, namesize);
+         if (!p)
+           {
+             rc = ENOMEM;
+             break;
+           }
+       }
+      strcpy (namebuf + namelen, ent->d_name);
+      if (stat (namebuf, &st) == 0 && S_ISDIR (st.st_mode))
+       {
+         has_subdirs = 1;
+         continue;
+       }
+      
+      if (unlink (namebuf))
+       {
+         rc = errno;
+         mu_diag_output (MU_DIAG_WARNING,
+                         "failed to remove %s: %s",
+                         namebuf, mu_strerror (rc));
+         break;
+       }
+    }
+  closedir (dir);
+  free (namebuf);
+
+  if (rc == 0 && !has_subdirs)
+    {
+      if (rmdir (name))
+       {
+         rc = errno;
+         /* POSIX.1-2001 allows EEXIST to be returned if the directory
+            contained entries other than . and .. */
+         if (rc == EEXIST)
+           rc = ENOTEMPTY;
+       }
+    }
+  return rc;
+}
+
+
diff --git a/libmailutils/base/argcv.c b/libmailutils/base/argcv.c
new file mode 100644
index 0000000..6e63b23
--- /dev/null
+++ b/libmailutils/base/argcv.c
@@ -0,0 +1,548 @@
+/* argcv.c - simple functions for parsing input based on whitespace
+   Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2010 Free
+   Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <ctype.h>
+#include <errno.h>
+#include <mailutils/argcv.h>
+
+/* Keep mailutils namespace clean */
+#define argcv_get            mu_argcv_get 
+#define argcv_get_n          mu_argcv_get_n 
+#define argcv_get_np         mu_argcv_get_np 
+#define argcv_string         mu_argcv_string
+#define argcv_free           mu_argcv_free
+#define argv_free            mu_argv_free 
+#define argcv_unquote_char   mu_argcv_unquote_char
+#define argcv_quote_char     mu_argcv_quote_char  
+#define argcv_quoted_length  mu_argcv_quoted_length
+#define argcv_unquote_copy   mu_argcv_unquote_copy 
+#define argcv_quote_copy     mu_argcv_quote_copy     
+
+/*
+ * takes a string and splits it into several strings, breaking at ' '
+ * command is the string to split
+ * the number of strings is placed into argc
+ * the split strings are put into argv
+ * returns 0 on success, nonzero on failure
+ */
+
+#define isws(c) ((c)==' '||(c)=='\t'||(c)=='\n')
+#define isdelim(c,delim) (strchr(delim,(c))!=NULL)
+
+struct argcv_info
+{
+  int len;
+  const char *command;
+  const char *delim;
+  const char *comment;
+  int flags;
+  
+  int start;
+  int end;
+  int save;
+  int finish_pos;
+};
+
+static void
+init_argcv_info (struct argcv_info *ap, int flags,
+                int len, const char *command, const char *delim,
+                const char *comment)
+{
+  memset (ap, 0, sizeof *ap);
+  ap->len = len;
+  ap->command = command;
+  ap->delim = delim;
+  ap->comment = comment;
+  ap->flags = flags;
+}
+
+static int
+argcv_scan (struct argcv_info *ap)
+{
+  int i = 0;
+  int len = ap->len;
+  const char *command = ap->command;
+  const char *delim = ap->delim;
+  const char *comment = ap->comment;
+  
+  for (;;)
+    {
+      i = ap->save;
+
+      if (i >= len)
+       return i + 1;
+
+      /* Skip initial whitespace */
+      while (i < len && isws (command[i]))
+       i++;
+      ap->start = i;
+
+      if (!isdelim (command[i], delim))
+       {
+         while (i < len)
+           {
+             if (command[i] == '\\')
+               {
+                 if (++i == len)
+                   break;
+                 i++;
+                 continue;
+               }
+             
+             if (command[i] == '\'' || command[i] == '"')
+               {
+                 int j;
+                 for (j = i + 1; j < len && command[j] != command[i]; j++)
+                   if (command[j] == '\\')
+                     j++;
+                 if (j < len)
+                   i = j + 1;
+                 else
+                   i++;
+               }
+             else if (isws (command[i]) || isdelim (command[i], delim))
+               break;
+             else
+               i++; /* skip the escaped character */
+           }
+         i--;
+       }
+      else if (!(ap->flags & MU_ARGCV_RETURN_DELIMS))
+       {
+         while (i < len && isdelim (command[i], delim))
+           i++;
+         ap->save = i;
+         continue;
+       }
+      
+
+      ap->end = i;
+      ap->save = ap->finish_pos = i + 1;
+
+      /* If we have a token, and it starts with a comment character, skip
+         to the newline and restart the token search. */
+      if (ap->save <= len)
+       {
+         if (strchr (comment, command[ap->start]) != NULL)
+           {
+             ap->finish_pos = ap->start;
+             i = ap->save;
+             while (i < len && command[i] != '\n')
+               i++;
+
+             ap->save = i;
+             continue;
+           }
+       }
+      break;
+    }
+  return ap->save;
+}
+
+static char quote_transtab[] = "\\\\\"\"a\ab\bf\fn\nr\rt\tv\v";
+
+int
+argcv_unquote_char (int c)
+{
+  char *p;
+
+  for (p = quote_transtab; *p; p += 2)
+    {
+      if (*p == c)
+       return p[1];
+    }
+  return c;
+}
+
+int
+argcv_quote_char (int c)
+{
+  char *p;
+  
+  for (p = quote_transtab + sizeof(quote_transtab) - 2;
+       p > quote_transtab; p -= 2)
+    {
+      if (*p == c)
+       return p[-1];
+    }
+  return -1;
+}
+  
+#define to_num(c) \
+  (isdigit(c) ? c - '0' : (isxdigit(c) ? toupper(c) - 'A' + 10 : 255 ))
+
+static int
+xtonum (int *pval, const char *src, int base, int cnt)
+{
+  int i, val;
+  
+  for (i = 0, val = 0; i < cnt; i++, src++)
+    {
+      int n = *(unsigned char*)src;
+      if (n > 127 || (n = to_num(n)) >= base)
+       break;
+      val = val*base + n;
+    }
+  *pval = val;
+  return i;
+}
+
+size_t
+argcv_quoted_length (const char *str, int *quote)
+{
+  size_t len = 0;
+
+  *quote = 0;
+  for (; *str; str++)
+    {
+      if (*str == ' ')
+       {
+         len++;
+         *quote = 1;
+       }
+      else if (*str == '"')
+       {
+         len += 2;
+         *quote = 1;
+       }
+      else if (*str != '\t' && *str != '\\' && isprint (*str))
+       len++;
+      else if (argcv_quote_char (*str) != -1)
+       len += 2;
+      else
+       len += 4;
+    }
+  return len;
+}
+
+void
+argcv_unquote_copy (char *dst, const char *src, size_t n)
+{
+  int i = 0;
+  int c;
+  int expect_delim = 0; 
+    
+  while (i < n)
+    {
+      switch (src[i])
+       {
+       case '\'':
+       case '"':
+         if (!expect_delim)
+           {
+             const char *p;
+             
+             for (p = src+i+1; *p && *p != src[i]; p++)
+               if (*p == '\\')
+                 p++;
+             if (*p)
+               expect_delim = src[i++];
+             else
+               *dst++ = src[i++];
+           }
+         else if (expect_delim == src[i])
+           ++i;
+         else
+           *dst++ = src[i++];
+         break;
+         
+       case '\\':
+         ++i;
+         if (src[i] == 'x' || src[i] == 'X')
+           {
+             if (n - i < 2)
+               {
+                 *dst++ = '\\';
+                 *dst++ = src[i++];
+               }
+             else 
+               {
+                 int off = xtonum(&c, src + i + 1, 16, 2);
+                 if (off == 0)
+                   {
+                     *dst++ = '\\';
+                     *dst++ = src[i++];
+                   }
+                 else
+                   {
+                     *dst++ = c;
+                     i += off + 1;
+                   }
+               }
+           }
+         else if ((unsigned char)src[i] < 128 && isdigit (src[i]))
+           {
+             if (n - i < 1)
+               {
+                 *dst++ = '\\';
+                 *dst++ = src[i++];
+               }
+             else
+               {
+                 int off = xtonum (&c, src+i, 8, 3);
+                 if (off == 0)
+                   {
+                     *dst++ = '\\';
+                     *dst++ = src[i++];
+                   }
+                 else
+                   {
+                     *dst++ = c;
+                     i += off;
+                   }
+               }
+           }
+         else
+           *dst++ = argcv_unquote_char (src[i++]);
+         break;
+         
+       default:
+         *dst++ = src[i++];
+       }
+    }
+  *dst = 0;
+}
+
+void
+argcv_quote_copy (char *dst, const char *src)
+{
+  for (; *src; src++)
+    {
+      if (*src == '"')
+       {
+         *dst++ = '\\';
+         *dst++ = *src;
+       }
+      else if (*src != '\t' && *src != '\\' && isprint(*src))
+       *dst++ = *src;      
+      else
+       {
+         int c = argcv_quote_char (*src);
+         *dst++ = '\\';
+         if (c != -1)
+           *dst++ = c;
+         else
+           {
+             char tmp[4];
+             snprintf (tmp, sizeof tmp, "%03o", *(unsigned char*)src);
+             memcpy (dst, tmp, 3);
+             dst += 3;
+           }
+       }
+    }
+}
+
+int
+argcv_get_np (const char *command, int len,
+             const char *delim, const char *cmnt,
+             int flags,
+             int *pargc, char ***pargv, char **endp)
+{
+  int i = 0;
+  struct argcv_info info;
+  int argc;
+  char **argv;
+  
+  if (!delim)
+    delim = "";
+  if (!cmnt)
+    cmnt = "";
+
+  init_argcv_info (&info, flags, len, command, delim, cmnt);
+
+  /* Count number of arguments */
+  argc = 0;
+  while (argcv_scan (&info) <= len)
+    argc++;
+
+  argv = calloc ((argc + 1), sizeof (char *));
+  if (argv == NULL)
+    return ENOMEM;
+  
+  i = 0;
+  info.save = 0;
+  for (i = 0; i < argc; i++)
+    {
+      int n;
+      int unquote;
+      
+      argcv_scan (&info);
+
+      if ((command[info.start] == '"' || command[info.end] == '\'')
+         && command[info.end] == command[info.start])
+       {
+         if (info.start < info.end)
+           {
+             info.start++;
+             info.end--;
+           }
+         unquote = 0;
+       }
+      else
+       unquote = 1;
+      
+      n = info.end - info.start + 1;
+      argv[i] = calloc (n + 1,  sizeof (char));
+      if (argv[i] == NULL)
+       {
+         argcv_free (i, argv);
+         return ENOMEM;
+       }
+      if (unquote)
+       argcv_unquote_copy (argv[i], &command[info.start], n);
+      else
+       memcpy (argv[i], &command[info.start], n);
+      argv[i][n] = 0;
+    }
+  argv[i] = NULL;
+
+  *pargc = argc;
+  *pargv = argv;
+  if (endp)
+    *endp = (char*) (command + info.finish_pos);
+  return 0;
+}
+
+int
+argcv_get_n (const char *command, int len, const char *delim, const char *cmnt,
+            int *pargc, char ***pargv)
+{
+  return argcv_get_np (command, len, delim, cmnt, MU_ARGCV_RETURN_DELIMS,
+                      pargc, pargv, NULL);
+}
+
+int
+argcv_get (const char *command, const char *delim, const char *cmnt,
+          int *argc, char ***argv)
+{
+  return argcv_get_n (command, strlen (command), delim, cmnt, argc, argv);
+}
+
+
+/*
+ * frees all elements of an argv array
+ * argc is the number of elements
+ * argv is the array
+ */
+void
+argcv_free (int argc, char **argv)
+{
+  if (argc <= 0)
+    return;
+  while (--argc >= 0)
+    if (argv[argc])
+      free (argv[argc]);
+  free (argv);
+}
+
+void
+argv_free (char **argv)
+{
+  int i;
+
+  for (i = 0; argv[i]; i++)
+    free (argv[i]);
+  free (argv);
+}
+
+/* Make a argv an make string separated by ' '.  */
+
+int
+argcv_string (int argc, char **argv, char **pstring)
+{
+  size_t i, j, len;
+  char *buffer;
+
+  /* No need.  */
+  if (pstring == NULL)
+    return EINVAL;
+
+  buffer = malloc (1);
+  if (buffer == NULL)
+    return ENOMEM;
+  *buffer = '\0';
+
+  for (len = i = j = 0; i < argc; i++)
+    {
+      int quote;
+      int toklen;
+
+      toklen = argcv_quoted_length (argv[i], &quote);
+      
+      len += toklen + 2;
+      if (quote)
+       len += 2;
+      
+      buffer = realloc (buffer, len);
+      if (buffer == NULL)
+        return ENOMEM;
+
+      if (i != 0)
+       buffer[j++] = ' ';
+      if (quote)
+       buffer[j++] = '"';
+      argcv_quote_copy (buffer + j, argv[i]);
+      j += toklen;
+      if (quote)
+       buffer[j++] = '"';
+    }
+
+  for (; j > 0 && isspace (buffer[j-1]); j--)
+    ;
+  buffer[j] = 0;
+  if (pstring)
+    *pstring = buffer;
+  return 0;
+}
+
+void
+mu_argcv_remove (int *pargc, char ***pargv,
+                int (*sel) (const char *, void *), void *data)
+{
+  int i, j;
+  int argc = *pargc;
+  char **argv = *pargv;
+  int cnt = 0;
+  
+  for (i = j = 0; i < argc; i++)
+    {
+      if (sel (argv[i], data))
+       {
+         free (argv[i]);
+         cnt++;
+       }
+      else
+       {
+         if (i != j)
+           argv[j] = argv[i];
+         j++;
+       }
+    }
+  if (i != j)
+    argv[j] = NULL;
+  argc -= cnt;
+
+  *pargc = argc;
+  *pargv = argv;
+}
+      
+ 
diff --git a/libmailutils/base/assoc.c b/libmailutils/base/assoc.c
new file mode 100644
index 0000000..4d27cb7
--- /dev/null
+++ b/libmailutils/base/assoc.c
@@ -0,0 +1,527 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/types.h>
+#include <mailutils/assoc.h>
+#include <mailutils/errno.h>
+#include <mailutils/error.h>
+#include <mailutils/iterator.h>
+#include <mailutils/mutil.h>
+#include <mailutils/cstr.h>
+#include <mailutils/sys/iterator.h>
+
+/* |hash_size| defines a sequence of symbol table sizes. These are prime
+   numbers, the distance between each pair of them grows exponentially,
+   starting from 64. Hardly someone will need more than 16411 symbols, and
+   even if someone will, it is easy enough to add more numbers to the
+   sequence. */
+
+static unsigned int hash_size[] = {
+    37,   101,  229,  487, 1009, 2039, 4091, 8191, 16411
+};
+
+/* |max_rehash| keeps the number of entries in |hash_size| table. */
+static unsigned int max_rehash = sizeof (hash_size) / sizeof (hash_size[0]);
+
+struct _mu_assoc_elem
+{
+  char *name;
+  char data[1];
+};
+
+struct _mu_assoc
+{
+  int flags;
+  unsigned int hash_num;  /* Index to hash_size table */
+  size_t elsize;          /* Size of an element */
+  void *tab;
+  mu_assoc_free_fn free;
+  mu_iterator_t itr;
+};
+
+struct _mu_assoc_elem_align
+{
+  char c;
+  struct _mu_assoc_elem x;
+};
+
+#define __ASSOC_ELEM_ALIGNMENT (mu_offsetof(struct _mu_assoc_elem_align, x))
+
+#define __ASSOC_ELEM_SIZE(a) \
+   ((a)->elsize + mu_offsetof(struct _mu_assoc_elem, data))
+#define __ASSOC_ALIGN(a, b) (((a) + (b) - 1) & ~((b) - 1))
+#define ASSOC_ELEM_SIZE(a) \
+   __ASSOC_ALIGN(__ASSOC_ELEM_SIZE(a),__ASSOC_ELEM_ALIGNMENT)
+
+#define __ASSOC_ELEM(a,p,n) \
+ ((struct _mu_assoc_elem*) ((char*) (p) + ASSOC_ELEM_SIZE (a) * n))
+
+#define ASSOC_ELEM(a,n) __ASSOC_ELEM(a,(a)->tab,n)
+
+#define ASSOC_ELEM_INDEX(a,e) \
+ (((char*)(e) - (char*)(a)->tab) / ASSOC_ELEM_SIZE (a))
+
+
+static unsigned
+hash (const char *name, unsigned long hash_num)
+{
+  unsigned i;
+       
+  for (i = 0; *name; name++)
+    {
+      i <<= 1;
+      i ^= *(unsigned char*) name;
+    }
+  return i % hash_size[hash_num];
+};
+
+static int
+assoc_lookup_or_install (struct _mu_assoc_elem **elp,
+                        mu_assoc_t assoc, const char *name, int *install);
+
+static int
+assoc_rehash (mu_assoc_t assoc)
+{
+  void *old_tab = assoc->tab;
+  void *new_tab;
+  unsigned int i;
+  unsigned int hash_num = assoc->hash_num + 1;
+  
+  if (hash_num >= max_rehash)
+      return MU_ERR_BUFSPACE;
+
+  new_tab = calloc (hash_size[hash_num], ASSOC_ELEM_SIZE (assoc));
+  assoc->tab = new_tab;
+  if (old_tab)
+    {
+      assoc->hash_num = hash_num;
+      for (i = 0; i < hash_size[hash_num-1]; i++)
+       {
+         struct _mu_assoc_elem *elt = __ASSOC_ELEM (assoc, old_tab, i);
+         if (elt->name)
+           {
+             int tmp;
+             struct _mu_assoc_elem *newp;
+             
+             int rc = assoc_lookup_or_install (&newp, assoc, elt->name, &tmp);
+             if (rc)
+               return rc;
+             newp->name = elt->name;
+             memcpy(newp->data, elt->data, assoc->elsize);
+           }
+       }
+      free (old_tab);
+    }
+  return 0;
+}
+
+static void
+assoc_free_elem (mu_assoc_t assoc, struct _mu_assoc_elem *elem)
+{
+  if (assoc->free)
+    assoc->free (elem->data);
+  if (!(assoc->flags & MU_ASSOC_COPY_KEY))
+    free (elem->name);
+}
+
+static int
+assoc_remove (mu_assoc_t assoc, struct _mu_assoc_elem *elem)
+{
+  unsigned int i, j, r;
+
+  if (!(ASSOC_ELEM (assoc, 0) <= elem
+       && elem < ASSOC_ELEM (assoc, hash_size[assoc->hash_num])))
+    return EINVAL;
+
+  assoc_free_elem (assoc, elem);
+  
+  for (i = ASSOC_ELEM_INDEX (assoc, elem);;)
+    {
+      struct _mu_assoc_elem *p = ASSOC_ELEM (assoc, i);
+      p->name = NULL;
+      j = i;
+
+      do
+       {
+         if (++i >= hash_size[assoc->hash_num])
+           i = 0;
+         p = ASSOC_ELEM (assoc, i);
+         if (!p->name)
+           return 0;
+         r = hash (p->name, assoc->hash_num);
+       }
+      while ((j < r && r <= i) || (i < j && j < r) || (r <= i && i < j));
+
+      if (j != i)
+             memcpy (ASSOC_ELEM (assoc, j), ASSOC_ELEM (assoc, i),
+                     assoc->elsize);
+    }
+  return 0;
+}
+
+#define name_cmp(assoc,a,b) (((assoc)->flags & MU_ASSOC_ICASE) ? \
+                             mu_c_strcasecmp(a,b) : strcmp(a,b))
+
+static int
+assoc_lookup_or_install (struct _mu_assoc_elem **elp,
+                        mu_assoc_t assoc, const char *name, int *install)
+{
+  int rc;
+  unsigned i, pos;
+  struct _mu_assoc_elem *elem;
+  
+  if (!assoc->tab)
+    {
+      if (install)
+       {
+         rc = assoc_rehash (assoc);
+         if (rc)
+           return rc;
+       }
+      else
+       return MU_ERR_NOENT;
+    }
+
+  pos = hash (name, assoc->hash_num);
+
+  for (i = pos; (elem = ASSOC_ELEM (assoc, i))->name;)
+    {
+      if (name_cmp (assoc, elem->name, name) == 0)
+       {
+         if (install)
+           *install = 0;
+         *elp = elem;
+         return 0;
+       }
+      
+      if (++i >= hash_size[assoc->hash_num])
+       i = 0;
+      if (i == pos)
+       break;
+    }
+
+  if (!install)
+    return MU_ERR_NOENT;
+  
+  if (elem->name == NULL)
+    {
+      *install = 1;
+      if (assoc->flags & MU_ASSOC_COPY_KEY)
+       elem->name = (char *) name;
+      else
+       {
+         elem->name = strdup (name);
+         if (!elem->name)
+           return ENOMEM;
+       }
+      *elp = elem;
+      return 0; 
+    }
+
+  if ((rc = assoc_rehash (assoc)) != 0)
+    return rc;
+
+  return assoc_lookup_or_install (elp, assoc, name, install);
+}
+
+int
+mu_assoc_create (mu_assoc_t *passoc, size_t elsize, int flags)
+{
+  mu_assoc_t assoc = calloc (1, sizeof (*assoc));
+  if (!assoc)
+    return ENOMEM;
+  assoc->flags = flags;
+  assoc->elsize = elsize;
+  *passoc = assoc;
+  return 0;
+}
+
+void
+mu_assoc_clear (mu_assoc_t assoc)
+{
+  unsigned i, hs;
+  
+  if (!assoc || !assoc->tab)
+    return;
+
+  hs = hash_size[assoc->hash_num];
+  for (i = 0; i < hs; i++)
+    {
+      struct _mu_assoc_elem *elem = ASSOC_ELEM (assoc, i);
+      if (elem->name)
+       {
+         assoc_free_elem (assoc, elem);
+         elem->name = NULL;
+       }
+    }
+}
+
+void
+mu_assoc_destroy (mu_assoc_t *passoc)
+{
+  mu_assoc_t assoc;
+  if (passoc && (assoc = *passoc) != NULL)
+    {
+      mu_assoc_clear (assoc);
+      free (assoc->tab);
+      free (assoc);
+      *passoc = NULL;
+    }
+}
+
+int
+mu_assoc_set_free (mu_assoc_t assoc, mu_assoc_free_fn fn)
+{
+  if (!assoc)
+    return EINVAL;
+  assoc->free = fn;
+  return 0;
+}
+
+void *
+mu_assoc_ref (mu_assoc_t assoc, const char *name)
+{
+  int rc;
+  static struct _mu_assoc_elem *elp;
+
+  if (!assoc || !name)
+    return NULL;
+  
+  rc = assoc_lookup_or_install (&elp, assoc, name, NULL);
+  if (rc == 0)
+    return elp->data;
+  return NULL;
+}
+
+int
+mu_assoc_install (mu_assoc_t assoc, const char *name, void *value)
+{
+  int rc;
+  int inst;
+  static struct _mu_assoc_elem *elp;
+
+  if (!assoc || !name)
+    return EINVAL;
+
+  rc = assoc_lookup_or_install (&elp, assoc, name, &inst);
+  if (rc)
+    return rc;
+  if (!inst)
+    return MU_ERR_EXISTS;
+  memcpy (elp->data, value, assoc->elsize);
+  return 0;
+}
+
+int
+mu_assoc_ref_install (mu_assoc_t assoc, const char *name, void **pval)
+{
+  int rc;
+  int inst;
+  static struct _mu_assoc_elem *elp;
+
+  if (!assoc || !name)
+    return EINVAL;
+
+  rc = assoc_lookup_or_install (&elp, assoc, name, &inst);
+  if (rc)
+    return rc;
+  *pval = elp->data;
+  return inst ? 0 : MU_ERR_EXISTS;
+}  
+
+int
+mu_assoc_remove (mu_assoc_t assoc, const char *name)
+{
+  int rc;
+  static struct _mu_assoc_elem *elem;
+
+  if (!assoc || !name)
+    return EINVAL;
+  rc = assoc_lookup_or_install (&elem, assoc, name, NULL);
+  if (rc)
+    return rc;
+  return assoc_remove (assoc, elem);
+}
+
+#define OFFSET(s,f) (size_t)(&((s*)0)->f)
+
+int
+mu_assoc_remove_ref (mu_assoc_t assoc, void *data)
+{
+  struct _mu_assoc_elem *elem;
+
+  elem = (struct _mu_assoc_elem *) ((char*)data -
+                                   OFFSET(struct _mu_assoc_elem, data));
+  return assoc_remove (assoc, elem);
+}
+
+
+/* Iterator interface */
+
+struct assoc_iterator
+{
+  mu_assoc_t assoc;
+  unsigned start;
+  unsigned index;
+};
+
+static int
+first (void *owner)
+{
+  struct assoc_iterator *itr = owner;
+  mu_assoc_t assoc = itr->assoc;
+  unsigned hash_max = hash_size[assoc->hash_num];
+  unsigned i;
+  
+  for (i = 0; i < hash_max; i++)
+    if ((ASSOC_ELEM (assoc, i))->name)
+      break;
+  itr->index = i;
+  return 0;
+}
+
+static int
+next (void *owner)
+{
+  struct assoc_iterator *itr = owner;
+  mu_assoc_t assoc = itr->assoc;
+  unsigned hash_max = hash_size[assoc->hash_num];
+  unsigned i;
+  
+  for (i = itr->index + 1; i < hash_max; i++)
+    if ((ASSOC_ELEM (assoc, i))->name)
+      break;
+
+  itr->index = i;
+  return 0;
+}
+
+static int
+getitem (void *owner, void **pret, const void **pkey)
+{
+  struct assoc_iterator *itr = owner;
+  struct _mu_assoc_elem *elem;
+
+  if (itr->index >= hash_size[itr->assoc->hash_num])
+    return EINVAL;
+  elem = ASSOC_ELEM (itr->assoc, itr->index);
+  *pret = elem->data;
+  if (pkey)
+    *pkey = elem->name;
+  return 0;
+}
+
+static int
+finished_p (void *owner)
+{
+  struct assoc_iterator *itr = owner;
+  return itr->index >= hash_size[itr->assoc->hash_num];
+}
+
+static int
+destroy (mu_iterator_t iterator, void *data)
+{
+  struct assoc_iterator *itr = data;
+  mu_iterator_detach (&itr->assoc->itr, iterator);
+  free (data);
+  return 0;
+}
+
+static int
+curitem_p (void *owner, void *item)
+{
+  struct assoc_iterator *itr = owner;
+  mu_assoc_t assoc = itr->assoc;
+  struct _mu_assoc_elem *elem = ASSOC_ELEM (assoc, itr->index);
+  
+  return elem == item;
+}
+
+static int
+assoc_data_dup (void **ptr, void *owner)
+{
+  *ptr = malloc (sizeof (struct assoc_iterator));
+  if (*ptr == NULL)
+    return ENOMEM;
+  memcpy (*ptr, owner, sizeof (struct assoc_iterator));
+  return 0;
+}
+
+int
+mu_assoc_get_iterator (mu_assoc_t assoc, mu_iterator_t *piterator)
+{
+  mu_iterator_t iterator;
+  int status;
+  struct assoc_iterator *itr;
+
+  if (!assoc)
+    return EINVAL;
+
+  itr = calloc (1, sizeof *itr);
+  if (!itr)
+    return ENOMEM;
+  itr->assoc = assoc;
+  itr->index = 0;
+
+  status = mu_iterator_create (&iterator, itr);
+  if (status)
+    {
+      free (itr);
+      return status;
+    }
+
+  mu_iterator_set_first (iterator, first);
+  mu_iterator_set_next (iterator, next);
+  mu_iterator_set_getitem (iterator, getitem);
+  mu_iterator_set_finished_p (iterator, finished_p);
+  mu_iterator_set_curitem_p (iterator, curitem_p);
+  mu_iterator_set_destroy (iterator, destroy);
+  mu_iterator_set_dup (iterator, assoc_data_dup);
+  
+  mu_iterator_attach (&assoc->itr, iterator);
+
+  *piterator = iterator;
+  return 0;
+}  
+
+
+
+int
+mu_assoc_count (mu_assoc_t assoc, size_t *pcount)
+{
+  mu_iterator_t itr;
+  int rc;
+  size_t count = 0;
+  
+  if (!assoc || !pcount)
+    return EINVAL;
+  rc = mu_assoc_get_iterator (assoc, &itr);
+  if (rc)
+    return rc;
+  for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
+       mu_iterator_next (itr))
+    count++;
+  mu_iterator_destroy (&itr);
+  *pcount = count;
+  return 0;
+}
+
diff --git a/libmailutils/base/daemon.c b/libmailutils/base/daemon.c
new file mode 100644
index 0000000..b5e0df6
--- /dev/null
+++ b/libmailutils/base/daemon.c
@@ -0,0 +1,188 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2004, 2005, 2007, 2008, 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/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <string.h>
+
+#include <mailutils/daemon.h>
+#include <mailutils/errno.h>
+#include <mailutils/error.h>
+#include <mailutils/nls.h>
+
+static char *pidfile;
+static pid_t current_pid;
+
+/* Return 0 if DIR is writable for EUID/EGID.
+   Otherwise, return error code. */
+static int
+ewraccess (const char *dir)
+{
+  struct stat st;
+  if (stat (dir, &st))
+    return errno;
+  if ((st.st_mode & S_IWOTH)
+      || (st.st_gid == getegid () && (st.st_mode & S_IWGRP))
+      || (st.st_uid == geteuid () && (st.st_mode & S_IWUSR)))
+    return 0;
+  else
+    return EACCES;
+}
+
+/* Return 0 if DIR is writable. If necessary and possible, raise to
+   EUID 0, in that case return prior EUID in the memory location pointed to
+   by PUID. */
+static int
+access_dir (const char *dir, uid_t *puid)
+{
+  int ec = ewraccess (dir);
+  if (ec)
+    {
+      if (ec == EACCES && access (dir, W_OK) == 0)
+       {
+         uid_t uid = geteuid ();
+         /* See if we can become root */
+         if (uid && getuid () == 0 && seteuid (0) == 0)
+           {
+             *puid = uid;
+             return 0;
+           }
+       }
+    }
+  return ec;
+}
+
+int
+mu_daemon_create_pidfile (const char *filename)
+{
+  char *p;
+  int fd;
+  uid_t uid = 0;
+  int rc;
+  
+  if (filename[0] != '/')
+    return EINVAL;
+
+  if (pidfile)
+    free (pidfile);
+  pidfile = strdup (filename);
+  if (!pidfile)
+    return ENOMEM;
+
+  /* Determine the hosting directory name */
+  p = strrchr (pidfile, '/');
+  if (pidfile == p)
+    {
+      free (pidfile);
+      pidfile = NULL;
+      /* Sorry, pidfiles in root dir are not allowed */
+      return EINVAL;
+    }
+  /* Check if we have write access to the directory */
+  *p = 0;
+  rc = access_dir (pidfile, &uid);
+  if (rc)
+    {
+      /* Nope, clean up and return */
+      free (pidfile);
+      pidfile = NULL;
+      return rc;
+    }
+
+  /* Restore directory separator */
+  *p = '/';
+    
+  unlink (pidfile);
+  current_pid = getpid ();
+  
+  if ((fd = open (pidfile, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0644)) != -1)
+    {
+      FILE *fp = fdopen (fd, "w");
+      if (!fp)
+       {
+         rc = errno;
+         free (pidfile);
+         close (fd);
+       }
+      else
+       {
+         fprintf (fp, "%lu", (unsigned long) current_pid);
+         fclose (fp);
+         atexit (mu_daemon_remove_pidfile);
+       }
+    }
+  else
+    {
+      rc = errno;
+      free (pidfile);
+      pidfile = NULL;
+    }
+
+  /* Restore previous EUID value. */
+  if (uid)
+    seteuid (uid);
+  
+  return rc;
+}
+
+void
+mu_daemon_remove_pidfile (void)
+{
+  if (getpid () == current_pid)
+    {
+      int rc;
+      uid_t uid = 0;
+
+      /* Determine the hosting directory name */
+      char *p = strrchr (pidfile, '/');
+      if (pidfile == p)
+       {
+         /* Should not happen */
+         abort ();
+       }
+      /* Check if we have write access to the directory */
+      *p = 0;
+      rc = access_dir (pidfile, &uid);
+      *p = '/';
+      if (rc == 0)
+       {
+         if (unlink (pidfile) && errno != ENOENT)
+           rc = errno;
+         else
+           rc = 0;
+       }
+      
+      if (rc)
+       mu_error (_("cannot remove pidfile %s: %s"),
+                 pidfile, mu_strerror (rc));
+
+      free (pidfile);
+      pidfile = NULL;
+    }
+}
+
+
+
diff --git a/libmailutils/base/date.c b/libmailutils/base/date.c
new file mode 100644
index 0000000..efb187b
--- /dev/null
+++ b/libmailutils/base/date.c
@@ -0,0 +1,244 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2002, 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/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/mutil.h>
+#include <mailutils/cstr.h>
+
+#define SECS_PER_DAY 86400
+#define ADJUSTMENT -719162L
+
+static time_t
+jan1st (int year)
+{
+  year--;               /* Do not consider the current year */
+  return  year*365L
+               + year/4L    /* Years divisible by 4 are leap years */
+               + year/400L  /* Years divisible by 400 are always leap years */
+               - year/100L; /* Years divisible by 100 but not 400 aren't */
+}
+
+static int  month_start[]=
+    {    0, 31, 59,  90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
+     /* Jan Feb Mar  Apr  May  Jun  Jul  Aug  Sep  Oct  Nov  Dec
+         31  28  31   30   31   30   31   31   30   31   30   31
+     */
+
+/* NOTE: ignore GCC warning. The precedence of operators is OK here */
+#define leap_year(y) ((y) % 4 == 0 && (y) % 100 != 0 || (y) % 400 == 0)
+
+static int
+dayofyear (time_t *pday, int year, int month, int day)
+{
+  int  leap, month_days;
+
+  if (year < 0 || month < 0 || month > 11)
+    return -1;
+    
+  leap = leap_year (year);
+  
+  month_days = month_start[month + 1] - month_start[month]
+               + ((month == 2) ? leap : 0);
+
+  if (day < 0 || day > month_days)
+    return -1;  /* Illegal Date */
+
+  if (month <= 2)
+    leap = 0;
+
+  *pday = month_start[month] + day + leap;
+  return 0;
+}
+
+
+/* Convert struct tm into time_t, taking into account timezone offset. */
+/* FIXME: It does not take DST into account */
+time_t
+mu_tm2time (struct tm *tm, mu_timezone *tz)
+{
+  time_t t;
+  
+  if (dayofyear (&t, tm->tm_year, tm->tm_mon, tm->tm_mday - 1))
+    return -1;
+  t = (t + ADJUSTMENT + jan1st (1900 + tm->tm_year)) * SECS_PER_DAY
+            + (tm->tm_hour * 60 + tm->tm_min) * 60 + tm->tm_sec
+      - tz->utc_offset;
+  return t;
+}
+
+/* Convert time 0 at UTC to our localtime, that tells us the offset
+   of our current timezone from UTC. */
+time_t
+mu_utc_offset (void)
+{
+  time_t t = 0;
+  struct tm *tm = gmtime (&t);
+
+  return - mktime (tm);
+}
+
+static const char *months[] =
+{
+  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL
+};
+
+static const char *wdays[] =
+{
+  "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL
+};
+
+int
+mu_parse_imap_date_time (const char **p, struct tm *tm, mu_timezone *tz)
+{
+  int year, mon, day, hour, min, sec;
+  char zone[6] = "+0000";      /* ( "+" / "-" ) hhmm */
+  char month[5] = "";
+  int hh = 0;
+  int mm = 0;
+  int sign = 1;
+  int scanned = 0, scanned3;
+  int i;
+  int tzoffset;
+
+  day = mon = year = hour = min = sec = 0;
+
+  memset (tm, 0, sizeof (*tm));
+
+  switch (sscanf (*p,
+                 "%2d-%3s-%4d%n %2d:%2d:%2d %5s%n",
+                 &day, month, &year, &scanned3, &hour, &min, &sec, zone,
+                 &scanned))
+    {
+    case 3:
+      scanned = scanned3;
+      break;
+    case 7:
+      break;
+    default:
+      return -1;
+    }
+
+  tm->tm_sec = sec;
+  tm->tm_min = min;
+  tm->tm_hour = hour;
+  tm->tm_mday = day;
+
+  for (i = 0; i < 12; i++)
+    {
+      if (mu_c_strncasecmp (month, months[i], 3) == 0)
+       {
+         mon = i;
+         break;
+       }
+    }
+  tm->tm_mon = mon;
+  tm->tm_year = (year > 1900) ? year - 1900 : year;
+  tm->tm_yday = 0;             /* unknown. */
+  tm->tm_wday = 0;             /* unknown. */
+#if HAVE_STRUCT_TM_TM_ISDST
+  tm->tm_isdst = -1;           /* unknown. */
+#endif
+
+  hh = (zone[1] - '0') * 10 + (zone[2] - '0');
+  mm = (zone[3] - '0') * 10 + (zone[4] - '0');
+  sign = (zone[0] == '-') ? -1 : +1;
+  tzoffset = sign * (hh * 60 * 60 + mm * 60);
+
+#if HAVE_STRUCT_TM_TM_GMTOFF
+  tm->tm_gmtoff = tzoffset;
+#endif
+
+  if (tz)
+    {
+      tz->utc_offset = tzoffset;
+      tz->tz_name = NULL;
+    }
+
+  *p += scanned;
+
+  return 0;
+}
+
+/* "ctime" format is: Thu Jul 01 15:58:27 1999, with no trailing \n.  */
+int
+mu_parse_ctime_date_time (const char **p, struct tm *tm, mu_timezone * tz)
+{
+  int wday = 0;
+  int year = 0;
+  int mon = 0;
+  int day = 0;
+  int hour = 0;
+  int min = 0;
+  int sec = 0;
+  int n = 0;
+  int i;
+  char weekday[5] = "";
+  char month[5] = "";
+
+  if (sscanf (*p, "%3s %3s %2d %2d:%2d:%2d %d%n\n",
+       weekday, month, &day, &hour, &min, &sec, &year, &n) != 7)
+    return -1;
+
+  *p += n;
+
+  for (i = 0; i < 7; i++)
+    {
+      if (mu_c_strncasecmp (weekday, wdays[i], 3) == 0)
+       {
+         wday = i;
+         break;
+       }
+    }
+
+  for (i = 0; i < 12; i++)
+    {
+      if (mu_c_strncasecmp (month, months[i], 3) == 0)
+       {
+         mon = i;
+         break;
+       }
+    }
+
+  if (tm)
+    {
+      memset (tm, 0, sizeof (struct tm));
+
+      tm->tm_sec = sec;
+      tm->tm_min = min;
+      tm->tm_hour = hour;
+      tm->tm_mday = day;
+      tm->tm_wday = wday;
+      tm->tm_mon = mon;
+      tm->tm_year = (year > 1900) ? year - 1900 : year;
+#ifdef HAVE_STRUCT_TM_TM_ISDST
+      tm->tm_isdst = -1;       /* unknown. */
+#endif
+    }
+
+  /* ctime has no timezone information, set tz to UTC if they ask. */
+  if (tz)
+    memset (tz, 0, sizeof (struct mu_timezone));
+
+  return 0;
+}
diff --git a/libmailutils/base/fgetpwent.c b/libmailutils/base/fgetpwent.c
new file mode 100644
index 0000000..79f6be3
--- /dev/null
+++ b/libmailutils/base/fgetpwent.c
@@ -0,0 +1,162 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2007, 2010 Free Software Foundation,
+   Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <pwd.h>
+#include <string.h>
+#include <stdlib.h>
+
+/*
+  Written by Alain Magloire.
+  Simple replacement for fgetpwent(), it is not :
+  - thread safe;
+  - static buffer was not use since it will limit the size
+    of the entry.  But rather memory is allocated and __never__
+    release.  The memory will grow if need be.
+  - no support for shadow
+  - no support for NIS(+)
+*/
+
+static char *buffer;
+static size_t buflen;
+static struct passwd pw;
+
+static char *
+parse_line (char *s, char **p)
+{
+  if (*s)
+    {
+      char *sep = strchr (s, ':');
+      if (sep)
+       {
+         *sep++ = '\0';
+         *p = sep;
+       }
+      else
+       *p = s + strlen (s);
+    }
+  else
+    *p = s;
+  return s;
+}
+
+static struct passwd *
+getentry (char *s)
+{
+  char *p;
+  pw.pw_name = parse_line (s, &p);
+  s = p;
+  pw.pw_passwd = parse_line (s, &p);
+  s = p;
+  pw.pw_uid = strtoul (parse_line (s, &p), NULL, 10);
+  s = p;
+  pw.pw_gid = strtoul (parse_line (s, &p), NULL, 10);
+  s = p;
+  pw.pw_gecos = parse_line (s, &p);
+  s = p;
+  pw.pw_dir = parse_line (s, &p);
+  s = p;
+  pw.pw_shell = parse_line (s, &p);
+  return &pw;
+}
+
+struct passwd *
+mu_fgetpwent (FILE *fp)
+{
+  size_t pos = 0;
+  int done = 0;
+  struct passwd *pw = NULL;
+
+  /* Allocate buffer if not yet available.  */
+  /* This buffer will be never free().  */
+  if (buffer == NULL)
+    {
+      buflen = 1024;
+      buffer = malloc (buflen);
+      if (buffer == NULL)
+       return NULL;
+    }
+
+  do
+    {
+      if (fgets (buffer + pos, buflen, fp) != NULL)
+       {
+         /* Need a full line.  */
+         if (buffer[strlen (buffer) - 1] == '\n')
+           {
+             /* reset marker position.  */
+             pos = 0;
+             /* Nuke trailing newline.  */
+             buffer[strlen (buffer) - 1] = '\0';
+
+             /* Skip comments.  */
+             if (buffer[0] != '#')
+               {
+                 done = 1;
+                 pw = getentry (buffer);
+               }
+           }
+         else
+           {
+             /* Line is too long reallocate the buffer.  */
+             char *tmp;
+             pos = strlen (buffer);
+             buflen *= 2;
+             tmp = realloc (buffer, buflen);
+             if (tmp)
+               buffer = tmp;
+             else
+               done = 1;
+           }
+       }
+      else
+       done = 1;
+    } while (!done);
+
+  return pw;
+
+}
+
+#ifdef STANDALONE
+int
+main ()
+{
+  FILE *fp = fopen ("/etc/passwd", "r");
+  if (fp)
+    {
+      struct passwd *pwd;
+      while ((pwd = fgetpwent (fp)))
+        {
+          printf ("--------------------------------------\n");
+          printf ("name %s\n", pwd->pw_name);
+          printf ("passwd %s\n", pwd->pw_passwd);
+          printf ("uid %d\n", pwd->pw_uid);
+          printf ("gid %d\n", pwd->pw_gid);
+          printf ("gecos %s\n", pwd->pw_gecos);
+          printf ("dir %s\n", pwd->pw_dir);
+          printf ("shell %s\n", pwd->pw_shell);
+        }
+    }
+  return 0;
+}
+
+#endif
diff --git a/libmailutils/base/freeitem.c b/libmailutils/base/freeitem.c
new file mode 100644
index 0000000..ad382a4
--- /dev/null
+++ b/libmailutils/base/freeitem.c
@@ -0,0 +1,28 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdlib.h>
+
+/* Default destroy_item function. */
+void
+mu_list_free_item (void *item)
+{
+  free (item);
+}
diff --git a/libmailutils/getpass.c b/libmailutils/base/getpass.c
similarity index 100%
rename from libmailutils/getpass.c
rename to libmailutils/base/getpass.c
diff --git a/libmailutils/base/iterator.c b/libmailutils/base/iterator.c
new file mode 100644
index 0000000..97f7b75
--- /dev/null
+++ b/libmailutils/base/iterator.c
@@ -0,0 +1,283 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2004, 2005, 2007, 2010 Free Software
+   Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+
+#include <mailutils/sys/list.h>
+#include <mailutils/sys/iterator.h>
+#include <mailutils/errno.h>
+
+int
+mu_iterator_create (mu_iterator_t *piterator, void *owner)
+{
+  mu_iterator_t iterator;
+  if (piterator == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  if (owner == NULL)
+    return EINVAL;
+  iterator = calloc (1, sizeof (*iterator));
+  if (iterator == NULL)
+    return ENOMEM;
+  iterator->owner = owner;
+  *piterator = iterator;
+  return 0;
+}
+
+int
+mu_iterator_set_first (mu_iterator_t itr, int (*first) (void *))
+{
+  if (!itr)
+    return EINVAL;
+  itr->first = first;
+  return 0;
+}
+
+int
+mu_iterator_set_next (mu_iterator_t itr, int (*next) (void *))
+{
+  if (!itr)
+    return EINVAL;
+  itr->next = next;
+  return 0;
+}
+
+int
+mu_iterator_set_getitem (mu_iterator_t itr,
+                         int (*getitem) (void *, void **, const void **))
+{
+  if (!itr)
+    return EINVAL;
+  itr->getitem = getitem;
+  return 0;
+}
+
+int
+mu_iterator_set_finished_p (mu_iterator_t itr, int (*finished_p) (void *))
+{
+  if (!itr)
+    return EINVAL;
+  itr->finished_p = finished_p;
+  return 0;
+}
+
+int
+mu_iterator_set_curitem_p (mu_iterator_t itr,
+                       int (*curitem_p) (void *, void *))
+{
+  if (!itr)
+    return EINVAL;
+  itr->curitem_p = curitem_p;
+  return 0;
+}
+
+int
+mu_iterator_set_itrctl (mu_iterator_t itr,
+                       int (*itrctl) (void *,
+                                      enum mu_itrctl_req,
+                                      void *))
+{
+  if (!itr)
+    return EINVAL;
+  itr->itrctl = itrctl;
+  return 0;
+}
+
+int
+mu_iterator_set_destroy (mu_iterator_t itr, int (*destroy) (mu_iterator_t, 
void *))
+{
+  if (!itr)
+    return EINVAL;
+  itr->destroy = destroy;
+  return 0;
+}
+
+int
+mu_iterator_set_dup (mu_iterator_t itr, int (*dup) (void **ptr, void *data))
+{
+  if (!itr)
+    return EINVAL;
+  itr->dup = dup;
+  return 0;
+}
+
+
+
+int
+mu_iterator_dup (mu_iterator_t *piterator, mu_iterator_t orig)
+{
+  mu_iterator_t iterator;
+  int status;
+  
+  if (piterator == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  if (orig == NULL)
+    return EINVAL;
+
+  status = mu_iterator_create (&iterator, orig->owner);
+  if (status)
+    return status;
+
+  status = orig->dup(&iterator->owner, orig->owner);
+  if (status)
+    {
+      free (iterator);
+      return status;
+    }
+  iterator->is_advanced = orig->is_advanced;   
+  iterator->dup = orig->dup;
+  iterator->destroy = orig->destroy;
+  iterator->first = orig->first;
+  iterator->next = orig->next;
+  iterator->getitem = orig->getitem;
+  iterator->curitem_p = orig->curitem_p;
+  iterator->finished_p = orig->finished_p;
+  iterator->itrctl = orig->itrctl;
+  
+  *piterator = iterator;
+  return 0;
+}
+
+void
+mu_iterator_destroy (mu_iterator_t *piterator)
+{
+  if (!piterator || !*piterator)
+    return;
+
+  if ((*piterator)->destroy)
+    (*piterator)->destroy (*piterator, (*piterator)->owner);
+  
+  free (*piterator);
+  *piterator = NULL;
+}
+
+int
+mu_iterator_first (mu_iterator_t iterator)
+{
+  iterator->is_advanced = 0;
+  return iterator->first (iterator->owner);
+}
+
+int
+mu_iterator_next (mu_iterator_t iterator)
+{
+  int status = 0;
+  if (!iterator->is_advanced)
+    status = iterator->next (iterator->owner);
+  iterator->is_advanced = 0;
+  return status;
+}
+
+int
+mu_iterator_skip (mu_iterator_t iterator, ssize_t count)
+{
+  int status;
+  if (count < 0)
+    return ENOSYS; /* Need prev method */
+  while (count--)
+    if ((status = mu_iterator_next (iterator)))
+      break;
+  return status;
+}
+
+int
+mu_iterator_current (mu_iterator_t iterator, void **pitem)
+{
+  return iterator->getitem (iterator->owner, pitem, NULL);
+}
+
+int
+mu_iterator_current_kv (mu_iterator_t iterator, 
+                        const void **pkey, void **pitem)
+{
+  return iterator->getitem (iterator->owner, (void**)pitem, pkey);
+}
+
+int
+mu_iterator_is_done (mu_iterator_t iterator)
+{
+  if (iterator == NULL)
+    return 1;
+  return iterator->finished_p (iterator->owner);
+}
+
+int
+iterator_get_owner (mu_iterator_t iterator, void **powner)
+{
+  if (!iterator)
+    return EINVAL;
+  if (!powner)
+    return MU_ERR_OUT_PTR_NULL;
+  *powner = iterator->owner;
+  return 0;
+}
+
+void
+mu_iterator_advance (mu_iterator_t iterator, void *e)
+{
+  for (; iterator; iterator = iterator->next_itr)
+    {
+      if (iterator->curitem_p (iterator->owner, e))
+       {
+         iterator->next (iterator->owner);
+         iterator->is_advanced++;
+       }
+    }
+}
+
+int
+mu_iterator_attach (mu_iterator_t *root, mu_iterator_t iterator)
+{
+  iterator->next_itr = *root;
+  *root = iterator;
+  return 0;
+}
+
+int
+mu_iterator_detach (mu_iterator_t *root, mu_iterator_t iterator)
+{
+  mu_iterator_t itr, prev;
+  
+  for (itr = *root, prev = NULL; itr; prev = itr, itr = itr->next_itr)
+    if (iterator == itr)
+      break;
+
+  if (itr)
+    {
+      if (prev)
+       prev->next_itr = itr->next_itr;
+      else
+       *root = itr->next_itr;
+    }
+  
+  return 0;
+}
+
+int
+mu_iterator_ctl (mu_iterator_t iterator, enum mu_itrctl_req req, void *arg)
+{
+  if (!iterator)
+    return EINVAL;
+  if (!iterator->itrctl)
+    return ENOSYS;
+  return iterator->itrctl (iterator->owner, req, arg);
+}
diff --git a/libmailutils/kwd.c b/libmailutils/base/kwd.c
similarity index 100%
rename from libmailutils/kwd.c
rename to libmailutils/base/kwd.c
diff --git a/libmailutils/base/list.c b/libmailutils/base/list.c
new file mode 100644
index 0000000..9147ef8
--- /dev/null
+++ b/libmailutils/base/list.c
@@ -0,0 +1,692 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2008, 2010 Free
+   Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <mailutils/sys/list.h>
+#include <mailutils/sys/iterator.h>
+#include <mailutils/errno.h>
+
+#define DESTROY_ITEM(list, elt)                        \
+  do                                           \
+    {                                          \
+       if ((list)->destroy_item)               \
+        (list)->destroy_item ((elt)->item);    \
+    }                                          \
+  while (0)
+
+int
+mu_list_create (mu_list_t *plist)
+{
+  mu_list_t list;
+  int status;
+
+  if (plist == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  list = calloc (sizeof (*list), 1);
+  if (list == NULL)
+    return ENOMEM;
+  status = mu_monitor_create (&list->monitor, 0,  list);
+  if (status != 0)
+    {
+      free (list);
+      return status;
+    }
+  list->head.next = &list->head;
+  list->head.prev = &list->head;
+  *plist = list;
+  return 0;
+}
+
+void
+mu_list_clear (mu_list_t list)
+{
+  struct list_data *current;
+  struct list_data *previous;
+  
+  mu_monitor_wrlock (list->monitor);
+  for (current = list->head.next; current != &list->head;)
+    {
+      previous = current;
+      current = current->next;
+      DESTROY_ITEM (list, previous);
+      free (previous);
+    }
+  list->head.next = list->head.prev = &list->head;
+  mu_monitor_unlock (list->monitor);
+}
+
+void
+mu_list_destroy (mu_list_t *plist)
+{
+  if (plist && *plist)
+    {
+      mu_list_t list = *plist;
+      mu_list_clear (list);
+      mu_monitor_destroy (&list->monitor, list);
+      free (list);
+      *plist = NULL;
+    }
+}
+
+int
+mu_list_append (mu_list_t list, void *item)
+{
+  struct list_data *ldata;
+  struct list_data *last;
+
+  if (list == NULL)
+    return EINVAL;
+  last = list->head.prev;
+  ldata = calloc (sizeof (*ldata), 1);
+  if (ldata == NULL)
+    return ENOMEM;
+  ldata->item = item;
+  mu_monitor_wrlock (list->monitor);
+  ldata->next = &list->head;
+  ldata->prev = list->head.prev;
+  last->next = ldata;
+  list->head.prev = ldata;
+  list->count++;
+  mu_monitor_unlock (list->monitor);
+  return 0;
+}
+
+int
+mu_list_prepend (mu_list_t list, void *item)
+{
+  struct list_data *ldata;
+  struct list_data *first;
+
+  if (list == NULL)
+    return EINVAL;
+  first = list->head.next;
+  ldata = calloc (sizeof (*ldata), 1);
+  if (ldata == NULL)
+    return ENOMEM;
+  ldata->item = item;
+  mu_monitor_wrlock (list->monitor);
+  ldata->prev = &list->head;
+  ldata->next = list->head.next;
+  first->prev = ldata;
+  list->head.next = ldata;
+  list->count++;
+  mu_monitor_unlock (list->monitor);
+  return 0;
+}
+
+int
+mu_list_is_empty (mu_list_t list)
+{
+  size_t n = 0;
+
+  mu_list_count (list, &n);
+  return (n == 0);
+}
+
+int
+mu_list_count (mu_list_t list, size_t *pcount)
+{
+  if (list == NULL)
+    return EINVAL;
+  if (pcount == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  *pcount = list->count;
+  return 0;
+}
+
+mu_list_comparator_t
+mu_list_set_comparator (mu_list_t list, mu_list_comparator_t comp)
+{
+  mu_list_comparator_t old_comp;
+
+  if (list == NULL)
+    return NULL;
+  old_comp = list->comp;
+  list->comp = comp;
+  return old_comp;
+}
+
+int
+mu_list_get_comparator (mu_list_t list, mu_list_comparator_t *comp)
+{
+  if (!list)
+    return EINVAL;
+  *comp = list->comp;
+  return 0;
+}
+
+int
+_mu_list_ptr_comparator (const void *item, const void *value)
+{
+  return item != value;
+}
+
+int
+mu_list_locate (mu_list_t list, void *item, void **ret_item)
+{
+  struct list_data *current, *previous;
+  mu_list_comparator_t comp;
+  int status = MU_ERR_NOENT;
+
+  if (list == NULL)
+    return EINVAL;
+  comp = list->comp ? list->comp : _mu_list_ptr_comparator;
+  mu_monitor_wrlock (list->monitor);
+  for (previous = &list->head, current = list->head.next;
+       current != &list->head; previous = current, current = current->next)
+    {
+      if (comp (current->item, item) == 0)
+       {
+         if (ret_item)
+           *ret_item = current->item;
+         status = 0;
+         break;
+       }
+    }
+  mu_monitor_unlock (list->monitor);
+  return status;
+}
+
+static int
+_insert_item (mu_list_t list, struct list_data *current, void *new_item,
+             int insert_before)
+{
+  int status;
+  struct list_data *ldata = calloc (sizeof (*ldata), 1);
+  if (ldata == NULL)
+    status = ENOMEM;
+  else
+    {
+      ldata->item = new_item;
+      _mu_list_insert_sublist (list, current,
+                              ldata, ldata,
+                              1,
+                              insert_before);
+      status = 0;
+    }
+  return status;
+}
+
+int
+mu_list_insert (mu_list_t list, void *item, void *new_item, int insert_before)
+{
+  struct list_data *current;
+  mu_list_comparator_t comp;
+  int status = MU_ERR_NOENT;
+
+  if (list == NULL)
+    return EINVAL;
+  comp = list->comp ? list->comp : _mu_list_ptr_comparator;
+
+  mu_monitor_wrlock (list->monitor);
+  for (current = list->head.next;
+       current != &list->head;
+       current = current->next)
+    {
+      if (comp (current->item, item) == 0)
+       {
+         status = _insert_item (list, current, new_item, insert_before);
+         break;
+       }
+    }
+  mu_monitor_unlock (list->monitor);
+  return status;
+}
+
+int
+mu_list_remove (mu_list_t list, void *item)
+{
+  struct list_data *current;
+  mu_list_comparator_t comp;
+  int status = MU_ERR_NOENT;
+
+  if (list == NULL)
+    return EINVAL;
+  comp = list->comp ? list->comp : _mu_list_ptr_comparator;
+  mu_monitor_wrlock (list->monitor);
+  for (current = list->head.next;
+       current != &list->head; current = current->next)
+    {
+      if (comp (current->item, item) == 0)
+       {
+         struct list_data *previous = current->prev;
+         
+         mu_iterator_advance (list->itr, current);
+         previous->next = current->next;
+         current->next->prev = previous;
+         DESTROY_ITEM (list, current);
+         free (current);
+         list->count--;
+         status = 0;
+         break;
+       }
+    }
+  mu_monitor_unlock (list->monitor);
+  return status;
+}
+
+int
+mu_list_remove_nd (mu_list_t list, void *item)
+{
+  mu_list_destroy_item_t dptr = mu_list_set_destroy_item (list, NULL);
+  int rc = mu_list_remove (list, item);
+  mu_list_set_destroy_item (list, dptr);
+  return rc;
+}
+
+int
+mu_list_replace (mu_list_t list, void *old_item, void *new_item)
+{
+  struct list_data *current, *previous;
+  mu_list_comparator_t comp;
+  int status = MU_ERR_NOENT;
+
+  if (list == NULL)
+    return EINVAL;
+  comp = list->comp ? list->comp : _mu_list_ptr_comparator;
+  mu_monitor_wrlock (list->monitor);
+  for (previous = &list->head, current = list->head.next;
+       current != &list->head; previous = current, current = current->next)
+    {
+      if (comp (current->item, old_item) == 0)
+       {
+         DESTROY_ITEM (list, current);
+         current->item = new_item;
+         status = 0;
+         break;
+       }
+    }
+  mu_monitor_unlock (list->monitor);
+  return status;
+}
+
+int
+mu_list_replace_nd (mu_list_t list, void *item, void *new_item)
+{
+  mu_list_destroy_item_t dptr = mu_list_set_destroy_item (list, NULL);
+  int rc = mu_list_replace (list, item, new_item);
+  mu_list_set_destroy_item (list, dptr);
+  return rc;
+}
+
+int
+mu_list_get (mu_list_t list, size_t indx, void **pitem)
+{
+  struct list_data *current;
+  size_t count;
+  int status = MU_ERR_NOENT;
+
+  if (list == NULL)
+    return EINVAL;
+  if (pitem == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  mu_monitor_rdlock (list->monitor);
+  for (current = list->head.next, count = 0; current != &list->head;
+       current = current->next, count++)
+    {
+      if (count == indx)
+        {
+          *pitem = current->item;
+         status = 0;
+         break;
+        }
+    }
+  mu_monitor_unlock (list->monitor);
+  return status;
+}
+
+int
+mu_list_do (mu_list_t list, mu_list_action_t *action, void *cbdata)
+{
+  mu_iterator_t itr;
+  int status = 0;
+
+  if (list == NULL || action == NULL)
+    return EINVAL;
+  status = mu_list_get_iterator (list, &itr);
+  if (status)
+    return status;
+  for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
+       mu_iterator_next (itr))
+    {
+      void *item;
+      mu_iterator_current (itr, &item);
+      if ((status = action (item, cbdata)))
+       break;
+    }
+  mu_iterator_destroy (&itr);
+  return status;
+}
+
+mu_list_destroy_item_t
+mu_list_set_destroy_item (mu_list_t list, void (*destroy_item)(void *item))
+{
+  mu_list_destroy_item_t ret = list->destroy_item;
+  list->destroy_item = destroy_item;
+  return ret;
+}
+
+int
+mu_list_to_array (mu_list_t list, void **array, size_t count, size_t *pcount)
+{
+  size_t total = 0;
+
+  if (!list)
+    return EINVAL;
+
+  total = (count < list->count) ? count : list->count;
+
+  if (array)
+    {
+      size_t i;
+      struct list_data *current;
+
+      for (i = 0, current = list->head.next;
+          i < total && current != &list->head; current = current->next)
+       array[i++] = current->item;
+    }
+  if (pcount)
+    *pcount = total;
+  return 0;
+}
+
+/* Computes an intersection of two lists and returns it in PDEST.
+   The resulting list contains elements from A that are
+   also encountered in B (as per comparison function of
+   the latter).
+
+   If DUP_ITEM is not NULL, it is used to create copies of
+   items to be stored in PDEST.  In this case, the destroy_item
+   function of B is also attached to PDEST.  Otherwise, if
+   DUP_ITEM is NULL, pointers to elements are stored and
+   no destroy_item function is assigned. */
+int
+mu_list_intersect_dup (mu_list_t *pdest, mu_list_t a, mu_list_t b,
+                      int (*dup_item) (void **, void *, void *),
+                      void *dup_closure)
+{
+  mu_list_t dest;
+  int rc;
+  mu_iterator_t itr;
+  
+  rc = mu_list_create (&dest);
+  if (rc)
+    return rc;
+
+  mu_list_set_comparator (dest, b->comp);
+  if (dup_item)
+    mu_list_set_destroy_item (dest, b->destroy_item);
+  
+  rc = mu_list_get_iterator (a, &itr);
+  if (rc)
+    {
+      mu_list_destroy (&dest);
+      return rc;
+    }
+
+  rc = 0;
+  for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
+       mu_iterator_next (itr))
+    {
+      void *data;
+      mu_iterator_current (itr, &data);
+      if (mu_list_locate (b, data, NULL) == 0)
+       {
+         void *new_data;
+         if (dup_item && data)
+           {
+             rc = dup_item (&new_data, data, dup_closure);
+             if (rc)
+               break;
+           }
+         else
+           new_data = data;
+       
+         mu_list_append (dest, new_data); /* FIXME: Check return, and? */
+       }
+    }
+  mu_iterator_destroy (&itr);
+  *pdest = dest;
+  return rc;
+}
+
+int
+mu_list_intersect (mu_list_t *pdest, mu_list_t a, mu_list_t b)
+{
+  return mu_list_intersect_dup (pdest, a, b, NULL, NULL);
+}
+
+
+/* Iterator interface */
+
+struct list_iterator
+{
+  mu_list_t list;
+  struct list_data *cur;
+  int backwards; /* true if iterating backwards */
+};
+
+static int
+first (void *owner)
+{
+  struct list_iterator *itr = owner;
+  if (itr->backwards)
+    itr->cur = itr->list->head.prev;
+  else
+    itr->cur = itr->list->head.next;
+  return 0;
+}
+
+static int
+next (void *owner)
+{
+  struct list_iterator *itr = owner;
+  if (itr->backwards)
+    itr->cur = itr->cur->prev;
+  else
+    itr->cur = itr->cur->next;
+  return 0;
+}
+
+static int
+getitem (void *owner, void **pret, const void **pkey)
+{
+  struct list_iterator *itr = owner;
+  *pret = itr->cur->item;
+  if (pkey)
+    *pkey = NULL;
+  return 0;
+}
+
+static int
+finished_p (void *owner)
+{
+  struct list_iterator *itr = owner;
+  return itr->cur == &itr->list->head;
+}
+
+static int
+destroy (mu_iterator_t iterator, void *data)
+{
+  struct list_iterator *itr = data;
+  mu_iterator_detach (&itr->list->itr, iterator);
+  free (data);
+  return 0;
+}
+
+static int
+curitem_p (void *owner, void *item)
+{
+  struct list_iterator *itr = owner;
+  return itr->cur == item;
+}
+
+static int
+list_data_dup (void **ptr, void *owner)
+{
+  *ptr = malloc (sizeof (struct list_iterator));
+  if (*ptr == NULL)
+    return ENOMEM;
+  memcpy (*ptr, owner, sizeof (struct list_iterator));
+  return 0;
+}
+
+static int
+list_itrctl (void *owner, enum mu_itrctl_req req, void *arg)
+{
+  struct list_iterator *itr = owner;
+  mu_list_t list = itr->list;
+  struct list_data *ptr;
+  
+  if (itr->cur == NULL)
+    return MU_ERR_NOENT;
+  switch (req)
+    {
+    case mu_itrctl_tell:
+      /* Return current position in the object */
+      {
+       size_t count;
+
+       for (count = 0, ptr = list->head.next; ptr != &list->head;
+            ptr = ptr->next, count++)
+         {
+           if (ptr == itr->cur)
+             {
+               *(size_t*)arg = count;
+               return 0;
+             }
+         }
+       return MU_ERR_NOENT;
+      }
+       
+    case mu_itrctl_delete:
+    case mu_itrctl_delete_nd:
+      /* Delete current element */
+      {
+       struct list_data *prev;
+       
+       ptr = itr->cur;
+       prev = ptr->prev;
+       
+       mu_iterator_advance (list->itr, ptr);
+       prev->next = ptr->next;
+       ptr->next->prev = prev;
+       if (req == mu_itrctl_delete)
+         DESTROY_ITEM (list, ptr);
+       free (ptr);
+       list->count--;
+      }
+      break;
+      
+    case mu_itrctl_replace:
+    case mu_itrctl_replace_nd:
+      /* Replace current element */
+      if (!arg)
+       return EINVAL;
+      ptr = itr->cur;
+      if (req == mu_itrctl_replace)
+         DESTROY_ITEM (list, ptr);
+      ptr = itr->cur;
+      ptr->item = arg;
+      break;
+      
+    case mu_itrctl_insert:
+      /* Insert new element in the current position */
+      if (!arg)
+       return EINVAL;
+      return _insert_item (list, itr->cur, arg, 0);
+
+    case mu_itrctl_insert_list:
+      /* Insert a list of elements */
+      if (!arg)
+       return EINVAL;
+      else
+       {
+         mu_list_t new_list = arg;
+         _mu_list_insert_sublist (list, itr->cur,
+                                  new_list->head.next, new_list->head.prev,
+                                  new_list->count,
+                                  0);
+         _mu_list_clear (new_list);
+       }
+      break;
+
+    case mu_itrctl_qry_direction:
+      if (!arg)
+       return EINVAL;
+      else
+       *(int*)arg = itr->backwards;
+      break;
+
+    case mu_itrctl_set_direction:
+      if (!arg)
+       return EINVAL;
+      else
+       itr->backwards = !!*(int*)arg;
+      break;
+      
+    default:
+      return ENOSYS;
+    }
+  return 0;
+}
+
+int
+mu_list_get_iterator (mu_list_t list, mu_iterator_t *piterator)
+{
+  mu_iterator_t iterator;
+  int status;
+  struct list_iterator *itr;
+
+  if (!list)
+    return EINVAL;
+
+  itr = calloc (1, sizeof *itr);
+  if (!itr)
+    return ENOMEM;
+  itr->list = list;
+  itr->cur = NULL;
+
+  status = mu_iterator_create (&iterator, itr);
+  if (status)
+    {
+      free (itr);
+      return status;
+    }
+
+  mu_iterator_set_first (iterator, first);
+  mu_iterator_set_next (iterator, next);
+  mu_iterator_set_getitem (iterator, getitem);
+  mu_iterator_set_finished_p (iterator, finished_p);
+  mu_iterator_set_curitem_p (iterator, curitem_p);
+  mu_iterator_set_destroy (iterator, destroy);
+  mu_iterator_set_dup (iterator, list_data_dup);
+  mu_iterator_set_itrctl (iterator, list_itrctl);
+  
+  mu_iterator_attach (&list->itr, iterator);
+
+  *piterator = iterator;
+  return 0;
+}
diff --git a/libmailutils/base/listlist.c b/libmailutils/base/listlist.c
new file mode 100644
index 0000000..723c0d4
--- /dev/null
+++ b/libmailutils/base/listlist.c
@@ -0,0 +1,138 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2008, 2010 Free
+   Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <mailutils/sys/list.h>
+#include <mailutils/sys/iterator.h>
+#include <mailutils/errno.h>
+
+void
+_mu_list_insert_sublist (mu_list_t list,
+                        struct list_data *current,
+                        struct list_data *head,
+                        struct list_data *tail,
+                        size_t count,
+                        int insert_before)
+{
+  if (insert_before)
+    {
+      head->prev = current->prev;
+      tail->next = current;
+      if (current->prev != &list->head)
+       current->prev->next = head;
+      else
+       list->head.next = head;
+
+      current->prev = tail;
+    }
+  else
+    {
+      tail->next = current->next;
+      head->prev = current;
+      if (current->next != &list->head)
+       current->next->prev = tail;
+      else
+       list->head.prev = tail;
+
+      current->next = head;
+    }
+  list->count += count;
+}
+
+void
+_mu_list_clear (mu_list_t list)
+{
+  list->head.next = list->head.prev = &list->head;
+  list->count = 0;
+}
+
+int
+mu_list_insert_list (mu_list_t list, void *item, mu_list_t new_list,
+                    int insert_before)
+{
+  struct list_data *current;
+  mu_list_comparator_t comp;
+  int status = MU_ERR_NOENT;
+
+  if (list == NULL)
+    return EINVAL;
+  comp = list->comp ? list->comp : _mu_list_ptr_comparator;
+
+  mu_monitor_wrlock (list->monitor);
+  for (current = list->head.next;
+       current != &list->head;
+       current = current->next)
+    {
+      if (comp (current->item, item) == 0)
+       {
+         _mu_list_insert_sublist (list, current,
+                                  new_list->head.next, new_list->head.prev,
+                                  new_list->count,
+                                  insert_before);
+         _mu_list_clear (new_list);
+         status = 0;
+         break;
+       }
+    }
+  mu_monitor_unlock (list->monitor);
+  return status;
+}
+
+void
+mu_list_append_list (mu_list_t list, mu_list_t new_list)
+{
+  if (list->count == 0)
+    {
+      list->head = new_list->head;
+      list->head.next->prev = list->head.prev->next = &list->head;
+      list->count = new_list->count;
+    }
+  else
+    _mu_list_insert_sublist (list, list->head.prev,
+                            new_list->head.next, new_list->head.prev,
+                            new_list->count,
+                            0);
+  _mu_list_clear (new_list);
+}
+
+void
+mu_list_prepend_list (mu_list_t list, mu_list_t new_list)
+{
+  if (list->count == 0)
+    {
+      list->head = new_list->head;
+      list->head.next->prev = list->head.prev->next = &list->head;
+      list->count = new_list->count;
+    }
+  else
+    _mu_list_insert_sublist (list, list->head.next,
+                            new_list->head.next, new_list->head.prev,
+                            new_list->count,
+                            1);
+  _mu_list_clear (new_list);
+}
+
+
+
diff --git a/libmailutils/base/locale.c b/libmailutils/base/locale.c
new file mode 100644
index 0000000..4234ad4
--- /dev/null
+++ b/libmailutils/base/locale.c
@@ -0,0 +1,241 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2003, 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/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/mutil.h>
+#include <mailutils/cstr.h>
+
+struct langtab
+{
+  char *lang;        /* Language code */
+  char *terr;        /* Territory code */
+  char *charset;     /* Corresponding charset */
+};
+
+/* The list of language codes defined in ISO 639 with the corresponding
+   default character sets.
+
+   NOTES:
+
+   1) The list must be ordered by:
+        a) lang field in ascending order
+       b) terr field in descending order.
+      NULL fields are considered less than non-null ones.
+   2) Many entries have NULL charset fields. Please help fill them!
+   3) The "default" character set for a given language is a matter
+      of preference. Possibly the table should contain a *list* of
+      possible character sets.
+   4) LC_ALL "modifier" field is not taken into account */
+
+static struct langtab langtab[] = {
+  { "C",     NULL, "ASCII"},
+  { "POSIX", NULL, "ASCII" },
+  { "aa",    NULL, NULL},              /* Afar */
+  { "ab",    NULL, NULL},              /* Abkhazian */
+  { "ae",    NULL, NULL},              /* Avestan */
+  { "af",    NULL, "iso-8859-1"},      /* Afrikaans */
+  { "am",    NULL, "UTF-8"},           /* Amharic */
+  { "ar",    NULL, "iso-8859-6"},      /* Arabic */
+  { "as",    NULL, NULL},              /* Assamese */
+  { "ay",    NULL, "iso-8859-1"},      /* Aymara */
+  { "az",    NULL, NULL},              /* Azerbaijani */
+  { "ba",    NULL, NULL},              /* Bashkir */
+  { "be",    NULL, "UTF-8"},           /* Byelorussian; Belarusian */
+  { "bg",    NULL, "iso-8859-5"},      /* Bulgarian */
+  { "bh",    NULL, NULL},              /* Bihari */
+  { "bi",    NULL, NULL},              /* Bislama */
+  { "bn",    NULL, NULL},              /* Bengali; Bangla */
+  { "bo",    NULL, NULL},              /* Tibetan */
+  { "br",    NULL, "iso-8859-1"},      /* Breton: 1,5,8,9 */
+  { "bs",    NULL, NULL},              /* Bosnian */
+  { "ca",    NULL, "iso-8859-1"},      /* Catalan: 1,5,8,9 */
+  { "ce",    NULL, NULL},              /* Chechen */
+  { "ch",    NULL, NULL},              /* Chamorro */
+  { "co",    NULL, "iso-8859-1"},      /* Corsican */
+  { "cs",    NULL, "iso-8859-2"},      /* Czech */
+  { "cu",    NULL, NULL },             /* Church Slavic */
+  { "cv",    NULL, NULL},              /* Chuvash */
+  { "cy",    NULL, "iso-8859-1"},      /* Welsh */
+  { "da",    NULL, "iso-8859-1"},      /* Danish: 4-9 */
+  { "de",    NULL, "iso-8859-1"},      /* German */
+  { "dz",    NULL, NULL },             /* Dzongkha; Bhutani */
+  { "el",    NULL, "iso-8859-7"},      /* Greek */
+  { "en",    NULL, "iso-8859-1"},      /* English */
+  { "eo",    NULL, "iso-8859-3"},      /* Esperanto */
+  { "es",    NULL, "iso-8859-1"},      /* Spanish */
+  { "et",    NULL, "iso-8859-15"},     /* Estonian: 6,7,9 */
+  { "eu",    NULL, "iso-8859-1"},      /* Basque: 5,8,9 */
+  { "fa",    NULL, "UTF-8"},           /* Persian */
+  { "fi",    NULL, "iso-8859-15"},     /* Finnish */
+  { "fj",    NULL, NULL },             /* Fijian; Fiji */
+  { "fo",    NULL, "iso-8859-1"},      /* Faroese: 6,9 */
+  { "fr",    NULL, "iso-8859-1"},      /* French */
+  { "fy",    NULL, "iso-8859-1"},      /* Frisian */
+  { "ga",    NULL, "iso-8859-14"},     /* Irish */
+  { "gd",    NULL, "iso-8859-14" },    /* Scots; Gaelic */
+  { "gl",    NULL, NULL },             /* Gallegan; Galician */
+  { "gn",    NULL, NULL},              /* Guarani */
+  { "gu",    NULL, NULL},              /* Gujarati */
+  { "gv",    NULL, "iso-8859-14"},     /* Manx */
+  { "ha",    NULL, NULL },             /* Hausa (?) */
+  { "he",    NULL, "iso-8859-8" },     /* Hebrew */
+  { "hi",    NULL, NULL},              /* Hindi */
+  { "ho",    NULL, NULL},              /* Hiri Motu */
+  { "hr",    NULL, "iso-8859-2"},      /* Croatian: 10 */
+  { "hu",    NULL, "iso-8859-2"},      /* Hungarian */
+  { "hy",    NULL, NULL},              /* Armenian */
+  { "hz",    NULL, NULL},              /* Herero */
+  { "id",    NULL, "iso-8859-1"},      /* Indonesian (formerly in) */
+  { "ia",    NULL, NULL},              /* Interlingua */
+  { "ie",    NULL, NULL},              /* Interlingue */
+  { "ik",    NULL, NULL},              /* Inupiak */
+  { "io",    NULL, NULL},              /* Ido */
+  { "is",    NULL, "iso-8859-1"},      /* Icelandic */
+  { "it",    NULL, "iso-8859-1"},      /* Italian */
+  { "iu",    NULL, NULL},              /* Inuktitut */
+  { "ja",    NULL, "EUC-JP"},          /* Japanese */
+  { "jv",    NULL, NULL},              /* Javanese */
+  { "ka",    NULL, NULL},              /* Georgian */
+  { "ki",    NULL, NULL},              /* Kikuyu */
+  { "kj",    NULL, NULL},              /* Kuanyama */
+  { "kk",    NULL, NULL},              /* Kazakh */
+  { "kl",    NULL, "iso-8859-1"},      /* Kalaallisut; Greenlandic */
+  { "km",    NULL, NULL},              /* Khmer; Cambodian */
+  { "kn",    NULL, NULL},              /* Kannada */
+  { "ko",    NULL, "EUC-KR"},          /* Korean */
+  { "ks",    NULL, NULL},              /* Kashmiri */
+  { "ku",    NULL, NULL},              /* Kurdish */
+  { "kv",    NULL, NULL},              /* Komi */
+  { "kw",    NULL, "iso-8859-14"},     /* Cornish: 1,5,8 */
+  { "ky",    NULL, NULL},              /* Kirghiz */
+  { "la",    NULL, "iso-8859-1"},      /* Latin */
+  { "lb",    NULL, "iso-8859-1"},      /* Letzeburgesch */
+  { "ln",    NULL, NULL},              /* Lingala */
+  { "lo",    NULL, NULL},              /* Lao; Laotian */
+  { "lt",    NULL, "iso-8859-4"},      /* Lithuanian */
+  { "lv",    NULL, "iso-8859-4"},      /* Latvian; Lettish */
+  { "mg",    NULL, NULL},              /* Malagasy */
+  { "mh",    NULL, NULL},              /* Marshall */
+  { "mi",    NULL, NULL},              /* Maori */
+  { "mk",    NULL, NULL},              /* Macedonian */
+  { "ml",    NULL, NULL},              /* Malayalam */
+  { "mn",    NULL, NULL},              /* Mongolian */
+  { "mo",    NULL, "iso-8859-2"},      /* Moldavian */
+  { "mr",    NULL, NULL},              /* Marathi */
+  { "ms",    NULL, NULL},              /* Malay */
+  { "mt",    NULL, "iso-8859-3"},      /* Maltese */
+  { "my",    NULL, NULL},              /* Burmese */
+  { "na",    NULL, NULL},              /* Nauru */
+  { "nb",    NULL, "iso-8859-1"},      /* Norwegian Bokmål; address@hidden  */
+  { "nd",    NULL, NULL},              /* Ndebele, North */
+  { "ne",    NULL, NULL},              /* Nepali */
+  { "ng",    NULL, NULL},              /* Ndonga */
+  { "nl",    NULL, "iso-8859-1"},      /* Dutch: 5,9 */
+  { "nn",    NULL, "iso-8859-1"},      /* Norwegian Nynorsk */
+  { "no",    NULL, "iso-8859-1"},      /* Norwegian */
+  { "nr",    NULL, NULL},              /* Ndebele, South */
+  { "nv",    NULL, NULL},              /* Navajo */
+  { "ny",    NULL, NULL},              /* Chichewa; Nyanja */
+  { "oc",    NULL, NULL},              /* Occitan; Provençal; Proven@,{c}al */
+  { "om",    NULL, NULL},              /* (Afan) Oromo */
+  { "or",    NULL, NULL},              /* Oriya */
+  { "os",    NULL, NULL},              /* Ossetian; Ossetic */
+  { "pa",    NULL, NULL},              /* Panjabi; Punjabi */
+  { "pi",    NULL, NULL},              /* Pali */
+  { "pl",    NULL, "iso-8859-2"},      /* Polish */
+  { "ps",    NULL, NULL},              /* Pashto, Pushto */
+  { "pt",    NULL, "iso-8859-1"},      /* Portuguese */
+  { "qu",    NULL, "iso-8859-1"},      /* Quechua */
+  { "rm",    NULL, "iso-8859-1"},      /* Rhaeto-Romance */
+  { "rn",    NULL, NULL },             /* Rundi; Kirundi */
+  { "ro",    NULL, "iso-8859-2"},      /* Romanian */
+  { "ru",    NULL, "koi8-r"},          /* Russian */
+  { "rw",    NULL, NULL},              /* Kinyarwanda */
+  { "sa",    NULL, NULL},              /* Sanskrit */
+  { "sc",    NULL, "iso-8859-1"},      /* Sardinian */
+  { "sd",    NULL, NULL},              /* Sindhi */
+  { "se",    NULL, "iso-8859-10"},     /* Northern Sami */
+  { "sg",    NULL, NULL},              /* Sango; Sangro */
+  { "si",    NULL, NULL},              /* Sinhalese */
+  { "sk",    NULL, "iso-8859-2"},      /* Slovak */
+  { "sl",    NULL, "iso-8859-1"},      /* Slovenian */
+  { "sm",    NULL, NULL},              /* Samoan */
+  { "sn",    NULL, NULL},              /* Shona */
+  { "so",    NULL, NULL},              /* Somali */
+  { "sq",    NULL, "iso-8859-1"},      /* Albanian: 2,5,8,9,10 */
+  { "sr",    NULL, "iso-8859-2"},      /* Serbian */
+  { "ss",    NULL, NULL},              /* Swati; Siswati */
+  { "st",    NULL, NULL},              /* Sesotho; Sotho, Southern */
+  { "su",    NULL, NULL},              /* Sundanese */
+  { "sv",    NULL, "iso-8859-1"},      /* Swedish */
+  { "sw",    NULL, NULL},              /* Swahili */
+  { "ta",    NULL, NULL},              /* Tamil */
+  { "te",    NULL, NULL},              /* Telugu */
+  { "tg",    NULL, NULL},              /* Tajik */
+  { "th",    NULL, "iso-8859-11"},     /* Thai */
+  { "ti",    NULL, NULL},              /* Tigrinya */
+  { "tk",    NULL, NULL},              /* Turkmen */
+  { "tl",    NULL, "iso-8859-1"},      /* Tagalog */
+  { "tn",    NULL, NULL},              /* Tswana; Setswana */
+  { "to",    NULL, NULL},              /* Tonga (?) */
+  { "tr",    NULL, "iso-8859-9"},      /* Turkish */
+  { "ts",    NULL, NULL},              /* Tsonga */
+  { "tt",    NULL, NULL},              /* Tatar */
+  { "tw",    NULL, NULL},              /* Twi */
+  { "ty",    NULL, NULL},              /* Tahitian */
+  { "ug",    NULL, NULL},              /* Uighur */
+  { "uk",    NULL, "koi8-u"},          /* Ukrainian */
+  { "ur",    NULL, NULL},              /* Urdu */
+  { "uz",    NULL, NULL},              /* Uzbek */
+  { "vi",    NULL, NULL},              /* Vietnamese */
+  { "vo",    NULL, NULL},              /* Volapük; Volap@"{u}k; Volapuk */
+  { "wa",    NULL, "iso-8859-1"},      /* Walloon */
+  { "wo",    NULL, NULL},              /* Wolof */
+  { "xh",    NULL, NULL},              /* Xhosa */
+  { "yi",    NULL, "iso-8859-8"},      /* Yiddish (formerly ji) */
+  { "yo",    NULL, NULL},              /* Yoruba */
+  { "za",    NULL, NULL},              /* Zhuang */
+  { "zh",    "TW", "big5"},            /* Chinese */
+  { "zh",    NULL, "gb2312"},          /* Chinese */
+  { "zu",    NULL, NULL},              /* Zulu */
+  { NULL }
+};
+
+/* Given the language and (optionally) territory code, return the
+   default character set for that language. See notes above. */
+
+const char *
+mu_charset_lookup (char *lang, char *terr)
+{
+  static struct langtab *p;
+
+  if (!lang)
+    return NULL;
+  for (p = langtab; p->lang; p++)
+    if (mu_c_strcasecmp (p->lang, lang) == 0
+       && (terr == NULL 
+           || p->terr == NULL
+           || !mu_c_strcasecmp (p->terr, terr) == 0))
+      return p->charset;
+  return NULL;
+}
+
diff --git a/libmailutils/base/locker.c b/libmailutils/base/locker.c
new file mode 100644
index 0000000..b720e20
--- /dev/null
+++ b/libmailutils/base/locker.c
@@ -0,0 +1,1026 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2005, 2006, 2007, 2008, 2010 Free
+   Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <utime.h>
+
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <mailutils/errno.h>
+#include <mailutils/locker.h>
+#include <mailutils/mutil.h>
+
+#define LOCKFILE_ATTR           0644
+
+/* First draft by Brian Edmond. */
+/* For subsequent modifications, see the GNU mailutils ChangeLog. */
+
+struct _mu_locker
+{
+  unsigned refcnt;             /* Number of times mu_locker_lock was called */
+  enum mu_locker_mode mode;    /* Current locking mode (if refcnt > 0) */
+
+  char *file;
+  int flags;
+  int expire_time;
+  int retries;
+  int retry_sleep;
+
+  union lock_data {
+    struct {
+      char *dotlock;
+      char *nfslock;
+    } dot;
+    
+    struct {
+      char *name;
+    } external;
+    
+    struct {
+      int fd;
+    } kernel;
+  } data;
+};
+
+#define MU_LOCKER_TYPE(l) MU_LOCKER_FLAG_TO_TYPE((l)->flags)
+
+struct locker_tab
+{
+  int (*init) (mu_locker_t);
+  void (*destroy) (mu_locker_t);
+  int (*prelock) (mu_locker_t); 
+  int (*lock) (mu_locker_t, enum mu_locker_mode);
+  int (*unlock) (mu_locker_t);
+};
+
+static int init_dotlock (mu_locker_t);
+static void destroy_dotlock (mu_locker_t);
+static int lock_dotlock (mu_locker_t, enum mu_locker_mode);
+static int unlock_dotlock (mu_locker_t);
+
+static int init_external (mu_locker_t);
+static void destroy_external (mu_locker_t);
+static int lock_external (mu_locker_t, enum mu_locker_mode);
+static int unlock_external (mu_locker_t);
+
+static int init_kernel (mu_locker_t);
+static int lock_kernel (mu_locker_t, enum mu_locker_mode);
+static int unlock_kernel (mu_locker_t);
+
+static int prelock_common (mu_locker_t);
+
+static struct locker_tab locker_tab[] = {
+  /* MU_LOCKER_TYPE_DOTLOCK */
+  { init_dotlock, destroy_dotlock, prelock_common,
+    lock_dotlock, unlock_dotlock },
+  /* MU_LOCKER_TYPE_EXTERNAL */
+  { init_external, destroy_external, prelock_common,
+    lock_external, unlock_external },
+  /* MU_LOCKER_TYPE_KERNEL */
+  { init_kernel, NULL, NULL, lock_kernel, unlock_kernel },
+  /* MU_LOCKER_TYPE_NULL */
+  { NULL, NULL, NULL, NULL, NULL }
+};
+
+#define MU_LOCKER_NTYPES (sizeof (locker_tab) / sizeof (locker_tab[0]))
+
+
+static int
+stat_check (const char *file, int fd, int links)
+{
+  struct stat fn_stat;
+  struct stat fd_stat;
+  int err = 0;
+  int localfd = -1;
+
+  if (fd == -1)
+    {
+      localfd = open (file, O_RDONLY);
+      
+      if (localfd == -1)
+       return errno;
+      fd = localfd;
+    }
+
+  /* We should always be able to stat a valid fd, so this
+     is an error condition. */
+  if (lstat (file, &fn_stat) || fstat (fd, &fd_stat))
+    err = errno;
+  else
+    {
+      /* If the link and stat don't report the same info, or the
+         file is a symlink, fail the locking. */
+#define CHK(X) if(X) err = EINVAL
+
+      CHK (!S_ISREG (fn_stat.st_mode));
+      CHK (!S_ISREG (fd_stat.st_mode));
+      CHK (fn_stat.st_nlink != links);
+      CHK (fn_stat.st_dev != fd_stat.st_dev);
+      CHK (fn_stat.st_ino != fd_stat.st_ino);
+      CHK (fn_stat.st_mode != fd_stat.st_mode);
+      CHK (fn_stat.st_nlink != fd_stat.st_nlink);
+      CHK (fn_stat.st_uid != fd_stat.st_uid);
+      CHK (fn_stat.st_gid != fd_stat.st_gid);
+      CHK (fn_stat.st_rdev != fd_stat.st_rdev);
+
+#undef CHK
+    }
+  if (localfd != -1)
+    close (localfd);
+
+  return err;
+}
+
+static int
+check_file_permissions (const char *file)
+{
+  int fd = -1;
+  int err = 0;
+
+  if ((fd = open (file, O_RDONLY)) == -1)
+    return errno == ENOENT ? 0 : errno;
+
+  err = stat_check (file, fd, 1);
+  close (fd);
+  fd = -1;
+  if (err)
+    {
+      if (err == EINVAL)
+       err = MU_ERR_LOCK_BAD_FILE;
+      return err;
+    }
+
+  return 0;
+}
+
+static int
+prelock_common (mu_locker_t locker)
+{
+  /* Check if we are trying to lock a regular file, with a link count
+     of 1, that we have permission to read, etc., or don't lock it. */
+  return check_file_permissions (locker->file);
+}
+
+
+static int mu_locker_default_flags = MU_LOCKER_DEFAULT;
+static time_t mu_locker_retry_timeout = MU_LOCKER_RETRY_SLEEP;
+static size_t mu_locker_retry_count = MU_LOCKER_RETRIES;
+static time_t mu_locker_expire_timeout = MU_LOCKER_EXPIRE_TIME;
+static char *mu_locker_external_program = NULL;
+
+int
+mu_locker_set_default_flags (int flags, enum mu_locker_set_mode mode)
+{
+  switch (mode)
+    {
+    case mu_locker_assign:
+      mu_locker_default_flags = flags;
+      break;
+
+    case mu_locker_set_bit:
+      mu_locker_default_flags |= flags;
+      break;
+
+    case mu_locker_clear_bit:
+      mu_locker_default_flags &= ~flags;
+      break;
+
+    default:
+      return EINVAL;
+    }
+  return 0;
+}
+
+void
+mu_locker_set_default_retry_timeout (time_t to)
+{
+  mu_locker_retry_timeout = to;
+}
+
+void
+mu_locker_set_default_retry_count (size_t n)
+{
+  mu_locker_retry_count = n;
+}
+
+void
+mu_locker_set_default_expire_timeout (time_t t)
+{
+  mu_locker_expire_timeout = t;
+}
+
+void
+mu_locker_set_default_external_program (char *path)
+{
+  free (mu_locker_external_program);
+  mu_locker_external_program = strdup (path);
+}
+
+int
+mu_locker_mod_flags (mu_locker_t locker, int flags,
+                    enum mu_locker_set_mode mode)
+{
+  unsigned otype, ntype;
+  int new_flags;
+  
+  if (!locker)
+    return MU_ERR_LOCKER_NULL;
+
+  switch (mode)
+    {
+    case mu_locker_assign:
+      new_flags = flags;
+      break;
+
+    case mu_locker_set_bit:
+      new_flags = locker->flags | flags;
+      break;
+
+    case mu_locker_clear_bit:
+      new_flags = locker->flags & ~flags;
+      break;
+
+    default:
+      return EINVAL;
+    }
+
+  otype = MU_LOCKER_TYPE (locker);
+  if (otype >= MU_LOCKER_NTYPES)
+    return EINVAL;
+  ntype = MU_LOCKER_FLAG_TO_TYPE (new_flags);
+  if (ntype >= MU_LOCKER_NTYPES)
+    return EINVAL;
+
+  if (ntype != otype)
+    {
+      int rc;
+      
+      if (locker_tab[otype].destroy)
+       locker_tab[otype].destroy (locker);
+      locker->flags = new_flags;
+      if (locker_tab[ntype].init)
+       {
+         rc = locker_tab[ntype].init (locker);
+         if (rc)
+           locker->flags = MU_LOCKER_NULL;
+         return rc;
+       }
+    }
+  else
+    locker->flags = new_flags;
+
+  return 0;
+}
+
+int
+mu_locker_set_flags (mu_locker_t locker, int flags)
+{
+  return mu_locker_mod_flags (locker, flags, mu_locker_assign);
+}
+
+int
+mu_locker_set_expire_time (mu_locker_t locker, int etime)
+{
+  if (!locker)
+    return MU_ERR_LOCKER_NULL;
+
+  if (etime <= 0)
+    return EINVAL;
+
+  locker->expire_time = etime;
+
+  return 0;
+}
+
+int
+mu_locker_set_retries (mu_locker_t locker, int retries)
+{
+  if (!locker)
+    return MU_ERR_LOCKER_NULL;
+
+  if (retries <= 0)
+    return EINVAL;
+
+  locker->retries = retries;
+
+  return 0;
+}
+
+int
+mu_locker_set_retry_sleep (mu_locker_t locker, int retry_sleep)
+{
+  if (!locker)
+    return MU_ERR_LOCKER_NULL;
+
+  if (retry_sleep <= 0)
+    return EINVAL;
+
+  locker->retry_sleep = retry_sleep;
+
+  return 0;
+}
+
+int
+mu_locker_set_external (mu_locker_t locker, const char* program)
+{
+  char* p = NULL;
+
+  if (!locker)
+    return MU_ERR_LOCKER_NULL;
+  if (MU_LOCKER_TYPE (locker) != MU_LOCKER_TYPE_EXTERNAL)
+    return EINVAL;
+    
+  /* program can be NULL */
+  if (program != 0)
+    {
+      p = strdup (program);
+      if (!p)
+       return ENOMEM;
+  }
+
+  free (locker->data.external.name);
+  locker->data.external.name = p;
+
+  return 0;
+}
+
+int
+mu_locker_get_flags (mu_locker_t locker, int *flags)
+{
+  if (!locker)
+    return MU_ERR_LOCKER_NULL;
+
+  if (!flags)
+    return EINVAL;
+
+  *flags = locker->flags;
+
+  return 0;
+}
+
+int
+mu_locker_get_expire_time (mu_locker_t locker, int *ptime)
+{
+  if (!locker)
+    return MU_ERR_LOCKER_NULL;
+
+  if (!ptime)
+    return EINVAL;
+
+  *ptime = locker->expire_time;
+
+  return 0;
+}
+
+int
+mu_locker_get_retries (mu_locker_t locker, int *retries)
+{
+  if (!locker)
+    return MU_ERR_LOCKER_NULL;
+
+  if (!retries)
+    return EINVAL;
+
+  *retries = locker->retries;
+
+  return 0;
+}
+
+int
+mu_locker_get_retry_sleep (mu_locker_t locker, int *retry_sleep)
+{
+  if (!locker)
+    return MU_ERR_LOCKER_NULL;
+
+  if (!retry_sleep)
+    return EINVAL;
+
+  *retry_sleep = locker->retry_sleep;
+
+  return 0;
+}
+
+int
+mu_locker_create (mu_locker_t *plocker, const char *fname, int flags)
+{
+  unsigned type;
+  mu_locker_t l;
+  char filename[_POSIX_PATH_MAX];
+  int err = 0;
+
+  if (plocker == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+
+  if (fname == NULL)
+    return EINVAL;
+
+  if ((err = mu_unroll_symlink (filename, sizeof (filename), fname)))
+    return err;
+
+  l = calloc (1, sizeof (*l));
+
+  if (l == NULL)
+    return ENOMEM;
+
+  l->file = strdup (filename);
+  
+  if (l->file == NULL)
+    {
+      free (l);
+      return ENOMEM;
+    }
+
+  if (strcmp (filename, "/dev/null") == 0)
+    l->flags = MU_LOCKER_NULL;
+  else if (flags)
+    l->flags = flags;
+  else
+    l->flags = mu_locker_default_flags;
+
+  l->expire_time = mu_locker_expire_timeout;
+  l->retries = mu_locker_retry_count;
+  l->retry_sleep = mu_locker_retry_timeout;
+
+  type = MU_LOCKER_TYPE (l);
+
+  if (type >= MU_LOCKER_NTYPES)
+    {
+      free (l->file);
+      return EINVAL;
+    }
+
+  /* Initialize locker-type-specific data */
+  err = locker_tab[type].init ? locker_tab[type].init (l) : 0;
+  if (err)
+    {
+      mu_locker_destroy (&l);
+      return err;
+    }
+
+  *plocker = l;
+
+  return 0;
+}
+
+void
+mu_locker_destroy (mu_locker_t *plocker)
+{
+  if (plocker && *plocker)
+    {
+      unsigned type = MU_LOCKER_TYPE (*plocker);
+      if (type < MU_LOCKER_NTYPES)
+       {
+         if (locker_tab[type].destroy)
+           locker_tab[type].destroy (*plocker);
+         free ((*plocker)->file);
+         free (*plocker);
+         *plocker = NULL;
+       }
+    }
+}
+
+int
+_mu_locker_lock (mu_locker_t lock, enum mu_locker_mode mode)
+{
+  int rc;
+  unsigned type;
+  unsigned retries = 1;
+  
+  if (lock == NULL || (type = MU_LOCKER_TYPE (lock)) >= MU_LOCKER_NTYPES)
+    return EINVAL;
+
+  if (locker_tab[type].prelock && (rc = locker_tab[type].prelock (lock)))
+    return rc;
+  
+  /* Is the lock already applied? */
+  if (lock->refcnt > 0)
+    {
+      lock->refcnt++;
+      if (mode == lock->mode)
+       return 0;
+    }
+
+  lock->mode = mode;
+
+  if (lock->flags & MU_LOCKER_RETRY)
+    retries = lock->retries;
+
+  if (locker_tab[type].lock)
+    {
+      while (retries--)
+       {
+         rc = locker_tab[type].lock (lock, mode);
+         if (rc == EAGAIN && retries)
+           {
+             sleep (lock->retry_sleep);
+             continue;
+           }
+
+         if (rc == 0)
+           lock->refcnt++;
+
+         break;
+       }
+    }
+  else
+    rc = 0;
+  
+  return rc;
+}
+
+int
+mu_locker_lock (mu_locker_t lock)
+{
+  return _mu_locker_lock (lock, mu_lck_exc);
+}
+
+int
+mu_locker_unlock (mu_locker_t lock)
+{
+  int rc = 0;
+  unsigned type;
+  
+  if (!lock)
+    return MU_ERR_LOCKER_NULL;
+
+  if (lock->refcnt == 0)
+    return MU_ERR_LOCK_NOT_HELD;
+
+  if ((rc = check_file_permissions (lock->file)))
+    return rc;
+
+  if (--lock->refcnt > 0)
+    return 0;
+
+  type = MU_LOCKER_TYPE (lock);
+  if (locker_tab[type].unlock)
+    rc = locker_tab[type].unlock (lock);
+  else
+    rc = 0;
+  
+  return rc;
+}
+
+int
+mu_locker_remove_lock (mu_locker_t lock)
+{
+  if (!lock)
+    return MU_ERR_LOCKER_NULL;
+
+  /* Force the reference count to 1 to unlock the file. */
+  lock->refcnt = 1;
+  return mu_locker_unlock (lock);
+}
+
+
+#define DOTLOCK_SUFFIX ".lock"
+
+/* expire a stale lock (if MU_LOCKER_PID or MU_LOCKER_TIME) */
+static void
+expire_stale_lock (mu_locker_t lock)
+{
+  int stale = 0;
+  int fd = open (lock->data.dot.dotlock, O_RDONLY);
+  if (fd == -1)
+    return;
+
+  /* Check to see if this process is still running.  */
+  if (lock->flags & MU_LOCKER_PID)
+    {
+      char buf[16];
+      pid_t pid;
+      int nread = read (fd, buf, sizeof (buf) - 1);
+      if (nread > 0)
+       {
+         buf[nread] = '\0';
+         pid = strtol (buf, NULL, 10);
+         if (pid > 0)
+           {
+             /* Process is gone so we try to remove the lock. */
+             if (kill (pid, 0) == -1)
+               stale = 1;
+           }
+         else
+           stale = 1;          /* Corrupted file, remove the lock. */
+       }
+    }
+  
+  /* Check to see if the lock expired.  */
+  if (lock->flags & MU_LOCKER_TIME)
+    {
+      struct stat stbuf;
+
+      fstat (fd, &stbuf);
+      /* The lock has expired. */
+      if ((time (NULL) - stbuf.st_mtime) > lock->expire_time)
+       stale = 1;
+    }
+
+  close (fd);
+  if (stale)
+    unlink (lock->data.dot.dotlock);
+}
+
+static int
+init_dotlock (mu_locker_t locker)
+{
+  char *tmp, *p;
+
+  /* Make sure the spool directory is writable */
+  tmp = strdup (locker->file);
+  if (!tmp)
+    return ENOMEM;
+
+  strcpy (tmp, locker->file);
+  p = strrchr (tmp, '/');
+  if (!p)
+    {
+      free (tmp);
+      tmp = strdup (".");
+      if (!tmp)
+       return ENOMEM;
+    }
+  else
+    *p = 0; 
+
+  if (access (tmp, W_OK))
+    {
+      /* Fallback to kernel locking */
+      free (tmp);
+      return mu_locker_set_flags (locker,
+                          MU_LOCKER_KERNEL|MU_LOCKER_OPTIONS(locker->flags));
+    }
+  
+  free (tmp);
+  
+  locker->data.dot.dotlock = malloc (strlen (locker->file)
+                                    + sizeof (DOTLOCK_SUFFIX));
+  
+  if (!locker->data.dot.dotlock)
+    return ENOMEM;
+  strcpy (locker->data.dot.dotlock, locker->file);
+  strcat (locker->data.dot.dotlock, DOTLOCK_SUFFIX);
+
+  return 0;
+}
+
+static void
+destroy_dotlock (mu_locker_t locker)
+{
+  free (locker->data.dot.dotlock);
+  free (locker->data.dot.nfslock);
+}
+
+static int
+lock_dotlock (mu_locker_t locker, enum mu_locker_mode mode)
+{
+  int rc;
+  char *host = NULL;
+  char pid[11];                /* 10 is strlen(2^32 = 4294967296) */
+  char now[11];
+  size_t sz = 0;
+  int err = 0;
+  int fd;
+    
+  if (locker->data.dot.nfslock)
+    {
+      unlink (locker->data.dot.nfslock);
+      free (locker->data.dot.nfslock);
+      locker->data.dot.nfslock = NULL;
+    }
+
+  expire_stale_lock (locker);
+
+  /* build the NFS hitching-post to the lock file */
+
+  rc = mu_get_host_name (&host);
+  if (rc)
+    return rc;
+
+  snprintf (now, sizeof (now), "%lu", (unsigned long) time (0));
+  now[sizeof (now) - 1] = 0;
+
+  snprintf (pid, sizeof (pid), "%lu", (unsigned long) getpid ());
+  pid[sizeof (pid) - 1] = 0;
+                 
+  sz = strlen (locker->file) + 1 /* "." */
+    + strlen (pid) + 1 /* "." */
+    + strlen (now) + 1 /* "." */
+    + strlen (host) + 1;
+  
+  locker->data.dot.nfslock = malloc (sz);
+  
+  if (!locker->data.dot.nfslock)
+    {
+      free (host);
+      return ENOMEM;
+    }
+
+  snprintf (locker->data.dot.nfslock, sz, "%s.%s.%s.%s",
+           locker->file, pid, now, host);
+  free (host);
+  
+  fd = open (locker->data.dot.nfslock,
+            O_WRONLY | O_CREAT | O_EXCL, LOCKFILE_ATTR);
+  if (fd == -1)
+    {
+      if (errno == EEXIST)
+       return EAGAIN;
+      else
+       return errno;
+    }
+  close (fd);
+  
+  /* Try to link to the lockfile. */
+  if (link (locker->data.dot.nfslock, locker->data.dot.dotlock) == -1)
+    {
+      unlink (locker->data.dot.nfslock);
+      if (errno == EEXIST)
+       return MU_ERR_LOCK_CONFLICT;
+      return errno;
+    }
+
+  if ((fd = open (locker->data.dot.dotlock, O_RDWR)) == -1)
+    {
+      unlink (locker->data.dot.nfslock);
+      return errno;
+    }
+  
+  err = stat_check (locker->data.dot.nfslock, fd, 2);
+  if (err)
+    {
+      unlink (locker->data.dot.nfslock);
+      if (err == EINVAL)
+       return MU_ERR_LOCK_BAD_LOCK;
+      return errno;
+    }
+
+  unlink (locker->data.dot.nfslock);
+
+  /* FIXME: If no errors, we have the lock. */
+  assert (locker->refcnt == 0);
+
+  if (locker->flags & MU_LOCKER_PID)
+    {
+      char buf[16];
+      sprintf (buf, "%ld", (long) getpid ());
+      write (fd, buf, strlen (buf));
+    }
+  close (fd);
+  return 0;
+}
+
+static int
+unlock_dotlock (mu_locker_t locker)
+{
+  if (unlink (locker->data.dot.dotlock) == -1)
+    {
+      int err = errno;
+      if (err == ENOENT)
+       {
+         locker->refcnt = 0; /*FIXME?*/
+         err = MU_ERR_LOCK_NOT_HELD;
+         return err;
+       }
+      return err;
+    }
+  return 0;
+}
+
+int
+mu_locker_touchlock (mu_locker_t lock)
+{
+  if (!lock)
+    return MU_ERR_LOCKER_NULL;
+
+  if (MU_LOCKER_TYPE (lock) != MU_LOCKER_TYPE_DOTLOCK)
+    return 0;
+  
+  if (lock->refcnt > 0)
+    return utime (lock->data.dot.dotlock, NULL);
+
+  return MU_ERR_LOCK_NOT_HELD;
+}
+
+
+/* Kernel locking */
+static int
+init_kernel (mu_locker_t locker)
+{
+  return 0;
+}
+
+static int
+lock_kernel (mu_locker_t locker, enum mu_locker_mode mode)
+{
+  int fd;
+  struct flock fl;
+
+  switch (mode)
+    {
+    case mu_lck_shr:
+    case mu_lck_opt:
+      mode = O_RDONLY;
+      fl.l_type = F_RDLCK;
+      break;
+
+    case mu_lck_exc:
+      mode = O_RDWR;
+      fl.l_type = F_WRLCK;
+      break;
+
+    default:
+      return EINVAL;
+    }
+  
+  fd = open (locker->file, O_RDWR);
+  if (fd == -1)
+    return errno;
+  locker->data.kernel.fd = fd;
+  
+  fl.l_whence = SEEK_SET;
+  fl.l_start = 0;
+  fl.l_len = 0; /* Lock entire file */
+  if (fcntl (fd, F_SETLK, &fl))
+    {
+#ifdef EACCESS      
+      if (errno == EACCESS)
+       return EAGAIN;
+#endif
+      if (errno == EAGAIN)
+       return EAGAIN;
+      return errno;
+    }
+  return 0;
+}
+
+static int
+unlock_kernel (mu_locker_t locker)
+{
+  struct flock fl;
+
+  fl.l_type = F_UNLCK;
+  fl.l_whence = SEEK_SET;
+  fl.l_start = 0;
+  fl.l_len = 0; /* Unlock entire file */
+  if (fcntl (locker->data.kernel.fd, F_SETLK, &fl))
+    {
+#ifdef EACCESS
+      if (errno == EACCESS)
+       return EAGAIN;
+#endif
+      if (errno == EAGAIN)
+       return EAGAIN;
+      return errno;
+    }
+  close (locker->data.kernel.fd);
+  return 0;
+}
+
+static int
+init_external (mu_locker_t locker)
+{
+  if (!(locker->data.external.name = strdup (mu_locker_external_program ?
+                                            mu_locker_external_program :
+                                            MU_LOCKER_EXTERNAL_PROGRAM)))
+    return ENOMEM;
+  return 0;
+}
+
+static void
+destroy_external (mu_locker_t locker)
+{
+  free (locker->data.external.name);
+}
+
+/*
+  Estimate 1 decimal digit per 3 bits, + 1 for round off.
+*/
+#define DEC_DIGS_PER_INT (sizeof(int) * 8 / 3 + 1)
+
+static int
+external_locker (mu_locker_t l, int lock)
+{
+  int err = 0;
+  char *av[6];
+  int ac = 0;
+  char aforce[3 + DEC_DIGS_PER_INT + 1];
+  char aretry[3 + DEC_DIGS_PER_INT + 1];
+  int status = 0;
+
+  assert (l);
+  assert (l->flags & MU_LOCKER_EXTERNAL);
+  /* FIXME */
+  assert (lock == !l->refcnt);
+  /* lock is true, refcnt is 0 or lock is false and refcnt is 1 */
+
+  av[ac++] = l->data.external.name ?
+                   l->data.external.name : MU_LOCKER_EXTERNAL_PROGRAM;
+
+  if (l->flags & MU_LOCKER_TIME)
+    {
+      snprintf (aforce, sizeof (aforce), "-f%d", l->expire_time);
+      aforce[sizeof (aforce) - 1] = 0;
+      av[ac++] = aforce;
+    }
+  
+  if (l->flags & MU_LOCKER_RETRY)
+    {
+      snprintf (aretry, sizeof (aretry), "-r%d", l->retries);
+      aretry[sizeof (aretry) - 1] = 0;
+      av[ac++] = aretry;
+    }
+
+  if (!lock)
+    av[ac++] = "-u";
+
+  av[ac++] = l->file;
+
+  av[ac++] = NULL;
+
+  if ((err = mu_spawnvp (av[0], av, &status)))
+    return err;
+
+  if (!WIFEXITED (status))
+    {
+      err = MU_ERR_LOCK_EXT_KILLED;
+    }
+  else
+    {
+      switch (WEXITSTATUS (status))
+       {
+       case 127:
+         err = MU_ERR_LOCK_EXT_FAIL;
+         break;
+         
+       case MU_DL_EX_OK:
+         err = 0;
+         l->refcnt = lock;
+         break;
+         
+       case MU_DL_EX_NEXIST:
+         err = MU_ERR_LOCK_NOT_HELD;
+         break;
+         
+       case MU_DL_EX_EXIST:
+         err = MU_ERR_LOCK_CONFLICT;
+         break;
+         
+       case MU_DL_EX_PERM:
+         err = EPERM;
+         break;
+         
+       default:
+       case MU_DL_EX_ERROR:
+         err = MU_ERR_LOCK_EXT_ERR;
+         break;
+       }
+    }
+
+  return err;
+}
+
+static int
+lock_external (mu_locker_t locker, enum mu_locker_mode mode)
+{
+  return external_locker (locker, 1);
+}
+
+static int
+unlock_external (mu_locker_t locker)
+{
+  return external_locker (locker, 0);
+}
+
diff --git a/libmailutils/base/mailcap.c b/libmailutils/base/mailcap.c
new file mode 100644
index 0000000..ede3f67
--- /dev/null
+++ b/libmailutils/base/mailcap.c
@@ -0,0 +1,739 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2003, 2004, 2005, 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/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include <mailutils/cctype.h>
+#include <mailutils/mailcap.h>
+#include <mailutils/stream.h>
+#include <mailutils/mutil.h>
+#include <mailutils/cstr.h>
+
+/* Definition of the structure, this should be in mailutils/sys/mailcap.h.  */
+struct _mu_mailcap_entry
+{
+  char * typefield;
+  char * viewcommand;
+  char ** fields;
+  size_t fields_count;
+};
+
+/* Definition of the structure, this should be in mailutils/sys/mailcap.h.  */
+struct _mu_mailcap
+{
+  mu_mailcap_entry_t *entries;
+  size_t entries_count;
+};
+
+
+static int mu_mailcap_parse (mu_mailcap_t mailcap, mu_stream_t stream);
+static int mu_mailcap_parse_entry (mu_mailcap_entry_t entry, char *buffer);
+static char * tokenize (char *s, char **save_ptr);
+
+int
+mu_mailcap_create (mu_mailcap_t * pmailcap, mu_stream_t stream)
+{
+  mu_mailcap_t mailcap;
+  int status = 0;
+
+  if (stream == NULL)
+    return EINVAL;
+  if (pmailcap == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+
+  mailcap = calloc (1, sizeof (*mailcap));
+  if (mailcap != NULL)
+    {
+      status = mu_mailcap_parse (mailcap, stream);
+      if (status != 0)
+       {
+         mu_mailcap_destroy (&mailcap);
+       }
+      else
+       {
+         *pmailcap = mailcap;
+       }
+    }
+  else
+    {
+      status = ENOMEM;
+    }
+  return status;
+}
+
+void
+mu_mailcap_destroy (mu_mailcap_t * pmailcap)
+{
+  if (pmailcap != NULL && *pmailcap != NULL)
+    {
+      int i;
+      mu_mailcap_t mailcap = *pmailcap;
+
+      for (i = 0; i < mailcap->entries_count; i++)
+       {
+         int j;
+         mu_mailcap_entry_t entry = mailcap->entries[i];
+         free (entry->typefield);
+         free (entry->viewcommand);
+         for (j = 0; j < entry->fields_count; j++)
+           {
+             free (entry->fields[j]);
+           }
+       }
+    }
+}
+
+int
+mu_mailcap_entries_count (mu_mailcap_t mailcap, size_t *pcount)
+{
+  int status = 0;
+
+  if (mailcap == NULL)
+    status = EINVAL;
+  if (pcount != NULL)
+    {
+      *pcount = mailcap->entries_count;
+    }
+  return status;
+}
+
+int
+mu_mailcap_get_entry (mu_mailcap_t mailcap, size_t no,
+                     mu_mailcap_entry_t *pentry)
+{
+  int status = 0;
+  if (mailcap == NULL)
+    status = EINVAL;
+  else if (pentry == NULL)
+    status = MU_ERR_OUT_PTR_NULL;
+  else if (no == 0 || no > mailcap->entries_count)
+    {
+      status = MU_ERR_NOENT;
+    }
+  else
+    {
+      *pentry = mailcap->entries[no - 1];
+    }
+  return status;
+}
+
+int
+mu_mailcap_entry_get_typefield (mu_mailcap_entry_t entry, char *buffer,
+                               size_t buflen, size_t *pn)
+{
+  int status = 0;
+  int len = 0;
+
+  if (entry == NULL)
+    {
+      status = EINVAL;
+    }
+  else
+    {
+      len = strlen(entry->typefield);
+      if (buffer != NULL && buflen > 0)
+       {
+         buflen--;
+         len = (len < buflen) ? len : buflen;
+         memcpy (buffer, entry->typefield, len);
+         buffer[len] = '\0';
+       }
+    }
+  if (pn)
+    {
+      *pn = len;
+    }
+  return status;
+}
+
+int
+mu_mailcap_entry_get_viewcommand (mu_mailcap_entry_t entry, char *buffer,
+                                 size_t buflen, size_t *pn)
+{
+  int status = 0;
+  int len = 0;
+
+  if (entry == NULL)
+    {
+      status = EINVAL;
+    }
+  else
+    {
+      len = strlen(entry->viewcommand);
+      if (buffer != NULL && buflen > 0)
+       {
+         buflen--;
+         len = (len < buflen) ? len : buflen;
+         memcpy (buffer, entry->viewcommand, len);
+         buffer[len] = '\0';
+       }
+    }
+  if (pn)
+    {
+      *pn = len;
+    }
+  return status;
+}
+
+int
+mu_mailcap_entry_fields_count (mu_mailcap_entry_t entry, size_t *pcount)
+{
+  int status = 0;
+  if (entry == NULL)
+    {
+      status = EINVAL;
+    }
+  if (pcount != NULL)
+    {
+      *pcount = entry->fields_count;
+    }
+  return status;
+}
+
+int
+mu_mailcap_entry_get_field (mu_mailcap_entry_t entry, size_t no,
+                           char *buffer, size_t buflen, size_t *pn)
+{
+  int status = 0;
+  int len = 0;
+
+  if (entry == NULL)
+    {
+      status = EINVAL;
+    }
+  else if ( no == 0 || no > entry->fields_count)
+    {
+      status = MU_ERR_NOENT;
+    }
+  else
+    {
+      len = strlen(entry->fields[no - 1]);
+      if (buffer != NULL && buflen > 0)
+       {
+         buflen--;
+         len = (len < buflen) ? len : buflen;
+         memcpy (buffer, entry->fields[no - 1], len);
+         buffer[len] = '\0';
+       }
+    }
+  if (pn)
+    {
+      *pn = len;
+    }
+  return status;
+}
+
+int
+mu_mailcap_entry_get_compose (mu_mailcap_entry_t entry,
+                             char *buffer, size_t buflen, size_t *pn)
+{
+  return mu_mailcap_entry_get_value (entry, "compose", buffer, buflen, pn);
+}
+
+int
+mu_mailcap_entry_get_composetyped (mu_mailcap_entry_t entry, char *buffer,
+                                  size_t buflen, size_t *pn)
+{
+  return mu_mailcap_entry_get_value (entry, "composetyped", buffer, buflen, 
pn);
+}
+
+int
+mu_mailcap_entry_get_edit (mu_mailcap_entry_t entry, char *buffer,
+                          size_t buflen, size_t *pn)
+{
+  return mu_mailcap_entry_get_value (entry, "edit", buffer, buflen, pn);
+}
+
+int
+mu_mailcap_entry_get_test (mu_mailcap_entry_t entry,
+                          char *buffer, size_t buflen, size_t *pn)
+{
+  return mu_mailcap_entry_get_value (entry, "test", buffer, buflen, pn);
+}
+
+int
+mu_mailcap_entry_get_x11bitmap (mu_mailcap_entry_t entry,
+                               char *buffer, size_t buflen, size_t *pn)
+{
+  return mu_mailcap_entry_get_value (entry, "x11-bitmap", buffer, buflen, pn);
+}
+
+int
+mu_mailcap_entry_get_description (mu_mailcap_entry_t entry,
+                                 char *buffer, size_t buflen, size_t *pn)
+{
+  return mu_mailcap_entry_get_value (entry, "description", buffer, buflen, pn);
+}
+
+int
+mu_mailcap_entry_needsterminal (mu_mailcap_entry_t entry, int *on)
+{
+  int status = 0;
+  int found = 0;
+  if (entry == NULL)
+    {
+      status = EINVAL;
+    }
+  else
+    {
+      int i;
+      for (i = 0; i < entry->fields_count; i++)
+       {
+         int n = mu_c_strcasecmp (entry->fields[i], "needsterminal");
+         if (n == 0)
+           {
+             found = 1;
+             break;
+           }
+       }
+    }
+  if (on)
+    *on = found;
+  return status;
+}
+
+int
+mu_mailcap_entry_copiousoutput (mu_mailcap_entry_t entry, int *on)
+{
+  int status = 0;
+  int found = 0;
+  if (entry == NULL)
+    {
+      status = EINVAL;
+    }
+  else
+    {
+      int i;
+      for (i = 0; i < entry->fields_count; i++)
+       {
+         int n = mu_c_strcasecmp (entry->fields[i], "copiousoutput");
+         if (n == 0)
+           {
+             found = 1;
+             break;
+           }
+       }
+    }
+  if (on)
+    *on = found;
+  return status;
+}
+
+int
+mu_mailcap_entry_get_value (mu_mailcap_entry_t entry, const char *key,
+                           char *buffer, size_t buflen, size_t *pn)
+{
+  int len = 0;
+  int status = ENOENT;
+
+  if (!entry)
+    status = EINVAL;
+  else
+    {
+      int i;
+      int key_len = strlen (key);
+      for (i = 0; i < entry->fields_count; i++)
+       {
+         int n = mu_c_strncasecmp (entry->fields[i], key, key_len);
+         if (n == 0)
+           {
+             int field_len = strlen(entry->fields[i]);
+             status = 0;
+             if (field_len > key_len)
+               {
+                 int c = entry->fields[i][key_len];
+                 if (mu_isspace (c) || c == '=')
+                   {
+                     char *value = strchr (entry->fields[i], '=');
+                     if (value != NULL)
+                       {
+                         value++; /* Pass the equal.  */
+                         /* Remove leading space.  */
+                         for (; mu_isspace (*value); value++)
+                           ;
+                         len = strlen (value);
+                         /* Strip surrounding double quotes */
+                         if (len > 1 && value[0] == '"' && value[len - 1] == 
'"')
+                           {
+                             value++;
+                             len -= 2;
+                           }
+                         if (buffer != NULL && buflen > 0)
+                           {
+                             buflen--;
+                             len = (len < buflen) ? len : buflen;
+                             memcpy (buffer, value, len);
+                             buffer[len] = '\0';
+                           }
+                         break;
+                       }
+                   }
+               }
+           }
+       }
+    }
+  if (pn)
+    *pn = len;
+  return status;
+}
+
+/*
+ * break the line on ';'.  Same as strtok() but
+ * check for escaped "\;"
+ */
+static char *
+tokenize (char *s, char **save_ptr)
+{
+  int c;
+  char *token;
+
+  if (s == NULL)
+    {
+      s = *save_ptr;
+    }
+
+  if (*s == '\0')
+    {
+      *save_ptr = s;
+      return NULL;
+    }
+
+  for (token = s, c = 0; *s; s++)
+    {
+      if (*s == ';' && c != '\\')
+       {
+         break;
+       }
+      c = *s;
+    }
+
+  if (*s == '\0')
+    {
+      *save_ptr = s;
+    }
+  else
+    {
+      *s = '\0';
+      *save_ptr = s + 1;
+    }
+  return token;
+}
+
+/**
+ * parse the mailcap line, fields are separated by ';'
+ */
+static int
+mu_mailcap_parse_entry (mu_mailcap_entry_t entry, char *buffer)
+{
+  char *token = NULL;
+  char *s = NULL;
+  int i;
+  for (i = 0, token = tokenize (buffer, &s);
+       token != NULL; token = tokenize (NULL, &s), i++)
+    {
+      switch (i)
+       {
+         /* The first entry in a mailcap line is the typefield.  */
+       case 0:
+         entry->typefield = strdup (mu_str_stripws (token));
+         break;
+
+         /* The second entry in a mailcap line is the view-command.  */
+       case 1:
+         entry->viewcommand = strdup (mu_str_stripws (token));
+         break;
+
+         /* The rest are the optional fields.  */
+       default:
+         {
+           char **fields = realloc (entry->fields,
+                                    (entry->fields_count + 1) *
+                                    sizeof (*fields));
+           if (fields != NULL)
+             {
+               entry->fields = fields;
+               entry->fields[entry->fields_count] =
+                 strdup (mu_str_stripws (token));
+               entry->fields_count++;
+             }
+         }
+       }
+    }
+  /* Make sure typefield and viewcommand are not null.  */
+  if (entry->typefield == NULL)
+    {
+      entry->typefield = strdup ("");
+    }
+  if (entry->viewcommand == NULL)
+    {
+      entry->viewcommand = strdup ("");
+    }
+  return 0;
+}
+
+/*
+ * parse a mailcap file or stream,
+ * - ignore empty line.
+ * - ignore line starting with '#'
+ * - multiline is done with the '\' as continuation
+ * example:
+# comment
+application/pgp; gpg < %s | metamail; needsterminal; \
+ test=test %{encapsulation}=entity ; copiousoutput
+ */
+static int
+mu_mailcap_parse (mu_mailcap_t mailcap, mu_stream_t stream)
+{
+  int status;
+  size_t n;
+  char *previous;
+  char *buffer;
+  size_t buflen = 512;
+
+  buffer = malloc (buflen);
+  if (buffer == NULL)
+    {
+      return ENOMEM;
+    }
+
+  /*
+   * We are doing this a little more complex then expected, because we do not
+   * want to seek() back in the stream:
+   * - we have to take care of continuation line i.e. line ending with '\'
+   * - we have to take to account that the line may be bigger then the buffer
+   *   and reallocate
+   * - check the return of malloc/realloc
+   * The old continuation line is saved in the "previous" pointer and
+   * prepended to the buffer.
+   */
+  status = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
+  if (status)
+    return status;
+  previous = NULL;
+  while ((status = mu_stream_readline (stream, buffer, buflen, &n)) == 0
+        && n > 0)
+    {
+      int len;
+
+      /* If there is no trailing newline, that means the buffer was too small,
+       * make room for the buffer and continue reading  */
+      if (buffer[n - 1] != '\n')
+        {
+         char *b = realloc (buffer, buflen * sizeof (*buffer));
+          buflen *= 2;
+          if (b == NULL)
+           {
+             status = ENOMEM;
+             break;
+           }
+         buffer = b;
+         /*
+          * Fake this as a continuation line, for simplicity.
+          */
+         strcat (buffer, "\\");
+        }
+      else
+       {
+         /* Nuke the trailing newline.  */
+         buffer[n - 1] = '\0';
+       }
+
+      /* recalculate the len.  */
+      len = strlen (buffer);
+
+      /* Ending with a '\' means continuation line.  */
+      if (len && buffer[len - 1] == '\\')
+       {
+         buffer[len - 1] = '\0';
+         /*
+          * Check for any previous line:
+          * - if yes append the buffer to the previous line.
+          * - if not set the buffer as the previous line and continue.
+          */
+         if (previous == NULL)
+           {
+             previous = strdup (buffer);
+             if (previous == NULL)
+               {
+                 status = ENOMEM;
+                 break;
+               }
+           }
+         else
+           {
+             char *b = realloc (previous, strlen (previous) + len + 1);
+             if (b == NULL)
+               {
+                 status = ENOMEM;
+                 break;
+               }
+             previous = b;
+             strcat(previous, buffer);
+           }
+       }
+      else
+       {
+         /* Did we have a previous incomplete line?
+          * if yes make one line from the previous and the buffer.
+          */
+         if (previous != NULL)
+           {
+             int prev_len = strlen (previous);
+             int total =  prev_len + len + 1;
+             if (total > buflen)
+               {
+                 char *b = realloc (buffer, total * sizeof (*buffer));
+                 if (b == NULL)
+                   {
+                     status = ENOMEM;
+                     break;
+                   }
+                 buffer = b;
+                 buflen = total;
+               }
+             memmove (buffer + prev_len, buffer, len + 1);
+             memcpy (buffer, previous, prev_len);
+             free (previous);
+             previous = NULL;
+           }
+       }
+
+      /* Parse the well-form mailcap line entry.  */
+      if (previous == NULL) {
+       /* Nuke the trailing/prepend spaces.  */
+       char *line = mu_str_stripws (buffer);
+       /* Ignore comments or empty lines  */
+       if (*line != '#' && *line != '\0')
+         {
+           mu_mailcap_entry_t *entries;
+           entries = realloc (mailcap->entries,
+                              (mailcap->entries_count + 1) *
+                              sizeof (*entries));
+           if (entries != NULL)
+             {
+               mailcap->entries = entries;
+               mailcap->entries[mailcap->entries_count] = calloc (1,
+                                                          sizeof(**entries));
+               if (mailcap->entries[mailcap->entries_count] != NULL)
+                 {
+                   mu_mailcap_parse_entry 
(mailcap->entries[mailcap->entries_count], line);
+                 }
+               mailcap->entries_count++;
+             }
+           else
+             {
+               status = ENOMEM;
+               break;
+             }
+         }
+      }
+    }
+
+  if (buffer != NULL)
+    {
+      free (buffer);
+    }
+  if (previous != NULL)
+    {
+      free (previous);
+    }
+  return status;
+}
+
+#ifdef STANDALONE_TEST
+int main()
+{
+  mu_stream_t stream = NULL;
+  int status = 0;
+
+  status = mu_file_stream_create (&stream, "/home/alain/mailcap",
+                                 MU_STREAM_READ);
+  if (status == 0)
+    {
+      mu_mailcap_t mailcap;
+      status = mu_mailcap_create (&mailcap, stream);
+      if (status == 0)
+       {
+         int i, n;
+         size_t count = 0;
+         char buffer[256];
+         
+         mu_mailcap_entries_count (mailcap, &count);
+         for (i = 1; i <= count; i++)
+           {
+             int j;
+             mu_mailcap_entry_t entry = NULL;
+             int fields_count = 0;
+             
+             printf ("entry[%d]\n", i);
+#if 1
+             
+             mu_mailcap_get_entry (mailcap, i, &entry);
+             /* Print typefield.  */
+             mu_mailcap_entry_get_typefield (entry, buffer,
+                                             sizeof (buffer), NULL);
+             printf ("\ttypefield: %s\n", buffer);
+             
+             /* Print view-command.  */
+             mu_mailcap_entry_get_viewcommand (entry, buffer,
+                                               sizeof (buffer), NULL);
+             printf ("\tview-command: %s\n", buffer);
+             
+             /* Print fields.  */
+             mu_mailcap_entry_fields_count (entry, &fields_count);
+             for (j = 1; j <= fields_count; j++)
+               {
+                 mu_mailcap_entry_get_field (entry, j, buffer,
+                                             sizeof (buffer), NULL);
+                 printf("\tfields[%d]: %s\n", j, buffer);
+               }
+             n = 0;
+             mu_mailcap_entry_get_compose (entry, buffer,
+                                           sizeof (buffer), &n);
+             if (n > 0)
+               {
+                 printf("\tcompose[%s]\n", buffer);
+               }
+             printf("\n");
+           }
+#else
+         for (i = 0; i < mailcap->entries_count; i++)
+           {
+             int j;
+             mu_mailcap_entry_t entry = mailcap->entries[i];
+             printf("[%s];[%s]", entry->typefield, entry->viewcommand);
+             for (j = 0; j < entry->fields_count; j++)
+               {
+                 printf(";[%s]", entry->fields[j]);
+               }
+             printf("\n");
+           }
+#endif
+         mu_mailcap_destroy (&mailcap);
+       }
+    }
+  return 0;
+}
+
+#endif
diff --git a/libmailutils/base/md5.c b/libmailutils/base/md5.c
new file mode 100644
index 0000000..c46ae79
--- /dev/null
+++ b/libmailutils/base/md5.c
@@ -0,0 +1,453 @@
+/* Functions to compute MD5 message digest of files or memory blocks.
+   according to the definition of MD5 in RFC 1321 from April 1992.
+   Copyright (C) 1995,1996,1997,1999,2000,2001,2005,2006,2010
+       Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by the
+   Free Software Foundation; either version 2, or (at your option) any
+   later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Ulrich Drepper <address@hidden>, 1995.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "mailutils/md5.h"
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+
+#if USE_UNLOCKED_IO
+# include "unlocked-io.h"
+#endif
+
+#ifdef _LIBC
+# include <endian.h>
+# if __BYTE_ORDER == __BIG_ENDIAN
+#  define WORDS_BIGENDIAN 1
+# endif
+#endif
+
+/* We need to keep the namespace clean so define the MD5 function
+   protected using leading __ .  */
+# define md5_init_ctx __md5_init_ctx
+# define md5_process_block __md5_process_block
+# define md5_process_bytes __md5_process_bytes
+# define md5_finish_ctx __md5_finish_ctx
+# define md5_read_ctx __md5_read_ctx
+# define md5_stream __md5_stream
+# define md5_buffer __md5_buffer
+
+#ifdef WORDS_BIGENDIAN
+# define SWAP(n)                                                       \
+    (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
+#else
+# define SWAP(n) (n)
+#endif
+
+#define BLOCKSIZE 4096
+#if BLOCKSIZE % 64 != 0
+# error "invalid BLOCKSIZE"
+#endif
+
+/* This array contains the bytes used to pad the buffer to the next
+   64-byte boundary.  (RFC 1321, 3.1: Step 1)  */
+static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ...  */ };
+
+
+/* Initialize structure containing state of computation.
+   (RFC 1321, 3.3: Step 3)  */
+void
+md5_init_ctx (struct md5_ctx *ctx)
+{
+  ctx->A = 0x67452301;
+  ctx->B = 0xefcdab89;
+  ctx->C = 0x98badcfe;
+  ctx->D = 0x10325476;
+
+  ctx->total[0] = ctx->total[1] = 0;
+  ctx->buflen = 0;
+}
+
+/* Put result from CTX in first 16 bytes following RESBUF.  The result
+   must be in little endian byte order.
+
+   IMPORTANT: On some systems it is required that RESBUF is correctly
+   aligned for a 32-bit value.  */
+void *
+md5_read_ctx (const struct md5_ctx *ctx, void *resbuf)
+{
+  ((uint32_t *) resbuf)[0] = SWAP (ctx->A);
+  ((uint32_t *) resbuf)[1] = SWAP (ctx->B);
+  ((uint32_t *) resbuf)[2] = SWAP (ctx->C);
+  ((uint32_t *) resbuf)[3] = SWAP (ctx->D);
+
+  return resbuf;
+}
+
+/* Process the remaining bytes in the internal buffer and the usual
+   prolog according to the standard and write the result to RESBUF.
+
+   IMPORTANT: On some systems it is required that RESBUF is correctly
+   aligned for a 32-bit value.  */
+void *
+md5_finish_ctx (struct md5_ctx *ctx, void *resbuf)
+{
+  /* Take yet unprocessed bytes into account.  */
+  uint32_t bytes = ctx->buflen;
+  size_t size = (bytes < 56) ? 64 / 4 : 64 * 2 / 4;
+
+  /* Now count remaining bytes.  */
+  ctx->total[0] += bytes;
+  if (ctx->total[0] < bytes)
+    ++ctx->total[1];
+
+  /* Put the 64-bit file length in *bits* at the end of the buffer.  */
+  ctx->buffer[size - 2] = SWAP (ctx->total[0] << 3);
+  ctx->buffer[size - 1] = SWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29));
+
+  memcpy (&((char *) ctx->buffer)[bytes], fillbuf, (size - 2) * 4 - bytes);
+
+  /* Process last bytes.  */
+  md5_process_block (ctx->buffer, size * 4, ctx);
+
+  return md5_read_ctx (ctx, resbuf);
+}
+
+/* Compute MD5 message digest for bytes read from STREAM.  The
+   resulting message digest number will be written into the 16 bytes
+   beginning at RESBLOCK.  */
+int
+md5_stream (FILE *stream, void *resblock)
+{
+  struct md5_ctx ctx;
+  char buffer[BLOCKSIZE + 72];
+  size_t sum;
+
+  /* Initialize the computation context.  */
+  md5_init_ctx (&ctx);
+
+  /* Iterate over full file contents.  */
+  while (1)
+    {
+      /* We read the file in blocks of BLOCKSIZE bytes.  One call of the
+         computation function processes the whole buffer so that with the
+         next round of the loop another block can be read.  */
+      size_t n;
+      sum = 0;
+
+      /* Read block.  Take care for partial reads.  */
+      while (1)
+       {
+         n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
+
+         sum += n;
+
+         if (sum == BLOCKSIZE)
+           break;
+
+         if (n == 0)
+           {
+             /* Check for the error flag IFF N == 0, so that we don't
+                exit the loop after a partial read due to e.g., EAGAIN
+                or EWOULDBLOCK.  */
+             if (ferror (stream))
+               return 1;
+             goto process_partial_block;
+           }
+
+         /* We've read at least one byte, so ignore errors.  But always
+            check for EOF, since feof may be true even though N > 0.
+            Otherwise, we could end up calling fread after EOF.  */
+         if (feof (stream))
+           goto process_partial_block;
+       }
+
+      /* Process buffer with BLOCKSIZE bytes.  Note that
+         BLOCKSIZE % 64 == 0
+       */
+      md5_process_block (buffer, BLOCKSIZE, &ctx);
+    }
+
+process_partial_block:
+
+  /* Process any remaining bytes.  */
+  if (sum > 0)
+    md5_process_bytes (buffer, sum, &ctx);
+
+  /* Construct result in desired memory.  */
+  md5_finish_ctx (&ctx, resblock);
+  return 0;
+}
+
+/* Compute MD5 message digest for LEN bytes beginning at BUFFER.  The
+   result is always in little endian byte order, so that a byte-wise
+   output yields to the wanted ASCII representation of the message
+   digest.  */
+void *
+md5_buffer (const char *buffer, size_t len, void *resblock)
+{
+  struct md5_ctx ctx;
+
+  /* Initialize the computation context.  */
+  md5_init_ctx (&ctx);
+
+  /* Process whole buffer but last len % 64 bytes.  */
+  md5_process_bytes (buffer, len, &ctx);
+
+  /* Put result in desired memory area.  */
+  return md5_finish_ctx (&ctx, resblock);
+}
+
+
+void
+md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx)
+{
+  /* When we already have some bits in our internal buffer concatenate
+     both inputs first.  */
+  if (ctx->buflen != 0)
+    {
+      size_t left_over = ctx->buflen;
+      size_t add = 128 - left_over > len ? len : 128 - left_over;
+
+      memcpy (&((char *) ctx->buffer)[left_over], buffer, add);
+      ctx->buflen += add;
+
+      if (ctx->buflen > 64)
+       {
+         md5_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
+
+         ctx->buflen &= 63;
+         /* The regions in the following copy operation cannot overlap.  */
+         memcpy (ctx->buffer,
+                 &((char *) ctx->buffer)[(left_over + add) & ~63],
+                 ctx->buflen);
+       }
+
+      buffer = (const char *) buffer + add;
+      len -= add;
+    }
+
+  /* Process available complete blocks.  */
+  if (len >= 64)
+    {
+#if !_STRING_ARCH_unaligned
+# define alignof(type) offsetof (struct { char c; type x; }, x)
+# define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0)
+      if (UNALIGNED_P (buffer))
+       while (len > 64)
+         {
+           md5_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx);
+           buffer = (const char *) buffer + 64;
+           len -= 64;
+         }
+      else
+#endif
+       {
+         md5_process_block (buffer, len & ~63, ctx);
+         buffer = (const char *) buffer + (len & ~63);
+         len &= 63;
+       }
+    }
+
+  /* Move remaining bytes in internal buffer.  */
+  if (len > 0)
+    {
+      size_t left_over = ctx->buflen;
+
+      memcpy (&((char *) ctx->buffer)[left_over], buffer, len);
+      left_over += len;
+      if (left_over >= 64)
+       {
+         md5_process_block (ctx->buffer, 64, ctx);
+         left_over -= 64;
+         memcpy (ctx->buffer, &ctx->buffer[16], left_over);
+       }
+      ctx->buflen = left_over;
+    }
+}
+
+
+/* These are the four functions used in the four steps of the MD5 algorithm
+   and defined in the RFC 1321.  The first function is a little bit optimized
+   (as found in Colin Plumbs public domain implementation).  */
+/* #define FF(b, c, d) ((b & c) | (~b & d)) */
+#define FF(b, c, d) (d ^ (b & (c ^ d)))
+#define FG(b, c, d) FF (d, b, c)
+#define FH(b, c, d) (b ^ c ^ d)
+#define FI(b, c, d) (c ^ (b | ~d))
+
+/* Process LEN bytes of BUFFER, accumulating context into CTX.
+   It is assumed that LEN % 64 == 0.  */
+
+void
+md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx)
+{
+  uint32_t correct_words[16];
+  const uint32_t *words = buffer;
+  size_t nwords = len / sizeof (uint32_t);
+  const uint32_t *endp = words + nwords;
+  uint32_t A = ctx->A;
+  uint32_t B = ctx->B;
+  uint32_t C = ctx->C;
+  uint32_t D = ctx->D;
+
+  /* First increment the byte count.  RFC 1321 specifies the possible
+     length of the file up to 2^64 bits.  Here we only compute the
+     number of bytes.  Do a double word increment.  */
+  ctx->total[0] += len;
+  if (ctx->total[0] < len)
+    ++ctx->total[1];
+
+  /* Process all bytes in the buffer with 64 bytes in each round of
+     the loop.  */
+  while (words < endp)
+    {
+      uint32_t *cwp = correct_words;
+      uint32_t A_save = A;
+      uint32_t B_save = B;
+      uint32_t C_save = C;
+      uint32_t D_save = D;
+
+      /* First round: using the given function, the context and a constant
+         the next context is computed.  Because the algorithms processing
+         unit is a 32-bit word and it is determined to work on words in
+         little endian byte order we perhaps have to change the byte order
+         before the computation.  To reduce the work for the next steps
+         we store the swapped words in the array CORRECT_WORDS.  */
+
+#define OP(a, b, c, d, s, T)                                           \
+      do                                                               \
+        {                                                              \
+         a += FF (b, c, d) + (*cwp++ = SWAP (*words)) + T;             \
+         ++words;                                                      \
+         CYCLIC (a, s);                                                \
+         a += b;                                                       \
+        }                                                              \
+      while (0)
+
+      /* It is unfortunate that C does not provide an operator for
+         cyclic rotation.  Hope the C compiler is smart enough.  */
+#define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s)))
+
+      /* Before we start, one word to the strange constants.
+         They are defined in RFC 1321 as
+
+         T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64
+
+         Here is an equivalent invocation using Perl:
+
+         perl -e 'foreach(1..64){printf "0x%08x\n", int (4294967296 * abs (sin 
$_))}'
+       */
+
+      /* Round 1.  */
+      OP (A, B, C, D, 7, 0xd76aa478);
+      OP (D, A, B, C, 12, 0xe8c7b756);
+      OP (C, D, A, B, 17, 0x242070db);
+      OP (B, C, D, A, 22, 0xc1bdceee);
+      OP (A, B, C, D, 7, 0xf57c0faf);
+      OP (D, A, B, C, 12, 0x4787c62a);
+      OP (C, D, A, B, 17, 0xa8304613);
+      OP (B, C, D, A, 22, 0xfd469501);
+      OP (A, B, C, D, 7, 0x698098d8);
+      OP (D, A, B, C, 12, 0x8b44f7af);
+      OP (C, D, A, B, 17, 0xffff5bb1);
+      OP (B, C, D, A, 22, 0x895cd7be);
+      OP (A, B, C, D, 7, 0x6b901122);
+      OP (D, A, B, C, 12, 0xfd987193);
+      OP (C, D, A, B, 17, 0xa679438e);
+      OP (B, C, D, A, 22, 0x49b40821);
+
+      /* For the second to fourth round we have the possibly swapped words
+         in CORRECT_WORDS.  Redefine the macro to take an additional first
+         argument specifying the function to use.  */
+#undef OP
+#define OP(f, a, b, c, d, k, s, T)                                     \
+      do                                                               \
+       {                                                               \
+         a += f (b, c, d) + correct_words[k] + T;                      \
+         CYCLIC (a, s);                                                \
+         a += b;                                                       \
+       }                                                               \
+      while (0)
+
+      /* Round 2.  */
+      OP (FG, A, B, C, D, 1, 5, 0xf61e2562);
+      OP (FG, D, A, B, C, 6, 9, 0xc040b340);
+      OP (FG, C, D, A, B, 11, 14, 0x265e5a51);
+      OP (FG, B, C, D, A, 0, 20, 0xe9b6c7aa);
+      OP (FG, A, B, C, D, 5, 5, 0xd62f105d);
+      OP (FG, D, A, B, C, 10, 9, 0x02441453);
+      OP (FG, C, D, A, B, 15, 14, 0xd8a1e681);
+      OP (FG, B, C, D, A, 4, 20, 0xe7d3fbc8);
+      OP (FG, A, B, C, D, 9, 5, 0x21e1cde6);
+      OP (FG, D, A, B, C, 14, 9, 0xc33707d6);
+      OP (FG, C, D, A, B, 3, 14, 0xf4d50d87);
+      OP (FG, B, C, D, A, 8, 20, 0x455a14ed);
+      OP (FG, A, B, C, D, 13, 5, 0xa9e3e905);
+      OP (FG, D, A, B, C, 2, 9, 0xfcefa3f8);
+      OP (FG, C, D, A, B, 7, 14, 0x676f02d9);
+      OP (FG, B, C, D, A, 12, 20, 0x8d2a4c8a);
+
+      /* Round 3.  */
+      OP (FH, A, B, C, D, 5, 4, 0xfffa3942);
+      OP (FH, D, A, B, C, 8, 11, 0x8771f681);
+      OP (FH, C, D, A, B, 11, 16, 0x6d9d6122);
+      OP (FH, B, C, D, A, 14, 23, 0xfde5380c);
+      OP (FH, A, B, C, D, 1, 4, 0xa4beea44);
+      OP (FH, D, A, B, C, 4, 11, 0x4bdecfa9);
+      OP (FH, C, D, A, B, 7, 16, 0xf6bb4b60);
+      OP (FH, B, C, D, A, 10, 23, 0xbebfbc70);
+      OP (FH, A, B, C, D, 13, 4, 0x289b7ec6);
+      OP (FH, D, A, B, C, 0, 11, 0xeaa127fa);
+      OP (FH, C, D, A, B, 3, 16, 0xd4ef3085);
+      OP (FH, B, C, D, A, 6, 23, 0x04881d05);
+      OP (FH, A, B, C, D, 9, 4, 0xd9d4d039);
+      OP (FH, D, A, B, C, 12, 11, 0xe6db99e5);
+      OP (FH, C, D, A, B, 15, 16, 0x1fa27cf8);
+      OP (FH, B, C, D, A, 2, 23, 0xc4ac5665);
+
+      /* Round 4.  */
+      OP (FI, A, B, C, D, 0, 6, 0xf4292244);
+      OP (FI, D, A, B, C, 7, 10, 0x432aff97);
+      OP (FI, C, D, A, B, 14, 15, 0xab9423a7);
+      OP (FI, B, C, D, A, 5, 21, 0xfc93a039);
+      OP (FI, A, B, C, D, 12, 6, 0x655b59c3);
+      OP (FI, D, A, B, C, 3, 10, 0x8f0ccc92);
+      OP (FI, C, D, A, B, 10, 15, 0xffeff47d);
+      OP (FI, B, C, D, A, 1, 21, 0x85845dd1);
+      OP (FI, A, B, C, D, 8, 6, 0x6fa87e4f);
+      OP (FI, D, A, B, C, 15, 10, 0xfe2ce6e0);
+      OP (FI, C, D, A, B, 6, 15, 0xa3014314);
+      OP (FI, B, C, D, A, 13, 21, 0x4e0811a1);
+      OP (FI, A, B, C, D, 4, 6, 0xf7537e82);
+      OP (FI, D, A, B, C, 11, 10, 0xbd3af235);
+      OP (FI, C, D, A, B, 2, 15, 0x2ad7d2bb);
+      OP (FI, B, C, D, A, 9, 21, 0xeb86d391);
+
+      /* Add the starting values of the context.  */
+      A += A_save;
+      B += B_save;
+      C += C_save;
+      D += D_save;
+    }
+
+  /* Put checksum in context given as argument.  */
+  ctx->A = A;
+  ctx->B = B;
+  ctx->C = C;
+  ctx->D = D;
+}
diff --git a/libmailutils/base/monitor.c b/libmailutils/base/monitor.c
new file mode 100644
index 0000000..f9b1593
--- /dev/null
+++ b/libmailutils/base/monitor.c
@@ -0,0 +1,281 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2007, 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/>. */
+
+/* Tell GLIBC that we want UNIX98 pthread_rwlock_xx() functions.  */
+#define _XOPEN_SOURCE   500
+/* Tell QNX/Neutrino to define pthread_rwlock_xx() functions.  */
+#define _QNX_SOURCE
+#define _POSIX_C_SOURCE 199506
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#ifdef WITH_PTHREAD
+#  ifdef HAVE_PTHREAD_H
+#    include <pthread.h>
+#  endif
+#endif
+#include <errno.h>
+#include <stdlib.h>
+
+#include <mailutils/sys/monitor.h>
+#include <mailutils/errno.h>
+
+#ifdef WITH_PTHREAD
+pthread_mutex_t monitor_lock = PTHREAD_MUTEX_INITIALIZER;
+#  define STATIC_LOCK(m) pthread_mutex_lock(m)
+#  define STATIC_UNLOCK(m) pthread_mutex_unlock(m)
+#else
+#  define STATIC_LOCK(m) 0
+#  define STATIC_UNLOCK(m)
+int monitor_lock;
+#endif
+
+union _p_lock
+{
+#ifdef WITH_PTHREAD
+#  ifdef HAVE_PTHREAD_RWLOCK_INIT
+     pthread_rwlock_t mutex;
+#  else
+     pthread_mutex_t mutex;
+#  endif
+#else
+  int dummy;
+#endif
+};
+
+typedef union _p_lock *p_lock_t;
+static int  monitor_pthread_create (p_lock_t *);
+static void monitor_pthread_destroy (p_lock_t *);
+static int monitor_pthread_rdlock (p_lock_t);
+static int monitor_pthread_wrlock (p_lock_t);
+static int monitor_pthread_unlock (p_lock_t);
+
+/* The idea was to have a general/portable object mu_monitor_t.
+   The mu_monitor_t object could have different implementation (on the fly ?)
+   of locking.  Also the rest of the library would not have to know about
+   different threading implementation.  So far we've pretty much hardcoded
+   the concrete implementation of monitor on pthread and read/write locks,
+   but changing to a different concrete implementation will not be hard if
+   the need arise.
+   For static initializers we take a small penality and since we have
+   a global static lock.
+ */
+
+int
+mu_monitor_create (mu_monitor_t *pmonitor, int flags, void *owner)
+{
+  mu_monitor_t monitor;
+
+  if (pmonitor == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+
+  monitor = calloc (1, sizeof (*monitor));
+  if (monitor == NULL)
+    return ENOMEM;
+
+  if (flags == MU_MONITOR_PTHREAD)
+    {
+      int status = monitor_pthread_create ((p_lock_t *)&(monitor->data));
+      if (status != 0)
+       {
+         free (monitor);
+         return status;
+       }
+    }
+  monitor->owner = owner;
+  monitor->allocated = 1;
+  monitor->flags = flags;
+  *pmonitor = monitor;
+  return 0;
+}
+
+void *
+mu_monitor_get_owner (mu_monitor_t monitor)
+{
+  return (monitor == NULL) ? NULL : monitor->owner;
+}
+
+void
+mu_monitor_destroy (mu_monitor_t *pmonitor, void *owner)
+{
+  if (pmonitor && *pmonitor)
+    {
+      mu_monitor_t monitor = *pmonitor;
+      if (monitor->owner == owner)
+       {
+         if (monitor->flags == MU_MONITOR_PTHREAD)
+           monitor_pthread_destroy ((p_lock_t *)&(monitor->data));
+       }
+      free (monitor);
+      *pmonitor = NULL;
+    }
+}
+
+int
+mu_monitor_rdlock (mu_monitor_t monitor)
+{
+  if (monitor)
+    {
+      if (!monitor->allocated)
+       {
+         int status = STATIC_LOCK (&monitor_lock);
+         if (monitor->data == NULL)
+           {
+             if (monitor->flags == MU_MONITOR_PTHREAD)
+               status = monitor_pthread_create ((p_lock_t*)&(monitor->data));
+             if (status != 0)
+               {
+                 STATIC_UNLOCK (&monitor_lock);
+                 return status;
+               }
+           }
+         monitor->allocated = 1;
+         STATIC_UNLOCK (&monitor_lock);
+       }
+      if (monitor->flags == MU_MONITOR_PTHREAD)
+       return monitor_pthread_rdlock ((p_lock_t)monitor->data);
+    }
+  return 0;
+}
+
+int
+mu_monitor_wrlock  (mu_monitor_t monitor)
+{
+  if (monitor)
+    {
+      if (!monitor->allocated)
+       {
+         int status = STATIC_LOCK (&monitor_lock);
+         if (monitor->data == NULL)
+           {
+             if (monitor->flags == MU_MONITOR_PTHREAD)
+               status = monitor_pthread_create ((p_lock_t *)&(monitor->data));
+             if (status != 0)
+               {
+                 STATIC_UNLOCK (&monitor_lock);
+                 return status;
+               }
+           }
+         monitor->allocated = 1;
+         STATIC_UNLOCK (&monitor_lock);
+       }
+      if (monitor->flags == MU_MONITOR_PTHREAD)
+       return monitor_pthread_wrlock ((p_lock_t)monitor->data);
+    }
+  return 0;
+}
+
+int
+mu_monitor_unlock (mu_monitor_t monitor)
+{
+  if (monitor)
+    {
+      if (monitor->flags == MU_MONITOR_PTHREAD)
+       return monitor_pthread_unlock ((p_lock_t)monitor->data);
+    }
+  return 0;
+}
+
+int
+mu_monitor_wait (mu_monitor_t monitor MU_ARG_UNUSED)
+{
+  return ENOSYS;
+}
+
+int
+mu_monitor_notify (mu_monitor_t monitor MU_ARG_UNUSED)
+{
+  return ENOSYS;
+}
+
+
+/* Concrete Implementation of pthread base on rwlocks.  */
+
+#ifdef WITH_PTHREAD
+#  ifdef HAVE_PTHREAD_RWLOCK_INIT
+#    define RWLOCK_INIT(rwl, attr)  pthread_rwlock_init (rwl, attr)
+#    define RWLOCK_DESTROY(rwl)     pthread_rwlock_destroy (rwl)
+#    define RWLOCK_RDLOCK(rwl)      pthread_rwlock_rdlock (rwl)
+#    define RWLOCK_WRLOCK(rwl)      pthread_rwlock_wrlock (rwl)
+#    define RWLOCK_UNLOCK(rwl)      pthread_rwlock_unlock (rwl)
+#  else
+#    define RWLOCK_INIT(rwl, attr)  pthread_mutex_init (rwl, attr)
+#    define RWLOCK_DESTROY(rwl)     pthread_mutex_destroy (rwl)
+#    define RWLOCK_RDLOCK(rwl)      pthread_mutex_lock (rwl)
+#    define RWLOCK_WRLOCK(rwl)      pthread_mutex_lock (rwl)
+#    define RWLOCK_UNLOCK(rwl)      pthread_mutex_unlock (rwl)
+#  endif
+#else
+#  define RWLOCK_INIT(rwl, attr)    0
+#  define RWLOCK_DESTROY(rwl)
+#  define RWLOCK_RDLOCK(rwl)        0
+#  define RWLOCK_WRLOCK(rwl)        0
+#  define RWLOCK_UNLOCK(rwl)        0
+#  define flockfile(arg)
+#  define funlockfile(arg)
+#endif
+
+
+
+static int
+monitor_pthread_create (p_lock_t *plock)
+{
+  int status;
+  p_lock_t lock = calloc (1, sizeof (*lock));
+  if (lock == NULL)
+    return ENOMEM;
+  status = RWLOCK_INIT (&(lock->mutex), NULL);
+  if (status != 0)
+    {
+      free (lock);
+      return status;
+    }
+  *plock = lock;
+  return 0;
+}
+
+static void
+monitor_pthread_destroy (p_lock_t *plock)
+{
+  p_lock_t lock = *plock;
+  if (lock)
+    {
+      RWLOCK_DESTROY (&(lock->mutex));
+      free (lock);
+    }
+  *plock = NULL;
+}
+
+static int
+monitor_pthread_rdlock (p_lock_t lock)
+{
+  return RWLOCK_RDLOCK (&(lock->mutex));
+}
+
+static int
+monitor_pthread_wrlock (p_lock_t lock)
+{
+  return RWLOCK_WRLOCK (&(lock->mutex));
+}
+
+static int
+monitor_pthread_unlock (p_lock_t lock)
+{
+  return RWLOCK_UNLOCK (&(lock->mutex));
+}
diff --git a/libmailutils/base/munre.c b/libmailutils/base/munre.c
new file mode 100644
index 0000000..69f6d7e
--- /dev/null
+++ b/libmailutils/base/munre.c
@@ -0,0 +1,92 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2006, 2007, 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 <mailutils/error.h>
+#include <mailutils/errno.h>
+
+#include <regex.h>
+
+static regex_t *re_prefix;
+
+int
+mu_unre_set_regex (const char *str, int caseflag, char **errp)
+{
+  int rc;
+  int flags = REG_EXTENDED;
+
+  if (errp)
+    *errp = NULL;
+
+  if (!str)
+    str = "^re: *";
+  if (re_prefix)
+    regfree (re_prefix);
+  else
+    {
+      re_prefix = malloc (sizeof (*re_prefix));
+      if (!re_prefix)
+       return ENOMEM;
+    }
+  if (!caseflag)
+    flags |= REG_ICASE;
+  rc = regcomp (re_prefix, str, flags);
+  if (rc)
+    {
+      if (errp)
+       {
+         size_t s = regerror (rc, re_prefix, NULL, 0);
+         s++;
+         *errp = malloc (s);
+         if (*errp)
+           regerror (rc, re_prefix, *errp, s);
+       }
+      regfree (re_prefix);
+      free (re_prefix);
+      return MU_ERR_FAILURE;
+    }
+  return 0;
+}
+
+int
+mu_unre_subject (const char *subject, const char **new_subject)
+{
+  int rc;
+  regmatch_t rm;
+
+  if (!subject)
+    return EINVAL;
+  
+  if (!re_prefix)
+    {
+      rc = mu_unre_set_regex (NULL, 0, NULL);
+      if (rc)
+       return rc;
+    }
+
+  rc = regexec (re_prefix, subject, 1, &rm, 0);
+  if (rc == 0 && rm.rm_eo != -1 && new_subject)
+    *new_subject = subject + rm.rm_eo;
+  return rc;
+}
diff --git a/libmailutils/base/mutil.c b/libmailutils/base/mutil.c
new file mode 100644
index 0000000..8612106
--- /dev/null
+++ b/libmailutils/base/mutil.c
@@ -0,0 +1,1535 @@
+/* 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 <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 <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/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)
+{
+  if (*p == '|')
+    return 1;
+  for (; *p && *p != '/'; p++)
+    if (*p == ':')
+      return 1;
+  return 0;
+}
+
+int
+mu_mh_delim (const char *str)
+{
+  if (str[0] == '-')
+    {
+      for (; *str == '-'; str++)
+       ;
+      for (; *str == ' ' || *str == '\t'; 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);
+  mu_restore_locale ();
+  return size;
+}
+  
+
+static void
+assoc_str_free (void *data)
+{
+  free (data);
+}
+
+int
+mutil_parse_field_map (const char *map, mu_assoc_t *passoc_tab, int *perr)
+{
+  int rc;
+  int i;
+  int argc;
+  char **argv;
+  mu_assoc_t assoc_tab = NULL;
+
+  rc = mu_argcv_get (map, ":", NULL, &argc, &argv);
+  if (rc)
+    {
+      mu_error (_("cannot split line `%s': %s"), map, mu_strerror (rc));
+      return rc;
+    }
+
+  for (i = 0; i < argc; i += 2)
+    {
+      char *tok = argv[i];
+      char *p = strchr (tok, '=');
+      char *pptr;
+      
+      if (!p)
+       {
+         rc = EINVAL;
+         break;
+       }
+      if (!assoc_tab)
+       {
+         rc = mu_assoc_create (&assoc_tab, sizeof(char*), 0);
+         if (rc)
+           break;
+         mu_assoc_set_free (assoc_tab, assoc_str_free);
+         *passoc_tab = assoc_tab;
+       }
+      *p++ = 0;
+      pptr = strdup (p);
+      if (!pptr)
+       {
+         rc = errno;
+         break;
+       }
+      rc = mu_assoc_install (assoc_tab, tok, &pptr);
+      if (rc)
+       {
+         free (p);
+         break;
+       }
+    }
+
+  mu_argcv_free (argc, argv);
+  if (rc && perr)
+    *perr = i;
+  return rc;
+}
+
+/* FIXME: should it be here? */
+int
+mu_sql_decode_password_type (const char *arg, enum mu_password_type *t)
+{
+  if (strcmp (arg, "plain") == 0)
+    *t = password_plaintext;
+  else if (strcmp (arg, "hash") == 0)
+    *t = password_hash;
+  else if (strcmp (arg, "scrambled") == 0)
+    *t = password_scrambled;
+  else
+    return 1;
+  return 0;
+}
+
+int
+mu_stream_flags_to_mode (int flags, int isdir)
+{
+  int mode = 0;
+  if (flags & MU_STREAM_IRGRP)
+    mode |= S_IRGRP;
+  if (flags & MU_STREAM_IWGRP)
+    mode |= S_IWGRP;
+  if (flags & MU_STREAM_IROTH)
+    mode |= S_IROTH;
+  if (flags & MU_STREAM_IWOTH)
+    mode |= S_IWOTH;
+
+  if (isdir)
+    {
+      if (mode & (S_IRGRP|S_IWGRP))
+       mode |= S_IXGRP;
+      if (mode & (S_IROTH|S_IWOTH))
+       mode |= S_IXOTH;
+    }
+  
+  return mode;
+}
diff --git a/libmailutils/base/nls.c b/libmailutils/base/nls.c
new file mode 100644
index 0000000..badda2f
--- /dev/null
+++ b/libmailutils/base/nls.c
@@ -0,0 +1,61 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2002, 2006, 2007, 2008, 2010 Free Software Foundation,
+   Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <mailutils/nls.h>
+#include <locale.h>
+
+/* Initialize Native Language Support */
+
+char *mu_locale_set;
+
+#ifndef HAVE_SETLOCALE
+# define setlocale(c,s) NULL
+#endif
+
+/* Set locale via LC_ALL.  */
+char *
+mu_set_locale (const char *locale)
+{
+#if defined HAVE_SETLOCALE
+  return setlocale (LC_ALL, locale);
+#else
+  return NULL;
+#endif
+}
+
+void
+mu_restore_locale (void)
+{
+  if (mu_locale_set)
+    mu_set_locale (mu_locale_set);
+}
+
+void
+mu_init_nls (void)
+{
+#ifdef ENABLE_NLS
+  mu_locale_set = mu_set_locale ("");
+  bindtextdomain (PACKAGE, LOCALEDIR);
+#endif /* ENABLE_NLS */
+}
+
diff --git a/libmailutils/nullrec.c b/libmailutils/base/nullrec.c
similarity index 100%
rename from libmailutils/nullrec.c
rename to libmailutils/base/nullrec.c
diff --git a/libmailutils/base/observer.c b/libmailutils/base/observer.c
new file mode 100644
index 0000000..81140c2
--- /dev/null
+++ b/libmailutils/base/observer.c
@@ -0,0 +1,238 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2004, 2005, 2007, 2010 Free Software
+   Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+
+#include <mailutils/list.h>
+#include <mailutils/iterator.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/observer.h>
+
+int
+mu_observer_create (mu_observer_t *pobserver, void *owner)
+{
+  mu_observer_t observer;
+  observer = calloc (sizeof (*observer), 1);
+  if (observer == NULL)
+    return ENOMEM;
+  observer->owner = owner;
+  *pobserver = observer;
+  return 0;
+}
+
+void
+mu_observer_destroy (mu_observer_t *pobserver, void *owner)
+{
+  if (pobserver && *pobserver)
+    {
+      mu_observer_t observer = *pobserver;
+      if (observer->owner == owner || observer->flags & MU_OBSERVER_NO_CHECK)
+       {
+         if (observer->_destroy)
+           observer->_destroy (observer, observer->_action_data);
+         free (observer);
+       }
+      *pobserver = NULL;
+    }
+}
+
+void *
+mu_observer_get_owner (mu_observer_t observer)
+{
+  return (observer) ? observer->owner : NULL;
+}
+
+int
+mu_observer_action (mu_observer_t observer, size_t type, void *data)
+{
+  if (observer == NULL)
+    return EINVAL;
+  if (observer->_action)
+    return observer->_action (observer, type, data, observer->_action_data);
+  return 0;
+}
+
+int
+mu_observer_set_action (mu_observer_t observer,
+                       int (*_action) (mu_observer_t, size_t, void *, void *),
+                       void *owner)
+{
+  if (observer == NULL)
+    return EINVAL;
+  if (observer->owner != owner)
+    return EACCES;
+  observer->_action = _action;
+  return 0;
+}
+
+int
+mu_observer_set_action_data  (mu_observer_t observer, void *data, void *owner)
+{
+  if (observer == NULL)
+    return EINVAL;
+  if (observer->owner != owner)
+    return EACCES;
+  observer->_action_data = data;
+  return 0;
+}
+
+int
+mu_observer_set_destroy (mu_observer_t observer,
+                        int (*_destroy) (mu_observer_t, void *),
+                        void *owner)
+{
+  if (observer == NULL)
+    return EINVAL;
+  if (observer->owner != owner)
+    return EACCES;
+  observer->_destroy = _destroy;
+  return 0;
+}
+
+int
+mu_observer_set_flags (mu_observer_t observer, int flags)
+{
+  if (observer == NULL)
+    return EINVAL;
+  observer->flags |= flags;
+  return 0;
+}
+
+static void
+_free_event (void *ptr)
+{
+  event_t event = ptr;
+  mu_observer_destroy (&event->observer, NULL);
+  free (event);
+}
+
+int
+mu_observable_create (mu_observable_t *pobservable, void *owner)
+{
+  mu_observable_t observable;
+  int status;
+  if (pobservable == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  observable = calloc (sizeof (*observable), 1);
+  if (observable == NULL)
+    return ENOMEM;
+  status = mu_list_create (&observable->list);
+  if (status != 0 )
+    {
+      free (observable);
+      return status;
+    }
+  mu_list_set_destroy_item (observable->list, _free_event);
+  observable->owner = owner;
+  *pobservable = observable;
+  return 0;
+}
+
+void
+mu_observable_destroy (mu_observable_t *pobservable, void *owner)
+{
+  if (pobservable && *pobservable)
+    {
+      mu_observable_t observable = *pobservable;
+      if (observable->owner == owner)
+       {
+         mu_list_destroy (&observable->list);
+         free (observable);
+       }
+      *pobservable = NULL;
+    }
+}
+
+void *
+mu_observable_get_owner (mu_observable_t observable)
+{
+  return (observable) ? observable->owner : NULL;
+}
+
+int
+mu_observable_attach (mu_observable_t observable, size_t type,  mu_observer_t 
observer)
+{
+  event_t event;
+  if (observable == NULL || observer == NULL)
+    return EINVAL;
+  event = calloc (1, sizeof (*event));
+  if (event == NULL)
+    return ENOMEM;
+  event->type = type;
+  event->observer = observer;
+  return mu_list_append (observable->list, event);
+}
+
+int
+mu_observable_detach (mu_observable_t observable, mu_observer_t observer)
+{
+  mu_iterator_t iterator;
+  int status;
+  event_t event = NULL;
+
+  if (observable == NULL || observer == NULL)
+    return EINVAL;
+  status = mu_list_get_iterator (observable->list, &iterator);
+  if (status != 0)
+    return status;
+  status = MU_ERR_NOENT;
+  for (mu_iterator_first (iterator); !mu_iterator_is_done (iterator);
+       mu_iterator_next (iterator))
+    {
+      event = NULL;
+      mu_iterator_current (iterator, (void **)&event);
+      if (event && event->observer == observer)
+        {
+          mu_iterator_ctl (iterator, mu_itrctl_delete, NULL);
+         status = 0;
+          break;
+        }
+    }
+  mu_iterator_destroy (&iterator);
+  return status;
+}
+
+int
+mu_observable_notify (mu_observable_t observable, int type, void *data)
+{
+  mu_iterator_t iterator;
+  event_t event = NULL;
+  int status = 0;
+  if (observable == NULL)
+    return EINVAL;
+  status = mu_list_get_iterator (observable->list, &iterator);
+  if (status != 0)
+    return status;
+  for (mu_iterator_first (iterator); !mu_iterator_is_done (iterator);
+       mu_iterator_next (iterator))
+    {
+      event = NULL;
+      mu_iterator_current (iterator, (void **)&event);
+      if (event && event->type & type)
+        {
+         status |= mu_observer_action (event->observer, type, data);
+        }
+    }
+  mu_iterator_destroy (&iterator);
+  return status;
+}
diff --git a/libmailutils/base/opool.c b/libmailutils/base/opool.c
new file mode 100644
index 0000000..9cb6b0c
--- /dev/null
+++ b/libmailutils/base/opool.c
@@ -0,0 +1,446 @@
+/* String-list functions for GNU Mailutils.
+   Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+
+   Based on slist module from GNU Radius.  Written by Sergey Poznyakoff.
+   
+   GNU Mailutils is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 3, or (at
+   your option) any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/types.h>
+#include <mailutils/alloc.h>
+#include <mailutils/opool.h>
+#include <mailutils/errno.h>
+#include <mailutils/error.h>
+#include <mailutils/nls.h>
+#include <mailutils/iterator.h>
+
+struct mu_opool_bucket
+{
+  struct mu_opool_bucket *next;
+  char *buf;
+  size_t level;
+  size_t size;
+};
+
+struct _mu_opool
+{
+  int memerr;
+  size_t bucket_size;
+  size_t itr_count;
+  struct mu_opool_bucket *head, *tail;
+  struct mu_opool_bucket *free;
+};
+
+static struct mu_opool_bucket *
+alloc_bucket (struct _mu_opool *opool, size_t size)
+{
+  struct mu_opool_bucket *p = malloc (sizeof (*p) + size);
+  if (!p)
+    {
+      if (opool->memerr)
+       mu_alloc_die ();
+    }
+  else
+    {
+      p->buf = (char*)(p + 1);
+      p->level = 0;
+      p->size = size;
+      p->next = NULL;
+    }
+  return p;
+}
+
+static int
+alloc_pool (mu_opool_t opool, size_t size)
+{
+  struct mu_opool_bucket *p = alloc_bucket (opool, opool->bucket_size);
+  if (!p)
+    return ENOMEM;
+  if (opool->tail)
+    opool->tail->next = p;
+  else
+    opool->head = p;
+  opool->tail = p;
+  return 0;
+}
+
+static int
+copy_chars (mu_opool_t opool, const char *str, size_t n, size_t *psize)
+{
+  size_t rest;
+
+  if (!opool->head || opool->tail->level == opool->tail->size)
+    if (alloc_pool (opool, opool->bucket_size))
+      return ENOMEM;
+  rest = opool->tail->size - opool->tail->level;
+  if (n > rest)
+    n = rest;
+  memcpy (opool->tail->buf + opool->tail->level, str, n);
+  opool->tail->level += n;
+  *psize = n;
+  return 0;
+}
+
+int
+mu_opool_create (mu_opool_t *pret, int memerr)
+{
+  struct _mu_opool *x = malloc (sizeof (x[0]));
+  if (!x)
+    {
+      if (memerr)
+       mu_alloc_die ();
+      return ENOMEM;
+    }
+  x->memerr = memerr;
+  x->bucket_size = MU_OPOOL_BUCKET_SIZE;
+  x->itr_count = 0;
+  x->head = x->tail = x->free = 0;
+  *pret = x;
+  return 0;
+}
+
+int
+mu_opool_set_bucket_size (mu_opool_t opool, size_t size)
+{
+  if (!opool)
+    return EINVAL;
+  opool->bucket_size = size;
+  return 0;
+}
+
+int
+mu_opool_get_bucket_size (mu_opool_t opool, size_t *psize)
+{
+  if (!opool || !psize)
+    return EINVAL;
+  *psize = opool->bucket_size;
+  return 0;
+}
+
+void
+mu_opool_clear (mu_opool_t opool)
+{
+  if (!opool)
+    return;
+  
+  if (opool->tail)
+    {
+      opool->tail->next = opool->free;
+      opool->free = opool->head;
+      opool->head = opool->tail = NULL;
+    }
+}      
+
+void
+mu_opool_destroy (mu_opool_t *popool)
+{
+  struct mu_opool_bucket *p;
+  if (popool && *popool)
+    {
+      mu_opool_t opool = *popool;
+      mu_opool_clear (opool);
+      for (p = opool->free; p; )
+       {
+         struct mu_opool_bucket *next = p->next;
+         free (p);
+         p = next;
+       }
+      free (opool);
+    }
+  *popool = NULL;
+}
+
+int
+mu_opool_append (mu_opool_t opool, const void *str, size_t n)
+{
+  const char *ptr = str;
+  while (n)
+    {
+      size_t s;
+      if (copy_chars (opool, ptr, n, &s))
+       return ENOMEM;
+      ptr += s;
+      n -= s;
+    }
+  return 0;
+}
+
+int
+mu_opool_append_char (mu_opool_t opool, char c)
+{
+  return mu_opool_append (opool, &c, 1);
+}      
+
+int
+mu_opool_appendz (mu_opool_t opool, const char *str)
+{
+  return mu_opool_append (opool, str, strlen (str))
+         || mu_opool_append_char (opool, 0);
+}
+
+size_t
+mu_opool_size (mu_opool_t opool)
+{
+  size_t size = 0;
+  struct mu_opool_bucket *p;
+  for (p = opool->head; p; p = p->next)
+    size += p->level;
+  return size;
+}
+
+size_t
+mu_opool_copy (mu_opool_t opool, void *buf, size_t size)
+{
+  char *cp = buf;
+  size_t total = 0;
+  struct mu_opool_bucket *p;
+  
+  for (p = opool->head; p && total < size; p = p->next)
+    {
+      size_t cpsize = size - total;
+      if (cpsize > p->level)
+       cpsize = p->level;
+      memcpy (cp, p->buf, cpsize);
+      cp += cpsize;
+      total += cpsize;
+    }
+  return total;
+}
+
+int
+mu_opool_coalesce (mu_opool_t opool, size_t *psize)
+{
+  size_t size;
+
+  if (opool->itr_count)
+    return MU_ERR_FAILURE;
+  if (opool->head && opool->head->next == NULL)
+    size = opool->head->level;
+  else {
+    struct mu_opool_bucket *bucket;
+    struct mu_opool_bucket *p;
+
+    size = mu_opool_size (opool);
+       
+    bucket = alloc_bucket (opool, size);
+    if (!bucket)
+      return ENOMEM;
+    for (p = opool->head; p; )
+      {
+       struct mu_opool_bucket *next = p->next;
+       memcpy (bucket->buf + bucket->level, p->buf, p->level);
+       bucket->level += p->level;
+       free (p);
+       p = next;
+      }
+    opool->head = opool->tail = bucket;
+  }
+  if (psize)
+    *psize = size;
+  return 0;
+}
+
+void *
+mu_opool_head (mu_opool_t opool, size_t *psize)
+{
+  if (*psize) 
+    *psize = opool->head ? opool->head->level : 0;
+  return opool->head ? opool->head->buf : NULL;
+}
+
+void *
+mu_opool_finish (mu_opool_t opool, size_t *psize)
+{
+  if (mu_opool_coalesce (opool, psize))
+    return NULL;
+  mu_opool_clear (opool);
+  return opool->free->buf;
+}
+
+int
+mu_opool_union (mu_opool_t *pdst, mu_opool_t *psrc)
+{
+  mu_opool_t src, dst;
+  
+  if (!psrc)
+    return EINVAL;
+  if (!*psrc)
+    return 0;
+  src = *psrc;
+  
+  if (!pdst)
+    return EINVAL;
+  if (!*pdst)
+    {
+      *pdst = src;
+      *psrc = NULL;
+      return 0;
+    }
+  else
+    dst = *pdst;
+
+  if (dst->tail)
+    dst->tail->next = src->head;
+  else
+    dst->head = src->head;
+  dst->tail = src->tail;
+
+  if (src->free)
+    {
+      struct mu_opool_bucket *p;
+
+      for (p = src->free; p->next; p = p->next)
+       ;
+      p->next = dst->free;
+      dst->free = src->free;
+    }
+
+  free (src);
+  *psrc = NULL;
+  return 0;
+}
+
+
+/* Iterator support */
+struct opool_iterator
+{
+  mu_opool_t opool;
+  struct mu_opool_bucket *cur;
+};
+
+static int
+opitr_first (void *owner)
+{
+  struct opool_iterator *itr = owner;
+  itr->cur = itr->opool->head;
+  return 0;
+}
+
+static int
+opitr_next (void *owner)
+{
+  struct opool_iterator *itr = owner;
+  if (itr->cur)
+    {
+      itr->cur = itr->cur->next;
+      return 0;
+    }
+  return EINVAL;
+}
+
+static int
+opitr_getitem (void *owner, void **pret, const void **pkey)
+{
+  struct opool_iterator *itr = owner;
+  if (!itr->cur)
+    return MU_ERR_NOENT;
+
+  *pret = itr->cur->buf;
+  if (pkey)
+    *(size_t*) pkey = itr->cur->level;
+  return 0;
+}
+
+static int
+opitr_finished_p (void *owner)
+{
+  struct opool_iterator *itr = owner;
+  return itr->cur == NULL;
+}
+
+static int
+opitr_curitem_p (void *owner, void *item)
+{
+  struct opool_iterator *itr = owner;
+  return itr->cur && itr->cur->buf == item;
+}
+
+static int
+opitr_destroy (mu_iterator_t iterator, void *data)
+{
+  struct opool_iterator *itr = data;
+  if (itr->opool->itr_count == 0)
+    {
+      /* oops! */
+      mu_error (_("%s: INTERNAL ERROR: zero reference count"),
+               "opool_destroy");
+    }
+  else
+    itr->opool->itr_count--;
+  free (data);
+  return 0;
+}
+
+static int
+opitr_data_dup (void **ptr, void *owner)
+{
+  struct opool_iterator *itr = owner;
+
+  *ptr = malloc (sizeof (struct opool_iterator));
+  if (*ptr == NULL)
+    return ENOMEM;
+  memcpy (*ptr, owner, sizeof (struct opool_iterator));
+  itr->opool->itr_count++;
+  return 0;
+}
+
+int
+mu_opool_get_iterator (mu_opool_t opool, mu_iterator_t *piterator)
+{
+  mu_iterator_t iterator;
+  int status;
+  struct opool_iterator *itr;
+
+  if (!opool)
+    return EINVAL;
+
+  itr = calloc (1, sizeof *itr);
+  if (!itr)
+    return ENOMEM;
+  itr->opool = opool;
+  itr->cur = opool->head;
+  
+  status = mu_iterator_create (&iterator, itr);
+  if (status)
+    {
+      free (itr);
+      return status;
+    }
+
+  mu_iterator_set_first (iterator, opitr_first);
+  mu_iterator_set_next (iterator, opitr_next);
+  mu_iterator_set_getitem (iterator, opitr_getitem);
+  mu_iterator_set_finished_p (iterator, opitr_finished_p);
+  mu_iterator_set_curitem_p (iterator, opitr_curitem_p);
+  mu_iterator_set_destroy (iterator, opitr_destroy);
+  mu_iterator_set_dup (iterator, opitr_data_dup);
+
+  opool->itr_count++;
+
+  *piterator = iterator;
+  return 0;
+}
+
+
+
+
+  
+  
+ 
diff --git a/libmailutils/base/parsedate.y b/libmailutils/base/parsedate.y
new file mode 100644
index 0000000..98c932b
--- /dev/null
+++ b/libmailutils/base/parsedate.y
@@ -0,0 +1,1205 @@
+%{
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2003, 2007, 2008, 2010 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+   
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+  
+/* A heavily modified version of the well-known public domain getdate.y.
+   It was originally written by Steven M. Bellovin <address@hidden>
+   while at the University of North Carolina at Chapel Hill.  Later tweaked
+   by a couple of people on Usenet.  Completely overhauled by Rich $alz
+   <address@hidden> and Jim Berets <address@hidden> in August, 1990.
+   Rewritten using a proper union by Sergey Poznyakoff <address@hidden> */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <ctype.h>
+
+#if HAVE_STDLIB_H
+# include <stdlib.h> /* for `free'; used by Bison 1.27 */
+#endif
+
+#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
+# define IN_CTYPE_DOMAIN(c) 1
+#else
+# define IN_CTYPE_DOMAIN(c) isascii(c)
+#endif
+
+#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
+#define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
+#define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
+#define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
+
+/* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
+   - Its arg may be any int or unsigned int; it need not be an unsigned char.
+   - It's guaranteed to evaluate its argument exactly once.
+   - It's typically faster.
+   Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
+   only '0' through '9' are digits.  Prefer ISDIGIT to ISDIGIT_LOCALE unless
+   it's important to use the locale's definition of `digit' even when the
+   host does not conform to Posix.  */
+#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
+
+#if defined (STDC_HEADERS) || defined (USG)
+# include <string.h>
+#endif
+
+/* Some old versions of bison generate parsers that use bcopy.
+   That loses on systems that don't provide the function, so we have
+   to redefine it here.  */
+#if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy)
+# define bcopy(from, to, len) memcpy ((to), (from), (len))
+#endif
+
+static int yylex ();
+static int yyerror ();
+
+#define EPOCH          1970
+#define HOUR(x)                ((x) * 60)
+
+#define MAX_BUFF_LEN    128   /* size of buffer to read the date into */
+
+/*
+**  An entry in the lexical lookup table.
+*/
+typedef struct _lex_tab {
+  const char   *name;
+  int          type;
+  int          value;
+} SYMBOL;
+
+
+/*
+**  Meridian:  am, pm, or 24-hour style.
+*/
+typedef enum meridian {
+  MERam,
+  MERpm,
+  MER24
+} MERIDIAN;
+
+#define PD_MASK_SECOND   00001
+#define PD_MASK_MINUTE   00002
+#define PD_MASK_HOUR     00004
+#define PD_MASK_DAY      00010
+#define PD_MASK_MONTH    00020
+#define PD_MASK_YEAR     00040
+#define PD_MASK_TZ       00100 
+#define PD_MASK_MERIDIAN 00200
+#define PD_MASK_ORDINAL  00400
+#define PD_MASK_NUMBER   01000
+
+#define PD_MASK_TIME PD_MASK_SECOND|PD_MASK_MINUTE|PD_MASK_HOUR
+#define PD_MASK_DATE PD_MASK_DAY|PD_MASK_MONTH|PD_MASK_YEAR
+#define PD_MASK_DOW PD_MASK_NUMBER
+ 
+#define MASK_IS_SET(f,m) (((f)&(m))==(m))
+#define MASK_TEST(f,m)   ((f)&(m)) 
+struct pd_date
+{
+  int mask;
+  int day;
+  int hour;
+  int minute;
+  int month;
+  int second;
+  int year;
+  int tz;
+  enum meridian meridian;
+  int number;
+  int ordinal;
+};
+
+#define DATE_INIT(date) memset(&(date), 0, sizeof(date))
+#define DATE_SET(date, memb, m, val, lim, onerror)                        \
+ do                                                                       \
+   {                                                                      \
+     int __x = val;                                                       \
+     if (((m) != PD_MASK_TZ && __x < 0) || (lim && __x > lim)) onerror;   \
+     date . memb = __x; date.mask |= m;                                   \
+   }                                                                      \
+ while (0)
+   
+#define __SET_SECOND(d,v,a)   DATE_SET(d,second,PD_MASK_SECOND,v,59,a)
+#define __SET_MINUTE(d,v,a)   DATE_SET(d,minute,PD_MASK_MINUTE,v,59,a)  
+#define __SET_HOUR(d,v,a)     DATE_SET(d,hour,PD_MASK_HOUR,v,23,a)
+#define __SET_DAY(d,v,a)      DATE_SET(d,day,PD_MASK_DAY,v,31,a)   
+#define __SET_MONTH(d,v,a)    DATE_SET(d,month,PD_MASK_MONTH,v,12,a)
+#define __SET_YEAR(d,v,a)     DATE_SET(d,year,PD_MASK_YEAR,v,0,a)  
+#define __SET_TZ(d,v,a)       DATE_SET(d,tz,PD_MASK_TZ,v,0,a)
+#define __SET_MERIDIAN(d,v,a) DATE_SET(d,meridian,PD_MASK_MERIDIAN,v,MER24,a)
+#define __SET_ORDINAL(d,v,a)  DATE_SET(d,ordinal,PD_MASK_ORDINAL,v,0,a)
+#define __SET_NUMBER(d,v,a)   DATE_SET(d,number,PD_MASK_NUMBER,v,0,a) 
+ 
+#define SET_SECOND(d,v)   __SET_SECOND(d,v,YYERROR)   
+#define SET_MINUTE(d,v)   __SET_MINUTE(d,v,YYERROR)   
+#define SET_HOUR(d,v)     __SET_HOUR(d,v,YYERROR)     
+#define SET_DAY(d,v)      __SET_DAY(d,v,YYERROR)      
+#define SET_MONTH(d,v)    __SET_MONTH(d,v,YYERROR)    
+#define SET_YEAR(d,v)     __SET_YEAR(d,v,YYERROR)     
+#define SET_TZ(d,v)       __SET_TZ(d,v,YYERROR)       
+#define SET_MERIDIAN(d,v) __SET_MERIDIAN(d,v,YYERROR) 
+#define SET_ORDINAL(d,v)  __SET_ORDINAL(d,v,YYERROR)  
+#define SET_NUMBER(d,v)   __SET_NUMBER(d,v,YYERROR)   
+
+int
+pd_date_union (struct pd_date *a, struct pd_date *b)
+{
+  int diff = (~a->mask) & b->mask;
+  if (!diff)
+    return 1;
+
+  a->mask |= diff;
+  
+  if (diff & PD_MASK_SECOND)
+    a->second = b->second;
+  
+  if (diff & PD_MASK_MINUTE)
+    a->minute = b->minute;
+
+  if (diff & PD_MASK_HOUR)
+    a->hour = b->hour;
+
+  if (diff & PD_MASK_DAY)
+    a->day = b->day;
+
+  if (diff & PD_MASK_MONTH)
+    a->month = b->month;
+
+  if (diff & PD_MASK_YEAR)
+    a->year = b->year;
+
+  if (diff & PD_MASK_TZ)
+    a->tz = b->tz;
+
+  if (diff & PD_MASK_MERIDIAN)
+    a->meridian = b->meridian;
+
+  if (diff & PD_MASK_ORDINAL)
+    a->ordinal = b->ordinal;
+
+  if (diff & PD_MASK_NUMBER)
+    a->number = b->number;
+
+  return 0;
+}
+
+struct pd_datespec
+{
+  struct pd_date date;
+  struct pd_date rel;
+};
+
+static struct pd_datespec pd;
+ 
+static const char      *yyinput;
+
+%}
+
+%union {
+  int number;
+  enum meridian meridian;
+  struct pd_date date;
+  struct pd_datespec datespec;
+}
+
+/*FIXME: do we need T_ID? */
+%token  T_AGO T_DST  T_ID
+
+%token <number> T_DAY T_DAY_UNIT T_DAYZONE T_HOUR_UNIT T_MINUTE_UNIT
+%token <number> T_MONTH T_MONTH_UNIT
+%token <number>        T_SEC_UNIT T_SNUMBER T_UNUMBER T_YEAR_UNIT T_ZONE
+%token <meridian> T_MERIDIAN
+
+%type <meridian> o_merid
+%type <date> item time zone date day rel relspec relunit
+%type <datespec> spec
+
+%%
+
+input   : spec
+          {
+           pd = $1;
+         }
+        ;
+
+spec   : /* NULL */
+          {
+           DATE_INIT ($$.date);
+           DATE_INIT ($$.rel);
+         }
+       | spec item
+          {
+           if (pd_date_union (&$1.date, &$2))
+             YYERROR;
+           $$ = $1;
+         }
+        | spec rel
+          {
+           if (pd_date_union (&$1.rel, &$2))
+             YYERROR;
+           $$ = $1;
+         }
+        | spec T_UNUMBER
+          {
+           if (MASK_IS_SET ($1.date.mask, (PD_MASK_TIME|PD_MASK_DATE))
+               && !$1.rel.mask)
+             SET_YEAR ($1.date, $2);
+           else
+             {
+               if ($2 > 10000)
+                 {
+                   SET_DAY ($1.date, $2 % 100);
+                   SET_MONTH ($1.date, ($2 / 100) %100);
+                   SET_YEAR ($1.date, $2 / 10000);
+                 }
+               else
+                 {
+                   if ($2 < 100)
+                     {
+                       SET_YEAR ($1.date, $2);
+                     }
+                   else
+                     {
+                       SET_HOUR ($1.date, $2 / 100);
+                       SET_MINUTE ($1.date, $2 % 100);
+                     }
+                   SET_MERIDIAN ($1.date, MER24);
+                 }
+             }
+           $$ = $1;
+         }
+       ;
+
+item   : time
+        | zone
+       | date
+       | day
+       ;
+
+time   : T_UNUMBER T_MERIDIAN
+          {
+           DATE_INIT ($$);
+           SET_HOUR ($$, $1);
+           SET_MERIDIAN ($$, $2);
+         }
+       | T_UNUMBER ':' T_UNUMBER o_merid
+          {
+           DATE_INIT ($$);
+           SET_HOUR ($$, $1);
+           SET_MINUTE ($$, $3);
+           SET_MERIDIAN ($$, $4);
+         }
+       | T_UNUMBER ':' T_UNUMBER T_SNUMBER
+          {
+           DATE_INIT ($$);
+           SET_HOUR ($$, $1);
+           SET_MINUTE ($$, $3);
+           SET_MERIDIAN ($$, MER24);
+           SET_TZ ($$, ($4 < 0
+                          ? -$4 % 100 + (-$4 / 100) * 60
+                          : - ($4 % 100 + ($4 / 100) * 60)));
+
+         }
+       | T_UNUMBER ':' T_UNUMBER ':' T_UNUMBER o_merid
+          {
+           DATE_INIT ($$);
+           SET_HOUR ($$, $1);
+           SET_MINUTE ($$, $3);
+           SET_SECOND ($$, $5);
+           SET_MERIDIAN ($$, $6);
+         }
+       | T_UNUMBER ':' T_UNUMBER ':' T_UNUMBER T_SNUMBER
+          {
+           DATE_INIT ($$);
+           SET_HOUR ($$, $1);
+           SET_MINUTE ($$, $3);
+           SET_SECOND ($$, $5);
+           SET_MERIDIAN ($$, MER24);
+           SET_TZ ($$, ($6 < 0
+                        ? -$6 % 100 + (-$6 / 100) * 60
+                        : - ($6 % 100 + ($6 / 100) * 60)));
+         }
+       ;
+
+zone   : T_ZONE
+          {
+           DATE_INIT ($$);
+           SET_TZ ($$, $1);
+         }
+       | T_DAYZONE
+          {
+           DATE_INIT ($$);
+           SET_TZ ($$, $1 - 60);
+         }
+       | T_ZONE T_DST
+          {
+           DATE_INIT ($$);
+           SET_TZ ($$, $1 - 60);
+         }
+       ;
+
+day    : T_DAY
+          {
+           DATE_INIT ($$);
+           SET_ORDINAL ($$, 1);
+           SET_NUMBER ($$, $1);
+         }
+       | T_DAY ','
+          {
+           DATE_INIT ($$);
+           SET_ORDINAL ($$, 1);
+           SET_NUMBER ($$, $1);
+         }
+       | T_UNUMBER T_DAY
+          {
+           DATE_INIT ($$);
+           SET_ORDINAL ($$, $1);
+           SET_NUMBER ($$, $2);
+         }
+       ;
+
+date   : T_UNUMBER '/' T_UNUMBER
+          {
+           DATE_INIT ($$);
+           SET_MONTH ($$, $1);
+           SET_DAY ($$, $3);
+         }
+       | T_UNUMBER '/' T_UNUMBER '/' T_UNUMBER
+          {
+           DATE_INIT ($$);
+           /* Interpret as YYYY/MM/DD if $1 >= 1000, otherwise as MM/DD/YY.
+              The goal in recognizing YYYY/MM/DD is solely to support legacy
+              machine-generated dates like those in an RCS log listing.  If
+              you want portability, use the ISO 8601 format.  */
+           if ($1 >= 1000)
+             {
+               SET_YEAR ($$, $1);
+               SET_MONTH ($$, $3);
+               SET_DAY ($$, $5);
+             }
+           else
+             {
+               SET_MONTH ($$, $1);
+               SET_DAY ($$, $3);
+               SET_YEAR ($$, $5);
+             }
+         }
+       | T_UNUMBER T_SNUMBER T_SNUMBER
+          {
+           DATE_INIT ($$);
+           /* ISO 8601 format.  yyyy-mm-dd.  */
+           SET_YEAR ($$, $1);
+           SET_MONTH ($$, -$2);
+           SET_DAY ($$, -$3);
+         }
+       | T_UNUMBER T_MONTH T_SNUMBER
+          {
+           /* either 17-JUN-1992 or 1992-JUN-17 */
+           DATE_INIT ($$);
+           if ($1 < 32)
+             {
+               SET_DAY ($$, $1);
+               SET_MONTH ($$, $2);
+               SET_YEAR ($$, -$3);
+             }
+           else
+             {
+               SET_DAY ($$, -$3);
+               SET_MONTH ($$, $2);
+               SET_YEAR ($$, $1);
+             }
+         }
+       | T_MONTH T_UNUMBER
+          {
+           DATE_INIT ($$);
+           SET_MONTH ($$, $1);
+           SET_DAY ($$, $2);
+         }
+       | T_MONTH T_UNUMBER ',' T_UNUMBER
+          {
+           DATE_INIT ($$);
+           SET_MONTH ($$, $1);
+           SET_DAY ($$, $2);
+           SET_YEAR ($$, $4);
+         }
+       | T_UNUMBER T_MONTH
+          {
+           DATE_INIT ($$);
+           SET_MONTH ($$, $2);
+           SET_DAY ($$, $1);
+         }
+       | T_UNUMBER T_MONTH T_UNUMBER
+          {
+           DATE_INIT ($$);
+           SET_MONTH ($$, $2);
+           SET_DAY ($$, $1);
+           SET_YEAR ($$, $3);
+         }
+        | T_DAY T_MONTH T_UNUMBER time T_UNUMBER
+          {
+           DATE_INIT ($$);
+
+           SET_ORDINAL ($$, 1);
+           SET_NUMBER ($$, $1);
+
+           SET_MONTH ($$, $2);
+           SET_DAY ($$, $3);
+           SET_YEAR ($$, $5);
+           if (pd_date_union (&$$, &$4))
+             YYERROR;
+         }
+       ;
+
+rel    : relspec T_AGO
+          {
+           $1.second = - $1.second;
+           $1.minute = - $1.minute;
+           $1.hour = - $1.hour;
+           $1.day = - $1.day;
+           $1.month = - $1.month;
+           $1.year = - $1.year;
+           $$ = $1;
+         }
+       | relspec
+       ;
+
+
+relspec : relunit
+          {
+           DATE_INIT ($$);
+           if (pd_date_union (&$$, &$1))
+             YYERROR;
+         }
+        | relspec relunit
+          {
+           if (pd_date_union (&$1, &$2))
+             YYERROR;
+           $$ = $1;
+         }
+        ;
+
+relunit        : T_UNUMBER T_YEAR_UNIT
+          {
+           DATE_INIT ($$);
+           SET_YEAR ($$, $1 * $2);
+         }
+       | T_SNUMBER T_YEAR_UNIT
+          {
+           DATE_INIT ($$);
+           SET_YEAR ($$, $1 * $2);
+         }
+       | T_YEAR_UNIT
+          {
+           DATE_INIT ($$);
+           SET_YEAR ($$, $1);
+         }
+       | T_UNUMBER T_MONTH_UNIT
+          {
+           DATE_INIT ($$);
+           SET_MONTH ($$, $1 * $2);
+         }
+       | T_SNUMBER T_MONTH_UNIT
+          {
+           DATE_INIT ($$);
+           SET_MONTH ($$, $1 * $2);
+         }
+       | T_MONTH_UNIT
+          {
+           DATE_INIT ($$);
+           SET_MONTH ($$, $1);
+         }
+       | T_UNUMBER T_DAY_UNIT
+          {
+           DATE_INIT ($$);
+           SET_DAY ($$, $1 * $2);
+         }
+       | T_SNUMBER T_DAY_UNIT
+          {
+           DATE_INIT ($$);
+           SET_DAY ($$, $1 * $2);
+         }
+       | T_DAY_UNIT
+          {
+           DATE_INIT ($$);
+           SET_DAY ($$, $1);
+         }
+       | T_UNUMBER T_HOUR_UNIT
+          {
+           DATE_INIT ($$);
+           SET_HOUR ($$, $1 * $2);
+         }
+       | T_SNUMBER T_HOUR_UNIT
+          {
+           DATE_INIT ($$);
+           SET_HOUR ($$, $1 * $2);
+         }
+       | T_HOUR_UNIT
+          {
+           DATE_INIT ($$);
+           SET_HOUR ($$, $1);
+         }
+       | T_UNUMBER T_MINUTE_UNIT
+          {
+           DATE_INIT ($$);
+           SET_MINUTE ($$, $1 * $2);
+         }
+       | T_SNUMBER T_MINUTE_UNIT
+          {
+           DATE_INIT ($$);
+           SET_MINUTE ($$, $1 * $2);
+         }
+       | T_MINUTE_UNIT
+          {
+           DATE_INIT ($$);
+           SET_MINUTE ($$, $1);
+         }
+       | T_UNUMBER T_SEC_UNIT
+          {
+           DATE_INIT ($$);
+           SET_SECOND ($$, $1 * $2);
+         }
+       | T_SNUMBER T_SEC_UNIT
+          {
+           DATE_INIT ($$);
+           SET_SECOND ($$, $1 * $2);
+         }
+       | T_SEC_UNIT
+          {
+           DATE_INIT ($$);
+           SET_SECOND ($$, $1);
+         }
+       ;
+
+o_merid        : /* empty */
+          {
+           $$ = MER24;
+         }
+       | T_MERIDIAN
+         {
+           $$ = $1;
+         }
+       ;
+
+%%
+
+#include <mailutils/types.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
+#include <mailutils/mutil.h>
+
+/* Month and day table. */
+static SYMBOL const month_day_tab[] = {
+  { "january", T_MONTH,  1 },
+  { "february",        T_MONTH,  2 },
+  { "march",   T_MONTH,  3 },
+  { "april",   T_MONTH,  4 },
+  { "may",     T_MONTH,  5 },
+  { "june",    T_MONTH,  6 },
+  { "july",    T_MONTH,  7 },
+  { "august",  T_MONTH,  8 },
+  { "september",T_MONTH,  9 },
+  { "sept",    T_MONTH,  9 },
+  { "october", T_MONTH, 10 },
+  { "november",        T_MONTH, 11 },
+  { "december",        T_MONTH, 12 },
+  { "sunday",  T_DAY,   0 },
+  { "monday",  T_DAY,   1 },
+  { "tuesday", T_DAY,   2 },
+  { "tues",    T_DAY,   2 },
+  { "wednesday",T_DAY,   3 },
+  { "wednes",  T_DAY,   3 },
+  { "thursday",        T_DAY,   4 },
+  { "thur",    T_DAY,   4 },
+  { "thurs",   T_DAY,   4 },
+  { "friday",  T_DAY,   5 },
+  { "saturday",        T_DAY,   6 },
+  { NULL, 0, 0 }
+};
+
+/* Time units table. */
+static SYMBOL const units_tab[] = {
+  { "year",    T_YEAR_UNIT,    1 },
+  { "month",   T_MONTH_UNIT,   1 },
+  { "fortnight",T_DAY_UNIT,    14 },
+  { "week",    T_DAY_UNIT,     7 },
+  { "day",     T_DAY_UNIT,     1 },
+  { "hour",    T_HOUR_UNIT,    1 },
+  { "minute",  T_MINUTE_UNIT,  1 },
+  { "min",     T_MINUTE_UNIT,  1 },
+  { "second",  T_SEC_UNIT,     1 },
+  { "sec",     T_SEC_UNIT,     1 },
+  { NULL, 0, 0 }
+};
+
+/* Assorted relative-time words. */
+static SYMBOL const other_tab[] = {
+  { "tomorrow",        T_MINUTE_UNIT,  1 * 24 * 60 },
+  { "yesterday",T_MINUTE_UNIT, -1 * 24 * 60 },
+  { "today",   T_MINUTE_UNIT,  0 },
+  { "now",     T_MINUTE_UNIT,  0 },
+  { "last",    T_UNUMBER,      -1 },
+  { "this",    T_MINUTE_UNIT,  0 },
+  { "next",    T_UNUMBER,      1 },
+  { "first",   T_UNUMBER,      1 },
+/*  { "second",        T_UNUMBER,      2 }, */
+  { "third",   T_UNUMBER,      3 },
+  { "fourth",  T_UNUMBER,      4 },
+  { "fifth",   T_UNUMBER,      5 },
+  { "sixth",   T_UNUMBER,      6 },
+  { "seventh", T_UNUMBER,      7 },
+  { "eighth",  T_UNUMBER,      8 },
+  { "ninth",   T_UNUMBER,      9 },
+  { "tenth",   T_UNUMBER,      10 },
+  { "eleventh",        T_UNUMBER,      11 },
+  { "twelfth", T_UNUMBER,      12 },
+  { "ago",     T_AGO,          1 },
+  { NULL, 0, 0 }
+};
+
+/* The timezone table. */
+static SYMBOL const tz_tab[] = {
+  { "gmt",     T_ZONE,     HOUR ( 0) },        /* Greenwich Mean */
+  { "ut",      T_ZONE,     HOUR ( 0) },        /* Universal (Coordinated) */
+  { "utc",     T_ZONE,     HOUR ( 0) },
+  { "wet",     T_ZONE,     HOUR ( 0) },        /* Western European */
+  { "bst",     T_DAYZONE,  HOUR ( 0) },        /* British Summer */
+  { "wat",     T_ZONE,     HOUR ( 1) },        /* West Africa */
+  { "at",      T_ZONE,     HOUR ( 2) },        /* Azores */
+#if    0
+  /* For completeness.  BST is also British Summer, and GST is
+   * also Guam Standard. */
+  { "bst",     T_ZONE,     HOUR ( 3) },        /* Brazil Standard */
+  { "gst",     T_ZONE,     HOUR ( 3) },        /* Greenland Standard */
+#endif
+#if 0
+  { "nft",     T_ZONE,     HOUR (3.5) },       /* Newfoundland */
+  { "nst",     T_ZONE,     HOUR (3.5) },       /* Newfoundland Standard */
+  { "ndt",     T_DAYZONE,  HOUR (3.5) },       /* Newfoundland Daylight */
+#endif
+  { "ast",     T_ZONE,     HOUR ( 4) },        /* Atlantic Standard */
+  { "adt",     T_DAYZONE,  HOUR ( 4) },        /* Atlantic Daylight */
+  { "est",     T_ZONE,     HOUR ( 5) },        /* Eastern Standard */
+  { "edt",     T_DAYZONE,  HOUR ( 5) },        /* Eastern Daylight */
+  { "cst",     T_ZONE,     HOUR ( 6) },        /* Central Standard */
+  { "cdt",     T_DAYZONE,  HOUR ( 6) },        /* Central Daylight */
+  { "mst",     T_ZONE,     HOUR ( 7) },        /* Mountain Standard */
+  { "mdt",     T_DAYZONE,  HOUR ( 7) },        /* Mountain Daylight */
+  { "pst",     T_ZONE,     HOUR ( 8) },        /* Pacific Standard */
+  { "pdt",     T_DAYZONE,  HOUR ( 8) },        /* Pacific Daylight */
+  { "yst",     T_ZONE,     HOUR ( 9) },        /* Yukon Standard */
+  { "ydt",     T_DAYZONE,  HOUR ( 9) },        /* Yukon Daylight */
+  { "hst",     T_ZONE,     HOUR (10) },        /* Hawaii Standard */
+  { "hdt",     T_DAYZONE,  HOUR (10) },        /* Hawaii Daylight */
+  { "cat",     T_ZONE,     HOUR (10) },        /* Central Alaska */
+  { "ahst",    T_ZONE,     HOUR (10) },        /* Alaska-Hawaii Standard */
+  { "nt",      T_ZONE,     HOUR (11) },        /* Nome */
+  { "idlw",    T_ZONE,     HOUR (12) },        /* International Date Line West 
*/
+  { "cet",     T_ZONE,     -HOUR (1) },        /* Central European */
+  { "met",     T_ZONE,     -HOUR (1) },        /* Middle European */
+  { "mewt",    T_ZONE,     -HOUR (1) },        /* Middle European Winter */
+  { "mest",    T_DAYZONE,  -HOUR (1) },        /* Middle European Summer */
+  { "mesz",    T_DAYZONE,  -HOUR (1) },        /* Middle European Summer */
+  { "swt",     T_ZONE,     -HOUR (1) },        /* Swedish Winter */
+  { "sst",     T_DAYZONE,  -HOUR (1) },        /* Swedish Summer */
+  { "fwt",     T_ZONE,     -HOUR (1) },        /* French Winter */
+  { "fst",     T_DAYZONE,  -HOUR (1) },        /* French Summer */
+  { "eet",     T_ZONE,     -HOUR (2) },        /* Eastern Europe, USSR Zone 1 
*/
+  { "bt",      T_ZONE,     -HOUR (3) },        /* Baghdad, USSR Zone 2 */
+#if 0
+  { "it",      T_ZONE,     -HOUR (3.5) },/* Iran */
+#endif
+  { "zp4",     T_ZONE,     -HOUR (4) },        /* USSR Zone 3 */
+  { "zp5",     T_ZONE,     -HOUR (5) },        /* USSR Zone 4 */
+#if 0
+  { "ist",     T_ZONE,     -HOUR (5.5) },/* Indian Standard */
+#endif
+  { "zp6",     T_ZONE,     -HOUR (6) },        /* USSR Zone 5 */
+#if    0
+  /* For completeness.  NST is also Newfoundland Standard, and SST is
+   * also Swedish Summer. */
+  { "nst",     T_ZONE,     -HOUR (6.5) },/* North Sumatra */
+  { "sst",     T_ZONE,     -HOUR (7) },        /* South Sumatra, USSR Zone 6 */
+#endif /* 0 */
+  { "wast",    T_ZONE,     -HOUR (7) },        /* West Australian Standard */
+  { "wadt",    T_DAYZONE,  -HOUR (7) },        /* West Australian Daylight */
+#if 0
+  { "jt",      T_ZONE,     -HOUR (7.5) },/* Java (3pm in Cronusland!) */
+#endif
+  { "cct",     T_ZONE,     -HOUR (8) },        /* China Coast, USSR Zone 7 */
+  { "jst",     T_ZONE,     -HOUR (9) },        /* Japan Standard, USSR Zone 8 
*/
+#if 0
+  { "cast",    T_ZONE,     -HOUR (9.5) },/* Central Australian Standard */
+  { "cadt",    T_DAYZONE,  -HOUR (9.5) },/* Central Australian Daylight */
+#endif
+  { "east",    T_ZONE,     -HOUR (10) },       /* Eastern Australian Standard 
*/
+  { "eadt",    T_DAYZONE,  -HOUR (10) },       /* Eastern Australian Daylight 
*/
+  { "gst",     T_ZONE,     -HOUR (10) },       /* Guam Standard, USSR Zone 9 */
+  { "nzt",     T_ZONE,     -HOUR (12) },       /* New Zealand */
+  { "nzst",    T_ZONE,     -HOUR (12) },       /* New Zealand Standard */
+  { "nzdt",    T_DAYZONE,  -HOUR (12) },       /* New Zealand Daylight */
+  { "idle",    T_ZONE,     -HOUR (12) },       /* International Date Line
+                                                  East */
+  {  NULL, 0, 0  }
+};
+
+/* Military timezone table. */
+static SYMBOL const mil_tz_tab[] = {
+  { "a",       T_ZONE, HOUR (  1) },
+  { "b",       T_ZONE, HOUR (  2) },
+  { "c",       T_ZONE, HOUR (  3) },
+  { "d",       T_ZONE, HOUR (  4) },
+  { "e",       T_ZONE, HOUR (  5) },
+  { "f",       T_ZONE, HOUR (  6) },
+  { "g",       T_ZONE, HOUR (  7) },
+  { "h",       T_ZONE, HOUR (  8) },
+  { "i",       T_ZONE, HOUR (  9) },
+  { "k",       T_ZONE, HOUR ( 10) },
+  { "l",       T_ZONE, HOUR ( 11) },
+  { "m",       T_ZONE, HOUR ( 12) },
+  { "n",       T_ZONE, HOUR (- 1) },
+  { "o",       T_ZONE, HOUR (- 2) },
+  { "p",       T_ZONE, HOUR (- 3) },
+  { "q",       T_ZONE, HOUR (- 4) },
+  { "r",       T_ZONE, HOUR (- 5) },
+  { "s",       T_ZONE, HOUR (- 6) },
+  { "t",       T_ZONE, HOUR (- 7) },
+  { "u",       T_ZONE, HOUR (- 8) },
+  { "v",       T_ZONE, HOUR (- 9) },
+  { "w",       T_ZONE, HOUR (-10) },
+  { "x",       T_ZONE, HOUR (-11) },
+  { "y",       T_ZONE, HOUR (-12) },
+  { "z",       T_ZONE, HOUR (  0) },
+  { NULL, 0, 0 }
+};
+
+
+
+
+/* ARGSUSED */
+static int
+yyerror (char *s MU_ARG_UNUSED)
+{
+  return 0;
+}
+
+static int
+norm_hour (int hours, MERIDIAN meridian)
+{
+  switch (meridian)
+    {
+    case MER24:
+      if (hours < 0 || hours > 23)
+       return -1;
+      return hours;
+      
+    case MERam:
+      if (hours < 1 || hours > 12)
+       return -1;
+      if (hours == 12)
+       hours = 0;
+      return hours;
+      
+    case MERpm:
+      if (hours < 1 || hours > 12)
+       return -1;
+      if (hours == 12)
+       hours = 0;
+      return hours + 12;
+      
+    default:
+      abort ();
+    }
+  /* NOTREACHED */
+}
+
+static int
+norm_year (int year)
+{
+  if (year < 0)
+    year = -year;
+  
+  /* XPG4 suggests that years 00-68 map to 2000-2068, and
+     years 69-99 map to 1969-1999.  */
+  if (year < 69)
+    year += 2000;
+  else if (year < 100)
+    year += 1900;
+
+  return year;
+}
+
+static int
+sym_lookup (char *buff)
+{
+  register char *p;
+  register char *q;
+  register const SYMBOL *tp;
+  int i;
+  int abbrev;
+  
+  /* Make it lowercase. */
+  for (p = buff; *p; p++)
+    if (ISUPPER ((unsigned char) *p))
+      *p = tolower (*p);
+  
+  if (strcmp (buff, "am") == 0 || strcmp (buff, "a.m.") == 0)
+    {
+      yylval.meridian = MERam;
+      return T_MERIDIAN;
+    }
+  if (strcmp (buff, "pm") == 0 || strcmp (buff, "p.m.") == 0)
+    {
+      yylval.meridian = MERpm;
+      return T_MERIDIAN;
+    }
+  
+  /* See if we have an abbreviation for a month. */
+  if (strlen (buff) == 3)
+    abbrev = 1;
+  else if (strlen (buff) == 4 && buff[3] == '.')
+    {
+      abbrev = 1;
+      buff[3] = '\0';
+    }
+  else
+    abbrev = 0;
+
+  for (tp = month_day_tab; tp->name; tp++)
+    {
+      if (abbrev)
+       {
+         if (strncmp (buff, tp->name, 3) == 0)
+           {
+             yylval.number = tp->value;
+             return tp->type;
+           }
+       }
+      else if (strcmp (buff, tp->name) == 0)
+       {
+         yylval.number = tp->value;
+         return tp->type;
+       }
+    }
+
+  for (tp = tz_tab; tp->name; tp++)
+    if (strcmp (buff, tp->name) == 0)
+      {
+       yylval.number = tp->value;
+       return tp->type;
+      }
+
+  if (strcmp (buff, "dst") == 0)
+    return T_DST;
+
+  for (tp = units_tab; tp->name; tp++)
+    if (strcmp (buff, tp->name) == 0)
+      {
+       yylval.number = tp->value;
+       return tp->type;
+      }
+
+  /* Strip off any plural and try the units table again. */
+  i = strlen (buff) - 1;
+  if (buff[i] == 's')
+    {
+      buff[i] = '\0';
+      for (tp = units_tab; tp->name; tp++)
+       if (strcmp (buff, tp->name) == 0)
+         {
+           yylval.number = tp->value;
+           return tp->type;
+         }
+      buff[i] = 's';           /* Put back for "this" in other_tab. */
+    }
+
+  for (tp = other_tab; tp->name; tp++)
+    if (strcmp (buff, tp->name) == 0)
+      {
+       yylval.number = tp->value;
+       return tp->type;
+      }
+
+  /* Military timezones. */
+  if (buff[1] == '\0' && ISALPHA ((unsigned char) *buff))
+    {
+      for (tp = mil_tz_tab; tp->name; tp++)
+       if (strcmp (buff, tp->name) == 0)
+         {
+           yylval.number = tp->value;
+           return tp->type;
+         }
+    }
+
+  /* Drop out any periods and try the timezone table again. */
+  for (i = 0, p = q = buff; *q; q++)
+    if (*q != '.')
+      *p++ = *q;
+    else
+      i++;
+  *p = '\0';
+  if (i)
+    for (tp = tz_tab; tp->name; tp++)
+      if (strcmp (buff, tp->name) == 0)
+       {
+         yylval.number = tp->value;
+         return tp->type;
+       }
+
+  return T_ID;
+}
+
+static int
+yylex ()
+{
+  register unsigned char c;
+  register char *p;
+  char buff[20];
+  int count;
+  int sign;
+
+  for (;;)
+    {
+      while (ISSPACE ((unsigned char) *yyinput))
+       yyinput++;
+
+      if (ISDIGIT (c = *yyinput) || c == '-' || c == '+')
+       {
+         if (c == '-' || c == '+')
+           {
+             sign = c == '-' ? -1 : 1;
+             if (!ISDIGIT (*++yyinput))
+               /* skip the '-' sign */
+               continue;
+           }
+         else
+           sign = 0;
+         for (yylval.number = 0; ISDIGIT (c = *yyinput++);)
+           yylval.number = 10 * yylval.number + c - '0';
+         yyinput--;
+         if (sign < 0)
+           yylval.number = -yylval.number;
+         return sign ? T_SNUMBER : T_UNUMBER;
+       }
+      if (ISALPHA (c))
+       {
+         for (p = buff; (c = *yyinput++, ISALPHA (c)) || c == '.';)
+           if (p < &buff[sizeof buff - 1])
+             *p++ = c;
+         *p = '\0';
+         yyinput--;
+         return sym_lookup (buff);
+       }
+      if (c != '(')
+       return *yyinput++;
+      count = 0;
+      do
+       {
+         c = *yyinput++;
+         if (c == '\0')
+           return c;
+         if (c == '(')
+           count++;
+         else if (c == ')')
+           count--;
+       }
+      while (count > 0);
+    }
+}
+
+#define TM_YEAR_ORIGIN 1900
+
+/* Yield A - B, measured in seconds.  */
+static long
+difftm (struct tm *a, struct tm *b)
+{
+  int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
+  int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
+  long days = (
+  /* difference in day of year */
+               a->tm_yday - b->tm_yday
+  /* + intervening leap days */
+               + ((ay >> 2) - (by >> 2))
+               - (ay / 100 - by / 100)
+               + ((ay / 100 >> 2) - (by / 100 >> 2))
+  /* + difference in years * 365 */
+               + (long) (ay - by) * 365
+  );
+  return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour))
+               + (a->tm_min - b->tm_min))
+         + (a->tm_sec - b->tm_sec));
+}
+
+int
+mu_parse_date (const char *p, time_t *rettime, const time_t *now)
+{
+  struct tm tm, tm0, *tmp;
+  time_t start;
+
+  yyinput = p;
+  start = now ? *now : time ((time_t *) NULL);
+  tmp = localtime (&start);
+  if (!tmp)
+    return -1;
+
+  memset (&tm, 0, sizeof tm);
+  tm.tm_isdst = tmp->tm_isdst;
+
+  if (yyparse ())
+    return -1;
+  
+  if (!MASK_IS_SET (pd.date.mask, PD_MASK_YEAR))
+    __SET_YEAR (pd.date, tmp->tm_year + TM_YEAR_ORIGIN, return -1);
+  if (!MASK_IS_SET (pd.date.mask, PD_MASK_MONTH))
+    __SET_MONTH (pd.date, tmp->tm_mon + 1, return -1);
+  if (!MASK_IS_SET (pd.date.mask, PD_MASK_DAY))
+    __SET_DAY (pd.date, tmp->tm_mday, return -1);
+  if (!MASK_IS_SET (pd.date.mask, PD_MASK_HOUR))
+    __SET_HOUR (pd.date, tmp->tm_hour, return -1);
+  if (!MASK_IS_SET (pd.date.mask, PD_MASK_MERIDIAN))
+    __SET_MERIDIAN (pd.date, MER24, return -1);
+  if (!MASK_IS_SET (pd.date.mask, PD_MASK_MINUTE))
+    __SET_MINUTE (pd.date, tmp->tm_min, return -1);
+  if (!MASK_IS_SET (pd.date.mask, PD_MASK_SECOND))
+    __SET_SECOND (pd.date, tmp->tm_sec, return -1);
+  
+  tm.tm_year = norm_year (pd.date.year) - TM_YEAR_ORIGIN + pd.rel.year;
+  tm.tm_mon = pd.date.month - 1 + pd.rel.month;
+  tm.tm_mday = pd.date.day + pd.rel.day;
+  if (MASK_TEST (pd.date.mask, PD_MASK_TIME)
+      || (pd.rel.mask && !MASK_TEST (pd.date.mask, PD_MASK_DATE)
+         && !MASK_TEST (pd.date.mask, PD_MASK_DOW)))
+    {
+      tm.tm_hour = norm_hour (pd.date.hour, pd.date.meridian);
+      if (tm.tm_hour < 0)
+       return -1;
+      tm.tm_min = pd.date.minute;
+      tm.tm_sec = pd.date.second;
+    }
+  else
+    {
+      tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
+    }
+  tm.tm_hour += pd.rel.hour;
+  tm.tm_min += pd.rel.minute;
+  tm.tm_sec += pd.rel.second;
+
+  /* Let mktime deduce tm_isdst if we have an absolute timestamp,
+     or if the relative timestamp mentions days, months, or years.  */
+  if (MASK_TEST (pd.date.mask, PD_MASK_DATE | PD_MASK_DOW | PD_MASK_TIME)
+      || MASK_TEST (pd.rel.mask, PD_MASK_DOW | PD_MASK_MONTH | PD_MASK_YEAR))
+    tm.tm_isdst = -1;
+
+  tm0 = tm;
+
+  start = mktime (&tm);
+
+  if (start == (time_t) -1)
+    {
+
+      /* Guard against falsely reporting errors near the time_t boundaries
+         when parsing times in other time zones.  For example, if the min
+         time_t value is 1970-01-01 00:00:00 UTC and we are 8 hours ahead
+         of UTC, then the min localtime value is 1970-01-01 08:00:00; if
+         we apply mktime to 1970-01-01 00:00:00 we will get an error, so
+         we apply mktime to 1970-01-02 08:00:00 instead and adjust the time
+         zone by 24 hours to compensate.  This algorithm assumes that
+         there is no DST transition within a day of the time_t boundaries.  */
+      if (MASK_TEST (pd.date.mask, PD_MASK_TZ))
+       {
+         tm = tm0;
+         if (tm.tm_year <= EPOCH - TM_YEAR_ORIGIN)
+           {
+             tm.tm_mday++;
+             pd.date.tz -= 24 * 60;
+           }
+         else
+           {
+             tm.tm_mday--;
+             pd.date.tz += 24 * 60;
+           }
+         start = mktime (&tm);
+       }
+
+      if (start == (time_t) -1)
+       return -1;
+    }
+
+  if (MASK_TEST (pd.date.mask, PD_MASK_DOW)
+      && !MASK_TEST (pd.date.mask, PD_MASK_DATE))
+    {
+      tm.tm_mday += ((pd.date.number - tm.tm_wday + 7) % 7
+                    + 7 * (pd.date.ordinal - (0 < pd.date.ordinal)));
+      start = mktime (&tm);
+      if (start == (time_t) -1)
+       return -1;
+    }
+  
+  if (MASK_TEST (pd.date.mask, PD_MASK_TZ))
+    {
+      long delta;
+      struct tm *gmt = gmtime (&start);
+      if (gmt)
+       {
+         delta = pd.date.tz * 60L + difftm (&tm, gmt);
+         if ((start + delta < start) != (delta < 0))
+           return -1;          /* time_t overflow */
+         start += delta;
+       }
+    }
+  
+  *rettime = start;
+  return 0;
+}
+
+#ifdef STANDALONE
+int
+main (int argc, char *argv[])
+{
+  char buff[MAX_BUFF_LEN + 1];
+  time_t d;
+
+  if (argc > 1 && strcmp (argv[1], "-d") == 0)
+    yydebug++;
+  printf ("Enter date, or blank line to exit.\n\t> ");
+  fflush (stdout);
+
+  buff[MAX_BUFF_LEN] = 0;
+  while (fgets (buff, MAX_BUFF_LEN, stdin) && buff[0])
+    {
+      if (mu_parse_date (buff, &d, NULL))
+       printf ("Bad format - couldn't convert.\n");
+      else
+       printf ("%s", ctime (&d));
+      printf ("\t> ");
+      fflush (stdout);
+    }
+  exit (0);
+  /* NOTREACHED */
+}
+
+#endif
diff --git a/libmailutils/base/permstr.c b/libmailutils/base/permstr.c
new file mode 100644
index 0000000..ae16ff6
--- /dev/null
+++ b/libmailutils/base/permstr.c
@@ -0,0 +1,127 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2008, 2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <mailutils/stream.h>
+#include <mailutils/mutil.h>
+#include <mailutils/errno.h>
+
+#define FILE_PERM_READ 0x1
+#define FILE_PERM_WRITE 0x2
+
+static int
+parse_perm_bits (int *pmode, const char *str, const char **endp)
+{
+  switch (*str)
+    {
+    case '+':
+    case '=':
+      str++;
+      break;
+
+    default:
+      if (endp)
+       *endp = str;
+      return 1;
+    }
+
+  for (; *str; str++)
+    {
+      switch (*str)
+       {
+       case 'r':
+         *pmode |= FILE_PERM_READ;
+         break;
+
+       case 'w':
+         *pmode |= FILE_PERM_WRITE;
+         break;
+
+       case ',':
+         if (endp)
+           *endp = str;
+         return 0;
+         
+       default:
+         if (endp)
+           *endp = str;
+         return 1;
+       }
+    }
+  if (endp)
+    *endp = str;
+  return 0;
+}
+
+/* Parse a MU stream permission specification in form:
+
+      g(+|=)[wr]+,o(+|=)[wr]+
+
+   Return 0 on success.
+   On failure, return MU_ERR_FAILURE and point endp to the offending character.
+*/
+int
+mu_parse_stream_perm_string (int *pmode, const char *str, const char **endp)
+{
+  int mode = 0;
+  int f;
+  while (*str)
+    {
+      switch (*str)
+       {
+       case 'g':
+         if (parse_perm_bits (&f, str + 1, &str))
+           {
+             if (endp)
+               *endp = str;
+             return MU_ERR_FAILURE;
+           }
+         if (f & FILE_PERM_READ)
+           mode |= MU_STREAM_IRGRP;
+         if (f & FILE_PERM_WRITE)
+           mode |= MU_STREAM_IWGRP;
+         break;
+         
+       case 'o':
+         if (parse_perm_bits (&f, str + 1, &str))
+           {
+             if (endp)
+               *endp = str;
+             return MU_ERR_FAILURE;
+           }
+         if (f & FILE_PERM_READ)
+           mode |= MU_STREAM_IROTH;
+         if (f & FILE_PERM_WRITE)
+           mode |= MU_STREAM_IWOTH;
+         break;
+         
+       default:
+         if (endp)
+           *endp = str;
+         return MU_ERR_FAILURE;
+       }
+      if (*str == ',')
+       str++;
+    }
+  *pmode = mode;
+  if (endp)
+    *endp = str;
+  return 0;
+}
+      
diff --git a/libmailutils/base/property.c b/libmailutils/base/property.c
new file mode 100644
index 0000000..eec0ddc
--- /dev/null
+++ b/libmailutils/base/property.c
@@ -0,0 +1,191 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2008, 2010 Free
+   Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/sys/property.h>
+#include <mailutils/errno.h>
+#include <mailutils/assoc.h>
+#include <stdlib.h>
+
+static void
+prop_free_value (void *data)
+{
+  struct property_item *item = data;
+  free (item->value);
+}
+
+int
+mu_property_create (mu_property_t *pp, void *owner)
+{
+  int rc;
+  mu_property_t prop;
+  if (pp == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  prop = calloc (1, sizeof *prop);
+  if (prop == NULL)
+    return ENOMEM;
+  rc = mu_assoc_create (&prop->assoc, sizeof (struct property_item), 0);
+  if (rc)
+    {
+      free (prop);
+      return rc;
+    }
+  mu_assoc_set_free (prop->assoc, prop_free_value);
+  mu_monitor_create (&prop->lock, 0, prop);
+  prop->owner = owner;
+  *pp = prop;
+  return 0;
+}
+
+void
+mu_property_destroy (mu_property_t *pp, void *owner)
+{
+  if (pp && *pp)
+    {
+      mu_property_t prop = *pp;
+      if (prop->owner == owner)
+       {
+         /* Destroy the list and is properties.  */
+         mu_monitor_wrlock (prop->lock);
+         mu_assoc_destroy (&prop->assoc);
+         mu_monitor_unlock (prop->lock);
+         mu_monitor_destroy (&prop->lock, prop);
+         free (prop);
+       }
+      *pp = NULL;
+    }
+}
+
+void *
+mu_property_get_owner (mu_property_t prop)
+{
+  return (prop == NULL) ? NULL : prop->owner;
+}
+
+int
+mu_property_set_value (mu_property_t prop, const char *key, const char *value,
+                      int overwrite)
+{
+  struct property_item *item;
+  int rc;
+
+  if (!prop)
+    return EINVAL;
+  rc = mu_assoc_ref_install (prop->assoc, key, (void **)&item);
+  if (rc == MU_ERR_NOENT)
+    {
+      item->value = strdup (value);
+    }
+  else if (overwrite)
+    {
+      free (item->value);
+      item->value = strdup (value);
+    }
+  else
+    return 0;
+  
+  if (!item->value)
+    {
+      mu_assoc_remove (prop->assoc, key);
+      return ENOMEM;
+    }
+
+  return 0;
+}
+  
+int
+mu_property_sget_value (mu_property_t prop, const char *key,
+                       const char **buffer)
+{
+  struct property_item *item;
+
+  if (!prop)
+    return EINVAL;
+  item = mu_assoc_ref (prop->assoc, key);
+  if (item == NULL)
+    return MU_ERR_NOENT;
+  if (buffer)
+    *buffer = item->value;
+  return 0;
+}
+
+int
+mu_property_aget_value (mu_property_t prop, const char *key,
+                       char **buffer)
+{
+  const char *value;
+  int rc = mu_property_sget_value (prop, key, &value);
+  if (rc == 0)
+    {
+      if ((*buffer = strdup (value)) == NULL)
+       return ENOMEM;
+    }
+  return rc;
+}
+
+int
+mu_property_get_value (mu_property_t prop, const char *key, char *buffer,
+                      size_t buflen, size_t *n)
+{
+  size_t len = 0;
+  const char *value;
+  int rc = mu_property_sget_value (prop, key, &value);
+  if (rc == 0)
+    {
+      len = strlen (value) + 1;
+      if (buffer && buflen)
+       {
+         if (buflen < len)
+           len = buflen;
+         len--;
+         memcpy (buffer, value, len);
+         buffer[len] = 0;
+       }
+    }
+  if (n)
+    *n = len;
+  return rc;
+}
+
+int
+mu_property_is_set (mu_property_t prop, const char *key)
+{
+  struct property_item *item = mu_assoc_ref (prop->assoc, key);
+  return (item == NULL) ? 0 : 1;
+}
+
+int
+mu_property_set (mu_property_t prop, const char *key)
+{
+  return mu_property_set_value (prop, key, "", 1);
+}
+
+int
+mu_property_unset (mu_property_t prop, const char *key)
+{
+  if (!prop)
+    return EINVAL;
+  return mu_assoc_remove (prop->assoc, key);
+}
+  
diff --git a/libmailutils/base/refcount.c b/libmailutils/base/refcount.c
new file mode 100644
index 0000000..6d18373
--- /dev/null
+++ b/libmailutils/base/refcount.c
@@ -0,0 +1,107 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2003, 2004, 2007, 2010 Free Software
+   Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library.  If not,
+   see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <errno.h>
+
+#include <mailutils/errno.h>
+#include <mailutils/monitor.h>
+#include <mailutils/refcount.h>
+
+struct _mu_refcount
+{
+  unsigned int ref;
+  mu_monitor_t lock;
+};
+
+int
+mu_refcount_create (mu_refcount_t *prefcount)
+{
+  int status = 0;
+  mu_refcount_t refcount;
+  if (prefcount == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  refcount = calloc (1, sizeof *refcount);
+  if (refcount != NULL)
+    {
+      refcount->ref = 1;
+      status = mu_monitor_create (&refcount->lock, 0, refcount);
+      if (status == 0)
+       {
+         *prefcount = refcount;
+       }
+      else
+       {
+         free (refcount);
+       }
+    }
+  else
+    {
+      status = ENOMEM;
+    }
+  return status;
+}
+
+unsigned
+mu_refcount_value (mu_refcount_t refcount)
+{
+  return refcount ? refcount->ref : 0;
+}
+
+void
+mu_refcount_destroy (mu_refcount_t *prefcount)
+{
+  if (prefcount && *prefcount)
+    {
+      mu_refcount_t refcount = *prefcount;
+      mu_monitor_destroy (&refcount->lock, refcount);
+      free (refcount);
+      *prefcount = NULL;
+    }
+}
+
+unsigned
+mu_refcount_inc (mu_refcount_t refcount)
+{
+  int count = 0;
+  if (refcount)
+    {
+      mu_monitor_wrlock (refcount->lock);
+      count = ++refcount->ref;
+      mu_monitor_unlock (refcount->lock);
+    }
+  return count;
+}
+
+unsigned
+mu_refcount_dec (mu_refcount_t refcount)
+{
+  int count = 0;
+  if (refcount)
+    {
+      mu_monitor_wrlock (refcount->lock);
+      if (refcount->ref)
+       count = --refcount->ref;
+      mu_monitor_unlock (refcount->lock);
+    }
+  return count;
+}
diff --git a/libmailutils/base/registrar.c b/libmailutils/base/registrar.c
new file mode 100644
index 0000000..33782e9
--- /dev/null
+++ b/libmailutils/base/registrar.c
@@ -0,0 +1,442 @@
+/* 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/>. */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/iterator.h>
+#include <mailutils/list.h>
+#include <mailutils/monitor.h>
+#include <mailutils/errno.h>
+#include <mailutils/nls.h>
+#include <mailutils/error.h>
+#include <mailutils/url.h>
+#include <mailutils/mutil.h>
+#include <mailutils/sys/registrar.h>
+
+/* NOTE: We will leak here since the monitor and the registrar will never
+   be released. That's ok we can live with this, it's only done once.  */
+static mu_list_t registrar_list;
+struct mu_monitor registrar_monitor = MU_MONITOR_INITIALIZER;
+
+static mu_record_t mu_default_record;
+
+void
+mu_registrar_set_default_record (mu_record_t record)
+{
+  mu_default_record = record;
+}
+
+int
+mu_registrar_get_default_record (mu_record_t *prec)
+{
+  if (mu_default_record)
+    {
+      if (prec)
+       *prec = mu_default_record;
+      return 0;
+    }
+  return MU_ERR_NOENT;
+}
+
+int
+mu_registrar_set_default_scheme (const char *scheme)
+{
+  int status;
+  mu_record_t rec;
+  
+  status = mu_registrar_lookup_scheme (scheme, &rec);
+  if (status == 0)
+    mu_default_record = rec;
+  return status;
+}
+
+const char *
+mu_registrar_get_default_scheme ()
+{
+  return mu_default_record ? mu_default_record->scheme : NULL;
+}
+
+static int
+_registrar_get_list (mu_list_t *plist)
+{
+  int status = 0;
+
+  if (plist == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  mu_monitor_wrlock (&registrar_monitor);
+  if (registrar_list == NULL)
+    status = mu_list_create (&registrar_list);
+  *plist = registrar_list;
+  mu_monitor_unlock (&registrar_monitor);
+  return status;
+}
+
+/* Provided for backward compatibility */
+int
+mu_registrar_get_list (mu_list_t *plist)
+{
+  static int warned;
+
+  if (!warned)
+    {
+      mu_error (_("program uses mu_registrar_get_list(), which is 
deprecated"));
+      warned = 1;
+    }
+  return _registrar_get_list (plist);
+}
+
+int
+mu_registrar_get_iterator (mu_iterator_t *pitr)
+{
+  int status = 0;
+  if (pitr == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  mu_monitor_wrlock (&registrar_monitor);
+  if (registrar_list == NULL)
+    {
+      status = mu_list_create (&registrar_list);
+      if (status)
+       return status;
+    }
+  status = mu_list_get_iterator (registrar_list, pitr);
+  mu_monitor_unlock (&registrar_monitor);
+  return status;
+}
+
+int
+mu_registrar_lookup_scheme (const char *scheme, mu_record_t *precord)
+{
+  size_t len;
+  mu_iterator_t iterator;
+  int status = mu_registrar_get_iterator (&iterator);
+  if (status != 0)
+    return status;
+  status = MU_ERR_NOENT;
+  len = strcspn (scheme, ":");
+  for (mu_iterator_first (iterator); !mu_iterator_is_done (iterator);
+       mu_iterator_next (iterator))
+    {
+      mu_record_t record;
+      mu_iterator_current (iterator, (void **)&record);
+      if (strlen (record->scheme) == len
+         && memcmp (record->scheme, scheme, len) == 0)
+       {
+         if (precord)
+           *precord = record;
+         status = 0;
+         break;
+       }
+    }
+  mu_iterator_destroy (&iterator);
+  return status;
+}
+
+int
+mu_registrar_lookup_url (mu_url_t url, int flags,
+                        mu_record_t *precord, int *pflags)
+{
+  mu_iterator_t iterator;
+  mu_record_t last_record = NULL;
+  int last_flags = 0;
+  int status = mu_registrar_get_iterator (&iterator);
+  if (status != 0)
+    return status;
+  status = MU_ERR_NOENT;
+  for (mu_iterator_first (iterator); !mu_iterator_is_done (iterator);
+       mu_iterator_next (iterator))
+    {
+      int rc;
+      mu_record_t record;
+      mu_iterator_current (iterator, (void **)&record);
+      if ((rc = mu_record_is_scheme (record, url, flags)))
+       {
+         if (rc == flags)
+           {
+             status = 0;
+             last_record = record;
+             last_flags = rc;
+             break;
+           }
+         else if (rc > last_flags)
+           {
+             status = 0;
+             last_record = record;
+             last_flags = rc;
+           }
+       }
+    }
+  mu_iterator_destroy (&iterator);
+
+  if (status == 0)
+    {
+      if (precord)
+       *precord = last_record;
+      if (pflags)
+       *pflags = last_flags;
+    }
+  else if (!mu_is_proto (mu_url_to_string (url)) /* FIXME: This check is not
+                                                   enough. */
+          && mu_registrar_get_default_record (precord) == 0)
+    {
+      status = 0;
+      if (pflags)
+       *pflags = flags & MU_FOLDER_ATTRIBUTE_FILE; /* FIXME? */
+    }
+  
+  return status;
+}
+
+int
+mu_registrar_lookup (const char *name, int flags,
+                    mu_record_t *precord, int *pflags)
+{
+  int rc;
+  mu_url_t url;
+  
+  rc = mu_url_create (&url, name);
+  if (rc)
+    return rc;
+  rc = mu_url_parse (url);
+  if (rc == 0)
+    rc = mu_registrar_lookup_url (url, flags, precord, pflags);
+  mu_url_destroy (&url);
+  return rc;
+}
+
+static int
+_compare_prio (const void *item, const void *value)
+{
+  const mu_record_t a = (const mu_record_t) item;
+  const mu_record_t b = (const mu_record_t) value;
+  if (a->priority > b->priority)
+    return 0;
+  return -1;
+}
+
+int
+mu_registrar_record (mu_record_t record)
+{
+  int status;
+  mu_list_t list;
+  mu_list_comparator_t comp;
+  
+  if (!record)
+    return 0;
+  _registrar_get_list (&list);
+  comp = mu_list_set_comparator (list, _compare_prio);
+  status = mu_list_insert (list, record, record, 1);
+  if (status == MU_ERR_NOENT)
+    status = mu_list_append (list, record);
+  mu_list_set_comparator (list, comp);
+  return status;
+}
+
+int
+mu_unregistrar_record (mu_record_t record)
+{
+  mu_list_t list;
+  _registrar_get_list (&list);
+  mu_list_remove (list, record);
+  return 0;
+}
+
+int
+mu_record_is_scheme (mu_record_t record, mu_url_t url, int flags)
+{
+  if (record == NULL)
+    return 0;
+
+  /* Overload.  */
+  if (record->_is_scheme)
+    return record->_is_scheme (record, url, flags);
+
+  if (mu_url_is_scheme (url, record->scheme))
+    return MU_FOLDER_ATTRIBUTE_ALL;
+
+  return 0;
+}
+
+int
+mu_record_set_scheme (mu_record_t record, const char *scheme)
+{
+  if (record == NULL)
+    return EINVAL;
+  record->scheme = scheme;
+  return 0;
+}
+
+int
+mu_record_set_is_scheme (mu_record_t record,
+                        int (*_is_scheme) (mu_record_t, mu_url_t, int))
+{
+  if (record == NULL)
+    return EINVAL;
+  record->_is_scheme = _is_scheme;
+  return 0;
+}
+
+int
+mu_record_get_url (mu_record_t record, int (*(*_purl)) (mu_url_t))
+{
+  if (record == NULL)
+    return EINVAL;
+  if (_purl == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  /* Overload.  */
+  if (record->_get_url)
+    return record->_get_url (record, _purl);
+  *_purl = record->_url;
+  return 0;
+}
+
+int
+mu_record_set_url (mu_record_t record, int (*_mu_url) (mu_url_t))
+{
+  if (record == NULL)
+    return EINVAL;
+  record->_url = _mu_url;
+  return 0;
+}
+
+int
+mu_record_set_get_url (mu_record_t record, int (*_get_url)
+                   (mu_record_t, int (*(*)) (mu_url_t)))
+{
+  if (record == NULL)
+    return EINVAL;
+  record->_get_url = _get_url;
+  return 0;
+}
+
+int
+mu_record_get_mailbox (mu_record_t record, int (*(*_pmailbox)) (mu_mailbox_t))
+{
+  if (record == NULL)
+    return EINVAL;
+  if (_pmailbox == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  /* Overload.  */
+  if (record->_get_mailbox)
+    return record->_get_mailbox (record, _pmailbox);
+  *_pmailbox = record->_mailbox;
+  return 0;
+}
+
+int
+mu_record_set_mailbox (mu_record_t record, int (*_mu_mailbox) (mu_mailbox_t))
+{
+  if (record)
+    return EINVAL;
+  record->_mailbox = _mu_mailbox;
+  return 0;
+}
+
+int
+mu_record_set_get_mailbox (mu_record_t record, 
+     int (*_get_mailbox) (mu_record_t, int (*(*)) (mu_mailbox_t)))
+{
+  if (record)
+    return EINVAL;
+  record->_get_mailbox = _get_mailbox;
+  return 0;
+}
+
+int
+mu_record_get_mailer (mu_record_t record, int (*(*_pmailer)) (mu_mailer_t))
+{
+  if (record == NULL)
+    return EINVAL;
+  if (_pmailer == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  /* Overload.  */
+  if (record->_get_mailer)
+    return record->_get_mailer (record, _pmailer);
+  *_pmailer = record->_mailer;
+  return 0;
+}
+
+int
+mu_record_set_mailer (mu_record_t record, int (*_mu_mailer) (mu_mailer_t))
+{
+  if (record)
+    return EINVAL;
+  record->_mailer = _mu_mailer;
+  return 0;
+}
+
+int
+mu_record_set_get_mailer (mu_record_t record, 
+  int (*_get_mailer) (mu_record_t, int (*(*)) (mu_mailer_t)))
+{
+  if (record == NULL)
+    return EINVAL;
+  record->_get_mailer = _get_mailer;
+  return 0;
+}
+
+int
+mu_record_get_folder (mu_record_t record, int (*(*_pfolder)) (mu_folder_t))
+{
+  if (record == NULL)
+    return EINVAL;
+  if (_pfolder == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  /* Overload.  */
+  if (record->_get_folder)
+    return record->_get_folder (record, _pfolder);
+  *_pfolder = record->_folder;
+  return 0;
+}
+
+int
+mu_record_set_folder (mu_record_t record, int (*_mu_folder) (mu_folder_t))
+{
+  if (record == NULL)
+    return EINVAL;
+  record->_folder = _mu_folder;
+  return 0;
+}
+
+int
+mu_record_set_get_folder (mu_record_t record, 
+   int (*_get_folder) (mu_record_t, int (*(*)) (mu_folder_t)))
+{
+  if (record == NULL)
+    return EINVAL;
+  record->_get_folder = _get_folder;
+  return 0;
+}
+
+int
+mu_record_list_p (mu_record_t record, const char *name, int flags)
+{
+  if (record == NULL)
+    return EINVAL;
+  return record == NULL
+          || !record->_list_p
+          || record->_list_p (record, name, flags);
+}
diff --git a/libmailutils/base/rfc2047.c b/libmailutils/base/rfc2047.c
new file mode 100644
index 0000000..32b0923
--- /dev/null
+++ b/libmailutils/base/rfc2047.c
@@ -0,0 +1,313 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2003, 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/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <ctype.h>
+#include <mailutils/stream.h>
+#include <mailutils/filter.h>
+#include <mailutils/errno.h>
+#include <mailutils/mutil.h>
+
+static int
+realloc_buffer (char **bufp, size_t *bufsizep, size_t incr)
+{
+  size_t newsize = *bufsizep + incr;
+  char *newp = realloc (*bufp, newsize);
+  if (newp == NULL)
+    return 1;
+  *bufp = newp;
+  *bufsizep = newsize;
+  return 0;
+}
+
+int
+getword (char **pret, const char **pstr, int delim)
+{
+  size_t len;
+  char *ret;
+  const char *start = *pstr;
+  const char *end = strchr (start, delim);
+
+  free (*pret);
+  *pret = NULL;
+  if (!end)
+    return MU_ERR_BAD_2047_INPUT;
+  len = end - start;
+  ret = malloc (len + 1);
+  if (!ret)
+    return ENOMEM;
+  memcpy (ret, start, len);
+  ret[len] = 0;
+  *pstr = end + 1;
+  *pret = ret;
+  return 0;
+}
+    
+int
+mu_rfc2047_decode (const char *tocode, const char *input, char **ptostr)
+{
+  int status = 0;
+  const char *fromstr;
+  char *buffer;
+  size_t bufsize;
+  size_t bufpos;
+  size_t run_count = 0;
+  char *fromcode = NULL;
+  char *encoding_type = NULL;
+  char *encoded_text = NULL;
+
+#define BUFINC 128  
+#define CHKBUF(count) do {                       \
+  if (bufpos+count >= bufsize)                   \
+    {                                            \
+      size_t s = bufpos + count - bufsize;       \
+      if (s < BUFINC)                            \
+        s = BUFINC;                              \
+      if (realloc_buffer (&buffer, &bufsize, s)) \
+       {                                        \
+         free (buffer);                         \
+          free (fromcode);                       \
+          free (encoding_type);                  \
+          free (encoded_text);                   \
+         return ENOMEM;                         \
+       }                                        \
+     }                                           \
+ } while (0) 
+  
+  if (!input)
+    return EINVAL;
+  if (!ptostr)
+    return MU_ERR_OUT_PTR_NULL;
+
+  fromstr = input;
+
+  /* Allocate the buffer. It is assumed that encoded string is always
+     longer than it's decoded variant, so it's safe to use its length
+     as the first estimate */
+  bufsize = strlen (fromstr) + 1;
+  buffer = malloc (bufsize);
+  if (buffer == NULL)
+    return ENOMEM;
+  bufpos = 0;
+  
+  while (*fromstr)
+    {
+      if (strncmp (fromstr, "=?", 2) == 0)
+       {
+         mu_stream_t filter = NULL;
+         mu_stream_t in_stream = NULL;
+         const char *filter_type = NULL;
+         size_t nbytes = 0, size;
+         const char *sp = fromstr + 2;
+         char tmp[128];
+         
+         status = getword (&fromcode, &sp, '?');
+         if (status)
+           break;
+         status = getword (&encoding_type, &sp, '?');
+         if (status)
+           break;
+         status = getword (&encoded_text, &sp, '?');
+         if (status)
+           break;
+         if (sp == NULL || sp[0] != '=')
+           {
+             status = MU_ERR_BAD_2047_INPUT;
+             break;
+           }
+      
+         size = strlen (encoded_text);
+
+         switch (encoding_type[0])
+           {
+            case 'b':
+           case 'B':
+             filter_type = "base64";
+             break;
+            
+            case 'q': 
+           case 'Q':
+             filter_type = "Q";
+             break;
+
+           default:
+             status = MU_ERR_BAD_2047_INPUT;
+             break;
+           }
+         
+         if (status != 0)
+           break;
+
+         mu_memory_stream_create (&in_stream, 0);
+         mu_stream_write (in_stream, encoded_text, size, NULL);
+         mu_stream_seek (in_stream, 0, MU_SEEK_SET, NULL);
+         status = mu_decode_filter (&filter, in_stream, filter_type, fromcode,
+                                    tocode);
+         mu_stream_unref (in_stream);
+         if (status != 0)
+           break;
+
+         while (mu_stream_read (filter, tmp, sizeof (tmp), &nbytes) == 0
+                && nbytes)
+           {
+             CHKBUF (nbytes);
+             memcpy (buffer + bufpos, tmp, nbytes);
+             bufpos += nbytes;
+           }
+
+         mu_stream_close (filter);
+         mu_stream_destroy (&filter);
+         
+         fromstr = sp + 1;
+         run_count = 1;
+       }
+      else if (run_count)
+       {
+         if (*fromstr == ' ' || *fromstr == '\t')
+           {
+             run_count++;
+             fromstr++;
+             continue;
+           }
+         else
+           {
+             if (--run_count)
+               {
+                 CHKBUF (run_count);
+                 memcpy (buffer + bufpos, fromstr - run_count, run_count);
+                 bufpos += run_count;
+                 run_count = 0;
+               }
+             CHKBUF (1);
+             buffer[bufpos++] = *fromstr++;
+           }
+       }
+      else
+       {
+         CHKBUF (1);
+         buffer[bufpos++] = *fromstr++;
+       }
+    }
+  
+  if (*fromstr)
+    {
+      size_t len = strlen (fromstr);
+      CHKBUF (len);
+      memcpy (buffer + bufpos, fromstr, len);
+      bufpos += len;
+    }
+
+  CHKBUF (1);
+  buffer[bufpos++] = 0;
+  
+  free (fromcode);
+  free (encoding_type);
+  free (encoded_text);
+
+  if (status)
+    free (buffer);
+  else
+    *ptostr = realloc (buffer, bufpos);
+  return status;
+}
+
+
+/**
+   Encode a header according to RFC 2047
+   
+   @param charset
+     Charset of the text to encode
+   @param encoding
+     Requested encoding (must be "base64" or "quoted-printable")
+   @param text
+     Actual text to encode
+   @param result [OUT]
+     Encoded string
+
+   @return 0 on success
+*/
+int
+mu_rfc2047_encode (const char *charset, const char *encoding,
+                  const char *text, char **result)
+{
+  mu_stream_t input_stream;
+  mu_stream_t output_stream;
+  int rc;
+  
+  if (charset == NULL || encoding == NULL || text == NULL)
+    return EINVAL;
+
+  if (strcmp (encoding, "base64") == 0)
+    encoding = "B";
+  else if (strcmp (encoding, "quoted-printable") == 0)
+    encoding = "Q";
+  else if (encoding[1] || !strchr ("BQ", encoding[0]))
+    return MU_ERR_BAD_2047_ENCODING;
+
+  rc = mu_memory_stream_create (&input_stream, 0);
+  if (rc)
+    return rc;
+  
+  mu_stream_write (input_stream, text, strlen (text), NULL);
+  mu_stream_seek (input_stream, 0, MU_SEEK_SET, NULL);
+  rc = mu_filter_create (&output_stream, input_stream,
+                        encoding, MU_FILTER_ENCODE,
+                        MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
+  if (rc == 0)
+    {
+      /* Assume strlen(qp_encoded_text) <= strlen(text) * 3 */
+      /* malloced length is composed of:
+        "=?"  
+        charset 
+        "?"
+        B or Q
+        "?" 
+        encoded_text
+        "?="
+        zero terminator */
+      
+      *result = malloc (2 + strlen (charset) + 3 + strlen (text) * 3 + 3);
+      if (*result)
+       {
+         char *p = *result;
+         size_t s;
+         
+         p += sprintf (p, "=?%s?%s?", charset, encoding);
+         
+         rc = mu_stream_read (output_stream,
+                              p,
+                              strlen (text) * 3, &s);
+
+         strcpy (p + s, "?=");
+       }
+      else
+       rc = ENOMEM;
+      mu_stream_destroy (&output_stream);
+    }
+  else
+    mu_stream_destroy (&input_stream);
+
+  return rc;
+}
diff --git a/libmailutils/base/secret.c b/libmailutils/base/secret.c
new file mode 100644
index 0000000..23b4363
--- /dev/null
+++ b/libmailutils/base/secret.c
@@ -0,0 +1,134 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 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/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/types.h>
+#include <mailutils/secret.h>
+#include <mailutils/errno.h>
+
+struct _mu_secret
+{
+  unsigned int refcnt;      /* Number of references to this object */
+  size_t length;            /* Secret length */
+  unsigned char *obptr;     /* Obfuscated data */
+  unsigned char *clptr;     /* Cleartext data */
+  unsigned int clref;       /* Number of references to clptr returned
+                              this far */
+};
+
+static unsigned char xchar;
+
+static void
+obfuscate (const unsigned char *input, unsigned char *output, size_t len)
+{
+  if (!xchar)
+    xchar = random () % 255;
+  while (len--)
+    *output++ = *input++ ^ xchar;
+}
+  
+int
+mu_secret_create (mu_secret_t *psec, const char *value, size_t len)
+{
+  mu_secret_t sec;
+  sec = calloc (1, sizeof (sec[0]) + 2 * (len + 1));
+  if (!sec)
+    return ENOMEM;
+  sec->obptr = (unsigned char*)(sec + 1);
+  sec->clptr = sec->obptr + len + 1;
+  obfuscate ((unsigned char *) value, sec->obptr, len);
+  sec->length = len;
+  *psec = sec;
+  mu_secret_ref (sec);
+  return 0;
+}
+
+int
+mu_secret_dup (mu_secret_t sec, mu_secret_t *newsec)
+{
+  const char *pass = mu_secret_password (sec);
+  int rc = mu_secret_create (newsec, pass, strlen (pass));
+  mu_secret_password_unref (sec);
+  return rc;
+}
+
+void
+mu_secret_ref (mu_secret_t sec)
+{
+  if (sec)
+    sec->refcnt++;
+}
+
+/* Decrement reference counter in SEC. If it falls to 0, free memory
+   allocated for SEC and return 0. Otherwise, return MU_ERR_EXISTS,
+   indicating that someone else is still holding it.
+   Return EINVAL if sec==NULL. */
+int
+mu_secret_unref (mu_secret_t sec)
+{
+  if (sec)
+    {
+      if (sec->refcnt)
+       sec->refcnt--;
+      if (sec->refcnt == 0)
+       {
+         memset (sec->clptr, 0, sec->length);
+         memset (sec->obptr, 0, sec->length);
+         free (sec);
+         return 0;
+       }
+      return MU_ERR_EXISTS;
+    }
+  return EINVAL;
+}
+
+void
+mu_secret_destroy (mu_secret_t *psec)
+{
+  if (psec && *psec && mu_secret_unref (*psec) == 0)
+    *psec = NULL;
+}
+
+const char *
+mu_secret_password (mu_secret_t sec)
+{
+  if (!sec)
+    return 0;
+  if (sec->clref++ == 0)
+    obfuscate (sec->obptr, sec->clptr, sec->length);
+  return (const char*) sec->clptr;
+}
+
+size_t
+mu_secret_length (mu_secret_t sec)
+{
+  if (!sec)
+    return 0;
+  return sec->length;
+}
+
+void
+mu_secret_password_unref (mu_secret_t sec)
+{
+  if (--sec->clref == 0)
+    memset (sec->clptr, 0, sec->length);
+}
+
diff --git a/libmailutils/base/sha1.c b/libmailutils/base/sha1.c
new file mode 100644
index 0000000..b9531b3
--- /dev/null
+++ b/libmailutils/base/sha1.c
@@ -0,0 +1,417 @@
+/* sha1.c - Functions to compute SHA1 message digest of files or
+   memory blocks according to the NIST specification FIPS-180-1.
+
+   Copyright (C) 2000, 2001, 2003, 2004, 2005, 2006, 2010 Free Software
+   Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by the
+   Free Software Foundation; either version 2, or (at your option) any
+   later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Scott G. Miller
+   Credits:
+      Robert Klep <address@hidden>  -- Expansion function fix
+*/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <mailutils/sha1.h>
+
+#include <stddef.h>
+#include <string.h>
+
+#if USE_UNLOCKED_IO
+# include "unlocked-io.h"
+#endif
+
+#ifdef WORDS_BIGENDIAN
+# define SWAP(n) (n)
+#else
+# define SWAP(n) \
+    (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
+#endif
+
+#define BLOCKSIZE 4096
+#if BLOCKSIZE % 64 != 0
+# error "invalid BLOCKSIZE"
+#endif
+
+/* This array contains the bytes used to pad the buffer to the next
+   64-byte boundary.  (RFC 1321, 3.1: Step 1)  */
+static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ...  */ };
+
+
+/* Take a pointer to a 160 bit block of data (five 32 bit ints) and
+   initialize it to the start constants of the SHA1 algorithm.  This
+   must be called before using hash in the call to sha1_hash.  */
+void
+sha1_init_ctx (struct sha1_ctx *ctx)
+{
+  ctx->A = 0x67452301;
+  ctx->B = 0xefcdab89;
+  ctx->C = 0x98badcfe;
+  ctx->D = 0x10325476;
+  ctx->E = 0xc3d2e1f0;
+
+  ctx->total[0] = ctx->total[1] = 0;
+  ctx->buflen = 0;
+}
+
+/* Put result from CTX in first 20 bytes following RESBUF.  The result
+   must be in little endian byte order.
+
+   IMPORTANT: On some systems it is required that RESBUF is correctly
+   aligned for a 32-bit value.  */
+void *
+sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf)
+{
+  ((uint32_t *) resbuf)[0] = SWAP (ctx->A);
+  ((uint32_t *) resbuf)[1] = SWAP (ctx->B);
+  ((uint32_t *) resbuf)[2] = SWAP (ctx->C);
+  ((uint32_t *) resbuf)[3] = SWAP (ctx->D);
+  ((uint32_t *) resbuf)[4] = SWAP (ctx->E);
+
+  return resbuf;
+}
+
+/* Process the remaining bytes in the internal buffer and the usual
+   prolog according to the standard and write the result to RESBUF.
+
+   IMPORTANT: On some systems it is required that RESBUF is correctly
+   aligned for a 32-bit value.  */
+void *
+sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf)
+{
+  /* Take yet unprocessed bytes into account.  */
+  uint32_t bytes = ctx->buflen;
+  size_t size = (bytes < 56) ? 64 / 4 : 64 * 2 / 4;
+
+  /* Now count remaining bytes.  */
+  ctx->total[0] += bytes;
+  if (ctx->total[0] < bytes)
+    ++ctx->total[1];
+
+  /* Put the 64-bit file length in *bits* at the end of the buffer.  */
+  ctx->buffer[size - 2] = SWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29));
+  ctx->buffer[size - 1] = SWAP (ctx->total[0] << 3);
+
+  memcpy (&((char *) ctx->buffer)[bytes], fillbuf, (size - 2) * 4 - bytes);
+
+  /* Process last bytes.  */
+  sha1_process_block (ctx->buffer, size * 4, ctx);
+
+  return sha1_read_ctx (ctx, resbuf);
+}
+
+/* Compute SHA1 message digest for bytes read from STREAM.  The
+   resulting message digest number will be written into the 16 bytes
+   beginning at RESBLOCK.  */
+int
+sha1_stream (FILE *stream, void *resblock)
+{
+  struct sha1_ctx ctx;
+  char buffer[BLOCKSIZE + 72];
+  size_t sum;
+
+  /* Initialize the computation context.  */
+  sha1_init_ctx (&ctx);
+
+  /* Iterate over full file contents.  */
+  while (1)
+    {
+      /* We read the file in blocks of BLOCKSIZE bytes.  One call of the
+        computation function processes the whole buffer so that with the
+        next round of the loop another block can be read.  */
+      size_t n;
+      sum = 0;
+
+      /* Read block.  Take care for partial reads.  */
+      while (1)
+       {
+         n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
+
+         sum += n;
+
+         if (sum == BLOCKSIZE)
+           break;
+
+         if (n == 0)
+           {
+             /* Check for the error flag IFF N == 0, so that we don't
+                exit the loop after a partial read due to e.g., EAGAIN
+                or EWOULDBLOCK.  */
+             if (ferror (stream))
+               return 1;
+             goto process_partial_block;
+           }
+
+         /* We've read at least one byte, so ignore errors.  But always
+            check for EOF, since feof may be true even though N > 0.
+            Otherwise, we could end up calling fread after EOF.  */
+         if (feof (stream))
+           goto process_partial_block;
+       }
+
+      /* Process buffer with BLOCKSIZE bytes.  Note that
+                       BLOCKSIZE % 64 == 0
+       */
+      sha1_process_block (buffer, BLOCKSIZE, &ctx);
+    }
+
+ process_partial_block:;
+
+  /* Process any remaining bytes.  */
+  if (sum > 0)
+    sha1_process_bytes (buffer, sum, &ctx);
+
+  /* Construct result in desired memory.  */
+  sha1_finish_ctx (&ctx, resblock);
+  return 0;
+}
+
+/* Compute SHA1 message digest for LEN bytes beginning at BUFFER.  The
+   result is always in little endian byte order, so that a byte-wise
+   output yields to the wanted ASCII representation of the message
+   digest.  */
+void *
+sha1_buffer (const char *buffer, size_t len, void *resblock)
+{
+  struct sha1_ctx ctx;
+
+  /* Initialize the computation context.  */
+  sha1_init_ctx (&ctx);
+
+  /* Process whole buffer but last len % 64 bytes.  */
+  sha1_process_bytes (buffer, len, &ctx);
+
+  /* Put result in desired memory area.  */
+  return sha1_finish_ctx (&ctx, resblock);
+}
+
+void
+sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
+{
+  /* When we already have some bits in our internal buffer concatenate
+     both inputs first.  */
+  if (ctx->buflen != 0)
+    {
+      size_t left_over = ctx->buflen;
+      size_t add = 128 - left_over > len ? len : 128 - left_over;
+
+      memcpy (&((char *) ctx->buffer)[left_over], buffer, add);
+      ctx->buflen += add;
+
+      if (ctx->buflen > 64)
+       {
+         sha1_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
+
+         ctx->buflen &= 63;
+         /* The regions in the following copy operation cannot overlap.  */
+         memcpy (ctx->buffer,
+                 &((char *) ctx->buffer)[(left_over + add) & ~63],
+                 ctx->buflen);
+       }
+
+      buffer = (const char *) buffer + add;
+      len -= add;
+    }
+
+  /* Process available complete blocks.  */
+  if (len >= 64)
+    {
+#if !_STRING_ARCH_unaligned
+# define alignof(type) offsetof (struct { char c; type x; }, x)
+# define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0)
+      if (UNALIGNED_P (buffer))
+       while (len > 64)
+         {
+           sha1_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx);
+           buffer = (const char *) buffer + 64;
+           len -= 64;
+         }
+      else
+#endif
+       {
+         sha1_process_block (buffer, len & ~63, ctx);
+         buffer = (const char *) buffer + (len & ~63);
+         len &= 63;
+       }
+    }
+
+  /* Move remaining bytes in internal buffer.  */
+  if (len > 0)
+    {
+      size_t left_over = ctx->buflen;
+
+      memcpy (&((char *) ctx->buffer)[left_over], buffer, len);
+      left_over += len;
+      if (left_over >= 64)
+       {
+         sha1_process_block (ctx->buffer, 64, ctx);
+         left_over -= 64;
+         memcpy (ctx->buffer, &ctx->buffer[16], left_over);
+       }
+      ctx->buflen = left_over;
+    }
+}
+
+/* --- Code below is the primary difference between md5.c and sha1.c --- */
+
+/* SHA1 round constants */
+#define K1 0x5a827999
+#define K2 0x6ed9eba1
+#define K3 0x8f1bbcdc
+#define K4 0xca62c1d6
+
+/* Round functions.  Note that F2 is the same as F4.  */
+#define F1(B,C,D) ( D ^ ( B & ( C ^ D ) ) )
+#define F2(B,C,D) (B ^ C ^ D)
+#define F3(B,C,D) ( ( B & C ) | ( D & ( B | C ) ) )
+#define F4(B,C,D) (B ^ C ^ D)
+
+/* Process LEN bytes of BUFFER, accumulating context into CTX.
+   It is assumed that LEN % 64 == 0.
+   Most of this code comes from GnuPG's cipher/sha1.c.  */
+
+void
+sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx)
+{
+  const uint32_t *words = buffer;
+  size_t nwords = len / sizeof (uint32_t);
+  const uint32_t *endp = words + nwords;
+  uint32_t x[16];
+  uint32_t a = ctx->A;
+  uint32_t b = ctx->B;
+  uint32_t c = ctx->C;
+  uint32_t d = ctx->D;
+  uint32_t e = ctx->E;
+
+  /* First increment the byte count.  RFC 1321 specifies the possible
+     length of the file up to 2^64 bits.  Here we only compute the
+     number of bytes.  Do a double word increment.  */
+  ctx->total[0] += len;
+  if (ctx->total[0] < len)
+    ++ctx->total[1];
+
+#define rol(x, n) (((x) << (n)) | ((uint32_t) (x) >> (32 - (n))))
+
+#define M(I) ( tm =   x[I&0x0f] ^ x[(I-14)&0x0f] \
+                   ^ x[(I-8)&0x0f] ^ x[(I-3)&0x0f] \
+              , (x[I&0x0f] = rol(tm, 1)) )
+
+#define R(A,B,C,D,E,F,K,M)  do { E += rol( A, 5 )     \
+                                     + F( B, C, D )  \
+                                     + K             \
+                                     + M;            \
+                                B = rol( B, 30 );    \
+                              } while(0)
+
+  while (words < endp)
+    {
+      uint32_t tm;
+      int t;
+      for (t = 0; t < 16; t++)
+       {
+         x[t] = SWAP (*words);
+         words++;
+       }
+
+      R( a, b, c, d, e, F1, K1, x[ 0] );
+      R( e, a, b, c, d, F1, K1, x[ 1] );
+      R( d, e, a, b, c, F1, K1, x[ 2] );
+      R( c, d, e, a, b, F1, K1, x[ 3] );
+      R( b, c, d, e, a, F1, K1, x[ 4] );
+      R( a, b, c, d, e, F1, K1, x[ 5] );
+      R( e, a, b, c, d, F1, K1, x[ 6] );
+      R( d, e, a, b, c, F1, K1, x[ 7] );
+      R( c, d, e, a, b, F1, K1, x[ 8] );
+      R( b, c, d, e, a, F1, K1, x[ 9] );
+      R( a, b, c, d, e, F1, K1, x[10] );
+      R( e, a, b, c, d, F1, K1, x[11] );
+      R( d, e, a, b, c, F1, K1, x[12] );
+      R( c, d, e, a, b, F1, K1, x[13] );
+      R( b, c, d, e, a, F1, K1, x[14] );
+      R( a, b, c, d, e, F1, K1, x[15] );
+      R( e, a, b, c, d, F1, K1, M(16) );
+      R( d, e, a, b, c, F1, K1, M(17) );
+      R( c, d, e, a, b, F1, K1, M(18) );
+      R( b, c, d, e, a, F1, K1, M(19) );
+      R( a, b, c, d, e, F2, K2, M(20) );
+      R( e, a, b, c, d, F2, K2, M(21) );
+      R( d, e, a, b, c, F2, K2, M(22) );
+      R( c, d, e, a, b, F2, K2, M(23) );
+      R( b, c, d, e, a, F2, K2, M(24) );
+      R( a, b, c, d, e, F2, K2, M(25) );
+      R( e, a, b, c, d, F2, K2, M(26) );
+      R( d, e, a, b, c, F2, K2, M(27) );
+      R( c, d, e, a, b, F2, K2, M(28) );
+      R( b, c, d, e, a, F2, K2, M(29) );
+      R( a, b, c, d, e, F2, K2, M(30) );
+      R( e, a, b, c, d, F2, K2, M(31) );
+      R( d, e, a, b, c, F2, K2, M(32) );
+      R( c, d, e, a, b, F2, K2, M(33) );
+      R( b, c, d, e, a, F2, K2, M(34) );
+      R( a, b, c, d, e, F2, K2, M(35) );
+      R( e, a, b, c, d, F2, K2, M(36) );
+      R( d, e, a, b, c, F2, K2, M(37) );
+      R( c, d, e, a, b, F2, K2, M(38) );
+      R( b, c, d, e, a, F2, K2, M(39) );
+      R( a, b, c, d, e, F3, K3, M(40) );
+      R( e, a, b, c, d, F3, K3, M(41) );
+      R( d, e, a, b, c, F3, K3, M(42) );
+      R( c, d, e, a, b, F3, K3, M(43) );
+      R( b, c, d, e, a, F3, K3, M(44) );
+      R( a, b, c, d, e, F3, K3, M(45) );
+      R( e, a, b, c, d, F3, K3, M(46) );
+      R( d, e, a, b, c, F3, K3, M(47) );
+      R( c, d, e, a, b, F3, K3, M(48) );
+      R( b, c, d, e, a, F3, K3, M(49) );
+      R( a, b, c, d, e, F3, K3, M(50) );
+      R( e, a, b, c, d, F3, K3, M(51) );
+      R( d, e, a, b, c, F3, K3, M(52) );
+      R( c, d, e, a, b, F3, K3, M(53) );
+      R( b, c, d, e, a, F3, K3, M(54) );
+      R( a, b, c, d, e, F3, K3, M(55) );
+      R( e, a, b, c, d, F3, K3, M(56) );
+      R( d, e, a, b, c, F3, K3, M(57) );
+      R( c, d, e, a, b, F3, K3, M(58) );
+      R( b, c, d, e, a, F3, K3, M(59) );
+      R( a, b, c, d, e, F4, K4, M(60) );
+      R( e, a, b, c, d, F4, K4, M(61) );
+      R( d, e, a, b, c, F4, K4, M(62) );
+      R( c, d, e, a, b, F4, K4, M(63) );
+      R( b, c, d, e, a, F4, K4, M(64) );
+      R( a, b, c, d, e, F4, K4, M(65) );
+      R( e, a, b, c, d, F4, K4, M(66) );
+      R( d, e, a, b, c, F4, K4, M(67) );
+      R( c, d, e, a, b, F4, K4, M(68) );
+      R( b, c, d, e, a, F4, K4, M(69) );
+      R( a, b, c, d, e, F4, K4, M(70) );
+      R( e, a, b, c, d, F4, K4, M(71) );
+      R( d, e, a, b, c, F4, K4, M(72) );
+      R( c, d, e, a, b, F4, K4, M(73) );
+      R( b, c, d, e, a, F4, K4, M(74) );
+      R( a, b, c, d, e, F4, K4, M(75) );
+      R( e, a, b, c, d, F4, K4, M(76) );
+      R( d, e, a, b, c, F4, K4, M(77) );
+      R( c, d, e, a, b, F4, K4, M(78) );
+      R( b, c, d, e, a, F4, K4, M(79) );
+
+      a = ctx->A += a;
+      b = ctx->B += b;
+      c = ctx->C += c;
+      d = ctx->D += d;
+      e = ctx->E += e;
+    }
+}
diff --git a/libmailutils/base/ticket.c b/libmailutils/base/ticket.c
new file mode 100644
index 0000000..4e12b56
--- /dev/null
+++ b/libmailutils/base/ticket.c
@@ -0,0 +1,244 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2005, 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/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <termios.h>
+
+#include <mailutils/mutil.h>
+#include <mailutils/errno.h>
+#include <mailutils/secret.h>
+#include <mailutils/sys/auth.h>
+
+static void
+echo_off (struct termios *stored_settings)
+{
+  struct termios new_settings;
+  tcgetattr (0, stored_settings);
+  new_settings = *stored_settings;
+  new_settings.c_lflag &= (~ECHO);
+  tcsetattr (0, TCSANOW, &new_settings);
+}
+
+static void
+echo_on (struct termios *stored_settings)
+{
+  tcsetattr (0, TCSANOW, stored_settings);
+}
+
+int
+mu_ticket_create (mu_ticket_t *pticket, void *owner)
+{
+  mu_ticket_t ticket;
+  if (pticket == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  ticket = calloc (1, sizeof (*ticket));
+  if (ticket == NULL)
+    return ENOMEM;
+  ticket->owner = owner;
+  mu_ticket_ref (ticket);
+  *pticket = ticket;
+  return 0;
+}
+
+int
+mu_ticket_ref (mu_ticket_t ticket)
+{
+  if (!ticket)
+    return EINVAL;
+  ticket->refcnt++;
+  return 0;
+}
+  
+int
+mu_ticket_unref (mu_ticket_t ticket)
+{
+  if (!ticket)
+    return EINVAL;
+  if (ticket->refcnt)
+    ticket->refcnt--;
+  if (ticket->refcnt == 0)
+    {
+      if (ticket->plain)
+       free (ticket->plain);
+      if (ticket->secret)
+       mu_secret_destroy (&ticket->secret);
+      if (ticket->_destroy)
+       ticket->_destroy (ticket);
+      free (ticket);
+      return 0;
+    }
+  return MU_ERR_EXISTS;
+}
+      
+void
+mu_ticket_destroy (mu_ticket_t *pticket)
+{
+  if (pticket && *pticket && mu_ticket_unref (*pticket) == 0)
+    *pticket = NULL;
+}
+
+int
+mu_ticket_set_destroy (mu_ticket_t ticket,
+                      void (*_destroy) (mu_ticket_t), void *owner)
+{
+  if (ticket == NULL)
+    return EINVAL;
+  if (ticket->owner != owner)
+    return EACCES;
+  ticket->_destroy = _destroy;
+  return 0;
+}
+
+void *
+mu_ticket_get_owner (mu_ticket_t ticket)
+{
+  return (ticket) ? ticket->owner : NULL;
+}
+
+int
+mu_ticket_set_get_cred (mu_ticket_t ticket,
+                       int  (*_get_cred) (mu_ticket_t, mu_url_t,
+                                          const char *,
+                                          char **, mu_secret_t *),
+                       void *owner)
+{
+  if (ticket == NULL)
+    return EINVAL;
+  if (ticket->owner != owner)
+    return EACCES;
+  ticket->_get_cred = _get_cred;
+  return 0;
+}
+
+int
+mu_ticket_set_secret (mu_ticket_t ticket, mu_secret_t secret)
+{
+  if (ticket == NULL)
+    return EINVAL;
+  if (ticket->secret)
+    mu_secret_unref (ticket->secret);
+  mu_secret_ref (secret);
+  ticket->secret = secret;
+  return 0;
+}
+
+int
+mu_ticket_set_plain (mu_ticket_t ticket, const char *text)
+{
+  if (ticket == NULL)
+    return EINVAL;
+  if (ticket->plain)
+    free (ticket->plain);
+  ticket->plain = strdup (text);
+  if (!ticket->plain)
+    return ENOMEM;
+  return 0;
+}
+
+int
+mu_ticket_get_cred (mu_ticket_t ticket, mu_url_t url, const char *challenge,
+                   char **pplain, mu_secret_t *psec)
+{
+  int rc = 0;
+  char arg[256];
+  
+  if (ticket == NULL || (pplain && psec))
+    return EINVAL;
+  if (pplain == NULL && psec == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+
+  if (ticket->_get_cred)
+    {
+      int res = ticket->_get_cred (ticket, url, challenge, pplain, psec);
+      if (res == 0)
+       return res;
+    }
+
+  if (pplain && ticket->plain)
+    {
+      *pplain = strdup (ticket->plain);
+      if (!*pplain)
+       return ENOMEM;
+    }
+  
+  if (psec && ticket->secret)
+    {
+      mu_secret_ref (ticket->secret);
+      *psec = ticket->secret;
+      return 0;
+    }
+  
+  if (isatty (fileno (stdin)))
+    {
+      struct termios stored_settings;
+      int echo = pplain != NULL;
+
+      printf ("%s", challenge);
+      fflush (stdout);
+      if (!echo)
+       echo_off (&stored_settings);
+      fgets (arg, sizeof (arg), stdin);
+      if (!echo)
+       {
+         echo_on (&stored_settings);
+         putchar ('\n');
+         fflush (stdout);
+       }
+      arg [strlen (arg) - 1] = '\0'; /* nuke the trailing line.  */
+    }
+  else
+    return MU_ERR_FAILURE;
+  
+  if (pplain)
+    {
+      *pplain = strdup (arg);
+      if (!*pplain)
+       return ENOMEM;
+    }
+  else
+    rc = mu_secret_create (psec, arg, strlen (arg));
+  return rc;
+}
+
+void *
+mu_ticket_get_data (mu_ticket_t ticket)
+{
+  if (!ticket)
+    return NULL;
+  return ticket->data;
+}
+
+int
+mu_ticket_set_data (mu_ticket_t ticket, void *data, void *owner)
+{
+  if (ticket == NULL)
+    return EINVAL;
+  if (ticket->owner != owner)
+    return EACCES;
+  ticket->data = data;
+  return 0;
+}
diff --git a/libmailutils/base/url.c b/libmailutils/base/url.c
new file mode 100644
index 0000000..554eb8a
--- /dev/null
+++ b/libmailutils/base/url.c
@@ -0,0 +1,1139 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2007, 2008, 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/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <ctype.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/mutil.h>
+#include <mailutils/errno.h>
+#include <mailutils/argcv.h>
+#include <mailutils/secret.h>
+#include <mailutils/cctype.h>
+#include <mailutils/cstr.h>
+#include <mailutils/sys/url.h>
+
+#define AC2(a,b) a ## b
+#define AC4(a,b,c,d) a ## b ## c ## d
+
+static int url_parse0 (mu_url_t, char *, size_t *poff, int *decode);
+
+static int
+parse_query (const char *query,
+            char *delim,
+            int *pargc, char ***pargv, const char **pend)
+{
+  size_t count, i;
+  char **v;
+  const char *p;
+
+  for (p = query, count = 0; ; count++)
+    {
+      size_t len = strcspn (p, delim);
+      p += len;
+      if (!*p || *p == delim[1])
+       break;
+      p++;
+    }
+
+  if (pend)
+    *pend = p;
+  if (p == query)
+    return 0;
+  count++;
+
+  v = calloc (count + 1, sizeof (v[0]));
+  for (i = 0, p = query; i < count; i++)
+    {
+      size_t len = strcspn (p, delim);
+      v[i] = mu_url_decode_len (p, len);
+      if (v[i] == NULL)
+       {
+         mu_argcv_free (i, v);
+         return 1;
+       }
+      p += len + 1;
+    }
+  v[i] = NULL;
+
+  *pargc = count;
+  *pargv = v;
+  return 0;
+}
+
+int
+mu_url_create (mu_url_t *purl, const char *name)
+{
+  mu_url_t url = calloc (1, sizeof (*url));
+  if (url == NULL)
+    return ENOMEM;
+
+  url->name = strdup (name);
+  if (url->name == NULL)
+    {
+      free (url);
+      return ENOMEM;
+    }
+  *purl = url;
+  return 0;
+}
+
+static char **
+argcv_copy (size_t argc, char **argv)
+{
+  size_t i;
+  char **nv = calloc (argc + 1, sizeof (nv[0]));
+  if (!nv)
+    return NULL;
+  for (i = 0; i < argc; i++)
+    if ((nv[i] = strdup (argv[i])) == NULL)
+      {
+       mu_argcv_free (i, nv);
+       free (nv);
+       return NULL;
+      }
+  return nv;
+}
+
+static int
+mu_url_copy0 (mu_url_t old_url, mu_url_t new_url)
+{
+  const char *str;
+  size_t argc;
+  char **argv;
+  int rc;
+  mu_secret_t sec;
+
+#define URLCOPY(what)                                          \
+  do                                                           \
+    {                                                          \
+      rc = AC2(mu_url_sget_,what) (old_url, &str);             \
+      if (rc == 0)                                             \
+       {                                                       \
+         if ((new_url->what = strdup (str)) == NULL)           \
+           return ENOMEM;                                      \
+       }                                                       \
+      else if (rc != MU_ERR_NOENT)                             \
+       return rc;                                              \
+    }                                                          \
+  while (0);
+
+  URLCOPY (scheme);
+  URLCOPY (user);
+
+  rc = mu_url_get_secret (old_url, &sec);
+  if (rc == MU_ERR_NOENT)
+    new_url->secret = NULL;
+  else if (rc)
+    return rc;
+  else
+    {
+      rc = mu_secret_dup (sec, &new_url->secret);
+      if (rc)
+       return rc;
+    }
+  
+  URLCOPY (auth);
+  URLCOPY (host);
+  new_url->port = old_url->port;
+  URLCOPY (path);
+
+  rc = mu_url_sget_fvpairs (old_url, &argc, &argv);
+  if (rc == 0 && argc)
+    {
+      if ((new_url->fvpairs = argcv_copy (argc, argv)) == NULL)
+       return ENOMEM;
+      new_url->fvcount = argc;
+    }
+
+  rc = mu_url_sget_query (old_url, &argc, &argv);
+  if (rc == 0 && argc)
+    {
+      if ((new_url->qargv = argcv_copy (argc, argv)) == NULL)
+       return ENOMEM;
+      new_url->qargc = argc;
+    }
+  return 0;
+#undef URLCOPY
+}
+
+int
+mu_url_dup (mu_url_t old_url, mu_url_t *new_url)
+{
+  mu_url_t url;
+  int rc = mu_url_create (&url, mu_url_to_string (old_url));
+
+  if (rc)
+    return rc;
+
+  rc = mu_url_copy0 (old_url, url);
+  if (rc == 0)
+    *new_url = url;
+  else
+    mu_url_destroy (&url);
+  return rc;
+}
+
+int
+mu_url_uplevel (mu_url_t url, mu_url_t *upurl)
+{
+  int rc;
+  char *p;
+  mu_url_t new_url;
+
+  if (url->_uplevel)
+    return url->_uplevel (url, upurl);
+
+  if (!url->path)
+    return MU_ERR_NOENT;
+  p = strrchr (url->path, '/');
+
+  rc = mu_url_dup (url, &new_url);
+  if (rc == 0)
+    {
+      if (!p || p == url->path)
+       {
+         free (new_url->path);
+         new_url->path = NULL;
+       }
+      else
+       {
+         size_t size = p - url->path;
+         new_url->path = realloc (new_url->path, size + 1);
+         if (!new_url->path)
+           {
+             mu_url_destroy (&new_url);
+             return ENOMEM;
+           }
+         memcpy (new_url->path, url->path, size);
+         new_url->path[size] = 0;
+       }
+      *upurl = new_url;
+    }
+  return rc;
+}
+
+void
+mu_url_destroy (mu_url_t * purl)
+{
+  if (purl && *purl)
+    {
+      mu_url_t url = (*purl);
+
+      if (url->_destroy)
+       url->_destroy (url);
+
+      if (url->name)
+       free (url->name);
+
+      if (url->scheme)
+       free (url->scheme);
+
+      if (url->user)
+       free (url->user);
+
+      mu_secret_destroy (&url->secret);
+
+      if (url->auth)
+       free (url->auth);
+
+      if (url->host)
+       free (url->host);
+
+      if (url->path)
+       free (url->path);
+
+      if (url->fvcount)
+       mu_argcv_free (url->fvcount, url->fvpairs);
+
+      mu_argcv_free (url->qargc, url->qargv);
+
+      free (url);
+
+      *purl = NULL;
+    }
+}
+
+int
+mu_url_parse (mu_url_t url)
+{
+  int err = 0;
+  char *n = NULL;
+  struct _mu_url u;
+  size_t pstart;
+  mu_secret_t newsec;
+  int want_decode;
+  
+  if (!url || !url->name)
+    return EINVAL;
+
+  memset (&u, 0, sizeof u);
+  /* can't have been parsed already */
+  if (url->scheme || url->user || url->secret || url->auth ||
+      url->host || url->path || url->qargc)
+    return EINVAL;
+
+  n = strdup (url->name);
+
+  if (!n)
+    return ENOMEM;
+
+  err = url_parse0 (&u, n, &pstart, &want_decode);
+
+  if (!err)
+    {
+      if (u.secret)
+       {
+         /* Obfuscate the password */
+#define PASS_REPL "***"
+#define PASS_REPL_LEN (sizeof (PASS_REPL) - 1)
+         size_t plen = mu_secret_length (u.secret);
+         size_t nlen = strlen (url->name);
+         size_t len = nlen - plen + PASS_REPL_LEN + 1;
+         char *newname;
+
+         memset (url->name + pstart, 0, plen);
+         newname = realloc (url->name, len);
+         if (!newname)
+           goto CLEANUP;
+         memmove (newname + pstart + PASS_REPL_LEN, newname + pstart + plen,
+                  nlen - (pstart + plen) + 1);
+         memcpy (newname + pstart, PASS_REPL, PASS_REPL_LEN);
+         url->name = newname;
+       }
+
+      /* Dup the strings we found. We wouldn't have to do this
+        if we did a single alloc of the source url name, and
+        kept it around. It's also a good time to do hex decoding,
+        though.
+       */
+
+#define UALLOC(X)                                                      \
+      if (u.X && u.X[0] &&                                             \
+         !(url->X = (want_decode ? mu_url_decode (u.X) : strdup (u.X)))) \
+       {                                                               \
+         err = ENOMEM;                                                 \
+         goto CLEANUP;                                                 \
+       }                                                               \
+      else                                                             \
+       {                                                               \
+         /* Set zero-length strings to NULL. */                        \
+         u.X = NULL;                                                   \
+       }
+
+      UALLOC (scheme);
+      UALLOC (user);
+
+      if (u.secret)
+       {
+         char *pass = mu_url_decode (mu_secret_password (u.secret));
+         err = mu_secret_create (&newsec, pass, strlen (pass));
+         memset (pass, 0, strlen (pass));
+         mu_secret_destroy (&u.secret);
+         if (err)
+           goto CLEANUP;
+
+         url->secret = newsec;
+       }
+
+      UALLOC (auth);
+      UALLOC (host);
+      UALLOC (path);
+
+#undef UALLOC
+      url->fvcount = u.fvcount;
+      url->fvpairs = u.fvpairs;
+
+      url->qargc = u.qargc;
+      url->qargv = u.qargv;
+
+      url->port = u.port;
+    }
+
+CLEANUP:
+  memset (n, 0, strlen (n));
+  free (n);
+
+  if (err)
+    {
+#define UFREE(X) if (X) { free(X); X = 0; }
+
+      UFREE (url->scheme);
+      UFREE (url->user);
+      mu_secret_destroy (&u.secret);
+      UFREE (url->auth);
+      UFREE (url->host);
+      UFREE (url->path);
+      mu_argcv_free (url->fvcount, url->fvpairs);
+      mu_argcv_free (url->qargc, url->qargv);
+#undef UFREE
+    }
+
+  return err;
+}
+
+/*
+
+Syntax, condensed from RFC 1738, and extended with the ;auth=
+of RFC 2384 (for POP) and RFC 2192 (for IMAP):
+
+url =
+    scheme ":" [ "//"
+
+    [ user [ ( ":" password ) | ( ";auth=" auth ) ] "@" ]
+
+    host [ ":" port ]
+
+    [ ( "/" urlpath ) | ( "?" query ) ] ]
+
+All hell will break loose in this parser if the user/pass/auth
+portion is missing, and the urlpath has any @ or : characters
+in it. A imap mailbox, say, named after the email address of
+the person the mail is from:
+
+  imap://imap.uniserve.com/address@hidden
+
+Is this required to be % quoted, though? I hope so!
+
+*/
+
+static int
+url_parse0 (mu_url_t u, char *name, size_t *poff, int *decode)
+{
+  char *start = name;
+  char *p;                     /* pointer into name */
+
+  /* reject the obvious */
+  if (name == NULL)
+    return EINVAL;
+
+  if (name[0] == '/')
+    {
+      u->scheme = "file";
+      *decode = 0;
+    }
+  else if (name[0] == '|')
+    {
+      int rc;
+      u->scheme = "prog";
+      *decode = 0;
+      rc = mu_argcv_get (name + 1, NULL, NULL, &u->qargc, &u->qargv);
+      if (rc == 0)
+       {
+         u->path = strdup (u->qargv[0]);
+         if (!u->path)
+           rc = ENOMEM;
+       }
+      return rc;
+    }
+  else
+    {
+      *decode = 1;
+      /* Parse out the SCHEME. */
+      p = strchr (name, ':');
+      if (p == NULL)
+       return MU_ERR_PARSE;
+
+      *p++ = 0;
+
+      u->scheme = name;
+
+      /* RFC 1738, section 2.1, lower the scheme case */
+      for (; name < p; name++)
+       *name = mu_tolower (*name);
+
+      name = p;
+    }
+
+  /* Check for nothing following the scheme. */
+  if (!*name)
+    return 0;
+
+  if (strncmp (name, "//", 2) == 0)
+    {
+      name += 2;
+
+      if (name[0] == '/')
+       {
+         u->path = name;
+         p = u->path + strcspn (u->path, ";?");
+       }
+      else
+       {
+         /* Split into LHS and RHS of the '@', and then parse each side. */
+         u->host = strchr (name, '@');
+         if (u->host == NULL)
+           u->host = name;
+         else
+           {
+             char *pass = NULL;
+
+             /* Parse the LHS into an identification/authentication pair. */
+             *u->host++ = 0;
+
+             u->user = name;
+
+             /* Try to split the user into a:
+                <user>:<password>
+                or
+                <user>:<password>;AUTH=<auth>
+             */
+
+             for (; *name; name++)
+               {
+                 if (*name == ':')
+                   {
+                     *name++ = 0;
+                     pass = name;
+                     *poff = pass - start;
+                   }
+                 else if (*name == ';')
+                   {
+                     /* Make sure it's the auth token. */
+                     if (mu_c_strncasecmp (name + 1, "auth=", 5) == 0)
+                       {
+                         *name++ = 0;
+                         name += 5;
+                         u->auth = name;
+                         break;
+                       }
+                   }
+               }
+
+             if (pass)
+               {
+                 if (mu_secret_create (&u->secret, pass, strlen (pass)))
+                   return ENOMEM;
+                 else
+                   /* Obfuscate password */
+                   memset (pass, 0, strlen (pass));
+               }
+           }
+
+         /* Parse the host and port from the RHS. */
+         p = strchr (u->host, ':');
+         if (p)
+           {
+             *p++ = 0;
+             u->port = strtol (p, &p, 10);
+
+             /* Check for garbage after the port: we should be on the start
+                of a path, a query, or at the end of the string. */
+             if (*p && strcspn (p, "/?") != 0)
+               return MU_ERR_PARSE;
+           }
+         else
+           p = u->host + strcspn (u->host, ";/?");
+       }
+    }
+  else
+    {
+      u->path = name;
+      p = u->path + strcspn (u->path, ";?");
+    }
+
+  /* Either way, if we're not at a nul, we're at a path or query. */
+  if (u->path == NULL && *p == '/')
+    {
+      /* found a path */
+      *p++ = 0;
+      u->path = p;
+      p = u->path + strcspn (u->path, ";?");
+    }
+
+  if (*p == ';')
+    {
+      *p++ = 0;
+      if (parse_query (p, ";?", &u->fvcount, &u->fvpairs, (const char **)&p))
+       return ENOMEM;
+    }
+
+  if (*p == '?')
+    {
+      /* found a query */
+      *p++ = 0;
+      if (parse_query (p, "&", &u->qargc, &u->qargv, NULL))
+       return ENOMEM;
+    }
+
+  return 0;
+}
+
+
+/* General accessors: */
+#define ACCESSOR(action,field) AC4(mu_url_,action,_,field)
+
+#define DECL_SGET(field)                                                 \
+int                                                                      \
+ACCESSOR(sget,field) (mu_url_t url, char const **sptr)                   \
+{                                                                        \
+  if (url == NULL)                                                       \
+    return EINVAL;                                                       \
+  if (!url->field)                                                       \
+    {                                                                    \
+      if (url->AC2(_get_,field))                                         \
+       {                                                                 \
+         size_t n;                                                       \
+         char *buf;                                                      \
+                                                                         \
+         int status = url->AC2(_get_,field) (url, NULL, 0, &n);          \
+         if (status)                                                     \
+           return status;                                                \
+                                                                         \
+         buf = malloc (n + 1);                                           \
+         if (!buf)                                                       \
+           return ENOMEM;                                                \
+                                                                         \
+         status = url->AC2(_get_,field) (url, buf, n + 1, NULL);         \
+         if (status)                                     \
+           return status;                                                \
+                                                                         \
+         if (buf[0])                                                     \
+           {                                                             \
+              url->field = mu_url_decode (buf);                          \
+              free (buf);                                                \
+           }                                                             \
+         else                                                            \
+           url->field = buf;                                             \
+         if (!url->field)                                                \
+           return ENOMEM;                                                \
+       }                                                                 \
+      else                                                               \
+       return MU_ERR_NOENT;                                              \
+    }                                                                    \
+  *sptr = url->field;                                                    \
+  return 0;                                                              \
+}
+
+#define DECL_GET(field)                                                        
  \
+int                                                                      \
+ACCESSOR(get,field) (mu_url_t url, char *buf, size_t len, size_t *n)      \
+{                                                                        \
+  size_t i;                                                              \
+  const char *str;                                                       \
+  int status = ACCESSOR(sget, field) (url, &str);                        \
+                                                                         \
+  if (status)                                                            \
+    return status;                                                       \
+                                                                         \
+  i = mu_cpystr (buf, str, len);                                         \
+  if (n)                                                                 \
+    *n = i;                                                              \
+  return 0;                                                              \
+}
+
+#define DECL_AGET(field)                                                 \
+int                                                                      \
+ACCESSOR(aget, field) (mu_url_t url, char **buf)                         \
+{                                                                        \
+  const char *str;                                                       \
+  int status = ACCESSOR(sget, field) (url, &str);                        \
+                                                                         \
+  if (status)                                                            \
+    return status;                                                       \
+                                                                         \
+  if (str)                                                               \
+    {                                                                    \
+      *buf = strdup (str);                                               \
+      if (!*buf)                                                         \
+       status = ENOMEM;                                                  \
+    }                                                                    \
+  else                                                                   \
+    *buf = NULL;                                                         \
+  return status;                                                         \
+}
+
+#define DECL_CMP(field)                                                        
  \
+int                                                                      \
+ACCESSOR(is_same,field) (mu_url_t url1, mu_url_t url2)                   \
+{                                                                        \
+  const char *s1, *s2;                                                   \
+  int status1, status2;                                                        
  \
+                                                                         \
+  status1 = ACCESSOR(sget, field) (url1, &s1);                           \
+  if (status1 && status1 != MU_ERR_NOENT)                                \
+    return 0;                                                            \
+  status2 = ACCESSOR(sget, field) (url2, &s2);                           \
+  if (status2 && status2 != MU_ERR_NOENT)                                \
+    return 0;                                                            \
+                                                                         \
+  if (status1 || status2)                                                \
+    return status1 == status2; /* Both fields are missing */             \
+  return mu_c_strcasecmp (s1, s2) == 0;                                        
  \
+}
+
+#define DECL_ACCESSORS(field)                                            \
+DECL_SGET(field)                                                         \
+DECL_GET(field)                                                                
  \
+DECL_AGET(field)                                                          \
+DECL_CMP(field)
+
+
+/* Declare particular accessors */
+DECL_ACCESSORS (scheme)
+DECL_ACCESSORS (user)
+DECL_ACCESSORS (auth)
+DECL_ACCESSORS (host)
+DECL_ACCESSORS (path)
+
+int
+mu_url_get_secret (const mu_url_t url, mu_secret_t *psecret)
+{
+  if (url->_get_secret)
+    return url->_get_secret (url, psecret);
+  if (url->secret == NULL)
+    return MU_ERR_NOENT;
+  mu_secret_ref (url->secret);
+  *psecret = url->secret;
+  return 0;
+}
+
+int
+mu_url_sget_query (const mu_url_t url, size_t *qc, char ***qv)
+{
+  if (url == NULL)
+    return EINVAL;
+  /* See FIXME below */
+  *qc = url->qargc;
+  *qv = url->qargv;
+  return 0;
+}
+
+int
+mu_url_aget_query (const mu_url_t url, size_t *qc, char ***qv)
+{
+  size_t qargc, i;
+  char **qargv;
+  char **qcopy;
+
+  int rc = mu_url_sget_fvpairs (url, &qargc, &qargv);
+  if (rc)
+    return rc;
+
+  qcopy = calloc (qargc + 1, sizeof (qcopy[0]));
+  if (!qcopy)
+    return errno;
+  for (i = 0; i < qargc; i++)
+    {
+      if (!(qcopy[i] = strdup (qargv[i])))
+       {
+         mu_argcv_free (i, qcopy);
+         return errno;
+       }
+    }
+  qcopy[i] = NULL;
+  *qc = qargc;
+  *qv = qcopy;
+  return 0;
+}
+
+/* field-value pairs accessors */
+int
+mu_url_sget_fvpairs (const mu_url_t url, size_t *fvc, char ***fvp)
+{
+  if (url == NULL)
+    return EINVAL;
+  /* FIXME: no _get_fvpairs method, but the method stuff needs to be rewritten
+     anyway */
+  *fvc = url->fvcount;
+  *fvp = url->fvpairs;
+  return 0;
+}
+
+int
+mu_url_aget_fvpairs (const mu_url_t url, size_t *pfvc, char ***pfvp)
+{
+  size_t fvc, i;
+  char **fvp;
+  char **fvcopy;
+
+  int rc = mu_url_sget_fvpairs (url, &fvc, &fvp);
+  if (rc)
+    return rc;
+
+  fvcopy = calloc (fvc + 1, sizeof (fvcopy[0]));
+  if (!fvcopy)
+    return errno;
+  for (i = 0; i < fvc; i++)
+    {
+      if (!(fvcopy[i] = strdup (fvp[i])))
+       {
+         mu_argcv_free (i, fvcopy);
+         return errno;
+       }
+    }
+  fvcopy[i] = NULL;
+  *pfvc = fvc;
+  *pfvp = fvcopy;
+  return 0;
+}
+
+int
+mu_url_get_port (const mu_url_t url, long *pport)
+{
+  if (url == NULL)
+    return EINVAL;
+  if (url->_get_port)
+    return url->_get_port (url, pport);
+  *pport = url->port;
+  return 0;
+}
+
+const char *
+mu_url_to_string (const mu_url_t url)
+{
+  if (url == NULL || url->name == NULL)
+    return "";
+  return url->name;
+}
+
+int
+mu_url_set_scheme (mu_url_t url, const char *scheme)
+{
+  char *p;
+  if (!url || !scheme)
+    return EINVAL;
+  p = realloc (url->scheme, strlen (scheme) + 1);
+  if (!p)
+    return ENOMEM;
+  strcpy (url->scheme, scheme);
+  return 0;
+}
+
+int
+mu_url_is_scheme (mu_url_t url, const char *scheme)
+{
+  if (url && scheme && url->scheme 
+      && mu_c_strcasecmp (url->scheme, scheme) == 0)
+    return 1;
+
+  return 0;
+}
+
+int
+mu_url_is_same_port (mu_url_t url1, mu_url_t url2)
+{
+  long p1 = 0, p2 = 0;
+
+  mu_url_get_port (url1, &p1);
+  mu_url_get_port (url2, &p2);
+  return (p1 == p2);
+}
+
+/* From RFC 1738, section 2.2 */
+char *
+mu_url_decode_len (const char *s, size_t len)
+{
+  char *d;
+  const char *eos = s + len;
+  int i;
+
+  d = malloc (len + 1);
+  if (!d)
+    return NULL;
+
+  for (i = 0; s < eos; i++)
+    {
+      if (*s != '%')
+       {
+         d[i] = *s;
+         s++;
+       }
+      else
+       {
+         unsigned long ul = 0;
+
+         s++;
+
+         /* don't check return value, it's correctly coded, or it's not,
+            in which case we just skip the garbage, this is a decoder,
+            not an AI project */
+
+         mu_hexstr2ul (&ul, s, 2);
+
+         s += 2;
+
+         d[i] = (char) ul;
+       }
+    }
+
+  d[i] = 0;
+
+  return d;
+}
+
+char *
+mu_url_decode (const char *s)
+{
+  return mu_url_decode_len (s, strlen (s));
+}
+
+static int
+defined (const char *s)
+{
+  if (s && strcmp ("*", s) != 0)
+    return 1;
+  return 0;
+}
+
+int
+mu_url_is_ticket (mu_url_t ticket, mu_url_t url)
+{
+  if (!ticket || !url)
+    return 0;
+
+  /* If ticket has a scheme, host, port, or path, then the queries
+     equivalent must be defined and match. */
+  if (defined (ticket->scheme))
+    {
+      if (!url->scheme || mu_c_strcasecmp (ticket->scheme, url->scheme) != 0)
+       return 0;
+    }
+  if (defined (ticket->host))
+    {
+      if (!url->host || mu_c_strcasecmp (ticket->host, url->host) != 0)
+       return 0;
+    }
+  if (ticket->port && ticket->port != url->port)
+    return 0;
+  /* If ticket has a user or pass, but url doesn't, that's OK, we were
+     urling for this info. But if url does have a user/pass, it
+     must match the ticket. */
+  if (url->user)
+    {
+      if (defined (ticket->user) && strcmp (ticket->user, url->user) != 0)
+       return 0;
+    }
+
+  /* Guess it matches. */
+  return 1;
+}
+
+int
+mu_url_init (mu_url_t url, int port, const char *scheme)
+{
+  int status = 0;
+
+  url->_destroy = NULL;
+
+  status = mu_url_parse (url);
+  if (status)
+    return status;
+
+  if (!mu_url_is_scheme (url, scheme))
+    return EINVAL;
+
+  if (url->port == 0)
+    url->port = port;
+
+  return status;
+}
+
+/* Default mailbox path generator */
+static char *
+_url_path_default (const char *spooldir, const char *user, int unused)
+{
+  char *mbox = malloc (strlen (spooldir) + strlen (user) + 2);
+  if (!mbox)
+    errno = ENOMEM;
+  else
+    sprintf (mbox, "%s/%s", spooldir, user);
+  return mbox;
+}
+
+/* Hashed indexing */
+static char *
+_url_path_hashed (const char *spooldir, const char *user, int param)
+{
+  int i;
+  int ulen = strlen (user);
+  char *mbox;
+  unsigned hash;
+
+  if (param > ulen)
+    param = ulen;
+  for (i = 0, hash = 0; i < param; i++)
+    hash += user[i];
+
+  mbox = malloc (ulen + strlen (spooldir) + 5);
+  sprintf (mbox, "%s/%02X/%s", spooldir, hash % 256, user);
+  return mbox;
+}
+
+static int transtab[] = {
+  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
+  'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
+  'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
+  'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f',
+  'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
+  'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
+  'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd',
+  'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
+  'm', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
+  'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
+  'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
+  'x', 'y', 'z', 'b', 'c', 'd', 'e', 'f',
+  'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
+  'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
+  'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
+  'x', 'y', 'z', 'b', 'c', 'd', 'e', 'f',
+  'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
+  'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
+  'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
+  'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
+  'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
+  'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
+  'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e',
+  'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
+  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
+  'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
+  'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
+  'y', 'z', 'b', 'c', 'd', 'e', 'f', 'g',
+  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
+  'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
+  'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
+  'y', 'z', 'b', 'c', 'd', 'e', 'f', 'g'
+};
+
+/* Forward Indexing */
+static char *
+_url_path_index (const char *spooldir, const char *iuser, int index_depth)
+{
+  const unsigned char* user = (const unsigned char*) iuser;
+  int i, ulen = strlen (iuser);
+  char *mbox, *p;
+
+  if (ulen == 0)
+    return NULL;
+
+  mbox = malloc (ulen + strlen (spooldir) + 2*index_depth + 2);
+  strcpy (mbox, spooldir);
+  p = mbox + strlen (mbox);
+  for (i = 0; i < index_depth && i < ulen; i++)
+    {
+      *p++ = '/';
+      *p++ = transtab[ user[i] ];
+    }
+  for (; i < index_depth; i++)
+    {
+      *p++ = '/';
+      *p++ = transtab[ user[ulen-1] ];
+    }
+  *p++ = '/';
+  strcpy (p, iuser);
+  return mbox;
+}
+
+/* Reverse Indexing */
+static char *
+_url_path_rev_index (const char *spooldir, const char *iuser, int index_depth)
+{
+  const unsigned char* user = (const unsigned char*) iuser;
+  int i, ulen = strlen (iuser);
+  char *mbox, *p;
+
+  if (ulen == 0)
+    return NULL;
+
+  mbox = malloc (ulen + strlen (spooldir) + 2*index_depth + 1);
+  strcpy (mbox, spooldir);
+  p = mbox + strlen (mbox);
+  for (i = 0; i < index_depth && i < ulen; i++)
+    {
+      *p++ = '/';
+      *p++ = transtab[ user[ulen - i - 1] ];
+    }
+  for (; i < index_depth; i++)
+    {
+      *p++ = '/';
+      *p++ = transtab[ user[0] ];
+    }
+  *p++ = '/';
+  strcpy (p, iuser);
+  return mbox;
+}
+
+static int
+rmselector (const char *p, void *data MU_ARG_UNUSED)
+{
+  return strncmp (p, "type=", 5) == 0
+        || strncmp (p, "user=", 5) == 0
+        || strncmp (p, "param=", 6) == 0;
+}
+
+int
+mu_url_expand_path (mu_url_t url)
+{
+  size_t i;
+  char *user = NULL;
+  int param = 0;
+  char *p;
+  char *(*fun) (const char *, const char *, int) = _url_path_default;
+
+  if (url->fvcount == 0)
+    return 0;
+
+  for (i = 0; i < url->fvcount; i++)
+    {
+      p = url->fvpairs[i];
+      if (strncmp (p, "type=", 5) == 0)
+       {
+         char *type = p + 5;
+
+         if (strcmp (type, "hash") == 0)
+           fun = _url_path_hashed;
+         else if (strcmp (type, "index") == 0)
+           fun = _url_path_index;
+         else if (strcmp (type, "rev-index") == 0)
+           fun = _url_path_rev_index;
+         else
+           return MU_ERR_NOENT;
+       }
+      else if (strncmp (p, "user=", 5) == 0)
+       {
+         user = p + 5;
+       }
+      else if (strncmp (p, "param=", 6) == 0)
+       {
+         param = strtoul (p + 6, NULL, 0);
+       }
+    }
+
+  if (user)
+    {
+      char *p = fun (url->path, user, param);
+      if (p)
+       {
+         free (url->path);
+         url->path = p;
+       }
+      mu_argcv_remove (&url->fvcount, &url->fvpairs, rmselector, NULL);
+    }
+  else
+    return MU_ERR_NOENT;
+
+  return 0;
+}
diff --git a/libmailutils/vartab.c b/libmailutils/base/vartab.c
similarity index 100%
rename from libmailutils/vartab.c
rename to libmailutils/base/vartab.c
diff --git a/libmailutils/base/version.c b/libmailutils/base/version.c
new file mode 100644
index 0000000..d482140
--- /dev/null
+++ b/libmailutils/base/version.c
@@ -0,0 +1,187 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   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
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <mailutils/nls.h>
+#include <mailutils/version.h>
+#include <mailutils/cstr.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <confpaths.h>
+
+char *mu_license_text =
+ N_("   GNU Mailutils is free software; you can redistribute it and/or 
modify\n"
+    "   it under the terms of the GNU General Public License as published by\n"
+    "   the Free Software Foundation; either version 3 of the License, or\n"
+    "   (at your option) any later version.\n"
+    "\n"
+    "   GNU Mailutils is distributed in the hope that it will be useful,\n"
+    "   but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+    "   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
+    "   GNU General Public License for more details.\n"
+    "\n"
+    "   You should have received a copy of the GNU General Public License 
along\n"
+    "   with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.\n"
+    "\n"
+    "\n"
+);
+
+static struct mu_conf_option mu_conf_option[] = {
+  { "VERSION=" VERSION, N_("Version of this package") },
+  { "SYSCONFDIR=" SYSCONFDIR, N_("System configuration directory") },
+  { "MAILSPOOLDIR=" MU_PATH_MAILDIR, N_("Default mail spool directory") },
+  { "SCHEME=" MU_DEFAULT_SCHEME, N_("Default mailbox type") },
+  { "LOG_FACILITY=" LOG_FACILITY_STRING, N_("Default syslog facility") },
+#ifdef USE_LIBPAM
+  { "USE_LIBPAM", N_("PAM support") },
+#endif
+#ifdef HAVE_LIBLTDL
+  { "HAVE_LIBLTDL", N_("a portable `dlopen' wrapper library") },
+#endif
+#ifdef WITH_BDB2
+  { "WITH_BDB2", N_("Berkeley DB v. 2") },
+#endif
+#ifdef WITH_NDBM
+  { "WITH_NDBM", },
+#endif
+#ifdef WITH_OLD_DBM
+  { "WITH_OLD_DBM", N_("Old DBM support") },
+#endif
+#ifdef WITH_GDBM
+  { "WITH_GDBM", N_("GNU DBM") },
+#endif
+#ifdef WITH_TOKYOCABINET
+  { "WITH_TOKYOCABINET", N_("Tokyo Cabinet DBM") },
+#endif
+#ifdef WITH_GNUTLS
+  { "WITH_GNUTLS", N_("TLS support using GNU TLS") },
+#endif
+#ifdef WITH_GSASL
+  { "WITH_GSASL", N_("SASL support using GNU SASL") },
+#endif
+#ifdef WITH_GSSAPI
+  { "WITH_GSSAPI", N_("GSSAPI support") },
+#endif
+#ifdef WITH_GUILE
+  { "WITH_GUILE", N_("Support for Guile as extension language") },
+#endif
+#ifdef WITH_PYTHON
+  { "WITH_PYTHON", N_("Support for Python as extension language") },
+#endif
+#ifdef WITH_PTHREAD
+  { "WITH_PTHREAD", N_("Support for POSIX threads") },
+#endif
+#ifdef WITH_READLINE
+  { "WITH_READLINE", N_("GNU Readline") },
+#endif
+#ifdef HAVE_MYSQL
+  { "HAVE_MYSQL", N_("MySQL") },
+#endif
+#ifdef HAVE_PGSQL
+  { "HAVE_PGSQL", N_("PostgreSQL") },
+#endif
+#ifdef WITH_LDAP
+  { "WITH_LDAP", },
+#endif
+#ifdef WITH_LIBWRAP
+  { "WITH_LIBWRAP", N_("Support for TCP wrappers") },
+#endif
+#ifdef ENABLE_VIRTUAL_DOMAINS
+  { "ENABLE_VIRTUAL_DOMAINS", N_("Support for virtual mail domains") },
+#endif
+#ifdef ENABLE_IMAP
+  { "ENABLE_IMAP", N_("IMAP4 protocol support") },
+#endif
+#ifdef ENABLE_POP
+  { "ENABLE_POP",  N_("POP3 protocol support") },
+#endif
+#ifdef ENABLE_MH
+  { "ENABLE_MH", N_("MH mail storage support") },
+#endif
+#ifdef ENABLE_MAILDIR
+  { "ENABLE_MAILDIR", N_("Maildir mail storage support") },
+#endif
+#ifdef ENABLE_SMTP
+  { "ENABLE_SMTP", N_("SMTP protocol support") },
+#endif
+#ifdef ENABLE_SENDMAIL
+  { "ENABLE_SENDMAIL", N_("Sendmail command line interface support")},
+#endif
+#ifdef ENABLE_NNTP
+  { "ENABLE_NNTP", N_("NNTP protocol support") },
+#endif
+#ifdef ENABLE_RADIUS
+  { "ENABLE_RADIUS", N_("RADIUS protocol support") },
+#endif
+#ifdef WITH_INCLUDED_LIBINTL
+  { "WITH_INCLUDED_LIBINTL", N_("GNU libintl compiled in") },
+#endif
+  { NULL }
+};
+
+void
+mu_fprint_conf_option (FILE *fp, const struct mu_conf_option *opt, int verbose)
+{
+  fprintf (fp, "%s", opt->name);
+  if (verbose && opt->descr)
+    fprintf (fp, " \t- %s", _(opt->descr));
+  fputc('\n', fp);
+}
+
+void
+mu_fprint_options (FILE *fp, int verbose)
+{
+  int i;
+  
+  for (i = 0; mu_conf_option[i].name; i++)
+    mu_fprint_conf_option (fp, mu_conf_option + i, verbose);
+}
+
+void
+mu_print_options ()
+{
+  mu_fprint_options (stdout, 1);
+}
+
+const struct mu_conf_option *
+mu_check_option (char *name)
+{
+  int i;
+  
+  for (i = 0; mu_conf_option[i].name; i++)
+    {
+      int len;
+      char *q, *p = strchr (mu_conf_option[i].name, '=');
+      if (p)
+       len = p - mu_conf_option[i].name;
+      else
+       len = strlen (mu_conf_option[i].name);
+
+      if (mu_c_strncasecmp (mu_conf_option[i].name, name, len) == 0)
+       return &mu_conf_option[i];
+      else if ((q = strchr (mu_conf_option[i].name, '_')) != NULL
+              && mu_c_strncasecmp (q + 1, name,
+                              len - (q - mu_conf_option[i].name) - 1) == 0)
+       return &mu_conf_option[i];
+    }
+  return NULL;
+}  
+
diff --git a/libmailutils/base/wicket.c b/libmailutils/base/wicket.c
new file mode 100644
index 0000000..1e6a657
--- /dev/null
+++ b/libmailutils/base/wicket.c
@@ -0,0 +1,356 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 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/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <pwd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <ctype.h>
+
+#include <mailutils/errno.h>
+#include <mailutils/mutil.h>
+#include <mailutils/mu_auth.h>
+#include <mailutils/stream.h>
+
+#include <mailutils/sys/auth.h>
+#include <mailutils/sys/url.h>
+
+int
+mu_wicket_create (mu_wicket_t *pwicket)
+{
+  mu_wicket_t wicket = calloc (1, sizeof (*wicket));
+  if (!wicket)
+    return ENOMEM;
+  wicket->refcnt = 1;
+  *pwicket = wicket;
+  return 0;
+}
+
+int
+mu_wicket_get_ticket (mu_wicket_t wicket, const char *user, mu_ticket_t 
*pticket)
+{
+  if (!wicket)
+    return EINVAL;
+  if (!pticket)
+    return EINVAL;
+  if (!wicket->_get_ticket)
+    return ENOSYS;
+  return wicket->_get_ticket (wicket, wicket->data, user, pticket);
+}
+
+int
+mu_wicket_ref (mu_wicket_t wicket)
+{
+  if (!wicket)
+    return EINVAL;
+  wicket->refcnt++;
+  return 0;
+}
+
+int
+mu_wicket_unref (mu_wicket_t wicket)
+{
+  if (!wicket)
+    return EINVAL;
+  if (wicket->refcnt)
+    wicket->refcnt--;
+  if (wicket->refcnt == 0)
+    {
+      if (wicket->_destroy)
+       wicket->_destroy (wicket);
+      free (wicket);
+      return 0;
+    }
+  return MU_ERR_EXISTS;
+}
+
+
+void
+mu_wicket_destroy (mu_wicket_t *pwicket)
+{
+  if (pwicket && *pwicket && mu_wicket_unref (*pwicket) == 0)
+    *pwicket = NULL;
+}
+
+int
+mu_wicket_set_destroy (mu_wicket_t wicket, void (*_destroy) (mu_wicket_t))
+{
+  if (!wicket)
+    return EINVAL;
+  wicket->_destroy = _destroy;
+  return 0;
+}
+
+int
+mu_wicket_set_data (mu_wicket_t wicket, void *data)
+{
+  if (!wicket)
+    return EINVAL;
+  wicket->data = data;
+  return 0;
+}
+
+void *
+mu_wicket_get_data (mu_wicket_t wicket)
+{
+  if (!wicket)
+    return NULL;
+  return wicket->data;
+}
+
+int
+mu_wicket_set_get_ticket (mu_wicket_t wicket,
+                         int (*_get_ticket) (mu_wicket_t, void *,
+                                             const char *, mu_ticket_t *))
+{
+  if (!wicket)
+    return EINVAL;
+  wicket->_get_ticket = _get_ticket;
+  return 0;
+}
+
+
+/* A "file wicket" implementation */
+
+struct file_wicket
+{
+  char *filename;
+};
+
+static void
+_file_wicket_destroy (mu_wicket_t wicket)
+{
+  struct file_wicket *fw = mu_wicket_get_data (wicket);
+  free (fw->filename);
+  free (fw);
+}
+
+struct file_ticket
+{
+  char *filename;
+  char *user;
+  mu_url_t tickurl;
+};
+
+static void
+file_ticket_destroy (mu_ticket_t ticket)
+{
+  struct file_ticket *ft = mu_ticket_get_data (ticket);
+  if (ft)
+    {
+      free (ft->filename);
+      free (ft->user);
+      mu_url_destroy (&ft->tickurl);
+      free (ft);
+    }
+}
+
+static int get_ticket_url (mu_ticket_t ticket, mu_url_t url, mu_url_t 
*pticket_url);
+
+int
+file_ticket_get_cred (mu_ticket_t ticket, mu_url_t url, const char *challenge,
+                     char **pplain, mu_secret_t *psec)
+{
+  struct file_ticket *ft = mu_ticket_get_data (ticket);
+
+  if (!ft->tickurl)
+    {
+      int rc = get_ticket_url (ticket, url, &ft->tickurl);
+      if (rc)
+       return rc;
+    }
+  if (pplain)
+    {
+      if (ft->user)
+       {
+         *pplain = strdup (ft->user);
+         if (!*pplain)
+           return ENOMEM;
+       }
+      else
+       return mu_url_aget_user (ft->tickurl, pplain);
+    }
+  else
+    return mu_url_get_secret (ft->tickurl, psec);
+}
+
+static int
+_file_wicket_get_ticket (mu_wicket_t wicket, void *data,
+                        const char *user, mu_ticket_t *pticket)
+{
+  int rc;
+  mu_ticket_t ticket;
+  struct file_wicket *fw = data;
+  struct file_ticket *ft = calloc (1, sizeof (*ft));
+  ft->filename = strdup (fw->filename);
+  if (!ft->filename)
+    {
+      free (ft);
+      return ENOMEM;
+    }
+  if (user)
+    {
+      ft->user = strdup (user);
+      if (!ft->user)
+       {
+         free (ft->filename);
+         free (ft);
+         return ENOMEM;
+       }
+    }
+  else
+    ft->user = NULL;
+
+  rc = mu_ticket_create (&ticket, NULL);
+  if (rc)
+    {
+      free (ft->filename);
+      free (ft->user);
+      free (ft);
+      return rc;
+    }
+       
+  mu_ticket_set_destroy (ticket, file_ticket_destroy, NULL);
+  mu_ticket_set_data (ticket, ft, NULL);
+  mu_ticket_set_get_cred (ticket, file_ticket_get_cred, NULL);
+
+  *pticket = ticket;
+  return 0;
+}
+  
+static int
+get_ticket_url (mu_ticket_t ticket, mu_url_t url, mu_url_t *pticket_url)
+{
+  mu_stream_t stream;
+  struct file_ticket *ft = mu_ticket_get_data (ticket);
+  int rc;
+  mu_url_t u = NULL;
+  char *buf = NULL;
+  size_t bufsize = 0;
+  size_t len;
+  
+  rc = mu_file_stream_create (&stream, ft->filename, MU_STREAM_READ);
+  if (rc)
+    return rc;
+    
+  while ((rc = mu_stream_getline (stream, &buf, &bufsize, &len)) == 0
+        && len > 0)
+    {
+      char *p;
+      int err;
+      
+      /* Truncate a trailing newline. */
+      if (len && buf[len - 1] == '\n')
+       buf[--len] = 0;
+      
+      /* Skip leading spaces  */
+      for (p = buf; *p == ' ' || *p == '\t'; p++)
+       ;
+      /* Skip trailing spaces */
+      for (; len > 0 && (p[len-1] == ' ' || p[len-1] == '\t'); )
+       p[--len] = 0;
+      
+      /* Skip empty lines and comments. */
+      if (*p == 0 || *p == '#')
+       continue;
+      
+      if ((err = mu_url_create (&u, p)) != 0)
+       {
+         /* Skip erroneous entry */
+         /* FIXME: Error message */
+         continue;
+       }
+      if ((err = mu_url_parse (u)) != 0)
+       {
+         /* FIXME: See above */
+         mu_url_destroy (&u);
+         continue;
+       }
+      
+      if (!mu_url_is_ticket (u, url))
+       {
+         mu_url_destroy (&u);
+         continue;
+       }
+      
+      if (ft->user)
+       {
+         if (u->name && strcmp (u->name, "*") != 0
+             && strcmp (ft->user, u->name) != 0)
+           {
+             mu_url_destroy (&u);
+             continue;
+           }
+       }
+      
+      break;
+    }
+  mu_stream_close (stream);
+  free (buf);
+    
+  mu_stream_destroy (&stream);
+
+  if (rc == 0)
+    {
+      if (u)
+       *pticket_url = u;
+      else
+       rc = MU_ERR_NOENT;
+    }
+  
+  return rc;
+}
+
+int
+mu_file_wicket_create (mu_wicket_t *pwicket, const char *filename)
+{
+  mu_wicket_t wicket;
+  int rc;
+  struct file_wicket *fw = calloc (1, sizeof (*fw));
+
+  if (!fw)
+    return ENOMEM;
+  fw->filename = strdup (filename);
+  if (!fw->filename)
+    {
+      free (fw);
+      return ENOMEM;
+    }
+  
+  rc = mu_wicket_create (&wicket);
+  if (rc)
+    {
+      free (fw->filename);
+      free (fw);
+      return rc;
+    }
+  mu_wicket_set_data (wicket, fw);
+  mu_wicket_set_destroy (wicket, _file_wicket_destroy);
+  mu_wicket_set_get_ticket (wicket, _file_wicket_get_ticket);
+  *pwicket = wicket;
+  return 0;
+}
+
diff --git a/libmailutils/body.c b/libmailutils/body.c
deleted file mode 100644
index 05b47f1..0000000
--- a/libmailutils/body.c
+++ /dev/null
@@ -1,417 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-#include <mailutils/stream.h>
-#include <mailutils/mutil.h>
-#include <mailutils/errno.h>
-#include <mailutils/sys/stream.h>
-#include <mailutils/sys/body.h>
-
-#define BODY_MODIFIED 0x10000
-
-static int _body_flush    (mu_stream_t);
-static int _body_read     (mu_stream_t, char *, size_t, size_t *);
-static int _body_truncate (mu_stream_t, mu_off_t);
-static int _body_size     (mu_stream_t, mu_off_t *);
-static int _body_write    (mu_stream_t, const char *, size_t, size_t *);
-static int _body_ioctl    (mu_stream_t, int, void *);
-static int _body_seek     (mu_stream_t, mu_off_t, mu_off_t *);
-static const char *_body_error_string (mu_stream_t, int);
-
-/* Our own defaults for the body.  */
-static int _body_get_size   (mu_body_t, size_t *);
-static int _body_get_lines  (mu_body_t, size_t *);
-static int _body_get_size0  (mu_stream_t, size_t *);
-static int _body_get_lines0 (mu_stream_t, size_t *);
-
-int
-mu_body_create (mu_body_t *pbody, void *owner)
-{
-  mu_body_t body;
-
-  if (pbody == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  if (owner == NULL)
-    return EINVAL;
-
-  body = calloc (1, sizeof (*body));
-  if (body == NULL)
-    return ENOMEM;
-
-  body->owner = owner;
-  *pbody = body;
-  return 0;
-}
-
-void
-mu_body_destroy (mu_body_t *pbody, void *owner)
-{
-  if (pbody && *pbody)
-    {
-      mu_body_t body = *pbody;
-      if (body->owner == owner)
-       {
-         if (body->filename)
-           {
-             /* FIXME: should we do this?  */
-             remove (body->filename);
-             free (body->filename);
-           }
-
-         if (body->stream)
-           mu_stream_destroy (&body->stream);
-
-         if (body->fstream)
-           {
-             mu_stream_close (body->fstream);
-             mu_stream_destroy (&body->fstream);
-           }
-
-         free (body);
-       }
-      *pbody = NULL;
-    }
-}
-
-void *
-mu_body_get_owner (mu_body_t body)
-{
-  return (body) ? body->owner : NULL;
-}
-
-/* FIXME: not implemented.  */
-int
-mu_body_is_modified (mu_body_t body)
-{
-  return (body) ? (body->flags & BODY_MODIFIED) : 0;
-}
-
-/* FIXME: not implemented.  */
-int
-mu_body_clear_modified (mu_body_t body)
-{
-  if (body)
-    body->flags &= ~BODY_MODIFIED;
-  return 0;
-}
-
-int
-mu_body_get_filename (mu_body_t body, char *filename, size_t len, size_t *pn)
-{
-  int n = 0;
-  if (body == NULL)
-    return EINVAL;
-  if (body->filename)
-    {
-      n = strlen (body->filename);
-      if (filename && len > 0)
-       {
-         len--; /* Space for the null.  */
-         strncpy (filename, body->filename, len)[len] = '\0';
-       }
-    }
-  if (pn)
-    *pn = n;
-  return 0;
-}
-
-
-struct _mu_body_stream
-{
-  struct _mu_stream stream;
-  mu_body_t body;
-};
-
-static int
-_body_get_stream (mu_body_t body, mu_stream_t *pstream, int ref)
-{
-  if (body == NULL)
-    return EINVAL;
-  if (pstream == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-
-  if (body->stream == NULL)
-    {
-      if (body->_get_stream)
-       {
-         int status = body->_get_stream (body, &body->stream);
-         if (status)
-           return status;
-       }
-      else
-       {
-         int status;
-         struct _mu_body_stream *str =
-           (struct _mu_body_stream *)
-           _mu_stream_create (sizeof (*str),
-                              MU_STREAM_RDWR|MU_STREAM_SEEK|_MU_STR_OPEN);
-         if (!str)
-           return ENOMEM;
-         
-         /* Create the temporary file.  */
-         body->filename = mu_tempname (NULL);
-         status = mu_file_stream_create (&body->fstream, 
-                                         body->filename, MU_STREAM_RDWR);
-         if (status != 0)
-           return status;
-         mu_stream_set_buffer (body->fstream, mu_buffer_full, 0);
-         str->stream.ctl = _body_ioctl;
-         str->stream.read = _body_read;
-         str->stream.write = _body_write;
-         str->stream.truncate = _body_truncate;
-         str->stream.size = _body_size;
-         str->stream.seek = _body_seek;
-         str->stream.flush = _body_flush;
-         str->body = body;
-         body->stream = (mu_stream_t) str;
-         /* Override the defaults.  */
-         body->_lines = _body_get_lines;
-         body->_size = _body_get_size;
-       }
-    }
-  
-  if (!ref)
-    {
-      *pstream = body->stream;
-      return 0;
-    }
-  return mu_streamref_create (pstream, body->stream);
-}
-
-int
-mu_body_get_stream (mu_body_t body, mu_stream_t *pstream)
-{
-  /* FIXME: Deprecation warning */
-  return _body_get_stream (body, pstream, 0);
-}
-
-int
-mu_body_get_streamref (mu_body_t body, mu_stream_t *pstream)
-{
-  return _body_get_stream (body, pstream, 1);
-}
-
-int
-mu_body_set_stream (mu_body_t body, mu_stream_t stream, void *owner)
-{
-  if (body == NULL)
-   return EINVAL;
-  if (body->owner != owner)
-    return EACCES;
-  /* make sure we destroy the old one if it is owned by the body */
-  mu_stream_destroy (&body->stream);
-  body->stream = stream;
-  body->flags |= BODY_MODIFIED;
-  return 0;
-}
-
-int
-mu_body_set_get_stream (mu_body_t body,
-                       int (*_getstr) (mu_body_t, mu_stream_t *),
-                       void *owner)
-{
-  if (body == NULL)
-    return EINVAL;
-  if (body->owner != owner)
-    return EACCES;
-  body->_get_stream = _getstr;
-  return 0;
-}
-
-int
-mu_body_set_lines (mu_body_t body, int (*_lines) (mu_body_t, size_t *),
-                  void *owner)
-{
-  if (body == NULL)
-    return EINVAL;
-  if (body->owner != owner)
-    return EACCES;
-  body->_lines = _lines;
-  return 0;
-}
-
-int
-mu_body_lines (mu_body_t body, size_t *plines)
-{
-  if (body == NULL)
-    return EINVAL;
-  if (body->_lines)
-    return body->_lines (body, plines);
-  /* Fall on the stream.  */
-  if (body->stream)
-    return _body_get_lines0 (body->stream, plines);
-  if (plines)
-    *plines = 0;
-  return 0;
-}
-
-int
-mu_body_size (mu_body_t body, size_t *psize)
-{
-  if (body == NULL)
-    return EINVAL;
-  if (body->_size)
-    return body->_size (body, psize);
-  /* Fall on the stream.  */
-  if (body->stream)
-    return _body_get_size0 (body->stream, psize);
-  if (psize)
-    *psize = 0;
-  return 0;
-}
-
-int
-mu_body_set_size (mu_body_t body, int (*_size)(mu_body_t, size_t*) , void 
*owner)
-{
-  if (body == NULL)
-    return EINVAL;
-  if (body->owner != owner)
-    return EACCES;
-  body->_size = _size;
-  return 0;
-}
-
-/* Stub function for the body stream.  */
-
-static int
-_body_seek (mu_stream_t stream, mu_off_t off, mu_off_t *presult)
-{
-  struct _mu_body_stream *str = (struct _mu_body_stream*) stream;
-  mu_body_t body = str->body;
-  return mu_stream_seek (body->fstream, off, MU_SEEK_SET, presult);
-}
-
-static const char *
-_body_error_string (mu_stream_t stream, int rc)
-{
-  /* FIXME: How to know if rc was returned by a body->stream? */
-  return NULL;
-}
-
-static int
-_body_ioctl (mu_stream_t stream, int code, void *ptr)
-{
-  struct _mu_body_stream *str = (struct _mu_body_stream*) stream;
-  mu_body_t body = str->body;
-  return mu_stream_ioctl (body->fstream, code, ptr);
-}
-
-static int
-_body_read (mu_stream_t stream, char *buf, size_t size, size_t *pret)
-{
-  struct _mu_body_stream *str = (struct _mu_body_stream*) stream;
-  mu_body_t body = str->body;
-  return mu_stream_read (body->fstream, buf, size, pret);
-}
-
-static int
-_body_write (mu_stream_t stream, const char *buf, size_t size, size_t *pret)
-{
-  struct _mu_body_stream *str = (struct _mu_body_stream*) stream;
-  mu_body_t body = str->body;
-  return mu_stream_write (body->fstream, buf, size, pret);
-}
-
-static int
-_body_truncate (mu_stream_t stream, mu_off_t n)
-{
-  struct _mu_body_stream *str = (struct _mu_body_stream*) stream;
-  mu_body_t body = str->body;
-  return mu_stream_truncate (body->fstream, n);
-}
-
-static int
-_body_size (mu_stream_t stream, mu_off_t *size)
-{
-  struct _mu_body_stream *str = (struct _mu_body_stream*) stream;
-  mu_body_t body = str->body;
-  return mu_stream_size (body->fstream, size);
-}
-
-static int
-_body_flush (mu_stream_t stream)
-{
-  struct _mu_body_stream *str = (struct _mu_body_stream*) stream;
-  mu_body_t body = str->body;
-  return mu_stream_flush (body->fstream);
-}
-
-/* Default function for the body.  */
-static int
-_body_get_lines (mu_body_t body, size_t *plines)
-{
-  return _body_get_lines0 (body->fstream, plines);
-}
-
-static int
-_body_get_size (mu_body_t body, size_t *psize)
-{
-  return _body_get_size0 (body->fstream, psize);
-}
-
-static int
-_body_get_size0 (mu_stream_t stream, size_t *psize)
-{
-  mu_off_t off = 0;
-  int status = mu_stream_size (stream, &off);
-  if (psize)
-    *psize = off;
-  return status;
-}
-
-static int
-_body_get_lines0 (mu_stream_t stream, size_t *plines)
-{
-  int status =  mu_stream_flush (stream);
-  size_t lines = 0;
-  
-  if (status == 0)
-    {
-      char buf[128];
-      size_t n = 0;
-
-      status = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
-      if (status)
-       return status;
-      while ((status = mu_stream_readline (stream, buf, sizeof buf,
-                                          &n)) == 0 && n > 0)
-       {
-         if (buf[n - 1] == '\n')
-           lines++;
-       }
-    }
-  if (plines)
-    *plines = lines;
-  return status;
-}
-
-
diff --git a/libmailutils/cfg/.gitignore b/libmailutils/cfg/.gitignore
new file mode 100644
index 0000000..473803d
--- /dev/null
+++ b/libmailutils/cfg/.gitignore
@@ -0,0 +1,3 @@
+cfg_lexer.c
+cfg_parser.c
+cfg_parser.h
diff --git a/libmailutils/cfg/Makefile.am b/libmailutils/cfg/Makefile.am
new file mode 100644
index 0000000..b46b523
--- /dev/null
+++ b/libmailutils/cfg/Makefile.am
@@ -0,0 +1,54 @@
+# 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/>.
+
+noinst_LTLIBRARIES = libcfg.la
+
+libcfg_la_SOURCES = \
+ driver.c\
+ format.c\
+ lexer.c\
+ parser.c\
+ gocs.c
+
+localedir = $(datadir)/locale
+AM_CPPFLAGS = \
+ -DSYSCONFDIR=\"$(sysconfdir)\"\
+ -DLOCALEDIR=\"$(localedir)\"
+
+INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
+
+EXTRA_DIST = \
+ lexer.l\
+ parser.y\
+ parser.h
+
+BUILT_SOURCES = parser.c parser.h lexer.c
+
+YLWRAP = $(SHELL) $(mu_aux_dir)/gylwrap
+AM_YFLAGS=-vt
+AM_LFLAGS=-dvp
+
+parser.c parser.h: $(srcdir)/parser.y
+       $(YLWRAP) "$(YACC) $(AM_YFLAGS) -d" $< \
+                 y.tab.c parser.c y.tab.h parser.h \
+                  y.output parser.y.output \
+                  -- -yy mu_cfg_yy
+
+lexer.c: $(srcdir)/lexer.l parser.h
+       $(YLWRAP) "$(LEX) $(AM_LFLAGS) $(LFLAGS)" \
+                  $(srcdir)/lexer.l lex.yy.c lexer.c \
+                  -- -yy mu_cfg_yy
diff --git a/libmailutils/cfg/driver.c b/libmailutils/cfg/driver.c
new file mode 100644
index 0000000..33683d4
--- /dev/null
+++ b/libmailutils/cfg/driver.c
@@ -0,0 +1,754 @@
+/* cfg_driver.c -- Main driver for Mailutils configuration files
+   Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 3, or (at
+   your option) any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <mailutils/argcv.h>
+#include <mailutils/nls.h>
+#define MU_CFG_COMPATIBILITY /* This source uses deprecated cfg interfaces */
+#include <mailutils/cfg.h>
+#include <mailutils/errno.h>
+#include <mailutils/error.h>
+#include <mailutils/mutil.h>
+#include <mailutils/monitor.h>
+#include <mailutils/refcount.h>
+#include <mailutils/list.h>
+#include <mailutils/iterator.h>
+#include <mailutils/stream.h>
+#include <mailutils/assoc.h>
+#include <mailutils/alloc.h>
+
+
+static mu_assoc_t section_tab;
+
+static void
+alloc_section_tab ()
+{
+  if (!section_tab)
+    mu_assoc_create (&section_tab, sizeof (struct mu_cfg_cont **),
+                    MU_ASSOC_COPY_KEY);
+}
+
+int
+mu_create_canned_section (char *name, struct mu_cfg_section **psection)
+{
+  int rc;
+  struct mu_cfg_cont **pcont;
+  alloc_section_tab ();
+  rc = mu_assoc_ref_install (section_tab, name, (void **)&pcont);
+  if (rc == 0)
+    {
+      mu_config_create_container (pcont, mu_cfg_cont_section);
+      *psection = &(*pcont)->v.section;
+      (*psection)->ident = name;
+    }
+  else if (rc == MU_ERR_EXISTS)
+    *psection = &(*pcont)->v.section;
+  return rc;
+}
+
+int
+mu_create_canned_param (char *name, struct mu_cfg_param **pparam)
+{
+  int rc;
+  struct mu_cfg_cont **pcont;
+  alloc_section_tab ();
+  rc = mu_assoc_ref_install (section_tab, name, (void **)&pcont);
+  if (rc == 0)
+    {
+      mu_config_create_container (pcont, mu_cfg_cont_param);
+      *pparam = &(*pcont)->v.param;
+      (*pparam)->ident = name;
+    }
+  else if (rc == MU_ERR_EXISTS)
+    *pparam = &(*pcont)->v.param;
+  return rc;
+}
+
+struct mu_cfg_cont *
+mu_get_canned_container (const char *name)
+{
+  struct mu_cfg_cont **pcont = mu_assoc_ref (section_tab, name);
+  return pcont ? *pcont : NULL;
+}
+
+
+static struct mu_cfg_cont *root_container;
+
+int
+mu_config_create_container (struct mu_cfg_cont **pcont,
+                           enum mu_cfg_cont_type type)
+{
+  struct mu_cfg_cont *cont;
+  int rc;
+  
+  cont = calloc (1, sizeof (*cont));
+  if (!cont)
+    return ENOMEM;
+  rc = mu_refcount_create (&cont->refcount);
+  if (rc)
+    free (cont);
+  else
+    {
+      cont->type = type;
+      *pcont = cont;
+    }
+  return rc; 
+}  
+
+
+struct dup_data
+{
+  struct mu_cfg_cont *cont;
+};
+
+static int dup_container (struct mu_cfg_cont **pcont);
+
+static int
+_dup_cont_action (void *item, void *cbdata)
+{
+  int rc;
+  struct mu_cfg_cont *cont = item;
+  struct dup_data *pdd = cbdata;
+
+  rc = dup_container (&cont);
+  if (rc)
+    return rc;
+
+  if (!pdd->cont->v.section.children)
+    {
+      int rc = mu_list_create (&pdd->cont->v.section.children);
+      if (rc)
+       return rc;
+    }
+  return mu_list_append (pdd->cont->v.section.children, cont);
+}
+
+static int
+dup_container (struct mu_cfg_cont **pcont)
+{
+  int rc;
+  struct mu_cfg_cont *newcont, *oldcont = *pcont;
+  struct dup_data dd;
+
+  rc = mu_config_create_container (&newcont, oldcont->type);
+  if (rc)
+    return rc;
+
+  dd.cont = newcont;
+  switch (oldcont->type)
+    {
+    case mu_cfg_cont_section:
+      newcont->v.section.ident = oldcont->v.section.ident;
+      newcont->v.section.label = oldcont->v.section.label;
+      newcont->v.section.parser = oldcont->v.section.parser;
+      newcont->v.section.target = oldcont->v.section.target;
+      newcont->v.section.offset = oldcont->v.section.offset;
+      newcont->v.section.docstring = oldcont->v.section.docstring;
+      newcont->v.section.children = NULL;
+      mu_list_do (oldcont->v.section.children, _dup_cont_action, &dd);
+      break;
+
+    case mu_cfg_cont_param:
+      newcont->v.param = oldcont->v.param;
+      break;
+    }
+  *pcont = newcont;
+  return 0;
+}
+
+
+static void
+destroy_list (mu_list_t *plist)
+{
+  mu_list_t list = *plist;
+  mu_iterator_t itr = NULL;
+  
+  if (!list)
+    return;
+
+  mu_list_get_iterator (list, &itr);
+  for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
+       mu_iterator_next (itr))
+    {
+      struct mu_cfg_cont *cont, *p;
+      mu_iterator_current (itr, (void**)&cont);
+      p = cont;
+      mu_config_destroy_container (&p);
+      if (!p)
+       mu_list_remove (list, cont);
+    }
+  mu_iterator_destroy (&itr);
+  if (mu_list_is_empty (list))
+    mu_list_destroy (plist);
+}
+
+void
+mu_config_destroy_container (struct mu_cfg_cont **pcont)
+{
+  struct mu_cfg_cont *cont = *pcont;
+  unsigned refcount = mu_refcount_dec (cont->refcount);
+  /* printf ("destr %p-%s: %d\n", cont, cont->v.section.ident, refcount); */
+  switch (cont->type)
+    {
+    case mu_cfg_cont_section:
+      destroy_list (&cont->v.section.children);
+      break;
+
+    case mu_cfg_cont_param:
+      break;
+    }
+
+  if (refcount == 0)
+    {
+      free (cont);
+      *pcont = 0;
+    }
+}
+     
+
+int
+mu_cfg_section_add_container (struct mu_cfg_section *sect,
+                             struct mu_cfg_cont *cont)
+{
+  if (!cont)
+    return 0;
+  if (!sect->children)
+    mu_list_create (&sect->children);
+  return mu_list_append (sect->children, cont);
+}
+
+int
+mu_cfg_section_add_params (struct mu_cfg_section *sect,
+                          struct mu_cfg_param *param)
+{
+  if (!param)
+    return 0;
+
+  for (; param->ident; param++)
+    {
+      int rc;
+      struct mu_cfg_cont *container;
+
+      if (param->type == mu_cfg_section)
+       {
+         container = mu_get_canned_container (param->ident);
+         if (!container)
+           {
+             mu_error (_("INTERNAL ERROR: Requested unknown canned "
+                         "section %s"),
+                       param->ident);
+             abort ();
+           }
+         if (param->ident[0] == '.')
+           {
+             mu_iterator_t itr;
+             mu_list_get_iterator (container->v.section.children, &itr);
+             for (mu_iterator_first (itr);
+                  !mu_iterator_is_done (itr);
+                  mu_iterator_next (itr))
+               {
+                 struct mu_cfg_cont *c;
+                 mu_iterator_current (itr, (void**)&c);
+                 mu_config_clone_container (c);
+                 if (mu_refcount_value (c->refcount) > 1)
+                   dup_container (&c);
+                 switch (c->type)
+                   {
+                   case mu_cfg_cont_section:
+                     c->v.section.offset += param->offset;
+                     break;
+
+                   case mu_cfg_cont_param:
+                     container->v.param.offset += param->offset;
+                     break;
+                   }
+                 mu_cfg_section_add_container (sect, c);
+               }
+             mu_iterator_destroy (&itr);
+             continue;
+           }
+         else
+           {
+             mu_config_clone_container (container);
+             if (mu_refcount_value (container->refcount) > 1)
+               dup_container (&container);
+             container->v.section.target = param->data;
+             container->v.section.offset = param->offset;
+           }
+       }
+      else
+       {
+         rc = mu_config_create_container (&container, mu_cfg_cont_param);
+         if (rc)
+           return rc;
+         container->v.param = *param;
+       }
+      mu_cfg_section_add_container (sect, container);
+    }
+  return 0;
+}
+
+static int
+_clone_action (void *item, void *cbdata)
+{
+  struct mu_cfg_cont *cont = item;
+  return mu_config_clone_container (cont);
+}
+
+int
+mu_config_clone_container (struct mu_cfg_cont *cont)
+{
+  if (!cont)
+    return 0;
+  mu_refcount_inc (cont->refcount);
+  /* printf("clone %p-%s: %d\n", cont, cont->v.section.ident, n); */
+  switch (cont->type)
+    {
+    case mu_cfg_cont_section:
+      mu_list_do (cont->v.section.children, _clone_action, NULL);
+      break;
+
+    case mu_cfg_cont_param:
+      break;
+    }
+  return 0;
+}  
+
+
+int
+_mu_config_register_section (struct mu_cfg_cont **proot,
+                            const char *parent_path,
+                            const char *ident,
+                            const char *label,
+                            mu_cfg_section_fp parser,
+                            struct mu_cfg_param *param,
+                            struct mu_cfg_section **psection)
+{
+  int rc;
+  struct mu_cfg_section *root_section;
+  struct mu_cfg_section *parent;
+  
+  if (!*proot)
+    {
+      rc = mu_config_create_container (proot, mu_cfg_cont_section);
+      if (rc)
+       return rc;
+      memset (&(*proot)->v.section, 0, sizeof (*proot)->v.section);
+    }
+  
+  root_section = &(*proot)->v.section;
+  
+  if (parent_path)
+    {
+      if (mu_cfg_find_section (root_section, parent_path, &parent))
+       return MU_ERR_NOENT;
+    }
+  else  
+    parent = root_section;
+
+  if (mu_refcount_value ((*proot)->refcount) > 1)
+    {
+      /* It is a clone, do copy-on-write */
+      rc = dup_container (proot);
+      if (rc)
+       return rc;
+
+      root_section = &(*proot)->v.section;
+      
+      if (parent_path)
+       {
+         if (mu_cfg_find_section (root_section, parent_path, &parent))
+           return MU_ERR_NOENT;
+       }
+      else  
+       parent = root_section;
+    }
+
+  if (ident)
+    {
+      struct mu_cfg_cont *container;
+      struct mu_cfg_section *s;
+      
+      if (!parent->children)
+       mu_list_create (&parent->children);
+      mu_config_create_container (&container, mu_cfg_cont_section);
+      mu_list_append (parent->children, container); 
+      s = &container->v.section;
+
+      s->ident = strdup (ident);
+      s->label = label ? strdup (label) : NULL;
+      s->parser = parser;
+      s->children = NULL;
+      mu_cfg_section_add_params (s, param);
+      if (psection)
+       *psection = s;
+    }
+  else
+    {
+      mu_cfg_section_add_params (parent, param);
+      /* FIXME: */
+      if (!parent->parser)
+       parent->parser = parser;
+      if (psection)
+       *psection = parent;
+    }
+  return 0;
+}
+  
+int
+mu_config_register_section (const char *parent_path,
+                           const char *ident,
+                           const char *label,
+                           mu_cfg_section_fp parser,
+                           struct mu_cfg_param *param)
+{
+  return _mu_config_register_section (&root_container,
+                                     parent_path,
+                                     ident, label,
+                                     parser, param, NULL);
+}
+
+int
+mu_config_register_plain_section (const char *parent_path, const char *ident,
+                                 struct mu_cfg_param *params)
+{
+  return mu_config_register_section (parent_path, ident, NULL, NULL, params);
+}
+
+static int
+prog_parser (enum mu_cfg_section_stage stage,
+            const mu_cfg_node_t *node,
+            const char *label, void **section_data,
+            void *call_data,
+            mu_cfg_tree_t *tree)
+{
+  if (stage == mu_cfg_section_start)
+    {
+      return node->label->type == MU_CFG_STRING
+            && strcmp (node->label->v.string, label);
+    }
+  
+  return 0;
+}
+
+struct include_data
+{
+  const char *progname;
+  struct mu_cfg_param *progparam;
+  int flags;
+  void *target;
+};
+
+static int
+_cb_include (mu_debug_t debug, void *data, mu_config_value_t *val)
+{
+  int ret = 0;
+  struct stat sb;
+  const char *dirname;
+  struct include_data *idp = data;
+  char *tmp = NULL;
+
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING, debug))
+    return 1;
+
+  dirname = val->v.string;
+  if (dirname[0] != '/')
+    {
+      dirname = tmp = mu_make_file_name (SYSCONFDIR, dirname);
+      if (!dirname)
+        {
+          mu_error ("%s", mu_strerror (errno));
+          return 1;
+        }
+    }
+    
+  if (stat (dirname, &sb) == 0)
+    {
+      if (S_ISDIR (sb.st_mode))
+       {
+         char *file = mu_make_file_name (dirname, idp->progname);
+         ret = mu_get_config (file, idp->progname, idp->progparam,
+                              idp->flags & ~MU_PARSE_CONFIG_GLOBAL,
+                              idp->target);
+       }
+      else
+       ret = mu_get_config (dirname, idp->progname, idp->progparam,
+                            idp->flags, idp->target);
+    }
+  else if (errno == ENOENT)
+    {
+      mu_cfg_format_error (debug, MU_DEBUG_ERROR,
+                          _("include file or directory does not exist"));
+      ret = 1;
+    }
+  else
+    {
+      mu_cfg_format_error (debug, MU_DEBUG_ERROR,
+                          _("cannot stat include file or directory: %s"),
+                          mu_strerror (errno));
+      ret = 1;
+    }
+  free (tmp);
+  return ret;
+}
+
+struct mu_cfg_cont *
+mu_build_container (const char *progname, struct include_data *idp)
+{
+  struct mu_cfg_cont *cont = root_container;
+
+  mu_config_clone_container (cont);
+  
+  if (idp->flags & MU_PARSE_CONFIG_PLAIN)
+    {
+      struct mu_cfg_param mu_include_param[] = {
+       { "include", mu_cfg_callback, NULL, 0, _cb_include,
+         N_("Include contents of the given file.  If a directory is given, "
+            "include contents of the file <file>/<program>, where "
+            "<program> is the name of the program.  This latter form is "
+            "allowed only in the site-wide configuration file."),
+         N_("file-or-directory") },
+       { NULL }
+      };
+
+      mu_include_param[0].data = idp;
+      _mu_config_register_section (&cont, NULL, NULL, NULL,
+                                  (void*) progname, mu_include_param, NULL);
+      
+      if (idp->flags & MU_PARSE_CONFIG_GLOBAL)
+       {
+         mu_iterator_t iter;
+         struct mu_cfg_section *prog_sect;
+         struct mu_cfg_cont *old_root = root_container;
+         static struct mu_cfg_param empty_param = { NULL };
+         
+         _mu_config_register_section (&cont, NULL, "program", progname,
+                                      prog_parser,
+                                      idp->progparam ?
+                                      idp->progparam : &empty_param,
+                                      &prog_sect);
+      
+         if (old_root->v.section.children)
+           {
+             if (!prog_sect->children)
+               mu_list_create (&prog_sect->children);
+             mu_list_get_iterator (old_root->v.section.children, &iter);
+             for (mu_iterator_first (iter); !mu_iterator_is_done (iter);
+                  mu_iterator_next (iter))
+               {
+                 struct mu_cfg_cont *c;
+                 mu_iterator_current (iter, (void**)&c);
+                 mu_list_append (prog_sect->children, c);
+               }
+             mu_iterator_destroy (&iter);
+           }
+       }
+      else if (idp->progparam)
+       _mu_config_register_section (&cont, NULL, NULL, NULL, NULL,
+                                    idp->progparam, NULL);
+    }
+  else if (idp->progparam)
+    _mu_config_register_section (&cont, NULL, NULL, NULL, NULL,
+                                idp->progparam, NULL);
+  
+  return cont;
+}
+
+int
+mu_cfg_tree_reduce (mu_cfg_tree_t *parse_tree, const char *progname,
+                   struct mu_cfg_param *progparam, int flags,
+                   void *target_ptr)
+{
+  int rc = 0;
+
+  if (!parse_tree)
+    return 0;
+  if (flags & MU_PARSE_CONFIG_DUMP)
+    {
+      mu_stream_t stream;
+      mu_stdio_stream_create (&stream, MU_STDERR_FD, 0);
+      mu_cfg_format_parse_tree (stream, parse_tree, MU_CFG_FMT_LOCUS);
+      mu_stream_destroy (&stream);
+    }
+
+  if (root_container)
+    {
+      struct include_data idata;
+      struct mu_cfg_cont *cont;
+      
+      idata.progname = progname;
+      idata.progparam = progparam;
+      idata.flags = flags;
+      idata.target = target_ptr;
+      
+      cont = mu_build_container (progname, &idata);
+      
+      rc = mu_cfg_scan_tree (parse_tree, &cont->v.section, target_ptr,
+                            (void*) progname);
+      mu_config_destroy_container (&cont);
+    }
+
+  return rc;
+}
+
+void
+mu_format_config_tree (mu_stream_t stream, const char *progname,
+                      struct mu_cfg_param *progparam, int flags)
+{
+  struct include_data idata;
+  struct mu_cfg_cont *cont;
+  
+  idata.progname = progname;
+  idata.progparam = progparam;
+  idata.flags = flags;
+  idata.target = NULL;
+  cont = mu_build_container (progname, &idata);
+  mu_cfg_format_container (stream, cont);
+  mu_config_destroy_container (&cont);
+}
+
+int
+mu_parse_config (const char *file, const char *progname,
+                struct mu_cfg_param *progparam, int flags,
+                void *target_ptr)
+{
+  int rc;
+  char *full_name = mu_tilde_expansion (file, "/", NULL);
+  if (full_name)
+    {
+      if (access (full_name, R_OK) == 0)
+       {
+         rc = mu_get_config (full_name, progname, progparam, flags,
+                             target_ptr);
+       }
+      else
+       rc = ENOENT;
+      free (full_name);
+    }
+  else
+    rc = ENOMEM;
+  return rc;
+}
+
+static const char *
+_first_value_ptr (mu_config_value_t *val)
+{
+  switch (val->type)
+    {
+    case MU_CFG_STRING:
+      return val->v.string;
+      
+    case MU_CFG_ARRAY:
+      return _first_value_ptr (val->v.arg.v);
+      
+    case MU_CFG_LIST:
+      mu_list_get (val->v.list, 0, (void**) &val);
+      return _first_value_ptr (val);
+    }
+  return "";  
+}
+
+int
+mu_cfg_assert_value_type (mu_config_value_t *val, int type, mu_debug_t debug)
+{
+  if (!val)
+    { 
+      mu_cfg_format_error (debug, MU_DEBUG_ERROR,
+                           _("required argument missing"));
+      return 1;
+    }
+
+  if (type == MU_CFG_ARRAY)
+    {
+      if (val->type == MU_CFG_STRING)
+       {
+         mu_config_value_t *arr = mu_calloc (1, sizeof arr[0]);
+         arr[0] = *val;
+         val->v.arg.c = 1;
+         val->v.arg.v = arr;
+         val->type = MU_CFG_ARRAY;
+       }
+    }
+  
+  if (val->type != type)
+    {
+      /* FIXME */
+      mu_cfg_format_error (debug, MU_DEBUG_ERROR,
+                          _("unexpected value: %s"), 
+                          _first_value_ptr (val));
+      return 1;
+    }
+  return 0;
+}
+
+int
+mu_cfg_string_value_cb (mu_debug_t debug, mu_config_value_t *val,
+                       int (*fun) (mu_debug_t, const char *, void *),
+                       void *data)
+{
+  int rc = 0;
+  
+  switch (val->type)
+    {
+    case MU_CFG_STRING:
+      return fun (debug, val->v.string, data);
+      break;
+
+    case MU_CFG_ARRAY:
+      {
+       int i;
+
+       for (i = 0; i < val->v.arg.c; i++)
+         {
+           if (mu_cfg_assert_value_type (&val->v.arg.v[i],
+                                         MU_CFG_STRING, debug))
+             return 1;
+           fun (debug, val->v.arg.v[i].v.string, data);
+         }
+      }
+      break;
+
+    case MU_CFG_LIST:
+      {
+       mu_iterator_t itr;
+       mu_list_get_iterator (val->v.list, &itr);
+       for (mu_iterator_first (itr);
+            !mu_iterator_is_done (itr); mu_iterator_next (itr))
+         {
+           mu_config_value_t *pval;
+           mu_iterator_current (itr, (void*) &pval);
+           if (mu_cfg_assert_value_type (pval, MU_CFG_STRING, debug))
+             {
+               rc = 1;
+               break;
+             }
+           fun (debug, pval->v.string, data);
+         }
+       mu_iterator_destroy (&itr);
+      }
+    }
+  return rc;
+}
diff --git a/libmailutils/cfg/format.c b/libmailutils/cfg/format.c
new file mode 100644
index 0000000..e7aaa7b
--- /dev/null
+++ b/libmailutils/cfg/format.c
@@ -0,0 +1,395 @@
+/* cfg_format.c -- convert configuration parse tree to human-readable format.
+   Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 3, or (at
+   your option) any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <mailutils/alloc.h>
+#include <mailutils/stream.h>
+#include <mailutils/error.h>
+#include <mailutils/cfg.h>
+#include <mailutils/argcv.h>
+#include <mailutils/nls.h>
+#include <mailutils/iterator.h>
+#include <ctype.h>
+
+struct tree_print
+{
+  int flags;
+  unsigned level;
+  mu_stream_t stream;
+  char *buf;
+  size_t bufsize;
+};
+
+static void
+format_level (mu_stream_t stream, int level)
+{
+  while (level--)
+    mu_stream_write (stream, "  ", 2, NULL);
+}
+
+static void
+format_string_value (struct tree_print *tp, const char *str)
+{
+  size_t size;
+  int quote;
+  char *p;
+
+  size = mu_argcv_quoted_length (str, &quote);
+  if (quote)
+    size += 2;
+  size++;
+  if (size > tp->bufsize)
+    {
+      p = mu_realloc (tp->buf, size);
+      tp->bufsize = size;
+      tp->buf = p;
+    }
+  
+  p = tp->buf;
+  if (quote)
+    {
+      tp->buf[0] = '"';
+      tp->buf[size-2] = '"';
+      p++;
+    }
+  tp->buf[size-1] = 0;
+  mu_argcv_quote_copy (p, str);
+  mu_stream_write (tp->stream, tp->buf, size - 1, NULL);
+}
+
+static void format_value (struct tree_print *tp, mu_config_value_t *val);
+
+static void
+format_list_value (struct tree_print *tp, mu_config_value_t *val)
+{
+  int i;
+  mu_iterator_t itr;
+  mu_stream_write (tp->stream, "(", 1, NULL);
+  mu_list_get_iterator (val->v.list, &itr);
+  
+  for (mu_iterator_first (itr), i = 0;
+       !mu_iterator_is_done (itr); mu_iterator_next (itr), i++)
+    {
+      mu_config_value_t *p;
+      mu_iterator_current (itr, (void**)&p);
+      if (i)
+       mu_stream_write (tp->stream, ", ", 2, NULL);
+      format_value (tp, p);
+    }
+  mu_iterator_destroy (&itr);
+  mu_stream_write (tp->stream, ")", 1, NULL);
+}
+
+static void
+format_array_value (struct tree_print *tp, mu_config_value_t *val)
+{
+  int i;
+
+  for (i = 0; i < val->v.arg.c; i++)
+    {
+      if (i)
+       mu_stream_write (tp->stream, " ", 1, NULL);
+      format_value (tp, &val->v.arg.v[i]);
+    }
+}
+    
+static void
+format_value (struct tree_print *tp, mu_config_value_t *val)
+{
+  switch (val->type)
+    {
+    case MU_CFG_STRING:
+      format_string_value (tp, val->v.string);
+      break;
+
+    case MU_CFG_LIST:
+      format_list_value (tp, val);
+      break;
+
+    case MU_CFG_ARRAY:
+      format_array_value (tp, val);
+    }
+}
+
+static int
+format_node (const mu_cfg_node_t *node, void *data)
+{
+  struct tree_print *tp = data;
+
+  if ((tp->flags & MU_CFG_FMT_LOCUS) && node->locus.file)
+    mu_stream_printf (tp->stream, "# %lu \"%s\"\n",
+                     (unsigned long) node->locus.line, 
+                     node->locus.file);
+  format_level (tp->stream, tp->level);
+  switch (node->type)
+    {
+    case mu_cfg_node_undefined:
+      mu_stream_printf (tp->stream, "%s",
+                       _("ERROR: undefined statement"));
+      break;
+
+    case mu_cfg_node_statement:
+      {
+       mu_stream_write (tp->stream, node->tag, strlen (node->tag), NULL);
+       if (node->label)
+         {
+           mu_stream_write (tp->stream, " ", 1, NULL);
+           format_value (tp, node->label);
+         }
+       mu_stream_write (tp->stream, " {", 2, NULL);
+       tp->level++;
+      }
+      break;
+
+    case mu_cfg_node_param:
+      mu_stream_write (tp->stream, node->tag, strlen (node->tag), NULL);
+      if (node->label)
+       {
+         mu_stream_write (tp->stream, " ", 1, NULL);
+         format_value (tp, node->label);
+         mu_stream_write (tp->stream, ";", 1, NULL);
+       }
+      break;
+    }
+  mu_stream_write (tp->stream, "\n", 1, NULL);
+  return MU_CFG_ITER_OK;
+}
+
+static int
+format_node_end (const mu_cfg_node_t *node, void *data)
+{
+  struct tree_print *tp = data;
+  tp->level--;
+  format_level (tp->stream, tp->level);
+  mu_stream_write (tp->stream, "};\n", 3, NULL);
+  return MU_CFG_ITER_OK;
+}
+
+void
+mu_cfg_format_parse_tree (mu_stream_t stream, mu_cfg_tree_t *tree, int flags)
+{
+  struct mu_cfg_iter_closure clos;
+  struct tree_print t;
+
+  t.flags = flags;
+  t.level = 0;
+  t.stream = stream;
+  t.buf = NULL;
+  t.bufsize = 0;
+  clos.beg = format_node;
+  clos.end = format_node_end;
+  clos.data = &t;
+  mu_cfg_preorder (tree->nodes, &clos);
+  free (t.buf);
+}
+
+void
+mu_cfg_format_node (mu_stream_t stream, const mu_cfg_node_t *node, int flags)
+{
+  struct tree_print t;
+  
+  t.flags = flags;
+  t.level = 0;
+  t.stream = stream;
+  t.buf = NULL;
+  t.bufsize = 0;
+  format_node (node, &t);
+  if (node->type == mu_cfg_node_statement)
+    {
+      struct mu_cfg_iter_closure clos;
+      clos.beg = format_node;
+      clos.end = format_node_end;
+      clos.data = &t;
+      mu_cfg_preorder (node->nodes, &clos);
+      format_node_end (node, &t);
+    }
+}
+
+
+
+const char *
+mu_cfg_data_type_string (enum mu_cfg_param_data_type type)
+{
+  switch (type)
+    {
+    case mu_cfg_string:
+      return N_("string");
+    case mu_cfg_short:
+    case mu_cfg_ushort:
+    case mu_cfg_int:
+    case mu_cfg_uint:
+    case mu_cfg_long:
+    case mu_cfg_ulong:
+    case mu_cfg_size:
+    case mu_cfg_off:
+      return N_("number");
+    case mu_cfg_time:
+      return N_("time");
+    case mu_cfg_bool:
+      return N_("boolean");
+    case mu_cfg_ipv4:
+      return N_("ipv4");
+    case mu_cfg_cidr:
+      return N_("cidr");
+    case mu_cfg_host:
+      return N_("host");
+    case mu_cfg_callback:
+      return N_("string");
+    case mu_cfg_section:
+      return N_("section");
+    }
+  return N_("unknown");
+}
+
+void
+mu_cfg_format_docstring (mu_stream_t stream, const char *docstring, int level)
+{
+  size_t len = strlen (docstring);
+  int width = 78 - level * 2;
+
+  if (width < 0)
+    {
+      width = 78;
+      level = 0;
+    }
+  
+  while (len)
+    {
+      size_t seglen;
+      const char *p;
+      
+      for (seglen = 0, p = docstring; p < docstring + width && *p; p++)
+       {
+         if (*p == '\n')
+           {
+             seglen = p - docstring;
+             break;
+           }
+         if (isspace (*p))
+           seglen = p - docstring;
+       }
+      if (seglen == 0 || *p == 0)
+       seglen = p - docstring;
+
+      format_level (stream, level);
+      mu_stream_write (stream, "# ", 2, NULL);
+      mu_stream_write (stream, docstring, seglen, NULL);
+      mu_stream_write (stream, "\n", 1, NULL);
+      len -= seglen;
+      docstring += seglen;
+      if (*docstring == '\n')
+       {
+         docstring++;
+         len--;
+       }
+      else
+       while (*docstring && isspace (*docstring))
+         {
+           docstring++;
+           len--;
+         }
+    }
+}
+
+static void
+format_param (mu_stream_t stream, struct mu_cfg_param *param, int level)
+{
+  if (param->docstring)
+    mu_cfg_format_docstring (stream, gettext (param->docstring), level);
+  format_level (stream, level);
+  if (param->argname && strchr (param->argname, ':'))
+    mu_stream_printf (stream, "%s <%s>;\n",
+                     param->ident,
+                     gettext (param->argname));
+  else if (MU_CFG_IS_LIST (param->type))
+    mu_stream_printf (stream, "%s <%s: list of %s>;\n",
+                     param->ident,
+                     gettext (param->argname ?
+                              param->argname : N_("arg")),
+       gettext (mu_cfg_data_type_string (MU_CFG_TYPE (param->type))));
+  else
+    mu_stream_printf (stream, "%s <%s: %s>;\n",
+                     param->ident,
+                     gettext (param->argname ?
+                              param->argname : N_("arg")),
+                     gettext (mu_cfg_data_type_string (param->type)));
+}
+
+static void format_container (mu_stream_t stream, struct mu_cfg_cont *cont,
+                             int level);
+
+static int
+_f_helper (void *item, void *data)
+{
+  struct tree_print *tp = data;
+  struct mu_cfg_cont *cont = item;
+  format_container (tp->stream, cont, tp->level);
+  return 0;
+}
+  
+static void
+format_section (mu_stream_t stream, struct mu_cfg_section *sect, int level)
+{
+  struct tree_print c;
+  if (sect->docstring)
+    mu_cfg_format_docstring (stream, gettext (sect->docstring), level);
+  format_level (stream, level);
+  if (sect->ident)
+    {
+      mu_stream_write (stream, sect->ident, strlen (sect->ident), NULL);
+      if (sect->label)
+       {
+         mu_stream_write (stream, " ", 1, NULL);
+         mu_stream_write (stream, sect->label, strlen (sect->label), NULL);
+       }
+      mu_stream_write (stream, " {\n", 3, NULL);
+      c.stream = stream;
+      c.level = level + 1; 
+      mu_list_do (sect->children, _f_helper, &c);
+      format_level (stream, level);
+      mu_stream_write (stream, "};\n\n", 4, NULL);
+    }
+  else
+    {
+      c.stream = stream;
+      c.level = level; 
+      mu_list_do (sect->children, _f_helper, &c);
+    }
+}
+
+static void
+format_container (mu_stream_t stream, struct mu_cfg_cont *cont, int level)
+{
+  switch (cont->type)
+    {
+    case mu_cfg_cont_section:
+      format_section (stream, &cont->v.section, level);
+      break;
+
+    case mu_cfg_cont_param:
+      format_param (stream, &cont->v.param, level);
+      break;
+    }
+}
+
+void
+mu_cfg_format_container (mu_stream_t stream, struct mu_cfg_cont *cont)
+{
+  format_container (stream, cont, 0);
+}
diff --git a/libmailutils/cfg/gocs.c b/libmailutils/cfg/gocs.c
new file mode 100644
index 0000000..e6b14b4
--- /dev/null
+++ b/libmailutils/cfg/gocs.c
@@ -0,0 +1,396 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2007, 2008, 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/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/types.h>
+#include <mailutils/gocs.h>
+#include <mailutils/mailbox.h>
+#include <mailutils/locker.h>
+#include <mailutils/mutil.h>
+#include <mailutils/mailer.h>
+#include <mailutils/error.h>
+#include <mailutils/errno.h>
+#include <mailutils/nls.h>
+#include <mailutils/debug.h>
+#include <mailutils/syslog.h>
+#include <mailutils/registrar.h>
+#include <syslog.h>
+
+int mu_load_user_rcfile = 1;
+int mu_load_site_rcfile = 1;
+char *mu_load_rcfile = NULL;
+
+
+int
+mu_gocs_dummy (enum mu_gocs_op op, void *data)
+{
+  return 0;
+}
+
+int
+mu_gocs_mailbox_init (enum mu_gocs_op op, void *data)
+{
+  int rc;
+  struct mu_gocs_mailbox *p = data;
+
+  if (op == mu_gocs_op_set && p)
+    {
+      if (p->mail_spool)
+       {
+         rc = mu_set_mail_directory (p->mail_spool);
+         if (rc)
+           mu_error (_("cannot set mail directory name to `%s': %s"),
+                     p->mail_spool, mu_strerror (rc));
+         free (p->mail_spool);
+         p->mail_spool = NULL;
+       }
+      if (p->mailbox_pattern)
+       {
+         rc = mu_set_mailbox_pattern (p->mailbox_pattern);
+         if (rc)
+           mu_error (_("cannot set mailbox pattern to `%s': %s"),
+                     p->mailbox_pattern, mu_strerror (rc));
+         free (p->mailbox_pattern);
+         p->mailbox_pattern = NULL;
+       }
+      if (p->mailbox_type)
+       {
+         if (mu_registrar_set_default_scheme (p->mailbox_type))
+           mu_error (_("invalid mailbox type: %s"), p->mailbox_type);
+         free (p->mailbox_type);
+         p->mailbox_type = NULL;
+       }
+    }
+  return 0;
+}
+
+int
+mu_gocs_locking_init (enum mu_gocs_op op, void *data)
+{
+  struct mu_gocs_locking *p = data;
+  
+  if (!(op == mu_gocs_op_set && p))
+    return 0;
+
+  if (p->lock_flags)
+    {
+      int flags = 0;
+      char *s;
+      
+      for (s = p->lock_flags; *s; s++)
+       {
+         switch (*s)
+           {
+           case 'E':
+             flags |= MU_LOCKER_EXTERNAL;
+             break;
+             
+           case 'R':
+             flags |= MU_LOCKER_RETRY;
+             break;
+             
+           case 'T':
+             flags |= MU_LOCKER_TIME;
+             break;
+             
+           case 'P':
+             flags |= MU_LOCKER_PID;
+             break;
+             
+           default:
+             mu_error (_("invalid lock flag `%c'"), *s);
+           }
+       }
+      mu_locker_set_default_flags (flags, mu_locker_assign);
+      free (p->lock_flags);
+      p->lock_flags = NULL;
+    }
+
+  if (p->lock_retry_count)
+    {
+      mu_locker_set_default_retry_count (p->lock_retry_count);
+      mu_locker_set_default_flags (MU_LOCKER_RETRY, mu_locker_set_bit);
+      p->lock_retry_count = 0;
+    }
+
+  if (p->lock_retry_timeout)
+    {
+      mu_locker_set_default_retry_timeout (p->lock_retry_timeout);
+      mu_locker_set_default_flags (MU_LOCKER_RETRY, mu_locker_set_bit);
+      p->lock_retry_timeout = 0;
+    }
+
+  if (p->lock_expire_timeout)
+    {
+      mu_locker_set_default_expire_timeout (p->lock_expire_timeout);
+      mu_locker_set_default_flags (MU_LOCKER_EXTERNAL, mu_locker_set_bit);
+      p->lock_expire_timeout = 0;
+    }
+
+  if (p->external_locker)
+    {
+      mu_locker_set_default_external_program (p->external_locker);
+      mu_locker_set_default_flags (MU_LOCKER_TIME, mu_locker_set_bit);
+      free (p->external_locker);
+      p->external_locker = NULL;
+    }
+  return 0;
+}
+
+int
+mu_gocs_source_email_init (enum mu_gocs_op op, void *data)
+{
+  struct mu_gocs_source_email *p = data;
+  int rc;
+
+  if (!(op == mu_gocs_op_set && p))
+    return 0;
+  
+  if (p->address)
+    {
+      if ((rc = mu_set_user_email (p->address)) != 0)
+       mu_error (_("invalid email address `%s': %s"),
+                 p->address, mu_strerror (rc));
+      free (p->address);
+      p->address = NULL;
+    }
+
+  if (p->domain)
+    {
+      if ((rc = mu_set_user_email_domain (p->domain)) != 0)
+       mu_error (_("invalid email domain `%s': %s"),
+                 p->domain, mu_strerror (rc));
+
+      free (p->domain);
+      p->domain = NULL;
+    }
+  return 0;
+}
+
+int
+mu_gocs_mailer_init (enum mu_gocs_op op, void *data)
+{
+  struct mu_gocs_mailer *p = data;
+  int rc;
+
+  if (!(op == mu_gocs_op_set && p))
+    return 0;
+  
+  if (p->mailer)
+    {
+      if ((rc = mu_mailer_set_url_default (p->mailer)) != 0)
+       mu_error (_("invalid mailer URL `%s': %s"),
+                 p->mailer, mu_strerror (rc));
+      free (p->mailer);
+      p->mailer = NULL;
+    }
+  return 0;
+}
+
+int
+mu_gocs_logging_init (enum mu_gocs_op op, void *data)
+{
+  struct mu_gocs_logging *p = data;
+
+  if (op == mu_gocs_op_set)
+    {
+      if (!p)
+       {
+         static struct mu_gocs_logging default_gocs_logging = { LOG_FACILITY };
+         p = &default_gocs_logging;
+       }
+  
+      if (p->facility)
+       {
+         mu_log_facility = p->facility;
+         mu_debug_default_printer = mu_debug_syslog_printer;
+       }
+      else
+       mu_debug_default_printer = mu_debug_stderr_printer;
+
+      if (p->tag)
+       mu_log_tag = strdup (p->tag);
+    }
+  return 0;
+}
+
+int
+mu_gocs_debug_init (enum mu_gocs_op op, void *data)
+{
+  if (op == mu_gocs_op_set && data)
+    {
+      struct mu_gocs_debug *p = data;
+      if (p->string && p->errpfx)
+       {
+         mu_global_debug_from_string (p->string, p->errpfx);
+         free (p->errpfx);
+       }
+      if (p->line_info >= 0)
+       mu_debug_line_info = p->line_info;
+    }
+  return 0;
+}
+
+
+struct mu_gocs_entry
+{
+  const char *name;
+  mu_gocs_init_fp init;
+};
+
+#define MAX_GOCS 512
+
+static struct mu_gocs_entry _gocs_table[MAX_GOCS];
+
+void
+mu_gocs_register (const char *capa, mu_gocs_init_fp init)
+{
+  int i;
+  for (i = 0; _gocs_table[i].name; i++)
+    if (i == MAX_GOCS-1)
+      {
+       mu_error (_("gocs table overflow"));
+       abort ();
+      }
+  _gocs_table[i].name = capa;
+  _gocs_table[i].init = init;
+}
+
+int
+mu_gocs_enumerate (mu_list_action_t action, void *data)
+{
+  int i;
+  
+  for (i = 0; _gocs_table[i].name; i++)
+    {
+      int rc = action ((void*) _gocs_table[i].name, data);
+      if (rc)
+       return rc;
+    }
+  return 0;
+}
+
+static mu_gocs_init_fp
+find_init_function (struct mu_gocs_entry *tab, const char *capa)
+{
+  for (; tab->name; tab++)
+    if (strcmp (tab->name, capa) == 0)
+      return tab->init;
+  return NULL;
+}
+
+static struct mu_gocs_entry std_gocs_table[] = {
+  { "common", mu_gocs_dummy },
+  { "license", mu_gocs_dummy },
+  { "mailbox", mu_gocs_mailbox_init },
+  { "locking", mu_gocs_locking_init },
+  { "address", mu_gocs_source_email_init },
+  { "mailer", mu_gocs_mailer_init },
+  { "logging", mu_gocs_logging_init },
+  { "debug", mu_gocs_debug_init },
+  { "auth", mu_gocs_dummy },
+  { NULL }
+};
+
+void
+mu_gocs_register_std (const char *name)
+{
+  mu_gocs_init_fp init = find_init_function (std_gocs_table, name);
+  if (!init)
+    {
+      mu_error (_("INTERNAL ERROR at %s:%d: unknown standard capability `%s'"),
+               __FILE__, __LINE__, name);
+      abort ();
+    }
+  mu_gocs_register (name, init);
+}
+
+
+struct mu_gocs_data
+{
+  char *capa;
+  void *data;
+};
+
+static mu_list_t /* of struct mu_gocs_data */ data_list;
+
+static int
+_gocs_comp (const void *a, const void *b)
+{
+  const struct mu_gocs_data *da = a, *db = b;
+  return !(strcmp (da->capa, db->capa) == 0 && da->data == db->data);
+}
+
+void
+mu_gocs_store (char *capa, void *data)
+{
+  struct mu_gocs_data *s;
+  if (!data_list)
+    {
+      mu_list_create (&data_list);
+      mu_list_set_destroy_item (data_list, mu_list_free_item);
+      mu_list_set_comparator (data_list, _gocs_comp);
+    }
+  s = malloc (sizeof *s);
+  if (!s)
+    {
+      mu_error ("%s", mu_strerror (ENOMEM));
+      exit (1);
+    }
+  s->capa = capa;
+  s->data = data;
+  if (mu_list_locate (data_list, s, NULL) == 0)
+    free (s);
+  else
+    mu_list_prepend (data_list, s);
+}
+
+int
+_gocs_flush (void *item, void *data)
+{
+  struct mu_gocs_data *s = item;
+  mu_gocs_init_fp initfun = find_init_function (_gocs_table, s->capa);
+
+  if (!initfun)
+    {
+      mu_error (_("INTERNAL ERROR at %s:%d: unknown capability `%s'"),
+               __FILE__, __LINE__, s->capa);
+      abort ();
+    }
+
+  if (initfun (mu_gocs_op_set, s->data))
+    {
+      mu_error (_("initialization of GOCS `%s' failed"), s->capa);
+      return 1;
+    }
+  
+  return 0;
+}
+
+void
+mu_gocs_flush ()
+{
+  int i;
+  mu_list_do (data_list, _gocs_flush, NULL);
+
+  for (i = 0; _gocs_table[i].name; i++)
+    _gocs_table[i].init (mu_gocs_op_flush, NULL);
+}
diff --git a/libmailutils/cfg/lexer.l b/libmailutils/cfg/lexer.l
new file mode 100644
index 0000000..83e8351
--- /dev/null
+++ b/libmailutils/cfg/lexer.l
@@ -0,0 +1,405 @@
+%top {
+/* cfg_lexer.l -- default lexer for Mailutils configuration files
+   Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 3, or (at
+   your option) any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+}
+
+%{
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <mailutils/cctype.h>
+#include <mailutils/errno.h>
+#include <mailutils/error.h>
+#include <mailutils/debug.h>  
+#include <mailutils/argcv.h>
+#include <mailutils/alloc.h>  
+#include <mailutils/nls.h>
+#include <mailutils/cfg.h>
+#include <mailutils/list.h>
+#include <mailutils/mutil.h>
+  
+#include "parser.h"
+
+void _mu_line_begin (void);
+void _mu_line_add (char *text, size_t len);
+char *_mu_line_finish (void);
+
+extern void mu_cfg_set_debug (void);
+static void
+mu_cfg_set_lex_debug (void)
+{
+  yy_flex_debug = mu_debug_check_level (mu_cfg_get_debug (),
+                                       MU_DEBUG_TRACE2);
+}
+ 
+static void _mu_line_add_unescape_last (char *text, size_t len);
+static void multiline_begin (char *p);
+static char *multiline_strip_tabs (char *text);
+static void multiline_add (char *s);
+static char *multiline_finish (void);
+ 
+static char *multiline_delimiter;
+static size_t multiline_delimiter_len;
+static int multiline_unescape;         /* Unescape here-document contents */
+static int (*char_to_strip)(char);     /* Strip matching characters of each
+                                         here-document line */
+static int isemptystr(int off);
+
+static mu_opool_t pool;
+
+%}
+
+%x COMMENT ML STR
+
+WS [ \t\f][ \t\f]*
+ID [a-zA-Z_][a-zA-Z_0-9-]+
+P [1-9][0-9]*
+
+%%
+         /* C-style comments */
+"/*"         BEGIN(COMMENT);
+<COMMENT>[^*\n]*        /* eat anything that's not a '*' */
+<COMMENT>"*"+[^*/\n]*   /* eat up '*'s not followed by '/'s */
+<COMMENT>\n             ++mu_cfg_locus.line;
+<COMMENT>"*"+"/"        BEGIN (INITIAL);
+         /* End-of-line comments */
+#debug=.*\n {
+          mu_log_level_t lev;
+          mu_debug_t dbg = mu_cfg_get_debug ();
+          if (mu_debug_level_from_string (yytext + 7, &lev, dbg) == 0)
+            {
+             mu_debug_set_level (dbg, lev);
+             mu_cfg_set_debug ();
+             mu_cfg_set_lex_debug ();
+           }
+          }
+#.*\n     { mu_cfg_locus.line++; }
+#.*     /* end-of-file comment */;
+"//".*\n  { mu_cfg_locus.line++; }
+"//".*    /* end-of-file comment */;
+        /* Identifiers */
+<INITIAL>{ID}         {
+                        _mu_line_begin ();
+                       _mu_line_add (yytext, yyleng);
+                       yylval.string = _mu_line_finish ();
+                       return MU_TOK_IDENT; }
+         /* Strings */
+[a-zA-Z0-9_\./:\*=-]+ { _mu_line_begin ();
+                        _mu_line_add (yytext, yyleng);
+                        yylval.string = _mu_line_finish ();
+                        return MU_TOK_STRING; }
+         /* Quoted strings */
+\"[^\\"\n]*\"         { _mu_line_begin ();
+                        _mu_line_add (yytext + 1, yyleng - 2);
+                        yylval.string = _mu_line_finish ();
+                        return MU_TOK_QSTRING; }
+\"[^\\"\n]*\\. |
+\"[^\\"\n]*\\\n        { BEGIN (STR);
+                        _mu_line_begin ();
+                       _mu_line_add_unescape_last (yytext + 1, yyleng - 1); }
+<STR>[^\\"\n]*\\. |
+<STR>\"[^\\"\n]*\\\n  { _mu_line_add_unescape_last (yytext, yyleng); }
+<STR>[^\\"\n]*\"      { BEGIN (INITIAL);
+                        if (yyleng > 1) 
+                          _mu_line_add (yytext, yyleng - 1); 
+                        yylval.string = _mu_line_finish ();
+                       return MU_TOK_QSTRING; }
+         /* Multiline strings */
+"<<"(-" "?)?\\?{ID}[ \t]*#.*\n |
+"<<"(-" "?)?\\?{ID}[ \t]*"//".*\n |
+"<<"(-" "?)?\\?{ID}[ \t]*\n |
+"<<"(-" "?)?\"{ID}\"[ \t]*#.*\n |
+"<<"(-" "?)?\"{ID}\"[ \t]*"//".*\n |
+"<<"(-" "?)?\"{ID}\"[ \t]*\n {
+                        BEGIN (ML);
+                       multiline_begin (yytext+2);
+                       mu_cfg_locus.line++;
+                 }
+<ML>.*\n { char *p = multiline_strip_tabs (yytext);
+          
+           if (!strncmp (p, multiline_delimiter, multiline_delimiter_len)
+              && isemptystr (p + multiline_delimiter_len - yytext))
+            {
+              free (multiline_delimiter);
+              multiline_delimiter = NULL;
+              BEGIN (INITIAL);
+              yylval.string = multiline_finish ();
+              return MU_TOK_MSTRING;
+            }
+           mu_cfg_locus.line++;
+          multiline_add (p); } 
+{WS}     ;
+         /* Other tokens */
+\n       { mu_cfg_locus.line++; } 
+[,;{}()] return yytext[0];
+.        { if (mu_isprint (yytext[0]))
+              mu_cfg_parse_error (_("stray character %c"), yytext[0]);
+           else 
+              mu_cfg_parse_error (_("stray character \\%03o"),
+                                 (unsigned char) yytext[0]);
+         }
+%%
+
+int
+yywrap ()
+{
+  return 1;
+}
+
+static void
+unescape_to_line (int c)
+{
+  if (c != '\n')
+    {
+      char t = mu_argcv_unquote_char (c);
+      if (t == c && t != '\\' && t != '\"')
+       mu_cfg_parse_error (_("unknown escape sequence '\\%c'"), c);
+      mu_opool_append_char (pool, t);
+    }
+}
+
+void
+_mu_line_add (char *text, size_t len)
+{
+  mu_opool_append (pool, text, len);
+}
+
+void
+_mu_line_add_unescape_last (char *text, size_t len)
+{
+  mu_opool_append (pool, text, len - 2);
+  unescape_to_line (text[len - 1]);
+}
+
+void
+_mu_line_begin ()
+{
+  if (!pool)
+    mu_opool_create (&pool, 1);
+  else
+    mu_opool_clear (pool);
+}
+
+char *
+_mu_line_finish ()
+{
+  mu_opool_append_char (pool, 0);
+  return mu_opool_finish (pool, NULL);
+}
+
+
+
+static int
+is_tab (char c)
+{
+    return c == '\t';
+}
+ 
+static int
+is_ws (char c)
+{
+    return c == '\t' || c == ' ';
+}
+
+static int
+isemptystr (int off)
+{
+  for (; yytext[off] && mu_isspace (yytext[off]); off++)
+    ;
+  if (yytext[off] == ';')
+    {
+      int i;
+      for (i = off + 1; yytext[i]; i++) 
+       if (!mu_isspace (yytext[i]))
+         return 0;
+      yyless (off);
+      return 1;
+    }
+  return yytext[off] == 0;
+}
+
+static void
+multiline_begin (char *p)
+{
+  if (*p == '-')
+    {
+      if (*++p == ' ')
+       {
+         char_to_strip = is_ws;
+         p++;
+       }
+      else
+       char_to_strip = is_tab;
+    }
+  else
+    char_to_strip = NULL;
+  if (*p == '\\')
+    {
+      p++;
+      multiline_unescape = 0;
+    }
+  else if (*p == '"')
+    {
+      char *q;
+      
+      p++;
+      multiline_unescape = 0;
+      q = strchr (p, '"');
+      multiline_delimiter_len = q - p;
+    }
+  else
+    {
+       multiline_delimiter_len = strcspn (p, " \t");
+       multiline_unescape = 1;
+    }
+
+  /* Remove trailing newline */
+  multiline_delimiter_len--;
+  multiline_delimiter = mu_alloc (multiline_delimiter_len + 1);
+  memcpy (multiline_delimiter, p, multiline_delimiter_len);
+  multiline_delimiter[multiline_delimiter_len] = 0;
+  _mu_line_begin ();
+}
+
+static char *
+multiline_strip_tabs (char *text)
+{
+  if (char_to_strip)
+    for (; *text && char_to_strip (*text); text++)
+      ;
+  return text;
+}
+
+static void
+multiline_add (char *s)
+{
+  if (multiline_unescape)
+    {
+      for (; *s; s++)
+       {
+         if (*s == '\\')
+           {
+             unescape_to_line (s[1]);
+             ++s;
+           }
+         else
+           _mu_line_add (s, 1);
+       }
+    }
+  else
+    _mu_line_add (s, strlen (s));
+}
+
+static char *
+multiline_finish ()
+{
+  return _mu_line_finish ();
+}
+
+
+int
+mu_cfg_parse_file (mu_cfg_tree_t **return_tree, const char *file, int flags)
+{
+  struct stat st;
+  FILE *fp;
+  int rc;
+  char *full_name = mu_tilde_expansion (file, "/", NULL);
+
+  if (stat (full_name, &st))
+    {
+      if (errno != ENOENT)
+       mu_error (_("cannot stat `%s': %s"), full_name, mu_strerror (errno));
+      free (full_name);
+      return ENOENT;
+    }
+  else if (!S_ISREG (st.st_mode))
+    {
+      if (flags & MU_PARSE_CONFIG_VERBOSE)
+       mu_diag_output (MU_DIAG_INFO, _("%s: not a regular file"), full_name);
+      free (full_name);
+      return ENOENT;
+    } 
+      
+  fp = fopen (full_name, "r");
+  if (!fp)
+    {
+      mu_error (_("cannot open config file `%s': %s"), full_name,
+               mu_strerror (errno));
+      free (full_name);
+      return errno;
+    }
+
+  if (flags & MU_PARSE_CONFIG_VERBOSE)
+    mu_diag_output (MU_DIAG_INFO, _("parsing file `%s'"), full_name);
+
+  mu_cfg_set_lex_debug ();
+
+  /* Initialize locus: */
+  /* 1. Save file name in the lexer object pool and point `file' member
+     to this copy. Free full_name: it is not used after that. */
+  _mu_line_begin ();
+  _mu_line_add (full_name, strlen (full_name));
+  mu_cfg_locus.file = _mu_line_finish ();
+  free (full_name); 
+  /* 2. Initialize line number */
+  mu_cfg_locus.line = 1;
+  
+  /* Parse configuration */
+  yyrestart (fp);
+  rc = mu_cfg_parse (return_tree);
+  fclose (fp);
+  if (flags & MU_PARSE_CONFIG_VERBOSE)
+    mu_diag_output (MU_DIAG_INFO, _("finished parsing file `%s'"),
+                   mu_cfg_locus.file);
+
+  return rc == 0 ? 0 : MU_ERR_FAILURE;
+}
+
+/* FIXME: Deprecated interface */
+int
+mu_get_config (const char *file, const char *progname,
+               struct mu_cfg_param *progparam, int flags, void *target_ptr)
+{
+  mu_cfg_tree_t *parse_tree;
+  int rc = mu_cfg_parse_file (&parse_tree, file, flags);
+  if (rc == 0)
+    {
+      rc = mu_cfg_tree_postprocess (parse_tree, flags);
+      if (rc == 0)
+       rc = mu_cfg_tree_reduce (parse_tree, progname, progparam, flags,
+                                target_ptr);
+      mu_cfg_destroy_tree (&parse_tree);
+    }
+
+  return rc == 0 ? 0 : MU_ERR_FAILURE;
+}
+
+
+mu_opool_t 
+mu_cfg_lexer_pool ()
+{
+  mu_opool_t p = pool;
+  pool = NULL;
+  return p;
+}
diff --git a/libmailutils/cfg/parser.y b/libmailutils/cfg/parser.y
new file mode 100644
index 0000000..8c8e060
--- /dev/null
+++ b/libmailutils/cfg/parser.y
@@ -0,0 +1,1839 @@
+%{
+/* cfg_parser.y -- general-purpose configuration file parser
+   Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 3, or (at
+   your option) any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <netdb.h>
+#include "intprops.h"
+#include <mailutils/argcv.h>
+#include <mailutils/nls.h>
+#include <mailutils/cfg.h>
+#include <mailutils/alloc.h>
+#include <mailutils/errno.h>
+#include <mailutils/error.h>
+#include <mailutils/list.h>
+#include <mailutils/iterator.h>
+#include <mailutils/debug.h>
+#include <mailutils/mutil.h>
+#include <mailutils/cctype.h>
+
+int mu_cfg_parser_verbose;
+static mu_list_t /* of mu_cfg_node_t */ parse_node_list; 
+mu_cfg_locus_t mu_cfg_locus;
+size_t mu_cfg_error_count;
+
+static int _mu_cfg_errcnt;
+static mu_debug_t _mu_cfg_debug;
+
+int yylex ();
+
+void _mu_line_begin (void);
+void _mu_line_add (char *text, size_t len);
+char *_mu_line_finish (void);
+
+static int
+yyerror (char *s)
+{
+  mu_cfg_parse_error ("%s", s);
+  return 0;
+}
+
+static mu_config_value_t *
+config_value_dup (mu_config_value_t *src)
+{
+  if (!src)
+    return NULL;
+  else
+    {
+      /* FIXME: Use mu_opool_alloc */
+      mu_config_value_t *val = mu_alloc (sizeof (*val));
+      *val = *src;
+      return val;
+    }
+}
+
+static mu_cfg_node_t *
+mu_cfg_alloc_node (enum mu_cfg_node_type type, mu_cfg_locus_t *loc,
+                  const char *tag, mu_config_value_t *label,
+                  mu_list_t nodelist)
+{
+  char *p;
+  mu_cfg_node_t *np;
+  size_t size = sizeof *np + strlen (tag) + 1;
+  np = mu_alloc (size);
+  np->type = type;
+  np->locus = *loc;
+  p = (char*) (np + 1);
+  np->tag = p;
+  strcpy (p, tag);
+  np->label = label;
+  np->nodes = nodelist;
+  return np;
+}
+
+void
+mu_cfg_free_node (mu_cfg_node_t *node)
+{
+  free (node->label);
+  free (node);
+}
+
+void
+mu_cfg_format_error (mu_debug_t debug, size_t level, const char *fmt, ...)
+{
+  va_list ap;
+
+  if (!debug)
+    mu_diag_get_debug (&debug);
+  va_start (ap, fmt);
+  mu_debug_vprintf (debug, 0, fmt, ap);
+  mu_debug_printf (debug, 0, "\n");
+  va_end (ap);
+  if (level <= MU_DEBUG_ERROR)
+    mu_cfg_error_count++;
+}
+
+static void
+_mu_cfg_debug_set_locus (mu_debug_t debug, const mu_cfg_locus_t *loc)
+{
+  mu_debug_set_locus (debug, loc->file ? loc->file : _("unknown file"),
+                     loc->line);
+}
+
+void
+mu_cfg_vperror (mu_debug_t debug, const mu_cfg_locus_t *loc,
+                const char *fmt, va_list ap)
+{
+  if (!debug)
+    mu_diag_get_debug (&debug);
+  _mu_cfg_debug_set_locus (debug, loc);
+  mu_debug_vprintf (debug, 0, fmt, ap);
+  mu_debug_printf (debug, 0, "\n");
+  mu_debug_set_locus (debug, NULL, 0);
+  mu_cfg_error_count++;
+}
+
+void
+mu_cfg_perror (mu_debug_t debug, const mu_cfg_locus_t *loc,
+              const char *fmt, ...)
+{
+  va_list ap;
+
+  va_start (ap, fmt);
+  mu_cfg_vperror (debug, loc, fmt, ap);
+  va_end (ap);
+}
+
+void
+mu_cfg_parse_error (const char *fmt, ...)
+{
+  va_list ap;
+
+  va_start (ap, fmt);
+  mu_cfg_vperror (_mu_cfg_debug, &mu_cfg_locus, fmt, ap);
+  va_end (ap);
+}
+
+#define node_type_str(t) (((t) == mu_cfg_node_statement) ? "stmt" : "param")
+
+static void
+debug_print_node (mu_cfg_node_t *node)
+{
+  if (mu_debug_check_level (_mu_cfg_debug, MU_DEBUG_TRACE0))
+    {
+      mu_debug_set_locus (_mu_cfg_debug,
+                         node->locus.file, node->locus.line);
+      if (node->type == mu_cfg_node_undefined)
+       /* Stay on the safe side */
+       mu_cfg_format_error (_mu_cfg_debug, MU_DEBUG_ERROR,
+                            "unknown statement type!");
+      else
+       /* FIXME: How to print label? */
+       mu_cfg_format_error (_mu_cfg_debug, MU_DEBUG_TRACE0,
+                            "statement: %s, id: %s",
+                            node_type_str (node->type),
+                            node->tag ? node->tag : "(null)");
+
+      mu_debug_set_locus (_mu_cfg_debug, NULL, 0);
+    }
+}
+
+static void
+free_node_item (void *item)
+{
+  mu_cfg_node_t *node = item;
+
+  switch (node->type)
+    {
+    case mu_cfg_node_statement:
+      mu_list_destroy (&node->nodes);
+      break;
+      
+    case mu_cfg_node_undefined: /* hmm... */
+    case mu_cfg_node_param:
+      break;
+    }
+  mu_cfg_free_node (node);
+}
+
+int
+mu_cfg_create_node_list (mu_list_t *plist)
+{
+  int rc;
+  mu_list_t list;
+
+  rc = mu_list_create (&list);
+  if (rc)
+    return rc;
+  mu_list_set_destroy_item (list, free_node_item);
+  *plist = list;
+  return 0;
+}
+
+%}
+
+%union {
+  mu_cfg_node_t node;
+  mu_cfg_node_t *pnode;
+  mu_list_t /* of mu_cfg_node_t */ nodelist;
+  char *string;
+  mu_config_value_t value, *pvalue;
+  mu_list_t list;
+  struct { const char *name; mu_cfg_locus_t locus; } ident;
+}
+
+%token <string> MU_TOK_IDENT MU_TOK_STRING MU_TOK_QSTRING MU_TOK_MSTRING
+%type <string> string slist
+%type <list> slist0
+%type <value> value
+%type <pvalue> tag vallist
+%type <list> values list vlist
+%type <ident> ident
+%type <nodelist> stmtlist
+%type <pnode> stmt simple block
+
+%%
+
+input   : stmtlist
+         {
+           parse_node_list = $1;
+         }
+       ;
+
+stmtlist: stmt
+         {
+           mu_cfg_create_node_list (&$$);
+           mu_list_append ($$, $1);
+         }
+       | stmtlist stmt
+         {
+           mu_list_append ($1, $2);
+           $$ = $1;
+           debug_print_node ($2);
+         }
+       ;
+
+stmt    : simple
+       | block
+       ;
+
+simple  : ident vallist ';'
+         {
+           $$ = mu_cfg_alloc_node (mu_cfg_node_param, &$1.locus,
+                                   $1.name, $2,
+                                   NULL);
+         }
+       ;
+
+block   : ident tag '{' '}' opt_sc
+         {
+           $$ = mu_cfg_alloc_node (mu_cfg_node_statement, &$1.locus,
+                                   $1.name, $2,
+                                   NULL);
+
+         }
+       | ident tag '{' stmtlist '}' opt_sc
+         {
+           $$ = mu_cfg_alloc_node (mu_cfg_node_statement, &$1.locus,
+                                   $1.name, $2, $4);
+
+         }
+       ;
+
+ident   : MU_TOK_IDENT
+         {
+           $$.name = $1;
+           $$.locus = mu_cfg_locus;
+         }
+       ;
+
+tag     : /* empty */
+         {
+           $$ = NULL;
+         }
+       | vallist
+       ;
+
+vallist : vlist
+         {
+           size_t n = 0;
+           mu_list_count($1, &n);
+           if (n == 1)
+             {
+               mu_list_get ($1, 0, (void**) &$$);
+             }
+           else
+             {
+               size_t i;
+               mu_config_value_t val;
+
+               val.type = MU_CFG_ARRAY;
+               val.v.arg.c = n;
+               /* FIXME: Use mu_opool_alloc */
+               val.v.arg.v = mu_alloc (n * sizeof (val.v.arg.v[0]));
+               if (!val.v.arg.v)
+                 {
+                   mu_cfg_parse_error (_("not enough memory"));
+                   abort();
+                 }
+
+               for (i = 0; i < n; i++)
+                 {
+                   mu_config_value_t *v;
+                   mu_list_get ($1, i, (void **) &v);
+                   val.v.arg.v[i] = *v;
+                 }
+               $$ = config_value_dup (&val);
+             }
+           mu_list_destroy (&$1);
+         }
+       ;
+
+vlist   : value
+           {
+             int rc = mu_list_create (&$$);
+             if (rc)
+               {
+                 mu_cfg_parse_error (_("cannot create list: %s"),
+                                     mu_strerror (rc));
+                 abort ();
+               }
+             mu_list_append ($$, config_value_dup (&$1)); /* FIXME */
+         }
+       | vlist value
+         {
+           mu_list_append ($1, config_value_dup (&$2));
+         }
+       ;
+
+value   : string
+         {
+             $$.type = MU_CFG_STRING;
+             $$.v.string = $1;
+         }
+       | list
+         {
+             $$.type = MU_CFG_LIST;
+             $$.v.list = $1;
+         }
+       | MU_TOK_MSTRING
+         {
+             $$.type = MU_CFG_STRING;
+             $$.v.string = $1;
+         }
+       ;
+
+string  : MU_TOK_STRING
+       | MU_TOK_IDENT
+       | slist
+       ;
+
+slist   : slist0
+         {
+           mu_iterator_t itr;
+           mu_list_get_iterator ($1, &itr);
+
+           _mu_line_begin ();
+           for (mu_iterator_first (itr);
+                !mu_iterator_is_done (itr); mu_iterator_next (itr))
+             {
+               char *p;
+               mu_iterator_current (itr, (void**)&p);
+               _mu_line_add (p, strlen (p));
+             }
+           $$ = _mu_line_finish ();
+           mu_iterator_destroy (&itr);
+           mu_list_destroy(&$1);
+         }
+       ;
+
+slist0  : MU_TOK_QSTRING
+         {
+           mu_list_create (&$$);
+           mu_list_append ($$, $1);
+         }
+       | slist0 MU_TOK_QSTRING
+         {
+           mu_list_append ($1, $2);
+           $$ = $1;
+         }
+       ;
+
+list    : '(' values ')'
+         {
+             $$ = $2;
+         }
+       | '(' values ',' ')'
+         {
+             $$ = $2;
+         }
+       ;
+
+values  : value
+         {
+           mu_list_create (&$$);
+           mu_list_append ($$, config_value_dup (&$1));
+         }
+       | values ',' value
+         {
+           mu_list_append ($1, config_value_dup (&$3));
+           $$ = $1;
+         }
+       ;
+
+opt_sc  : /* empty */
+       | ';'
+       ;
+
+
+%%
+
+static int
+_cfg_default_printer (void *unused, mu_log_level_t level, const char *str)
+{
+  fprintf (stderr, "%s", str);
+  return 0;
+}
+
+mu_debug_t
+mu_cfg_get_debug ()
+{
+  if (!_mu_cfg_debug)
+    {
+      mu_debug_create (&_mu_cfg_debug, NULL);
+      mu_debug_set_print (_mu_cfg_debug, _cfg_default_printer, NULL);
+      mu_debug_set_level (_mu_cfg_debug, mu_global_debug_level ("config"));
+    }
+  return _mu_cfg_debug;
+}
+
+void
+mu_cfg_set_debug ()
+{
+  if (mu_debug_check_level (mu_cfg_get_debug (), MU_DEBUG_TRACE7))
+    yydebug = 1;
+}
+
+int
+mu_cfg_parse (mu_cfg_tree_t **ptree)
+{
+  int rc;
+  mu_cfg_tree_t *tree;
+  mu_opool_t pool;
+  
+  mu_cfg_set_debug ();
+  _mu_cfg_errcnt = 0;
+
+  rc = yyparse ();
+  pool = mu_cfg_lexer_pool ();
+  if (rc == 0 && _mu_cfg_errcnt)
+    {
+      mu_opool_destroy (&pool);
+      rc = 1;
+    }
+  else
+    {
+      tree = mu_alloc (sizeof (*tree));
+      tree->debug = _mu_cfg_debug;
+      _mu_cfg_debug = NULL;
+      tree->nodes = parse_node_list;
+      tree->pool = pool;
+      parse_node_list = NULL;
+      *ptree = tree;
+    }
+  return rc;
+}
+
+int
+mu_cfg_tree_union (mu_cfg_tree_t **pa, mu_cfg_tree_t **pb)
+{
+  mu_cfg_tree_t *a, *b;
+  int rc;
+  
+  if (!pb)
+    return EINVAL;
+  if (!*pb)
+    return 0;
+  b = *pb;
+  if (!pa)
+    return EINVAL;
+  if (!*pa)
+    {
+      *pa = b;
+      *pb = NULL;
+      return 0;
+    }
+  else
+    a = *pa;
+  
+  /* Merge opools */
+  rc = mu_opool_union (&b->pool, &a->pool);
+  if (rc)
+    return rc;
+    
+  /* Link node lists */
+  if (b->nodes)
+    {
+      mu_list_append_list (a->nodes, b->nodes);
+      mu_list_destroy (&b->nodes);
+    }
+  
+  mu_debug_destroy (&b->debug, mu_debug_get_owner (b->debug));
+  free (b);
+  *pb = NULL;
+  return 0;
+}
+
+static mu_cfg_tree_t *
+do_include (const char *name, int flags, mu_cfg_locus_t *loc)
+{
+  struct stat sb;
+  char *tmpname = NULL;
+  mu_cfg_tree_t *tree = NULL;
+  
+  if (name[0] != '/')
+    {
+      name = tmpname = mu_make_file_name (SYSCONFDIR, name);
+      if (!name)
+        {
+          mu_error ("%s", mu_strerror (errno));
+          return NULL;
+        }
+    }
+  if (stat (name, &sb) == 0)
+    {
+      int rc = 0;
+
+      if (S_ISDIR (sb.st_mode))
+       {
+         if (flags & MU_PARSE_CONFIG_GLOBAL)
+           {
+             char *file = mu_make_file_name (name, mu_program_name);
+             rc = mu_cfg_parse_file (&tree, file, flags);
+             free (file);
+           }
+       }
+      else
+       rc = mu_cfg_parse_file (&tree, name, flags);
+             
+      if (rc == 0 && tree)
+       mu_cfg_tree_postprocess (tree, flags & ~MU_PARSE_CONFIG_GLOBAL);
+    }
+  else if (errno == ENOENT)
+    mu_cfg_perror (tree->debug, loc,
+                  _("include file or directory does not exist"));
+  else
+    mu_cfg_perror (tree->debug, loc,
+                  _("cannot stat include file or directory: %s"),
+                  mu_strerror (errno));
+  free (tmpname);
+  return tree;
+}
+    
+int
+mu_cfg_tree_postprocess (mu_cfg_tree_t *tree, int flags)
+{
+  int rc;
+  mu_iterator_t itr;
+
+  if (!tree->nodes)
+    return 0;
+  rc = mu_list_get_iterator (tree->nodes, &itr);
+  if (rc)
+    return rc;
+  for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
+       mu_iterator_next (itr))
+    {
+      mu_cfg_node_t *node;
+
+      mu_iterator_current (itr, (void**) &node);
+
+      if (node->type == mu_cfg_node_statement)
+       {
+         if ((flags & MU_PARSE_CONFIG_GLOBAL) &&
+             strcmp (node->tag, "program") == 0)
+           {
+             if (node->label->type == MU_CFG_STRING)
+               {
+                 if (strcmp (node->label->v.string, mu_program_name) == 0)
+                   {
+                     /* Move all nodes from this block to the topmost
+                        level */
+                     mu_iterator_ctl (itr, mu_itrctl_insert_list,
+                                      node->nodes);
+                     mu_iterator_ctl (itr, mu_itrctl_delete, NULL);
+                     /*FIXME:mu_cfg_free_node (node);*/
+                   }
+               }
+             else
+               {
+                 mu_cfg_perror (tree->debug, &node->locus,
+                                _("argument to `program' is not a string"));
+                 mu_iterator_ctl (itr, mu_itrctl_delete, NULL);
+               }
+           }
+       }
+      else if (node->type == mu_cfg_node_param &&
+              strcmp (node->tag, "include") == 0)
+       {
+         if (node->label->type == MU_CFG_STRING)
+           {
+             mu_cfg_tree_t *t = do_include (node->label->v.string, flags,
+                                            &node->locus);
+             if (t)
+               {
+                 /* Merge the new tree into the current point and
+                    destroy the rest of it */
+                 mu_iterator_ctl (itr, mu_itrctl_insert_list, t->nodes);
+                 mu_opool_union (&tree->pool, &t->pool);
+                 mu_cfg_destroy_tree (&t);
+               }                     
+           }
+         else
+           mu_cfg_perror (tree->debug, &node->locus,
+                          _("argument to `include' is not a string"));
+         /* Remove node from the list */
+         mu_iterator_ctl (itr, mu_itrctl_delete, NULL);
+       }
+    }
+  return 0;
+}
+
+static int
+_mu_cfg_preorder_recursive (void *item, void *cbdata)
+{
+  mu_cfg_node_t *node = item;
+  struct mu_cfg_iter_closure *clos = cbdata;
+
+  switch (node->type)
+    {
+    case mu_cfg_node_undefined:
+      abort ();
+
+    case mu_cfg_node_statement:
+      switch (clos->beg (node, clos->data))
+       {
+       case MU_CFG_ITER_OK:
+         if (mu_cfg_preorder (node->nodes, clos))
+           return 1;
+         if (clos->end && clos->end (node, clos->data) == MU_CFG_ITER_STOP)
+           return 1;
+         break;
+
+       case MU_CFG_ITER_SKIP:
+         break;
+
+       case MU_CFG_ITER_STOP:
+         return 1;
+       }
+      break;
+
+    case mu_cfg_node_param:
+      return clos->beg (node, clos->data) == MU_CFG_ITER_STOP;
+    }
+  return 0;
+}
+
+int
+mu_cfg_preorder (mu_list_t nodelist, struct mu_cfg_iter_closure *clos)
+{
+  return mu_list_do (nodelist, _mu_cfg_preorder_recursive, clos);
+}
+
+
+
+void
+mu_cfg_destroy_tree (mu_cfg_tree_t **ptree)
+{
+  if (ptree && *ptree)
+    {
+      mu_cfg_tree_t *tree = *ptree;
+      mu_list_destroy (&tree->nodes);
+      mu_opool_destroy (&tree->pool);
+      *ptree = NULL;
+    }
+}
+
+
+
+struct mu_cfg_section_list
+{
+  struct mu_cfg_section_list *next;
+  struct mu_cfg_section *sec;
+};
+
+struct scan_tree_data
+{
+  struct mu_cfg_section_list *list;
+  void *target;
+  void *call_data;
+  mu_cfg_tree_t *tree;
+  int error;
+};
+
+static struct mu_cfg_cont *
+find_container (mu_list_t list, enum mu_cfg_cont_type type,
+               const char *ident, size_t len)
+{
+  mu_iterator_t iter;
+  struct mu_cfg_cont *ret = NULL;
+
+  if (len == 0)
+    len = strlen (ident);
+
+  mu_list_get_iterator (list, &iter);
+  for (mu_iterator_first (iter); !mu_iterator_is_done (iter);
+       mu_iterator_next (iter))
+    {
+      struct mu_cfg_cont *cont;
+      mu_iterator_current (iter, (void**) &cont);
+
+      if (cont->type == type
+         && strlen (cont->v.ident) == len
+         && memcmp (cont->v.ident, ident, len) == 0)
+       {
+         ret = cont;
+         break;
+       }
+    }
+  mu_iterator_destroy (&iter);
+  return ret;
+}
+
+static struct mu_cfg_section *
+find_subsection (struct mu_cfg_section *sec, const char *ident, size_t len)
+{
+  if (sec)
+    {
+      if (sec->children)
+       {
+         struct mu_cfg_cont *cont = find_container (sec->children,
+                                                    mu_cfg_cont_section,
+                                                    ident, len);
+         if (cont)
+           return &cont->v.section;
+       }
+    }
+  return NULL;
+}
+
+static struct mu_cfg_param *
+find_param (struct mu_cfg_section *sec, const char *ident, size_t len)
+{
+  if (sec)
+    {
+      if (sec->children)
+       {
+         struct mu_cfg_cont *cont = find_container (sec->children,
+                                                    mu_cfg_cont_param,
+                                                    ident, len);
+         if (cont)
+           return &cont->v.param;
+       }
+    }
+  return NULL;
+}
+
+static int
+push_section (struct scan_tree_data *dat, struct mu_cfg_section *sec)
+{
+  struct mu_cfg_section_list *p = mu_alloc (sizeof *p);
+  if (!p)
+    {
+      mu_cfg_perror (dat->tree->debug, NULL, _("not enough memory"));
+      return 1;
+    }
+  p->sec = sec;
+  p->next = dat->list;
+  dat->list = p;
+  return 0;
+}
+
+static struct mu_cfg_section *
+pop_section (struct scan_tree_data *dat)
+{
+  struct mu_cfg_section_list *p = dat->list;
+  struct mu_cfg_section *sec = p->sec;
+  dat->list = p->next;
+  free (p);
+  return sec;
+}
+
+#define STRTONUM(s, type, base, res, limit, d, loc)                    \
+  {                                                                    \
+    type sum = 0;                                                      \
+                                                                       \
+    for (; *s; s++)                                                    \
+      {                                                                        
\
+       type x;                                                         \
+                                                                       \
+       if ('0' <= *s && *s <= '9')                                     \
+         x = sum * base + *s - '0';                                    \
+       else if (base == 16 && 'a' <= *s && *s <= 'f')                  \
+         x = sum * base + *s - 'a';                                    \
+       else if (base == 16 && 'A' <= *s && *s <= 'F')                  \
+         x = sum * base + *s - 'A';                                    \
+       else                                                            \
+         break;                                                        \
+       if (x <= sum)                                                   \
+         {                                                             \
+           mu_cfg_perror (d, loc, _("numeric overflow"));              \
+           return 1;                                                   \
+         }                                                             \
+       else if (limit && x > limit)                                    \
+         {                                                             \
+           mu_cfg_perror (d, loc,                                      \
+                           _("value out of allowed range"));           \
+           return 1;                                                   \
+         }                                                             \
+       sum = x;                                                        \
+      }                                                                        
\
+    res = sum;                                                         \
+  }
+
+#define STRxTONUM(s, type, res, limit, d, loc)                         \
+  {                                                                    \
+    int base;                                                          \
+    if (*s == '0')                                                     \
+      {                                                                        
\
+       s++;                                                            \
+       if (*s == 0)                                                    \
+         base = 10;                                                    \
+       else if (*s == 'x' || *s == 'X')                                \
+         {                                                             \
+           s++;                                                        \
+           base = 16;                                                  \
+         }                                                             \
+       else                                                            \
+         base = 8;                                                     \
+      } else                                                           \
+      base = 10;                                                       \
+    STRTONUM (s, type, base, res, limit, d, loc);                      \
+  }
+
+#define GETUNUM(str, type, res, d, loc)                                        
\
+  {                                                                    \
+    type tmpres;                                                       \
+    const char *s = str;                                               \
+    STRxTONUM (s, type, tmpres, 0, d, loc);                            \
+    if (*s)                                                            \
+      {                                                                        
\
+       mu_cfg_perror (d, loc,                                          \
+                      _("not a number (stopped near `%s')"),           \
+                      s);                                              \
+       return 1;                                                       \
+      }                                                                        
\
+    res = tmpres;                                                      \
+  }
+
+#define GETSNUM(str, type, res, d, loc)                                        
\
+  {                                                                    \
+    unsigned type tmpres;                                              \
+    const char *s = str;                                               \
+    int sign;                                                          \
+    unsigned type limit;                                               \
+                                                                       \
+    if (*s == '-')                                                     \
+      {                                                                        
\
+       sign++;                                                         \
+       s++;                                                            \
+       limit = TYPE_MINIMUM (type);                                    \
+       limit = - limit;                                                \
+      }                                                                        
\
+    else                                                               \
+      {                                                                        
\
+       sign = 0;                                                       \
+       limit = TYPE_MAXIMUM (type);                                    \
+      }                                                                        
\
+                                                                       \
+    STRxTONUM (s, unsigned type, tmpres, limit, d, loc);               \
+    if (*s)                                                            \
+      {                                                                        
\
+       mu_cfg_perror (d, loc,                                          \
+                      _("not a number (stopped near `%s')"),           \
+                      s);                                              \
+       return 1;                                                       \
+      }                                                                        
\
+    res = sign ? - tmpres : tmpres;                                    \
+  }
+
+static int
+parse_ipv4 (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus,
+           const char *str, struct in_addr *res)
+{
+  struct in_addr addr;
+  if (inet_aton (str, &addr) == 0)
+    {
+      mu_cfg_perror (sdata->tree->debug, locus, _("not an IPv4"));
+      return 1;
+    }
+  addr.s_addr = ntohl (addr.s_addr);
+  *res = addr;
+  return 0;
+}
+
+static int
+parse_host (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus,
+           const char *str, struct in_addr *res)
+{
+  struct in_addr addr;
+  struct hostent *hp = gethostbyname (str);
+  if (hp)
+    {
+      addr.s_addr = *(unsigned long *)hp->h_addr;
+    }
+  else if (inet_aton (str, &addr) == 0)
+    {
+      mu_cfg_perror (sdata->tree->debug, locus,
+                    _("cannot resolve hostname `%s'"),
+                    str);
+      return 1;
+    }
+  addr.s_addr = ntohl (addr.s_addr);
+  *res = addr;
+  return 0;
+}
+
+static int
+parse_cidr (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus,
+           const char *str, mu_cfg_cidr_t *res)
+{
+  struct in_addr addr;
+  unsigned long mask;
+  char astr[16];
+  const char *p, *s;
+
+  p = strchr (str, '/');
+  if (p)
+    {
+      int len = p - str;
+      if (len > sizeof astr - 1) {
+       mu_cfg_perror (sdata->tree->debug, locus,
+                      _("not a valid IPv4 address in CIDR"));
+       return 1;
+      }
+      memcpy (astr, str, len);
+      astr[len] = 0;
+      if (inet_aton (astr, &addr) == 0)
+       {
+         mu_cfg_perror (sdata->tree->debug, locus,
+                        _("not a valid IPv4 address in CIDR"));
+         return 1;
+       }
+      addr.s_addr = ntohl (addr.s_addr);
+
+      p++;
+      s = p;
+      STRxTONUM (s, unsigned long, mask, 0, sdata->tree->debug, locus);
+      if (*s == '.')
+       {
+         struct in_addr a;
+         if (inet_aton (p, &a) == 0)
+           {
+             mu_cfg_perror (sdata->tree->debug, locus,
+                            _("not a valid network in CIDR"));
+             return 1;
+           }
+         a.s_addr = ntohl (a.s_addr);
+         for (mask = 0; (a.s_addr & 1) == 0 && mask < 32; )
+           {
+             mask++;
+             a.s_addr >>= 1;
+           }
+         mask = 32 - mask;
+       }
+      else if (mask > 32)
+       {
+         mu_cfg_perror (sdata->tree->debug, locus,
+                        _("not a valid network mask in CIDR"));
+         return 1;
+       }
+    }
+  else
+    {
+      int i;
+      unsigned short x;
+      addr.s_addr = 0;
+
+      p = str;
+      for (i = 0; i < 3; i++)
+       {
+         STRxTONUM (p, unsigned short, x, 255, sdata->tree->debug, locus);
+         if (*p != '.')
+           break;
+         addr.s_addr = (addr.s_addr << 8) + x;
+       }
+
+      if (*p)
+       {
+         mu_cfg_perror (sdata->tree->debug, locus,
+                        _("not a CIDR (stopped near `%s')"),
+                        p);
+         return 1;
+       }
+
+      mask = i * 8;
+
+      addr.s_addr <<= (4 - i) * 8;
+    }
+
+  res->addr = addr;
+  res->mask = mask;
+  return 0;
+}
+
+int
+mu_cfg_parse_boolean (const char *str, int *res)
+{
+  if (strcmp (str, "yes") == 0
+      || strcmp (str, "on") == 0
+      || strcmp (str, "t") == 0
+      || strcmp (str, "true") == 0
+      || strcmp (str, "1") == 0)
+    *res = 1;
+  else if (strcmp (str, "no") == 0
+          || strcmp (str, "off") == 0
+          || strcmp (str, "nil") == 0
+          || strcmp (str, "false") == 0
+          || strcmp (str, "0") == 0)
+    *res = 0;
+  else
+    return 1;
+  return 0;
+}
+
+static int
+parse_bool (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus,
+           const char *str, int *res)
+{
+  if (mu_cfg_parse_boolean (str, res))
+    {
+      mu_cfg_perror (sdata->tree->debug, locus, _("not a boolean"));
+      return 1;
+    }
+  return 0;
+}
+
+static int
+valcvt (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus,
+       void *tgt,
+       enum mu_cfg_param_data_type type, mu_config_value_t *val)
+{
+  if (val->type != MU_CFG_STRING)
+    {
+      mu_cfg_perror (sdata->tree->debug, locus, _("expected string value"));
+      return 1;
+    }
+  switch (type)
+    {
+    case mu_cfg_string:
+      {
+       char *s = mu_strdup (val->v.string);
+       /* FIXME: free tgt? */
+       *(char**)tgt = s;
+       break;
+      }
+
+    case mu_cfg_short:
+      GETSNUM (val->v.string, short, *(short*)tgt, sdata->tree->debug, locus);
+      break;
+
+    case mu_cfg_ushort:
+      GETUNUM (val->v.string, unsigned short, *(unsigned short*)tgt,
+              sdata->tree->debug, locus);
+      break;
+
+    case mu_cfg_int:
+      GETSNUM (val->v.string, int, *(int*)tgt, sdata->tree->debug, locus);
+      break;
+
+    case mu_cfg_uint:
+      GETUNUM (val->v.string, unsigned int, *(unsigned int*)tgt,
+              sdata->tree->debug, locus);
+      break;
+
+    case mu_cfg_long:
+      GETSNUM (val->v.string, long, *(long*)tgt,
+              sdata->tree->debug, locus);
+      break;
+
+    case mu_cfg_ulong:
+      GETUNUM (val->v.string, unsigned long, *(unsigned long*)tgt,
+              sdata->tree->debug, locus);
+      break;
+
+    case mu_cfg_size:
+      GETUNUM (val->v.string, size_t, *(size_t*)tgt,
+              sdata->tree->debug, locus);
+      break;
+
+    case mu_cfg_off:
+      mu_cfg_perror (sdata->tree->debug, locus, _("not implemented yet"));
+      /* GETSNUM(node->tag_label, off_t, *(off_t*)tgt); */
+      return 1;
+
+    case mu_cfg_time:
+      GETUNUM (val->v.string, time_t, *(time_t*)tgt,
+              sdata->tree->debug, locus);
+      break;
+
+    case mu_cfg_bool:
+      if (parse_bool (sdata, locus, val->v.string, (int*) tgt))
+       return 1;
+      break;
+
+    case mu_cfg_ipv4:
+      if (parse_ipv4 (sdata, locus, val->v.string, (struct in_addr *)tgt))
+       return 1;
+      break;
+
+    case mu_cfg_cidr:
+      if (parse_cidr (sdata, locus, val->v.string, (mu_cfg_cidr_t *)tgt))
+       return 1;
+      break;
+
+    case mu_cfg_host:
+      if (parse_host (sdata, locus, val->v.string, (struct in_addr *)tgt))
+       return 1;
+      break;
+
+    default:
+      return 1;
+    }
+  return 0;
+}
+
+struct set_closure
+{
+  mu_list_t list;
+  enum mu_cfg_param_data_type type;
+  struct scan_tree_data *sdata;
+  const mu_cfg_locus_t *locus;
+};
+
+static size_t config_type_size[] = {
+  sizeof (char*),          /* mu_cfg_string */
+  sizeof (short),          /* mu_cfg_short */
+  sizeof (unsigned short), /* mu_cfg_ushort */
+  sizeof (int),            /* mu_cfg_int */
+  sizeof (unsigned),       /* mu_cfg_uint */
+  sizeof (long),           /* mu_cfg_long */
+  sizeof (unsigned long),  /* mu_cfg_ulong */
+  sizeof (size_t),         /* mu_cfg_size */
+  sizeof (mu_off_t),       /* mu_cfg_off */
+  sizeof (time_t),         /* mu_cfg_time */
+  sizeof (int),            /* mu_cfg_bool */
+  sizeof (struct in_addr), /* mu_cfg_ipv4 */
+  sizeof (mu_cfg_cidr_t),  /* mu_cfg_cidr */
+  sizeof (struct in_addr), /* mu_cfg_host */
+  0,                       /* mu_cfg_callback */
+  0,                       /* mu_cfg_section */
+}  ;
+
+static int
+_set_fun (void *item, void *data)
+{
+  mu_config_value_t *val = item;
+  struct set_closure *clos = data;
+  void *tgt;
+  size_t size;
+
+  if (clos->type >= MU_ARRAY_SIZE(config_type_size)
+      || (size = config_type_size[clos->type]) == 0)
+    {
+    mu_cfg_perror (clos->sdata->tree->debug, clos->locus,
+                  _("INTERNAL ERROR at %s:%d: unhandled data type %d"),
+                  __FILE__, __LINE__, clos->type);
+    return 1;
+    }
+
+  tgt = mu_alloc (size);
+  if (!tgt)
+    {
+      mu_cfg_perror (clos->sdata->tree->debug, clos->locus,
+                    _("not enough memory"));
+      return 1;
+    }
+
+  if (valcvt (clos->sdata, clos->locus, &tgt, clos->type, val) == 0)
+    mu_list_append (clos->list, tgt);
+  return 0;
+}
+
+static int
+parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node)
+{
+  void *tgt;
+  struct set_closure clos;
+  struct mu_cfg_param *param = find_param (sdata->list->sec, node->tag,
+                                          0);
+
+  if (!param)
+    {
+      mu_cfg_perror (sdata->tree->debug, &node->locus,
+                    _("unknown keyword `%s'"),
+                    node->tag);
+      return 1;
+    }
+
+  if (param->data)
+    tgt = param->data;
+  else if (sdata->list->sec->target)
+    tgt = (char*)sdata->list->sec->target + param->offset;
+  else if (sdata->target)
+    tgt = (char*)sdata->target + param->offset;
+  else if (param->type == mu_cfg_callback)
+    tgt = NULL;
+  else
+    {
+      mu_cfg_perror (sdata->tree->debug, &node->locus,
+                    _("INTERNAL ERROR: cannot determine target offset for "
+                      "%s"), param->ident);
+      abort ();
+    }
+
+  memset (&clos, 0, sizeof clos);
+  clos.type = MU_CFG_TYPE (param->type);
+  if (MU_CFG_IS_LIST (param->type))
+    {
+      clos.sdata = sdata;
+      clos.locus = &node->locus;
+      switch (node->label->type)
+       {
+       case MU_CFG_LIST:
+         break;
+
+       case MU_CFG_STRING:
+         {
+           mu_list_t list;
+           mu_list_create (&list);
+           mu_list_append (list, config_value_dup (node->label));
+           node->label->type = MU_CFG_LIST;
+           node->label->v.list = list;
+         }
+         break;
+
+       case MU_CFG_ARRAY:
+         mu_cfg_perror (sdata->tree->debug, &node->locus,
+                        _("expected list, but found array"));
+         return 1;
+       }
+
+      mu_list_create (&clos.list);
+      mu_list_do (node->label->v.list, _set_fun, &clos);
+      *(mu_list_t*)tgt = clos.list;
+    }
+  else if (clos.type == mu_cfg_callback)
+    {
+      mu_debug_set_locus (sdata->tree->debug, node->locus.file,
+                         node->locus.line);
+      if (!param->callback)
+       {
+         mu_cfg_perror (sdata->tree->debug, &node->locus,
+                        _("INTERNAL ERROR: %s: callback not defined"),
+                        node->tag);
+         abort ();
+       }
+      if (param->callback (sdata->tree->debug, tgt, node->label))
+       return 1;
+
+    }
+  else
+    return valcvt (sdata, &node->locus, tgt, clos.type, node->label);
+
+  return 0;
+}
+
+
+static int
+_scan_tree_helper (const mu_cfg_node_t *node, void *data)
+{
+  struct scan_tree_data *sdata = data;
+  struct mu_cfg_section *sec;
+
+  switch (node->type)
+    {
+    case mu_cfg_node_undefined:
+      abort ();
+
+    case mu_cfg_node_statement:
+      sec = find_subsection (sdata->list->sec, node->tag, 0);
+      if (!sec)
+       {
+         if (mu_cfg_parser_verbose)
+           {
+             _mu_cfg_debug_set_locus (sdata->tree->debug, &node->locus);
+             mu_cfg_format_error (sdata->tree->debug, MU_DIAG_WARNING,
+                                  _("unknown section `%s'"),
+                                  node->tag);
+           }
+         return MU_CFG_ITER_SKIP;
+       }
+      if (!sec->children)
+       return MU_CFG_ITER_SKIP;
+      if (sdata->list->sec->target)
+       sec->target = (char*)sdata->list->sec->target + sec->offset;
+      else if (sdata->target)
+       sec->target = (char*)sdata->target + sec->offset;
+      if (sec->parser)
+       {
+         mu_debug_set_locus (sdata->tree->debug,
+                             node->locus.file ?
+                                    node->locus.file : _("unknown file"),
+                             node->locus.line);
+         if (sec->parser (mu_cfg_section_start, node,
+                          sec->label, &sec->target,
+                          sdata->call_data, sdata->tree))
+           {
+             sdata->error++;
+             return MU_CFG_ITER_SKIP;
+           }
+       }
+      push_section(sdata, sec);
+      break;
+
+    case mu_cfg_node_param:
+      if (parse_param (sdata, node))
+       {
+         sdata->error++;
+         return MU_CFG_ITER_SKIP;
+       }
+      break;
+    }
+  return MU_CFG_ITER_OK;
+}
+
+static int
+_scan_tree_end_helper (const mu_cfg_node_t *node, void *data)
+{
+  struct scan_tree_data *sdata = data;
+  struct mu_cfg_section *sec;
+
+  switch (node->type)
+    {
+    default:
+      abort ();
+
+    case mu_cfg_node_statement:
+      sec = pop_section (sdata);
+      if (sec && sec->parser)
+       {
+         if (sec->parser (mu_cfg_section_end, node,
+                          sec->label, &sec->target,
+                          sdata->call_data, sdata->tree))
+           {
+             sdata->error++;
+             return MU_CFG_ITER_SKIP;
+           }
+       }
+    }
+  return MU_CFG_ITER_OK;
+}
+
+int
+mu_cfg_scan_tree (mu_cfg_tree_t *tree, struct mu_cfg_section *sections,
+                 void *target, void *data)
+{
+  mu_debug_t debug = NULL;
+  struct scan_tree_data dat;
+  struct mu_cfg_iter_closure clos;
+    
+  dat.tree = tree;
+  dat.list = NULL;
+  dat.error = 0;
+  dat.call_data = data;
+  dat.target = target;
+  
+  if (!tree->debug)
+    {
+      mu_diag_get_debug (&debug);
+      tree->debug = debug;
+    }
+  if (push_section (&dat, sections))
+    return 1;
+  clos.beg = _scan_tree_helper;
+  clos.end = _scan_tree_end_helper;
+  clos.data = &dat;
+  mu_cfg_preorder (tree->nodes, &clos);
+  if (debug)
+    {
+      mu_debug_set_locus (debug, NULL, 0);
+      tree->debug = NULL;
+    }
+  pop_section (&dat);
+  return dat.error;
+}
+
+int
+mu_cfg_find_section (struct mu_cfg_section *root_sec,
+                    const char *path, struct mu_cfg_section **retval)
+{
+  while (path[0])
+    {
+      struct mu_cfg_section *sec;
+      size_t len;
+      const char *p;
+
+      while (*path == MU_CFG_PATH_DELIM)
+       path++;
+
+      if (*path == 0)
+       return MU_ERR_NOENT;
+
+      p = strchr (path, MU_CFG_PATH_DELIM);
+      if (p)
+       len = p - path;
+      else
+       len = strlen (path);
+
+      sec = find_subsection (root_sec, path, len);
+      if (!sec)
+       return MU_ERR_NOENT;
+      root_sec = sec;
+      path += len;
+    }
+  if (retval)
+    *retval = root_sec;
+  return 0;
+}
+
+
+int
+mu_cfg_tree_create (struct mu_cfg_tree **ptree)
+{
+  struct mu_cfg_tree *tree = calloc (1, sizeof *tree);
+  if (!tree)
+    return errno;
+  mu_opool_create (&tree->pool, 1);
+  *ptree = tree;
+  return 0;
+}
+
+void
+mu_cfg_tree_set_debug (struct mu_cfg_tree *tree, mu_debug_t debug)
+{
+  tree->debug = debug;
+}
+
+mu_cfg_node_t *
+mu_cfg_tree_create_node (struct mu_cfg_tree *tree,
+                        enum mu_cfg_node_type type,
+                        const mu_cfg_locus_t *loc,
+                        const char *tag, const char *label,
+                        mu_list_t nodelist)
+{
+  char *p;
+  mu_cfg_node_t *np;
+  size_t size = sizeof *np + strlen (tag) + 1;
+  mu_config_value_t val;
+
+  np = mu_alloc (size);
+  np->type = type;
+  if (loc)
+    np->locus = *loc;
+  else
+    memset (&np->locus, 0, sizeof np->locus);
+  p = (char*) (np + 1);
+  np->tag = p;
+  strcpy (p, tag);
+  p += strlen (p) + 1;
+  val.type = MU_CFG_STRING;
+  if (label)
+    {
+      mu_opool_clear (tree->pool);
+      mu_opool_appendz (tree->pool, label);
+      val.v.string = mu_opool_finish (tree->pool, NULL);
+      np->label = config_value_dup (&val);
+    }
+  else
+    np->label = NULL;
+  np->nodes = nodelist;
+  return np;
+}
+
+void
+mu_cfg_tree_add_node (mu_cfg_tree_t *tree, mu_cfg_node_t *node)
+{
+  if (!node)
+    return;
+  if (!tree->nodes)
+    /* FIXME: return code? */
+    mu_cfg_create_node_list (&tree->nodes);
+  mu_list_append (tree->nodes, node);
+}
+
+void
+mu_cfg_tree_add_nodelist (mu_cfg_tree_t *tree, mu_list_t nodelist)
+{
+  if (!nodelist)
+    return;
+  if (!tree->nodes)
+    /* FIXME: return code? */
+    mu_cfg_create_node_list (&tree->nodes);
+  mu_list_append_list (tree->nodes, nodelist);
+}
+
+
+/* Return 1 if configuration value A equals B */
+int
+mu_cfg_value_eq (mu_config_value_t *a, mu_config_value_t *b)
+{
+  if (a->type != b->type)
+    return 0;
+  switch (a->type)
+    {
+    case MU_CFG_STRING:
+      if (a->v.string == NULL)
+       return b->v.string == NULL;
+      return strcmp (a->v.string, b->v.string) == 0;
+                    
+    case MU_CFG_LIST:
+      {
+       int ret = 1;
+       size_t cnt;
+       size_t i;
+       mu_iterator_t aitr, bitr;
+       
+       mu_list_count (a->v.list, &cnt);
+       mu_list_count (b->v.list, &i);
+       if (i != cnt)
+         return 1;
+
+       mu_list_get_iterator (a->v.list, &aitr);
+       mu_list_get_iterator (b->v.list, &bitr);
+       for (i = 0,
+              mu_iterator_first (aitr),
+              mu_iterator_first (bitr);
+            !mu_iterator_is_done (aitr) && !mu_iterator_is_done (bitr);
+            mu_iterator_next (aitr),
+              mu_iterator_next (bitr),
+              i++)
+         {
+           mu_config_value_t *ap, *bp;
+           mu_iterator_current (aitr, (void**)&ap);
+           mu_iterator_current (bitr, (void**)&bp);
+           ret = mu_cfg_value_eq (ap, bp);
+           if (!ret)
+             break;
+         }
+       mu_iterator_destroy (&aitr);
+       mu_iterator_destroy (&bitr);
+       return ret && i == cnt;
+      }
+       
+    case MU_CFG_ARRAY:
+      if (a->v.arg.c == b->v.arg.c)
+       {
+         size_t i;
+         for (i = 0; i < a->v.arg.c; i++)
+           if (!mu_cfg_value_eq (&a->v.arg.v[i], &b->v.arg.v[i]))
+             return 0;
+         return 1;
+       }
+    }
+  return 0;
+}
+
+
+static int
+split_cfg_path (const char *path, int *pargc, char ***pargv)
+{
+  int rc;
+  int argc;
+  char **argv;
+  char *delim = MU_CFG_PATH_DELIM_STR;
+  char static_delim[2] = { 0, 0 };
+  
+  if (path[0] == '\\')
+    {
+      argv = calloc (2, sizeof (*argv));
+      if (!argv)
+       return ENOMEM;
+      argv[0] = strdup (path + 1);
+      if (!argv[0])
+       {
+         free (argv);
+         return ENOMEM;
+       }
+      argv[1] = NULL;
+      argc = 1;
+      rc = 0;
+    }
+  else
+    {
+      if (mu_ispunct (path[0]))
+       {
+         delim = static_delim;
+         delim[0] = path[0];
+         path++;
+       }
+      rc = mu_argcv_get_np (path, strlen (path), delim, NULL, 0,
+                           &argc, &argv, NULL);
+    }
+  if (rc == 0)
+    {
+      *pargc = argc;
+      *pargv = argv;
+    }
+  return rc;
+}
+
+struct find_data
+{
+  int argc;
+  char **argv;
+  int tag;
+  mu_config_value_t *label;
+  const mu_cfg_node_t *node;
+};
+
+static void
+free_value_mem (mu_config_value_t *p)
+{
+  switch (p->type)
+    {
+    case MU_CFG_STRING:
+      free ((char*)p->v.string);
+      break;
+      
+    case MU_CFG_LIST:
+      /* FIXME */
+      break;
+      
+    case MU_CFG_ARRAY:
+      {
+       size_t i;
+       for (i = 0; i < p->v.arg.c; i++)
+         free_value_mem (&p->v.arg.v[i]);
+      }
+    }
+}
+
+static void
+destroy_value (void *p)
+{
+  mu_config_value_t *val = p;
+  if (val)
+    {
+      free_value_mem (val);
+      free (val);
+    }
+}
+
+static mu_config_value_t *
+parse_label (const char *str)
+{
+  mu_config_value_t *val = NULL;
+  int count, i;
+  char **vect;
+  size_t len = strlen (str);
+  
+  if (len > 1 && str[0] == '(' && str[len-1] == ')')
+    {
+      mu_list_t lst;
+      mu_argcv_get_np (str + 1, len - 2,
+                      ", \t", NULL,
+                      0,
+                      &count, &vect, NULL);
+      mu_list_create (&lst);
+      mu_list_set_destroy_item (lst, destroy_value);
+      for (i = 0; i < count; i++)
+       {
+         mu_config_value_t *p = mu_alloc (sizeof (*p));
+         p->type = MU_CFG_STRING;
+         p->v.string = vect[i];
+         mu_list_append (lst, p);
+       }
+      free (vect);
+      val = mu_alloc (sizeof (*val));
+      val->type = MU_CFG_LIST;
+      val->v.list = lst;
+    }
+  else
+    {      
+      mu_argcv_get (str, NULL, NULL, &count, &vect);
+      val = mu_alloc (sizeof (*val));
+      if (count == 1)
+       {
+         val->type = MU_CFG_STRING;
+         val->v.string = vect[0];
+         free (vect);
+       }
+      else
+       {
+         val->type = MU_CFG_ARRAY;
+         val->v.arg.c = count;
+         val->v.arg.v = mu_alloc (count * sizeof (val->v.arg.v[0]));
+         for (i = 0; i < count; i++)
+           {
+             val->v.arg.v[i].type = MU_CFG_STRING;
+             val->v.arg.v[i].v.string = vect[i];
+           }
+         free (vect);
+       }
+    }
+  return val;
+}
+
+static void
+parse_tag (struct find_data *fptr)
+{
+  char *p = strchr (fptr->argv[fptr->tag], '=');
+  if (p)
+    {
+      *p++ = 0;
+      fptr->label = parse_label (p);
+    }
+  else
+    fptr->label = NULL;
+}
+
+static int
+node_finder (const mu_cfg_node_t *node, void *data)
+{
+  struct find_data *fdptr = data;
+  if (strcmp (fdptr->argv[fdptr->tag], node->tag) == 0
+      && (!fdptr->label || mu_cfg_value_eq (fdptr->label, node->label)))
+    {
+      fdptr->tag++;
+      if (fdptr->tag == fdptr->argc)
+       {
+         fdptr->node = node;
+         return MU_CFG_ITER_STOP;
+       }
+      parse_tag (fdptr);
+      return MU_CFG_ITER_OK;
+    }
+  
+  return node->type == mu_cfg_node_statement ?
+               MU_CFG_ITER_SKIP : MU_CFG_ITER_OK;
+}
+
+int        
+mu_cfg_find_node (mu_cfg_tree_t *tree, const char *path, mu_cfg_node_t **pval)
+{
+  int rc;
+  struct find_data data;
+  struct mu_cfg_iter_closure clos;
+
+  rc = split_cfg_path (path, &data.argc, &data.argv);
+  if (rc)
+    return rc;
+  data.tag = 0;
+  parse_tag (&data);
+
+  clos.beg = node_finder;
+  clos.end = NULL;
+  clos.data = &data;
+  rc = mu_cfg_preorder (tree->nodes, &clos);
+  destroy_value (data.label);
+  if (rc)
+    {
+      *pval = (mu_cfg_node_t *) data.node;
+      return 0;
+    }
+  return MU_ERR_NOENT;
+}
+
+
+
+int
+mu_cfg_create_subtree (const char *path, mu_cfg_node_t **pnode)
+{
+  int rc;
+  int argc, i;
+  char **argv;
+  enum mu_cfg_node_type type;
+  mu_cfg_node_t *node = NULL;
+  mu_cfg_locus_t locus;
+
+  locus.file = "<int>";
+  locus.line = 0;
+
+  rc = split_cfg_path (path, &argc, &argv);
+  if (rc)
+    return rc;
+
+  for (i = argc - 1; i >= 0; i--)
+    {
+      mu_list_t nodelist = NULL;
+      mu_config_value_t *label = NULL;
+      char *q = argv[i], *p;
+      
+      type = mu_cfg_node_statement;
+      do
+       {
+         p = strchr (q, '=');
+         if (p && p > argv[i] && p[-1] != '\\')
+           {
+             *p++ = 0;
+             label = parse_label (p);
+             if (i == argc - 1)
+               type = mu_cfg_node_param;
+             break;
+           }
+         else if (p)
+           q = p + 1;
+         else
+           break;
+       }
+      while (*q);
+      
+      if (node)
+       {
+         mu_cfg_create_node_list (&nodelist);
+         mu_list_append (nodelist, node);
+       }
+      node = mu_cfg_alloc_node (type, &locus, argv[i], label, nodelist);
+    }
+
+  mu_argcv_free (argc, argv);
+  *pnode = node;
+  return 0;
+}
+
+  
+         
+        
+  
diff --git a/libmailutils/cfg_driver.c b/libmailutils/cfg_driver.c
deleted file mode 100644
index f07a22f..0000000
--- a/libmailutils/cfg_driver.c
+++ /dev/null
@@ -1,754 +0,0 @@
-/* cfg_driver.c -- Main driver for Mailutils configuration files
-   Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
-
-   GNU Mailutils is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 3, or (at
-   your option) any later version.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <ctype.h>
-#include <mailutils/argcv.h>
-#include <mailutils/nls.h>
-#define MU_CFG_COMPATIBILITY /* This source uses deprecated cfg interfaces */
-#include <mailutils/cfg.h>
-#include <mailutils/errno.h>
-#include <mailutils/error.h>
-#include <mailutils/mutil.h>
-#include <mailutils/monitor.h>
-#include <mailutils/refcount.h>
-#include <mailutils/list.h>
-#include <mailutils/iterator.h>
-#include <mailutils/stream.h>
-#include <mailutils/assoc.h>
-#include <mailutils/alloc.h>
-
-
-static mu_assoc_t section_tab;
-
-static void
-alloc_section_tab ()
-{
-  if (!section_tab)
-    mu_assoc_create (&section_tab, sizeof (struct mu_cfg_cont **),
-                    MU_ASSOC_COPY_KEY);
-}
-
-int
-mu_create_canned_section (char *name, struct mu_cfg_section **psection)
-{
-  int rc;
-  struct mu_cfg_cont **pcont;
-  alloc_section_tab ();
-  rc = mu_assoc_ref_install (section_tab, name, (void **)&pcont);
-  if (rc == 0)
-    {
-      mu_config_create_container (pcont, mu_cfg_cont_section);
-      *psection = &(*pcont)->v.section;
-      (*psection)->ident = name;
-    }
-  else if (rc == MU_ERR_EXISTS)
-    *psection = &(*pcont)->v.section;
-  return rc;
-}
-
-int
-mu_create_canned_param (char *name, struct mu_cfg_param **pparam)
-{
-  int rc;
-  struct mu_cfg_cont **pcont;
-  alloc_section_tab ();
-  rc = mu_assoc_ref_install (section_tab, name, (void **)&pcont);
-  if (rc == 0)
-    {
-      mu_config_create_container (pcont, mu_cfg_cont_param);
-      *pparam = &(*pcont)->v.param;
-      (*pparam)->ident = name;
-    }
-  else if (rc == MU_ERR_EXISTS)
-    *pparam = &(*pcont)->v.param;
-  return rc;
-}
-
-struct mu_cfg_cont *
-mu_get_canned_container (const char *name)
-{
-  struct mu_cfg_cont **pcont = mu_assoc_ref (section_tab, name);
-  return pcont ? *pcont : NULL;
-}
-
-
-static struct mu_cfg_cont *root_container;
-
-int
-mu_config_create_container (struct mu_cfg_cont **pcont,
-                           enum mu_cfg_cont_type type)
-{
-  struct mu_cfg_cont *cont;
-  int rc;
-  
-  cont = calloc (1, sizeof (*cont));
-  if (!cont)
-    return ENOMEM;
-  rc = mu_refcount_create (&cont->refcount);
-  if (rc)
-    free (cont);
-  else
-    {
-      cont->type = type;
-      *pcont = cont;
-    }
-  return rc; 
-}  
-
-
-struct dup_data
-{
-  struct mu_cfg_cont *cont;
-};
-
-static int dup_container (struct mu_cfg_cont **pcont);
-
-static int
-_dup_cont_action (void *item, void *cbdata)
-{
-  int rc;
-  struct mu_cfg_cont *cont = item;
-  struct dup_data *pdd = cbdata;
-
-  rc = dup_container (&cont);
-  if (rc)
-    return rc;
-
-  if (!pdd->cont->v.section.children)
-    {
-      int rc = mu_list_create (&pdd->cont->v.section.children);
-      if (rc)
-       return rc;
-    }
-  return mu_list_append (pdd->cont->v.section.children, cont);
-}
-
-static int
-dup_container (struct mu_cfg_cont **pcont)
-{
-  int rc;
-  struct mu_cfg_cont *newcont, *oldcont = *pcont;
-  struct dup_data dd;
-
-  rc = mu_config_create_container (&newcont, oldcont->type);
-  if (rc)
-    return rc;
-
-  dd.cont = newcont;
-  switch (oldcont->type)
-    {
-    case mu_cfg_cont_section:
-      newcont->v.section.ident = oldcont->v.section.ident;
-      newcont->v.section.label = oldcont->v.section.label;
-      newcont->v.section.parser = oldcont->v.section.parser;
-      newcont->v.section.target = oldcont->v.section.target;
-      newcont->v.section.offset = oldcont->v.section.offset;
-      newcont->v.section.docstring = oldcont->v.section.docstring;
-      newcont->v.section.children = NULL;
-      mu_list_do (oldcont->v.section.children, _dup_cont_action, &dd);
-      break;
-
-    case mu_cfg_cont_param:
-      newcont->v.param = oldcont->v.param;
-      break;
-    }
-  *pcont = newcont;
-  return 0;
-}
-
-
-static void
-destroy_list (mu_list_t *plist)
-{
-  mu_list_t list = *plist;
-  mu_iterator_t itr = NULL;
-  
-  if (!list)
-    return;
-
-  mu_list_get_iterator (list, &itr);
-  for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
-       mu_iterator_next (itr))
-    {
-      struct mu_cfg_cont *cont, *p;
-      mu_iterator_current (itr, (void**)&cont);
-      p = cont;
-      mu_config_destroy_container (&p);
-      if (!p)
-       mu_list_remove (list, cont);
-    }
-  mu_iterator_destroy (&itr);
-  if (mu_list_is_empty (list))
-    mu_list_destroy (plist);
-}
-
-void
-mu_config_destroy_container (struct mu_cfg_cont **pcont)
-{
-  struct mu_cfg_cont *cont = *pcont;
-  unsigned refcount = mu_refcount_dec (cont->refcount);
-  /* printf ("destr %p-%s: %d\n", cont, cont->v.section.ident, refcount); */
-  switch (cont->type)
-    {
-    case mu_cfg_cont_section:
-      destroy_list (&cont->v.section.children);
-      break;
-
-    case mu_cfg_cont_param:
-      break;
-    }
-
-  if (refcount == 0)
-    {
-      free (cont);
-      *pcont = 0;
-    }
-}
-     
-
-int
-mu_cfg_section_add_container (struct mu_cfg_section *sect,
-                             struct mu_cfg_cont *cont)
-{
-  if (!cont)
-    return 0;
-  if (!sect->children)
-    mu_list_create (&sect->children);
-  return mu_list_append (sect->children, cont);
-}
-
-int
-mu_cfg_section_add_params (struct mu_cfg_section *sect,
-                          struct mu_cfg_param *param)
-{
-  if (!param)
-    return 0;
-
-  for (; param->ident; param++)
-    {
-      int rc;
-      struct mu_cfg_cont *container;
-
-      if (param->type == mu_cfg_section)
-       {
-         container = mu_get_canned_container (param->ident);
-         if (!container)
-           {
-             mu_error (_("INTERNAL ERROR: Requested unknown canned "
-                         "section %s"),
-                       param->ident);
-             abort ();
-           }
-         if (param->ident[0] == '.')
-           {
-             mu_iterator_t itr;
-             mu_list_get_iterator (container->v.section.children, &itr);
-             for (mu_iterator_first (itr);
-                  !mu_iterator_is_done (itr);
-                  mu_iterator_next (itr))
-               {
-                 struct mu_cfg_cont *c;
-                 mu_iterator_current (itr, (void**)&c);
-                 mu_config_clone_container (c);
-                 if (mu_refcount_value (c->refcount) > 1)
-                   dup_container (&c);
-                 switch (c->type)
-                   {
-                   case mu_cfg_cont_section:
-                     c->v.section.offset += param->offset;
-                     break;
-
-                   case mu_cfg_cont_param:
-                     container->v.param.offset += param->offset;
-                     break;
-                   }
-                 mu_cfg_section_add_container (sect, c);
-               }
-             mu_iterator_destroy (&itr);
-             continue;
-           }
-         else
-           {
-             mu_config_clone_container (container);
-             if (mu_refcount_value (container->refcount) > 1)
-               dup_container (&container);
-             container->v.section.target = param->data;
-             container->v.section.offset = param->offset;
-           }
-       }
-      else
-       {
-         rc = mu_config_create_container (&container, mu_cfg_cont_param);
-         if (rc)
-           return rc;
-         container->v.param = *param;
-       }
-      mu_cfg_section_add_container (sect, container);
-    }
-  return 0;
-}
-
-static int
-_clone_action (void *item, void *cbdata)
-{
-  struct mu_cfg_cont *cont = item;
-  return mu_config_clone_container (cont);
-}
-
-int
-mu_config_clone_container (struct mu_cfg_cont *cont)
-{
-  if (!cont)
-    return 0;
-  mu_refcount_inc (cont->refcount);
-  /* printf("clone %p-%s: %d\n", cont, cont->v.section.ident, n); */
-  switch (cont->type)
-    {
-    case mu_cfg_cont_section:
-      mu_list_do (cont->v.section.children, _clone_action, NULL);
-      break;
-
-    case mu_cfg_cont_param:
-      break;
-    }
-  return 0;
-}  
-
-
-int
-_mu_config_register_section (struct mu_cfg_cont **proot,
-                            const char *parent_path,
-                            const char *ident,
-                            const char *label,
-                            mu_cfg_section_fp parser,
-                            struct mu_cfg_param *param,
-                            struct mu_cfg_section **psection)
-{
-  int rc;
-  struct mu_cfg_section *root_section;
-  struct mu_cfg_section *parent;
-  
-  if (!*proot)
-    {
-      rc = mu_config_create_container (proot, mu_cfg_cont_section);
-      if (rc)
-       return rc;
-      memset (&(*proot)->v.section, 0, sizeof (*proot)->v.section);
-    }
-  
-  root_section = &(*proot)->v.section;
-  
-  if (parent_path)
-    {
-      if (mu_cfg_find_section (root_section, parent_path, &parent))
-       return MU_ERR_NOENT;
-    }
-  else  
-    parent = root_section;
-
-  if (mu_refcount_value ((*proot)->refcount) > 1)
-    {
-      /* It is a clone, do copy-on-write */
-      rc = dup_container (proot);
-      if (rc)
-       return rc;
-
-      root_section = &(*proot)->v.section;
-      
-      if (parent_path)
-       {
-         if (mu_cfg_find_section (root_section, parent_path, &parent))
-           return MU_ERR_NOENT;
-       }
-      else  
-       parent = root_section;
-    }
-
-  if (ident)
-    {
-      struct mu_cfg_cont *container;
-      struct mu_cfg_section *s;
-      
-      if (!parent->children)
-       mu_list_create (&parent->children);
-      mu_config_create_container (&container, mu_cfg_cont_section);
-      mu_list_append (parent->children, container); 
-      s = &container->v.section;
-
-      s->ident = strdup (ident);
-      s->label = label ? strdup (label) : NULL;
-      s->parser = parser;
-      s->children = NULL;
-      mu_cfg_section_add_params (s, param);
-      if (psection)
-       *psection = s;
-    }
-  else
-    {
-      mu_cfg_section_add_params (parent, param);
-      /* FIXME: */
-      if (!parent->parser)
-       parent->parser = parser;
-      if (psection)
-       *psection = parent;
-    }
-  return 0;
-}
-  
-int
-mu_config_register_section (const char *parent_path,
-                           const char *ident,
-                           const char *label,
-                           mu_cfg_section_fp parser,
-                           struct mu_cfg_param *param)
-{
-  return _mu_config_register_section (&root_container,
-                                     parent_path,
-                                     ident, label,
-                                     parser, param, NULL);
-}
-
-int
-mu_config_register_plain_section (const char *parent_path, const char *ident,
-                                 struct mu_cfg_param *params)
-{
-  return mu_config_register_section (parent_path, ident, NULL, NULL, params);
-}
-
-static int
-prog_parser (enum mu_cfg_section_stage stage,
-            const mu_cfg_node_t *node,
-            const char *label, void **section_data,
-            void *call_data,
-            mu_cfg_tree_t *tree)
-{
-  if (stage == mu_cfg_section_start)
-    {
-      return node->label->type == MU_CFG_STRING
-            && strcmp (node->label->v.string, label);
-    }
-  
-  return 0;
-}
-
-struct include_data
-{
-  const char *progname;
-  struct mu_cfg_param *progparam;
-  int flags;
-  void *target;
-};
-
-static int
-_cb_include (mu_debug_t debug, void *data, mu_config_value_t *val)
-{
-  int ret = 0;
-  struct stat sb;
-  const char *dirname;
-  struct include_data *idp = data;
-  char *tmp = NULL;
-
-  if (mu_cfg_assert_value_type (val, MU_CFG_STRING, debug))
-    return 1;
-
-  dirname = val->v.string;
-  if (dirname[0] != '/')
-    {
-      dirname = tmp = mu_make_file_name (SYSCONFDIR, dirname);
-      if (!dirname)
-        {
-          mu_error ("%s", mu_strerror (errno));
-          return 1;
-        }
-    }
-    
-  if (stat (dirname, &sb) == 0)
-    {
-      if (S_ISDIR (sb.st_mode))
-       {
-         char *file = mu_make_file_name (dirname, idp->progname);
-         ret = mu_get_config (file, idp->progname, idp->progparam,
-                              idp->flags & ~MU_PARSE_CONFIG_GLOBAL,
-                              idp->target);
-       }
-      else
-       ret = mu_get_config (dirname, idp->progname, idp->progparam,
-                            idp->flags, idp->target);
-    }
-  else if (errno == ENOENT)
-    {
-      mu_cfg_format_error (debug, MU_DEBUG_ERROR,
-                          _("include file or directory does not exist"));
-      ret = 1;
-    }
-  else
-    {
-      mu_cfg_format_error (debug, MU_DEBUG_ERROR,
-                          _("cannot stat include file or directory: %s"),
-                          mu_strerror (errno));
-      ret = 1;
-    }
-  free (tmp);
-  return ret;
-}
-
-struct mu_cfg_cont *
-mu_build_container (const char *progname, struct include_data *idp)
-{
-  struct mu_cfg_cont *cont = root_container;
-
-  mu_config_clone_container (cont);
-  
-  if (idp->flags & MU_PARSE_CONFIG_PLAIN)
-    {
-      struct mu_cfg_param mu_include_param[] = {
-       { "include", mu_cfg_callback, NULL, 0, _cb_include,
-         N_("Include contents of the given file.  If a directory is given, "
-            "include contents of the file <file>/<program>, where "
-            "<program> is the name of the program.  This latter form is "
-            "allowed only in the site-wide configuration file."),
-         N_("file-or-directory") },
-       { NULL }
-      };
-
-      mu_include_param[0].data = idp;
-      _mu_config_register_section (&cont, NULL, NULL, NULL,
-                                  (void*) progname, mu_include_param, NULL);
-      
-      if (idp->flags & MU_PARSE_CONFIG_GLOBAL)
-       {
-         mu_iterator_t iter;
-         struct mu_cfg_section *prog_sect;
-         struct mu_cfg_cont *old_root = root_container;
-         static struct mu_cfg_param empty_param = { NULL };
-         
-         _mu_config_register_section (&cont, NULL, "program", progname,
-                                      prog_parser,
-                                      idp->progparam ?
-                                      idp->progparam : &empty_param,
-                                      &prog_sect);
-      
-         if (old_root->v.section.children)
-           {
-             if (!prog_sect->children)
-               mu_list_create (&prog_sect->children);
-             mu_list_get_iterator (old_root->v.section.children, &iter);
-             for (mu_iterator_first (iter); !mu_iterator_is_done (iter);
-                  mu_iterator_next (iter))
-               {
-                 struct mu_cfg_cont *c;
-                 mu_iterator_current (iter, (void**)&c);
-                 mu_list_append (prog_sect->children, c);
-               }
-             mu_iterator_destroy (&iter);
-           }
-       }
-      else if (idp->progparam)
-       _mu_config_register_section (&cont, NULL, NULL, NULL, NULL,
-                                    idp->progparam, NULL);
-    }
-  else if (idp->progparam)
-    _mu_config_register_section (&cont, NULL, NULL, NULL, NULL,
-                                idp->progparam, NULL);
-  
-  return cont;
-}
-
-int
-mu_cfg_tree_reduce (mu_cfg_tree_t *parse_tree, const char *progname,
-                   struct mu_cfg_param *progparam, int flags,
-                   void *target_ptr)
-{
-  int rc = 0;
-
-  if (!parse_tree)
-    return 0;
-  if (flags & MU_PARSE_CONFIG_DUMP)
-    {
-      mu_stream_t stream;
-      mu_stdio_stream_create (&stream, MU_STDERR_FD, 0);
-      mu_cfg_format_parse_tree (stream, parse_tree, MU_CFG_FMT_LOCUS);
-      mu_stream_destroy (&stream);
-    }
-
-  if (root_container)
-    {
-      struct include_data idata;
-      struct mu_cfg_cont *cont;
-      
-      idata.progname = progname;
-      idata.progparam = progparam;
-      idata.flags = flags;
-      idata.target = target_ptr;
-      
-      cont = mu_build_container (progname, &idata);
-      
-      rc = mu_cfg_scan_tree (parse_tree, &cont->v.section, target_ptr,
-                            (void*) progname);
-      mu_config_destroy_container (&cont);
-    }
-
-  return rc;
-}
-
-void
-mu_format_config_tree (mu_stream_t stream, const char *progname,
-                      struct mu_cfg_param *progparam, int flags)
-{
-  struct include_data idata;
-  struct mu_cfg_cont *cont;
-  
-  idata.progname = progname;
-  idata.progparam = progparam;
-  idata.flags = flags;
-  idata.target = NULL;
-  cont = mu_build_container (progname, &idata);
-  mu_cfg_format_container (stream, cont);
-  mu_config_destroy_container (&cont);
-}
-
-int
-mu_parse_config (const char *file, const char *progname,
-                struct mu_cfg_param *progparam, int flags,
-                void *target_ptr)
-{
-  int rc;
-  char *full_name = mu_tilde_expansion (file, "/", NULL);
-  if (full_name)
-    {
-      if (access (full_name, R_OK) == 0)
-       {
-         rc = mu_get_config (full_name, progname, progparam, flags,
-                             target_ptr);
-       }
-      else
-       rc = ENOENT;
-      free (full_name);
-    }
-  else
-    rc = ENOMEM;
-  return rc;
-}
-
-static const char *
-_first_value_ptr (mu_config_value_t *val)
-{
-  switch (val->type)
-    {
-    case MU_CFG_STRING:
-      return val->v.string;
-      
-    case MU_CFG_ARRAY:
-      return _first_value_ptr (val->v.arg.v);
-      
-    case MU_CFG_LIST:
-      mu_list_get (val->v.list, 0, (void**) &val);
-      return _first_value_ptr (val);
-    }
-  return "";  
-}
-
-int
-mu_cfg_assert_value_type (mu_config_value_t *val, int type, mu_debug_t debug)
-{
-  if (!val)
-    { 
-      mu_cfg_format_error (debug, MU_DEBUG_ERROR,
-                           _("required argument missing"));
-      return 1;
-    }
-
-  if (type == MU_CFG_ARRAY)
-    {
-      if (val->type == MU_CFG_STRING)
-       {
-         mu_config_value_t *arr = mu_calloc (1, sizeof arr[0]);
-         arr[0] = *val;
-         val->v.arg.c = 1;
-         val->v.arg.v = arr;
-         val->type = MU_CFG_ARRAY;
-       }
-    }
-  
-  if (val->type != type)
-    {
-      /* FIXME */
-      mu_cfg_format_error (debug, MU_DEBUG_ERROR,
-                          _("unexpected value: %s"), 
-                          _first_value_ptr (val));
-      return 1;
-    }
-  return 0;
-}
-
-int
-mu_cfg_string_value_cb (mu_debug_t debug, mu_config_value_t *val,
-                       int (*fun) (mu_debug_t, const char *, void *),
-                       void *data)
-{
-  int rc = 0;
-  
-  switch (val->type)
-    {
-    case MU_CFG_STRING:
-      return fun (debug, val->v.string, data);
-      break;
-
-    case MU_CFG_ARRAY:
-      {
-       int i;
-
-       for (i = 0; i < val->v.arg.c; i++)
-         {
-           if (mu_cfg_assert_value_type (&val->v.arg.v[i],
-                                         MU_CFG_STRING, debug))
-             return 1;
-           fun (debug, val->v.arg.v[i].v.string, data);
-         }
-      }
-      break;
-
-    case MU_CFG_LIST:
-      {
-       mu_iterator_t itr;
-       mu_list_get_iterator (val->v.list, &itr);
-       for (mu_iterator_first (itr);
-            !mu_iterator_is_done (itr); mu_iterator_next (itr))
-         {
-           mu_config_value_t *pval;
-           mu_iterator_current (itr, (void*) &pval);
-           if (mu_cfg_assert_value_type (pval, MU_CFG_STRING, debug))
-             {
-               rc = 1;
-               break;
-             }
-           fun (debug, pval->v.string, data);
-         }
-       mu_iterator_destroy (&itr);
-      }
-    }
-  return rc;
-}
diff --git a/libmailutils/cfg_format.c b/libmailutils/cfg_format.c
deleted file mode 100644
index be37bae..0000000
--- a/libmailutils/cfg_format.c
+++ /dev/null
@@ -1,395 +0,0 @@
-/* cfg_print.c -- convert configuration parse tree to human-readable format.
-   Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
-
-   GNU Mailutils is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 3, or (at
-   your option) any later version.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <mailutils/alloc.h>
-#include <mailutils/stream.h>
-#include <mailutils/error.h>
-#include <mailutils/cfg.h>
-#include <mailutils/argcv.h>
-#include <mailutils/nls.h>
-#include <mailutils/iterator.h>
-#include <ctype.h>
-
-struct tree_print
-{
-  int flags;
-  unsigned level;
-  mu_stream_t stream;
-  char *buf;
-  size_t bufsize;
-};
-
-static void
-format_level (mu_stream_t stream, int level)
-{
-  while (level--)
-    mu_stream_write (stream, "  ", 2, NULL);
-}
-
-static void
-format_string_value (struct tree_print *tp, const char *str)
-{
-  size_t size;
-  int quote;
-  char *p;
-
-  size = mu_argcv_quoted_length (str, &quote);
-  if (quote)
-    size += 2;
-  size++;
-  if (size > tp->bufsize)
-    {
-      p = mu_realloc (tp->buf, size);
-      tp->bufsize = size;
-      tp->buf = p;
-    }
-  
-  p = tp->buf;
-  if (quote)
-    {
-      tp->buf[0] = '"';
-      tp->buf[size-2] = '"';
-      p++;
-    }
-  tp->buf[size-1] = 0;
-  mu_argcv_quote_copy (p, str);
-  mu_stream_write (tp->stream, tp->buf, size - 1, NULL);
-}
-
-static void format_value (struct tree_print *tp, mu_config_value_t *val);
-
-static void
-format_list_value (struct tree_print *tp, mu_config_value_t *val)
-{
-  int i;
-  mu_iterator_t itr;
-  mu_stream_write (tp->stream, "(", 1, NULL);
-  mu_list_get_iterator (val->v.list, &itr);
-  
-  for (mu_iterator_first (itr), i = 0;
-       !mu_iterator_is_done (itr); mu_iterator_next (itr), i++)
-    {
-      mu_config_value_t *p;
-      mu_iterator_current (itr, (void**)&p);
-      if (i)
-       mu_stream_write (tp->stream, ", ", 2, NULL);
-      format_value (tp, p);
-    }
-  mu_iterator_destroy (&itr);
-  mu_stream_write (tp->stream, ")", 1, NULL);
-}
-
-static void
-format_array_value (struct tree_print *tp, mu_config_value_t *val)
-{
-  int i;
-
-  for (i = 0; i < val->v.arg.c; i++)
-    {
-      if (i)
-       mu_stream_write (tp->stream, " ", 1, NULL);
-      format_value (tp, &val->v.arg.v[i]);
-    }
-}
-    
-static void
-format_value (struct tree_print *tp, mu_config_value_t *val)
-{
-  switch (val->type)
-    {
-    case MU_CFG_STRING:
-      format_string_value (tp, val->v.string);
-      break;
-
-    case MU_CFG_LIST:
-      format_list_value (tp, val);
-      break;
-
-    case MU_CFG_ARRAY:
-      format_array_value (tp, val);
-    }
-}
-
-static int
-format_node (const mu_cfg_node_t *node, void *data)
-{
-  struct tree_print *tp = data;
-
-  if ((tp->flags & MU_CFG_FMT_LOCUS) && node->locus.file)
-    mu_stream_printf (tp->stream, "# %lu \"%s\"\n",
-                     (unsigned long) node->locus.line, 
-                     node->locus.file);
-  format_level (tp->stream, tp->level);
-  switch (node->type)
-    {
-    case mu_cfg_node_undefined:
-      mu_stream_printf (tp->stream, "%s",
-                       _("ERROR: undefined statement"));
-      break;
-
-    case mu_cfg_node_statement:
-      {
-       mu_stream_write (tp->stream, node->tag, strlen (node->tag), NULL);
-       if (node->label)
-         {
-           mu_stream_write (tp->stream, " ", 1, NULL);
-           format_value (tp, node->label);
-         }
-       mu_stream_write (tp->stream, " {", 2, NULL);
-       tp->level++;
-      }
-      break;
-
-    case mu_cfg_node_param:
-      mu_stream_write (tp->stream, node->tag, strlen (node->tag), NULL);
-      if (node->label)
-       {
-         mu_stream_write (tp->stream, " ", 1, NULL);
-         format_value (tp, node->label);
-         mu_stream_write (tp->stream, ";", 1, NULL);
-       }
-      break;
-    }
-  mu_stream_write (tp->stream, "\n", 1, NULL);
-  return MU_CFG_ITER_OK;
-}
-
-static int
-format_node_end (const mu_cfg_node_t *node, void *data)
-{
-  struct tree_print *tp = data;
-  tp->level--;
-  format_level (tp->stream, tp->level);
-  mu_stream_write (tp->stream, "};\n", 3, NULL);
-  return MU_CFG_ITER_OK;
-}
-
-void
-mu_cfg_format_parse_tree (mu_stream_t stream, mu_cfg_tree_t *tree, int flags)
-{
-  struct mu_cfg_iter_closure clos;
-  struct tree_print t;
-
-  t.flags = flags;
-  t.level = 0;
-  t.stream = stream;
-  t.buf = NULL;
-  t.bufsize = 0;
-  clos.beg = format_node;
-  clos.end = format_node_end;
-  clos.data = &t;
-  mu_cfg_preorder (tree->nodes, &clos);
-  free (t.buf);
-}
-
-void
-mu_cfg_format_node (mu_stream_t stream, const mu_cfg_node_t *node, int flags)
-{
-  struct tree_print t;
-  
-  t.flags = flags;
-  t.level = 0;
-  t.stream = stream;
-  t.buf = NULL;
-  t.bufsize = 0;
-  format_node (node, &t);
-  if (node->type == mu_cfg_node_statement)
-    {
-      struct mu_cfg_iter_closure clos;
-      clos.beg = format_node;
-      clos.end = format_node_end;
-      clos.data = &t;
-      mu_cfg_preorder (node->nodes, &clos);
-      format_node_end (node, &t);
-    }
-}
-
-
-
-const char *
-mu_cfg_data_type_string (enum mu_cfg_param_data_type type)
-{
-  switch (type)
-    {
-    case mu_cfg_string:
-      return N_("string");
-    case mu_cfg_short:
-    case mu_cfg_ushort:
-    case mu_cfg_int:
-    case mu_cfg_uint:
-    case mu_cfg_long:
-    case mu_cfg_ulong:
-    case mu_cfg_size:
-    case mu_cfg_off:
-      return N_("number");
-    case mu_cfg_time:
-      return N_("time");
-    case mu_cfg_bool:
-      return N_("boolean");
-    case mu_cfg_ipv4:
-      return N_("ipv4");
-    case mu_cfg_cidr:
-      return N_("cidr");
-    case mu_cfg_host:
-      return N_("host");
-    case mu_cfg_callback:
-      return N_("string");
-    case mu_cfg_section:
-      return N_("section");
-    }
-  return N_("unknown");
-}
-
-void
-mu_cfg_format_docstring (mu_stream_t stream, const char *docstring, int level)
-{
-  size_t len = strlen (docstring);
-  int width = 78 - level * 2;
-
-  if (width < 0)
-    {
-      width = 78;
-      level = 0;
-    }
-  
-  while (len)
-    {
-      size_t seglen;
-      const char *p;
-      
-      for (seglen = 0, p = docstring; p < docstring + width && *p; p++)
-       {
-         if (*p == '\n')
-           {
-             seglen = p - docstring;
-             break;
-           }
-         if (isspace (*p))
-           seglen = p - docstring;
-       }
-      if (seglen == 0 || *p == 0)
-       seglen = p - docstring;
-
-      format_level (stream, level);
-      mu_stream_write (stream, "# ", 2, NULL);
-      mu_stream_write (stream, docstring, seglen, NULL);
-      mu_stream_write (stream, "\n", 1, NULL);
-      len -= seglen;
-      docstring += seglen;
-      if (*docstring == '\n')
-       {
-         docstring++;
-         len--;
-       }
-      else
-       while (*docstring && isspace (*docstring))
-         {
-           docstring++;
-           len--;
-         }
-    }
-}
-
-static void
-format_param (mu_stream_t stream, struct mu_cfg_param *param, int level)
-{
-  if (param->docstring)
-    mu_cfg_format_docstring (stream, gettext (param->docstring), level);
-  format_level (stream, level);
-  if (param->argname && strchr (param->argname, ':'))
-    mu_stream_printf (stream, "%s <%s>;\n",
-                     param->ident,
-                     gettext (param->argname));
-  else if (MU_CFG_IS_LIST (param->type))
-    mu_stream_printf (stream, "%s <%s: list of %s>;\n",
-                     param->ident,
-                     gettext (param->argname ?
-                              param->argname : N_("arg")),
-       gettext (mu_cfg_data_type_string (MU_CFG_TYPE (param->type))));
-  else
-    mu_stream_printf (stream, "%s <%s: %s>;\n",
-                     param->ident,
-                     gettext (param->argname ?
-                              param->argname : N_("arg")),
-                     gettext (mu_cfg_data_type_string (param->type)));
-}
-
-static void format_container (mu_stream_t stream, struct mu_cfg_cont *cont,
-                             int level);
-
-static int
-_f_helper (void *item, void *data)
-{
-  struct tree_print *tp = data;
-  struct mu_cfg_cont *cont = item;
-  format_container (tp->stream, cont, tp->level);
-  return 0;
-}
-  
-static void
-format_section (mu_stream_t stream, struct mu_cfg_section *sect, int level)
-{
-  struct tree_print c;
-  if (sect->docstring)
-    mu_cfg_format_docstring (stream, gettext (sect->docstring), level);
-  format_level (stream, level);
-  if (sect->ident)
-    {
-      mu_stream_write (stream, sect->ident, strlen (sect->ident), NULL);
-      if (sect->label)
-       {
-         mu_stream_write (stream, " ", 1, NULL);
-         mu_stream_write (stream, sect->label, strlen (sect->label), NULL);
-       }
-      mu_stream_write (stream, " {\n", 3, NULL);
-      c.stream = stream;
-      c.level = level + 1; 
-      mu_list_do (sect->children, _f_helper, &c);
-      format_level (stream, level);
-      mu_stream_write (stream, "};\n\n", 4, NULL);
-    }
-  else
-    {
-      c.stream = stream;
-      c.level = level; 
-      mu_list_do (sect->children, _f_helper, &c);
-    }
-}
-
-static void
-format_container (mu_stream_t stream, struct mu_cfg_cont *cont, int level)
-{
-  switch (cont->type)
-    {
-    case mu_cfg_cont_section:
-      format_section (stream, &cont->v.section, level);
-      break;
-
-    case mu_cfg_cont_param:
-      format_param (stream, &cont->v.param, level);
-      break;
-    }
-}
-
-void
-mu_cfg_format_container (mu_stream_t stream, struct mu_cfg_cont *cont)
-{
-  format_container (stream, cont, 0);
-}
diff --git a/libmailutils/cfg_lexer.l b/libmailutils/cfg_lexer.l
deleted file mode 100644
index 998d84d..0000000
--- a/libmailutils/cfg_lexer.l
+++ /dev/null
@@ -1,405 +0,0 @@
-%top {
-/* cfg_lexer.l -- default lexer for Mailutils configuration files
-   Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
-
-   GNU Mailutils is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 3, or (at
-   your option) any later version.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-}
-
-%{
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <mailutils/cctype.h>
-#include <mailutils/errno.h>
-#include <mailutils/error.h>
-#include <mailutils/debug.h>  
-#include <mailutils/argcv.h>
-#include <mailutils/alloc.h>  
-#include <mailutils/nls.h>
-#include <mailutils/cfg.h>
-#include <mailutils/list.h>
-#include <mailutils/mutil.h>
-  
-#include "cfg_parser.h"
-
-void _mu_line_begin (void);
-void _mu_line_add (char *text, size_t len);
-char *_mu_line_finish (void);
-
-extern void mu_cfg_set_debug (void);
-static void
-mu_cfg_set_lex_debug (void)
-{
-  yy_flex_debug = mu_debug_check_level (mu_cfg_get_debug (),
-                                       MU_DEBUG_TRACE2);
-}
- 
-static void _mu_line_add_unescape_last (char *text, size_t len);
-static void multiline_begin (char *p);
-static char *multiline_strip_tabs (char *text);
-static void multiline_add (char *s);
-static char *multiline_finish (void);
- 
-static char *multiline_delimiter;
-static size_t multiline_delimiter_len;
-static int multiline_unescape;         /* Unescape here-document contents */
-static int (*char_to_strip)(char);     /* Strip matching characters of each
-                                         here-document line */
-static int isemptystr(int off);
-
-static mu_opool_t pool;
-
-%}
-
-%x COMMENT ML STR
-
-WS [ \t\f][ \t\f]*
-ID [a-zA-Z_][a-zA-Z_0-9-]+
-P [1-9][0-9]*
-
-%%
-         /* C-style comments */
-"/*"         BEGIN(COMMENT);
-<COMMENT>[^*\n]*        /* eat anything that's not a '*' */
-<COMMENT>"*"+[^*/\n]*   /* eat up '*'s not followed by '/'s */
-<COMMENT>\n             ++mu_cfg_locus.line;
-<COMMENT>"*"+"/"        BEGIN (INITIAL);
-         /* End-of-line comments */
-#debug=.*\n {
-          mu_log_level_t lev;
-          mu_debug_t dbg = mu_cfg_get_debug ();
-          if (mu_debug_level_from_string (yytext + 7, &lev, dbg) == 0)
-            {
-             mu_debug_set_level (dbg, lev);
-             mu_cfg_set_debug ();
-             mu_cfg_set_lex_debug ();
-           }
-          }
-#.*\n     { mu_cfg_locus.line++; }
-#.*     /* end-of-file comment */;
-"//".*\n  { mu_cfg_locus.line++; }
-"//".*    /* end-of-file comment */;
-        /* Identifiers */
-<INITIAL>{ID}         {
-                        _mu_line_begin ();
-                       _mu_line_add (yytext, yyleng);
-                       yylval.string = _mu_line_finish ();
-                       return MU_TOK_IDENT; }
-         /* Strings */
-[a-zA-Z0-9_\./:\*=-]+ { _mu_line_begin ();
-                        _mu_line_add (yytext, yyleng);
-                        yylval.string = _mu_line_finish ();
-                        return MU_TOK_STRING; }
-         /* Quoted strings */
-\"[^\\"\n]*\"         { _mu_line_begin ();
-                        _mu_line_add (yytext + 1, yyleng - 2);
-                        yylval.string = _mu_line_finish ();
-                        return MU_TOK_QSTRING; }
-\"[^\\"\n]*\\. |
-\"[^\\"\n]*\\\n        { BEGIN (STR);
-                        _mu_line_begin ();
-                       _mu_line_add_unescape_last (yytext + 1, yyleng - 1); }
-<STR>[^\\"\n]*\\. |
-<STR>\"[^\\"\n]*\\\n  { _mu_line_add_unescape_last (yytext, yyleng); }
-<STR>[^\\"\n]*\"      { BEGIN (INITIAL);
-                        if (yyleng > 1) 
-                          _mu_line_add (yytext, yyleng - 1); 
-                        yylval.string = _mu_line_finish ();
-                       return MU_TOK_QSTRING; }
-         /* Multiline strings */
-"<<"(-" "?)?\\?{ID}[ \t]*#.*\n |
-"<<"(-" "?)?\\?{ID}[ \t]*"//".*\n |
-"<<"(-" "?)?\\?{ID}[ \t]*\n |
-"<<"(-" "?)?\"{ID}\"[ \t]*#.*\n |
-"<<"(-" "?)?\"{ID}\"[ \t]*"//".*\n |
-"<<"(-" "?)?\"{ID}\"[ \t]*\n {
-                        BEGIN (ML);
-                       multiline_begin (yytext+2);
-                       mu_cfg_locus.line++;
-                 }
-<ML>.*\n { char *p = multiline_strip_tabs (yytext);
-          
-           if (!strncmp (p, multiline_delimiter, multiline_delimiter_len)
-              && isemptystr (p + multiline_delimiter_len - yytext))
-            {
-              free (multiline_delimiter);
-              multiline_delimiter = NULL;
-              BEGIN (INITIAL);
-              yylval.string = multiline_finish ();
-              return MU_TOK_MSTRING;
-            }
-           mu_cfg_locus.line++;
-          multiline_add (p); } 
-{WS}     ;
-         /* Other tokens */
-\n       { mu_cfg_locus.line++; } 
-[,;{}()] return yytext[0];
-.        { if (mu_isprint (yytext[0]))
-              mu_cfg_parse_error (_("stray character %c"), yytext[0]);
-           else 
-              mu_cfg_parse_error (_("stray character \\%03o"),
-                                 (unsigned char) yytext[0]);
-         }
-%%
-
-int
-yywrap ()
-{
-  return 1;
-}
-
-static void
-unescape_to_line (int c)
-{
-  if (c != '\n')
-    {
-      char t = mu_argcv_unquote_char (c);
-      if (t == c && t != '\\' && t != '\"')
-       mu_cfg_parse_error (_("unknown escape sequence '\\%c'"), c);
-      mu_opool_append_char (pool, t);
-    }
-}
-
-void
-_mu_line_add (char *text, size_t len)
-{
-  mu_opool_append (pool, text, len);
-}
-
-void
-_mu_line_add_unescape_last (char *text, size_t len)
-{
-  mu_opool_append (pool, text, len - 2);
-  unescape_to_line (text[len - 1]);
-}
-
-void
-_mu_line_begin ()
-{
-  if (!pool)
-    mu_opool_create (&pool, 1);
-  else
-    mu_opool_clear (pool);
-}
-
-char *
-_mu_line_finish ()
-{
-  mu_opool_append_char (pool, 0);
-  return mu_opool_finish (pool, NULL);
-}
-
-
-
-static int
-is_tab (char c)
-{
-    return c == '\t';
-}
- 
-static int
-is_ws (char c)
-{
-    return c == '\t' || c == ' ';
-}
-
-static int
-isemptystr (int off)
-{
-  for (; yytext[off] && mu_isspace (yytext[off]); off++)
-    ;
-  if (yytext[off] == ';')
-    {
-      int i;
-      for (i = off + 1; yytext[i]; i++) 
-       if (!mu_isspace (yytext[i]))
-         return 0;
-      yyless (off);
-      return 1;
-    }
-  return yytext[off] == 0;
-}
-
-static void
-multiline_begin (char *p)
-{
-  if (*p == '-')
-    {
-      if (*++p == ' ')
-       {
-         char_to_strip = is_ws;
-         p++;
-       }
-      else
-       char_to_strip = is_tab;
-    }
-  else
-    char_to_strip = NULL;
-  if (*p == '\\')
-    {
-      p++;
-      multiline_unescape = 0;
-    }
-  else if (*p == '"')
-    {
-      char *q;
-      
-      p++;
-      multiline_unescape = 0;
-      q = strchr (p, '"');
-      multiline_delimiter_len = q - p;
-    }
-  else
-    {
-       multiline_delimiter_len = strcspn (p, " \t");
-       multiline_unescape = 1;
-    }
-
-  /* Remove trailing newline */
-  multiline_delimiter_len--;
-  multiline_delimiter = mu_alloc (multiline_delimiter_len + 1);
-  memcpy (multiline_delimiter, p, multiline_delimiter_len);
-  multiline_delimiter[multiline_delimiter_len] = 0;
-  _mu_line_begin ();
-}
-
-static char *
-multiline_strip_tabs (char *text)
-{
-  if (char_to_strip)
-    for (; *text && char_to_strip (*text); text++)
-      ;
-  return text;
-}
-
-static void
-multiline_add (char *s)
-{
-  if (multiline_unescape)
-    {
-      for (; *s; s++)
-       {
-         if (*s == '\\')
-           {
-             unescape_to_line (s[1]);
-             ++s;
-           }
-         else
-           _mu_line_add (s, 1);
-       }
-    }
-  else
-    _mu_line_add (s, strlen (s));
-}
-
-static char *
-multiline_finish ()
-{
-  return _mu_line_finish ();
-}
-
-
-int
-mu_cfg_parse_file (mu_cfg_tree_t **return_tree, const char *file, int flags)
-{
-  struct stat st;
-  FILE *fp;
-  int rc;
-  char *full_name = mu_tilde_expansion (file, "/", NULL);
-
-  if (stat (full_name, &st))
-    {
-      if (errno != ENOENT)
-       mu_error (_("cannot stat `%s': %s"), full_name, mu_strerror (errno));
-      free (full_name);
-      return ENOENT;
-    }
-  else if (!S_ISREG (st.st_mode))
-    {
-      if (flags & MU_PARSE_CONFIG_VERBOSE)
-       mu_diag_output (MU_DIAG_INFO, _("%s: not a regular file"), full_name);
-      free (full_name);
-      return ENOENT;
-    } 
-      
-  fp = fopen (full_name, "r");
-  if (!fp)
-    {
-      mu_error (_("cannot open config file `%s': %s"), full_name,
-               mu_strerror (errno));
-      free (full_name);
-      return errno;
-    }
-
-  if (flags & MU_PARSE_CONFIG_VERBOSE)
-    mu_diag_output (MU_DIAG_INFO, _("parsing file `%s'"), full_name);
-
-  mu_cfg_set_lex_debug ();
-
-  /* Initialize locus: */
-  /* 1. Save file name in the lexer object pool and point `file' member
-     to this copy. Free full_name: it is not used after that. */
-  _mu_line_begin ();
-  _mu_line_add (full_name, strlen (full_name));
-  mu_cfg_locus.file = _mu_line_finish ();
-  free (full_name); 
-  /* 2. Initialize line number */
-  mu_cfg_locus.line = 1;
-  
-  /* Parse configuration */
-  yyrestart (fp);
-  rc = mu_cfg_parse (return_tree);
-  fclose (fp);
-  if (flags & MU_PARSE_CONFIG_VERBOSE)
-    mu_diag_output (MU_DIAG_INFO, _("finished parsing file `%s'"),
-                   mu_cfg_locus.file);
-
-  return rc == 0 ? 0 : MU_ERR_FAILURE;
-}
-
-/* FIXME: Deprecated interface */
-int
-mu_get_config (const char *file, const char *progname,
-               struct mu_cfg_param *progparam, int flags, void *target_ptr)
-{
-  mu_cfg_tree_t *parse_tree;
-  int rc = mu_cfg_parse_file (&parse_tree, file, flags);
-  if (rc == 0)
-    {
-      rc = mu_cfg_tree_postprocess (parse_tree, flags);
-      if (rc == 0)
-       rc = mu_cfg_tree_reduce (parse_tree, progname, progparam, flags,
-                                target_ptr);
-      mu_cfg_destroy_tree (&parse_tree);
-    }
-
-  return rc == 0 ? 0 : MU_ERR_FAILURE;
-}
-
-
-mu_opool_t 
-mu_cfg_lexer_pool ()
-{
-  mu_opool_t p = pool;
-  pool = NULL;
-  return p;
-}
diff --git a/libmailutils/cfg_parser.y b/libmailutils/cfg_parser.y
deleted file mode 100644
index f6a5397..0000000
--- a/libmailutils/cfg_parser.y
+++ /dev/null
@@ -1,1839 +0,0 @@
-%{
-/* cfg_parser.y -- general-purpose configuration file parser
-   Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
-
-   GNU Mailutils is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 3, or (at
-   your option) any later version.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <netdb.h>
-#include "intprops.h"
-#include <mailutils/argcv.h>
-#include <mailutils/nls.h>
-#include <mailutils/cfg.h>
-#include <mailutils/alloc.h>
-#include <mailutils/errno.h>
-#include <mailutils/error.h>
-#include <mailutils/list.h>
-#include <mailutils/iterator.h>
-#include <mailutils/debug.h>
-#include <mailutils/mutil.h>
-#include <mailutils/cctype.h>
-
-int mu_cfg_parser_verbose;
-static mu_list_t /* of mu_cfg_node_t */ parse_node_list; 
-mu_cfg_locus_t mu_cfg_locus;
-size_t mu_cfg_error_count;
-
-static int _mu_cfg_errcnt;
-static mu_debug_t _mu_cfg_debug;
-
-int yylex ();
-
-void _mu_line_begin (void);
-void _mu_line_add (char *text, size_t len);
-char *_mu_line_finish (void);
-
-static int
-yyerror (char *s)
-{
-  mu_cfg_parse_error ("%s", s);
-  return 0;
-}
-
-static mu_config_value_t *
-config_value_dup (mu_config_value_t *src)
-{
-  if (!src)
-    return NULL;
-  else
-    {
-      /* FIXME: Use mu_opool_alloc */
-      mu_config_value_t *val = mu_alloc (sizeof (*val));
-      *val = *src;
-      return val;
-    }
-}
-
-static mu_cfg_node_t *
-mu_cfg_alloc_node (enum mu_cfg_node_type type, mu_cfg_locus_t *loc,
-                  const char *tag, mu_config_value_t *label,
-                  mu_list_t nodelist)
-{
-  char *p;
-  mu_cfg_node_t *np;
-  size_t size = sizeof *np + strlen (tag) + 1;
-  np = mu_alloc (size);
-  np->type = type;
-  np->locus = *loc;
-  p = (char*) (np + 1);
-  np->tag = p;
-  strcpy (p, tag);
-  np->label = label;
-  np->nodes = nodelist;
-  return np;
-}
-
-void
-mu_cfg_free_node (mu_cfg_node_t *node)
-{
-  free (node->label);
-  free (node);
-}
-
-void
-mu_cfg_format_error (mu_debug_t debug, size_t level, const char *fmt, ...)
-{
-  va_list ap;
-
-  if (!debug)
-    mu_diag_get_debug (&debug);
-  va_start (ap, fmt);
-  mu_debug_vprintf (debug, 0, fmt, ap);
-  mu_debug_printf (debug, 0, "\n");
-  va_end (ap);
-  if (level <= MU_DEBUG_ERROR)
-    mu_cfg_error_count++;
-}
-
-static void
-_mu_cfg_debug_set_locus (mu_debug_t debug, const mu_cfg_locus_t *loc)
-{
-  mu_debug_set_locus (debug, loc->file ? loc->file : _("unknown file"),
-                     loc->line);
-}
-
-void
-mu_cfg_vperror (mu_debug_t debug, const mu_cfg_locus_t *loc,
-                const char *fmt, va_list ap)
-{
-  if (!debug)
-    mu_diag_get_debug (&debug);
-  _mu_cfg_debug_set_locus (debug, loc);
-  mu_debug_vprintf (debug, 0, fmt, ap);
-  mu_debug_printf (debug, 0, "\n");
-  mu_debug_set_locus (debug, NULL, 0);
-  mu_cfg_error_count++;
-}
-
-void
-mu_cfg_perror (mu_debug_t debug, const mu_cfg_locus_t *loc,
-              const char *fmt, ...)
-{
-  va_list ap;
-
-  va_start (ap, fmt);
-  mu_cfg_vperror (debug, loc, fmt, ap);
-  va_end (ap);
-}
-
-void
-mu_cfg_parse_error (const char *fmt, ...)
-{
-  va_list ap;
-
-  va_start (ap, fmt);
-  mu_cfg_vperror (_mu_cfg_debug, &mu_cfg_locus, fmt, ap);
-  va_end (ap);
-}
-
-#define node_type_str(t) (((t) == mu_cfg_node_statement) ? "stmt" : "param")
-
-static void
-debug_print_node (mu_cfg_node_t *node)
-{
-  if (mu_debug_check_level (_mu_cfg_debug, MU_DEBUG_TRACE0))
-    {
-      mu_debug_set_locus (_mu_cfg_debug,
-                         node->locus.file, node->locus.line);
-      if (node->type == mu_cfg_node_undefined)
-       /* Stay on the safe side */
-       mu_cfg_format_error (_mu_cfg_debug, MU_DEBUG_ERROR,
-                            "unknown statement type!");
-      else
-       /* FIXME: How to print label? */
-       mu_cfg_format_error (_mu_cfg_debug, MU_DEBUG_TRACE0,
-                            "statement: %s, id: %s",
-                            node_type_str (node->type),
-                            node->tag ? node->tag : "(null)");
-
-      mu_debug_set_locus (_mu_cfg_debug, NULL, 0);
-    }
-}
-
-static void
-free_node_item (void *item)
-{
-  mu_cfg_node_t *node = item;
-
-  switch (node->type)
-    {
-    case mu_cfg_node_statement:
-      mu_list_destroy (&node->nodes);
-      break;
-      
-    case mu_cfg_node_undefined: /* hmm... */
-    case mu_cfg_node_param:
-      break;
-    }
-  mu_cfg_free_node (node);
-}
-
-int
-mu_cfg_create_node_list (mu_list_t *plist)
-{
-  int rc;
-  mu_list_t list;
-
-  rc = mu_list_create (&list);
-  if (rc)
-    return rc;
-  mu_list_set_destroy_item (list, free_node_item);
-  *plist = list;
-  return 0;
-}
-
-%}
-
-%union {
-  mu_cfg_node_t node;
-  mu_cfg_node_t *pnode;
-  mu_list_t /* of mu_cfg_node_t */ nodelist;
-  char *string;
-  mu_config_value_t value, *pvalue;
-  mu_list_t list;
-  struct { const char *name; mu_cfg_locus_t locus; } ident;
-}
-
-%token <string> MU_TOK_IDENT MU_TOK_STRING MU_TOK_QSTRING MU_TOK_MSTRING
-%type <string> string slist
-%type <list> slist0
-%type <value> value
-%type <pvalue> tag vallist
-%type <list> values list vlist
-%type <ident> ident
-%type <nodelist> stmtlist
-%type <pnode> stmt simple block
-
-%%
-
-input   : stmtlist
-         {
-           parse_node_list = $1;
-         }
-       ;
-
-stmtlist: stmt
-         {
-           mu_cfg_create_node_list (&$$);
-           mu_list_append ($$, $1);
-         }
-       | stmtlist stmt
-         {
-           mu_list_append ($1, $2);
-           $$ = $1;
-           debug_print_node ($2);
-         }
-       ;
-
-stmt    : simple
-       | block
-       ;
-
-simple  : ident vallist ';'
-         {
-           $$ = mu_cfg_alloc_node (mu_cfg_node_param, &$1.locus,
-                                   $1.name, $2,
-                                   NULL);
-         }
-       ;
-
-block   : ident tag '{' '}' opt_sc
-         {
-           $$ = mu_cfg_alloc_node (mu_cfg_node_statement, &$1.locus,
-                                   $1.name, $2,
-                                   NULL);
-
-         }
-       | ident tag '{' stmtlist '}' opt_sc
-         {
-           $$ = mu_cfg_alloc_node (mu_cfg_node_statement, &$1.locus,
-                                   $1.name, $2, $4);
-
-         }
-       ;
-
-ident   : MU_TOK_IDENT
-         {
-           $$.name = $1;
-           $$.locus = mu_cfg_locus;
-         }
-       ;
-
-tag     : /* empty */
-         {
-           $$ = NULL;
-         }
-       | vallist
-       ;
-
-vallist : vlist
-         {
-           size_t n = 0;
-           mu_list_count($1, &n);
-           if (n == 1)
-             {
-               mu_list_get ($1, 0, (void**) &$$);
-             }
-           else
-             {
-               size_t i;
-               mu_config_value_t val;
-
-               val.type = MU_CFG_ARRAY;
-               val.v.arg.c = n;
-               /* FIXME: Use mu_opool_alloc */
-               val.v.arg.v = mu_alloc (n * sizeof (val.v.arg.v[0]));
-               if (!val.v.arg.v)
-                 {
-                   mu_cfg_parse_error (_("not enough memory"));
-                   abort();
-                 }
-
-               for (i = 0; i < n; i++)
-                 {
-                   mu_config_value_t *v;
-                   mu_list_get ($1, i, (void **) &v);
-                   val.v.arg.v[i] = *v;
-                 }
-               $$ = config_value_dup (&val);
-             }
-           mu_list_destroy (&$1);
-         }
-       ;
-
-vlist   : value
-           {
-             int rc = mu_list_create (&$$);
-             if (rc)
-               {
-                 mu_cfg_parse_error (_("cannot create list: %s"),
-                                     mu_strerror (rc));
-                 abort ();
-               }
-             mu_list_append ($$, config_value_dup (&$1)); /* FIXME */
-         }
-       | vlist value
-         {
-           mu_list_append ($1, config_value_dup (&$2));
-         }
-       ;
-
-value   : string
-         {
-             $$.type = MU_CFG_STRING;
-             $$.v.string = $1;
-         }
-       | list
-         {
-             $$.type = MU_CFG_LIST;
-             $$.v.list = $1;
-         }
-       | MU_TOK_MSTRING
-         {
-             $$.type = MU_CFG_STRING;
-             $$.v.string = $1;
-         }
-       ;
-
-string  : MU_TOK_STRING
-       | MU_TOK_IDENT
-       | slist
-       ;
-
-slist   : slist0
-         {
-           mu_iterator_t itr;
-           mu_list_get_iterator ($1, &itr);
-
-           _mu_line_begin ();
-           for (mu_iterator_first (itr);
-                !mu_iterator_is_done (itr); mu_iterator_next (itr))
-             {
-               char *p;
-               mu_iterator_current (itr, (void**)&p);
-               _mu_line_add (p, strlen (p));
-             }
-           $$ = _mu_line_finish ();
-           mu_iterator_destroy (&itr);
-           mu_list_destroy(&$1);
-         }
-       ;
-
-slist0  : MU_TOK_QSTRING
-         {
-           mu_list_create (&$$);
-           mu_list_append ($$, $1);
-         }
-       | slist0 MU_TOK_QSTRING
-         {
-           mu_list_append ($1, $2);
-           $$ = $1;
-         }
-       ;
-
-list    : '(' values ')'
-         {
-             $$ = $2;
-         }
-       | '(' values ',' ')'
-         {
-             $$ = $2;
-         }
-       ;
-
-values  : value
-         {
-           mu_list_create (&$$);
-           mu_list_append ($$, config_value_dup (&$1));
-         }
-       | values ',' value
-         {
-           mu_list_append ($1, config_value_dup (&$3));
-           $$ = $1;
-         }
-       ;
-
-opt_sc  : /* empty */
-       | ';'
-       ;
-
-
-%%
-
-static int
-_cfg_default_printer (void *unused, mu_log_level_t level, const char *str)
-{
-  fprintf (stderr, "%s", str);
-  return 0;
-}
-
-mu_debug_t
-mu_cfg_get_debug ()
-{
-  if (!_mu_cfg_debug)
-    {
-      mu_debug_create (&_mu_cfg_debug, NULL);
-      mu_debug_set_print (_mu_cfg_debug, _cfg_default_printer, NULL);
-      mu_debug_set_level (_mu_cfg_debug, mu_global_debug_level ("config"));
-    }
-  return _mu_cfg_debug;
-}
-
-void
-mu_cfg_set_debug ()
-{
-  if (mu_debug_check_level (mu_cfg_get_debug (), MU_DEBUG_TRACE7))
-    yydebug = 1;
-}
-
-int
-mu_cfg_parse (mu_cfg_tree_t **ptree)
-{
-  int rc;
-  mu_cfg_tree_t *tree;
-  mu_opool_t pool;
-  
-  mu_cfg_set_debug ();
-  _mu_cfg_errcnt = 0;
-
-  rc = yyparse ();
-  pool = mu_cfg_lexer_pool ();
-  if (rc == 0 && _mu_cfg_errcnt)
-    {
-      mu_opool_destroy (&pool);
-      rc = 1;
-    }
-  else
-    {
-      tree = mu_alloc (sizeof (*tree));
-      tree->debug = _mu_cfg_debug;
-      _mu_cfg_debug = NULL;
-      tree->nodes = parse_node_list;
-      tree->pool = pool;
-      parse_node_list = NULL;
-      *ptree = tree;
-    }
-  return rc;
-}
-
-int
-mu_cfg_tree_union (mu_cfg_tree_t **pa, mu_cfg_tree_t **pb)
-{
-  mu_cfg_tree_t *a, *b;
-  int rc;
-  
-  if (!pb)
-    return EINVAL;
-  if (!*pb)
-    return 0;
-  b = *pb;
-  if (!pa)
-    return EINVAL;
-  if (!*pa)
-    {
-      *pa = b;
-      *pb = NULL;
-      return 0;
-    }
-  else
-    a = *pa;
-  
-  /* Merge opools */
-  rc = mu_opool_union (&b->pool, &a->pool);
-  if (rc)
-    return rc;
-    
-  /* Link node lists */
-  if (b->nodes)
-    {
-      mu_list_append_list (a->nodes, b->nodes);
-      mu_list_destroy (&b->nodes);
-    }
-  
-  mu_debug_destroy (&b->debug, mu_debug_get_owner (b->debug));
-  free (b);
-  *pb = NULL;
-  return 0;
-}
-
-static mu_cfg_tree_t *
-do_include (const char *name, int flags, mu_cfg_locus_t *loc)
-{
-  struct stat sb;
-  char *tmpname = NULL;
-  mu_cfg_tree_t *tree = NULL;
-  
-  if (name[0] != '/')
-    {
-      name = tmpname = mu_make_file_name (SYSCONFDIR, name);
-      if (!name)
-        {
-          mu_error ("%s", mu_strerror (errno));
-          return NULL;
-        }
-    }
-  if (stat (name, &sb) == 0)
-    {
-      int rc = 0;
-
-      if (S_ISDIR (sb.st_mode))
-       {
-         if (flags & MU_PARSE_CONFIG_GLOBAL)
-           {
-             char *file = mu_make_file_name (name, mu_program_name);
-             rc = mu_cfg_parse_file (&tree, file, flags);
-             free (file);
-           }
-       }
-      else
-       rc = mu_cfg_parse_file (&tree, name, flags);
-             
-      if (rc == 0 && tree)
-       mu_cfg_tree_postprocess (tree, flags & ~MU_PARSE_CONFIG_GLOBAL);
-    }
-  else if (errno == ENOENT)
-    mu_cfg_perror (tree->debug, loc,
-                  _("include file or directory does not exist"));
-  else
-    mu_cfg_perror (tree->debug, loc,
-                  _("cannot stat include file or directory: %s"),
-                  mu_strerror (errno));
-  free (tmpname);
-  return tree;
-}
-    
-int
-mu_cfg_tree_postprocess (mu_cfg_tree_t *tree, int flags)
-{
-  int rc;
-  mu_iterator_t itr;
-
-  if (!tree->nodes)
-    return 0;
-  rc = mu_list_get_iterator (tree->nodes, &itr);
-  if (rc)
-    return rc;
-  for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
-       mu_iterator_next (itr))
-    {
-      mu_cfg_node_t *node;
-
-      mu_iterator_current (itr, (void**) &node);
-
-      if (node->type == mu_cfg_node_statement)
-       {
-         if ((flags & MU_PARSE_CONFIG_GLOBAL) &&
-             strcmp (node->tag, "program") == 0)
-           {
-             if (node->label->type == MU_CFG_STRING)
-               {
-                 if (strcmp (node->label->v.string, mu_program_name) == 0)
-                   {
-                     /* Move all nodes from this block to the topmost
-                        level */
-                     mu_iterator_ctl (itr, mu_itrctl_insert_list,
-                                      node->nodes);
-                     mu_iterator_ctl (itr, mu_itrctl_delete, NULL);
-                     /*FIXME:mu_cfg_free_node (node);*/
-                   }
-               }
-             else
-               {
-                 mu_cfg_perror (tree->debug, &node->locus,
-                                _("argument to `program' is not a string"));
-                 mu_iterator_ctl (itr, mu_itrctl_delete, NULL);
-               }
-           }
-       }
-      else if (node->type == mu_cfg_node_param &&
-              strcmp (node->tag, "include") == 0)
-       {
-         if (node->label->type == MU_CFG_STRING)
-           {
-             mu_cfg_tree_t *t = do_include (node->label->v.string, flags,
-                                            &node->locus);
-             if (t)
-               {
-                 /* Merge the new tree into the current point and
-                    destroy the rest of it */
-                 mu_iterator_ctl (itr, mu_itrctl_insert_list, t->nodes);
-                 mu_opool_union (&tree->pool, &t->pool);
-                 mu_cfg_destroy_tree (&t);
-               }                     
-           }
-         else
-           mu_cfg_perror (tree->debug, &node->locus,
-                          _("argument to `include' is not a string"));
-         /* Remove node from the list */
-         mu_iterator_ctl (itr, mu_itrctl_delete, NULL);
-       }
-    }
-  return 0;
-}
-
-static int
-_mu_cfg_preorder_recursive (void *item, void *cbdata)
-{
-  mu_cfg_node_t *node = item;
-  struct mu_cfg_iter_closure *clos = cbdata;
-
-  switch (node->type)
-    {
-    case mu_cfg_node_undefined:
-      abort ();
-
-    case mu_cfg_node_statement:
-      switch (clos->beg (node, clos->data))
-       {
-       case MU_CFG_ITER_OK:
-         if (mu_cfg_preorder (node->nodes, clos))
-           return 1;
-         if (clos->end && clos->end (node, clos->data) == MU_CFG_ITER_STOP)
-           return 1;
-         break;
-
-       case MU_CFG_ITER_SKIP:
-         break;
-
-       case MU_CFG_ITER_STOP:
-         return 1;
-       }
-      break;
-
-    case mu_cfg_node_param:
-      return clos->beg (node, clos->data) == MU_CFG_ITER_STOP;
-    }
-  return 0;
-}
-
-int
-mu_cfg_preorder (mu_list_t nodelist, struct mu_cfg_iter_closure *clos)
-{
-  return mu_list_do (nodelist, _mu_cfg_preorder_recursive, clos);
-}
-
-
-
-void
-mu_cfg_destroy_tree (mu_cfg_tree_t **ptree)
-{
-  if (ptree && *ptree)
-    {
-      mu_cfg_tree_t *tree = *ptree;
-      mu_list_destroy (&tree->nodes);
-      mu_opool_destroy (&tree->pool);
-      *ptree = NULL;
-    }
-}
-
-
-
-struct mu_cfg_section_list
-{
-  struct mu_cfg_section_list *next;
-  struct mu_cfg_section *sec;
-};
-
-struct scan_tree_data
-{
-  struct mu_cfg_section_list *list;
-  void *target;
-  void *call_data;
-  mu_cfg_tree_t *tree;
-  int error;
-};
-
-static struct mu_cfg_cont *
-find_container (mu_list_t list, enum mu_cfg_cont_type type,
-               const char *ident, size_t len)
-{
-  mu_iterator_t iter;
-  struct mu_cfg_cont *ret = NULL;
-
-  if (len == 0)
-    len = strlen (ident);
-
-  mu_list_get_iterator (list, &iter);
-  for (mu_iterator_first (iter); !mu_iterator_is_done (iter);
-       mu_iterator_next (iter))
-    {
-      struct mu_cfg_cont *cont;
-      mu_iterator_current (iter, (void**) &cont);
-
-      if (cont->type == type
-         && strlen (cont->v.ident) == len
-         && memcmp (cont->v.ident, ident, len) == 0)
-       {
-         ret = cont;
-         break;
-       }
-    }
-  mu_iterator_destroy (&iter);
-  return ret;
-}
-
-static struct mu_cfg_section *
-find_subsection (struct mu_cfg_section *sec, const char *ident, size_t len)
-{
-  if (sec)
-    {
-      if (sec->children)
-       {
-         struct mu_cfg_cont *cont = find_container (sec->children,
-                                                    mu_cfg_cont_section,
-                                                    ident, len);
-         if (cont)
-           return &cont->v.section;
-       }
-    }
-  return NULL;
-}
-
-static struct mu_cfg_param *
-find_param (struct mu_cfg_section *sec, const char *ident, size_t len)
-{
-  if (sec)
-    {
-      if (sec->children)
-       {
-         struct mu_cfg_cont *cont = find_container (sec->children,
-                                                    mu_cfg_cont_param,
-                                                    ident, len);
-         if (cont)
-           return &cont->v.param;
-       }
-    }
-  return NULL;
-}
-
-static int
-push_section (struct scan_tree_data *dat, struct mu_cfg_section *sec)
-{
-  struct mu_cfg_section_list *p = mu_alloc (sizeof *p);
-  if (!p)
-    {
-      mu_cfg_perror (dat->tree->debug, NULL, _("not enough memory"));
-      return 1;
-    }
-  p->sec = sec;
-  p->next = dat->list;
-  dat->list = p;
-  return 0;
-}
-
-static struct mu_cfg_section *
-pop_section (struct scan_tree_data *dat)
-{
-  struct mu_cfg_section_list *p = dat->list;
-  struct mu_cfg_section *sec = p->sec;
-  dat->list = p->next;
-  free (p);
-  return sec;
-}
-
-#define STRTONUM(s, type, base, res, limit, d, loc)                    \
-  {                                                                    \
-    type sum = 0;                                                      \
-                                                                       \
-    for (; *s; s++)                                                    \
-      {                                                                        
\
-       type x;                                                         \
-                                                                       \
-       if ('0' <= *s && *s <= '9')                                     \
-         x = sum * base + *s - '0';                                    \
-       else if (base == 16 && 'a' <= *s && *s <= 'f')                  \
-         x = sum * base + *s - 'a';                                    \
-       else if (base == 16 && 'A' <= *s && *s <= 'F')                  \
-         x = sum * base + *s - 'A';                                    \
-       else                                                            \
-         break;                                                        \
-       if (x <= sum)                                                   \
-         {                                                             \
-           mu_cfg_perror (d, loc, _("numeric overflow"));              \
-           return 1;                                                   \
-         }                                                             \
-       else if (limit && x > limit)                                    \
-         {                                                             \
-           mu_cfg_perror (d, loc,                                      \
-                           _("value out of allowed range"));           \
-           return 1;                                                   \
-         }                                                             \
-       sum = x;                                                        \
-      }                                                                        
\
-    res = sum;                                                         \
-  }
-
-#define STRxTONUM(s, type, res, limit, d, loc)                         \
-  {                                                                    \
-    int base;                                                          \
-    if (*s == '0')                                                     \
-      {                                                                        
\
-       s++;                                                            \
-       if (*s == 0)                                                    \
-         base = 10;                                                    \
-       else if (*s == 'x' || *s == 'X')                                \
-         {                                                             \
-           s++;                                                        \
-           base = 16;                                                  \
-         }                                                             \
-       else                                                            \
-         base = 8;                                                     \
-      } else                                                           \
-      base = 10;                                                       \
-    STRTONUM (s, type, base, res, limit, d, loc);                      \
-  }
-
-#define GETUNUM(str, type, res, d, loc)                                        
\
-  {                                                                    \
-    type tmpres;                                                       \
-    const char *s = str;                                               \
-    STRxTONUM (s, type, tmpres, 0, d, loc);                            \
-    if (*s)                                                            \
-      {                                                                        
\
-       mu_cfg_perror (d, loc,                                          \
-                      _("not a number (stopped near `%s')"),           \
-                      s);                                              \
-       return 1;                                                       \
-      }                                                                        
\
-    res = tmpres;                                                      \
-  }
-
-#define GETSNUM(str, type, res, d, loc)                                        
\
-  {                                                                    \
-    unsigned type tmpres;                                              \
-    const char *s = str;                                               \
-    int sign;                                                          \
-    unsigned type limit;                                               \
-                                                                       \
-    if (*s == '-')                                                     \
-      {                                                                        
\
-       sign++;                                                         \
-       s++;                                                            \
-       limit = TYPE_MINIMUM (type);                                    \
-       limit = - limit;                                                \
-      }                                                                        
\
-    else                                                               \
-      {                                                                        
\
-       sign = 0;                                                       \
-       limit = TYPE_MAXIMUM (type);                                    \
-      }                                                                        
\
-                                                                       \
-    STRxTONUM (s, unsigned type, tmpres, limit, d, loc);               \
-    if (*s)                                                            \
-      {                                                                        
\
-       mu_cfg_perror (d, loc,                                          \
-                      _("not a number (stopped near `%s')"),           \
-                      s);                                              \
-       return 1;                                                       \
-      }                                                                        
\
-    res = sign ? - tmpres : tmpres;                                    \
-  }
-
-static int
-parse_ipv4 (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus,
-           const char *str, struct in_addr *res)
-{
-  struct in_addr addr;
-  if (inet_aton (str, &addr) == 0)
-    {
-      mu_cfg_perror (sdata->tree->debug, locus, _("not an IPv4"));
-      return 1;
-    }
-  addr.s_addr = ntohl (addr.s_addr);
-  *res = addr;
-  return 0;
-}
-
-static int
-parse_host (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus,
-           const char *str, struct in_addr *res)
-{
-  struct in_addr addr;
-  struct hostent *hp = gethostbyname (str);
-  if (hp)
-    {
-      addr.s_addr = *(unsigned long *)hp->h_addr;
-    }
-  else if (inet_aton (str, &addr) == 0)
-    {
-      mu_cfg_perror (sdata->tree->debug, locus,
-                    _("cannot resolve hostname `%s'"),
-                    str);
-      return 1;
-    }
-  addr.s_addr = ntohl (addr.s_addr);
-  *res = addr;
-  return 0;
-}
-
-static int
-parse_cidr (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus,
-           const char *str, mu_cfg_cidr_t *res)
-{
-  struct in_addr addr;
-  unsigned long mask;
-  char astr[16];
-  const char *p, *s;
-
-  p = strchr (str, '/');
-  if (p)
-    {
-      int len = p - str;
-      if (len > sizeof astr - 1) {
-       mu_cfg_perror (sdata->tree->debug, locus,
-                      _("not a valid IPv4 address in CIDR"));
-       return 1;
-      }
-      memcpy (astr, str, len);
-      astr[len] = 0;
-      if (inet_aton (astr, &addr) == 0)
-       {
-         mu_cfg_perror (sdata->tree->debug, locus,
-                        _("not a valid IPv4 address in CIDR"));
-         return 1;
-       }
-      addr.s_addr = ntohl (addr.s_addr);
-
-      p++;
-      s = p;
-      STRxTONUM (s, unsigned long, mask, 0, sdata->tree->debug, locus);
-      if (*s == '.')
-       {
-         struct in_addr a;
-         if (inet_aton (p, &a) == 0)
-           {
-             mu_cfg_perror (sdata->tree->debug, locus,
-                            _("not a valid network in CIDR"));
-             return 1;
-           }
-         a.s_addr = ntohl (a.s_addr);
-         for (mask = 0; (a.s_addr & 1) == 0 && mask < 32; )
-           {
-             mask++;
-             a.s_addr >>= 1;
-           }
-         mask = 32 - mask;
-       }
-      else if (mask > 32)
-       {
-         mu_cfg_perror (sdata->tree->debug, locus,
-                        _("not a valid network mask in CIDR"));
-         return 1;
-       }
-    }
-  else
-    {
-      int i;
-      unsigned short x;
-      addr.s_addr = 0;
-
-      p = str;
-      for (i = 0; i < 3; i++)
-       {
-         STRxTONUM (p, unsigned short, x, 255, sdata->tree->debug, locus);
-         if (*p != '.')
-           break;
-         addr.s_addr = (addr.s_addr << 8) + x;
-       }
-
-      if (*p)
-       {
-         mu_cfg_perror (sdata->tree->debug, locus,
-                        _("not a CIDR (stopped near `%s')"),
-                        p);
-         return 1;
-       }
-
-      mask = i * 8;
-
-      addr.s_addr <<= (4 - i) * 8;
-    }
-
-  res->addr = addr;
-  res->mask = mask;
-  return 0;
-}
-
-int
-mu_cfg_parse_boolean (const char *str, int *res)
-{
-  if (strcmp (str, "yes") == 0
-      || strcmp (str, "on") == 0
-      || strcmp (str, "t") == 0
-      || strcmp (str, "true") == 0
-      || strcmp (str, "1") == 0)
-    *res = 1;
-  else if (strcmp (str, "no") == 0
-          || strcmp (str, "off") == 0
-          || strcmp (str, "nil") == 0
-          || strcmp (str, "false") == 0
-          || strcmp (str, "0") == 0)
-    *res = 0;
-  else
-    return 1;
-  return 0;
-}
-
-static int
-parse_bool (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus,
-           const char *str, int *res)
-{
-  if (mu_cfg_parse_boolean (str, res))
-    {
-      mu_cfg_perror (sdata->tree->debug, locus, _("not a boolean"));
-      return 1;
-    }
-  return 0;
-}
-
-static int
-valcvt (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus,
-       void *tgt,
-       enum mu_cfg_param_data_type type, mu_config_value_t *val)
-{
-  if (val->type != MU_CFG_STRING)
-    {
-      mu_cfg_perror (sdata->tree->debug, locus, _("expected string value"));
-      return 1;
-    }
-  switch (type)
-    {
-    case mu_cfg_string:
-      {
-       char *s = mu_strdup (val->v.string);
-       /* FIXME: free tgt? */
-       *(char**)tgt = s;
-       break;
-      }
-
-    case mu_cfg_short:
-      GETSNUM (val->v.string, short, *(short*)tgt, sdata->tree->debug, locus);
-      break;
-
-    case mu_cfg_ushort:
-      GETUNUM (val->v.string, unsigned short, *(unsigned short*)tgt,
-              sdata->tree->debug, locus);
-      break;
-
-    case mu_cfg_int:
-      GETSNUM (val->v.string, int, *(int*)tgt, sdata->tree->debug, locus);
-      break;
-
-    case mu_cfg_uint:
-      GETUNUM (val->v.string, unsigned int, *(unsigned int*)tgt,
-              sdata->tree->debug, locus);
-      break;
-
-    case mu_cfg_long:
-      GETSNUM (val->v.string, long, *(long*)tgt,
-              sdata->tree->debug, locus);
-      break;
-
-    case mu_cfg_ulong:
-      GETUNUM (val->v.string, unsigned long, *(unsigned long*)tgt,
-              sdata->tree->debug, locus);
-      break;
-
-    case mu_cfg_size:
-      GETUNUM (val->v.string, size_t, *(size_t*)tgt,
-              sdata->tree->debug, locus);
-      break;
-
-    case mu_cfg_off:
-      mu_cfg_perror (sdata->tree->debug, locus, _("not implemented yet"));
-      /* GETSNUM(node->tag_label, off_t, *(off_t*)tgt); */
-      return 1;
-
-    case mu_cfg_time:
-      GETUNUM (val->v.string, time_t, *(time_t*)tgt,
-              sdata->tree->debug, locus);
-      break;
-
-    case mu_cfg_bool:
-      if (parse_bool (sdata, locus, val->v.string, (int*) tgt))
-       return 1;
-      break;
-
-    case mu_cfg_ipv4:
-      if (parse_ipv4 (sdata, locus, val->v.string, (struct in_addr *)tgt))
-       return 1;
-      break;
-
-    case mu_cfg_cidr:
-      if (parse_cidr (sdata, locus, val->v.string, (mu_cfg_cidr_t *)tgt))
-       return 1;
-      break;
-
-    case mu_cfg_host:
-      if (parse_host (sdata, locus, val->v.string, (struct in_addr *)tgt))
-       return 1;
-      break;
-
-    default:
-      return 1;
-    }
-  return 0;
-}
-
-struct set_closure
-{
-  mu_list_t list;
-  enum mu_cfg_param_data_type type;
-  struct scan_tree_data *sdata;
-  const mu_cfg_locus_t *locus;
-};
-
-static size_t config_type_size[] = {
-  sizeof (char*),          /* mu_cfg_string */
-  sizeof (short),          /* mu_cfg_short */
-  sizeof (unsigned short), /* mu_cfg_ushort */
-  sizeof (int),            /* mu_cfg_int */
-  sizeof (unsigned),       /* mu_cfg_uint */
-  sizeof (long),           /* mu_cfg_long */
-  sizeof (unsigned long),  /* mu_cfg_ulong */
-  sizeof (size_t),         /* mu_cfg_size */
-  sizeof (mu_off_t),       /* mu_cfg_off */
-  sizeof (time_t),         /* mu_cfg_time */
-  sizeof (int),            /* mu_cfg_bool */
-  sizeof (struct in_addr), /* mu_cfg_ipv4 */
-  sizeof (mu_cfg_cidr_t),  /* mu_cfg_cidr */
-  sizeof (struct in_addr), /* mu_cfg_host */
-  0,                       /* mu_cfg_callback */
-  0,                       /* mu_cfg_section */
-}  ;
-
-static int
-_set_fun (void *item, void *data)
-{
-  mu_config_value_t *val = item;
-  struct set_closure *clos = data;
-  void *tgt;
-  size_t size;
-
-  if (clos->type >= MU_ARRAY_SIZE(config_type_size)
-      || (size = config_type_size[clos->type]) == 0)
-    {
-    mu_cfg_perror (clos->sdata->tree->debug, clos->locus,
-                  _("INTERNAL ERROR at %s:%d: unhandled data type %d"),
-                  __FILE__, __LINE__, clos->type);
-    return 1;
-    }
-
-  tgt = mu_alloc (size);
-  if (!tgt)
-    {
-      mu_cfg_perror (clos->sdata->tree->debug, clos->locus,
-                    _("not enough memory"));
-      return 1;
-    }
-
-  if (valcvt (clos->sdata, clos->locus, &tgt, clos->type, val) == 0)
-    mu_list_append (clos->list, tgt);
-  return 0;
-}
-
-static int
-parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node)
-{
-  void *tgt;
-  struct set_closure clos;
-  struct mu_cfg_param *param = find_param (sdata->list->sec, node->tag,
-                                          0);
-
-  if (!param)
-    {
-      mu_cfg_perror (sdata->tree->debug, &node->locus,
-                    _("unknown keyword `%s'"),
-                    node->tag);
-      return 1;
-    }
-
-  if (param->data)
-    tgt = param->data;
-  else if (sdata->list->sec->target)
-    tgt = (char*)sdata->list->sec->target + param->offset;
-  else if (sdata->target)
-    tgt = (char*)sdata->target + param->offset;
-  else if (param->type == mu_cfg_callback)
-    tgt = NULL;
-  else
-    {
-      mu_cfg_perror (sdata->tree->debug, &node->locus,
-                    _("INTERNAL ERROR: cannot determine target offset for "
-                      "%s"), param->ident);
-      abort ();
-    }
-
-  memset (&clos, 0, sizeof clos);
-  clos.type = MU_CFG_TYPE (param->type);
-  if (MU_CFG_IS_LIST (param->type))
-    {
-      clos.sdata = sdata;
-      clos.locus = &node->locus;
-      switch (node->label->type)
-       {
-       case MU_CFG_LIST:
-         break;
-
-       case MU_CFG_STRING:
-         {
-           mu_list_t list;
-           mu_list_create (&list);
-           mu_list_append (list, config_value_dup (node->label));
-           node->label->type = MU_CFG_LIST;
-           node->label->v.list = list;
-         }
-         break;
-
-       case MU_CFG_ARRAY:
-         mu_cfg_perror (sdata->tree->debug, &node->locus,
-                        _("expected list, but found array"));
-         return 1;
-       }
-
-      mu_list_create (&clos.list);
-      mu_list_do (node->label->v.list, _set_fun, &clos);
-      *(mu_list_t*)tgt = clos.list;
-    }
-  else if (clos.type == mu_cfg_callback)
-    {
-      mu_debug_set_locus (sdata->tree->debug, node->locus.file,
-                         node->locus.line);
-      if (!param->callback)
-       {
-         mu_cfg_perror (sdata->tree->debug, &node->locus,
-                        _("INTERNAL ERROR: %s: callback not defined"),
-                        node->tag);
-         abort ();
-       }
-      if (param->callback (sdata->tree->debug, tgt, node->label))
-       return 1;
-
-    }
-  else
-    return valcvt (sdata, &node->locus, tgt, clos.type, node->label);
-
-  return 0;
-}
-
-
-static int
-_scan_tree_helper (const mu_cfg_node_t *node, void *data)
-{
-  struct scan_tree_data *sdata = data;
-  struct mu_cfg_section *sec;
-
-  switch (node->type)
-    {
-    case mu_cfg_node_undefined:
-      abort ();
-
-    case mu_cfg_node_statement:
-      sec = find_subsection (sdata->list->sec, node->tag, 0);
-      if (!sec)
-       {
-         if (mu_cfg_parser_verbose)
-           {
-             _mu_cfg_debug_set_locus (sdata->tree->debug, &node->locus);
-             mu_cfg_format_error (sdata->tree->debug, MU_DIAG_WARNING,
-                                  _("unknown section `%s'"),
-                                  node->tag);
-           }
-         return MU_CFG_ITER_SKIP;
-       }
-      if (!sec->children)
-       return MU_CFG_ITER_SKIP;
-      if (sdata->list->sec->target)
-       sec->target = (char*)sdata->list->sec->target + sec->offset;
-      else if (sdata->target)
-       sec->target = (char*)sdata->target + sec->offset;
-      if (sec->parser)
-       {
-         mu_debug_set_locus (sdata->tree->debug,
-                             node->locus.file ?
-                                    node->locus.file : _("unknown file"),
-                             node->locus.line);
-         if (sec->parser (mu_cfg_section_start, node,
-                          sec->label, &sec->target,
-                          sdata->call_data, sdata->tree))
-           {
-             sdata->error++;
-             return MU_CFG_ITER_SKIP;
-           }
-       }
-      push_section(sdata, sec);
-      break;
-
-    case mu_cfg_node_param:
-      if (parse_param (sdata, node))
-       {
-         sdata->error++;
-         return MU_CFG_ITER_SKIP;
-       }
-      break;
-    }
-  return MU_CFG_ITER_OK;
-}
-
-static int
-_scan_tree_end_helper (const mu_cfg_node_t *node, void *data)
-{
-  struct scan_tree_data *sdata = data;
-  struct mu_cfg_section *sec;
-
-  switch (node->type)
-    {
-    default:
-      abort ();
-
-    case mu_cfg_node_statement:
-      sec = pop_section (sdata);
-      if (sec && sec->parser)
-       {
-         if (sec->parser (mu_cfg_section_end, node,
-                          sec->label, &sec->target,
-                          sdata->call_data, sdata->tree))
-           {
-             sdata->error++;
-             return MU_CFG_ITER_SKIP;
-           }
-       }
-    }
-  return MU_CFG_ITER_OK;
-}
-
-int
-mu_cfg_scan_tree (mu_cfg_tree_t *tree, struct mu_cfg_section *sections,
-                 void *target, void *data)
-{
-  mu_debug_t debug = NULL;
-  struct scan_tree_data dat;
-  struct mu_cfg_iter_closure clos;
-    
-  dat.tree = tree;
-  dat.list = NULL;
-  dat.error = 0;
-  dat.call_data = data;
-  dat.target = target;
-  
-  if (!tree->debug)
-    {
-      mu_diag_get_debug (&debug);
-      tree->debug = debug;
-    }
-  if (push_section (&dat, sections))
-    return 1;
-  clos.beg = _scan_tree_helper;
-  clos.end = _scan_tree_end_helper;
-  clos.data = &dat;
-  mu_cfg_preorder (tree->nodes, &clos);
-  if (debug)
-    {
-      mu_debug_set_locus (debug, NULL, 0);
-      tree->debug = NULL;
-    }
-  pop_section (&dat);
-  return dat.error;
-}
-
-int
-mu_cfg_find_section (struct mu_cfg_section *root_sec,
-                    const char *path, struct mu_cfg_section **retval)
-{
-  while (path[0])
-    {
-      struct mu_cfg_section *sec;
-      size_t len;
-      const char *p;
-
-      while (*path == MU_CFG_PATH_DELIM)
-       path++;
-
-      if (*path == 0)
-       return MU_ERR_NOENT;
-
-      p = strchr (path, MU_CFG_PATH_DELIM);
-      if (p)
-       len = p - path;
-      else
-       len = strlen (path);
-
-      sec = find_subsection (root_sec, path, len);
-      if (!sec)
-       return MU_ERR_NOENT;
-      root_sec = sec;
-      path += len;
-    }
-  if (retval)
-    *retval = root_sec;
-  return 0;
-}
-
-
-int
-mu_cfg_tree_create (struct mu_cfg_tree **ptree)
-{
-  struct mu_cfg_tree *tree = calloc (1, sizeof *tree);
-  if (!tree)
-    return errno;
-  mu_opool_create (&tree->pool, 1);
-  *ptree = tree;
-  return 0;
-}
-
-void
-mu_cfg_tree_set_debug (struct mu_cfg_tree *tree, mu_debug_t debug)
-{
-  tree->debug = debug;
-}
-
-mu_cfg_node_t *
-mu_cfg_tree_create_node (struct mu_cfg_tree *tree,
-                        enum mu_cfg_node_type type,
-                        const mu_cfg_locus_t *loc,
-                        const char *tag, const char *label,
-                        mu_list_t nodelist)
-{
-  char *p;
-  mu_cfg_node_t *np;
-  size_t size = sizeof *np + strlen (tag) + 1;
-  mu_config_value_t val;
-
-  np = mu_alloc (size);
-  np->type = type;
-  if (loc)
-    np->locus = *loc;
-  else
-    memset (&np->locus, 0, sizeof np->locus);
-  p = (char*) (np + 1);
-  np->tag = p;
-  strcpy (p, tag);
-  p += strlen (p) + 1;
-  val.type = MU_CFG_STRING;
-  if (label)
-    {
-      mu_opool_clear (tree->pool);
-      mu_opool_appendz (tree->pool, label);
-      val.v.string = mu_opool_finish (tree->pool, NULL);
-      np->label = config_value_dup (&val);
-    }
-  else
-    np->label = NULL;
-  np->nodes = nodelist;
-  return np;
-}
-
-void
-mu_cfg_tree_add_node (mu_cfg_tree_t *tree, mu_cfg_node_t *node)
-{
-  if (!node)
-    return;
-  if (!tree->nodes)
-    /* FIXME: return code? */
-    mu_cfg_create_node_list (&tree->nodes);
-  mu_list_append (tree->nodes, node);
-}
-
-void
-mu_cfg_tree_add_nodelist (mu_cfg_tree_t *tree, mu_list_t nodelist)
-{
-  if (!nodelist)
-    return;
-  if (!tree->nodes)
-    /* FIXME: return code? */
-    mu_cfg_create_node_list (&tree->nodes);
-  mu_list_append_list (tree->nodes, nodelist);
-}
-
-
-/* Return 1 if configuration value A equals B */
-int
-mu_cfg_value_eq (mu_config_value_t *a, mu_config_value_t *b)
-{
-  if (a->type != b->type)
-    return 0;
-  switch (a->type)
-    {
-    case MU_CFG_STRING:
-      if (a->v.string == NULL)
-       return b->v.string == NULL;
-      return strcmp (a->v.string, b->v.string) == 0;
-                    
-    case MU_CFG_LIST:
-      {
-       int ret = 1;
-       size_t cnt;
-       size_t i;
-       mu_iterator_t aitr, bitr;
-       
-       mu_list_count (a->v.list, &cnt);
-       mu_list_count (b->v.list, &i);
-       if (i != cnt)
-         return 1;
-
-       mu_list_get_iterator (a->v.list, &aitr);
-       mu_list_get_iterator (b->v.list, &bitr);
-       for (i = 0,
-              mu_iterator_first (aitr),
-              mu_iterator_first (bitr);
-            !mu_iterator_is_done (aitr) && !mu_iterator_is_done (bitr);
-            mu_iterator_next (aitr),
-              mu_iterator_next (bitr),
-              i++)
-         {
-           mu_config_value_t *ap, *bp;
-           mu_iterator_current (aitr, (void**)&ap);
-           mu_iterator_current (bitr, (void**)&bp);
-           ret = mu_cfg_value_eq (ap, bp);
-           if (!ret)
-             break;
-         }
-       mu_iterator_destroy (&aitr);
-       mu_iterator_destroy (&bitr);
-       return ret && i == cnt;
-      }
-       
-    case MU_CFG_ARRAY:
-      if (a->v.arg.c == b->v.arg.c)
-       {
-         size_t i;
-         for (i = 0; i < a->v.arg.c; i++)
-           if (!mu_cfg_value_eq (&a->v.arg.v[i], &b->v.arg.v[i]))
-             return 0;
-         return 1;
-       }
-    }
-  return 0;
-}
-
-
-static int
-split_cfg_path (const char *path, int *pargc, char ***pargv)
-{
-  int rc;
-  int argc;
-  char **argv;
-  char *delim = MU_CFG_PATH_DELIM_STR;
-  char static_delim[2] = { 0, 0 };
-  
-  if (path[0] == '\\')
-    {
-      argv = calloc (2, sizeof (*argv));
-      if (!argv)
-       return ENOMEM;
-      argv[0] = strdup (path + 1);
-      if (!argv[0])
-       {
-         free (argv);
-         return ENOMEM;
-       }
-      argv[1] = NULL;
-      argc = 1;
-      rc = 0;
-    }
-  else
-    {
-      if (mu_ispunct (path[0]))
-       {
-         delim = static_delim;
-         delim[0] = path[0];
-         path++;
-       }
-      rc = mu_argcv_get_np (path, strlen (path), delim, NULL, 0,
-                           &argc, &argv, NULL);
-    }
-  if (rc == 0)
-    {
-      *pargc = argc;
-      *pargv = argv;
-    }
-  return rc;
-}
-
-struct find_data
-{
-  int argc;
-  char **argv;
-  int tag;
-  mu_config_value_t *label;
-  const mu_cfg_node_t *node;
-};
-
-static void
-free_value_mem (mu_config_value_t *p)
-{
-  switch (p->type)
-    {
-    case MU_CFG_STRING:
-      free ((char*)p->v.string);
-      break;
-      
-    case MU_CFG_LIST:
-      /* FIXME */
-      break;
-      
-    case MU_CFG_ARRAY:
-      {
-       size_t i;
-       for (i = 0; i < p->v.arg.c; i++)
-         free_value_mem (&p->v.arg.v[i]);
-      }
-    }
-}
-
-static void
-destroy_value (void *p)
-{
-  mu_config_value_t *val = p;
-  if (val)
-    {
-      free_value_mem (val);
-      free (val);
-    }
-}
-
-static mu_config_value_t *
-parse_label (const char *str)
-{
-  mu_config_value_t *val = NULL;
-  int count, i;
-  char **vect;
-  size_t len = strlen (str);
-  
-  if (len > 1 && str[0] == '(' && str[len-1] == ')')
-    {
-      mu_list_t lst;
-      mu_argcv_get_np (str + 1, len - 2,
-                      ", \t", NULL,
-                      0,
-                      &count, &vect, NULL);
-      mu_list_create (&lst);
-      mu_list_set_destroy_item (lst, destroy_value);
-      for (i = 0; i < count; i++)
-       {
-         mu_config_value_t *p = mu_alloc (sizeof (*p));
-         p->type = MU_CFG_STRING;
-         p->v.string = vect[i];
-         mu_list_append (lst, p);
-       }
-      free (vect);
-      val = mu_alloc (sizeof (*val));
-      val->type = MU_CFG_LIST;
-      val->v.list = lst;
-    }
-  else
-    {      
-      mu_argcv_get (str, NULL, NULL, &count, &vect);
-      val = mu_alloc (sizeof (*val));
-      if (count == 1)
-       {
-         val->type = MU_CFG_STRING;
-         val->v.string = vect[0];
-         free (vect);
-       }
-      else
-       {
-         val->type = MU_CFG_ARRAY;
-         val->v.arg.c = count;
-         val->v.arg.v = mu_alloc (count * sizeof (val->v.arg.v[0]));
-         for (i = 0; i < count; i++)
-           {
-             val->v.arg.v[i].type = MU_CFG_STRING;
-             val->v.arg.v[i].v.string = vect[i];
-           }
-         free (vect);
-       }
-    }
-  return val;
-}
-
-static void
-parse_tag (struct find_data *fptr)
-{
-  char *p = strchr (fptr->argv[fptr->tag], '=');
-  if (p)
-    {
-      *p++ = 0;
-      fptr->label = parse_label (p);
-    }
-  else
-    fptr->label = NULL;
-}
-
-static int
-node_finder (const mu_cfg_node_t *node, void *data)
-{
-  struct find_data *fdptr = data;
-  if (strcmp (fdptr->argv[fdptr->tag], node->tag) == 0
-      && (!fdptr->label || mu_cfg_value_eq (fdptr->label, node->label)))
-    {
-      fdptr->tag++;
-      if (fdptr->tag == fdptr->argc)
-       {
-         fdptr->node = node;
-         return MU_CFG_ITER_STOP;
-       }
-      parse_tag (fdptr);
-      return MU_CFG_ITER_OK;
-    }
-  
-  return node->type == mu_cfg_node_statement ?
-               MU_CFG_ITER_SKIP : MU_CFG_ITER_OK;
-}
-
-int        
-mu_cfg_find_node (mu_cfg_tree_t *tree, const char *path, mu_cfg_node_t **pval)
-{
-  int rc;
-  struct find_data data;
-  struct mu_cfg_iter_closure clos;
-
-  rc = split_cfg_path (path, &data.argc, &data.argv);
-  if (rc)
-    return rc;
-  data.tag = 0;
-  parse_tag (&data);
-
-  clos.beg = node_finder;
-  clos.end = NULL;
-  clos.data = &data;
-  rc = mu_cfg_preorder (tree->nodes, &clos);
-  destroy_value (data.label);
-  if (rc)
-    {
-      *pval = (mu_cfg_node_t *) data.node;
-      return 0;
-    }
-  return MU_ERR_NOENT;
-}
-
-
-
-int
-mu_cfg_create_subtree (const char *path, mu_cfg_node_t **pnode)
-{
-  int rc;
-  int argc, i;
-  char **argv;
-  enum mu_cfg_node_type type;
-  mu_cfg_node_t *node = NULL;
-  mu_cfg_locus_t locus;
-
-  locus.file = "<int>";
-  locus.line = 0;
-
-  rc = split_cfg_path (path, &argc, &argv);
-  if (rc)
-    return rc;
-
-  for (i = argc - 1; i >= 0; i--)
-    {
-      mu_list_t nodelist = NULL;
-      mu_config_value_t *label = NULL;
-      char *q = argv[i], *p;
-      
-      type = mu_cfg_node_statement;
-      do
-       {
-         p = strchr (q, '=');
-         if (p && p > argv[i] && p[-1] != '\\')
-           {
-             *p++ = 0;
-             label = parse_label (p);
-             if (i == argc - 1)
-               type = mu_cfg_node_param;
-             break;
-           }
-         else if (p)
-           q = p + 1;
-         else
-           break;
-       }
-      while (*q);
-      
-      if (node)
-       {
-         mu_cfg_create_node_list (&nodelist);
-         mu_list_append (nodelist, node);
-       }
-      node = mu_cfg_alloc_node (type, &locus, argv[i], label, nodelist);
-    }
-
-  mu_argcv_free (argc, argv);
-  *pnode = node;
-  return 0;
-}
-
-  
-         
-        
-  
diff --git a/libmailutils/crlfdot.c b/libmailutils/crlfdot.c
deleted file mode 100644
index eed4519..0000000
--- a/libmailutils/crlfdot.c
+++ /dev/null
@@ -1,336 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2003, 2007, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-/* This source implements a CRLFDOT filter, useful for data I/O in
-   such protocols as POP3 and SMTP.  When encoding, this filter
-   replaces each '\n' not following '\r' by "\r\n" and "byte-stuffs"
-   the input by outputting an additional '.' in front of any '.' appearing
-   at the beginning of a line.  Upon closing the filter in this mode, it
-   outputs additional ".\r\n".
-   
-   When decoding, the reverse is performed: each "\r\n" is replaced by a
-   '\n', and additional '.' are removed from beginning of lines.  A single
-   dot on a line by itself marks end of the stream.
- */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include <mailutils/errno.h>
-#include <mailutils/filter.h>
-#include <mailutils/stream.h>
-
-enum crlfdot_decode_state
-  {
-    crlfdot_decode_init,  /* initial state */
-    crlfdot_decode_char,  /* Any character excepting [\r\n.] */
-    crlfdot_decode_cr,    /* prev. char was \r */
-    crlfdot_decode_crlf,  /* 2 prev. char were \r\n */
-    crlfdot_decode_dot,   /* 3 prev. chars were \r\n. */
-    crlfdot_decode_dotcr, /* 4 prev. chars were \r\n.\r */
-    crlfdot_decode_end    /* final state, a \r\n.\r\n seen. */
-  };
-
-static enum crlfdot_decode_state
-new_decode_state (enum crlfdot_decode_state state, int c)
-{
-  switch (state)
-    {
-    case crlfdot_decode_init:
-      switch (c)
-       {
-       case '\r':
-         return crlfdot_decode_cr;
-       case '.':
-         return crlfdot_decode_dot;
-       }
-      break;
-      
-    case crlfdot_decode_char:
-      switch (c)
-       {
-       case '\r':
-         return crlfdot_decode_cr;
-       }
-      break;
-      
-    case crlfdot_decode_cr:
-      switch (c)
-       {
-       case '\r':
-         return crlfdot_decode_cr;
-       case '\n':
-         return crlfdot_decode_crlf;
-       }
-      break;
-      
-    case crlfdot_decode_crlf:
-      switch (c)
-       {
-       case '\r':
-         return crlfdot_decode_cr;
-       case '.':
-         return crlfdot_decode_dot;
-       }
-      
-    case crlfdot_decode_dot:
-      switch (c)
-       {
-       case '\r':
-         return crlfdot_decode_dotcr;
-       }
-      break;
-
-    case crlfdot_decode_dotcr:
-      switch (c)
-       {
-       case '\n':
-         return crlfdot_decode_end;
-       }
-
-    case crlfdot_decode_end:
-      break;
-    }
-  return crlfdot_decode_char;
-}
-
-/* Move min(isize,osize) bytes from iptr to optr, replacing each \r\n
-   with \n. */
-static enum mu_filter_result
-_crlfdot_decoder (void *xd,
-                 enum mu_filter_command cmd,
-                 struct mu_filter_io *iobuf)
-{
-  int *pstate = xd;
-  size_t i, j;
-  const unsigned char *iptr;
-  size_t isize;
-  char *optr;
-  size_t osize;
-
-  switch (cmd)
-    {
-    case mu_filter_init:
-      *pstate = crlfdot_decode_init;
-      return mu_filter_ok;
-      
-    case mu_filter_done:
-      return mu_filter_ok;
-      
-    default:
-      break;
-    }
-  
-  iptr = (const unsigned char *) iobuf->input;
-  isize = iobuf->isize;
-  optr = iobuf->output;
-  osize = iobuf->osize;
-
-  for (i = j = 0; *pstate != crlfdot_decode_end && i < isize && j < osize; i++)
-    {
-      unsigned char c = *iptr++;
-
-      if (c == '\r')
-       {
-         if (i + 1 == isize)
-           break;
-         *pstate = new_decode_state (*pstate, c);
-         if (*iptr == '\n')
-           continue;
-       }
-      else if (c == '.' &&
-              (*pstate == crlfdot_decode_init ||
-               *pstate == crlfdot_decode_crlf))
-       {
-         /* Make sure we have two more characters in the buffer */
-         if (i + 2 == isize)
-           break;
-         *pstate = new_decode_state (*pstate, c);
-         if (*iptr != '\r')
-           continue;
-       }
-      else
-       *pstate = new_decode_state (*pstate, c);
-      optr[j++] = c;
-    }
-  
-  if (*pstate == crlfdot_decode_end)
-    {
-      j -= 2; /* remove the trailing .\n */
-      iobuf->eof = 1;
-    }
-  iobuf->isize = i;
-  iobuf->osize = j;
-  return mu_filter_ok;
-}
-
-enum crlfdot_encode_state
-  {
-    crlfdot_encode_init,  /* initial state */
-    crlfdot_encode_char,  /* Any character excepting [\r\n] */
-    crlfdot_encode_cr,    /* prev. char was \r */
-    crlfdot_encode_lf,    /* prev. char was \n */
-  };    
-
-static enum crlfdot_encode_state
-new_encode_state (enum crlfdot_encode_state state, int c)
-{
-  switch (c)
-    {
-    case '\r':
-      return crlfdot_encode_cr;
-      
-    case '\n':
-      return crlfdot_encode_lf;
-    }
-  return crlfdot_encode_char;
-}
-
-/* Move min(isize,osize) bytes from iptr to optr, replacing each \n
-   with \r\n.  Any input \r\n sequences remain untouched. */
-static enum mu_filter_result
-_crlfdot_encoder (void *xd,
-                 enum mu_filter_command cmd,
-                 struct mu_filter_io *iobuf)
-{
-  enum mu_filter_result result;
-  size_t i, j;
-  const unsigned char *iptr;
-  size_t isize;
-  char *optr;
-  size_t osize;
-  int *state = xd;
-  
-  switch (cmd)
-    {
-    case mu_filter_init:
-      *state = crlfdot_encode_init;
-      return mu_filter_ok;
-      
-    case mu_filter_done:
-      return mu_filter_ok;
-
-    default:
-      break;
-    }
-  
-  iptr = (const unsigned char *) iobuf->input;
-  isize = iobuf->isize;
-  optr = iobuf->output;
-  osize = iobuf->osize;
-
-  for (i = j = 0; i < isize && j < osize; i++, iptr++)
-    {
-      unsigned char c = *iptr;
-      int curstate = *state;
-
-      if (c == '\n')
-       {
-         if (curstate == crlfdot_encode_cr)
-           optr[j++] = c;
-         else if (j + 1 == osize)
-           {
-             if (i == 0)
-               {
-                 iobuf->osize = 2;
-                 return mu_filter_moreoutput;
-               }
-             break;
-           }
-         else
-           {
-             optr[j++] = '\r';
-             optr[j++] = '\n';
-           }
-       }
-      else if (c == '.' &&
-              (curstate == crlfdot_encode_init ||
-               curstate == crlfdot_encode_lf))
-       {
-         if (j + 2 > osize)
-           {
-             if (i == 0)
-               {
-                 iobuf->osize = 2;
-                 return mu_filter_moreoutput;
-               }
-             break;
-           }
-         optr[j++] = '.';
-         optr[j++] = '.';
-       }
-      else
-       optr[j++] = c;
-
-      *state = new_encode_state (curstate, c);
-    }
-
-  result = mu_filter_ok;
-  if (cmd == mu_filter_lastbuf)
-    {
-      switch (*state)
-       {
-       case crlfdot_encode_lf:
-         if (j + 3 > osize)
-           result = mu_filter_again;
-         break;
-             
-       default:
-         if (j + 5 > osize)
-           result = mu_filter_again;
-         else
-           {
-             optr[j++] = '\r';
-             optr[j++] = '\n';
-           }
-       }
-
-      if (result == mu_filter_ok)
-       {
-         optr[j++] = '.';
-         optr[j++] = '\r';
-         optr[j++] = '\n';
-       }
-    }
-
-  iobuf->isize = i;
-  iobuf->osize = j;
-  return result;
-}
-
-static int
-alloc_state (void **pret, int mode MU_ARG_UNUSED, void *data MU_ARG_UNUSED)
-{
-  *pret = malloc (sizeof (int));
-  if (!*pret)
-    return ENOMEM;
-  return 0;
-}
-
-static struct _mu_filter_record _crlfdot_filter = {
-  "CRLFDOT",
-  0,
-  alloc_state,
-  _crlfdot_encoder,
-  _crlfdot_decoder
-};
-
-mu_filter_record_t mu_crlfdot_filter = &_crlfdot_filter;
diff --git a/libmailutils/daemon.c b/libmailutils/daemon.c
deleted file mode 100644
index b7fca61..0000000
--- a/libmailutils/daemon.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2004, 2005, 2007, 2008, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <string.h>
-
-#include <mailutils/daemon.h>
-#include <mailutils/errno.h>
-#include <mailutils/error.h>
-#include <mailutils/nls.h>
-
-static char *pidfile;
-static pid_t current_pid;
-
-/* Return 0 if DIR is writable for EUID/EGID.
-   Otherwise, return error code. */
-static int
-ewraccess (const char *dir)
-{
-  struct stat st;
-  if (stat (dir, &st))
-    return errno;
-  if ((st.st_mode & S_IWOTH)
-      || (st.st_gid == getegid () && (st.st_mode & S_IWGRP))
-      || (st.st_uid == geteuid () && (st.st_mode & S_IWUSR)))
-    return 0;
-  else
-    return EACCES;
-}
-
-/* Return 0 if DIR is writable. If necessary and possible, raise to
-   EUID 0, in that case return prior EUID in the memory location pointed to
-   by PUID. */
-static int
-access_dir (const char *dir, uid_t *puid)
-{
-  int ec = ewraccess (dir);
-  if (ec)
-    {
-      if (ec == EACCES && access (dir, W_OK) == 0)
-       {
-         uid_t uid = geteuid ();
-         /* See if we can become root */
-         if (uid && getuid () == 0 && seteuid (0) == 0)
-           {
-             *puid = uid;
-             return 0;
-           }
-       }
-    }
-  return ec;
-}
-
-int
-mu_daemon_create_pidfile (const char *filename)
-{
-  char *p;
-  int fd;
-  uid_t uid = 0;
-  int rc;
-  
-  if (filename[0] != '/')
-    return EINVAL;
-
-  if (pidfile)
-    free (pidfile);
-  pidfile = strdup (filename);
-  if (!pidfile)
-    return ENOMEM;
-
-  /* Determine the hosting directory name */
-  p = strrchr (pidfile, '/');
-  if (pidfile == p)
-    {
-      free (pidfile);
-      pidfile = NULL;
-      /* Sorry, pidfiles in root dir are not allowed */
-      return EINVAL;
-    }
-  /* Check if we have write access to the directory */
-  *p = 0;
-  rc = access_dir (pidfile, &uid);
-  if (rc)
-    {
-      /* Nope, clean up and return */
-      free (pidfile);
-      pidfile = NULL;
-      return rc;
-    }
-
-  /* Restore directory separator */
-  *p = '/';
-    
-  unlink (pidfile);
-  current_pid = getpid ();
-  
-  if ((fd = open (pidfile, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0644)) != -1)
-    {
-      FILE *fp = fdopen (fd, "w");
-      if (!fp)
-       {
-         rc = errno;
-         free (pidfile);
-         close (fd);
-       }
-      else
-       {
-         fprintf (fp, "%lu", (unsigned long) current_pid);
-         fclose (fp);
-         atexit (mu_daemon_remove_pidfile);
-       }
-    }
-  else
-    {
-      rc = errno;
-      free (pidfile);
-      pidfile = NULL;
-    }
-
-  /* Restore previous EUID value. */
-  if (uid)
-    seteuid (uid);
-  
-  return rc;
-}
-
-void
-mu_daemon_remove_pidfile (void)
-{
-  if (getpid () == current_pid)
-    {
-      int rc;
-      uid_t uid = 0;
-
-      /* Determine the hosting directory name */
-      char *p = strrchr (pidfile, '/');
-      if (pidfile == p)
-       {
-         /* Should not happen */
-         abort ();
-       }
-      /* Check if we have write access to the directory */
-      *p = 0;
-      rc = access_dir (pidfile, &uid);
-      *p = '/';
-      if (rc == 0)
-       {
-         if (unlink (pidfile) && errno != ENOENT)
-           rc = errno;
-         else
-           rc = 0;
-       }
-      
-      if (rc)
-       mu_error (_("cannot remove pidfile %s: %s"),
-                 pidfile, mu_strerror (rc));
-
-      free (pidfile);
-      pidfile = NULL;
-    }
-}
-
-
-
diff --git a/libmailutils/date.c b/libmailutils/date.c
deleted file mode 100644
index d667e34..0000000
--- a/libmailutils/date.c
+++ /dev/null
@@ -1,245 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2002, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <mailutils/mutil.h>
-#include <mailutils/cstr.h>
-
-#define SECS_PER_DAY 86400
-#define ADJUSTMENT -719162L
-
-static time_t
-jan1st (int year)
-{
-  year--;               /* Do not consider the current year */
-  return  year*365L
-               + year/4L    /* Years divisible by 4 are leap years */
-               + year/400L  /* Years divisible by 400 are always leap years */
-               - year/100L; /* Years divisible by 100 but not 400 aren't */
-}
-
-static int  month_start[]=
-    {    0, 31, 59,  90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
-     /* Jan Feb Mar  Apr  May  Jun  Jul  Aug  Sep  Oct  Nov  Dec
-         31  28  31   30   31   30   31   31   30   31   30   31
-     */
-
-/* NOTE: ignore GCC warning. The precedence of operators is OK here */
-#define leap_year(y) ((y) % 4 == 0 && (y) % 100 != 0 || (y) % 400 == 0)
-
-static int
-dayofyear (time_t *pday, int year, int month, int day)
-{
-  int  leap, month_days;
-
-  if (year < 0 || month < 0 || month > 11)
-    return -1;
-    
-  leap = leap_year (year);
-  
-  month_days = month_start[month + 1] - month_start[month]
-               + ((month == 2) ? leap : 0);
-
-  if (day < 0 || day > month_days)
-    return -1;  /* Illegal Date */
-
-  if (month <= 2)
-    leap = 0;
-
-  *pday = month_start[month] + day + leap;
-  return 0;
-}
-
-
-/* Convert struct tm into time_t, taking into account timezone offset. */
-/* FIXME: It does not take DST into account */
-time_t
-mu_tm2time (struct tm *tm, mu_timezone *tz)
-{
-  time_t t;
-  
-  if (dayofyear (&t, tm->tm_year, tm->tm_mon, tm->tm_mday - 1))
-    return -1;
-  t = (t + ADJUSTMENT + jan1st (1900 + tm->tm_year)) * SECS_PER_DAY
-            + (tm->tm_hour * 60 + tm->tm_min) * 60 + tm->tm_sec
-      - tz->utc_offset;
-  return t;
-}
-
-/* Convert time 0 at UTC to our localtime, that tells us the offset
-   of our current timezone from UTC. */
-time_t
-mu_utc_offset (void)
-{
-  time_t t = 0;
-  struct tm *tm = gmtime (&t);
-
-  return - mktime (tm);
-}
-
-static const char *months[] =
-{
-  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
-  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL
-};
-
-static const char *wdays[] =
-{
-  "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL
-};
-
-int
-mu_parse_imap_date_time (const char **p, struct tm *tm, mu_timezone *tz)
-{
-  int year, mon, day, hour, min, sec;
-  char zone[6] = "+0000";      /* ( "+" / "-" ) hhmm */
-  char month[5] = "";
-  int hh = 0;
-  int mm = 0;
-  int sign = 1;
-  int scanned = 0, scanned3;
-  int i;
-  int tzoffset;
-
-  day = mon = year = hour = min = sec = 0;
-
-  memset (tm, 0, sizeof (*tm));
-
-  switch (sscanf (*p,
-                 "%2d-%3s-%4d%n %2d:%2d:%2d %5s%n",
-                 &day, month, &year, &scanned3, &hour, &min, &sec, zone,
-                 &scanned))
-    {
-    case 3:
-      scanned = scanned3;
-      break;
-    case 7:
-      break;
-    default:
-      return -1;
-    }
-
-  tm->tm_sec = sec;
-  tm->tm_min = min;
-  tm->tm_hour = hour;
-  tm->tm_mday = day;
-
-  for (i = 0; i < 12; i++)
-    {
-      if (mu_c_strncasecmp (month, months[i], 3) == 0)
-       {
-         mon = i;
-         break;
-       }
-    }
-  tm->tm_mon = mon;
-  tm->tm_year = (year > 1900) ? year - 1900 : year;
-  tm->tm_yday = 0;             /* unknown. */
-  tm->tm_wday = 0;             /* unknown. */
-#if HAVE_STRUCT_TM_TM_ISDST
-  tm->tm_isdst = -1;           /* unknown. */
-#endif
-
-  hh = (zone[1] - '0') * 10 + (zone[2] - '0');
-  mm = (zone[3] - '0') * 10 + (zone[4] - '0');
-  sign = (zone[0] == '-') ? -1 : +1;
-  tzoffset = sign * (hh * 60 * 60 + mm * 60);
-
-#if HAVE_STRUCT_TM_TM_GMTOFF
-  tm->tm_gmtoff = tzoffset;
-#endif
-
-  if (tz)
-    {
-      tz->utc_offset = tzoffset;
-      tz->tz_name = NULL;
-    }
-
-  *p += scanned;
-
-  return 0;
-}
-
-/* "ctime" format is: Thu Jul 01 15:58:27 1999, with no trailing \n.  */
-int
-mu_parse_ctime_date_time (const char **p, struct tm *tm, mu_timezone * tz)
-{
-  int wday = 0;
-  int year = 0;
-  int mon = 0;
-  int day = 0;
-  int hour = 0;
-  int min = 0;
-  int sec = 0;
-  int n = 0;
-  int i;
-  char weekday[5] = "";
-  char month[5] = "";
-
-  if (sscanf (*p, "%3s %3s %2d %2d:%2d:%2d %d%n\n",
-       weekday, month, &day, &hour, &min, &sec, &year, &n) != 7)
-    return -1;
-
-  *p += n;
-
-  for (i = 0; i < 7; i++)
-    {
-      if (mu_c_strncasecmp (weekday, wdays[i], 3) == 0)
-       {
-         wday = i;
-         break;
-       }
-    }
-
-  for (i = 0; i < 12; i++)
-    {
-      if (mu_c_strncasecmp (month, months[i], 3) == 0)
-       {
-         mon = i;
-         break;
-       }
-    }
-
-  if (tm)
-    {
-      memset (tm, 0, sizeof (struct tm));
-
-      tm->tm_sec = sec;
-      tm->tm_min = min;
-      tm->tm_hour = hour;
-      tm->tm_mday = day;
-      tm->tm_wday = wday;
-      tm->tm_mon = mon;
-      tm->tm_year = (year > 1900) ? year - 1900 : year;
-#ifdef HAVE_STRUCT_TM_TM_ISDST
-      tm->tm_isdst = -1;       /* unknown. */
-#endif
-    }
-
-  /* ctime has no timezone information, set tz to UTC if they ask. */
-  if (tz)
-    memset (tz, 0, sizeof (struct mu_timezone));
-
-  return 0;
-}
diff --git a/libmailutils/dbgstderr.c b/libmailutils/dbgstderr.c
deleted file mode 100644
index 9a2e164..0000000
--- a/libmailutils/dbgstderr.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <mailutils/debug.h>
-#include <stdio.h>
-
-int
-mu_debug_stderr_printer (void *unused, mu_log_level_t level, const char *str)
-{
-  fprintf (stderr, "%s: %s",
-          (level == MU_DEBUG_ERROR) ? "ERROR" : "DEBUG",
-          str);
-  return 0;
-}
-
-
diff --git a/libmailutils/dbgsyslog.c b/libmailutils/dbgsyslog.c
deleted file mode 100644
index f906cd3..0000000
--- a/libmailutils/dbgsyslog.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <mailutils/debug.h>
-#include <syslog.h>
-
-int
-mu_debug_syslog_printer (void *unused, mu_log_level_t level, const char *str)
-{
-  syslog ((level == MU_DEBUG_ERROR) ? LOG_ERR : LOG_DEBUG, "%s", str);
-  return 0;
-}
-
-
diff --git a/libmailutils/debug.c b/libmailutils/debug.c
deleted file mode 100644
index d738cef..0000000
--- a/libmailutils/debug.c
+++ /dev/null
@@ -1,299 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2008, 2010 Free
-   Software Foundation, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library; if not, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <mailutils/errno.h>
-#include <mailutils/nls.h>
-#include <mailutils/sys/debug.h>
-
-mu_debug_printer_fp mu_debug_default_printer = mu_debug_stderr_printer;
-
-int
-mu_debug_create (mu_debug_t *pdebug, void *owner)
-{
-  mu_debug_t debug;
-  if (pdebug == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  debug = calloc (sizeof (*debug), 1);
-  if (debug == NULL)
-    return ENOMEM;
-  debug->printer = NULL;
-  debug->owner = owner;
-  *pdebug = debug;
-  return 0;
-}
-
-void
-mu_debug_destroy (mu_debug_t *pdebug, void *owner)
-{
-  if (pdebug && *pdebug)
-    {
-      mu_debug_t debug = *pdebug;
-      if (debug->owner == owner)
-       {
-         if (debug->stream)
-           {
-             mu_off_t len = 0;
-             int rc = mu_stream_size (debug->stream, &len);
-             if (rc == 0 && len)
-               /* Flush leftover data */
-               mu_debug_printf (debug, 0, "\n");
-
-             mu_stream_destroy (&debug->stream);
-           }
-         if (debug->destroy)
-           debug->destroy (debug->data);
-         free (*pdebug);
-         *pdebug = NULL;
-       }
-    }
-}
-
-void *
-mu_debug_get_owner (mu_debug_t debug)
-{
-  return (debug) ? debug->owner : NULL;
-}
-
-int
-mu_debug_set_level (mu_debug_t debug, mu_log_level_t level)
-{
-  if (debug == NULL)
-    return EINVAL;
-  debug->level = level;
-  return 0;
-}
-
-int
-mu_debug_get_level (mu_debug_t debug, mu_log_level_t *plevel)
-{
-  if (debug == NULL)
-    return EINVAL;
-  if (plevel)
-    *plevel = debug->level;
-  return 0;
-}
-
-int
-mu_debug_set_print (mu_debug_t debug, mu_debug_printer_fp printer, void *owner)
-{
-  if (debug == NULL)
-    return EINVAL;
-  if (debug->owner != owner)
-    return EACCES;
-  debug->printer = printer;
-  return 0;
-}
-
-int
-mu_debug_set_data (mu_debug_t debug, void *data, void (*destroy) (void*),
-                  void *owner)
-{
-  if (!debug)
-    return EINVAL;
-  if (debug->owner != owner)
-    return EACCES;
-  debug->data = data;
-  debug->destroy = destroy;
-  return 0;
-}
-
-static void
-debug_format_prefix (mu_debug_t debug)
-{
-  int need_space = 0;
-  if (debug->locus.file)
-    {
-      mu_stream_printf (debug->stream, "%s:%d:",
-                       debug->locus.file, debug->locus.line);
-      need_space = 1;
-    }
-  
-  if (debug->function)
-    {
-      mu_stream_printf (debug->stream, "%s:", debug->function);
-      need_space = 1;
-    }
-  
-  if (need_space)
-    mu_stream_write (debug->stream, " ", 1, NULL);
-}
-
-int
-mu_debug_vprintf (mu_debug_t debug, mu_log_level_t level,
-                 const char *format, va_list ap)
-{
-  mu_debug_printer_fp printer;
-  
-  if (debug == NULL || format == NULL)
-    return EINVAL;
-
-  printer = debug->printer ? debug->printer : mu_debug_default_printer;
-  if (printer)
-    {
-      mu_off_t len;
-      mu_transport_t tbuf[2];
-      char *ptr, *start, *p;
-      size_t nseg;
-      
-      if (debug->stream == NULL)
-       {
-         int rc = mu_memory_stream_create (&debug->stream, 0);
-         if (rc)
-           {
-             fprintf (stderr,
-                      _("cannot create memory stream for debugging "
-                        "output: %s\n"),
-                      mu_strerror (rc));
-             vfprintf (stderr, format, ap);
-             return rc;
-           }
-       }
-
-      if (mu_stream_size (debug->stream, &len) == 0 && len == 0)
-       debug_format_prefix (debug);
-      
-      mu_stream_vprintf (debug->stream, format, ap);
-
-      mu_stream_ioctl (debug->stream, MU_IOCTL_GET_TRANSPORT, tbuf);
-      start = (char*) tbuf[0];
-      mu_stream_size (debug->stream, &len);
-      ptr = start;
-      nseg = 0;
-      for (p = ptr = start; p < start + len; p++)
-       {
-         if (*p == '\n')
-           {
-             int c = *++p;
-             *p = 0;
-             printer (debug->data, level, ptr);
-             *p = c;
-             ptr = p;
-             nseg++;
-           }
-       }
-
-      if (nseg)
-       {
-         if (start[len - 1] != '\n')
-           {
-             size_t s = len - (ptr - start);
-             memmove (start, ptr, s);
-           }
-         else
-           len = 0;
-
-         mu_stream_truncate (debug->stream, len);
-         mu_stream_seek (debug->stream, len, SEEK_SET, NULL);
-       }
-    }
-  else
-    vfprintf (stderr, format, ap);
-
-  return 0;
-}
-
-int
-mu_debug_printf (mu_debug_t debug, mu_log_level_t level,
-                const char *format, ...)
-{
-  va_list ap;
-
-  va_start (ap, format);
-  mu_debug_vprintf (debug, level, format, ap);
-  va_end (ap);
-  return 0;
-}
-  
-
-int
-mu_debug_print (mu_debug_t debug, mu_log_level_t level,
-               const char *format, ...)
-{
-  va_list ap;
-  va_start(ap, format);
-  mu_debug_printv (debug, level, format, ap);
-  va_end (ap);
-  return 0;
-}
-
-int
-mu_debug_printv (mu_debug_t debug, mu_log_level_t level, const char *format,
-                va_list ap)
-{
-  if (debug == NULL || format == NULL)
-    return EINVAL;
-  if (debug->level & MU_DEBUG_LEVEL_MASK (level))
-    return 0;
-  return mu_debug_vprintf (debug, level, format, ap);
-}
-
-int
-mu_debug_check_level (mu_debug_t debug, mu_log_level_t level)
-{
-  if (!debug)
-    return 0;
-  return debug->level & MU_DEBUG_LEVEL_MASK (level);
-}
-
-int
-mu_debug_set_locus (mu_debug_t debug, const char *file, int line)
-{
-  if (!debug)
-    return EINVAL;
-  debug->locus.file = file;
-  debug->locus.line = line;
-  return 0;
-}
-
-int
-mu_debug_get_locus (mu_debug_t debug, struct mu_debug_locus *ploc)
-{
-  if (!debug)
-    return EINVAL;
-  *ploc = debug->locus;
-  return 0;
-}
-
-int
-mu_debug_set_function (mu_debug_t debug, const char *function)
-{
-  if (!debug)
-    return EINVAL;
-  debug->function = function;
-  return 0;
-}
-
-int
-mu_debug_get_function (mu_debug_t debug, const char **pfunction)
-{
-  if (!debug)
-    return EINVAL;
-  *pfunction = debug->function;
-  return 0;
-}
-
diff --git a/libmailutils/diag.c b/libmailutils/diag.c
deleted file mode 100644
index 7497c82..0000000
--- a/libmailutils/diag.c
+++ /dev/null
@@ -1,179 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2005, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <syslog.h>
-#include <string.h>
-#include <mailutils/diag.h>
-#include <mailutils/nls.h>
-#include <mailutils/errno.h>
-
-const char *mu_program_name;
-mu_debug_t mu_diag_debug;
-
-void
-mu_set_program_name (const char *name)
-{
-  const char *progname;
-
-  if (!name)
-    progname = name;
-  else
-    {
-      progname = strrchr (name, '/');
-      if (progname)
-       progname++;
-      else
-       progname = name;
-      
-      if (strlen (progname) > 3 && memcmp (progname, "lt-", 3) == 0)
-       progname += 3;
-    }
-  
-  mu_program_name = progname;
-}
-
-void
-mu_diag_init ()
-{
-  if (!mu_diag_debug)
-    {
-      int rc = mu_debug_create (&mu_diag_debug, NULL);
-      if (rc)
-       {
-         fprintf (stderr,
-                  _("cannot initialize debug object for diagnostics: %s\n"),
-                  mu_strerror (rc));
-         /* That's a fatal error */
-         abort ();
-       }
-      mu_debug_set_print (mu_diag_debug, mu_diag_stderr_printer, NULL);
-    }
-}
-
-void
-mu_diag_get_debug (mu_debug_t *pdebug)
-{
-  mu_diag_init ();
-  *pdebug = mu_diag_debug;
-}
-
-void
-mu_diag_set_debug (mu_debug_t debug)
-{
-  if (mu_diag_debug)
-    mu_debug_destroy (&mu_diag_debug, NULL);
-  mu_diag_debug = debug;
-}
-
-void
-mu_diag_vprintf (mu_log_level_t level, const char *fmt, va_list ap)
-{
-  mu_diag_init ();  
-  mu_debug_vprintf (mu_diag_debug, level, fmt, ap);
-}
-
-void
-mu_diag_printf (mu_log_level_t level, const char *fmt, ...)
-{
-  va_list ap;
-  va_start (ap, fmt);
-  mu_diag_vprintf (level, fmt, ap);
-  va_end (ap);
-}
-
-void
-mu_diag_voutput (mu_log_level_t level, const char *fmt, va_list ap)
-{
-  mu_diag_init ();  
-  mu_debug_vprintf (mu_diag_debug, level, fmt, ap);
-  mu_debug_printf (mu_diag_debug, level, "\n");
-}
-
-void
-mu_diag_output (mu_log_level_t level, const char *fmt, ...)
-{
-  va_list ap;
-  va_start (ap, fmt);
-  mu_diag_voutput (level, fmt, ap);
-  va_end (ap);
-}
-
-const char *
-mu_diag_level_to_string (mu_log_level_t level)
-{
-  switch (level)
-    {
-    case MU_DIAG_EMERG:
-      return _("emergency");
-      
-    case MU_DIAG_ALERT:
-      return _("alert");
-       
-    case MU_DIAG_CRIT:
-      return _("critical");
-      
-    case MU_DIAG_ERROR:
-      return _("error");
-      
-    case MU_DIAG_WARNING:
-      return _("warning");
-      
-    case MU_DIAG_NOTICE:
-      return _("notice");
-      
-    case MU_DIAG_INFO:
-      return _("info");
-      
-    case MU_DIAG_DEBUG:
-      return _("debug");
-    }
-  return _("unknown");
-}
-
-int
-mu_diag_stderr_printer (void *data, mu_log_level_t level, const char *buf)
-{
-  if (mu_program_name)
-    fprintf (stderr, "%s: ", mu_program_name);
-  if (level != MU_DIAG_ERROR)
-    fprintf (stderr, "%s: ", mu_diag_level_to_string (level));
-  fputs (buf, stderr);
-  return 0;
-}
-
-void
-mu_diag_funcall (mu_log_level_t level, const char *func,
-                const char *arg, int err)
-{
-  if (err)
-    /* TRANSLATORS: First %s stands for function name, second for its
-       arguments, third one for the actual error message. */
-    mu_diag_output (level, _("%s(%s) failed: %s"), func, arg ? arg : "",
-                   mu_strerror (err));
-  else
-    /* TRANSLATORS: First %s stands for function name, second for its
-       arguments. */
-    mu_diag_output (level, _("%s(%s) failed"), func, arg ? arg : "");
-}
diff --git a/libmailutils/diag/.gitignore b/libmailutils/diag/.gitignore
new file mode 100644
index 0000000..f200331
--- /dev/null
+++ b/libmailutils/diag/.gitignore
@@ -0,0 +1 @@
+muerrno.c
diff --git a/libmailutils/diag/Makefile.am b/libmailutils/diag/Makefile.am
new file mode 100644
index 0000000..f2dae72
--- /dev/null
+++ b/libmailutils/diag/Makefile.am
@@ -0,0 +1,42 @@
+# 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/>.
+
+noinst_LTLIBRARIES = libdiag.la
+
+libdiag_la_SOURCES = \
+ debug.c\
+ diag.c\
+ gdebug.c\
+ muerror.c\
+ muerrno.c\
+ syslog.c\
+ dbgstderr.c\
+ dbgsyslog.c
+
+INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
+
+EXTRA_DIST = \
+ errors\
+ muerrno.cin
+
+BUILT_SOURCES = muerrno.c
+
+muerrno.c: errors muerrno.cin
+       $(AWK) -f $(mu_aux_dir)/generr.awk $^ > $@
+
+
+
diff --git a/libmailutils/diag/dbgstderr.c b/libmailutils/diag/dbgstderr.c
new file mode 100644
index 0000000..caaf248
--- /dev/null
+++ b/libmailutils/diag/dbgstderr.c
@@ -0,0 +1,35 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2010 Free Software
+   Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <mailutils/debug.h>
+#include <stdio.h>
+
+int
+mu_debug_stderr_printer (void *unused, mu_log_level_t level, const char *str)
+{
+  fprintf (stderr, "%s: %s",
+          (level == MU_DEBUG_ERROR) ? "ERROR" : "DEBUG",
+          str);
+  return 0;
+}
+
+
diff --git a/libmailutils/diag/dbgsyslog.c b/libmailutils/diag/dbgsyslog.c
new file mode 100644
index 0000000..af6f2fe
--- /dev/null
+++ b/libmailutils/diag/dbgsyslog.c
@@ -0,0 +1,33 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2010 Free Software
+   Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <mailutils/debug.h>
+#include <syslog.h>
+
+int
+mu_debug_syslog_printer (void *unused, mu_log_level_t level, const char *str)
+{
+  syslog ((level == MU_DEBUG_ERROR) ? LOG_ERR : LOG_DEBUG, "%s", str);
+  return 0;
+}
+
+
diff --git a/libmailutils/diag/debug.c b/libmailutils/diag/debug.c
new file mode 100644
index 0000000..749a04b
--- /dev/null
+++ b/libmailutils/diag/debug.c
@@ -0,0 +1,298 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2008, 2010 Free
+   Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <mailutils/errno.h>
+#include <mailutils/nls.h>
+#include <mailutils/sys/debug.h>
+
+mu_debug_printer_fp mu_debug_default_printer = mu_debug_stderr_printer;
+
+int
+mu_debug_create (mu_debug_t *pdebug, void *owner)
+{
+  mu_debug_t debug;
+  if (pdebug == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  debug = calloc (sizeof (*debug), 1);
+  if (debug == NULL)
+    return ENOMEM;
+  debug->printer = NULL;
+  debug->owner = owner;
+  *pdebug = debug;
+  return 0;
+}
+
+void
+mu_debug_destroy (mu_debug_t *pdebug, void *owner)
+{
+  if (pdebug && *pdebug)
+    {
+      mu_debug_t debug = *pdebug;
+      if (debug->owner == owner)
+       {
+         if (debug->stream)
+           {
+             mu_off_t len = 0;
+             int rc = mu_stream_size (debug->stream, &len);
+             if (rc == 0 && len)
+               /* Flush leftover data */
+               mu_debug_printf (debug, 0, "\n");
+
+             mu_stream_destroy (&debug->stream);
+           }
+         if (debug->destroy)
+           debug->destroy (debug->data);
+         free (*pdebug);
+         *pdebug = NULL;
+       }
+    }
+}
+
+void *
+mu_debug_get_owner (mu_debug_t debug)
+{
+  return (debug) ? debug->owner : NULL;
+}
+
+int
+mu_debug_set_level (mu_debug_t debug, mu_log_level_t level)
+{
+  if (debug == NULL)
+    return EINVAL;
+  debug->level = level;
+  return 0;
+}
+
+int
+mu_debug_get_level (mu_debug_t debug, mu_log_level_t *plevel)
+{
+  if (debug == NULL)
+    return EINVAL;
+  if (plevel)
+    *plevel = debug->level;
+  return 0;
+}
+
+int
+mu_debug_set_print (mu_debug_t debug, mu_debug_printer_fp printer, void *owner)
+{
+  if (debug == NULL)
+    return EINVAL;
+  if (debug->owner != owner)
+    return EACCES;
+  debug->printer = printer;
+  return 0;
+}
+
+int
+mu_debug_set_data (mu_debug_t debug, void *data, void (*destroy) (void*),
+                  void *owner)
+{
+  if (!debug)
+    return EINVAL;
+  if (debug->owner != owner)
+    return EACCES;
+  debug->data = data;
+  debug->destroy = destroy;
+  return 0;
+}
+
+static void
+debug_format_prefix (mu_debug_t debug)
+{
+  int need_space = 0;
+  if (debug->locus.file)
+    {
+      mu_stream_printf (debug->stream, "%s:%d:",
+                       debug->locus.file, debug->locus.line);
+      need_space = 1;
+    }
+  
+  if (debug->function)
+    {
+      mu_stream_printf (debug->stream, "%s:", debug->function);
+      need_space = 1;
+    }
+  
+  if (need_space)
+    mu_stream_write (debug->stream, " ", 1, NULL);
+}
+
+int
+mu_debug_vprintf (mu_debug_t debug, mu_log_level_t level,
+                 const char *format, va_list ap)
+{
+  mu_debug_printer_fp printer;
+  
+  if (debug == NULL || format == NULL)
+    return EINVAL;
+
+  printer = debug->printer ? debug->printer : mu_debug_default_printer;
+  if (printer)
+    {
+      mu_off_t len;
+      mu_transport_t tbuf[2];
+      char *ptr, *start, *p;
+      size_t nseg;
+      
+      if (debug->stream == NULL)
+       {
+         int rc = mu_memory_stream_create (&debug->stream, 0);
+         if (rc)
+           {
+             fprintf (stderr,
+                      _("cannot create memory stream for debugging "
+                        "output: %s\n"),
+                      mu_strerror (rc));
+             vfprintf (stderr, format, ap);
+             return rc;
+           }
+       }
+
+      if (mu_stream_size (debug->stream, &len) == 0 && len == 0)
+       debug_format_prefix (debug);
+      
+      mu_stream_vprintf (debug->stream, format, ap);
+
+      mu_stream_ioctl (debug->stream, MU_IOCTL_GET_TRANSPORT, tbuf);
+      start = (char*) tbuf[0];
+      mu_stream_size (debug->stream, &len);
+      ptr = start;
+      nseg = 0;
+      for (p = ptr = start; p < start + len; p++)
+       {
+         if (*p == '\n')
+           {
+             int c = *++p;
+             *p = 0;
+             printer (debug->data, level, ptr);
+             *p = c;
+             ptr = p;
+             nseg++;
+           }
+       }
+
+      if (nseg)
+       {
+         if (start[len - 1] != '\n')
+           {
+             size_t s = len - (ptr - start);
+             memmove (start, ptr, s);
+           }
+         else
+           len = 0;
+
+         mu_stream_truncate (debug->stream, len);
+         mu_stream_seek (debug->stream, len, SEEK_SET, NULL);
+       }
+    }
+  else
+    vfprintf (stderr, format, ap);
+
+  return 0;
+}
+
+int
+mu_debug_printf (mu_debug_t debug, mu_log_level_t level,
+                const char *format, ...)
+{
+  va_list ap;
+
+  va_start (ap, format);
+  mu_debug_vprintf (debug, level, format, ap);
+  va_end (ap);
+  return 0;
+}
+  
+
+int
+mu_debug_print (mu_debug_t debug, mu_log_level_t level,
+               const char *format, ...)
+{
+  va_list ap;
+  va_start(ap, format);
+  mu_debug_printv (debug, level, format, ap);
+  va_end (ap);
+  return 0;
+}
+
+int
+mu_debug_printv (mu_debug_t debug, mu_log_level_t level, const char *format,
+                va_list ap)
+{
+  if (debug == NULL || format == NULL)
+    return EINVAL;
+  if (debug->level & MU_DEBUG_LEVEL_MASK (level))
+    return 0;
+  return mu_debug_vprintf (debug, level, format, ap);
+}
+
+int
+mu_debug_check_level (mu_debug_t debug, mu_log_level_t level)
+{
+  if (!debug)
+    return 0;
+  return debug->level & MU_DEBUG_LEVEL_MASK (level);
+}
+
+int
+mu_debug_set_locus (mu_debug_t debug, const char *file, int line)
+{
+  if (!debug)
+    return EINVAL;
+  debug->locus.file = file;
+  debug->locus.line = line;
+  return 0;
+}
+
+int
+mu_debug_get_locus (mu_debug_t debug, struct mu_debug_locus *ploc)
+{
+  if (!debug)
+    return EINVAL;
+  *ploc = debug->locus;
+  return 0;
+}
+
+int
+mu_debug_set_function (mu_debug_t debug, const char *function)
+{
+  if (!debug)
+    return EINVAL;
+  debug->function = function;
+  return 0;
+}
+
+int
+mu_debug_get_function (mu_debug_t debug, const char **pfunction)
+{
+  if (!debug)
+    return EINVAL;
+  *pfunction = debug->function;
+  return 0;
+}
+
diff --git a/libmailutils/diag/diag.c b/libmailutils/diag/diag.c
new file mode 100644
index 0000000..55372af
--- /dev/null
+++ b/libmailutils/diag/diag.c
@@ -0,0 +1,178 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2005, 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/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <syslog.h>
+#include <string.h>
+#include <mailutils/diag.h>
+#include <mailutils/nls.h>
+#include <mailutils/errno.h>
+
+const char *mu_program_name;
+mu_debug_t mu_diag_debug;
+
+void
+mu_set_program_name (const char *name)
+{
+  const char *progname;
+
+  if (!name)
+    progname = name;
+  else
+    {
+      progname = strrchr (name, '/');
+      if (progname)
+       progname++;
+      else
+       progname = name;
+      
+      if (strlen (progname) > 3 && memcmp (progname, "lt-", 3) == 0)
+       progname += 3;
+    }
+  
+  mu_program_name = progname;
+}
+
+void
+mu_diag_init ()
+{
+  if (!mu_diag_debug)
+    {
+      int rc = mu_debug_create (&mu_diag_debug, NULL);
+      if (rc)
+       {
+         fprintf (stderr,
+                  _("cannot initialize debug object for diagnostics: %s\n"),
+                  mu_strerror (rc));
+         /* That's a fatal error */
+         abort ();
+       }
+      mu_debug_set_print (mu_diag_debug, mu_diag_stderr_printer, NULL);
+    }
+}
+
+void
+mu_diag_get_debug (mu_debug_t *pdebug)
+{
+  mu_diag_init ();
+  *pdebug = mu_diag_debug;
+}
+
+void
+mu_diag_set_debug (mu_debug_t debug)
+{
+  if (mu_diag_debug)
+    mu_debug_destroy (&mu_diag_debug, NULL);
+  mu_diag_debug = debug;
+}
+
+void
+mu_diag_vprintf (mu_log_level_t level, const char *fmt, va_list ap)
+{
+  mu_diag_init ();  
+  mu_debug_vprintf (mu_diag_debug, level, fmt, ap);
+}
+
+void
+mu_diag_printf (mu_log_level_t level, const char *fmt, ...)
+{
+  va_list ap;
+  va_start (ap, fmt);
+  mu_diag_vprintf (level, fmt, ap);
+  va_end (ap);
+}
+
+void
+mu_diag_voutput (mu_log_level_t level, const char *fmt, va_list ap)
+{
+  mu_diag_init ();  
+  mu_debug_vprintf (mu_diag_debug, level, fmt, ap);
+  mu_debug_printf (mu_diag_debug, level, "\n");
+}
+
+void
+mu_diag_output (mu_log_level_t level, const char *fmt, ...)
+{
+  va_list ap;
+  va_start (ap, fmt);
+  mu_diag_voutput (level, fmt, ap);
+  va_end (ap);
+}
+
+const char *
+mu_diag_level_to_string (mu_log_level_t level)
+{
+  switch (level)
+    {
+    case MU_DIAG_EMERG:
+      return _("emergency");
+      
+    case MU_DIAG_ALERT:
+      return _("alert");
+       
+    case MU_DIAG_CRIT:
+      return _("critical");
+      
+    case MU_DIAG_ERROR:
+      return _("error");
+      
+    case MU_DIAG_WARNING:
+      return _("warning");
+      
+    case MU_DIAG_NOTICE:
+      return _("notice");
+      
+    case MU_DIAG_INFO:
+      return _("info");
+      
+    case MU_DIAG_DEBUG:
+      return _("debug");
+    }
+  return _("unknown");
+}
+
+int
+mu_diag_stderr_printer (void *data, mu_log_level_t level, const char *buf)
+{
+  if (mu_program_name)
+    fprintf (stderr, "%s: ", mu_program_name);
+  if (level != MU_DIAG_ERROR)
+    fprintf (stderr, "%s: ", mu_diag_level_to_string (level));
+  fputs (buf, stderr);
+  return 0;
+}
+
+void
+mu_diag_funcall (mu_log_level_t level, const char *func,
+                const char *arg, int err)
+{
+  if (err)
+    /* TRANSLATORS: First %s stands for function name, second for its
+       arguments, third one for the actual error message. */
+    mu_diag_output (level, _("%s(%s) failed: %s"), func, arg ? arg : "",
+                   mu_strerror (err));
+  else
+    /* TRANSLATORS: First %s stands for function name, second for its
+       arguments. */
+    mu_diag_output (level, _("%s(%s) failed"), func, arg ? arg : "");
+}
diff --git a/libmailutils/diag/errors b/libmailutils/diag/errors
new file mode 100644
index 0000000..5f82f7b
--- /dev/null
+++ b/libmailutils/diag/errors
@@ -0,0 +1,94 @@
+# Error messages for GNU Mailutils
+# Copyright (C) 2005, 2006, 2007, 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/>. 
+
+MU_ERR_FAILURE              _("Operation failed")
+MU_ERR_CANCELED             _("Operation canceled")
+
+MU_ERR_NO_HANDLER           _("No registered handler")
+MU_ERR_EMPTY_VFN            _("Empty virtual function")
+
+MU_ERR_OUT_NULL             _("Pointer to output null")
+MU_ERR_OUT_PTR_NULL         _("Pointer to output pointer null")
+
+MU_ERR_MBX_NULL             _("Mailbox null")
+MU_ERR_MBX_REMOVED          _("Mailbox removed")
+
+MU_ERR_NOT_OPEN             _("Resource not open")
+MU_ERR_OPEN                 _("Resource is already open")
+
+MU_ERR_BAD_822_FORMAT       _("Format of RFC822 object is bad")
+MU_ERR_EMPTY_ADDRESS        _("Address contains no addr specs")
+
+MU_ERR_LOCKER_NULL          _("Locker null")
+MU_ERR_LOCK_CONFLICT        _("Conflict with previous locker")
+MU_ERR_LOCK_BAD_LOCK        _("Lock file check failed")
+MU_ERR_LOCK_BAD_FILE        _("File check failed")
+MU_ERR_LOCK_NOT_HELD        _("Lock not held on file")
+MU_ERR_LOCK_EXT_FAIL        _("Failed to execute external locker")
+MU_ERR_LOCK_EXT_ERR         _("External locker failed")
+MU_ERR_LOCK_EXT_KILLED      _("External locker killed")
+
+MU_ERR_NO_SUCH_USER         _("No such user name")
+
+MU_ERR_GETHOSTBYNAME        _("DNS name resolution failed")
+MU_ERR_BAD_RESUMPTION       _("State busy must resume operation")
+MU_ERR_MAILER_BAD_FROM      _("Not a valid mailer from address")
+MU_ERR_MAILER_BAD_TO        _("Not a valid mailer to address")
+MU_ERR_MAILER_NO_RCPT_TO    _("No receipt addresses found")
+MU_ERR_MAILER_BAD_URL       _("Malformed or unsupported mailer URL")
+MU_ERR_SMTP_RCPT_FAILED     _("SMTP rcpt to command failed")
+MU_ERR_TCP_NO_HOST          _("Tcp connections need a host")
+MU_ERR_TCP_NO_PORT          _("Tcp connections need a postive port")
+
+MU_ERR_BAD_2047_INPUT       _("Input string is not RFC 2047 encoded")
+MU_ERR_BAD_2047_ENCODING    _("Not a valid RFC 2047 encoding")
+
+MU_ERR_NOUSERNAME           _("User name is not supplied")
+MU_ERR_NOPASSWORD           _("User password is not supplied")
+MU_ERR_BADREPLY             _("Invalid reply from the remote host")
+
+MU_ERR_SEQ                  _("Bad command sequence")
+MU_ERR_REPLY                _("Erroneous reply received")
+
+MU_ERR_UNSAFE_PERMS         _("Unsafe file permissions. Set 0600")
+MU_ERR_BAD_AUTH_SCHEME      _("Unsupported authentication scheme")
+MU_ERR_AUTH_FAILURE         _("Authentication failed")
+
+MU_ERR_PROCESS_NOEXEC       _("Cannot execute")
+MU_ERR_PROCESS_EXITED       _("Process exited with a non-zero status")
+MU_ERR_PROCESS_SIGNALED     _("Process exited on signal")
+MU_ERR_PROCESS_UNKNOWN_FAILURE _("Unknown failure while executing subprocess")
+MU_ERR_CONN_CLOSED          _("Connection closed by remote host")
+MU_ERR_PARSE                _("Parse error")
+MU_ERR_NOENT                _("Requested item not found")
+MU_ERR_EXISTS               _("Item already exists")
+MU_ERR_BUFSPACE             _("Not enough buffer space")
+
+MU_ERR_SQL                  _("SQL error")
+MU_ERR_DB_ALREADY_CONNECTED _("Already connected to the database")
+MU_ERR_DB_NOT_CONNECTED     _("Not connected to the database")
+MU_ERR_RESULT_NOT_RELEASED  _("Result of the previous query is not released")
+MU_ERR_NO_QUERY             _("No query was yet executed")
+MU_ERR_BAD_COLUMN           _("Bad column address")
+MU_ERR_NO_RESULT            _("No result from the previous query available")
+MU_ERR_NO_INTERFACE         _("No such interface")
+
+MU_ERR_BADOP                _("Inappropriate operation for this mode")
+MU_ERR_BAD_FILENAME         _("Badly formed file or directory name")
+MU_ERR_READ                 _("Read error")
+
+MU_ERR_NO_TRANSPORT         _("Transport stream not set")
+MU_ERR_AUTH_NO_CRED         _("No credentials supplied")
diff --git a/libmailutils/diag/gdebug.c b/libmailutils/diag/gdebug.c
new file mode 100644
index 0000000..7e6f63c
--- /dev/null
+++ b/libmailutils/diag/gdebug.c
@@ -0,0 +1,262 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2008, 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/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <mailutils/cctype.h>
+#include <mailutils/assoc.h>
+#include <mailutils/error.h>
+#include <mailutils/errno.h>
+#include <mailutils/argcv.h>
+#include <mailutils/debug.h>
+#include <mailutils/cfg.h>
+#include <mailutils/nls.h>
+
+int mu_debug_line_info = 0;
+
+struct debug_level
+{
+  unsigned level;
+};
+
+static mu_assoc_t debug_table;
+
+mu_log_level_t
+mu_global_debug_level (const char *object_name)
+{
+  struct debug_level *p = mu_assoc_ref (debug_table, object_name);
+  if (p)
+    return p->level;
+  return 0;
+}
+
+int
+mu_global_debug_set_level (const char *object_name, mu_log_level_t level)
+{
+  int rc;
+  struct debug_level *dbg;
+  
+  if (!debug_table)
+    {
+      rc = mu_assoc_create (&debug_table, sizeof(struct debug_level), 0);
+      if (rc)
+       return rc;
+    }
+
+  rc = mu_assoc_ref_install (debug_table, object_name, (void**) &dbg);
+  if (rc == 0 || rc == MU_ERR_EXISTS)
+    dbg->level = level;
+  return rc;
+}
+
+int
+mu_global_debug_clear_level (const char *object_name)
+{
+  int rc = 0;
+  
+  if (!object_name)
+    mu_assoc_clear (debug_table);
+  else
+    rc = mu_assoc_remove (debug_table, object_name);
+  return rc;
+}
+
+int
+decode_debug_level (const char *p, int *lev)
+{
+  if (strcmp (p, "error") == 0)
+    *lev = MU_DEBUG_ERROR;
+  else if (strncmp (p, "trace", 5) == 0 && mu_isdigit (p[5]) && p[6] == 0)
+    *lev = MU_DEBUG_TRACE0 + atoi (p + 5);
+  else if (strcmp (p, "proto") == 0)
+    *lev = MU_DEBUG_PROT;
+  else
+    return 1;
+  return 0;
+}
+
+int
+mu_debug_level_from_string (const char *string, mu_log_level_t *plev,
+                           mu_debug_t debug)
+{
+  char *q;
+  unsigned level = MU_DEBUG_INHERIT;
+  
+  if (mu_isdigit (*string))
+    {
+      level = strtoul (string, &q, 0);
+      if (*q)
+       {
+         mu_cfg_format_error (debug, MU_DEBUG_ERROR,
+                              _("invalid debugging specification `%s': "
+                                "expected levels or number after `=', "
+                                "but found `%s'"),
+                              string, string);
+         return MU_ERR_FAILURE;
+       }
+    }
+  else
+    {
+      char *p = strdup (string);
+      size_t len = strlen (p);
+      if (len > 0 && p[len-1] == '\n')
+       p[len-1] = 0;
+      for (q = strtok (p, ","); q; q = strtok (NULL, ","))
+       {
+         int flag;
+         int revert = 0;
+         int upto = 0;
+         
+         if (*q == '!')
+           {
+             q++;
+             revert = 1;
+           }
+         if (*q == '<')
+           {
+             q++;
+             upto = 1;
+           }
+         
+         if (decode_debug_level (q, &flag))
+           mu_cfg_format_error (debug, MU_DEBUG_ERROR,
+                                _("invalid debugging level `%s'"),
+                                q);
+         else if (revert)
+           {
+             if (upto)
+               level &= ~MU_DEBUG_LEVEL_UPTO (flag);
+             else
+               level &= ~MU_DEBUG_LEVEL_MASK (flag);
+           }
+         else
+           {
+             if (upto)
+               level |= MU_DEBUG_LEVEL_UPTO (flag);
+             else
+               level |= MU_DEBUG_LEVEL_MASK (flag);
+           }
+       }
+      free (p);
+    }
+  *plev = level;
+  return 0;
+}
+
+int
+mu_global_debug_from_string (const char *string, const char *errpfx)
+{
+  int rc;
+  int argc;
+  char **argv;
+  int i;
+  
+  rc = mu_argcv_get (string, ";", NULL, &argc, &argv);
+  if (rc)
+    return rc;
+
+  for (i = 0; i < argc; i++)
+    {
+      char *p;
+      mu_log_level_t level = MU_DEBUG_INHERIT;
+      char *object_name = argv[i];
+      
+      for (p = object_name; *p && *p != '='; p++)
+       ;
+
+      if (*p == '=')
+       {
+         /* FIXME: Use mu_debug_level_from_string */
+         char *q;
+         
+         *p++ = 0;
+         if (mu_isdigit (*p))
+           {
+             level = strtoul (p, &q, 0);
+             if (*q)
+               {
+                 mu_error ("%s: invalid debugging specification `%s': "
+                           "expected levels or number after `=', "
+                           "but found `%s'",
+                           errpfx, argv[i], p);
+                 break;
+               }
+           }
+         else
+           {
+             char *q;
+             for (q = strtok (p, ","); q; q = strtok (NULL, ","))
+               {
+                 int flag;
+                 int revert = 0;
+                 int upto = 0;
+                 
+                 if (*q == '!')
+                   {
+                     q++;
+                     revert = 1;
+                   }
+                 if (*q == '<')
+                   {
+                     q++;
+                     upto = 1;
+                   }
+                 
+                 if (decode_debug_level (q, &flag))
+                   mu_error ("%s: invalid debugging level `%s'",
+                             errpfx, q);
+                 else if (revert)
+                   {
+                     if (upto)
+                       level &= ~MU_DEBUG_LEVEL_UPTO (flag);
+                     else
+                       level &= ~MU_DEBUG_LEVEL_MASK (flag);
+                   }
+                 else
+                   {
+                     if (upto)
+                       level |= MU_DEBUG_LEVEL_UPTO (flag);
+                     else
+                       level |= MU_DEBUG_LEVEL_MASK (flag);
+                   }
+               }
+           }   
+       }         
+      else
+       level |= MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT);
+      
+      if (p[-1] == ':')
+       {
+         p[-1] = 0;
+         level &= ~MU_DEBUG_INHERIT;
+       }
+      
+      mu_global_debug_set_level (object_name, level);
+    }
+  
+  mu_argcv_free (argc, argv);
+  return 0;
+}
+
+
diff --git a/libmailutils/diag/muerrno.cin b/libmailutils/diag/muerrno.cin
new file mode 100644
index 0000000..e448159
--- /dev/null
+++ b/libmailutils/diag/muerrno.cin
@@ -0,0 +1,65 @@
+/* -*- c -*- $AUTOWARN
+   GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2010
+   Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library.  If not, see 
<http://www.gnu.org/licenses/>.
+*/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+
+#include <mailutils/errno.h>
+#include <mailutils/nls.h>
+
+#ifndef EOK
+# define EOK 0
+#endif
+
+const char*
+mu_errname (int e)
+{
+  static char buf[128];
+  
+  switch (e)
+    {
+    case EOK:
+      return "EOK";
+
+      $MESSAGE_CODES
+    }
+
+  snprintf (buf, sizeof buf, _("Error %d"), e);
+  return buf;
+}
+
+const char *
+mu_strerror (int e)
+{
+  switch (e)
+    {
+    case EOK:
+      return _("Success");
+
+    $MESSAGE_STRINGS
+    }
+
+  return strerror (e);
+}
+
diff --git a/libmailutils/diag/muerror.c b/libmailutils/diag/muerror.c
new file mode 100644
index 0000000..3b0b38e
--- /dev/null
+++ b/libmailutils/diag/muerror.c
@@ -0,0 +1,116 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2005, 2007, 2010 Free Software
+   Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <syslog.h>
+#include <string.h>
+#include <mailutils/error.h>
+
+
+/* Historic shortcuts for mu_diag_ functions */
+
+int
+mu_verror (const char *fmt, va_list ap)
+{
+  mu_diag_voutput (MU_DIAG_ERROR, fmt, ap);
+  return 0;
+}
+
+int
+mu_error (const char *fmt, ...)
+{
+  va_list ap;
+  va_start (ap, fmt);
+  mu_verror (fmt, ap);
+  va_end (ap);
+  return 0;
+}
+
+
+/* Compatibility layer */
+int
+mu_default_error_printer (const char *fmt, va_list ap)
+{
+  if (mu_program_name)
+    fprintf (stderr, "%s: ", mu_program_name);
+  vfprintf (stderr, fmt, ap);
+  fputc ('\n', stderr);
+  return 0;
+}
+
+int
+mu_syslog_error_printer (const char *fmt, va_list ap)
+{
+#ifdef HAVE_VSYSLOG
+  vsyslog (LOG_CRIT, fmt, ap);
+#else
+  char buf[128];
+  vsnprintf (buf, sizeof buf, fmt, ap);
+  syslog (LOG_CRIT, "%s", buf);
+#endif
+  return 0;
+}
+
+static void
+compat_error_printer0 (mu_error_pfn_t pfn, const char *fmt, ...)
+{
+  va_list ap;
+  va_start (ap, fmt);
+  pfn (fmt, ap);
+  va_end (ap);
+}
+
+static int
+compat_error_printer (void *data, mu_log_level_t level, const char *buf)
+{
+  if (!data)
+    mu_diag_stderr_printer (NULL, level, buf);
+  else
+    {
+      int len = strlen (buf);
+      if (len > 0 && buf[len-1] == '\n')
+       len--;
+      compat_error_printer0 (data, "%-.*s", len, buf);
+    }
+  return 0;
+}
+
+void
+mu_error_set_print (mu_error_pfn_t pfn)
+{
+  mu_debug_t debug;
+  mu_diag_get_debug (&debug);
+  mu_debug_set_print (debug, compat_error_printer, NULL);
+  mu_debug_set_data (debug, pfn, NULL, NULL);
+#if 0
+ {
+   static int warned;
+   if (!warned)
+     {
+       warned = 1;
+       mu_diag_output ("this program uses mu_error_set_print, which is 
deprecated");
+     }
+#endif
+}
+
+
diff --git a/libmailutils/diag/syslog.c b/libmailutils/diag/syslog.c
new file mode 100644
index 0000000..da7d233
--- /dev/null
+++ b/libmailutils/diag/syslog.c
@@ -0,0 +1,145 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by the
+   Free Software Foundation; either version 3 of the License, or (at your
+   option) any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <syslog.h>
+#include <string.h>
+#include <mailutils/diag.h>
+#include <mailutils/kwd.h>
+#include <mailutils/syslog.h>
+#include <mailutils/cstr.h>
+
+#ifndef LOG_AUTHPRIV
+# define LOG_AUTHPRIV
+#endif
+
+static mu_kwd_t kw_facility[] = {
+  { "USER",    LOG_USER },   
+  { "DAEMON",  LOG_DAEMON },
+  { "AUTH",    LOG_AUTH },
+  { "AUTHPRIV",LOG_AUTHPRIV },
+  { "MAIL",    LOG_MAIL },
+  { "CRON",    LOG_CRON },
+  { "LOCAL0",  LOG_LOCAL0 },
+  { "LOCAL1",  LOG_LOCAL1 },
+  { "LOCAL2",  LOG_LOCAL2 },
+  { "LOCAL3",  LOG_LOCAL3 },
+  { "LOCAL4",  LOG_LOCAL4 },
+  { "LOCAL5",  LOG_LOCAL5 },
+  { "LOCAL6",  LOG_LOCAL6 },
+  { "LOCAL7",  LOG_LOCAL7 },
+  { NULL }
+};
+
+static int
+syslog_to_n (mu_kwd_t *kw, const char *str, int *pint)
+{
+  if (mu_c_strncasecmp (str, "LOG_", 4) == 0)
+    str += 4;
+  return mu_kwd_xlat_name_ci (kw, str, pint);
+}
+
+int
+mu_string_to_syslog_facility (const char *str, int *pfacility)
+{
+  return syslog_to_n (kw_facility, str, pfacility);
+}
+
+const char *
+mu_syslog_facility_to_string (int n)
+{
+  const char *res = NULL;
+  mu_kwd_xlat_tok (kw_facility, n, &res);
+  return res;
+}
+
+static mu_kwd_t kw_prio[] = {
+  { "EMERG", LOG_EMERG },
+  { "ALERT", LOG_ALERT },
+  { "CRIT", LOG_CRIT },
+  { "ERR", LOG_ERR },
+  { "WARNING", LOG_WARNING },
+  { "NOTICE", LOG_NOTICE },
+  { "INFO", LOG_INFO },
+  { "DEBUG", LOG_DEBUG },
+  { NULL }
+};
+
+int
+mu_string_to_syslog_priority (const char *str, int *pprio)
+{
+  return syslog_to_n (kw_prio, str, pprio);
+}
+
+const char *
+mu_syslog_priority_to_string (int n)
+{
+  const char *res = NULL;
+  mu_kwd_xlat_tok (kw_prio, n, &res);
+  return res;
+}
+
+int
+mu_diag_level_to_syslog (mu_log_level_t level)
+{
+  switch (level)
+    {
+    case MU_DIAG_EMERG:
+      return LOG_EMERG;
+      
+    case MU_DIAG_ALERT:
+      return LOG_ALERT;
+       
+    case MU_DIAG_CRIT:
+      return LOG_CRIT;
+      
+    case MU_DIAG_ERROR:
+      return LOG_ERR;
+      
+    case MU_DIAG_WARNING:
+      return LOG_WARNING;
+      
+    case MU_DIAG_NOTICE:
+      return LOG_NOTICE;
+      
+    case MU_DIAG_INFO:
+      return LOG_INFO;
+      
+    case MU_DIAG_DEBUG:
+      return LOG_DEBUG;
+    }
+  return LOG_EMERG;
+}
+
+int
+mu_diag_syslog_printer (void *data, mu_log_level_t level, const char *buf)
+{
+  int len = strlen (buf);
+  if (len > 0 && buf[len-1] == '\n')
+    {
+      len--;
+      if (len > 0 && buf[len-1] == '\r')
+       len--;
+    }
+  syslog (mu_diag_level_to_syslog (level), "%-.*s", len, buf);
+  return 0;
+}
+
+
+int mu_log_facility = LOG_FACILITY;
+char *mu_log_tag = NULL;
diff --git a/libmailutils/dot.c b/libmailutils/dot.c
deleted file mode 100644
index a0d43fa..0000000
--- a/libmailutils/dot.c
+++ /dev/null
@@ -1,268 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2003, 2007, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-/* This file implements a DOT filter, useful for data I/O in
-   such protocols as POP3 and SMTP.  When encoding, this filter
-   "byte-stuffs" the input by outputting an additional '.' in front
-   of any '.' appearing at the beginning of a line.  Upon closing the
-   filter in this mode, it outputs additional ".\n".
-   
-   When decoding, the reverse is performed: any '.' appearing at the
-   beginning of a line is removed.  A single dot on a line by itself
-   marks end of the stream.
-
-   MU also provides a hairy version of this filter, called CRLFDOT.
-   In addition to byte-stuffing, CRLFDOT also performs CRLF/LF translation.
- */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include <mailutils/errno.h>
-#include <mailutils/filter.h>
-#include <mailutils/stream.h>
-
-enum dot_decode_state
-  {
-    dot_decode_init,  /* initial state */
-    dot_decode_char,  /* Any character excepting [\r\n.] */
-    dot_decode_lf,    /* prev. char was \n */
-    dot_decode_dot,   /* 2 prev. chars were \n. */
-    dot_decode_end   /* final state, a \n.\n seen. */
-  };
-
-static enum dot_decode_state
-new_decode_state (enum dot_decode_state state, int c)
-{
-  switch (state)
-    {
-    case dot_decode_init:
-      switch (c)
-       {
-       case '.':
-         return dot_decode_dot;
-       }
-      break;
-      
-    case dot_decode_char:
-      switch (c)
-       {
-       case '\n':
-         return dot_decode_lf;
-       }
-      break;
-      
-    case dot_decode_lf:
-      switch (c)
-       {
-       case '.':
-         return dot_decode_dot;
-       }
-      
-    case dot_decode_dot:
-      switch (c)
-       {
-       case '\n':
-         return dot_decode_end;
-       }
-      break;
-
-    case dot_decode_end:
-      return dot_decode_end;
-    }
-  return dot_decode_char;
-}
-
-/* Move min(isize,osize) bytes from iptr to optr, replacing each \r\n
-   with \n. */
-static enum mu_filter_result
-_dot_decoder (void *xd,
-             enum mu_filter_command cmd,
-             struct mu_filter_io *iobuf)
-{
-  int *pstate = xd;
-  size_t i, j;
-  const unsigned char *iptr;
-  size_t isize;
-  char *optr;
-  size_t osize;
-
-  switch (cmd)
-    {
-    case mu_filter_init:
-      *pstate = dot_decode_init;
-      return mu_filter_ok;
-      
-    case mu_filter_done:
-      return mu_filter_ok;
-      
-    default:
-      break;
-    }
-  
-  iptr = (const unsigned char *) iobuf->input;
-  isize = iobuf->isize;
-  optr = iobuf->output;
-  osize = iobuf->osize;
-
-  for (i = j = 0; *pstate != dot_decode_end && i < isize && j < osize; i++)
-    {
-      unsigned char c = *iptr++;
-      int curstate = *pstate;
-      
-      *pstate = new_decode_state (curstate, c);
-      if (!(c == '.' && (curstate == dot_decode_init ||
-                        curstate == dot_decode_lf)))
-       optr[j++] = c;
-    }
-  
-  if (*pstate == dot_decode_end)
-    iobuf->eof = 1;
-
-  iobuf->isize = i;
-  iobuf->osize = j;
-  return mu_filter_ok;
-}
-
-enum dot_encode_state
-  {
-    dot_encode_init,  /* initial state */
-    dot_encode_char,  /* Any character excepting \n */
-    dot_encode_lf,    /* prev. char was \n */
-  };    
-
-static enum dot_encode_state
-new_encode_state (int c)
-{
-  switch (c)
-    {
-    case '\n':
-      return dot_encode_lf;
-    }
-  return dot_encode_char;
-}
-
-/* Move min(isize,osize) bytes from iptr to optr, replacing each \n
-   with \r\n.  Any input \r\n sequences remain untouched. */
-static enum mu_filter_result
-_dot_encoder (void *xd,
-             enum mu_filter_command cmd,
-             struct mu_filter_io *iobuf)
-{
-  enum mu_filter_result result;
-  size_t i, j;
-  const unsigned char *iptr;
-  size_t isize;
-  char *optr;
-  size_t osize;
-  int *state = xd;
-  
-  switch (cmd)
-    {
-    case mu_filter_init:
-      *state = dot_encode_init;
-      return mu_filter_ok;
-      
-    case mu_filter_done:
-      return mu_filter_ok;
-
-    default:
-      break;
-    }
-  
-  iptr = (const unsigned char *) iobuf->input;
-  isize = iobuf->isize;
-  optr = iobuf->output;
-  osize = iobuf->osize;
-
-  for (i = j = 0; i < isize && j < osize; i++, iptr++)
-    {
-      unsigned char c = *iptr;
-      int curstate = *state;
-
-      if (c == '.' && (curstate == dot_encode_init ||
-                      curstate == dot_encode_lf))
-       {
-         if (j + 2 > osize)
-           {
-             if (i == 0)
-               {
-                 iobuf->osize = 2;
-                 return mu_filter_moreoutput;
-               }
-             break;
-           }
-         optr[j++] = '.';
-         optr[j++] = '.';
-       }
-      else
-       optr[j++] = c;
-
-      *state = new_encode_state (c);
-    }
-
-  result = mu_filter_ok;
-  if (cmd == mu_filter_lastbuf)
-    {
-      switch (*state)
-       {
-       case dot_encode_lf:
-         if (j + 2 > osize)
-           result = mu_filter_again;
-         break;
-             
-       default:
-         if (j + 3 > osize)
-           result = mu_filter_again;
-         else
-           optr[j++] = '\n';
-       }
-
-      if (result == mu_filter_ok)
-       {
-         optr[j++] = '.';
-         optr[j++] = '\n';
-       }
-    }
-
-  iobuf->isize = i;
-  iobuf->osize = j;
-  return result;
-}
-
-static int
-alloc_state (void **pret, int mode MU_ARG_UNUSED, void *data MU_ARG_UNUSED)
-{
-  *pret = malloc (sizeof (int));
-  if (!*pret)
-    return ENOMEM;
-  return 0;
-}
-
-static struct _mu_filter_record _dot_filter = {
-  "DOT",
-  0,
-  alloc_state,
-  _dot_encoder,
-  _dot_decoder
-};
-
-mu_filter_record_t mu_dot_filter = &_dot_filter;
diff --git a/libmailutils/envelope.c b/libmailutils/envelope.c
deleted file mode 100644
index 1e5aa4a..0000000
--- a/libmailutils/envelope.c
+++ /dev/null
@@ -1,181 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2004, 2005, 2007, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <mailutils/errno.h>
-#include <mailutils/mutil.h>
-#include <mailutils/sys/envelope.h>
-
-int
-mu_envelope_create (mu_envelope_t *penvelope, void *owner)
-{
-  mu_envelope_t envelope;
-  if (penvelope == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  envelope = calloc (1, sizeof (*envelope));
-  if (envelope == NULL)
-    return ENOMEM;
-  envelope->owner = owner;
-  *penvelope = envelope;
-  return 0;
-}
-
-void
-mu_envelope_destroy (mu_envelope_t *penvelope, void *owner)
-{
-  if (penvelope && *penvelope)
-    {
-      mu_envelope_t envelope = *penvelope;
-      if (envelope->owner == owner)
-       {
-         if (envelope->_destroy)
-           envelope->_destroy (envelope);
-         free (envelope->date);
-         free (envelope->sender);
-         free (envelope);
-       }
-      *penvelope = NULL;
-    }
-}
-
-void *
-mu_envelope_get_owner (mu_envelope_t envelope)
-{
-  return (envelope) ? envelope->owner : NULL;
-}
-
-int
-mu_envelope_set_sender (mu_envelope_t envelope,
-                       int (*_sender) (mu_envelope_t, char *, size_t,
-                                       size_t*),
-                       void *owner)
-{
-  if (envelope == NULL)
-    return EINVAL;
-  if (envelope->owner != owner)
-    return EACCES;
-  envelope->_get_sender = _sender;
-  return 0;
-}
-
-int
-mu_envelope_set_date (mu_envelope_t envelope,
-                     int (*_date) (mu_envelope_t, char *, size_t , size_t *),
-                     void *owner)
-{
-  if (envelope == NULL)
-    return EINVAL;
-  if (envelope->owner != owner)
-    return EACCES;
-  envelope->_get_date = _date;
-  return 0;
-}
-
-
-/* General accessors: */
-#define AC2(a,b) a ## b
-#define AC4(a,b,c,d) a ## b ## c ## d
-#define ACCESSOR(action,field) AC4(mu_envelope_,action,_,field)
-
-#define DECL_SGET(field)                                                 \
-int                                                                      \
-ACCESSOR(sget,field) (mu_envelope_t env, char const **sptr)               \
-{                                                                        \
-  if (env == NULL)                                                       \
-    return EINVAL;                                                       \
-  if (!env->field)                                                       \
-    {                                                                     \
-      if (env->AC2(_get_,field))                                          \
-       {                                                                 \
-         size_t n;                                                       \
-         char *buf;                                                      \
-          int status;                                                     \
-                                                                         \
-         status = env->AC2(_get_,field) (env, NULL, 0, &n);              \
-         if (status)                                                     \
-           return status;                                                \
-                                                                         \
-         buf = malloc (n + 1);                                           \
-         if (!buf)                                                       \
-           return ENOMEM;                                                \
-                                                                         \
-         status = env->AC2(_get_,field) (env, buf, n + 1, NULL);         \
-         if (status)                                                     \
-            return status;                                               \
-                                                                         \
-          env->field = buf;                                               \
-       }                                                                 \
-      else                                                               \
-        return MU_ERR_NOENT;                                             \
-    }                                                                    \
-  *sptr = env->field;                                                    \
-  return 0;                                                              \
-}
-
-#define DECL_GET(field)                                                        
  \
-int                                                                      \
-ACCESSOR(get,field) (mu_envelope_t env, char *buf, size_t len, size_t *n) \
-{                                                                        \
-  size_t i;                                                              \
-  const char *str;                                                       \
-  int status = ACCESSOR(sget, field) (env, &str);                        \
-                                                                         \
-  if (status)                                                            \
-    return status;                                                       \
-                                                                         \
-  i = mu_cpystr (buf, str, len);                                         \
-  if (n)                                                                 \
-    *n = i;                                                              \
-  return 0;                                                              \
-}
-
-#define DECL_AGET(field)                                                 \
-int                                                                      \
-ACCESSOR(aget, field) (mu_envelope_t env, char **buf)                    \
-{                                                                        \
-  const char *str;                                                       \
-  int status = ACCESSOR(sget, field) (env, &str);                        \
-                                                                         \
-  if (status)                                                            \
-    return status;                                                       \
-                                                                         \
-  if (str)                                                               \
-    {                                                                    \
-      *buf = strdup (str);                                               \
-      if (!*buf)                                                         \
-       status = ENOMEM;                                                  \
-    }                                                                    \
-  else                                                                   \
-    *buf = NULL;                                                         \
-  return status;                                                         \
-}
-
-#define DECL_ACCESSORS(field)                                            \
-DECL_SGET(field)                                                         \
-DECL_GET(field)                                                                
  \
-DECL_AGET(field)
-
-DECL_ACCESSORS(sender)
-DECL_ACCESSORS(date)     
-
diff --git a/libmailutils/errors b/libmailutils/errors
deleted file mode 100644
index 8593c79..0000000
--- a/libmailutils/errors
+++ /dev/null
@@ -1,96 +0,0 @@
-# Error messages for GNU Mailutils
-# Copyright (C) 2005, 2006, 2007, 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, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301  USA  
-
-MU_ERR_FAILURE              _("Operation failed")
-MU_ERR_CANCELED             _("Operation canceled")
-
-MU_ERR_NO_HANDLER           _("No registered handler")
-MU_ERR_EMPTY_VFN            _("Empty virtual function")
-
-MU_ERR_OUT_NULL             _("Pointer to output null")
-MU_ERR_OUT_PTR_NULL         _("Pointer to output pointer null")
-
-MU_ERR_MBX_NULL             _("Mailbox null")
-MU_ERR_MBX_REMOVED          _("Mailbox removed")
-
-MU_ERR_NOT_OPEN             _("Resource not open")
-MU_ERR_OPEN                 _("Resource is already open")
-
-MU_ERR_BAD_822_FORMAT       _("Format of RFC822 object is bad")
-MU_ERR_EMPTY_ADDRESS        _("Address contains no addr specs")
-
-MU_ERR_LOCKER_NULL          _("Locker null")
-MU_ERR_LOCK_CONFLICT        _("Conflict with previous locker")
-MU_ERR_LOCK_BAD_LOCK        _("Lock file check failed")
-MU_ERR_LOCK_BAD_FILE        _("File check failed")
-MU_ERR_LOCK_NOT_HELD        _("Lock not held on file")
-MU_ERR_LOCK_EXT_FAIL        _("Failed to execute external locker")
-MU_ERR_LOCK_EXT_ERR         _("External locker failed")
-MU_ERR_LOCK_EXT_KILLED      _("External locker killed")
-
-MU_ERR_NO_SUCH_USER         _("No such user name")
-
-MU_ERR_GETHOSTBYNAME        _("DNS name resolution failed")
-MU_ERR_BAD_RESUMPTION       _("State busy must resume operation")
-MU_ERR_MAILER_BAD_FROM      _("Not a valid mailer from address")
-MU_ERR_MAILER_BAD_TO        _("Not a valid mailer to address")
-MU_ERR_MAILER_NO_RCPT_TO    _("No receipt addresses found")
-MU_ERR_MAILER_BAD_URL       _("Malformed or unsupported mailer URL")
-MU_ERR_SMTP_RCPT_FAILED     _("SMTP rcpt to command failed")
-MU_ERR_TCP_NO_HOST          _("Tcp connections need a host")
-MU_ERR_TCP_NO_PORT          _("Tcp connections need a postive port")
-
-MU_ERR_BAD_2047_INPUT       _("Input string is not RFC 2047 encoded")
-MU_ERR_BAD_2047_ENCODING    _("Not a valid RFC 2047 encoding")
-
-MU_ERR_NOUSERNAME           _("User name is not supplied")
-MU_ERR_NOPASSWORD           _("User password is not supplied")
-MU_ERR_BADREPLY             _("Invalid reply from the remote host")
-
-MU_ERR_SEQ                  _("Bad command sequence")
-MU_ERR_REPLY                _("Erroneous reply received")
-
-MU_ERR_UNSAFE_PERMS         _("Unsafe file permissions. Set 0600")
-MU_ERR_BAD_AUTH_SCHEME      _("Unsupported authentication scheme")
-MU_ERR_AUTH_FAILURE         _("Authentication failed")
-
-MU_ERR_PROCESS_NOEXEC       _("Cannot execute")
-MU_ERR_PROCESS_EXITED       _("Process exited with a non-zero status")
-MU_ERR_PROCESS_SIGNALED     _("Process exited on signal")
-MU_ERR_PROCESS_UNKNOWN_FAILURE _("Unknown failure while executing subprocess")
-MU_ERR_CONN_CLOSED          _("Connection closed by remote host")
-MU_ERR_PARSE                _("Parse error")
-MU_ERR_NOENT                _("Requested item not found")
-MU_ERR_EXISTS               _("Item already exists")
-MU_ERR_BUFSPACE             _("Not enough buffer space")
-
-MU_ERR_SQL                  _("SQL error")
-MU_ERR_DB_ALREADY_CONNECTED _("Already connected to the database")
-MU_ERR_DB_NOT_CONNECTED     _("Not connected to the database")
-MU_ERR_RESULT_NOT_RELEASED  _("Result of the previous query is not released")
-MU_ERR_NO_QUERY             _("No query was yet executed")
-MU_ERR_BAD_COLUMN           _("Bad column address")
-MU_ERR_NO_RESULT            _("No result from the previous query available")
-MU_ERR_NO_INTERFACE         _("No such interface")
-
-MU_ERR_BADOP                _("Inappropriate operation for this mode")
-MU_ERR_BAD_FILENAME         _("Badly formed file or directory name")
-MU_ERR_READ                 _("Read error")
-
-MU_ERR_NO_TRANSPORT         _("Transport stream not set")
-MU_ERR_AUTH_NO_CRED         _("No credentials supplied")
diff --git a/libmailutils/fgetpwent.c b/libmailutils/fgetpwent.c
deleted file mode 100644
index 99ec9da..0000000
--- a/libmailutils/fgetpwent.c
+++ /dev/null
@@ -1,163 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2007, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdio.h>
-#include <pwd.h>
-#include <string.h>
-#include <stdlib.h>
-
-/*
-  Written by Alain Magloire.
-  Simple replacement for fgetpwent(), it is not :
-  - thread safe;
-  - static buffer was not use since it will limit the size
-    of the entry.  But rather memory is allocated and __never__
-    release.  The memory will grow if need be.
-  - no support for shadow
-  - no support for NIS(+)
-*/
-
-static char *buffer;
-static size_t buflen;
-static struct passwd pw;
-
-static char *
-parse_line (char *s, char **p)
-{
-  if (*s)
-    {
-      char *sep = strchr (s, ':');
-      if (sep)
-       {
-         *sep++ = '\0';
-         *p = sep;
-       }
-      else
-       *p = s + strlen (s);
-    }
-  else
-    *p = s;
-  return s;
-}
-
-static struct passwd *
-getentry (char *s)
-{
-  char *p;
-  pw.pw_name = parse_line (s, &p);
-  s = p;
-  pw.pw_passwd = parse_line (s, &p);
-  s = p;
-  pw.pw_uid = strtoul (parse_line (s, &p), NULL, 10);
-  s = p;
-  pw.pw_gid = strtoul (parse_line (s, &p), NULL, 10);
-  s = p;
-  pw.pw_gecos = parse_line (s, &p);
-  s = p;
-  pw.pw_dir = parse_line (s, &p);
-  s = p;
-  pw.pw_shell = parse_line (s, &p);
-  return &pw;
-}
-
-struct passwd *
-mu_fgetpwent (FILE *fp)
-{
-  size_t pos = 0;
-  int done = 0;
-  struct passwd *pw = NULL;
-
-  /* Allocate buffer if not yet available.  */
-  /* This buffer will be never free().  */
-  if (buffer == NULL)
-    {
-      buflen = 1024;
-      buffer = malloc (buflen);
-      if (buffer == NULL)
-       return NULL;
-    }
-
-  do
-    {
-      if (fgets (buffer + pos, buflen, fp) != NULL)
-       {
-         /* Need a full line.  */
-         if (buffer[strlen (buffer) - 1] == '\n')
-           {
-             /* reset marker position.  */
-             pos = 0;
-             /* Nuke trailing newline.  */
-             buffer[strlen (buffer) - 1] = '\0';
-
-             /* Skip comments.  */
-             if (buffer[0] != '#')
-               {
-                 done = 1;
-                 pw = getentry (buffer);
-               }
-           }
-         else
-           {
-             /* Line is too long reallocate the buffer.  */
-             char *tmp;
-             pos = strlen (buffer);
-             buflen *= 2;
-             tmp = realloc (buffer, buflen);
-             if (tmp)
-               buffer = tmp;
-             else
-               done = 1;
-           }
-       }
-      else
-       done = 1;
-    } while (!done);
-
-  return pw;
-
-}
-
-#ifdef STANDALONE
-int
-main ()
-{
-  FILE *fp = fopen ("/etc/passwd", "r");
-  if (fp)
-    {
-      struct passwd *pwd;
-      while ((pwd = fgetpwent (fp)))
-        {
-          printf ("--------------------------------------\n");
-          printf ("name %s\n", pwd->pw_name);
-          printf ("passwd %s\n", pwd->pw_passwd);
-          printf ("uid %d\n", pwd->pw_uid);
-          printf ("gid %d\n", pwd->pw_gid);
-          printf ("gecos %s\n", pwd->pw_gecos);
-          printf ("dir %s\n", pwd->pw_dir);
-          printf ("shell %s\n", pwd->pw_shell);
-        }
-    }
-  return 0;
-}
-
-#endif
diff --git a/libmailutils/filter.c b/libmailutils/filter.c
deleted file mode 100644
index 0008ba0..0000000
--- a/libmailutils/filter.c
+++ /dev/null
@@ -1,194 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-/* Notes:
-   First draft: Alain Magloire.
-   Complete rewrite: Sergey Poznyakoff.
-*/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
-#endif
-
-#include <mailutils/filter.h>
-#include <mailutils/monitor.h>
-#include <mailutils/list.h>
-#include <mailutils/stream.h>
-#include <mailutils/errno.h>
-#include <mailutils/cstr.h>
-
-/* NOTE: We will leak here since the monitor of the filter will never
-   be release.  That's ok we can leave with this, it's only done once.  */
-static mu_list_t filter_list;
-struct mu_monitor filter_monitor = MU_MONITOR_INITIALIZER;
-
-static int
-filter_name_cmp (const void *item, const void *data)
-{
-  struct _mu_filter_record const *rec = item;
-  char const *name = data;
-  return mu_c_strcasecmp (rec->name, name);
-}
-
-int
-mu_filter_get_list (mu_list_t *plist)
-{
-  if (plist == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  mu_monitor_wrlock (&filter_monitor);
-  if (filter_list == NULL)
-    {
-      int status = mu_list_create (&filter_list);
-      if (status != 0)
-       return status;
-      mu_list_set_comparator (filter_list, filter_name_cmp);
-      /* Default filters.  */
-      mu_list_append (filter_list, mu_base64_filter);
-      mu_list_append (filter_list, mu_qp_filter);
-      mu_list_append (filter_list, mu_binary_filter);
-      mu_list_append (filter_list, mu_bit8_filter);
-      mu_list_append (filter_list, mu_bit7_filter);
-      mu_list_append (filter_list, mu_rfc822_filter);
-      mu_list_append (filter_list, mu_crlf_filter);
-      mu_list_append (filter_list, mu_crlfdot_filter);
-      mu_list_append (filter_list, mu_dot_filter);
-      mu_list_append (filter_list, mu_rfc_2047_Q_filter);
-      mu_list_append (filter_list, mu_rfc_2047_B_filter);
-      mu_list_append (filter_list, mu_from_filter);
-      /* FIXME: add the default encodings?  */
-    }
-  *plist = filter_list;
-  mu_monitor_unlock (&filter_monitor);
-  return 0;
-}
-
-static int
-filter_create_rd (mu_stream_t *pstream, mu_stream_t stream,
-                 size_t max_line_length,
-                 int mode,
-                 mu_filter_xcode_t xcode, void *xdata,
-                 int flags)
-{
-  int status;
-  mu_stream_t fltstream;
-
-  flags &= ~MU_STREAM_AUTOCLOSE;
-  
-  status = mu_filter_stream_create (&fltstream, stream,
-                                   mode, xcode, xdata,
-                                   flags);
-  if (status == 0)
-    {
-      if (max_line_length)
-       {
-         status = mu_linelen_filter_create (pstream, fltstream,
-                                            max_line_length,
-                                            flags);
-         mu_stream_unref (fltstream);
-         if (status)
-           return status;
-       }
-      else
-       *pstream = fltstream;
-
-      if (flags & MU_STREAM_AUTOCLOSE)
-       mu_stream_unref (stream);
-    }
-  return status;
-}
-
-static int
-filter_create_wr (mu_stream_t *pstream, mu_stream_t stream,
-                 size_t max_line_length,
-                 int mode,
-                 mu_filter_xcode_t xcode, void *xdata,
-                 int flags)
-{
-  int status;
-  mu_stream_t fltstream, instream = NULL, tmpstr;
-
-  flags &= ~MU_STREAM_AUTOCLOSE;
-
-  if (max_line_length)
-    {
-      status = mu_linelen_filter_create (&instream, stream,
-                                        max_line_length,
-                                        flags);
-      if (status)
-       return status;
-      tmpstr = instream;
-    }
-  else
-    tmpstr = stream;
-  
-  status = mu_filter_stream_create (&fltstream, tmpstr,
-                                   mode, xcode, xdata,
-                                   flags);
-  mu_stream_unref (instream);
-  if (status)
-    return status;
-  *pstream = fltstream;
-  if (flags & MU_STREAM_AUTOCLOSE)
-    mu_stream_unref (stream);
-  return status;
-}
-
-int
-mu_filter_create (mu_stream_t *pstream, mu_stream_t stream, const char *name,
-                 int mode, int flags)
-{
-  int status;
-  mu_filter_record_t frec;
-  mu_list_t list;
-  void *xdata = NULL;
-  
-  if ((flags & MU_STREAM_RDWR) == MU_STREAM_RDWR)
-    return EINVAL;
-  
-  mu_filter_get_list (&list);
-  status = mu_list_locate (list, (void*)name, (void**)&frec);
-  if (status)
-    return status;
-
-  if (frec->newdata)
-    {
-      status = frec->newdata (&xdata, mode, NULL);
-      if (status)
-       return status;
-    }
-
-  status = ((flags & MU_STREAM_WRITE) ? filter_create_wr : filter_create_rd)
-                   (pstream, stream,
-                   frec->max_line_length,
-                   mode,
-                   mode == MU_FILTER_ENCODE ? frec->encoder : frec->decoder,
-                   xdata,
-                   flags);
-  if (status)
-    free (xdata);
-  return status;
-}
diff --git a/libmailutils/filter/Makefile.am b/libmailutils/filter/Makefile.am
new file mode 100644
index 0000000..08082bb
--- /dev/null
+++ b/libmailutils/filter/Makefile.am
@@ -0,0 +1,33 @@
+# 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/>.
+
+noinst_LTLIBRARIES = libfilter.la
+
+libfilter_la_SOURCES =\
+ base64.c\
+ binflt.c\
+ crlfdot.c\
+ crlfflt.c\
+ dot.c\
+ filter.c\
+ filter_iconv.c\
+ fromflt.c\
+ linelenflt.c\
+ qpflt.c
+
+INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I${top_srcdir}/libmailutils
+
diff --git a/libmailutils/base64.c b/libmailutils/filter/base64.c
similarity index 100%
rename from libmailutils/base64.c
rename to libmailutils/filter/base64.c
diff --git a/libmailutils/binflt.c b/libmailutils/filter/binflt.c
similarity index 100%
rename from libmailutils/binflt.c
rename to libmailutils/filter/binflt.c
diff --git a/libmailutils/filter/crlfdot.c b/libmailutils/filter/crlfdot.c
new file mode 100644
index 0000000..35043a6
--- /dev/null
+++ b/libmailutils/filter/crlfdot.c
@@ -0,0 +1,335 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2003, 2007, 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/>. */
+
+/* This source implements a CRLFDOT filter, useful for data I/O in
+   such protocols as POP3 and SMTP.  When encoding, this filter
+   replaces each '\n' not following '\r' by "\r\n" and "byte-stuffs"
+   the input by outputting an additional '.' in front of any '.' appearing
+   at the beginning of a line.  Upon closing the filter in this mode, it
+   outputs additional ".\r\n".
+   
+   When decoding, the reverse is performed: each "\r\n" is replaced by a
+   '\n', and additional '.' are removed from beginning of lines.  A single
+   dot on a line by itself marks end of the stream.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/errno.h>
+#include <mailutils/filter.h>
+#include <mailutils/stream.h>
+
+enum crlfdot_decode_state
+  {
+    crlfdot_decode_init,  /* initial state */
+    crlfdot_decode_char,  /* Any character excepting [\r\n.] */
+    crlfdot_decode_cr,    /* prev. char was \r */
+    crlfdot_decode_crlf,  /* 2 prev. char were \r\n */
+    crlfdot_decode_dot,   /* 3 prev. chars were \r\n. */
+    crlfdot_decode_dotcr, /* 4 prev. chars were \r\n.\r */
+    crlfdot_decode_end    /* final state, a \r\n.\r\n seen. */
+  };
+
+static enum crlfdot_decode_state
+new_decode_state (enum crlfdot_decode_state state, int c)
+{
+  switch (state)
+    {
+    case crlfdot_decode_init:
+      switch (c)
+       {
+       case '\r':
+         return crlfdot_decode_cr;
+       case '.':
+         return crlfdot_decode_dot;
+       }
+      break;
+      
+    case crlfdot_decode_char:
+      switch (c)
+       {
+       case '\r':
+         return crlfdot_decode_cr;
+       }
+      break;
+      
+    case crlfdot_decode_cr:
+      switch (c)
+       {
+       case '\r':
+         return crlfdot_decode_cr;
+       case '\n':
+         return crlfdot_decode_crlf;
+       }
+      break;
+      
+    case crlfdot_decode_crlf:
+      switch (c)
+       {
+       case '\r':
+         return crlfdot_decode_cr;
+       case '.':
+         return crlfdot_decode_dot;
+       }
+      
+    case crlfdot_decode_dot:
+      switch (c)
+       {
+       case '\r':
+         return crlfdot_decode_dotcr;
+       }
+      break;
+
+    case crlfdot_decode_dotcr:
+      switch (c)
+       {
+       case '\n':
+         return crlfdot_decode_end;
+       }
+
+    case crlfdot_decode_end:
+      break;
+    }
+  return crlfdot_decode_char;
+}
+
+/* Move min(isize,osize) bytes from iptr to optr, replacing each \r\n
+   with \n. */
+static enum mu_filter_result
+_crlfdot_decoder (void *xd,
+                 enum mu_filter_command cmd,
+                 struct mu_filter_io *iobuf)
+{
+  int *pstate = xd;
+  size_t i, j;
+  const unsigned char *iptr;
+  size_t isize;
+  char *optr;
+  size_t osize;
+
+  switch (cmd)
+    {
+    case mu_filter_init:
+      *pstate = crlfdot_decode_init;
+      return mu_filter_ok;
+      
+    case mu_filter_done:
+      return mu_filter_ok;
+      
+    default:
+      break;
+    }
+  
+  iptr = (const unsigned char *) iobuf->input;
+  isize = iobuf->isize;
+  optr = iobuf->output;
+  osize = iobuf->osize;
+
+  for (i = j = 0; *pstate != crlfdot_decode_end && i < isize && j < osize; i++)
+    {
+      unsigned char c = *iptr++;
+
+      if (c == '\r')
+       {
+         if (i + 1 == isize)
+           break;
+         *pstate = new_decode_state (*pstate, c);
+         if (*iptr == '\n')
+           continue;
+       }
+      else if (c == '.' &&
+              (*pstate == crlfdot_decode_init ||
+               *pstate == crlfdot_decode_crlf))
+       {
+         /* Make sure we have two more characters in the buffer */
+         if (i + 2 == isize)
+           break;
+         *pstate = new_decode_state (*pstate, c);
+         if (*iptr != '\r')
+           continue;
+       }
+      else
+       *pstate = new_decode_state (*pstate, c);
+      optr[j++] = c;
+    }
+  
+  if (*pstate == crlfdot_decode_end)
+    {
+      j -= 2; /* remove the trailing .\n */
+      iobuf->eof = 1;
+    }
+  iobuf->isize = i;
+  iobuf->osize = j;
+  return mu_filter_ok;
+}
+
+enum crlfdot_encode_state
+  {
+    crlfdot_encode_init,  /* initial state */
+    crlfdot_encode_char,  /* Any character excepting [\r\n] */
+    crlfdot_encode_cr,    /* prev. char was \r */
+    crlfdot_encode_lf,    /* prev. char was \n */
+  };    
+
+static enum crlfdot_encode_state
+new_encode_state (enum crlfdot_encode_state state, int c)
+{
+  switch (c)
+    {
+    case '\r':
+      return crlfdot_encode_cr;
+      
+    case '\n':
+      return crlfdot_encode_lf;
+    }
+  return crlfdot_encode_char;
+}
+
+/* Move min(isize,osize) bytes from iptr to optr, replacing each \n
+   with \r\n.  Any input \r\n sequences remain untouched. */
+static enum mu_filter_result
+_crlfdot_encoder (void *xd,
+                 enum mu_filter_command cmd,
+                 struct mu_filter_io *iobuf)
+{
+  enum mu_filter_result result;
+  size_t i, j;
+  const unsigned char *iptr;
+  size_t isize;
+  char *optr;
+  size_t osize;
+  int *state = xd;
+  
+  switch (cmd)
+    {
+    case mu_filter_init:
+      *state = crlfdot_encode_init;
+      return mu_filter_ok;
+      
+    case mu_filter_done:
+      return mu_filter_ok;
+
+    default:
+      break;
+    }
+  
+  iptr = (const unsigned char *) iobuf->input;
+  isize = iobuf->isize;
+  optr = iobuf->output;
+  osize = iobuf->osize;
+
+  for (i = j = 0; i < isize && j < osize; i++, iptr++)
+    {
+      unsigned char c = *iptr;
+      int curstate = *state;
+
+      if (c == '\n')
+       {
+         if (curstate == crlfdot_encode_cr)
+           optr[j++] = c;
+         else if (j + 1 == osize)
+           {
+             if (i == 0)
+               {
+                 iobuf->osize = 2;
+                 return mu_filter_moreoutput;
+               }
+             break;
+           }
+         else
+           {
+             optr[j++] = '\r';
+             optr[j++] = '\n';
+           }
+       }
+      else if (c == '.' &&
+              (curstate == crlfdot_encode_init ||
+               curstate == crlfdot_encode_lf))
+       {
+         if (j + 2 > osize)
+           {
+             if (i == 0)
+               {
+                 iobuf->osize = 2;
+                 return mu_filter_moreoutput;
+               }
+             break;
+           }
+         optr[j++] = '.';
+         optr[j++] = '.';
+       }
+      else
+       optr[j++] = c;
+
+      *state = new_encode_state (curstate, c);
+    }
+
+  result = mu_filter_ok;
+  if (cmd == mu_filter_lastbuf)
+    {
+      switch (*state)
+       {
+       case crlfdot_encode_lf:
+         if (j + 3 > osize)
+           result = mu_filter_again;
+         break;
+             
+       default:
+         if (j + 5 > osize)
+           result = mu_filter_again;
+         else
+           {
+             optr[j++] = '\r';
+             optr[j++] = '\n';
+           }
+       }
+
+      if (result == mu_filter_ok)
+       {
+         optr[j++] = '.';
+         optr[j++] = '\r';
+         optr[j++] = '\n';
+       }
+    }
+
+  iobuf->isize = i;
+  iobuf->osize = j;
+  return result;
+}
+
+static int
+alloc_state (void **pret, int mode MU_ARG_UNUSED, void *data MU_ARG_UNUSED)
+{
+  *pret = malloc (sizeof (int));
+  if (!*pret)
+    return ENOMEM;
+  return 0;
+}
+
+static struct _mu_filter_record _crlfdot_filter = {
+  "CRLFDOT",
+  0,
+  alloc_state,
+  _crlfdot_encoder,
+  _crlfdot_decoder
+};
+
+mu_filter_record_t mu_crlfdot_filter = &_crlfdot_filter;
diff --git a/libmailutils/crlfflt.c b/libmailutils/filter/crlfflt.c
similarity index 100%
rename from libmailutils/crlfflt.c
rename to libmailutils/filter/crlfflt.c
diff --git a/libmailutils/filter/dot.c b/libmailutils/filter/dot.c
new file mode 100644
index 0000000..872f6ba
--- /dev/null
+++ b/libmailutils/filter/dot.c
@@ -0,0 +1,267 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2003, 2007, 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/>. */
+
+/* This file implements a DOT filter, useful for data I/O in
+   such protocols as POP3 and SMTP.  When encoding, this filter
+   "byte-stuffs" the input by outputting an additional '.' in front
+   of any '.' appearing at the beginning of a line.  Upon closing the
+   filter in this mode, it outputs additional ".\n".
+   
+   When decoding, the reverse is performed: any '.' appearing at the
+   beginning of a line is removed.  A single dot on a line by itself
+   marks end of the stream.
+
+   MU also provides a hairy version of this filter, called CRLFDOT.
+   In addition to byte-stuffing, CRLFDOT also performs CRLF/LF translation.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/errno.h>
+#include <mailutils/filter.h>
+#include <mailutils/stream.h>
+
+enum dot_decode_state
+  {
+    dot_decode_init,  /* initial state */
+    dot_decode_char,  /* Any character excepting [\r\n.] */
+    dot_decode_lf,    /* prev. char was \n */
+    dot_decode_dot,   /* 2 prev. chars were \n. */
+    dot_decode_end   /* final state, a \n.\n seen. */
+  };
+
+static enum dot_decode_state
+new_decode_state (enum dot_decode_state state, int c)
+{
+  switch (state)
+    {
+    case dot_decode_init:
+      switch (c)
+       {
+       case '.':
+         return dot_decode_dot;
+       }
+      break;
+      
+    case dot_decode_char:
+      switch (c)
+       {
+       case '\n':
+         return dot_decode_lf;
+       }
+      break;
+      
+    case dot_decode_lf:
+      switch (c)
+       {
+       case '.':
+         return dot_decode_dot;
+       }
+      
+    case dot_decode_dot:
+      switch (c)
+       {
+       case '\n':
+         return dot_decode_end;
+       }
+      break;
+
+    case dot_decode_end:
+      return dot_decode_end;
+    }
+  return dot_decode_char;
+}
+
+/* Move min(isize,osize) bytes from iptr to optr, replacing each \r\n
+   with \n. */
+static enum mu_filter_result
+_dot_decoder (void *xd,
+             enum mu_filter_command cmd,
+             struct mu_filter_io *iobuf)
+{
+  int *pstate = xd;
+  size_t i, j;
+  const unsigned char *iptr;
+  size_t isize;
+  char *optr;
+  size_t osize;
+
+  switch (cmd)
+    {
+    case mu_filter_init:
+      *pstate = dot_decode_init;
+      return mu_filter_ok;
+      
+    case mu_filter_done:
+      return mu_filter_ok;
+      
+    default:
+      break;
+    }
+  
+  iptr = (const unsigned char *) iobuf->input;
+  isize = iobuf->isize;
+  optr = iobuf->output;
+  osize = iobuf->osize;
+
+  for (i = j = 0; *pstate != dot_decode_end && i < isize && j < osize; i++)
+    {
+      unsigned char c = *iptr++;
+      int curstate = *pstate;
+      
+      *pstate = new_decode_state (curstate, c);
+      if (!(c == '.' && (curstate == dot_decode_init ||
+                        curstate == dot_decode_lf)))
+       optr[j++] = c;
+    }
+  
+  if (*pstate == dot_decode_end)
+    iobuf->eof = 1;
+
+  iobuf->isize = i;
+  iobuf->osize = j;
+  return mu_filter_ok;
+}
+
+enum dot_encode_state
+  {
+    dot_encode_init,  /* initial state */
+    dot_encode_char,  /* Any character excepting \n */
+    dot_encode_lf,    /* prev. char was \n */
+  };    
+
+static enum dot_encode_state
+new_encode_state (int c)
+{
+  switch (c)
+    {
+    case '\n':
+      return dot_encode_lf;
+    }
+  return dot_encode_char;
+}
+
+/* Move min(isize,osize) bytes from iptr to optr, replacing each \n
+   with \r\n.  Any input \r\n sequences remain untouched. */
+static enum mu_filter_result
+_dot_encoder (void *xd,
+             enum mu_filter_command cmd,
+             struct mu_filter_io *iobuf)
+{
+  enum mu_filter_result result;
+  size_t i, j;
+  const unsigned char *iptr;
+  size_t isize;
+  char *optr;
+  size_t osize;
+  int *state = xd;
+  
+  switch (cmd)
+    {
+    case mu_filter_init:
+      *state = dot_encode_init;
+      return mu_filter_ok;
+      
+    case mu_filter_done:
+      return mu_filter_ok;
+
+    default:
+      break;
+    }
+  
+  iptr = (const unsigned char *) iobuf->input;
+  isize = iobuf->isize;
+  optr = iobuf->output;
+  osize = iobuf->osize;
+
+  for (i = j = 0; i < isize && j < osize; i++, iptr++)
+    {
+      unsigned char c = *iptr;
+      int curstate = *state;
+
+      if (c == '.' && (curstate == dot_encode_init ||
+                      curstate == dot_encode_lf))
+       {
+         if (j + 2 > osize)
+           {
+             if (i == 0)
+               {
+                 iobuf->osize = 2;
+                 return mu_filter_moreoutput;
+               }
+             break;
+           }
+         optr[j++] = '.';
+         optr[j++] = '.';
+       }
+      else
+       optr[j++] = c;
+
+      *state = new_encode_state (c);
+    }
+
+  result = mu_filter_ok;
+  if (cmd == mu_filter_lastbuf)
+    {
+      switch (*state)
+       {
+       case dot_encode_lf:
+         if (j + 2 > osize)
+           result = mu_filter_again;
+         break;
+             
+       default:
+         if (j + 3 > osize)
+           result = mu_filter_again;
+         else
+           optr[j++] = '\n';
+       }
+
+      if (result == mu_filter_ok)
+       {
+         optr[j++] = '.';
+         optr[j++] = '\n';
+       }
+    }
+
+  iobuf->isize = i;
+  iobuf->osize = j;
+  return result;
+}
+
+static int
+alloc_state (void **pret, int mode MU_ARG_UNUSED, void *data MU_ARG_UNUSED)
+{
+  *pret = malloc (sizeof (int));
+  if (!*pret)
+    return ENOMEM;
+  return 0;
+}
+
+static struct _mu_filter_record _dot_filter = {
+  "DOT",
+  0,
+  alloc_state,
+  _dot_encoder,
+  _dot_decoder
+};
+
+mu_filter_record_t mu_dot_filter = &_dot_filter;
diff --git a/libmailutils/filter/filter.c b/libmailutils/filter/filter.c
new file mode 100644
index 0000000..a98d0a9
--- /dev/null
+++ b/libmailutils/filter/filter.c
@@ -0,0 +1,193 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2005, 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/>. */
+
+/* Notes:
+   First draft: Alain Magloire.
+   Complete rewrite: Sergey Poznyakoff.
+*/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/filter.h>
+#include <mailutils/monitor.h>
+#include <mailutils/list.h>
+#include <mailutils/stream.h>
+#include <mailutils/errno.h>
+#include <mailutils/cstr.h>
+
+/* NOTE: We will leak here since the monitor of the filter will never
+   be release.  That's ok we can leave with this, it's only done once.  */
+static mu_list_t filter_list;
+struct mu_monitor filter_monitor = MU_MONITOR_INITIALIZER;
+
+static int
+filter_name_cmp (const void *item, const void *data)
+{
+  struct _mu_filter_record const *rec = item;
+  char const *name = data;
+  return mu_c_strcasecmp (rec->name, name);
+}
+
+int
+mu_filter_get_list (mu_list_t *plist)
+{
+  if (plist == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  mu_monitor_wrlock (&filter_monitor);
+  if (filter_list == NULL)
+    {
+      int status = mu_list_create (&filter_list);
+      if (status != 0)
+       return status;
+      mu_list_set_comparator (filter_list, filter_name_cmp);
+      /* Default filters.  */
+      mu_list_append (filter_list, mu_base64_filter);
+      mu_list_append (filter_list, mu_qp_filter);
+      mu_list_append (filter_list, mu_binary_filter);
+      mu_list_append (filter_list, mu_bit8_filter);
+      mu_list_append (filter_list, mu_bit7_filter);
+      mu_list_append (filter_list, mu_rfc822_filter);
+      mu_list_append (filter_list, mu_crlf_filter);
+      mu_list_append (filter_list, mu_crlfdot_filter);
+      mu_list_append (filter_list, mu_dot_filter);
+      mu_list_append (filter_list, mu_rfc_2047_Q_filter);
+      mu_list_append (filter_list, mu_rfc_2047_B_filter);
+      mu_list_append (filter_list, mu_from_filter);
+      /* FIXME: add the default encodings?  */
+    }
+  *plist = filter_list;
+  mu_monitor_unlock (&filter_monitor);
+  return 0;
+}
+
+static int
+filter_create_rd (mu_stream_t *pstream, mu_stream_t stream,
+                 size_t max_line_length,
+                 int mode,
+                 mu_filter_xcode_t xcode, void *xdata,
+                 int flags)
+{
+  int status;
+  mu_stream_t fltstream;
+
+  flags &= ~MU_STREAM_AUTOCLOSE;
+  
+  status = mu_filter_stream_create (&fltstream, stream,
+                                   mode, xcode, xdata,
+                                   flags);
+  if (status == 0)
+    {
+      if (max_line_length)
+       {
+         status = mu_linelen_filter_create (pstream, fltstream,
+                                            max_line_length,
+                                            flags);
+         mu_stream_unref (fltstream);
+         if (status)
+           return status;
+       }
+      else
+       *pstream = fltstream;
+
+      if (flags & MU_STREAM_AUTOCLOSE)
+       mu_stream_unref (stream);
+    }
+  return status;
+}
+
+static int
+filter_create_wr (mu_stream_t *pstream, mu_stream_t stream,
+                 size_t max_line_length,
+                 int mode,
+                 mu_filter_xcode_t xcode, void *xdata,
+                 int flags)
+{
+  int status;
+  mu_stream_t fltstream, instream = NULL, tmpstr;
+
+  flags &= ~MU_STREAM_AUTOCLOSE;
+
+  if (max_line_length)
+    {
+      status = mu_linelen_filter_create (&instream, stream,
+                                        max_line_length,
+                                        flags);
+      if (status)
+       return status;
+      tmpstr = instream;
+    }
+  else
+    tmpstr = stream;
+  
+  status = mu_filter_stream_create (&fltstream, tmpstr,
+                                   mode, xcode, xdata,
+                                   flags);
+  mu_stream_unref (instream);
+  if (status)
+    return status;
+  *pstream = fltstream;
+  if (flags & MU_STREAM_AUTOCLOSE)
+    mu_stream_unref (stream);
+  return status;
+}
+
+int
+mu_filter_create (mu_stream_t *pstream, mu_stream_t stream, const char *name,
+                 int mode, int flags)
+{
+  int status;
+  mu_filter_record_t frec;
+  mu_list_t list;
+  void *xdata = NULL;
+  
+  if ((flags & MU_STREAM_RDWR) == MU_STREAM_RDWR)
+    return EINVAL;
+  
+  mu_filter_get_list (&list);
+  status = mu_list_locate (list, (void*)name, (void**)&frec);
+  if (status)
+    return status;
+
+  if (frec->newdata)
+    {
+      status = frec->newdata (&xdata, mode, NULL);
+      if (status)
+       return status;
+    }
+
+  status = ((flags & MU_STREAM_WRITE) ? filter_create_wr : filter_create_rd)
+                   (pstream, stream,
+                   frec->max_line_length,
+                   mode,
+                   mode == MU_FILTER_ENCODE ? frec->encoder : frec->decoder,
+                   xdata,
+                   flags);
+  if (status)
+    free (xdata);
+  return status;
+}
diff --git a/libmailutils/filter/filter_iconv.c 
b/libmailutils/filter/filter_iconv.c
new file mode 100644
index 0000000..79835a5
--- /dev/null
+++ b/libmailutils/filter/filter_iconv.c
@@ -0,0 +1,481 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2004, 2005, 2007, 2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <mailutils/stream.h>
+#include <mailutils/sys/stream.h>
+#include <mailutils/filter.h>
+#include <mailutils/errno.h>
+#include <mailutils/nls.h>
+
+#ifdef HAVE_ICONV_H
+# include <iconv.h>
+#endif
+
+#ifndef ICONV_CONST
+# define ICONV_CONST
+#endif
+
+#ifndef HAVE_ICONV
+# undef iconv_open
+# define iconv_open(tocode, fromcode) ((iconv_t) -1)
+
+# undef iconv
+# define iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft) (errno = EILSEQ, 
(size_t) -1)
+
+# undef iconv_close
+# define iconv_close(cd) 0
+
+#endif 
+
+enum _icvt_state
+  {
+    state_closed,           /* Filter is closed */
+    state_open,             /* Filter is open and running in conversion mode */
+    state_copy_pass,        /* Filter is open and running in copy-pass mode */
+    state_copy_octal,       /* Filter is open and running in copy-octal mode */
+    state_iconv_error,      /* A fatal iconv error has occurred */
+    state_transport_error   /* A fatal transport error has occurred */
+  };
+
+struct icvt_stream
+{
+  struct _mu_stream stream;
+  mu_stream_t transport;/* I/O stream */
+  int fallback_mode;
+  iconv_t cd;           /* Conversion descriptor */
+  char *buf;            /* Conversion buffer */
+  size_t bufsize;       /* Size of buf */
+  size_t bufpos;        /* Current position in buf */
+  enum _icvt_state state;
+  int ec;               /* Error code */
+  char errbuf[128];     /* Error message buffer */
+};
+
+static int
+_icvt_open (mu_stream_t stream)
+{
+  struct icvt_stream *s = (struct icvt_stream *)stream;
+  if (s->cd == (iconv_t) -1)
+    return EINVAL;
+  s->state = state_open;
+  return 0;
+}
+
+static int
+_icvt_close (mu_stream_t stream)
+{
+  struct icvt_stream *s = (struct icvt_stream *)stream;
+  if (s->state != state_closed)
+    {
+      mu_stream_close (s->transport);
+      iconv_close (s->cd);
+      s->cd = (iconv_t) -1;
+      s->state = state_closed;
+    }
+  return 0;
+}
+
+static void
+_icvt_done (mu_stream_t stream)
+{
+  struct icvt_stream *s = (struct icvt_stream *)stream;
+
+  if (s->state != state_closed)
+    _icvt_close (stream);
+  mu_stream_destroy (&s->transport);
+  free (s->buf);
+}
+
+static int _icvt_read (mu_stream_t stream, char *optr, size_t osize,
+                      size_t *pnbytes);
+
+static int
+internal_icvt_read (mu_stream_t stream, char *optr, size_t osize,
+                   size_t *pnbytes)
+{
+  struct icvt_stream *s = (struct icvt_stream *)stream;
+  size_t nbytes = 0;
+  int rc, status = 0;
+  char *ob = optr;
+  size_t olen = osize;
+
+  if (s->bufpos == 0)
+    {
+      status = mu_stream_read (s->transport, s->buf, s->bufsize, &nbytes);
+      if (status)
+       {
+         s->state = state_transport_error;
+         s->ec = rc;
+         return MU_ERR_FAILURE;
+       }
+      else if (nbytes == 0)
+       {
+         if (pnbytes)
+           *pnbytes = 0;
+         return 0;
+       }
+    }
+  
+  do
+    {
+      char ICONV_CONST *ib = s->buf;
+      size_t inlen = s->bufpos + nbytes;
+      
+      rc = iconv (s->cd, &ib, &inlen, &ob, &olen);
+      if (ib > s->buf)
+       {
+         memmove (s->buf, ib, inlen);
+         s->bufpos = inlen;
+       }
+      else
+       s->bufpos += nbytes;
+      
+      if (rc == -1)
+       {
+         if (errno == E2BIG)
+           {
+             if (ob > optr)
+               break;
+             else
+               {
+                 s->ec = MU_ERR_BUFSPACE;
+                 return MU_ERR_BUFSPACE;
+               }
+           }
+         else if (errno == EILSEQ)
+           {
+             switch (s->fallback_mode)
+               {
+               case mu_fallback_none:
+                 s->state = state_iconv_error;
+                 s->ec = errno;
+                 if (ob == optr)
+                   return MU_ERR_FAILURE;
+                 break;
+
+               case mu_fallback_copy_pass:
+                 s->state = state_copy_pass;
+                 if (ob == optr)
+                   return _icvt_read (stream, optr, osize, pnbytes);
+                 break;
+                 
+               case mu_fallback_copy_octal:
+                 s->state = state_copy_octal;
+                 if (ob == optr)
+                   return _icvt_read (stream, optr, osize, pnbytes);
+                 break;
+               }
+           }
+         else if (errno == EINVAL)
+           {
+             if (inlen == s->bufsize)
+               {
+                 /* Try to reallocate temp buffer */
+                 char *p = realloc (s->buf, s->bufsize + 128);
+                 if (!p)
+                   return ENOMEM;
+                 s->buf = p;
+                 s->bufsize += 128;
+               }
+             continue;
+           }
+         else
+           {
+             s->ec = errno;
+             s->state = state_iconv_error;
+             return MU_ERR_FAILURE;
+           }
+       }
+    }
+  while (olen > 0 
+        && (status = mu_stream_read (s->transport,
+                                     s->buf + s->bufpos,
+                                     s->bufsize - s->bufpos,
+                                     &nbytes)) == 0
+        && nbytes);
+
+  if (status)
+    {
+      s->state = state_transport_error;
+      s->ec = status;
+      if (ob == optr)
+       return MU_ERR_FAILURE;
+    }
+      
+  if (pnbytes)
+    *pnbytes = ob - optr;
+  return 0;
+}
+
+#define ISPRINT(c) (((c)>=' '&&(c)<127)||(c)=='\n')
+
+static int
+copy_octal (struct icvt_stream *s, char *optr, size_t osize, size_t *pnbytes)
+{
+  size_t i, j;
+  int status;
+  
+  if (osize == 0)
+    return MU_ERR_BUFSPACE;
+  
+  if (s->bufpos < osize)
+    {
+      size_t rdcount = osize;
+      if (s->bufsize < rdcount)
+       {
+         /* Try to reallocate temp buffer */
+         char *p = realloc (s->buf, rdcount);
+         if (p)
+           {
+             s->bufsize = rdcount;
+             s->buf = p;
+           }
+         else
+           rdcount = s->bufsize;
+       }
+
+      status = mu_stream_read (s->transport,
+                              s->buf + s->bufpos,
+                              rdcount - s->bufpos,
+                              &rdcount);
+      if (status)
+       {
+         s->state = state_transport_error;
+         s->ec = status;
+         if (s->bufpos == 0)
+           return MU_ERR_FAILURE;
+       }
+      else
+       s->bufpos += rdcount;
+    }
+  
+  for (i = j = 0; j < osize && i < s->bufpos; i++)
+    {
+      if (ISPRINT (*(unsigned char*)(s->buf+i)))
+       optr[j++] = s->buf[i];
+      else if (j + 4 >= osize)
+       break;
+      else
+       {
+         sprintf (optr + j, "\\%03o", *(unsigned char*)(s->buf+i));
+         j += 4;
+       }
+    }
+  s->bufpos -= i;
+  memmove (s->buf, s->buf + i, s->bufpos);
+  if (pnbytes)
+    *pnbytes = j;
+  return 0;
+}
+
+static int
+copy_pass (struct icvt_stream *s, char *optr, size_t osize, size_t *pnbytes)
+{
+  int status;
+  size_t nbytes;
+  
+  if (s->bufpos)
+    {
+      size_t sz = s->bufpos < osize ? s->bufpos : osize;
+      memcpy (optr, s->buf, sz);
+      s->bufpos -= sz;
+      if (s->bufpos)
+       memmove (s->buf, s->buf + sz, s->bufpos);
+      if (pnbytes)
+       *pnbytes = sz;
+      return 0;
+    }
+
+  status = mu_stream_read (s->transport, optr, osize, &nbytes);
+  if (status)
+    {
+      s->state = state_transport_error;
+      s->ec = status;
+      if (s->bufpos == 0)
+       return MU_ERR_FAILURE;
+    }
+  if (pnbytes)
+    *pnbytes = nbytes;
+  return 0;
+}
+
+static int
+_icvt_read (mu_stream_t stream, char *optr, size_t osize, size_t *pnbytes)
+{
+  struct icvt_stream *s = (struct icvt_stream *)stream;
+
+  switch (s->state)
+    {
+    case state_open:
+      return internal_icvt_read (stream, optr, osize, pnbytes);
+      
+    case state_closed:
+      return EINVAL;
+      
+    case state_copy_pass:
+      return copy_pass (s, optr, osize, pnbytes);
+      
+    case state_copy_octal:
+      return copy_octal (s, optr, osize, pnbytes);
+       
+    default:
+      break;
+    }
+  return MU_ERR_FAILURE;
+}
+
+const char *
+_icvt_strerror (mu_stream_t stream, int rc)
+{
+  struct icvt_stream *s = (struct icvt_stream *)stream;
+
+  switch (s->state)
+    {
+    case state_transport_error:
+      snprintf (s->errbuf, sizeof s->errbuf,
+               _("Transport error: %s"), mu_strerror (s->ec));
+      break;
+
+    case state_iconv_error:
+      switch (s->ec)
+       {
+       case EILSEQ:
+         snprintf (s->errbuf, sizeof s->errbuf,
+                   _("Illegal multibyte sequence near %*.*s"),
+                   (int) s->bufpos, (int) s->bufpos, s->buf);
+         break;
+
+       default:
+         snprintf (s->errbuf, sizeof s->errbuf,
+                   _("Iconv error: %s"), mu_strerror (s->ec));
+       }
+      break;
+
+    case state_closed:
+      return _("Stream is closed"); 
+      
+    default:
+      return mu_strerror (s->ec);
+    }
+  
+  return s->errbuf;
+}
+
+static int
+_icvt_ioctl (mu_stream_t stream, int code, void *ptr)
+{
+  struct icvt_stream *s = (struct icvt_stream *)stream;
+  mu_transport_t *ptrans;
+  
+  switch (code)
+    {
+    case MU_IOCTL_GET_TRANSPORT:
+      if (!ptr)
+       return EINVAL;
+      ptrans = ptr;
+      ptrans[0] = (mu_transport_t) s->transport;
+      ptrans[1] = NULL;
+      break;
+
+    case MU_IOCTL_GET_STREAM:
+    case MU_IOCTL_SET_STREAM:
+    case MU_IOCTL_GET_TRANSPORT_BUFFER:
+    case MU_IOCTL_SET_TRANSPORT_BUFFER:
+      return mu_stream_ioctl (s->transport, code, ptr);
+      
+    default:
+      return ENOSYS;
+    }
+  return 0;
+}
+
+int
+_icvt_wait (mu_stream_t stream, int *pflags, struct timeval *tvp)
+{
+  struct icvt_stream *s = (struct icvt_stream *)stream;
+  return mu_stream_wait (s->transport, pflags, tvp);
+}
+
+/* FIXME: Seeks in the *transport* stream. */
+int
+_icvt_seek (mu_stream_t stream, mu_off_t off, mu_off_t *presult)
+{
+  struct icvt_stream *s = (struct icvt_stream *)stream;
+  return mu_stream_seek (s->transport, off, MU_SEEK_SET, presult);
+}
+
+int
+mu_filter_iconv_create (mu_stream_t *s, mu_stream_t transport,
+                       const char *fromcode, const char *tocode, int flags,
+                       enum mu_iconv_fallback_mode fallback_mode)
+{
+  struct icvt_stream *iptr;
+  iconv_t cd;
+  int rc;
+  mu_stream_t stream;
+    
+  cd = iconv_open (tocode, fromcode);
+  if (cd == (iconv_t) -1)
+    return MU_ERR_FAILURE;
+
+  iptr = (struct icvt_stream *) _mu_stream_create (sizeof (*iptr), flags);
+  if (!iptr)
+    {
+      iconv_close (cd);
+      return ENOMEM;
+    }
+  
+  if (!(flags & MU_STREAM_AUTOCLOSE))
+    mu_stream_ref (transport);
+  iptr->transport = transport;
+  iptr->fallback_mode = fallback_mode;
+  iptr->cd = cd;
+  iptr->state = state_closed;
+  iptr->bufsize = 128;
+  iptr->buf = malloc (iptr->bufsize);
+  if (!iptr->buf)
+    {
+      free (iptr);
+      return ENOMEM;
+    }
+  iptr->bufpos = 0;
+  
+  iptr->stream.open = _icvt_open;
+  iptr->stream.close = _icvt_close;
+  iptr->stream.read = _icvt_read;
+  iptr->stream.done = _icvt_done;
+  iptr->stream.error_string = _icvt_strerror;
+  iptr->stream.ctl = _icvt_ioctl;
+  iptr->stream.wait = _icvt_wait;
+  iptr->stream.seek = _icvt_seek;
+  iptr->stream.flags = MU_STREAM_READ | MU_STREAM_SEEK;
+  stream = (mu_stream_t)iptr;
+  rc = mu_stream_open (stream);
+  if (rc)
+    mu_stream_destroy (&stream);
+  else
+    *s = stream;
+  return 0;
+}
diff --git a/libmailutils/filter/fromflt.c b/libmailutils/filter/fromflt.c
new file mode 100644
index 0000000..ebf4326
--- /dev/null
+++ b/libmailutils/filter/fromflt.c
@@ -0,0 +1,282 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2003, 2007, 2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/errno.h>
+#include <mailutils/filter.h>
+#include <mailutils/stream.h>
+
+enum from_decode_state
+  {
+    from_decode_init,
+    from_decode_nl,
+    from_decode_char
+  };
+
+#define GT_FROM_MARK_STR ">From "
+#define GT_FROM_MARK_LEN (sizeof (GT_FROM_MARK_STR) - 1)
+
+/* Move min(isize,osize) bytes from iptr to optr, replacing each '>From '
+   at the beginning of line with 'From '. */
+static enum mu_filter_result
+_from_decoder (void *xd,
+              enum mu_filter_command cmd,
+              struct mu_filter_io *iobuf)
+{
+  int *pstate = xd;
+  const unsigned char *iptr;
+  size_t isize;
+  char *optr;
+  size_t osize;
+  enum from_decode_state state;
+  size_t i, j;
+
+  switch (cmd)
+    {
+    case mu_filter_init:
+      *pstate = from_decode_init;
+      return mu_filter_ok;
+      
+    case mu_filter_done:
+      return mu_filter_ok;
+      
+    default:
+      state = *pstate;
+      break;
+    }
+  
+  iptr = (const unsigned char *) iobuf->input;
+  isize = iobuf->isize;
+  optr = iobuf->output;
+  osize = iobuf->osize;
+
+  for (i = j = 0; i < isize && j < osize; i++)
+    {
+      unsigned char c = *iptr++;
+      
+      if (c == '\n')
+       state = from_decode_nl;
+      else if (state == from_decode_init || state == from_decode_nl)
+       {
+         size_t len = isize - i;
+
+         if (len < GT_FROM_MARK_LEN)
+           {
+             if (memcmp (iptr - 1, GT_FROM_MARK_STR, len) == 0)
+               {
+                 if (i == 0)
+                   {
+                     iobuf->isize = GT_FROM_MARK_LEN - len;
+                     return mu_filter_moreinput;
+                   }
+                 break;
+               }
+             else
+               state = from_decode_char;
+           }
+         else if (memcmp (iptr - 1, GT_FROM_MARK_STR, GT_FROM_MARK_LEN) == 0)
+           {
+             /* Skip > */
+             state = from_decode_char;
+             continue;
+           }
+       }         
+      optr[j++] = c;
+    }
+
+  *pstate = state;
+  iobuf->isize = i;
+  iobuf->osize = j;
+  return mu_filter_ok;
+}
+
+#define FROM_MARK_STR "From "
+#define FROM_MARK_LEN (sizeof (FROM_MARK_STR) - 1)
+
+enum from_encode_state
+  {
+    from_encode_init,
+    from_encode_nl,
+    from_encode_char,
+    from_encode_gt,
+    from_encode_f,
+    from_encode_r,
+    from_encode_o,
+    from_encode_m,
+    from_encode_sp
+  };
+
+static int length_to_state_tab[] = {
+  from_encode_gt,
+  from_encode_f,
+  from_encode_r,
+  from_encode_o,
+  from_encode_m,
+  from_encode_sp
+};
+
+static int state_to_length_tab[] = {
+  0, 0, 0,
+  GT_FROM_MARK_LEN,
+  GT_FROM_MARK_LEN-1,
+  GT_FROM_MARK_LEN-2,
+  GT_FROM_MARK_LEN-3,
+  GT_FROM_MARK_LEN-4,
+  GT_FROM_MARK_LEN-5
+};      
+
+/* Move min(isize,osize) bytes from iptr to optr, replacing each 'From '
+   at the beginning of line with '>From '. */
+
+static enum mu_filter_result
+_from_encoder (void *xd,
+              enum mu_filter_command cmd,
+              struct mu_filter_io *iobuf)
+{
+  int *pstate = xd;
+  const unsigned char *iptr;
+  size_t isize;
+  char *optr;
+  size_t osize;
+  enum from_encode_state state;
+  size_t i, j;
+  
+  switch (cmd)
+    {
+    case mu_filter_init:
+      *pstate = from_encode_init;
+      return mu_filter_ok;
+      
+    case mu_filter_done:
+      return mu_filter_ok;
+      
+    default:
+      state = *pstate;
+      switch (state)
+       {
+       case from_encode_init:
+       case from_encode_nl:
+       case from_encode_char:
+         break;
+
+       default:
+         osize = state_to_length_tab[state];
+         if (iobuf->osize < osize)
+           {
+             iobuf->osize = osize;
+             return mu_filter_moreoutput;
+           }
+         memcpy (iobuf->output, GT_FROM_MARK_STR + GT_FROM_MARK_LEN - osize,
+                 osize);
+         iobuf->osize = osize;
+         iobuf->isize = osize;
+         *pstate = from_encode_init;
+         return mu_filter_ok;
+       }
+      break;
+    }
+  
+  iptr = (const unsigned char *) iobuf->input;
+  isize = iobuf->isize;
+  optr = iobuf->output;
+  osize = iobuf->osize;
+
+  for (i = j = 0; i < isize && j < osize; i++)
+    {
+      unsigned char c = *iptr++;
+      
+      if (c == '\n')
+       state = from_encode_nl;
+      else if (state == from_encode_init || state == from_encode_nl)
+       {
+         size_t len = isize - i;
+
+         if (len < FROM_MARK_LEN)
+           {
+             if (memcmp (iptr - 1, FROM_MARK_STR, len) == 0)
+               {
+                 if (i == 0)
+                   {
+                     iobuf->isize = FROM_MARK_LEN;
+                     return mu_filter_moreinput;
+                   }
+                 break;
+               }
+             else
+               state = from_encode_char;
+           }
+         else if (memcmp (iptr - 1, FROM_MARK_STR, FROM_MARK_LEN) == 0)
+           {
+             size_t rest = osize - j;
+             
+             if (rest > GT_FROM_MARK_LEN)
+               rest = GT_FROM_MARK_LEN;
+             else if (rest < 2)
+               {
+                 if (i == 0)
+                   {
+                     iobuf->osize = GT_FROM_MARK_LEN;
+                     return mu_filter_moreoutput;
+                   }
+                 break;
+               }
+             
+             memcpy (optr + j, GT_FROM_MARK_STR, rest);
+             i += rest - 2;
+             iptr += rest - 2;
+             j += rest;
+             if (rest < GT_FROM_MARK_LEN)
+               state = length_to_state_tab[rest];
+             else
+               state = from_encode_char;
+             continue;
+           }
+         else
+           state = from_encode_char;
+       }
+      optr[j++] = c;
+    }
+  *pstate = state;
+  iobuf->isize = i;
+  iobuf->osize = j;
+  return mu_filter_ok;
+}
+
+static int
+_from_alloc_state (void **pret, int mode, void *data MU_ARG_UNUSED)
+{
+  *pret = malloc (sizeof (int));
+  if (!*pret)
+    return ENOMEM;
+  return 0;
+}
+
+static struct _mu_filter_record _from_filter = {
+  "FROM",
+  0,
+  _from_alloc_state,
+  _from_encoder,
+  _from_decoder
+};
+
+mu_filter_record_t mu_from_filter = &_from_filter;
+
diff --git a/libmailutils/linelenflt.c b/libmailutils/filter/linelenflt.c
similarity index 100%
rename from libmailutils/linelenflt.c
rename to libmailutils/filter/linelenflt.c
diff --git a/libmailutils/qpflt.c b/libmailutils/filter/qpflt.c
similarity index 100%
rename from libmailutils/qpflt.c
rename to libmailutils/filter/qpflt.c
diff --git a/libmailutils/filter_iconv.c b/libmailutils/filter_iconv.c
deleted file mode 100644
index 571e8b7..0000000
--- a/libmailutils/filter_iconv.c
+++ /dev/null
@@ -1,482 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2004, 2005, 2007, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <mailutils/stream.h>
-#include <mailutils/sys/stream.h>
-#include <mailutils/filter.h>
-#include <mailutils/errno.h>
-#include <mailutils/nls.h>
-
-#ifdef HAVE_ICONV_H
-# include <iconv.h>
-#endif
-
-#ifndef ICONV_CONST
-# define ICONV_CONST
-#endif
-
-#ifndef HAVE_ICONV
-# undef iconv_open
-# define iconv_open(tocode, fromcode) ((iconv_t) -1)
-
-# undef iconv
-# define iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft) (errno = EILSEQ, 
(size_t) -1)
-
-# undef iconv_close
-# define iconv_close(cd) 0
-
-#endif 
-
-enum _icvt_state
-  {
-    state_closed,           /* Filter is closed */
-    state_open,             /* Filter is open and running in conversion mode */
-    state_copy_pass,        /* Filter is open and running in copy-pass mode */
-    state_copy_octal,       /* Filter is open and running in copy-octal mode */
-    state_iconv_error,      /* A fatal iconv error has occurred */
-    state_transport_error   /* A fatal transport error has occurred */
-  };
-
-struct icvt_stream
-{
-  struct _mu_stream stream;
-  mu_stream_t transport;/* I/O stream */
-  int fallback_mode;
-  iconv_t cd;           /* Conversion descriptor */
-  char *buf;            /* Conversion buffer */
-  size_t bufsize;       /* Size of buf */
-  size_t bufpos;        /* Current position in buf */
-  enum _icvt_state state;
-  int ec;               /* Error code */
-  char errbuf[128];     /* Error message buffer */
-};
-
-static int
-_icvt_open (mu_stream_t stream)
-{
-  struct icvt_stream *s = (struct icvt_stream *)stream;
-  if (s->cd == (iconv_t) -1)
-    return EINVAL;
-  s->state = state_open;
-  return 0;
-}
-
-static int
-_icvt_close (mu_stream_t stream)
-{
-  struct icvt_stream *s = (struct icvt_stream *)stream;
-  if (s->state != state_closed)
-    {
-      mu_stream_close (s->transport);
-      iconv_close (s->cd);
-      s->cd = (iconv_t) -1;
-      s->state = state_closed;
-    }
-  return 0;
-}
-
-static void
-_icvt_done (mu_stream_t stream)
-{
-  struct icvt_stream *s = (struct icvt_stream *)stream;
-
-  if (s->state != state_closed)
-    _icvt_close (stream);
-  mu_stream_destroy (&s->transport);
-  free (s->buf);
-}
-
-static int _icvt_read (mu_stream_t stream, char *optr, size_t osize,
-                      size_t *pnbytes);
-
-static int
-internal_icvt_read (mu_stream_t stream, char *optr, size_t osize,
-                   size_t *pnbytes)
-{
-  struct icvt_stream *s = (struct icvt_stream *)stream;
-  size_t nbytes = 0;
-  int rc, status = 0;
-  char *ob = optr;
-  size_t olen = osize;
-
-  if (s->bufpos == 0)
-    {
-      status = mu_stream_read (s->transport, s->buf, s->bufsize, &nbytes);
-      if (status)
-       {
-         s->state = state_transport_error;
-         s->ec = rc;
-         return MU_ERR_FAILURE;
-       }
-      else if (nbytes == 0)
-       {
-         if (pnbytes)
-           *pnbytes = 0;
-         return 0;
-       }
-    }
-  
-  do
-    {
-      char ICONV_CONST *ib = s->buf;
-      size_t inlen = s->bufpos + nbytes;
-      
-      rc = iconv (s->cd, &ib, &inlen, &ob, &olen);
-      if (ib > s->buf)
-       {
-         memmove (s->buf, ib, inlen);
-         s->bufpos = inlen;
-       }
-      else
-       s->bufpos += nbytes;
-      
-      if (rc == -1)
-       {
-         if (errno == E2BIG)
-           {
-             if (ob > optr)
-               break;
-             else
-               {
-                 s->ec = MU_ERR_BUFSPACE;
-                 return MU_ERR_BUFSPACE;
-               }
-           }
-         else if (errno == EILSEQ)
-           {
-             switch (s->fallback_mode)
-               {
-               case mu_fallback_none:
-                 s->state = state_iconv_error;
-                 s->ec = errno;
-                 if (ob == optr)
-                   return MU_ERR_FAILURE;
-                 break;
-
-               case mu_fallback_copy_pass:
-                 s->state = state_copy_pass;
-                 if (ob == optr)
-                   return _icvt_read (stream, optr, osize, pnbytes);
-                 break;
-                 
-               case mu_fallback_copy_octal:
-                 s->state = state_copy_octal;
-                 if (ob == optr)
-                   return _icvt_read (stream, optr, osize, pnbytes);
-                 break;
-               }
-           }
-         else if (errno == EINVAL)
-           {
-             if (inlen == s->bufsize)
-               {
-                 /* Try to reallocate temp buffer */
-                 char *p = realloc (s->buf, s->bufsize + 128);
-                 if (!p)
-                   return ENOMEM;
-                 s->buf = p;
-                 s->bufsize += 128;
-               }
-             continue;
-           }
-         else
-           {
-             s->ec = errno;
-             s->state = state_iconv_error;
-             return MU_ERR_FAILURE;
-           }
-       }
-    }
-  while (olen > 0 
-        && (status = mu_stream_read (s->transport,
-                                     s->buf + s->bufpos,
-                                     s->bufsize - s->bufpos,
-                                     &nbytes)) == 0
-        && nbytes);
-
-  if (status)
-    {
-      s->state = state_transport_error;
-      s->ec = status;
-      if (ob == optr)
-       return MU_ERR_FAILURE;
-    }
-      
-  if (pnbytes)
-    *pnbytes = ob - optr;
-  return 0;
-}
-
-#define ISPRINT(c) (((c)>=' '&&(c)<127)||(c)=='\n')
-
-static int
-copy_octal (struct icvt_stream *s, char *optr, size_t osize, size_t *pnbytes)
-{
-  size_t i, j;
-  int status;
-  
-  if (osize == 0)
-    return MU_ERR_BUFSPACE;
-  
-  if (s->bufpos < osize)
-    {
-      size_t rdcount = osize;
-      if (s->bufsize < rdcount)
-       {
-         /* Try to reallocate temp buffer */
-         char *p = realloc (s->buf, rdcount);
-         if (p)
-           {
-             s->bufsize = rdcount;
-             s->buf = p;
-           }
-         else
-           rdcount = s->bufsize;
-       }
-
-      status = mu_stream_read (s->transport,
-                              s->buf + s->bufpos,
-                              rdcount - s->bufpos,
-                              &rdcount);
-      if (status)
-       {
-         s->state = state_transport_error;
-         s->ec = status;
-         if (s->bufpos == 0)
-           return MU_ERR_FAILURE;
-       }
-      else
-       s->bufpos += rdcount;
-    }
-  
-  for (i = j = 0; j < osize && i < s->bufpos; i++)
-    {
-      if (ISPRINT (*(unsigned char*)(s->buf+i)))
-       optr[j++] = s->buf[i];
-      else if (j + 4 >= osize)
-       break;
-      else
-       {
-         sprintf (optr + j, "\\%03o", *(unsigned char*)(s->buf+i));
-         j += 4;
-       }
-    }
-  s->bufpos -= i;
-  memmove (s->buf, s->buf + i, s->bufpos);
-  if (pnbytes)
-    *pnbytes = j;
-  return 0;
-}
-
-static int
-copy_pass (struct icvt_stream *s, char *optr, size_t osize, size_t *pnbytes)
-{
-  int status;
-  size_t nbytes;
-  
-  if (s->bufpos)
-    {
-      size_t sz = s->bufpos < osize ? s->bufpos : osize;
-      memcpy (optr, s->buf, sz);
-      s->bufpos -= sz;
-      if (s->bufpos)
-       memmove (s->buf, s->buf + sz, s->bufpos);
-      if (pnbytes)
-       *pnbytes = sz;
-      return 0;
-    }
-
-  status = mu_stream_read (s->transport, optr, osize, &nbytes);
-  if (status)
-    {
-      s->state = state_transport_error;
-      s->ec = status;
-      if (s->bufpos == 0)
-       return MU_ERR_FAILURE;
-    }
-  if (pnbytes)
-    *pnbytes = nbytes;
-  return 0;
-}
-
-static int
-_icvt_read (mu_stream_t stream, char *optr, size_t osize, size_t *pnbytes)
-{
-  struct icvt_stream *s = (struct icvt_stream *)stream;
-
-  switch (s->state)
-    {
-    case state_open:
-      return internal_icvt_read (stream, optr, osize, pnbytes);
-      
-    case state_closed:
-      return EINVAL;
-      
-    case state_copy_pass:
-      return copy_pass (s, optr, osize, pnbytes);
-      
-    case state_copy_octal:
-      return copy_octal (s, optr, osize, pnbytes);
-       
-    default:
-      break;
-    }
-  return MU_ERR_FAILURE;
-}
-
-const char *
-_icvt_strerror (mu_stream_t stream, int rc)
-{
-  struct icvt_stream *s = (struct icvt_stream *)stream;
-
-  switch (s->state)
-    {
-    case state_transport_error:
-      snprintf (s->errbuf, sizeof s->errbuf,
-               _("Transport error: %s"), mu_strerror (s->ec));
-      break;
-
-    case state_iconv_error:
-      switch (s->ec)
-       {
-       case EILSEQ:
-         snprintf (s->errbuf, sizeof s->errbuf,
-                   _("Illegal multibyte sequence near %*.*s"),
-                   (int) s->bufpos, (int) s->bufpos, s->buf);
-         break;
-
-       default:
-         snprintf (s->errbuf, sizeof s->errbuf,
-                   _("Iconv error: %s"), mu_strerror (s->ec));
-       }
-      break;
-
-    case state_closed:
-      return _("Stream is closed"); 
-      
-    default:
-      return mu_strerror (s->ec);
-    }
-  
-  return s->errbuf;
-}
-
-static int
-_icvt_ioctl (mu_stream_t stream, int code, void *ptr)
-{
-  struct icvt_stream *s = (struct icvt_stream *)stream;
-  mu_transport_t *ptrans;
-  
-  switch (code)
-    {
-    case MU_IOCTL_GET_TRANSPORT:
-      if (!ptr)
-       return EINVAL;
-      ptrans = ptr;
-      ptrans[0] = (mu_transport_t) s->transport;
-      ptrans[1] = NULL;
-      break;
-
-    case MU_IOCTL_GET_STREAM:
-    case MU_IOCTL_SET_STREAM:
-    case MU_IOCTL_GET_TRANSPORT_BUFFER:
-    case MU_IOCTL_SET_TRANSPORT_BUFFER:
-      return mu_stream_ioctl (s->transport, code, ptr);
-      
-    default:
-      return ENOSYS;
-    }
-  return 0;
-}
-
-int
-_icvt_wait (mu_stream_t stream, int *pflags, struct timeval *tvp)
-{
-  struct icvt_stream *s = (struct icvt_stream *)stream;
-  return mu_stream_wait (s->transport, pflags, tvp);
-}
-
-/* FIXME: Seeks in the *transport* stream. */
-int
-_icvt_seek (mu_stream_t stream, mu_off_t off, mu_off_t *presult)
-{
-  struct icvt_stream *s = (struct icvt_stream *)stream;
-  return mu_stream_seek (s->transport, off, MU_SEEK_SET, presult);
-}
-
-int
-mu_filter_iconv_create (mu_stream_t *s, mu_stream_t transport,
-                       const char *fromcode, const char *tocode, int flags,
-                       enum mu_iconv_fallback_mode fallback_mode)
-{
-  struct icvt_stream *iptr;
-  iconv_t cd;
-  int rc;
-  mu_stream_t stream;
-    
-  cd = iconv_open (tocode, fromcode);
-  if (cd == (iconv_t) -1)
-    return MU_ERR_FAILURE;
-
-  iptr = (struct icvt_stream *) _mu_stream_create (sizeof (*iptr), flags);
-  if (!iptr)
-    {
-      iconv_close (cd);
-      return ENOMEM;
-    }
-  
-  if (!(flags & MU_STREAM_AUTOCLOSE))
-    mu_stream_ref (transport);
-  iptr->transport = transport;
-  iptr->fallback_mode = fallback_mode;
-  iptr->cd = cd;
-  iptr->state = state_closed;
-  iptr->bufsize = 128;
-  iptr->buf = malloc (iptr->bufsize);
-  if (!iptr->buf)
-    {
-      free (iptr);
-      return ENOMEM;
-    }
-  iptr->bufpos = 0;
-  
-  iptr->stream.open = _icvt_open;
-  iptr->stream.close = _icvt_close;
-  iptr->stream.read = _icvt_read;
-  iptr->stream.done = _icvt_done;
-  iptr->stream.error_string = _icvt_strerror;
-  iptr->stream.ctl = _icvt_ioctl;
-  iptr->stream.wait = _icvt_wait;
-  iptr->stream.seek = _icvt_seek;
-  iptr->stream.flags = MU_STREAM_READ | MU_STREAM_SEEK;
-  stream = (mu_stream_t)iptr;
-  rc = mu_stream_open (stream);
-  if (rc)
-    mu_stream_destroy (&stream);
-  else
-    *s = stream;
-  return 0;
-}
diff --git a/libmailutils/folder.c b/libmailutils/folder.c
deleted file mode 100644
index 3ce430a..0000000
--- a/libmailutils/folder.c
+++ /dev/null
@@ -1,511 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2006, 2007, 2008, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fnmatch.h>
-
-#include <mailutils/auth.h>
-#include <mailutils/debug.h>
-#include <mailutils/iterator.h>
-#include <mailutils/list.h>
-#include <mailutils/monitor.h>
-#include <mailutils/observer.h>
-#include <mailutils/registrar.h>
-#include <mailutils/stream.h>
-#include <mailutils/url.h>
-#include <mailutils/errno.h>
-
-#include <mailutils/sys/folder.h>
-
-/* Internal folder list.  */
-static mu_list_t known_folder_list;
-static int is_known_folder (mu_url_t, mu_folder_t *);
-
-/* Static folder lock.  */
-static struct mu_monitor folder_lock = MU_MONITOR_INITIALIZER;
-
-int
-mu_folder_match (const char *name, void *pattern, int flags)
-{
-  return fnmatch (pattern, name[0] == '/' ? name + 1 : name, flags);
-}
-
-/* A folder could be remote (IMAP), or local(a spool directory) like $HOME/Mail
-   etc ..  We maintain a list of known folders to avoid creating multiple
-   folders for the same URL.  So, when mu_folder_create is called we check if
-   we already have a folder for that URL and return it, otherwise we create a
-   new one.  Downsides: the scheme to detect the same URL is very weak, and
-   there could be cases where you'll want a different folder for the same URL,
-   there is not easy way to do this.  */
-int
-mu_folder_create_from_record (mu_folder_t *pfolder, mu_url_t url,
-                             mu_record_t record)
-{
-  if (!pfolder)
-    return MU_ERR_OUT_PTR_NULL;
-
-  if (record || 
-      /* Look in the registrar list(iterator), for a possible concrete mailbox
-        implementation that could match the URL.  */
-      mu_registrar_lookup_url (url, MU_FOLDER_ATTRIBUTE_DIRECTORY, &record,
-                              NULL) == 0)
-    {
-      int (*f_init) (mu_folder_t) = NULL;
-      
-      mu_record_get_folder (record, &f_init);
-      if (f_init)
-        {
-         int status;
-         mu_folder_t folder;
-         int (*u_init) (mu_url_t) = NULL;
-
-         mu_record_get_url (record, &u_init);
-         if (u_init)
-           {
-             status = u_init (url);
-             if (status)
-               return status;
-           }
-         
-         mu_monitor_wrlock (&folder_lock);
-
-         /* Check if we already have the same URL folder.  */
-         if (is_known_folder (url, &folder))
-           {
-             folder->ref++;
-             *pfolder = folder;
-             mu_url_destroy (&url); /* FIXME: Hmm */
-             mu_monitor_unlock (&folder_lock);
-             return  0;
-           }
-         else
-           mu_monitor_unlock (&folder_lock);
-         
-         /* Create a new folder.  */
-
-         /* Allocate memory for the folder.  */
-         folder = calloc (1, sizeof (*folder));
-         if (folder != NULL)
-           {
-             folder->url = url;
-             /* Initialize the internal foilder lock, now so the
-                concrete folder could use it.  */
-             status = mu_monitor_create (&folder->monitor, 0, folder);
-             if (status == 0)
-               {
-                 /* Create the concrete folder type.  */
-                 status = f_init (folder);
-                 if (status == 0)
-                   {
-                     if (!folder->_match)
-                       folder->_match = mu_folder_match;
-                     *pfolder = folder;
-                     folder->ref++;
-                     /* Put on the internal list of known folders.  */
-                     if (known_folder_list == NULL)
-                       mu_list_create (&known_folder_list);
-                     mu_list_append (known_folder_list, folder);
-                   }
-               }
-             /* Something went wrong, destroy the object. */
-             if (status)
-               {
-                 if (folder->monitor)
-                   mu_monitor_destroy (&folder->monitor, folder);
-                 free (folder);
-               }
-           }
-         return status;
-       }
-    }
-
-    return MU_ERR_NOENT;
-}
-
-int
-mu_folder_create (mu_folder_t *pfolder, const char *name)
-{
-  int rc;
-  mu_url_t url;
-  
-  rc = mu_url_create (&url, name);
-  if (rc)
-    return rc;
-  rc = mu_url_parse (url);
-  if (rc == 0)
-    rc = mu_folder_create_from_record (pfolder, url, NULL);
-  if (rc)
-    mu_url_destroy (&url);
-  return rc;
-}
-
-/* The folder is destroy if it is the last reference.  */
-void
-mu_folder_destroy (mu_folder_t *pfolder)
-{
-  if (pfolder && *pfolder)
-    {
-      mu_folder_t folder = *pfolder;
-      int destroy_lock = 0;
-      mu_monitor_t monitor = folder->monitor;
-
-      mu_monitor_wrlock (monitor);
-
-      /* Check if this the last reference for this folder.  If yes removed
-         it from the list.  */
-      mu_monitor_wrlock (&folder_lock);
-      folder->ref--;
-      /* Remove the folder from the list of known folder.  */
-      if (folder->ref <= 0)
-       mu_list_remove (known_folder_list, folder);
-      /* If the list is empty we can safely remove it.  */
-      if (mu_list_is_empty (known_folder_list))
-       mu_list_destroy (&known_folder_list);
-
-      mu_monitor_unlock (&folder_lock);
-
-      if (folder->ref <= 0)
-       {
-         mu_monitor_unlock (monitor);
-         destroy_lock = 1;
-         /* Notify the observers.  */
-         if (folder->observable)
-           {
-             mu_observable_notify (folder->observable, MU_EVT_FOLDER_DESTROY,
-                                   folder);
-             mu_observable_destroy (&folder->observable, folder);
-           }
-         if (folder->_destroy)
-           folder->_destroy (folder);
-         mu_monitor_wrlock (monitor);
-         if (folder->authority)
-           mu_authority_destroy (&folder->authority, folder);
-         if (folder->stream)
-           mu_stream_destroy (&folder->stream);
-         if (folder->url)
-           mu_url_destroy (&folder->url);
-         free (folder);
-       }
-      mu_monitor_unlock (monitor);
-      if (destroy_lock)
-       mu_monitor_destroy (&monitor, folder);
-      *pfolder = NULL;
-    }
-}
-
-/* Cover functions.  */
-int
-mu_folder_open (mu_folder_t folder, int flags)
-{
-  if (folder == NULL || folder->_open == NULL)
-    return ENOSYS;
-  return folder->_open (folder, flags);
-}
-
-int
-mu_folder_close (mu_folder_t folder)
-{
-  if (folder == NULL || folder->_close == NULL)
-    return ENOSYS;
-  return folder->_close (folder);
-}
-
-int
-mu_folder_set_stream (mu_folder_t folder, mu_stream_t stream)
-{
-  if (folder == NULL)
-    return EINVAL;
-  if (folder->stream)
-    mu_stream_destroy (&folder->stream);
-  folder->stream = stream;
-  return 0;
-}
-
-int
-mu_folder_get_stream (mu_folder_t folder, mu_stream_t *pstream)
-{
-  /* FIXME: Deprecation warning */
-  if (folder == NULL)
-    return EINVAL;
-  if (pstream == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  *pstream = folder->stream;
-  return 0;
-}
-
-int
-mu_folder_get_streamref (mu_folder_t folder, mu_stream_t *pstream)
-{
-  if (folder == NULL)
-    return EINVAL;
-  if (pstream == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  return mu_streamref_create (pstream, folder->stream);
-}
-
-int
-mu_folder_set_authority (mu_folder_t folder, mu_authority_t authority)
-{
-  if (folder == NULL)
-    return EINVAL;
-  if (folder->authority)
-    mu_authority_destroy (&folder->authority, folder);
-  folder->authority = authority;
-  return 0;
-}
-
-int
-mu_folder_get_authority (mu_folder_t folder, mu_authority_t *pauthority)
-{
-  if (folder == NULL)
-    return EINVAL;
-  if (pauthority == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  *pauthority = folder->authority;
-  return 0;
-}
-
-int
-mu_folder_get_observable (mu_folder_t folder, mu_observable_t *pobservable)
-{
-  if (folder == NULL)
-    return EINVAL;
-  if (pobservable == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-
-  if (folder->observable == NULL)
-    {
-      int status = mu_observable_create (&folder->observable, folder);
-      if (status != 0)
-        return status;
-    }
-  *pobservable = folder->observable;
-  return 0;
-}
-
-int
-mu_folder_set_match (mu_folder_t folder, mu_folder_match_fp pmatch)
-{
-  if (folder == NULL)
-    return EINVAL;
-  folder->_match = pmatch;
-  return 0;
-}
-
-int
-mu_folder_get_match (mu_folder_t folder, mu_folder_match_fp *pmatch)
-{
-  if (folder == NULL)
-    return EINVAL;
-  if (pmatch == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  *pmatch = folder->_match;
-  return 0;
-}
-
-int
-mu_folder_has_debug (mu_folder_t folder)
-{
-  if (folder == NULL)
-    return 0;
-
-  return folder->debug ? 1 : 0;
-}
-
-int
-mu_folder_set_debug (mu_folder_t folder, mu_debug_t debug)
-{
-  if (folder == NULL)
-    return EINVAL;
-  if (folder->debug)
-    mu_debug_destroy (&folder->debug, folder);
-  folder->debug = debug;
-  return 0;
-}
-
-int
-mu_folder_get_debug (mu_folder_t folder, mu_debug_t *pdebug)
-{
-  if (folder == NULL)
-    return EINVAL;
-  if (pdebug == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  if (folder->debug == NULL)
-    {
-      int status = mu_debug_create (&folder->debug, folder);
-      if (status != 0)
-        return status;
-    }
-  *pdebug = folder->debug;
-  return 0;
-}
-
-void
-mu_list_response_free (void *data)
-{
-  struct mu_list_response *f = data;
-  free (f->name);
-  free (f);
-}
-
-int
-mu_folder_list (mu_folder_t folder, const char *dirname, void *pattern,
-               size_t max_level,
-               mu_list_t *pflist)
-{
-  return mu_folder_enumerate (folder, dirname, pattern, 0, max_level,
-                             pflist, NULL, NULL);
-}
-
-int
-mu_folder_enumerate (mu_folder_t folder, const char *name,
-                    void *pattern, int flags,
-                    size_t max_level,
-                    mu_list_t *pflist,
-                    mu_folder_enumerate_fp enumfun, void *enumdata)
-{
-  int status;
-  if (folder == NULL || folder->_list == NULL)
-    return EINVAL;
-  else
-    {
-      mu_list_t list = NULL;
-      
-      if (pflist)
-       {
-         status = mu_list_create (&list);
-         if (status)
-           return status;
-         *pflist = list;
-         mu_list_set_destroy_item (list, mu_list_response_free);
-       }
-      else if (!enumfun)
-       return EINVAL;
-      
-      status = folder->_list (folder, name, pattern, flags, max_level,
-                             list, enumfun, enumdata);
-      if (status)
-       mu_list_destroy (pflist);
-    }
-  return status;
-}
-
-int
-mu_folder_lsub (mu_folder_t folder, const char *dirname, const char *basename,
-               mu_list_t *pflist)
-{
-  int status;
-  
-  if (folder == NULL || folder->_lsub == NULL)
-    return ENOSYS;
-  else
-    {
-      status = mu_list_create (pflist);
-      if (status)
-       return status;
-      mu_list_set_destroy_item (*pflist, mu_list_response_free);
-      status = folder->_lsub (folder, dirname, basename, *pflist);
-    }
-  return status;
-}
-
-int
-mu_folder_subscribe (mu_folder_t folder, const char *name)
-{
-  if (folder == NULL || folder->_subscribe == NULL)
-    return EINVAL;
-  return folder->_subscribe (folder, name);
-}
-
-int
-mu_folder_unsubscribe (mu_folder_t folder, const char *name)
-{
-  if (folder == NULL || folder->_unsubscribe == NULL)
-    return EINVAL;
-  return folder->_unsubscribe (folder, name);
-}
-
-int
-mu_folder_delete (mu_folder_t folder, const char *name)
-{
-  if (folder == NULL || folder->_delete == NULL)
-    return ENOSYS;
-  return folder->_delete (folder, name);
-}
-
-int
-mu_folder_rename (mu_folder_t folder, const char *oldname, const char *newname)
-{
-  if (folder == NULL || folder->_rename == NULL)
-    return ENOSYS;
-  return folder->_rename (folder, oldname, newname);
-}
-
-int
-mu_folder_get_url (mu_folder_t folder, mu_url_t *purl)
-{
-  if (folder == NULL)
-    return EINVAL;
-  if (purl == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  *purl = folder->url;
-  return 0;
-}
-
-static int
-is_known_folder (mu_url_t url, mu_folder_t *pfolder)
-{
-  int ret = 0;
-  mu_folder_t folder = NULL;
-  mu_iterator_t iterator;
-
-  if (url == NULL || pfolder == NULL)
-    return ret;
-
-  if (mu_list_get_iterator (known_folder_list, &iterator) != 0)
-    return ret;
-
-  for (mu_iterator_first (iterator); !mu_iterator_is_done (iterator);
-       mu_iterator_next (iterator))
-    {
-      mu_iterator_current (iterator, (void **)&folder);
-      /* Check if the same URL type.  */
-      if (folder && folder->url
-         && mu_url_is_same_scheme (url, folder->url)
-         && mu_url_is_same_user (url, folder->url)
-         && mu_url_is_same_host (url, folder->url)
-         && mu_url_is_same_path (url, folder->url) 
-         && mu_url_is_same_port (url, folder->url))
-       {
-         ret = 1;
-         break;
-       }
-    }
-  if (ret)
-    *pfolder = folder;
-  mu_iterator_destroy (&iterator);
-  return ret;
-}
-
diff --git a/libmailutils/freeitem.c b/libmailutils/freeitem.c
deleted file mode 100644
index c268ea4..0000000
--- a/libmailutils/freeitem.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/* 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdlib.h>
-
-/* Default destroy_item function. */
-void
-mu_list_free_item (void *item)
-{
-  free (item);
-}
diff --git a/libmailutils/fromflt.c b/libmailutils/fromflt.c
deleted file mode 100644
index d96d46d..0000000
--- a/libmailutils/fromflt.c
+++ /dev/null
@@ -1,283 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2003, 2007, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include <mailutils/errno.h>
-#include <mailutils/filter.h>
-#include <mailutils/stream.h>
-
-enum from_decode_state
-  {
-    from_decode_init,
-    from_decode_nl,
-    from_decode_char
-  };
-
-#define GT_FROM_MARK_STR ">From "
-#define GT_FROM_MARK_LEN (sizeof (GT_FROM_MARK_STR) - 1)
-
-/* Move min(isize,osize) bytes from iptr to optr, replacing each '>From '
-   at the beginning of line with 'From '. */
-static enum mu_filter_result
-_from_decoder (void *xd,
-              enum mu_filter_command cmd,
-              struct mu_filter_io *iobuf)
-{
-  int *pstate = xd;
-  const unsigned char *iptr;
-  size_t isize;
-  char *optr;
-  size_t osize;
-  enum from_decode_state state;
-  size_t i, j;
-
-  switch (cmd)
-    {
-    case mu_filter_init:
-      *pstate = from_decode_init;
-      return mu_filter_ok;
-      
-    case mu_filter_done:
-      return mu_filter_ok;
-      
-    default:
-      state = *pstate;
-      break;
-    }
-  
-  iptr = (const unsigned char *) iobuf->input;
-  isize = iobuf->isize;
-  optr = iobuf->output;
-  osize = iobuf->osize;
-
-  for (i = j = 0; i < isize && j < osize; i++)
-    {
-      unsigned char c = *iptr++;
-      
-      if (c == '\n')
-       state = from_decode_nl;
-      else if (state == from_decode_init || state == from_decode_nl)
-       {
-         size_t len = isize - i;
-
-         if (len < GT_FROM_MARK_LEN)
-           {
-             if (memcmp (iptr - 1, GT_FROM_MARK_STR, len) == 0)
-               {
-                 if (i == 0)
-                   {
-                     iobuf->isize = GT_FROM_MARK_LEN - len;
-                     return mu_filter_moreinput;
-                   }
-                 break;
-               }
-             else
-               state = from_decode_char;
-           }
-         else if (memcmp (iptr - 1, GT_FROM_MARK_STR, GT_FROM_MARK_LEN) == 0)
-           {
-             /* Skip > */
-             state = from_decode_char;
-             continue;
-           }
-       }         
-      optr[j++] = c;
-    }
-
-  *pstate = state;
-  iobuf->isize = i;
-  iobuf->osize = j;
-  return mu_filter_ok;
-}
-
-#define FROM_MARK_STR "From "
-#define FROM_MARK_LEN (sizeof (FROM_MARK_STR) - 1)
-
-enum from_encode_state
-  {
-    from_encode_init,
-    from_encode_nl,
-    from_encode_char,
-    from_encode_gt,
-    from_encode_f,
-    from_encode_r,
-    from_encode_o,
-    from_encode_m,
-    from_encode_sp
-  };
-
-static int length_to_state_tab[] = {
-  from_encode_gt,
-  from_encode_f,
-  from_encode_r,
-  from_encode_o,
-  from_encode_m,
-  from_encode_sp
-};
-
-static int state_to_length_tab[] = {
-  0, 0, 0,
-  GT_FROM_MARK_LEN,
-  GT_FROM_MARK_LEN-1,
-  GT_FROM_MARK_LEN-2,
-  GT_FROM_MARK_LEN-3,
-  GT_FROM_MARK_LEN-4,
-  GT_FROM_MARK_LEN-5
-};      
-
-/* Move min(isize,osize) bytes from iptr to optr, replacing each 'From '
-   at the beginning of line with '>From '. */
-
-static enum mu_filter_result
-_from_encoder (void *xd,
-              enum mu_filter_command cmd,
-              struct mu_filter_io *iobuf)
-{
-  int *pstate = xd;
-  const unsigned char *iptr;
-  size_t isize;
-  char *optr;
-  size_t osize;
-  enum from_encode_state state;
-  size_t i, j;
-  
-  switch (cmd)
-    {
-    case mu_filter_init:
-      *pstate = from_encode_init;
-      return mu_filter_ok;
-      
-    case mu_filter_done:
-      return mu_filter_ok;
-      
-    default:
-      state = *pstate;
-      switch (state)
-       {
-       case from_encode_init:
-       case from_encode_nl:
-       case from_encode_char:
-         break;
-
-       default:
-         osize = state_to_length_tab[state];
-         if (iobuf->osize < osize)
-           {
-             iobuf->osize = osize;
-             return mu_filter_moreoutput;
-           }
-         memcpy (iobuf->output, GT_FROM_MARK_STR + GT_FROM_MARK_LEN - osize,
-                 osize);
-         iobuf->osize = osize;
-         iobuf->isize = osize;
-         *pstate = from_encode_init;
-         return mu_filter_ok;
-       }
-      break;
-    }
-  
-  iptr = (const unsigned char *) iobuf->input;
-  isize = iobuf->isize;
-  optr = iobuf->output;
-  osize = iobuf->osize;
-
-  for (i = j = 0; i < isize && j < osize; i++)
-    {
-      unsigned char c = *iptr++;
-      
-      if (c == '\n')
-       state = from_encode_nl;
-      else if (state == from_encode_init || state == from_encode_nl)
-       {
-         size_t len = isize - i;
-
-         if (len < FROM_MARK_LEN)
-           {
-             if (memcmp (iptr - 1, FROM_MARK_STR, len) == 0)
-               {
-                 if (i == 0)
-                   {
-                     iobuf->isize = FROM_MARK_LEN;
-                     return mu_filter_moreinput;
-                   }
-                 break;
-               }
-             else
-               state = from_encode_char;
-           }
-         else if (memcmp (iptr - 1, FROM_MARK_STR, FROM_MARK_LEN) == 0)
-           {
-             size_t rest = osize - j;
-             
-             if (rest > GT_FROM_MARK_LEN)
-               rest = GT_FROM_MARK_LEN;
-             else if (rest < 2)
-               {
-                 if (i == 0)
-                   {
-                     iobuf->osize = GT_FROM_MARK_LEN;
-                     return mu_filter_moreoutput;
-                   }
-                 break;
-               }
-             
-             memcpy (optr + j, GT_FROM_MARK_STR, rest);
-             i += rest - 2;
-             iptr += rest - 2;
-             j += rest;
-             if (rest < GT_FROM_MARK_LEN)
-               state = length_to_state_tab[rest];
-             else
-               state = from_encode_char;
-             continue;
-           }
-         else
-           state = from_encode_char;
-       }
-      optr[j++] = c;
-    }
-  *pstate = state;
-  iobuf->isize = i;
-  iobuf->osize = j;
-  return mu_filter_ok;
-}
-
-static int
-_from_alloc_state (void **pret, int mode, void *data MU_ARG_UNUSED)
-{
-  *pret = malloc (sizeof (int));
-  if (!*pret)
-    return ENOMEM;
-  return 0;
-}
-
-static struct _mu_filter_record _from_filter = {
-  "FROM",
-  0,
-  _from_alloc_state,
-  _from_encoder,
-  _from_decoder
-};
-
-mu_filter_record_t mu_from_filter = &_from_filter;
-
diff --git a/libmailutils/gdebug.c b/libmailutils/gdebug.c
deleted file mode 100644
index 3d1a54c..0000000
--- a/libmailutils/gdebug.c
+++ /dev/null
@@ -1,263 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2008, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <mailutils/cctype.h>
-#include <mailutils/assoc.h>
-#include <mailutils/error.h>
-#include <mailutils/errno.h>
-#include <mailutils/argcv.h>
-#include <mailutils/debug.h>
-#include <mailutils/cfg.h>
-#include <mailutils/nls.h>
-
-int mu_debug_line_info = 0;
-
-struct debug_level
-{
-  unsigned level;
-};
-
-static mu_assoc_t debug_table;
-
-mu_log_level_t
-mu_global_debug_level (const char *object_name)
-{
-  struct debug_level *p = mu_assoc_ref (debug_table, object_name);
-  if (p)
-    return p->level;
-  return 0;
-}
-
-int
-mu_global_debug_set_level (const char *object_name, mu_log_level_t level)
-{
-  int rc;
-  struct debug_level *dbg;
-  
-  if (!debug_table)
-    {
-      rc = mu_assoc_create (&debug_table, sizeof(struct debug_level), 0);
-      if (rc)
-       return rc;
-    }
-
-  rc = mu_assoc_ref_install (debug_table, object_name, (void**) &dbg);
-  if (rc == 0 || rc == MU_ERR_EXISTS)
-    dbg->level = level;
-  return rc;
-}
-
-int
-mu_global_debug_clear_level (const char *object_name)
-{
-  int rc = 0;
-  
-  if (!object_name)
-    mu_assoc_clear (debug_table);
-  else
-    rc = mu_assoc_remove (debug_table, object_name);
-  return rc;
-}
-
-int
-decode_debug_level (const char *p, int *lev)
-{
-  if (strcmp (p, "error") == 0)
-    *lev = MU_DEBUG_ERROR;
-  else if (strncmp (p, "trace", 5) == 0 && mu_isdigit (p[5]) && p[6] == 0)
-    *lev = MU_DEBUG_TRACE0 + atoi (p + 5);
-  else if (strcmp (p, "proto") == 0)
-    *lev = MU_DEBUG_PROT;
-  else
-    return 1;
-  return 0;
-}
-
-int
-mu_debug_level_from_string (const char *string, mu_log_level_t *plev,
-                           mu_debug_t debug)
-{
-  char *q;
-  unsigned level = MU_DEBUG_INHERIT;
-  
-  if (mu_isdigit (*string))
-    {
-      level = strtoul (string, &q, 0);
-      if (*q)
-       {
-         mu_cfg_format_error (debug, MU_DEBUG_ERROR,
-                              _("invalid debugging specification `%s': "
-                                "expected levels or number after `=', "
-                                "but found `%s'"),
-                              string, string);
-         return MU_ERR_FAILURE;
-       }
-    }
-  else
-    {
-      char *p = strdup (string);
-      size_t len = strlen (p);
-      if (len > 0 && p[len-1] == '\n')
-       p[len-1] = 0;
-      for (q = strtok (p, ","); q; q = strtok (NULL, ","))
-       {
-         int flag;
-         int revert = 0;
-         int upto = 0;
-         
-         if (*q == '!')
-           {
-             q++;
-             revert = 1;
-           }
-         if (*q == '<')
-           {
-             q++;
-             upto = 1;
-           }
-         
-         if (decode_debug_level (q, &flag))
-           mu_cfg_format_error (debug, MU_DEBUG_ERROR,
-                                _("invalid debugging level `%s'"),
-                                q);
-         else if (revert)
-           {
-             if (upto)
-               level &= ~MU_DEBUG_LEVEL_UPTO (flag);
-             else
-               level &= ~MU_DEBUG_LEVEL_MASK (flag);
-           }
-         else
-           {
-             if (upto)
-               level |= MU_DEBUG_LEVEL_UPTO (flag);
-             else
-               level |= MU_DEBUG_LEVEL_MASK (flag);
-           }
-       }
-      free (p);
-    }
-  *plev = level;
-  return 0;
-}
-
-int
-mu_global_debug_from_string (const char *string, const char *errpfx)
-{
-  int rc;
-  int argc;
-  char **argv;
-  int i;
-  
-  rc = mu_argcv_get (string, ";", NULL, &argc, &argv);
-  if (rc)
-    return rc;
-
-  for (i = 0; i < argc; i++)
-    {
-      char *p;
-      mu_log_level_t level = MU_DEBUG_INHERIT;
-      char *object_name = argv[i];
-      
-      for (p = object_name; *p && *p != '='; p++)
-       ;
-
-      if (*p == '=')
-       {
-         /* FIXME: Use mu_debug_level_from_string */
-         char *q;
-         
-         *p++ = 0;
-         if (mu_isdigit (*p))
-           {
-             level = strtoul (p, &q, 0);
-             if (*q)
-               {
-                 mu_error ("%s: invalid debugging specification `%s': "
-                           "expected levels or number after `=', "
-                           "but found `%s'",
-                           errpfx, argv[i], p);
-                 break;
-               }
-           }
-         else
-           {
-             char *q;
-             for (q = strtok (p, ","); q; q = strtok (NULL, ","))
-               {
-                 int flag;
-                 int revert = 0;
-                 int upto = 0;
-                 
-                 if (*q == '!')
-                   {
-                     q++;
-                     revert = 1;
-                   }
-                 if (*q == '<')
-                   {
-                     q++;
-                     upto = 1;
-                   }
-                 
-                 if (decode_debug_level (q, &flag))
-                   mu_error ("%s: invalid debugging level `%s'",
-                             errpfx, q);
-                 else if (revert)
-                   {
-                     if (upto)
-                       level &= ~MU_DEBUG_LEVEL_UPTO (flag);
-                     else
-                       level &= ~MU_DEBUG_LEVEL_MASK (flag);
-                   }
-                 else
-                   {
-                     if (upto)
-                       level |= MU_DEBUG_LEVEL_UPTO (flag);
-                     else
-                       level |= MU_DEBUG_LEVEL_MASK (flag);
-                   }
-               }
-           }   
-       }         
-      else
-       level |= MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT);
-      
-      if (p[-1] == ':')
-       {
-         p[-1] = 0;
-         level &= ~MU_DEBUG_INHERIT;
-       }
-      
-      mu_global_debug_set_level (object_name, level);
-    }
-  
-  mu_argcv_free (argc, argv);
-  return 0;
-}
-
-
diff --git a/libmailutils/gocs.c b/libmailutils/gocs.c
deleted file mode 100644
index 40bde9d..0000000
--- a/libmailutils/gocs.c
+++ /dev/null
@@ -1,397 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2007, 2008, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include <string.h>
-#include <mailutils/types.h>
-#include <mailutils/gocs.h>
-#include <mailutils/mailbox.h>
-#include <mailutils/locker.h>
-#include <mailutils/mutil.h>
-#include <mailutils/mailer.h>
-#include <mailutils/error.h>
-#include <mailutils/errno.h>
-#include <mailutils/nls.h>
-#include <mailutils/debug.h>
-#include <mailutils/syslog.h>
-#include <mailutils/registrar.h>
-#include <syslog.h>
-
-int mu_load_user_rcfile = 1;
-int mu_load_site_rcfile = 1;
-char *mu_load_rcfile = NULL;
-
-
-int
-mu_gocs_dummy (enum mu_gocs_op op, void *data)
-{
-  return 0;
-}
-
-int
-mu_gocs_mailbox_init (enum mu_gocs_op op, void *data)
-{
-  int rc;
-  struct mu_gocs_mailbox *p = data;
-
-  if (op == mu_gocs_op_set && p)
-    {
-      if (p->mail_spool)
-       {
-         rc = mu_set_mail_directory (p->mail_spool);
-         if (rc)
-           mu_error (_("cannot set mail directory name to `%s': %s"),
-                     p->mail_spool, mu_strerror (rc));
-         free (p->mail_spool);
-         p->mail_spool = NULL;
-       }
-      if (p->mailbox_pattern)
-       {
-         rc = mu_set_mailbox_pattern (p->mailbox_pattern);
-         if (rc)
-           mu_error (_("cannot set mailbox pattern to `%s': %s"),
-                     p->mailbox_pattern, mu_strerror (rc));
-         free (p->mailbox_pattern);
-         p->mailbox_pattern = NULL;
-       }
-      if (p->mailbox_type)
-       {
-         if (mu_registrar_set_default_scheme (p->mailbox_type))
-           mu_error (_("invalid mailbox type: %s"), p->mailbox_type);
-         free (p->mailbox_type);
-         p->mailbox_type = NULL;
-       }
-    }
-  return 0;
-}
-
-int
-mu_gocs_locking_init (enum mu_gocs_op op, void *data)
-{
-  struct mu_gocs_locking *p = data;
-  
-  if (!(op == mu_gocs_op_set && p))
-    return 0;
-
-  if (p->lock_flags)
-    {
-      int flags = 0;
-      char *s;
-      
-      for (s = p->lock_flags; *s; s++)
-       {
-         switch (*s)
-           {
-           case 'E':
-             flags |= MU_LOCKER_EXTERNAL;
-             break;
-             
-           case 'R':
-             flags |= MU_LOCKER_RETRY;
-             break;
-             
-           case 'T':
-             flags |= MU_LOCKER_TIME;
-             break;
-             
-           case 'P':
-             flags |= MU_LOCKER_PID;
-             break;
-             
-           default:
-             mu_error (_("invalid lock flag `%c'"), *s);
-           }
-       }
-      mu_locker_set_default_flags (flags, mu_locker_assign);
-      free (p->lock_flags);
-      p->lock_flags = NULL;
-    }
-
-  if (p->lock_retry_count)
-    {
-      mu_locker_set_default_retry_count (p->lock_retry_count);
-      mu_locker_set_default_flags (MU_LOCKER_RETRY, mu_locker_set_bit);
-      p->lock_retry_count = 0;
-    }
-
-  if (p->lock_retry_timeout)
-    {
-      mu_locker_set_default_retry_timeout (p->lock_retry_timeout);
-      mu_locker_set_default_flags (MU_LOCKER_RETRY, mu_locker_set_bit);
-      p->lock_retry_timeout = 0;
-    }
-
-  if (p->lock_expire_timeout)
-    {
-      mu_locker_set_default_expire_timeout (p->lock_expire_timeout);
-      mu_locker_set_default_flags (MU_LOCKER_EXTERNAL, mu_locker_set_bit);
-      p->lock_expire_timeout = 0;
-    }
-
-  if (p->external_locker)
-    {
-      mu_locker_set_default_external_program (p->external_locker);
-      mu_locker_set_default_flags (MU_LOCKER_TIME, mu_locker_set_bit);
-      free (p->external_locker);
-      p->external_locker = NULL;
-    }
-  return 0;
-}
-
-int
-mu_gocs_source_email_init (enum mu_gocs_op op, void *data)
-{
-  struct mu_gocs_source_email *p = data;
-  int rc;
-
-  if (!(op == mu_gocs_op_set && p))
-    return 0;
-  
-  if (p->address)
-    {
-      if ((rc = mu_set_user_email (p->address)) != 0)
-       mu_error (_("invalid email address `%s': %s"),
-                 p->address, mu_strerror (rc));
-      free (p->address);
-      p->address = NULL;
-    }
-
-  if (p->domain)
-    {
-      if ((rc = mu_set_user_email_domain (p->domain)) != 0)
-       mu_error (_("invalid email domain `%s': %s"),
-                 p->domain, mu_strerror (rc));
-
-      free (p->domain);
-      p->domain = NULL;
-    }
-  return 0;
-}
-
-int
-mu_gocs_mailer_init (enum mu_gocs_op op, void *data)
-{
-  struct mu_gocs_mailer *p = data;
-  int rc;
-
-  if (!(op == mu_gocs_op_set && p))
-    return 0;
-  
-  if (p->mailer)
-    {
-      if ((rc = mu_mailer_set_url_default (p->mailer)) != 0)
-       mu_error (_("invalid mailer URL `%s': %s"),
-                 p->mailer, mu_strerror (rc));
-      free (p->mailer);
-      p->mailer = NULL;
-    }
-  return 0;
-}
-
-int
-mu_gocs_logging_init (enum mu_gocs_op op, void *data)
-{
-  struct mu_gocs_logging *p = data;
-
-  if (op == mu_gocs_op_set)
-    {
-      if (!p)
-       {
-         static struct mu_gocs_logging default_gocs_logging = { LOG_FACILITY };
-         p = &default_gocs_logging;
-       }
-  
-      if (p->facility)
-       {
-         mu_log_facility = p->facility;
-         mu_debug_default_printer = mu_debug_syslog_printer;
-       }
-      else
-       mu_debug_default_printer = mu_debug_stderr_printer;
-
-      if (p->tag)
-       mu_log_tag = strdup (p->tag);
-    }
-  return 0;
-}
-
-int
-mu_gocs_debug_init (enum mu_gocs_op op, void *data)
-{
-  if (op == mu_gocs_op_set && data)
-    {
-      struct mu_gocs_debug *p = data;
-      if (p->string && p->errpfx)
-       {
-         mu_global_debug_from_string (p->string, p->errpfx);
-         free (p->errpfx);
-       }
-      if (p->line_info >= 0)
-       mu_debug_line_info = p->line_info;
-    }
-  return 0;
-}
-
-
-struct mu_gocs_entry
-{
-  const char *name;
-  mu_gocs_init_fp init;
-};
-
-#define MAX_GOCS 512
-
-static struct mu_gocs_entry _gocs_table[MAX_GOCS];
-
-void
-mu_gocs_register (const char *capa, mu_gocs_init_fp init)
-{
-  int i;
-  for (i = 0; _gocs_table[i].name; i++)
-    if (i == MAX_GOCS-1)
-      {
-       mu_error (_("gocs table overflow"));
-       abort ();
-      }
-  _gocs_table[i].name = capa;
-  _gocs_table[i].init = init;
-}
-
-int
-mu_gocs_enumerate (mu_list_action_t action, void *data)
-{
-  int i;
-  
-  for (i = 0; _gocs_table[i].name; i++)
-    {
-      int rc = action ((void*) _gocs_table[i].name, data);
-      if (rc)
-       return rc;
-    }
-  return 0;
-}
-
-static mu_gocs_init_fp
-find_init_function (struct mu_gocs_entry *tab, const char *capa)
-{
-  for (; tab->name; tab++)
-    if (strcmp (tab->name, capa) == 0)
-      return tab->init;
-  return NULL;
-}
-
-static struct mu_gocs_entry std_gocs_table[] = {
-  { "common", mu_gocs_dummy },
-  { "license", mu_gocs_dummy },
-  { "mailbox", mu_gocs_mailbox_init },
-  { "locking", mu_gocs_locking_init },
-  { "address", mu_gocs_source_email_init },
-  { "mailer", mu_gocs_mailer_init },
-  { "logging", mu_gocs_logging_init },
-  { "debug", mu_gocs_debug_init },
-  { "auth", mu_gocs_dummy },
-  { NULL }
-};
-
-void
-mu_gocs_register_std (const char *name)
-{
-  mu_gocs_init_fp init = find_init_function (std_gocs_table, name);
-  if (!init)
-    {
-      mu_error (_("INTERNAL ERROR at %s:%d: unknown standard capability `%s'"),
-               __FILE__, __LINE__, name);
-      abort ();
-    }
-  mu_gocs_register (name, init);
-}
-
-
-struct mu_gocs_data
-{
-  char *capa;
-  void *data;
-};
-
-static mu_list_t /* of struct mu_gocs_data */ data_list;
-
-static int
-_gocs_comp (const void *a, const void *b)
-{
-  const struct mu_gocs_data *da = a, *db = b;
-  return !(strcmp (da->capa, db->capa) == 0 && da->data == db->data);
-}
-
-void
-mu_gocs_store (char *capa, void *data)
-{
-  struct mu_gocs_data *s;
-  if (!data_list)
-    {
-      mu_list_create (&data_list);
-      mu_list_set_destroy_item (data_list, mu_list_free_item);
-      mu_list_set_comparator (data_list, _gocs_comp);
-    }
-  s = malloc (sizeof *s);
-  if (!s)
-    {
-      mu_error ("%s", mu_strerror (ENOMEM));
-      exit (1);
-    }
-  s->capa = capa;
-  s->data = data;
-  if (mu_list_locate (data_list, s, NULL) == 0)
-    free (s);
-  else
-    mu_list_prepend (data_list, s);
-}
-
-int
-_gocs_flush (void *item, void *data)
-{
-  struct mu_gocs_data *s = item;
-  mu_gocs_init_fp initfun = find_init_function (_gocs_table, s->capa);
-
-  if (!initfun)
-    {
-      mu_error (_("INTERNAL ERROR at %s:%d: unknown capability `%s'"),
-               __FILE__, __LINE__, s->capa);
-      abort ();
-    }
-
-  if (initfun (mu_gocs_op_set, s->data))
-    {
-      mu_error (_("initialization of GOCS `%s' failed"), s->capa);
-      return 1;
-    }
-  
-  return 0;
-}
-
-void
-mu_gocs_flush ()
-{
-  int i;
-  mu_list_do (data_list, _gocs_flush, NULL);
-
-  for (i = 0; _gocs_table[i].name; i++)
-    _gocs_table[i].init (mu_gocs_op_flush, NULL);
-}
diff --git a/libmailutils/hdritr.c b/libmailutils/hdritr.c
deleted file mode 100644
index 595735f..0000000
--- a/libmailutils/hdritr.c
+++ /dev/null
@@ -1,162 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2008, 2010 Free Software Foundation, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library; if not, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-/* Mail header iterators. */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include <string.h>
-
-#include <mailutils/sys/header.h>
-#include <mailutils/errno.h>
-
-struct header_iterator
-{
-  mu_header_t header;
-  size_t index;
-};
-
-static int
-hdr_first (void *owner)
-{
-  struct header_iterator *itr = owner;
-  itr->index = 1;
-  return 0;
-}
-
-static int
-hdr_next (void *owner)
-{
-  struct header_iterator *itr = owner;
-  itr->index++;
-  return 0;
-}
-
-static int
-hdr_getitem (void *owner, void **pret, const void **pkey)
-{
-  struct header_iterator *itr = owner;
-  int rc;
-  size_t count;
-
-  rc = mu_header_get_field_count (itr->header, &count);
-  if (rc)
-    return rc;
-  if (itr->index > count)
-    return MU_ERR_NOENT;
-  
-  rc = mu_header_sget_field_name (itr->header, itr->index,
-                                 (const char**) pkey);
-  if (rc == 0)
-    {
-      if (pkey)
-       rc = mu_header_sget_field_value (itr->header, itr->index,
-                                        (const char**) pret);
-    }
-  return rc;
-}
-
-static int
-hdr_finished_p (void *owner)
-{
-  struct header_iterator *itr = owner;
-  size_t count;
-
-  if (mu_header_get_field_count (itr->header, &count))
-    return 1;
-  return itr->index > count;
-}
-
-static int
-hdr_destroy (mu_iterator_t iterator, void *data)
-{
-  struct header_iterator *itr = data;
-  mu_iterator_detach (&itr->header->itr, iterator);
-  free (data);
-  return 0;
-}
-
-static int
-hdr_curitem_p (void *owner, void *item)
-{
-  void *ptr;
-
-  if (hdr_getitem (owner, &ptr, NULL))
-    return 0;
-  return ptr == item;
-}
-
-static int
-hdr_data_dup (void **ptr, void *owner)
-{
-  struct header_iterator *itr = owner;
-
-  *ptr = malloc (sizeof (struct header_iterator));
-  if (*ptr == NULL)
-    return ENOMEM;
-  memcpy (*ptr, owner, sizeof (struct header_iterator));
-  mu_iterator_attach (&itr->header->itr, *ptr);
-  return 0;
-}
-
-int
-mu_header_get_iterator (mu_header_t hdr, mu_iterator_t *piterator)
-{
-  mu_iterator_t iterator;
-  int status;
-  struct header_iterator *itr;
-
-  if (!hdr)
-    return EINVAL;
-
-  itr = calloc (1, sizeof *itr);
-  if (!itr)
-    return ENOMEM;
-  itr->header = hdr;
-  itr->index = 1;
-
-  status = mu_iterator_create (&iterator, itr);
-  if (status)
-    {
-      free (itr);
-      return status;
-    }
-
-  mu_iterator_set_first (iterator, hdr_first);
-  mu_iterator_set_next (iterator, hdr_next);
-  mu_iterator_set_getitem (iterator, hdr_getitem);
-  mu_iterator_set_finished_p (iterator, hdr_finished_p);
-  mu_iterator_set_curitem_p (iterator, hdr_curitem_p);
-  mu_iterator_set_destroy (iterator, hdr_destroy);
-  mu_iterator_set_dup (iterator, hdr_data_dup);
-
-  mu_iterator_attach (&hdr->itr, iterator);
-
-  *piterator = iterator;
-  return 0;
-}
-
-
-
-
-
-
-
-
diff --git a/libmailutils/header.c b/libmailutils/header.c
deleted file mode 100644
index 7c95e08..0000000
--- a/libmailutils/header.c
+++ /dev/null
@@ -1,1222 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2008, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-/*  This all header business needs a good rewrite.
- *          -- Alain Magloire, 2000-07-03 (rev. 1.21)
- *
- *  It's the job that's never started as takes longest to finish.
- *          -- Hamfast Gamgee, some time in the Third Age
- *
- *  It took almost 7 years to gather the courage to start the job,
- *  and only one day to finish it.
- *          -- Sergey Poznyakoff, 2007-06-24
- */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <errno.h>
-
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
-#endif
-
-#include <mailutils/stream.h>
-#include <mailutils/address.h>
-#include <mailutils/mutil.h>
-#include <mailutils/errno.h>
-#include <mailutils/cstr.h>
-#include <mailutils/sys/header_stream.h>
-#include <mailutils/sys/header.h>
-
-#define HEADER_MODIFIED   0x01
-#define HEADER_INVALIDATE 0x02
-
-#define HEADER_SET_MODIFIED(h) \
-  ((h)->flags |= (HEADER_MODIFIED|HEADER_INVALIDATE))
-
-
-/* mu_hdrent manipulation */
-
-#define MU_HDRENT_NAME(hp,ep) ((hp)->spool + (ep)->fn)
-#define MU_HDRENT_VALUE(hp,ep) ((hp)->spool + (ep)->fv)
-#define MU_STR_SIZE(nlen,vlen) ((nlen) + 2 + (vlen) + 1)
-
-static struct mu_hdrent *
-mu_hdrent_nth (struct _mu_header *hdr, int n)
-{
-  struct mu_hdrent *p;
-  for (p = hdr->head; p; p = p->next)
-    if (n-- == 1)
-      break;
-  return p;
-}
-
-static struct mu_hdrent *
-mu_hdrent_find (struct _mu_header *hdr, const char *name, int pos)
-{
-  struct mu_hdrent *p;
-
-  if (pos > 0)
-    {
-      for (p = hdr->head; p; p = p->next)
-       if (mu_c_strcasecmp (MU_HDRENT_NAME (hdr,p), name) == 0 && pos-- == 1)
-         break;
-    }
-  else if (pos < 0)
-    {
-      for (p = hdr->tail; p; p = p->prev)
-       if (mu_c_strcasecmp (MU_HDRENT_NAME (hdr,p), name) == 0 && ++pos == 0)
-         break;
-    }
-  else
-    p = NULL;
-  return p;
-}
-
-static int
-mu_hdrent_find_stream_pos (struct _mu_header *hdr, mu_off_t pos,
-                          struct mu_hdrent **pent, size_t *poff)
-{
-  mu_off_t x;
-  struct mu_hdrent *p;
-
-  for (p = hdr->head, x = 0; p; p = p->next)
-    {
-      size_t strsize = MU_STR_SIZE (p->nlen, p->vlen);
-      if (x <= pos && pos < x + strsize)
-       {
-         *poff = pos - x;
-         *pent = p;
-         return 0;
-       }
-      x += strsize;
-    }
-  if (x == pos && hdr->tail)
-    {
-      /* To supply the trailing '\n' */
-      p = hdr->tail;
-      *pent = p;
-      *poff = MU_STR_SIZE (p->nlen, p->vlen) - 1;
-      return 0;
-    }
-  return 1;
-}
-     
-static void
-mu_hdrent_count (struct _mu_header *hdr, size_t *pcount, size_t *psize,
-                size_t *plines)
-{
-  if (hdr->flags & HEADER_INVALIDATE)
-    {
-      size_t size = 0;
-      size_t count = 0;
-      size_t lines = 0;
-      struct mu_hdrent *p;
-      for (p = hdr->head; p; p = p->next)
-       {
-         count++;
-         size += MU_STR_SIZE (p->nlen, p->vlen);
-         lines += p->nlines;
-       }
-
-      hdr->numhdr = count;
-      hdr->numlines = lines;
-      hdr->size = size;
-      hdr->flags &= ~HEADER_INVALIDATE;
-    }
-      
-  *pcount = hdr->numhdr;
-  *psize = hdr->size;
-  *plines = hdr->numlines;
-}
-
-static void
-mu_hdrent_remove (struct _mu_header *hdr, struct mu_hdrent *ent)
-{
-  struct mu_hdrent *p = ent->prev;
-  if (p)
-    p->next = ent->next;
-  else
-    hdr->head = ent->next;
-
-  p = ent->next;
-  if (p)
-    p->prev = ent->prev;
-  else
-    hdr->tail = ent->prev;
-}
-
-static void
-mu_hdrent_prepend (struct _mu_header *hdr, struct mu_hdrent *ent)
-{
-  struct mu_hdrent *p = hdr->head;
-  ent->prev = NULL;
-  ent->next = p;
-  if (p)
-    p->prev = ent;
-  else
-    hdr->tail = ent;
-  hdr->head = ent;
-}
-
-static void
-mu_hdrent_append (struct _mu_header *hdr, struct mu_hdrent *ent)
-{
-  struct mu_hdrent *p = hdr->tail;
-  ent->next = NULL;
-  ent->prev = p;
-  if (p)
-    p->next = ent;
-  else
-    hdr->head = ent;
-  hdr->tail = ent;
-}
-
-static int
-mu_hdrent_insert (struct _mu_header *hdr, struct mu_hdrent *ent,
-                 const char *name, int pos, int before)
-{
-  struct mu_hdrent *p;
-  struct mu_hdrent *ref = mu_hdrent_find (hdr, name, pos);
-  if (!ref)
-    return MU_ERR_NOENT;
-
-  if (before)
-    {
-      ref = ref->prev;
-      if (!ref)
-       {
-         mu_hdrent_prepend (hdr, ent);
-         return 0;
-       }
-    }
-
-  p = ref->next;
-  if (!p)
-    {
-      mu_hdrent_append (hdr, ent);
-      return 0;
-    }
-
-  ent->next = p;
-  p->prev = ent;
-  ent->prev = ref;
-  ref->next = ent;
-  
-  return 0;
-}
-
-#define SPOOLBLKSIZ 1024
-
-static struct mu_hdrent *
-mu_hdrent_create (struct _mu_header *ph,
-                 struct mu_hdrent *ent,
-                 const char *name, size_t nsize,
-                 const char *value, size_t vsize)
-{
-  size_t strsize;
-  size_t sizeleft;
-  const char *p;
-  
-  if (!ent)
-    {
-      ent = calloc (1, sizeof (*ent));
-      if (!ent)
-       return NULL;
-    }
-  
-  strsize = MU_STR_SIZE (nsize, vsize);
-  sizeleft = ph->spool_size - ph->spool_used;
-
-  /* Ensure there is enough space in spool */
-  if (sizeleft < strsize)
-    {
-      char *newp;
-      size_t delta = (strsize - sizeleft + SPOOLBLKSIZ - 1) / SPOOLBLKSIZ;
-      delta *= SPOOLBLKSIZ;
-      newp = realloc (ph->spool, ph->spool_size + delta);
-      if (!newp)
-       return 0;
-      ph->spool = newp;
-      ph->spool_size += delta;
-    }
-
-  /* Copy header name */
-  ent->fn = ph->spool_used;
-  ent->nlen = nsize;
-  memcpy (ph->spool + ph->spool_used, name, nsize);
-  ph->spool_used += nsize;
-  ph->spool[ph->spool_used++] = 0;
-  ph->spool[ph->spool_used++] = ' ';
-
-  /* Copy header value */
-  ent->fv = ph->spool_used;
-  ent->vlen = vsize;
-  memcpy (ph->spool + ph->spool_used, value, vsize);
-  ph->spool_used += vsize;
-  ph->spool[ph->spool_used++] = 0;
-  
-  ent->nlines = 1;
-  for (p = value; p < value + vsize; p++)
-    if (*p == '\n')
-      ent->nlines++;
-  
-  return ent;
-}
-
-static void
-mu_hdrent_free_list (struct _mu_header *hdr)
-{
-  struct mu_hdrent *p;
-  for (p = hdr->head; p; )
-    {
-      struct mu_hdrent *next = p->next;
-      free (p);
-      p = next;
-    }
-  hdr->head = hdr->tail = NULL;
-  hdr->spool_used = 0;
-}
-  
-
-
-#define ISLWSP(c) (((c) == ' ' || (c) == '\t'))
-
-/* Parsing is done in a rather simple fashion, meaning we just consider an
-   entry to be a field-name an a field-value.  So they maybe duplicate of
-   field-name like "Received" they are just put in the array, see _get_value()
-   on how to handle the case. in the case of error .i.e a bad header construct
-   we do a full stop and return what we have so far.  */
-
-static int
-header_parse (mu_header_t header, const char *blurb, int len)
-{
-  const char *header_end;
-  const char *header_start;
-  const char *header_start2;
-  
-  /* Nothing to parse.  */
-  if (blurb == NULL)
-    return 0;
-
-  header->flags |= HEADER_INVALIDATE;
-  mu_hdrent_free_list (header);
-
-  /* Get a header, a header is:
-     field-name LWSP ':'
-       LWSP field-value '\r' '\n'
-       *[ (' ' | '\t') field-value '\r' '\n' ]
-  */
-  /* First loop goes through the blurb */
-  for (header_start = blurb; len > 0; header_start = ++header_end)
-    {
-      const char *fn, *fn_end, *fv, *fv_end;
-      struct mu_hdrent *ent;
-
-      if (header_start[0] == ' '
-         || header_start[0] == '\t'
-         || header_start[0] == '\n')
-       break;
-
-      /* Second loop extract one header field. */
-      for (header_start2 = header_start; len; header_start2 = ++header_end)
-       {
-         header_end = memchr (header_start2, '\n', len);
-         if (header_end == NULL)
-           {
-             header_end = header_start2 + len;
-             len = 0;
-             break;
-           }
-         else
-           {
-             len -= (header_end - header_start2 + 1);
-             if (!len
-                 || (header_end[1] != ' '
-                     && header_end[1] != '\t'))
-               break; /* New header break the inner for. */
-           }
-         /* *header_end = ' ';  smash LF ? NO */
-       }
-
-      /* Now save the header in the data structure.  */
-
-      /* Treats unix "From " specially.  FIXME: Should we? */
-      if ((header_end - header_start >= 5)
-         && strncmp (header_start, "From ", 5) == 0)
-       {
-         fn = header_start;
-         fn_end = header_start + 5;
-         fv = header_start + 5;
-         fv_end = header_end;
-       }
-      else /* Break the header in key: value */
-       {
-         char *colon = memchr (header_start, ':', header_end - header_start);
-
-         /* Houston we have a problem.  */
-         if (colon == NULL)
-           break; /* FIXME: Disregard the rest and bailout.  */
-
-         fn = header_start;
-         fn_end = colon;
-         /* Shrink any LWSP after the field name -- CRITICAL for 
-            later name comparisons to work correctly! */
-         while (ISLWSP (fn_end[-1]))
-           fn_end--;
-
-         fv = colon + 1;
-         fv_end = header_end;
-
-         /* Skip any LWSP before the field value -- unnecessary, but
-            might make some field values look a little tidier. */
-         while (ISLWSP (fv[0]))
-           fv++;
-       }
-
-      /* Register this header */
-      ent = mu_hdrent_create (header, NULL, fn, fn_end - fn, fv, fv_end - fv);
-      if (!ent)
-       return ENOMEM;
-      mu_hdrent_append (header, ent);
-    } /* for (header_start ...) */
-
-  return 0;
-}
-
-
-static int 
-mu_header_fill (mu_header_t header)
-{
-  int status;
-  size_t blurb_len = 0;
-  char *blurb = NULL;
-  
-  if (header->spool_used)
-    return 0;
-  
-  if (header->_fill == NULL)
-    return 0; /* FIXME: Really? */
-
-  /* Bring in the entire header.  */
-  status = header->_fill (header->data, &blurb, &blurb_len);
-  if (status)
-    return status;
-  status = header_parse (header, blurb, blurb_len);
-  free (blurb);
-  return status;
-}
-
-
-
-int
-mu_header_create (mu_header_t *ph, const char *blurb, size_t len)
-{
-  mu_header_t header;
-  int status = 0;
-
-  header = calloc (1, sizeof (*header));
-  if (header == NULL)
-    return ENOMEM;
-  
-  status = header_parse (header, blurb, len);
-
-  *ph = header;
-  return status;
-}
-
-void
-mu_header_destroy (mu_header_t *ph)
-{
-  if (ph && *ph)
-    {  
-      mu_header_t header = *ph;
-
-      mu_stream_destroy (&header->stream);
-      mu_hdrent_free_list (header);
-      free (header->spool);
-      free (header);
-      *ph = NULL;
-    }
-}
-
-
-int
-mu_header_set_value (mu_header_t header, const char *fn, const char *fv,
-                    int replace)
-{
-  int status;
-  struct mu_hdrent *ent = NULL;
-  
-  if (header == NULL || fn == NULL)
-    return EINVAL;
-
-  status = mu_header_fill (header);
-  if (status)
-    return status;
-  
-  /* An fv of NULL means delete the field, but only do it if replace
-     was also set to true! */
-  if (fv == NULL && !replace)
-    return EINVAL;
-
-  if (replace)
-    {
-      ent = mu_hdrent_find (header, fn, 1);
-      if (ent)
-       {
-         if (fv == NULL)
-           {
-             /* Delete the header */
-             mu_hdrent_remove (header, ent);
-             free (ent);
-             return 0;
-           }
-         mu_hdrent_create (header, ent, fn, strlen (fn), fv, strlen (fv));
-         HEADER_SET_MODIFIED (header);
-         return 0;
-       }
-      else if (fv == NULL)
-       return 0;
-    }
-
-  ent = mu_hdrent_create (header, NULL,
-                         fn, strlen (fn), fv, strlen (fv));
-  if (!ent)
-    return ENOMEM;
-  mu_hdrent_prepend (header, ent);
-  HEADER_SET_MODIFIED (header);
-  return 0;
-}
-
-int
-mu_header_remove (mu_header_t header, const char *fn, int n)
-{
-  int status;
-  struct mu_hdrent *ent;
-  
-  if (header == NULL || fn == NULL)
-    return EINVAL;
-
-  status = mu_header_fill (header);
-  if (status)
-    return status;
-
-  ent = mu_hdrent_find (header, fn, n);
-  if (!ent)
-    return MU_ERR_NOENT;
-
-  mu_hdrent_remove (header, ent);
-  HEADER_SET_MODIFIED (header);
-  free (ent);
-  return 0;
-}
-
-int
-mu_header_append (mu_header_t header, const char *fn, const char *fv)
-{
-  int status;
-  struct mu_hdrent *ent;
-
-  if (header == NULL || fn == NULL || fv == NULL)
-    return EINVAL;
-
-  status = mu_header_fill (header);
-  if (status)
-    return status;
-
-  ent = mu_hdrent_create (header, NULL, fn, strlen (fn), fv, strlen (fv));
-  if (!ent)
-    return ENOMEM;
-  mu_hdrent_append (header, ent);
-  HEADER_SET_MODIFIED (header);
-  return 0;
-}
-
-int
-mu_header_prepend (mu_header_t header, const char *fn, const char *fv)
-{
-  int status;
-  struct mu_hdrent *ent;
-
-  if (header == NULL || fn == NULL || fv == NULL)
-    return EINVAL;
-
-  status = mu_header_fill (header);
-  if (status)
-    return status;
-
-  ent = mu_hdrent_create (header, NULL, fn, strlen (fn), fv, strlen (fv));
-  if (!ent)
-    return ENOMEM;
-  mu_hdrent_prepend (header, ent);
-  HEADER_SET_MODIFIED (header);
-  return 0;
-}
-
-int
-mu_header_insert (mu_header_t header,
-                 const char *fn, const char *fv, 
-                 const char *ref, int n, int flags)
-{
-  int status;
-  struct mu_hdrent *ent;
-
-  if (header == NULL || fn == NULL || fv == NULL)
-    return EINVAL;
-
-  status = mu_header_fill (header);
-  if (status)
-    return status;
-    
-  if (flags & MU_HEADER_REPLACE)
-    {
-      if (!ref)
-       ref = fn;
-      ent = mu_hdrent_find (header, ref, n);
-      mu_hdrent_create (header, ent, fn, strlen (fn), fv, strlen (fv));
-    }
-  else
-    {
-      ent = mu_hdrent_create (header, NULL,
-                             fn, strlen (fn), fv, strlen (fv));
-      if (!ent)
-       return ENOMEM;
-      if (ref)
-       return mu_hdrent_insert (header, ent, ref, n,
-                                flags & MU_HEADER_BEFORE);
-      else
-       mu_hdrent_prepend (header, ent);
-    }
-  HEADER_SET_MODIFIED (header);
-  return 0;
-}
-  
-
-int
-mu_header_sget_value_n (mu_header_t header,
-                       const char *name, int n,
-                       const char **pval)
-{
-  int status;
-  struct mu_hdrent *ent;
-
-  if (header == NULL || name == NULL)
-    return EINVAL;
-  status = mu_header_fill (header);
-  if (status)
-    return status;
-
-  ent = mu_hdrent_find (header, name, n);
-  if (!ent)
-    return MU_ERR_NOENT;
-
-  *pval = MU_HDRENT_VALUE (header, ent);
-  return 0;
-}
-
-int
-mu_header_aget_value_n (mu_header_t header,
-                     const char *name, int n,
-                     char **pval)
-{
-  const char *s;
-  int status = mu_header_sget_value_n (header, name, n, &s);
-  if (status == 0)
-    {
-      *pval = strdup (s);
-      if (!*pval)
-       status = ENOMEM;
-    }
-  return status;
-}
-
-int
-mu_header_get_value_n (mu_header_t header, const char *name, int n,
-                      char *buffer, size_t buflen, size_t *pn)
-{
-  const char *s;
-  int status = mu_header_sget_value_n (header, name, n, &s);
-  if (status == 0)
-    {
-      size_t slen = strlen (s);
-
-      if (buffer)
-       {
-         if (slen > buflen)
-           slen = buflen;
-         memcpy (buffer, s, slen);
-         buffer[slen] = 0;
-       }
-      if (pn)
-       *pn = slen;
-    }
-  return status;
-}
-
-
-/* Unfolding functions */
-int
-mu_header_get_value_unfold_n (mu_header_t header,
-                             const char *name, int n, char *buffer,
-                             size_t buflen, size_t *pn)
-{
-  int rc = mu_header_get_value_n (header, name, n, buffer, buflen, pn);
-
-  if (rc == 0)
-    mu_string_unfold (buffer, pn);
-  return rc;
-}
-
-int
-mu_header_aget_value_unfold_n (mu_header_t header, const char *name, int n,
-                              char **pvalue)
-{
-  int rc = mu_header_aget_value_n (header, name, n, pvalue);
-  if (rc == 0)
-    mu_string_unfold (*pvalue, NULL);
-  return rc;
-}
-
-
-int
-mu_header_get_address_n (mu_header_t header, const char *name, int n,
-                        mu_address_t *addr)
-{
-  const char *value = NULL;
-  int status = mu_header_sget_value_n (header, name, n, &value);
-
-  if (status)
-    return status;
-
-  return mu_address_create (addr, value);
-}
-
-
-int
-mu_header_get_field_count (mu_header_t header, size_t *pcount)
-{
-  size_t count;
-  size_t size;
-  size_t lines;
-  int status;
-  
-  if (header == NULL)
-    return EINVAL;
-
-  status = mu_header_fill (header);
-  if (status == 0)
-    {
-      mu_hdrent_count (header, &count, &size, &lines);
-      
-      if (pcount)
-       *pcount = count;
-    }
-  
-  return status;
-}
-
-int
-mu_header_sget_field_name (mu_header_t header, size_t num, const char **sptr)
-{
-  int status;
-  
-  if (header == NULL)
-    return EINVAL;
-
-  status = mu_header_fill (header);
-  if (status == 0)
-    {
-      struct mu_hdrent *ent = mu_hdrent_nth (header, num);
-      if (ent)
-       *sptr = MU_HDRENT_NAME (header, ent);
-      else
-       status = MU_ERR_NOENT;
-    }
-  return status;
-}
-
-int
-mu_header_get_field_name (mu_header_t header, size_t num, char *buffer,
-                         size_t buflen, size_t *pn)
-{
-  const char *s;
-  int status = mu_header_sget_field_name (header, num, &s);
-  if (status == 0)
-    {
-      size_t slen = strlen (s);
-
-      if (buffer)
-       {
-         if (slen > buflen)
-           slen = buflen;
-         memcpy (buffer, s, slen);
-         buffer[slen] = 0;
-       }
-      if (pn)
-       *pn = slen;
-    }
-  return status;
-}
-
-int
-mu_header_aget_field_name (mu_header_t header, size_t num, char **pvalue)
-{
-  const char *s;
-  int status = mu_header_sget_field_name (header, num, &s);
-  if (status == 0)
-    {
-      if ((*pvalue = strdup (s)) == NULL)
-       status = ENOMEM;
-    }
-  return status;
-}
-
-
-int
-mu_header_sget_field_value (mu_header_t header, size_t num, const char **sptr)
-{
-  int status;
-  
-  if (header == NULL)
-    return EINVAL;
-
-  status = mu_header_fill (header);
-  if (status == 0)
-    {
-      struct mu_hdrent *ent = mu_hdrent_nth (header, num);
-      if (ent)
-       *sptr = MU_HDRENT_VALUE (header, ent);
-      else
-       status = MU_ERR_NOENT;
-    }
-  return status;
-}
-
-int
-mu_header_get_field_value (mu_header_t header, size_t num, char *buffer,
-                          size_t buflen, size_t *pn)
-{
-  const char *s;
-  int status = mu_header_sget_field_value (header, num, &s);
-  if (status == 0)
-    {
-      size_t slen = strlen (s);
-
-      if (buffer)
-       {
-         if (slen > buflen)
-           slen = buflen;
-         memcpy (buffer, s, slen);
-         buffer[slen] = 0;
-       }
-      if (pn)
-       *pn = slen;
-    }
-  return status;
-}
-
-int
-mu_header_aget_field_value (mu_header_t header, size_t num, char **pvalue)
-{
-  const char *s;
-  int status = mu_header_sget_field_value (header, num, &s);
-  if (status == 0)
-    {
-      if ((*pvalue = strdup (s)) == NULL)
-       status = ENOMEM;
-    }
-  return status;
-}
-
-int
-mu_header_get_field_value_unfold (mu_header_t header, size_t num, char *buf,
-                                 size_t buflen, size_t *nwritten)
-{
-  int rc = mu_header_get_field_value (header, num, buf, buflen, nwritten);
-  if (rc == 0)
-    mu_string_unfold (buf, nwritten);
-  return rc;
-}
-
-int
-mu_header_aget_field_value_unfold (mu_header_t header, size_t num,
-                                  char **pvalue)
-{
-  int rc = mu_header_aget_field_value (header, num, pvalue);
-  if (rc == 0)
-    mu_string_unfold (*pvalue, NULL);
-  return rc;
-}
-
-
-int
-mu_header_lines (mu_header_t header, size_t *plines)
-{
-  int status;
-
-  if (header == NULL)
-    return EINVAL;
-  if (plines == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-
-  status = mu_header_fill (header);
-  if (status == 0)
-    {
-      size_t count;
-      size_t size;
-      size_t lines;
-      mu_hdrent_count (header, &count, &size, &lines);
-      *plines = lines + 1;
-    }
-  return status;
-}
-
-int
-mu_header_size (mu_header_t header, size_t *psize)
-{
-  int status;
-
-  if (header == NULL)
-    return EINVAL;
-  if (psize == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-
-  status = mu_header_fill (header);
-  if (status == 0)
-    {
-      size_t count;
-      size_t size;
-      size_t lines;
-      mu_hdrent_count (header, &count, &size, &lines);
-      *psize = size + 1;
-    }
-  return status;
-}
-
-int
-mu_header_invalidate (mu_header_t hdr)
-{
-  if (hdr == NULL)
-    return EINVAL;
-  mu_hdrent_free_list (hdr);
-  return 0;
-}
-
-
-static void
-mu_hdrent_fixup (mu_header_t hdr, struct mu_hdrent *ent)
-{
-  char *s = MU_HDRENT_NAME (hdr, ent);
-  s[ent->nlen] = ':';
-  s = MU_HDRENT_VALUE (hdr, ent);
-  s[ent->vlen] = '\n';
-}
-
-static void
-mu_hdrent_unroll_fixup (mu_header_t hdr, struct mu_hdrent *ent)
-{
-  char *s = MU_HDRENT_NAME (hdr, ent);
-  s[ent->nlen] = 0;
-  s = MU_HDRENT_VALUE (hdr, ent);
-  s[ent->vlen] = 0;
-}
-
-int
-header_seek (mu_stream_t str, mu_off_t off, mu_off_t *presult)
-{ 
-  struct _mu_header_stream *hstr = (struct _mu_header_stream *) str;
-  size_t size;
-  int status;
-    
-  status = mu_header_size (hstr->hdr, &size);
-  if (status)
-    return status;
-  
-  if (off < 0 || off > size)
-    return ESPIPE;
-  hstr->off = off;
-  *presult = off;
-  return 0;
-}
-
-static int
-header_read (mu_stream_t is, char *buffer, size_t buflen, size_t *pnread)
-{
-  struct _mu_header_stream *hstr = (struct _mu_header_stream *) is;
-  mu_header_t header;
-  struct mu_hdrent *ent;
-  size_t ent_off;
-  int status;
-  size_t nread;
-  
-  if (is == NULL)
-    return EINVAL;
-
-  header = hstr->hdr;
-  status = mu_header_fill (header);
-  if (status)
-    return status;
-  
-  if (mu_hdrent_find_stream_pos (header, hstr->off, &ent, &ent_off))
-    {
-      if (pnread)
-       *pnread = 0;
-      return 0;
-    }
-
-  for (nread = 0; nread < buflen && ent; ent = ent->next)
-    {
-      size_t rest = buflen - nread;
-      size_t strsize = MU_STR_SIZE (ent->nlen, ent->vlen) - ent_off;
-      if (rest > strsize)
-       rest = strsize;
-      mu_hdrent_fixup (header, ent);
-      memcpy (buffer + nread, MU_HDRENT_NAME (header, ent) + ent_off, rest);
-      mu_hdrent_unroll_fixup (header, ent);
-      nread += rest;
-      hstr->off += rest;
-      ent_off = 0;
-    }
-  if (pnread)
-    *pnread = nread;
-  return 0;
-}
-
-#if 0
-/* FIXME: Implement header_readdelim based on this: */
-static int
-_header_readline (mu_stream_t is, char *buffer, size_t buflen, size_t *pnread)
-{
-  struct _mu_header_stream *hstr = (struct _mu_header_stream *) is;
-  mu_header_t header = hstr->hdr;
-  struct mu_hdrent *ent;
-  size_t ent_off;
-  int status;
-  size_t strsize;
-  char *start, *end;
-
-  if (buflen == 0)
-    return EINVAL;
-
-  header = mu_stream_get_owner (is);
-  status = mu_header_fill (header);
-  if (status)
-    return status;
-  if (mu_hdrent_find_stream_pos (header, hstr->off, &ent, &ent_off))
-    {
-      if (pnread)
-       *pnread = 0;
-      return 0;
-    }
-
-  buflen--; /* Account for the terminating nul */
-
-  mu_hdrent_fixup (header, ent);
-  strsize = MU_STR_SIZE (ent->nlen, ent->vlen) - ent_off;
-  start = MU_HDRENT_NAME (header, ent) + ent_off;
-  end = strchr (start, '\n');
-  if (end)
-    {
-      size_t len = end - start + 1;
-      if (len < strsize)
-       strsize = len;
-    }
-
-  if (strsize < buflen)
-    buflen = strsize;
-
-  memcpy (buffer, start, buflen);
-  buffer[buflen] = 0;
-  hstr->off += buflen;
-  mu_hdrent_unroll_fixup (header, ent);
-  if (pnread)
-    *pnread = buflen;
-  return 0;
-}
-#endif
-
-static int
-header_write (mu_stream_t os, const char *buf, size_t buflen, size_t *pnwrite)
-{
-  struct _mu_header_stream *hstr;
-  mu_header_t header;
-  int status;
-  mu_off_t mstream_size;
-  
-  if (!os || !buf)
-    return EINVAL;
-
-  hstr = (struct _mu_header_stream *) os;
-  header = hstr->hdr;
-  if (header == NULL)
-    return EINVAL;
-  
-  /* Skip the obvious.  */
-  if (*buf == '\0' || buflen == 0)
-    {
-      if (pnwrite)
-        *pnwrite = 0;
-      return 0;
-    }
-
-  if (!header->mstream)
-    {
-      status = mu_memory_stream_create (&header->mstream, MU_STREAM_RDWR);
-      if (status)
-       return status;
-    }
-
-  status = mu_stream_write (header->mstream, buf, buflen, NULL);
-  if (status)
-    {
-      mu_stream_destroy (&header->mstream);
-      return status;
-    }
-
-  status = mu_stream_size (header->mstream, &mstream_size);
-  if (status == 0 && mstream_size > 1)
-    {
-      char nlbuf[2];
-
-      status = mu_stream_seek (header->mstream, -2, MU_SEEK_END, NULL);
-      if (status == 0)
-       status = mu_stream_read (header->mstream, nlbuf, 2, NULL);
-      if (status == 0 && memcmp (nlbuf, "\n\n", 2) == 0)
-       {
-         char *blurb;
-
-         blurb = calloc (1, mstream_size + 1);
-         if (blurb)
-           {
-             mu_stream_read (header->mstream, blurb, mstream_size, NULL);
-             status = header_parse (header, blurb, mstream_size);
-           }
-         free (blurb);
-         mu_stream_destroy (&header->mstream);
-       }
-    }
-  
-  if (pnwrite)
-    *pnwrite = buflen;
-  
-  return status;
-}
-
-static int
-header_size (mu_stream_t str, mu_off_t *psize)
-{
-  mu_header_t header;
-  int status;
-  size_t size;
-  
-  if (str == NULL)
-    return EINVAL;
-  if (psize == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  
-  header = ((struct _mu_header_stream *) str)->hdr;
-  status = mu_header_fill (header);
-  if (status)
-    return status;
-  status = mu_header_size (header, &size);
-  if (status == 0)
-    *psize = size;
-  return status;
-}
-
-static int
-_header_get_stream (mu_header_t header, mu_stream_t *pstream, int ref)
-{
-  if (header == NULL)
-    return EINVAL;
-
-  if (pstream == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-
-  if (header->stream == NULL)
-    {
-      struct _mu_header_stream *str = 
-       (struct _mu_header_stream *) _mu_stream_create (sizeof (*str),
-                                                       
MU_STREAM_RDWR|MU_STREAM_SEEK);
-      if (!str)
-       return ENOMEM;
-      str->stream.read = header_read;
-      /*str->stream.rdelim? */
-      str->stream.write = header_write;
-      str->stream.seek = header_seek;
-      str->stream.size = header_size;
-      str->hdr = header;
-      header->stream = (mu_stream_t) str;
-    }
-  if (!ref)
-    {
-      *pstream = header->stream;
-      return 0;
-    }
-  return mu_streamref_create (pstream, header->stream);
-}
-
-int
-mu_header_get_stream (mu_header_t header, mu_stream_t *pstream)
-{
-  /* FIXME: Deprecation warning */
-  return _header_get_stream (header, pstream, 0);
-}
-
-int
-mu_header_get_streamref (mu_header_t header, mu_stream_t *pstream)
-{
-  return _header_get_stream (header, pstream, 1);
-}
-
-
-int
-mu_header_set_fill (mu_header_t header, int
-                   (*_fill) (void *data, char **, size_t *),
-                   void *data)
-{
-  if (header == NULL)
-    return EINVAL;
-  header->_fill = _fill;
-  header->data = data;
-  return 0;
-}
-
-
-int
-mu_header_is_modified (mu_header_t header)
-{
-  return header ? (header->flags & HEADER_MODIFIED) : 0;
-}
-
-int
-mu_header_clear_modified (mu_header_t header)
-{
-  if (header)
-    header->flags &= ~HEADER_MODIFIED;
-  return 0;
-}
-
-
diff --git a/libmailutils/iterator.c b/libmailutils/iterator.c
deleted file mode 100644
index 3897925..0000000
--- a/libmailutils/iterator.c
+++ /dev/null
@@ -1,284 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2004, 2005, 2007, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <errno.h>
-#include <stdlib.h>
-
-#include <mailutils/sys/list.h>
-#include <mailutils/sys/iterator.h>
-#include <mailutils/errno.h>
-
-int
-mu_iterator_create (mu_iterator_t *piterator, void *owner)
-{
-  mu_iterator_t iterator;
-  if (piterator == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  if (owner == NULL)
-    return EINVAL;
-  iterator = calloc (1, sizeof (*iterator));
-  if (iterator == NULL)
-    return ENOMEM;
-  iterator->owner = owner;
-  *piterator = iterator;
-  return 0;
-}
-
-int
-mu_iterator_set_first (mu_iterator_t itr, int (*first) (void *))
-{
-  if (!itr)
-    return EINVAL;
-  itr->first = first;
-  return 0;
-}
-
-int
-mu_iterator_set_next (mu_iterator_t itr, int (*next) (void *))
-{
-  if (!itr)
-    return EINVAL;
-  itr->next = next;
-  return 0;
-}
-
-int
-mu_iterator_set_getitem (mu_iterator_t itr,
-                         int (*getitem) (void *, void **, const void **))
-{
-  if (!itr)
-    return EINVAL;
-  itr->getitem = getitem;
-  return 0;
-}
-
-int
-mu_iterator_set_finished_p (mu_iterator_t itr, int (*finished_p) (void *))
-{
-  if (!itr)
-    return EINVAL;
-  itr->finished_p = finished_p;
-  return 0;
-}
-
-int
-mu_iterator_set_curitem_p (mu_iterator_t itr,
-                       int (*curitem_p) (void *, void *))
-{
-  if (!itr)
-    return EINVAL;
-  itr->curitem_p = curitem_p;
-  return 0;
-}
-
-int
-mu_iterator_set_itrctl (mu_iterator_t itr,
-                       int (*itrctl) (void *,
-                                      enum mu_itrctl_req,
-                                      void *))
-{
-  if (!itr)
-    return EINVAL;
-  itr->itrctl = itrctl;
-  return 0;
-}
-
-int
-mu_iterator_set_destroy (mu_iterator_t itr, int (*destroy) (mu_iterator_t, 
void *))
-{
-  if (!itr)
-    return EINVAL;
-  itr->destroy = destroy;
-  return 0;
-}
-
-int
-mu_iterator_set_dup (mu_iterator_t itr, int (*dup) (void **ptr, void *data))
-{
-  if (!itr)
-    return EINVAL;
-  itr->dup = dup;
-  return 0;
-}
-
-
-
-int
-mu_iterator_dup (mu_iterator_t *piterator, mu_iterator_t orig)
-{
-  mu_iterator_t iterator;
-  int status;
-  
-  if (piterator == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  if (orig == NULL)
-    return EINVAL;
-
-  status = mu_iterator_create (&iterator, orig->owner);
-  if (status)
-    return status;
-
-  status = orig->dup(&iterator->owner, orig->owner);
-  if (status)
-    {
-      free (iterator);
-      return status;
-    }
-  iterator->is_advanced = orig->is_advanced;   
-  iterator->dup = orig->dup;
-  iterator->destroy = orig->destroy;
-  iterator->first = orig->first;
-  iterator->next = orig->next;
-  iterator->getitem = orig->getitem;
-  iterator->curitem_p = orig->curitem_p;
-  iterator->finished_p = orig->finished_p;
-  iterator->itrctl = orig->itrctl;
-  
-  *piterator = iterator;
-  return 0;
-}
-
-void
-mu_iterator_destroy (mu_iterator_t *piterator)
-{
-  if (!piterator || !*piterator)
-    return;
-
-  if ((*piterator)->destroy)
-    (*piterator)->destroy (*piterator, (*piterator)->owner);
-  
-  free (*piterator);
-  *piterator = NULL;
-}
-
-int
-mu_iterator_first (mu_iterator_t iterator)
-{
-  iterator->is_advanced = 0;
-  return iterator->first (iterator->owner);
-}
-
-int
-mu_iterator_next (mu_iterator_t iterator)
-{
-  int status = 0;
-  if (!iterator->is_advanced)
-    status = iterator->next (iterator->owner);
-  iterator->is_advanced = 0;
-  return status;
-}
-
-int
-mu_iterator_skip (mu_iterator_t iterator, ssize_t count)
-{
-  int status;
-  if (count < 0)
-    return ENOSYS; /* Need prev method */
-  while (count--)
-    if ((status = mu_iterator_next (iterator)))
-      break;
-  return status;
-}
-
-int
-mu_iterator_current (mu_iterator_t iterator, void **pitem)
-{
-  return iterator->getitem (iterator->owner, pitem, NULL);
-}
-
-int
-mu_iterator_current_kv (mu_iterator_t iterator, 
-                        const void **pkey, void **pitem)
-{
-  return iterator->getitem (iterator->owner, (void**)pitem, pkey);
-}
-
-int
-mu_iterator_is_done (mu_iterator_t iterator)
-{
-  if (iterator == NULL)
-    return 1;
-  return iterator->finished_p (iterator->owner);
-}
-
-int
-iterator_get_owner (mu_iterator_t iterator, void **powner)
-{
-  if (!iterator)
-    return EINVAL;
-  if (!powner)
-    return MU_ERR_OUT_PTR_NULL;
-  *powner = iterator->owner;
-  return 0;
-}
-
-void
-mu_iterator_advance (mu_iterator_t iterator, void *e)
-{
-  for (; iterator; iterator = iterator->next_itr)
-    {
-      if (iterator->curitem_p (iterator->owner, e))
-       {
-         iterator->next (iterator->owner);
-         iterator->is_advanced++;
-       }
-    }
-}
-
-int
-mu_iterator_attach (mu_iterator_t *root, mu_iterator_t iterator)
-{
-  iterator->next_itr = *root;
-  *root = iterator;
-  return 0;
-}
-
-int
-mu_iterator_detach (mu_iterator_t *root, mu_iterator_t iterator)
-{
-  mu_iterator_t itr, prev;
-  
-  for (itr = *root, prev = NULL; itr; prev = itr, itr = itr->next_itr)
-    if (iterator == itr)
-      break;
-
-  if (itr)
-    {
-      if (prev)
-       prev->next_itr = itr->next_itr;
-      else
-       *root = itr->next_itr;
-    }
-  
-  return 0;
-}
-
-int
-mu_iterator_ctl (mu_iterator_t iterator, enum mu_itrctl_req req, void *arg)
-{
-  if (!iterator)
-    return EINVAL;
-  if (!iterator->itrctl)
-    return ENOSYS;
-  return iterator->itrctl (iterator->owner, req, arg);
-}
diff --git a/libmailutils/list.c b/libmailutils/list.c
deleted file mode 100644
index 0045eba..0000000
--- a/libmailutils/list.c
+++ /dev/null
@@ -1,693 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2008, 2010 Free
-   Software Foundation, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library; if not, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <mailutils/sys/list.h>
-#include <mailutils/sys/iterator.h>
-#include <mailutils/errno.h>
-
-#define DESTROY_ITEM(list, elt)                        \
-  do                                           \
-    {                                          \
-       if ((list)->destroy_item)               \
-        (list)->destroy_item ((elt)->item);    \
-    }                                          \
-  while (0)
-
-int
-mu_list_create (mu_list_t *plist)
-{
-  mu_list_t list;
-  int status;
-
-  if (plist == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  list = calloc (sizeof (*list), 1);
-  if (list == NULL)
-    return ENOMEM;
-  status = mu_monitor_create (&list->monitor, 0,  list);
-  if (status != 0)
-    {
-      free (list);
-      return status;
-    }
-  list->head.next = &list->head;
-  list->head.prev = &list->head;
-  *plist = list;
-  return 0;
-}
-
-void
-mu_list_clear (mu_list_t list)
-{
-  struct list_data *current;
-  struct list_data *previous;
-  
-  mu_monitor_wrlock (list->monitor);
-  for (current = list->head.next; current != &list->head;)
-    {
-      previous = current;
-      current = current->next;
-      DESTROY_ITEM (list, previous);
-      free (previous);
-    }
-  list->head.next = list->head.prev = &list->head;
-  mu_monitor_unlock (list->monitor);
-}
-
-void
-mu_list_destroy (mu_list_t *plist)
-{
-  if (plist && *plist)
-    {
-      mu_list_t list = *plist;
-      mu_list_clear (list);
-      mu_monitor_destroy (&list->monitor, list);
-      free (list);
-      *plist = NULL;
-    }
-}
-
-int
-mu_list_append (mu_list_t list, void *item)
-{
-  struct list_data *ldata;
-  struct list_data *last;
-
-  if (list == NULL)
-    return EINVAL;
-  last = list->head.prev;
-  ldata = calloc (sizeof (*ldata), 1);
-  if (ldata == NULL)
-    return ENOMEM;
-  ldata->item = item;
-  mu_monitor_wrlock (list->monitor);
-  ldata->next = &list->head;
-  ldata->prev = list->head.prev;
-  last->next = ldata;
-  list->head.prev = ldata;
-  list->count++;
-  mu_monitor_unlock (list->monitor);
-  return 0;
-}
-
-int
-mu_list_prepend (mu_list_t list, void *item)
-{
-  struct list_data *ldata;
-  struct list_data *first;
-
-  if (list == NULL)
-    return EINVAL;
-  first = list->head.next;
-  ldata = calloc (sizeof (*ldata), 1);
-  if (ldata == NULL)
-    return ENOMEM;
-  ldata->item = item;
-  mu_monitor_wrlock (list->monitor);
-  ldata->prev = &list->head;
-  ldata->next = list->head.next;
-  first->prev = ldata;
-  list->head.next = ldata;
-  list->count++;
-  mu_monitor_unlock (list->monitor);
-  return 0;
-}
-
-int
-mu_list_is_empty (mu_list_t list)
-{
-  size_t n = 0;
-
-  mu_list_count (list, &n);
-  return (n == 0);
-}
-
-int
-mu_list_count (mu_list_t list, size_t *pcount)
-{
-  if (list == NULL)
-    return EINVAL;
-  if (pcount == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  *pcount = list->count;
-  return 0;
-}
-
-mu_list_comparator_t
-mu_list_set_comparator (mu_list_t list, mu_list_comparator_t comp)
-{
-  mu_list_comparator_t old_comp;
-
-  if (list == NULL)
-    return NULL;
-  old_comp = list->comp;
-  list->comp = comp;
-  return old_comp;
-}
-
-int
-mu_list_get_comparator (mu_list_t list, mu_list_comparator_t *comp)
-{
-  if (!list)
-    return EINVAL;
-  *comp = list->comp;
-  return 0;
-}
-
-int
-_mu_list_ptr_comparator (const void *item, const void *value)
-{
-  return item != value;
-}
-
-int
-mu_list_locate (mu_list_t list, void *item, void **ret_item)
-{
-  struct list_data *current, *previous;
-  mu_list_comparator_t comp;
-  int status = MU_ERR_NOENT;
-
-  if (list == NULL)
-    return EINVAL;
-  comp = list->comp ? list->comp : _mu_list_ptr_comparator;
-  mu_monitor_wrlock (list->monitor);
-  for (previous = &list->head, current = list->head.next;
-       current != &list->head; previous = current, current = current->next)
-    {
-      if (comp (current->item, item) == 0)
-       {
-         if (ret_item)
-           *ret_item = current->item;
-         status = 0;
-         break;
-       }
-    }
-  mu_monitor_unlock (list->monitor);
-  return status;
-}
-
-static int
-_insert_item (mu_list_t list, struct list_data *current, void *new_item,
-             int insert_before)
-{
-  int status;
-  struct list_data *ldata = calloc (sizeof (*ldata), 1);
-  if (ldata == NULL)
-    status = ENOMEM;
-  else
-    {
-      ldata->item = new_item;
-      _mu_list_insert_sublist (list, current,
-                              ldata, ldata,
-                              1,
-                              insert_before);
-      status = 0;
-    }
-  return status;
-}
-
-int
-mu_list_insert (mu_list_t list, void *item, void *new_item, int insert_before)
-{
-  struct list_data *current;
-  mu_list_comparator_t comp;
-  int status = MU_ERR_NOENT;
-
-  if (list == NULL)
-    return EINVAL;
-  comp = list->comp ? list->comp : _mu_list_ptr_comparator;
-
-  mu_monitor_wrlock (list->monitor);
-  for (current = list->head.next;
-       current != &list->head;
-       current = current->next)
-    {
-      if (comp (current->item, item) == 0)
-       {
-         status = _insert_item (list, current, new_item, insert_before);
-         break;
-       }
-    }
-  mu_monitor_unlock (list->monitor);
-  return status;
-}
-
-int
-mu_list_remove (mu_list_t list, void *item)
-{
-  struct list_data *current;
-  mu_list_comparator_t comp;
-  int status = MU_ERR_NOENT;
-
-  if (list == NULL)
-    return EINVAL;
-  comp = list->comp ? list->comp : _mu_list_ptr_comparator;
-  mu_monitor_wrlock (list->monitor);
-  for (current = list->head.next;
-       current != &list->head; current = current->next)
-    {
-      if (comp (current->item, item) == 0)
-       {
-         struct list_data *previous = current->prev;
-         
-         mu_iterator_advance (list->itr, current);
-         previous->next = current->next;
-         current->next->prev = previous;
-         DESTROY_ITEM (list, current);
-         free (current);
-         list->count--;
-         status = 0;
-         break;
-       }
-    }
-  mu_monitor_unlock (list->monitor);
-  return status;
-}
-
-int
-mu_list_remove_nd (mu_list_t list, void *item)
-{
-  mu_list_destroy_item_t dptr = mu_list_set_destroy_item (list, NULL);
-  int rc = mu_list_remove (list, item);
-  mu_list_set_destroy_item (list, dptr);
-  return rc;
-}
-
-int
-mu_list_replace (mu_list_t list, void *old_item, void *new_item)
-{
-  struct list_data *current, *previous;
-  mu_list_comparator_t comp;
-  int status = MU_ERR_NOENT;
-
-  if (list == NULL)
-    return EINVAL;
-  comp = list->comp ? list->comp : _mu_list_ptr_comparator;
-  mu_monitor_wrlock (list->monitor);
-  for (previous = &list->head, current = list->head.next;
-       current != &list->head; previous = current, current = current->next)
-    {
-      if (comp (current->item, old_item) == 0)
-       {
-         DESTROY_ITEM (list, current);
-         current->item = new_item;
-         status = 0;
-         break;
-       }
-    }
-  mu_monitor_unlock (list->monitor);
-  return status;
-}
-
-int
-mu_list_replace_nd (mu_list_t list, void *item, void *new_item)
-{
-  mu_list_destroy_item_t dptr = mu_list_set_destroy_item (list, NULL);
-  int rc = mu_list_replace (list, item, new_item);
-  mu_list_set_destroy_item (list, dptr);
-  return rc;
-}
-
-int
-mu_list_get (mu_list_t list, size_t indx, void **pitem)
-{
-  struct list_data *current;
-  size_t count;
-  int status = MU_ERR_NOENT;
-
-  if (list == NULL)
-    return EINVAL;
-  if (pitem == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  mu_monitor_rdlock (list->monitor);
-  for (current = list->head.next, count = 0; current != &list->head;
-       current = current->next, count++)
-    {
-      if (count == indx)
-        {
-          *pitem = current->item;
-         status = 0;
-         break;
-        }
-    }
-  mu_monitor_unlock (list->monitor);
-  return status;
-}
-
-int
-mu_list_do (mu_list_t list, mu_list_action_t *action, void *cbdata)
-{
-  mu_iterator_t itr;
-  int status = 0;
-
-  if (list == NULL || action == NULL)
-    return EINVAL;
-  status = mu_list_get_iterator (list, &itr);
-  if (status)
-    return status;
-  for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
-       mu_iterator_next (itr))
-    {
-      void *item;
-      mu_iterator_current (itr, &item);
-      if ((status = action (item, cbdata)))
-       break;
-    }
-  mu_iterator_destroy (&itr);
-  return status;
-}
-
-mu_list_destroy_item_t
-mu_list_set_destroy_item (mu_list_t list, void (*destroy_item)(void *item))
-{
-  mu_list_destroy_item_t ret = list->destroy_item;
-  list->destroy_item = destroy_item;
-  return ret;
-}
-
-int
-mu_list_to_array (mu_list_t list, void **array, size_t count, size_t *pcount)
-{
-  size_t total = 0;
-
-  if (!list)
-    return EINVAL;
-
-  total = (count < list->count) ? count : list->count;
-
-  if (array)
-    {
-      size_t i;
-      struct list_data *current;
-
-      for (i = 0, current = list->head.next;
-          i < total && current != &list->head; current = current->next)
-       array[i++] = current->item;
-    }
-  if (pcount)
-    *pcount = total;
-  return 0;
-}
-
-/* Computes an intersection of two lists and returns it in PDEST.
-   The resulting list contains elements from A that are
-   also encountered in B (as per comparison function of
-   the latter).
-
-   If DUP_ITEM is not NULL, it is used to create copies of
-   items to be stored in PDEST.  In this case, the destroy_item
-   function of B is also attached to PDEST.  Otherwise, if
-   DUP_ITEM is NULL, pointers to elements are stored and
-   no destroy_item function is assigned. */
-int
-mu_list_intersect_dup (mu_list_t *pdest, mu_list_t a, mu_list_t b,
-                      int (*dup_item) (void **, void *, void *),
-                      void *dup_closure)
-{
-  mu_list_t dest;
-  int rc;
-  mu_iterator_t itr;
-  
-  rc = mu_list_create (&dest);
-  if (rc)
-    return rc;
-
-  mu_list_set_comparator (dest, b->comp);
-  if (dup_item)
-    mu_list_set_destroy_item (dest, b->destroy_item);
-  
-  rc = mu_list_get_iterator (a, &itr);
-  if (rc)
-    {
-      mu_list_destroy (&dest);
-      return rc;
-    }
-
-  rc = 0;
-  for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
-       mu_iterator_next (itr))
-    {
-      void *data;
-      mu_iterator_current (itr, &data);
-      if (mu_list_locate (b, data, NULL) == 0)
-       {
-         void *new_data;
-         if (dup_item && data)
-           {
-             rc = dup_item (&new_data, data, dup_closure);
-             if (rc)
-               break;
-           }
-         else
-           new_data = data;
-       
-         mu_list_append (dest, new_data); /* FIXME: Check return, and? */
-       }
-    }
-  mu_iterator_destroy (&itr);
-  *pdest = dest;
-  return rc;
-}
-
-int
-mu_list_intersect (mu_list_t *pdest, mu_list_t a, mu_list_t b)
-{
-  return mu_list_intersect_dup (pdest, a, b, NULL, NULL);
-}
-
-
-/* Iterator interface */
-
-struct list_iterator
-{
-  mu_list_t list;
-  struct list_data *cur;
-  int backwards; /* true if iterating backwards */
-};
-
-static int
-first (void *owner)
-{
-  struct list_iterator *itr = owner;
-  if (itr->backwards)
-    itr->cur = itr->list->head.prev;
-  else
-    itr->cur = itr->list->head.next;
-  return 0;
-}
-
-static int
-next (void *owner)
-{
-  struct list_iterator *itr = owner;
-  if (itr->backwards)
-    itr->cur = itr->cur->prev;
-  else
-    itr->cur = itr->cur->next;
-  return 0;
-}
-
-static int
-getitem (void *owner, void **pret, const void **pkey)
-{
-  struct list_iterator *itr = owner;
-  *pret = itr->cur->item;
-  if (pkey)
-    *pkey = NULL;
-  return 0;
-}
-
-static int
-finished_p (void *owner)
-{
-  struct list_iterator *itr = owner;
-  return itr->cur == &itr->list->head;
-}
-
-static int
-destroy (mu_iterator_t iterator, void *data)
-{
-  struct list_iterator *itr = data;
-  mu_iterator_detach (&itr->list->itr, iterator);
-  free (data);
-  return 0;
-}
-
-static int
-curitem_p (void *owner, void *item)
-{
-  struct list_iterator *itr = owner;
-  return itr->cur == item;
-}
-
-static int
-list_data_dup (void **ptr, void *owner)
-{
-  *ptr = malloc (sizeof (struct list_iterator));
-  if (*ptr == NULL)
-    return ENOMEM;
-  memcpy (*ptr, owner, sizeof (struct list_iterator));
-  return 0;
-}
-
-static int
-list_itrctl (void *owner, enum mu_itrctl_req req, void *arg)
-{
-  struct list_iterator *itr = owner;
-  mu_list_t list = itr->list;
-  struct list_data *ptr;
-  
-  if (itr->cur == NULL)
-    return MU_ERR_NOENT;
-  switch (req)
-    {
-    case mu_itrctl_tell:
-      /* Return current position in the object */
-      {
-       size_t count;
-
-       for (count = 0, ptr = list->head.next; ptr != &list->head;
-            ptr = ptr->next, count++)
-         {
-           if (ptr == itr->cur)
-             {
-               *(size_t*)arg = count;
-               return 0;
-             }
-         }
-       return MU_ERR_NOENT;
-      }
-       
-    case mu_itrctl_delete:
-    case mu_itrctl_delete_nd:
-      /* Delete current element */
-      {
-       struct list_data *prev;
-       
-       ptr = itr->cur;
-       prev = ptr->prev;
-       
-       mu_iterator_advance (list->itr, ptr);
-       prev->next = ptr->next;
-       ptr->next->prev = prev;
-       if (req == mu_itrctl_delete)
-         DESTROY_ITEM (list, ptr);
-       free (ptr);
-       list->count--;
-      }
-      break;
-      
-    case mu_itrctl_replace:
-    case mu_itrctl_replace_nd:
-      /* Replace current element */
-      if (!arg)
-       return EINVAL;
-      ptr = itr->cur;
-      if (req == mu_itrctl_replace)
-         DESTROY_ITEM (list, ptr);
-      ptr = itr->cur;
-      ptr->item = arg;
-      break;
-      
-    case mu_itrctl_insert:
-      /* Insert new element in the current position */
-      if (!arg)
-       return EINVAL;
-      return _insert_item (list, itr->cur, arg, 0);
-
-    case mu_itrctl_insert_list:
-      /* Insert a list of elements */
-      if (!arg)
-       return EINVAL;
-      else
-       {
-         mu_list_t new_list = arg;
-         _mu_list_insert_sublist (list, itr->cur,
-                                  new_list->head.next, new_list->head.prev,
-                                  new_list->count,
-                                  0);
-         _mu_list_clear (new_list);
-       }
-      break;
-
-    case mu_itrctl_qry_direction:
-      if (!arg)
-       return EINVAL;
-      else
-       *(int*)arg = itr->backwards;
-      break;
-
-    case mu_itrctl_set_direction:
-      if (!arg)
-       return EINVAL;
-      else
-       itr->backwards = !!*(int*)arg;
-      break;
-      
-    default:
-      return ENOSYS;
-    }
-  return 0;
-}
-
-int
-mu_list_get_iterator (mu_list_t list, mu_iterator_t *piterator)
-{
-  mu_iterator_t iterator;
-  int status;
-  struct list_iterator *itr;
-
-  if (!list)
-    return EINVAL;
-
-  itr = calloc (1, sizeof *itr);
-  if (!itr)
-    return ENOMEM;
-  itr->list = list;
-  itr->cur = NULL;
-
-  status = mu_iterator_create (&iterator, itr);
-  if (status)
-    {
-      free (itr);
-      return status;
-    }
-
-  mu_iterator_set_first (iterator, first);
-  mu_iterator_set_next (iterator, next);
-  mu_iterator_set_getitem (iterator, getitem);
-  mu_iterator_set_finished_p (iterator, finished_p);
-  mu_iterator_set_curitem_p (iterator, curitem_p);
-  mu_iterator_set_destroy (iterator, destroy);
-  mu_iterator_set_dup (iterator, list_data_dup);
-  mu_iterator_set_itrctl (iterator, list_itrctl);
-  
-  mu_iterator_attach (&list->itr, iterator);
-
-  *piterator = iterator;
-  return 0;
-}
diff --git a/libmailutils/listlist.c b/libmailutils/listlist.c
deleted file mode 100644
index 94172ac..0000000
--- a/libmailutils/listlist.c
+++ /dev/null
@@ -1,139 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2008, 2010 Free
-   Software Foundation, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library; if not, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <mailutils/sys/list.h>
-#include <mailutils/sys/iterator.h>
-#include <mailutils/errno.h>
-
-void
-_mu_list_insert_sublist (mu_list_t list,
-                        struct list_data *current,
-                        struct list_data *head,
-                        struct list_data *tail,
-                        size_t count,
-                        int insert_before)
-{
-  if (insert_before)
-    {
-      head->prev = current->prev;
-      tail->next = current;
-      if (current->prev != &list->head)
-       current->prev->next = head;
-      else
-       list->head.next = head;
-
-      current->prev = tail;
-    }
-  else
-    {
-      tail->next = current->next;
-      head->prev = current;
-      if (current->next != &list->head)
-       current->next->prev = tail;
-      else
-       list->head.prev = tail;
-
-      current->next = head;
-    }
-  list->count += count;
-}
-
-void
-_mu_list_clear (mu_list_t list)
-{
-  list->head.next = list->head.prev = &list->head;
-  list->count = 0;
-}
-
-int
-mu_list_insert_list (mu_list_t list, void *item, mu_list_t new_list,
-                    int insert_before)
-{
-  struct list_data *current;
-  mu_list_comparator_t comp;
-  int status = MU_ERR_NOENT;
-
-  if (list == NULL)
-    return EINVAL;
-  comp = list->comp ? list->comp : _mu_list_ptr_comparator;
-
-  mu_monitor_wrlock (list->monitor);
-  for (current = list->head.next;
-       current != &list->head;
-       current = current->next)
-    {
-      if (comp (current->item, item) == 0)
-       {
-         _mu_list_insert_sublist (list, current,
-                                  new_list->head.next, new_list->head.prev,
-                                  new_list->count,
-                                  insert_before);
-         _mu_list_clear (new_list);
-         status = 0;
-         break;
-       }
-    }
-  mu_monitor_unlock (list->monitor);
-  return status;
-}
-
-void
-mu_list_append_list (mu_list_t list, mu_list_t new_list)
-{
-  if (list->count == 0)
-    {
-      list->head = new_list->head;
-      list->head.next->prev = list->head.prev->next = &list->head;
-      list->count = new_list->count;
-    }
-  else
-    _mu_list_insert_sublist (list, list->head.prev,
-                            new_list->head.next, new_list->head.prev,
-                            new_list->count,
-                            0);
-  _mu_list_clear (new_list);
-}
-
-void
-mu_list_prepend_list (mu_list_t list, mu_list_t new_list)
-{
-  if (list->count == 0)
-    {
-      list->head = new_list->head;
-      list->head.next->prev = list->head.prev->next = &list->head;
-      list->count = new_list->count;
-    }
-  else
-    _mu_list_insert_sublist (list, list->head.next,
-                            new_list->head.next, new_list->head.prev,
-                            new_list->count,
-                            1);
-  _mu_list_clear (new_list);
-}
-
-
-
diff --git a/libmailutils/locale.c b/libmailutils/locale.c
deleted file mode 100644
index b6bdc08..0000000
--- a/libmailutils/locale.c
+++ /dev/null
@@ -1,242 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2003, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include <mailutils/mutil.h>
-#include <mailutils/cstr.h>
-
-struct langtab
-{
-  char *lang;        /* Language code */
-  char *terr;        /* Territory code */
-  char *charset;     /* Corresponding charset */
-};
-
-/* The list of language codes defined in ISO 639 with the corresponding
-   default character sets.
-
-   NOTES:
-
-   1) The list must be ordered by:
-        a) lang field in ascending order
-       b) terr field in descending order.
-      NULL fields are considered less than non-null ones.
-   2) Many entries have NULL charset fields. Please help fill them!
-   3) The "default" character set for a given language is a matter
-      of preference. Possibly the table should contain a *list* of
-      possible character sets.
-   4) LC_ALL "modifier" field is not taken into account */
-
-static struct langtab langtab[] = {
-  { "C",     NULL, "ASCII"},
-  { "POSIX", NULL, "ASCII" },
-  { "aa",    NULL, NULL},              /* Afar */
-  { "ab",    NULL, NULL},              /* Abkhazian */
-  { "ae",    NULL, NULL},              /* Avestan */
-  { "af",    NULL, "iso-8859-1"},      /* Afrikaans */
-  { "am",    NULL, "UTF-8"},           /* Amharic */
-  { "ar",    NULL, "iso-8859-6"},      /* Arabic */
-  { "as",    NULL, NULL},              /* Assamese */
-  { "ay",    NULL, "iso-8859-1"},      /* Aymara */
-  { "az",    NULL, NULL},              /* Azerbaijani */
-  { "ba",    NULL, NULL},              /* Bashkir */
-  { "be",    NULL, "UTF-8"},           /* Byelorussian; Belarusian */
-  { "bg",    NULL, "iso-8859-5"},      /* Bulgarian */
-  { "bh",    NULL, NULL},              /* Bihari */
-  { "bi",    NULL, NULL},              /* Bislama */
-  { "bn",    NULL, NULL},              /* Bengali; Bangla */
-  { "bo",    NULL, NULL},              /* Tibetan */
-  { "br",    NULL, "iso-8859-1"},      /* Breton: 1,5,8,9 */
-  { "bs",    NULL, NULL},              /* Bosnian */
-  { "ca",    NULL, "iso-8859-1"},      /* Catalan: 1,5,8,9 */
-  { "ce",    NULL, NULL},              /* Chechen */
-  { "ch",    NULL, NULL},              /* Chamorro */
-  { "co",    NULL, "iso-8859-1"},      /* Corsican */
-  { "cs",    NULL, "iso-8859-2"},      /* Czech */
-  { "cu",    NULL, NULL },             /* Church Slavic */
-  { "cv",    NULL, NULL},              /* Chuvash */
-  { "cy",    NULL, "iso-8859-1"},      /* Welsh */
-  { "da",    NULL, "iso-8859-1"},      /* Danish: 4-9 */
-  { "de",    NULL, "iso-8859-1"},      /* German */
-  { "dz",    NULL, NULL },             /* Dzongkha; Bhutani */
-  { "el",    NULL, "iso-8859-7"},      /* Greek */
-  { "en",    NULL, "iso-8859-1"},      /* English */
-  { "eo",    NULL, "iso-8859-3"},      /* Esperanto */
-  { "es",    NULL, "iso-8859-1"},      /* Spanish */
-  { "et",    NULL, "iso-8859-15"},     /* Estonian: 6,7,9 */
-  { "eu",    NULL, "iso-8859-1"},      /* Basque: 5,8,9 */
-  { "fa",    NULL, "UTF-8"},           /* Persian */
-  { "fi",    NULL, "iso-8859-15"},     /* Finnish */
-  { "fj",    NULL, NULL },             /* Fijian; Fiji */
-  { "fo",    NULL, "iso-8859-1"},      /* Faroese: 6,9 */
-  { "fr",    NULL, "iso-8859-1"},      /* French */
-  { "fy",    NULL, "iso-8859-1"},      /* Frisian */
-  { "ga",    NULL, "iso-8859-14"},     /* Irish */
-  { "gd",    NULL, "iso-8859-14" },    /* Scots; Gaelic */
-  { "gl",    NULL, NULL },             /* Gallegan; Galician */
-  { "gn",    NULL, NULL},              /* Guarani */
-  { "gu",    NULL, NULL},              /* Gujarati */
-  { "gv",    NULL, "iso-8859-14"},     /* Manx */
-  { "ha",    NULL, NULL },             /* Hausa (?) */
-  { "he",    NULL, "iso-8859-8" },     /* Hebrew */
-  { "hi",    NULL, NULL},              /* Hindi */
-  { "ho",    NULL, NULL},              /* Hiri Motu */
-  { "hr",    NULL, "iso-8859-2"},      /* Croatian: 10 */
-  { "hu",    NULL, "iso-8859-2"},      /* Hungarian */
-  { "hy",    NULL, NULL},              /* Armenian */
-  { "hz",    NULL, NULL},              /* Herero */
-  { "id",    NULL, "iso-8859-1"},      /* Indonesian (formerly in) */
-  { "ia",    NULL, NULL},              /* Interlingua */
-  { "ie",    NULL, NULL},              /* Interlingue */
-  { "ik",    NULL, NULL},              /* Inupiak */
-  { "io",    NULL, NULL},              /* Ido */
-  { "is",    NULL, "iso-8859-1"},      /* Icelandic */
-  { "it",    NULL, "iso-8859-1"},      /* Italian */
-  { "iu",    NULL, NULL},              /* Inuktitut */
-  { "ja",    NULL, "EUC-JP"},          /* Japanese */
-  { "jv",    NULL, NULL},              /* Javanese */
-  { "ka",    NULL, NULL},              /* Georgian */
-  { "ki",    NULL, NULL},              /* Kikuyu */
-  { "kj",    NULL, NULL},              /* Kuanyama */
-  { "kk",    NULL, NULL},              /* Kazakh */
-  { "kl",    NULL, "iso-8859-1"},      /* Kalaallisut; Greenlandic */
-  { "km",    NULL, NULL},              /* Khmer; Cambodian */
-  { "kn",    NULL, NULL},              /* Kannada */
-  { "ko",    NULL, "EUC-KR"},          /* Korean */
-  { "ks",    NULL, NULL},              /* Kashmiri */
-  { "ku",    NULL, NULL},              /* Kurdish */
-  { "kv",    NULL, NULL},              /* Komi */
-  { "kw",    NULL, "iso-8859-14"},     /* Cornish: 1,5,8 */
-  { "ky",    NULL, NULL},              /* Kirghiz */
-  { "la",    NULL, "iso-8859-1"},      /* Latin */
-  { "lb",    NULL, "iso-8859-1"},      /* Letzeburgesch */
-  { "ln",    NULL, NULL},              /* Lingala */
-  { "lo",    NULL, NULL},              /* Lao; Laotian */
-  { "lt",    NULL, "iso-8859-4"},      /* Lithuanian */
-  { "lv",    NULL, "iso-8859-4"},      /* Latvian; Lettish */
-  { "mg",    NULL, NULL},              /* Malagasy */
-  { "mh",    NULL, NULL},              /* Marshall */
-  { "mi",    NULL, NULL},              /* Maori */
-  { "mk",    NULL, NULL},              /* Macedonian */
-  { "ml",    NULL, NULL},              /* Malayalam */
-  { "mn",    NULL, NULL},              /* Mongolian */
-  { "mo",    NULL, "iso-8859-2"},      /* Moldavian */
-  { "mr",    NULL, NULL},              /* Marathi */
-  { "ms",    NULL, NULL},              /* Malay */
-  { "mt",    NULL, "iso-8859-3"},      /* Maltese */
-  { "my",    NULL, NULL},              /* Burmese */
-  { "na",    NULL, NULL},              /* Nauru */
-  { "nb",    NULL, "iso-8859-1"},      /* Norwegian Bokmål; address@hidden  */
-  { "nd",    NULL, NULL},              /* Ndebele, North */
-  { "ne",    NULL, NULL},              /* Nepali */
-  { "ng",    NULL, NULL},              /* Ndonga */
-  { "nl",    NULL, "iso-8859-1"},      /* Dutch: 5,9 */
-  { "nn",    NULL, "iso-8859-1"},      /* Norwegian Nynorsk */
-  { "no",    NULL, "iso-8859-1"},      /* Norwegian */
-  { "nr",    NULL, NULL},              /* Ndebele, South */
-  { "nv",    NULL, NULL},              /* Navajo */
-  { "ny",    NULL, NULL},              /* Chichewa; Nyanja */
-  { "oc",    NULL, NULL},              /* Occitan; Provençal; Proven@,{c}al */
-  { "om",    NULL, NULL},              /* (Afan) Oromo */
-  { "or",    NULL, NULL},              /* Oriya */
-  { "os",    NULL, NULL},              /* Ossetian; Ossetic */
-  { "pa",    NULL, NULL},              /* Panjabi; Punjabi */
-  { "pi",    NULL, NULL},              /* Pali */
-  { "pl",    NULL, "iso-8859-2"},      /* Polish */
-  { "ps",    NULL, NULL},              /* Pashto, Pushto */
-  { "pt",    NULL, "iso-8859-1"},      /* Portuguese */
-  { "qu",    NULL, "iso-8859-1"},      /* Quechua */
-  { "rm",    NULL, "iso-8859-1"},      /* Rhaeto-Romance */
-  { "rn",    NULL, NULL },             /* Rundi; Kirundi */
-  { "ro",    NULL, "iso-8859-2"},      /* Romanian */
-  { "ru",    NULL, "koi8-r"},          /* Russian */
-  { "rw",    NULL, NULL},              /* Kinyarwanda */
-  { "sa",    NULL, NULL},              /* Sanskrit */
-  { "sc",    NULL, "iso-8859-1"},      /* Sardinian */
-  { "sd",    NULL, NULL},              /* Sindhi */
-  { "se",    NULL, "iso-8859-10"},     /* Northern Sami */
-  { "sg",    NULL, NULL},              /* Sango; Sangro */
-  { "si",    NULL, NULL},              /* Sinhalese */
-  { "sk",    NULL, "iso-8859-2"},      /* Slovak */
-  { "sl",    NULL, "iso-8859-1"},      /* Slovenian */
-  { "sm",    NULL, NULL},              /* Samoan */
-  { "sn",    NULL, NULL},              /* Shona */
-  { "so",    NULL, NULL},              /* Somali */
-  { "sq",    NULL, "iso-8859-1"},      /* Albanian: 2,5,8,9,10 */
-  { "sr",    NULL, "iso-8859-2"},      /* Serbian */
-  { "ss",    NULL, NULL},              /* Swati; Siswati */
-  { "st",    NULL, NULL},              /* Sesotho; Sotho, Southern */
-  { "su",    NULL, NULL},              /* Sundanese */
-  { "sv",    NULL, "iso-8859-1"},      /* Swedish */
-  { "sw",    NULL, NULL},              /* Swahili */
-  { "ta",    NULL, NULL},              /* Tamil */
-  { "te",    NULL, NULL},              /* Telugu */
-  { "tg",    NULL, NULL},              /* Tajik */
-  { "th",    NULL, "iso-8859-11"},     /* Thai */
-  { "ti",    NULL, NULL},              /* Tigrinya */
-  { "tk",    NULL, NULL},              /* Turkmen */
-  { "tl",    NULL, "iso-8859-1"},      /* Tagalog */
-  { "tn",    NULL, NULL},              /* Tswana; Setswana */
-  { "to",    NULL, NULL},              /* Tonga (?) */
-  { "tr",    NULL, "iso-8859-9"},      /* Turkish */
-  { "ts",    NULL, NULL},              /* Tsonga */
-  { "tt",    NULL, NULL},              /* Tatar */
-  { "tw",    NULL, NULL},              /* Twi */
-  { "ty",    NULL, NULL},              /* Tahitian */
-  { "ug",    NULL, NULL},              /* Uighur */
-  { "uk",    NULL, "koi8-u"},          /* Ukrainian */
-  { "ur",    NULL, NULL},              /* Urdu */
-  { "uz",    NULL, NULL},              /* Uzbek */
-  { "vi",    NULL, NULL},              /* Vietnamese */
-  { "vo",    NULL, NULL},              /* Volapük; Volap@"{u}k; Volapuk */
-  { "wa",    NULL, "iso-8859-1"},      /* Walloon */
-  { "wo",    NULL, NULL},              /* Wolof */
-  { "xh",    NULL, NULL},              /* Xhosa */
-  { "yi",    NULL, "iso-8859-8"},      /* Yiddish (formerly ji) */
-  { "yo",    NULL, NULL},              /* Yoruba */
-  { "za",    NULL, NULL},              /* Zhuang */
-  { "zh",    "TW", "big5"},            /* Chinese */
-  { "zh",    NULL, "gb2312"},          /* Chinese */
-  { "zu",    NULL, NULL},              /* Zulu */
-  { NULL }
-};
-
-/* Given the language and (optionally) territory code, return the
-   default character set for that language. See notes above. */
-
-const char *
-mu_charset_lookup (char *lang, char *terr)
-{
-  static struct langtab *p;
-
-  if (!lang)
-    return NULL;
-  for (p = langtab; p->lang; p++)
-    if (mu_c_strcasecmp (p->lang, lang) == 0
-       && (terr == NULL 
-           || p->terr == NULL
-           || !mu_c_strcasecmp (p->terr, terr) == 0))
-      return p->charset;
-  return NULL;
-}
-
diff --git a/libmailutils/locker.c b/libmailutils/locker.c
deleted file mode 100644
index 4f0dcf2..0000000
--- a/libmailutils/locker.c
+++ /dev/null
@@ -1,1027 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2005, 2006, 2007, 2008, 2010 Free
-   Software Foundation, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library; if not, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <assert.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <utime.h>
-
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-
-#include <mailutils/errno.h>
-#include <mailutils/locker.h>
-#include <mailutils/mutil.h>
-
-#define LOCKFILE_ATTR           0644
-
-/* First draft by Brian Edmond. */
-/* For subsequent modifications, see the GNU mailutils ChangeLog. */
-
-struct _mu_locker
-{
-  unsigned refcnt;             /* Number of times mu_locker_lock was called */
-  enum mu_locker_mode mode;    /* Current locking mode (if refcnt > 0) */
-
-  char *file;
-  int flags;
-  int expire_time;
-  int retries;
-  int retry_sleep;
-
-  union lock_data {
-    struct {
-      char *dotlock;
-      char *nfslock;
-    } dot;
-    
-    struct {
-      char *name;
-    } external;
-    
-    struct {
-      int fd;
-    } kernel;
-  } data;
-};
-
-#define MU_LOCKER_TYPE(l) MU_LOCKER_FLAG_TO_TYPE((l)->flags)
-
-struct locker_tab
-{
-  int (*init) (mu_locker_t);
-  void (*destroy) (mu_locker_t);
-  int (*prelock) (mu_locker_t); 
-  int (*lock) (mu_locker_t, enum mu_locker_mode);
-  int (*unlock) (mu_locker_t);
-};
-
-static int init_dotlock (mu_locker_t);
-static void destroy_dotlock (mu_locker_t);
-static int lock_dotlock (mu_locker_t, enum mu_locker_mode);
-static int unlock_dotlock (mu_locker_t);
-
-static int init_external (mu_locker_t);
-static void destroy_external (mu_locker_t);
-static int lock_external (mu_locker_t, enum mu_locker_mode);
-static int unlock_external (mu_locker_t);
-
-static int init_kernel (mu_locker_t);
-static int lock_kernel (mu_locker_t, enum mu_locker_mode);
-static int unlock_kernel (mu_locker_t);
-
-static int prelock_common (mu_locker_t);
-
-static struct locker_tab locker_tab[] = {
-  /* MU_LOCKER_TYPE_DOTLOCK */
-  { init_dotlock, destroy_dotlock, prelock_common,
-    lock_dotlock, unlock_dotlock },
-  /* MU_LOCKER_TYPE_EXTERNAL */
-  { init_external, destroy_external, prelock_common,
-    lock_external, unlock_external },
-  /* MU_LOCKER_TYPE_KERNEL */
-  { init_kernel, NULL, NULL, lock_kernel, unlock_kernel },
-  /* MU_LOCKER_TYPE_NULL */
-  { NULL, NULL, NULL, NULL, NULL }
-};
-
-#define MU_LOCKER_NTYPES (sizeof (locker_tab) / sizeof (locker_tab[0]))
-
-
-static int
-stat_check (const char *file, int fd, int links)
-{
-  struct stat fn_stat;
-  struct stat fd_stat;
-  int err = 0;
-  int localfd = -1;
-
-  if (fd == -1)
-    {
-      localfd = open (file, O_RDONLY);
-      
-      if (localfd == -1)
-       return errno;
-      fd = localfd;
-    }
-
-  /* We should always be able to stat a valid fd, so this
-     is an error condition. */
-  if (lstat (file, &fn_stat) || fstat (fd, &fd_stat))
-    err = errno;
-  else
-    {
-      /* If the link and stat don't report the same info, or the
-         file is a symlink, fail the locking. */
-#define CHK(X) if(X) err = EINVAL
-
-      CHK (!S_ISREG (fn_stat.st_mode));
-      CHK (!S_ISREG (fd_stat.st_mode));
-      CHK (fn_stat.st_nlink != links);
-      CHK (fn_stat.st_dev != fd_stat.st_dev);
-      CHK (fn_stat.st_ino != fd_stat.st_ino);
-      CHK (fn_stat.st_mode != fd_stat.st_mode);
-      CHK (fn_stat.st_nlink != fd_stat.st_nlink);
-      CHK (fn_stat.st_uid != fd_stat.st_uid);
-      CHK (fn_stat.st_gid != fd_stat.st_gid);
-      CHK (fn_stat.st_rdev != fd_stat.st_rdev);
-
-#undef CHK
-    }
-  if (localfd != -1)
-    close (localfd);
-
-  return err;
-}
-
-static int
-check_file_permissions (const char *file)
-{
-  int fd = -1;
-  int err = 0;
-
-  if ((fd = open (file, O_RDONLY)) == -1)
-    return errno == ENOENT ? 0 : errno;
-
-  err = stat_check (file, fd, 1);
-  close (fd);
-  fd = -1;
-  if (err)
-    {
-      if (err == EINVAL)
-       err = MU_ERR_LOCK_BAD_FILE;
-      return err;
-    }
-
-  return 0;
-}
-
-static int
-prelock_common (mu_locker_t locker)
-{
-  /* Check if we are trying to lock a regular file, with a link count
-     of 1, that we have permission to read, etc., or don't lock it. */
-  return check_file_permissions (locker->file);
-}
-
-
-static int mu_locker_default_flags = MU_LOCKER_DEFAULT;
-static time_t mu_locker_retry_timeout = MU_LOCKER_RETRY_SLEEP;
-static size_t mu_locker_retry_count = MU_LOCKER_RETRIES;
-static time_t mu_locker_expire_timeout = MU_LOCKER_EXPIRE_TIME;
-static char *mu_locker_external_program = NULL;
-
-int
-mu_locker_set_default_flags (int flags, enum mu_locker_set_mode mode)
-{
-  switch (mode)
-    {
-    case mu_locker_assign:
-      mu_locker_default_flags = flags;
-      break;
-
-    case mu_locker_set_bit:
-      mu_locker_default_flags |= flags;
-      break;
-
-    case mu_locker_clear_bit:
-      mu_locker_default_flags &= ~flags;
-      break;
-
-    default:
-      return EINVAL;
-    }
-  return 0;
-}
-
-void
-mu_locker_set_default_retry_timeout (time_t to)
-{
-  mu_locker_retry_timeout = to;
-}
-
-void
-mu_locker_set_default_retry_count (size_t n)
-{
-  mu_locker_retry_count = n;
-}
-
-void
-mu_locker_set_default_expire_timeout (time_t t)
-{
-  mu_locker_expire_timeout = t;
-}
-
-void
-mu_locker_set_default_external_program (char *path)
-{
-  free (mu_locker_external_program);
-  mu_locker_external_program = strdup (path);
-}
-
-int
-mu_locker_mod_flags (mu_locker_t locker, int flags,
-                    enum mu_locker_set_mode mode)
-{
-  unsigned otype, ntype;
-  int new_flags;
-  
-  if (!locker)
-    return MU_ERR_LOCKER_NULL;
-
-  switch (mode)
-    {
-    case mu_locker_assign:
-      new_flags = flags;
-      break;
-
-    case mu_locker_set_bit:
-      new_flags = locker->flags | flags;
-      break;
-
-    case mu_locker_clear_bit:
-      new_flags = locker->flags & ~flags;
-      break;
-
-    default:
-      return EINVAL;
-    }
-
-  otype = MU_LOCKER_TYPE (locker);
-  if (otype >= MU_LOCKER_NTYPES)
-    return EINVAL;
-  ntype = MU_LOCKER_FLAG_TO_TYPE (new_flags);
-  if (ntype >= MU_LOCKER_NTYPES)
-    return EINVAL;
-
-  if (ntype != otype)
-    {
-      int rc;
-      
-      if (locker_tab[otype].destroy)
-       locker_tab[otype].destroy (locker);
-      locker->flags = new_flags;
-      if (locker_tab[ntype].init)
-       {
-         rc = locker_tab[ntype].init (locker);
-         if (rc)
-           locker->flags = MU_LOCKER_NULL;
-         return rc;
-       }
-    }
-  else
-    locker->flags = new_flags;
-
-  return 0;
-}
-
-int
-mu_locker_set_flags (mu_locker_t locker, int flags)
-{
-  return mu_locker_mod_flags (locker, flags, mu_locker_assign);
-}
-
-int
-mu_locker_set_expire_time (mu_locker_t locker, int etime)
-{
-  if (!locker)
-    return MU_ERR_LOCKER_NULL;
-
-  if (etime <= 0)
-    return EINVAL;
-
-  locker->expire_time = etime;
-
-  return 0;
-}
-
-int
-mu_locker_set_retries (mu_locker_t locker, int retries)
-{
-  if (!locker)
-    return MU_ERR_LOCKER_NULL;
-
-  if (retries <= 0)
-    return EINVAL;
-
-  locker->retries = retries;
-
-  return 0;
-}
-
-int
-mu_locker_set_retry_sleep (mu_locker_t locker, int retry_sleep)
-{
-  if (!locker)
-    return MU_ERR_LOCKER_NULL;
-
-  if (retry_sleep <= 0)
-    return EINVAL;
-
-  locker->retry_sleep = retry_sleep;
-
-  return 0;
-}
-
-int
-mu_locker_set_external (mu_locker_t locker, const char* program)
-{
-  char* p = NULL;
-
-  if (!locker)
-    return MU_ERR_LOCKER_NULL;
-  if (MU_LOCKER_TYPE (locker) != MU_LOCKER_TYPE_EXTERNAL)
-    return EINVAL;
-    
-  /* program can be NULL */
-  if (program != 0)
-    {
-      p = strdup (program);
-      if (!p)
-       return ENOMEM;
-  }
-
-  free (locker->data.external.name);
-  locker->data.external.name = p;
-
-  return 0;
-}
-
-int
-mu_locker_get_flags (mu_locker_t locker, int *flags)
-{
-  if (!locker)
-    return MU_ERR_LOCKER_NULL;
-
-  if (!flags)
-    return EINVAL;
-
-  *flags = locker->flags;
-
-  return 0;
-}
-
-int
-mu_locker_get_expire_time (mu_locker_t locker, int *ptime)
-{
-  if (!locker)
-    return MU_ERR_LOCKER_NULL;
-
-  if (!ptime)
-    return EINVAL;
-
-  *ptime = locker->expire_time;
-
-  return 0;
-}
-
-int
-mu_locker_get_retries (mu_locker_t locker, int *retries)
-{
-  if (!locker)
-    return MU_ERR_LOCKER_NULL;
-
-  if (!retries)
-    return EINVAL;
-
-  *retries = locker->retries;
-
-  return 0;
-}
-
-int
-mu_locker_get_retry_sleep (mu_locker_t locker, int *retry_sleep)
-{
-  if (!locker)
-    return MU_ERR_LOCKER_NULL;
-
-  if (!retry_sleep)
-    return EINVAL;
-
-  *retry_sleep = locker->retry_sleep;
-
-  return 0;
-}
-
-int
-mu_locker_create (mu_locker_t *plocker, const char *fname, int flags)
-{
-  unsigned type;
-  mu_locker_t l;
-  char filename[_POSIX_PATH_MAX];
-  int err = 0;
-
-  if (plocker == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-
-  if (fname == NULL)
-    return EINVAL;
-
-  if ((err = mu_unroll_symlink (filename, sizeof (filename), fname)))
-    return err;
-
-  l = calloc (1, sizeof (*l));
-
-  if (l == NULL)
-    return ENOMEM;
-
-  l->file = strdup (filename);
-  
-  if (l->file == NULL)
-    {
-      free (l);
-      return ENOMEM;
-    }
-
-  if (strcmp (filename, "/dev/null") == 0)
-    l->flags = MU_LOCKER_NULL;
-  else if (flags)
-    l->flags = flags;
-  else
-    l->flags = mu_locker_default_flags;
-
-  l->expire_time = mu_locker_expire_timeout;
-  l->retries = mu_locker_retry_count;
-  l->retry_sleep = mu_locker_retry_timeout;
-
-  type = MU_LOCKER_TYPE (l);
-
-  if (type >= MU_LOCKER_NTYPES)
-    {
-      free (l->file);
-      return EINVAL;
-    }
-
-  /* Initialize locker-type-specific data */
-  err = locker_tab[type].init ? locker_tab[type].init (l) : 0;
-  if (err)
-    {
-      mu_locker_destroy (&l);
-      return err;
-    }
-
-  *plocker = l;
-
-  return 0;
-}
-
-void
-mu_locker_destroy (mu_locker_t *plocker)
-{
-  if (plocker && *plocker)
-    {
-      unsigned type = MU_LOCKER_TYPE (*plocker);
-      if (type < MU_LOCKER_NTYPES)
-       {
-         if (locker_tab[type].destroy)
-           locker_tab[type].destroy (*plocker);
-         free ((*plocker)->file);
-         free (*plocker);
-         *plocker = NULL;
-       }
-    }
-}
-
-int
-_mu_locker_lock (mu_locker_t lock, enum mu_locker_mode mode)
-{
-  int rc;
-  unsigned type;
-  unsigned retries = 1;
-  
-  if (lock == NULL || (type = MU_LOCKER_TYPE (lock)) >= MU_LOCKER_NTYPES)
-    return EINVAL;
-
-  if (locker_tab[type].prelock && (rc = locker_tab[type].prelock (lock)))
-    return rc;
-  
-  /* Is the lock already applied? */
-  if (lock->refcnt > 0)
-    {
-      lock->refcnt++;
-      if (mode == lock->mode)
-       return 0;
-    }
-
-  lock->mode = mode;
-
-  if (lock->flags & MU_LOCKER_RETRY)
-    retries = lock->retries;
-
-  if (locker_tab[type].lock)
-    {
-      while (retries--)
-       {
-         rc = locker_tab[type].lock (lock, mode);
-         if (rc == EAGAIN && retries)
-           {
-             sleep (lock->retry_sleep);
-             continue;
-           }
-
-         if (rc == 0)
-           lock->refcnt++;
-
-         break;
-       }
-    }
-  else
-    rc = 0;
-  
-  return rc;
-}
-
-int
-mu_locker_lock (mu_locker_t lock)
-{
-  return _mu_locker_lock (lock, mu_lck_exc);
-}
-
-int
-mu_locker_unlock (mu_locker_t lock)
-{
-  int rc = 0;
-  unsigned type;
-  
-  if (!lock)
-    return MU_ERR_LOCKER_NULL;
-
-  if (lock->refcnt == 0)
-    return MU_ERR_LOCK_NOT_HELD;
-
-  if ((rc = check_file_permissions (lock->file)))
-    return rc;
-
-  if (--lock->refcnt > 0)
-    return 0;
-
-  type = MU_LOCKER_TYPE (lock);
-  if (locker_tab[type].unlock)
-    rc = locker_tab[type].unlock (lock);
-  else
-    rc = 0;
-  
-  return rc;
-}
-
-int
-mu_locker_remove_lock (mu_locker_t lock)
-{
-  if (!lock)
-    return MU_ERR_LOCKER_NULL;
-
-  /* Force the reference count to 1 to unlock the file. */
-  lock->refcnt = 1;
-  return mu_locker_unlock (lock);
-}
-
-
-#define DOTLOCK_SUFFIX ".lock"
-
-/* expire a stale lock (if MU_LOCKER_PID or MU_LOCKER_TIME) */
-static void
-expire_stale_lock (mu_locker_t lock)
-{
-  int stale = 0;
-  int fd = open (lock->data.dot.dotlock, O_RDONLY);
-  if (fd == -1)
-    return;
-
-  /* Check to see if this process is still running.  */
-  if (lock->flags & MU_LOCKER_PID)
-    {
-      char buf[16];
-      pid_t pid;
-      int nread = read (fd, buf, sizeof (buf) - 1);
-      if (nread > 0)
-       {
-         buf[nread] = '\0';
-         pid = strtol (buf, NULL, 10);
-         if (pid > 0)
-           {
-             /* Process is gone so we try to remove the lock. */
-             if (kill (pid, 0) == -1)
-               stale = 1;
-           }
-         else
-           stale = 1;          /* Corrupted file, remove the lock. */
-       }
-    }
-  
-  /* Check to see if the lock expired.  */
-  if (lock->flags & MU_LOCKER_TIME)
-    {
-      struct stat stbuf;
-
-      fstat (fd, &stbuf);
-      /* The lock has expired. */
-      if ((time (NULL) - stbuf.st_mtime) > lock->expire_time)
-       stale = 1;
-    }
-
-  close (fd);
-  if (stale)
-    unlink (lock->data.dot.dotlock);
-}
-
-static int
-init_dotlock (mu_locker_t locker)
-{
-  char *tmp, *p;
-
-  /* Make sure the spool directory is writable */
-  tmp = strdup (locker->file);
-  if (!tmp)
-    return ENOMEM;
-
-  strcpy (tmp, locker->file);
-  p = strrchr (tmp, '/');
-  if (!p)
-    {
-      free (tmp);
-      tmp = strdup (".");
-      if (!tmp)
-       return ENOMEM;
-    }
-  else
-    *p = 0; 
-
-  if (access (tmp, W_OK))
-    {
-      /* Fallback to kernel locking */
-      free (tmp);
-      return mu_locker_set_flags (locker,
-                          MU_LOCKER_KERNEL|MU_LOCKER_OPTIONS(locker->flags));
-    }
-  
-  free (tmp);
-  
-  locker->data.dot.dotlock = malloc (strlen (locker->file)
-                                    + sizeof (DOTLOCK_SUFFIX));
-  
-  if (!locker->data.dot.dotlock)
-    return ENOMEM;
-  strcpy (locker->data.dot.dotlock, locker->file);
-  strcat (locker->data.dot.dotlock, DOTLOCK_SUFFIX);
-
-  return 0;
-}
-
-static void
-destroy_dotlock (mu_locker_t locker)
-{
-  free (locker->data.dot.dotlock);
-  free (locker->data.dot.nfslock);
-}
-
-static int
-lock_dotlock (mu_locker_t locker, enum mu_locker_mode mode)
-{
-  int rc;
-  char *host = NULL;
-  char pid[11];                /* 10 is strlen(2^32 = 4294967296) */
-  char now[11];
-  size_t sz = 0;
-  int err = 0;
-  int fd;
-    
-  if (locker->data.dot.nfslock)
-    {
-      unlink (locker->data.dot.nfslock);
-      free (locker->data.dot.nfslock);
-      locker->data.dot.nfslock = NULL;
-    }
-
-  expire_stale_lock (locker);
-
-  /* build the NFS hitching-post to the lock file */
-
-  rc = mu_get_host_name (&host);
-  if (rc)
-    return rc;
-
-  snprintf (now, sizeof (now), "%lu", (unsigned long) time (0));
-  now[sizeof (now) - 1] = 0;
-
-  snprintf (pid, sizeof (pid), "%lu", (unsigned long) getpid ());
-  pid[sizeof (pid) - 1] = 0;
-                 
-  sz = strlen (locker->file) + 1 /* "." */
-    + strlen (pid) + 1 /* "." */
-    + strlen (now) + 1 /* "." */
-    + strlen (host) + 1;
-  
-  locker->data.dot.nfslock = malloc (sz);
-  
-  if (!locker->data.dot.nfslock)
-    {
-      free (host);
-      return ENOMEM;
-    }
-
-  snprintf (locker->data.dot.nfslock, sz, "%s.%s.%s.%s",
-           locker->file, pid, now, host);
-  free (host);
-  
-  fd = open (locker->data.dot.nfslock,
-            O_WRONLY | O_CREAT | O_EXCL, LOCKFILE_ATTR);
-  if (fd == -1)
-    {
-      if (errno == EEXIST)
-       return EAGAIN;
-      else
-       return errno;
-    }
-  close (fd);
-  
-  /* Try to link to the lockfile. */
-  if (link (locker->data.dot.nfslock, locker->data.dot.dotlock) == -1)
-    {
-      unlink (locker->data.dot.nfslock);
-      if (errno == EEXIST)
-       return MU_ERR_LOCK_CONFLICT;
-      return errno;
-    }
-
-  if ((fd = open (locker->data.dot.dotlock, O_RDWR)) == -1)
-    {
-      unlink (locker->data.dot.nfslock);
-      return errno;
-    }
-  
-  err = stat_check (locker->data.dot.nfslock, fd, 2);
-  if (err)
-    {
-      unlink (locker->data.dot.nfslock);
-      if (err == EINVAL)
-       return MU_ERR_LOCK_BAD_LOCK;
-      return errno;
-    }
-
-  unlink (locker->data.dot.nfslock);
-
-  /* FIXME: If no errors, we have the lock. */
-  assert (locker->refcnt == 0);
-
-  if (locker->flags & MU_LOCKER_PID)
-    {
-      char buf[16];
-      sprintf (buf, "%ld", (long) getpid ());
-      write (fd, buf, strlen (buf));
-    }
-  close (fd);
-  return 0;
-}
-
-static int
-unlock_dotlock (mu_locker_t locker)
-{
-  if (unlink (locker->data.dot.dotlock) == -1)
-    {
-      int err = errno;
-      if (err == ENOENT)
-       {
-         locker->refcnt = 0; /*FIXME?*/
-         err = MU_ERR_LOCK_NOT_HELD;
-         return err;
-       }
-      return err;
-    }
-  return 0;
-}
-
-int
-mu_locker_touchlock (mu_locker_t lock)
-{
-  if (!lock)
-    return MU_ERR_LOCKER_NULL;
-
-  if (MU_LOCKER_TYPE (lock) != MU_LOCKER_TYPE_DOTLOCK)
-    return 0;
-  
-  if (lock->refcnt > 0)
-    return utime (lock->data.dot.dotlock, NULL);
-
-  return MU_ERR_LOCK_NOT_HELD;
-}
-
-
-/* Kernel locking */
-static int
-init_kernel (mu_locker_t locker)
-{
-  return 0;
-}
-
-static int
-lock_kernel (mu_locker_t locker, enum mu_locker_mode mode)
-{
-  int fd;
-  struct flock fl;
-
-  switch (mode)
-    {
-    case mu_lck_shr:
-    case mu_lck_opt:
-      mode = O_RDONLY;
-      fl.l_type = F_RDLCK;
-      break;
-
-    case mu_lck_exc:
-      mode = O_RDWR;
-      fl.l_type = F_WRLCK;
-      break;
-
-    default:
-      return EINVAL;
-    }
-  
-  fd = open (locker->file, O_RDWR);
-  if (fd == -1)
-    return errno;
-  locker->data.kernel.fd = fd;
-  
-  fl.l_whence = SEEK_SET;
-  fl.l_start = 0;
-  fl.l_len = 0; /* Lock entire file */
-  if (fcntl (fd, F_SETLK, &fl))
-    {
-#ifdef EACCESS      
-      if (errno == EACCESS)
-       return EAGAIN;
-#endif
-      if (errno == EAGAIN)
-       return EAGAIN;
-      return errno;
-    }
-  return 0;
-}
-
-static int
-unlock_kernel (mu_locker_t locker)
-{
-  struct flock fl;
-
-  fl.l_type = F_UNLCK;
-  fl.l_whence = SEEK_SET;
-  fl.l_start = 0;
-  fl.l_len = 0; /* Unlock entire file */
-  if (fcntl (locker->data.kernel.fd, F_SETLK, &fl))
-    {
-#ifdef EACCESS
-      if (errno == EACCESS)
-       return EAGAIN;
-#endif
-      if (errno == EAGAIN)
-       return EAGAIN;
-      return errno;
-    }
-  close (locker->data.kernel.fd);
-  return 0;
-}
-
-static int
-init_external (mu_locker_t locker)
-{
-  if (!(locker->data.external.name = strdup (mu_locker_external_program ?
-                                            mu_locker_external_program :
-                                            MU_LOCKER_EXTERNAL_PROGRAM)))
-    return ENOMEM;
-  return 0;
-}
-
-static void
-destroy_external (mu_locker_t locker)
-{
-  free (locker->data.external.name);
-}
-
-/*
-  Estimate 1 decimal digit per 3 bits, + 1 for round off.
-*/
-#define DEC_DIGS_PER_INT (sizeof(int) * 8 / 3 + 1)
-
-static int
-external_locker (mu_locker_t l, int lock)
-{
-  int err = 0;
-  char *av[6];
-  int ac = 0;
-  char aforce[3 + DEC_DIGS_PER_INT + 1];
-  char aretry[3 + DEC_DIGS_PER_INT + 1];
-  int status = 0;
-
-  assert (l);
-  assert (l->flags & MU_LOCKER_EXTERNAL);
-  /* FIXME */
-  assert (lock == !l->refcnt);
-  /* lock is true, refcnt is 0 or lock is false and refcnt is 1 */
-
-  av[ac++] = l->data.external.name ?
-                   l->data.external.name : MU_LOCKER_EXTERNAL_PROGRAM;
-
-  if (l->flags & MU_LOCKER_TIME)
-    {
-      snprintf (aforce, sizeof (aforce), "-f%d", l->expire_time);
-      aforce[sizeof (aforce) - 1] = 0;
-      av[ac++] = aforce;
-    }
-  
-  if (l->flags & MU_LOCKER_RETRY)
-    {
-      snprintf (aretry, sizeof (aretry), "-r%d", l->retries);
-      aretry[sizeof (aretry) - 1] = 0;
-      av[ac++] = aretry;
-    }
-
-  if (!lock)
-    av[ac++] = "-u";
-
-  av[ac++] = l->file;
-
-  av[ac++] = NULL;
-
-  if ((err = mu_spawnvp (av[0], av, &status)))
-    return err;
-
-  if (!WIFEXITED (status))
-    {
-      err = MU_ERR_LOCK_EXT_KILLED;
-    }
-  else
-    {
-      switch (WEXITSTATUS (status))
-       {
-       case 127:
-         err = MU_ERR_LOCK_EXT_FAIL;
-         break;
-         
-       case MU_DL_EX_OK:
-         err = 0;
-         l->refcnt = lock;
-         break;
-         
-       case MU_DL_EX_NEXIST:
-         err = MU_ERR_LOCK_NOT_HELD;
-         break;
-         
-       case MU_DL_EX_EXIST:
-         err = MU_ERR_LOCK_CONFLICT;
-         break;
-         
-       case MU_DL_EX_PERM:
-         err = EPERM;
-         break;
-         
-       default:
-       case MU_DL_EX_ERROR:
-         err = MU_ERR_LOCK_EXT_ERR;
-         break;
-       }
-    }
-
-  return err;
-}
-
-static int
-lock_external (mu_locker_t locker, enum mu_locker_mode mode)
-{
-  return external_locker (locker, 1);
-}
-
-static int
-unlock_external (mu_locker_t locker)
-{
-  return external_locker (locker, 0);
-}
-
diff --git a/libmailutils/mailbox.c b/libmailutils/mailbox.c
deleted file mode 100644
index 56503f5..0000000
--- a/libmailutils/mailbox.c
+++ /dev/null
@@ -1,819 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2006, 2007, 2008, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-
-#include <mailutils/debug.h>
-#include <mailutils/errno.h>
-#include <mailutils/error.h>
-#include <mailutils/folder.h>
-#include <mailutils/iterator.h>
-#include <mailutils/list.h>
-#include <mailutils/locker.h>
-#include <mailutils/observer.h>
-#include <mailutils/property.h>
-#include <mailutils/registrar.h>
-#include <mailutils/stream.h>
-#include <mailutils/url.h>
-#include <mailutils/attribute.h>
-#include <mailutils/message.h>
-#include <mailutils/mutil.h>
-
-#include <mailutils/sys/mailbox.h>
-#include <mailutils/sys/url.h>
-
-/* Mailbox-specific flags */
-#define _MU_MAILBOX_OPEN    0x10000000
-#define _MU_MAILBOX_REMOVED 0x20000000
-#define _MU_MAILBOX_MASK    0xF0000000
-
-static int
-mailbox_folder_create (mu_mailbox_t mbox, const char *name,
-                      mu_record_t record)
-{
-  int rc;
-  mu_url_t url;
-  
-  if ((rc = mu_url_uplevel (mbox->url, &url)))
-    {
-      if (rc == MU_ERR_NOENT)
-       {
-         rc = mu_url_dup (mbox->url, &url);
-         if (rc)
-           return rc;
-       }
-      else
-       return rc;
-    }
-
-  rc = mu_folder_create_from_record (&mbox->folder, url, record);
-  if (rc)
-    mu_url_destroy (&url);
-  return rc;
-}
-
-int
-_mailbox_create_from_record (mu_mailbox_t *pmbox,
-                            mu_record_t record,
-                            mu_url_t url, 
-                            const char *name)
-{
-  mu_log_level_t level;
-  int (*m_init) (mu_mailbox_t) = NULL;
-      
-  mu_record_get_mailbox (record, &m_init);
-  if (m_init)
-    {
-      int status;
-      int (*u_init) (mu_url_t) = NULL;
-      mu_mailbox_t mbox;
-      
-      /* Allocate memory for mbox.  */
-      mbox = calloc (1, sizeof (*mbox));
-      if (mbox == NULL)
-       return ENOMEM;
-      
-      /* Initialize the internal lock now, so the concrete mailbox
-        could use it. */
-      status = mu_monitor_create (&mbox->monitor, 0, mbox);
-      if (status != 0)
-       {
-         mu_mailbox_destroy (&mbox);
-         return status;
-       }
-      
-      /* Make sure scheme contains actual mailbox scheme */
-      /* FIXME: It is appropriate not for all record types.  For now we
-        assume that if the record scheme ends with a plus sign, this
-        should not be done.  Probably it requires some flag in struct
-        _mu_record? */
-      if (strcmp (url->scheme, record->scheme))
-       {
-         char *p = strdup (record->scheme);
-         if (!p)
-           {
-             mu_mailbox_destroy (&mbox);
-             return errno;
-           }
-         free (url->scheme);
-         url->scheme = p;
-       }
-      
-      mu_record_get_url (record, &u_init);
-      if (u_init && (status = u_init (url)) != 0)
-       {
-         mu_mailbox_destroy (&mbox);
-         return status;
-       }
-      
-      mbox->url = url;
-      
-      /* Create the folder before initializing the concrete mailbox.
-        The mailbox needs it's back pointer. */
-      status = mailbox_folder_create (mbox, name, record);
-      
-      if (status == 0)
-       status = m_init (mbox);   /* Create the concrete mailbox type.  */
-      
-      if (status != 0)
-       {
-         /* Take care not to destroy url.  Leave it to caller. */
-         mbox->url = NULL;
-         mu_mailbox_destroy (&mbox);
-       }
-      else
-       {
-         *pmbox = mbox;
-         
-         level = mu_global_debug_level ("mailbox");
-         if (level)
-           {
-             int status = mu_debug_create (&mbox->debug, mbox);
-             if (status)
-               return 0; /* FIXME: don't want to bail out just because I
-                            failed to create a *debug* object. But I may
-                            be wrong... */
-             mu_debug_set_level (mbox->debug, level);
-             if (level & MU_DEBUG_INHERIT)
-               mu_folder_set_debug (mbox->folder, mbox->debug);
-           }
-       }
-      
-      return status;
-    }
-  return MU_ERR_NO_HANDLER;
-}
-
-static int
-_create_mailbox0 (mu_mailbox_t *pmbox, mu_url_t url, const char *name)
-{
-  mu_record_t record = NULL;
-
-  if (mu_registrar_lookup_url (url, MU_FOLDER_ATTRIBUTE_FILE, &record, NULL)
-      == 0)
-    return _mailbox_create_from_record (pmbox, record, url, name);
-  return MU_ERR_NO_HANDLER;
-}
-
-static int
-_create_mailbox (mu_mailbox_t *pmbox, const char *name)
-{
-  int status;
-  mu_url_t url;
-
-  status = mu_url_create (&url, name);
-  if (status)
-    return status;
-  status = mu_url_parse (url);
-  if (status == 0)
-    status = _create_mailbox0 (pmbox, url, name);
-  if (status)
-    mu_url_destroy (&url);
-  return status;
-}
-
-/* The Mailbox Factory.
-   Create an iterator for registrar and see if any url scheme match,
-   Then we call the mailbox's mu_url_create() to parse the URL. Last
-   initialize the concrete mailbox and folder.  */
-int
-mu_mailbox_create (mu_mailbox_t *pmbox, const char *name)
-{
-  if (pmbox == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-
-  return _create_mailbox (pmbox, name);
-}
-
-int
-mu_mailbox_create_from_url (mu_mailbox_t *pmbox, mu_url_t url)
-{
-  if (pmbox == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  return _create_mailbox0 (pmbox, url, mu_url_to_string (url));
-}
-
-int
-mu_mailbox_create_from_record (mu_mailbox_t *pmbox, mu_record_t record,
-                              const char *name)
-{
-  mu_url_t url;
-  int rc;
-  
-  rc = mu_url_create (&url, name);
-  if (rc)
-    return rc;
-  rc = mu_url_parse (url);
-  if (rc == 0)
-    rc = _mailbox_create_from_record (pmbox, record, url, name);
-  if (rc)
-    mu_url_destroy (&url);
-  return rc;
-}
-
-void
-mu_mailbox_destroy (mu_mailbox_t *pmbox)
-{
-  if (pmbox && *pmbox)
-    {
-      mu_mailbox_t mbox = *pmbox;
-      mu_monitor_t monitor = mbox->monitor;
-
-      /* Notify the observers.  */
-      if (mbox->observable)
-       {
-         mu_observable_notify (mbox->observable, MU_EVT_MAILBOX_DESTROY,
-                               mbox);
-         mu_observable_destroy (&mbox->observable, mbox);
-       }
-
-      /* Call the concrete mailbox _destroy method. So it can clean itself.  */
-      if (mbox->_destroy)
-       mbox->_destroy (mbox);
-
-      mu_monitor_wrlock (monitor);
-
-      /* Close the stream and nuke it */
-      if (mbox->stream)
-       {
-         /* FIXME: Is this right, should the client be responsible
-            for closing the stream?  */
-         /* mu_stream_close (mbox->stream); */
-         mu_stream_destroy (&mbox->stream);
-       }
-
-      if (mbox->url)
-        mu_url_destroy (&mbox->url);
-
-      if (mbox->locker)
-       mu_locker_destroy (&mbox->locker);
-
-      if (mbox->debug)
-       mu_debug_destroy (&mbox->debug, mbox);
-
-      if (mbox->folder)
-       mu_folder_destroy (&mbox->folder);
-
-      if (mbox->property)
-       mu_property_destroy (&mbox->property, mbox);
-
-      free (mbox);
-      *pmbox = NULL;
-      mu_monitor_unlock (monitor);
-      mu_monitor_destroy (&monitor, mbox);
-    }
-}
-
-
-/* -------------- stub functions ------------------- */
-
-int
-mu_mailbox_open (mu_mailbox_t mbox, int flag)
-{
-  int rc;
-  
-  if (!mbox)
-    return MU_ERR_MBX_NULL;
-  if (mbox->_open == NULL)
-    return MU_ERR_EMPTY_VFN;
-  if (mbox->flags & _MU_MAILBOX_OPEN)
-    return MU_ERR_OPEN;
-  if (flag & MU_STREAM_QACCESS)
-    {
-      /* Quick access mailboxes are read-only */
-      if (flag & (MU_STREAM_WRITE | MU_STREAM_RDWR
-                 | MU_STREAM_APPEND | MU_STREAM_CREAT))
-       return EINVAL; /* FIXME: Better error code, please? */
-    }
-  rc = mbox->_open (mbox, flag);
-  if (rc == 0)
-    mbox->flags |= _MU_MAILBOX_OPEN;
-  return rc;
-}
-
-int
-mu_mailbox_close (mu_mailbox_t mbox)
-{
-  int rc;
-
-  if (!mbox)
-    return MU_ERR_MBX_NULL;
-  if (!(mbox->flags & _MU_MAILBOX_OPEN))
-    return MU_ERR_NOT_OPEN;
-  if (mbox == NULL || mbox->_close == NULL)
-    return MU_ERR_EMPTY_VFN;
-
-  rc = mbox->_close (mbox);
-  if (rc == 0)
-    mbox->flags &= ~_MU_MAILBOX_OPEN;
-  return rc;
-}
-
-int
-mu_mailbox_remove (mu_mailbox_t mbox)
-{
-  if (!mbox)
-    return MU_ERR_MBX_NULL;
-  if (mbox->flags & _MU_MAILBOX_OPEN)
-    return MU_ERR_OPEN;
-  if (mbox->flags & _MU_MAILBOX_REMOVED)
-    return MU_ERR_MBX_REMOVED;
-  if (!mbox->_remove)
-    return MU_ERR_EMPTY_VFN;
-  return mbox->_remove (mbox);
-}
-
-int
-mu_mailbox_flush (mu_mailbox_t mbox, int expunge)
-{
-  size_t i, total = 0;
-  int status = 0;
-  
-  if (!mbox)
-    return MU_ERR_MBX_NULL;
-  if (mbox->flags & _MU_MAILBOX_REMOVED)
-    return MU_ERR_MBX_REMOVED;
-  if (!(mbox->flags & _MU_MAILBOX_OPEN))
-    return _MU_MAILBOX_OPEN;
-  if (!(mbox->flags & (MU_STREAM_RDWR|MU_STREAM_WRITE|MU_STREAM_APPEND)))
-    return 0;
-
-  mu_mailbox_messages_count (mbox, &total);
-  if (!(mbox->flags & MU_STREAM_APPEND))
-    for (i = 1; i <= total; i++)
-      {
-       mu_message_t msg = NULL;
-       mu_attribute_t attr = NULL;
-       mu_mailbox_get_message (mbox, i, &msg);
-       mu_message_get_attribute (msg, &attr);
-       mu_attribute_set_seen (attr);
-      }
-
-  if (expunge)
-    status = mu_mailbox_expunge (mbox);
-  else
-    status = mu_mailbox_sync (mbox);
-
-  return status;
-}
-
-#define _MBOX_CHECK_FLAGS(mbox)                        \
-  if (mbox == NULL)                            \
-    return MU_ERR_MBX_NULL;                    \
-  if (mbox->flags & _MU_MAILBOX_REMOVED)       \
-    return MU_ERR_MBX_REMOVED;                 \
-  if (!(mbox->flags & _MU_MAILBOX_OPEN))       \
-    return _MU_MAILBOX_OPEN
-
-#define _MBOX_CHECK(mbox,method)               \
-  _MBOX_CHECK_FLAGS(mbox);                     \
-  if (mbox->method == NULL)                    \
-    return MU_ERR_EMPTY_VFN
-
-#define _MBOX_CHECK_Q(mbox,method)             \
-  _MBOX_CHECK(mbox,method);                    \
-  if (mbox->flags & MU_STREAM_QACCESS)         \
-    return MU_ERR_BADOP
-
-/* messages */
-int
-mu_mailbox_append_message (mu_mailbox_t mbox, mu_message_t msg)
-{
-  _MBOX_CHECK_Q (mbox, _append_message);
-  if (!(mbox->flags & (MU_STREAM_RDWR|MU_STREAM_WRITE|MU_STREAM_APPEND)))
-    return EACCES;
-  return mbox->_append_message (mbox, msg);
-}
-
-int
-mu_mailbox_get_message (mu_mailbox_t mbox, size_t msgno,  mu_message_t *pmsg)
-{
-  _MBOX_CHECK_Q (mbox, _get_message);
-  return mbox->_get_message (mbox, msgno, pmsg);
-}
-
-int
-mu_mailbox_quick_get_message (mu_mailbox_t mbox, mu_message_qid_t qid,
-                             mu_message_t *pmsg)
-{
-  _MBOX_CHECK (mbox, _quick_get_message);
-  if (!(mbox->flags & MU_STREAM_QACCESS))
-    return MU_ERR_BADOP;
-  return mbox->_quick_get_message (mbox, qid, pmsg);
-}
-
-int
-mu_mailbox_messages_count (mu_mailbox_t mbox, size_t *num)
-{
-  _MBOX_CHECK_Q (mbox, _messages_count);
-  return mbox->_messages_count (mbox, num);
-}
-
-int
-mu_mailbox_messages_recent (mu_mailbox_t mbox, size_t *num)
-{
-  _MBOX_CHECK_Q (mbox, _messages_recent);
-  return mbox->_messages_recent (mbox, num);
-}
-
-int
-mu_mailbox_message_unseen (mu_mailbox_t mbox, size_t *num)
-{
-  _MBOX_CHECK_Q (mbox, _message_unseen);
-  return mbox->_message_unseen (mbox, num);
-}
-
-int
-mu_mailbox_sync (mu_mailbox_t mbox)
-{
-  _MBOX_CHECK_Q (mbox, _sync);
-  if (!(mbox->flags & (MU_STREAM_RDWR|MU_STREAM_WRITE|MU_STREAM_APPEND)))
-    return 0;
-  return mbox->_sync (mbox);
-}
-
-/* Historic alias: */
-int
-mu_mailbox_save_attributes (mu_mailbox_t mbox)
-{
-  return mu_mailbox_sync (mbox);
-}
-
-int
-mu_mailbox_expunge (mu_mailbox_t mbox)
-{
-  _MBOX_CHECK_Q (mbox, _expunge);
-  if (!(mbox->flags & (MU_STREAM_RDWR|MU_STREAM_WRITE|MU_STREAM_APPEND)))
-    return EACCES;
-  return mbox->_expunge (mbox);
-}
-
-int
-mu_mailbox_is_updated (mu_mailbox_t mbox)
-{
-  if (mbox == NULL ||
-      !(mbox->flags & _MU_MAILBOX_OPEN) ||
-      (mbox->flags & _MU_MAILBOX_REMOVED) ||
-      mbox->_is_updated == NULL)
-    return 1;
-  if (mbox->flags & MU_STREAM_QACCESS)
-    return 1;
-  return mbox->_is_updated (mbox);
-}
-
-int
-mu_mailbox_scan (mu_mailbox_t mbox, size_t msgno, size_t *pcount)
-{
-  _MBOX_CHECK_Q (mbox, _scan);
-  return mbox->_scan (mbox, msgno, pcount);
-}
-
-int
-mu_mailbox_get_size (mu_mailbox_t mbox, mu_off_t *psize)
-{
-  int status;
-
-  _MBOX_CHECK_FLAGS (mbox);
-  if (mbox->flags & MU_STREAM_QACCESS)
-    return MU_ERR_BADOP;
-  if (mbox->_get_size == NULL
-      || (status = mbox->_get_size (mbox, psize)) == ENOSYS)
-    {
-      /* Fall back to brute-force method */
-      size_t i, total;
-      mu_off_t size = 0;
-      
-      status = mu_mailbox_messages_count (mbox, &total);
-      if (status)
-       return status;
-      for (i = 1; i <= total; i++)
-       {
-         mu_message_t msg;
-         size_t msgsize;
-         status = mu_mailbox_get_message (mbox, i, &msg);
-         if (status)
-           return status;
-         status = mu_message_size (msg, &msgsize);
-         if (status)
-           return status;
-         size += msgsize;
-       }
-      *psize = size;
-    }
-  return status;
-}
-
-int
-mu_mailbox_uidvalidity (mu_mailbox_t mbox, unsigned long *pvalid)
-{
-  _MBOX_CHECK_Q (mbox, _uidvalidity);
-  return mbox->_uidvalidity (mbox, pvalid);
-}
-
-int
-mu_mailbox_uidnext (mu_mailbox_t mbox, size_t *puidnext)
-{
-  _MBOX_CHECK_Q (mbox, _uidnext);
-  return mbox->_uidnext (mbox, puidnext);
-}
-
-/* locking */
-int
-mu_mailbox_set_locker (mu_mailbox_t mbox, mu_locker_t locker)
-{
-  if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
-  if (mbox->locker)
-    mu_locker_destroy (&mbox->locker);
-  mbox->locker = locker;
-  return 0;
-}
-
-int
-mu_mailbox_get_locker (mu_mailbox_t mbox, mu_locker_t *plocker)
-{
-  if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
-  if (plocker == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  *plocker = mbox->locker;
-  return 0;
-}
-
-int
-mu_mailbox_get_flags (mu_mailbox_t mbox, int *flags)
-{
-  if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
-  if (!*flags)
-    return MU_ERR_OUT_NULL;
-  *flags = mbox->flags & ~_MU_MAILBOX_MASK;
-  return 0;
-}
-
-int
-mu_mailbox_set_stream (mu_mailbox_t mbox, mu_stream_t stream)
-{
-  if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
-  if (mbox->flags & MU_STREAM_QACCESS)
-    return MU_ERR_BADOP;
-  if (mbox->stream)
-    mu_stream_destroy (&mbox->stream);
-  mbox->stream = stream;
-  return 0;
-}
-
-/* FIXME: This is a problem.  We provide a mu_mailbox_get_stream ()
-   and this stream is special it should, in theory, represent
-   a "view" of a flow of messages.  But providing this perspective
-   may make sense for local mailboxes but downright impossible
-   for a remote mailbox, short on downloading the entire mailbox
-   locally.
-   The question is : should this function be removed?
-   So far it as been used on local mailboxes to get offsets.  */
-int
-mu_mailbox_get_stream (mu_mailbox_t mbox, mu_stream_t *pstream)
-{
-  /* FIXME: Deprecation warning */
-  if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
-  if (pstream == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-
-  /* If null two cases:
-     - it is no open yet.
-     - it a remote stream and the socket stream is on the folder.  */
-  if (mbox->stream == NULL)
-    {
-      if (mbox->folder)
-       return mu_folder_get_stream (mbox->folder, pstream);
-    }
-  *pstream = mbox->stream;
-  return 0;
-}
-
-int
-mu_mailbox_get_streamref (mu_mailbox_t mbox, mu_stream_t *pstream)
-{
-  if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
-  if (pstream == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-
-  /* If null two cases:
-     - it is no open yet.
-     - it a remote stream and the socket stream is on the folder.  */
-  if (mbox->stream == NULL)
-    {
-      if (mbox->folder)
-       return mu_folder_get_streamref (mbox->folder, pstream);
-    }
-  return mu_streamref_create (pstream, mbox->stream);
-}
-
-int
-mu_mailbox_get_observable (mu_mailbox_t mbox, mu_observable_t *pobservable)
-{
-  if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
-  if (pobservable == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-
-  if (mbox->observable == NULL)
-    {
-      int status = mu_observable_create (&mbox->observable, mbox);
-      if (status != 0)
-       return status;
-    }
-  *pobservable = mbox->observable;
-  return 0;
-}
-
-int
-mu_mailbox_get_property (mu_mailbox_t mbox, mu_property_t *pproperty)
-{
-  if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
-  if (pproperty == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  
-  if (mbox->property == NULL)
-    {
-      int status = mu_property_create (&mbox->property, mbox);
-      if (status != 0)
-       return status;
-    }
-  *pproperty = mbox->property;
-  return 0;
-}
-
-int
-mu_mailbox_has_debug (mu_mailbox_t mailbox)
-{
-  if (mailbox == NULL)
-    return 0;
-
-  return mailbox->debug ? 1 : 0;
-}
-
-int
-mu_mailbox_set_debug (mu_mailbox_t mbox, mu_debug_t debug)
-{
-  if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
-  if (mbox->debug)
-    mu_debug_destroy (&mbox->debug, mbox);
-  mbox->debug = debug;
-  /* FIXME: Honor MU_DEBUG_INHERIT */
-  if (!mu_folder_has_debug (mbox->folder))
-    mu_folder_set_debug (mbox->folder, debug);
-  return 0;
-}
-
-int
-mu_mailbox_get_debug (mu_mailbox_t mbox, mu_debug_t *pdebug)
-{
-  if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
-  if (pdebug == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  if (mbox->debug == NULL)
-    {
-      int status = mu_debug_create (&mbox->debug, mbox);
-      if (status != 0)
-       return status;
-      /* FIXME: MU_DEBUG_INHERIT?? */
-      if (!mu_folder_has_debug (mbox->folder))
-       mu_folder_set_debug (mbox->folder, mbox->debug);
-    }
-  *pdebug = mbox->debug;
-  return 0;
-}
-
-int
-mu_mailbox_get_url (mu_mailbox_t mbox, mu_url_t *purl)
-{
-  if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
-  if (purl == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  *purl = mbox->url;
-  return 0;
-}
-
-int
-mu_mailbox_get_folder (mu_mailbox_t mbox, mu_folder_t *pfolder)
-{
-  if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
-  if (pfolder == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  *pfolder = mbox->folder;
-  return 0;
-}
-
-int
-mu_mailbox_set_folder (mu_mailbox_t mbox, mu_folder_t folder)
-{
-  if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
-   mbox->folder = folder;
-  return 0;
-}
-
-int
-mu_mailbox_lock (mu_mailbox_t mbox)
-{
-  mu_locker_t lock = NULL;
-  mu_mailbox_get_locker (mbox, &lock);
-  return mu_locker_lock (lock);
-}
-
-int
-mu_mailbox_unlock (mu_mailbox_t mbox)
-{
-  mu_locker_t lock = NULL;
-  mu_mailbox_get_locker (mbox, &lock);
-  return mu_locker_unlock (lock);
-}
-
-int
-mu_mailbox_get_uidls (mu_mailbox_t mbox, mu_list_t *plist)
-{
-  mu_list_t list;
-  int status;
-
-  if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
-  if (plist == NULL)
-    return EINVAL;
-  status = mu_list_create (&list);
-  if (status)
-    return status;
-  mu_list_set_destroy_item (list, mu_list_free_item);
-  if (mbox->_get_uidls)
-    status = mbox->_get_uidls (mbox, list);
-  else
-    {
-      size_t i, total;
-
-      status = mu_mailbox_messages_count (mbox, &total);
-      if (status)
-       return status;
-      for (i = 1; i <= total; i++)
-       {
-         mu_message_t msg = NULL;
-         char buf[MU_UIDL_BUFFER_SIZE];
-         size_t n;
-         struct mu_uidl *uidl;
-         
-         status = mu_mailbox_get_message (mbox, i, &msg);
-         if (status)
-           break;
-         status = mu_message_get_uidl (msg, buf, sizeof (buf), &n);
-         if (status)
-           break;
-         uidl = malloc (sizeof (uidl[0]));
-         if (!uidl)
-           {
-             status = ENOMEM;
-             break;
-           }
-         uidl->msgno = i;
-         strncpy (uidl->uidl, strdup (buf), MU_UIDL_BUFFER_SIZE);
-         status = mu_list_append (list, uidl);
-         if (status)
-           {
-             free (uidl);
-             break;
-           }
-       }
-    }
-  *plist = list;
-  return status;
-}
-
-         
diff --git a/libmailutils/mailbox/Makefile.am b/libmailutils/mailbox/Makefile.am
new file mode 100644
index 0000000..5fffd57
--- /dev/null
+++ b/libmailutils/mailbox/Makefile.am
@@ -0,0 +1,33 @@
+# 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/>.
+
+noinst_LTLIBRARIES = libmailbox.la
+
+libmailbox_la_SOURCES =  \
+ mailbox.c\
+ mbx_default.c\
+ mbxitr.c\
+ attribute.c\
+ body.c\
+ envelope.c\
+ folder.c\
+ hdritr.c\
+ header.c\
+ message.c\
+ msgscan.c
+
+INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
diff --git a/libmailutils/mailbox/attribute.c b/libmailutils/mailbox/attribute.c
new file mode 100644
index 0000000..37e479a
--- /dev/null
+++ b/libmailutils/mailbox/attribute.c
@@ -0,0 +1,469 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2005, 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/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/errno.h>
+#include <mailutils/mutil.h>
+#include <mailutils/cstr.h>
+#include <mailutils/sys/attribute.h>
+
+int
+mu_attribute_create (mu_attribute_t *pattr, void *owner)
+{
+  mu_attribute_t attr;
+  if (pattr == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  attr = calloc (1, sizeof(*attr));
+  if (attr == NULL)
+    return ENOMEM;
+  attr->owner = owner;
+  *pattr = attr;
+  return 0;
+}
+
+void
+mu_attribute_destroy (mu_attribute_t *pattr, void *owner)
+{
+  if (pattr && *pattr)
+    {
+      mu_attribute_t attr = *pattr;
+      if (attr->owner == owner)
+       free (*pattr);
+      /* Loose the link */
+      *pattr = NULL;
+    }
+}
+
+void *
+mu_attribute_get_owner (mu_attribute_t attr)
+{
+  return (attr) ? attr->owner : NULL;
+}
+
+int
+mu_attribute_is_modified (mu_attribute_t attr)
+{
+  return (attr) ? attr->flags & MU_ATTRIBUTE_MODIFIED : 0;
+}
+
+int
+mu_attribute_clear_modified (mu_attribute_t attr)
+{
+  if (attr)
+    attr->flags &= ~MU_ATTRIBUTE_MODIFIED;
+  return 0;
+}
+
+int
+mu_attribute_set_modified (mu_attribute_t attr)
+{
+  if (attr)
+    attr->flags |= MU_ATTRIBUTE_MODIFIED;
+  return 0;
+}
+
+int
+mu_attribute_get_flags (mu_attribute_t attr, int *pflags)
+{
+  if (attr == NULL)
+    return EINVAL;
+  if (pflags == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  if (attr->_get_flags)
+    return attr->_get_flags (attr, pflags);
+  *pflags = attr->flags;
+  return 0;
+}
+
+int
+mu_attribute_set_flags (mu_attribute_t attr, int flags)
+{
+  int status = 0;
+  int oflags = 0;
+  
+  if (attr == NULL)
+    return EINVAL;
+
+  /* If the required bits are already set, do not modify anything */
+  mu_attribute_get_flags (attr, &oflags);
+  if ((oflags & flags) == flags)
+    return 0;
+  
+  if (attr->_set_flags)
+    status = attr->_set_flags (attr, flags);
+  else
+    attr->flags |= flags;
+  if (status == 0)
+    mu_attribute_set_modified (attr);
+  return 0;
+}
+
+int
+mu_attribute_unset_flags (mu_attribute_t attr, int flags)
+{
+  int status = 0;
+  int oflags = 0;
+
+  if (attr == NULL)
+    return EINVAL;
+
+  /* If the required bits are already cleared, do not modify anything */
+  mu_attribute_get_flags (attr, &oflags);
+  if ((oflags & flags) == 0)
+    return 0;
+
+  if (attr->_unset_flags)
+    status = attr->_unset_flags (attr, flags);
+  else
+    attr->flags &= ~flags;
+  if (status == 0)
+    mu_attribute_set_modified (attr);
+  return 0;
+}
+
+int
+mu_attribute_set_get_flags (mu_attribute_t attr, int (*_get_flags)
+                        (mu_attribute_t, int *), void *owner)
+{
+  if (attr == NULL)
+    return EINVAL;
+  if (attr->owner != owner)
+    return EACCES;
+  attr->_get_flags = _get_flags;
+  return 0;
+}
+
+int
+mu_attribute_set_set_flags (mu_attribute_t attr, int (*_set_flags)
+                        (mu_attribute_t, int), void *owner)
+{
+  if (attr == NULL)
+    return EINVAL;
+  if (attr->owner != owner)
+    return EACCES;
+  attr->_set_flags = _set_flags;
+  return 0;
+}
+
+int
+mu_attribute_set_unset_flags (mu_attribute_t attr, int (*_unset_flags)
+                        (mu_attribute_t, int), void *owner)
+{
+  if (attr == NULL)
+    return EINVAL;
+  if (attr->owner != owner)
+    return EACCES;
+  attr->_unset_flags = _unset_flags;
+  return 0;
+}
+
+/* We add support for "USER" flag, it is a way for external objects
+   Not being the owner to add custom flags.  */
+int
+mu_attribute_set_userflag (mu_attribute_t attr, int flag)
+{
+  if (attr == NULL)
+    return EINVAL;
+  attr->user_flags |= flag;
+  return 0;
+}
+
+int
+mu_attribute_set_seen (mu_attribute_t attr)
+{
+  return mu_attribute_set_flags (attr, MU_ATTRIBUTE_SEEN);
+}
+
+int
+mu_attribute_set_answered (mu_attribute_t attr)
+{
+  return mu_attribute_set_flags (attr, MU_ATTRIBUTE_ANSWERED);
+}
+
+int
+mu_attribute_set_flagged (mu_attribute_t attr)
+{
+  return mu_attribute_set_flags (attr, MU_ATTRIBUTE_FLAGGED);
+}
+
+int
+mu_attribute_set_read (mu_attribute_t attr)
+{
+  return mu_attribute_set_flags (attr, MU_ATTRIBUTE_READ);
+}
+
+int
+mu_attribute_set_deleted (mu_attribute_t attr)
+{
+  return mu_attribute_set_flags (attr, MU_ATTRIBUTE_DELETED);
+}
+
+int
+mu_attribute_set_draft (mu_attribute_t attr)
+{
+  return mu_attribute_set_flags (attr, MU_ATTRIBUTE_DRAFT);
+}
+
+int
+mu_attribute_set_recent (mu_attribute_t attr)
+{
+  int status = mu_attribute_unset_flags (attr, MU_ATTRIBUTE_READ);
+  if (status == 0)
+    status = mu_attribute_unset_flags (attr, MU_ATTRIBUTE_SEEN);
+  return status;
+}
+
+int
+mu_attribute_is_userflag (mu_attribute_t attr, int flag)
+{
+  if (attr == NULL)
+    return 0;
+  return attr->user_flags & flag;
+}
+
+int
+mu_attribute_is_seen (mu_attribute_t attr)
+{
+  int flags = 0;
+  if (mu_attribute_get_flags (attr, &flags) == 0)
+    return flags & MU_ATTRIBUTE_SEEN;
+  return 0;
+}
+
+int
+mu_attribute_is_answered (mu_attribute_t attr)
+{
+  int flags = 0;
+  if (mu_attribute_get_flags (attr, &flags) == 0)
+    return flags & MU_ATTRIBUTE_ANSWERED;
+  return 0;
+}
+
+int
+mu_attribute_is_flagged (mu_attribute_t attr)
+{
+  int flags = 0;
+  if (mu_attribute_get_flags (attr, &flags) == 0)
+    return flags & MU_ATTRIBUTE_FLAGGED;
+  return 0;
+}
+
+int
+mu_attribute_is_read (mu_attribute_t attr)
+{
+  int flags = 0;
+  if (mu_attribute_get_flags (attr, &flags) == 0)
+    return flags & MU_ATTRIBUTE_READ;
+  return 0;
+}
+
+int
+mu_attribute_is_deleted (mu_attribute_t attr)
+{
+  int flags = 0;
+  if (mu_attribute_get_flags (attr, &flags) == 0)
+    return flags & MU_ATTRIBUTE_DELETED;
+  return 0;
+}
+
+int
+mu_attribute_is_draft (mu_attribute_t attr)
+{
+  int flags = 0;
+  if (mu_attribute_get_flags (attr, &flags) == 0)
+    return flags & MU_ATTRIBUTE_DRAFT;
+  return 0;
+}
+
+int
+mu_attribute_is_recent (mu_attribute_t attr)
+{
+  int flags = 0;
+  if (mu_attribute_get_flags (attr, &flags) == 0)
+    return MU_ATTRIBUTE_IS_UNSEEN(flags);
+  return 0;
+}
+
+int
+mu_attribute_unset_userflag (mu_attribute_t attr, int flag)
+{
+  if (attr == NULL)
+    return 0;
+  attr->user_flags &= ~flag;
+  return 0;
+}
+
+int
+mu_attribute_unset_seen (mu_attribute_t attr)
+{
+  return mu_attribute_unset_flags (attr, MU_ATTRIBUTE_SEEN);
+}
+
+int
+mu_attribute_unset_answered (mu_attribute_t attr)
+{
+  return mu_attribute_unset_flags (attr, MU_ATTRIBUTE_ANSWERED);
+}
+
+int
+mu_attribute_unset_flagged (mu_attribute_t attr)
+{
+  return mu_attribute_unset_flags (attr, MU_ATTRIBUTE_FLAGGED);
+}
+
+int
+mu_attribute_unset_read (mu_attribute_t attr)
+{
+  return mu_attribute_unset_flags (attr, MU_ATTRIBUTE_READ);
+}
+
+int
+mu_attribute_unset_deleted (mu_attribute_t attr)
+{
+  return mu_attribute_unset_flags (attr, MU_ATTRIBUTE_DELETED);
+}
+
+int
+mu_attribute_unset_draft (mu_attribute_t attr)
+{
+  return mu_attribute_unset_flags (attr, MU_ATTRIBUTE_DRAFT);
+}
+
+int
+mu_attribute_unset_recent (mu_attribute_t attr)
+{
+  return mu_attribute_unset_flags (attr, MU_ATTRIBUTE_SEEN);
+}
+
+int
+mu_attribute_is_equal (mu_attribute_t attr, mu_attribute_t attr2)
+{
+  int flags2 = 0, flags = 0;
+  mu_attribute_get_flags (attr, &flags);
+  mu_attribute_get_flags (attr2, &flags2);
+  return flags == flags;
+}
+
+/*   Miscellaneous.  */
+int
+mu_attribute_copy (mu_attribute_t dest, mu_attribute_t src)
+{
+  if (dest == NULL || src == NULL)
+    return EINVAL;
+  /* Can not be a deep copy.  */
+  /* memcpy (dest, src, sizeof (*dest)); */
+  dest->flags = src->flags;
+  return 0;
+}
+
+struct flagtrans
+{
+  int flag;
+  char letter;
+};
+
+/* The two macros below are taken from gnulib module verify.h */
+#define mu_verify_true(R) \
+  (!!sizeof \
+   (struct { unsigned int verify_error_if_negative_size__: (R) ? 1 : -1; }))
+#define mu_verify(R) extern int (* verify_function__ (void)) [mu_verify_true 
(R)]
+
+static struct flagtrans flagtrans[] = {
+  { MU_ATTRIBUTE_SEEN, 'O' },
+  { MU_ATTRIBUTE_ANSWERED, 'A' },
+  { MU_ATTRIBUTE_FLAGGED, 'F' },
+  { MU_ATTRIBUTE_READ, 'R' },
+  { MU_ATTRIBUTE_DELETED, 'd' },
+  { 0 }
+};
+
+/* If cc reports an error in this statement, fix the MU_STATUS_BUF_SIZE
+   declaration in include/mailutils/attribute.h */
+mu_verify (MU_ARRAY_SIZE (flagtrans) == MU_STATUS_BUF_SIZE);
+
+int
+mu_string_to_flags (const char *buffer, int *pflags)
+{
+  const char *sep;
+
+  if (pflags == NULL)
+    return EINVAL;
+
+  /* Set the attribute */
+  if (mu_c_strncasecmp (buffer, "Status:", 7) == 0)
+    {
+      sep = strchr(buffer, ':'); /* pass the ':' */
+      sep++;
+    }
+  else
+    sep = buffer;
+
+  for (; *sep; sep++)
+    {
+      struct flagtrans *ft;
+
+      for (ft = flagtrans; ft->flag; ft++)
+       if (ft->letter == *sep)
+         {
+           *pflags |= ft->flag;
+           break;
+         }
+    }
+  return 0;
+}
+
+/* NOTE: When adding/removing flags, make sure to update the
+   MU_STATUS_BUF_SIZE define in include/mailutils/attribute.h */
+int
+mu_attribute_to_string (mu_attribute_t attr, char *buffer, size_t len,
+                       size_t *pn)
+{
+  int flags = 0;
+  char buf[MU_STATUS_BUF_SIZE];
+  int i;
+  int rc;
+  struct flagtrans *ft;
+  
+  rc = mu_attribute_get_flags (attr, &flags);
+  if (rc)
+    return rc;
+
+  i = 0;
+  for (ft = flagtrans; ft->flag; ft++)
+    if (ft->flag & flags)
+      buf[i++] = ft->letter;
+  buf[i++] = 0;
+
+  i = mu_cpystr (buffer, buf, i);
+  if (pn)
+    *pn = i;
+  return 0;
+}
+
diff --git a/libmailutils/mailbox/body.c b/libmailutils/mailbox/body.c
new file mode 100644
index 0000000..b4cf22b
--- /dev/null
+++ b/libmailutils/mailbox/body.c
@@ -0,0 +1,416 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2010 Free Software
+   Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <mailutils/stream.h>
+#include <mailutils/mutil.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/stream.h>
+#include <mailutils/sys/body.h>
+
+#define BODY_MODIFIED 0x10000
+
+static int _body_flush    (mu_stream_t);
+static int _body_read     (mu_stream_t, char *, size_t, size_t *);
+static int _body_truncate (mu_stream_t, mu_off_t);
+static int _body_size     (mu_stream_t, mu_off_t *);
+static int _body_write    (mu_stream_t, const char *, size_t, size_t *);
+static int _body_ioctl    (mu_stream_t, int, void *);
+static int _body_seek     (mu_stream_t, mu_off_t, mu_off_t *);
+static const char *_body_error_string (mu_stream_t, int);
+
+/* Our own defaults for the body.  */
+static int _body_get_size   (mu_body_t, size_t *);
+static int _body_get_lines  (mu_body_t, size_t *);
+static int _body_get_size0  (mu_stream_t, size_t *);
+static int _body_get_lines0 (mu_stream_t, size_t *);
+
+int
+mu_body_create (mu_body_t *pbody, void *owner)
+{
+  mu_body_t body;
+
+  if (pbody == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  if (owner == NULL)
+    return EINVAL;
+
+  body = calloc (1, sizeof (*body));
+  if (body == NULL)
+    return ENOMEM;
+
+  body->owner = owner;
+  *pbody = body;
+  return 0;
+}
+
+void
+mu_body_destroy (mu_body_t *pbody, void *owner)
+{
+  if (pbody && *pbody)
+    {
+      mu_body_t body = *pbody;
+      if (body->owner == owner)
+       {
+         if (body->filename)
+           {
+             /* FIXME: should we do this?  */
+             remove (body->filename);
+             free (body->filename);
+           }
+
+         if (body->stream)
+           mu_stream_destroy (&body->stream);
+
+         if (body->fstream)
+           {
+             mu_stream_close (body->fstream);
+             mu_stream_destroy (&body->fstream);
+           }
+
+         free (body);
+       }
+      *pbody = NULL;
+    }
+}
+
+void *
+mu_body_get_owner (mu_body_t body)
+{
+  return (body) ? body->owner : NULL;
+}
+
+/* FIXME: not implemented.  */
+int
+mu_body_is_modified (mu_body_t body)
+{
+  return (body) ? (body->flags & BODY_MODIFIED) : 0;
+}
+
+/* FIXME: not implemented.  */
+int
+mu_body_clear_modified (mu_body_t body)
+{
+  if (body)
+    body->flags &= ~BODY_MODIFIED;
+  return 0;
+}
+
+int
+mu_body_get_filename (mu_body_t body, char *filename, size_t len, size_t *pn)
+{
+  int n = 0;
+  if (body == NULL)
+    return EINVAL;
+  if (body->filename)
+    {
+      n = strlen (body->filename);
+      if (filename && len > 0)
+       {
+         len--; /* Space for the null.  */
+         strncpy (filename, body->filename, len)[len] = '\0';
+       }
+    }
+  if (pn)
+    *pn = n;
+  return 0;
+}
+
+
+struct _mu_body_stream
+{
+  struct _mu_stream stream;
+  mu_body_t body;
+};
+
+static int
+_body_get_stream (mu_body_t body, mu_stream_t *pstream, int ref)
+{
+  if (body == NULL)
+    return EINVAL;
+  if (pstream == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+
+  if (body->stream == NULL)
+    {
+      if (body->_get_stream)
+       {
+         int status = body->_get_stream (body, &body->stream);
+         if (status)
+           return status;
+       }
+      else
+       {
+         int status;
+         struct _mu_body_stream *str =
+           (struct _mu_body_stream *)
+           _mu_stream_create (sizeof (*str),
+                              MU_STREAM_RDWR|MU_STREAM_SEEK|_MU_STR_OPEN);
+         if (!str)
+           return ENOMEM;
+         
+         /* Create the temporary file.  */
+         body->filename = mu_tempname (NULL);
+         status = mu_file_stream_create (&body->fstream, 
+                                         body->filename, MU_STREAM_RDWR);
+         if (status != 0)
+           return status;
+         mu_stream_set_buffer (body->fstream, mu_buffer_full, 0);
+         str->stream.ctl = _body_ioctl;
+         str->stream.read = _body_read;
+         str->stream.write = _body_write;
+         str->stream.truncate = _body_truncate;
+         str->stream.size = _body_size;
+         str->stream.seek = _body_seek;
+         str->stream.flush = _body_flush;
+         str->body = body;
+         body->stream = (mu_stream_t) str;
+         /* Override the defaults.  */
+         body->_lines = _body_get_lines;
+         body->_size = _body_get_size;
+       }
+    }
+  
+  if (!ref)
+    {
+      *pstream = body->stream;
+      return 0;
+    }
+  return mu_streamref_create (pstream, body->stream);
+}
+
+int
+mu_body_get_stream (mu_body_t body, mu_stream_t *pstream)
+{
+  /* FIXME: Deprecation warning */
+  return _body_get_stream (body, pstream, 0);
+}
+
+int
+mu_body_get_streamref (mu_body_t body, mu_stream_t *pstream)
+{
+  return _body_get_stream (body, pstream, 1);
+}
+
+int
+mu_body_set_stream (mu_body_t body, mu_stream_t stream, void *owner)
+{
+  if (body == NULL)
+   return EINVAL;
+  if (body->owner != owner)
+    return EACCES;
+  /* make sure we destroy the old one if it is owned by the body */
+  mu_stream_destroy (&body->stream);
+  body->stream = stream;
+  body->flags |= BODY_MODIFIED;
+  return 0;
+}
+
+int
+mu_body_set_get_stream (mu_body_t body,
+                       int (*_getstr) (mu_body_t, mu_stream_t *),
+                       void *owner)
+{
+  if (body == NULL)
+    return EINVAL;
+  if (body->owner != owner)
+    return EACCES;
+  body->_get_stream = _getstr;
+  return 0;
+}
+
+int
+mu_body_set_lines (mu_body_t body, int (*_lines) (mu_body_t, size_t *),
+                  void *owner)
+{
+  if (body == NULL)
+    return EINVAL;
+  if (body->owner != owner)
+    return EACCES;
+  body->_lines = _lines;
+  return 0;
+}
+
+int
+mu_body_lines (mu_body_t body, size_t *plines)
+{
+  if (body == NULL)
+    return EINVAL;
+  if (body->_lines)
+    return body->_lines (body, plines);
+  /* Fall on the stream.  */
+  if (body->stream)
+    return _body_get_lines0 (body->stream, plines);
+  if (plines)
+    *plines = 0;
+  return 0;
+}
+
+int
+mu_body_size (mu_body_t body, size_t *psize)
+{
+  if (body == NULL)
+    return EINVAL;
+  if (body->_size)
+    return body->_size (body, psize);
+  /* Fall on the stream.  */
+  if (body->stream)
+    return _body_get_size0 (body->stream, psize);
+  if (psize)
+    *psize = 0;
+  return 0;
+}
+
+int
+mu_body_set_size (mu_body_t body, int (*_size)(mu_body_t, size_t*) , void 
*owner)
+{
+  if (body == NULL)
+    return EINVAL;
+  if (body->owner != owner)
+    return EACCES;
+  body->_size = _size;
+  return 0;
+}
+
+/* Stub function for the body stream.  */
+
+static int
+_body_seek (mu_stream_t stream, mu_off_t off, mu_off_t *presult)
+{
+  struct _mu_body_stream *str = (struct _mu_body_stream*) stream;
+  mu_body_t body = str->body;
+  return mu_stream_seek (body->fstream, off, MU_SEEK_SET, presult);
+}
+
+static const char *
+_body_error_string (mu_stream_t stream, int rc)
+{
+  /* FIXME: How to know if rc was returned by a body->stream? */
+  return NULL;
+}
+
+static int
+_body_ioctl (mu_stream_t stream, int code, void *ptr)
+{
+  struct _mu_body_stream *str = (struct _mu_body_stream*) stream;
+  mu_body_t body = str->body;
+  return mu_stream_ioctl (body->fstream, code, ptr);
+}
+
+static int
+_body_read (mu_stream_t stream, char *buf, size_t size, size_t *pret)
+{
+  struct _mu_body_stream *str = (struct _mu_body_stream*) stream;
+  mu_body_t body = str->body;
+  return mu_stream_read (body->fstream, buf, size, pret);
+}
+
+static int
+_body_write (mu_stream_t stream, const char *buf, size_t size, size_t *pret)
+{
+  struct _mu_body_stream *str = (struct _mu_body_stream*) stream;
+  mu_body_t body = str->body;
+  return mu_stream_write (body->fstream, buf, size, pret);
+}
+
+static int
+_body_truncate (mu_stream_t stream, mu_off_t n)
+{
+  struct _mu_body_stream *str = (struct _mu_body_stream*) stream;
+  mu_body_t body = str->body;
+  return mu_stream_truncate (body->fstream, n);
+}
+
+static int
+_body_size (mu_stream_t stream, mu_off_t *size)
+{
+  struct _mu_body_stream *str = (struct _mu_body_stream*) stream;
+  mu_body_t body = str->body;
+  return mu_stream_size (body->fstream, size);
+}
+
+static int
+_body_flush (mu_stream_t stream)
+{
+  struct _mu_body_stream *str = (struct _mu_body_stream*) stream;
+  mu_body_t body = str->body;
+  return mu_stream_flush (body->fstream);
+}
+
+/* Default function for the body.  */
+static int
+_body_get_lines (mu_body_t body, size_t *plines)
+{
+  return _body_get_lines0 (body->fstream, plines);
+}
+
+static int
+_body_get_size (mu_body_t body, size_t *psize)
+{
+  return _body_get_size0 (body->fstream, psize);
+}
+
+static int
+_body_get_size0 (mu_stream_t stream, size_t *psize)
+{
+  mu_off_t off = 0;
+  int status = mu_stream_size (stream, &off);
+  if (psize)
+    *psize = off;
+  return status;
+}
+
+static int
+_body_get_lines0 (mu_stream_t stream, size_t *plines)
+{
+  int status =  mu_stream_flush (stream);
+  size_t lines = 0;
+  
+  if (status == 0)
+    {
+      char buf[128];
+      size_t n = 0;
+
+      status = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
+      if (status)
+       return status;
+      while ((status = mu_stream_readline (stream, buf, sizeof buf,
+                                          &n)) == 0 && n > 0)
+       {
+         if (buf[n - 1] == '\n')
+           lines++;
+       }
+    }
+  if (plines)
+    *plines = lines;
+  return status;
+}
+
+
diff --git a/libmailutils/mailbox/envelope.c b/libmailutils/mailbox/envelope.c
new file mode 100644
index 0000000..9546885
--- /dev/null
+++ b/libmailutils/mailbox/envelope.c
@@ -0,0 +1,180 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2004, 2005, 2007, 2010 Free Software
+   Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/errno.h>
+#include <mailutils/mutil.h>
+#include <mailutils/sys/envelope.h>
+
+int
+mu_envelope_create (mu_envelope_t *penvelope, void *owner)
+{
+  mu_envelope_t envelope;
+  if (penvelope == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  envelope = calloc (1, sizeof (*envelope));
+  if (envelope == NULL)
+    return ENOMEM;
+  envelope->owner = owner;
+  *penvelope = envelope;
+  return 0;
+}
+
+void
+mu_envelope_destroy (mu_envelope_t *penvelope, void *owner)
+{
+  if (penvelope && *penvelope)
+    {
+      mu_envelope_t envelope = *penvelope;
+      if (envelope->owner == owner)
+       {
+         if (envelope->_destroy)
+           envelope->_destroy (envelope);
+         free (envelope->date);
+         free (envelope->sender);
+         free (envelope);
+       }
+      *penvelope = NULL;
+    }
+}
+
+void *
+mu_envelope_get_owner (mu_envelope_t envelope)
+{
+  return (envelope) ? envelope->owner : NULL;
+}
+
+int
+mu_envelope_set_sender (mu_envelope_t envelope,
+                       int (*_sender) (mu_envelope_t, char *, size_t,
+                                       size_t*),
+                       void *owner)
+{
+  if (envelope == NULL)
+    return EINVAL;
+  if (envelope->owner != owner)
+    return EACCES;
+  envelope->_get_sender = _sender;
+  return 0;
+}
+
+int
+mu_envelope_set_date (mu_envelope_t envelope,
+                     int (*_date) (mu_envelope_t, char *, size_t , size_t *),
+                     void *owner)
+{
+  if (envelope == NULL)
+    return EINVAL;
+  if (envelope->owner != owner)
+    return EACCES;
+  envelope->_get_date = _date;
+  return 0;
+}
+
+
+/* General accessors: */
+#define AC2(a,b) a ## b
+#define AC4(a,b,c,d) a ## b ## c ## d
+#define ACCESSOR(action,field) AC4(mu_envelope_,action,_,field)
+
+#define DECL_SGET(field)                                                 \
+int                                                                      \
+ACCESSOR(sget,field) (mu_envelope_t env, char const **sptr)               \
+{                                                                        \
+  if (env == NULL)                                                       \
+    return EINVAL;                                                       \
+  if (!env->field)                                                       \
+    {                                                                     \
+      if (env->AC2(_get_,field))                                          \
+       {                                                                 \
+         size_t n;                                                       \
+         char *buf;                                                      \
+          int status;                                                     \
+                                                                         \
+         status = env->AC2(_get_,field) (env, NULL, 0, &n);              \
+         if (status)                                                     \
+           return status;                                                \
+                                                                         \
+         buf = malloc (n + 1);                                           \
+         if (!buf)                                                       \
+           return ENOMEM;                                                \
+                                                                         \
+         status = env->AC2(_get_,field) (env, buf, n + 1, NULL);         \
+         if (status)                                                     \
+            return status;                                               \
+                                                                         \
+          env->field = buf;                                               \
+       }                                                                 \
+      else                                                               \
+        return MU_ERR_NOENT;                                             \
+    }                                                                    \
+  *sptr = env->field;                                                    \
+  return 0;                                                              \
+}
+
+#define DECL_GET(field)                                                        
  \
+int                                                                      \
+ACCESSOR(get,field) (mu_envelope_t env, char *buf, size_t len, size_t *n) \
+{                                                                        \
+  size_t i;                                                              \
+  const char *str;                                                       \
+  int status = ACCESSOR(sget, field) (env, &str);                        \
+                                                                         \
+  if (status)                                                            \
+    return status;                                                       \
+                                                                         \
+  i = mu_cpystr (buf, str, len);                                         \
+  if (n)                                                                 \
+    *n = i;                                                              \
+  return 0;                                                              \
+}
+
+#define DECL_AGET(field)                                                 \
+int                                                                      \
+ACCESSOR(aget, field) (mu_envelope_t env, char **buf)                    \
+{                                                                        \
+  const char *str;                                                       \
+  int status = ACCESSOR(sget, field) (env, &str);                        \
+                                                                         \
+  if (status)                                                            \
+    return status;                                                       \
+                                                                         \
+  if (str)                                                               \
+    {                                                                    \
+      *buf = strdup (str);                                               \
+      if (!*buf)                                                         \
+       status = ENOMEM;                                                  \
+    }                                                                    \
+  else                                                                   \
+    *buf = NULL;                                                         \
+  return status;                                                         \
+}
+
+#define DECL_ACCESSORS(field)                                            \
+DECL_SGET(field)                                                         \
+DECL_GET(field)                                                                
  \
+DECL_AGET(field)
+
+DECL_ACCESSORS(sender)
+DECL_ACCESSORS(date)     
+
diff --git a/libmailutils/mailbox/folder.c b/libmailutils/mailbox/folder.c
new file mode 100644
index 0000000..2b85601
--- /dev/null
+++ b/libmailutils/mailbox/folder.c
@@ -0,0 +1,510 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2006, 2007, 2008, 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/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fnmatch.h>
+
+#include <mailutils/auth.h>
+#include <mailutils/debug.h>
+#include <mailutils/iterator.h>
+#include <mailutils/list.h>
+#include <mailutils/monitor.h>
+#include <mailutils/observer.h>
+#include <mailutils/registrar.h>
+#include <mailutils/stream.h>
+#include <mailutils/url.h>
+#include <mailutils/errno.h>
+
+#include <mailutils/sys/folder.h>
+
+/* Internal folder list.  */
+static mu_list_t known_folder_list;
+static int is_known_folder (mu_url_t, mu_folder_t *);
+
+/* Static folder lock.  */
+static struct mu_monitor folder_lock = MU_MONITOR_INITIALIZER;
+
+int
+mu_folder_match (const char *name, void *pattern, int flags)
+{
+  return fnmatch (pattern, name[0] == '/' ? name + 1 : name, flags);
+}
+
+/* A folder could be remote (IMAP), or local(a spool directory) like $HOME/Mail
+   etc ..  We maintain a list of known folders to avoid creating multiple
+   folders for the same URL.  So, when mu_folder_create is called we check if
+   we already have a folder for that URL and return it, otherwise we create a
+   new one.  Downsides: the scheme to detect the same URL is very weak, and
+   there could be cases where you'll want a different folder for the same URL,
+   there is not easy way to do this.  */
+int
+mu_folder_create_from_record (mu_folder_t *pfolder, mu_url_t url,
+                             mu_record_t record)
+{
+  if (!pfolder)
+    return MU_ERR_OUT_PTR_NULL;
+
+  if (record || 
+      /* Look in the registrar list(iterator), for a possible concrete mailbox
+        implementation that could match the URL.  */
+      mu_registrar_lookup_url (url, MU_FOLDER_ATTRIBUTE_DIRECTORY, &record,
+                              NULL) == 0)
+    {
+      int (*f_init) (mu_folder_t) = NULL;
+      
+      mu_record_get_folder (record, &f_init);
+      if (f_init)
+        {
+         int status;
+         mu_folder_t folder;
+         int (*u_init) (mu_url_t) = NULL;
+
+         mu_record_get_url (record, &u_init);
+         if (u_init)
+           {
+             status = u_init (url);
+             if (status)
+               return status;
+           }
+         
+         mu_monitor_wrlock (&folder_lock);
+
+         /* Check if we already have the same URL folder.  */
+         if (is_known_folder (url, &folder))
+           {
+             folder->ref++;
+             *pfolder = folder;
+             mu_url_destroy (&url); /* FIXME: Hmm */
+             mu_monitor_unlock (&folder_lock);
+             return  0;
+           }
+         else
+           mu_monitor_unlock (&folder_lock);
+         
+         /* Create a new folder.  */
+
+         /* Allocate memory for the folder.  */
+         folder = calloc (1, sizeof (*folder));
+         if (folder != NULL)
+           {
+             folder->url = url;
+             /* Initialize the internal foilder lock, now so the
+                concrete folder could use it.  */
+             status = mu_monitor_create (&folder->monitor, 0, folder);
+             if (status == 0)
+               {
+                 /* Create the concrete folder type.  */
+                 status = f_init (folder);
+                 if (status == 0)
+                   {
+                     if (!folder->_match)
+                       folder->_match = mu_folder_match;
+                     *pfolder = folder;
+                     folder->ref++;
+                     /* Put on the internal list of known folders.  */
+                     if (known_folder_list == NULL)
+                       mu_list_create (&known_folder_list);
+                     mu_list_append (known_folder_list, folder);
+                   }
+               }
+             /* Something went wrong, destroy the object. */
+             if (status)
+               {
+                 if (folder->monitor)
+                   mu_monitor_destroy (&folder->monitor, folder);
+                 free (folder);
+               }
+           }
+         return status;
+       }
+    }
+
+    return MU_ERR_NOENT;
+}
+
+int
+mu_folder_create (mu_folder_t *pfolder, const char *name)
+{
+  int rc;
+  mu_url_t url;
+  
+  rc = mu_url_create (&url, name);
+  if (rc)
+    return rc;
+  rc = mu_url_parse (url);
+  if (rc == 0)
+    rc = mu_folder_create_from_record (pfolder, url, NULL);
+  if (rc)
+    mu_url_destroy (&url);
+  return rc;
+}
+
+/* The folder is destroy if it is the last reference.  */
+void
+mu_folder_destroy (mu_folder_t *pfolder)
+{
+  if (pfolder && *pfolder)
+    {
+      mu_folder_t folder = *pfolder;
+      int destroy_lock = 0;
+      mu_monitor_t monitor = folder->monitor;
+
+      mu_monitor_wrlock (monitor);
+
+      /* Check if this the last reference for this folder.  If yes removed
+         it from the list.  */
+      mu_monitor_wrlock (&folder_lock);
+      folder->ref--;
+      /* Remove the folder from the list of known folder.  */
+      if (folder->ref <= 0)
+       mu_list_remove (known_folder_list, folder);
+      /* If the list is empty we can safely remove it.  */
+      if (mu_list_is_empty (known_folder_list))
+       mu_list_destroy (&known_folder_list);
+
+      mu_monitor_unlock (&folder_lock);
+
+      if (folder->ref <= 0)
+       {
+         mu_monitor_unlock (monitor);
+         destroy_lock = 1;
+         /* Notify the observers.  */
+         if (folder->observable)
+           {
+             mu_observable_notify (folder->observable, MU_EVT_FOLDER_DESTROY,
+                                   folder);
+             mu_observable_destroy (&folder->observable, folder);
+           }
+         if (folder->_destroy)
+           folder->_destroy (folder);
+         mu_monitor_wrlock (monitor);
+         if (folder->authority)
+           mu_authority_destroy (&folder->authority, folder);
+         if (folder->stream)
+           mu_stream_destroy (&folder->stream);
+         if (folder->url)
+           mu_url_destroy (&folder->url);
+         free (folder);
+       }
+      mu_monitor_unlock (monitor);
+      if (destroy_lock)
+       mu_monitor_destroy (&monitor, folder);
+      *pfolder = NULL;
+    }
+}
+
+/* Cover functions.  */
+int
+mu_folder_open (mu_folder_t folder, int flags)
+{
+  if (folder == NULL || folder->_open == NULL)
+    return ENOSYS;
+  return folder->_open (folder, flags);
+}
+
+int
+mu_folder_close (mu_folder_t folder)
+{
+  if (folder == NULL || folder->_close == NULL)
+    return ENOSYS;
+  return folder->_close (folder);
+}
+
+int
+mu_folder_set_stream (mu_folder_t folder, mu_stream_t stream)
+{
+  if (folder == NULL)
+    return EINVAL;
+  if (folder->stream)
+    mu_stream_destroy (&folder->stream);
+  folder->stream = stream;
+  return 0;
+}
+
+int
+mu_folder_get_stream (mu_folder_t folder, mu_stream_t *pstream)
+{
+  /* FIXME: Deprecation warning */
+  if (folder == NULL)
+    return EINVAL;
+  if (pstream == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  *pstream = folder->stream;
+  return 0;
+}
+
+int
+mu_folder_get_streamref (mu_folder_t folder, mu_stream_t *pstream)
+{
+  if (folder == NULL)
+    return EINVAL;
+  if (pstream == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  return mu_streamref_create (pstream, folder->stream);
+}
+
+int
+mu_folder_set_authority (mu_folder_t folder, mu_authority_t authority)
+{
+  if (folder == NULL)
+    return EINVAL;
+  if (folder->authority)
+    mu_authority_destroy (&folder->authority, folder);
+  folder->authority = authority;
+  return 0;
+}
+
+int
+mu_folder_get_authority (mu_folder_t folder, mu_authority_t *pauthority)
+{
+  if (folder == NULL)
+    return EINVAL;
+  if (pauthority == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  *pauthority = folder->authority;
+  return 0;
+}
+
+int
+mu_folder_get_observable (mu_folder_t folder, mu_observable_t *pobservable)
+{
+  if (folder == NULL)
+    return EINVAL;
+  if (pobservable == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+
+  if (folder->observable == NULL)
+    {
+      int status = mu_observable_create (&folder->observable, folder);
+      if (status != 0)
+        return status;
+    }
+  *pobservable = folder->observable;
+  return 0;
+}
+
+int
+mu_folder_set_match (mu_folder_t folder, mu_folder_match_fp pmatch)
+{
+  if (folder == NULL)
+    return EINVAL;
+  folder->_match = pmatch;
+  return 0;
+}
+
+int
+mu_folder_get_match (mu_folder_t folder, mu_folder_match_fp *pmatch)
+{
+  if (folder == NULL)
+    return EINVAL;
+  if (pmatch == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  *pmatch = folder->_match;
+  return 0;
+}
+
+int
+mu_folder_has_debug (mu_folder_t folder)
+{
+  if (folder == NULL)
+    return 0;
+
+  return folder->debug ? 1 : 0;
+}
+
+int
+mu_folder_set_debug (mu_folder_t folder, mu_debug_t debug)
+{
+  if (folder == NULL)
+    return EINVAL;
+  if (folder->debug)
+    mu_debug_destroy (&folder->debug, folder);
+  folder->debug = debug;
+  return 0;
+}
+
+int
+mu_folder_get_debug (mu_folder_t folder, mu_debug_t *pdebug)
+{
+  if (folder == NULL)
+    return EINVAL;
+  if (pdebug == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  if (folder->debug == NULL)
+    {
+      int status = mu_debug_create (&folder->debug, folder);
+      if (status != 0)
+        return status;
+    }
+  *pdebug = folder->debug;
+  return 0;
+}
+
+void
+mu_list_response_free (void *data)
+{
+  struct mu_list_response *f = data;
+  free (f->name);
+  free (f);
+}
+
+int
+mu_folder_list (mu_folder_t folder, const char *dirname, void *pattern,
+               size_t max_level,
+               mu_list_t *pflist)
+{
+  return mu_folder_enumerate (folder, dirname, pattern, 0, max_level,
+                             pflist, NULL, NULL);
+}
+
+int
+mu_folder_enumerate (mu_folder_t folder, const char *name,
+                    void *pattern, int flags,
+                    size_t max_level,
+                    mu_list_t *pflist,
+                    mu_folder_enumerate_fp enumfun, void *enumdata)
+{
+  int status;
+  if (folder == NULL || folder->_list == NULL)
+    return EINVAL;
+  else
+    {
+      mu_list_t list = NULL;
+      
+      if (pflist)
+       {
+         status = mu_list_create (&list);
+         if (status)
+           return status;
+         *pflist = list;
+         mu_list_set_destroy_item (list, mu_list_response_free);
+       }
+      else if (!enumfun)
+       return EINVAL;
+      
+      status = folder->_list (folder, name, pattern, flags, max_level,
+                             list, enumfun, enumdata);
+      if (status)
+       mu_list_destroy (pflist);
+    }
+  return status;
+}
+
+int
+mu_folder_lsub (mu_folder_t folder, const char *dirname, const char *basename,
+               mu_list_t *pflist)
+{
+  int status;
+  
+  if (folder == NULL || folder->_lsub == NULL)
+    return ENOSYS;
+  else
+    {
+      status = mu_list_create (pflist);
+      if (status)
+       return status;
+      mu_list_set_destroy_item (*pflist, mu_list_response_free);
+      status = folder->_lsub (folder, dirname, basename, *pflist);
+    }
+  return status;
+}
+
+int
+mu_folder_subscribe (mu_folder_t folder, const char *name)
+{
+  if (folder == NULL || folder->_subscribe == NULL)
+    return EINVAL;
+  return folder->_subscribe (folder, name);
+}
+
+int
+mu_folder_unsubscribe (mu_folder_t folder, const char *name)
+{
+  if (folder == NULL || folder->_unsubscribe == NULL)
+    return EINVAL;
+  return folder->_unsubscribe (folder, name);
+}
+
+int
+mu_folder_delete (mu_folder_t folder, const char *name)
+{
+  if (folder == NULL || folder->_delete == NULL)
+    return ENOSYS;
+  return folder->_delete (folder, name);
+}
+
+int
+mu_folder_rename (mu_folder_t folder, const char *oldname, const char *newname)
+{
+  if (folder == NULL || folder->_rename == NULL)
+    return ENOSYS;
+  return folder->_rename (folder, oldname, newname);
+}
+
+int
+mu_folder_get_url (mu_folder_t folder, mu_url_t *purl)
+{
+  if (folder == NULL)
+    return EINVAL;
+  if (purl == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  *purl = folder->url;
+  return 0;
+}
+
+static int
+is_known_folder (mu_url_t url, mu_folder_t *pfolder)
+{
+  int ret = 0;
+  mu_folder_t folder = NULL;
+  mu_iterator_t iterator;
+
+  if (url == NULL || pfolder == NULL)
+    return ret;
+
+  if (mu_list_get_iterator (known_folder_list, &iterator) != 0)
+    return ret;
+
+  for (mu_iterator_first (iterator); !mu_iterator_is_done (iterator);
+       mu_iterator_next (iterator))
+    {
+      mu_iterator_current (iterator, (void **)&folder);
+      /* Check if the same URL type.  */
+      if (folder && folder->url
+         && mu_url_is_same_scheme (url, folder->url)
+         && mu_url_is_same_user (url, folder->url)
+         && mu_url_is_same_host (url, folder->url)
+         && mu_url_is_same_path (url, folder->url) 
+         && mu_url_is_same_port (url, folder->url))
+       {
+         ret = 1;
+         break;
+       }
+    }
+  if (ret)
+    *pfolder = folder;
+  mu_iterator_destroy (&iterator);
+  return ret;
+}
+
diff --git a/libmailutils/mailbox/hdritr.c b/libmailutils/mailbox/hdritr.c
new file mode 100644
index 0000000..1efd18b
--- /dev/null
+++ b/libmailutils/mailbox/hdritr.c
@@ -0,0 +1,161 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2008, 2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+/* Mail header iterators. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+
+#include <mailutils/sys/header.h>
+#include <mailutils/errno.h>
+
+struct header_iterator
+{
+  mu_header_t header;
+  size_t index;
+};
+
+static int
+hdr_first (void *owner)
+{
+  struct header_iterator *itr = owner;
+  itr->index = 1;
+  return 0;
+}
+
+static int
+hdr_next (void *owner)
+{
+  struct header_iterator *itr = owner;
+  itr->index++;
+  return 0;
+}
+
+static int
+hdr_getitem (void *owner, void **pret, const void **pkey)
+{
+  struct header_iterator *itr = owner;
+  int rc;
+  size_t count;
+
+  rc = mu_header_get_field_count (itr->header, &count);
+  if (rc)
+    return rc;
+  if (itr->index > count)
+    return MU_ERR_NOENT;
+  
+  rc = mu_header_sget_field_name (itr->header, itr->index,
+                                 (const char**) pkey);
+  if (rc == 0)
+    {
+      if (pkey)
+       rc = mu_header_sget_field_value (itr->header, itr->index,
+                                        (const char**) pret);
+    }
+  return rc;
+}
+
+static int
+hdr_finished_p (void *owner)
+{
+  struct header_iterator *itr = owner;
+  size_t count;
+
+  if (mu_header_get_field_count (itr->header, &count))
+    return 1;
+  return itr->index > count;
+}
+
+static int
+hdr_destroy (mu_iterator_t iterator, void *data)
+{
+  struct header_iterator *itr = data;
+  mu_iterator_detach (&itr->header->itr, iterator);
+  free (data);
+  return 0;
+}
+
+static int
+hdr_curitem_p (void *owner, void *item)
+{
+  void *ptr;
+
+  if (hdr_getitem (owner, &ptr, NULL))
+    return 0;
+  return ptr == item;
+}
+
+static int
+hdr_data_dup (void **ptr, void *owner)
+{
+  struct header_iterator *itr = owner;
+
+  *ptr = malloc (sizeof (struct header_iterator));
+  if (*ptr == NULL)
+    return ENOMEM;
+  memcpy (*ptr, owner, sizeof (struct header_iterator));
+  mu_iterator_attach (&itr->header->itr, *ptr);
+  return 0;
+}
+
+int
+mu_header_get_iterator (mu_header_t hdr, mu_iterator_t *piterator)
+{
+  mu_iterator_t iterator;
+  int status;
+  struct header_iterator *itr;
+
+  if (!hdr)
+    return EINVAL;
+
+  itr = calloc (1, sizeof *itr);
+  if (!itr)
+    return ENOMEM;
+  itr->header = hdr;
+  itr->index = 1;
+
+  status = mu_iterator_create (&iterator, itr);
+  if (status)
+    {
+      free (itr);
+      return status;
+    }
+
+  mu_iterator_set_first (iterator, hdr_first);
+  mu_iterator_set_next (iterator, hdr_next);
+  mu_iterator_set_getitem (iterator, hdr_getitem);
+  mu_iterator_set_finished_p (iterator, hdr_finished_p);
+  mu_iterator_set_curitem_p (iterator, hdr_curitem_p);
+  mu_iterator_set_destroy (iterator, hdr_destroy);
+  mu_iterator_set_dup (iterator, hdr_data_dup);
+
+  mu_iterator_attach (&hdr->itr, iterator);
+
+  *piterator = iterator;
+  return 0;
+}
+
+
+
+
+
+
+
+
diff --git a/libmailutils/mailbox/header.c b/libmailutils/mailbox/header.c
new file mode 100644
index 0000000..6de32d2
--- /dev/null
+++ b/libmailutils/mailbox/header.c
@@ -0,0 +1,1221 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2008, 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/>. */
+
+/*  This all header business needs a good rewrite.
+ *          -- Alain Magloire, 2000-07-03 (rev. 1.21)
+ *
+ *  It's the job that's never started as takes longest to finish.
+ *          -- Hamfast Gamgee, some time in the Third Age
+ *
+ *  It took almost 7 years to gather the courage to start the job,
+ *  and only one day to finish it.
+ *          -- Sergey Poznyakoff, 2007-06-24
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/stream.h>
+#include <mailutils/address.h>
+#include <mailutils/mutil.h>
+#include <mailutils/errno.h>
+#include <mailutils/cstr.h>
+#include <mailutils/sys/header_stream.h>
+#include <mailutils/sys/header.h>
+
+#define HEADER_MODIFIED   0x01
+#define HEADER_INVALIDATE 0x02
+
+#define HEADER_SET_MODIFIED(h) \
+  ((h)->flags |= (HEADER_MODIFIED|HEADER_INVALIDATE))
+
+
+/* mu_hdrent manipulation */
+
+#define MU_HDRENT_NAME(hp,ep) ((hp)->spool + (ep)->fn)
+#define MU_HDRENT_VALUE(hp,ep) ((hp)->spool + (ep)->fv)
+#define MU_STR_SIZE(nlen,vlen) ((nlen) + 2 + (vlen) + 1)
+
+static struct mu_hdrent *
+mu_hdrent_nth (struct _mu_header *hdr, int n)
+{
+  struct mu_hdrent *p;
+  for (p = hdr->head; p; p = p->next)
+    if (n-- == 1)
+      break;
+  return p;
+}
+
+static struct mu_hdrent *
+mu_hdrent_find (struct _mu_header *hdr, const char *name, int pos)
+{
+  struct mu_hdrent *p;
+
+  if (pos > 0)
+    {
+      for (p = hdr->head; p; p = p->next)
+       if (mu_c_strcasecmp (MU_HDRENT_NAME (hdr,p), name) == 0 && pos-- == 1)
+         break;
+    }
+  else if (pos < 0)
+    {
+      for (p = hdr->tail; p; p = p->prev)
+       if (mu_c_strcasecmp (MU_HDRENT_NAME (hdr,p), name) == 0 && ++pos == 0)
+         break;
+    }
+  else
+    p = NULL;
+  return p;
+}
+
+static int
+mu_hdrent_find_stream_pos (struct _mu_header *hdr, mu_off_t pos,
+                          struct mu_hdrent **pent, size_t *poff)
+{
+  mu_off_t x;
+  struct mu_hdrent *p;
+
+  for (p = hdr->head, x = 0; p; p = p->next)
+    {
+      size_t strsize = MU_STR_SIZE (p->nlen, p->vlen);
+      if (x <= pos && pos < x + strsize)
+       {
+         *poff = pos - x;
+         *pent = p;
+         return 0;
+       }
+      x += strsize;
+    }
+  if (x == pos && hdr->tail)
+    {
+      /* To supply the trailing '\n' */
+      p = hdr->tail;
+      *pent = p;
+      *poff = MU_STR_SIZE (p->nlen, p->vlen) - 1;
+      return 0;
+    }
+  return 1;
+}
+     
+static void
+mu_hdrent_count (struct _mu_header *hdr, size_t *pcount, size_t *psize,
+                size_t *plines)
+{
+  if (hdr->flags & HEADER_INVALIDATE)
+    {
+      size_t size = 0;
+      size_t count = 0;
+      size_t lines = 0;
+      struct mu_hdrent *p;
+      for (p = hdr->head; p; p = p->next)
+       {
+         count++;
+         size += MU_STR_SIZE (p->nlen, p->vlen);
+         lines += p->nlines;
+       }
+
+      hdr->numhdr = count;
+      hdr->numlines = lines;
+      hdr->size = size;
+      hdr->flags &= ~HEADER_INVALIDATE;
+    }
+      
+  *pcount = hdr->numhdr;
+  *psize = hdr->size;
+  *plines = hdr->numlines;
+}
+
+static void
+mu_hdrent_remove (struct _mu_header *hdr, struct mu_hdrent *ent)
+{
+  struct mu_hdrent *p = ent->prev;
+  if (p)
+    p->next = ent->next;
+  else
+    hdr->head = ent->next;
+
+  p = ent->next;
+  if (p)
+    p->prev = ent->prev;
+  else
+    hdr->tail = ent->prev;
+}
+
+static void
+mu_hdrent_prepend (struct _mu_header *hdr, struct mu_hdrent *ent)
+{
+  struct mu_hdrent *p = hdr->head;
+  ent->prev = NULL;
+  ent->next = p;
+  if (p)
+    p->prev = ent;
+  else
+    hdr->tail = ent;
+  hdr->head = ent;
+}
+
+static void
+mu_hdrent_append (struct _mu_header *hdr, struct mu_hdrent *ent)
+{
+  struct mu_hdrent *p = hdr->tail;
+  ent->next = NULL;
+  ent->prev = p;
+  if (p)
+    p->next = ent;
+  else
+    hdr->head = ent;
+  hdr->tail = ent;
+}
+
+static int
+mu_hdrent_insert (struct _mu_header *hdr, struct mu_hdrent *ent,
+                 const char *name, int pos, int before)
+{
+  struct mu_hdrent *p;
+  struct mu_hdrent *ref = mu_hdrent_find (hdr, name, pos);
+  if (!ref)
+    return MU_ERR_NOENT;
+
+  if (before)
+    {
+      ref = ref->prev;
+      if (!ref)
+       {
+         mu_hdrent_prepend (hdr, ent);
+         return 0;
+       }
+    }
+
+  p = ref->next;
+  if (!p)
+    {
+      mu_hdrent_append (hdr, ent);
+      return 0;
+    }
+
+  ent->next = p;
+  p->prev = ent;
+  ent->prev = ref;
+  ref->next = ent;
+  
+  return 0;
+}
+
+#define SPOOLBLKSIZ 1024
+
+static struct mu_hdrent *
+mu_hdrent_create (struct _mu_header *ph,
+                 struct mu_hdrent *ent,
+                 const char *name, size_t nsize,
+                 const char *value, size_t vsize)
+{
+  size_t strsize;
+  size_t sizeleft;
+  const char *p;
+  
+  if (!ent)
+    {
+      ent = calloc (1, sizeof (*ent));
+      if (!ent)
+       return NULL;
+    }
+  
+  strsize = MU_STR_SIZE (nsize, vsize);
+  sizeleft = ph->spool_size - ph->spool_used;
+
+  /* Ensure there is enough space in spool */
+  if (sizeleft < strsize)
+    {
+      char *newp;
+      size_t delta = (strsize - sizeleft + SPOOLBLKSIZ - 1) / SPOOLBLKSIZ;
+      delta *= SPOOLBLKSIZ;
+      newp = realloc (ph->spool, ph->spool_size + delta);
+      if (!newp)
+       return 0;
+      ph->spool = newp;
+      ph->spool_size += delta;
+    }
+
+  /* Copy header name */
+  ent->fn = ph->spool_used;
+  ent->nlen = nsize;
+  memcpy (ph->spool + ph->spool_used, name, nsize);
+  ph->spool_used += nsize;
+  ph->spool[ph->spool_used++] = 0;
+  ph->spool[ph->spool_used++] = ' ';
+
+  /* Copy header value */
+  ent->fv = ph->spool_used;
+  ent->vlen = vsize;
+  memcpy (ph->spool + ph->spool_used, value, vsize);
+  ph->spool_used += vsize;
+  ph->spool[ph->spool_used++] = 0;
+  
+  ent->nlines = 1;
+  for (p = value; p < value + vsize; p++)
+    if (*p == '\n')
+      ent->nlines++;
+  
+  return ent;
+}
+
+static void
+mu_hdrent_free_list (struct _mu_header *hdr)
+{
+  struct mu_hdrent *p;
+  for (p = hdr->head; p; )
+    {
+      struct mu_hdrent *next = p->next;
+      free (p);
+      p = next;
+    }
+  hdr->head = hdr->tail = NULL;
+  hdr->spool_used = 0;
+}
+  
+
+
+#define ISLWSP(c) (((c) == ' ' || (c) == '\t'))
+
+/* Parsing is done in a rather simple fashion, meaning we just consider an
+   entry to be a field-name an a field-value.  So they maybe duplicate of
+   field-name like "Received" they are just put in the array, see _get_value()
+   on how to handle the case. in the case of error .i.e a bad header construct
+   we do a full stop and return what we have so far.  */
+
+static int
+header_parse (mu_header_t header, const char *blurb, int len)
+{
+  const char *header_end;
+  const char *header_start;
+  const char *header_start2;
+  
+  /* Nothing to parse.  */
+  if (blurb == NULL)
+    return 0;
+
+  header->flags |= HEADER_INVALIDATE;
+  mu_hdrent_free_list (header);
+
+  /* Get a header, a header is:
+     field-name LWSP ':'
+       LWSP field-value '\r' '\n'
+       *[ (' ' | '\t') field-value '\r' '\n' ]
+  */
+  /* First loop goes through the blurb */
+  for (header_start = blurb; len > 0; header_start = ++header_end)
+    {
+      const char *fn, *fn_end, *fv, *fv_end;
+      struct mu_hdrent *ent;
+
+      if (header_start[0] == ' '
+         || header_start[0] == '\t'
+         || header_start[0] == '\n')
+       break;
+
+      /* Second loop extract one header field. */
+      for (header_start2 = header_start; len; header_start2 = ++header_end)
+       {
+         header_end = memchr (header_start2, '\n', len);
+         if (header_end == NULL)
+           {
+             header_end = header_start2 + len;
+             len = 0;
+             break;
+           }
+         else
+           {
+             len -= (header_end - header_start2 + 1);
+             if (!len
+                 || (header_end[1] != ' '
+                     && header_end[1] != '\t'))
+               break; /* New header break the inner for. */
+           }
+         /* *header_end = ' ';  smash LF ? NO */
+       }
+
+      /* Now save the header in the data structure.  */
+
+      /* Treats unix "From " specially.  FIXME: Should we? */
+      if ((header_end - header_start >= 5)
+         && strncmp (header_start, "From ", 5) == 0)
+       {
+         fn = header_start;
+         fn_end = header_start + 5;
+         fv = header_start + 5;
+         fv_end = header_end;
+       }
+      else /* Break the header in key: value */
+       {
+         char *colon = memchr (header_start, ':', header_end - header_start);
+
+         /* Houston we have a problem.  */
+         if (colon == NULL)
+           break; /* FIXME: Disregard the rest and bailout.  */
+
+         fn = header_start;
+         fn_end = colon;
+         /* Shrink any LWSP after the field name -- CRITICAL for 
+            later name comparisons to work correctly! */
+         while (ISLWSP (fn_end[-1]))
+           fn_end--;
+
+         fv = colon + 1;
+         fv_end = header_end;
+
+         /* Skip any LWSP before the field value -- unnecessary, but
+            might make some field values look a little tidier. */
+         while (ISLWSP (fv[0]))
+           fv++;
+       }
+
+      /* Register this header */
+      ent = mu_hdrent_create (header, NULL, fn, fn_end - fn, fv, fv_end - fv);
+      if (!ent)
+       return ENOMEM;
+      mu_hdrent_append (header, ent);
+    } /* for (header_start ...) */
+
+  return 0;
+}
+
+
+static int 
+mu_header_fill (mu_header_t header)
+{
+  int status;
+  size_t blurb_len = 0;
+  char *blurb = NULL;
+  
+  if (header->spool_used)
+    return 0;
+  
+  if (header->_fill == NULL)
+    return 0; /* FIXME: Really? */
+
+  /* Bring in the entire header.  */
+  status = header->_fill (header->data, &blurb, &blurb_len);
+  if (status)
+    return status;
+  status = header_parse (header, blurb, blurb_len);
+  free (blurb);
+  return status;
+}
+
+
+
+int
+mu_header_create (mu_header_t *ph, const char *blurb, size_t len)
+{
+  mu_header_t header;
+  int status = 0;
+
+  header = calloc (1, sizeof (*header));
+  if (header == NULL)
+    return ENOMEM;
+  
+  status = header_parse (header, blurb, len);
+
+  *ph = header;
+  return status;
+}
+
+void
+mu_header_destroy (mu_header_t *ph)
+{
+  if (ph && *ph)
+    {  
+      mu_header_t header = *ph;
+
+      mu_stream_destroy (&header->stream);
+      mu_hdrent_free_list (header);
+      free (header->spool);
+      free (header);
+      *ph = NULL;
+    }
+}
+
+
+int
+mu_header_set_value (mu_header_t header, const char *fn, const char *fv,
+                    int replace)
+{
+  int status;
+  struct mu_hdrent *ent = NULL;
+  
+  if (header == NULL || fn == NULL)
+    return EINVAL;
+
+  status = mu_header_fill (header);
+  if (status)
+    return status;
+  
+  /* An fv of NULL means delete the field, but only do it if replace
+     was also set to true! */
+  if (fv == NULL && !replace)
+    return EINVAL;
+
+  if (replace)
+    {
+      ent = mu_hdrent_find (header, fn, 1);
+      if (ent)
+       {
+         if (fv == NULL)
+           {
+             /* Delete the header */
+             mu_hdrent_remove (header, ent);
+             free (ent);
+             return 0;
+           }
+         mu_hdrent_create (header, ent, fn, strlen (fn), fv, strlen (fv));
+         HEADER_SET_MODIFIED (header);
+         return 0;
+       }
+      else if (fv == NULL)
+       return 0;
+    }
+
+  ent = mu_hdrent_create (header, NULL,
+                         fn, strlen (fn), fv, strlen (fv));
+  if (!ent)
+    return ENOMEM;
+  mu_hdrent_prepend (header, ent);
+  HEADER_SET_MODIFIED (header);
+  return 0;
+}
+
+int
+mu_header_remove (mu_header_t header, const char *fn, int n)
+{
+  int status;
+  struct mu_hdrent *ent;
+  
+  if (header == NULL || fn == NULL)
+    return EINVAL;
+
+  status = mu_header_fill (header);
+  if (status)
+    return status;
+
+  ent = mu_hdrent_find (header, fn, n);
+  if (!ent)
+    return MU_ERR_NOENT;
+
+  mu_hdrent_remove (header, ent);
+  HEADER_SET_MODIFIED (header);
+  free (ent);
+  return 0;
+}
+
+int
+mu_header_append (mu_header_t header, const char *fn, const char *fv)
+{
+  int status;
+  struct mu_hdrent *ent;
+
+  if (header == NULL || fn == NULL || fv == NULL)
+    return EINVAL;
+
+  status = mu_header_fill (header);
+  if (status)
+    return status;
+
+  ent = mu_hdrent_create (header, NULL, fn, strlen (fn), fv, strlen (fv));
+  if (!ent)
+    return ENOMEM;
+  mu_hdrent_append (header, ent);
+  HEADER_SET_MODIFIED (header);
+  return 0;
+}
+
+int
+mu_header_prepend (mu_header_t header, const char *fn, const char *fv)
+{
+  int status;
+  struct mu_hdrent *ent;
+
+  if (header == NULL || fn == NULL || fv == NULL)
+    return EINVAL;
+
+  status = mu_header_fill (header);
+  if (status)
+    return status;
+
+  ent = mu_hdrent_create (header, NULL, fn, strlen (fn), fv, strlen (fv));
+  if (!ent)
+    return ENOMEM;
+  mu_hdrent_prepend (header, ent);
+  HEADER_SET_MODIFIED (header);
+  return 0;
+}
+
+int
+mu_header_insert (mu_header_t header,
+                 const char *fn, const char *fv, 
+                 const char *ref, int n, int flags)
+{
+  int status;
+  struct mu_hdrent *ent;
+
+  if (header == NULL || fn == NULL || fv == NULL)
+    return EINVAL;
+
+  status = mu_header_fill (header);
+  if (status)
+    return status;
+    
+  if (flags & MU_HEADER_REPLACE)
+    {
+      if (!ref)
+       ref = fn;
+      ent = mu_hdrent_find (header, ref, n);
+      mu_hdrent_create (header, ent, fn, strlen (fn), fv, strlen (fv));
+    }
+  else
+    {
+      ent = mu_hdrent_create (header, NULL,
+                             fn, strlen (fn), fv, strlen (fv));
+      if (!ent)
+       return ENOMEM;
+      if (ref)
+       return mu_hdrent_insert (header, ent, ref, n,
+                                flags & MU_HEADER_BEFORE);
+      else
+       mu_hdrent_prepend (header, ent);
+    }
+  HEADER_SET_MODIFIED (header);
+  return 0;
+}
+  
+
+int
+mu_header_sget_value_n (mu_header_t header,
+                       const char *name, int n,
+                       const char **pval)
+{
+  int status;
+  struct mu_hdrent *ent;
+
+  if (header == NULL || name == NULL)
+    return EINVAL;
+  status = mu_header_fill (header);
+  if (status)
+    return status;
+
+  ent = mu_hdrent_find (header, name, n);
+  if (!ent)
+    return MU_ERR_NOENT;
+
+  *pval = MU_HDRENT_VALUE (header, ent);
+  return 0;
+}
+
+int
+mu_header_aget_value_n (mu_header_t header,
+                     const char *name, int n,
+                     char **pval)
+{
+  const char *s;
+  int status = mu_header_sget_value_n (header, name, n, &s);
+  if (status == 0)
+    {
+      *pval = strdup (s);
+      if (!*pval)
+       status = ENOMEM;
+    }
+  return status;
+}
+
+int
+mu_header_get_value_n (mu_header_t header, const char *name, int n,
+                      char *buffer, size_t buflen, size_t *pn)
+{
+  const char *s;
+  int status = mu_header_sget_value_n (header, name, n, &s);
+  if (status == 0)
+    {
+      size_t slen = strlen (s);
+
+      if (buffer)
+       {
+         if (slen > buflen)
+           slen = buflen;
+         memcpy (buffer, s, slen);
+         buffer[slen] = 0;
+       }
+      if (pn)
+       *pn = slen;
+    }
+  return status;
+}
+
+
+/* Unfolding functions */
+int
+mu_header_get_value_unfold_n (mu_header_t header,
+                             const char *name, int n, char *buffer,
+                             size_t buflen, size_t *pn)
+{
+  int rc = mu_header_get_value_n (header, name, n, buffer, buflen, pn);
+
+  if (rc == 0)
+    mu_string_unfold (buffer, pn);
+  return rc;
+}
+
+int
+mu_header_aget_value_unfold_n (mu_header_t header, const char *name, int n,
+                              char **pvalue)
+{
+  int rc = mu_header_aget_value_n (header, name, n, pvalue);
+  if (rc == 0)
+    mu_string_unfold (*pvalue, NULL);
+  return rc;
+}
+
+
+int
+mu_header_get_address_n (mu_header_t header, const char *name, int n,
+                        mu_address_t *addr)
+{
+  const char *value = NULL;
+  int status = mu_header_sget_value_n (header, name, n, &value);
+
+  if (status)
+    return status;
+
+  return mu_address_create (addr, value);
+}
+
+
+int
+mu_header_get_field_count (mu_header_t header, size_t *pcount)
+{
+  size_t count;
+  size_t size;
+  size_t lines;
+  int status;
+  
+  if (header == NULL)
+    return EINVAL;
+
+  status = mu_header_fill (header);
+  if (status == 0)
+    {
+      mu_hdrent_count (header, &count, &size, &lines);
+      
+      if (pcount)
+       *pcount = count;
+    }
+  
+  return status;
+}
+
+int
+mu_header_sget_field_name (mu_header_t header, size_t num, const char **sptr)
+{
+  int status;
+  
+  if (header == NULL)
+    return EINVAL;
+
+  status = mu_header_fill (header);
+  if (status == 0)
+    {
+      struct mu_hdrent *ent = mu_hdrent_nth (header, num);
+      if (ent)
+       *sptr = MU_HDRENT_NAME (header, ent);
+      else
+       status = MU_ERR_NOENT;
+    }
+  return status;
+}
+
+int
+mu_header_get_field_name (mu_header_t header, size_t num, char *buffer,
+                         size_t buflen, size_t *pn)
+{
+  const char *s;
+  int status = mu_header_sget_field_name (header, num, &s);
+  if (status == 0)
+    {
+      size_t slen = strlen (s);
+
+      if (buffer)
+       {
+         if (slen > buflen)
+           slen = buflen;
+         memcpy (buffer, s, slen);
+         buffer[slen] = 0;
+       }
+      if (pn)
+       *pn = slen;
+    }
+  return status;
+}
+
+int
+mu_header_aget_field_name (mu_header_t header, size_t num, char **pvalue)
+{
+  const char *s;
+  int status = mu_header_sget_field_name (header, num, &s);
+  if (status == 0)
+    {
+      if ((*pvalue = strdup (s)) == NULL)
+       status = ENOMEM;
+    }
+  return status;
+}
+
+
+int
+mu_header_sget_field_value (mu_header_t header, size_t num, const char **sptr)
+{
+  int status;
+  
+  if (header == NULL)
+    return EINVAL;
+
+  status = mu_header_fill (header);
+  if (status == 0)
+    {
+      struct mu_hdrent *ent = mu_hdrent_nth (header, num);
+      if (ent)
+       *sptr = MU_HDRENT_VALUE (header, ent);
+      else
+       status = MU_ERR_NOENT;
+    }
+  return status;
+}
+
+int
+mu_header_get_field_value (mu_header_t header, size_t num, char *buffer,
+                          size_t buflen, size_t *pn)
+{
+  const char *s;
+  int status = mu_header_sget_field_value (header, num, &s);
+  if (status == 0)
+    {
+      size_t slen = strlen (s);
+
+      if (buffer)
+       {
+         if (slen > buflen)
+           slen = buflen;
+         memcpy (buffer, s, slen);
+         buffer[slen] = 0;
+       }
+      if (pn)
+       *pn = slen;
+    }
+  return status;
+}
+
+int
+mu_header_aget_field_value (mu_header_t header, size_t num, char **pvalue)
+{
+  const char *s;
+  int status = mu_header_sget_field_value (header, num, &s);
+  if (status == 0)
+    {
+      if ((*pvalue = strdup (s)) == NULL)
+       status = ENOMEM;
+    }
+  return status;
+}
+
+int
+mu_header_get_field_value_unfold (mu_header_t header, size_t num, char *buf,
+                                 size_t buflen, size_t *nwritten)
+{
+  int rc = mu_header_get_field_value (header, num, buf, buflen, nwritten);
+  if (rc == 0)
+    mu_string_unfold (buf, nwritten);
+  return rc;
+}
+
+int
+mu_header_aget_field_value_unfold (mu_header_t header, size_t num,
+                                  char **pvalue)
+{
+  int rc = mu_header_aget_field_value (header, num, pvalue);
+  if (rc == 0)
+    mu_string_unfold (*pvalue, NULL);
+  return rc;
+}
+
+
+int
+mu_header_lines (mu_header_t header, size_t *plines)
+{
+  int status;
+
+  if (header == NULL)
+    return EINVAL;
+  if (plines == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+
+  status = mu_header_fill (header);
+  if (status == 0)
+    {
+      size_t count;
+      size_t size;
+      size_t lines;
+      mu_hdrent_count (header, &count, &size, &lines);
+      *plines = lines + 1;
+    }
+  return status;
+}
+
+int
+mu_header_size (mu_header_t header, size_t *psize)
+{
+  int status;
+
+  if (header == NULL)
+    return EINVAL;
+  if (psize == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+
+  status = mu_header_fill (header);
+  if (status == 0)
+    {
+      size_t count;
+      size_t size;
+      size_t lines;
+      mu_hdrent_count (header, &count, &size, &lines);
+      *psize = size + 1;
+    }
+  return status;
+}
+
+int
+mu_header_invalidate (mu_header_t hdr)
+{
+  if (hdr == NULL)
+    return EINVAL;
+  mu_hdrent_free_list (hdr);
+  return 0;
+}
+
+
+static void
+mu_hdrent_fixup (mu_header_t hdr, struct mu_hdrent *ent)
+{
+  char *s = MU_HDRENT_NAME (hdr, ent);
+  s[ent->nlen] = ':';
+  s = MU_HDRENT_VALUE (hdr, ent);
+  s[ent->vlen] = '\n';
+}
+
+static void
+mu_hdrent_unroll_fixup (mu_header_t hdr, struct mu_hdrent *ent)
+{
+  char *s = MU_HDRENT_NAME (hdr, ent);
+  s[ent->nlen] = 0;
+  s = MU_HDRENT_VALUE (hdr, ent);
+  s[ent->vlen] = 0;
+}
+
+int
+header_seek (mu_stream_t str, mu_off_t off, mu_off_t *presult)
+{ 
+  struct _mu_header_stream *hstr = (struct _mu_header_stream *) str;
+  size_t size;
+  int status;
+    
+  status = mu_header_size (hstr->hdr, &size);
+  if (status)
+    return status;
+  
+  if (off < 0 || off > size)
+    return ESPIPE;
+  hstr->off = off;
+  *presult = off;
+  return 0;
+}
+
+static int
+header_read (mu_stream_t is, char *buffer, size_t buflen, size_t *pnread)
+{
+  struct _mu_header_stream *hstr = (struct _mu_header_stream *) is;
+  mu_header_t header;
+  struct mu_hdrent *ent;
+  size_t ent_off;
+  int status;
+  size_t nread;
+  
+  if (is == NULL)
+    return EINVAL;
+
+  header = hstr->hdr;
+  status = mu_header_fill (header);
+  if (status)
+    return status;
+  
+  if (mu_hdrent_find_stream_pos (header, hstr->off, &ent, &ent_off))
+    {
+      if (pnread)
+       *pnread = 0;
+      return 0;
+    }
+
+  for (nread = 0; nread < buflen && ent; ent = ent->next)
+    {
+      size_t rest = buflen - nread;
+      size_t strsize = MU_STR_SIZE (ent->nlen, ent->vlen) - ent_off;
+      if (rest > strsize)
+       rest = strsize;
+      mu_hdrent_fixup (header, ent);
+      memcpy (buffer + nread, MU_HDRENT_NAME (header, ent) + ent_off, rest);
+      mu_hdrent_unroll_fixup (header, ent);
+      nread += rest;
+      hstr->off += rest;
+      ent_off = 0;
+    }
+  if (pnread)
+    *pnread = nread;
+  return 0;
+}
+
+#if 0
+/* FIXME: Implement header_readdelim based on this: */
+static int
+_header_readline (mu_stream_t is, char *buffer, size_t buflen, size_t *pnread)
+{
+  struct _mu_header_stream *hstr = (struct _mu_header_stream *) is;
+  mu_header_t header = hstr->hdr;
+  struct mu_hdrent *ent;
+  size_t ent_off;
+  int status;
+  size_t strsize;
+  char *start, *end;
+
+  if (buflen == 0)
+    return EINVAL;
+
+  header = mu_stream_get_owner (is);
+  status = mu_header_fill (header);
+  if (status)
+    return status;
+  if (mu_hdrent_find_stream_pos (header, hstr->off, &ent, &ent_off))
+    {
+      if (pnread)
+       *pnread = 0;
+      return 0;
+    }
+
+  buflen--; /* Account for the terminating nul */
+
+  mu_hdrent_fixup (header, ent);
+  strsize = MU_STR_SIZE (ent->nlen, ent->vlen) - ent_off;
+  start = MU_HDRENT_NAME (header, ent) + ent_off;
+  end = strchr (start, '\n');
+  if (end)
+    {
+      size_t len = end - start + 1;
+      if (len < strsize)
+       strsize = len;
+    }
+
+  if (strsize < buflen)
+    buflen = strsize;
+
+  memcpy (buffer, start, buflen);
+  buffer[buflen] = 0;
+  hstr->off += buflen;
+  mu_hdrent_unroll_fixup (header, ent);
+  if (pnread)
+    *pnread = buflen;
+  return 0;
+}
+#endif
+
+static int
+header_write (mu_stream_t os, const char *buf, size_t buflen, size_t *pnwrite)
+{
+  struct _mu_header_stream *hstr;
+  mu_header_t header;
+  int status;
+  mu_off_t mstream_size;
+  
+  if (!os || !buf)
+    return EINVAL;
+
+  hstr = (struct _mu_header_stream *) os;
+  header = hstr->hdr;
+  if (header == NULL)
+    return EINVAL;
+  
+  /* Skip the obvious.  */
+  if (*buf == '\0' || buflen == 0)
+    {
+      if (pnwrite)
+        *pnwrite = 0;
+      return 0;
+    }
+
+  if (!header->mstream)
+    {
+      status = mu_memory_stream_create (&header->mstream, MU_STREAM_RDWR);
+      if (status)
+       return status;
+    }
+
+  status = mu_stream_write (header->mstream, buf, buflen, NULL);
+  if (status)
+    {
+      mu_stream_destroy (&header->mstream);
+      return status;
+    }
+
+  status = mu_stream_size (header->mstream, &mstream_size);
+  if (status == 0 && mstream_size > 1)
+    {
+      char nlbuf[2];
+
+      status = mu_stream_seek (header->mstream, -2, MU_SEEK_END, NULL);
+      if (status == 0)
+       status = mu_stream_read (header->mstream, nlbuf, 2, NULL);
+      if (status == 0 && memcmp (nlbuf, "\n\n", 2) == 0)
+       {
+         char *blurb;
+
+         blurb = calloc (1, mstream_size + 1);
+         if (blurb)
+           {
+             mu_stream_read (header->mstream, blurb, mstream_size, NULL);
+             status = header_parse (header, blurb, mstream_size);
+           }
+         free (blurb);
+         mu_stream_destroy (&header->mstream);
+       }
+    }
+  
+  if (pnwrite)
+    *pnwrite = buflen;
+  
+  return status;
+}
+
+static int
+header_size (mu_stream_t str, mu_off_t *psize)
+{
+  mu_header_t header;
+  int status;
+  size_t size;
+  
+  if (str == NULL)
+    return EINVAL;
+  if (psize == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  
+  header = ((struct _mu_header_stream *) str)->hdr;
+  status = mu_header_fill (header);
+  if (status)
+    return status;
+  status = mu_header_size (header, &size);
+  if (status == 0)
+    *psize = size;
+  return status;
+}
+
+static int
+_header_get_stream (mu_header_t header, mu_stream_t *pstream, int ref)
+{
+  if (header == NULL)
+    return EINVAL;
+
+  if (pstream == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+
+  if (header->stream == NULL)
+    {
+      struct _mu_header_stream *str = 
+       (struct _mu_header_stream *) _mu_stream_create (sizeof (*str),
+                                                       
MU_STREAM_RDWR|MU_STREAM_SEEK);
+      if (!str)
+       return ENOMEM;
+      str->stream.read = header_read;
+      /*str->stream.rdelim? */
+      str->stream.write = header_write;
+      str->stream.seek = header_seek;
+      str->stream.size = header_size;
+      str->hdr = header;
+      header->stream = (mu_stream_t) str;
+    }
+  if (!ref)
+    {
+      *pstream = header->stream;
+      return 0;
+    }
+  return mu_streamref_create (pstream, header->stream);
+}
+
+int
+mu_header_get_stream (mu_header_t header, mu_stream_t *pstream)
+{
+  /* FIXME: Deprecation warning */
+  return _header_get_stream (header, pstream, 0);
+}
+
+int
+mu_header_get_streamref (mu_header_t header, mu_stream_t *pstream)
+{
+  return _header_get_stream (header, pstream, 1);
+}
+
+
+int
+mu_header_set_fill (mu_header_t header, int
+                   (*_fill) (void *data, char **, size_t *),
+                   void *data)
+{
+  if (header == NULL)
+    return EINVAL;
+  header->_fill = _fill;
+  header->data = data;
+  return 0;
+}
+
+
+int
+mu_header_is_modified (mu_header_t header)
+{
+  return header ? (header->flags & HEADER_MODIFIED) : 0;
+}
+
+int
+mu_header_clear_modified (mu_header_t header)
+{
+  if (header)
+    header->flags &= ~HEADER_MODIFIED;
+  return 0;
+}
+
+
diff --git a/libmailutils/mailbox/mailbox.c b/libmailutils/mailbox/mailbox.c
new file mode 100644
index 0000000..fcf2243
--- /dev/null
+++ b/libmailutils/mailbox/mailbox.c
@@ -0,0 +1,818 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2006, 2007, 2008, 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/>. */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+
+#include <mailutils/debug.h>
+#include <mailutils/errno.h>
+#include <mailutils/error.h>
+#include <mailutils/folder.h>
+#include <mailutils/iterator.h>
+#include <mailutils/list.h>
+#include <mailutils/locker.h>
+#include <mailutils/observer.h>
+#include <mailutils/property.h>
+#include <mailutils/registrar.h>
+#include <mailutils/stream.h>
+#include <mailutils/url.h>
+#include <mailutils/attribute.h>
+#include <mailutils/message.h>
+#include <mailutils/mutil.h>
+
+#include <mailutils/sys/mailbox.h>
+#include <mailutils/sys/url.h>
+
+/* Mailbox-specific flags */
+#define _MU_MAILBOX_OPEN    0x10000000
+#define _MU_MAILBOX_REMOVED 0x20000000
+#define _MU_MAILBOX_MASK    0xF0000000
+
+static int
+mailbox_folder_create (mu_mailbox_t mbox, const char *name,
+                      mu_record_t record)
+{
+  int rc;
+  mu_url_t url;
+  
+  if ((rc = mu_url_uplevel (mbox->url, &url)))
+    {
+      if (rc == MU_ERR_NOENT)
+       {
+         rc = mu_url_dup (mbox->url, &url);
+         if (rc)
+           return rc;
+       }
+      else
+       return rc;
+    }
+
+  rc = mu_folder_create_from_record (&mbox->folder, url, record);
+  if (rc)
+    mu_url_destroy (&url);
+  return rc;
+}
+
+int
+_mailbox_create_from_record (mu_mailbox_t *pmbox,
+                            mu_record_t record,
+                            mu_url_t url, 
+                            const char *name)
+{
+  mu_log_level_t level;
+  int (*m_init) (mu_mailbox_t) = NULL;
+      
+  mu_record_get_mailbox (record, &m_init);
+  if (m_init)
+    {
+      int status;
+      int (*u_init) (mu_url_t) = NULL;
+      mu_mailbox_t mbox;
+      
+      /* Allocate memory for mbox.  */
+      mbox = calloc (1, sizeof (*mbox));
+      if (mbox == NULL)
+       return ENOMEM;
+      
+      /* Initialize the internal lock now, so the concrete mailbox
+        could use it. */
+      status = mu_monitor_create (&mbox->monitor, 0, mbox);
+      if (status != 0)
+       {
+         mu_mailbox_destroy (&mbox);
+         return status;
+       }
+      
+      /* Make sure scheme contains actual mailbox scheme */
+      /* FIXME: It is appropriate not for all record types.  For now we
+        assume that if the record scheme ends with a plus sign, this
+        should not be done.  Probably it requires some flag in struct
+        _mu_record? */
+      if (strcmp (url->scheme, record->scheme))
+       {
+         char *p = strdup (record->scheme);
+         if (!p)
+           {
+             mu_mailbox_destroy (&mbox);
+             return errno;
+           }
+         free (url->scheme);
+         url->scheme = p;
+       }
+      
+      mu_record_get_url (record, &u_init);
+      if (u_init && (status = u_init (url)) != 0)
+       {
+         mu_mailbox_destroy (&mbox);
+         return status;
+       }
+      
+      mbox->url = url;
+      
+      /* Create the folder before initializing the concrete mailbox.
+        The mailbox needs it's back pointer. */
+      status = mailbox_folder_create (mbox, name, record);
+      
+      if (status == 0)
+       status = m_init (mbox);   /* Create the concrete mailbox type.  */
+      
+      if (status != 0)
+       {
+         /* Take care not to destroy url.  Leave it to caller. */
+         mbox->url = NULL;
+         mu_mailbox_destroy (&mbox);
+       }
+      else
+       {
+         *pmbox = mbox;
+         
+         level = mu_global_debug_level ("mailbox");
+         if (level)
+           {
+             int status = mu_debug_create (&mbox->debug, mbox);
+             if (status)
+               return 0; /* FIXME: don't want to bail out just because I
+                            failed to create a *debug* object. But I may
+                            be wrong... */
+             mu_debug_set_level (mbox->debug, level);
+             if (level & MU_DEBUG_INHERIT)
+               mu_folder_set_debug (mbox->folder, mbox->debug);
+           }
+       }
+      
+      return status;
+    }
+  return MU_ERR_NO_HANDLER;
+}
+
+static int
+_create_mailbox0 (mu_mailbox_t *pmbox, mu_url_t url, const char *name)
+{
+  mu_record_t record = NULL;
+
+  if (mu_registrar_lookup_url (url, MU_FOLDER_ATTRIBUTE_FILE, &record, NULL)
+      == 0)
+    return _mailbox_create_from_record (pmbox, record, url, name);
+  return MU_ERR_NO_HANDLER;
+}
+
+static int
+_create_mailbox (mu_mailbox_t *pmbox, const char *name)
+{
+  int status;
+  mu_url_t url;
+
+  status = mu_url_create (&url, name);
+  if (status)
+    return status;
+  status = mu_url_parse (url);
+  if (status == 0)
+    status = _create_mailbox0 (pmbox, url, name);
+  if (status)
+    mu_url_destroy (&url);
+  return status;
+}
+
+/* The Mailbox Factory.
+   Create an iterator for registrar and see if any url scheme match,
+   Then we call the mailbox's mu_url_create() to parse the URL. Last
+   initialize the concrete mailbox and folder.  */
+int
+mu_mailbox_create (mu_mailbox_t *pmbox, const char *name)
+{
+  if (pmbox == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+
+  return _create_mailbox (pmbox, name);
+}
+
+int
+mu_mailbox_create_from_url (mu_mailbox_t *pmbox, mu_url_t url)
+{
+  if (pmbox == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  return _create_mailbox0 (pmbox, url, mu_url_to_string (url));
+}
+
+int
+mu_mailbox_create_from_record (mu_mailbox_t *pmbox, mu_record_t record,
+                              const char *name)
+{
+  mu_url_t url;
+  int rc;
+  
+  rc = mu_url_create (&url, name);
+  if (rc)
+    return rc;
+  rc = mu_url_parse (url);
+  if (rc == 0)
+    rc = _mailbox_create_from_record (pmbox, record, url, name);
+  if (rc)
+    mu_url_destroy (&url);
+  return rc;
+}
+
+void
+mu_mailbox_destroy (mu_mailbox_t *pmbox)
+{
+  if (pmbox && *pmbox)
+    {
+      mu_mailbox_t mbox = *pmbox;
+      mu_monitor_t monitor = mbox->monitor;
+
+      /* Notify the observers.  */
+      if (mbox->observable)
+       {
+         mu_observable_notify (mbox->observable, MU_EVT_MAILBOX_DESTROY,
+                               mbox);
+         mu_observable_destroy (&mbox->observable, mbox);
+       }
+
+      /* Call the concrete mailbox _destroy method. So it can clean itself.  */
+      if (mbox->_destroy)
+       mbox->_destroy (mbox);
+
+      mu_monitor_wrlock (monitor);
+
+      /* Close the stream and nuke it */
+      if (mbox->stream)
+       {
+         /* FIXME: Is this right, should the client be responsible
+            for closing the stream?  */
+         /* mu_stream_close (mbox->stream); */
+         mu_stream_destroy (&mbox->stream);
+       }
+
+      if (mbox->url)
+        mu_url_destroy (&mbox->url);
+
+      if (mbox->locker)
+       mu_locker_destroy (&mbox->locker);
+
+      if (mbox->debug)
+       mu_debug_destroy (&mbox->debug, mbox);
+
+      if (mbox->folder)
+       mu_folder_destroy (&mbox->folder);
+
+      if (mbox->property)
+       mu_property_destroy (&mbox->property, mbox);
+
+      free (mbox);
+      *pmbox = NULL;
+      mu_monitor_unlock (monitor);
+      mu_monitor_destroy (&monitor, mbox);
+    }
+}
+
+
+/* -------------- stub functions ------------------- */
+
+int
+mu_mailbox_open (mu_mailbox_t mbox, int flag)
+{
+  int rc;
+  
+  if (!mbox)
+    return MU_ERR_MBX_NULL;
+  if (mbox->_open == NULL)
+    return MU_ERR_EMPTY_VFN;
+  if (mbox->flags & _MU_MAILBOX_OPEN)
+    return MU_ERR_OPEN;
+  if (flag & MU_STREAM_QACCESS)
+    {
+      /* Quick access mailboxes are read-only */
+      if (flag & (MU_STREAM_WRITE | MU_STREAM_RDWR
+                 | MU_STREAM_APPEND | MU_STREAM_CREAT))
+       return EINVAL; /* FIXME: Better error code, please? */
+    }
+  rc = mbox->_open (mbox, flag);
+  if (rc == 0)
+    mbox->flags |= _MU_MAILBOX_OPEN;
+  return rc;
+}
+
+int
+mu_mailbox_close (mu_mailbox_t mbox)
+{
+  int rc;
+
+  if (!mbox)
+    return MU_ERR_MBX_NULL;
+  if (!(mbox->flags & _MU_MAILBOX_OPEN))
+    return MU_ERR_NOT_OPEN;
+  if (mbox == NULL || mbox->_close == NULL)
+    return MU_ERR_EMPTY_VFN;
+
+  rc = mbox->_close (mbox);
+  if (rc == 0)
+    mbox->flags &= ~_MU_MAILBOX_OPEN;
+  return rc;
+}
+
+int
+mu_mailbox_remove (mu_mailbox_t mbox)
+{
+  if (!mbox)
+    return MU_ERR_MBX_NULL;
+  if (mbox->flags & _MU_MAILBOX_OPEN)
+    return MU_ERR_OPEN;
+  if (mbox->flags & _MU_MAILBOX_REMOVED)
+    return MU_ERR_MBX_REMOVED;
+  if (!mbox->_remove)
+    return MU_ERR_EMPTY_VFN;
+  return mbox->_remove (mbox);
+}
+
+int
+mu_mailbox_flush (mu_mailbox_t mbox, int expunge)
+{
+  size_t i, total = 0;
+  int status = 0;
+  
+  if (!mbox)
+    return MU_ERR_MBX_NULL;
+  if (mbox->flags & _MU_MAILBOX_REMOVED)
+    return MU_ERR_MBX_REMOVED;
+  if (!(mbox->flags & _MU_MAILBOX_OPEN))
+    return _MU_MAILBOX_OPEN;
+  if (!(mbox->flags & (MU_STREAM_RDWR|MU_STREAM_WRITE|MU_STREAM_APPEND)))
+    return 0;
+
+  mu_mailbox_messages_count (mbox, &total);
+  if (!(mbox->flags & MU_STREAM_APPEND))
+    for (i = 1; i <= total; i++)
+      {
+       mu_message_t msg = NULL;
+       mu_attribute_t attr = NULL;
+       mu_mailbox_get_message (mbox, i, &msg);
+       mu_message_get_attribute (msg, &attr);
+       mu_attribute_set_seen (attr);
+      }
+
+  if (expunge)
+    status = mu_mailbox_expunge (mbox);
+  else
+    status = mu_mailbox_sync (mbox);
+
+  return status;
+}
+
+#define _MBOX_CHECK_FLAGS(mbox)                        \
+  if (mbox == NULL)                            \
+    return MU_ERR_MBX_NULL;                    \
+  if (mbox->flags & _MU_MAILBOX_REMOVED)       \
+    return MU_ERR_MBX_REMOVED;                 \
+  if (!(mbox->flags & _MU_MAILBOX_OPEN))       \
+    return _MU_MAILBOX_OPEN
+
+#define _MBOX_CHECK(mbox,method)               \
+  _MBOX_CHECK_FLAGS(mbox);                     \
+  if (mbox->method == NULL)                    \
+    return MU_ERR_EMPTY_VFN
+
+#define _MBOX_CHECK_Q(mbox,method)             \
+  _MBOX_CHECK(mbox,method);                    \
+  if (mbox->flags & MU_STREAM_QACCESS)         \
+    return MU_ERR_BADOP
+
+/* messages */
+int
+mu_mailbox_append_message (mu_mailbox_t mbox, mu_message_t msg)
+{
+  _MBOX_CHECK_Q (mbox, _append_message);
+  if (!(mbox->flags & (MU_STREAM_RDWR|MU_STREAM_WRITE|MU_STREAM_APPEND)))
+    return EACCES;
+  return mbox->_append_message (mbox, msg);
+}
+
+int
+mu_mailbox_get_message (mu_mailbox_t mbox, size_t msgno,  mu_message_t *pmsg)
+{
+  _MBOX_CHECK_Q (mbox, _get_message);
+  return mbox->_get_message (mbox, msgno, pmsg);
+}
+
+int
+mu_mailbox_quick_get_message (mu_mailbox_t mbox, mu_message_qid_t qid,
+                             mu_message_t *pmsg)
+{
+  _MBOX_CHECK (mbox, _quick_get_message);
+  if (!(mbox->flags & MU_STREAM_QACCESS))
+    return MU_ERR_BADOP;
+  return mbox->_quick_get_message (mbox, qid, pmsg);
+}
+
+int
+mu_mailbox_messages_count (mu_mailbox_t mbox, size_t *num)
+{
+  _MBOX_CHECK_Q (mbox, _messages_count);
+  return mbox->_messages_count (mbox, num);
+}
+
+int
+mu_mailbox_messages_recent (mu_mailbox_t mbox, size_t *num)
+{
+  _MBOX_CHECK_Q (mbox, _messages_recent);
+  return mbox->_messages_recent (mbox, num);
+}
+
+int
+mu_mailbox_message_unseen (mu_mailbox_t mbox, size_t *num)
+{
+  _MBOX_CHECK_Q (mbox, _message_unseen);
+  return mbox->_message_unseen (mbox, num);
+}
+
+int
+mu_mailbox_sync (mu_mailbox_t mbox)
+{
+  _MBOX_CHECK_Q (mbox, _sync);
+  if (!(mbox->flags & (MU_STREAM_RDWR|MU_STREAM_WRITE|MU_STREAM_APPEND)))
+    return 0;
+  return mbox->_sync (mbox);
+}
+
+/* Historic alias: */
+int
+mu_mailbox_save_attributes (mu_mailbox_t mbox)
+{
+  return mu_mailbox_sync (mbox);
+}
+
+int
+mu_mailbox_expunge (mu_mailbox_t mbox)
+{
+  _MBOX_CHECK_Q (mbox, _expunge);
+  if (!(mbox->flags & (MU_STREAM_RDWR|MU_STREAM_WRITE|MU_STREAM_APPEND)))
+    return EACCES;
+  return mbox->_expunge (mbox);
+}
+
+int
+mu_mailbox_is_updated (mu_mailbox_t mbox)
+{
+  if (mbox == NULL ||
+      !(mbox->flags & _MU_MAILBOX_OPEN) ||
+      (mbox->flags & _MU_MAILBOX_REMOVED) ||
+      mbox->_is_updated == NULL)
+    return 1;
+  if (mbox->flags & MU_STREAM_QACCESS)
+    return 1;
+  return mbox->_is_updated (mbox);
+}
+
+int
+mu_mailbox_scan (mu_mailbox_t mbox, size_t msgno, size_t *pcount)
+{
+  _MBOX_CHECK_Q (mbox, _scan);
+  return mbox->_scan (mbox, msgno, pcount);
+}
+
+int
+mu_mailbox_get_size (mu_mailbox_t mbox, mu_off_t *psize)
+{
+  int status;
+
+  _MBOX_CHECK_FLAGS (mbox);
+  if (mbox->flags & MU_STREAM_QACCESS)
+    return MU_ERR_BADOP;
+  if (mbox->_get_size == NULL
+      || (status = mbox->_get_size (mbox, psize)) == ENOSYS)
+    {
+      /* Fall back to brute-force method */
+      size_t i, total;
+      mu_off_t size = 0;
+      
+      status = mu_mailbox_messages_count (mbox, &total);
+      if (status)
+       return status;
+      for (i = 1; i <= total; i++)
+       {
+         mu_message_t msg;
+         size_t msgsize;
+         status = mu_mailbox_get_message (mbox, i, &msg);
+         if (status)
+           return status;
+         status = mu_message_size (msg, &msgsize);
+         if (status)
+           return status;
+         size += msgsize;
+       }
+      *psize = size;
+    }
+  return status;
+}
+
+int
+mu_mailbox_uidvalidity (mu_mailbox_t mbox, unsigned long *pvalid)
+{
+  _MBOX_CHECK_Q (mbox, _uidvalidity);
+  return mbox->_uidvalidity (mbox, pvalid);
+}
+
+int
+mu_mailbox_uidnext (mu_mailbox_t mbox, size_t *puidnext)
+{
+  _MBOX_CHECK_Q (mbox, _uidnext);
+  return mbox->_uidnext (mbox, puidnext);
+}
+
+/* locking */
+int
+mu_mailbox_set_locker (mu_mailbox_t mbox, mu_locker_t locker)
+{
+  if (mbox == NULL)
+    return MU_ERR_MBX_NULL;
+  if (mbox->locker)
+    mu_locker_destroy (&mbox->locker);
+  mbox->locker = locker;
+  return 0;
+}
+
+int
+mu_mailbox_get_locker (mu_mailbox_t mbox, mu_locker_t *plocker)
+{
+  if (mbox == NULL)
+    return MU_ERR_MBX_NULL;
+  if (plocker == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  *plocker = mbox->locker;
+  return 0;
+}
+
+int
+mu_mailbox_get_flags (mu_mailbox_t mbox, int *flags)
+{
+  if (mbox == NULL)
+    return MU_ERR_MBX_NULL;
+  if (!*flags)
+    return MU_ERR_OUT_NULL;
+  *flags = mbox->flags & ~_MU_MAILBOX_MASK;
+  return 0;
+}
+
+int
+mu_mailbox_set_stream (mu_mailbox_t mbox, mu_stream_t stream)
+{
+  if (mbox == NULL)
+    return MU_ERR_MBX_NULL;
+  if (mbox->flags & MU_STREAM_QACCESS)
+    return MU_ERR_BADOP;
+  if (mbox->stream)
+    mu_stream_destroy (&mbox->stream);
+  mbox->stream = stream;
+  return 0;
+}
+
+/* FIXME: This is a problem.  We provide a mu_mailbox_get_stream ()
+   and this stream is special it should, in theory, represent
+   a "view" of a flow of messages.  But providing this perspective
+   may make sense for local mailboxes but downright impossible
+   for a remote mailbox, short on downloading the entire mailbox
+   locally.
+   The question is : should this function be removed?
+   So far it as been used on local mailboxes to get offsets.  */
+int
+mu_mailbox_get_stream (mu_mailbox_t mbox, mu_stream_t *pstream)
+{
+  /* FIXME: Deprecation warning */
+  if (mbox == NULL)
+    return MU_ERR_MBX_NULL;
+  if (pstream == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+
+  /* If null two cases:
+     - it is no open yet.
+     - it a remote stream and the socket stream is on the folder.  */
+  if (mbox->stream == NULL)
+    {
+      if (mbox->folder)
+       return mu_folder_get_stream (mbox->folder, pstream);
+    }
+  *pstream = mbox->stream;
+  return 0;
+}
+
+int
+mu_mailbox_get_streamref (mu_mailbox_t mbox, mu_stream_t *pstream)
+{
+  if (mbox == NULL)
+    return MU_ERR_MBX_NULL;
+  if (pstream == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+
+  /* If null two cases:
+     - it is no open yet.
+     - it a remote stream and the socket stream is on the folder.  */
+  if (mbox->stream == NULL)
+    {
+      if (mbox->folder)
+       return mu_folder_get_streamref (mbox->folder, pstream);
+    }
+  return mu_streamref_create (pstream, mbox->stream);
+}
+
+int
+mu_mailbox_get_observable (mu_mailbox_t mbox, mu_observable_t *pobservable)
+{
+  if (mbox == NULL)
+    return MU_ERR_MBX_NULL;
+  if (pobservable == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+
+  if (mbox->observable == NULL)
+    {
+      int status = mu_observable_create (&mbox->observable, mbox);
+      if (status != 0)
+       return status;
+    }
+  *pobservable = mbox->observable;
+  return 0;
+}
+
+int
+mu_mailbox_get_property (mu_mailbox_t mbox, mu_property_t *pproperty)
+{
+  if (mbox == NULL)
+    return MU_ERR_MBX_NULL;
+  if (pproperty == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  
+  if (mbox->property == NULL)
+    {
+      int status = mu_property_create (&mbox->property, mbox);
+      if (status != 0)
+       return status;
+    }
+  *pproperty = mbox->property;
+  return 0;
+}
+
+int
+mu_mailbox_has_debug (mu_mailbox_t mailbox)
+{
+  if (mailbox == NULL)
+    return 0;
+
+  return mailbox->debug ? 1 : 0;
+}
+
+int
+mu_mailbox_set_debug (mu_mailbox_t mbox, mu_debug_t debug)
+{
+  if (mbox == NULL)
+    return MU_ERR_MBX_NULL;
+  if (mbox->debug)
+    mu_debug_destroy (&mbox->debug, mbox);
+  mbox->debug = debug;
+  /* FIXME: Honor MU_DEBUG_INHERIT */
+  if (!mu_folder_has_debug (mbox->folder))
+    mu_folder_set_debug (mbox->folder, debug);
+  return 0;
+}
+
+int
+mu_mailbox_get_debug (mu_mailbox_t mbox, mu_debug_t *pdebug)
+{
+  if (mbox == NULL)
+    return MU_ERR_MBX_NULL;
+  if (pdebug == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  if (mbox->debug == NULL)
+    {
+      int status = mu_debug_create (&mbox->debug, mbox);
+      if (status != 0)
+       return status;
+      /* FIXME: MU_DEBUG_INHERIT?? */
+      if (!mu_folder_has_debug (mbox->folder))
+       mu_folder_set_debug (mbox->folder, mbox->debug);
+    }
+  *pdebug = mbox->debug;
+  return 0;
+}
+
+int
+mu_mailbox_get_url (mu_mailbox_t mbox, mu_url_t *purl)
+{
+  if (mbox == NULL)
+    return MU_ERR_MBX_NULL;
+  if (purl == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  *purl = mbox->url;
+  return 0;
+}
+
+int
+mu_mailbox_get_folder (mu_mailbox_t mbox, mu_folder_t *pfolder)
+{
+  if (mbox == NULL)
+    return MU_ERR_MBX_NULL;
+  if (pfolder == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  *pfolder = mbox->folder;
+  return 0;
+}
+
+int
+mu_mailbox_set_folder (mu_mailbox_t mbox, mu_folder_t folder)
+{
+  if (mbox == NULL)
+    return MU_ERR_MBX_NULL;
+   mbox->folder = folder;
+  return 0;
+}
+
+int
+mu_mailbox_lock (mu_mailbox_t mbox)
+{
+  mu_locker_t lock = NULL;
+  mu_mailbox_get_locker (mbox, &lock);
+  return mu_locker_lock (lock);
+}
+
+int
+mu_mailbox_unlock (mu_mailbox_t mbox)
+{
+  mu_locker_t lock = NULL;
+  mu_mailbox_get_locker (mbox, &lock);
+  return mu_locker_unlock (lock);
+}
+
+int
+mu_mailbox_get_uidls (mu_mailbox_t mbox, mu_list_t *plist)
+{
+  mu_list_t list;
+  int status;
+
+  if (mbox == NULL)
+    return MU_ERR_MBX_NULL;
+  if (plist == NULL)
+    return EINVAL;
+  status = mu_list_create (&list);
+  if (status)
+    return status;
+  mu_list_set_destroy_item (list, mu_list_free_item);
+  if (mbox->_get_uidls)
+    status = mbox->_get_uidls (mbox, list);
+  else
+    {
+      size_t i, total;
+
+      status = mu_mailbox_messages_count (mbox, &total);
+      if (status)
+       return status;
+      for (i = 1; i <= total; i++)
+       {
+         mu_message_t msg = NULL;
+         char buf[MU_UIDL_BUFFER_SIZE];
+         size_t n;
+         struct mu_uidl *uidl;
+         
+         status = mu_mailbox_get_message (mbox, i, &msg);
+         if (status)
+           break;
+         status = mu_message_get_uidl (msg, buf, sizeof (buf), &n);
+         if (status)
+           break;
+         uidl = malloc (sizeof (uidl[0]));
+         if (!uidl)
+           {
+             status = ENOMEM;
+             break;
+           }
+         uidl->msgno = i;
+         strncpy (uidl->uidl, strdup (buf), MU_UIDL_BUFFER_SIZE);
+         status = mu_list_append (list, uidl);
+         if (status)
+           {
+             free (uidl);
+             break;
+           }
+       }
+    }
+  *plist = list;
+  return status;
+}
+
+         
diff --git a/libmailutils/mailbox/mbx_default.c 
b/libmailutils/mailbox/mbx_default.c
new file mode 100644
index 0000000..9069c6f
--- /dev/null
+++ b/libmailutils/mailbox/mbx_default.c
@@ -0,0 +1,453 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2008,
+   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/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <stdio.h>
+#include <pwd.h>
+#include <unistd.h>
+
+#include <confpaths.h>
+
+#include <mailutils/mailbox.h>
+#include <mailutils/mutil.h>
+#include <mailutils/debug.h>
+#include <mailutils/error.h>
+#include <mailutils/errno.h>
+#include <mailutils/mu_auth.h>
+#include <mailutils/vartab.h>
+#include <mailutils/folder.h>
+#include <mailutils/auth.h>
+
+#include <mailutils/sys/mailbox.h>
+
+char *mu_ticket_file = "~/.mu-tickets";
+
+static char *_mu_mailbox_pattern;
+
+static char *_default_folder_dir = "Mail";
+static char *_mu_folder_dir;
+
+static int
+mu_normalize_mailbox_url (char **pout, const char *dir)
+{
+  int len;
+  int addslash = 0;
+#define USERSUFFIX "${user}"
+  
+  if (!pout)
+    return MU_ERR_OUT_PTR_NULL;
+      
+  len = strlen (dir);
+  if (dir[len-1] == '=')
+    {
+      if (len > 5 && strcmp (dir + len - 5, "user=") == 0)
+       *pout = strdup (dir);
+      else
+       return MU_ERR_BAD_FILENAME;
+    }
+  else if (dir[len-1] != '/')
+    addslash = 1;
+
+  *pout = malloc (strlen (dir) + (addslash ? 1 : 0) + sizeof USERSUFFIX);
+  if (!*pout)
+    return ENOMEM;
+
+  strcpy (*pout, dir);
+  if (addslash)
+    strcat (*pout, "/");
+  strcat (*pout, USERSUFFIX);
+#undef USERSUFFIX
+  return 0;
+}
+
+int
+mu_set_mail_directory (const char *p)
+{
+  if (_mu_mailbox_pattern)
+    free (_mu_mailbox_pattern);
+  if (!p)
+    {
+      _mu_mailbox_pattern = NULL;
+      return 0;
+    }
+  return mu_normalize_mailbox_url (&_mu_mailbox_pattern, p);
+}
+
+int
+mu_set_mailbox_pattern (const char *pat)
+{
+  if (_mu_mailbox_pattern)
+    free (_mu_mailbox_pattern);
+  if (!pat)
+    {
+      _mu_mailbox_pattern = NULL;
+      return 0;
+    }
+  _mu_mailbox_pattern = strdup (pat);
+  return _mu_mailbox_pattern ? 0 : ENOMEM;
+}
+
+void
+mu_set_folder_directory (const char *p)
+{
+  if (_mu_folder_dir != _default_folder_dir)
+    free (_mu_folder_dir);
+  _mu_folder_dir = strdup (p);
+}
+
+const char *
+mu_mailbox_url ()
+{
+  if (!_mu_mailbox_pattern)
+    mu_set_mail_directory (MU_PATH_MAILDIR);
+  return _mu_mailbox_pattern;
+}
+
+const char *
+mu_folder_directory ()
+{
+  if (!_mu_folder_dir)
+    _mu_folder_dir = _default_folder_dir;
+  return _mu_folder_dir;
+}
+
+int
+mu_construct_user_mailbox_url (char **pout, const char *name)
+{
+  int rc;
+  const char *pat = mu_mailbox_url ();
+  mu_vartab_t vtab;
+
+  mu_vartab_create (&vtab);
+  mu_vartab_define (vtab, "user", name, 1);
+  rc = mu_vartab_expand (vtab, pat, pout);
+  mu_vartab_destroy (&vtab);
+  return rc;
+}
+
+/* Is this a security risk?  */
+#define USE_ENVIRON 1
+
+static int
+split_shortcut (const char *file, const char pfx[], char **user, char **rest)
+{
+  *user = NULL;
+  *rest = NULL;
+
+  if (!strchr (pfx, file[0]))
+    return 0;
+
+  if (*++file == 0)
+    return 0;
+  else
+    {
+      char *p = strchr (file, '/');
+      int len;
+      if (p)
+        len = p - file + 1;
+      else
+        len = strlen (file) + 1;
+
+      if (len == 1)
+       *user = NULL;
+      else
+       {
+         *user = calloc (1, len);
+         if (!*user)
+           return ENOMEM;
+
+         memcpy (*user, file, len);
+         (*user)[len-1] = 0;
+       }
+      file += len-1;
+      if (file[0] == '/')
+        file++;
+    }
+
+  if (file[0])
+    {
+      *rest = strdup (file);
+      if (!*rest)
+        {
+          free (*user);
+          return ENOMEM;
+        }
+    }
+  
+  return 0;
+}
+
+static char *
+get_homedir (const char *user)
+{
+  char *homedir = NULL;
+  struct mu_auth_data *auth = NULL;
+  
+  if (user)
+    {
+      auth = mu_get_auth_by_name (user);
+      if (auth)
+        homedir = auth->dir;
+    }
+  else
+    {
+#ifdef USE_ENVIRON
+      /* NOTE: Should we honor ${HOME}?  */
+      homedir = getenv ("HOME");
+      if (homedir == NULL)
+        {
+         auth = mu_get_auth_by_name (user);
+         if (auth)
+           homedir = auth->dir;
+        }
+#else
+      auth = mu_get_auth_by_name (user);
+      if (auth)
+       homedir = auth->dir;
+#endif
+    }
+
+  if (homedir)
+    homedir = strdup (homedir);
+  mu_auth_data_free (auth);
+  return homedir;
+}
+
+static int
+user_mailbox_name (const char *user, char **mailbox_name)
+{
+#ifdef USE_ENVIRON
+  if (!user)
+    user = (getenv ("LOGNAME")) ? getenv ("LOGNAME") : getenv ("USER");
+#endif
+
+  if (user)
+    {
+      int rc = mu_construct_user_mailbox_url (mailbox_name, user);
+      if (rc)
+       return rc;
+    }
+  else
+    {
+      struct mu_auth_data *auth = mu_get_auth_by_uid (getuid ());
+
+      if (!auth)
+        {
+          mu_error ("Who am I?");
+          return EINVAL;
+        }
+      *mailbox_name = strdup (auth->mailbox);
+      mu_auth_data_free (auth);
+    }
+
+  return 0;
+}
+
+static int
+plus_expand (const char *file, char **buf)
+{
+  char *home;
+  const char *folder_dir = mu_folder_directory ();
+  int len;
+
+  home = get_homedir (NULL);
+  if (!home)
+    return ENOENT;
+  
+  file++;
+  
+  if (folder_dir[0] == '/' || mu_is_proto (folder_dir))
+    {
+      len = strlen (folder_dir) + strlen (file) + 2;
+      *buf = malloc (len);
+      sprintf (*buf, "%s/%s", folder_dir, file);
+    }
+  else
+    {
+      len = strlen (home) + strlen (folder_dir) + strlen (file) + 3;
+      *buf = malloc (len);
+      sprintf (*buf, "%s/%s/%s", home, folder_dir, file);
+    }
+  (*buf)[len-1] = 0;
+  
+  free (home);
+  return 0;
+}
+
+static int
+percent_expand (const char *file, char **mbox)
+{
+  char *user = NULL;
+  char *path = NULL;
+  int status;
+  
+  if ((status = split_shortcut (file, "%", &user, &path)))
+    return status;
+
+  if (path)
+    {
+      free (user);
+      free (path);
+      return ENOENT;
+    }
+
+  status = user_mailbox_name (user, mbox);
+  free (user);
+  return status;
+}
+
+static void
+attach_auth_ticket (mu_mailbox_t mbox)
+{
+  mu_folder_t folder = NULL;
+  mu_authority_t auth = NULL;
+
+  if (mu_mailbox_get_folder (mbox, &folder) == 0
+      && mu_folder_get_authority (folder, &auth) == 0
+      && auth)
+    {
+      char *filename = mu_tilde_expansion (mu_ticket_file, "/", NULL);
+      mu_wicket_t wicket;
+      int rc;
+  
+      MU_DEBUG1 (mbox->debug, MU_DEBUG_TRACE1,
+                "Reading user ticket file %s\n", filename);
+      if ((rc = mu_file_wicket_create (&wicket, filename)) == 0)
+       {
+         mu_ticket_t ticket;
+      
+         if ((rc = mu_wicket_get_ticket (wicket, NULL, &ticket)) == 0)
+           {
+             rc = mu_authority_set_ticket (auth, ticket);
+             MU_DEBUG1 (mbox->debug, MU_DEBUG_TRACE1,
+                        "Retrieved and set ticket: %d\n", rc);
+           }
+         else
+           MU_DEBUG1 (mbox->debug, MU_DEBUG_ERROR,
+                      "Error retrieving ticket: %s\n",
+                      mu_strerror (rc));
+         mu_wicket_destroy (&wicket);
+       }
+      else
+       MU_DEBUG1 (mbox->debug, MU_DEBUG_ERROR,
+                  "Error creating wicket: %s\n", mu_strerror (rc));
+      free (filename);
+    }
+}
+
+/* We are trying to be smart about the location of the mail.
+   mu_mailbox_create() is not doing this.
+   %           --> system mailbox for the real uid
+   %user       --> system mailbox for the given user
+   ~/file      --> /home/user/file
+   ~user/file  --> /home/user/file
+   +file       --> /home/user/Mail/file
+   =file       --> /home/user/Mail/file
+*/
+int
+mu_mailbox_create_default (mu_mailbox_t *pmbox, const char *mail)
+{
+  char *mbox = NULL;
+  char *tmp_mbox = NULL;
+  char *p;
+  int status = 0;
+
+  /* Sanity.  */
+  if (pmbox == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+
+  if (mail && *mail == 0)
+    mail = NULL;
+  
+  if (mail == NULL)
+    {
+      if (!_mu_mailbox_pattern)
+       {
+         /* Other utilities may not understand GNU mailutils url namespace, so
+            use FOLDER instead, to not confuse others by using MAIL.  */
+         mail = getenv ("FOLDER");
+         if (!mail)
+           {
+             /* Fallback to well-known environment.  */
+             mail = getenv ("MAIL");
+           }
+       }
+
+      if (!mail)
+       {
+         if ((status = user_mailbox_name (NULL, &tmp_mbox)))
+           return status;
+         mail = tmp_mbox;
+       }
+    }
+
+  p = mu_tilde_expansion (mail, "/", NULL);
+  if (tmp_mbox)
+    free (tmp_mbox);
+  tmp_mbox = p;
+  mail = tmp_mbox;
+  if (!mail)
+    return ENOMEM;
+  
+  switch (mail[0])
+    {
+    case '%':
+      status = percent_expand (mail, &mbox);
+      break;
+      
+    case '+':
+    case '=':
+      status = plus_expand (mail, &mbox);
+      break;
+
+    case '/':
+      mbox = strdup (mail);
+      break;
+      
+    default:
+      if (!mu_is_proto (mail))
+       {
+         p = mu_getcwd();
+         mbox = malloc (strlen (p) + strlen (mail) + 2);
+         sprintf (mbox, "%s/%s", p, mail);
+         free (p);  
+       }
+      else
+       mbox = strdup (mail);
+      break;
+    }
+
+  if (tmp_mbox)
+    free (tmp_mbox);
+
+  if (status)
+    return status;
+  
+  status = mu_mailbox_create (pmbox, mbox);
+  free (mbox);
+  if (status == 0)
+    attach_auth_ticket (*pmbox);
+      
+  return status;
+}
diff --git a/libmailutils/mailbox/mbxitr.c b/libmailutils/mailbox/mbxitr.c
new file mode 100644
index 0000000..c8ae139
--- /dev/null
+++ b/libmailutils/mailbox/mbxitr.c
@@ -0,0 +1,159 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+
+#include <mailutils/debug.h>
+#include <mailutils/errno.h>
+#include <mailutils/error.h>
+#include <mailutils/iterator.h>
+
+#include <mailutils/sys/mailbox.h>
+
+struct mailbox_iterator
+{
+  mu_mailbox_t mbx;
+  size_t idx;
+};
+
+static int
+mbx_first (void *owner)
+{
+  struct mailbox_iterator *itr = owner;
+  itr->idx = 1;
+  return 0;
+}
+
+static int
+mbx_next (void *owner)
+{
+  struct mailbox_iterator *itr = owner;
+  itr->idx++;
+  return 0;
+}
+
+static int
+mbx_getitem (void *owner, void **pret, const void **pkey)
+{
+  struct mailbox_iterator *itr = owner;
+  size_t count;
+  int rc;
+  
+  rc = mu_mailbox_messages_count (itr->mbx, &count);
+  if (rc)
+    return rc;
+  if (itr->idx > count)
+    return MU_ERR_NOENT;
+  rc = mu_mailbox_get_message (itr->mbx, itr->idx, (mu_message_t*)pret);
+  if (rc == 0 && pkey)
+    *pkey = NULL; /* FIXME: Perhaps return UIDL or other unique id? */
+  return rc;
+}
+
+static int
+mbx_finished_p (void *owner)
+{
+  struct mailbox_iterator *itr = owner;
+  size_t count;
+
+  if (mu_mailbox_messages_count (itr->mbx, &count))
+    return 1;
+  return itr->idx > count;
+}
+
+static int
+mbx_destroy (mu_iterator_t iterator, void *data)
+{
+  struct mailbox_iterator *itr = data;
+
+  mu_iterator_detach (&itr->mbx->iterator, iterator);
+  free (data);
+  return 0;
+}
+
+static int
+mbx_curitem_p (void *owner, void *item)
+{
+  void *ptr;
+
+  if (mbx_getitem (owner, &ptr, NULL))
+    return 0;
+  return ptr == item;/* FIXME: Is it ok? */
+}
+
+static int
+mbx_data_dup (void **ptr, void *owner)
+{
+  struct mailbox_iterator *itr = owner;
+
+  *ptr = malloc (sizeof (struct mailbox_iterator));
+  if (*ptr == NULL)
+    return ENOMEM;
+  memcpy (*ptr, owner, sizeof (struct mailbox_iterator));
+  mu_iterator_attach (&itr->mbx->iterator, *ptr);
+  return 0;
+}
+
+int
+mu_mailbox_get_iterator (mu_mailbox_t mbx, mu_iterator_t *piterator)
+{
+  mu_iterator_t iterator;
+  int status;
+  struct mailbox_iterator *itr;
+
+  if (!mbx)
+    return EINVAL;
+
+  itr = calloc (1, sizeof *itr);
+  if (!itr)
+    return ENOMEM;
+  itr->mbx = mbx;
+  itr->idx = 1;
+
+  status = mu_iterator_create (&iterator, itr);
+  if (status)
+    {
+      free (itr);
+      return status;
+    }
+
+  mu_iterator_set_first (iterator, mbx_first);
+  mu_iterator_set_next (iterator, mbx_next);
+  mu_iterator_set_getitem (iterator, mbx_getitem);
+  mu_iterator_set_finished_p (iterator, mbx_finished_p);
+  mu_iterator_set_curitem_p (iterator, mbx_curitem_p);
+  mu_iterator_set_destroy (iterator, mbx_destroy);
+  mu_iterator_set_dup (iterator, mbx_data_dup);
+
+  mu_iterator_attach (&mbx->iterator, iterator);
+
+  *piterator = iterator;
+  return 0;
+}
+
+
+
+
+
+  
+
diff --git a/libmailutils/mailbox/message.c b/libmailutils/mailbox/message.c
new file mode 100644
index 0000000..b6f81b7
--- /dev/null
+++ b/libmailutils/mailbox/message.c
@@ -0,0 +1,1293 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2009,
+   2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <time.h>
+#include <unistd.h>
+#include <string.h>
+#include <pwd.h>
+
+#include <mailutils/cctype.h>
+#include <mailutils/address.h>
+#include <mailutils/attribute.h>
+#include <mailutils/auth.h>
+#include <mailutils/body.h>
+#include <mailutils/debug.h>
+#include <mailutils/envelope.h>
+#include <mailutils/errno.h>
+#include <mailutils/folder.h>
+#include <mailutils/header.h>
+#include <mailutils/mailbox.h>
+#include <mailutils/mutil.h>
+#include <mailutils/observer.h>
+#include <mailutils/stream.h>
+#include <mailutils/mu_auth.h>
+#include <mailutils/nls.h>
+#include <mailutils/md5.h>
+#include <mailutils/io.h>
+
+#include <mailutils/sys/message.h>
+#include <mailutils/sys/stream.h>
+
+#define MESSAGE_MODIFIED        0x10000
+#define MESSAGE_INTERNAL_STREAM 0x20000
+
+
+/* Message stream */
+
+enum _message_stream_state
+  {
+    _mss_init,
+    _mss_header,
+    _mss_body,
+    _mss_eof
+  };
+
+struct _mu_message_stream
+{
+  struct _mu_stream stream;
+  mu_message_t msg;
+  enum _message_stream_state state;
+  mu_stream_t transport;
+  mu_off_t limit;
+};
+
+static int
+_check_stream_state (struct _mu_message_stream *str)
+{
+  int rc = 0;
+  
+  if (str->transport && mu_stream_eof (str->transport))
+    mu_stream_destroy (&str->transport);
+  
+  switch (str->state)
+    {
+    case _mss_init:
+      if (!str->transport)
+       {
+         rc = mu_header_get_streamref (str->msg->header, &str->transport);
+         if (rc == 0)
+           {
+             str->state = _mss_header;
+             rc = mu_stream_seek (str->transport, 0, MU_SEEK_SET, NULL);
+           }
+       }
+      break;
+      
+    case _mss_header:
+      if (!str->transport)
+       {
+         rc = mu_body_get_streamref (str->msg->body, &str->transport);
+         if (rc == 0)
+           {
+             str->state = _mss_body;
+             rc = mu_stream_seek (str->transport, 0, MU_SEEK_SET, NULL);
+           }
+       }
+      break;
+      
+    case _mss_body:
+      if (!str->transport)
+       str->state = _mss_eof;
+    case _mss_eof:
+      break;
+    }
+  return rc;
+}
+
+static void
+_message_stream_done (struct _mu_stream *str)
+{
+  struct _mu_message_stream *sp = (struct _mu_message_stream *)str;
+  mu_stream_destroy (&sp->transport);
+}
+
+static int
+_message_stream_flush (struct _mu_stream *str)
+{
+  struct _mu_message_stream *sp = (struct _mu_message_stream *)str;
+  int rc = _check_stream_state (sp);
+  if (rc)
+    return rc;
+  return mu_stream_flush (sp->transport);
+}
+  
+static int
+_message_stream_size (struct _mu_stream *str, mu_off_t *psize)
+{
+  struct _mu_message_stream *sp = (struct _mu_message_stream *)str;
+  size_t hsize, bsize;
+  mu_header_size (sp->msg->header, &hsize);
+  mu_body_size (sp->msg->body, &bsize);
+  if (psize)
+    *psize = hsize + bsize;
+  return 0;
+}
+
+static int
+_message_stream_seek (struct _mu_stream *str, mu_off_t off, mu_off_t *ppos)
+{
+  struct _mu_message_stream *sp = (struct _mu_message_stream *)str;
+  size_t hsize, size;
+  int rc;
+  
+  rc = _check_stream_state (sp);
+  if (rc)
+    return rc;
+  mu_header_size (sp->msg->header, &hsize);
+  mu_body_size (sp->msg->body, &size);
+  size += hsize;
+  
+  if (off < 0 || off >= size)
+    return ESPIPE;
+
+  switch (sp->state)
+    {
+    case _mss_eof:
+      sp->state = _mss_init;
+      rc = _check_stream_state (sp);
+      if (rc)
+       return rc;
+      /* fall through */
+    case _mss_header:
+      if (off < hsize)
+       break;
+      mu_stream_destroy (&sp->transport);
+      rc = _check_stream_state (sp);
+      if (rc)
+       return rc;
+      /* fall through */
+    case _mss_body:
+      if (off > hsize)
+       off -= hsize;   
+      else
+       {
+         mu_stream_destroy (&sp->transport);
+         sp->state = _mss_init;
+         rc = _check_stream_state (sp);
+         if (rc)
+           return rc;
+       }
+
+      break;
+
+    default:
+      break;
+    }
+  rc = mu_stream_seek (sp->transport, off, MU_SEEK_SET, &off);
+  if (rc == 0)
+    {
+      if (sp->state == _mss_body)
+       off += hsize;
+      *ppos = off;
+    }
+  return rc;
+}
+
+static int
+_message_stream_read (struct _mu_stream *str, char *buf, size_t bufsize,
+                     size_t *pnread)
+{
+  struct _mu_message_stream *sp = (struct _mu_message_stream *)str;
+  size_t nread = 0;
+  int rc;
+  
+  while (bufsize)
+    {
+      size_t n;
+      rc = _check_stream_state (sp);
+      if (rc)
+       break;
+      if (sp->state == _mss_eof)
+       break;
+      rc = mu_stream_read (sp->transport, buf, bufsize, &n);
+      nread += n;
+      buf += n;
+      bufsize -= n;
+    }
+  *pnread = nread;
+  return rc;
+}
+
+static int
+_message_stream_readdelim (struct _mu_stream *str, char *buf, size_t bufsize,
+                          int delim, size_t *pnread)
+{
+  struct _mu_message_stream *sp = (struct _mu_message_stream *)str;
+  size_t nread = 0;
+  int rc;
+  
+  while (bufsize)
+    {
+      size_t n;
+      rc = _check_stream_state (sp);
+      if (rc)
+       break;
+      if (sp->state == _mss_eof)
+       break;
+      rc = mu_stream_readdelim (sp->transport, buf, bufsize, delim, &n);
+      if (rc || n == 0)
+       break;
+      nread += n;
+      buf += n;
+      bufsize -= n;
+    }
+  *pnread = nread;
+  return rc;
+}  
+
+#if 0
+static int
+_message_stream_write (struct _mu_stream *str,
+                      const char *buf, size_t bufsize,
+                      size_t *pnwritten)
+{
+  struct _mu_message_stream *sp = (struct _mu_message_stream *)str;
+  
+  /* FIXME */
+}
+#endif
+
+static int
+_message_stream_create (mu_stream_t *pmsg, mu_message_t msg, int flags)
+{
+  struct _mu_message_stream *sp;
+
+  sp = (struct _mu_message_stream *) _mu_stream_create (sizeof (*sp),
+                                                       flags |
+                                                       MU_STREAM_SEEK |
+                                                       _MU_STR_OPEN);
+  if (!sp)
+    return ENOMEM;
+
+  sp->stream.read = _message_stream_read;
+  sp->stream.readdelim = _message_stream_readdelim;
+  /* FIXME: Write is not defined */
+  /*  sp->stream.write = _message_stream_write;*/
+  sp->stream.done = _message_stream_done;
+  sp->stream.flush = _message_stream_flush;
+  sp->stream.seek = _message_stream_seek; 
+  sp->stream.size = _message_stream_size;
+  sp->state = _mss_init;
+  sp->msg = msg;
+  *pmsg = (mu_stream_t) sp;
+  return 0;
+}
+
+
+enum eoh_state
+  {
+    eoh_no,
+    eoh_maybe,
+    eoh_yes
+  };
+
+/* Message header stuff */
+static enum eoh_state
+string_find_eoh (enum eoh_state eoh, const char *str, size_t len,
+                size_t *ppos)
+{
+  size_t pos;
+
+  if (eoh == eoh_maybe && *str == '\n')
+    {
+      *ppos = 0;
+      return eoh_yes;
+    }
+  
+  for (pos = 0; pos < len - 1; pos++)
+    if (str[pos] == '\n' && str[pos + 1] == '\n')
+      {
+       *ppos = pos + 1;
+       return eoh_yes;
+      }
+  
+  *ppos = pos + 1;
+  return str[pos] == '\n' ? eoh_maybe : eoh_no;
+}
+
+#define MIN_HEADER_BUF_SIZE 2048
+
+static int
+_header_fill (mu_stream_t stream, char **pbuf, size_t *plen)
+{
+  int status = 0;
+  char *buffer = NULL;
+  size_t bufsize = 0;
+  char inbuf[MIN_HEADER_BUF_SIZE];
+  size_t nread;
+  enum eoh_state eoh = eoh_no;
+  
+  status = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
+  if (status)
+    return status;
+      
+  while (eoh != eoh_yes
+        && (status = mu_stream_read (stream, inbuf, sizeof (inbuf), &nread))
+           == 0
+        && nread)
+    {
+      char *nbuf;
+      size_t len;
+
+      eoh = string_find_eoh (eoh, inbuf, nread, &len);
+      
+      nbuf = realloc (buffer, bufsize + len);
+      if (!nbuf)
+       {
+         status = ENOMEM;
+         break;
+       }
+      memcpy (nbuf + bufsize, inbuf, len);
+      buffer = nbuf;
+      bufsize += len;
+    }
+
+  if (status)
+    free (buffer);
+  else
+    {
+      *pbuf = buffer;
+      *plen = bufsize;
+    }
+  return status;
+}
+    
+static int
+message_header_fill (void *data, char **pbuf, size_t *plen)
+{
+  int status = 0;
+  mu_message_t msg = data;
+  mu_stream_t stream;
+
+  status = mu_message_get_streamref (msg, &stream);
+  if (status == 0)
+    {
+      status = _header_fill (stream, pbuf, plen);
+      mu_stream_destroy (&stream);
+    }
+  return status;
+}
+
+
+/* Message envelope */
+static int
+message_envelope_date (mu_envelope_t envelope, char *buf, size_t len,
+                      size_t *pnwrite)
+{
+  mu_message_t msg = mu_envelope_get_owner (envelope);
+  time_t t;
+  size_t n;
+
+  if (msg == NULL)
+    return EINVAL;
+
+  /* FIXME: extract the time from "Date:".  */
+
+  if (buf == NULL || len == 0)
+    {
+      n = MU_ENVELOPE_DATE_LENGTH;
+    }
+  else
+    {
+      char tmpbuf[MU_ENVELOPE_DATE_LENGTH+1];
+      t = time (NULL);
+      n = mu_strftime (tmpbuf, sizeof tmpbuf, 
+                       MU_ENVELOPE_DATE_FORMAT, localtime (&t));
+      n = mu_cpystr (buf, tmpbuf, len);
+    }
+  if (pnwrite)
+    *pnwrite = n;
+  return 0;
+}
+
+static int
+message_envelope_sender (mu_envelope_t envelope, char *buf, size_t len,
+                        size_t *pnwrite)
+{
+  mu_message_t msg = mu_envelope_get_owner (envelope);
+  mu_header_t header = NULL;
+  size_t n = 0;
+  int status;
+
+  if (msg == NULL)
+    return EINVAL;
+
+  /* Can it be extracted from the From:  */
+  mu_message_get_header (msg, &header);
+  status = mu_header_get_value (header, MU_HEADER_FROM, NULL, 0, &n);
+  if (status == 0 && n != 0)
+    {
+      char *sender;
+      mu_address_t address = NULL;
+      sender = calloc (1, n + 1);
+      if (sender == NULL)
+       return ENOMEM;
+      mu_header_get_value (header, MU_HEADER_FROM, sender, n + 1, NULL);
+      if (mu_address_create (&address, sender) == 0)
+       mu_address_get_email (address, 1, buf, n + 1, pnwrite);
+      free (sender);
+      mu_address_destroy (&address);
+      return 0;
+    }
+  else if (status == EAGAIN)
+    return status;
+
+  /* oops! We are still here */
+  {
+    struct mu_auth_data *auth = mu_get_auth_by_uid (getuid ());
+    const char *sender = auth ? auth->name : "unknown";
+    n = strlen (sender);
+    if (buf && len > 0)
+      {
+       len--; /* One for the null.  */
+       n = (n < len) ? n : len;
+       memcpy (buf, auth->name, n);
+       buf[n] = '\0';
+      }
+    if (auth)
+      mu_auth_data_free (auth);
+  }
+
+  if (pnwrite)
+    *pnwrite = n;
+  return 0;
+}
+
+
+
+/*  Allocate ressources for the mu_message_t.  */
+int
+mu_message_create (mu_message_t *pmsg, void *owner)
+{
+  mu_message_t msg;
+  int status;
+
+  if (pmsg == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  msg = calloc (1, sizeof (*msg));
+  if (msg == NULL)
+    return ENOMEM;
+  status = mu_monitor_create (&msg->monitor, 0, msg);
+  if (status != 0)
+    {
+      free (msg);
+      return status;
+    }
+  msg->owner = owner;
+  msg->ref = 1;
+  *pmsg = msg;
+  return 0;
+}
+
+void
+mu_message_destroy (mu_message_t *pmsg, void *owner)
+{
+  if (pmsg && *pmsg)
+    {
+      mu_message_t msg = *pmsg;
+      mu_monitor_t monitor = msg->monitor;
+      int destroy_lock = 0;
+
+      mu_monitor_wrlock (monitor);
+      /* Note: msg->ref may be incremented by mu_message_ref without
+        additional checking for its owner, therefore decrementing
+        it must also occur independently of the owner checking. Due
+        to this inconsistency ref may reach negative values, which
+        is very unfortunate.
+
+        The `owner' stuff is a leftover from older mailutils versions.
+        There is an ongoing attempt to remove it in the stream-cleanup
+        branch. When it is ready, it will be merged to the HEAD and this
+        will finally resolve this issue. */
+      if (msg->ref > 0)
+       msg->ref--;
+      if ((msg->owner && msg->owner == owner)
+         || (msg->owner == NULL && msg->ref <= 0))
+       {
+         destroy_lock =  1;
+         /* Notify the listeners.  */
+         /* FIXME: to be removed since we do not support this event.  */
+         if (msg->observable)
+           {
+             mu_observable_notify (msg->observable, MU_EVT_MESSAGE_DESTROY,
+                                   msg);
+             mu_observable_destroy (&msg->observable, msg);
+           }
+
+         /* Envelope.  */
+         if (msg->envelope)
+           mu_envelope_destroy (&msg->envelope, msg);
+
+         /* Header.  */
+         if (msg->header)
+           mu_header_destroy (&msg->header);
+
+         /* Body.  */
+         if (msg->body)
+           mu_body_destroy (&msg->body, msg);
+
+         /* Attribute.  */
+         if (msg->attribute)
+           mu_attribute_destroy (&msg->attribute, msg);
+
+         /* Stream.  */
+         if (msg->stream)
+           mu_stream_destroy (&msg->stream);
+
+         /*  Mime.  */
+         if (msg->mime)
+           mu_mime_destroy (&msg->mime);
+
+         /* Loose the owner.  */
+         msg->owner = NULL;
+
+         free (msg);
+       }
+      mu_monitor_unlock (monitor);
+      if (destroy_lock)
+       mu_monitor_destroy (&monitor, msg);
+      /* Loose the link */
+      *pmsg = NULL;
+    }
+}
+
+int
+mu_message_create_copy (mu_message_t *to, mu_message_t from)
+{
+  int status = 0;
+  mu_stream_t fromstr = NULL;
+  mu_stream_t tmp = NULL;
+
+  if (!to)
+    return MU_ERR_OUT_PTR_NULL;
+  if (!from)
+    return EINVAL;
+
+  status = mu_memory_stream_create (&tmp, MU_STREAM_RDWR|MU_STREAM_SEEK);
+  if (status)
+    return status;
+
+  status = mu_message_get_streamref (from, &fromstr);
+  if (status)
+    {
+      mu_stream_destroy (&tmp);
+      return status;
+    }
+
+  status = mu_stream_copy (tmp, fromstr, 0, NULL);
+  if (status == 0)
+    {
+      status = mu_message_create (to, NULL);
+      if (status == 0)
+       mu_message_set_stream (*to, tmp, NULL);
+    }
+
+  if (status)
+    mu_stream_destroy (&tmp);
+  mu_stream_destroy (&fromstr);
+
+  return status;
+}
+
+int
+mu_message_ref (mu_message_t msg)
+{
+  if (msg)
+    {
+      mu_monitor_wrlock (msg->monitor);
+      msg->ref++;
+      mu_monitor_unlock (msg->monitor);
+    }
+  return 0;
+}
+
+void *
+mu_message_get_owner (mu_message_t msg)
+{
+  return (msg == NULL) ? NULL : msg->owner;
+}
+
+int
+mu_message_is_modified (mu_message_t msg)
+{
+  int mod = 0;
+  if (msg)
+    {
+      mod |= mu_header_is_modified (msg->header);
+      mod |= mu_attribute_is_modified (msg->attribute);
+      mod |= mu_body_is_modified (msg->body);
+      mod |= msg->flags;
+    }
+  return mod;
+}
+
+int
+mu_message_clear_modified (mu_message_t msg)
+{
+  if (msg)
+    {
+      if (msg->header)
+       mu_header_clear_modified (msg->header);
+      if (msg->attribute)
+       mu_attribute_clear_modified (msg->attribute);
+      if (msg->body)
+       mu_body_clear_modified (msg->body);
+      msg->flags &= ~MESSAGE_MODIFIED;
+    }
+  return 0;
+}
+
+int
+mu_message_get_mailbox (mu_message_t msg, mu_mailbox_t *pmailbox)
+{
+  if (msg == NULL)
+    return EINVAL;
+  if (pmailbox == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  *pmailbox = msg->mailbox;
+  return 0;
+}
+
+int
+mu_message_set_mailbox (mu_message_t msg, mu_mailbox_t mailbox, void *owner)
+{
+  if (msg == NULL)
+    return EINVAL;
+  if (msg->owner != owner)
+    return EACCES;
+  msg->mailbox = mailbox;
+  return 0;
+}
+
+int
+mu_message_get_header (mu_message_t msg, mu_header_t *phdr)
+{
+  if (msg == NULL)
+    return EINVAL;
+  if (phdr == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+
+  if (msg->header == NULL)
+    {
+      mu_header_t header;
+      int status = mu_header_create (&header, NULL, 0);
+      if (status != 0)
+       return status;
+      if (msg->stream)
+       mu_header_set_fill (header, message_header_fill, msg);
+      status = mu_header_size (header, &msg->orig_header_size);
+      if (status)
+       return status;
+      msg->header = header;
+    }
+  *phdr = msg->header;
+  return 0;
+}
+
+/* Note: mu_message_set_header steals the reference to hdr */
+int
+mu_message_set_header (mu_message_t msg, mu_header_t hdr, void *owner)
+{
+  if (msg == NULL )
+    return EINVAL;
+  if (msg->owner != owner)
+     return EACCES;
+  if (msg->header)
+    mu_header_destroy (&msg->header);
+  msg->header = hdr;
+  msg->flags |= MESSAGE_MODIFIED;
+  return 0;
+}
+
+int
+mu_message_get_body (mu_message_t msg, mu_body_t *pbody)
+{
+  if (msg == NULL)
+    return EINVAL;
+  if (pbody == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+
+  /* Is it a floating mesg.  */
+  if (msg->body == NULL)
+    {
+      mu_body_t body;
+      int status = mu_body_create (&body, msg);
+      if (status != 0)
+       return status;
+      /* If a stream is already set, use it to create the body stream.  */
+      /* FIXME: I'm not sure if the second condition is really needed */
+      if (msg->stream/* && (msg->flags & MESSAGE_INTERNAL_STREAM)*/)
+       {
+         mu_stream_t stream;
+         int flags = 0;
+
+         /* FIXME: The actual mu_header_size cannot be used as offset,
+            because the headers might have been modified in between. */
+         
+         mu_stream_get_flags (msg->stream, &flags);
+         status = mu_streamref_create_abridged (&stream, msg->stream,
+                                                msg->orig_header_size, 0);
+         if (status)
+           {
+             mu_body_destroy (&body, msg);
+             return status;
+           }
+         mu_body_set_stream (body, stream, msg);
+       }
+      msg->body = body;
+    }
+  *pbody = msg->body;
+  return 0;
+}
+
+int
+mu_message_set_body (mu_message_t msg, mu_body_t body, void *owner)
+{
+  if (msg == NULL )
+    return EINVAL;
+  if (msg->owner != owner)
+    return EACCES;
+  /* Make sure we destroy the old if it was owned by the mesg.  */
+  /* FIXME:  I do not know if somebody has already a ref on this ? */
+  if (msg->body)
+    mu_body_destroy (&msg->body, msg);
+  msg->body = body;
+  msg->flags |= MESSAGE_MODIFIED;
+  return 0;
+}
+
+int
+mu_message_set_stream (mu_message_t msg, mu_stream_t stream, void *owner)
+{
+  if (msg == NULL)
+    return EINVAL;
+  if (msg->owner != owner)
+    return EACCES;
+  if (msg->stream)
+    mu_stream_destroy (&msg->stream);
+  msg->stream = stream;
+  msg->flags |= MESSAGE_MODIFIED;
+  msg->flags &= ~MESSAGE_INTERNAL_STREAM;
+  return 0;
+}
+
+static int
+_message_get_stream (mu_message_t msg, mu_stream_t *pstream, int ref)
+{
+  int status;
+
+  if (msg == NULL)
+    return EINVAL;
+  if (pstream == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+
+  if (msg->stream == NULL)
+    {
+      if (msg->_get_stream)
+       {
+         status = msg->_get_stream (msg, &msg->stream);
+         if (status)
+           return status;
+       }
+      else
+       {
+         mu_header_t hdr;
+         mu_body_t body;
+
+         /* FIXME: Kind of a kludge: make sure the message has header
+            and body initialized. */
+         status = mu_message_get_header (msg, &hdr);
+         if (status)
+           return status;
+         status = mu_message_get_body (msg, &body);
+         if (status)
+           return status;
+         
+         status = _message_stream_create (&msg->stream, msg, MU_STREAM_RDWR);
+         if (status)
+           return status;
+         msg->flags |= MESSAGE_INTERNAL_STREAM;
+       }
+    }
+  
+  if (!ref)
+    {
+      *pstream = msg->stream;
+      return 0;
+    }
+  return mu_streamref_create (pstream, msg->stream);
+}
+
+int
+mu_message_get_stream (mu_message_t msg, mu_stream_t *pstream)
+{
+  /* FIXME: Deprecation warning */
+  return _message_get_stream (msg, pstream, 0);
+}
+
+int
+mu_message_get_streamref (mu_message_t msg, mu_stream_t *pstream)
+{
+  return _message_get_stream (msg, pstream, 1);
+}
+
+int
+mu_message_set_get_stream (mu_message_t msg,
+                          int (*_getstr) (mu_message_t, mu_stream_t *),
+                          void *owner)
+{
+  if (msg == NULL)
+    return EINVAL;
+  if (msg->owner != owner)
+    return EACCES;
+  msg->_get_stream = _getstr;
+  return 0;
+}
+
+int
+mu_message_set_lines (mu_message_t msg, int (*_lines)
+                  (mu_message_t, size_t *), void *owner)
+{
+  if (msg == NULL)
+    return EINVAL;
+  if (msg->owner != owner)
+    return EACCES;
+  msg->_lines = _lines;
+  return 0;
+}
+
+int
+mu_message_lines (mu_message_t msg, size_t *plines)
+{
+  size_t hlines, blines;
+  int ret = 0;
+
+  if (msg == NULL)
+    return EINVAL;
+  /* Overload.  */
+  if (msg->_lines)
+    return msg->_lines (msg, plines);
+  if (plines)
+    {
+      hlines = blines = 0;
+      if ( ( ret = mu_header_lines (msg->header, &hlines) ) == 0 )
+             ret = mu_body_lines (msg->body, &blines);
+      *plines = hlines + blines;
+    }
+  return ret;
+}
+
+int
+mu_message_set_size (mu_message_t msg, int (*_size)
+                 (mu_message_t, size_t *), void *owner)
+{
+  if (msg == NULL)
+    return EINVAL;
+  if (msg->owner != owner)
+    return EACCES;
+  msg->_size = _size;
+  return 0;
+}
+
+int
+mu_message_size (mu_message_t msg, size_t *psize)
+{
+  size_t hsize, bsize;
+  int ret = 0;
+
+  if (msg == NULL)
+    return EINVAL;
+  /* Overload ? */
+  if (msg->_size)
+    return msg->_size (msg, psize);
+  if (psize)
+    {
+      mu_header_t hdr = NULL;
+      mu_body_t body = NULL;
+      
+      hsize = bsize = 0;
+      mu_message_get_header (msg, &hdr);
+      mu_message_get_body (msg, &body);
+      if ( ( ret = mu_header_size (hdr, &hsize) ) == 0 )
+       ret = mu_body_size (body, &bsize);
+      *psize = hsize + bsize;
+    }
+  return ret;
+}
+
+int
+mu_message_get_envelope (mu_message_t msg, mu_envelope_t *penvelope)
+{
+  if (msg == NULL)
+    return EINVAL;
+  if (penvelope == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+
+  if (msg->envelope == NULL)
+    {
+      mu_envelope_t envelope;
+      int status = mu_envelope_create (&envelope, msg);
+      if (status != 0)
+       return status;
+      mu_envelope_set_sender (envelope, message_envelope_sender, msg);
+      mu_envelope_set_date (envelope, message_envelope_date, msg);
+      msg->envelope = envelope;
+    }
+  *penvelope = msg->envelope;
+  return 0;
+}
+
+int
+mu_message_set_envelope (mu_message_t msg, mu_envelope_t envelope, void *owner)
+{
+  if (msg == NULL)
+    return EINVAL;
+  if (msg->owner != owner)
+    return EACCES;
+  if (msg->envelope)
+    mu_envelope_destroy (&msg->envelope, msg);
+  msg->envelope = envelope;
+  msg->flags |= MESSAGE_MODIFIED;
+  return 0;
+}
+
+int
+mu_message_get_attribute (mu_message_t msg, mu_attribute_t *pattribute)
+{
+  if (msg == NULL)
+    return EINVAL;
+  if (pattribute == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  if (msg->attribute == NULL)
+    {
+      mu_attribute_t attribute;
+      int status = mu_attribute_create (&attribute, msg);
+      if (status != 0)
+       return status;
+      msg->attribute = attribute;
+    }
+  *pattribute = msg->attribute;
+  return 0;
+}
+
+int
+mu_message_set_attribute (mu_message_t msg, mu_attribute_t attribute, void 
*owner)
+{
+  if (msg == NULL)
+   return EINVAL;
+  if (msg->owner != owner)
+    return EACCES;
+  if (msg->attribute)
+    mu_attribute_destroy (&msg->attribute, owner);
+  msg->attribute = attribute;
+  msg->flags |= MESSAGE_MODIFIED;
+  return 0;
+}
+
+int
+mu_message_get_uid (mu_message_t msg, size_t *puid)
+{
+  if (msg == NULL)
+    return EINVAL;
+  if (msg->_get_uid)
+    return msg->_get_uid (msg, puid);
+  *puid = 0;
+  return 0;
+}
+
+int
+mu_message_get_uidl (mu_message_t msg, char *buffer, size_t buflen,
+                    size_t *pwriten)
+{
+  mu_header_t header = NULL;
+  size_t n = 0;
+  int status;
+
+  if (msg == NULL || buffer == NULL || buflen == 0)
+    return EINVAL;
+
+  buffer[0] = '\0';
+  /* Try the function overload if error fallback.  */
+  if (msg->_get_uidl)
+    {
+      status = msg->_get_uidl (msg, buffer, buflen, pwriten);
+      if (status == 0)
+       return status;
+    }
+
+  /* Be compatible with Qpopper ? qppoper saves the UIDL in "X-UIDL".
+     We generate a chksum and save it in the header.  */
+  mu_message_get_header (msg, &header);
+  status = mu_header_get_value_unfold (header, "X-UIDL", buffer, buflen, &n);
+  if (status != 0 || n == 0)
+    {
+      size_t uid = 0;
+      struct mu_md5_ctx md5context;
+      mu_stream_t stream = NULL;
+      char buf[1024];
+      unsigned char md5digest[16];
+      char *tmp;
+      n = 0;
+      mu_message_get_uid (msg, &uid);
+      mu_message_get_streamref (msg, &stream);
+      mu_md5_init_ctx (&md5context);
+      status = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
+      if (status == 0)
+       {
+         while (mu_stream_read (stream, buf, sizeof (buf), &n) == 0
+                && n > 0)
+           mu_md5_process_bytes (buf, n, &md5context);
+         mu_md5_finish_ctx (&md5context, md5digest);
+         tmp = buf;
+         for (n = 0; n < 16; n++, tmp += 2)
+           sprintf (tmp, "%02x", md5digest[n]);
+         *tmp = '\0';
+         /* POP3 rfc says that an UID should not be longer than 70.  */
+         snprintf (buf + 32, 70, ".%lu.%lu", (unsigned long)time (NULL), 
+                   (unsigned long) uid);
+
+         mu_header_set_value (header, "X-UIDL", buf, 1);
+         buflen--; /* leave space for the NULL.  */
+         strncpy (buffer, buf, buflen)[buflen] = '\0';
+       }
+      mu_stream_destroy (&stream);
+    }
+  return status;
+}
+
+int
+mu_message_get_qid (mu_message_t msg, mu_message_qid_t *pqid)
+{
+  if (msg == NULL)
+    return EINVAL;
+  if (!msg->_get_qid)
+    return ENOSYS;
+  return msg->_get_qid (msg, pqid);
+}
+    
+int
+mu_message_set_qid (mu_message_t msg,
+                   int (*_get_qid) (mu_message_t, mu_message_qid_t *),
+                   void *owner)
+{
+  if (msg == NULL)
+    return EINVAL;
+  if (msg->owner != owner)
+    return EACCES;
+  msg->_get_qid = _get_qid;
+  return 0;
+}
+
+int
+mu_message_set_uid (mu_message_t msg, int (*_get_uid) (mu_message_t, size_t *),
+                   void *owner)
+{
+  if (msg == NULL)
+    return EINVAL;
+  if (msg->owner != owner)
+    return EACCES;
+  msg->_get_uid = _get_uid;
+  return 0;
+}
+
+int
+mu_message_set_uidl (mu_message_t msg,
+                 int (* _get_uidl) (mu_message_t, char *, size_t, size_t *),
+                 void *owner)
+{
+  if (msg == NULL)
+    return EINVAL;
+  if (msg->owner != owner)
+    return EACCES;
+  msg->_get_uidl = _get_uidl;
+  return 0;
+}
+
+int
+mu_message_set_is_multipart (mu_message_t msg,
+                         int (*_is_multipart) (mu_message_t, int *),
+                         void *owner)
+{
+  if (msg == NULL)
+    return EINVAL;
+  if (msg->owner != owner)
+    return EACCES;
+  msg->_is_multipart = _is_multipart;
+  return 0;
+}
+
+int
+mu_message_is_multipart (mu_message_t msg, int *pmulti)
+{
+  if (msg && pmulti)
+    {
+      if (msg->_is_multipart)
+       return msg->_is_multipart (msg, pmulti);
+      if (msg->mime == NULL)
+       {
+         int status = mu_mime_create (&msg->mime, msg, 0);
+         if (status != 0)
+           return 0;
+       }
+      *pmulti = mu_mime_is_multipart(msg->mime);
+    }
+  return 0;
+}
+
+int
+mu_message_get_num_parts (mu_message_t msg, size_t *pparts)
+{
+  if (msg == NULL || pparts == NULL)
+    return EINVAL;
+
+  if (msg->_get_num_parts)
+    return msg->_get_num_parts (msg, pparts);
+
+  if (msg->mime == NULL)
+    {
+      int status = mu_mime_create (&msg->mime, msg, 0);
+      if (status != 0)
+       return status;
+    }
+  return mu_mime_get_num_parts (msg->mime, pparts);
+}
+
+int
+mu_message_set_get_num_parts (mu_message_t msg,
+                          int (*_get_num_parts) (mu_message_t, size_t *),
+                          void *owner)
+{
+  if (msg == NULL)
+    return EINVAL;
+  if (msg->owner != owner)
+    return EACCES;
+  msg->_get_num_parts = _get_num_parts;
+  return 0;
+}
+
+int
+mu_message_get_part (mu_message_t msg, size_t part, mu_message_t *pmsg)
+{
+  if (msg == NULL || pmsg == NULL)
+    return EINVAL;
+
+  /* Overload.  */
+  if (msg->_get_part)
+    return msg->_get_part (msg, part, pmsg);
+
+  if (msg->mime == NULL)
+    {
+      int status = mu_mime_create (&msg->mime, msg, 0);
+      if (status != 0)
+       return status;
+    }
+  return mu_mime_get_part (msg->mime, part, pmsg);
+}
+
+int
+mu_message_set_get_part (mu_message_t msg, int (*_get_part)
+                     (mu_message_t, size_t, mu_message_t *),
+                     void *owner)
+{
+  if (msg == NULL)
+    return EINVAL;
+  if (msg->owner != owner)
+    return EACCES;
+  msg->_get_part = _get_part;
+  return 0;
+}
+
+int
+mu_message_get_observable (mu_message_t msg, mu_observable_t *pobservable)
+{
+  if (msg == NULL || pobservable == NULL)
+    return EINVAL;
+
+  if (msg->observable == NULL)
+    {
+      int status = mu_observable_create (&msg->observable, msg);
+      if (status != 0)
+       return status;
+    }
+  *pobservable = msg->observable;
+  return 0;
+}
+
+int
+mu_message_save_to_mailbox (mu_message_t msg, 
+                            mu_debug_t debug,
+                           const char *toname, int perms)
+{
+  int rc = 0;
+  mu_mailbox_t to = 0;
+
+  if ((rc = mu_mailbox_create_default (&to, toname)))
+    {
+      MU_DEBUG2 (debug, MU_DEBUG_ERROR,
+                "mu_mailbox_create_default (%s) failed: %s\n", toname,
+                mu_strerror (rc));
+      goto end;
+    }
+
+  if (debug && (rc = mu_mailbox_set_debug (to, debug)))
+       goto end;
+
+  if ((rc = mu_mailbox_open (to,
+                            MU_STREAM_WRITE | MU_STREAM_CREAT
+                            | (perms & MU_STREAM_IMASK))))
+    {
+      MU_DEBUG2 (debug, MU_DEBUG_ERROR,
+                "mu_mailbox_open (%s) failed: %s\n", toname,
+                mu_strerror (rc));
+      goto end;
+    }
+
+  if ((rc = mu_mailbox_append_message (to, msg)))
+    {
+      MU_DEBUG2 (debug, MU_DEBUG_ERROR,
+                "mu_mailbox_append_message (%s) failed: %s\n", toname,
+                mu_strerror (rc));
+      goto end;
+    }
+
+end:
+
+  if (!rc)
+    {
+      if ((rc = mu_mailbox_close (to)))
+       MU_DEBUG2 (debug, MU_DEBUG_ERROR,
+                  "mu_mailbox_close (%s) failed: %s\n", toname,
+                  mu_strerror (rc));
+    }
+  else
+    mu_mailbox_close (to);
+
+  mu_mailbox_destroy (&to);
+
+  return rc;
+}
+
diff --git a/libmailutils/msgscan.c b/libmailutils/mailbox/msgscan.c
similarity index 100%
rename from libmailutils/msgscan.c
rename to libmailutils/mailbox/msgscan.c
diff --git a/libmailutils/mailcap.c b/libmailutils/mailcap.c
deleted file mode 100644
index 8d8c700..0000000
--- a/libmailutils/mailcap.c
+++ /dev/null
@@ -1,740 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2003, 2004, 2005, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include <mailutils/cctype.h>
-#include <mailutils/mailcap.h>
-#include <mailutils/stream.h>
-#include <mailutils/mutil.h>
-#include <mailutils/cstr.h>
-
-/* Definition of the structure, this should be in mailutils/sys/mailcap.h.  */
-struct _mu_mailcap_entry
-{
-  char * typefield;
-  char * viewcommand;
-  char ** fields;
-  size_t fields_count;
-};
-
-/* Definition of the structure, this should be in mailutils/sys/mailcap.h.  */
-struct _mu_mailcap
-{
-  mu_mailcap_entry_t *entries;
-  size_t entries_count;
-};
-
-
-static int mu_mailcap_parse (mu_mailcap_t mailcap, mu_stream_t stream);
-static int mu_mailcap_parse_entry (mu_mailcap_entry_t entry, char *buffer);
-static char * tokenize (char *s, char **save_ptr);
-
-int
-mu_mailcap_create (mu_mailcap_t * pmailcap, mu_stream_t stream)
-{
-  mu_mailcap_t mailcap;
-  int status = 0;
-
-  if (stream == NULL)
-    return EINVAL;
-  if (pmailcap == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-
-  mailcap = calloc (1, sizeof (*mailcap));
-  if (mailcap != NULL)
-    {
-      status = mu_mailcap_parse (mailcap, stream);
-      if (status != 0)
-       {
-         mu_mailcap_destroy (&mailcap);
-       }
-      else
-       {
-         *pmailcap = mailcap;
-       }
-    }
-  else
-    {
-      status = ENOMEM;
-    }
-  return status;
-}
-
-void
-mu_mailcap_destroy (mu_mailcap_t * pmailcap)
-{
-  if (pmailcap != NULL && *pmailcap != NULL)
-    {
-      int i;
-      mu_mailcap_t mailcap = *pmailcap;
-
-      for (i = 0; i < mailcap->entries_count; i++)
-       {
-         int j;
-         mu_mailcap_entry_t entry = mailcap->entries[i];
-         free (entry->typefield);
-         free (entry->viewcommand);
-         for (j = 0; j < entry->fields_count; j++)
-           {
-             free (entry->fields[j]);
-           }
-       }
-    }
-}
-
-int
-mu_mailcap_entries_count (mu_mailcap_t mailcap, size_t *pcount)
-{
-  int status = 0;
-
-  if (mailcap == NULL)
-    status = EINVAL;
-  if (pcount != NULL)
-    {
-      *pcount = mailcap->entries_count;
-    }
-  return status;
-}
-
-int
-mu_mailcap_get_entry (mu_mailcap_t mailcap, size_t no,
-                     mu_mailcap_entry_t *pentry)
-{
-  int status = 0;
-  if (mailcap == NULL)
-    status = EINVAL;
-  else if (pentry == NULL)
-    status = MU_ERR_OUT_PTR_NULL;
-  else if (no == 0 || no > mailcap->entries_count)
-    {
-      status = MU_ERR_NOENT;
-    }
-  else
-    {
-      *pentry = mailcap->entries[no - 1];
-    }
-  return status;
-}
-
-int
-mu_mailcap_entry_get_typefield (mu_mailcap_entry_t entry, char *buffer,
-                               size_t buflen, size_t *pn)
-{
-  int status = 0;
-  int len = 0;
-
-  if (entry == NULL)
-    {
-      status = EINVAL;
-    }
-  else
-    {
-      len = strlen(entry->typefield);
-      if (buffer != NULL && buflen > 0)
-       {
-         buflen--;
-         len = (len < buflen) ? len : buflen;
-         memcpy (buffer, entry->typefield, len);
-         buffer[len] = '\0';
-       }
-    }
-  if (pn)
-    {
-      *pn = len;
-    }
-  return status;
-}
-
-int
-mu_mailcap_entry_get_viewcommand (mu_mailcap_entry_t entry, char *buffer,
-                                 size_t buflen, size_t *pn)
-{
-  int status = 0;
-  int len = 0;
-
-  if (entry == NULL)
-    {
-      status = EINVAL;
-    }
-  else
-    {
-      len = strlen(entry->viewcommand);
-      if (buffer != NULL && buflen > 0)
-       {
-         buflen--;
-         len = (len < buflen) ? len : buflen;
-         memcpy (buffer, entry->viewcommand, len);
-         buffer[len] = '\0';
-       }
-    }
-  if (pn)
-    {
-      *pn = len;
-    }
-  return status;
-}
-
-int
-mu_mailcap_entry_fields_count (mu_mailcap_entry_t entry, size_t *pcount)
-{
-  int status = 0;
-  if (entry == NULL)
-    {
-      status = EINVAL;
-    }
-  if (pcount != NULL)
-    {
-      *pcount = entry->fields_count;
-    }
-  return status;
-}
-
-int
-mu_mailcap_entry_get_field (mu_mailcap_entry_t entry, size_t no,
-                           char *buffer, size_t buflen, size_t *pn)
-{
-  int status = 0;
-  int len = 0;
-
-  if (entry == NULL)
-    {
-      status = EINVAL;
-    }
-  else if ( no == 0 || no > entry->fields_count)
-    {
-      status = MU_ERR_NOENT;
-    }
-  else
-    {
-      len = strlen(entry->fields[no - 1]);
-      if (buffer != NULL && buflen > 0)
-       {
-         buflen--;
-         len = (len < buflen) ? len : buflen;
-         memcpy (buffer, entry->fields[no - 1], len);
-         buffer[len] = '\0';
-       }
-    }
-  if (pn)
-    {
-      *pn = len;
-    }
-  return status;
-}
-
-int
-mu_mailcap_entry_get_compose (mu_mailcap_entry_t entry,
-                             char *buffer, size_t buflen, size_t *pn)
-{
-  return mu_mailcap_entry_get_value (entry, "compose", buffer, buflen, pn);
-}
-
-int
-mu_mailcap_entry_get_composetyped (mu_mailcap_entry_t entry, char *buffer,
-                                  size_t buflen, size_t *pn)
-{
-  return mu_mailcap_entry_get_value (entry, "composetyped", buffer, buflen, 
pn);
-}
-
-int
-mu_mailcap_entry_get_edit (mu_mailcap_entry_t entry, char *buffer,
-                          size_t buflen, size_t *pn)
-{
-  return mu_mailcap_entry_get_value (entry, "edit", buffer, buflen, pn);
-}
-
-int
-mu_mailcap_entry_get_test (mu_mailcap_entry_t entry,
-                          char *buffer, size_t buflen, size_t *pn)
-{
-  return mu_mailcap_entry_get_value (entry, "test", buffer, buflen, pn);
-}
-
-int
-mu_mailcap_entry_get_x11bitmap (mu_mailcap_entry_t entry,
-                               char *buffer, size_t buflen, size_t *pn)
-{
-  return mu_mailcap_entry_get_value (entry, "x11-bitmap", buffer, buflen, pn);
-}
-
-int
-mu_mailcap_entry_get_description (mu_mailcap_entry_t entry,
-                                 char *buffer, size_t buflen, size_t *pn)
-{
-  return mu_mailcap_entry_get_value (entry, "description", buffer, buflen, pn);
-}
-
-int
-mu_mailcap_entry_needsterminal (mu_mailcap_entry_t entry, int *on)
-{
-  int status = 0;
-  int found = 0;
-  if (entry == NULL)
-    {
-      status = EINVAL;
-    }
-  else
-    {
-      int i;
-      for (i = 0; i < entry->fields_count; i++)
-       {
-         int n = mu_c_strcasecmp (entry->fields[i], "needsterminal");
-         if (n == 0)
-           {
-             found = 1;
-             break;
-           }
-       }
-    }
-  if (on)
-    *on = found;
-  return status;
-}
-
-int
-mu_mailcap_entry_copiousoutput (mu_mailcap_entry_t entry, int *on)
-{
-  int status = 0;
-  int found = 0;
-  if (entry == NULL)
-    {
-      status = EINVAL;
-    }
-  else
-    {
-      int i;
-      for (i = 0; i < entry->fields_count; i++)
-       {
-         int n = mu_c_strcasecmp (entry->fields[i], "copiousoutput");
-         if (n == 0)
-           {
-             found = 1;
-             break;
-           }
-       }
-    }
-  if (on)
-    *on = found;
-  return status;
-}
-
-int
-mu_mailcap_entry_get_value (mu_mailcap_entry_t entry, const char *key,
-                           char *buffer, size_t buflen, size_t *pn)
-{
-  int len = 0;
-  int status = ENOENT;
-
-  if (!entry)
-    status = EINVAL;
-  else
-    {
-      int i;
-      int key_len = strlen (key);
-      for (i = 0; i < entry->fields_count; i++)
-       {
-         int n = mu_c_strncasecmp (entry->fields[i], key, key_len);
-         if (n == 0)
-           {
-             int field_len = strlen(entry->fields[i]);
-             status = 0;
-             if (field_len > key_len)
-               {
-                 int c = entry->fields[i][key_len];
-                 if (mu_isspace (c) || c == '=')
-                   {
-                     char *value = strchr (entry->fields[i], '=');
-                     if (value != NULL)
-                       {
-                         value++; /* Pass the equal.  */
-                         /* Remove leading space.  */
-                         for (; mu_isspace (*value); value++)
-                           ;
-                         len = strlen (value);
-                         /* Strip surrounding double quotes */
-                         if (len > 1 && value[0] == '"' && value[len - 1] == 
'"')
-                           {
-                             value++;
-                             len -= 2;
-                           }
-                         if (buffer != NULL && buflen > 0)
-                           {
-                             buflen--;
-                             len = (len < buflen) ? len : buflen;
-                             memcpy (buffer, value, len);
-                             buffer[len] = '\0';
-                           }
-                         break;
-                       }
-                   }
-               }
-           }
-       }
-    }
-  if (pn)
-    *pn = len;
-  return status;
-}
-
-/*
- * break the line on ';'.  Same as strtok() but
- * check for escaped "\;"
- */
-static char *
-tokenize (char *s, char **save_ptr)
-{
-  int c;
-  char *token;
-
-  if (s == NULL)
-    {
-      s = *save_ptr;
-    }
-
-  if (*s == '\0')
-    {
-      *save_ptr = s;
-      return NULL;
-    }
-
-  for (token = s, c = 0; *s; s++)
-    {
-      if (*s == ';' && c != '\\')
-       {
-         break;
-       }
-      c = *s;
-    }
-
-  if (*s == '\0')
-    {
-      *save_ptr = s;
-    }
-  else
-    {
-      *s = '\0';
-      *save_ptr = s + 1;
-    }
-  return token;
-}
-
-/**
- * parse the mailcap line, fields are separated by ';'
- */
-static int
-mu_mailcap_parse_entry (mu_mailcap_entry_t entry, char *buffer)
-{
-  char *token = NULL;
-  char *s = NULL;
-  int i;
-  for (i = 0, token = tokenize (buffer, &s);
-       token != NULL; token = tokenize (NULL, &s), i++)
-    {
-      switch (i)
-       {
-         /* The first entry in a mailcap line is the typefield.  */
-       case 0:
-         entry->typefield = strdup (mu_str_stripws (token));
-         break;
-
-         /* The second entry in a mailcap line is the view-command.  */
-       case 1:
-         entry->viewcommand = strdup (mu_str_stripws (token));
-         break;
-
-         /* The rest are the optional fields.  */
-       default:
-         {
-           char **fields = realloc (entry->fields,
-                                    (entry->fields_count + 1) *
-                                    sizeof (*fields));
-           if (fields != NULL)
-             {
-               entry->fields = fields;
-               entry->fields[entry->fields_count] =
-                 strdup (mu_str_stripws (token));
-               entry->fields_count++;
-             }
-         }
-       }
-    }
-  /* Make sure typefield and viewcommand are not null.  */
-  if (entry->typefield == NULL)
-    {
-      entry->typefield = strdup ("");
-    }
-  if (entry->viewcommand == NULL)
-    {
-      entry->viewcommand = strdup ("");
-    }
-  return 0;
-}
-
-/*
- * parse a mailcap file or stream,
- * - ignore empty line.
- * - ignore line starting with '#'
- * - multiline is done with the '\' as continuation
- * example:
-# comment
-application/pgp; gpg < %s | metamail; needsterminal; \
- test=test %{encapsulation}=entity ; copiousoutput
- */
-static int
-mu_mailcap_parse (mu_mailcap_t mailcap, mu_stream_t stream)
-{
-  int status;
-  size_t n;
-  char *previous;
-  char *buffer;
-  size_t buflen = 512;
-
-  buffer = malloc (buflen);
-  if (buffer == NULL)
-    {
-      return ENOMEM;
-    }
-
-  /*
-   * We are doing this a little more complex then expected, because we do not
-   * want to seek() back in the stream:
-   * - we have to take care of continuation line i.e. line ending with '\'
-   * - we have to take to account that the line may be bigger then the buffer
-   *   and reallocate
-   * - check the return of malloc/realloc
-   * The old continuation line is saved in the "previous" pointer and
-   * prepended to the buffer.
-   */
-  status = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
-  if (status)
-    return status;
-  previous = NULL;
-  while ((status = mu_stream_readline (stream, buffer, buflen, &n)) == 0
-        && n > 0)
-    {
-      int len;
-
-      /* If there is no trailing newline, that means the buffer was too small,
-       * make room for the buffer and continue reading  */
-      if (buffer[n - 1] != '\n')
-        {
-         char *b = realloc (buffer, buflen * sizeof (*buffer));
-          buflen *= 2;
-          if (b == NULL)
-           {
-             status = ENOMEM;
-             break;
-           }
-         buffer = b;
-         /*
-          * Fake this as a continuation line, for simplicity.
-          */
-         strcat (buffer, "\\");
-        }
-      else
-       {
-         /* Nuke the trailing newline.  */
-         buffer[n - 1] = '\0';
-       }
-
-      /* recalculate the len.  */
-      len = strlen (buffer);
-
-      /* Ending with a '\' means continuation line.  */
-      if (len && buffer[len - 1] == '\\')
-       {
-         buffer[len - 1] = '\0';
-         /*
-          * Check for any previous line:
-          * - if yes append the buffer to the previous line.
-          * - if not set the buffer as the previous line and continue.
-          */
-         if (previous == NULL)
-           {
-             previous = strdup (buffer);
-             if (previous == NULL)
-               {
-                 status = ENOMEM;
-                 break;
-               }
-           }
-         else
-           {
-             char *b = realloc (previous, strlen (previous) + len + 1);
-             if (b == NULL)
-               {
-                 status = ENOMEM;
-                 break;
-               }
-             previous = b;
-             strcat(previous, buffer);
-           }
-       }
-      else
-       {
-         /* Did we have a previous incomplete line?
-          * if yes make one line from the previous and the buffer.
-          */
-         if (previous != NULL)
-           {
-             int prev_len = strlen (previous);
-             int total =  prev_len + len + 1;
-             if (total > buflen)
-               {
-                 char *b = realloc (buffer, total * sizeof (*buffer));
-                 if (b == NULL)
-                   {
-                     status = ENOMEM;
-                     break;
-                   }
-                 buffer = b;
-                 buflen = total;
-               }
-             memmove (buffer + prev_len, buffer, len + 1);
-             memcpy (buffer, previous, prev_len);
-             free (previous);
-             previous = NULL;
-           }
-       }
-
-      /* Parse the well-form mailcap line entry.  */
-      if (previous == NULL) {
-       /* Nuke the trailing/prepend spaces.  */
-       char *line = mu_str_stripws (buffer);
-       /* Ignore comments or empty lines  */
-       if (*line != '#' && *line != '\0')
-         {
-           mu_mailcap_entry_t *entries;
-           entries = realloc (mailcap->entries,
-                              (mailcap->entries_count + 1) *
-                              sizeof (*entries));
-           if (entries != NULL)
-             {
-               mailcap->entries = entries;
-               mailcap->entries[mailcap->entries_count] = calloc (1,
-                                                          sizeof(**entries));
-               if (mailcap->entries[mailcap->entries_count] != NULL)
-                 {
-                   mu_mailcap_parse_entry 
(mailcap->entries[mailcap->entries_count], line);
-                 }
-               mailcap->entries_count++;
-             }
-           else
-             {
-               status = ENOMEM;
-               break;
-             }
-         }
-      }
-    }
-
-  if (buffer != NULL)
-    {
-      free (buffer);
-    }
-  if (previous != NULL)
-    {
-      free (previous);
-    }
-  return status;
-}
-
-#ifdef STANDALONE_TEST
-int main()
-{
-  mu_stream_t stream = NULL;
-  int status = 0;
-
-  status = mu_file_stream_create (&stream, "/home/alain/mailcap",
-                                 MU_STREAM_READ);
-  if (status == 0)
-    {
-      mu_mailcap_t mailcap;
-      status = mu_mailcap_create (&mailcap, stream);
-      if (status == 0)
-       {
-         int i, n;
-         size_t count = 0;
-         char buffer[256];
-         
-         mu_mailcap_entries_count (mailcap, &count);
-         for (i = 1; i <= count; i++)
-           {
-             int j;
-             mu_mailcap_entry_t entry = NULL;
-             int fields_count = 0;
-             
-             printf ("entry[%d]\n", i);
-#if 1
-             
-             mu_mailcap_get_entry (mailcap, i, &entry);
-             /* Print typefield.  */
-             mu_mailcap_entry_get_typefield (entry, buffer,
-                                             sizeof (buffer), NULL);
-             printf ("\ttypefield: %s\n", buffer);
-             
-             /* Print view-command.  */
-             mu_mailcap_entry_get_viewcommand (entry, buffer,
-                                               sizeof (buffer), NULL);
-             printf ("\tview-command: %s\n", buffer);
-             
-             /* Print fields.  */
-             mu_mailcap_entry_fields_count (entry, &fields_count);
-             for (j = 1; j <= fields_count; j++)
-               {
-                 mu_mailcap_entry_get_field (entry, j, buffer,
-                                             sizeof (buffer), NULL);
-                 printf("\tfields[%d]: %s\n", j, buffer);
-               }
-             n = 0;
-             mu_mailcap_entry_get_compose (entry, buffer,
-                                           sizeof (buffer), &n);
-             if (n > 0)
-               {
-                 printf("\tcompose[%s]\n", buffer);
-               }
-             printf("\n");
-           }
-#else
-         for (i = 0; i < mailcap->entries_count; i++)
-           {
-             int j;
-             mu_mailcap_entry_t entry = mailcap->entries[i];
-             printf("[%s];[%s]", entry->typefield, entry->viewcommand);
-             for (j = 0; j < entry->fields_count; j++)
-               {
-                 printf(";[%s]", entry->fields[j]);
-               }
-             printf("\n");
-           }
-#endif
-         mu_mailcap_destroy (&mailcap);
-       }
-    }
-  return 0;
-}
-
-#endif
diff --git a/libmailutils/mailer.c b/libmailutils/mailer.c
deleted file mode 100644
index 8faf778..0000000
--- a/libmailutils/mailer.c
+++ /dev/null
@@ -1,698 +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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include <sys/time.h>
-
-#include <mailutils/cstr.h>
-#include <mailutils/address.h>
-#include <mailutils/debug.h>
-#include <mailutils/errno.h>
-#include <mailutils/iterator.h>
-#include <mailutils/list.h>
-#include <mailutils/observer.h>
-#include <mailutils/property.h>
-#include <mailutils/registrar.h>
-#include <mailutils/stream.h>
-#include <mailutils/url.h>
-#include <mailutils/header.h>
-#include <mailutils/body.h>
-#include <mailutils/mailbox.h>
-#include <mailutils/message.h>
-#include <mailutils/argcv.h>
-#include <mailutils/mutil.h>
-#include <mailutils/mime.h>
-#include <mailutils/io.h>
-
-#include <mailutils/sys/mailer.h>
-
-static char *mailer_url_default;
-
-/* FIXME: I'd like to check that the URL is valid, but that requires that the
-   mailers already be registered! */
-int
-mu_mailer_set_url_default (const char *url)
-{
-  char *n = NULL;
-
-  if (!url)
-    return EINVAL;
-
-  if ((n = strdup (url)) == NULL)
-    return ENOMEM;
-
-  if (mailer_url_default)
-    free (mailer_url_default);
-
-  mailer_url_default = n;
-
-  return 0;
-}
-
-int
-mu_mailer_get_url_default (const char **url)
-{
-  if (!url)
-    return EINVAL;
-
-  if (mailer_url_default)
-    *url = mailer_url_default;
-  else
-    *url = MAILER_URL_DEFAULT;
-
-  return 0;
-}
-
-static void
-set_default_debug (mu_mailer_t mailer)
-{
-  mu_log_level_t level = mu_global_debug_level ("mailer");
-  if (level)
-    {
-      mu_debug_t debug;
-      if (mu_mailer_get_debug (mailer, &debug))
-       return;
-      mu_debug_set_level (debug, level);
-    }
-}
-
-int
-mu_mailer_create_from_url (mu_mailer_t *pmailer, mu_url_t url)
-{
-  mu_record_t record;
-
-  if (mu_registrar_lookup_url (url, MU_FOLDER_ATTRIBUTE_FILE, &record,
-                              NULL) == 0)
-    {
-      int (*m_init) (mu_mailer_t) = NULL;
-
-      mu_record_get_mailer (record, &m_init);
-      if (m_init)
-        {
-         int status;
-         mu_mailer_t mailer;
-         int (*u_init) (mu_url_t) = NULL;
-         
-         /* Allocate memory for mailer.  */
-         mailer = calloc (1, sizeof (*mailer));
-         if (mailer == NULL)
-           return ENOMEM;
-
-         status = mu_monitor_create (&mailer->monitor, 0, mailer);
-         if (status)
-           {
-             mu_mailer_destroy (&mailer);
-             return status;
-           }
-
-         status = m_init (mailer);
-         if (status)
-           {
-             mu_mailer_destroy (&mailer);
-             return status;
-           }
-
-         mu_record_get_url (record, &u_init);
-         if (u_init && (status = u_init (url)) != 0)
-           {
-             mu_mailer_destroy (&mailer);
-             return status;
-           }
-         
-         mailer->url = url;
-         *pmailer = mailer;
-
-         set_default_debug (mailer);
-         return status;
-       }
-    }
-  
-    return MU_ERR_MAILER_BAD_URL;
-}
-
-int
-mu_mailer_create (mu_mailer_t * pmailer, const char *name)
-{
-  int status;
-  mu_url_t url;
-
-  if (name == NULL)
-    mu_mailer_get_url_default (&name);
-
-  status = mu_url_create (&url, name);
-  if (status)
-    return status;
-  status = mu_url_parse (url);
-  if (status == 0)
-    status = mu_mailer_create_from_url (pmailer, url);
-  if (status)
-    mu_url_destroy (&url);
-  return status;
-}
-
-void
-mu_mailer_destroy (mu_mailer_t * pmailer)
-{
-  if (pmailer && *pmailer)
-    {
-      mu_mailer_t mailer = *pmailer;
-      mu_monitor_t monitor = mailer->monitor;
-
-      if (mailer->observable)
-       {
-         mu_observable_notify (mailer->observable, MU_EVT_MAILER_DESTROY,
-                               mailer);
-         mu_observable_destroy (&mailer->observable, mailer);
-       }
-
-      /* Call the object destructor.  */
-      if (mailer->_destroy)
-       mailer->_destroy (mailer);
-
-      mu_monitor_wrlock (monitor);
-
-      if (mailer->stream)
-       {
-         /* FIXME: Should be the client responsability to close this?  */
-         /* mu_stream_close (mailer->stream); */
-         mu_stream_destroy (&mailer->stream);
-       }
-
-      if (mailer->url)
-       mu_url_destroy (&(mailer->url));
-
-      if (mailer->debug)
-       mu_debug_destroy (&(mailer->debug), mailer);
-
-      if (mailer->property)
-       mu_property_destroy (&(mailer->property), mailer);
-
-      free (mailer);
-      *pmailer = NULL;
-      mu_monitor_unlock (monitor);
-      mu_monitor_destroy (&monitor, mailer);
-    }
-}
-
-
-/* -------------- stub functions ------------------- */
-
-int
-mu_mailer_open (mu_mailer_t mailer, int flag)
-{
-  if (mailer == NULL || mailer->_open == NULL)
-    return ENOSYS;
-  return mailer->_open (mailer, flag);
-}
-
-int
-mu_mailer_close (mu_mailer_t mailer)
-{
-  if (mailer == NULL || mailer->_close == NULL)
-    return ENOSYS;
-  return mailer->_close (mailer);
-}
-
-
-int
-mu_mailer_check_from (mu_address_t from)
-{
-  size_t n = 0;
-
-  if (!from)
-    return EINVAL;
-
-  if (mu_address_get_count (from, &n) || n != 1)
-    return MU_ERR_MAILER_BAD_FROM;
-
-  if (mu_address_get_email_count (from, &n) || n == 0)
-    return MU_ERR_MAILER_BAD_FROM;
-
-  return 0;
-}
-
-int
-mu_mailer_check_to (mu_address_t to)
-{
-  size_t count = 0;
-  size_t emails = 0;
-  size_t groups = 0;
-
-  if (!to)
-    return EINVAL;
-
-  if (mu_address_get_count (to, &count))
-    return MU_ERR_MAILER_BAD_TO;
-
-  if (mu_address_get_email_count (to, &emails))
-    return MU_ERR_MAILER_BAD_TO;
-
-  if (emails == 0)
-    return MU_ERR_MAILER_NO_RCPT_TO;
-
-  if (mu_address_get_group_count (to, &groups))
-    return MU_ERR_MAILER_BAD_TO;
-
-  if (count - emails - groups != 0)
-    /* then not everything is a group or an email address */
-    return MU_ERR_MAILER_BAD_TO;
-
-  return 0;
-}
-
-static void
-save_fcc (mu_message_t msg)
-{
-  mu_header_t hdr;
-  size_t count = 0, i;
-  char buf[512], *fcc;
-  
-  if (mu_message_get_header (msg, &hdr))
-    return;
-
-  if (mu_header_get_value (hdr, MU_HEADER_FCC, NULL, 0, NULL))
-    return;
-  
-  mu_header_get_field_count (hdr, &count);
-  for (i = 1; i <= count; i++)
-    {
-      mu_mailbox_t mbox;
-      
-      mu_header_get_field_name (hdr, i, buf, sizeof buf, NULL);
-      if (mu_c_strcasecmp (buf, MU_HEADER_FCC) == 0
-         && mu_header_aget_field_value (hdr, i, &fcc) == 0)
-       {
-         int i, argc;
-         char **argv;
-         
-         mu_argcv_get (fcc, ",", NULL, &argc, &argv);
-         for (i = 0; i < argc; i += 2)
-           {
-             if (mu_mailbox_create_default (&mbox, argv[i]))
-               continue; /*FIXME: error message?? */
-             if (mu_mailbox_open (mbox,
-                                  MU_STREAM_RDWR | MU_STREAM_CREAT
-                                  | MU_STREAM_APPEND) == 0)
-               {
-                 mu_mailbox_append_message (mbox, msg);
-                 mu_mailbox_flush (mbox, 0);
-               }
-             mu_mailbox_close (mbox);
-             mu_mailbox_destroy (&mbox);
-           }
-         mu_argcv_free (argc, argv);
-         free (fcc);
-       }
-    }
-}
-
-static int
-_set_from (mu_address_t *pfrom, mu_message_t msg, mu_address_t from,
-          mu_mailer_t mailer)
-{
-  int status = 0;
-  char *mail_from;
-  mu_header_t header = NULL;
-
-  *pfrom = NULL;
-  
-  /* Get MAIL_FROM from FROM, the message, or the environment. */
-  if (!from)
-    {
-      const char *type;
-      
-      if ((status = mu_message_get_header (msg, &header)) != 0)
-       return status;
-      
-      status = mu_header_aget_value (header, MU_HEADER_FROM, &mail_from);
-      
-      switch (status)
-       {
-       default:
-         return status;
-
-         /* Use the From: header. */
-       case 0:
-         MU_DEBUG1 (mailer->debug, MU_DEBUG_TRACE,
-                    "mu_mailer_send_message(): using From: %s\n",
-                    mail_from);
-           
-         status = mu_address_create (pfrom, mail_from);
-         free (mail_from);
-         break;
-
-       case MU_ERR_NOENT:
-         if (mu_property_sget_value (mailer->property, "TYPE", &type) == 0
-             && strcmp (type, "SENDMAIL") == 0)
-           return 0;
-         
-         /* Use the environment. */
-         mail_from = mu_get_user_email (NULL);
-
-         if (mail_from)
-            MU_DEBUG1 (mailer->debug, MU_DEBUG_TRACE,
-                      "mu_mailer_send_message(): using user's address: %s\n",
-                      mail_from);
-         else
-            MU_DEBUG (mailer->debug, MU_DEBUG_ERROR,
-                     "mu_mailer_send_message(): no user's address, failing\n");
-
-         if (!mail_from)
-           return errno;
-
-         status = mu_address_create (pfrom, mail_from);
-         /* FIXME: should we add the From: header? */
-         break;
-       }
-    }
-
-  return status;
-}
-
-static int
-create_part (mu_mime_t mime, mu_stream_t istr, 
-            size_t fragsize, size_t n, size_t nparts, char *msgid)
-{
-  int status = 0;
-  mu_message_t newmsg;
-  mu_header_t newhdr;
-  mu_body_t body;
-  mu_stream_t ostr;
-  char buffer[512], *str;
-  size_t slen;
-  
-  mu_message_create (&newmsg, NULL);
-  mu_message_get_header (newmsg, &newhdr); 
-
-  str = NULL;
-  slen = 0;
-  mu_asnprintf (&str, &slen,
-               "message/partial; id=\"%s\"; number=%lu; total=%lu",
-               msgid, (unsigned long)n, (unsigned long)nparts);
-  mu_header_append (newhdr, MU_HEADER_CONTENT_TYPE, str);
-  mu_asnprintf (&str, &slen, "part %lu of %lu",
-               (unsigned long)n, (unsigned long)nparts);
-  mu_header_append (newhdr, MU_HEADER_CONTENT_DESCRIPTION, str);
-  free (str);
-  
-  mu_message_get_body (newmsg, &body);
-  mu_body_get_streamref (body, &ostr);
-
-  status = mu_stream_seek (ostr, 0, SEEK_SET, NULL);
-  if (status == 0)
-    while (fragsize)
-      {
-       size_t rds = fragsize;
-       if (rds > sizeof buffer)
-         rds = sizeof buffer;
-       
-       status = mu_stream_read (istr, buffer, rds, &rds);
-       if (status || rds == 0)
-         break;
-       status = mu_stream_write (ostr, buffer, rds, NULL);
-       if (status)
-         break;
-       fragsize -= rds;
-      }
-  mu_stream_destroy (&ostr);
-  
-  if (status == 0)
-    {
-      mu_mime_add_part (mime, newmsg);
-      mu_message_unref (newmsg);
-    }
-  return status;
-}
-
-static void
-merge_headers (mu_message_t newmsg, mu_header_t hdr)
-{
-  size_t i, count;
-  mu_header_t newhdr;
-  
-  mu_message_get_header (newmsg, &newhdr);
-  mu_header_get_field_count (hdr, &count);
-  for (i = 1; i <= count; i++)
-    {
-      const char *fn, *fv;
-
-      mu_header_sget_field_name (hdr, i, &fn);
-      mu_header_sget_field_value (hdr, i, &fv);
-      if (mu_c_strcasecmp (fn, MU_HEADER_MESSAGE_ID) == 0)
-       continue;
-      else if (mu_c_strcasecmp (fn, MU_HEADER_MIME_VERSION) == 0)
-       mu_header_append (newhdr, "X-Orig-" MU_HEADER_MIME_VERSION,
-                         fv);
-      else if (mu_c_strcasecmp (fn, MU_HEADER_CONTENT_TYPE) == 0)
-       mu_header_append (newhdr, "X-Orig-" MU_HEADER_CONTENT_TYPE,
-                         fv);
-      else if (mu_c_strcasecmp (fn, MU_HEADER_CONTENT_DESCRIPTION) == 0)
-       mu_header_append (newhdr, "X-Orig-" MU_HEADER_CONTENT_DESCRIPTION,
-                         fv);
-      else
-       mu_header_append (newhdr, fn, fv);
-    }
-}
-  
-
-int
-send_fragments (mu_mailer_t mailer,
-               mu_header_t hdr,
-               mu_stream_t str,
-               size_t nparts, size_t fragsize,
-               struct timeval *delay,
-               mu_address_t from, mu_address_t to)
-{
-  int status = 0;
-  size_t i;
-  char *msgid = NULL;
-  
-  if (mu_header_aget_value (hdr, MU_HEADER_MESSAGE_ID, &msgid))
-    mu_rfc2822_msg_id (0, &msgid);
-  
-  for (i = 1; i <= nparts; i++)
-    {
-      mu_message_t newmsg;
-      mu_mime_t mime;
-                 
-      mu_mime_create (&mime, NULL, 0);
-      status = create_part (mime, str, fragsize, i, nparts, msgid);
-      if (status)
-       break;
-
-      mu_mime_get_message (mime, &newmsg);
-      merge_headers (newmsg, hdr);
-      
-      status = mailer->_send_message (mailer, newmsg, from, to);
-      mu_mime_destroy (&mime);
-      if (status)
-       break;
-      if (delay)
-       {
-         struct timeval t = *delay;
-         select (0, NULL, NULL, NULL, &t);
-       }
-    }
-  free (msgid);
-  return status;
-}
-
-int
-mu_mailer_send_fragments (mu_mailer_t mailer,
-                         mu_message_t msg,
-                         size_t fragsize, struct timeval *delay,
-                         mu_address_t from, mu_address_t to)
-{
-  int status;
-  mu_address_t sender_addr = NULL;
-  
-  if (mailer == NULL)
-    return EINVAL;
-  if (mailer->_send_message == NULL)
-    return ENOSYS;
-
-  status = _set_from (&sender_addr, msg, from, mailer);
-  if (status)
-    return status;
-  if (sender_addr)
-    from = sender_addr;
-  
-  if ((!from || (status = mu_mailer_check_from (from)) == 0)
-      && (!to || (status = mu_mailer_check_to (to)) == 0))
-    {
-      save_fcc (msg);
-      if (fragsize == 0)
-       status = mailer->_send_message (mailer, msg, from, to);
-      else
-       {
-         mu_header_t hdr;
-         mu_body_t body;
-         size_t bsize;
-         size_t nparts;
-         
-         /* Estimate the number of messages to be sent. */
-         mu_message_get_header (msg, &hdr);
-
-         mu_message_get_body (msg, &body);
-         mu_body_size (body, &bsize);
-
-         nparts = bsize + fragsize - 1;
-         if (nparts < bsize) /* overflow */
-           return EINVAL;
-         nparts /= fragsize;
-
-         if (nparts == 1)
-           status = mailer->_send_message (mailer, msg, from, to);
-         else
-           {
-             mu_stream_t str;
-             status = mu_body_get_streamref (body, &str);
-             if (status)
-               {
-                 status = send_fragments (mailer, hdr, str, nparts,
-                                          fragsize, delay, from, to);
-                 mu_stream_destroy (&str);
-               }
-           }
-       }
-    }
-  mu_address_destroy (&sender_addr);
-  return status;
-}
-
-int
-mu_mailer_send_message (mu_mailer_t mailer, mu_message_t msg,
-                       mu_address_t from, mu_address_t to)
-{
-  return mu_mailer_send_fragments (mailer, msg, 0, NULL, from, to);
-}
-
-int
-mu_mailer_set_stream (mu_mailer_t mailer, mu_stream_t stream)
-{
-  if (mailer == NULL)
-    return EINVAL;
-  mailer->stream = stream;
-  return 0;
-}
-
-int
-mu_mailer_get_stream (mu_mailer_t mailer, mu_stream_t * pstream)
-{
-  /* FIXME: Deprecation warning */
-  if (mailer == NULL)
-    return EINVAL;
-  if (pstream == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  *pstream = mailer->stream;
-  return 0;
-}
-
-int
-mu_mailer_get_streamref (mu_mailer_t mailer, mu_stream_t * pstream)
-{
-  if (mailer == NULL)
-    return EINVAL;
-  if (pstream == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  return mu_streamref_create (pstream, mailer->stream);
-}
-
-int
-mu_mailer_get_observable (mu_mailer_t mailer, mu_observable_t * pobservable)
-{
-  /* FIXME: I should check for invalid types */
-  if (mailer == NULL)
-    return EINVAL;
-  if (pobservable == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  if (mailer->observable == NULL)
-    {
-      int status = mu_observable_create (&(mailer->observable), mailer);
-      if (status != 0)
-       return status;
-    }
-  *pobservable = mailer->observable;
-  return 0;
-}
-
-int
-mu_mailer_get_property (mu_mailer_t mailer, mu_property_t * pproperty)
-{
-  if (mailer == NULL)
-    return EINVAL;
-  if (pproperty == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  if (mailer->property == NULL)
-    {
-      int status = mu_property_create (&(mailer->property), mailer);
-      if (status != 0)
-       return status;
-    }
-  *pproperty = mailer->property;
-  return 0;
-}
-
-int
-mu_mailer_set_debug (mu_mailer_t mailer, mu_debug_t debug)
-{
-  if (mailer == NULL)
-    return EINVAL;
-  mu_debug_destroy (&(mailer->debug), mailer);
-  mailer->debug = debug;
-  return 0;
-}
-
-int
-mu_mailer_get_debug (mu_mailer_t mailer, mu_debug_t * pdebug)
-{
-  if (mailer == NULL)
-    return EINVAL;
-  if (pdebug == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  if (mailer->debug == NULL)
-    {
-      int status = mu_debug_create (&(mailer->debug), mailer);
-      if (status != 0)
-       return status;
-    }
-  *pdebug = mailer->debug;
-  return 0;
-}
-
-int
-mu_mailer_get_url (mu_mailer_t mailer, mu_url_t * purl)
-{
-  if (!mailer)
-    return EINVAL;
-  if (!purl)
-    return MU_ERR_OUT_PTR_NULL;
-  *purl = mailer->url;
-  return 0;
-}
diff --git a/libmailutils/mailer/Makefile.am b/libmailutils/mailer/Makefile.am
new file mode 100644
index 0000000..1d5b242
--- /dev/null
+++ b/libmailutils/mailer/Makefile.am
@@ -0,0 +1,24 @@
+# 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/>.
+
+noinst_LTLIBRARIES = libmailer.la
+
+libmailer_la_SOURCES = \
+ mailer.c\
+ progmailer.c
+
+INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
diff --git a/libmailutils/mailer/mailer.c b/libmailutils/mailer/mailer.c
new file mode 100644
index 0000000..35c9862
--- /dev/null
+++ b/libmailutils/mailer/mailer.c
@@ -0,0 +1,697 @@
+/* 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/>. */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <sys/time.h>
+
+#include <mailutils/cstr.h>
+#include <mailutils/address.h>
+#include <mailutils/debug.h>
+#include <mailutils/errno.h>
+#include <mailutils/iterator.h>
+#include <mailutils/list.h>
+#include <mailutils/observer.h>
+#include <mailutils/property.h>
+#include <mailutils/registrar.h>
+#include <mailutils/stream.h>
+#include <mailutils/url.h>
+#include <mailutils/header.h>
+#include <mailutils/body.h>
+#include <mailutils/mailbox.h>
+#include <mailutils/message.h>
+#include <mailutils/argcv.h>
+#include <mailutils/mutil.h>
+#include <mailutils/mime.h>
+#include <mailutils/io.h>
+
+#include <mailutils/sys/mailer.h>
+
+static char *mailer_url_default;
+
+/* FIXME: I'd like to check that the URL is valid, but that requires that the
+   mailers already be registered! */
+int
+mu_mailer_set_url_default (const char *url)
+{
+  char *n = NULL;
+
+  if (!url)
+    return EINVAL;
+
+  if ((n = strdup (url)) == NULL)
+    return ENOMEM;
+
+  if (mailer_url_default)
+    free (mailer_url_default);
+
+  mailer_url_default = n;
+
+  return 0;
+}
+
+int
+mu_mailer_get_url_default (const char **url)
+{
+  if (!url)
+    return EINVAL;
+
+  if (mailer_url_default)
+    *url = mailer_url_default;
+  else
+    *url = MAILER_URL_DEFAULT;
+
+  return 0;
+}
+
+static void
+set_default_debug (mu_mailer_t mailer)
+{
+  mu_log_level_t level = mu_global_debug_level ("mailer");
+  if (level)
+    {
+      mu_debug_t debug;
+      if (mu_mailer_get_debug (mailer, &debug))
+       return;
+      mu_debug_set_level (debug, level);
+    }
+}
+
+int
+mu_mailer_create_from_url (mu_mailer_t *pmailer, mu_url_t url)
+{
+  mu_record_t record;
+
+  if (mu_registrar_lookup_url (url, MU_FOLDER_ATTRIBUTE_FILE, &record,
+                              NULL) == 0)
+    {
+      int (*m_init) (mu_mailer_t) = NULL;
+
+      mu_record_get_mailer (record, &m_init);
+      if (m_init)
+        {
+         int status;
+         mu_mailer_t mailer;
+         int (*u_init) (mu_url_t) = NULL;
+         
+         /* Allocate memory for mailer.  */
+         mailer = calloc (1, sizeof (*mailer));
+         if (mailer == NULL)
+           return ENOMEM;
+
+         status = mu_monitor_create (&mailer->monitor, 0, mailer);
+         if (status)
+           {
+             mu_mailer_destroy (&mailer);
+             return status;
+           }
+
+         status = m_init (mailer);
+         if (status)
+           {
+             mu_mailer_destroy (&mailer);
+             return status;
+           }
+
+         mu_record_get_url (record, &u_init);
+         if (u_init && (status = u_init (url)) != 0)
+           {
+             mu_mailer_destroy (&mailer);
+             return status;
+           }
+         
+         mailer->url = url;
+         *pmailer = mailer;
+
+         set_default_debug (mailer);
+         return status;
+       }
+    }
+  
+    return MU_ERR_MAILER_BAD_URL;
+}
+
+int
+mu_mailer_create (mu_mailer_t * pmailer, const char *name)
+{
+  int status;
+  mu_url_t url;
+
+  if (name == NULL)
+    mu_mailer_get_url_default (&name);
+
+  status = mu_url_create (&url, name);
+  if (status)
+    return status;
+  status = mu_url_parse (url);
+  if (status == 0)
+    status = mu_mailer_create_from_url (pmailer, url);
+  if (status)
+    mu_url_destroy (&url);
+  return status;
+}
+
+void
+mu_mailer_destroy (mu_mailer_t * pmailer)
+{
+  if (pmailer && *pmailer)
+    {
+      mu_mailer_t mailer = *pmailer;
+      mu_monitor_t monitor = mailer->monitor;
+
+      if (mailer->observable)
+       {
+         mu_observable_notify (mailer->observable, MU_EVT_MAILER_DESTROY,
+                               mailer);
+         mu_observable_destroy (&mailer->observable, mailer);
+       }
+
+      /* Call the object destructor.  */
+      if (mailer->_destroy)
+       mailer->_destroy (mailer);
+
+      mu_monitor_wrlock (monitor);
+
+      if (mailer->stream)
+       {
+         /* FIXME: Should be the client responsability to close this?  */
+         /* mu_stream_close (mailer->stream); */
+         mu_stream_destroy (&mailer->stream);
+       }
+
+      if (mailer->url)
+       mu_url_destroy (&(mailer->url));
+
+      if (mailer->debug)
+       mu_debug_destroy (&(mailer->debug), mailer);
+
+      if (mailer->property)
+       mu_property_destroy (&(mailer->property), mailer);
+
+      free (mailer);
+      *pmailer = NULL;
+      mu_monitor_unlock (monitor);
+      mu_monitor_destroy (&monitor, mailer);
+    }
+}
+
+
+/* -------------- stub functions ------------------- */
+
+int
+mu_mailer_open (mu_mailer_t mailer, int flag)
+{
+  if (mailer == NULL || mailer->_open == NULL)
+    return ENOSYS;
+  return mailer->_open (mailer, flag);
+}
+
+int
+mu_mailer_close (mu_mailer_t mailer)
+{
+  if (mailer == NULL || mailer->_close == NULL)
+    return ENOSYS;
+  return mailer->_close (mailer);
+}
+
+
+int
+mu_mailer_check_from (mu_address_t from)
+{
+  size_t n = 0;
+
+  if (!from)
+    return EINVAL;
+
+  if (mu_address_get_count (from, &n) || n != 1)
+    return MU_ERR_MAILER_BAD_FROM;
+
+  if (mu_address_get_email_count (from, &n) || n == 0)
+    return MU_ERR_MAILER_BAD_FROM;
+
+  return 0;
+}
+
+int
+mu_mailer_check_to (mu_address_t to)
+{
+  size_t count = 0;
+  size_t emails = 0;
+  size_t groups = 0;
+
+  if (!to)
+    return EINVAL;
+
+  if (mu_address_get_count (to, &count))
+    return MU_ERR_MAILER_BAD_TO;
+
+  if (mu_address_get_email_count (to, &emails))
+    return MU_ERR_MAILER_BAD_TO;
+
+  if (emails == 0)
+    return MU_ERR_MAILER_NO_RCPT_TO;
+
+  if (mu_address_get_group_count (to, &groups))
+    return MU_ERR_MAILER_BAD_TO;
+
+  if (count - emails - groups != 0)
+    /* then not everything is a group or an email address */
+    return MU_ERR_MAILER_BAD_TO;
+
+  return 0;
+}
+
+static void
+save_fcc (mu_message_t msg)
+{
+  mu_header_t hdr;
+  size_t count = 0, i;
+  char buf[512], *fcc;
+  
+  if (mu_message_get_header (msg, &hdr))
+    return;
+
+  if (mu_header_get_value (hdr, MU_HEADER_FCC, NULL, 0, NULL))
+    return;
+  
+  mu_header_get_field_count (hdr, &count);
+  for (i = 1; i <= count; i++)
+    {
+      mu_mailbox_t mbox;
+      
+      mu_header_get_field_name (hdr, i, buf, sizeof buf, NULL);
+      if (mu_c_strcasecmp (buf, MU_HEADER_FCC) == 0
+         && mu_header_aget_field_value (hdr, i, &fcc) == 0)
+       {
+         int i, argc;
+         char **argv;
+         
+         mu_argcv_get (fcc, ",", NULL, &argc, &argv);
+         for (i = 0; i < argc; i += 2)
+           {
+             if (mu_mailbox_create_default (&mbox, argv[i]))
+               continue; /*FIXME: error message?? */
+             if (mu_mailbox_open (mbox,
+                                  MU_STREAM_RDWR | MU_STREAM_CREAT
+                                  | MU_STREAM_APPEND) == 0)
+               {
+                 mu_mailbox_append_message (mbox, msg);
+                 mu_mailbox_flush (mbox, 0);
+               }
+             mu_mailbox_close (mbox);
+             mu_mailbox_destroy (&mbox);
+           }
+         mu_argcv_free (argc, argv);
+         free (fcc);
+       }
+    }
+}
+
+static int
+_set_from (mu_address_t *pfrom, mu_message_t msg, mu_address_t from,
+          mu_mailer_t mailer)
+{
+  int status = 0;
+  char *mail_from;
+  mu_header_t header = NULL;
+
+  *pfrom = NULL;
+  
+  /* Get MAIL_FROM from FROM, the message, or the environment. */
+  if (!from)
+    {
+      const char *type;
+      
+      if ((status = mu_message_get_header (msg, &header)) != 0)
+       return status;
+      
+      status = mu_header_aget_value (header, MU_HEADER_FROM, &mail_from);
+      
+      switch (status)
+       {
+       default:
+         return status;
+
+         /* Use the From: header. */
+       case 0:
+         MU_DEBUG1 (mailer->debug, MU_DEBUG_TRACE,
+                    "mu_mailer_send_message(): using From: %s\n",
+                    mail_from);
+           
+         status = mu_address_create (pfrom, mail_from);
+         free (mail_from);
+         break;
+
+       case MU_ERR_NOENT:
+         if (mu_property_sget_value (mailer->property, "TYPE", &type) == 0
+             && strcmp (type, "SENDMAIL") == 0)
+           return 0;
+         
+         /* Use the environment. */
+         mail_from = mu_get_user_email (NULL);
+
+         if (mail_from)
+            MU_DEBUG1 (mailer->debug, MU_DEBUG_TRACE,
+                      "mu_mailer_send_message(): using user's address: %s\n",
+                      mail_from);
+         else
+            MU_DEBUG (mailer->debug, MU_DEBUG_ERROR,
+                     "mu_mailer_send_message(): no user's address, failing\n");
+
+         if (!mail_from)
+           return errno;
+
+         status = mu_address_create (pfrom, mail_from);
+         /* FIXME: should we add the From: header? */
+         break;
+       }
+    }
+
+  return status;
+}
+
+static int
+create_part (mu_mime_t mime, mu_stream_t istr, 
+            size_t fragsize, size_t n, size_t nparts, char *msgid)
+{
+  int status = 0;
+  mu_message_t newmsg;
+  mu_header_t newhdr;
+  mu_body_t body;
+  mu_stream_t ostr;
+  char buffer[512], *str;
+  size_t slen;
+  
+  mu_message_create (&newmsg, NULL);
+  mu_message_get_header (newmsg, &newhdr); 
+
+  str = NULL;
+  slen = 0;
+  mu_asnprintf (&str, &slen,
+               "message/partial; id=\"%s\"; number=%lu; total=%lu",
+               msgid, (unsigned long)n, (unsigned long)nparts);
+  mu_header_append (newhdr, MU_HEADER_CONTENT_TYPE, str);
+  mu_asnprintf (&str, &slen, "part %lu of %lu",
+               (unsigned long)n, (unsigned long)nparts);
+  mu_header_append (newhdr, MU_HEADER_CONTENT_DESCRIPTION, str);
+  free (str);
+  
+  mu_message_get_body (newmsg, &body);
+  mu_body_get_streamref (body, &ostr);
+
+  status = mu_stream_seek (ostr, 0, SEEK_SET, NULL);
+  if (status == 0)
+    while (fragsize)
+      {
+       size_t rds = fragsize;
+       if (rds > sizeof buffer)
+         rds = sizeof buffer;
+       
+       status = mu_stream_read (istr, buffer, rds, &rds);
+       if (status || rds == 0)
+         break;
+       status = mu_stream_write (ostr, buffer, rds, NULL);
+       if (status)
+         break;
+       fragsize -= rds;
+      }
+  mu_stream_destroy (&ostr);
+  
+  if (status == 0)
+    {
+      mu_mime_add_part (mime, newmsg);
+      mu_message_unref (newmsg);
+    }
+  return status;
+}
+
+static void
+merge_headers (mu_message_t newmsg, mu_header_t hdr)
+{
+  size_t i, count;
+  mu_header_t newhdr;
+  
+  mu_message_get_header (newmsg, &newhdr);
+  mu_header_get_field_count (hdr, &count);
+  for (i = 1; i <= count; i++)
+    {
+      const char *fn, *fv;
+
+      mu_header_sget_field_name (hdr, i, &fn);
+      mu_header_sget_field_value (hdr, i, &fv);
+      if (mu_c_strcasecmp (fn, MU_HEADER_MESSAGE_ID) == 0)
+       continue;
+      else if (mu_c_strcasecmp (fn, MU_HEADER_MIME_VERSION) == 0)
+       mu_header_append (newhdr, "X-Orig-" MU_HEADER_MIME_VERSION,
+                         fv);
+      else if (mu_c_strcasecmp (fn, MU_HEADER_CONTENT_TYPE) == 0)
+       mu_header_append (newhdr, "X-Orig-" MU_HEADER_CONTENT_TYPE,
+                         fv);
+      else if (mu_c_strcasecmp (fn, MU_HEADER_CONTENT_DESCRIPTION) == 0)
+       mu_header_append (newhdr, "X-Orig-" MU_HEADER_CONTENT_DESCRIPTION,
+                         fv);
+      else
+       mu_header_append (newhdr, fn, fv);
+    }
+}
+  
+
+int
+send_fragments (mu_mailer_t mailer,
+               mu_header_t hdr,
+               mu_stream_t str,
+               size_t nparts, size_t fragsize,
+               struct timeval *delay,
+               mu_address_t from, mu_address_t to)
+{
+  int status = 0;
+  size_t i;
+  char *msgid = NULL;
+  
+  if (mu_header_aget_value (hdr, MU_HEADER_MESSAGE_ID, &msgid))
+    mu_rfc2822_msg_id (0, &msgid);
+  
+  for (i = 1; i <= nparts; i++)
+    {
+      mu_message_t newmsg;
+      mu_mime_t mime;
+                 
+      mu_mime_create (&mime, NULL, 0);
+      status = create_part (mime, str, fragsize, i, nparts, msgid);
+      if (status)
+       break;
+
+      mu_mime_get_message (mime, &newmsg);
+      merge_headers (newmsg, hdr);
+      
+      status = mailer->_send_message (mailer, newmsg, from, to);
+      mu_mime_destroy (&mime);
+      if (status)
+       break;
+      if (delay)
+       {
+         struct timeval t = *delay;
+         select (0, NULL, NULL, NULL, &t);
+       }
+    }
+  free (msgid);
+  return status;
+}
+
+int
+mu_mailer_send_fragments (mu_mailer_t mailer,
+                         mu_message_t msg,
+                         size_t fragsize, struct timeval *delay,
+                         mu_address_t from, mu_address_t to)
+{
+  int status;
+  mu_address_t sender_addr = NULL;
+  
+  if (mailer == NULL)
+    return EINVAL;
+  if (mailer->_send_message == NULL)
+    return ENOSYS;
+
+  status = _set_from (&sender_addr, msg, from, mailer);
+  if (status)
+    return status;
+  if (sender_addr)
+    from = sender_addr;
+  
+  if ((!from || (status = mu_mailer_check_from (from)) == 0)
+      && (!to || (status = mu_mailer_check_to (to)) == 0))
+    {
+      save_fcc (msg);
+      if (fragsize == 0)
+       status = mailer->_send_message (mailer, msg, from, to);
+      else
+       {
+         mu_header_t hdr;
+         mu_body_t body;
+         size_t bsize;
+         size_t nparts;
+         
+         /* Estimate the number of messages to be sent. */
+         mu_message_get_header (msg, &hdr);
+
+         mu_message_get_body (msg, &body);
+         mu_body_size (body, &bsize);
+
+         nparts = bsize + fragsize - 1;
+         if (nparts < bsize) /* overflow */
+           return EINVAL;
+         nparts /= fragsize;
+
+         if (nparts == 1)
+           status = mailer->_send_message (mailer, msg, from, to);
+         else
+           {
+             mu_stream_t str;
+             status = mu_body_get_streamref (body, &str);
+             if (status)
+               {
+                 status = send_fragments (mailer, hdr, str, nparts,
+                                          fragsize, delay, from, to);
+                 mu_stream_destroy (&str);
+               }
+           }
+       }
+    }
+  mu_address_destroy (&sender_addr);
+  return status;
+}
+
+int
+mu_mailer_send_message (mu_mailer_t mailer, mu_message_t msg,
+                       mu_address_t from, mu_address_t to)
+{
+  return mu_mailer_send_fragments (mailer, msg, 0, NULL, from, to);
+}
+
+int
+mu_mailer_set_stream (mu_mailer_t mailer, mu_stream_t stream)
+{
+  if (mailer == NULL)
+    return EINVAL;
+  mailer->stream = stream;
+  return 0;
+}
+
+int
+mu_mailer_get_stream (mu_mailer_t mailer, mu_stream_t * pstream)
+{
+  /* FIXME: Deprecation warning */
+  if (mailer == NULL)
+    return EINVAL;
+  if (pstream == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  *pstream = mailer->stream;
+  return 0;
+}
+
+int
+mu_mailer_get_streamref (mu_mailer_t mailer, mu_stream_t * pstream)
+{
+  if (mailer == NULL)
+    return EINVAL;
+  if (pstream == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  return mu_streamref_create (pstream, mailer->stream);
+}
+
+int
+mu_mailer_get_observable (mu_mailer_t mailer, mu_observable_t * pobservable)
+{
+  /* FIXME: I should check for invalid types */
+  if (mailer == NULL)
+    return EINVAL;
+  if (pobservable == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  if (mailer->observable == NULL)
+    {
+      int status = mu_observable_create (&(mailer->observable), mailer);
+      if (status != 0)
+       return status;
+    }
+  *pobservable = mailer->observable;
+  return 0;
+}
+
+int
+mu_mailer_get_property (mu_mailer_t mailer, mu_property_t * pproperty)
+{
+  if (mailer == NULL)
+    return EINVAL;
+  if (pproperty == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  if (mailer->property == NULL)
+    {
+      int status = mu_property_create (&(mailer->property), mailer);
+      if (status != 0)
+       return status;
+    }
+  *pproperty = mailer->property;
+  return 0;
+}
+
+int
+mu_mailer_set_debug (mu_mailer_t mailer, mu_debug_t debug)
+{
+  if (mailer == NULL)
+    return EINVAL;
+  mu_debug_destroy (&(mailer->debug), mailer);
+  mailer->debug = debug;
+  return 0;
+}
+
+int
+mu_mailer_get_debug (mu_mailer_t mailer, mu_debug_t * pdebug)
+{
+  if (mailer == NULL)
+    return EINVAL;
+  if (pdebug == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  if (mailer->debug == NULL)
+    {
+      int status = mu_debug_create (&(mailer->debug), mailer);
+      if (status != 0)
+       return status;
+    }
+  *pdebug = mailer->debug;
+  return 0;
+}
+
+int
+mu_mailer_get_url (mu_mailer_t mailer, mu_url_t * purl)
+{
+  if (!mailer)
+    return EINVAL;
+  if (!purl)
+    return MU_ERR_OUT_PTR_NULL;
+  *purl = mailer->url;
+  return 0;
+}
diff --git a/libmailutils/mailer/progmailer.c b/libmailutils/mailer/progmailer.c
new file mode 100644
index 0000000..6411cf0
--- /dev/null
+++ b/libmailutils/mailer/progmailer.c
@@ -0,0 +1,313 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2006, 2007, 2008, 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/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <signal.h>
+#include <sysexits.h>
+
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <mailutils/debug.h>
+#include <mailutils/error.h>
+#include <mailutils/errno.h>
+#include <mailutils/stream.h>
+#include <mailutils/header.h>
+#include <mailutils/body.h>
+#include <mailutils/message.h>
+#include <mailutils/progmailer.h>
+#include <mailutils/mutil.h>
+#include <mailutils/cstr.h>
+
+struct _mu_progmailer
+{
+  int fd;
+  pid_t pid;
+  RETSIGTYPE (*sighandler)();
+  mu_debug_t debug;
+  char *command;
+};
+
+/* Close FD unless it is part of pipe P */
+#define SCLOSE(fd,p) if (p[0]!=fd&&p[1]!=fd) close(fd)
+
+int
+mu_progmailer_create (struct _mu_progmailer **ppm)
+{
+  struct _mu_progmailer *pm = malloc (sizeof (*pm));
+  if (!pm)
+    return ENOMEM;
+  pm->fd = -1;
+  pm->pid = -1;
+  pm->sighandler = SIG_ERR;
+  pm->debug = NULL;
+  pm->command = NULL;
+  *ppm = pm;
+  return 0;
+}
+
+int
+mu_progmailer_set_command (mu_progmailer_t pm, const char *command)
+{
+  if (!pm)
+    return EINVAL;
+  free (pm->command);
+  if (command)
+    {
+      pm->command = strdup (command);
+      if (!pm->command)
+       return EINVAL;
+    }
+  else
+    pm->command = NULL;
+  return 0;
+}
+
+int
+mu_progmailer_sget_command (mu_progmailer_t pm, const char **command)
+{
+  if (!pm)
+    return EINVAL;
+  *command = pm->command;
+  return 0;
+}
+
+int
+mu_progmailer_set_debug (mu_progmailer_t pm, mu_debug_t debug)
+{
+  if (!pm)
+    return EINVAL;
+  pm->debug = debug;
+  return 0;
+}
+
+void
+mu_progmailer_destroy (struct _mu_progmailer **ppm)
+{
+  if (*ppm)
+    {
+      free ((*ppm)->command);
+      free (*ppm);
+      *ppm = NULL;
+    }
+}
+
+int
+mu_progmailer_open (struct _mu_progmailer *pm, char **argv)
+{
+  int tunnel[2];
+  int status = 0;
+  int i;
+
+  if (!pm || !argv)
+    return EINVAL;
+  
+  if ((pm->sighandler = signal (SIGCHLD, SIG_DFL)) == SIG_ERR)
+    {
+      status = errno;
+      MU_DEBUG1 (pm->debug, MU_DEBUG_ERROR,
+                "setting SIGCHLD failed: %s\n", mu_strerror (status));
+      return status;
+    }
+      
+  if (pipe (tunnel) == 0)
+    {
+      pm->fd = tunnel[1];
+      pm->pid = fork ();
+      if (pm->pid == 0)        /* Child.  */
+       {
+         SCLOSE (STDIN_FILENO, tunnel);
+         SCLOSE (STDOUT_FILENO, tunnel);
+         SCLOSE (STDERR_FILENO, tunnel);
+         close (tunnel[1]);
+         dup2 (tunnel[0], STDIN_FILENO);
+         execv (pm->command ? pm->command : argv[0], argv);
+         exit (errno ? EX_CANTCREAT : 0);
+       }
+      else if (pm->pid == -1)
+       {
+         status = errno;
+         MU_DEBUG1 (pm->debug, MU_DEBUG_ERROR,
+                    "fork failed: %s\n", mu_strerror (status));
+       }
+    }
+  else
+    {
+      status = errno;
+      MU_DEBUG1 (pm->debug, MU_DEBUG_ERROR,
+                "pipe() failed: %s\n", mu_strerror (status));
+    }
+  MU_DEBUG1 (pm->debug, MU_DEBUG_TRACE, "exec %s argv:", pm->command);
+  for (i = 0; argv[i]; i++)
+    MU_DEBUG1 (pm->debug, MU_DEBUG_TRACE, " %s", argv[i]);
+  MU_DEBUG (pm->debug, MU_DEBUG_TRACE, "\n");
+  close (tunnel[0]);
+
+  if (status != 0)
+    close (pm->fd);
+  return status;
+}
+
+int
+mu_progmailer_send (struct _mu_progmailer *pm, mu_message_t msg)
+{
+  int status;
+  mu_stream_t stream = NULL;
+  char buffer[512];
+  size_t len = 0;
+  int rc;
+  mu_header_t hdr;
+  mu_body_t body;
+  int found_nl = 0;
+  int exit_status;
+       
+  if (!pm || !msg)
+    return EINVAL;
+  mu_message_get_header (msg, &hdr);
+  status = mu_header_get_streamref (hdr, &stream);
+  if (status)
+    {
+      MU_DEBUG1 (pm->debug, MU_DEBUG_ERROR,
+                "cannot get header stream: %s\n", mu_strerror (status));
+      return status;
+    }
+  MU_DEBUG (pm->debug, MU_DEBUG_TRACE, "Sending headers...\n");
+  mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
+  while ((status = mu_stream_readline (stream, buffer, sizeof (buffer),
+                                      &len)) == 0
+        && len != 0)
+    {
+      if (mu_c_strncasecmp (buffer, MU_HEADER_FCC, sizeof (MU_HEADER_FCC) - 1))
+       {
+         MU_DEBUG1 (pm->debug, MU_DEBUG_PROT, "Header: %s", buffer);
+         if (write (pm->fd, buffer, len) == -1)
+           {
+             status = errno;
+             
+             MU_DEBUG1 (pm->debug, MU_DEBUG_TRACE,
+                        "write failed: %s\n", strerror (status));
+             break;
+           }
+       }
+      found_nl = (len == 1 && buffer[0] == '\n');
+    }
+
+  if (!found_nl)
+    {
+      if (write (pm->fd, "\n", 1) == -1)
+       {
+         status = errno;
+               
+         MU_DEBUG1 (pm->debug, MU_DEBUG_TRACE,
+                    "write failed: %s\n", strerror (status));
+       }
+    }
+  mu_stream_destroy (&stream);
+  
+  MU_DEBUG (pm->debug, MU_DEBUG_TRACE, "Sending body...\n");
+  mu_message_get_body (msg, &body);
+  status = mu_body_get_streamref (body, &stream);
+  if (status)
+    {
+      MU_DEBUG1 (pm->debug, MU_DEBUG_ERROR,
+                "cannot get body stream: %s\n", mu_strerror (status));
+      return status;
+    }
+
+  mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
+  while ((status = mu_stream_read (stream, buffer, sizeof (buffer),
+                                  &len)) == 0
+        && len != 0)
+    {
+      if (write (pm->fd, buffer, len) == -1)
+       {
+         status = errno;
+         
+         MU_DEBUG1 (pm->debug, MU_DEBUG_TRACE,
+                    "write failed: %s\n", strerror (status));
+         break;
+       }
+    }
+  mu_body_get_streamref (body, &stream);
+
+  close (pm->fd);
+
+  rc = waitpid (pm->pid, &exit_status, 0);
+  if (status == 0)
+    {
+      if (rc < 0)
+       {
+         if (errno == ECHILD)
+           status = 0;
+         else
+           { 
+             status = errno;
+             MU_DEBUG2 (pm->debug, MU_DEBUG_TRACE,
+                        "waitpid(%lu) failed: %s\n",
+                        (unsigned long) pm->pid, strerror (status));
+           }
+       }
+      else if (WIFEXITED (exit_status))
+       {
+         exit_status = WEXITSTATUS (exit_status);
+         MU_DEBUG2 (pm->debug, MU_DEBUG_TRACE,
+                    "%s exited with: %d\n",
+                    pm->command, exit_status);
+         status = (exit_status == 0) ? 0 : MU_ERR_PROCESS_EXITED;
+       }
+      else if (WIFSIGNALED (exit_status))
+       status = MU_ERR_PROCESS_SIGNALED;
+      else
+       status = MU_ERR_PROCESS_UNKNOWN_FAILURE;
+    }
+  pm->pid = -1;
+  return status;
+}
+
+int
+mu_progmailer_close (struct _mu_progmailer *pm)
+{
+  int status = 0;
+
+  if (!pm)
+    return EINVAL;
+  
+  if (pm->pid > 0)
+    {
+      kill (SIGTERM, pm->pid);
+      pm->pid = -1;
+    }
+
+  if (pm->sighandler != SIG_ERR
+      && signal (SIGCHLD, pm->sighandler) == SIG_ERR)
+    {
+      status = errno;
+      MU_DEBUG1 (pm->debug, MU_DEBUG_ERROR,
+                "resetting SIGCHLD failed: %s\n", mu_strerror (status));
+    }
+  pm->sighandler = SIG_ERR;
+  return status;
+}
diff --git a/libmailutils/mbx_default.c b/libmailutils/mbx_default.c
deleted file mode 100644
index 348e7f7..0000000
--- a/libmailutils/mbx_default.c
+++ /dev/null
@@ -1,454 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2008,
-   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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <stdio.h>
-#include <pwd.h>
-#include <unistd.h>
-
-#include <confpaths.h>
-
-#include <mailutils/mailbox.h>
-#include <mailutils/mutil.h>
-#include <mailutils/debug.h>
-#include <mailutils/error.h>
-#include <mailutils/errno.h>
-#include <mailutils/mu_auth.h>
-#include <mailutils/vartab.h>
-#include <mailutils/folder.h>
-#include <mailutils/auth.h>
-
-#include <mailutils/sys/mailbox.h>
-
-char *mu_ticket_file = "~/.mu-tickets";
-
-static char *_mu_mailbox_pattern;
-
-static char *_default_folder_dir = "Mail";
-static char *_mu_folder_dir;
-
-static int
-mu_normalize_mailbox_url (char **pout, const char *dir)
-{
-  int len;
-  int addslash = 0;
-#define USERSUFFIX "${user}"
-  
-  if (!pout)
-    return MU_ERR_OUT_PTR_NULL;
-      
-  len = strlen (dir);
-  if (dir[len-1] == '=')
-    {
-      if (len > 5 && strcmp (dir + len - 5, "user=") == 0)
-       *pout = strdup (dir);
-      else
-       return MU_ERR_BAD_FILENAME;
-    }
-  else if (dir[len-1] != '/')
-    addslash = 1;
-
-  *pout = malloc (strlen (dir) + (addslash ? 1 : 0) + sizeof USERSUFFIX);
-  if (!*pout)
-    return ENOMEM;
-
-  strcpy (*pout, dir);
-  if (addslash)
-    strcat (*pout, "/");
-  strcat (*pout, USERSUFFIX);
-#undef USERSUFFIX
-  return 0;
-}
-
-int
-mu_set_mail_directory (const char *p)
-{
-  if (_mu_mailbox_pattern)
-    free (_mu_mailbox_pattern);
-  if (!p)
-    {
-      _mu_mailbox_pattern = NULL;
-      return 0;
-    }
-  return mu_normalize_mailbox_url (&_mu_mailbox_pattern, p);
-}
-
-int
-mu_set_mailbox_pattern (const char *pat)
-{
-  if (_mu_mailbox_pattern)
-    free (_mu_mailbox_pattern);
-  if (!pat)
-    {
-      _mu_mailbox_pattern = NULL;
-      return 0;
-    }
-  _mu_mailbox_pattern = strdup (pat);
-  return _mu_mailbox_pattern ? 0 : ENOMEM;
-}
-
-void
-mu_set_folder_directory (const char *p)
-{
-  if (_mu_folder_dir != _default_folder_dir)
-    free (_mu_folder_dir);
-  _mu_folder_dir = strdup (p);
-}
-
-const char *
-mu_mailbox_url ()
-{
-  if (!_mu_mailbox_pattern)
-    mu_set_mail_directory (MU_PATH_MAILDIR);
-  return _mu_mailbox_pattern;
-}
-
-const char *
-mu_folder_directory ()
-{
-  if (!_mu_folder_dir)
-    _mu_folder_dir = _default_folder_dir;
-  return _mu_folder_dir;
-}
-
-int
-mu_construct_user_mailbox_url (char **pout, const char *name)
-{
-  int rc;
-  const char *pat = mu_mailbox_url ();
-  mu_vartab_t vtab;
-
-  mu_vartab_create (&vtab);
-  mu_vartab_define (vtab, "user", name, 1);
-  rc = mu_vartab_expand (vtab, pat, pout);
-  mu_vartab_destroy (&vtab);
-  return rc;
-}
-
-/* Is this a security risk?  */
-#define USE_ENVIRON 1
-
-static int
-split_shortcut (const char *file, const char pfx[], char **user, char **rest)
-{
-  *user = NULL;
-  *rest = NULL;
-
-  if (!strchr (pfx, file[0]))
-    return 0;
-
-  if (*++file == 0)
-    return 0;
-  else
-    {
-      char *p = strchr (file, '/');
-      int len;
-      if (p)
-        len = p - file + 1;
-      else
-        len = strlen (file) + 1;
-
-      if (len == 1)
-       *user = NULL;
-      else
-       {
-         *user = calloc (1, len);
-         if (!*user)
-           return ENOMEM;
-
-         memcpy (*user, file, len);
-         (*user)[len-1] = 0;
-       }
-      file += len-1;
-      if (file[0] == '/')
-        file++;
-    }
-
-  if (file[0])
-    {
-      *rest = strdup (file);
-      if (!*rest)
-        {
-          free (*user);
-          return ENOMEM;
-        }
-    }
-  
-  return 0;
-}
-
-static char *
-get_homedir (const char *user)
-{
-  char *homedir = NULL;
-  struct mu_auth_data *auth = NULL;
-  
-  if (user)
-    {
-      auth = mu_get_auth_by_name (user);
-      if (auth)
-        homedir = auth->dir;
-    }
-  else
-    {
-#ifdef USE_ENVIRON
-      /* NOTE: Should we honor ${HOME}?  */
-      homedir = getenv ("HOME");
-      if (homedir == NULL)
-        {
-         auth = mu_get_auth_by_name (user);
-         if (auth)
-           homedir = auth->dir;
-        }
-#else
-      auth = mu_get_auth_by_name (user);
-      if (auth)
-       homedir = auth->dir;
-#endif
-    }
-
-  if (homedir)
-    homedir = strdup (homedir);
-  mu_auth_data_free (auth);
-  return homedir;
-}
-
-static int
-user_mailbox_name (const char *user, char **mailbox_name)
-{
-#ifdef USE_ENVIRON
-  if (!user)
-    user = (getenv ("LOGNAME")) ? getenv ("LOGNAME") : getenv ("USER");
-#endif
-
-  if (user)
-    {
-      int rc = mu_construct_user_mailbox_url (mailbox_name, user);
-      if (rc)
-       return rc;
-    }
-  else
-    {
-      struct mu_auth_data *auth = mu_get_auth_by_uid (getuid ());
-
-      if (!auth)
-        {
-          mu_error ("Who am I?");
-          return EINVAL;
-        }
-      *mailbox_name = strdup (auth->mailbox);
-      mu_auth_data_free (auth);
-    }
-
-  return 0;
-}
-
-static int
-plus_expand (const char *file, char **buf)
-{
-  char *home;
-  const char *folder_dir = mu_folder_directory ();
-  int len;
-
-  home = get_homedir (NULL);
-  if (!home)
-    return ENOENT;
-  
-  file++;
-  
-  if (folder_dir[0] == '/' || mu_is_proto (folder_dir))
-    {
-      len = strlen (folder_dir) + strlen (file) + 2;
-      *buf = malloc (len);
-      sprintf (*buf, "%s/%s", folder_dir, file);
-    }
-  else
-    {
-      len = strlen (home) + strlen (folder_dir) + strlen (file) + 3;
-      *buf = malloc (len);
-      sprintf (*buf, "%s/%s/%s", home, folder_dir, file);
-    }
-  (*buf)[len-1] = 0;
-  
-  free (home);
-  return 0;
-}
-
-static int
-percent_expand (const char *file, char **mbox)
-{
-  char *user = NULL;
-  char *path = NULL;
-  int status;
-  
-  if ((status = split_shortcut (file, "%", &user, &path)))
-    return status;
-
-  if (path)
-    {
-      free (user);
-      free (path);
-      return ENOENT;
-    }
-
-  status = user_mailbox_name (user, mbox);
-  free (user);
-  return status;
-}
-
-static void
-attach_auth_ticket (mu_mailbox_t mbox)
-{
-  mu_folder_t folder = NULL;
-  mu_authority_t auth = NULL;
-
-  if (mu_mailbox_get_folder (mbox, &folder) == 0
-      && mu_folder_get_authority (folder, &auth) == 0
-      && auth)
-    {
-      char *filename = mu_tilde_expansion (mu_ticket_file, "/", NULL);
-      mu_wicket_t wicket;
-      int rc;
-  
-      MU_DEBUG1 (mbox->debug, MU_DEBUG_TRACE1,
-                "Reading user ticket file %s\n", filename);
-      if ((rc = mu_file_wicket_create (&wicket, filename)) == 0)
-       {
-         mu_ticket_t ticket;
-      
-         if ((rc = mu_wicket_get_ticket (wicket, NULL, &ticket)) == 0)
-           {
-             rc = mu_authority_set_ticket (auth, ticket);
-             MU_DEBUG1 (mbox->debug, MU_DEBUG_TRACE1,
-                        "Retrieved and set ticket: %d\n", rc);
-           }
-         else
-           MU_DEBUG1 (mbox->debug, MU_DEBUG_ERROR,
-                      "Error retrieving ticket: %s\n",
-                      mu_strerror (rc));
-         mu_wicket_destroy (&wicket);
-       }
-      else
-       MU_DEBUG1 (mbox->debug, MU_DEBUG_ERROR,
-                  "Error creating wicket: %s\n", mu_strerror (rc));
-      free (filename);
-    }
-}
-
-/* We are trying to be smart about the location of the mail.
-   mu_mailbox_create() is not doing this.
-   %           --> system mailbox for the real uid
-   %user       --> system mailbox for the given user
-   ~/file      --> /home/user/file
-   ~user/file  --> /home/user/file
-   +file       --> /home/user/Mail/file
-   =file       --> /home/user/Mail/file
-*/
-int
-mu_mailbox_create_default (mu_mailbox_t *pmbox, const char *mail)
-{
-  char *mbox = NULL;
-  char *tmp_mbox = NULL;
-  char *p;
-  int status = 0;
-
-  /* Sanity.  */
-  if (pmbox == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-
-  if (mail && *mail == 0)
-    mail = NULL;
-  
-  if (mail == NULL)
-    {
-      if (!_mu_mailbox_pattern)
-       {
-         /* Other utilities may not understand GNU mailutils url namespace, so
-            use FOLDER instead, to not confuse others by using MAIL.  */
-         mail = getenv ("FOLDER");
-         if (!mail)
-           {
-             /* Fallback to well-known environment.  */
-             mail = getenv ("MAIL");
-           }
-       }
-
-      if (!mail)
-       {
-         if ((status = user_mailbox_name (NULL, &tmp_mbox)))
-           return status;
-         mail = tmp_mbox;
-       }
-    }
-
-  p = mu_tilde_expansion (mail, "/", NULL);
-  if (tmp_mbox)
-    free (tmp_mbox);
-  tmp_mbox = p;
-  mail = tmp_mbox;
-  if (!mail)
-    return ENOMEM;
-  
-  switch (mail[0])
-    {
-    case '%':
-      status = percent_expand (mail, &mbox);
-      break;
-      
-    case '+':
-    case '=':
-      status = plus_expand (mail, &mbox);
-      break;
-
-    case '/':
-      mbox = strdup (mail);
-      break;
-      
-    default:
-      if (!mu_is_proto (mail))
-       {
-         p = mu_getcwd();
-         mbox = malloc (strlen (p) + strlen (mail) + 2);
-         sprintf (mbox, "%s/%s", p, mail);
-         free (p);  
-       }
-      else
-       mbox = strdup (mail);
-      break;
-    }
-
-  if (tmp_mbox)
-    free (tmp_mbox);
-
-  if (status)
-    return status;
-  
-  status = mu_mailbox_create (pmbox, mbox);
-  free (mbox);
-  if (status == 0)
-    attach_auth_ticket (*pmbox);
-      
-  return status;
-}
diff --git a/libmailutils/mbxitr.c b/libmailutils/mbxitr.c
deleted file mode 100644
index 8463201..0000000
--- a/libmailutils/mbxitr.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/* 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-
-#include <mailutils/debug.h>
-#include <mailutils/errno.h>
-#include <mailutils/error.h>
-#include <mailutils/iterator.h>
-
-#include <mailutils/sys/mailbox.h>
-
-struct mailbox_iterator
-{
-  mu_mailbox_t mbx;
-  size_t idx;
-};
-
-static int
-mbx_first (void *owner)
-{
-  struct mailbox_iterator *itr = owner;
-  itr->idx = 1;
-  return 0;
-}
-
-static int
-mbx_next (void *owner)
-{
-  struct mailbox_iterator *itr = owner;
-  itr->idx++;
-  return 0;
-}
-
-static int
-mbx_getitem (void *owner, void **pret, const void **pkey)
-{
-  struct mailbox_iterator *itr = owner;
-  size_t count;
-  int rc;
-  
-  rc = mu_mailbox_messages_count (itr->mbx, &count);
-  if (rc)
-    return rc;
-  if (itr->idx > count)
-    return MU_ERR_NOENT;
-  rc = mu_mailbox_get_message (itr->mbx, itr->idx, (mu_message_t*)pret);
-  if (rc == 0 && pkey)
-    *pkey = NULL; /* FIXME: Perhaps return UIDL or other unique id? */
-  return rc;
-}
-
-static int
-mbx_finished_p (void *owner)
-{
-  struct mailbox_iterator *itr = owner;
-  size_t count;
-
-  if (mu_mailbox_messages_count (itr->mbx, &count))
-    return 1;
-  return itr->idx > count;
-}
-
-static int
-mbx_destroy (mu_iterator_t iterator, void *data)
-{
-  struct mailbox_iterator *itr = data;
-
-  mu_iterator_detach (&itr->mbx->iterator, iterator);
-  free (data);
-  return 0;
-}
-
-static int
-mbx_curitem_p (void *owner, void *item)
-{
-  void *ptr;
-
-  if (mbx_getitem (owner, &ptr, NULL))
-    return 0;
-  return ptr == item;/* FIXME: Is it ok? */
-}
-
-static int
-mbx_data_dup (void **ptr, void *owner)
-{
-  struct mailbox_iterator *itr = owner;
-
-  *ptr = malloc (sizeof (struct mailbox_iterator));
-  if (*ptr == NULL)
-    return ENOMEM;
-  memcpy (*ptr, owner, sizeof (struct mailbox_iterator));
-  mu_iterator_attach (&itr->mbx->iterator, *ptr);
-  return 0;
-}
-
-int
-mu_mailbox_get_iterator (mu_mailbox_t mbx, mu_iterator_t *piterator)
-{
-  mu_iterator_t iterator;
-  int status;
-  struct mailbox_iterator *itr;
-
-  if (!mbx)
-    return EINVAL;
-
-  itr = calloc (1, sizeof *itr);
-  if (!itr)
-    return ENOMEM;
-  itr->mbx = mbx;
-  itr->idx = 1;
-
-  status = mu_iterator_create (&iterator, itr);
-  if (status)
-    {
-      free (itr);
-      return status;
-    }
-
-  mu_iterator_set_first (iterator, mbx_first);
-  mu_iterator_set_next (iterator, mbx_next);
-  mu_iterator_set_getitem (iterator, mbx_getitem);
-  mu_iterator_set_finished_p (iterator, mbx_finished_p);
-  mu_iterator_set_curitem_p (iterator, mbx_curitem_p);
-  mu_iterator_set_destroy (iterator, mbx_destroy);
-  mu_iterator_set_dup (iterator, mbx_data_dup);
-
-  mu_iterator_attach (&mbx->iterator, iterator);
-
-  *piterator = iterator;
-  return 0;
-}
-
-
-
-
-
-  
-
diff --git a/libmailutils/md5.c b/libmailutils/md5.c
deleted file mode 100644
index a6d3247..0000000
--- a/libmailutils/md5.c
+++ /dev/null
@@ -1,454 +0,0 @@
-/* Functions to compute MD5 message digest of files or memory blocks.
-   according to the definition of MD5 in RFC 1321 from April 1992.
-   Copyright (C) 1995,1996,1997,1999,2000,2001,2005,2006,2010
-       Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   This program is free software; you can redistribute it and/or modify it
-   under the terms of the GNU General Public License as published by the
-   Free Software Foundation; either version 2, or (at your option) any
-   later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* Written by Ulrich Drepper <address@hidden>, 1995.  */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include "mailutils/md5.h"
-
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-
-#if USE_UNLOCKED_IO
-# include "unlocked-io.h"
-#endif
-
-#ifdef _LIBC
-# include <endian.h>
-# if __BYTE_ORDER == __BIG_ENDIAN
-#  define WORDS_BIGENDIAN 1
-# endif
-#endif
-
-/* We need to keep the namespace clean so define the MD5 function
-   protected using leading __ .  */
-# define md5_init_ctx __md5_init_ctx
-# define md5_process_block __md5_process_block
-# define md5_process_bytes __md5_process_bytes
-# define md5_finish_ctx __md5_finish_ctx
-# define md5_read_ctx __md5_read_ctx
-# define md5_stream __md5_stream
-# define md5_buffer __md5_buffer
-
-#ifdef WORDS_BIGENDIAN
-# define SWAP(n)                                                       \
-    (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
-#else
-# define SWAP(n) (n)
-#endif
-
-#define BLOCKSIZE 4096
-#if BLOCKSIZE % 64 != 0
-# error "invalid BLOCKSIZE"
-#endif
-
-/* This array contains the bytes used to pad the buffer to the next
-   64-byte boundary.  (RFC 1321, 3.1: Step 1)  */
-static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ...  */ };
-
-
-/* Initialize structure containing state of computation.
-   (RFC 1321, 3.3: Step 3)  */
-void
-md5_init_ctx (struct md5_ctx *ctx)
-{
-  ctx->A = 0x67452301;
-  ctx->B = 0xefcdab89;
-  ctx->C = 0x98badcfe;
-  ctx->D = 0x10325476;
-
-  ctx->total[0] = ctx->total[1] = 0;
-  ctx->buflen = 0;
-}
-
-/* Put result from CTX in first 16 bytes following RESBUF.  The result
-   must be in little endian byte order.
-
-   IMPORTANT: On some systems it is required that RESBUF is correctly
-   aligned for a 32-bit value.  */
-void *
-md5_read_ctx (const struct md5_ctx *ctx, void *resbuf)
-{
-  ((uint32_t *) resbuf)[0] = SWAP (ctx->A);
-  ((uint32_t *) resbuf)[1] = SWAP (ctx->B);
-  ((uint32_t *) resbuf)[2] = SWAP (ctx->C);
-  ((uint32_t *) resbuf)[3] = SWAP (ctx->D);
-
-  return resbuf;
-}
-
-/* Process the remaining bytes in the internal buffer and the usual
-   prolog according to the standard and write the result to RESBUF.
-
-   IMPORTANT: On some systems it is required that RESBUF is correctly
-   aligned for a 32-bit value.  */
-void *
-md5_finish_ctx (struct md5_ctx *ctx, void *resbuf)
-{
-  /* Take yet unprocessed bytes into account.  */
-  uint32_t bytes = ctx->buflen;
-  size_t size = (bytes < 56) ? 64 / 4 : 64 * 2 / 4;
-
-  /* Now count remaining bytes.  */
-  ctx->total[0] += bytes;
-  if (ctx->total[0] < bytes)
-    ++ctx->total[1];
-
-  /* Put the 64-bit file length in *bits* at the end of the buffer.  */
-  ctx->buffer[size - 2] = SWAP (ctx->total[0] << 3);
-  ctx->buffer[size - 1] = SWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29));
-
-  memcpy (&((char *) ctx->buffer)[bytes], fillbuf, (size - 2) * 4 - bytes);
-
-  /* Process last bytes.  */
-  md5_process_block (ctx->buffer, size * 4, ctx);
-
-  return md5_read_ctx (ctx, resbuf);
-}
-
-/* Compute MD5 message digest for bytes read from STREAM.  The
-   resulting message digest number will be written into the 16 bytes
-   beginning at RESBLOCK.  */
-int
-md5_stream (FILE *stream, void *resblock)
-{
-  struct md5_ctx ctx;
-  char buffer[BLOCKSIZE + 72];
-  size_t sum;
-
-  /* Initialize the computation context.  */
-  md5_init_ctx (&ctx);
-
-  /* Iterate over full file contents.  */
-  while (1)
-    {
-      /* We read the file in blocks of BLOCKSIZE bytes.  One call of the
-         computation function processes the whole buffer so that with the
-         next round of the loop another block can be read.  */
-      size_t n;
-      sum = 0;
-
-      /* Read block.  Take care for partial reads.  */
-      while (1)
-       {
-         n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
-
-         sum += n;
-
-         if (sum == BLOCKSIZE)
-           break;
-
-         if (n == 0)
-           {
-             /* Check for the error flag IFF N == 0, so that we don't
-                exit the loop after a partial read due to e.g., EAGAIN
-                or EWOULDBLOCK.  */
-             if (ferror (stream))
-               return 1;
-             goto process_partial_block;
-           }
-
-         /* We've read at least one byte, so ignore errors.  But always
-            check for EOF, since feof may be true even though N > 0.
-            Otherwise, we could end up calling fread after EOF.  */
-         if (feof (stream))
-           goto process_partial_block;
-       }
-
-      /* Process buffer with BLOCKSIZE bytes.  Note that
-         BLOCKSIZE % 64 == 0
-       */
-      md5_process_block (buffer, BLOCKSIZE, &ctx);
-    }
-
-process_partial_block:
-
-  /* Process any remaining bytes.  */
-  if (sum > 0)
-    md5_process_bytes (buffer, sum, &ctx);
-
-  /* Construct result in desired memory.  */
-  md5_finish_ctx (&ctx, resblock);
-  return 0;
-}
-
-/* Compute MD5 message digest for LEN bytes beginning at BUFFER.  The
-   result is always in little endian byte order, so that a byte-wise
-   output yields to the wanted ASCII representation of the message
-   digest.  */
-void *
-md5_buffer (const char *buffer, size_t len, void *resblock)
-{
-  struct md5_ctx ctx;
-
-  /* Initialize the computation context.  */
-  md5_init_ctx (&ctx);
-
-  /* Process whole buffer but last len % 64 bytes.  */
-  md5_process_bytes (buffer, len, &ctx);
-
-  /* Put result in desired memory area.  */
-  return md5_finish_ctx (&ctx, resblock);
-}
-
-
-void
-md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx)
-{
-  /* When we already have some bits in our internal buffer concatenate
-     both inputs first.  */
-  if (ctx->buflen != 0)
-    {
-      size_t left_over = ctx->buflen;
-      size_t add = 128 - left_over > len ? len : 128 - left_over;
-
-      memcpy (&((char *) ctx->buffer)[left_over], buffer, add);
-      ctx->buflen += add;
-
-      if (ctx->buflen > 64)
-       {
-         md5_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
-
-         ctx->buflen &= 63;
-         /* The regions in the following copy operation cannot overlap.  */
-         memcpy (ctx->buffer,
-                 &((char *) ctx->buffer)[(left_over + add) & ~63],
-                 ctx->buflen);
-       }
-
-      buffer = (const char *) buffer + add;
-      len -= add;
-    }
-
-  /* Process available complete blocks.  */
-  if (len >= 64)
-    {
-#if !_STRING_ARCH_unaligned
-# define alignof(type) offsetof (struct { char c; type x; }, x)
-# define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0)
-      if (UNALIGNED_P (buffer))
-       while (len > 64)
-         {
-           md5_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx);
-           buffer = (const char *) buffer + 64;
-           len -= 64;
-         }
-      else
-#endif
-       {
-         md5_process_block (buffer, len & ~63, ctx);
-         buffer = (const char *) buffer + (len & ~63);
-         len &= 63;
-       }
-    }
-
-  /* Move remaining bytes in internal buffer.  */
-  if (len > 0)
-    {
-      size_t left_over = ctx->buflen;
-
-      memcpy (&((char *) ctx->buffer)[left_over], buffer, len);
-      left_over += len;
-      if (left_over >= 64)
-       {
-         md5_process_block (ctx->buffer, 64, ctx);
-         left_over -= 64;
-         memcpy (ctx->buffer, &ctx->buffer[16], left_over);
-       }
-      ctx->buflen = left_over;
-    }
-}
-
-
-/* These are the four functions used in the four steps of the MD5 algorithm
-   and defined in the RFC 1321.  The first function is a little bit optimized
-   (as found in Colin Plumbs public domain implementation).  */
-/* #define FF(b, c, d) ((b & c) | (~b & d)) */
-#define FF(b, c, d) (d ^ (b & (c ^ d)))
-#define FG(b, c, d) FF (d, b, c)
-#define FH(b, c, d) (b ^ c ^ d)
-#define FI(b, c, d) (c ^ (b | ~d))
-
-/* Process LEN bytes of BUFFER, accumulating context into CTX.
-   It is assumed that LEN % 64 == 0.  */
-
-void
-md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx)
-{
-  uint32_t correct_words[16];
-  const uint32_t *words = buffer;
-  size_t nwords = len / sizeof (uint32_t);
-  const uint32_t *endp = words + nwords;
-  uint32_t A = ctx->A;
-  uint32_t B = ctx->B;
-  uint32_t C = ctx->C;
-  uint32_t D = ctx->D;
-
-  /* First increment the byte count.  RFC 1321 specifies the possible
-     length of the file up to 2^64 bits.  Here we only compute the
-     number of bytes.  Do a double word increment.  */
-  ctx->total[0] += len;
-  if (ctx->total[0] < len)
-    ++ctx->total[1];
-
-  /* Process all bytes in the buffer with 64 bytes in each round of
-     the loop.  */
-  while (words < endp)
-    {
-      uint32_t *cwp = correct_words;
-      uint32_t A_save = A;
-      uint32_t B_save = B;
-      uint32_t C_save = C;
-      uint32_t D_save = D;
-
-      /* First round: using the given function, the context and a constant
-         the next context is computed.  Because the algorithms processing
-         unit is a 32-bit word and it is determined to work on words in
-         little endian byte order we perhaps have to change the byte order
-         before the computation.  To reduce the work for the next steps
-         we store the swapped words in the array CORRECT_WORDS.  */
-
-#define OP(a, b, c, d, s, T)                                           \
-      do                                                               \
-        {                                                              \
-         a += FF (b, c, d) + (*cwp++ = SWAP (*words)) + T;             \
-         ++words;                                                      \
-         CYCLIC (a, s);                                                \
-         a += b;                                                       \
-        }                                                              \
-      while (0)
-
-      /* It is unfortunate that C does not provide an operator for
-         cyclic rotation.  Hope the C compiler is smart enough.  */
-#define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s)))
-
-      /* Before we start, one word to the strange constants.
-         They are defined in RFC 1321 as
-
-         T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64
-
-         Here is an equivalent invocation using Perl:
-
-         perl -e 'foreach(1..64){printf "0x%08x\n", int (4294967296 * abs (sin 
$_))}'
-       */
-
-      /* Round 1.  */
-      OP (A, B, C, D, 7, 0xd76aa478);
-      OP (D, A, B, C, 12, 0xe8c7b756);
-      OP (C, D, A, B, 17, 0x242070db);
-      OP (B, C, D, A, 22, 0xc1bdceee);
-      OP (A, B, C, D, 7, 0xf57c0faf);
-      OP (D, A, B, C, 12, 0x4787c62a);
-      OP (C, D, A, B, 17, 0xa8304613);
-      OP (B, C, D, A, 22, 0xfd469501);
-      OP (A, B, C, D, 7, 0x698098d8);
-      OP (D, A, B, C, 12, 0x8b44f7af);
-      OP (C, D, A, B, 17, 0xffff5bb1);
-      OP (B, C, D, A, 22, 0x895cd7be);
-      OP (A, B, C, D, 7, 0x6b901122);
-      OP (D, A, B, C, 12, 0xfd987193);
-      OP (C, D, A, B, 17, 0xa679438e);
-      OP (B, C, D, A, 22, 0x49b40821);
-
-      /* For the second to fourth round we have the possibly swapped words
-         in CORRECT_WORDS.  Redefine the macro to take an additional first
-         argument specifying the function to use.  */
-#undef OP
-#define OP(f, a, b, c, d, k, s, T)                                     \
-      do                                                               \
-       {                                                               \
-         a += f (b, c, d) + correct_words[k] + T;                      \
-         CYCLIC (a, s);                                                \
-         a += b;                                                       \
-       }                                                               \
-      while (0)
-
-      /* Round 2.  */
-      OP (FG, A, B, C, D, 1, 5, 0xf61e2562);
-      OP (FG, D, A, B, C, 6, 9, 0xc040b340);
-      OP (FG, C, D, A, B, 11, 14, 0x265e5a51);
-      OP (FG, B, C, D, A, 0, 20, 0xe9b6c7aa);
-      OP (FG, A, B, C, D, 5, 5, 0xd62f105d);
-      OP (FG, D, A, B, C, 10, 9, 0x02441453);
-      OP (FG, C, D, A, B, 15, 14, 0xd8a1e681);
-      OP (FG, B, C, D, A, 4, 20, 0xe7d3fbc8);
-      OP (FG, A, B, C, D, 9, 5, 0x21e1cde6);
-      OP (FG, D, A, B, C, 14, 9, 0xc33707d6);
-      OP (FG, C, D, A, B, 3, 14, 0xf4d50d87);
-      OP (FG, B, C, D, A, 8, 20, 0x455a14ed);
-      OP (FG, A, B, C, D, 13, 5, 0xa9e3e905);
-      OP (FG, D, A, B, C, 2, 9, 0xfcefa3f8);
-      OP (FG, C, D, A, B, 7, 14, 0x676f02d9);
-      OP (FG, B, C, D, A, 12, 20, 0x8d2a4c8a);
-
-      /* Round 3.  */
-      OP (FH, A, B, C, D, 5, 4, 0xfffa3942);
-      OP (FH, D, A, B, C, 8, 11, 0x8771f681);
-      OP (FH, C, D, A, B, 11, 16, 0x6d9d6122);
-      OP (FH, B, C, D, A, 14, 23, 0xfde5380c);
-      OP (FH, A, B, C, D, 1, 4, 0xa4beea44);
-      OP (FH, D, A, B, C, 4, 11, 0x4bdecfa9);
-      OP (FH, C, D, A, B, 7, 16, 0xf6bb4b60);
-      OP (FH, B, C, D, A, 10, 23, 0xbebfbc70);
-      OP (FH, A, B, C, D, 13, 4, 0x289b7ec6);
-      OP (FH, D, A, B, C, 0, 11, 0xeaa127fa);
-      OP (FH, C, D, A, B, 3, 16, 0xd4ef3085);
-      OP (FH, B, C, D, A, 6, 23, 0x04881d05);
-      OP (FH, A, B, C, D, 9, 4, 0xd9d4d039);
-      OP (FH, D, A, B, C, 12, 11, 0xe6db99e5);
-      OP (FH, C, D, A, B, 15, 16, 0x1fa27cf8);
-      OP (FH, B, C, D, A, 2, 23, 0xc4ac5665);
-
-      /* Round 4.  */
-      OP (FI, A, B, C, D, 0, 6, 0xf4292244);
-      OP (FI, D, A, B, C, 7, 10, 0x432aff97);
-      OP (FI, C, D, A, B, 14, 15, 0xab9423a7);
-      OP (FI, B, C, D, A, 5, 21, 0xfc93a039);
-      OP (FI, A, B, C, D, 12, 6, 0x655b59c3);
-      OP (FI, D, A, B, C, 3, 10, 0x8f0ccc92);
-      OP (FI, C, D, A, B, 10, 15, 0xffeff47d);
-      OP (FI, B, C, D, A, 1, 21, 0x85845dd1);
-      OP (FI, A, B, C, D, 8, 6, 0x6fa87e4f);
-      OP (FI, D, A, B, C, 15, 10, 0xfe2ce6e0);
-      OP (FI, C, D, A, B, 6, 15, 0xa3014314);
-      OP (FI, B, C, D, A, 13, 21, 0x4e0811a1);
-      OP (FI, A, B, C, D, 4, 6, 0xf7537e82);
-      OP (FI, D, A, B, C, 11, 10, 0xbd3af235);
-      OP (FI, C, D, A, B, 2, 15, 0x2ad7d2bb);
-      OP (FI, B, C, D, A, 9, 21, 0xeb86d391);
-
-      /* Add the starting values of the context.  */
-      A += A_save;
-      B += B_save;
-      C += C_save;
-      D += D_save;
-    }
-
-  /* Put checksum in context given as argument.  */
-  ctx->A = A;
-  ctx->B = B;
-  ctx->C = C;
-  ctx->D = D;
-}
diff --git a/libmailutils/message.c b/libmailutils/message.c
deleted file mode 100644
index caeba8f..0000000
--- a/libmailutils/message.c
+++ /dev/null
@@ -1,1294 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2009,
-   2010 Free Software Foundation, Inc.
-
-   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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <time.h>
-#include <unistd.h>
-#include <string.h>
-#include <pwd.h>
-
-#include <mailutils/cctype.h>
-#include <mailutils/address.h>
-#include <mailutils/attribute.h>
-#include <mailutils/auth.h>
-#include <mailutils/body.h>
-#include <mailutils/debug.h>
-#include <mailutils/envelope.h>
-#include <mailutils/errno.h>
-#include <mailutils/folder.h>
-#include <mailutils/header.h>
-#include <mailutils/mailbox.h>
-#include <mailutils/mutil.h>
-#include <mailutils/observer.h>
-#include <mailutils/stream.h>
-#include <mailutils/mu_auth.h>
-#include <mailutils/nls.h>
-#include <mailutils/md5.h>
-#include <mailutils/io.h>
-
-#include <mailutils/sys/message.h>
-#include <mailutils/sys/stream.h>
-
-#define MESSAGE_MODIFIED        0x10000
-#define MESSAGE_INTERNAL_STREAM 0x20000
-
-
-/* Message stream */
-
-enum _message_stream_state
-  {
-    _mss_init,
-    _mss_header,
-    _mss_body,
-    _mss_eof
-  };
-
-struct _mu_message_stream
-{
-  struct _mu_stream stream;
-  mu_message_t msg;
-  enum _message_stream_state state;
-  mu_stream_t transport;
-  mu_off_t limit;
-};
-
-static int
-_check_stream_state (struct _mu_message_stream *str)
-{
-  int rc = 0;
-  
-  if (str->transport && mu_stream_eof (str->transport))
-    mu_stream_destroy (&str->transport);
-  
-  switch (str->state)
-    {
-    case _mss_init:
-      if (!str->transport)
-       {
-         rc = mu_header_get_streamref (str->msg->header, &str->transport);
-         if (rc == 0)
-           {
-             str->state = _mss_header;
-             rc = mu_stream_seek (str->transport, 0, MU_SEEK_SET, NULL);
-           }
-       }
-      break;
-      
-    case _mss_header:
-      if (!str->transport)
-       {
-         rc = mu_body_get_streamref (str->msg->body, &str->transport);
-         if (rc == 0)
-           {
-             str->state = _mss_body;
-             rc = mu_stream_seek (str->transport, 0, MU_SEEK_SET, NULL);
-           }
-       }
-      break;
-      
-    case _mss_body:
-      if (!str->transport)
-       str->state = _mss_eof;
-    case _mss_eof:
-      break;
-    }
-  return rc;
-}
-
-static void
-_message_stream_done (struct _mu_stream *str)
-{
-  struct _mu_message_stream *sp = (struct _mu_message_stream *)str;
-  mu_stream_destroy (&sp->transport);
-}
-
-static int
-_message_stream_flush (struct _mu_stream *str)
-{
-  struct _mu_message_stream *sp = (struct _mu_message_stream *)str;
-  int rc = _check_stream_state (sp);
-  if (rc)
-    return rc;
-  return mu_stream_flush (sp->transport);
-}
-  
-static int
-_message_stream_size (struct _mu_stream *str, mu_off_t *psize)
-{
-  struct _mu_message_stream *sp = (struct _mu_message_stream *)str;
-  size_t hsize, bsize;
-  mu_header_size (sp->msg->header, &hsize);
-  mu_body_size (sp->msg->body, &bsize);
-  if (psize)
-    *psize = hsize + bsize;
-  return 0;
-}
-
-static int
-_message_stream_seek (struct _mu_stream *str, mu_off_t off, mu_off_t *ppos)
-{
-  struct _mu_message_stream *sp = (struct _mu_message_stream *)str;
-  size_t hsize, size;
-  int rc;
-  
-  rc = _check_stream_state (sp);
-  if (rc)
-    return rc;
-  mu_header_size (sp->msg->header, &hsize);
-  mu_body_size (sp->msg->body, &size);
-  size += hsize;
-  
-  if (off < 0 || off >= size)
-    return ESPIPE;
-
-  switch (sp->state)
-    {
-    case _mss_eof:
-      sp->state = _mss_init;
-      rc = _check_stream_state (sp);
-      if (rc)
-       return rc;
-      /* fall through */
-    case _mss_header:
-      if (off < hsize)
-       break;
-      mu_stream_destroy (&sp->transport);
-      rc = _check_stream_state (sp);
-      if (rc)
-       return rc;
-      /* fall through */
-    case _mss_body:
-      if (off > hsize)
-       off -= hsize;   
-      else
-       {
-         mu_stream_destroy (&sp->transport);
-         sp->state = _mss_init;
-         rc = _check_stream_state (sp);
-         if (rc)
-           return rc;
-       }
-
-      break;
-
-    default:
-      break;
-    }
-  rc = mu_stream_seek (sp->transport, off, MU_SEEK_SET, &off);
-  if (rc == 0)
-    {
-      if (sp->state == _mss_body)
-       off += hsize;
-      *ppos = off;
-    }
-  return rc;
-}
-
-static int
-_message_stream_read (struct _mu_stream *str, char *buf, size_t bufsize,
-                     size_t *pnread)
-{
-  struct _mu_message_stream *sp = (struct _mu_message_stream *)str;
-  size_t nread = 0;
-  int rc;
-  
-  while (bufsize)
-    {
-      size_t n;
-      rc = _check_stream_state (sp);
-      if (rc)
-       break;
-      if (sp->state == _mss_eof)
-       break;
-      rc = mu_stream_read (sp->transport, buf, bufsize, &n);
-      nread += n;
-      buf += n;
-      bufsize -= n;
-    }
-  *pnread = nread;
-  return rc;
-}
-
-static int
-_message_stream_readdelim (struct _mu_stream *str, char *buf, size_t bufsize,
-                          int delim, size_t *pnread)
-{
-  struct _mu_message_stream *sp = (struct _mu_message_stream *)str;
-  size_t nread = 0;
-  int rc;
-  
-  while (bufsize)
-    {
-      size_t n;
-      rc = _check_stream_state (sp);
-      if (rc)
-       break;
-      if (sp->state == _mss_eof)
-       break;
-      rc = mu_stream_readdelim (sp->transport, buf, bufsize, delim, &n);
-      if (rc || n == 0)
-       break;
-      nread += n;
-      buf += n;
-      bufsize -= n;
-    }
-  *pnread = nread;
-  return rc;
-}  
-
-#if 0
-static int
-_message_stream_write (struct _mu_stream *str,
-                      const char *buf, size_t bufsize,
-                      size_t *pnwritten)
-{
-  struct _mu_message_stream *sp = (struct _mu_message_stream *)str;
-  
-  /* FIXME */
-}
-#endif
-
-static int
-_message_stream_create (mu_stream_t *pmsg, mu_message_t msg, int flags)
-{
-  struct _mu_message_stream *sp;
-
-  sp = (struct _mu_message_stream *) _mu_stream_create (sizeof (*sp),
-                                                       flags |
-                                                       MU_STREAM_SEEK |
-                                                       _MU_STR_OPEN);
-  if (!sp)
-    return ENOMEM;
-
-  sp->stream.read = _message_stream_read;
-  sp->stream.readdelim = _message_stream_readdelim;
-  /* FIXME: Write is not defined */
-  /*  sp->stream.write = _message_stream_write;*/
-  sp->stream.done = _message_stream_done;
-  sp->stream.flush = _message_stream_flush;
-  sp->stream.seek = _message_stream_seek; 
-  sp->stream.size = _message_stream_size;
-  sp->state = _mss_init;
-  sp->msg = msg;
-  *pmsg = (mu_stream_t) sp;
-  return 0;
-}
-
-
-enum eoh_state
-  {
-    eoh_no,
-    eoh_maybe,
-    eoh_yes
-  };
-
-/* Message header stuff */
-static enum eoh_state
-string_find_eoh (enum eoh_state eoh, const char *str, size_t len,
-                size_t *ppos)
-{
-  size_t pos;
-
-  if (eoh == eoh_maybe && *str == '\n')
-    {
-      *ppos = 0;
-      return eoh_yes;
-    }
-  
-  for (pos = 0; pos < len - 1; pos++)
-    if (str[pos] == '\n' && str[pos + 1] == '\n')
-      {
-       *ppos = pos + 1;
-       return eoh_yes;
-      }
-  
-  *ppos = pos + 1;
-  return str[pos] == '\n' ? eoh_maybe : eoh_no;
-}
-
-#define MIN_HEADER_BUF_SIZE 2048
-
-static int
-_header_fill (mu_stream_t stream, char **pbuf, size_t *plen)
-{
-  int status = 0;
-  char *buffer = NULL;
-  size_t bufsize = 0;
-  char inbuf[MIN_HEADER_BUF_SIZE];
-  size_t nread;
-  enum eoh_state eoh = eoh_no;
-  
-  status = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
-  if (status)
-    return status;
-      
-  while (eoh != eoh_yes
-        && (status = mu_stream_read (stream, inbuf, sizeof (inbuf), &nread))
-           == 0
-        && nread)
-    {
-      char *nbuf;
-      size_t len;
-
-      eoh = string_find_eoh (eoh, inbuf, nread, &len);
-      
-      nbuf = realloc (buffer, bufsize + len);
-      if (!nbuf)
-       {
-         status = ENOMEM;
-         break;
-       }
-      memcpy (nbuf + bufsize, inbuf, len);
-      buffer = nbuf;
-      bufsize += len;
-    }
-
-  if (status)
-    free (buffer);
-  else
-    {
-      *pbuf = buffer;
-      *plen = bufsize;
-    }
-  return status;
-}
-    
-static int
-message_header_fill (void *data, char **pbuf, size_t *plen)
-{
-  int status = 0;
-  mu_message_t msg = data;
-  mu_stream_t stream;
-
-  status = mu_message_get_streamref (msg, &stream);
-  if (status == 0)
-    {
-      status = _header_fill (stream, pbuf, plen);
-      mu_stream_destroy (&stream);
-    }
-  return status;
-}
-
-
-/* Message envelope */
-static int
-message_envelope_date (mu_envelope_t envelope, char *buf, size_t len,
-                      size_t *pnwrite)
-{
-  mu_message_t msg = mu_envelope_get_owner (envelope);
-  time_t t;
-  size_t n;
-
-  if (msg == NULL)
-    return EINVAL;
-
-  /* FIXME: extract the time from "Date:".  */
-
-  if (buf == NULL || len == 0)
-    {
-      n = MU_ENVELOPE_DATE_LENGTH;
-    }
-  else
-    {
-      char tmpbuf[MU_ENVELOPE_DATE_LENGTH+1];
-      t = time (NULL);
-      n = mu_strftime (tmpbuf, sizeof tmpbuf, 
-                       MU_ENVELOPE_DATE_FORMAT, localtime (&t));
-      n = mu_cpystr (buf, tmpbuf, len);
-    }
-  if (pnwrite)
-    *pnwrite = n;
-  return 0;
-}
-
-static int
-message_envelope_sender (mu_envelope_t envelope, char *buf, size_t len,
-                        size_t *pnwrite)
-{
-  mu_message_t msg = mu_envelope_get_owner (envelope);
-  mu_header_t header = NULL;
-  size_t n = 0;
-  int status;
-
-  if (msg == NULL)
-    return EINVAL;
-
-  /* Can it be extracted from the From:  */
-  mu_message_get_header (msg, &header);
-  status = mu_header_get_value (header, MU_HEADER_FROM, NULL, 0, &n);
-  if (status == 0 && n != 0)
-    {
-      char *sender;
-      mu_address_t address = NULL;
-      sender = calloc (1, n + 1);
-      if (sender == NULL)
-       return ENOMEM;
-      mu_header_get_value (header, MU_HEADER_FROM, sender, n + 1, NULL);
-      if (mu_address_create (&address, sender) == 0)
-       mu_address_get_email (address, 1, buf, n + 1, pnwrite);
-      free (sender);
-      mu_address_destroy (&address);
-      return 0;
-    }
-  else if (status == EAGAIN)
-    return status;
-
-  /* oops! We are still here */
-  {
-    struct mu_auth_data *auth = mu_get_auth_by_uid (getuid ());
-    const char *sender = auth ? auth->name : "unknown";
-    n = strlen (sender);
-    if (buf && len > 0)
-      {
-       len--; /* One for the null.  */
-       n = (n < len) ? n : len;
-       memcpy (buf, auth->name, n);
-       buf[n] = '\0';
-      }
-    if (auth)
-      mu_auth_data_free (auth);
-  }
-
-  if (pnwrite)
-    *pnwrite = n;
-  return 0;
-}
-
-
-
-/*  Allocate ressources for the mu_message_t.  */
-int
-mu_message_create (mu_message_t *pmsg, void *owner)
-{
-  mu_message_t msg;
-  int status;
-
-  if (pmsg == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  msg = calloc (1, sizeof (*msg));
-  if (msg == NULL)
-    return ENOMEM;
-  status = mu_monitor_create (&msg->monitor, 0, msg);
-  if (status != 0)
-    {
-      free (msg);
-      return status;
-    }
-  msg->owner = owner;
-  msg->ref = 1;
-  *pmsg = msg;
-  return 0;
-}
-
-void
-mu_message_destroy (mu_message_t *pmsg, void *owner)
-{
-  if (pmsg && *pmsg)
-    {
-      mu_message_t msg = *pmsg;
-      mu_monitor_t monitor = msg->monitor;
-      int destroy_lock = 0;
-
-      mu_monitor_wrlock (monitor);
-      /* Note: msg->ref may be incremented by mu_message_ref without
-        additional checking for its owner, therefore decrementing
-        it must also occur independently of the owner checking. Due
-        to this inconsistency ref may reach negative values, which
-        is very unfortunate.
-
-        The `owner' stuff is a leftover from older mailutils versions.
-        There is an ongoing attempt to remove it in the stream-cleanup
-        branch. When it is ready, it will be merged to the HEAD and this
-        will finally resolve this issue. */
-      if (msg->ref > 0)
-       msg->ref--;
-      if ((msg->owner && msg->owner == owner)
-         || (msg->owner == NULL && msg->ref <= 0))
-       {
-         destroy_lock =  1;
-         /* Notify the listeners.  */
-         /* FIXME: to be removed since we do not support this event.  */
-         if (msg->observable)
-           {
-             mu_observable_notify (msg->observable, MU_EVT_MESSAGE_DESTROY,
-                                   msg);
-             mu_observable_destroy (&msg->observable, msg);
-           }
-
-         /* Envelope.  */
-         if (msg->envelope)
-           mu_envelope_destroy (&msg->envelope, msg);
-
-         /* Header.  */
-         if (msg->header)
-           mu_header_destroy (&msg->header);
-
-         /* Body.  */
-         if (msg->body)
-           mu_body_destroy (&msg->body, msg);
-
-         /* Attribute.  */
-         if (msg->attribute)
-           mu_attribute_destroy (&msg->attribute, msg);
-
-         /* Stream.  */
-         if (msg->stream)
-           mu_stream_destroy (&msg->stream);
-
-         /*  Mime.  */
-         if (msg->mime)
-           mu_mime_destroy (&msg->mime);
-
-         /* Loose the owner.  */
-         msg->owner = NULL;
-
-         free (msg);
-       }
-      mu_monitor_unlock (monitor);
-      if (destroy_lock)
-       mu_monitor_destroy (&monitor, msg);
-      /* Loose the link */
-      *pmsg = NULL;
-    }
-}
-
-int
-mu_message_create_copy (mu_message_t *to, mu_message_t from)
-{
-  int status = 0;
-  mu_stream_t fromstr = NULL;
-  mu_stream_t tmp = NULL;
-
-  if (!to)
-    return MU_ERR_OUT_PTR_NULL;
-  if (!from)
-    return EINVAL;
-
-  status = mu_memory_stream_create (&tmp, MU_STREAM_RDWR|MU_STREAM_SEEK);
-  if (status)
-    return status;
-
-  status = mu_message_get_streamref (from, &fromstr);
-  if (status)
-    {
-      mu_stream_destroy (&tmp);
-      return status;
-    }
-
-  status = mu_stream_copy (tmp, fromstr, 0, NULL);
-  if (status == 0)
-    {
-      status = mu_message_create (to, NULL);
-      if (status == 0)
-       mu_message_set_stream (*to, tmp, NULL);
-    }
-
-  if (status)
-    mu_stream_destroy (&tmp);
-  mu_stream_destroy (&fromstr);
-
-  return status;
-}
-
-int
-mu_message_ref (mu_message_t msg)
-{
-  if (msg)
-    {
-      mu_monitor_wrlock (msg->monitor);
-      msg->ref++;
-      mu_monitor_unlock (msg->monitor);
-    }
-  return 0;
-}
-
-void *
-mu_message_get_owner (mu_message_t msg)
-{
-  return (msg == NULL) ? NULL : msg->owner;
-}
-
-int
-mu_message_is_modified (mu_message_t msg)
-{
-  int mod = 0;
-  if (msg)
-    {
-      mod |= mu_header_is_modified (msg->header);
-      mod |= mu_attribute_is_modified (msg->attribute);
-      mod |= mu_body_is_modified (msg->body);
-      mod |= msg->flags;
-    }
-  return mod;
-}
-
-int
-mu_message_clear_modified (mu_message_t msg)
-{
-  if (msg)
-    {
-      if (msg->header)
-       mu_header_clear_modified (msg->header);
-      if (msg->attribute)
-       mu_attribute_clear_modified (msg->attribute);
-      if (msg->body)
-       mu_body_clear_modified (msg->body);
-      msg->flags &= ~MESSAGE_MODIFIED;
-    }
-  return 0;
-}
-
-int
-mu_message_get_mailbox (mu_message_t msg, mu_mailbox_t *pmailbox)
-{
-  if (msg == NULL)
-    return EINVAL;
-  if (pmailbox == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  *pmailbox = msg->mailbox;
-  return 0;
-}
-
-int
-mu_message_set_mailbox (mu_message_t msg, mu_mailbox_t mailbox, void *owner)
-{
-  if (msg == NULL)
-    return EINVAL;
-  if (msg->owner != owner)
-    return EACCES;
-  msg->mailbox = mailbox;
-  return 0;
-}
-
-int
-mu_message_get_header (mu_message_t msg, mu_header_t *phdr)
-{
-  if (msg == NULL)
-    return EINVAL;
-  if (phdr == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-
-  if (msg->header == NULL)
-    {
-      mu_header_t header;
-      int status = mu_header_create (&header, NULL, 0);
-      if (status != 0)
-       return status;
-      if (msg->stream)
-       mu_header_set_fill (header, message_header_fill, msg);
-      status = mu_header_size (header, &msg->orig_header_size);
-      if (status)
-       return status;
-      msg->header = header;
-    }
-  *phdr = msg->header;
-  return 0;
-}
-
-/* Note: mu_message_set_header steals the reference to hdr */
-int
-mu_message_set_header (mu_message_t msg, mu_header_t hdr, void *owner)
-{
-  if (msg == NULL )
-    return EINVAL;
-  if (msg->owner != owner)
-     return EACCES;
-  if (msg->header)
-    mu_header_destroy (&msg->header);
-  msg->header = hdr;
-  msg->flags |= MESSAGE_MODIFIED;
-  return 0;
-}
-
-int
-mu_message_get_body (mu_message_t msg, mu_body_t *pbody)
-{
-  if (msg == NULL)
-    return EINVAL;
-  if (pbody == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-
-  /* Is it a floating mesg.  */
-  if (msg->body == NULL)
-    {
-      mu_body_t body;
-      int status = mu_body_create (&body, msg);
-      if (status != 0)
-       return status;
-      /* If a stream is already set, use it to create the body stream.  */
-      /* FIXME: I'm not sure if the second condition is really needed */
-      if (msg->stream/* && (msg->flags & MESSAGE_INTERNAL_STREAM)*/)
-       {
-         mu_stream_t stream;
-         int flags = 0;
-
-         /* FIXME: The actual mu_header_size cannot be used as offset,
-            because the headers might have been modified in between. */
-         
-         mu_stream_get_flags (msg->stream, &flags);
-         status = mu_streamref_create_abridged (&stream, msg->stream,
-                                                msg->orig_header_size, 0);
-         if (status)
-           {
-             mu_body_destroy (&body, msg);
-             return status;
-           }
-         mu_body_set_stream (body, stream, msg);
-       }
-      msg->body = body;
-    }
-  *pbody = msg->body;
-  return 0;
-}
-
-int
-mu_message_set_body (mu_message_t msg, mu_body_t body, void *owner)
-{
-  if (msg == NULL )
-    return EINVAL;
-  if (msg->owner != owner)
-    return EACCES;
-  /* Make sure we destroy the old if it was owned by the mesg.  */
-  /* FIXME:  I do not know if somebody has already a ref on this ? */
-  if (msg->body)
-    mu_body_destroy (&msg->body, msg);
-  msg->body = body;
-  msg->flags |= MESSAGE_MODIFIED;
-  return 0;
-}
-
-int
-mu_message_set_stream (mu_message_t msg, mu_stream_t stream, void *owner)
-{
-  if (msg == NULL)
-    return EINVAL;
-  if (msg->owner != owner)
-    return EACCES;
-  if (msg->stream)
-    mu_stream_destroy (&msg->stream);
-  msg->stream = stream;
-  msg->flags |= MESSAGE_MODIFIED;
-  msg->flags &= ~MESSAGE_INTERNAL_STREAM;
-  return 0;
-}
-
-static int
-_message_get_stream (mu_message_t msg, mu_stream_t *pstream, int ref)
-{
-  int status;
-
-  if (msg == NULL)
-    return EINVAL;
-  if (pstream == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-
-  if (msg->stream == NULL)
-    {
-      if (msg->_get_stream)
-       {
-         status = msg->_get_stream (msg, &msg->stream);
-         if (status)
-           return status;
-       }
-      else
-       {
-         mu_header_t hdr;
-         mu_body_t body;
-
-         /* FIXME: Kind of a kludge: make sure the message has header
-            and body initialized. */
-         status = mu_message_get_header (msg, &hdr);
-         if (status)
-           return status;
-         status = mu_message_get_body (msg, &body);
-         if (status)
-           return status;
-         
-         status = _message_stream_create (&msg->stream, msg, MU_STREAM_RDWR);
-         if (status)
-           return status;
-         msg->flags |= MESSAGE_INTERNAL_STREAM;
-       }
-    }
-  
-  if (!ref)
-    {
-      *pstream = msg->stream;
-      return 0;
-    }
-  return mu_streamref_create (pstream, msg->stream);
-}
-
-int
-mu_message_get_stream (mu_message_t msg, mu_stream_t *pstream)
-{
-  /* FIXME: Deprecation warning */
-  return _message_get_stream (msg, pstream, 0);
-}
-
-int
-mu_message_get_streamref (mu_message_t msg, mu_stream_t *pstream)
-{
-  return _message_get_stream (msg, pstream, 1);
-}
-
-int
-mu_message_set_get_stream (mu_message_t msg,
-                          int (*_getstr) (mu_message_t, mu_stream_t *),
-                          void *owner)
-{
-  if (msg == NULL)
-    return EINVAL;
-  if (msg->owner != owner)
-    return EACCES;
-  msg->_get_stream = _getstr;
-  return 0;
-}
-
-int
-mu_message_set_lines (mu_message_t msg, int (*_lines)
-                  (mu_message_t, size_t *), void *owner)
-{
-  if (msg == NULL)
-    return EINVAL;
-  if (msg->owner != owner)
-    return EACCES;
-  msg->_lines = _lines;
-  return 0;
-}
-
-int
-mu_message_lines (mu_message_t msg, size_t *plines)
-{
-  size_t hlines, blines;
-  int ret = 0;
-
-  if (msg == NULL)
-    return EINVAL;
-  /* Overload.  */
-  if (msg->_lines)
-    return msg->_lines (msg, plines);
-  if (plines)
-    {
-      hlines = blines = 0;
-      if ( ( ret = mu_header_lines (msg->header, &hlines) ) == 0 )
-             ret = mu_body_lines (msg->body, &blines);
-      *plines = hlines + blines;
-    }
-  return ret;
-}
-
-int
-mu_message_set_size (mu_message_t msg, int (*_size)
-                 (mu_message_t, size_t *), void *owner)
-{
-  if (msg == NULL)
-    return EINVAL;
-  if (msg->owner != owner)
-    return EACCES;
-  msg->_size = _size;
-  return 0;
-}
-
-int
-mu_message_size (mu_message_t msg, size_t *psize)
-{
-  size_t hsize, bsize;
-  int ret = 0;
-
-  if (msg == NULL)
-    return EINVAL;
-  /* Overload ? */
-  if (msg->_size)
-    return msg->_size (msg, psize);
-  if (psize)
-    {
-      mu_header_t hdr = NULL;
-      mu_body_t body = NULL;
-      
-      hsize = bsize = 0;
-      mu_message_get_header (msg, &hdr);
-      mu_message_get_body (msg, &body);
-      if ( ( ret = mu_header_size (hdr, &hsize) ) == 0 )
-       ret = mu_body_size (body, &bsize);
-      *psize = hsize + bsize;
-    }
-  return ret;
-}
-
-int
-mu_message_get_envelope (mu_message_t msg, mu_envelope_t *penvelope)
-{
-  if (msg == NULL)
-    return EINVAL;
-  if (penvelope == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-
-  if (msg->envelope == NULL)
-    {
-      mu_envelope_t envelope;
-      int status = mu_envelope_create (&envelope, msg);
-      if (status != 0)
-       return status;
-      mu_envelope_set_sender (envelope, message_envelope_sender, msg);
-      mu_envelope_set_date (envelope, message_envelope_date, msg);
-      msg->envelope = envelope;
-    }
-  *penvelope = msg->envelope;
-  return 0;
-}
-
-int
-mu_message_set_envelope (mu_message_t msg, mu_envelope_t envelope, void *owner)
-{
-  if (msg == NULL)
-    return EINVAL;
-  if (msg->owner != owner)
-    return EACCES;
-  if (msg->envelope)
-    mu_envelope_destroy (&msg->envelope, msg);
-  msg->envelope = envelope;
-  msg->flags |= MESSAGE_MODIFIED;
-  return 0;
-}
-
-int
-mu_message_get_attribute (mu_message_t msg, mu_attribute_t *pattribute)
-{
-  if (msg == NULL)
-    return EINVAL;
-  if (pattribute == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  if (msg->attribute == NULL)
-    {
-      mu_attribute_t attribute;
-      int status = mu_attribute_create (&attribute, msg);
-      if (status != 0)
-       return status;
-      msg->attribute = attribute;
-    }
-  *pattribute = msg->attribute;
-  return 0;
-}
-
-int
-mu_message_set_attribute (mu_message_t msg, mu_attribute_t attribute, void 
*owner)
-{
-  if (msg == NULL)
-   return EINVAL;
-  if (msg->owner != owner)
-    return EACCES;
-  if (msg->attribute)
-    mu_attribute_destroy (&msg->attribute, owner);
-  msg->attribute = attribute;
-  msg->flags |= MESSAGE_MODIFIED;
-  return 0;
-}
-
-int
-mu_message_get_uid (mu_message_t msg, size_t *puid)
-{
-  if (msg == NULL)
-    return EINVAL;
-  if (msg->_get_uid)
-    return msg->_get_uid (msg, puid);
-  *puid = 0;
-  return 0;
-}
-
-int
-mu_message_get_uidl (mu_message_t msg, char *buffer, size_t buflen,
-                    size_t *pwriten)
-{
-  mu_header_t header = NULL;
-  size_t n = 0;
-  int status;
-
-  if (msg == NULL || buffer == NULL || buflen == 0)
-    return EINVAL;
-
-  buffer[0] = '\0';
-  /* Try the function overload if error fallback.  */
-  if (msg->_get_uidl)
-    {
-      status = msg->_get_uidl (msg, buffer, buflen, pwriten);
-      if (status == 0)
-       return status;
-    }
-
-  /* Be compatible with Qpopper ? qppoper saves the UIDL in "X-UIDL".
-     We generate a chksum and save it in the header.  */
-  mu_message_get_header (msg, &header);
-  status = mu_header_get_value_unfold (header, "X-UIDL", buffer, buflen, &n);
-  if (status != 0 || n == 0)
-    {
-      size_t uid = 0;
-      struct mu_md5_ctx md5context;
-      mu_stream_t stream = NULL;
-      char buf[1024];
-      unsigned char md5digest[16];
-      char *tmp;
-      n = 0;
-      mu_message_get_uid (msg, &uid);
-      mu_message_get_streamref (msg, &stream);
-      mu_md5_init_ctx (&md5context);
-      status = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
-      if (status == 0)
-       {
-         while (mu_stream_read (stream, buf, sizeof (buf), &n) == 0
-                && n > 0)
-           mu_md5_process_bytes (buf, n, &md5context);
-         mu_md5_finish_ctx (&md5context, md5digest);
-         tmp = buf;
-         for (n = 0; n < 16; n++, tmp += 2)
-           sprintf (tmp, "%02x", md5digest[n]);
-         *tmp = '\0';
-         /* POP3 rfc says that an UID should not be longer than 70.  */
-         snprintf (buf + 32, 70, ".%lu.%lu", (unsigned long)time (NULL), 
-                   (unsigned long) uid);
-
-         mu_header_set_value (header, "X-UIDL", buf, 1);
-         buflen--; /* leave space for the NULL.  */
-         strncpy (buffer, buf, buflen)[buflen] = '\0';
-       }
-      mu_stream_destroy (&stream);
-    }
-  return status;
-}
-
-int
-mu_message_get_qid (mu_message_t msg, mu_message_qid_t *pqid)
-{
-  if (msg == NULL)
-    return EINVAL;
-  if (!msg->_get_qid)
-    return ENOSYS;
-  return msg->_get_qid (msg, pqid);
-}
-    
-int
-mu_message_set_qid (mu_message_t msg,
-                   int (*_get_qid) (mu_message_t, mu_message_qid_t *),
-                   void *owner)
-{
-  if (msg == NULL)
-    return EINVAL;
-  if (msg->owner != owner)
-    return EACCES;
-  msg->_get_qid = _get_qid;
-  return 0;
-}
-
-int
-mu_message_set_uid (mu_message_t msg, int (*_get_uid) (mu_message_t, size_t *),
-                   void *owner)
-{
-  if (msg == NULL)
-    return EINVAL;
-  if (msg->owner != owner)
-    return EACCES;
-  msg->_get_uid = _get_uid;
-  return 0;
-}
-
-int
-mu_message_set_uidl (mu_message_t msg,
-                 int (* _get_uidl) (mu_message_t, char *, size_t, size_t *),
-                 void *owner)
-{
-  if (msg == NULL)
-    return EINVAL;
-  if (msg->owner != owner)
-    return EACCES;
-  msg->_get_uidl = _get_uidl;
-  return 0;
-}
-
-int
-mu_message_set_is_multipart (mu_message_t msg,
-                         int (*_is_multipart) (mu_message_t, int *),
-                         void *owner)
-{
-  if (msg == NULL)
-    return EINVAL;
-  if (msg->owner != owner)
-    return EACCES;
-  msg->_is_multipart = _is_multipart;
-  return 0;
-}
-
-int
-mu_message_is_multipart (mu_message_t msg, int *pmulti)
-{
-  if (msg && pmulti)
-    {
-      if (msg->_is_multipart)
-       return msg->_is_multipart (msg, pmulti);
-      if (msg->mime == NULL)
-       {
-         int status = mu_mime_create (&msg->mime, msg, 0);
-         if (status != 0)
-           return 0;
-       }
-      *pmulti = mu_mime_is_multipart(msg->mime);
-    }
-  return 0;
-}
-
-int
-mu_message_get_num_parts (mu_message_t msg, size_t *pparts)
-{
-  if (msg == NULL || pparts == NULL)
-    return EINVAL;
-
-  if (msg->_get_num_parts)
-    return msg->_get_num_parts (msg, pparts);
-
-  if (msg->mime == NULL)
-    {
-      int status = mu_mime_create (&msg->mime, msg, 0);
-      if (status != 0)
-       return status;
-    }
-  return mu_mime_get_num_parts (msg->mime, pparts);
-}
-
-int
-mu_message_set_get_num_parts (mu_message_t msg,
-                          int (*_get_num_parts) (mu_message_t, size_t *),
-                          void *owner)
-{
-  if (msg == NULL)
-    return EINVAL;
-  if (msg->owner != owner)
-    return EACCES;
-  msg->_get_num_parts = _get_num_parts;
-  return 0;
-}
-
-int
-mu_message_get_part (mu_message_t msg, size_t part, mu_message_t *pmsg)
-{
-  if (msg == NULL || pmsg == NULL)
-    return EINVAL;
-
-  /* Overload.  */
-  if (msg->_get_part)
-    return msg->_get_part (msg, part, pmsg);
-
-  if (msg->mime == NULL)
-    {
-      int status = mu_mime_create (&msg->mime, msg, 0);
-      if (status != 0)
-       return status;
-    }
-  return mu_mime_get_part (msg->mime, part, pmsg);
-}
-
-int
-mu_message_set_get_part (mu_message_t msg, int (*_get_part)
-                     (mu_message_t, size_t, mu_message_t *),
-                     void *owner)
-{
-  if (msg == NULL)
-    return EINVAL;
-  if (msg->owner != owner)
-    return EACCES;
-  msg->_get_part = _get_part;
-  return 0;
-}
-
-int
-mu_message_get_observable (mu_message_t msg, mu_observable_t *pobservable)
-{
-  if (msg == NULL || pobservable == NULL)
-    return EINVAL;
-
-  if (msg->observable == NULL)
-    {
-      int status = mu_observable_create (&msg->observable, msg);
-      if (status != 0)
-       return status;
-    }
-  *pobservable = msg->observable;
-  return 0;
-}
-
-int
-mu_message_save_to_mailbox (mu_message_t msg, 
-                            mu_debug_t debug,
-                           const char *toname, int perms)
-{
-  int rc = 0;
-  mu_mailbox_t to = 0;
-
-  if ((rc = mu_mailbox_create_default (&to, toname)))
-    {
-      MU_DEBUG2 (debug, MU_DEBUG_ERROR,
-                "mu_mailbox_create_default (%s) failed: %s\n", toname,
-                mu_strerror (rc));
-      goto end;
-    }
-
-  if (debug && (rc = mu_mailbox_set_debug (to, debug)))
-       goto end;
-
-  if ((rc = mu_mailbox_open (to,
-                            MU_STREAM_WRITE | MU_STREAM_CREAT
-                            | (perms & MU_STREAM_IMASK))))
-    {
-      MU_DEBUG2 (debug, MU_DEBUG_ERROR,
-                "mu_mailbox_open (%s) failed: %s\n", toname,
-                mu_strerror (rc));
-      goto end;
-    }
-
-  if ((rc = mu_mailbox_append_message (to, msg)))
-    {
-      MU_DEBUG2 (debug, MU_DEBUG_ERROR,
-                "mu_mailbox_append_message (%s) failed: %s\n", toname,
-                mu_strerror (rc));
-      goto end;
-    }
-
-end:
-
-  if (!rc)
-    {
-      if ((rc = mu_mailbox_close (to)))
-       MU_DEBUG2 (debug, MU_DEBUG_ERROR,
-                  "mu_mailbox_close (%s) failed: %s\n", toname,
-                  mu_strerror (rc));
-    }
-  else
-    mu_mailbox_close (to);
-
-  mu_mailbox_destroy (&to);
-
-  return rc;
-}
-
diff --git a/libmailutils/message_stream.c b/libmailutils/message_stream.c
deleted file mode 100644
index 9f590d9..0000000
--- a/libmailutils/message_stream.c
+++ /dev/null
@@ -1,440 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2002, 2005, 2006, 2007, 2009, 2010
-   Free Software Foundation, Inc.
-
-   GNU Mailutils is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3, or (at your option)
-   any later version.
-
-   GNU Mailutils is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
-
-/* This file implements an MH draftfile stream: a read-only stream used
-   to transparently pass MH draftfiles to mailers. The only difference
-   between the usual RFC822 and MH draft is that the latter allows to use
-   a string of dashes to separate the headers from the body. */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include <ctype.h>
-#include <string.h>
-
-#include <mailutils/types.h>
-#include <mailutils/address.h>
-#include <mailutils/alloc.h>
-#include <mailutils/envelope.h>
-#include <mailutils/message.h>
-#include <mailutils/header.h>
-#include <mailutils/body.h>
-#include <mailutils/stream.h>
-#include <mailutils/mutil.h>
-#include <mailutils/errno.h>
-#include <mailutils/error.h>
-#include <mailutils/cctype.h>
-#include <mailutils/cstr.h>
-#include <mailutils/sys/message_stream.h>
-
-
-static int
-_env_msg_date (mu_envelope_t envelope, char *buf, size_t len, size_t *pnwrite)
-{
-  struct _mu_message_stream *str = mu_envelope_get_owner (envelope);
-  
-  if (!str || !str->date)
-    return EINVAL;
-  if (buf)
-    {
-      strncpy (buf, str->date, len);
-      buf[len-1] = 0;
-      if (pnwrite)
-       *pnwrite = len;
-    }
-  else if (!pnwrite)
-    return EINVAL;
-  else
-    *pnwrite = strlen (str->date);
-  return 0;
-}
-
-static int
-_env_msg_sender (mu_envelope_t envelope, char *buf, size_t len,
-                size_t *pnwrite)
-{
-  struct _mu_message_stream *str = mu_envelope_get_owner (envelope);
-  
-  if (!str || !str->from)
-    return EINVAL;
-  if (buf)
-    {
-      strncpy (buf, str->from, len);
-      buf[len-1] = 0;
-      if (pnwrite)
-       *pnwrite = len;
-    }
-  else if (!pnwrite)
-    return EINVAL;
-  else
-    *pnwrite = strlen (str->from);
-    
-  return 0;
-}
-
-
-static int
-_message_read (mu_stream_t stream, char *optr, size_t osize, size_t *nbytes)
-{
-  int rc;
-  struct _mu_message_stream *s = (struct _mu_message_stream*) stream;
-  mu_off_t offset = s->offset + s->envelope_length;
-  size_t rsize;
-  
-  if (offset < s->mark_offset)
-    {
-      if (offset + osize >= s->mark_offset)
-       osize = s->mark_offset - offset;
-    }
-  else
-    offset += s->mark_length;
-  /* FIXME: Seeking each time before read is awkward. The streamref
-     should be modified to take care of it */
-  rc = mu_stream_seek (s->transport, offset, MU_SEEK_SET, NULL);
-  if (rc == 0)
-    rc = mu_stream_read (s->transport, optr, osize, &rsize);
-  if (rc == 0)
-    {
-      s->offset += rsize;
-      if (nbytes)
-       *nbytes = rsize;
-    }
-  else
-    s->stream.last_err = rc;
-  return rc;
-}
-  
-static int
-_message_size (mu_stream_t stream, mu_off_t *psize)
-{
-  struct _mu_message_stream *s = (struct _mu_message_stream*) stream;
-  int rc = mu_stream_size (s->transport, psize);
-  
-  if (rc == 0)
-    *psize -= s->envelope_length + s->mark_length;
-  return rc;
-}
-  
-static int
-scan_stream (struct _mu_message_stream *str)
-{
-  char *from = NULL;
-  char *env_from = NULL;
-  char *env_date = NULL;
-  int rc;
-  char *buffer = NULL;
-  size_t bufsize = 0;
-  size_t len;
-  mu_off_t body_start, body_end;
-  mu_stream_t stream = str->transport;
-
-  if (str->envelope)
-    {
-      char *s = str->envelope + 5;
-      char *p = strchr (s, ' ');
-      size_t len;
-
-      if (p)
-       {
-         len = p - s;
-         env_from = mu_alloc (len + 1);
-         if (!env_from)
-           return ENOMEM;
-         memcpy (env_from, s, len);
-         env_from[len] = 0;
-         env_date = mu_strdup (p + 1);
-         if (!env_date)
-           {
-             free (env_from);
-             return ENOMEM;
-           }
-       }
-    }
-
-  rc = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
-  if (rc)
-    return rc;
-  while ((rc = mu_stream_getline (stream, &buffer, &bufsize, &len)) == 0
-        && len > 0)
-    {
-      if (buffer[0] == '\n')
-       break;
-
-      if (!env_from || !env_date)
-       {
-         if (!from && mu_c_strncasecmp (buffer, MU_HEADER_FROM,
-                                        sizeof (MU_HEADER_FROM) - 1) == 0)
-           
-           from = mu_strdup (mu_str_skip_class (buffer +
-                                                sizeof (MU_HEADER_FROM),
-                                                MU_CTYPE_SPACE));
-         else if (!env_from
-                  && mu_c_strncasecmp (buffer, MU_HEADER_ENV_SENDER,
-                                       sizeof (MU_HEADER_ENV_SENDER) - 1) == 0)
-           env_from = mu_strdup (mu_str_skip_class (buffer +
-                                       sizeof (MU_HEADER_ENV_SENDER),
-                                                    MU_CTYPE_SPACE));
-         else if (!env_date
-                  && mu_c_strncasecmp (buffer, MU_HEADER_ENV_DATE,
-                                       sizeof (MU_HEADER_ENV_DATE) - 1) == 0)
-           env_date = mu_strdup (mu_str_skip_class (buffer +
-                                                 sizeof (MU_HEADER_ENV_DATE),
-                                                    MU_CTYPE_SPACE));
-       }
-    }
-
-  free (buffer);
-
-  rc = mu_stream_seek (stream, 0, MU_SEEK_CUR, &body_start);
-  if (rc)
-    return rc;
-  rc = mu_stream_size (stream, &body_end);
-  if (rc)
-    return rc;
-  
-  if (!env_from)
-    {
-      if (from)
-       {
-         mu_address_t addr;
-         
-         mu_address_create (&addr, from);
-         if (!addr
-             || mu_address_aget_email (addr, 1, &env_from))
-           env_from = mu_strdup ("GNU-Mailutils");
-         mu_address_destroy (&addr);
-       }
-      else
-       env_from = mu_strdup ("GNU-MH");
-    }
-  free (from);
-  
-  if (!env_date)
-    {
-      struct tm *tm;
-      time_t t;
-      char date[80]; /* FIXME: This size is way too big */
-
-      time(&t);
-      tm = gmtime(&t);
-      mu_strftime (date, sizeof (date), "%a %b %e %H:%M:%S %Y", tm);
-      env_date = strdup (date);
-    }
-
-  str->from = env_from;
-  str->date = env_date;
-
-  str->body_start = body_start;
-  str->body_end = body_end - 1;
-  
-  return 0;
-}
-
-static int
-_message_open (mu_stream_t stream)
-{
-  struct _mu_message_stream *s = (struct _mu_message_stream*) stream;
-  size_t offset, len;
-  char *buffer = NULL;
-  size_t bufsize = 0;
-  int rc;
-
-  offset = 0;
-  mu_stream_seek (s->transport, 0, MU_SEEK_SET, NULL);
-  while ((rc = mu_stream_getline (s->transport, &buffer, &bufsize,
-                                 &len)) == 0
-        && len > 0)
-    {
-      if (offset == 0 && memcmp (buffer, "From ", 5) == 0)
-       {
-         s->envelope_length = len;
-         s->envelope = mu_strdup (buffer);
-         if (!s->envelope)
-           return ENOMEM;
-         s->envelope[len - 1] = 0;
-       }
-      else if (mu_mh_delim (buffer))
-       {
-         s->mark_offset = offset;
-         s->mark_length = len - 1; /* do not count the terminating newline */
-         break;
-       }
-
-      offset += len;
-    }
-  free (buffer);
-
-  return scan_stream (s);
-}
-
-static int
-_message_close (mu_stream_t stream)
-{
-  struct _mu_message_stream *s = (struct _mu_message_stream*) stream;
-  return s->stream.last_err = mu_stream_close (s->transport);
-}
-
-static void
-_message_done (mu_stream_t stream)
-{
-  struct _mu_message_stream *s = (struct _mu_message_stream*) stream;
-
-  free (s->envelope);
-  free (s->date);
-  free (s->from);
-  mu_stream_destroy (&s->transport);
-}
-
-static int
-_message_seek (struct _mu_stream *stream, mu_off_t off, mu_off_t *presult)
-{ 
-  struct _mu_message_stream *s = (struct _mu_message_stream*) stream;
-  mu_off_t size;
-
-  mu_stream_size (stream, &size);
-  if (off < 0 || off >= size)
-    return ESPIPE;
-  s->offset = off;
-  *presult = off;
-  return 0;
-}
-
-const char *
-_message_error_string (struct _mu_stream *stream, int rc)
-{
-  struct _mu_message_stream *str = (struct _mu_message_stream*) stream;
-  return mu_stream_strerror (str->transport, rc);
-}
-
-int
-mu_message_stream_create (mu_stream_t *pstream, mu_stream_t src, int flags)
-{
-  struct _mu_message_stream *s;
-  int sflag;
-  int rc;
-  mu_stream_t stream;
-  
-  mu_stream_get_flags (src, &sflag);
-  sflag &= MU_STREAM_SEEK;
-  
-  if (!flags)
-    flags = MU_STREAM_READ;
-  if (flags & (MU_STREAM_WRITE|MU_STREAM_CREAT|MU_STREAM_APPEND))
-    return EINVAL;
-  s = (struct _mu_message_stream *) _mu_stream_create (sizeof (*s),
-                                                      flags | sflag);
-  if (!s)
-    return ENOMEM;
-
-  rc = mu_streamref_create (&s->transport, src);
-  if (rc)
-    {
-      free (s);
-      return rc;
-    }
-  s->stream.open = _message_open;
-  s->stream.close = _message_close;
-  s->stream.done = _message_done;
-  s->stream.read = _message_read;
-  s->stream.size = _message_size;
-  s->stream.seek = _message_seek;
-  s->stream.error_string = _message_error_string;
-
-  stream = (mu_stream_t)s;
-  rc = mu_stream_open (stream);
-  if (rc)
-    mu_stream_destroy (&stream);
-  else
-    *pstream = stream;
-  return rc;
-}
-
-
-/* *************************** MH draft message **************************** */
-
-
-
-static int
-_body_obj_size (mu_body_t body, size_t *size)
-{
-  mu_message_t msg = mu_body_get_owner (body);
-  struct _mu_message_stream *str = mu_message_get_owner (msg);
-
-  if (size)
-    *size = str->body_end - str->body_start + 1;
-  return 0;
-}
-
-
-
-int
-mu_stream_to_message (mu_stream_t instream, mu_message_t *pmsg)
-{
-  mu_envelope_t env;
-  mu_message_t msg;
-  mu_body_t body;
-  mu_stream_t bstream;
-  mu_stream_t draftstream;
-  int rc;
-  struct _mu_message_stream *sp;
-  
-  /* FIXME: Perhaps MU_STREAM_NO_CLOSE is needed */
-  if ((rc = mu_message_stream_create (&draftstream, instream, 0)))
-    return rc;
-
-  if ((rc = mu_message_create (&msg, draftstream)))
-    {
-      mu_stream_destroy (&draftstream);
-      return rc;
-    }
-  
-  mu_message_set_stream (msg, draftstream, draftstream);
-  
-  if ((rc = mu_envelope_create (&env, draftstream)))
-    {
-      mu_message_destroy (&msg, draftstream);
-      mu_stream_destroy (&draftstream);
-      return rc;
-    }
-  
-  mu_envelope_set_date (env, _env_msg_date, draftstream);
-  mu_envelope_set_sender (env, _env_msg_sender, draftstream);
-  mu_message_set_envelope (msg, env, draftstream);
-
-  mu_body_create (&body, msg);
-  /* FIXME: It would be cleaner to use ioctl here */
-  sp = (struct _mu_message_stream *) draftstream;
-  rc = mu_streamref_create_abridged (&bstream, instream,
-                                    sp->body_start, sp->body_end);
-  if (rc)
-    {
-      mu_body_destroy (&body, msg);
-      mu_message_destroy (&msg, draftstream);
-      mu_stream_destroy (&draftstream);
-      return rc;
-    }
-  
-  mu_body_set_stream (body, bstream, msg);
-  mu_body_set_size (body, _body_obj_size, msg);
-  mu_message_set_body (msg, body, draftstream);
-
-  *pmsg = msg;
-  return 0;
-}
diff --git a/libmailutils/mime.c b/libmailutils/mime.c
deleted file mode 100644
index 2c923cc..0000000
--- a/libmailutils/mime.c
+++ /dev/null
@@ -1,1071 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2003, 2004, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
-#endif
-
-#include <mailutils/cctype.h>
-#include <mailutils/cstr.h>
-#include <mailutils/message.h>
-#include <mailutils/stream.h>
-#include <mailutils/body.h>
-#include <mailutils/header.h>
-#include <mailutils/errno.h>
-#include <mailutils/mutil.h>
-
-#include <mailutils/sys/mime.h>
-#include <mailutils/sys/stream.h>
-
-#ifndef TRUE
-#define TRUE (1)
-#define FALSE (0)
-#endif
-
-#define CT_MULTIPART_DIGEST "multipart/digest"
-#define CT_MULTIPART_DIGEST_LEN (sizeof (CT_MULTIPART_DIGEST) - 1)
-
-/* TODO:
- *  Need to prevent re-entry into mime lib, but allow non-blocking re-entry
- *  into lib.
- */
-
-static int
-_mime_is_multipart_digest (mu_mime_t mime)
-{
-  if (mime->content_type)
-    return mu_c_strncasecmp (CT_MULTIPART_DIGEST, mime->content_type,
-                            CT_MULTIPART_DIGEST_LEN) == 0;
-  return 0;
-}
-
-static int
-_mime_append_part (mu_mime_t mime, mu_message_t msg, int offset, int len, int 
lines)
-{
-  struct _mime_part *mime_part, **part_arr;
-  int             ret;
-  size_t          size;
-  mu_header_t        hdr;
-
-  if ((mime_part = calloc (1, sizeof (*mime_part))) == NULL)
-    return ENOMEM;
-
-  if (mime->nmtp_parts >= mime->tparts)
-    {
-      if ((part_arr =
-          realloc (mime->mtp_parts,
-                   (mime->tparts + 5) * sizeof (mime_part))) == NULL)
-       {
-         free (mime_part);
-         return ENOMEM;
-       }
-      mime->mtp_parts = part_arr;
-      mime->tparts += 5;
-    }
-  mime->mtp_parts[mime->nmtp_parts++] = mime_part;
-  if (msg == NULL)
-    {
-      if ((ret = mu_message_create (&(mime_part->msg), mime_part)) == 0)
-       {
-         if ((ret =
-              mu_header_create (&hdr, mime->header_buf,
-                                mime->header_length)) != 0)
-           {
-             mu_message_destroy (&mime_part->msg, mime_part);
-             free (mime_part);
-             return ret;
-           }
-         mu_message_set_header (mime_part->msg, hdr, mime_part);
-       }
-      else
-       {
-         free (mime_part);
-         return ret;
-       }
-      mime->header_length = 0;
-      if ((ret =
-          mu_header_get_value (hdr, MU_HEADER_CONTENT_TYPE, NULL,
-                               0, &size)) != 0 || size == 0)
-       {
-         if (_mime_is_multipart_digest (mime))
-           mu_header_set_value (hdr,
-                                MU_HEADER_CONTENT_TYPE, "message/rfc822", 0);
-         else
-           mu_header_set_value (hdr, MU_HEADER_CONTENT_TYPE, "text/plain",
-                                0);
-       }
-      mime_part->len = len;
-      mime_part->lines = lines;
-      mime_part->offset = offset;
-    }
-  else
-    {
-      mu_message_ref (msg);
-      mu_message_size (msg, &mime_part->len);
-      mu_message_lines (msg, &mime_part->lines);
-      if (mime->nmtp_parts > 1)
-       mime_part->offset = mime->mtp_parts[mime->nmtp_parts - 2]->len;
-      mime_part->msg = msg;
-    }
-  mime_part->mime = mime;
-  return 0;
-}
-
-#define _ISSPECIAL(c) (                                                 \
-    ((c) == '(') || ((c) == ')') || ((c) == '<') || ((c) == '>') \
-    || ((c) == '@') || ((c) == ',') || ((c) == ';') || ((c) == ':') \
-    || ((c) == '\\') || ((c) == '.') || ((c) == '[') \
-    || ((c) == ']') )
-
-static void
-_mime_munge_content_header (char *field_body)
-{
-  char           *p, *e, *str = field_body;
-  int             quoted = 0;
-
-  mu_str_stripws (field_body);
-
-  if ((e = strchr (str, ';')) == NULL)
-    return;
-  while (*e == ';')
-    {
-      p = e;
-      e++;
-      while (*e && mu_isspace (*e)) /* remove space up to param */
-       e++;
-      memmove (p + 1, e, strlen (e) + 1);
-      e = p + 1;
-
-      while (*e && *e != '=')  /* find end of value */
-       e++;
-      e = p = e + 1;
-      while (*e
-            && (quoted
-                || (!_ISSPECIAL (*e) && !mu_isspace (*e))))
-       {
-         if (*e == '\\')
-           {                   /* escaped */
-             memmove (e, e + 1, strlen (e));
-           }
-         else if (*e == '\"')
-           quoted = ~quoted;
-         e++;
-       }
-    }
-}
-
-static char    *
-_mime_get_param (char *field_body, const char *param, int *len)
-{
-  char           *str, *p, *v, *e;
-  int             quoted = 0, was_quoted;
-
-  if (len == NULL || (str = field_body) == NULL)
-    return NULL;
-
-  p = strchr (str, ';');
-  while (p)
-    {
-      p++;
-      if ((v = strchr (p, '=')) == NULL)
-       break;
-      *len = 0;
-      v = e = v + 1;
-      was_quoted = 0;
-      while (*e
-            && (quoted
-                || (!_ISSPECIAL (*e) && !mu_isspace (*e))))
-       {                       /* skip pass value and calc len */
-         if (*e == '\"')
-           quoted = ~quoted, was_quoted = 1;
-         else
-           (*len)++;
-         e++;
-       }
-      if (mu_c_strncasecmp (p, param, strlen (param)))
-       {                       /* no match jump to next */
-         p = strchr (e, ';');
-         continue;
-       }
-      else
-       return was_quoted ? v + 1 : v;  /* return unquoted value */
-    }
-  return NULL;
-}
-
-static int
-_mime_setup_buffers (mu_mime_t mime)
-{
-  if (mime->cur_buf == NULL
-      && (mime->cur_buf = malloc (mime->buf_size)) == NULL)
-    {
-      return ENOMEM;
-    }
-  if (mime->cur_line == NULL
-      && (mime->cur_line = calloc (mime->line_size, 1)) == NULL)
-    {
-      free (mime->cur_buf);
-      return ENOMEM;
-    }
-  return 0;
-}
-
-static void
-_mime_append_header_line (mu_mime_t mime)
-{
-  if (mime->header_length + mime->line_ndx > mime->header_buf_size)
-    {
-      char           *nhb;
-
-      if ((nhb =
-          realloc (mime->header_buf,
-                   mime->header_length + mime->line_ndx + 128)) == NULL)
-       return;
-      mime->header_buf = nhb;
-      mime->header_buf_size = mime->header_length + mime->line_ndx + 128;
-    }
-  memcpy (mime->header_buf + mime->header_length, mime->cur_line,
-         mime->line_ndx);
-  mime->header_length += mime->line_ndx;
-}
-
-static int
-_mime_parse_mpart_message (mu_mime_t mime)
-{
-  char           *cp, *cp2;
-  int             blength, mb_length, mb_offset, mb_lines, ret;
-  size_t          nbytes;
-
-  if (!(mime->flags & MIME_PARSER_ACTIVE))
-    {
-      char           *boundary;
-      int             len;
-
-      if ((ret = _mime_setup_buffers (mime)) != 0)
-       return ret;
-      if ((boundary =
-          _mime_get_param (mime->content_type, "boundary", &len)) == NULL)
-       return EINVAL;
-      if ((mime->boundary = calloc (1, len + 1)) == NULL)
-       return ENOMEM;
-      strncpy (mime->boundary, boundary, len);
-
-      mime->cur_offset = 0;
-      mime->line_ndx = 0;
-      mime->parser_state = MIME_STATE_SCAN_BOUNDARY;
-      mime->flags |= MIME_PARSER_ACTIVE;
-    }
-  mb_length = mime->body_length;
-  mb_offset = mime->body_offset;
-  mb_lines = mime->body_lines;
-  blength = strlen (mime->boundary);
-
-  mu_stream_seek (mime->stream, mime->cur_offset, MU_SEEK_SET, NULL);
-  while ((ret =
-         mu_stream_read (mime->stream, mime->cur_buf, mime->buf_size,
-                         &nbytes)) == 0 && nbytes)
-    {
-      cp = mime->cur_buf;
-      while (nbytes)
-       {
-         mime->cur_line[mime->line_ndx] = *cp;
-         if (*cp == '\n')
-           {
-             switch (mime->parser_state)
-               {
-               case MIME_STATE_BEGIN_LINE:
-                 mime->cur_line[0] = *cp;
-                 mime->line_ndx = 0;
-                 mime->parser_state = MIME_STATE_SCAN_BOUNDARY;
-                 break;
-
-               case MIME_STATE_SCAN_BOUNDARY:
-                 cp2 =
-                   mime->cur_line[0] ==
-                   '\n' ? mime->cur_line + 1 : mime->cur_line;
-                 if (mime->line_ndx >= blength)
-                   {
-                     if ((!strncmp (cp2, "--", 2)
-                          && !mu_c_strncasecmp (cp2 + 2, mime->boundary,
-                                                blength))
-                         || !mu_c_strncasecmp (cp2, mime->boundary, blength))
-                       {
-                         mime->parser_state = MIME_STATE_HEADERS;
-                         mime->flags &= ~MIME_PARSER_HAVE_CR;
-                         mb_length = mime->cur_offset 
-                                          - mb_offset
-                                          - mime->line_ndx;
-                         if (mime->header_length)
-                           /* this skips the preamble */
-                           {
-                             /* RFC 1521 [Page 30]:
-                                NOTE: The CRLF preceding the encapsulation
-                                line is conceptually attached to the boundary
-                                so that it is possible to have a part that
-                                does not end with a CRLF (line break). Body
-                                parts that must be considered to end with line
-                                breaks, therefore, must have two CRLFs
-                                preceding the encapsulation line, the first
-                                of which is part of the preceding body part,
-                                and the second of which is part of the
-                                encapsulation boundary. */
-                             
-                             if (mb_lines)
-                               /* to prevent negative values in case of a
-                                  malformed message */
-                               mb_lines--;
-                                 
-                             _mime_append_part (mime, NULL,
-                                                mb_offset, mb_length,
-                                                mb_lines);
-                           }
-
-                         if ((&mime->cur_line[mime->line_ndx] - cp2 - 1 >
-                              blength
-                              && !strncmp (cp2 + blength + 2, "--", 2))
-                             || (&mime->cur_line[mime->line_ndx] - cp2 - 1 ==
-                                 blength
-                                 && !strncmp (cp2 + blength, "--", 2)))
-                           {   /* last boundary */
-                             mime->parser_state = MIME_STATE_BEGIN_LINE;
-                             mime->header_length = 0;
-                           }
-                         else
-                           mime->line_ndx = -1; /* headers parsing requires
-                                                   empty line */
-                         break;
-                       }
-                   }
-
-                 if (mime->header_length)
-                   mb_lines++;
-
-                 mime->line_ndx = 0;
-                 mime->cur_line[0] = *cp;      /* stay in this state but
-                                                  leave '\n' at begining */
-                 break;
-
-               case MIME_STATE_HEADERS:
-                 mime->line_ndx++;
-                 _mime_append_header_line (mime);
-                 if (mime->line_ndx == 1 || mime->cur_line[0] == '\r')
-                   {
-                     mime->parser_state = MIME_STATE_SCAN_BOUNDARY;
-                     mb_offset = mime->cur_offset + 1;
-                     mb_lines = 0;
-                   }
-                 mime->line_ndx = -1;
-                 break;
-               }
-           }
-         mime->line_ndx++;
-         if (mime->line_ndx >= mime->line_size)
-           {
-             size_t newsize = mime->line_size + MIME_MAX_HDR_LEN;
-             char *p = realloc (mime->cur_line, newsize);
-             if (!p)
-               {
-                 ret = ENOMEM;
-                 break;
-               }
-             mime->cur_line = p;
-             mime->line_size = newsize;
-           }
-         mime->cur_offset++;
-         nbytes--;
-         cp++;
-       }
-    }
-  mime->body_lines = mb_lines;
-  mime->body_length = mb_length;
-  mime->body_offset = mb_offset;
-  if (ret != EAGAIN)
-    {                          /* finished cleanup */
-      if (mime->header_length) /* this skips the preamble */
-       _mime_append_part (mime, NULL, mb_offset, mb_length, mb_lines);
-      mime->flags &= ~MIME_PARSER_ACTIVE;
-      mime->body_offset = mime->body_length =
-       mime->header_length = mime->body_lines = 0;
-    }
-  return ret;
-}
-
-/*------ Mime message functions for READING a multipart message -----*/
-
-static int
-_mimepart_body_size (mu_body_t body, size_t *psize)
-{
-  mu_message_t       msg = mu_body_get_owner (body);
-  struct _mime_part *mime_part = mu_message_get_owner (msg);
-
-  if (mime_part == NULL)
-    return EINVAL;
-  if (psize)
-    *psize = mime_part->len;
-  return 0;
-}
-
-static int
-_mimepart_body_lines (mu_body_t body, size_t *plines)
-{
-  mu_message_t       msg = mu_body_get_owner (body);
-  struct _mime_part *mime_part = mu_message_get_owner (msg);
-
-  if (mime_part == NULL)
-    return EINVAL;
-  if (plines)
-    *plines = mime_part->lines;
-  return 0;
-}
-
-/*------ Mime message/header functions for CREATING multipart message -----*/
-static int
-_mime_set_content_type (mu_mime_t mime)
-{
-  const char  *content_type;
-  mu_header_t     hdr = NULL;
-  size_t          size;
-  int             ret;
-
-  /* Delayed the creation of the header 'til they create the final message via
-     mu_mime_get_message()  */
-  if (mime->hdrs == NULL)
-    return 0;
-  if (mime->nmtp_parts > 1)
-    {
-      char *cstr;
-      
-      if (mime->flags & MIME_ADDED_MULTIPART_CT)
-       return 0;
-      if (mime->flags & MU_MIME_MULTIPART_MIXED)
-       content_type = "multipart/mixed; boundary=";
-      else
-       content_type = "multipart/alternative; boundary=";
-      if (mime->boundary == NULL)
-       {
-         char boundary[128];
-         
-         snprintf (boundary, sizeof boundary, "%ld-%ld=:%ld",
-                   (long) random (), (long) time (0), (long) getpid ());
-         if ((mime->boundary = strdup (boundary)) == NULL)
-           return ENOMEM;
-       }
-      size = strlen (content_type) + 2 + strlen (mime->boundary) + 1;
-      cstr = malloc (size);
-      if (!cstr)
-       return ENOMEM;
-      strcpy (cstr, content_type);
-      strcat (cstr, "\"");
-      strcat (cstr, mime->boundary);
-      strcat (cstr, "\"");
-      mime->flags |= MIME_ADDED_MULTIPART_CT;
-
-      ret = mu_header_set_value (mime->hdrs, MU_HEADER_CONTENT_TYPE, cstr, 1);
-      free (cstr);
-    }
-  else
-    {
-      if ((mime->flags & (MIME_ADDED_CT | MIME_ADDED_MULTIPART_CT))
-         == MIME_ADDED_CT)
-       return 0;
-      mime->flags &= ~MIME_ADDED_MULTIPART_CT;
-      if (mime->nmtp_parts)
-       mu_message_get_header (mime->mtp_parts[0]->msg, &hdr);
-
-      if (hdr == NULL
-         || mu_header_sget_value (hdr, MU_HEADER_CONTENT_TYPE,
-                                  &content_type))
-       content_type = "text/plain; charset=us-ascii";
-
-      ret = mu_header_set_value (mime->hdrs, MU_HEADER_CONTENT_TYPE,
-                                content_type, 1);
-      if (ret)
-       return ret;
-
-      if (hdr)
-       {
-         const char *content_te;
-         
-         /* if the only part contains a transfer-encoding
-            field, set it on the message header too */
-         if (mu_header_sget_value (hdr,
-                               MU_HEADER_CONTENT_TRANSFER_ENCODING,
-                               &content_te) == 0)
-           ret = mu_header_set_value (mime->hdrs,
-                                      MU_HEADER_CONTENT_TRANSFER_ENCODING,
-                                      content_te, 1);
-
-         if (ret == 0
-             && mu_header_sget_value (hdr,
-                                      MU_HEADER_CONTENT_DESCRIPTION,
-                                      &content_te) == 0)
-           ret = mu_header_set_value (mime->hdrs,
-                                      MU_HEADER_CONTENT_DESCRIPTION,
-                                      content_te, 1);
-
-       }
-    }
-  mime->flags |= MIME_ADDED_CT;
-  return ret;
-}
-
-
-static int
-_mime_part_size (mu_mime_t mime, size_t *psize)
-{
-  int i, ret;
-  size_t size, total = 0;
-
-  if (mime->nmtp_parts == 0)
-    return EINVAL;
-
-  if ((ret = _mime_set_content_type (mime)) != 0)
-    return ret;
-  for (i = 0; i < mime->nmtp_parts; i++)
-    {
-      mu_message_size (mime->mtp_parts[i]->msg, &size);
-      total += size;
-      if (mime->nmtp_parts > 1)        /* boundary line */
-       total += strlen (mime->boundary) + 3;
-    }
-  if (mime->nmtp_parts > 1)    /* ending boundary line */
-    total += 2;
-  *psize = total;
-  return 0;
-}
-
-
-struct _mime_body_stream
-{
-  struct _mu_stream stream;
-  mu_mime_t mime;
-};
-
-static int
-_mime_body_stream_size (mu_stream_t stream, mu_off_t *psize)
-{
-  struct _mime_body_stream *mstr = (struct _mime_body_stream *)stream;
-  mu_mime_t mime = mstr->mime;
-  size_t sz;
-  int rc = _mime_part_size (mime, &sz);
-  if (rc == 0)
-    *psize = sz;
-  return rc;
-}
-
-static void
-mime_reset_state (mu_mime_t mime)
-{                              /* reset message */
-  mime->cur_offset = 0;
-  mime->cur_part = 0;
-  mime->part_offset = 0;
-  
-  if (mime->nmtp_parts > 1)
-    mime->flags |= MIME_INSERT_BOUNDARY;
-}
-
-/* FIXME: The seek method is defective */
-static int
-_mime_body_stream_seek (mu_stream_t stream, mu_off_t off, mu_off_t *presult)
-{
-  struct _mime_body_stream *mstr = (struct _mime_body_stream *)stream;
-  mu_mime_t mime = mstr->mime;
-
-  if (off == 0)
-    mime_reset_state (mime);
-
-  if (off != mime->cur_offset)
-    return ESPIPE;
-  *presult = off;
-  return 0;
-}
-
-#define ADD_CHAR(buf, c, offset, buflen, total, nbytes)        \
-  do                                                   \
-    {                                                  \
-      *(buf)++ = c;                                    \
-      (offset)++;                                      \
-      (total)++;                                       \
-      if (--(buflen) == 0)                             \
-       {                                               \
-         *(nbytes) = total;                            \
-         return 0;                                     \
-       }                                               \
-    }                                                  \
-  while (0)
-
-static int
-_mime_body_stream_read (mu_stream_t stream, char *buf, size_t buflen, size_t 
*nbytes)
-{
-  struct _mime_body_stream *mstr = (struct _mime_body_stream *)stream;
-  mu_mime_t mime = mstr->mime;
-  int                ret = 0;
-  size_t             total = 0;
-  
-  if (mime->nmtp_parts == 0)
-    return EINVAL;
-  
-  if ((ret = _mime_set_content_type (mime)) == 0)
-    {
-      do
-       {
-         size_t             part_nbytes = 0;
-
-         if (buflen == 0)
-           break;
-         if (mime->nmtp_parts > 1)
-           {
-             size_t len;
-             
-             if (mime->flags & MIME_INSERT_BOUNDARY)
-               {
-                 if ((mime->flags & MIME_ADDING_BOUNDARY) == 0)
-                   {
-                     mime->boundary_len = strlen (mime->boundary);
-                     mime->preamble = 2;
-                     if (mime->cur_part == mime->nmtp_parts)
-                       mime->postamble = 2;
-                     mime->flags |= MIME_ADDING_BOUNDARY;
-                   }
-                 while (mime->preamble)
-                   {
-                     mime->preamble--;
-                     ADD_CHAR (buf, '-', mime->cur_offset, buflen,
-                               total, nbytes);
-                   }
-                 len = strlen (mime->boundary) - mime->boundary_len;
-                 while (mime->boundary_len)
-                   {
-                     mime->boundary_len--;
-                     ADD_CHAR (buf,
-                               mime->boundary[len++],
-                               mime->cur_offset, buflen,
-                               total, nbytes);
-                   }
-                 while (mime->postamble)
-                   {
-                     mime->postamble--;
-                     ADD_CHAR (buf, '-', mime->cur_offset, buflen,
-                               total, nbytes);
-                   }
-                 mime->flags &=
-                   ~(MIME_INSERT_BOUNDARY | MIME_ADDING_BOUNDARY);
-                 mime->part_offset = 0;
-                 ADD_CHAR (buf, '\n', mime->cur_offset, buflen,
-                           total, nbytes);
-               }
-
-             if (!mime->part_stream)
-               {
-                 if (mime->cur_part >= mime->nmtp_parts)
-                   {
-                     *nbytes = total;
-                     return 0;
-                   }
-                 ret = mu_message_get_streamref 
(mime->mtp_parts[mime->cur_part]->msg,
-                                                 &mime->part_stream);
-               }
-           }
-         else if (!mime->part_stream)
-           {
-             mu_body_t part_body;
-
-             if (mime->cur_part >= mime->nmtp_parts)
-               {
-                 *nbytes = total;
-                 return 0;
-               }
-             mu_message_get_body (mime->mtp_parts[mime->cur_part]->msg,
-                                  &part_body);
-             ret = mu_body_get_streamref (part_body, &mime->part_stream);
-           }
-         if (ret)
-           break;
-         ret = mu_stream_seek (mime->part_stream, mime->part_offset,
-                               MU_SEEK_SET, NULL);
-         if (ret)
-           {
-             mu_stream_destroy (&mime->part_stream);
-             break;
-           }
-         while (buflen > 0 &&
-                (ret = mu_stream_read (mime->part_stream, buf, buflen,
-                                       &part_nbytes)) == 0)
-           {
-             if (part_nbytes)
-               {
-                 mime->part_offset += part_nbytes;
-                 mime->cur_offset += part_nbytes;
-                 total += part_nbytes;
-                 buflen -= part_nbytes;
-                 buf += part_nbytes;
-               }
-             else 
-               {
-                 mu_stream_destroy (&mime->part_stream);
-                 mime->flags |= MIME_INSERT_BOUNDARY;
-                 mime->cur_part++;
-                 ADD_CHAR (buf, '\n', mime->cur_offset, buflen,
-                           total, nbytes);
-                 break;
-               }
-           }
-       }
-      while (ret == 0 && mime->cur_part <= mime->nmtp_parts);
-    }
-  if (ret)
-    mu_stream_destroy (&mime->part_stream);
-  
-  *nbytes = total;
-  return ret;
-}
-
-static int
-_mime_body_stream_ioctl (mu_stream_t stream, int code, void *arg)
-{
-  struct _mime_body_stream *mstr = (struct _mime_body_stream *)stream;
-  mu_mime_t mime = mstr->mime;
-  mu_stream_t msg_stream;
-  int rc;
-  
-  switch (code)
-    {
-    case MU_IOCTL_GET_TRANSPORT:
-      if (!arg)
-       return EINVAL;
-      
-      if (mime->nmtp_parts == 0 || mime->cur_offset == 0)
-       return EINVAL;
-      rc = mu_message_get_streamref (mime->mtp_parts[mime->cur_part]->msg,
-                                    &msg_stream);
-      if (rc)
-       break;
-      rc = mu_stream_ioctl (msg_stream, code, arg);
-      mu_stream_destroy (&msg_stream);
-      break;
-
-    default:
-      rc = ENOSYS;
-    }
-  return rc;
-}
-
-static int
-create_mime_body_stream (mu_stream_t *pstr, mu_mime_t mime)
-{
-  struct _mime_body_stream *sp =
-    (struct _mime_body_stream *)_mu_stream_create (sizeof (*sp),
-                                                  MU_STREAM_READ | 
MU_STREAM_SEEK);
-  if (!sp)
-    return ENOMEM;
-  sp->stream.read = _mime_body_stream_read;
-  sp->stream.seek = _mime_body_stream_seek;
-  sp->stream.ctl = _mime_body_stream_ioctl;
-  sp->stream.size = _mime_body_stream_size;
-  sp->mime = mime;
-  mime_reset_state (mime);
-  *pstr = (mu_stream_t) sp;
-  return 0;
-}
-
-
-static int
-_mime_body_size (mu_body_t body, size_t *psize)
-{
-  mu_message_t       msg = mu_body_get_owner (body);
-  mu_mime_t          mime = mu_message_get_owner (msg);
-  return _mime_part_size (mime, psize);
-}
-
-static int
-_mime_body_lines (mu_body_t body, size_t *plines)
-{
-  mu_message_t       msg = mu_body_get_owner (body);
-  mu_mime_t          mime = mu_message_get_owner (msg);
-  int             i, ret;
-  size_t          lines;
-
-  if (mime->nmtp_parts == 0)
-    return EINVAL;
-
-  if ((ret = _mime_set_content_type (mime)) != 0)
-    return ret;
-  for (i = 0; i < mime->nmtp_parts; i++)
-    {
-      mu_message_lines (mime->mtp_parts[i]->msg, &lines);
-      plines += lines;
-      if (mime->nmtp_parts > 1)        /* boundary line */
-       plines++;
-    }
-  return 0;
-}
-
-int
-mu_mime_create (mu_mime_t *pmime, mu_message_t msg, int flags)
-{
-  mu_mime_t          mime = NULL;
-  int             ret = 0;
-  size_t          size;
-  mu_body_t          body;
-
-  if (pmime == NULL)
-    return EINVAL;
-  *pmime = NULL;
-  if ((mime = calloc (1, sizeof (*mime))) == NULL)
-    return ENOMEM;
-  if (msg)
-    {
-      if ((ret = mu_message_get_header (msg, &mime->hdrs)) == 0)
-       {
-         if ((ret =
-              mu_header_get_value (mime->hdrs,
-                                   MU_HEADER_CONTENT_TYPE,
-                                   NULL, 0, &size)) == 0 && size)
-           {
-             if ((mime->content_type = malloc (size + 1)) == NULL)
-               ret = ENOMEM;
-             else if ((ret = mu_header_get_value (mime->hdrs,
-                                                  MU_HEADER_CONTENT_TYPE,
-                                                  mime->content_type,
-                                                  size + 1, 0)) == 0)
-               _mime_munge_content_header (mime->content_type);
-           }
-         else
-           {
-             if (ret == MU_ERR_NOENT)
-               {
-                 ret = 0;
-                 if ((mime->content_type =
-                      strdup ("text/plain; charset=us-ascii")) == NULL)
-                   /* default as per spec. */
-                   ret = ENOMEM;
-               }
-           }
-         if (ret == 0)
-           {
-             mime->msg = msg;
-             mime->buf_size = MIME_DFLT_BUF_SIZE;
-             mime->line_size = MIME_MAX_HDR_LEN;
-             mu_message_get_body (msg, &body);
-             mu_body_get_streamref (body, &mime->stream);
-           }
-       }
-    }
-  else
-    {
-      mime->flags |= MIME_NEW_MESSAGE | MU_MIME_MULTIPART_MIXED;
-    }
-  if (ret != 0)
-    {
-      if (mime->content_type)
-       free (mime->content_type);
-      free (mime);
-    }
-  else
-    {
-      mime->flags |= (flags & MIME_FLAG_MASK);
-      *pmime = mime;
-    }
-  return ret;
-}
-
-void
-mu_mime_destroy (mu_mime_t *pmime)
-{
-  mu_mime_t          mime;
-  struct _mime_part *mime_part;
-  int             i;
-
-  if (pmime && *pmime)
-    {
-      mime = *pmime;
-      if (mime->mtp_parts != NULL)
-       {
-         for (i = 0; i < mime->nmtp_parts; i++)
-           {
-             mime_part = mime->mtp_parts[i];
-             if (mime_part->msg && mime->flags & MIME_NEW_MESSAGE)
-               mu_message_unref (mime_part->msg);
-             else
-               mu_message_destroy (&mime_part->msg, mime_part);
-             free (mime_part);
-           }
-         free (mime->mtp_parts);
-       }
-      mu_stream_destroy (&mime->stream);
-      mu_stream_destroy (&mime->part_stream);
-      if (mime->msg && mime->flags & MIME_NEW_MESSAGE)
-       mu_message_destroy (&mime->msg, mime);
-      if (mime->content_type)
-       free (mime->content_type);
-      if (mime->cur_buf)
-       free (mime->cur_buf);
-      if (mime->cur_line)
-       free (mime->cur_line);
-      if (mime->boundary)
-       free (mime->boundary);
-      if (mime->header_buf)
-       free (mime->header_buf);
-      free (mime);
-      *pmime = NULL;
-    }
-}
-
-int
-mu_mime_get_part (mu_mime_t mime, size_t part, mu_message_t *msg)
-{
-  size_t          nmtp_parts;
-  int             ret = 0, flags = 0;
-  mu_stream_t        stream;
-  mu_body_t          body;
-  struct _mime_part *mime_part;
-
-  if ((ret = mu_mime_get_num_parts (mime, &nmtp_parts)) == 0)
-    {
-      if (part < 1 || part > nmtp_parts)
-       return MU_ERR_NOENT;
-      if (nmtp_parts == 1 && mime->mtp_parts == NULL)
-       *msg = mime->msg;
-      else
-       {
-         mime_part = mime->mtp_parts[part - 1];
-         if (!mime_part->body_created
-             && (ret = mu_body_create (&body, mime_part->msg)) == 0)
-           {
-             mu_body_set_size (body, _mimepart_body_size, mime_part->msg);
-             mu_body_set_lines (body, _mimepart_body_lines, mime_part->msg);
-             mu_stream_get_flags (mime->stream, &flags);
-             ret = mu_streamref_create_abridged (&stream, mime->stream,
-                                                 mime_part->offset,
-                                                 mime_part->offset +
-                                                   mime_part->len - 1);
-             if (ret == 0)
-               {
-                 mu_stream_set_flags (stream,
-                                      MU_STREAM_READ | (flags &
-                                                        (MU_STREAM_SEEK
-                                                         | 
MU_STREAM_NONBLOCK)));
-                 mu_body_set_stream (body, stream, mime_part->msg);
-                 mu_message_set_body (mime_part->msg, body, mime_part);
-                 mime_part->body_created = 1;
-               }
-           }
-         *msg = mime_part->msg;
-       }
-    }
-  return ret;
-}
-
-int
-mu_mime_get_num_parts (mu_mime_t mime, size_t *nmtp_parts)
-{
-  int             ret = 0;
-
-  if ((mime->nmtp_parts == 0 && !mime->boundary)
-      || mime->flags & MIME_PARSER_ACTIVE)
-    {
-      if (mu_mime_is_multipart (mime))
-       {
-         if ((ret = _mime_parse_mpart_message (mime)) != 0)
-           return (ret);
-       }
-      else
-       mime->nmtp_parts = 1;
-    }
-  *nmtp_parts = mime->nmtp_parts;
-  return (ret);
-
-}
-
-int
-mu_mime_add_part (mu_mime_t mime, mu_message_t msg)
-{
-  int             ret;
-
-  if (mime == NULL || msg == NULL || (mime->flags & MIME_NEW_MESSAGE) == 0)
-    return EINVAL;
-  if ((ret = _mime_append_part (mime, msg, 0, 0, 0)) == 0)
-    ret = _mime_set_content_type (mime);
-  return ret;
-}
-
-int
-mu_mime_get_message (mu_mime_t mime, mu_message_t *msg)
-{
-  mu_stream_t        body_stream;
-  mu_body_t          body;
-  int             ret = 0;
-
-  if (mime == NULL || msg == NULL)
-    return EINVAL;
-  if (mime->msg == NULL)
-    {
-      if ((mime->flags & MIME_NEW_MESSAGE) == 0)
-       return EINVAL;
-      if ((ret = mu_message_create (&mime->msg, mime)) == 0)
-       {
-         if ((ret = mu_header_create (&mime->hdrs, NULL, 0)) == 0)
-           {
-             mu_message_set_header (mime->msg, mime->hdrs, mime);
-             mu_header_set_value (mime->hdrs, MU_HEADER_MIME_VERSION, "1.0",
-                                  0);
-             if ((ret = _mime_set_content_type (mime)) == 0)
-               {
-                 if ((ret = mu_body_create (&body, mime->msg)) == 0)
-                   {
-                     mu_message_set_body (mime->msg, body, mime);
-                     mu_body_set_size (body, _mime_body_size, mime->msg);
-                     mu_body_set_lines (body, _mime_body_lines, mime->msg);
-                     ret = create_mime_body_stream (&body_stream, mime);
-                     if (ret == 0)
-                       {
-                         mu_body_set_stream (body, body_stream, mime->msg);
-                         *msg = mime->msg;
-                         return 0;
-                       }
-                   }
-               }
-           }
-         mu_message_destroy (&mime->msg, mime);
-         mime->msg = NULL;
-       }
-    }
-  if (ret == 0)
-    *msg = mime->msg;
-  return ret;
-}
-
-int
-mu_mime_is_multipart (mu_mime_t mime)
-{
-  if (mime->content_type)
-    return (mu_c_strncasecmp ("multipart", mime->content_type,
-                             strlen ("multipart")) ? 0 : 1);
-  return 0;
-}
diff --git a/libmailutils/mime/Makefile.am b/libmailutils/mime/Makefile.am
new file mode 100644
index 0000000..70a3ebc
--- /dev/null
+++ b/libmailutils/mime/Makefile.am
@@ -0,0 +1,25 @@
+# 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/>.
+
+noinst_LTLIBRARIES = libmime.la
+
+libmime_la_SOURCES = \
+ attachment.c\
+ mime.c\
+ mimehdr.c
+
+INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
diff --git a/libmailutils/mime/attachment.c b/libmailutils/mime/attachment.c
new file mode 100644
index 0000000..e877cb7
--- /dev/null
+++ b/libmailutils/mime/attachment.c
@@ -0,0 +1,460 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2005, 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/>. */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#ifdef HAVE_LIBGEN_H
+# include <libgen.h>
+#endif
+
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/cctype.h>
+#include <mailutils/cstr.h>
+#include <mailutils/body.h>
+#include <mailutils/filter.h>
+#include <mailutils/header.h>
+#include <mailutils/message.h>
+#include <mailutils/stream.h>
+#include <mailutils/errno.h>
+#include <mailutils/mutil.h>
+
+#define BUF_SIZE       2048
+
+struct _mu_mime_io_buffer
+{
+  unsigned int refcnt;
+  char *buf;
+  size_t bufsize;
+  char *charset;
+  mu_header_t hdr;
+  mu_message_t msg;
+  mu_stream_t stream;  /* output file/decoding stream for saving attachment */
+  mu_stream_t fstream; /* output file stream for saving attachment */
+};
+
+#define MSG_HDR "Content-Type: %s; name=%s\nContent-Transfer-Encoding: 
%s\nContent-Disposition: attachment; filename=%s\n\n"
+
+int
+mu_message_create_attachment (const char *content_type, const char *encoding,
+                             const char *filename, mu_message_t *newmsg)
+{
+  mu_header_t hdr;
+  mu_body_t body;
+  mu_stream_t fstream = NULL, tstream = NULL;
+  char *header = NULL, *name = NULL, *fname = NULL;
+  int ret;
+
+  if (newmsg == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  if (filename == NULL)
+    return EINVAL;
+
+  if ((ret = mu_message_create (newmsg, NULL)) == 0)
+    {
+      if (content_type == NULL)
+       content_type = "text/plain";
+      if (encoding == NULL)
+       encoding = "7bit";
+      if ((fname = strdup (filename)) != NULL)
+       {
+         name = strrchr (fname, '/');
+         if (name)
+           name++;
+         else
+           name = fname;
+         if ((header =
+              malloc (strlen (MSG_HDR) + strlen (content_type) +
+                      strlen (name) * 2 + strlen (encoding) + 1)) == NULL)
+           ret = ENOMEM;
+         else
+           {
+             sprintf (header, MSG_HDR, content_type, name, encoding, name);
+             if ((ret = mu_header_create (&hdr, header, strlen (header)))
+                 == 0)
+               {
+                 mu_message_get_body (*newmsg, &body);
+                 if ((ret =
+                      mu_file_stream_create (&fstream, filename,
+                                             MU_STREAM_READ)) == 0)
+                   {
+                     if ((ret =
+                          mu_filter_create (&tstream, fstream, encoding,
+                                            MU_FILTER_ENCODE,
+                                            MU_STREAM_READ)) == 0)
+                       {
+                         mu_body_set_stream (body, tstream, *newmsg);
+                         mu_message_set_header (*newmsg, hdr, NULL);
+                       }
+                   }
+               }
+             free (header);
+           }
+       }
+    }
+  if (ret)
+    {
+      if (*newmsg)
+       mu_message_destroy (newmsg, NULL);
+      if (hdr)
+       mu_header_destroy (&hdr);
+      if (fstream)
+       mu_stream_destroy (&fstream);
+      if (fname)
+       free (fname);
+    }
+  return ret;
+}
+
+int
+mu_mime_io_buffer_create (mu_mime_io_buffer_t *pinfo)
+{
+  mu_mime_io_buffer_t info;
+  
+  if ((info = calloc (1, sizeof (*info))) == NULL)
+    return ENOMEM;
+  info->refcnt = 1;
+  info->bufsize = BUF_SIZE;
+  *pinfo = info;
+  return 0;
+}
+
+void
+mu_mime_io_buffer_set_size (mu_mime_io_buffer_t info, size_t size)
+{
+  info->bufsize = size;
+}
+
+void
+mu_mime_io_buffer_get_size (mu_mime_io_buffer_t info, size_t *psize)
+{
+  *psize = info->bufsize;
+}
+
+int
+mu_mime_io_buffer_set_charset (mu_mime_io_buffer_t info, const char *charset)
+{
+  char *cp = strdup (charset);
+  if (!cp)
+    return ENOMEM;
+  free (info->charset);
+  info->charset = cp;
+  return 0;
+}
+
+void
+mu_mime_io_buffer_sget_charset (mu_mime_io_buffer_t info, const char **charset)
+{
+  *charset = info->charset;
+}
+
+int
+mu_mime_io_buffer_aget_charset (mu_mime_io_buffer_t info, const char **charset)
+{
+  *charset = strdup (info->charset);
+  if (!charset)
+    return ENOMEM;
+  return 0;
+}
+
+void
+mu_mime_io_buffer_destroy (mu_mime_io_buffer_t *pinfo)
+{
+  if (pinfo && *pinfo)
+    {
+      mu_mime_io_buffer_t info = *pinfo;
+      free (info->charset);
+      free (info->buf);
+      free (info);
+      *pinfo = NULL;
+    }
+}
+
+static void
+_attachment_free (struct _mu_mime_io_buffer *info, int free_message)
+{
+  if (free_message)
+    {
+      if (info->msg)
+       mu_message_destroy (&info->msg, NULL);
+      else if (info->hdr)
+       mu_header_destroy (&info->hdr);
+    }
+  info->msg = NULL;
+  info->hdr = NULL;
+  info->stream = NULL;
+  info->fstream = NULL;
+  if (--info->refcnt == 0)
+    {
+      free (info->charset);
+      free (info->buf);
+      free (info);
+    }
+}
+
+static int
+_attachment_setup (mu_mime_io_buffer_t *pinfo, mu_message_t msg,
+                  mu_stream_t *pstream)
+{
+  int ret;
+  mu_body_t body;
+  mu_mime_io_buffer_t info;
+  mu_stream_t stream;
+    
+  if ((ret = mu_message_get_body (msg, &body)) != 0 ||
+      (ret = mu_body_get_streamref (body, &stream)) != 0)
+    return ret;
+  ret = mu_stream_seek (stream, 0, SEEK_SET, NULL);
+  if (ret)
+    return ret;
+  *pstream = stream;
+  if (*pinfo)
+    {
+      info = *pinfo;
+      info->refcnt++;
+    }
+  else
+    {
+      ret = mu_mime_io_buffer_create (&info);
+      if (ret)
+       return ret;
+    }
+  
+  if (!info->buf && ((info->buf = malloc (info->bufsize)) == NULL))
+    {
+      _attachment_free (info, 0);
+      return ENOMEM;
+    }
+  info->msg = msg;
+  *pinfo = info;
+  return 0;
+}
+
+int
+mu_message_save_attachment (mu_message_t msg, const char *filename,
+                           mu_mime_io_buffer_t info)
+{
+  mu_stream_t istream;
+  int ret;
+  size_t size;
+  size_t nbytes;
+  mu_header_t hdr;
+  const char *fname = NULL;
+  char *partname = NULL;
+
+  if (msg == NULL)
+    return EINVAL;
+
+  if ((ret = _attachment_setup (&info, msg, &istream)) != 0)
+    return ret;
+
+  if (ret == 0 && (ret = mu_message_get_header (msg, &hdr)) == 0)
+    {
+      if (filename == NULL)
+       {
+         ret = mu_message_aget_decoded_attachment_name (msg, info->charset,
+                                                        &partname, NULL);
+         if (partname)
+           fname = partname;
+       }
+      else
+       fname = filename;
+      if (fname
+         && (ret =
+             mu_file_stream_create (&info->fstream, fname,
+                                    MU_STREAM_WRITE | MU_STREAM_CREAT)) == 0)
+       {
+         char *content_encoding;
+         char *content_encoding_mem = NULL;
+         
+         mu_header_get_value (hdr, "Content-Transfer-Encoding", NULL, 0,
+                              &size);
+         if (size)
+           {
+             content_encoding_mem = malloc (size + 1);
+             if (content_encoding_mem == NULL)
+               ret = ENOMEM;
+             content_encoding = content_encoding_mem;
+             mu_header_get_value (hdr, "Content-Transfer-Encoding",
+                                  content_encoding, size + 1, 0);
+           }
+         else
+           content_encoding = "7bit";
+         ret =
+           mu_filter_create (&info->stream, istream, content_encoding,
+                             MU_FILTER_DECODE,
+                             MU_STREAM_READ);
+         free (content_encoding_mem);
+       }
+    }
+  if (info->stream && istream)
+    {
+      while (((ret =
+              mu_stream_read (info->stream, info->buf, BUF_SIZE, 
+                              &nbytes)) == 0 && nbytes))
+       {
+         if ((ret =
+              mu_stream_write (info->fstream, info->buf, nbytes, NULL)) != 0)
+           break;
+       }
+    }
+  if (ret != EAGAIN && info)
+    {
+      mu_stream_close (info->fstream);
+      mu_stream_destroy (&info->stream);
+      mu_stream_destroy (&info->fstream);
+    }
+
+  mu_stream_destroy (&istream);
+  _attachment_free (info, ret); /* FIXME: or 0? */
+  
+  /* Free fname if we allocated it. */
+  if (partname)
+    free (partname);
+
+  return ret;
+}
+
+int
+mu_message_encapsulate (mu_message_t msg, mu_message_t *newmsg,
+                       mu_mime_io_buffer_t info)
+{
+  mu_stream_t istream, ostream;
+  const char *header;
+  int ret = 0;
+  size_t nbytes;
+  mu_message_t tmsg = NULL;
+  
+  if (newmsg == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+
+  if (msg == NULL)
+    {
+      mu_header_t hdr;
+      
+      ret = mu_message_create (&tmsg, NULL);
+      if (ret)
+       return ret;
+      msg = tmsg;
+      header =
+       "Content-Type: message/rfc822\nContent-Transfer-Encoding: 7bit\n\n";
+      if ((ret =
+          mu_header_create (&hdr, header, strlen (header))) == 0)
+       ret = mu_message_set_header (msg, hdr, NULL);
+      if (ret)
+       {
+         mu_message_destroy (&msg, NULL);
+         return ret;
+       }
+    }
+      
+  if ((ret = _attachment_setup (&info, msg, &ostream)) != 0)
+    {
+      mu_message_destroy (&tmsg, NULL);
+      return ret;
+    }
+
+  if (ret == 0 && (ret = mu_message_get_streamref (msg, &istream)) == 0)
+    {
+      mu_stream_seek (istream, 0, MU_SEEK_SET, NULL);
+      while (((ret = mu_stream_read (istream, info->buf, BUF_SIZE, 
+                                    &nbytes)) == 0 && nbytes))
+       {
+         if ((ret =
+              mu_stream_write (ostream, info->buf, nbytes, NULL)) != 0)
+           break;
+       }
+      mu_stream_destroy (&istream);
+    }
+  if (ret == 0)
+    *newmsg = info->msg;
+  mu_stream_destroy (&ostream);
+  _attachment_free (info, ret && ret != EAGAIN);
+  return ret;
+}
+
+#define MESSAGE_RFC822_STR "message/rfc822"
+
+int
+mu_message_unencapsulate (mu_message_t msg, mu_message_t *newmsg,
+                         mu_mime_io_buffer_t info)
+{
+  size_t size, nbytes;
+  int ret = 0;
+  mu_header_t hdr;
+  mu_stream_t istream, ostream;
+
+  if (msg == NULL)
+    return EINVAL;
+  if (newmsg == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+
+  if (info == NULL /* FIXME: not needed? */
+      && (ret = mu_message_get_header (msg, &hdr)) == 0)
+    {
+      mu_header_get_value (hdr, "Content-Type", NULL, 0, &size);
+      if (size)
+       {
+         char *content_type;
+         if ((content_type = malloc (size + 1)) == NULL)
+           return ENOMEM;
+         mu_header_get_value (hdr, "Content-Type", content_type, size + 1,
+                              0);
+         ret = mu_c_strncasecmp (content_type, MESSAGE_RFC822_STR,
+                                 sizeof (MESSAGE_RFC822_STR) - 1);
+         free (content_type);
+         if (ret != 0)
+           return EINVAL;
+       }
+      else
+       return EINVAL;
+    }
+  if ((ret = _attachment_setup (&info, msg, &istream)) != 0)
+    return ret;
+  if (info->msg == NULL)
+    ret = mu_message_create (&info->msg, NULL);
+  if (ret == 0)
+    {
+      mu_message_get_streamref (info->msg, &ostream);
+      mu_stream_seek (ostream, 0, MU_SEEK_SET, NULL);
+      while (((ret =
+              mu_stream_read (istream, info->buf, BUF_SIZE, 
+                              &nbytes)) == 0 && nbytes))
+       {
+         if ((ret =
+              mu_stream_write (ostream, info->buf, nbytes, NULL)) != 0)
+           break;
+       }
+      mu_stream_destroy (&ostream);
+    }
+  if (ret == 0)
+    *newmsg = info->msg;
+  mu_stream_destroy (&istream);
+  _attachment_free (info, ret && ret != EAGAIN);
+  return ret;
+}
diff --git a/libmailutils/mime/mime.c b/libmailutils/mime/mime.c
new file mode 100644
index 0000000..17c5441
--- /dev/null
+++ b/libmailutils/mime/mime.c
@@ -0,0 +1,1070 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2003, 2004, 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/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/cctype.h>
+#include <mailutils/cstr.h>
+#include <mailutils/message.h>
+#include <mailutils/stream.h>
+#include <mailutils/body.h>
+#include <mailutils/header.h>
+#include <mailutils/errno.h>
+#include <mailutils/mutil.h>
+
+#include <mailutils/sys/mime.h>
+#include <mailutils/sys/stream.h>
+
+#ifndef TRUE
+#define TRUE (1)
+#define FALSE (0)
+#endif
+
+#define CT_MULTIPART_DIGEST "multipart/digest"
+#define CT_MULTIPART_DIGEST_LEN (sizeof (CT_MULTIPART_DIGEST) - 1)
+
+/* TODO:
+ *  Need to prevent re-entry into mime lib, but allow non-blocking re-entry
+ *  into lib.
+ */
+
+static int
+_mime_is_multipart_digest (mu_mime_t mime)
+{
+  if (mime->content_type)
+    return mu_c_strncasecmp (CT_MULTIPART_DIGEST, mime->content_type,
+                            CT_MULTIPART_DIGEST_LEN) == 0;
+  return 0;
+}
+
+static int
+_mime_append_part (mu_mime_t mime, mu_message_t msg, int offset, int len, int 
lines)
+{
+  struct _mime_part *mime_part, **part_arr;
+  int             ret;
+  size_t          size;
+  mu_header_t        hdr;
+
+  if ((mime_part = calloc (1, sizeof (*mime_part))) == NULL)
+    return ENOMEM;
+
+  if (mime->nmtp_parts >= mime->tparts)
+    {
+      if ((part_arr =
+          realloc (mime->mtp_parts,
+                   (mime->tparts + 5) * sizeof (mime_part))) == NULL)
+       {
+         free (mime_part);
+         return ENOMEM;
+       }
+      mime->mtp_parts = part_arr;
+      mime->tparts += 5;
+    }
+  mime->mtp_parts[mime->nmtp_parts++] = mime_part;
+  if (msg == NULL)
+    {
+      if ((ret = mu_message_create (&(mime_part->msg), mime_part)) == 0)
+       {
+         if ((ret =
+              mu_header_create (&hdr, mime->header_buf,
+                                mime->header_length)) != 0)
+           {
+             mu_message_destroy (&mime_part->msg, mime_part);
+             free (mime_part);
+             return ret;
+           }
+         mu_message_set_header (mime_part->msg, hdr, mime_part);
+       }
+      else
+       {
+         free (mime_part);
+         return ret;
+       }
+      mime->header_length = 0;
+      if ((ret =
+          mu_header_get_value (hdr, MU_HEADER_CONTENT_TYPE, NULL,
+                               0, &size)) != 0 || size == 0)
+       {
+         if (_mime_is_multipart_digest (mime))
+           mu_header_set_value (hdr,
+                                MU_HEADER_CONTENT_TYPE, "message/rfc822", 0);
+         else
+           mu_header_set_value (hdr, MU_HEADER_CONTENT_TYPE, "text/plain",
+                                0);
+       }
+      mime_part->len = len;
+      mime_part->lines = lines;
+      mime_part->offset = offset;
+    }
+  else
+    {
+      mu_message_ref (msg);
+      mu_message_size (msg, &mime_part->len);
+      mu_message_lines (msg, &mime_part->lines);
+      if (mime->nmtp_parts > 1)
+       mime_part->offset = mime->mtp_parts[mime->nmtp_parts - 2]->len;
+      mime_part->msg = msg;
+    }
+  mime_part->mime = mime;
+  return 0;
+}
+
+#define _ISSPECIAL(c) (                                                 \
+    ((c) == '(') || ((c) == ')') || ((c) == '<') || ((c) == '>') \
+    || ((c) == '@') || ((c) == ',') || ((c) == ';') || ((c) == ':') \
+    || ((c) == '\\') || ((c) == '.') || ((c) == '[') \
+    || ((c) == ']') )
+
+static void
+_mime_munge_content_header (char *field_body)
+{
+  char           *p, *e, *str = field_body;
+  int             quoted = 0;
+
+  mu_str_stripws (field_body);
+
+  if ((e = strchr (str, ';')) == NULL)
+    return;
+  while (*e == ';')
+    {
+      p = e;
+      e++;
+      while (*e && mu_isspace (*e)) /* remove space up to param */
+       e++;
+      memmove (p + 1, e, strlen (e) + 1);
+      e = p + 1;
+
+      while (*e && *e != '=')  /* find end of value */
+       e++;
+      e = p = e + 1;
+      while (*e
+            && (quoted
+                || (!_ISSPECIAL (*e) && !mu_isspace (*e))))
+       {
+         if (*e == '\\')
+           {                   /* escaped */
+             memmove (e, e + 1, strlen (e));
+           }
+         else if (*e == '\"')
+           quoted = ~quoted;
+         e++;
+       }
+    }
+}
+
+static char    *
+_mime_get_param (char *field_body, const char *param, int *len)
+{
+  char           *str, *p, *v, *e;
+  int             quoted = 0, was_quoted;
+
+  if (len == NULL || (str = field_body) == NULL)
+    return NULL;
+
+  p = strchr (str, ';');
+  while (p)
+    {
+      p++;
+      if ((v = strchr (p, '=')) == NULL)
+       break;
+      *len = 0;
+      v = e = v + 1;
+      was_quoted = 0;
+      while (*e
+            && (quoted
+                || (!_ISSPECIAL (*e) && !mu_isspace (*e))))
+       {                       /* skip pass value and calc len */
+         if (*e == '\"')
+           quoted = ~quoted, was_quoted = 1;
+         else
+           (*len)++;
+         e++;
+       }
+      if (mu_c_strncasecmp (p, param, strlen (param)))
+       {                       /* no match jump to next */
+         p = strchr (e, ';');
+         continue;
+       }
+      else
+       return was_quoted ? v + 1 : v;  /* return unquoted value */
+    }
+  return NULL;
+}
+
+static int
+_mime_setup_buffers (mu_mime_t mime)
+{
+  if (mime->cur_buf == NULL
+      && (mime->cur_buf = malloc (mime->buf_size)) == NULL)
+    {
+      return ENOMEM;
+    }
+  if (mime->cur_line == NULL
+      && (mime->cur_line = calloc (mime->line_size, 1)) == NULL)
+    {
+      free (mime->cur_buf);
+      return ENOMEM;
+    }
+  return 0;
+}
+
+static void
+_mime_append_header_line (mu_mime_t mime)
+{
+  if (mime->header_length + mime->line_ndx > mime->header_buf_size)
+    {
+      char           *nhb;
+
+      if ((nhb =
+          realloc (mime->header_buf,
+                   mime->header_length + mime->line_ndx + 128)) == NULL)
+       return;
+      mime->header_buf = nhb;
+      mime->header_buf_size = mime->header_length + mime->line_ndx + 128;
+    }
+  memcpy (mime->header_buf + mime->header_length, mime->cur_line,
+         mime->line_ndx);
+  mime->header_length += mime->line_ndx;
+}
+
+static int
+_mime_parse_mpart_message (mu_mime_t mime)
+{
+  char           *cp, *cp2;
+  int             blength, mb_length, mb_offset, mb_lines, ret;
+  size_t          nbytes;
+
+  if (!(mime->flags & MIME_PARSER_ACTIVE))
+    {
+      char           *boundary;
+      int             len;
+
+      if ((ret = _mime_setup_buffers (mime)) != 0)
+       return ret;
+      if ((boundary =
+          _mime_get_param (mime->content_type, "boundary", &len)) == NULL)
+       return EINVAL;
+      if ((mime->boundary = calloc (1, len + 1)) == NULL)
+       return ENOMEM;
+      strncpy (mime->boundary, boundary, len);
+
+      mime->cur_offset = 0;
+      mime->line_ndx = 0;
+      mime->parser_state = MIME_STATE_SCAN_BOUNDARY;
+      mime->flags |= MIME_PARSER_ACTIVE;
+    }
+  mb_length = mime->body_length;
+  mb_offset = mime->body_offset;
+  mb_lines = mime->body_lines;
+  blength = strlen (mime->boundary);
+
+  mu_stream_seek (mime->stream, mime->cur_offset, MU_SEEK_SET, NULL);
+  while ((ret =
+         mu_stream_read (mime->stream, mime->cur_buf, mime->buf_size,
+                         &nbytes)) == 0 && nbytes)
+    {
+      cp = mime->cur_buf;
+      while (nbytes)
+       {
+         mime->cur_line[mime->line_ndx] = *cp;
+         if (*cp == '\n')
+           {
+             switch (mime->parser_state)
+               {
+               case MIME_STATE_BEGIN_LINE:
+                 mime->cur_line[0] = *cp;
+                 mime->line_ndx = 0;
+                 mime->parser_state = MIME_STATE_SCAN_BOUNDARY;
+                 break;
+
+               case MIME_STATE_SCAN_BOUNDARY:
+                 cp2 =
+                   mime->cur_line[0] ==
+                   '\n' ? mime->cur_line + 1 : mime->cur_line;
+                 if (mime->line_ndx >= blength)
+                   {
+                     if ((!strncmp (cp2, "--", 2)
+                          && !mu_c_strncasecmp (cp2 + 2, mime->boundary,
+                                                blength))
+                         || !mu_c_strncasecmp (cp2, mime->boundary, blength))
+                       {
+                         mime->parser_state = MIME_STATE_HEADERS;
+                         mime->flags &= ~MIME_PARSER_HAVE_CR;
+                         mb_length = mime->cur_offset 
+                                          - mb_offset
+                                          - mime->line_ndx;
+                         if (mime->header_length)
+                           /* this skips the preamble */
+                           {
+                             /* RFC 1521 [Page 30]:
+                                NOTE: The CRLF preceding the encapsulation
+                                line is conceptually attached to the boundary
+                                so that it is possible to have a part that
+                                does not end with a CRLF (line break). Body
+                                parts that must be considered to end with line
+                                breaks, therefore, must have two CRLFs
+                                preceding the encapsulation line, the first
+                                of which is part of the preceding body part,
+                                and the second of which is part of the
+                                encapsulation boundary. */
+                             
+                             if (mb_lines)
+                               /* to prevent negative values in case of a
+                                  malformed message */
+                               mb_lines--;
+                                 
+                             _mime_append_part (mime, NULL,
+                                                mb_offset, mb_length,
+                                                mb_lines);
+                           }
+
+                         if ((&mime->cur_line[mime->line_ndx] - cp2 - 1 >
+                              blength
+                              && !strncmp (cp2 + blength + 2, "--", 2))
+                             || (&mime->cur_line[mime->line_ndx] - cp2 - 1 ==
+                                 blength
+                                 && !strncmp (cp2 + blength, "--", 2)))
+                           {   /* last boundary */
+                             mime->parser_state = MIME_STATE_BEGIN_LINE;
+                             mime->header_length = 0;
+                           }
+                         else
+                           mime->line_ndx = -1; /* headers parsing requires
+                                                   empty line */
+                         break;
+                       }
+                   }
+
+                 if (mime->header_length)
+                   mb_lines++;
+
+                 mime->line_ndx = 0;
+                 mime->cur_line[0] = *cp;      /* stay in this state but
+                                                  leave '\n' at begining */
+                 break;
+
+               case MIME_STATE_HEADERS:
+                 mime->line_ndx++;
+                 _mime_append_header_line (mime);
+                 if (mime->line_ndx == 1 || mime->cur_line[0] == '\r')
+                   {
+                     mime->parser_state = MIME_STATE_SCAN_BOUNDARY;
+                     mb_offset = mime->cur_offset + 1;
+                     mb_lines = 0;
+                   }
+                 mime->line_ndx = -1;
+                 break;
+               }
+           }
+         mime->line_ndx++;
+         if (mime->line_ndx >= mime->line_size)
+           {
+             size_t newsize = mime->line_size + MIME_MAX_HDR_LEN;
+             char *p = realloc (mime->cur_line, newsize);
+             if (!p)
+               {
+                 ret = ENOMEM;
+                 break;
+               }
+             mime->cur_line = p;
+             mime->line_size = newsize;
+           }
+         mime->cur_offset++;
+         nbytes--;
+         cp++;
+       }
+    }
+  mime->body_lines = mb_lines;
+  mime->body_length = mb_length;
+  mime->body_offset = mb_offset;
+  if (ret != EAGAIN)
+    {                          /* finished cleanup */
+      if (mime->header_length) /* this skips the preamble */
+       _mime_append_part (mime, NULL, mb_offset, mb_length, mb_lines);
+      mime->flags &= ~MIME_PARSER_ACTIVE;
+      mime->body_offset = mime->body_length =
+       mime->header_length = mime->body_lines = 0;
+    }
+  return ret;
+}
+
+/*------ Mime message functions for READING a multipart message -----*/
+
+static int
+_mimepart_body_size (mu_body_t body, size_t *psize)
+{
+  mu_message_t       msg = mu_body_get_owner (body);
+  struct _mime_part *mime_part = mu_message_get_owner (msg);
+
+  if (mime_part == NULL)
+    return EINVAL;
+  if (psize)
+    *psize = mime_part->len;
+  return 0;
+}
+
+static int
+_mimepart_body_lines (mu_body_t body, size_t *plines)
+{
+  mu_message_t       msg = mu_body_get_owner (body);
+  struct _mime_part *mime_part = mu_message_get_owner (msg);
+
+  if (mime_part == NULL)
+    return EINVAL;
+  if (plines)
+    *plines = mime_part->lines;
+  return 0;
+}
+
+/*------ Mime message/header functions for CREATING multipart message -----*/
+static int
+_mime_set_content_type (mu_mime_t mime)
+{
+  const char  *content_type;
+  mu_header_t     hdr = NULL;
+  size_t          size;
+  int             ret;
+
+  /* Delayed the creation of the header 'til they create the final message via
+     mu_mime_get_message()  */
+  if (mime->hdrs == NULL)
+    return 0;
+  if (mime->nmtp_parts > 1)
+    {
+      char *cstr;
+      
+      if (mime->flags & MIME_ADDED_MULTIPART_CT)
+       return 0;
+      if (mime->flags & MU_MIME_MULTIPART_MIXED)
+       content_type = "multipart/mixed; boundary=";
+      else
+       content_type = "multipart/alternative; boundary=";
+      if (mime->boundary == NULL)
+       {
+         char boundary[128];
+         
+         snprintf (boundary, sizeof boundary, "%ld-%ld=:%ld",
+                   (long) random (), (long) time (0), (long) getpid ());
+         if ((mime->boundary = strdup (boundary)) == NULL)
+           return ENOMEM;
+       }
+      size = strlen (content_type) + 2 + strlen (mime->boundary) + 1;
+      cstr = malloc (size);
+      if (!cstr)
+       return ENOMEM;
+      strcpy (cstr, content_type);
+      strcat (cstr, "\"");
+      strcat (cstr, mime->boundary);
+      strcat (cstr, "\"");
+      mime->flags |= MIME_ADDED_MULTIPART_CT;
+
+      ret = mu_header_set_value (mime->hdrs, MU_HEADER_CONTENT_TYPE, cstr, 1);
+      free (cstr);
+    }
+  else
+    {
+      if ((mime->flags & (MIME_ADDED_CT | MIME_ADDED_MULTIPART_CT))
+         == MIME_ADDED_CT)
+       return 0;
+      mime->flags &= ~MIME_ADDED_MULTIPART_CT;
+      if (mime->nmtp_parts)
+       mu_message_get_header (mime->mtp_parts[0]->msg, &hdr);
+
+      if (hdr == NULL
+         || mu_header_sget_value (hdr, MU_HEADER_CONTENT_TYPE,
+                                  &content_type))
+       content_type = "text/plain; charset=us-ascii";
+
+      ret = mu_header_set_value (mime->hdrs, MU_HEADER_CONTENT_TYPE,
+                                content_type, 1);
+      if (ret)
+       return ret;
+
+      if (hdr)
+       {
+         const char *content_te;
+         
+         /* if the only part contains a transfer-encoding
+            field, set it on the message header too */
+         if (mu_header_sget_value (hdr,
+                               MU_HEADER_CONTENT_TRANSFER_ENCODING,
+                               &content_te) == 0)
+           ret = mu_header_set_value (mime->hdrs,
+                                      MU_HEADER_CONTENT_TRANSFER_ENCODING,
+                                      content_te, 1);
+
+         if (ret == 0
+             && mu_header_sget_value (hdr,
+                                      MU_HEADER_CONTENT_DESCRIPTION,
+                                      &content_te) == 0)
+           ret = mu_header_set_value (mime->hdrs,
+                                      MU_HEADER_CONTENT_DESCRIPTION,
+                                      content_te, 1);
+
+       }
+    }
+  mime->flags |= MIME_ADDED_CT;
+  return ret;
+}
+
+
+static int
+_mime_part_size (mu_mime_t mime, size_t *psize)
+{
+  int i, ret;
+  size_t size, total = 0;
+
+  if (mime->nmtp_parts == 0)
+    return EINVAL;
+
+  if ((ret = _mime_set_content_type (mime)) != 0)
+    return ret;
+  for (i = 0; i < mime->nmtp_parts; i++)
+    {
+      mu_message_size (mime->mtp_parts[i]->msg, &size);
+      total += size;
+      if (mime->nmtp_parts > 1)        /* boundary line */
+       total += strlen (mime->boundary) + 3;
+    }
+  if (mime->nmtp_parts > 1)    /* ending boundary line */
+    total += 2;
+  *psize = total;
+  return 0;
+}
+
+
+struct _mime_body_stream
+{
+  struct _mu_stream stream;
+  mu_mime_t mime;
+};
+
+static int
+_mime_body_stream_size (mu_stream_t stream, mu_off_t *psize)
+{
+  struct _mime_body_stream *mstr = (struct _mime_body_stream *)stream;
+  mu_mime_t mime = mstr->mime;
+  size_t sz;
+  int rc = _mime_part_size (mime, &sz);
+  if (rc == 0)
+    *psize = sz;
+  return rc;
+}
+
+static void
+mime_reset_state (mu_mime_t mime)
+{                              /* reset message */
+  mime->cur_offset = 0;
+  mime->cur_part = 0;
+  mime->part_offset = 0;
+  
+  if (mime->nmtp_parts > 1)
+    mime->flags |= MIME_INSERT_BOUNDARY;
+}
+
+/* FIXME: The seek method is defective */
+static int
+_mime_body_stream_seek (mu_stream_t stream, mu_off_t off, mu_off_t *presult)
+{
+  struct _mime_body_stream *mstr = (struct _mime_body_stream *)stream;
+  mu_mime_t mime = mstr->mime;
+
+  if (off == 0)
+    mime_reset_state (mime);
+
+  if (off != mime->cur_offset)
+    return ESPIPE;
+  *presult = off;
+  return 0;
+}
+
+#define ADD_CHAR(buf, c, offset, buflen, total, nbytes)        \
+  do                                                   \
+    {                                                  \
+      *(buf)++ = c;                                    \
+      (offset)++;                                      \
+      (total)++;                                       \
+      if (--(buflen) == 0)                             \
+       {                                               \
+         *(nbytes) = total;                            \
+         return 0;                                     \
+       }                                               \
+    }                                                  \
+  while (0)
+
+static int
+_mime_body_stream_read (mu_stream_t stream, char *buf, size_t buflen, size_t 
*nbytes)
+{
+  struct _mime_body_stream *mstr = (struct _mime_body_stream *)stream;
+  mu_mime_t mime = mstr->mime;
+  int                ret = 0;
+  size_t             total = 0;
+  
+  if (mime->nmtp_parts == 0)
+    return EINVAL;
+  
+  if ((ret = _mime_set_content_type (mime)) == 0)
+    {
+      do
+       {
+         size_t             part_nbytes = 0;
+
+         if (buflen == 0)
+           break;
+         if (mime->nmtp_parts > 1)
+           {
+             size_t len;
+             
+             if (mime->flags & MIME_INSERT_BOUNDARY)
+               {
+                 if ((mime->flags & MIME_ADDING_BOUNDARY) == 0)
+                   {
+                     mime->boundary_len = strlen (mime->boundary);
+                     mime->preamble = 2;
+                     if (mime->cur_part == mime->nmtp_parts)
+                       mime->postamble = 2;
+                     mime->flags |= MIME_ADDING_BOUNDARY;
+                   }
+                 while (mime->preamble)
+                   {
+                     mime->preamble--;
+                     ADD_CHAR (buf, '-', mime->cur_offset, buflen,
+                               total, nbytes);
+                   }
+                 len = strlen (mime->boundary) - mime->boundary_len;
+                 while (mime->boundary_len)
+                   {
+                     mime->boundary_len--;
+                     ADD_CHAR (buf,
+                               mime->boundary[len++],
+                               mime->cur_offset, buflen,
+                               total, nbytes);
+                   }
+                 while (mime->postamble)
+                   {
+                     mime->postamble--;
+                     ADD_CHAR (buf, '-', mime->cur_offset, buflen,
+                               total, nbytes);
+                   }
+                 mime->flags &=
+                   ~(MIME_INSERT_BOUNDARY | MIME_ADDING_BOUNDARY);
+                 mime->part_offset = 0;
+                 ADD_CHAR (buf, '\n', mime->cur_offset, buflen,
+                           total, nbytes);
+               }
+
+             if (!mime->part_stream)
+               {
+                 if (mime->cur_part >= mime->nmtp_parts)
+                   {
+                     *nbytes = total;
+                     return 0;
+                   }
+                 ret = mu_message_get_streamref 
(mime->mtp_parts[mime->cur_part]->msg,
+                                                 &mime->part_stream);
+               }
+           }
+         else if (!mime->part_stream)
+           {
+             mu_body_t part_body;
+
+             if (mime->cur_part >= mime->nmtp_parts)
+               {
+                 *nbytes = total;
+                 return 0;
+               }
+             mu_message_get_body (mime->mtp_parts[mime->cur_part]->msg,
+                                  &part_body);
+             ret = mu_body_get_streamref (part_body, &mime->part_stream);
+           }
+         if (ret)
+           break;
+         ret = mu_stream_seek (mime->part_stream, mime->part_offset,
+                               MU_SEEK_SET, NULL);
+         if (ret)
+           {
+             mu_stream_destroy (&mime->part_stream);
+             break;
+           }
+         while (buflen > 0 &&
+                (ret = mu_stream_read (mime->part_stream, buf, buflen,
+                                       &part_nbytes)) == 0)
+           {
+             if (part_nbytes)
+               {
+                 mime->part_offset += part_nbytes;
+                 mime->cur_offset += part_nbytes;
+                 total += part_nbytes;
+                 buflen -= part_nbytes;
+                 buf += part_nbytes;
+               }
+             else 
+               {
+                 mu_stream_destroy (&mime->part_stream);
+                 mime->flags |= MIME_INSERT_BOUNDARY;
+                 mime->cur_part++;
+                 ADD_CHAR (buf, '\n', mime->cur_offset, buflen,
+                           total, nbytes);
+                 break;
+               }
+           }
+       }
+      while (ret == 0 && mime->cur_part <= mime->nmtp_parts);
+    }
+  if (ret)
+    mu_stream_destroy (&mime->part_stream);
+  
+  *nbytes = total;
+  return ret;
+}
+
+static int
+_mime_body_stream_ioctl (mu_stream_t stream, int code, void *arg)
+{
+  struct _mime_body_stream *mstr = (struct _mime_body_stream *)stream;
+  mu_mime_t mime = mstr->mime;
+  mu_stream_t msg_stream;
+  int rc;
+  
+  switch (code)
+    {
+    case MU_IOCTL_GET_TRANSPORT:
+      if (!arg)
+       return EINVAL;
+      
+      if (mime->nmtp_parts == 0 || mime->cur_offset == 0)
+       return EINVAL;
+      rc = mu_message_get_streamref (mime->mtp_parts[mime->cur_part]->msg,
+                                    &msg_stream);
+      if (rc)
+       break;
+      rc = mu_stream_ioctl (msg_stream, code, arg);
+      mu_stream_destroy (&msg_stream);
+      break;
+
+    default:
+      rc = ENOSYS;
+    }
+  return rc;
+}
+
+static int
+create_mime_body_stream (mu_stream_t *pstr, mu_mime_t mime)
+{
+  struct _mime_body_stream *sp =
+    (struct _mime_body_stream *)_mu_stream_create (sizeof (*sp),
+                                                  MU_STREAM_READ | 
MU_STREAM_SEEK);
+  if (!sp)
+    return ENOMEM;
+  sp->stream.read = _mime_body_stream_read;
+  sp->stream.seek = _mime_body_stream_seek;
+  sp->stream.ctl = _mime_body_stream_ioctl;
+  sp->stream.size = _mime_body_stream_size;
+  sp->mime = mime;
+  mime_reset_state (mime);
+  *pstr = (mu_stream_t) sp;
+  return 0;
+}
+
+
+static int
+_mime_body_size (mu_body_t body, size_t *psize)
+{
+  mu_message_t       msg = mu_body_get_owner (body);
+  mu_mime_t          mime = mu_message_get_owner (msg);
+  return _mime_part_size (mime, psize);
+}
+
+static int
+_mime_body_lines (mu_body_t body, size_t *plines)
+{
+  mu_message_t       msg = mu_body_get_owner (body);
+  mu_mime_t          mime = mu_message_get_owner (msg);
+  int             i, ret;
+  size_t          lines;
+
+  if (mime->nmtp_parts == 0)
+    return EINVAL;
+
+  if ((ret = _mime_set_content_type (mime)) != 0)
+    return ret;
+  for (i = 0; i < mime->nmtp_parts; i++)
+    {
+      mu_message_lines (mime->mtp_parts[i]->msg, &lines);
+      plines += lines;
+      if (mime->nmtp_parts > 1)        /* boundary line */
+       plines++;
+    }
+  return 0;
+}
+
+int
+mu_mime_create (mu_mime_t *pmime, mu_message_t msg, int flags)
+{
+  mu_mime_t          mime = NULL;
+  int             ret = 0;
+  size_t          size;
+  mu_body_t          body;
+
+  if (pmime == NULL)
+    return EINVAL;
+  *pmime = NULL;
+  if ((mime = calloc (1, sizeof (*mime))) == NULL)
+    return ENOMEM;
+  if (msg)
+    {
+      if ((ret = mu_message_get_header (msg, &mime->hdrs)) == 0)
+       {
+         if ((ret =
+              mu_header_get_value (mime->hdrs,
+                                   MU_HEADER_CONTENT_TYPE,
+                                   NULL, 0, &size)) == 0 && size)
+           {
+             if ((mime->content_type = malloc (size + 1)) == NULL)
+               ret = ENOMEM;
+             else if ((ret = mu_header_get_value (mime->hdrs,
+                                                  MU_HEADER_CONTENT_TYPE,
+                                                  mime->content_type,
+                                                  size + 1, 0)) == 0)
+               _mime_munge_content_header (mime->content_type);
+           }
+         else
+           {
+             if (ret == MU_ERR_NOENT)
+               {
+                 ret = 0;
+                 if ((mime->content_type =
+                      strdup ("text/plain; charset=us-ascii")) == NULL)
+                   /* default as per spec. */
+                   ret = ENOMEM;
+               }
+           }
+         if (ret == 0)
+           {
+             mime->msg = msg;
+             mime->buf_size = MIME_DFLT_BUF_SIZE;
+             mime->line_size = MIME_MAX_HDR_LEN;
+             mu_message_get_body (msg, &body);
+             mu_body_get_streamref (body, &mime->stream);
+           }
+       }
+    }
+  else
+    {
+      mime->flags |= MIME_NEW_MESSAGE | MU_MIME_MULTIPART_MIXED;
+    }
+  if (ret != 0)
+    {
+      if (mime->content_type)
+       free (mime->content_type);
+      free (mime);
+    }
+  else
+    {
+      mime->flags |= (flags & MIME_FLAG_MASK);
+      *pmime = mime;
+    }
+  return ret;
+}
+
+void
+mu_mime_destroy (mu_mime_t *pmime)
+{
+  mu_mime_t          mime;
+  struct _mime_part *mime_part;
+  int             i;
+
+  if (pmime && *pmime)
+    {
+      mime = *pmime;
+      if (mime->mtp_parts != NULL)
+       {
+         for (i = 0; i < mime->nmtp_parts; i++)
+           {
+             mime_part = mime->mtp_parts[i];
+             if (mime_part->msg && mime->flags & MIME_NEW_MESSAGE)
+               mu_message_unref (mime_part->msg);
+             else
+               mu_message_destroy (&mime_part->msg, mime_part);
+             free (mime_part);
+           }
+         free (mime->mtp_parts);
+       }
+      mu_stream_destroy (&mime->stream);
+      mu_stream_destroy (&mime->part_stream);
+      if (mime->msg && mime->flags & MIME_NEW_MESSAGE)
+       mu_message_destroy (&mime->msg, mime);
+      if (mime->content_type)
+       free (mime->content_type);
+      if (mime->cur_buf)
+       free (mime->cur_buf);
+      if (mime->cur_line)
+       free (mime->cur_line);
+      if (mime->boundary)
+       free (mime->boundary);
+      if (mime->header_buf)
+       free (mime->header_buf);
+      free (mime);
+      *pmime = NULL;
+    }
+}
+
+int
+mu_mime_get_part (mu_mime_t mime, size_t part, mu_message_t *msg)
+{
+  size_t          nmtp_parts;
+  int             ret = 0, flags = 0;
+  mu_stream_t        stream;
+  mu_body_t          body;
+  struct _mime_part *mime_part;
+
+  if ((ret = mu_mime_get_num_parts (mime, &nmtp_parts)) == 0)
+    {
+      if (part < 1 || part > nmtp_parts)
+       return MU_ERR_NOENT;
+      if (nmtp_parts == 1 && mime->mtp_parts == NULL)
+       *msg = mime->msg;
+      else
+       {
+         mime_part = mime->mtp_parts[part - 1];
+         if (!mime_part->body_created
+             && (ret = mu_body_create (&body, mime_part->msg)) == 0)
+           {
+             mu_body_set_size (body, _mimepart_body_size, mime_part->msg);
+             mu_body_set_lines (body, _mimepart_body_lines, mime_part->msg);
+             mu_stream_get_flags (mime->stream, &flags);
+             ret = mu_streamref_create_abridged (&stream, mime->stream,
+                                                 mime_part->offset,
+                                                 mime_part->offset +
+                                                   mime_part->len - 1);
+             if (ret == 0)
+               {
+                 mu_stream_set_flags (stream,
+                                      MU_STREAM_READ | (flags &
+                                                        (MU_STREAM_SEEK
+                                                         | 
MU_STREAM_NONBLOCK)));
+                 mu_body_set_stream (body, stream, mime_part->msg);
+                 mu_message_set_body (mime_part->msg, body, mime_part);
+                 mime_part->body_created = 1;
+               }
+           }
+         *msg = mime_part->msg;
+       }
+    }
+  return ret;
+}
+
+int
+mu_mime_get_num_parts (mu_mime_t mime, size_t *nmtp_parts)
+{
+  int             ret = 0;
+
+  if ((mime->nmtp_parts == 0 && !mime->boundary)
+      || mime->flags & MIME_PARSER_ACTIVE)
+    {
+      if (mu_mime_is_multipart (mime))
+       {
+         if ((ret = _mime_parse_mpart_message (mime)) != 0)
+           return (ret);
+       }
+      else
+       mime->nmtp_parts = 1;
+    }
+  *nmtp_parts = mime->nmtp_parts;
+  return (ret);
+
+}
+
+int
+mu_mime_add_part (mu_mime_t mime, mu_message_t msg)
+{
+  int             ret;
+
+  if (mime == NULL || msg == NULL || (mime->flags & MIME_NEW_MESSAGE) == 0)
+    return EINVAL;
+  if ((ret = _mime_append_part (mime, msg, 0, 0, 0)) == 0)
+    ret = _mime_set_content_type (mime);
+  return ret;
+}
+
+int
+mu_mime_get_message (mu_mime_t mime, mu_message_t *msg)
+{
+  mu_stream_t        body_stream;
+  mu_body_t          body;
+  int             ret = 0;
+
+  if (mime == NULL || msg == NULL)
+    return EINVAL;
+  if (mime->msg == NULL)
+    {
+      if ((mime->flags & MIME_NEW_MESSAGE) == 0)
+       return EINVAL;
+      if ((ret = mu_message_create (&mime->msg, mime)) == 0)
+       {
+         if ((ret = mu_header_create (&mime->hdrs, NULL, 0)) == 0)
+           {
+             mu_message_set_header (mime->msg, mime->hdrs, mime);
+             mu_header_set_value (mime->hdrs, MU_HEADER_MIME_VERSION, "1.0",
+                                  0);
+             if ((ret = _mime_set_content_type (mime)) == 0)
+               {
+                 if ((ret = mu_body_create (&body, mime->msg)) == 0)
+                   {
+                     mu_message_set_body (mime->msg, body, mime);
+                     mu_body_set_size (body, _mime_body_size, mime->msg);
+                     mu_body_set_lines (body, _mime_body_lines, mime->msg);
+                     ret = create_mime_body_stream (&body_stream, mime);
+                     if (ret == 0)
+                       {
+                         mu_body_set_stream (body, body_stream, mime->msg);
+                         *msg = mime->msg;
+                         return 0;
+                       }
+                   }
+               }
+           }
+         mu_message_destroy (&mime->msg, mime);
+         mime->msg = NULL;
+       }
+    }
+  if (ret == 0)
+    *msg = mime->msg;
+  return ret;
+}
+
+int
+mu_mime_is_multipart (mu_mime_t mime)
+{
+  if (mime->content_type)
+    return (mu_c_strncasecmp ("multipart", mime->content_type,
+                             strlen ("multipart")) ? 0 : 1);
+  return 0;
+}
diff --git a/libmailutils/mimehdr.c b/libmailutils/mime/mimehdr.c
similarity index 100%
rename from libmailutils/mimehdr.c
rename to libmailutils/mime/mimehdr.c
diff --git a/libmailutils/monitor.c b/libmailutils/monitor.c
deleted file mode 100644
index 45e7dc9..0000000
--- a/libmailutils/monitor.c
+++ /dev/null
@@ -1,282 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2007, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-/* Tell GLIBC that we want UNIX98 pthread_rwlock_xx() functions.  */
-#define _XOPEN_SOURCE   500
-/* Tell QNX/Neutrino to define pthread_rwlock_xx() functions.  */
-#define _QNX_SOURCE
-#define _POSIX_C_SOURCE 199506
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
-#ifdef WITH_PTHREAD
-#  ifdef HAVE_PTHREAD_H
-#    include <pthread.h>
-#  endif
-#endif
-#include <errno.h>
-#include <stdlib.h>
-
-#include <mailutils/sys/monitor.h>
-#include <mailutils/errno.h>
-
-#ifdef WITH_PTHREAD
-pthread_mutex_t monitor_lock = PTHREAD_MUTEX_INITIALIZER;
-#  define STATIC_LOCK(m) pthread_mutex_lock(m)
-#  define STATIC_UNLOCK(m) pthread_mutex_unlock(m)
-#else
-#  define STATIC_LOCK(m) 0
-#  define STATIC_UNLOCK(m)
-int monitor_lock;
-#endif
-
-union _p_lock
-{
-#ifdef WITH_PTHREAD
-#  ifdef HAVE_PTHREAD_RWLOCK_INIT
-     pthread_rwlock_t mutex;
-#  else
-     pthread_mutex_t mutex;
-#  endif
-#else
-  int dummy;
-#endif
-};
-
-typedef union _p_lock *p_lock_t;
-static int  monitor_pthread_create (p_lock_t *);
-static void monitor_pthread_destroy (p_lock_t *);
-static int monitor_pthread_rdlock (p_lock_t);
-static int monitor_pthread_wrlock (p_lock_t);
-static int monitor_pthread_unlock (p_lock_t);
-
-/* The idea was to have a general/portable object mu_monitor_t.
-   The mu_monitor_t object could have different implementation (on the fly ?)
-   of locking.  Also the rest of the library would not have to know about
-   different threading implementation.  So far we've pretty much hardcoded
-   the concrete implementation of monitor on pthread and read/write locks,
-   but changing to a different concrete implementation will not be hard if
-   the need arise.
-   For static initializers we take a small penality and since we have
-   a global static lock.
- */
-
-int
-mu_monitor_create (mu_monitor_t *pmonitor, int flags, void *owner)
-{
-  mu_monitor_t monitor;
-
-  if (pmonitor == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-
-  monitor = calloc (1, sizeof (*monitor));
-  if (monitor == NULL)
-    return ENOMEM;
-
-  if (flags == MU_MONITOR_PTHREAD)
-    {
-      int status = monitor_pthread_create ((p_lock_t *)&(monitor->data));
-      if (status != 0)
-       {
-         free (monitor);
-         return status;
-       }
-    }
-  monitor->owner = owner;
-  monitor->allocated = 1;
-  monitor->flags = flags;
-  *pmonitor = monitor;
-  return 0;
-}
-
-void *
-mu_monitor_get_owner (mu_monitor_t monitor)
-{
-  return (monitor == NULL) ? NULL : monitor->owner;
-}
-
-void
-mu_monitor_destroy (mu_monitor_t *pmonitor, void *owner)
-{
-  if (pmonitor && *pmonitor)
-    {
-      mu_monitor_t monitor = *pmonitor;
-      if (monitor->owner == owner)
-       {
-         if (monitor->flags == MU_MONITOR_PTHREAD)
-           monitor_pthread_destroy ((p_lock_t *)&(monitor->data));
-       }
-      free (monitor);
-      *pmonitor = NULL;
-    }
-}
-
-int
-mu_monitor_rdlock (mu_monitor_t monitor)
-{
-  if (monitor)
-    {
-      if (!monitor->allocated)
-       {
-         int status = STATIC_LOCK (&monitor_lock);
-         if (monitor->data == NULL)
-           {
-             if (monitor->flags == MU_MONITOR_PTHREAD)
-               status = monitor_pthread_create ((p_lock_t*)&(monitor->data));
-             if (status != 0)
-               {
-                 STATIC_UNLOCK (&monitor_lock);
-                 return status;
-               }
-           }
-         monitor->allocated = 1;
-         STATIC_UNLOCK (&monitor_lock);
-       }
-      if (monitor->flags == MU_MONITOR_PTHREAD)
-       return monitor_pthread_rdlock ((p_lock_t)monitor->data);
-    }
-  return 0;
-}
-
-int
-mu_monitor_wrlock  (mu_monitor_t monitor)
-{
-  if (monitor)
-    {
-      if (!monitor->allocated)
-       {
-         int status = STATIC_LOCK (&monitor_lock);
-         if (monitor->data == NULL)
-           {
-             if (monitor->flags == MU_MONITOR_PTHREAD)
-               status = monitor_pthread_create ((p_lock_t *)&(monitor->data));
-             if (status != 0)
-               {
-                 STATIC_UNLOCK (&monitor_lock);
-                 return status;
-               }
-           }
-         monitor->allocated = 1;
-         STATIC_UNLOCK (&monitor_lock);
-       }
-      if (monitor->flags == MU_MONITOR_PTHREAD)
-       return monitor_pthread_wrlock ((p_lock_t)monitor->data);
-    }
-  return 0;
-}
-
-int
-mu_monitor_unlock (mu_monitor_t monitor)
-{
-  if (monitor)
-    {
-      if (monitor->flags == MU_MONITOR_PTHREAD)
-       return monitor_pthread_unlock ((p_lock_t)monitor->data);
-    }
-  return 0;
-}
-
-int
-mu_monitor_wait (mu_monitor_t monitor MU_ARG_UNUSED)
-{
-  return ENOSYS;
-}
-
-int
-mu_monitor_notify (mu_monitor_t monitor MU_ARG_UNUSED)
-{
-  return ENOSYS;
-}
-
-
-/* Concrete Implementation of pthread base on rwlocks.  */
-
-#ifdef WITH_PTHREAD
-#  ifdef HAVE_PTHREAD_RWLOCK_INIT
-#    define RWLOCK_INIT(rwl, attr)  pthread_rwlock_init (rwl, attr)
-#    define RWLOCK_DESTROY(rwl)     pthread_rwlock_destroy (rwl)
-#    define RWLOCK_RDLOCK(rwl)      pthread_rwlock_rdlock (rwl)
-#    define RWLOCK_WRLOCK(rwl)      pthread_rwlock_wrlock (rwl)
-#    define RWLOCK_UNLOCK(rwl)      pthread_rwlock_unlock (rwl)
-#  else
-#    define RWLOCK_INIT(rwl, attr)  pthread_mutex_init (rwl, attr)
-#    define RWLOCK_DESTROY(rwl)     pthread_mutex_destroy (rwl)
-#    define RWLOCK_RDLOCK(rwl)      pthread_mutex_lock (rwl)
-#    define RWLOCK_WRLOCK(rwl)      pthread_mutex_lock (rwl)
-#    define RWLOCK_UNLOCK(rwl)      pthread_mutex_unlock (rwl)
-#  endif
-#else
-#  define RWLOCK_INIT(rwl, attr)    0
-#  define RWLOCK_DESTROY(rwl)
-#  define RWLOCK_RDLOCK(rwl)        0
-#  define RWLOCK_WRLOCK(rwl)        0
-#  define RWLOCK_UNLOCK(rwl)        0
-#  define flockfile(arg)
-#  define funlockfile(arg)
-#endif
-
-
-
-static int
-monitor_pthread_create (p_lock_t *plock)
-{
-  int status;
-  p_lock_t lock = calloc (1, sizeof (*lock));
-  if (lock == NULL)
-    return ENOMEM;
-  status = RWLOCK_INIT (&(lock->mutex), NULL);
-  if (status != 0)
-    {
-      free (lock);
-      return status;
-    }
-  *plock = lock;
-  return 0;
-}
-
-static void
-monitor_pthread_destroy (p_lock_t *plock)
-{
-  p_lock_t lock = *plock;
-  if (lock)
-    {
-      RWLOCK_DESTROY (&(lock->mutex));
-      free (lock);
-    }
-  *plock = NULL;
-}
-
-static int
-monitor_pthread_rdlock (p_lock_t lock)
-{
-  return RWLOCK_RDLOCK (&(lock->mutex));
-}
-
-static int
-monitor_pthread_wrlock (p_lock_t lock)
-{
-  return RWLOCK_WRLOCK (&(lock->mutex));
-}
-
-static int
-monitor_pthread_unlock (p_lock_t lock)
-{
-  return RWLOCK_UNLOCK (&(lock->mutex));
-}
diff --git a/libmailutils/mu_auth.c b/libmailutils/mu_auth.c
deleted file mode 100644
index bba6b45..0000000
--- a/libmailutils/mu_auth.c
+++ /dev/null
@@ -1,539 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2002, 2004, 2005, 2006, 2007, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <unistd.h>
-#include <sys/types.h>
-#include <pwd.h>
-#ifdef HAVE_SHADOW_H
-# include <shadow.h>
-#endif
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
-#endif
-#ifdef HAVE_SECURITY_PAM_APPL_H
-# include <security/pam_appl.h>
-#endif
-#ifdef HAVE_CRYPT_H
-# include <crypt.h>
-#endif
-
-#include <mailutils/argcv.h>
-#include <mailutils/list.h>
-#include <mailutils/iterator.h>
-#include <mailutils/mailbox.h>
-#include <mailutils/mu_auth.h>
-#include <mailutils/error.h>
-#include <mailutils/errno.h>
-#include <mailutils/nls.h>
-#include <mailutils/debug.h>
-
-static mu_debug_t mu_auth_debug;
-
-#define S(s) ((s) ? (s) : "(none)")
-#define DEBUG_AUTH(a)                                                         \
-     MU_DEBUG11 (mu_auth_debug, MU_DEBUG_TRACE,                               \
-                       "source=%s, name=%s, passwd=%s, uid=%lu, gid=%lu, "    \
-                       "gecos=%s, dir=%s, shell=%s, mailbox=%s, quota=%lu, "  \
-                       "change_uid=%d\n",                                     \
-                       S ((a)->source),                                       \
-                       S ((a)->name),                                         \
-                       S ((a)->passwd),                                       \
-                       (unsigned long) (a)->uid,                              \
-                       (unsigned long) (a)->gid,                              \
-                       S ((a)->gecos),                                        \
-                       S ((a)->dir),                                          \
-                       S ((a)->shell),                                        \
-                       S ((a)->mailbox),                                      \
-                       (unsigned long) (a)->quota,                            \
-                       (a)->change_uid)
-     
-mu_debug_t
-mu_auth_set_debug (mu_debug_t debug)
-{
-  mu_debug_t prev = mu_auth_debug;
-  mu_auth_debug = debug;
-  return prev;
-}
-
-
-/* memory allocation */
-int 
-mu_auth_data_alloc (struct mu_auth_data **ptr,
-                    const char *name,
-                    const char *passwd,
-                    uid_t uid,
-                    gid_t gid,
-                    const char *gecos,
-                    const char *dir,
-                    const char *shell,
-                    const char *mailbox,
-                    int change_uid)
-{
-  size_t size;
-  char *p;
-  char *tmp_mailbox_name = NULL;
-  
-  if (!name)
-    return EINVAL;
-  if (!passwd)
-    passwd = "x";
-  if (!gecos)
-    gecos = "";
-  if (!dir)
-    dir = "/nonexisting";
-  if (!shell)
-    shell = "/dev/null";
-  if (!mailbox)
-    {
-      int rc = mu_construct_user_mailbox_url (&tmp_mailbox_name, name);
-      if (rc)
-       return rc;
-      mailbox = tmp_mailbox_name;
-    }
-
-  size = sizeof (**ptr) +
-         strlen (name) + 1 +
-         strlen (passwd) + 1 +
-         strlen (gecos) + 1 +
-         strlen (dir) + 1 +
-         strlen (shell) + 1 +
-         strlen (mailbox) + 1;
-  
-  *ptr = calloc (1, size);
-  if (!*ptr)
-    return ENOMEM;
-
-  p = (char *)(*ptr + 1);
-  
-#define COPY(f) \
-  (*ptr)->f = p; \
-  strcpy (p, f); \
-  p += strlen (f) + 1
-  
-  COPY (name);
-  COPY (passwd);
-  COPY (gecos);
-  COPY (dir);
-  COPY (shell);
-  COPY (mailbox);
-  (*ptr)->uid = uid;
-  (*ptr)->gid = gid;
-  (*ptr)->change_uid = change_uid;
-
-  free (tmp_mailbox_name);
-  return 0;
-}
-
-void
-mu_auth_data_set_quota (struct mu_auth_data *ptr, mu_off_t q)
-{
-  ptr->flags |= MU_AF_QUOTA;
-  ptr->quota = q;
-}
-
-void
-mu_auth_data_free (struct mu_auth_data *ptr)
-{
-  free (ptr);
-}
-
-void
-mu_auth_data_destroy (struct mu_auth_data **pptr)
-{
-  if (pptr)
-    {
-      mu_auth_data_free (*pptr);
-      *pptr = NULL;
-    }
-}
-
-/* Generic functions */
-
-struct auth_stack_entry {
-  char *name;        /* for diagnostics purposes */
-  mu_auth_fp fun;
-  void *func_data;
-};
-
-void
-mu_insert_stack_entry (mu_list_t *pflist, struct auth_stack_entry *entry)
-{
-  if (!*pflist && mu_list_create (pflist))
-    return;
-  mu_list_append (*pflist, entry);
-}
-
-int
-mu_auth_runlist (mu_list_t flist, struct mu_auth_data **return_data,
-                 const void *key, void *data)
-{
-  int status = MU_ERR_AUTH_FAILURE;
-  int rc;
-  mu_iterator_t itr;
-
-  if (mu_list_get_iterator (flist, &itr) == 0)
-    {
-      struct auth_stack_entry *ep;
-      
-      for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
-           mu_iterator_next (itr))
-        {
-          mu_iterator_current (itr, (void **)&ep);
-          MU_DEBUG1 (mu_auth_debug, MU_DEBUG_TRACE, "Trying %s...", ep->name);
-          rc = ep->fun (return_data, key, ep->func_data, data);
-          MU_DEBUG2 (mu_auth_debug, MU_DEBUG_TRACE, 
-                     "result: %d=%s\n", rc, mu_strerror (rc));
-          if (rc == 0)
-            {
-              if (return_data)
-                {
-                  struct mu_auth_data *auth = *return_data;
-                  if (auth->source == NULL)
-                    auth->source = ep->name;
-                  DEBUG_AUTH (auth);
-                }
-              status = rc;
-              break;
-            }
-          else if (rc == ENOSYS && status != 0)
-           /* nothing: do not overwrite last meaningful return code */;
-         else if (status != EAGAIN)
-            status = rc;
-        }
-
-      mu_iterator_destroy (&itr);
-    }
-  return status;
-}
-
-int
-mu_auth_nosupport (struct mu_auth_data **return_data MU_ARG_UNUSED,
-                   const void *key MU_ARG_UNUSED,
-                   void *func_data MU_ARG_UNUSED,
-                   void *call_data MU_ARG_UNUSED)
-{
-  return ENOSYS;
-}
-
-/* II. Authorization: retrieving information about user */
-
-static mu_list_t mu_auth_by_name_list, _tmp_auth_by_name_list;
-static mu_list_t mu_auth_by_uid_list, _tmp_auth_by_uid_list;
-
-int
-mu_get_auth (struct mu_auth_data **auth, enum mu_auth_key_type type,
-             const void *key)
-{
-  mu_list_t list;
-  
-  if (!mu_auth_by_name_list)
-    mu_auth_begin_setup ();
-  switch (type)
-    {
-    case mu_auth_key_name:
-      MU_DEBUG1 (mu_auth_debug, MU_DEBUG_TRACE, 
-                 "Getting auth info for user %s\n", 
-                 (char*) key);
-      list = mu_auth_by_name_list;
-      break;
-
-    case mu_auth_key_uid:
-      MU_DEBUG1 (mu_auth_debug, MU_DEBUG_TRACE, 
-                 "Getting auth info for UID %lu\n",
-                (unsigned long) *(uid_t*) key);
-      list = mu_auth_by_uid_list;
-      break;
-
-    default:
-      MU_DEBUG1 (mu_auth_debug, MU_DEBUG_ERROR, 
-                 "Unknown mu_auth_key_type: %d\n", type);
-      return EINVAL;
-    }
-  return mu_auth_runlist (list, auth, key, NULL);
-}
-
-struct mu_auth_data *
-mu_get_auth_by_name (const char *username)
-{
-  struct mu_auth_data *auth = NULL;
-  mu_get_auth (&auth, mu_auth_key_name, username);
-  return auth;
-}
-
-struct mu_auth_data *
-mu_get_auth_by_uid (uid_t uid)
-{
-  struct mu_auth_data *auth = NULL;
-  mu_get_auth (&auth, mu_auth_key_uid, &uid);
-  return auth;
-}
-
-/* III. Authentication: determining the authenticity of a user */
-
-static mu_list_t mu_authenticate_list, _tmp_authenticate_list;
-
-int
-mu_authenticate (struct mu_auth_data *auth_data, const char *pass)
-{
-  if (!auth_data)
-    return EINVAL;
-  MU_DEBUG2 (mu_auth_debug, MU_DEBUG_TRACE, 
-             "mu_authenticate, user %s, source %s\n", 
-             auth_data->name, auth_data->source);
-  if (!mu_authenticate_list)
-    mu_auth_begin_setup ();
-  return mu_auth_runlist (mu_authenticate_list, NULL, auth_data, (void*) pass);
-}
-
-
-/* ************************************************************************* */
-
-struct _module_handler {
-  struct auth_stack_entry authenticate;
-  struct auth_stack_entry auth_by_name;
-  struct auth_stack_entry auth_by_uid;
-};
-
-static mu_list_t module_handler_list;
-
-void
-mu_auth_register_module (struct mu_auth_module *mod)
-{
-  struct _module_handler *entry;
-  
-  if (mod->init)
-    mu_gocs_register (mod->name, mod->init);
-  
-  if (!module_handler_list && mu_list_create (&module_handler_list))
-    abort ();
-
-  entry = malloc (sizeof (*entry));
-  if (!entry)
-    {
-      mu_error ("not enough memory");
-      exit (1);
-    }
-  entry->authenticate.name = mod->name;
-  entry->authenticate.fun  = mod->authenticate;
-  entry->authenticate.func_data = mod->authenticate_data;
-  entry->auth_by_name.name = mod->name;
-  entry->auth_by_name.fun = mod->auth_by_name;
-  entry->auth_by_name.func_data = mod->auth_by_name_data;
-  entry->auth_by_uid.name = mod->name;
-  entry->auth_by_uid.fun = mod->auth_by_uid;
-  entry->auth_by_uid.func_data = mod->auth_by_uid_data;
-    
-  mu_list_append (module_handler_list, entry);
-  
-}
-
-static struct _module_handler *
-_locate (const char *name)
-{
-  struct _module_handler *rp = NULL;
-  mu_iterator_t itr;
-
-  if (mu_list_get_iterator (module_handler_list, &itr) == 0)
-    {
-      struct _module_handler *p;
-      
-      for (mu_iterator_first (itr); !rp && !mu_iterator_is_done (itr);
-           mu_iterator_next (itr))
-        {
-          mu_iterator_current (itr, (void **)&p);
-          if (strcmp (p->authenticate.name, name) == 0)
-            rp = p;
-        }
-
-      mu_iterator_destroy (&itr);
-    }
-  return rp;
-}
-
-static void
-_add_module_list (const char *modlist, int (*fun)(const char *name))
-{
-  int argc;
-  char **argv;
-  int rc, i;
-  
-  rc = mu_argcv_get (modlist, ":", NULL, &argc, &argv);
-  if (rc)
-    {
-      mu_error (_("cannot split line `%s': %s"), modlist, mu_strerror (rc));
-      exit (1);
-    }
-
-  for (i = 0; i < argc; i += 2)
-    {
-      if (fun (argv[i]))
-        {
-          /* Historically,auth functions used ENOENT. We support this
-             return value for backward compatibility. */
-          if (errno == ENOENT || errno == MU_ERR_NOENT)
-            mu_error (_("no such module: %s"), argv[i]);
-          else
-            mu_error (_("failed to add module %s: %s"),
-                      argv[i], strerror (errno));
-          exit (1);
-        }
-    }
-  mu_argcv_free (argc, argv);
-}
-
-
-int
-mu_authorization_add_module (const char *name)
-{
-  struct _module_handler *mod = _locate (name);
-  
-  if (!mod)
-    {
-      errno = MU_ERR_NOENT;
-      return 1;
-    }
-  mu_insert_stack_entry (&_tmp_auth_by_name_list, &mod->auth_by_name);
-  mu_insert_stack_entry (&_tmp_auth_by_uid_list, &mod->auth_by_uid);
-  return 0;
-}
-
-void
-mu_authorization_add_module_list (const char *modlist)
-{
-  _add_module_list (modlist, mu_authorization_add_module);
-}
-
-void
-mu_authorization_clear_list ()
-{
-  mu_list_destroy (&_tmp_auth_by_name_list);
-  mu_list_destroy (&_tmp_auth_by_uid_list);
-}
-
-
-int
-mu_authentication_add_module (const char *name)
-{
-  struct _module_handler *mod = _locate (name);
-
-  if (!mod)
-    {
-      errno = MU_ERR_NOENT;
-      return 1;
-    }
-  mu_insert_stack_entry (&_tmp_authenticate_list, &mod->authenticate);
-  return 0;
-}
-
-void
-mu_authentication_add_module_list (const char *modlist)
-{
-  _add_module_list (modlist, mu_authentication_add_module);
-}
-
-void
-mu_authentication_clear_list ()
-{
-  mu_list_destroy (&_tmp_authenticate_list);
-}
-
-
-/* ************************************************************************ */
-
-/* Setup functions. Note that:
-   1) If libmuath is not linked in, then "generic" and "system" modules
-      are used unconditionally. This provides compatibility with the
-      standard getpw.* functions.
-   2) --authentication and --authorization modify only temporary lists,
-      which get flushed to the main ones when mu_auth_finish_setup() is
-      run. Thus, the default "generic:system" remain in force until
-      argp_parse() exits. */
-   
-void
-mu_auth_begin_setup ()
-{
-  mu_iterator_t itr;
-
-  if (!module_handler_list)
-    {
-      mu_auth_register_module (&mu_auth_generic_module); 
-      mu_auth_register_module (&mu_auth_system_module);
-    }
-  
-  if (!mu_authenticate_list)
-    {
-      if (mu_list_get_iterator (module_handler_list, &itr) == 0)
-        {
-          struct _module_handler *mod;
-          
-          for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
-               mu_iterator_next (itr))
-            {
-              mu_iterator_current (itr, (void **)&mod);
-              mu_insert_stack_entry (&mu_authenticate_list,
-                                     &mod->authenticate);
-            }
-          mu_iterator_destroy (&itr);
-        }
-    }
-
-  if (!mu_auth_by_name_list)
-    {
-      if (mu_list_get_iterator (module_handler_list, &itr) == 0)
-        {
-          struct _module_handler *mod;
-          
-          for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
-               mu_iterator_next (itr))
-            {
-              mu_iterator_current (itr, (void **)&mod);
-              mu_insert_stack_entry (&mu_auth_by_name_list, 
&mod->auth_by_name);
-              mu_insert_stack_entry (&mu_auth_by_uid_list, &mod->auth_by_uid);
-            }
-          mu_iterator_destroy (&itr);
-        }
-    }
-}
-
-void
-mu_auth_finish_setup ()
-{
-  mu_list_destroy (&mu_authenticate_list);
-  mu_list_destroy (&mu_auth_by_name_list);
-  mu_list_destroy (&mu_auth_by_uid_list);
-  
-  mu_authenticate_list = _tmp_authenticate_list;
-  _tmp_authenticate_list = NULL;
-  mu_auth_by_name_list = _tmp_auth_by_name_list;
-  _tmp_auth_by_name_list = NULL;
-  mu_auth_by_uid_list = _tmp_auth_by_uid_list;
-  _tmp_auth_by_uid_list = NULL;
-  
-  mu_auth_begin_setup ();
-}
-
-
diff --git a/libmailutils/muerrno.cin b/libmailutils/muerrno.cin
deleted file mode 100644
index f00fb94..0000000
--- a/libmailutils/muerrno.cin
+++ /dev/null
@@ -1,65 +0,0 @@
-/* -*- c -*- $AUTOWARN
-   GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 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, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  
USA  */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-
-#include <mailutils/errno.h>
-#include <mailutils/nls.h>
-
-#ifndef EOK
-# define EOK 0
-#endif
-
-const char*
-mu_errname (int e)
-{
-  static char buf[128];
-  
-  switch (e)
-    {
-    case EOK:
-      return "EOK";
-
-      $MESSAGE_CODES
-    }
-
-  snprintf (buf, sizeof buf, _("Error %d"), e);
-  return buf;
-}
-
-const char *
-mu_strerror (int e)
-{
-  switch (e)
-    {
-    case EOK:
-      return _("Success");
-
-    $MESSAGE_STRINGS
-    }
-
-  return strerror (e);
-}
-
diff --git a/libmailutils/muerror.c b/libmailutils/muerror.c
deleted file mode 100644
index e18f0fe..0000000
--- a/libmailutils/muerror.c
+++ /dev/null
@@ -1,117 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2005, 2007, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <syslog.h>
-#include <string.h>
-#include <mailutils/error.h>
-
-
-/* Historic shortcuts for mu_diag_ functions */
-
-int
-mu_verror (const char *fmt, va_list ap)
-{
-  mu_diag_voutput (MU_DIAG_ERROR, fmt, ap);
-  return 0;
-}
-
-int
-mu_error (const char *fmt, ...)
-{
-  va_list ap;
-  va_start (ap, fmt);
-  mu_verror (fmt, ap);
-  va_end (ap);
-  return 0;
-}
-
-
-/* Compatibility layer */
-int
-mu_default_error_printer (const char *fmt, va_list ap)
-{
-  if (mu_program_name)
-    fprintf (stderr, "%s: ", mu_program_name);
-  vfprintf (stderr, fmt, ap);
-  fputc ('\n', stderr);
-  return 0;
-}
-
-int
-mu_syslog_error_printer (const char *fmt, va_list ap)
-{
-#ifdef HAVE_VSYSLOG
-  vsyslog (LOG_CRIT, fmt, ap);
-#else
-  char buf[128];
-  vsnprintf (buf, sizeof buf, fmt, ap);
-  syslog (LOG_CRIT, "%s", buf);
-#endif
-  return 0;
-}
-
-static void
-compat_error_printer0 (mu_error_pfn_t pfn, const char *fmt, ...)
-{
-  va_list ap;
-  va_start (ap, fmt);
-  pfn (fmt, ap);
-  va_end (ap);
-}
-
-static int
-compat_error_printer (void *data, mu_log_level_t level, const char *buf)
-{
-  if (!data)
-    mu_diag_stderr_printer (NULL, level, buf);
-  else
-    {
-      int len = strlen (buf);
-      if (len > 0 && buf[len-1] == '\n')
-       len--;
-      compat_error_printer0 (data, "%-.*s", len, buf);
-    }
-  return 0;
-}
-
-void
-mu_error_set_print (mu_error_pfn_t pfn)
-{
-  mu_debug_t debug;
-  mu_diag_get_debug (&debug);
-  mu_debug_set_print (debug, compat_error_printer, NULL);
-  mu_debug_set_data (debug, pfn, NULL, NULL);
-#if 0
- {
-   static int warned;
-   if (!warned)
-     {
-       warned = 1;
-       mu_diag_output ("this program uses mu_error_set_print, which is 
deprecated");
-     }
-#endif
-}
-
-
diff --git a/libmailutils/munre.c b/libmailutils/munre.c
deleted file mode 100644
index ca66cad..0000000
--- a/libmailutils/munre.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2006, 2007, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#if HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <errno.h>
-#include <stdlib.h>
-
-#include <mailutils/error.h>
-#include <mailutils/errno.h>
-
-#include <regex.h>
-
-static regex_t *re_prefix;
-
-int
-mu_unre_set_regex (const char *str, int caseflag, char **errp)
-{
-  int rc;
-  int flags = REG_EXTENDED;
-
-  if (errp)
-    *errp = NULL;
-
-  if (!str)
-    str = "^re: *";
-  if (re_prefix)
-    regfree (re_prefix);
-  else
-    {
-      re_prefix = malloc (sizeof (*re_prefix));
-      if (!re_prefix)
-       return ENOMEM;
-    }
-  if (!caseflag)
-    flags |= REG_ICASE;
-  rc = regcomp (re_prefix, str, flags);
-  if (rc)
-    {
-      if (errp)
-       {
-         size_t s = regerror (rc, re_prefix, NULL, 0);
-         s++;
-         *errp = malloc (s);
-         if (*errp)
-           regerror (rc, re_prefix, *errp, s);
-       }
-      regfree (re_prefix);
-      free (re_prefix);
-      return MU_ERR_FAILURE;
-    }
-  return 0;
-}
-
-int
-mu_unre_subject (const char *subject, const char **new_subject)
-{
-  int rc;
-  regmatch_t rm;
-
-  if (!subject)
-    return EINVAL;
-  
-  if (!re_prefix)
-    {
-      rc = mu_unre_set_regex (NULL, 0, NULL);
-      if (rc)
-       return rc;
-    }
-
-  rc = regexec (re_prefix, subject, 1, &rm, 0);
-  if (rc == 0 && rm.rm_eo != -1 && new_subject)
-    *new_subject = subject + rm.rm_eo;
-  return rc;
-}
diff --git a/libmailutils/mutil.c b/libmailutils/mutil.c
deleted file mode 100644
index 2b091ce..0000000
--- a/libmailutils/mutil.c
+++ /dev/null
@@ -1,1536 +0,0 @@
-/* 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#if HAVE_CONFIG_H
-# 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 <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/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)
-{
-  if (*p == '|')
-    return 1;
-  for (; *p && *p != '/'; p++)
-    if (*p == ':')
-      return 1;
-  return 0;
-}
-
-int
-mu_mh_delim (const char *str)
-{
-  if (str[0] == '-')
-    {
-      for (; *str == '-'; str++)
-       ;
-      for (; *str == ' ' || *str == '\t'; 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);
-  mu_restore_locale ();
-  return size;
-}
-  
-
-static void
-assoc_str_free (void *data)
-{
-  free (data);
-}
-
-int
-mutil_parse_field_map (const char *map, mu_assoc_t *passoc_tab, int *perr)
-{
-  int rc;
-  int i;
-  int argc;
-  char **argv;
-  mu_assoc_t assoc_tab = NULL;
-
-  rc = mu_argcv_get (map, ":", NULL, &argc, &argv);
-  if (rc)
-    {
-      mu_error (_("cannot split line `%s': %s"), map, mu_strerror (rc));
-      return rc;
-    }
-
-  for (i = 0; i < argc; i += 2)
-    {
-      char *tok = argv[i];
-      char *p = strchr (tok, '=');
-      char *pptr;
-      
-      if (!p)
-       {
-         rc = EINVAL;
-         break;
-       }
-      if (!assoc_tab)
-       {
-         rc = mu_assoc_create (&assoc_tab, sizeof(char*), 0);
-         if (rc)
-           break;
-         mu_assoc_set_free (assoc_tab, assoc_str_free);
-         *passoc_tab = assoc_tab;
-       }
-      *p++ = 0;
-      pptr = strdup (p);
-      if (!pptr)
-       {
-         rc = errno;
-         break;
-       }
-      rc = mu_assoc_install (assoc_tab, tok, &pptr);
-      if (rc)
-       {
-         free (p);
-         break;
-       }
-    }
-
-  mu_argcv_free (argc, argv);
-  if (rc && perr)
-    *perr = i;
-  return rc;
-}
-
-/* FIXME: should it be here? */
-int
-mu_sql_decode_password_type (const char *arg, enum mu_password_type *t)
-{
-  if (strcmp (arg, "plain") == 0)
-    *t = password_plaintext;
-  else if (strcmp (arg, "hash") == 0)
-    *t = password_hash;
-  else if (strcmp (arg, "scrambled") == 0)
-    *t = password_scrambled;
-  else
-    return 1;
-  return 0;
-}
-
-int
-mu_stream_flags_to_mode (int flags, int isdir)
-{
-  int mode = 0;
-  if (flags & MU_STREAM_IRGRP)
-    mode |= S_IRGRP;
-  if (flags & MU_STREAM_IWGRP)
-    mode |= S_IWGRP;
-  if (flags & MU_STREAM_IROTH)
-    mode |= S_IROTH;
-  if (flags & MU_STREAM_IWOTH)
-    mode |= S_IWOTH;
-
-  if (isdir)
-    {
-      if (mode & (S_IRGRP|S_IWGRP))
-       mode |= S_IXGRP;
-      if (mode & (S_IROTH|S_IWOTH))
-       mode |= S_IXOTH;
-    }
-  
-  return mode;
-}
diff --git a/libmailutils/nls.c b/libmailutils/nls.c
deleted file mode 100644
index 4b9a8fe..0000000
--- a/libmailutils/nls.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2002, 2006, 2007, 2008, 2010 Free Software Foundation,
-   Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library; if not, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#if HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <mailutils/nls.h>
-#include <locale.h>
-
-/* Initialize Native Language Support */
-
-char *mu_locale_set;
-
-#ifndef HAVE_SETLOCALE
-# define setlocale(c,s) NULL
-#endif
-
-/* Set locale via LC_ALL.  */
-char *
-mu_set_locale (const char *locale)
-{
-#if defined HAVE_SETLOCALE
-  return setlocale (LC_ALL, locale);
-#else
-  return NULL;
-#endif
-}
-
-void
-mu_restore_locale (void)
-{
-  if (mu_locale_set)
-    mu_set_locale (mu_locale_set);
-}
-
-void
-mu_init_nls (void)
-{
-#ifdef ENABLE_NLS
-  mu_locale_set = mu_set_locale ("");
-  bindtextdomain (PACKAGE, LOCALEDIR);
-#endif /* ENABLE_NLS */
-}
-
diff --git a/libmailutils/observer.c b/libmailutils/observer.c
deleted file mode 100644
index 51b0260..0000000
--- a/libmailutils/observer.c
+++ /dev/null
@@ -1,239 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2004, 2005, 2007, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <errno.h>
-#include <stdlib.h>
-
-#include <mailutils/list.h>
-#include <mailutils/iterator.h>
-#include <mailutils/errno.h>
-#include <mailutils/sys/observer.h>
-
-int
-mu_observer_create (mu_observer_t *pobserver, void *owner)
-{
-  mu_observer_t observer;
-  observer = calloc (sizeof (*observer), 1);
-  if (observer == NULL)
-    return ENOMEM;
-  observer->owner = owner;
-  *pobserver = observer;
-  return 0;
-}
-
-void
-mu_observer_destroy (mu_observer_t *pobserver, void *owner)
-{
-  if (pobserver && *pobserver)
-    {
-      mu_observer_t observer = *pobserver;
-      if (observer->owner == owner || observer->flags & MU_OBSERVER_NO_CHECK)
-       {
-         if (observer->_destroy)
-           observer->_destroy (observer, observer->_action_data);
-         free (observer);
-       }
-      *pobserver = NULL;
-    }
-}
-
-void *
-mu_observer_get_owner (mu_observer_t observer)
-{
-  return (observer) ? observer->owner : NULL;
-}
-
-int
-mu_observer_action (mu_observer_t observer, size_t type, void *data)
-{
-  if (observer == NULL)
-    return EINVAL;
-  if (observer->_action)
-    return observer->_action (observer, type, data, observer->_action_data);
-  return 0;
-}
-
-int
-mu_observer_set_action (mu_observer_t observer,
-                       int (*_action) (mu_observer_t, size_t, void *, void *),
-                       void *owner)
-{
-  if (observer == NULL)
-    return EINVAL;
-  if (observer->owner != owner)
-    return EACCES;
-  observer->_action = _action;
-  return 0;
-}
-
-int
-mu_observer_set_action_data  (mu_observer_t observer, void *data, void *owner)
-{
-  if (observer == NULL)
-    return EINVAL;
-  if (observer->owner != owner)
-    return EACCES;
-  observer->_action_data = data;
-  return 0;
-}
-
-int
-mu_observer_set_destroy (mu_observer_t observer,
-                        int (*_destroy) (mu_observer_t, void *),
-                        void *owner)
-{
-  if (observer == NULL)
-    return EINVAL;
-  if (observer->owner != owner)
-    return EACCES;
-  observer->_destroy = _destroy;
-  return 0;
-}
-
-int
-mu_observer_set_flags (mu_observer_t observer, int flags)
-{
-  if (observer == NULL)
-    return EINVAL;
-  observer->flags |= flags;
-  return 0;
-}
-
-static void
-_free_event (void *ptr)
-{
-  event_t event = ptr;
-  mu_observer_destroy (&event->observer, NULL);
-  free (event);
-}
-
-int
-mu_observable_create (mu_observable_t *pobservable, void *owner)
-{
-  mu_observable_t observable;
-  int status;
-  if (pobservable == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  observable = calloc (sizeof (*observable), 1);
-  if (observable == NULL)
-    return ENOMEM;
-  status = mu_list_create (&observable->list);
-  if (status != 0 )
-    {
-      free (observable);
-      return status;
-    }
-  mu_list_set_destroy_item (observable->list, _free_event);
-  observable->owner = owner;
-  *pobservable = observable;
-  return 0;
-}
-
-void
-mu_observable_destroy (mu_observable_t *pobservable, void *owner)
-{
-  if (pobservable && *pobservable)
-    {
-      mu_observable_t observable = *pobservable;
-      if (observable->owner == owner)
-       {
-         mu_list_destroy (&observable->list);
-         free (observable);
-       }
-      *pobservable = NULL;
-    }
-}
-
-void *
-mu_observable_get_owner (mu_observable_t observable)
-{
-  return (observable) ? observable->owner : NULL;
-}
-
-int
-mu_observable_attach (mu_observable_t observable, size_t type,  mu_observer_t 
observer)
-{
-  event_t event;
-  if (observable == NULL || observer == NULL)
-    return EINVAL;
-  event = calloc (1, sizeof (*event));
-  if (event == NULL)
-    return ENOMEM;
-  event->type = type;
-  event->observer = observer;
-  return mu_list_append (observable->list, event);
-}
-
-int
-mu_observable_detach (mu_observable_t observable, mu_observer_t observer)
-{
-  mu_iterator_t iterator;
-  int status;
-  event_t event = NULL;
-
-  if (observable == NULL || observer == NULL)
-    return EINVAL;
-  status = mu_list_get_iterator (observable->list, &iterator);
-  if (status != 0)
-    return status;
-  status = MU_ERR_NOENT;
-  for (mu_iterator_first (iterator); !mu_iterator_is_done (iterator);
-       mu_iterator_next (iterator))
-    {
-      event = NULL;
-      mu_iterator_current (iterator, (void **)&event);
-      if (event && event->observer == observer)
-        {
-          mu_iterator_ctl (iterator, mu_itrctl_delete, NULL);
-         status = 0;
-          break;
-        }
-    }
-  mu_iterator_destroy (&iterator);
-  return status;
-}
-
-int
-mu_observable_notify (mu_observable_t observable, int type, void *data)
-{
-  mu_iterator_t iterator;
-  event_t event = NULL;
-  int status = 0;
-  if (observable == NULL)
-    return EINVAL;
-  status = mu_list_get_iterator (observable->list, &iterator);
-  if (status != 0)
-    return status;
-  for (mu_iterator_first (iterator); !mu_iterator_is_done (iterator);
-       mu_iterator_next (iterator))
-    {
-      event = NULL;
-      mu_iterator_current (iterator, (void **)&event);
-      if (event && event->type & type)
-        {
-         status |= mu_observer_action (event->observer, type, data);
-        }
-    }
-  mu_iterator_destroy (&iterator);
-  return status;
-}
diff --git a/libmailutils/opool.c b/libmailutils/opool.c
deleted file mode 100644
index 991b527..0000000
--- a/libmailutils/opool.c
+++ /dev/null
@@ -1,446 +0,0 @@
-/* String-list functions for GNU Mailutils.
-   Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
-
-   Based on slist module from GNU Radius.  Written by Sergey Poznyakoff.
-   
-   GNU Mailutils is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 3, or (at
-   your option) any later version.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <mailutils/types.h>
-#include <mailutils/alloc.h>
-#include <mailutils/opool.h>
-#include <mailutils/errno.h>
-#include <mailutils/error.h>
-#include <mailutils/nls.h>
-#include <mailutils/iterator.h>
-
-struct mu_opool_bucket
-{
-  struct mu_opool_bucket *next;
-  char *buf;
-  size_t level;
-  size_t size;
-};
-
-struct _mu_opool
-{
-  int memerr;
-  size_t bucket_size;
-  size_t itr_count;
-  struct mu_opool_bucket *head, *tail;
-  struct mu_opool_bucket *free;
-};
-
-static struct mu_opool_bucket *
-alloc_bucket (struct _mu_opool *opool, size_t size)
-{
-  struct mu_opool_bucket *p = malloc (sizeof (*p) + size);
-  if (!p)
-    {
-      if (opool->memerr)
-       mu_alloc_die ();
-    }
-  else
-    {
-      p->buf = (char*)(p + 1);
-      p->level = 0;
-      p->size = size;
-      p->next = NULL;
-    }
-  return p;
-}
-
-static int
-alloc_pool (mu_opool_t opool, size_t size)
-{
-  struct mu_opool_bucket *p = alloc_bucket (opool, opool->bucket_size);
-  if (!p)
-    return ENOMEM;
-  if (opool->tail)
-    opool->tail->next = p;
-  else
-    opool->head = p;
-  opool->tail = p;
-  return 0;
-}
-
-static int
-copy_chars (mu_opool_t opool, const char *str, size_t n, size_t *psize)
-{
-  size_t rest;
-
-  if (!opool->head || opool->tail->level == opool->tail->size)
-    if (alloc_pool (opool, opool->bucket_size))
-      return ENOMEM;
-  rest = opool->tail->size - opool->tail->level;
-  if (n > rest)
-    n = rest;
-  memcpy (opool->tail->buf + opool->tail->level, str, n);
-  opool->tail->level += n;
-  *psize = n;
-  return 0;
-}
-
-int
-mu_opool_create (mu_opool_t *pret, int memerr)
-{
-  struct _mu_opool *x = malloc (sizeof (x[0]));
-  if (!x)
-    {
-      if (memerr)
-       mu_alloc_die ();
-      return ENOMEM;
-    }
-  x->memerr = memerr;
-  x->bucket_size = MU_OPOOL_BUCKET_SIZE;
-  x->itr_count = 0;
-  x->head = x->tail = x->free = 0;
-  *pret = x;
-  return 0;
-}
-
-int
-mu_opool_set_bucket_size (mu_opool_t opool, size_t size)
-{
-  if (!opool)
-    return EINVAL;
-  opool->bucket_size = size;
-  return 0;
-}
-
-int
-mu_opool_get_bucket_size (mu_opool_t opool, size_t *psize)
-{
-  if (!opool || !psize)
-    return EINVAL;
-  *psize = opool->bucket_size;
-  return 0;
-}
-
-void
-mu_opool_clear (mu_opool_t opool)
-{
-  if (!opool)
-    return;
-  
-  if (opool->tail)
-    {
-      opool->tail->next = opool->free;
-      opool->free = opool->head;
-      opool->head = opool->tail = NULL;
-    }
-}      
-
-void
-mu_opool_destroy (mu_opool_t *popool)
-{
-  struct mu_opool_bucket *p;
-  if (popool && *popool)
-    {
-      mu_opool_t opool = *popool;
-      mu_opool_clear (opool);
-      for (p = opool->free; p; )
-       {
-         struct mu_opool_bucket *next = p->next;
-         free (p);
-         p = next;
-       }
-      free (opool);
-    }
-  *popool = NULL;
-}
-
-int
-mu_opool_append (mu_opool_t opool, const void *str, size_t n)
-{
-  const char *ptr = str;
-  while (n)
-    {
-      size_t s;
-      if (copy_chars (opool, ptr, n, &s))
-       return ENOMEM;
-      ptr += s;
-      n -= s;
-    }
-  return 0;
-}
-
-int
-mu_opool_append_char (mu_opool_t opool, char c)
-{
-  return mu_opool_append (opool, &c, 1);
-}      
-
-int
-mu_opool_appendz (mu_opool_t opool, const char *str)
-{
-  return mu_opool_append (opool, str, strlen (str))
-         || mu_opool_append_char (opool, 0);
-}
-
-size_t
-mu_opool_size (mu_opool_t opool)
-{
-  size_t size = 0;
-  struct mu_opool_bucket *p;
-  for (p = opool->head; p; p = p->next)
-    size += p->level;
-  return size;
-}
-
-size_t
-mu_opool_copy (mu_opool_t opool, void *buf, size_t size)
-{
-  char *cp = buf;
-  size_t total = 0;
-  struct mu_opool_bucket *p;
-  
-  for (p = opool->head; p && total < size; p = p->next)
-    {
-      size_t cpsize = size - total;
-      if (cpsize > p->level)
-       cpsize = p->level;
-      memcpy (cp, p->buf, cpsize);
-      cp += cpsize;
-      total += cpsize;
-    }
-  return total;
-}
-
-int
-mu_opool_coalesce (mu_opool_t opool, size_t *psize)
-{
-  size_t size;
-
-  if (opool->itr_count)
-    return MU_ERR_FAILURE;
-  if (opool->head && opool->head->next == NULL)
-    size = opool->head->level;
-  else {
-    struct mu_opool_bucket *bucket;
-    struct mu_opool_bucket *p;
-
-    size = mu_opool_size (opool);
-       
-    bucket = alloc_bucket (opool, size);
-    if (!bucket)
-      return ENOMEM;
-    for (p = opool->head; p; )
-      {
-       struct mu_opool_bucket *next = p->next;
-       memcpy (bucket->buf + bucket->level, p->buf, p->level);
-       bucket->level += p->level;
-       free (p);
-       p = next;
-      }
-    opool->head = opool->tail = bucket;
-  }
-  if (psize)
-    *psize = size;
-  return 0;
-}
-
-void *
-mu_opool_head (mu_opool_t opool, size_t *psize)
-{
-  if (*psize) 
-    *psize = opool->head ? opool->head->level : 0;
-  return opool->head ? opool->head->buf : NULL;
-}
-
-void *
-mu_opool_finish (mu_opool_t opool, size_t *psize)
-{
-  if (mu_opool_coalesce (opool, psize))
-    return NULL;
-  mu_opool_clear (opool);
-  return opool->free->buf;
-}
-
-int
-mu_opool_union (mu_opool_t *pdst, mu_opool_t *psrc)
-{
-  mu_opool_t src, dst;
-  
-  if (!psrc)
-    return EINVAL;
-  if (!*psrc)
-    return 0;
-  src = *psrc;
-  
-  if (!pdst)
-    return EINVAL;
-  if (!*pdst)
-    {
-      *pdst = src;
-      *psrc = NULL;
-      return 0;
-    }
-  else
-    dst = *pdst;
-
-  if (dst->tail)
-    dst->tail->next = src->head;
-  else
-    dst->head = src->head;
-  dst->tail = src->tail;
-
-  if (src->free)
-    {
-      struct mu_opool_bucket *p;
-
-      for (p = src->free; p->next; p = p->next)
-       ;
-      p->next = dst->free;
-      dst->free = src->free;
-    }
-
-  free (src);
-  *psrc = NULL;
-  return 0;
-}
-
-
-/* Iterator support */
-struct opool_iterator
-{
-  mu_opool_t opool;
-  struct mu_opool_bucket *cur;
-};
-
-static int
-opitr_first (void *owner)
-{
-  struct opool_iterator *itr = owner;
-  itr->cur = itr->opool->head;
-  return 0;
-}
-
-static int
-opitr_next (void *owner)
-{
-  struct opool_iterator *itr = owner;
-  if (itr->cur)
-    {
-      itr->cur = itr->cur->next;
-      return 0;
-    }
-  return EINVAL;
-}
-
-static int
-opitr_getitem (void *owner, void **pret, const void **pkey)
-{
-  struct opool_iterator *itr = owner;
-  if (!itr->cur)
-    return MU_ERR_NOENT;
-
-  *pret = itr->cur->buf;
-  if (pkey)
-    *(size_t*) pkey = itr->cur->level;
-  return 0;
-}
-
-static int
-opitr_finished_p (void *owner)
-{
-  struct opool_iterator *itr = owner;
-  return itr->cur == NULL;
-}
-
-static int
-opitr_curitem_p (void *owner, void *item)
-{
-  struct opool_iterator *itr = owner;
-  return itr->cur && itr->cur->buf == item;
-}
-
-static int
-opitr_destroy (mu_iterator_t iterator, void *data)
-{
-  struct opool_iterator *itr = data;
-  if (itr->opool->itr_count == 0)
-    {
-      /* oops! */
-      mu_error (_("%s: INTERNAL ERROR: zero reference count"),
-               "opool_destroy");
-    }
-  else
-    itr->opool->itr_count--;
-  free (data);
-  return 0;
-}
-
-static int
-opitr_data_dup (void **ptr, void *owner)
-{
-  struct opool_iterator *itr = owner;
-
-  *ptr = malloc (sizeof (struct opool_iterator));
-  if (*ptr == NULL)
-    return ENOMEM;
-  memcpy (*ptr, owner, sizeof (struct opool_iterator));
-  itr->opool->itr_count++;
-  return 0;
-}
-
-int
-mu_opool_get_iterator (mu_opool_t opool, mu_iterator_t *piterator)
-{
-  mu_iterator_t iterator;
-  int status;
-  struct opool_iterator *itr;
-
-  if (!opool)
-    return EINVAL;
-
-  itr = calloc (1, sizeof *itr);
-  if (!itr)
-    return ENOMEM;
-  itr->opool = opool;
-  itr->cur = opool->head;
-  
-  status = mu_iterator_create (&iterator, itr);
-  if (status)
-    {
-      free (itr);
-      return status;
-    }
-
-  mu_iterator_set_first (iterator, opitr_first);
-  mu_iterator_set_next (iterator, opitr_next);
-  mu_iterator_set_getitem (iterator, opitr_getitem);
-  mu_iterator_set_finished_p (iterator, opitr_finished_p);
-  mu_iterator_set_curitem_p (iterator, opitr_curitem_p);
-  mu_iterator_set_destroy (iterator, opitr_destroy);
-  mu_iterator_set_dup (iterator, opitr_data_dup);
-
-  opool->itr_count++;
-
-  *piterator = iterator;
-  return 0;
-}
-
-
-
-
-  
-  
- 
diff --git a/libmailutils/parse822.c b/libmailutils/parse822.c
deleted file mode 100644
index b4d66bc..0000000
--- a/libmailutils/parse822.c
+++ /dev/null
@@ -1,2040 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2005, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-/*
-
-FIXME: what is the status of this TODO list?
-
-Things to consider:
-
-  - When parsing phrase, should I ignore non-ascii, or replace with a
-    '?' character? Right now parsing fails.
-
-    --> Should ignore non-ascii, it is unicode or iso8892-1.
-
-  - Are comments allowed in domain-literals?
-
-  - Need a way to mark the *end* of a group. Maybe add a field to _mu_address,
-    int group_end;, so if you care, you can search for the end of
-    a group with address_is_group_end();
-
-    --> Groups no longer show up in the mu_address_t list.
-
-  - Need a way to parse ",,,", it's a valid address-list, it just doesn't
-    have any addresses.
-
-  - The personal for ""Sam"" <address@hidden> is "Sam", and for 
"'address@hidden'" <address@hidden>
-    is 'address@hidden', should I strip those outside parentheses, or is that
-    too intrusive? Maybe an apps business if it wants to?
-
-  - Should we do best effort parsing, so parsing "address@hidden, foo@"
-    gets one address, or just say it is or it isn't in RFC format?
-    Right now we're strict, we'll see how it goes.
-
-  - parse Received: field?
-
-  - test for memory leaks on malloc failure
-
-  - fix the realloc, try a struct _string { char* b, size_t sz };
-
-The lexer finds consecutive sequences of characters, so it should
-define:
-
-struct parse822_token_t {
-    const char* b;  // beginning of token
-    const char* e;  // one past end of token
-}
-typedef struct parse822_token_t TOK;
-
-Then I can have str_append_token(), and the lexer functions can
-look like:
-
-int mu_parse822_atom(const char** p, const char* e, TOK* atom);
-
-Just a quick thought, I'll have to see how many functions that will
-actually help.
-
-  - get example addresses from rfc2822, and from the perl code.
-*/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <assert.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <time.h>
-
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
-#endif
-
-#include <mailutils/cctype.h>
-#include <mailutils/cstr.h>
-#include <mailutils/errno.h>
-#include <mailutils/parse822.h>
-#include <mailutils/address.h>
-
-#ifdef EOK
-# undef EOK
-#endif
-
-#define EOK    0
-#define EPARSE MU_ERR_BAD_822_FORMAT
-
-/*
- * Some convenience functions for dealing with dynamically re-sized
- * strings.
- */
-
-static int
-str_append_n (char **to, const char *from, size_t n)
-{
-  size_t l = 0;
-
-  /* if not to, then silently discard data */
-  if (!to)
-    {
-      return EOK;
-    }
-
-  if (*to)
-    {
-      char *bigger;
-
-      l = strlen (*to);
-
-      bigger = realloc (*to, l + n + 1);
-
-      if (!bigger)
-       {
-         return ENOMEM;
-       }
-
-      *to = bigger;
-    }
-  else
-    {
-      *to = malloc (n + 1);
-    }
-
-  strncpy (&to[0][l], from, n);
-
-  /* strncpy is lame, nul terminate our buffer */
-
-  to[0][l + n] = 0;
-
-  return EOK;
-}
-
-static int
-str_append (char **to, const char *from)
-{
-  if (!from)
-    return 0;
-  return str_append_n (to, from, strlen (from));
-}
-
-static int
-str_append_char (char **to, char c)
-{
-  return str_append_n (to, &c, 1);
-}
-
-static int
-str_append_range (char **to, const char *b, const char *e)
-{
-  return str_append_n (to, b, e - b);
-}
-
-static void
-str_free (char **s)
-{
-  if (s && *s)
-    {
-      free (*s);
-      *s = 0;
-    }
-}
-
-/*
- * Character Classification - could be rewritten in a C library
- * independent way, my system's C library matches the RFC
- * definitions. I don't know if that's guaranteed.
- *  
- * Note that all return values are:
- *   1 -> TRUE
- *   0 -> FALSE
- * This may be appear different than the 0 == success return
- * values of the other functions, but I was getting lost in
- * boolean arithmetic.
- */
-int
-mu_parse822_is_char (char c)
-{
-  return mu_isascii (c);
-}
-
-int
-mu_parse822_is_digit (char c)
-{
-  /* digit = <any ASCII decimal digit> */
-
-  return mu_isdigit ((unsigned) c);
-}
-
-int
-mu_parse822_is_ctl (char c)
-{
-  return mu_iscntrl ((unsigned) c) || c == 127 /* DEL */ ;
-}
-
-int
-mu_parse822_is_space (char c)
-{
-  return c == ' ';
-}
-
-int
-mu_parse822_is_htab (char c)
-{
-  return c == '\t';
-}
-
-int
-mu_parse822_is_lwsp_char (char c)
-{
-  return mu_parse822_is_space (c) || mu_parse822_is_htab (c);
-}
-
-int
-mu_parse822_is_special (char c)
-{
-  return strchr ("()<>@,;:\\\".[]", c) ? 1 : 0;
-}
-
-int
-parse822_is_atom_char_ex (char c)
-{
-  return !mu_parse822_is_special (c)
-    && !mu_parse822_is_space (c)
-    && !mu_parse822_is_ctl (c);
-}
-
-int
-mu_parse822_is_atom_char (char c)
-{
-  return mu_parse822_is_char (c) && parse822_is_atom_char_ex (c);
-}
-
-int
-mu_parse822_is_q_text (char c)
-{
-  return
-    mu_parse822_is_char (c) &&
-    c != '"' &&
-    c != '\\' &&
-    c != '\r';
-}
-
-int
-mu_parse822_is_d_text (char c)
-{
-  return
-    mu_parse822_is_char (c) &&
-    c != '[' &&
-    c != ']' &&
-    c != '\\' &&
-    c != '\r';
-}
-/*
- * SMTP's version of qtext, called <q> in the RFC 821 syntax,
- * also excludes <LF>.
- */
-int
-mu_parse822_is_smtp_q (char c)
-{
-  return
-    mu_parse822_is_q_text (c) &&
-    c != '\n';
-}
-
-/***** From RFC 822, 3.3 Lexical Tokens *****/
-
-int
-mu_parse822_skip_nl (const char **p, const char *e)
-{
-  /* Here we consider a new-line (NL) to be either a bare LF, or
-   * a CRLF pair as required by the RFC.
-   */
-  const char *s = *p;
-
-  if ((&s[1] < e) && s[0] == '\r' && s[1] == '\n')
-    {
-      *p += 2;
-
-      return EOK;
-    }
-
-  if ((&s[0] < e) && s[0] == '\n')
-    {
-      *p += 1;
-
-      return EOK;
-    }
-
-  return EPARSE;
-}
-
-int
-mu_parse822_skip_lwsp_char (const char **p, const char *e)
-{
-  if (*p < e && mu_parse822_is_lwsp_char (**p))
-    {
-      *p += 1;
-      return EOK;
-    }
-  return EPARSE;
-}
-
-int
-mu_parse822_skip_lwsp (const char **p, const char *e)
-{
-  /*
-   * linear-white-space = 1*([[CR]LF] LWSP-char)
-   *
-   *   We interpret a bare LF as identical to the canonical CRLF
-   *   line ending, I don't know another way since on a Unix system
-   *   all CRLF will be translated to the local convention, a bare
-   *   LF, and thus we can not deal with bare NLs in the message.
-   */
-  int space = 0;
-
-  while (*p != e)
-    {
-      const char *save = *p;
-
-      if (mu_parse822_skip_lwsp_char (p, e) == EOK)
-       {
-         space = 1;
-         continue;
-       }
-      if (mu_parse822_skip_nl (p, e) == EOK)
-       {
-         if (mu_parse822_skip_lwsp_char (p, e) == EOK)
-           {
-             continue;
-           }
-         *p = save;
-         return EPARSE;
-       }
-      break;
-    }
-  return space ? EOK : EPARSE;
-}
-
-int
-mu_parse822_skip_comments (const char **p, const char *e)
-{
-  int status;
-
-  while ((status = mu_parse822_comment (p, e, 0)) == EOK)
-    ;
-
-  return EOK;
-}
-
-int
-mu_parse822_digits (const char **p, const char *e, int min, int max, int 
*digits)
-{
-  const char *save = *p;
-
-  int i = 0;
-
-  assert (digits);
-
-  *digits = 0;
-
-  while (*p < e && mu_parse822_is_digit (**p))
-    {
-      *digits = *digits * 10 + **p - '0';
-      *p += 1;
-      ++i;
-      if (max != 0 && i == max)
-       {
-         break;
-       }
-    }
-  if (i < min)
-    {
-      *p = save;
-      return EPARSE;
-    }
-
-  return EOK;
-}
-
-int
-mu_parse822_special (const char **p, const char *e, char c)
-{
-  mu_parse822_skip_lwsp (p, e);        /* not comments, they start with a 
special... */
-
-  if ((*p != e) && **p == c)
-    {
-      *p += 1;
-      return EOK;
-    }
-  return EPARSE;
-}
-
-int
-mu_parse822_comment (const char **p, const char *e, char **comment)
-{
-  /* comment = "(" *(ctext / quoted-pair / comment) ")"
-   * ctext = <any char except "(", ")", "\", & CR, including lwsp>
-   */
-  const char *save = *p;
-  int rc;
-
-  if ((rc = mu_parse822_special (p, e, '(')))
-    {
-      return rc;
-    }
-
-  while (*p != e)
-    {
-      char c = **p;
-
-      if (c == ')')
-       {
-         *p += 1;
-         return EOK;           /* found end-of-comment */
-       }
-      else if (c == '(')
-       {
-         rc = mu_parse822_comment (p, e, comment);
-       }
-      else if (c == '\\')
-       {
-         rc = mu_parse822_quoted_pair (p, e, comment);
-       }
-      else if (c == '\r')
-       {
-         /* invalid character... */
-         *p += 1;
-       }
-      else if (mu_parse822_is_char (c))
-       {
-         rc = str_append_char (comment, c);
-         *p += 1;
-       }
-      else
-       {
-         /* invalid character... */
-         *p += 1;
-       }
-      if (rc != EOK)
-       break;
-    }
-
-  if (*p == e)
-    {
-      rc = EPARSE;             /* end-of-comment not found */
-    }
-
-  *p = save;
-
-  assert (rc != EOK);
-
-  return rc;
-}
-
-int
-mu_parse822_atom (const char **p, const char *e, char **atom)
-{
-  /* atom = 1*<an atom char> */
-
-  const char *save = *p;
-  int rc = EPARSE;
-
-  mu_parse822_skip_comments (p, e);
-
-  save = *p;
-
-  while ((*p != e) && (**p == '.' || mu_parse822_is_atom_char (**p)))
-    {
-      rc = str_append_char (atom, **p);
-      *p += 1;
-      if (rc != EOK)
-       {
-         *p = save;
-         break;
-       }
-    }
-  return rc;
-}
-
-int
-parse822_atom_ex (const char **p, const char *e, char **atom)
-{
-  /* atom = 1*<an atom char> */
-  const char *ptr;
-  int rc;
-
-  mu_parse822_skip_comments (p, e);
-
-  for (ptr = *p; (ptr != e) && parse822_is_atom_char_ex (*ptr); ptr++)
-    ;
-  if (ptr - *p == 0)
-    return EPARSE;
-  rc = str_append_n (atom, *p, ptr - *p);
-  if (rc == 0)
-    *p = ptr;
-  return rc;
-}
-
-int
-mu_parse822_quoted_pair (const char **p, const char *e, char **qpair)
-{
-  /* quoted-pair = "\" char */
-
-  int rc;
-
-  /* need TWO characters to be available */
-  if ((e - *p) < 2)
-    return EPARSE;
-
-  if (**p != '\\')
-    return EPARSE;
-
-  if ((rc = str_append_char (qpair, *(*p + 1))))
-    return rc;
-
-  *p += 2;
-
-  return EOK;
-}
-
-int
-mu_parse822_quoted_string (const char **p, const char *e, char **qstr)
-{
-  /* quoted-string = <"> *(qtext/quoted-pair) <">
-   * qtext = char except <">, "\", & CR, including lwsp-char
-   */
-
-  const char *save = *p;
-  int rc;
-
-  mu_parse822_skip_comments (p, e);
-
-  save = *p;
-
-  if ((rc = mu_parse822_special (p, e, '"')))
-    return rc;
-
-  while (*p != e)
-    {
-      char c = **p;
-
-      if (c == '"')
-       {
-         *p += 1;
-         return EOK;           /* found end-of-qstr */
-       }
-      else if (c == '\\')
-       {
-         rc = mu_parse822_quoted_pair (p, e, qstr);
-       }
-      else if (c == '\r')
-       {
-         /* invalid character... */
-         *p += 1;
-       }
-      else if (mu_parse822_is_char (c))
-       {
-         rc = str_append_char (qstr, c);
-         *p += 1;
-       }
-      else
-       {
-         /* invalid character... */
-         *p += 1;
-       }
-      if (rc)
-       {
-         *p = save;
-         str_free (qstr);
-         return rc;
-       }
-    }
-  *p = save;
-  str_free (qstr);
-  return EPARSE;               /* end-of-qstr not found */
-}
-
-int
-mu_parse822_word (const char **p, const char *e, char **word)
-{
-  /* word = atom / quoted-string */
-
-  const char *save = *p;
-  int rc = EOK;
-
-  mu_parse822_skip_comments (p, e);
-
-  save = *p;
-
-  {
-    char *qstr = 0;
-    if ((rc = mu_parse822_quoted_string (p, e, &qstr)) == EOK && qstr)
-      {
-       rc = str_append (word, qstr);
-
-       str_free (&qstr);
-
-       if (rc != EOK)
-         *p = save;
-
-       return rc;
-      }
-    assert (qstr == NULL);
-  }
-
-  if (rc != EPARSE)
-    {
-      /* it's fatal */
-      return rc;
-    }
-
-  /* Necessary because the quoted string could have found
-   * a partial string (invalid syntax). Thus reset, the atom
-   * will fail to if the syntax is invalid.
-   * We use parse822_atom_ex to allow for non-rfc-compliant atoms:
-   *
-   * "Be liberal in what you accept, and conservative in what you send."
-   */
-
-  {
-    char *atom = 0;
-    if (parse822_atom_ex (p, e, &atom) == EOK)
-      {
-       rc = str_append (word, atom);
-
-       str_free (&atom);
-
-       if (rc != EOK)
-         *p = save;
-
-       return rc;
-      }
-    assert (atom == NULL);
-  }
-
-  return EPARSE;
-}
-
-/* Some mailers do not quote personal part even if it contains dot.
-   Try to be smart about it.
-*/
-       
-int
-parse822_word_dot (const char **p, const char *e, char **word)
-{
-  int rc = mu_parse822_word (p, e, word);
-  for (;rc == 0 && (*p != e) && **p == '.'; ++*p)
-    rc = str_append (word, ".");
-  return rc;
-}
-
-int
-mu_parse822_phrase (const char **p, const char *e, char **phrase)
-{
-  /* phrase = 1*word */
-
-  const char *save = *p;
-  int rc;
-
-  if ((rc = parse822_word_dot (p, e, phrase)))
-    return rc;
-
-  /* ok, got the 1 word, now append all the others we can */
-  {
-    char *word = 0;
-
-    while ((rc = parse822_word_dot (p, e, &word)) == EOK)
-      {
-       rc = str_append_char (phrase, ' ');
-
-       if (rc == EOK)
-         rc = str_append (phrase, word);
-
-       str_free (&word);
-
-       if (rc != EOK)
-         break;
-      }
-    assert (word == NULL);
-    if (rc == EPARSE)
-      rc = EOK;                        /* its not an error to find no more 
words */
-  }
-  if (rc)
-    *p = save;
-
-  return rc;
-}
-
-/***** From RFC 822, 6.1 Address Specification Syntax *****/
-
-static mu_address_t
-new_mb (void)
-{
-  return calloc (1, sizeof (struct mu_address));
-}
-
-static char *
-addr_field_by_mask (mu_address_t addr, int mask)
-{
-  switch (mask)                                                
-    {
-    case MU_ADDR_HINT_ADDR:
-      return addr->addr;
-         
-    case MU_ADDR_HINT_COMMENTS:                                
-      return addr->comments;                                   
-         
-    case MU_ADDR_HINT_PERSONAL:                                
-      return addr->personal;                                   
-
-    case MU_ADDR_HINT_EMAIL:
-      return addr->email;
-
-    case MU_ADDR_HINT_LOCAL:
-      return addr->local_part;
-      
-    case MU_ADDR_HINT_DOMAIN:                          
-      return addr->domain;                                     
-
-    case MU_ADDR_HINT_ROUTE:
-      return addr->route;
-    }
-  return NULL;
-}                                                      
-
-static char *
-get_val (mu_address_t hint, int hflags, char *value, int mask, int *memflag)
-{
-  if (!value && hint && (hflags & mask))
-    {
-      char *p = addr_field_by_mask (hint, mask);
-      if (p)                                                   
-       {
-         if (memflag)
-           *memflag |= mask;
-         value = strdup (p);
-       }
-    }
-  return value;
-}
-
-static void
-addr_free_fields (mu_address_t a, int memflag)
-{
-  char *p;
-  
-  if ((p = addr_field_by_mask (a, memflag & MU_ADDR_HINT_ADDR)))
-    free (p);
-  if ((p = addr_field_by_mask (a, memflag & MU_ADDR_HINT_COMMENTS)))
-    free (p);
-  if ((p = addr_field_by_mask (a, memflag & MU_ADDR_HINT_PERSONAL)))
-    free (p);
-  if ((p = addr_field_by_mask (a, memflag & MU_ADDR_HINT_EMAIL)))
-    free (p);
-  if ((p = addr_field_by_mask (a, memflag & MU_ADDR_HINT_LOCAL)))
-    free (p);
-  if ((p = addr_field_by_mask (a, memflag & MU_ADDR_HINT_DOMAIN)))
-    free (p);
-  if ((p = addr_field_by_mask (a, memflag & MU_ADDR_HINT_ROUTE)))
-    free (p);
-}
-
-static int
-fill_mb (mu_address_t *pa,
-        char *comments, char *personal, char *local, char *domain,
-        mu_address_t hint, int hflags)
-{
-  int rc = EOK;
-  mu_address_t a;
-  int memflag = 0;
-
-  a = new_mb ();
-
-  if (!a)
-    return ENOMEM;
-
-  a->comments = get_val (hint, hflags, comments, MU_ADDR_HINT_COMMENTS,
-                        &memflag);
-  a->personal = get_val (hint, hflags, personal, MU_ADDR_HINT_PERSONAL,
-                        &memflag);
-
-  domain = get_val (hint, hflags, domain, MU_ADDR_HINT_DOMAIN,
-                   &memflag);
-  local = get_val (hint, hflags, local, MU_ADDR_HINT_LOCAL,
-                  &memflag);
-  do
-    {
-      /* loop exists only to break out of */
-      if (!local)
-       /* no email to construct */
-       break;
-
-      if ((rc = mu_parse822_quote_local_part (&a->email, local)))
-       break;
-      if (domain)
-       {
-         if ((rc = str_append (&a->email, "@")))
-           break;
-         if ((rc = str_append (&a->email, domain)))
-           break;
-       }
-    }
-  while (0);
-
-  a->local_part = local;
-  a->domain = domain;
-
-  if (rc != EOK)
-    {
-      addr_free_fields (a, memflag);
-      /* note that the arguments have NOT been freed, we only own
-       * them on success. */
-      free (a);
-    }
-  else
-    *pa = a;
-
-  return rc;
-}
-
-int
-mu_parse822_address_list (mu_address_t *a, const char *s,
-                         mu_address_t hint, int hflags)
-{
-  /* address-list = #(address) */
-
-  const char **p = &s;
-  const char *e = &s[strlen (s)];
-  int rc = EOK;
-  mu_address_t *n = a;         /* the next address we'll be creating */
-
-  rc = mu_parse822_address (p, e, n, hint, hflags);
-
-  /* A list may start with a leading <,>, we'll find out if
-   * that's not the case at the top of the while, but give
-   * this a conditional OK unless there was some other kind
-   * of error.
-   */
-  if (rc != EOK && rc != EPARSE)
-    {
-      return rc;
-    }
-  while (*p < e)
-    {
-      mu_parse822_skip_comments (p, e);
-
-      /* An address can contain a group, so an entire
-       * list of addresses may have been appended, or no
-       * addresses at all. Walk to the end.
-       */
-      while (*n)
-       {
-         n = &(*n)->next;
-       }
-
-      /* Remember that ',,address@hidden' is a valid list! So, we must find
-       * the <,>, but the address after it can be empty.
-       */
-      if ((rc = mu_parse822_special (p, e, ',')))
-       {
-         break;
-       }
-      mu_parse822_skip_comments (p, e);
-
-      rc = mu_parse822_address (p, e, n, hint, hflags);
-
-      if (rc == EOK || rc == EPARSE)
-       {
-         /* that's cool, it may be a <,>, we'll find out if it isn't
-          * at the top of the loop
-          */
-         rc = EOK;
-       }
-      else
-       {
-         /* anything else is a fatal error, break out */
-         break;
-       }
-    }
-
-  if (rc)
-    {
-      mu_address_destroy (a);
-    }
-
-  return rc;
-}
-
-int
-mu_parse822_address (const char **p, const char *e, mu_address_t *a,
-                    mu_address_t hint, int hflags)
-{
-  /* address = mailbox / group / unix-mbox */
-
-  int rc;
-
-  if ((rc = mu_parse822_mail_box (p, e, a, hint, hflags)) == EPARSE)
-    {
-      if ((rc = mu_parse822_group (p, e, a, hint, hflags)) == EPARSE)
-       {
-         rc = mu_parse822_unix_mbox (p, e, a, hint, hflags);
-       }
-    }
-
-  if (rc == 0 && *a && !(*a)->route)
-    (*a)->route = get_val (hint, hflags, NULL, MU_ADDR_HINT_ROUTE, NULL);
-
-  return rc;
-}
-
-/* No longer put groups into an address node, it wasn't useful, was
- * troublesome, and since there wasn't an end-group marker, wasn't
- * even conceivably useful.
- */
-#undef ADD_GROUPS
-int
-mu_parse822_group (const char **p, const char *e, mu_address_t *a,
-                  mu_address_t hint, int hflags)
-{
-  /* group = phrase ":" [#mailbox] ";" */
-
-  const char *save = *p;
-  mu_address_t *asave = a;             /* so we can destroy these if parsing 
fails */
-  int rc;
-  char *phrase = 0;
-
-  mu_parse822_skip_comments (p, e);
-
-  *p = save;
-
-  if ((rc = mu_parse822_phrase (p, e, &phrase)))
-    {
-      return rc;
-    }
-
-  mu_parse822_skip_comments (p, e);
-
-  if ((rc = mu_parse822_special (p, e, ':')))
-    {
-      *p = save;
-      str_free (&phrase);
-      return rc;
-    }
-#ifdef ADD_GROUPS
-  /* fake up an address node for the group's descriptive phrase, if
-   * it fails, clean-up will happen after the loop
-   */
-  if ((rc = fill_mb (a, 0, phrase, 0, 0, hint, hflags)) == EOK)
-    {
-      a = &(*a)->next;
-    }
-  else
-    {
-      str_free (&phrase);
-    }
-#else
-  str_free (&phrase);
-#endif
-
-  /* Basically, on each loop, we may find a mailbox, but we must find
-   * a comma after the mailbox, otherwise we've popped off the end
-   * of the list.
-   */
-  while (!rc)
-    {
-      mu_parse822_skip_comments (p, e);
-
-      /* it's ok not be a mailbox, but other errors are fatal */
-      rc = mu_parse822_mail_box (p, e, a, hint, hflags);
-      if (rc == EOK)
-       {
-         a = &(*a)->next;
-
-         mu_parse822_skip_comments (p, e);
-       }
-      else if (rc != EPARSE)
-       {
-         break;
-       }
-
-      if ((rc = mu_parse822_special (p, e, ',')))
-       {
-         /* the commas aren't optional */
-         break;
-       }
-    }
-  if (rc == EPARSE)
-    {
-      rc = EOK;                        /* ok, as long as we find the ";" next 
*/
-    }
-
-  if (rc || (rc = mu_parse822_special (p, e, ';')))
-    {
-      *p = save;
-
-      mu_address_destroy (asave);
-    }
-
-  return rc;
-}
-
-int
-mu_parse822_mail_box (const char **p, const char *e, mu_address_t *a,
-                     mu_address_t hint, int hflags)
-{
-  /* mailbox =
-   *     addr-spec [ "(" comment ")" ] /
-   *     [phrase] route-addr
-   *
-   *  Note: we parse the ancient comment on the right since
-   *    it's such "common practice". :-(
-   *  Note: phrase is called display-name in drums.
-   *  Note: phrase is optional in drums, though not in RFC 822.
-   */
-  const char *save = *p;
-  int rc;
-
-  /* -> addr-spec */
-  if ((rc = mu_parse822_addr_spec (p, e, a, hint, hflags)) == EOK)
-    {
-      mu_parse822_skip_lwsp (p, e);
-
-      /* yuck. */
-      if ((rc = mu_parse822_comment (p, e, &(*a)->personal)) == EPARSE)
-       {
-         rc = EOK;
-         /* cool if there's no comment, */
-       }
-      /* but if something else is wrong, destroy the address */
-      if (rc)
-       {
-         mu_address_destroy (a);
-         *p = save;
-       }
-
-      return rc;
-    }
-
-  /* -> phrase route-addr */
-  {
-    char *phrase = 0;
-
-    rc = mu_parse822_phrase (p, e, &phrase);
-
-    if (rc != EPARSE && rc != EOK)
-      {
-       return rc;
-      }
-
-    if ((rc = mu_parse822_route_addr (p, e, a, hint, hflags)) == EOK)
-      {
-       /* add the phrase */
-       (*a)->personal = phrase;
-
-       return EOK;
-      }
-    /* some internal error, fail out */
-    str_free (&phrase);
-    *p = save;
-
-    return rc;
-  }
-
-  return rc;
-}
-
-int
-mu_parse822_route_addr (const char **p, const char *e, mu_address_t *a,
-                       mu_address_t hint, int hflags)
-{
-  /* route-addr = "<" [route] addr-spec ">" */
-
-  const char *save = *p;
-  char *route = NULL;
-  int rc;
-  int memflag = 0;
-  
-  mu_parse822_skip_comments (p, e);
-
-  if ((rc = mu_parse822_special (p, e, '<')))
-    {
-      *p = save;
-
-      return rc;
-    }
-  if (!(rc = mu_parse822_special (p, e, '>')))
-    {
-      if ((rc = fill_mb (a, 0, 0, 0, 0, hint, hflags)) == EOK)
-       rc = str_append (&(*a)->email, "");
-       
-      return rc;
-    }
-
-  mu_parse822_route (p, e, &route);
-
-  if ((rc = mu_parse822_addr_spec (p, e, a, hint, hflags)))
-    {
-      *p = save;
-
-      str_free (&route);
-
-      return rc;
-    }
-
-  (*a)->route = get_val (hint, hflags, route, MU_ADDR_HINT_ROUTE,
-                        &memflag);
-
-  mu_parse822_skip_comments (p, e);
-
-  if ((rc = mu_parse822_special (p, e, '>')))
-    {
-      *p = save;
-
-      mu_address_destroy (a);
-
-      return rc;
-    }
-
-  return EOK;
-}
-
-int
-mu_parse822_route (const char **p, const char *e, char **route)
-{
-  /* route = 1#("@" domain ) ":" */
-
-  const char *save = *p;
-  char *accumulator = 0;
-  int rc = EOK;
-
-  for (;;)
-    {
-      mu_parse822_skip_comments (p, e);
-
-      if ((rc = mu_parse822_special (p, e, '@')))
-       {
-         break;
-       }
-
-      if ((rc = str_append (&accumulator, "@")))
-       {
-         break;
-       }
-
-      mu_parse822_skip_comments (p, e);
-
-      if ((rc = mu_parse822_domain (p, e, &accumulator)))
-       {
-         /* it looked like a route, but there's no domain! */
-         break;
-       }
-
-      mu_parse822_skip_comments (p, e);
-
-      if ((rc = mu_parse822_special (p, e, ',')) == EPARSE)
-       {
-         /* no more routes, but we got one so its ok */
-         rc = EOK;
-         break;
-       }
-      if ((rc = str_append (&accumulator, ", ")))
-       {
-         break;
-       }
-    }
-
-  mu_parse822_skip_comments (p, e);
-
-  if (!rc)
-    {
-      rc = mu_parse822_special (p, e, ':');
-    }
-
-  if (!rc)
-    {
-      rc = str_append (route, accumulator);
-    }
-  if (rc)
-    {
-      *p = save;
-    }
-  str_free (&accumulator);
-  return rc;
-}
-
-int
-mu_parse822_addr_spec (const char **p, const char *e, mu_address_t *a,
-                      mu_address_t hint, int hflags)
-{
-  /* addr-spec = local-part "@" domain */
-
-  const char *save = *p;
-  char *local_part = 0;
-  char *domain = 0;
-  int rc;
-
-  rc = mu_parse822_local_part (p, e, &local_part);
-
-  mu_parse822_skip_comments (p, e);
-
-  if (!rc)
-    {
-      rc = mu_parse822_special (p, e, '@');
-      
-      if (!rc)
-       {
-         rc = mu_parse822_domain (p, e, &domain);
-
-         if (!rc)
-           rc = fill_mb (a, 0, 0, local_part, domain, hint, hflags);
-       }
-    }
-  
-  if (rc)
-    {
-      *p = save;
-      str_free (&local_part);
-      str_free (&domain);
-    }
-  return rc;
-}
-
-int
-mu_parse822_unix_mbox (const char **p, const char *e, mu_address_t *a,
-                      mu_address_t hint, int hflags)
-{
-  /* unix-mbox = atom */
-
-  const char *save = *p;
-  char *mbox = 0;
-  int rc;
-
-  mu_parse822_skip_comments (p, e);
-
-  rc = mu_parse822_atom (p, e, &mbox);
-
-  if (!rc)
-    rc = fill_mb (a, 0, 0, mbox, 0, hint, hflags);
-
-  if (rc)
-    {
-      *p = save;
-      str_free (&mbox);
-    }
-  return rc;
-}
-
-int
-mu_parse822_local_part (const char **p, const char *e, char **local_part)
-{
-  /* local-part = word *("." word)
-   *
-   * Note: rewrite as ->  word ["." local-part]
-   */
-
-  const char *save = *p;
-  const char *save2 = *p;
-  int rc;
-
-  mu_parse822_skip_comments (p, e);
-
-  if ((rc = mu_parse822_word (p, e, local_part)))
-    {
-      *p = save;
-      return rc;
-    }
-  /* We've got a local-part, but keep looking for more. */
-
-  mu_parse822_skip_comments (p, e);
-
-  /* If we get a parse error, we roll back to save2, but if
-   * something else failed, we have to roll back to save.
-   */
-  save2 = *p;
-
-  rc = mu_parse822_special (p, e, '.');
-
-  if (!rc)
-    {
-      char *more = 0;
-      if ((rc = mu_parse822_local_part (p, e, &more)) == EOK)
-       {
-         /* append more */
-         if ((rc = str_append (local_part, ".")) == EOK)
-           {
-             rc = str_append (local_part, more);
-           }
-       }
-      str_free (&more);
-    }
-
-  if (rc == EPARSE)
-    {
-      /* if we didn't get more ("." word) pairs, that's ok */
-      *p = save2;
-      rc = EOK;
-    }
-  if (rc)
-    {
-      /* if anything else failed, that's real */
-      *p = save;
-      str_free (local_part);
-    }
-  return rc;
-}
-
-int
-mu_parse822_domain (const char **p, const char *e, char **domain)
-{
-  /* domain = sub-domain *("." sub-domain)
-   *
-   * Note: rewrite as -> sub-domain ("." domain)
-   */
-
-  const char *save = *p;
-  const char *save2 = 0;
-  int rc;
-
-  mu_parse822_skip_comments (p, e);
-
-  if ((rc = mu_parse822_sub_domain (p, e, domain)))
-    {
-      *p = save;
-      return rc;
-    }
-
-
-  /* We save before skipping comments to preserve the comment
-   * at the end of a domain, the addr-spec may want to abuse it
-   * for a personal name.
-   */
-  save2 = *p;
-
-  /* we've got the 1, keep looking for more */
-
-  mu_parse822_skip_comments (p, e);
-
-  rc = mu_parse822_special (p, e, '.');
-
-  if (!rc)
-    {
-      char *more = 0;
-      if ((rc = mu_parse822_domain (p, e, &more)) == EOK)
-       {
-         if ((rc = str_append (domain, ".")) == EOK)
-           {
-             rc = str_append (domain, more);
-           }
-       }
-      str_free (&more);
-    }
-  if (rc == EPARSE)
-    {
-      /* we didn't parse more ("." sub-domain) pairs, that's ok */
-      *p = save2;
-      rc = EOK;
-    }
-
-  if (rc)
-    {
-      /* something else failed, roll it all back */
-      *p = save;
-      str_free (domain);
-    }
-  return rc;
-}
-
-int
-mu_parse822_sub_domain (const char **p, const char *e, char **sub_domain)
-{
-  /* sub-domain = domain-ref / domain-literal
-   */
-
-  int rc;
-
-  if ((rc = mu_parse822_domain_ref (p, e, sub_domain)) == EPARSE)
-    rc = mu_parse822_domain_literal (p, e, sub_domain);
-
-  return rc;
-}
-
-int
-mu_parse822_domain_ref (const char **p, const char *e, char **domain_ref)
-{
-  /* domain-ref = atom */
-
-  return mu_parse822_atom (p, e, domain_ref);
-}
-
-int
-mu_parse822_d_text (const char **p, const char *e, char **dtext)
-{
-  /* d-text = 1*dtext
-   *
-   * Note: dtext is only defined as a character class in
-   *  RFC822, but this definition is more useful for
-   *  slurping domain literals.
-   */
-
-  const char *start = *p;
-  int rc = EOK;
-
-  while (*p < e && mu_parse822_is_d_text (**p))
-    {
-      *p += 1;
-    }
-
-  if (start == *p)
-    {
-      return EPARSE;
-    }
-
-  if ((rc = str_append_range (dtext, start, *p)))
-    {
-      *p = start;
-    }
-
-  return rc;
-}
-
-int
-mu_parse822_domain_literal (const char **p, const char *e, char 
**domain_literal)
-{
-  /* domain-literal = "[" *(dtext / quoted-pair) "]" */
-
-  const char *save = *p;
-  char *literal = 0;
-  int rc;
-
-  if ((rc = mu_parse822_special (p, e, '[')))
-    {
-      return rc;
-    }
-  if ((rc = str_append_char (&literal, '[')))
-    {
-      *p = save;
-      return rc;
-    }
-
-  while ((rc = mu_parse822_d_text (p, e, &literal)) == EOK ||
-        (rc = mu_parse822_quoted_pair (p, e, &literal)) == EOK)
-    {
-      /* Eat all of this we can get! */
-    }
-  if (rc == EPARSE)
-    {
-      rc = EOK;
-    }
-  if (!rc)
-    {
-      rc = mu_parse822_special (p, e, ']');
-    }
-  if (!rc)
-    {
-      rc = str_append_char (&literal, ']');
-    }
-  if (!rc)
-    {
-      rc = str_append (domain_literal, literal);
-    }
-
-  str_free (&literal);
-
-  if (rc)
-    {
-      *p = save;
-    }
-  return rc;
-}
-
-/***** From RFC 822, 5.1 Date and Time Specification Syntax *****/
-
-int
-mu_parse822_day (const char **p, const char *e, int *day)
-{
-  /* day = "Mon" / "Tue" / "Wed" / "Thu" / "Fri" / "Sat" / "Sun" */
-
-  const char *days[] = {
-    "Sun",
-    "Mon",
-    "Tue",
-    "Wed",
-    "Thu",
-    "Fri",
-    "Sat",
-    NULL
-  };
-
-  int d;
-
-  mu_parse822_skip_comments (p, e);
-
-  if ((e - *p) < 3)
-    return EPARSE;
-
-  for (d = 0; days[d]; d++)
-    {
-      if (mu_c_strncasecmp (*p, days[d], 3) == 0)
-       {
-         *p += 3;
-         if (day)
-           *day = d;
-         return EOK;
-       }
-    }
-  return EPARSE;
-}
-
-int
-mu_parse822_date (const char **p, const char *e, int *day, int *mon, int *year)
-{
-  /* date = 1*2DIGIT month 2*4DIGIT
-   * month =  "Jan"  /  "Feb" /  "Mar"  /  "Apr"
-   *       /  "May"  /  "Jun" /  "Jul"  /  "Aug"
-   *       /  "Sep"  /  "Oct" /  "Nov"  /  "Dec"
-   */
-
-  const char *mons[] = {
-    "Jan",
-    "Feb",
-    "Mar",
-    "Apr",
-    "May",
-    "Jun",
-    "Jul",
-    "Aug",
-    "Sep",
-    "Oct",
-    "Nov",
-    "Dec",
-    NULL
-  };
-
-  const char *save = *p;
-  int rc = EOK;
-  int m = 0;
-  int yr = 0;
-  const char *yrbeg = 0;
-
-  mu_parse822_skip_comments (p, e);
-
-  if ((rc = mu_parse822_digits (p, e, 1, 2, day)))
-    {
-      *p = save;
-      return rc;
-    }
-
-  mu_parse822_skip_comments (p, e);
-
-  if ((e - *p) < 3)
-    return EPARSE;
-
-  for (m = 0; mons[m]; m++)
-    {
-      if (mu_c_strncasecmp (*p, mons[m], 3) == 0)
-       {
-         *p += 3;
-         if (mon)
-           *mon = m;
-         break;
-       }
-    }
-
-  if (!mons[m])
-    {
-      *p = save;
-      return EPARSE;
-    }
-
-  mu_parse822_skip_comments (p, e);
-
-  /* We need to count how many digits their were, and adjust the
-   * interpretation of the year accordingly. This is from RFC 2822,
-   * Section 4.3, Obsolete Date and Time. */
-  yrbeg = *p;
-
-  if ((rc = mu_parse822_digits (p, e, 2, 4, &yr)))
-    {
-      *p = save;
-      return rc;
-    }
-
-  /* rationalize year to four digit, then adjust to tz notation */
-  switch (*p - yrbeg)
-    {
-    case 2:
-      if (yr >= 0 && yr <= 49)
-       {
-         yr += 2000;
-         break;
-       }
-    case 3:
-      yr += 1900;
-      break;
-    }
-
-  if (year)
-    *year = yr - 1900;
-
-  return EOK;
-}
-
-int
-mu_parse822_time (const char **p, const char *e,
-              int *hour, int *min, int *sec, int *tz, const char **tz_name)
-{
-  /* time        =  hour zone
-   * hour        =  2DIGIT ":" 2DIGIT [":" 2DIGIT] ; 00:00:00 - 23:59:59
-   * zone        =  "UT"  / "GMT"           ; Universal Time
-   *                                        ; North American : UT
-   *             /  "EST" / "EDT"           ;  Eastern:  - 5/ - 4
-   *             /  "CST" / "CDT"           ;  Central:  - 6/ - 5
-   *             /  "MST" / "MDT"           ;  Mountain: - 7/ - 6
-   *             /  "PST" / "PDT"           ;  Pacific:  - 8/ - 7
-   *             /  1ALPHA                  ; RFC 822 was wrong, RFC 2822
-   *                                        ; says treat these all as -0000.
-   *             / ( ("+" / "-") 4DIGIT )   ; Local differential
-   *                                        ;  hours+min. (HHMM)
-   */
-
-  struct
-  {
-    const char *tzname;
-    int tz;
-  }
-  tzs[] =
-  {
-    { "UT",   0 * 60 * 60 },
-    { "UTC",  0 * 60 * 60 },
-    { "GMT",  0 * 60 * 60 },
-    { "EST", -5 * 60 * 60 },
-    { "EDT", -4 * 60 * 60 },
-    { "CST", -6 * 60 * 60 },
-    { "CDT", -5 * 60 * 60 },
-    { "MST", -7 * 60 * 60 },
-    { "MDT", -6 * 60 * 60 },
-    { "PST", -8 * 60 * 60 },
-    { "PDT", -7 * 60 * 60 },
-    { NULL, 0}
-  };
-
-  const char *save = *p;
-  int rc = EOK;
-  int z = 0;
-  char *zone = NULL;
-
-  mu_parse822_skip_comments (p, e);
-
-  if ((rc = mu_parse822_digits (p, e, 1, 2, hour)))
-    {
-      *p = save;
-      return rc;
-    }
-
-  if ((rc = mu_parse822_special (p, e, ':')))
-    {
-      *p = save;
-      return rc;
-    }
-
-  if ((rc = mu_parse822_digits (p, e, 1, 2, min)))
-    {
-      *p = save;
-      return rc;
-    }
-
-  if ((rc = mu_parse822_special (p, e, ':')))
-    {
-      *sec = 0;
-    }
-  else if ((rc = mu_parse822_digits (p, e, 1, 2, sec)))
-    {
-      *p = save;
-      return rc;
-    }
-
-  mu_parse822_skip_comments (p, e);
-
-  if ((rc = mu_parse822_atom (p, e, &zone)))
-    {
-      /* zone is optional */
-      if (tz)
-       *tz = 0;
-      return EOK;
-    }
-
-  /* see if it's a timezone */
-  for (; tzs[z].tzname; z++)
-    {
-      if (mu_c_strcasecmp (zone, tzs[z].tzname) == 0)
-       break;
-    }
-  if (tzs[z].tzname)
-    {
-      if (tz_name)
-       *tz_name = tzs[z].tzname;
-
-      if (tz)
-       *tz = tzs[z].tz;
-    }
-  else if (strlen (zone) > 5 || strlen (zone) < 4)
-    {
-      if (*tz)
-       *tz = 0; /* Assume UTC */
-    }
-  else
-    {
-      /* zone = ( + / - ) hhmm */
-      int hh;
-      int mm;
-      int sign;
-      char *zp = zone;
-
-      switch (zp[0])
-       {
-       case '-':
-         sign = -1;
-         zp++;
-         break;
-       case '+':
-         sign = +1;
-         zp++;
-         break;
-       default:
-         sign = 1;
-         break;
-       }
-
-      if (strspn (zp, "0123456789") == 4)
-       {
-      /* convert to seconds from UTC */
-      hh = (zone[1] - '0') * 10 + (zone[2] - '0');
-      mm = (zone[3] - '0') * 10 + (zone[4] - '0');
-       }
-      else
-       {
-         hh = mm = 0; /* Consider equivalent to -0000 */
-       }
-      if (tz)
-       *tz = sign * (hh * 60 * 60 + mm * 60);
-    }
-
-  str_free (&zone);
-
-  return EOK;
-}
-
-#if 0
-For reference, especially the for the required range and values of the
-integer fields.
-
-struct tm
-{
-  int tm_sec;                  /* Seconds.     [0-60] (1 leap second) */
-  int tm_min;                  /* Minutes.     [0-59] */
-  int tm_hour;                 /* Hours.       [0-23] */
-  int tm_mday;                 /* Day.         [1-31] */
-  int tm_mon;                  /* Month.       [0-11] */
-  int tm_year;                 /* Year - 1900.  */
-  int tm_wday;                 /* Day of week. [0-6] */
-  int tm_yday;                 /* Days in year.[0-365] */
-  int tm_isdst;                        /* DST.         [-1/0/1]*/
-
-  int tm_gmtoff;        /* Seconds east of UTC. */
-  const char *tm_zone; /* Timezone abbreviation.  */
-};
-#endif
-
-int
-mu_parse822_date_time (const char **p, const char *e, struct tm *tm,
-                      struct mu_timezone *tz)
-{
-  /* date-time = [ day "," ] date time */
-
-  const char *save = *p;
-  int rc = 0;
-
-  int wday = 0;
-
-  int mday = 0;
-  int mon = 0;
-  int year = 0;
-
-  int hour = 0;
-  int min = 0;
-  int sec = 0;
-
-  int tzoffset = 0;
-  const char *tz_name = 0;
-
-  if ((rc = mu_parse822_day (p, e, &wday)))
-    {
-      if (rc != EPARSE)
-       return rc;
-    }
-  else
-    {
-      /* If we got a day, we MUST have a ','. */
-      mu_parse822_skip_comments (p, e);
-
-      if ((rc = mu_parse822_special (p, e, ',')))
-       {
-         *p = save;
-         return rc;
-       }
-    }
-
-  if ((rc = mu_parse822_date (p, e, &mday, &mon, &year)))
-    {
-      *p = save;
-      return rc;
-    }
-  if ((rc = mu_parse822_time (p, e, &hour, &min, &sec, &tzoffset, &tz_name)))
-    {
-      *p = save;
-      return rc;
-    }
-
-  if (tm)
-    {
-      memset (tm, 0, sizeof (*tm));
-
-      tm->tm_wday = wday;
-
-      tm->tm_mday = mday;
-      tm->tm_mon = mon;
-      tm->tm_year = year;
-
-      tm->tm_hour = hour;
-      tm->tm_min = min;
-      tm->tm_sec = sec;
-
-#ifdef HAVE_STRUCT_TM_TM_ISDST
-      tm->tm_isdst = -1;       /* unknown whether it's dst or not */
-#endif
-#ifdef HAVE_STRUCT_TM_TM_GMTOFF
-      tm->tm_gmtoff = tzoffset;
-#endif
-#ifdef HAVE_STRUCT_TM_TM_ZONE
-      tm->tm_zone = (char*) tz_name;
-#endif
-    }
-
-  if (tz)
-    {
-      tz->utc_offset = tzoffset;
-      tz->tz_name = tz_name;
-    }
-
-  return EOK;
-}
-
-/***** From RFC 822, 3.2 Header Field Definitions *****/
-
-int
-mu_parse822_field_name (const char **p, const char *e, char **fieldname)
-{
-  /* field-name = 1*<any char, excluding ctls, space, and ":"> ":" */
-
-  const char *save = *p;
-
-  char *fn = NULL;
-
-  while (*p != e)
-    {
-      char c = **p;
-
-      if (!mu_parse822_is_char (c))
-       break;
-
-      if (mu_parse822_is_ctl (c))
-       break;
-      if (mu_parse822_is_space (c))
-       break;
-      if (c == ':')
-       break;
-
-      str_append_char (&fn, c);
-      *p += 1;
-    }
-  /* must be at least one char in the field name */
-  if (!fn)
-    {
-      *p = save;
-      return EPARSE;
-    }
-  mu_parse822_skip_comments (p, e);
-
-  if (!mu_parse822_special (p, e, ':'))
-    {
-      *p = save;
-      if (fn)
-       free (fn);
-      return EPARSE;
-    }
-
-  *fieldname = fn;
-
-  return EOK;
-}
-
-int
-mu_parse822_field_body (const char **p, const char *e, char **fieldbody)
-{
-  /* field-body = *text [CRLF lwsp-char field-body] */
-
-  /*const char *save = *p; */
-
-  char *fb = NULL;
-
-  for (;;)
-    {
-      const char *eol = *p;
-      while (eol != e)
-       {
-         /*char c = *eol; */
-         if (eol[0] == '\r' && (eol + 1) != e && eol[1] == '\n')
-           break;
-         ++eol;
-       }
-      str_append_range (&fb, *p, eol);
-      *p = eol;
-      if (eol == e)
-       break;                  /* no more, so we're done */
-
-      /*assert(p[0] == '\r'); */
-      /*assert(p[1] == '\n'); */
-
-      *p += 2;
-
-      if (*p == e)
-       break;                  /* no more, so we're done */
-
-      /* check if next line is a continuation line */
-      if (**p != ' ' && **p != '\t')
-       break;
-    }
-
-  *fieldbody = fb;
-
-  return EOK;
-}
-
-/***** RFC 822 Quoting Functions *****/
-
-int
-mu_parse822_quote_string (char **quoted, const char *raw)
-{
-  /* quoted-string = <"> *(qtext/quoted-pair) <">
-   *
-   * So double quote the string, and back quote anything that
-   * isn't qtext.
-   */
-
-  int rc = EOK;
-  const char *s;
-
-  if (!raw || !quoted || *quoted)
-    {
-      return EINVAL;
-    }
-
-  s = raw;
-
-  rc = str_append_char (quoted, '"');
-
-  while (!rc && *s)
-    {
-      if (!mu_parse822_is_q_text (*s))
-       {
-         rc = str_append_char (quoted, '\\');
-       }
-
-      if (!rc)
-       {
-         rc = str_append_char (quoted, *s);
-       }
-      ++s;
-    }
-
-  if (!rc)
-    {
-      rc = str_append_char (quoted, '"');
-    }
-
-  if (rc)
-    {
-      str_free (quoted);
-    }
-  return rc;
-}
-
-int
-mu_parse822_quote_local_part (char **quoted, const char *raw)
-{
-  /* local-part = word * ("." word)
-   * word = atom / quoted-string
-   *
-   * So, if any character isn't a "." or an atom character, we quote
-   * the whole thing as a string, for simplicity, otherwise just
-   * copy it.
-   */
-
-  const char *s = 0;
-
-  if (!raw || !quoted || *quoted)
-    {
-      return EINVAL;
-    }
-  s = raw;
-
-  while (*s)
-    {
-      if (*s != '.' && !mu_parse822_is_atom_char (*s))
-       {
-         return mu_parse822_quote_string (quoted, raw);
-       }
-      ++s;
-    }
-
-  /* if we don't have to quote it, just copy it over */
-
-  return str_append (quoted, raw);
-}
-
diff --git a/libmailutils/parsedate.y b/libmailutils/parsedate.y
deleted file mode 100644
index 79eda8b..0000000
--- a/libmailutils/parsedate.y
+++ /dev/null
@@ -1,1206 +0,0 @@
-%{
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2003, 2007, 2008, 2010 Free Software Foundation, Inc.
-
-   GNU Mailutils is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-   
-   GNU Mailutils is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
-  
-/* A heavily modified version of the well-known public domain getdate.y.
-   It was originally written by Steven M. Bellovin <address@hidden>
-   while at the University of North Carolina at Chapel Hill.  Later tweaked
-   by a couple of people on Usenet.  Completely overhauled by Rich $alz
-   <address@hidden> and Jim Berets <address@hidden> in August, 1990.
-   Rewritten using a proper union by Sergey Poznyakoff <address@hidden> */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdio.h>
-#include <ctype.h>
-
-#if HAVE_STDLIB_H
-# include <stdlib.h> /* for `free'; used by Bison 1.27 */
-#endif
-
-#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
-# define IN_CTYPE_DOMAIN(c) 1
-#else
-# define IN_CTYPE_DOMAIN(c) isascii(c)
-#endif
-
-#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
-#define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
-#define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
-#define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
-
-/* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
-   - Its arg may be any int or unsigned int; it need not be an unsigned char.
-   - It's guaranteed to evaluate its argument exactly once.
-   - It's typically faster.
-   Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
-   only '0' through '9' are digits.  Prefer ISDIGIT to ISDIGIT_LOCALE unless
-   it's important to use the locale's definition of `digit' even when the
-   host does not conform to Posix.  */
-#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
-
-#if defined (STDC_HEADERS) || defined (USG)
-# include <string.h>
-#endif
-
-/* Some old versions of bison generate parsers that use bcopy.
-   That loses on systems that don't provide the function, so we have
-   to redefine it here.  */
-#if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy)
-# define bcopy(from, to, len) memcpy ((to), (from), (len))
-#endif
-
-static int yylex ();
-static int yyerror ();
-
-#define EPOCH          1970
-#define HOUR(x)                ((x) * 60)
-
-#define MAX_BUFF_LEN    128   /* size of buffer to read the date into */
-
-/*
-**  An entry in the lexical lookup table.
-*/
-typedef struct _lex_tab {
-  const char   *name;
-  int          type;
-  int          value;
-} SYMBOL;
-
-
-/*
-**  Meridian:  am, pm, or 24-hour style.
-*/
-typedef enum meridian {
-  MERam,
-  MERpm,
-  MER24
-} MERIDIAN;
-
-#define PD_MASK_SECOND   00001
-#define PD_MASK_MINUTE   00002
-#define PD_MASK_HOUR     00004
-#define PD_MASK_DAY      00010
-#define PD_MASK_MONTH    00020
-#define PD_MASK_YEAR     00040
-#define PD_MASK_TZ       00100 
-#define PD_MASK_MERIDIAN 00200
-#define PD_MASK_ORDINAL  00400
-#define PD_MASK_NUMBER   01000
-
-#define PD_MASK_TIME PD_MASK_SECOND|PD_MASK_MINUTE|PD_MASK_HOUR
-#define PD_MASK_DATE PD_MASK_DAY|PD_MASK_MONTH|PD_MASK_YEAR
-#define PD_MASK_DOW PD_MASK_NUMBER
- 
-#define MASK_IS_SET(f,m) (((f)&(m))==(m))
-#define MASK_TEST(f,m)   ((f)&(m)) 
-struct pd_date
-{
-  int mask;
-  int day;
-  int hour;
-  int minute;
-  int month;
-  int second;
-  int year;
-  int tz;
-  enum meridian meridian;
-  int number;
-  int ordinal;
-};
-
-#define DATE_INIT(date) memset(&(date), 0, sizeof(date))
-#define DATE_SET(date, memb, m, val, lim, onerror)                        \
- do                                                                       \
-   {                                                                      \
-     int __x = val;                                                       \
-     if (((m) != PD_MASK_TZ && __x < 0) || (lim && __x > lim)) onerror;   \
-     date . memb = __x; date.mask |= m;                                   \
-   }                                                                      \
- while (0)
-   
-#define __SET_SECOND(d,v,a)   DATE_SET(d,second,PD_MASK_SECOND,v,59,a)
-#define __SET_MINUTE(d,v,a)   DATE_SET(d,minute,PD_MASK_MINUTE,v,59,a)  
-#define __SET_HOUR(d,v,a)     DATE_SET(d,hour,PD_MASK_HOUR,v,23,a)
-#define __SET_DAY(d,v,a)      DATE_SET(d,day,PD_MASK_DAY,v,31,a)   
-#define __SET_MONTH(d,v,a)    DATE_SET(d,month,PD_MASK_MONTH,v,12,a)
-#define __SET_YEAR(d,v,a)     DATE_SET(d,year,PD_MASK_YEAR,v,0,a)  
-#define __SET_TZ(d,v,a)       DATE_SET(d,tz,PD_MASK_TZ,v,0,a)
-#define __SET_MERIDIAN(d,v,a) DATE_SET(d,meridian,PD_MASK_MERIDIAN,v,MER24,a)
-#define __SET_ORDINAL(d,v,a)  DATE_SET(d,ordinal,PD_MASK_ORDINAL,v,0,a)
-#define __SET_NUMBER(d,v,a)   DATE_SET(d,number,PD_MASK_NUMBER,v,0,a) 
- 
-#define SET_SECOND(d,v)   __SET_SECOND(d,v,YYERROR)   
-#define SET_MINUTE(d,v)   __SET_MINUTE(d,v,YYERROR)   
-#define SET_HOUR(d,v)     __SET_HOUR(d,v,YYERROR)     
-#define SET_DAY(d,v)      __SET_DAY(d,v,YYERROR)      
-#define SET_MONTH(d,v)    __SET_MONTH(d,v,YYERROR)    
-#define SET_YEAR(d,v)     __SET_YEAR(d,v,YYERROR)     
-#define SET_TZ(d,v)       __SET_TZ(d,v,YYERROR)       
-#define SET_MERIDIAN(d,v) __SET_MERIDIAN(d,v,YYERROR) 
-#define SET_ORDINAL(d,v)  __SET_ORDINAL(d,v,YYERROR)  
-#define SET_NUMBER(d,v)   __SET_NUMBER(d,v,YYERROR)   
-
-int
-pd_date_union (struct pd_date *a, struct pd_date *b)
-{
-  int diff = (~a->mask) & b->mask;
-  if (!diff)
-    return 1;
-
-  a->mask |= diff;
-  
-  if (diff & PD_MASK_SECOND)
-    a->second = b->second;
-  
-  if (diff & PD_MASK_MINUTE)
-    a->minute = b->minute;
-
-  if (diff & PD_MASK_HOUR)
-    a->hour = b->hour;
-
-  if (diff & PD_MASK_DAY)
-    a->day = b->day;
-
-  if (diff & PD_MASK_MONTH)
-    a->month = b->month;
-
-  if (diff & PD_MASK_YEAR)
-    a->year = b->year;
-
-  if (diff & PD_MASK_TZ)
-    a->tz = b->tz;
-
-  if (diff & PD_MASK_MERIDIAN)
-    a->meridian = b->meridian;
-
-  if (diff & PD_MASK_ORDINAL)
-    a->ordinal = b->ordinal;
-
-  if (diff & PD_MASK_NUMBER)
-    a->number = b->number;
-
-  return 0;
-}
-
-struct pd_datespec
-{
-  struct pd_date date;
-  struct pd_date rel;
-};
-
-static struct pd_datespec pd;
- 
-static const char      *yyinput;
-
-%}
-
-%union {
-  int number;
-  enum meridian meridian;
-  struct pd_date date;
-  struct pd_datespec datespec;
-}
-
-/*FIXME: do we need T_ID? */
-%token  T_AGO T_DST  T_ID
-
-%token <number> T_DAY T_DAY_UNIT T_DAYZONE T_HOUR_UNIT T_MINUTE_UNIT
-%token <number> T_MONTH T_MONTH_UNIT
-%token <number>        T_SEC_UNIT T_SNUMBER T_UNUMBER T_YEAR_UNIT T_ZONE
-%token <meridian> T_MERIDIAN
-
-%type <meridian> o_merid
-%type <date> item time zone date day rel relspec relunit
-%type <datespec> spec
-
-%%
-
-input   : spec
-          {
-           pd = $1;
-         }
-        ;
-
-spec   : /* NULL */
-          {
-           DATE_INIT ($$.date);
-           DATE_INIT ($$.rel);
-         }
-       | spec item
-          {
-           if (pd_date_union (&$1.date, &$2))
-             YYERROR;
-           $$ = $1;
-         }
-        | spec rel
-          {
-           if (pd_date_union (&$1.rel, &$2))
-             YYERROR;
-           $$ = $1;
-         }
-        | spec T_UNUMBER
-          {
-           if (MASK_IS_SET ($1.date.mask, (PD_MASK_TIME|PD_MASK_DATE))
-               && !$1.rel.mask)
-             SET_YEAR ($1.date, $2);
-           else
-             {
-               if ($2 > 10000)
-                 {
-                   SET_DAY ($1.date, $2 % 100);
-                   SET_MONTH ($1.date, ($2 / 100) %100);
-                   SET_YEAR ($1.date, $2 / 10000);
-                 }
-               else
-                 {
-                   if ($2 < 100)
-                     {
-                       SET_YEAR ($1.date, $2);
-                     }
-                   else
-                     {
-                       SET_HOUR ($1.date, $2 / 100);
-                       SET_MINUTE ($1.date, $2 % 100);
-                     }
-                   SET_MERIDIAN ($1.date, MER24);
-                 }
-             }
-           $$ = $1;
-         }
-       ;
-
-item   : time
-        | zone
-       | date
-       | day
-       ;
-
-time   : T_UNUMBER T_MERIDIAN
-          {
-           DATE_INIT ($$);
-           SET_HOUR ($$, $1);
-           SET_MERIDIAN ($$, $2);
-         }
-       | T_UNUMBER ':' T_UNUMBER o_merid
-          {
-           DATE_INIT ($$);
-           SET_HOUR ($$, $1);
-           SET_MINUTE ($$, $3);
-           SET_MERIDIAN ($$, $4);
-         }
-       | T_UNUMBER ':' T_UNUMBER T_SNUMBER
-          {
-           DATE_INIT ($$);
-           SET_HOUR ($$, $1);
-           SET_MINUTE ($$, $3);
-           SET_MERIDIAN ($$, MER24);
-           SET_TZ ($$, ($4 < 0
-                          ? -$4 % 100 + (-$4 / 100) * 60
-                          : - ($4 % 100 + ($4 / 100) * 60)));
-
-         }
-       | T_UNUMBER ':' T_UNUMBER ':' T_UNUMBER o_merid
-          {
-           DATE_INIT ($$);
-           SET_HOUR ($$, $1);
-           SET_MINUTE ($$, $3);
-           SET_SECOND ($$, $5);
-           SET_MERIDIAN ($$, $6);
-         }
-       | T_UNUMBER ':' T_UNUMBER ':' T_UNUMBER T_SNUMBER
-          {
-           DATE_INIT ($$);
-           SET_HOUR ($$, $1);
-           SET_MINUTE ($$, $3);
-           SET_SECOND ($$, $5);
-           SET_MERIDIAN ($$, MER24);
-           SET_TZ ($$, ($6 < 0
-                        ? -$6 % 100 + (-$6 / 100) * 60
-                        : - ($6 % 100 + ($6 / 100) * 60)));
-         }
-       ;
-
-zone   : T_ZONE
-          {
-           DATE_INIT ($$);
-           SET_TZ ($$, $1);
-         }
-       | T_DAYZONE
-          {
-           DATE_INIT ($$);
-           SET_TZ ($$, $1 - 60);
-         }
-       | T_ZONE T_DST
-          {
-           DATE_INIT ($$);
-           SET_TZ ($$, $1 - 60);
-         }
-       ;
-
-day    : T_DAY
-          {
-           DATE_INIT ($$);
-           SET_ORDINAL ($$, 1);
-           SET_NUMBER ($$, $1);
-         }
-       | T_DAY ','
-          {
-           DATE_INIT ($$);
-           SET_ORDINAL ($$, 1);
-           SET_NUMBER ($$, $1);
-         }
-       | T_UNUMBER T_DAY
-          {
-           DATE_INIT ($$);
-           SET_ORDINAL ($$, $1);
-           SET_NUMBER ($$, $2);
-         }
-       ;
-
-date   : T_UNUMBER '/' T_UNUMBER
-          {
-           DATE_INIT ($$);
-           SET_MONTH ($$, $1);
-           SET_DAY ($$, $3);
-         }
-       | T_UNUMBER '/' T_UNUMBER '/' T_UNUMBER
-          {
-           DATE_INIT ($$);
-           /* Interpret as YYYY/MM/DD if $1 >= 1000, otherwise as MM/DD/YY.
-              The goal in recognizing YYYY/MM/DD is solely to support legacy
-              machine-generated dates like those in an RCS log listing.  If
-              you want portability, use the ISO 8601 format.  */
-           if ($1 >= 1000)
-             {
-               SET_YEAR ($$, $1);
-               SET_MONTH ($$, $3);
-               SET_DAY ($$, $5);
-             }
-           else
-             {
-               SET_MONTH ($$, $1);
-               SET_DAY ($$, $3);
-               SET_YEAR ($$, $5);
-             }
-         }
-       | T_UNUMBER T_SNUMBER T_SNUMBER
-          {
-           DATE_INIT ($$);
-           /* ISO 8601 format.  yyyy-mm-dd.  */
-           SET_YEAR ($$, $1);
-           SET_MONTH ($$, -$2);
-           SET_DAY ($$, -$3);
-         }
-       | T_UNUMBER T_MONTH T_SNUMBER
-          {
-           /* either 17-JUN-1992 or 1992-JUN-17 */
-           DATE_INIT ($$);
-           if ($1 < 32)
-             {
-               SET_DAY ($$, $1);
-               SET_MONTH ($$, $2);
-               SET_YEAR ($$, -$3);
-             }
-           else
-             {
-               SET_DAY ($$, -$3);
-               SET_MONTH ($$, $2);
-               SET_YEAR ($$, $1);
-             }
-         }
-       | T_MONTH T_UNUMBER
-          {
-           DATE_INIT ($$);
-           SET_MONTH ($$, $1);
-           SET_DAY ($$, $2);
-         }
-       | T_MONTH T_UNUMBER ',' T_UNUMBER
-          {
-           DATE_INIT ($$);
-           SET_MONTH ($$, $1);
-           SET_DAY ($$, $2);
-           SET_YEAR ($$, $4);
-         }
-       | T_UNUMBER T_MONTH
-          {
-           DATE_INIT ($$);
-           SET_MONTH ($$, $2);
-           SET_DAY ($$, $1);
-         }
-       | T_UNUMBER T_MONTH T_UNUMBER
-          {
-           DATE_INIT ($$);
-           SET_MONTH ($$, $2);
-           SET_DAY ($$, $1);
-           SET_YEAR ($$, $3);
-         }
-        | T_DAY T_MONTH T_UNUMBER time T_UNUMBER
-          {
-           DATE_INIT ($$);
-
-           SET_ORDINAL ($$, 1);
-           SET_NUMBER ($$, $1);
-
-           SET_MONTH ($$, $2);
-           SET_DAY ($$, $3);
-           SET_YEAR ($$, $5);
-           if (pd_date_union (&$$, &$4))
-             YYERROR;
-         }
-       ;
-
-rel    : relspec T_AGO
-          {
-           $1.second = - $1.second;
-           $1.minute = - $1.minute;
-           $1.hour = - $1.hour;
-           $1.day = - $1.day;
-           $1.month = - $1.month;
-           $1.year = - $1.year;
-           $$ = $1;
-         }
-       | relspec
-       ;
-
-
-relspec : relunit
-          {
-           DATE_INIT ($$);
-           if (pd_date_union (&$$, &$1))
-             YYERROR;
-         }
-        | relspec relunit
-          {
-           if (pd_date_union (&$1, &$2))
-             YYERROR;
-           $$ = $1;
-         }
-        ;
-
-relunit        : T_UNUMBER T_YEAR_UNIT
-          {
-           DATE_INIT ($$);
-           SET_YEAR ($$, $1 * $2);
-         }
-       | T_SNUMBER T_YEAR_UNIT
-          {
-           DATE_INIT ($$);
-           SET_YEAR ($$, $1 * $2);
-         }
-       | T_YEAR_UNIT
-          {
-           DATE_INIT ($$);
-           SET_YEAR ($$, $1);
-         }
-       | T_UNUMBER T_MONTH_UNIT
-          {
-           DATE_INIT ($$);
-           SET_MONTH ($$, $1 * $2);
-         }
-       | T_SNUMBER T_MONTH_UNIT
-          {
-           DATE_INIT ($$);
-           SET_MONTH ($$, $1 * $2);
-         }
-       | T_MONTH_UNIT
-          {
-           DATE_INIT ($$);
-           SET_MONTH ($$, $1);
-         }
-       | T_UNUMBER T_DAY_UNIT
-          {
-           DATE_INIT ($$);
-           SET_DAY ($$, $1 * $2);
-         }
-       | T_SNUMBER T_DAY_UNIT
-          {
-           DATE_INIT ($$);
-           SET_DAY ($$, $1 * $2);
-         }
-       | T_DAY_UNIT
-          {
-           DATE_INIT ($$);
-           SET_DAY ($$, $1);
-         }
-       | T_UNUMBER T_HOUR_UNIT
-          {
-           DATE_INIT ($$);
-           SET_HOUR ($$, $1 * $2);
-         }
-       | T_SNUMBER T_HOUR_UNIT
-          {
-           DATE_INIT ($$);
-           SET_HOUR ($$, $1 * $2);
-         }
-       | T_HOUR_UNIT
-          {
-           DATE_INIT ($$);
-           SET_HOUR ($$, $1);
-         }
-       | T_UNUMBER T_MINUTE_UNIT
-          {
-           DATE_INIT ($$);
-           SET_MINUTE ($$, $1 * $2);
-         }
-       | T_SNUMBER T_MINUTE_UNIT
-          {
-           DATE_INIT ($$);
-           SET_MINUTE ($$, $1 * $2);
-         }
-       | T_MINUTE_UNIT
-          {
-           DATE_INIT ($$);
-           SET_MINUTE ($$, $1);
-         }
-       | T_UNUMBER T_SEC_UNIT
-          {
-           DATE_INIT ($$);
-           SET_SECOND ($$, $1 * $2);
-         }
-       | T_SNUMBER T_SEC_UNIT
-          {
-           DATE_INIT ($$);
-           SET_SECOND ($$, $1 * $2);
-         }
-       | T_SEC_UNIT
-          {
-           DATE_INIT ($$);
-           SET_SECOND ($$, $1);
-         }
-       ;
-
-o_merid        : /* empty */
-          {
-           $$ = MER24;
-         }
-       | T_MERIDIAN
-         {
-           $$ = $1;
-         }
-       ;
-
-%%
-
-#include <mailutils/types.h>
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
-#endif
-
-#include <mailutils/mutil.h>
-
-/* Month and day table. */
-static SYMBOL const month_day_tab[] = {
-  { "january", T_MONTH,  1 },
-  { "february",        T_MONTH,  2 },
-  { "march",   T_MONTH,  3 },
-  { "april",   T_MONTH,  4 },
-  { "may",     T_MONTH,  5 },
-  { "june",    T_MONTH,  6 },
-  { "july",    T_MONTH,  7 },
-  { "august",  T_MONTH,  8 },
-  { "september",T_MONTH,  9 },
-  { "sept",    T_MONTH,  9 },
-  { "october", T_MONTH, 10 },
-  { "november",        T_MONTH, 11 },
-  { "december",        T_MONTH, 12 },
-  { "sunday",  T_DAY,   0 },
-  { "monday",  T_DAY,   1 },
-  { "tuesday", T_DAY,   2 },
-  { "tues",    T_DAY,   2 },
-  { "wednesday",T_DAY,   3 },
-  { "wednes",  T_DAY,   3 },
-  { "thursday",        T_DAY,   4 },
-  { "thur",    T_DAY,   4 },
-  { "thurs",   T_DAY,   4 },
-  { "friday",  T_DAY,   5 },
-  { "saturday",        T_DAY,   6 },
-  { NULL, 0, 0 }
-};
-
-/* Time units table. */
-static SYMBOL const units_tab[] = {
-  { "year",    T_YEAR_UNIT,    1 },
-  { "month",   T_MONTH_UNIT,   1 },
-  { "fortnight",T_DAY_UNIT,    14 },
-  { "week",    T_DAY_UNIT,     7 },
-  { "day",     T_DAY_UNIT,     1 },
-  { "hour",    T_HOUR_UNIT,    1 },
-  { "minute",  T_MINUTE_UNIT,  1 },
-  { "min",     T_MINUTE_UNIT,  1 },
-  { "second",  T_SEC_UNIT,     1 },
-  { "sec",     T_SEC_UNIT,     1 },
-  { NULL, 0, 0 }
-};
-
-/* Assorted relative-time words. */
-static SYMBOL const other_tab[] = {
-  { "tomorrow",        T_MINUTE_UNIT,  1 * 24 * 60 },
-  { "yesterday",T_MINUTE_UNIT, -1 * 24 * 60 },
-  { "today",   T_MINUTE_UNIT,  0 },
-  { "now",     T_MINUTE_UNIT,  0 },
-  { "last",    T_UNUMBER,      -1 },
-  { "this",    T_MINUTE_UNIT,  0 },
-  { "next",    T_UNUMBER,      1 },
-  { "first",   T_UNUMBER,      1 },
-/*  { "second",        T_UNUMBER,      2 }, */
-  { "third",   T_UNUMBER,      3 },
-  { "fourth",  T_UNUMBER,      4 },
-  { "fifth",   T_UNUMBER,      5 },
-  { "sixth",   T_UNUMBER,      6 },
-  { "seventh", T_UNUMBER,      7 },
-  { "eighth",  T_UNUMBER,      8 },
-  { "ninth",   T_UNUMBER,      9 },
-  { "tenth",   T_UNUMBER,      10 },
-  { "eleventh",        T_UNUMBER,      11 },
-  { "twelfth", T_UNUMBER,      12 },
-  { "ago",     T_AGO,          1 },
-  { NULL, 0, 0 }
-};
-
-/* The timezone table. */
-static SYMBOL const tz_tab[] = {
-  { "gmt",     T_ZONE,     HOUR ( 0) },        /* Greenwich Mean */
-  { "ut",      T_ZONE,     HOUR ( 0) },        /* Universal (Coordinated) */
-  { "utc",     T_ZONE,     HOUR ( 0) },
-  { "wet",     T_ZONE,     HOUR ( 0) },        /* Western European */
-  { "bst",     T_DAYZONE,  HOUR ( 0) },        /* British Summer */
-  { "wat",     T_ZONE,     HOUR ( 1) },        /* West Africa */
-  { "at",      T_ZONE,     HOUR ( 2) },        /* Azores */
-#if    0
-  /* For completeness.  BST is also British Summer, and GST is
-   * also Guam Standard. */
-  { "bst",     T_ZONE,     HOUR ( 3) },        /* Brazil Standard */
-  { "gst",     T_ZONE,     HOUR ( 3) },        /* Greenland Standard */
-#endif
-#if 0
-  { "nft",     T_ZONE,     HOUR (3.5) },       /* Newfoundland */
-  { "nst",     T_ZONE,     HOUR (3.5) },       /* Newfoundland Standard */
-  { "ndt",     T_DAYZONE,  HOUR (3.5) },       /* Newfoundland Daylight */
-#endif
-  { "ast",     T_ZONE,     HOUR ( 4) },        /* Atlantic Standard */
-  { "adt",     T_DAYZONE,  HOUR ( 4) },        /* Atlantic Daylight */
-  { "est",     T_ZONE,     HOUR ( 5) },        /* Eastern Standard */
-  { "edt",     T_DAYZONE,  HOUR ( 5) },        /* Eastern Daylight */
-  { "cst",     T_ZONE,     HOUR ( 6) },        /* Central Standard */
-  { "cdt",     T_DAYZONE,  HOUR ( 6) },        /* Central Daylight */
-  { "mst",     T_ZONE,     HOUR ( 7) },        /* Mountain Standard */
-  { "mdt",     T_DAYZONE,  HOUR ( 7) },        /* Mountain Daylight */
-  { "pst",     T_ZONE,     HOUR ( 8) },        /* Pacific Standard */
-  { "pdt",     T_DAYZONE,  HOUR ( 8) },        /* Pacific Daylight */
-  { "yst",     T_ZONE,     HOUR ( 9) },        /* Yukon Standard */
-  { "ydt",     T_DAYZONE,  HOUR ( 9) },        /* Yukon Daylight */
-  { "hst",     T_ZONE,     HOUR (10) },        /* Hawaii Standard */
-  { "hdt",     T_DAYZONE,  HOUR (10) },        /* Hawaii Daylight */
-  { "cat",     T_ZONE,     HOUR (10) },        /* Central Alaska */
-  { "ahst",    T_ZONE,     HOUR (10) },        /* Alaska-Hawaii Standard */
-  { "nt",      T_ZONE,     HOUR (11) },        /* Nome */
-  { "idlw",    T_ZONE,     HOUR (12) },        /* International Date Line West 
*/
-  { "cet",     T_ZONE,     -HOUR (1) },        /* Central European */
-  { "met",     T_ZONE,     -HOUR (1) },        /* Middle European */
-  { "mewt",    T_ZONE,     -HOUR (1) },        /* Middle European Winter */
-  { "mest",    T_DAYZONE,  -HOUR (1) },        /* Middle European Summer */
-  { "mesz",    T_DAYZONE,  -HOUR (1) },        /* Middle European Summer */
-  { "swt",     T_ZONE,     -HOUR (1) },        /* Swedish Winter */
-  { "sst",     T_DAYZONE,  -HOUR (1) },        /* Swedish Summer */
-  { "fwt",     T_ZONE,     -HOUR (1) },        /* French Winter */
-  { "fst",     T_DAYZONE,  -HOUR (1) },        /* French Summer */
-  { "eet",     T_ZONE,     -HOUR (2) },        /* Eastern Europe, USSR Zone 1 
*/
-  { "bt",      T_ZONE,     -HOUR (3) },        /* Baghdad, USSR Zone 2 */
-#if 0
-  { "it",      T_ZONE,     -HOUR (3.5) },/* Iran */
-#endif
-  { "zp4",     T_ZONE,     -HOUR (4) },        /* USSR Zone 3 */
-  { "zp5",     T_ZONE,     -HOUR (5) },        /* USSR Zone 4 */
-#if 0
-  { "ist",     T_ZONE,     -HOUR (5.5) },/* Indian Standard */
-#endif
-  { "zp6",     T_ZONE,     -HOUR (6) },        /* USSR Zone 5 */
-#if    0
-  /* For completeness.  NST is also Newfoundland Standard, and SST is
-   * also Swedish Summer. */
-  { "nst",     T_ZONE,     -HOUR (6.5) },/* North Sumatra */
-  { "sst",     T_ZONE,     -HOUR (7) },        /* South Sumatra, USSR Zone 6 */
-#endif /* 0 */
-  { "wast",    T_ZONE,     -HOUR (7) },        /* West Australian Standard */
-  { "wadt",    T_DAYZONE,  -HOUR (7) },        /* West Australian Daylight */
-#if 0
-  { "jt",      T_ZONE,     -HOUR (7.5) },/* Java (3pm in Cronusland!) */
-#endif
-  { "cct",     T_ZONE,     -HOUR (8) },        /* China Coast, USSR Zone 7 */
-  { "jst",     T_ZONE,     -HOUR (9) },        /* Japan Standard, USSR Zone 8 
*/
-#if 0
-  { "cast",    T_ZONE,     -HOUR (9.5) },/* Central Australian Standard */
-  { "cadt",    T_DAYZONE,  -HOUR (9.5) },/* Central Australian Daylight */
-#endif
-  { "east",    T_ZONE,     -HOUR (10) },       /* Eastern Australian Standard 
*/
-  { "eadt",    T_DAYZONE,  -HOUR (10) },       /* Eastern Australian Daylight 
*/
-  { "gst",     T_ZONE,     -HOUR (10) },       /* Guam Standard, USSR Zone 9 */
-  { "nzt",     T_ZONE,     -HOUR (12) },       /* New Zealand */
-  { "nzst",    T_ZONE,     -HOUR (12) },       /* New Zealand Standard */
-  { "nzdt",    T_DAYZONE,  -HOUR (12) },       /* New Zealand Daylight */
-  { "idle",    T_ZONE,     -HOUR (12) },       /* International Date Line
-                                                  East */
-  {  NULL, 0, 0  }
-};
-
-/* Military timezone table. */
-static SYMBOL const mil_tz_tab[] = {
-  { "a",       T_ZONE, HOUR (  1) },
-  { "b",       T_ZONE, HOUR (  2) },
-  { "c",       T_ZONE, HOUR (  3) },
-  { "d",       T_ZONE, HOUR (  4) },
-  { "e",       T_ZONE, HOUR (  5) },
-  { "f",       T_ZONE, HOUR (  6) },
-  { "g",       T_ZONE, HOUR (  7) },
-  { "h",       T_ZONE, HOUR (  8) },
-  { "i",       T_ZONE, HOUR (  9) },
-  { "k",       T_ZONE, HOUR ( 10) },
-  { "l",       T_ZONE, HOUR ( 11) },
-  { "m",       T_ZONE, HOUR ( 12) },
-  { "n",       T_ZONE, HOUR (- 1) },
-  { "o",       T_ZONE, HOUR (- 2) },
-  { "p",       T_ZONE, HOUR (- 3) },
-  { "q",       T_ZONE, HOUR (- 4) },
-  { "r",       T_ZONE, HOUR (- 5) },
-  { "s",       T_ZONE, HOUR (- 6) },
-  { "t",       T_ZONE, HOUR (- 7) },
-  { "u",       T_ZONE, HOUR (- 8) },
-  { "v",       T_ZONE, HOUR (- 9) },
-  { "w",       T_ZONE, HOUR (-10) },
-  { "x",       T_ZONE, HOUR (-11) },
-  { "y",       T_ZONE, HOUR (-12) },
-  { "z",       T_ZONE, HOUR (  0) },
-  { NULL, 0, 0 }
-};
-
-
-
-
-/* ARGSUSED */
-static int
-yyerror (char *s MU_ARG_UNUSED)
-{
-  return 0;
-}
-
-static int
-norm_hour (int hours, MERIDIAN meridian)
-{
-  switch (meridian)
-    {
-    case MER24:
-      if (hours < 0 || hours > 23)
-       return -1;
-      return hours;
-      
-    case MERam:
-      if (hours < 1 || hours > 12)
-       return -1;
-      if (hours == 12)
-       hours = 0;
-      return hours;
-      
-    case MERpm:
-      if (hours < 1 || hours > 12)
-       return -1;
-      if (hours == 12)
-       hours = 0;
-      return hours + 12;
-      
-    default:
-      abort ();
-    }
-  /* NOTREACHED */
-}
-
-static int
-norm_year (int year)
-{
-  if (year < 0)
-    year = -year;
-  
-  /* XPG4 suggests that years 00-68 map to 2000-2068, and
-     years 69-99 map to 1969-1999.  */
-  if (year < 69)
-    year += 2000;
-  else if (year < 100)
-    year += 1900;
-
-  return year;
-}
-
-static int
-sym_lookup (char *buff)
-{
-  register char *p;
-  register char *q;
-  register const SYMBOL *tp;
-  int i;
-  int abbrev;
-  
-  /* Make it lowercase. */
-  for (p = buff; *p; p++)
-    if (ISUPPER ((unsigned char) *p))
-      *p = tolower (*p);
-  
-  if (strcmp (buff, "am") == 0 || strcmp (buff, "a.m.") == 0)
-    {
-      yylval.meridian = MERam;
-      return T_MERIDIAN;
-    }
-  if (strcmp (buff, "pm") == 0 || strcmp (buff, "p.m.") == 0)
-    {
-      yylval.meridian = MERpm;
-      return T_MERIDIAN;
-    }
-  
-  /* See if we have an abbreviation for a month. */
-  if (strlen (buff) == 3)
-    abbrev = 1;
-  else if (strlen (buff) == 4 && buff[3] == '.')
-    {
-      abbrev = 1;
-      buff[3] = '\0';
-    }
-  else
-    abbrev = 0;
-
-  for (tp = month_day_tab; tp->name; tp++)
-    {
-      if (abbrev)
-       {
-         if (strncmp (buff, tp->name, 3) == 0)
-           {
-             yylval.number = tp->value;
-             return tp->type;
-           }
-       }
-      else if (strcmp (buff, tp->name) == 0)
-       {
-         yylval.number = tp->value;
-         return tp->type;
-       }
-    }
-
-  for (tp = tz_tab; tp->name; tp++)
-    if (strcmp (buff, tp->name) == 0)
-      {
-       yylval.number = tp->value;
-       return tp->type;
-      }
-
-  if (strcmp (buff, "dst") == 0)
-    return T_DST;
-
-  for (tp = units_tab; tp->name; tp++)
-    if (strcmp (buff, tp->name) == 0)
-      {
-       yylval.number = tp->value;
-       return tp->type;
-      }
-
-  /* Strip off any plural and try the units table again. */
-  i = strlen (buff) - 1;
-  if (buff[i] == 's')
-    {
-      buff[i] = '\0';
-      for (tp = units_tab; tp->name; tp++)
-       if (strcmp (buff, tp->name) == 0)
-         {
-           yylval.number = tp->value;
-           return tp->type;
-         }
-      buff[i] = 's';           /* Put back for "this" in other_tab. */
-    }
-
-  for (tp = other_tab; tp->name; tp++)
-    if (strcmp (buff, tp->name) == 0)
-      {
-       yylval.number = tp->value;
-       return tp->type;
-      }
-
-  /* Military timezones. */
-  if (buff[1] == '\0' && ISALPHA ((unsigned char) *buff))
-    {
-      for (tp = mil_tz_tab; tp->name; tp++)
-       if (strcmp (buff, tp->name) == 0)
-         {
-           yylval.number = tp->value;
-           return tp->type;
-         }
-    }
-
-  /* Drop out any periods and try the timezone table again. */
-  for (i = 0, p = q = buff; *q; q++)
-    if (*q != '.')
-      *p++ = *q;
-    else
-      i++;
-  *p = '\0';
-  if (i)
-    for (tp = tz_tab; tp->name; tp++)
-      if (strcmp (buff, tp->name) == 0)
-       {
-         yylval.number = tp->value;
-         return tp->type;
-       }
-
-  return T_ID;
-}
-
-static int
-yylex ()
-{
-  register unsigned char c;
-  register char *p;
-  char buff[20];
-  int count;
-  int sign;
-
-  for (;;)
-    {
-      while (ISSPACE ((unsigned char) *yyinput))
-       yyinput++;
-
-      if (ISDIGIT (c = *yyinput) || c == '-' || c == '+')
-       {
-         if (c == '-' || c == '+')
-           {
-             sign = c == '-' ? -1 : 1;
-             if (!ISDIGIT (*++yyinput))
-               /* skip the '-' sign */
-               continue;
-           }
-         else
-           sign = 0;
-         for (yylval.number = 0; ISDIGIT (c = *yyinput++);)
-           yylval.number = 10 * yylval.number + c - '0';
-         yyinput--;
-         if (sign < 0)
-           yylval.number = -yylval.number;
-         return sign ? T_SNUMBER : T_UNUMBER;
-       }
-      if (ISALPHA (c))
-       {
-         for (p = buff; (c = *yyinput++, ISALPHA (c)) || c == '.';)
-           if (p < &buff[sizeof buff - 1])
-             *p++ = c;
-         *p = '\0';
-         yyinput--;
-         return sym_lookup (buff);
-       }
-      if (c != '(')
-       return *yyinput++;
-      count = 0;
-      do
-       {
-         c = *yyinput++;
-         if (c == '\0')
-           return c;
-         if (c == '(')
-           count++;
-         else if (c == ')')
-           count--;
-       }
-      while (count > 0);
-    }
-}
-
-#define TM_YEAR_ORIGIN 1900
-
-/* Yield A - B, measured in seconds.  */
-static long
-difftm (struct tm *a, struct tm *b)
-{
-  int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
-  int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
-  long days = (
-  /* difference in day of year */
-               a->tm_yday - b->tm_yday
-  /* + intervening leap days */
-               + ((ay >> 2) - (by >> 2))
-               - (ay / 100 - by / 100)
-               + ((ay / 100 >> 2) - (by / 100 >> 2))
-  /* + difference in years * 365 */
-               + (long) (ay - by) * 365
-  );
-  return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour))
-               + (a->tm_min - b->tm_min))
-         + (a->tm_sec - b->tm_sec));
-}
-
-int
-mu_parse_date (const char *p, time_t *rettime, const time_t *now)
-{
-  struct tm tm, tm0, *tmp;
-  time_t start;
-
-  yyinput = p;
-  start = now ? *now : time ((time_t *) NULL);
-  tmp = localtime (&start);
-  if (!tmp)
-    return -1;
-
-  memset (&tm, 0, sizeof tm);
-  tm.tm_isdst = tmp->tm_isdst;
-
-  if (yyparse ())
-    return -1;
-  
-  if (!MASK_IS_SET (pd.date.mask, PD_MASK_YEAR))
-    __SET_YEAR (pd.date, tmp->tm_year + TM_YEAR_ORIGIN, return -1);
-  if (!MASK_IS_SET (pd.date.mask, PD_MASK_MONTH))
-    __SET_MONTH (pd.date, tmp->tm_mon + 1, return -1);
-  if (!MASK_IS_SET (pd.date.mask, PD_MASK_DAY))
-    __SET_DAY (pd.date, tmp->tm_mday, return -1);
-  if (!MASK_IS_SET (pd.date.mask, PD_MASK_HOUR))
-    __SET_HOUR (pd.date, tmp->tm_hour, return -1);
-  if (!MASK_IS_SET (pd.date.mask, PD_MASK_MERIDIAN))
-    __SET_MERIDIAN (pd.date, MER24, return -1);
-  if (!MASK_IS_SET (pd.date.mask, PD_MASK_MINUTE))
-    __SET_MINUTE (pd.date, tmp->tm_min, return -1);
-  if (!MASK_IS_SET (pd.date.mask, PD_MASK_SECOND))
-    __SET_SECOND (pd.date, tmp->tm_sec, return -1);
-  
-  tm.tm_year = norm_year (pd.date.year) - TM_YEAR_ORIGIN + pd.rel.year;
-  tm.tm_mon = pd.date.month - 1 + pd.rel.month;
-  tm.tm_mday = pd.date.day + pd.rel.day;
-  if (MASK_TEST (pd.date.mask, PD_MASK_TIME)
-      || (pd.rel.mask && !MASK_TEST (pd.date.mask, PD_MASK_DATE)
-         && !MASK_TEST (pd.date.mask, PD_MASK_DOW)))
-    {
-      tm.tm_hour = norm_hour (pd.date.hour, pd.date.meridian);
-      if (tm.tm_hour < 0)
-       return -1;
-      tm.tm_min = pd.date.minute;
-      tm.tm_sec = pd.date.second;
-    }
-  else
-    {
-      tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
-    }
-  tm.tm_hour += pd.rel.hour;
-  tm.tm_min += pd.rel.minute;
-  tm.tm_sec += pd.rel.second;
-
-  /* Let mktime deduce tm_isdst if we have an absolute timestamp,
-     or if the relative timestamp mentions days, months, or years.  */
-  if (MASK_TEST (pd.date.mask, PD_MASK_DATE | PD_MASK_DOW | PD_MASK_TIME)
-      || MASK_TEST (pd.rel.mask, PD_MASK_DOW | PD_MASK_MONTH | PD_MASK_YEAR))
-    tm.tm_isdst = -1;
-
-  tm0 = tm;
-
-  start = mktime (&tm);
-
-  if (start == (time_t) -1)
-    {
-
-      /* Guard against falsely reporting errors near the time_t boundaries
-         when parsing times in other time zones.  For example, if the min
-         time_t value is 1970-01-01 00:00:00 UTC and we are 8 hours ahead
-         of UTC, then the min localtime value is 1970-01-01 08:00:00; if
-         we apply mktime to 1970-01-01 00:00:00 we will get an error, so
-         we apply mktime to 1970-01-02 08:00:00 instead and adjust the time
-         zone by 24 hours to compensate.  This algorithm assumes that
-         there is no DST transition within a day of the time_t boundaries.  */
-      if (MASK_TEST (pd.date.mask, PD_MASK_TZ))
-       {
-         tm = tm0;
-         if (tm.tm_year <= EPOCH - TM_YEAR_ORIGIN)
-           {
-             tm.tm_mday++;
-             pd.date.tz -= 24 * 60;
-           }
-         else
-           {
-             tm.tm_mday--;
-             pd.date.tz += 24 * 60;
-           }
-         start = mktime (&tm);
-       }
-
-      if (start == (time_t) -1)
-       return -1;
-    }
-
-  if (MASK_TEST (pd.date.mask, PD_MASK_DOW)
-      && !MASK_TEST (pd.date.mask, PD_MASK_DATE))
-    {
-      tm.tm_mday += ((pd.date.number - tm.tm_wday + 7) % 7
-                    + 7 * (pd.date.ordinal - (0 < pd.date.ordinal)));
-      start = mktime (&tm);
-      if (start == (time_t) -1)
-       return -1;
-    }
-  
-  if (MASK_TEST (pd.date.mask, PD_MASK_TZ))
-    {
-      long delta;
-      struct tm *gmt = gmtime (&start);
-      if (gmt)
-       {
-         delta = pd.date.tz * 60L + difftm (&tm, gmt);
-         if ((start + delta < start) != (delta < 0))
-           return -1;          /* time_t overflow */
-         start += delta;
-       }
-    }
-  
-  *rettime = start;
-  return 0;
-}
-
-#ifdef STANDALONE
-int
-main (int argc, char *argv[])
-{
-  char buff[MAX_BUFF_LEN + 1];
-  time_t d;
-
-  if (argc > 1 && strcmp (argv[1], "-d") == 0)
-    yydebug++;
-  printf ("Enter date, or blank line to exit.\n\t> ");
-  fflush (stdout);
-
-  buff[MAX_BUFF_LEN] = 0;
-  while (fgets (buff, MAX_BUFF_LEN, stdin) && buff[0])
-    {
-      if (mu_parse_date (buff, &d, NULL))
-       printf ("Bad format - couldn't convert.\n");
-      else
-       printf ("%s", ctime (&d));
-      printf ("\t> ");
-      fflush (stdout);
-    }
-  exit (0);
-  /* NOTREACHED */
-}
-
-#endif
diff --git a/libmailutils/permstr.c b/libmailutils/permstr.c
deleted file mode 100644
index d3d184a..0000000
--- a/libmailutils/permstr.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2008, 2010 Free Software Foundation, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library; if not, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#if HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <mailutils/stream.h>
-#include <mailutils/mutil.h>
-#include <mailutils/errno.h>
-
-#define FILE_PERM_READ 0x1
-#define FILE_PERM_WRITE 0x2
-
-static int
-parse_perm_bits (int *pmode, const char *str, const char **endp)
-{
-  switch (*str)
-    {
-    case '+':
-    case '=':
-      str++;
-      break;
-
-    default:
-      if (endp)
-       *endp = str;
-      return 1;
-    }
-
-  for (; *str; str++)
-    {
-      switch (*str)
-       {
-       case 'r':
-         *pmode |= FILE_PERM_READ;
-         break;
-
-       case 'w':
-         *pmode |= FILE_PERM_WRITE;
-         break;
-
-       case ',':
-         if (endp)
-           *endp = str;
-         return 0;
-         
-       default:
-         if (endp)
-           *endp = str;
-         return 1;
-       }
-    }
-  if (endp)
-    *endp = str;
-  return 0;
-}
-
-/* Parse a MU stream permission specification in form:
-
-      g(+|=)[wr]+,o(+|=)[wr]+
-
-   Return 0 on success.
-   On failure, return MU_ERR_FAILURE and point endp to the offending character.
-*/
-int
-mu_parse_stream_perm_string (int *pmode, const char *str, const char **endp)
-{
-  int mode = 0;
-  int f;
-  while (*str)
-    {
-      switch (*str)
-       {
-       case 'g':
-         if (parse_perm_bits (&f, str + 1, &str))
-           {
-             if (endp)
-               *endp = str;
-             return MU_ERR_FAILURE;
-           }
-         if (f & FILE_PERM_READ)
-           mode |= MU_STREAM_IRGRP;
-         if (f & FILE_PERM_WRITE)
-           mode |= MU_STREAM_IWGRP;
-         break;
-         
-       case 'o':
-         if (parse_perm_bits (&f, str + 1, &str))
-           {
-             if (endp)
-               *endp = str;
-             return MU_ERR_FAILURE;
-           }
-         if (f & FILE_PERM_READ)
-           mode |= MU_STREAM_IROTH;
-         if (f & FILE_PERM_WRITE)
-           mode |= MU_STREAM_IWOTH;
-         break;
-         
-       default:
-         if (endp)
-           *endp = str;
-         return MU_ERR_FAILURE;
-       }
-      if (*str == ',')
-       str++;
-    }
-  *pmode = mode;
-  if (endp)
-    *endp = str;
-  return 0;
-}
-      
diff --git a/libmailutils/progmailer.c b/libmailutils/progmailer.c
deleted file mode 100644
index f39440f..0000000
--- a/libmailutils/progmailer.c
+++ /dev/null
@@ -1,314 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2006, 2007, 2008, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <signal.h>
-#include <sysexits.h>
-
-#include <sys/types.h>
-#include <sys/wait.h>
-
-#include <mailutils/debug.h>
-#include <mailutils/error.h>
-#include <mailutils/errno.h>
-#include <mailutils/stream.h>
-#include <mailutils/header.h>
-#include <mailutils/body.h>
-#include <mailutils/message.h>
-#include <mailutils/progmailer.h>
-#include <mailutils/mutil.h>
-#include <mailutils/cstr.h>
-
-struct _mu_progmailer
-{
-  int fd;
-  pid_t pid;
-  RETSIGTYPE (*sighandler)();
-  mu_debug_t debug;
-  char *command;
-};
-
-/* Close FD unless it is part of pipe P */
-#define SCLOSE(fd,p) if (p[0]!=fd&&p[1]!=fd) close(fd)
-
-int
-mu_progmailer_create (struct _mu_progmailer **ppm)
-{
-  struct _mu_progmailer *pm = malloc (sizeof (*pm));
-  if (!pm)
-    return ENOMEM;
-  pm->fd = -1;
-  pm->pid = -1;
-  pm->sighandler = SIG_ERR;
-  pm->debug = NULL;
-  pm->command = NULL;
-  *ppm = pm;
-  return 0;
-}
-
-int
-mu_progmailer_set_command (mu_progmailer_t pm, const char *command)
-{
-  if (!pm)
-    return EINVAL;
-  free (pm->command);
-  if (command)
-    {
-      pm->command = strdup (command);
-      if (!pm->command)
-       return EINVAL;
-    }
-  else
-    pm->command = NULL;
-  return 0;
-}
-
-int
-mu_progmailer_sget_command (mu_progmailer_t pm, const char **command)
-{
-  if (!pm)
-    return EINVAL;
-  *command = pm->command;
-  return 0;
-}
-
-int
-mu_progmailer_set_debug (mu_progmailer_t pm, mu_debug_t debug)
-{
-  if (!pm)
-    return EINVAL;
-  pm->debug = debug;
-  return 0;
-}
-
-void
-mu_progmailer_destroy (struct _mu_progmailer **ppm)
-{
-  if (*ppm)
-    {
-      free ((*ppm)->command);
-      free (*ppm);
-      *ppm = NULL;
-    }
-}
-
-int
-mu_progmailer_open (struct _mu_progmailer *pm, char **argv)
-{
-  int tunnel[2];
-  int status = 0;
-  int i;
-
-  if (!pm || !argv)
-    return EINVAL;
-  
-  if ((pm->sighandler = signal (SIGCHLD, SIG_DFL)) == SIG_ERR)
-    {
-      status = errno;
-      MU_DEBUG1 (pm->debug, MU_DEBUG_ERROR,
-                "setting SIGCHLD failed: %s\n", mu_strerror (status));
-      return status;
-    }
-      
-  if (pipe (tunnel) == 0)
-    {
-      pm->fd = tunnel[1];
-      pm->pid = fork ();
-      if (pm->pid == 0)        /* Child.  */
-       {
-         SCLOSE (STDIN_FILENO, tunnel);
-         SCLOSE (STDOUT_FILENO, tunnel);
-         SCLOSE (STDERR_FILENO, tunnel);
-         close (tunnel[1]);
-         dup2 (tunnel[0], STDIN_FILENO);
-         execv (pm->command ? pm->command : argv[0], argv);
-         exit (errno ? EX_CANTCREAT : 0);
-       }
-      else if (pm->pid == -1)
-       {
-         status = errno;
-         MU_DEBUG1 (pm->debug, MU_DEBUG_ERROR,
-                    "fork failed: %s\n", mu_strerror (status));
-       }
-    }
-  else
-    {
-      status = errno;
-      MU_DEBUG1 (pm->debug, MU_DEBUG_ERROR,
-                "pipe() failed: %s\n", mu_strerror (status));
-    }
-  MU_DEBUG1 (pm->debug, MU_DEBUG_TRACE, "exec %s argv:", pm->command);
-  for (i = 0; argv[i]; i++)
-    MU_DEBUG1 (pm->debug, MU_DEBUG_TRACE, " %s", argv[i]);
-  MU_DEBUG (pm->debug, MU_DEBUG_TRACE, "\n");
-  close (tunnel[0]);
-
-  if (status != 0)
-    close (pm->fd);
-  return status;
-}
-
-int
-mu_progmailer_send (struct _mu_progmailer *pm, mu_message_t msg)
-{
-  int status;
-  mu_stream_t stream = NULL;
-  char buffer[512];
-  size_t len = 0;
-  int rc;
-  mu_header_t hdr;
-  mu_body_t body;
-  int found_nl = 0;
-  int exit_status;
-       
-  if (!pm || !msg)
-    return EINVAL;
-  mu_message_get_header (msg, &hdr);
-  status = mu_header_get_streamref (hdr, &stream);
-  if (status)
-    {
-      MU_DEBUG1 (pm->debug, MU_DEBUG_ERROR,
-                "cannot get header stream: %s\n", mu_strerror (status));
-      return status;
-    }
-  MU_DEBUG (pm->debug, MU_DEBUG_TRACE, "Sending headers...\n");
-  mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
-  while ((status = mu_stream_readline (stream, buffer, sizeof (buffer),
-                                      &len)) == 0
-        && len != 0)
-    {
-      if (mu_c_strncasecmp (buffer, MU_HEADER_FCC, sizeof (MU_HEADER_FCC) - 1))
-       {
-         MU_DEBUG1 (pm->debug, MU_DEBUG_PROT, "Header: %s", buffer);
-         if (write (pm->fd, buffer, len) == -1)
-           {
-             status = errno;
-             
-             MU_DEBUG1 (pm->debug, MU_DEBUG_TRACE,
-                        "write failed: %s\n", strerror (status));
-             break;
-           }
-       }
-      found_nl = (len == 1 && buffer[0] == '\n');
-    }
-
-  if (!found_nl)
-    {
-      if (write (pm->fd, "\n", 1) == -1)
-       {
-         status = errno;
-               
-         MU_DEBUG1 (pm->debug, MU_DEBUG_TRACE,
-                    "write failed: %s\n", strerror (status));
-       }
-    }
-  mu_stream_destroy (&stream);
-  
-  MU_DEBUG (pm->debug, MU_DEBUG_TRACE, "Sending body...\n");
-  mu_message_get_body (msg, &body);
-  status = mu_body_get_streamref (body, &stream);
-  if (status)
-    {
-      MU_DEBUG1 (pm->debug, MU_DEBUG_ERROR,
-                "cannot get body stream: %s\n", mu_strerror (status));
-      return status;
-    }
-
-  mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
-  while ((status = mu_stream_read (stream, buffer, sizeof (buffer),
-                                  &len)) == 0
-        && len != 0)
-    {
-      if (write (pm->fd, buffer, len) == -1)
-       {
-         status = errno;
-         
-         MU_DEBUG1 (pm->debug, MU_DEBUG_TRACE,
-                    "write failed: %s\n", strerror (status));
-         break;
-       }
-    }
-  mu_body_get_streamref (body, &stream);
-
-  close (pm->fd);
-
-  rc = waitpid (pm->pid, &exit_status, 0);
-  if (status == 0)
-    {
-      if (rc < 0)
-       {
-         if (errno == ECHILD)
-           status = 0;
-         else
-           { 
-             status = errno;
-             MU_DEBUG2 (pm->debug, MU_DEBUG_TRACE,
-                        "waitpid(%lu) failed: %s\n",
-                        (unsigned long) pm->pid, strerror (status));
-           }
-       }
-      else if (WIFEXITED (exit_status))
-       {
-         exit_status = WEXITSTATUS (exit_status);
-         MU_DEBUG2 (pm->debug, MU_DEBUG_TRACE,
-                    "%s exited with: %d\n",
-                    pm->command, exit_status);
-         status = (exit_status == 0) ? 0 : MU_ERR_PROCESS_EXITED;
-       }
-      else if (WIFSIGNALED (exit_status))
-       status = MU_ERR_PROCESS_SIGNALED;
-      else
-       status = MU_ERR_PROCESS_UNKNOWN_FAILURE;
-    }
-  pm->pid = -1;
-  return status;
-}
-
-int
-mu_progmailer_close (struct _mu_progmailer *pm)
-{
-  int status = 0;
-
-  if (!pm)
-    return EINVAL;
-  
-  if (pm->pid > 0)
-    {
-      kill (SIGTERM, pm->pid);
-      pm->pid = -1;
-    }
-
-  if (pm->sighandler != SIG_ERR
-      && signal (SIGCHLD, pm->sighandler) == SIG_ERR)
-    {
-      status = errno;
-      MU_DEBUG1 (pm->debug, MU_DEBUG_ERROR,
-                "resetting SIGCHLD failed: %s\n", mu_strerror (status));
-    }
-  pm->sighandler = SIG_ERR;
-  return status;
-}
diff --git a/libmailutils/property.c b/libmailutils/property.c
deleted file mode 100644
index 435d8e2..0000000
--- a/libmailutils/property.c
+++ /dev/null
@@ -1,192 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2008, 2010 Free
-   Software Foundation, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library; if not, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
-#endif
-
-#include <mailutils/sys/property.h>
-#include <mailutils/errno.h>
-#include <mailutils/assoc.h>
-#include <stdlib.h>
-
-static void
-prop_free_value (void *data)
-{
-  struct property_item *item = data;
-  free (item->value);
-}
-
-int
-mu_property_create (mu_property_t *pp, void *owner)
-{
-  int rc;
-  mu_property_t prop;
-  if (pp == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  prop = calloc (1, sizeof *prop);
-  if (prop == NULL)
-    return ENOMEM;
-  rc = mu_assoc_create (&prop->assoc, sizeof (struct property_item), 0);
-  if (rc)
-    {
-      free (prop);
-      return rc;
-    }
-  mu_assoc_set_free (prop->assoc, prop_free_value);
-  mu_monitor_create (&prop->lock, 0, prop);
-  prop->owner = owner;
-  *pp = prop;
-  return 0;
-}
-
-void
-mu_property_destroy (mu_property_t *pp, void *owner)
-{
-  if (pp && *pp)
-    {
-      mu_property_t prop = *pp;
-      if (prop->owner == owner)
-       {
-         /* Destroy the list and is properties.  */
-         mu_monitor_wrlock (prop->lock);
-         mu_assoc_destroy (&prop->assoc);
-         mu_monitor_unlock (prop->lock);
-         mu_monitor_destroy (&prop->lock, prop);
-         free (prop);
-       }
-      *pp = NULL;
-    }
-}
-
-void *
-mu_property_get_owner (mu_property_t prop)
-{
-  return (prop == NULL) ? NULL : prop->owner;
-}
-
-int
-mu_property_set_value (mu_property_t prop, const char *key, const char *value,
-                      int overwrite)
-{
-  struct property_item *item;
-  int rc;
-
-  if (!prop)
-    return EINVAL;
-  rc = mu_assoc_ref_install (prop->assoc, key, (void **)&item);
-  if (rc == MU_ERR_NOENT)
-    {
-      item->value = strdup (value);
-    }
-  else if (overwrite)
-    {
-      free (item->value);
-      item->value = strdup (value);
-    }
-  else
-    return 0;
-  
-  if (!item->value)
-    {
-      mu_assoc_remove (prop->assoc, key);
-      return ENOMEM;
-    }
-
-  return 0;
-}
-  
-int
-mu_property_sget_value (mu_property_t prop, const char *key,
-                       const char **buffer)
-{
-  struct property_item *item;
-
-  if (!prop)
-    return EINVAL;
-  item = mu_assoc_ref (prop->assoc, key);
-  if (item == NULL)
-    return MU_ERR_NOENT;
-  if (buffer)
-    *buffer = item->value;
-  return 0;
-}
-
-int
-mu_property_aget_value (mu_property_t prop, const char *key,
-                       char **buffer)
-{
-  const char *value;
-  int rc = mu_property_sget_value (prop, key, &value);
-  if (rc == 0)
-    {
-      if ((*buffer = strdup (value)) == NULL)
-       return ENOMEM;
-    }
-  return rc;
-}
-
-int
-mu_property_get_value (mu_property_t prop, const char *key, char *buffer,
-                      size_t buflen, size_t *n)
-{
-  size_t len = 0;
-  const char *value;
-  int rc = mu_property_sget_value (prop, key, &value);
-  if (rc == 0)
-    {
-      len = strlen (value) + 1;
-      if (buffer && buflen)
-       {
-         if (buflen < len)
-           len = buflen;
-         len--;
-         memcpy (buffer, value, len);
-         buffer[len] = 0;
-       }
-    }
-  if (n)
-    *n = len;
-  return rc;
-}
-
-int
-mu_property_is_set (mu_property_t prop, const char *key)
-{
-  struct property_item *item = mu_assoc_ref (prop->assoc, key);
-  return (item == NULL) ? 0 : 1;
-}
-
-int
-mu_property_set (mu_property_t prop, const char *key)
-{
-  return mu_property_set_value (prop, key, "", 1);
-}
-
-int
-mu_property_unset (mu_property_t prop, const char *key)
-{
-  if (!prop)
-    return EINVAL;
-  return mu_assoc_remove (prop->assoc, key);
-}
-  
diff --git a/libmailutils/refcount.c b/libmailutils/refcount.c
deleted file mode 100644
index 1be1fc6..0000000
--- a/libmailutils/refcount.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2003, 2004, 2007, 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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <errno.h>
-
-#include <mailutils/errno.h>
-#include <mailutils/monitor.h>
-#include <mailutils/refcount.h>
-
-struct _mu_refcount
-{
-  unsigned int ref;
-  mu_monitor_t lock;
-};
-
-int
-mu_refcount_create (mu_refcount_t *prefcount)
-{
-  int status = 0;
-  mu_refcount_t refcount;
-  if (prefcount == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  refcount = calloc (1, sizeof *refcount);
-  if (refcount != NULL)
-    {
-      refcount->ref = 1;
-      status = mu_monitor_create (&refcount->lock, 0, refcount);
-      if (status == 0)
-       {
-         *prefcount = refcount;
-       }
-      else
-       {
-         free (refcount);
-       }
-    }
-  else
-    {
-      status = ENOMEM;
-    }
-  return status;
-}
-
-unsigned
-mu_refcount_value (mu_refcount_t refcount)
-{
-  return refcount ? refcount->ref : 0;
-}
-
-void
-mu_refcount_destroy (mu_refcount_t *prefcount)
-{
-  if (prefcount && *prefcount)
-    {
-      mu_refcount_t refcount = *prefcount;
-      mu_monitor_destroy (&refcount->lock, refcount);
-      free (refcount);
-      *prefcount = NULL;
-    }
-}
-
-unsigned
-mu_refcount_inc (mu_refcount_t refcount)
-{
-  int count = 0;
-  if (refcount)
-    {
-      mu_monitor_wrlock (refcount->lock);
-      count = ++refcount->ref;
-      mu_monitor_unlock (refcount->lock);
-    }
-  return count;
-}
-
-unsigned
-mu_refcount_dec (mu_refcount_t refcount)
-{
-  int count = 0;
-  if (refcount)
-    {
-      mu_monitor_wrlock (refcount->lock);
-      if (refcount->ref)
-       count = --refcount->ref;
-      mu_monitor_unlock (refcount->lock);
-    }
-  return count;
-}
diff --git a/libmailutils/registrar.c b/libmailutils/registrar.c
deleted file mode 100644
index a1a2b4f..0000000
--- a/libmailutils/registrar.c
+++ /dev/null
@@ -1,443 +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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
-#endif
-
-#include <mailutils/iterator.h>
-#include <mailutils/list.h>
-#include <mailutils/monitor.h>
-#include <mailutils/errno.h>
-#include <mailutils/nls.h>
-#include <mailutils/error.h>
-#include <mailutils/url.h>
-#include <mailutils/mutil.h>
-#include <mailutils/sys/registrar.h>
-
-/* NOTE: We will leak here since the monitor and the registrar will never
-   be released. That's ok we can live with this, it's only done once.  */
-static mu_list_t registrar_list;
-struct mu_monitor registrar_monitor = MU_MONITOR_INITIALIZER;
-
-static mu_record_t mu_default_record;
-
-void
-mu_registrar_set_default_record (mu_record_t record)
-{
-  mu_default_record = record;
-}
-
-int
-mu_registrar_get_default_record (mu_record_t *prec)
-{
-  if (mu_default_record)
-    {
-      if (prec)
-       *prec = mu_default_record;
-      return 0;
-    }
-  return MU_ERR_NOENT;
-}
-
-int
-mu_registrar_set_default_scheme (const char *scheme)
-{
-  int status;
-  mu_record_t rec;
-  
-  status = mu_registrar_lookup_scheme (scheme, &rec);
-  if (status == 0)
-    mu_default_record = rec;
-  return status;
-}
-
-const char *
-mu_registrar_get_default_scheme ()
-{
-  return mu_default_record ? mu_default_record->scheme : NULL;
-}
-
-static int
-_registrar_get_list (mu_list_t *plist)
-{
-  int status = 0;
-
-  if (plist == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  mu_monitor_wrlock (&registrar_monitor);
-  if (registrar_list == NULL)
-    status = mu_list_create (&registrar_list);
-  *plist = registrar_list;
-  mu_monitor_unlock (&registrar_monitor);
-  return status;
-}
-
-/* Provided for backward compatibility */
-int
-mu_registrar_get_list (mu_list_t *plist)
-{
-  static int warned;
-
-  if (!warned)
-    {
-      mu_error (_("program uses mu_registrar_get_list(), which is 
deprecated"));
-      warned = 1;
-    }
-  return _registrar_get_list (plist);
-}
-
-int
-mu_registrar_get_iterator (mu_iterator_t *pitr)
-{
-  int status = 0;
-  if (pitr == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  mu_monitor_wrlock (&registrar_monitor);
-  if (registrar_list == NULL)
-    {
-      status = mu_list_create (&registrar_list);
-      if (status)
-       return status;
-    }
-  status = mu_list_get_iterator (registrar_list, pitr);
-  mu_monitor_unlock (&registrar_monitor);
-  return status;
-}
-
-int
-mu_registrar_lookup_scheme (const char *scheme, mu_record_t *precord)
-{
-  size_t len;
-  mu_iterator_t iterator;
-  int status = mu_registrar_get_iterator (&iterator);
-  if (status != 0)
-    return status;
-  status = MU_ERR_NOENT;
-  len = strcspn (scheme, ":");
-  for (mu_iterator_first (iterator); !mu_iterator_is_done (iterator);
-       mu_iterator_next (iterator))
-    {
-      mu_record_t record;
-      mu_iterator_current (iterator, (void **)&record);
-      if (strlen (record->scheme) == len
-         && memcmp (record->scheme, scheme, len) == 0)
-       {
-         if (precord)
-           *precord = record;
-         status = 0;
-         break;
-       }
-    }
-  mu_iterator_destroy (&iterator);
-  return status;
-}
-
-int
-mu_registrar_lookup_url (mu_url_t url, int flags,
-                        mu_record_t *precord, int *pflags)
-{
-  mu_iterator_t iterator;
-  mu_record_t last_record = NULL;
-  int last_flags = 0;
-  int status = mu_registrar_get_iterator (&iterator);
-  if (status != 0)
-    return status;
-  status = MU_ERR_NOENT;
-  for (mu_iterator_first (iterator); !mu_iterator_is_done (iterator);
-       mu_iterator_next (iterator))
-    {
-      int rc;
-      mu_record_t record;
-      mu_iterator_current (iterator, (void **)&record);
-      if ((rc = mu_record_is_scheme (record, url, flags)))
-       {
-         if (rc == flags)
-           {
-             status = 0;
-             last_record = record;
-             last_flags = rc;
-             break;
-           }
-         else if (rc > last_flags)
-           {
-             status = 0;
-             last_record = record;
-             last_flags = rc;
-           }
-       }
-    }
-  mu_iterator_destroy (&iterator);
-
-  if (status == 0)
-    {
-      if (precord)
-       *precord = last_record;
-      if (pflags)
-       *pflags = last_flags;
-    }
-  else if (!mu_is_proto (mu_url_to_string (url)) /* FIXME: This check is not
-                                                   enough. */
-          && mu_registrar_get_default_record (precord) == 0)
-    {
-      status = 0;
-      if (pflags)
-       *pflags = flags & MU_FOLDER_ATTRIBUTE_FILE; /* FIXME? */
-    }
-  
-  return status;
-}
-
-int
-mu_registrar_lookup (const char *name, int flags,
-                    mu_record_t *precord, int *pflags)
-{
-  int rc;
-  mu_url_t url;
-  
-  rc = mu_url_create (&url, name);
-  if (rc)
-    return rc;
-  rc = mu_url_parse (url);
-  if (rc == 0)
-    rc = mu_registrar_lookup_url (url, flags, precord, pflags);
-  mu_url_destroy (&url);
-  return rc;
-}
-
-static int
-_compare_prio (const void *item, const void *value)
-{
-  const mu_record_t a = (const mu_record_t) item;
-  const mu_record_t b = (const mu_record_t) value;
-  if (a->priority > b->priority)
-    return 0;
-  return -1;
-}
-
-int
-mu_registrar_record (mu_record_t record)
-{
-  int status;
-  mu_list_t list;
-  mu_list_comparator_t comp;
-  
-  if (!record)
-    return 0;
-  _registrar_get_list (&list);
-  comp = mu_list_set_comparator (list, _compare_prio);
-  status = mu_list_insert (list, record, record, 1);
-  if (status == MU_ERR_NOENT)
-    status = mu_list_append (list, record);
-  mu_list_set_comparator (list, comp);
-  return status;
-}
-
-int
-mu_unregistrar_record (mu_record_t record)
-{
-  mu_list_t list;
-  _registrar_get_list (&list);
-  mu_list_remove (list, record);
-  return 0;
-}
-
-int
-mu_record_is_scheme (mu_record_t record, mu_url_t url, int flags)
-{
-  if (record == NULL)
-    return 0;
-
-  /* Overload.  */
-  if (record->_is_scheme)
-    return record->_is_scheme (record, url, flags);
-
-  if (mu_url_is_scheme (url, record->scheme))
-    return MU_FOLDER_ATTRIBUTE_ALL;
-
-  return 0;
-}
-
-int
-mu_record_set_scheme (mu_record_t record, const char *scheme)
-{
-  if (record == NULL)
-    return EINVAL;
-  record->scheme = scheme;
-  return 0;
-}
-
-int
-mu_record_set_is_scheme (mu_record_t record,
-                        int (*_is_scheme) (mu_record_t, mu_url_t, int))
-{
-  if (record == NULL)
-    return EINVAL;
-  record->_is_scheme = _is_scheme;
-  return 0;
-}
-
-int
-mu_record_get_url (mu_record_t record, int (*(*_purl)) (mu_url_t))
-{
-  if (record == NULL)
-    return EINVAL;
-  if (_purl == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  /* Overload.  */
-  if (record->_get_url)
-    return record->_get_url (record, _purl);
-  *_purl = record->_url;
-  return 0;
-}
-
-int
-mu_record_set_url (mu_record_t record, int (*_mu_url) (mu_url_t))
-{
-  if (record == NULL)
-    return EINVAL;
-  record->_url = _mu_url;
-  return 0;
-}
-
-int
-mu_record_set_get_url (mu_record_t record, int (*_get_url)
-                   (mu_record_t, int (*(*)) (mu_url_t)))
-{
-  if (record == NULL)
-    return EINVAL;
-  record->_get_url = _get_url;
-  return 0;
-}
-
-int
-mu_record_get_mailbox (mu_record_t record, int (*(*_pmailbox)) (mu_mailbox_t))
-{
-  if (record == NULL)
-    return EINVAL;
-  if (_pmailbox == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  /* Overload.  */
-  if (record->_get_mailbox)
-    return record->_get_mailbox (record, _pmailbox);
-  *_pmailbox = record->_mailbox;
-  return 0;
-}
-
-int
-mu_record_set_mailbox (mu_record_t record, int (*_mu_mailbox) (mu_mailbox_t))
-{
-  if (record)
-    return EINVAL;
-  record->_mailbox = _mu_mailbox;
-  return 0;
-}
-
-int
-mu_record_set_get_mailbox (mu_record_t record, 
-     int (*_get_mailbox) (mu_record_t, int (*(*)) (mu_mailbox_t)))
-{
-  if (record)
-    return EINVAL;
-  record->_get_mailbox = _get_mailbox;
-  return 0;
-}
-
-int
-mu_record_get_mailer (mu_record_t record, int (*(*_pmailer)) (mu_mailer_t))
-{
-  if (record == NULL)
-    return EINVAL;
-  if (_pmailer == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  /* Overload.  */
-  if (record->_get_mailer)
-    return record->_get_mailer (record, _pmailer);
-  *_pmailer = record->_mailer;
-  return 0;
-}
-
-int
-mu_record_set_mailer (mu_record_t record, int (*_mu_mailer) (mu_mailer_t))
-{
-  if (record)
-    return EINVAL;
-  record->_mailer = _mu_mailer;
-  return 0;
-}
-
-int
-mu_record_set_get_mailer (mu_record_t record, 
-  int (*_get_mailer) (mu_record_t, int (*(*)) (mu_mailer_t)))
-{
-  if (record == NULL)
-    return EINVAL;
-  record->_get_mailer = _get_mailer;
-  return 0;
-}
-
-int
-mu_record_get_folder (mu_record_t record, int (*(*_pfolder)) (mu_folder_t))
-{
-  if (record == NULL)
-    return EINVAL;
-  if (_pfolder == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  /* Overload.  */
-  if (record->_get_folder)
-    return record->_get_folder (record, _pfolder);
-  *_pfolder = record->_folder;
-  return 0;
-}
-
-int
-mu_record_set_folder (mu_record_t record, int (*_mu_folder) (mu_folder_t))
-{
-  if (record == NULL)
-    return EINVAL;
-  record->_folder = _mu_folder;
-  return 0;
-}
-
-int
-mu_record_set_get_folder (mu_record_t record, 
-   int (*_get_folder) (mu_record_t, int (*(*)) (mu_folder_t)))
-{
-  if (record == NULL)
-    return EINVAL;
-  record->_get_folder = _get_folder;
-  return 0;
-}
-
-int
-mu_record_list_p (mu_record_t record, const char *name, int flags)
-{
-  if (record == NULL)
-    return EINVAL;
-  return record == NULL
-          || !record->_list_p
-          || record->_list_p (record, name, flags);
-}
diff --git a/libmailutils/rfc2047.c b/libmailutils/rfc2047.c
deleted file mode 100644
index c30ba2f..0000000
--- a/libmailutils/rfc2047.c
+++ /dev/null
@@ -1,314 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2003, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <ctype.h>
-#include <mailutils/stream.h>
-#include <mailutils/filter.h>
-#include <mailutils/errno.h>
-#include <mailutils/mutil.h>
-
-static int
-realloc_buffer (char **bufp, size_t *bufsizep, size_t incr)
-{
-  size_t newsize = *bufsizep + incr;
-  char *newp = realloc (*bufp, newsize);
-  if (newp == NULL)
-    return 1;
-  *bufp = newp;
-  *bufsizep = newsize;
-  return 0;
-}
-
-int
-getword (char **pret, const char **pstr, int delim)
-{
-  size_t len;
-  char *ret;
-  const char *start = *pstr;
-  const char *end = strchr (start, delim);
-
-  free (*pret);
-  *pret = NULL;
-  if (!end)
-    return MU_ERR_BAD_2047_INPUT;
-  len = end - start;
-  ret = malloc (len + 1);
-  if (!ret)
-    return ENOMEM;
-  memcpy (ret, start, len);
-  ret[len] = 0;
-  *pstr = end + 1;
-  *pret = ret;
-  return 0;
-}
-    
-int
-mu_rfc2047_decode (const char *tocode, const char *input, char **ptostr)
-{
-  int status = 0;
-  const char *fromstr;
-  char *buffer;
-  size_t bufsize;
-  size_t bufpos;
-  size_t run_count = 0;
-  char *fromcode = NULL;
-  char *encoding_type = NULL;
-  char *encoded_text = NULL;
-
-#define BUFINC 128  
-#define CHKBUF(count) do {                       \
-  if (bufpos+count >= bufsize)                   \
-    {                                            \
-      size_t s = bufpos + count - bufsize;       \
-      if (s < BUFINC)                            \
-        s = BUFINC;                              \
-      if (realloc_buffer (&buffer, &bufsize, s)) \
-       {                                        \
-         free (buffer);                         \
-          free (fromcode);                       \
-          free (encoding_type);                  \
-          free (encoded_text);                   \
-         return ENOMEM;                         \
-       }                                        \
-     }                                           \
- } while (0) 
-  
-  if (!input)
-    return EINVAL;
-  if (!ptostr)
-    return MU_ERR_OUT_PTR_NULL;
-
-  fromstr = input;
-
-  /* Allocate the buffer. It is assumed that encoded string is always
-     longer than it's decoded variant, so it's safe to use its length
-     as the first estimate */
-  bufsize = strlen (fromstr) + 1;
-  buffer = malloc (bufsize);
-  if (buffer == NULL)
-    return ENOMEM;
-  bufpos = 0;
-  
-  while (*fromstr)
-    {
-      if (strncmp (fromstr, "=?", 2) == 0)
-       {
-         mu_stream_t filter = NULL;
-         mu_stream_t in_stream = NULL;
-         const char *filter_type = NULL;
-         size_t nbytes = 0, size;
-         const char *sp = fromstr + 2;
-         char tmp[128];
-         
-         status = getword (&fromcode, &sp, '?');
-         if (status)
-           break;
-         status = getword (&encoding_type, &sp, '?');
-         if (status)
-           break;
-         status = getword (&encoded_text, &sp, '?');
-         if (status)
-           break;
-         if (sp == NULL || sp[0] != '=')
-           {
-             status = MU_ERR_BAD_2047_INPUT;
-             break;
-           }
-      
-         size = strlen (encoded_text);
-
-         switch (encoding_type[0])
-           {
-            case 'b':
-           case 'B':
-             filter_type = "base64";
-             break;
-            
-            case 'q': 
-           case 'Q':
-             filter_type = "Q";
-             break;
-
-           default:
-             status = MU_ERR_BAD_2047_INPUT;
-             break;
-           }
-         
-         if (status != 0)
-           break;
-
-         mu_memory_stream_create (&in_stream, 0);
-         mu_stream_write (in_stream, encoded_text, size, NULL);
-         mu_stream_seek (in_stream, 0, MU_SEEK_SET, NULL);
-         status = mu_decode_filter (&filter, in_stream, filter_type, fromcode,
-                                    tocode);
-         mu_stream_unref (in_stream);
-         if (status != 0)
-           break;
-
-         while (mu_stream_read (filter, tmp, sizeof (tmp), &nbytes) == 0
-                && nbytes)
-           {
-             CHKBUF (nbytes);
-             memcpy (buffer + bufpos, tmp, nbytes);
-             bufpos += nbytes;
-           }
-
-         mu_stream_close (filter);
-         mu_stream_destroy (&filter);
-         
-         fromstr = sp + 1;
-         run_count = 1;
-       }
-      else if (run_count)
-       {
-         if (*fromstr == ' ' || *fromstr == '\t')
-           {
-             run_count++;
-             fromstr++;
-             continue;
-           }
-         else
-           {
-             if (--run_count)
-               {
-                 CHKBUF (run_count);
-                 memcpy (buffer + bufpos, fromstr - run_count, run_count);
-                 bufpos += run_count;
-                 run_count = 0;
-               }
-             CHKBUF (1);
-             buffer[bufpos++] = *fromstr++;
-           }
-       }
-      else
-       {
-         CHKBUF (1);
-         buffer[bufpos++] = *fromstr++;
-       }
-    }
-  
-  if (*fromstr)
-    {
-      size_t len = strlen (fromstr);
-      CHKBUF (len);
-      memcpy (buffer + bufpos, fromstr, len);
-      bufpos += len;
-    }
-
-  CHKBUF (1);
-  buffer[bufpos++] = 0;
-  
-  free (fromcode);
-  free (encoding_type);
-  free (encoded_text);
-
-  if (status)
-    free (buffer);
-  else
-    *ptostr = realloc (buffer, bufpos);
-  return status;
-}
-
-
-/**
-   Encode a header according to RFC 2047
-   
-   @param charset
-     Charset of the text to encode
-   @param encoding
-     Requested encoding (must be "base64" or "quoted-printable")
-   @param text
-     Actual text to encode
-   @param result [OUT]
-     Encoded string
-
-   @return 0 on success
-*/
-int
-mu_rfc2047_encode (const char *charset, const char *encoding,
-                  const char *text, char **result)
-{
-  mu_stream_t input_stream;
-  mu_stream_t output_stream;
-  int rc;
-  
-  if (charset == NULL || encoding == NULL || text == NULL)
-    return EINVAL;
-
-  if (strcmp (encoding, "base64") == 0)
-    encoding = "B";
-  else if (strcmp (encoding, "quoted-printable") == 0)
-    encoding = "Q";
-  else if (encoding[1] || !strchr ("BQ", encoding[0]))
-    return MU_ERR_BAD_2047_ENCODING;
-
-  rc = mu_memory_stream_create (&input_stream, 0);
-  if (rc)
-    return rc;
-  
-  mu_stream_write (input_stream, text, strlen (text), NULL);
-  mu_stream_seek (input_stream, 0, MU_SEEK_SET, NULL);
-  rc = mu_filter_create (&output_stream, input_stream,
-                        encoding, MU_FILTER_ENCODE,
-                        MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
-  if (rc == 0)
-    {
-      /* Assume strlen(qp_encoded_text) <= strlen(text) * 3 */
-      /* malloced length is composed of:
-        "=?"  
-        charset 
-        "?"
-        B or Q
-        "?" 
-        encoded_text
-        "?="
-        zero terminator */
-      
-      *result = malloc (2 + strlen (charset) + 3 + strlen (text) * 3 + 3);
-      if (*result)
-       {
-         char *p = *result;
-         size_t s;
-         
-         p += sprintf (p, "=?%s?%s?", charset, encoding);
-         
-         rc = mu_stream_read (output_stream,
-                              p,
-                              strlen (text) * 3, &s);
-
-         strcpy (p + s, "?=");
-       }
-      else
-       rc = ENOMEM;
-      mu_stream_destroy (&output_stream);
-    }
-  else
-    mu_stream_destroy (&input_stream);
-
-  return rc;
-}
diff --git a/libmailutils/secret.c b/libmailutils/secret.c
deleted file mode 100644
index e472839..0000000
--- a/libmailutils/secret.c
+++ /dev/null
@@ -1,135 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include <string.h>
-#include <mailutils/types.h>
-#include <mailutils/secret.h>
-#include <mailutils/errno.h>
-
-struct _mu_secret
-{
-  unsigned int refcnt;      /* Number of references to this object */
-  size_t length;            /* Secret length */
-  unsigned char *obptr;     /* Obfuscated data */
-  unsigned char *clptr;     /* Cleartext data */
-  unsigned int clref;       /* Number of references to clptr returned
-                              this far */
-};
-
-static unsigned char xchar;
-
-static void
-obfuscate (const unsigned char *input, unsigned char *output, size_t len)
-{
-  if (!xchar)
-    xchar = random () % 255;
-  while (len--)
-    *output++ = *input++ ^ xchar;
-}
-  
-int
-mu_secret_create (mu_secret_t *psec, const char *value, size_t len)
-{
-  mu_secret_t sec;
-  sec = calloc (1, sizeof (sec[0]) + 2 * (len + 1));
-  if (!sec)
-    return ENOMEM;
-  sec->obptr = (unsigned char*)(sec + 1);
-  sec->clptr = sec->obptr + len + 1;
-  obfuscate ((unsigned char *) value, sec->obptr, len);
-  sec->length = len;
-  *psec = sec;
-  mu_secret_ref (sec);
-  return 0;
-}
-
-int
-mu_secret_dup (mu_secret_t sec, mu_secret_t *newsec)
-{
-  const char *pass = mu_secret_password (sec);
-  int rc = mu_secret_create (newsec, pass, strlen (pass));
-  mu_secret_password_unref (sec);
-  return rc;
-}
-
-void
-mu_secret_ref (mu_secret_t sec)
-{
-  if (sec)
-    sec->refcnt++;
-}
-
-/* Decrement reference counter in SEC. If it falls to 0, free memory
-   allocated for SEC and return 0. Otherwise, return MU_ERR_EXISTS,
-   indicating that someone else is still holding it.
-   Return EINVAL if sec==NULL. */
-int
-mu_secret_unref (mu_secret_t sec)
-{
-  if (sec)
-    {
-      if (sec->refcnt)
-       sec->refcnt--;
-      if (sec->refcnt == 0)
-       {
-         memset (sec->clptr, 0, sec->length);
-         memset (sec->obptr, 0, sec->length);
-         free (sec);
-         return 0;
-       }
-      return MU_ERR_EXISTS;
-    }
-  return EINVAL;
-}
-
-void
-mu_secret_destroy (mu_secret_t *psec)
-{
-  if (psec && *psec && mu_secret_unref (*psec) == 0)
-    *psec = NULL;
-}
-
-const char *
-mu_secret_password (mu_secret_t sec)
-{
-  if (!sec)
-    return 0;
-  if (sec->clref++ == 0)
-    obfuscate (sec->obptr, sec->clptr, sec->length);
-  return (const char*) sec->clptr;
-}
-
-size_t
-mu_secret_length (mu_secret_t sec)
-{
-  if (!sec)
-    return 0;
-  return sec->length;
-}
-
-void
-mu_secret_password_unref (mu_secret_t sec)
-{
-  if (--sec->clref == 0)
-    memset (sec->clptr, 0, sec->length);
-}
-
diff --git a/libmailutils/server/Makefile.am b/libmailutils/server/Makefile.am
new file mode 100644
index 0000000..77aa154
--- /dev/null
+++ b/libmailutils/server/Makefile.am
@@ -0,0 +1,26 @@
+# 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/>.
+
+noinst_LTLIBRARIES = libserver.la
+
+libserver_la_SOURCES = \
+ acl.c\
+ server.c\
+ msrv.c\
+ ipsrv.c
+
+INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
diff --git a/libmailutils/acl.c b/libmailutils/server/acl.c
similarity index 100%
rename from libmailutils/acl.c
rename to libmailutils/server/acl.c
diff --git a/libmailutils/ipsrv.c b/libmailutils/server/ipsrv.c
similarity index 100%
rename from libmailutils/ipsrv.c
rename to libmailutils/server/ipsrv.c
diff --git a/libmailutils/msrv.c b/libmailutils/server/msrv.c
similarity index 100%
rename from libmailutils/msrv.c
rename to libmailutils/server/msrv.c
diff --git a/libmailutils/server.c b/libmailutils/server/server.c
similarity index 100%
rename from libmailutils/server.c
rename to libmailutils/server/server.c
diff --git a/libmailutils/sha1.c b/libmailutils/sha1.c
deleted file mode 100644
index 57d6377..0000000
--- a/libmailutils/sha1.c
+++ /dev/null
@@ -1,418 +0,0 @@
-/* sha1.c - Functions to compute SHA1 message digest of files or
-   memory blocks according to the NIST specification FIPS-180-1.
-
-   Copyright (C) 2000, 2001, 2003, 2004, 2005, 2006, 2010 Free Software
-   Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify it
-   under the terms of the GNU General Public License as published by the
-   Free Software Foundation; either version 2, or (at your option) any
-   later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* Written by Scott G. Miller
-   Credits:
-      Robert Klep <address@hidden>  -- Expansion function fix
-*/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <mailutils/sha1.h>
-
-#include <stddef.h>
-#include <string.h>
-
-#if USE_UNLOCKED_IO
-# include "unlocked-io.h"
-#endif
-
-#ifdef WORDS_BIGENDIAN
-# define SWAP(n) (n)
-#else
-# define SWAP(n) \
-    (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
-#endif
-
-#define BLOCKSIZE 4096
-#if BLOCKSIZE % 64 != 0
-# error "invalid BLOCKSIZE"
-#endif
-
-/* This array contains the bytes used to pad the buffer to the next
-   64-byte boundary.  (RFC 1321, 3.1: Step 1)  */
-static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ...  */ };
-
-
-/* Take a pointer to a 160 bit block of data (five 32 bit ints) and
-   initialize it to the start constants of the SHA1 algorithm.  This
-   must be called before using hash in the call to sha1_hash.  */
-void
-sha1_init_ctx (struct sha1_ctx *ctx)
-{
-  ctx->A = 0x67452301;
-  ctx->B = 0xefcdab89;
-  ctx->C = 0x98badcfe;
-  ctx->D = 0x10325476;
-  ctx->E = 0xc3d2e1f0;
-
-  ctx->total[0] = ctx->total[1] = 0;
-  ctx->buflen = 0;
-}
-
-/* Put result from CTX in first 20 bytes following RESBUF.  The result
-   must be in little endian byte order.
-
-   IMPORTANT: On some systems it is required that RESBUF is correctly
-   aligned for a 32-bit value.  */
-void *
-sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf)
-{
-  ((uint32_t *) resbuf)[0] = SWAP (ctx->A);
-  ((uint32_t *) resbuf)[1] = SWAP (ctx->B);
-  ((uint32_t *) resbuf)[2] = SWAP (ctx->C);
-  ((uint32_t *) resbuf)[3] = SWAP (ctx->D);
-  ((uint32_t *) resbuf)[4] = SWAP (ctx->E);
-
-  return resbuf;
-}
-
-/* Process the remaining bytes in the internal buffer and the usual
-   prolog according to the standard and write the result to RESBUF.
-
-   IMPORTANT: On some systems it is required that RESBUF is correctly
-   aligned for a 32-bit value.  */
-void *
-sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf)
-{
-  /* Take yet unprocessed bytes into account.  */
-  uint32_t bytes = ctx->buflen;
-  size_t size = (bytes < 56) ? 64 / 4 : 64 * 2 / 4;
-
-  /* Now count remaining bytes.  */
-  ctx->total[0] += bytes;
-  if (ctx->total[0] < bytes)
-    ++ctx->total[1];
-
-  /* Put the 64-bit file length in *bits* at the end of the buffer.  */
-  ctx->buffer[size - 2] = SWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29));
-  ctx->buffer[size - 1] = SWAP (ctx->total[0] << 3);
-
-  memcpy (&((char *) ctx->buffer)[bytes], fillbuf, (size - 2) * 4 - bytes);
-
-  /* Process last bytes.  */
-  sha1_process_block (ctx->buffer, size * 4, ctx);
-
-  return sha1_read_ctx (ctx, resbuf);
-}
-
-/* Compute SHA1 message digest for bytes read from STREAM.  The
-   resulting message digest number will be written into the 16 bytes
-   beginning at RESBLOCK.  */
-int
-sha1_stream (FILE *stream, void *resblock)
-{
-  struct sha1_ctx ctx;
-  char buffer[BLOCKSIZE + 72];
-  size_t sum;
-
-  /* Initialize the computation context.  */
-  sha1_init_ctx (&ctx);
-
-  /* Iterate over full file contents.  */
-  while (1)
-    {
-      /* We read the file in blocks of BLOCKSIZE bytes.  One call of the
-        computation function processes the whole buffer so that with the
-        next round of the loop another block can be read.  */
-      size_t n;
-      sum = 0;
-
-      /* Read block.  Take care for partial reads.  */
-      while (1)
-       {
-         n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
-
-         sum += n;
-
-         if (sum == BLOCKSIZE)
-           break;
-
-         if (n == 0)
-           {
-             /* Check for the error flag IFF N == 0, so that we don't
-                exit the loop after a partial read due to e.g., EAGAIN
-                or EWOULDBLOCK.  */
-             if (ferror (stream))
-               return 1;
-             goto process_partial_block;
-           }
-
-         /* We've read at least one byte, so ignore errors.  But always
-            check for EOF, since feof may be true even though N > 0.
-            Otherwise, we could end up calling fread after EOF.  */
-         if (feof (stream))
-           goto process_partial_block;
-       }
-
-      /* Process buffer with BLOCKSIZE bytes.  Note that
-                       BLOCKSIZE % 64 == 0
-       */
-      sha1_process_block (buffer, BLOCKSIZE, &ctx);
-    }
-
- process_partial_block:;
-
-  /* Process any remaining bytes.  */
-  if (sum > 0)
-    sha1_process_bytes (buffer, sum, &ctx);
-
-  /* Construct result in desired memory.  */
-  sha1_finish_ctx (&ctx, resblock);
-  return 0;
-}
-
-/* Compute SHA1 message digest for LEN bytes beginning at BUFFER.  The
-   result is always in little endian byte order, so that a byte-wise
-   output yields to the wanted ASCII representation of the message
-   digest.  */
-void *
-sha1_buffer (const char *buffer, size_t len, void *resblock)
-{
-  struct sha1_ctx ctx;
-
-  /* Initialize the computation context.  */
-  sha1_init_ctx (&ctx);
-
-  /* Process whole buffer but last len % 64 bytes.  */
-  sha1_process_bytes (buffer, len, &ctx);
-
-  /* Put result in desired memory area.  */
-  return sha1_finish_ctx (&ctx, resblock);
-}
-
-void
-sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
-{
-  /* When we already have some bits in our internal buffer concatenate
-     both inputs first.  */
-  if (ctx->buflen != 0)
-    {
-      size_t left_over = ctx->buflen;
-      size_t add = 128 - left_over > len ? len : 128 - left_over;
-
-      memcpy (&((char *) ctx->buffer)[left_over], buffer, add);
-      ctx->buflen += add;
-
-      if (ctx->buflen > 64)
-       {
-         sha1_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
-
-         ctx->buflen &= 63;
-         /* The regions in the following copy operation cannot overlap.  */
-         memcpy (ctx->buffer,
-                 &((char *) ctx->buffer)[(left_over + add) & ~63],
-                 ctx->buflen);
-       }
-
-      buffer = (const char *) buffer + add;
-      len -= add;
-    }
-
-  /* Process available complete blocks.  */
-  if (len >= 64)
-    {
-#if !_STRING_ARCH_unaligned
-# define alignof(type) offsetof (struct { char c; type x; }, x)
-# define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0)
-      if (UNALIGNED_P (buffer))
-       while (len > 64)
-         {
-           sha1_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx);
-           buffer = (const char *) buffer + 64;
-           len -= 64;
-         }
-      else
-#endif
-       {
-         sha1_process_block (buffer, len & ~63, ctx);
-         buffer = (const char *) buffer + (len & ~63);
-         len &= 63;
-       }
-    }
-
-  /* Move remaining bytes in internal buffer.  */
-  if (len > 0)
-    {
-      size_t left_over = ctx->buflen;
-
-      memcpy (&((char *) ctx->buffer)[left_over], buffer, len);
-      left_over += len;
-      if (left_over >= 64)
-       {
-         sha1_process_block (ctx->buffer, 64, ctx);
-         left_over -= 64;
-         memcpy (ctx->buffer, &ctx->buffer[16], left_over);
-       }
-      ctx->buflen = left_over;
-    }
-}
-
-/* --- Code below is the primary difference between md5.c and sha1.c --- */
-
-/* SHA1 round constants */
-#define K1 0x5a827999
-#define K2 0x6ed9eba1
-#define K3 0x8f1bbcdc
-#define K4 0xca62c1d6
-
-/* Round functions.  Note that F2 is the same as F4.  */
-#define F1(B,C,D) ( D ^ ( B & ( C ^ D ) ) )
-#define F2(B,C,D) (B ^ C ^ D)
-#define F3(B,C,D) ( ( B & C ) | ( D & ( B | C ) ) )
-#define F4(B,C,D) (B ^ C ^ D)
-
-/* Process LEN bytes of BUFFER, accumulating context into CTX.
-   It is assumed that LEN % 64 == 0.
-   Most of this code comes from GnuPG's cipher/sha1.c.  */
-
-void
-sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx)
-{
-  const uint32_t *words = buffer;
-  size_t nwords = len / sizeof (uint32_t);
-  const uint32_t *endp = words + nwords;
-  uint32_t x[16];
-  uint32_t a = ctx->A;
-  uint32_t b = ctx->B;
-  uint32_t c = ctx->C;
-  uint32_t d = ctx->D;
-  uint32_t e = ctx->E;
-
-  /* First increment the byte count.  RFC 1321 specifies the possible
-     length of the file up to 2^64 bits.  Here we only compute the
-     number of bytes.  Do a double word increment.  */
-  ctx->total[0] += len;
-  if (ctx->total[0] < len)
-    ++ctx->total[1];
-
-#define rol(x, n) (((x) << (n)) | ((uint32_t) (x) >> (32 - (n))))
-
-#define M(I) ( tm =   x[I&0x0f] ^ x[(I-14)&0x0f] \
-                   ^ x[(I-8)&0x0f] ^ x[(I-3)&0x0f] \
-              , (x[I&0x0f] = rol(tm, 1)) )
-
-#define R(A,B,C,D,E,F,K,M)  do { E += rol( A, 5 )     \
-                                     + F( B, C, D )  \
-                                     + K             \
-                                     + M;            \
-                                B = rol( B, 30 );    \
-                              } while(0)
-
-  while (words < endp)
-    {
-      uint32_t tm;
-      int t;
-      for (t = 0; t < 16; t++)
-       {
-         x[t] = SWAP (*words);
-         words++;
-       }
-
-      R( a, b, c, d, e, F1, K1, x[ 0] );
-      R( e, a, b, c, d, F1, K1, x[ 1] );
-      R( d, e, a, b, c, F1, K1, x[ 2] );
-      R( c, d, e, a, b, F1, K1, x[ 3] );
-      R( b, c, d, e, a, F1, K1, x[ 4] );
-      R( a, b, c, d, e, F1, K1, x[ 5] );
-      R( e, a, b, c, d, F1, K1, x[ 6] );
-      R( d, e, a, b, c, F1, K1, x[ 7] );
-      R( c, d, e, a, b, F1, K1, x[ 8] );
-      R( b, c, d, e, a, F1, K1, x[ 9] );
-      R( a, b, c, d, e, F1, K1, x[10] );
-      R( e, a, b, c, d, F1, K1, x[11] );
-      R( d, e, a, b, c, F1, K1, x[12] );
-      R( c, d, e, a, b, F1, K1, x[13] );
-      R( b, c, d, e, a, F1, K1, x[14] );
-      R( a, b, c, d, e, F1, K1, x[15] );
-      R( e, a, b, c, d, F1, K1, M(16) );
-      R( d, e, a, b, c, F1, K1, M(17) );
-      R( c, d, e, a, b, F1, K1, M(18) );
-      R( b, c, d, e, a, F1, K1, M(19) );
-      R( a, b, c, d, e, F2, K2, M(20) );
-      R( e, a, b, c, d, F2, K2, M(21) );
-      R( d, e, a, b, c, F2, K2, M(22) );
-      R( c, d, e, a, b, F2, K2, M(23) );
-      R( b, c, d, e, a, F2, K2, M(24) );
-      R( a, b, c, d, e, F2, K2, M(25) );
-      R( e, a, b, c, d, F2, K2, M(26) );
-      R( d, e, a, b, c, F2, K2, M(27) );
-      R( c, d, e, a, b, F2, K2, M(28) );
-      R( b, c, d, e, a, F2, K2, M(29) );
-      R( a, b, c, d, e, F2, K2, M(30) );
-      R( e, a, b, c, d, F2, K2, M(31) );
-      R( d, e, a, b, c, F2, K2, M(32) );
-      R( c, d, e, a, b, F2, K2, M(33) );
-      R( b, c, d, e, a, F2, K2, M(34) );
-      R( a, b, c, d, e, F2, K2, M(35) );
-      R( e, a, b, c, d, F2, K2, M(36) );
-      R( d, e, a, b, c, F2, K2, M(37) );
-      R( c, d, e, a, b, F2, K2, M(38) );
-      R( b, c, d, e, a, F2, K2, M(39) );
-      R( a, b, c, d, e, F3, K3, M(40) );
-      R( e, a, b, c, d, F3, K3, M(41) );
-      R( d, e, a, b, c, F3, K3, M(42) );
-      R( c, d, e, a, b, F3, K3, M(43) );
-      R( b, c, d, e, a, F3, K3, M(44) );
-      R( a, b, c, d, e, F3, K3, M(45) );
-      R( e, a, b, c, d, F3, K3, M(46) );
-      R( d, e, a, b, c, F3, K3, M(47) );
-      R( c, d, e, a, b, F3, K3, M(48) );
-      R( b, c, d, e, a, F3, K3, M(49) );
-      R( a, b, c, d, e, F3, K3, M(50) );
-      R( e, a, b, c, d, F3, K3, M(51) );
-      R( d, e, a, b, c, F3, K3, M(52) );
-      R( c, d, e, a, b, F3, K3, M(53) );
-      R( b, c, d, e, a, F3, K3, M(54) );
-      R( a, b, c, d, e, F3, K3, M(55) );
-      R( e, a, b, c, d, F3, K3, M(56) );
-      R( d, e, a, b, c, F3, K3, M(57) );
-      R( c, d, e, a, b, F3, K3, M(58) );
-      R( b, c, d, e, a, F3, K3, M(59) );
-      R( a, b, c, d, e, F4, K4, M(60) );
-      R( e, a, b, c, d, F4, K4, M(61) );
-      R( d, e, a, b, c, F4, K4, M(62) );
-      R( c, d, e, a, b, F4, K4, M(63) );
-      R( b, c, d, e, a, F4, K4, M(64) );
-      R( a, b, c, d, e, F4, K4, M(65) );
-      R( e, a, b, c, d, F4, K4, M(66) );
-      R( d, e, a, b, c, F4, K4, M(67) );
-      R( c, d, e, a, b, F4, K4, M(68) );
-      R( b, c, d, e, a, F4, K4, M(69) );
-      R( a, b, c, d, e, F4, K4, M(70) );
-      R( e, a, b, c, d, F4, K4, M(71) );
-      R( d, e, a, b, c, F4, K4, M(72) );
-      R( c, d, e, a, b, F4, K4, M(73) );
-      R( b, c, d, e, a, F4, K4, M(74) );
-      R( a, b, c, d, e, F4, K4, M(75) );
-      R( e, a, b, c, d, F4, K4, M(76) );
-      R( d, e, a, b, c, F4, K4, M(77) );
-      R( c, d, e, a, b, F4, K4, M(78) );
-      R( b, c, d, e, a, F4, K4, M(79) );
-
-      a = ctx->A += a;
-      b = ctx->B += b;
-      c = ctx->C += c;
-      d = ctx->D += d;
-      e = ctx->E += e;
-    }
-}
diff --git a/libmailutils/size_max.h b/libmailutils/size_max.h
deleted file mode 100644
index ee3fc25..0000000
--- a/libmailutils/size_max.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/* size_max.h -- declare SIZE_MAX through system headers
-   Copyright (C) 2005, 2006, 2010 Free Software Foundation, Inc.
-   Written by Simon Josefsson.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#ifndef GNULIB_SIZE_MAX_H
-#define GNULIB_SIZE_MAX_H
-
-/* Get SIZE_MAX declaration on systems like Solaris 7/8/9.  */
-# include <limits.h>
-/* Get SIZE_MAX declaration on systems like glibc 2.  */
-# if HAVE_STDINT_H
-#  include <stdint.h>
-# endif
-/* On systems where these include files don't define it, SIZE_MAX is defined
-   in config.h.  */
-
-#endif /* GNULIB_SIZE_MAX_H */
diff --git a/libmailutils/stream/Makefile.am b/libmailutils/stream/Makefile.am
new file mode 100644
index 0000000..c68e83a
--- /dev/null
+++ b/libmailutils/stream/Makefile.am
@@ -0,0 +1,41 @@
+# 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/>.
+
+noinst_LTLIBRARIES = libstream.la
+
+libstream_la_SOURCES = \
+ dbgstream.c\
+ file_stream.c\
+ fltstream.c\
+ iostream.c\
+ mapfile_stream.c\
+ memory_stream.c\
+ message_stream.c\
+ prog_stream.c\
+ rdcache_stream.c\
+ socket_stream.c\
+ stdio_stream.c\
+ stream.c\
+ stream_printf.c\
+ stream_vprintf.c\
+ streamcpy.c\
+ streamref.c\
+ tcp.c\
+ temp_file_stream.c\
+ xscript-stream.c
+
+INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
diff --git a/libmailutils/dbgstream.c b/libmailutils/stream/dbgstream.c
similarity index 100%
rename from libmailutils/dbgstream.c
rename to libmailutils/stream/dbgstream.c
diff --git a/libmailutils/file_stream.c b/libmailutils/stream/file_stream.c
similarity index 100%
rename from libmailutils/file_stream.c
rename to libmailutils/stream/file_stream.c
diff --git a/libmailutils/fltstream.c b/libmailutils/stream/fltstream.c
similarity index 100%
rename from libmailutils/fltstream.c
rename to libmailutils/stream/fltstream.c
diff --git a/libmailutils/iostream.c b/libmailutils/stream/iostream.c
similarity index 100%
rename from libmailutils/iostream.c
rename to libmailutils/stream/iostream.c
diff --git a/libmailutils/mapfile_stream.c 
b/libmailutils/stream/mapfile_stream.c
similarity index 100%
rename from libmailutils/mapfile_stream.c
rename to libmailutils/stream/mapfile_stream.c
diff --git a/libmailutils/memory_stream.c b/libmailutils/stream/memory_stream.c
similarity index 100%
rename from libmailutils/memory_stream.c
rename to libmailutils/stream/memory_stream.c
diff --git a/libmailutils/stream/message_stream.c 
b/libmailutils/stream/message_stream.c
new file mode 100644
index 0000000..91bef83
--- /dev/null
+++ b/libmailutils/stream/message_stream.c
@@ -0,0 +1,438 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2002, 2005, 2006, 2007, 2009, 2010
+   Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+/* This file implements an MH draftfile stream: a read-only stream used
+   to transparently pass MH draftfiles to mailers. The only difference
+   between the usual RFC822 and MH draft is that the latter allows to use
+   a string of dashes to separate the headers from the body. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+
+#include <mailutils/types.h>
+#include <mailutils/address.h>
+#include <mailutils/alloc.h>
+#include <mailutils/envelope.h>
+#include <mailutils/message.h>
+#include <mailutils/header.h>
+#include <mailutils/body.h>
+#include <mailutils/stream.h>
+#include <mailutils/mutil.h>
+#include <mailutils/errno.h>
+#include <mailutils/error.h>
+#include <mailutils/cctype.h>
+#include <mailutils/cstr.h>
+#include <mailutils/sys/message_stream.h>
+
+
+static int
+_env_msg_date (mu_envelope_t envelope, char *buf, size_t len, size_t *pnwrite)
+{
+  struct _mu_message_stream *str = mu_envelope_get_owner (envelope);
+  
+  if (!str || !str->date)
+    return EINVAL;
+  if (buf)
+    {
+      strncpy (buf, str->date, len);
+      buf[len-1] = 0;
+      if (pnwrite)
+       *pnwrite = len;
+    }
+  else if (!pnwrite)
+    return EINVAL;
+  else
+    *pnwrite = strlen (str->date);
+  return 0;
+}
+
+static int
+_env_msg_sender (mu_envelope_t envelope, char *buf, size_t len,
+                size_t *pnwrite)
+{
+  struct _mu_message_stream *str = mu_envelope_get_owner (envelope);
+  
+  if (!str || !str->from)
+    return EINVAL;
+  if (buf)
+    {
+      strncpy (buf, str->from, len);
+      buf[len-1] = 0;
+      if (pnwrite)
+       *pnwrite = len;
+    }
+  else if (!pnwrite)
+    return EINVAL;
+  else
+    *pnwrite = strlen (str->from);
+    
+  return 0;
+}
+
+
+static int
+_message_read (mu_stream_t stream, char *optr, size_t osize, size_t *nbytes)
+{
+  int rc;
+  struct _mu_message_stream *s = (struct _mu_message_stream*) stream;
+  mu_off_t offset = s->offset + s->envelope_length;
+  size_t rsize;
+  
+  if (offset < s->mark_offset)
+    {
+      if (offset + osize >= s->mark_offset)
+       osize = s->mark_offset - offset;
+    }
+  else
+    offset += s->mark_length;
+  /* FIXME: Seeking each time before read is awkward. The streamref
+     should be modified to take care of it */
+  rc = mu_stream_seek (s->transport, offset, MU_SEEK_SET, NULL);
+  if (rc == 0)
+    rc = mu_stream_read (s->transport, optr, osize, &rsize);
+  if (rc == 0)
+    {
+      s->offset += rsize;
+      if (nbytes)
+       *nbytes = rsize;
+    }
+  else
+    s->stream.last_err = rc;
+  return rc;
+}
+  
+static int
+_message_size (mu_stream_t stream, mu_off_t *psize)
+{
+  struct _mu_message_stream *s = (struct _mu_message_stream*) stream;
+  int rc = mu_stream_size (s->transport, psize);
+  
+  if (rc == 0)
+    *psize -= s->envelope_length + s->mark_length;
+  return rc;
+}
+  
+static int
+scan_stream (struct _mu_message_stream *str)
+{
+  char *from = NULL;
+  char *env_from = NULL;
+  char *env_date = NULL;
+  int rc;
+  char *buffer = NULL;
+  size_t bufsize = 0;
+  size_t len;
+  mu_off_t body_start, body_end;
+  mu_stream_t stream = str->transport;
+
+  if (str->envelope)
+    {
+      char *s = str->envelope + 5;
+      char *p = strchr (s, ' ');
+      size_t len;
+
+      if (p)
+       {
+         len = p - s;
+         env_from = mu_alloc (len + 1);
+         if (!env_from)
+           return ENOMEM;
+         memcpy (env_from, s, len);
+         env_from[len] = 0;
+         env_date = mu_strdup (p + 1);
+         if (!env_date)
+           {
+             free (env_from);
+             return ENOMEM;
+           }
+       }
+    }
+
+  rc = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
+  if (rc)
+    return rc;
+  while ((rc = mu_stream_getline (stream, &buffer, &bufsize, &len)) == 0
+        && len > 0)
+    {
+      if (buffer[0] == '\n')
+       break;
+
+      if (!env_from || !env_date)
+       {
+         if (!from && mu_c_strncasecmp (buffer, MU_HEADER_FROM,
+                                        sizeof (MU_HEADER_FROM) - 1) == 0)
+           
+           from = mu_strdup (mu_str_skip_class (buffer +
+                                                sizeof (MU_HEADER_FROM),
+                                                MU_CTYPE_SPACE));
+         else if (!env_from
+                  && mu_c_strncasecmp (buffer, MU_HEADER_ENV_SENDER,
+                                       sizeof (MU_HEADER_ENV_SENDER) - 1) == 0)
+           env_from = mu_strdup (mu_str_skip_class (buffer +
+                                       sizeof (MU_HEADER_ENV_SENDER),
+                                                    MU_CTYPE_SPACE));
+         else if (!env_date
+                  && mu_c_strncasecmp (buffer, MU_HEADER_ENV_DATE,
+                                       sizeof (MU_HEADER_ENV_DATE) - 1) == 0)
+           env_date = mu_strdup (mu_str_skip_class (buffer +
+                                                 sizeof (MU_HEADER_ENV_DATE),
+                                                    MU_CTYPE_SPACE));
+       }
+    }
+
+  free (buffer);
+
+  rc = mu_stream_seek (stream, 0, MU_SEEK_CUR, &body_start);
+  if (rc)
+    return rc;
+  rc = mu_stream_size (stream, &body_end);
+  if (rc)
+    return rc;
+  
+  if (!env_from)
+    {
+      if (from)
+       {
+         mu_address_t addr;
+         
+         mu_address_create (&addr, from);
+         if (!addr
+             || mu_address_aget_email (addr, 1, &env_from))
+           env_from = mu_strdup ("GNU-Mailutils");
+         mu_address_destroy (&addr);
+       }
+      else
+       env_from = mu_strdup ("GNU-MH");
+    }
+  free (from);
+  
+  if (!env_date)
+    {
+      struct tm *tm;
+      time_t t;
+      char date[80]; /* FIXME: This size is way too big */
+
+      time(&t);
+      tm = gmtime(&t);
+      mu_strftime (date, sizeof (date), "%a %b %e %H:%M:%S %Y", tm);
+      env_date = strdup (date);
+    }
+
+  str->from = env_from;
+  str->date = env_date;
+
+  str->body_start = body_start;
+  str->body_end = body_end - 1;
+  
+  return 0;
+}
+
+static int
+_message_open (mu_stream_t stream)
+{
+  struct _mu_message_stream *s = (struct _mu_message_stream*) stream;
+  size_t offset, len;
+  char *buffer = NULL;
+  size_t bufsize = 0;
+  int rc;
+
+  offset = 0;
+  mu_stream_seek (s->transport, 0, MU_SEEK_SET, NULL);
+  while ((rc = mu_stream_getline (s->transport, &buffer, &bufsize,
+                                 &len)) == 0
+        && len > 0)
+    {
+      if (offset == 0 && memcmp (buffer, "From ", 5) == 0)
+       {
+         s->envelope_length = len;
+         s->envelope = mu_strdup (buffer);
+         if (!s->envelope)
+           return ENOMEM;
+         s->envelope[len - 1] = 0;
+       }
+      else if (mu_mh_delim (buffer))
+       {
+         s->mark_offset = offset;
+         s->mark_length = len - 1; /* do not count the terminating newline */
+         break;
+       }
+
+      offset += len;
+    }
+  free (buffer);
+
+  return scan_stream (s);
+}
+
+static int
+_message_close (mu_stream_t stream)
+{
+  struct _mu_message_stream *s = (struct _mu_message_stream*) stream;
+  return s->stream.last_err = mu_stream_close (s->transport);
+}
+
+static void
+_message_done (mu_stream_t stream)
+{
+  struct _mu_message_stream *s = (struct _mu_message_stream*) stream;
+
+  free (s->envelope);
+  free (s->date);
+  free (s->from);
+  mu_stream_destroy (&s->transport);
+}
+
+static int
+_message_seek (struct _mu_stream *stream, mu_off_t off, mu_off_t *presult)
+{ 
+  struct _mu_message_stream *s = (struct _mu_message_stream*) stream;
+  mu_off_t size;
+
+  mu_stream_size (stream, &size);
+  if (off < 0 || off >= size)
+    return ESPIPE;
+  s->offset = off;
+  *presult = off;
+  return 0;
+}
+
+const char *
+_message_error_string (struct _mu_stream *stream, int rc)
+{
+  struct _mu_message_stream *str = (struct _mu_message_stream*) stream;
+  return mu_stream_strerror (str->transport, rc);
+}
+
+int
+mu_message_stream_create (mu_stream_t *pstream, mu_stream_t src, int flags)
+{
+  struct _mu_message_stream *s;
+  int sflag;
+  int rc;
+  mu_stream_t stream;
+  
+  mu_stream_get_flags (src, &sflag);
+  sflag &= MU_STREAM_SEEK;
+  
+  if (!flags)
+    flags = MU_STREAM_READ;
+  if (flags & (MU_STREAM_WRITE|MU_STREAM_CREAT|MU_STREAM_APPEND))
+    return EINVAL;
+  s = (struct _mu_message_stream *) _mu_stream_create (sizeof (*s),
+                                                      flags | sflag);
+  if (!s)
+    return ENOMEM;
+
+  rc = mu_streamref_create (&s->transport, src);
+  if (rc)
+    {
+      free (s);
+      return rc;
+    }
+  s->stream.open = _message_open;
+  s->stream.close = _message_close;
+  s->stream.done = _message_done;
+  s->stream.read = _message_read;
+  s->stream.size = _message_size;
+  s->stream.seek = _message_seek;
+  s->stream.error_string = _message_error_string;
+
+  stream = (mu_stream_t)s;
+  rc = mu_stream_open (stream);
+  if (rc)
+    mu_stream_destroy (&stream);
+  else
+    *pstream = stream;
+  return rc;
+}
+
+
+/* *************************** MH draft message **************************** */
+
+
+
+static int
+_body_obj_size (mu_body_t body, size_t *size)
+{
+  mu_message_t msg = mu_body_get_owner (body);
+  struct _mu_message_stream *str = mu_message_get_owner (msg);
+
+  if (size)
+    *size = str->body_end - str->body_start + 1;
+  return 0;
+}
+
+
+
+int
+mu_stream_to_message (mu_stream_t instream, mu_message_t *pmsg)
+{
+  mu_envelope_t env;
+  mu_message_t msg;
+  mu_body_t body;
+  mu_stream_t bstream;
+  mu_stream_t draftstream;
+  int rc;
+  struct _mu_message_stream *sp;
+  
+  /* FIXME: Perhaps MU_STREAM_NO_CLOSE is needed */
+  if ((rc = mu_message_stream_create (&draftstream, instream, 0)))
+    return rc;
+
+  if ((rc = mu_message_create (&msg, draftstream)))
+    {
+      mu_stream_destroy (&draftstream);
+      return rc;
+    }
+  
+  mu_message_set_stream (msg, draftstream, draftstream);
+  
+  if ((rc = mu_envelope_create (&env, draftstream)))
+    {
+      mu_message_destroy (&msg, draftstream);
+      mu_stream_destroy (&draftstream);
+      return rc;
+    }
+  
+  mu_envelope_set_date (env, _env_msg_date, draftstream);
+  mu_envelope_set_sender (env, _env_msg_sender, draftstream);
+  mu_message_set_envelope (msg, env, draftstream);
+
+  mu_body_create (&body, msg);
+  /* FIXME: It would be cleaner to use ioctl here */
+  sp = (struct _mu_message_stream *) draftstream;
+  rc = mu_streamref_create_abridged (&bstream, instream,
+                                    sp->body_start, sp->body_end);
+  if (rc)
+    {
+      mu_body_destroy (&body, msg);
+      mu_message_destroy (&msg, draftstream);
+      mu_stream_destroy (&draftstream);
+      return rc;
+    }
+  
+  mu_body_set_stream (body, bstream, msg);
+  mu_body_set_size (body, _body_obj_size, msg);
+  mu_message_set_body (msg, body, draftstream);
+
+  *pmsg = msg;
+  return 0;
+}
diff --git a/libmailutils/prog_stream.c b/libmailutils/stream/prog_stream.c
similarity index 100%
rename from libmailutils/prog_stream.c
rename to libmailutils/stream/prog_stream.c
diff --git a/libmailutils/rdcache_stream.c 
b/libmailutils/stream/rdcache_stream.c
similarity index 100%
rename from libmailutils/rdcache_stream.c
rename to libmailutils/stream/rdcache_stream.c
diff --git a/libmailutils/socket_stream.c b/libmailutils/stream/socket_stream.c
similarity index 100%
rename from libmailutils/socket_stream.c
rename to libmailutils/stream/socket_stream.c
diff --git a/libmailutils/stdio_stream.c b/libmailutils/stream/stdio_stream.c
similarity index 100%
rename from libmailutils/stdio_stream.c
rename to libmailutils/stream/stdio_stream.c
diff --git a/libmailutils/stream.c b/libmailutils/stream/stream.c
similarity index 100%
rename from libmailutils/stream.c
rename to libmailutils/stream/stream.c
diff --git a/libmailutils/stream_printf.c b/libmailutils/stream/stream_printf.c
similarity index 100%
rename from libmailutils/stream_printf.c
rename to libmailutils/stream/stream_printf.c
diff --git a/libmailutils/stream_vprintf.c 
b/libmailutils/stream/stream_vprintf.c
similarity index 100%
rename from libmailutils/stream_vprintf.c
rename to libmailutils/stream/stream_vprintf.c
diff --git a/libmailutils/streamcpy.c b/libmailutils/stream/streamcpy.c
similarity index 100%
rename from libmailutils/streamcpy.c
rename to libmailutils/stream/streamcpy.c
diff --git a/libmailutils/streamref.c b/libmailutils/stream/streamref.c
similarity index 100%
rename from libmailutils/streamref.c
rename to libmailutils/stream/streamref.c
diff --git a/libmailutils/stream/tcp.c b/libmailutils/stream/tcp.c
new file mode 100644
index 0000000..eafd40b
--- /dev/null
+++ b/libmailutils/stream/tcp.c
@@ -0,0 +1,362 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2004, 2006, 2007, 2010 Free Software
+   Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <fcntl.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sys/socket.h>
+#include <sys/types.h>
+
+#include <netinet/in.h>
+
+#include <arpa/inet.h>
+
+#include <mailutils/errno.h>
+#include <mailutils/stream.h>
+#include <mailutils/mutil.h>
+
+#include <mailutils/sys/stream.h>
+
+#define TCP_STATE_INIT                 1
+#define TCP_STATE_RESOLVE      2
+#define TCP_STATE_RESOLVING    3
+#define TCP_STATE_CONNECTING   4
+#define TCP_STATE_CONNECTED    5
+
+struct _tcp_instance
+{
+  struct _mu_stream stream;
+  int          fd;
+  char                 *host;
+  int          port;
+  int          state;
+  unsigned long        address;
+  unsigned long source_addr;
+};
+
+/* On solaris inet_addr() return -1.  */
+#ifndef INADDR_NONE
+# define INADDR_NONE (unsigned long)-1
+#endif
+
+static int
+_tcp_close (mu_stream_t stream)
+{
+  struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
+  int err = 0;
+
+  if (tcp->fd != -1)
+    {
+      if (close (tcp->fd) != 0)
+       {
+         err = errno;
+       }
+    }
+  tcp->fd = -1;
+  tcp->state = TCP_STATE_INIT;
+  return err;
+}
+
+static int
+resolve_hostname (const char *host, unsigned long *ip)
+{
+  unsigned long address = inet_addr (host);
+  if (address == INADDR_NONE)
+    {
+      struct hostent *phe = gethostbyname (host);
+      if (!phe)
+       return MU_ERR_GETHOSTBYNAME;
+      address = *(((unsigned long **) phe->h_addr_list)[0]);
+    }
+  *ip = address;
+  return 0;
+}
+
+static int
+_tcp_open (mu_stream_t stream)
+{
+  struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
+  int flgs, ret;
+  socklen_t namelen;
+  struct sockaddr_in peer_addr;
+  struct sockaddr_in soc_addr;
+  int flags;
+
+  mu_stream_get_flags (stream, &flags);
+
+  switch (tcp->state)
+    {
+    case TCP_STATE_INIT:
+      if (tcp->fd == -1)
+       {
+         if ((tcp->fd = socket (PF_INET, SOCK_STREAM, 0)) == -1)
+           return errno;
+       }
+      if (flags & MU_STREAM_NONBLOCK)
+       {
+         flgs = fcntl (tcp->fd, F_GETFL);
+         flgs |= O_NONBLOCK;
+         fcntl (tcp->fd, F_SETFL, flgs);
+         mu_stream_set_flags (stream, MU_STREAM_NONBLOCK);
+       }
+      if (tcp->source_addr != INADDR_ANY)
+       {
+         struct sockaddr_in s;
+         s.sin_family = AF_INET;
+         s.sin_addr.s_addr = tcp->source_addr;
+         s.sin_port = 0;
+         if (bind (tcp->fd, (struct sockaddr*) &s, sizeof(s)) < 0)
+           {
+             int e = errno;
+             close (tcp->fd);
+             tcp->fd = -1;
+             return e;
+           }
+       }
+      
+      tcp->state = TCP_STATE_RESOLVING;
+      
+    case TCP_STATE_RESOLVING:
+      if (!(tcp->host != NULL && tcp->port > 0))
+       {
+         _tcp_close (stream);
+         return EINVAL;
+       }
+      
+      if ((ret = resolve_hostname (tcp->host, &tcp->address)))
+       {
+         _tcp_close (stream);
+         return ret;
+       }
+      tcp->state = TCP_STATE_RESOLVE;
+      
+    case TCP_STATE_RESOLVE:
+      memset (&soc_addr, 0, sizeof (soc_addr));
+      soc_addr.sin_family = AF_INET;
+      soc_addr.sin_port = htons (tcp->port);
+      soc_addr.sin_addr.s_addr = tcp->address;
+
+      if ((connect (tcp->fd,
+                   (struct sockaddr *) &soc_addr, sizeof (soc_addr))) == -1)
+       {
+         ret = errno;
+         if (ret == EINPROGRESS || ret == EAGAIN)
+           {
+             tcp->state = TCP_STATE_CONNECTING;
+             ret = EAGAIN;
+           }
+         else
+           _tcp_close (stream);
+         return ret;
+       }
+      tcp->state = TCP_STATE_CONNECTING;
+      
+    case TCP_STATE_CONNECTING:
+      namelen = sizeof (peer_addr);
+      if (getpeername (tcp->fd,
+                      (struct sockaddr *) &peer_addr, &namelen) == 0)
+       tcp->state = TCP_STATE_CONNECTED;
+      else
+       {
+         ret = errno;
+         _tcp_close (stream);
+         return ret;
+       }
+      break;
+    }
+  return 0;
+}
+
+static int
+_tcp_ioctl (mu_stream_t stream, int code, void *ptr)
+{
+  struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
+  mu_transport_t *ptrans;
+
+  switch (code)
+    {
+    case MU_IOCTL_GET_TRANSPORT:
+      if (!ptr)
+       return EINVAL;
+      ptrans = ptr;
+      ptrans[0] = (mu_transport_t) tcp->fd;
+      ptrans[1] = NULL;
+      break;
+
+    default:
+      return ENOSYS;
+    }
+  return 0;
+}
+
+static int
+_tcp_read (mu_stream_t stream, char *buf, size_t size, size_t *pret)
+{
+  struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
+  ssize_t bytes;
+
+  if ((bytes = recv (tcp->fd, buf, size, 0)) == -1)
+    return errno;
+  *pret = bytes;
+  return 0;
+}
+
+static int
+_tcp_write (mu_stream_t stream, const char *buf, size_t size, size_t *pret)
+{
+  struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
+  ssize_t bytes;
+
+  if ((bytes = send (tcp->fd, buf, size, 0)) == -1)
+    return errno;
+  *pret = bytes;
+  return 0;
+}
+
+static void
+_tcp_done (mu_stream_t stream)
+{
+  struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
+
+  if (tcp->host)
+    free (tcp->host);
+  if (tcp->fd != -1)
+    close (tcp->fd);
+}
+
+int
+_tcp_wait (mu_stream_t stream, int *pflags, struct timeval *tvp)
+{
+  struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
+  if (tcp->fd == -1)
+    return EINVAL;
+  return mu_fd_wait (tcp->fd, pflags, tvp);
+}
+
+int
+_tcp_shutdown (mu_stream_t stream, int how)
+{
+  struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
+  int flag;
+  if (tcp->fd == -1)
+    return EINVAL;
+
+  switch (how)
+    {
+    case MU_STREAM_READ:
+      flag = SHUT_RD;
+      break;
+      
+    case MU_STREAM_WRITE:
+      flag = SHUT_WR;
+    }
+
+  if (shutdown (tcp->fd, flag))
+    return errno;
+  return 0;
+}
+
+static struct _tcp_instance *
+_create_tcp_stream (int flags)
+{
+  struct _tcp_instance *tcp =
+    (struct _tcp_instance *)_mu_stream_create (sizeof (*tcp), flags);
+
+  if (tcp)
+    {
+      tcp->stream.open = _tcp_open;
+      tcp->stream.close = _tcp_close;
+      tcp->stream.read = _tcp_read;
+      tcp->stream.write = _tcp_write;
+      tcp->stream.ctl = _tcp_ioctl;
+      tcp->stream.done = _tcp_done;
+      tcp->stream.wait = _tcp_wait;
+      tcp->stream.shutdown = _tcp_shutdown;
+      tcp->fd = -1;
+      tcp->state = TCP_STATE_INIT;
+    }
+  return tcp;
+}
+
+int
+mu_tcp_stream_create_with_source_ip (mu_stream_t *pstream,
+                                    const char *host, int port,
+                                    unsigned long source_ip,
+                                    int flags)
+{
+  int rc;
+  mu_stream_t stream;
+  struct _tcp_instance *tcp;
+
+  if (host == NULL)
+    return MU_ERR_TCP_NO_HOST;
+
+  if (port < 1)
+    return MU_ERR_TCP_NO_PORT;
+
+  tcp = _create_tcp_stream (flags | MU_STREAM_RDWR);
+  if (!tcp)
+    return ENOMEM;
+  tcp->host = strdup (host);
+  if (!tcp->host)
+    {
+      free (tcp);
+      return ENOMEM;
+    }
+  tcp->port = port;
+  tcp->state = TCP_STATE_INIT;
+  tcp->source_addr = source_ip;
+  stream = (mu_stream_t) tcp;
+  rc = mu_stream_open (stream);
+  if (rc == 0 || rc == EAGAIN || rc == EINPROGRESS)
+    *pstream = stream;
+  else
+    mu_stream_destroy (&stream);
+  return rc;
+}
+
+int
+mu_tcp_stream_create_with_source_host (mu_stream_t *stream,
+                                      const char *host, int port,
+                                      const char *source_host,
+                                      int flags)
+{
+  unsigned long source_addr;
+  int ret = resolve_hostname (source_host, &source_addr);
+  if (ret == 0)
+    ret = mu_tcp_stream_create_with_source_ip (stream, host, port,
+                                              source_addr, flags);
+  return ret;
+}
+       
+int
+mu_tcp_stream_create (mu_stream_t *stream, const char *host, int port,
+                     int flags)
+{
+  return mu_tcp_stream_create_with_source_ip (stream, host, port,
+                                             INADDR_ANY, flags);
+}
diff --git a/libmailutils/temp_file_stream.c 
b/libmailutils/stream/temp_file_stream.c
similarity index 100%
rename from libmailutils/temp_file_stream.c
rename to libmailutils/stream/temp_file_stream.c
diff --git a/libmailutils/xscript-stream.c 
b/libmailutils/stream/xscript-stream.c
similarity index 100%
rename from libmailutils/xscript-stream.c
rename to libmailutils/stream/xscript-stream.c
diff --git a/libmailutils/string/Makefile.am b/libmailutils/string/Makefile.am
new file mode 100644
index 0000000..52452b9
--- /dev/null
+++ b/libmailutils/string/Makefile.am
@@ -0,0 +1,34 @@
+# 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/>.
+
+noinst_LTLIBRARIES = libstring.la
+
+libstring_la_SOURCES = \
+ cstrcasecmp.c\
+ cstrlower.c\
+ cstrupper.c\
+ strltrim.c\
+ strskip.c\
+ stripws.c\
+ strrtrim.c\
+ asnprintf.c\
+ asprintf.c\
+ muctype.c\
+ vasnprintf.c\
+ mkfilename.c
+
+INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
diff --git a/libmailutils/string/asnprintf.c b/libmailutils/string/asnprintf.c
new file mode 100644
index 0000000..2d74ec9
--- /dev/null
+++ b/libmailutils/string/asnprintf.c
@@ -0,0 +1,39 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 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 <stdlib.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include <mailutils/io.h>
+
+int
+mu_asnprintf (char **pbuf, size_t *psize, const char *fmt, ...)
+{
+  int rc;
+  va_list ap;
+
+  va_start (ap, fmt);
+  rc = mu_vasnprintf (pbuf, psize, fmt, ap);
+  va_end (ap);
+  return rc;
+}
+
diff --git a/libmailutils/string/asprintf.c b/libmailutils/string/asprintf.c
new file mode 100644
index 0000000..3d11df8
--- /dev/null
+++ b/libmailutils/string/asprintf.c
@@ -0,0 +1,40 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 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 <stdlib.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include <mailutils/io.h>
+
+int
+mu_asprintf (char **pbuf, const char *fmt, ...)
+{
+  va_list ap;
+  size_t size;
+  int rc;
+  
+  va_start (ap, fmt);
+  *pbuf = NULL;
+  size = 0;
+  rc = mu_vasnprintf (pbuf, &size, fmt, ap);
+  va_end (ap);
+  return rc;
+}
diff --git a/libmailutils/cstrcasecmp.c b/libmailutils/string/cstrcasecmp.c
similarity index 100%
rename from libmailutils/cstrcasecmp.c
rename to libmailutils/string/cstrcasecmp.c
diff --git a/libmailutils/cstrlower.c b/libmailutils/string/cstrlower.c
similarity index 100%
rename from libmailutils/cstrlower.c
rename to libmailutils/string/cstrlower.c
diff --git a/libmailutils/cstrupper.c b/libmailutils/string/cstrupper.c
similarity index 100%
rename from libmailutils/cstrupper.c
rename to libmailutils/string/cstrupper.c
diff --git a/libmailutils/mkfilename.c b/libmailutils/string/mkfilename.c
similarity index 100%
rename from libmailutils/mkfilename.c
rename to libmailutils/string/mkfilename.c
diff --git a/libmailutils/muctype.c b/libmailutils/string/muctype.c
similarity index 100%
rename from libmailutils/muctype.c
rename to libmailutils/string/muctype.c
diff --git a/libmailutils/stripws.c b/libmailutils/string/stripws.c
similarity index 100%
rename from libmailutils/stripws.c
rename to libmailutils/string/stripws.c
diff --git a/libmailutils/strltrim.c b/libmailutils/string/strltrim.c
similarity index 100%
rename from libmailutils/strltrim.c
rename to libmailutils/string/strltrim.c
diff --git a/libmailutils/strrtrim.c b/libmailutils/string/strrtrim.c
similarity index 100%
rename from libmailutils/strrtrim.c
rename to libmailutils/string/strrtrim.c
diff --git a/libmailutils/strskip.c b/libmailutils/string/strskip.c
similarity index 100%
rename from libmailutils/strskip.c
rename to libmailutils/string/strskip.c
diff --git a/libmailutils/string/vasnprintf.c b/libmailutils/string/vasnprintf.c
new file mode 100644
index 0000000..6c788d5
--- /dev/null
+++ b/libmailutils/string/vasnprintf.c
@@ -0,0 +1,86 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 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 <stdlib.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+
+#include <mailutils/io.h>
+
+int
+mu_vasnprintf (char **pbuf, size_t *psize, const char *fmt, va_list ap)
+{
+  char *buf = *pbuf;
+  size_t buflen = *psize;
+  int rc = 0;
+  
+  if (!buf)
+    {
+      if (buflen == 0)
+       buflen = 512; /* Initial allocation */
+      
+      buf = calloc (1, buflen);
+      if (buf == NULL)
+       return ENOMEM;
+    }
+  
+  for (;;)
+    {
+      ssize_t n = vsnprintf (buf, buflen, fmt, ap);
+      if (n < 0 || n >= buflen || !memchr (buf, '\0', n + 1))
+       {
+         char *newbuf;
+         size_t newlen = buflen * 2;
+         if (newlen < buflen)
+           {
+             rc = ENOMEM;
+             break;
+           }
+         newbuf = realloc (buf, newlen);
+         if (newbuf == NULL)
+           {
+             rc = ENOMEM;
+             break;
+           }
+         buflen = newlen;
+         buf = newbuf;
+       }
+      else
+       break;
+    }
+
+  if (rc)
+    {
+      if (!*pbuf)
+       {
+         /* We made first allocation, now free it */
+         free (buf);
+         buf = NULL;
+         buflen = 0;
+       }
+    }
+
+  *pbuf = buf;
+  *psize = buflen;
+  return rc;
+}
diff --git a/libmailutils/syslog.c b/libmailutils/syslog.c
deleted file mode 100644
index c97da9b..0000000
--- a/libmailutils/syslog.c
+++ /dev/null
@@ -1,145 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify it
-   under the terms of the GNU General Public License as published by the
-   Free Software Foundation; either version 3 of the License, or (at your
-   option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <syslog.h>
-#include <string.h>
-#include <mailutils/diag.h>
-#include <mailutils/kwd.h>
-#include <mailutils/syslog.h>
-#include <mailutils/cstr.h>
-
-#ifndef LOG_AUTHPRIV
-# define LOG_AUTHPRIV
-#endif
-
-static mu_kwd_t kw_facility[] = {
-  { "USER",    LOG_USER },   
-  { "DAEMON",  LOG_DAEMON },
-  { "AUTH",    LOG_AUTH },
-  { "AUTHPRIV",LOG_AUTHPRIV },
-  { "MAIL",    LOG_MAIL },
-  { "CRON",    LOG_CRON },
-  { "LOCAL0",  LOG_LOCAL0 },
-  { "LOCAL1",  LOG_LOCAL1 },
-  { "LOCAL2",  LOG_LOCAL2 },
-  { "LOCAL3",  LOG_LOCAL3 },
-  { "LOCAL4",  LOG_LOCAL4 },
-  { "LOCAL5",  LOG_LOCAL5 },
-  { "LOCAL6",  LOG_LOCAL6 },
-  { "LOCAL7",  LOG_LOCAL7 },
-  { NULL }
-};
-
-static int
-syslog_to_n (mu_kwd_t *kw, const char *str, int *pint)
-{
-  if (mu_c_strncasecmp (str, "LOG_", 4) == 0)
-    str += 4;
-  return mu_kwd_xlat_name_ci (kw, str, pint);
-}
-
-int
-mu_string_to_syslog_facility (const char *str, int *pfacility)
-{
-  return syslog_to_n (kw_facility, str, pfacility);
-}
-
-const char *
-mu_syslog_facility_to_string (int n)
-{
-  const char *res = NULL;
-  mu_kwd_xlat_tok (kw_facility, n, &res);
-  return res;
-}
-
-static mu_kwd_t kw_prio[] = {
-  { "EMERG", LOG_EMERG },
-  { "ALERT", LOG_ALERT },
-  { "CRIT", LOG_CRIT },
-  { "ERR", LOG_ERR },
-  { "WARNING", LOG_WARNING },
-  { "NOTICE", LOG_NOTICE },
-  { "INFO", LOG_INFO },
-  { "DEBUG", LOG_DEBUG },
-  { NULL }
-};
-
-int
-mu_string_to_syslog_priority (const char *str, int *pprio)
-{
-  return syslog_to_n (kw_prio, str, pprio);
-}
-
-const char *
-mu_syslog_priority_to_string (int n)
-{
-  const char *res = NULL;
-  mu_kwd_xlat_tok (kw_prio, n, &res);
-  return res;
-}
-
-int
-mu_diag_level_to_syslog (mu_log_level_t level)
-{
-  switch (level)
-    {
-    case MU_DIAG_EMERG:
-      return LOG_EMERG;
-      
-    case MU_DIAG_ALERT:
-      return LOG_ALERT;
-       
-    case MU_DIAG_CRIT:
-      return LOG_CRIT;
-      
-    case MU_DIAG_ERROR:
-      return LOG_ERR;
-      
-    case MU_DIAG_WARNING:
-      return LOG_WARNING;
-      
-    case MU_DIAG_NOTICE:
-      return LOG_NOTICE;
-      
-    case MU_DIAG_INFO:
-      return LOG_INFO;
-      
-    case MU_DIAG_DEBUG:
-      return LOG_DEBUG;
-    }
-  return LOG_EMERG;
-}
-
-int
-mu_diag_syslog_printer (void *data, mu_log_level_t level, const char *buf)
-{
-  int len = strlen (buf);
-  if (len > 0 && buf[len-1] == '\n')
-    {
-      len--;
-      if (len > 0 && buf[len-1] == '\r')
-       len--;
-    }
-  syslog (mu_diag_level_to_syslog (level), "%-.*s", len, buf);
-  return 0;
-}
-
-
-int mu_log_facility = LOG_FACILITY;
-char *mu_log_tag = NULL;
diff --git a/libmailutils/system.c b/libmailutils/system.c
deleted file mode 100644
index 8e28caa..0000000
--- a/libmailutils/system.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2002, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <unistd.h>
-#include <sys/types.h>
-#include <pwd.h>
-#ifdef HAVE_SHADOW_H
-# include <shadow.h>
-#endif
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
-#endif
-#ifdef HAVE_CRYPT_H
-# include <crypt.h>
-#endif
-
-#include <mailutils/list.h>
-#include <mailutils/iterator.h>
-#include <mailutils/mailbox.h>
-#include <mailutils/mu_auth.h>
-#include <mailutils/errno.h>
-
-/* System database */
-static int
-mu_auth_system (struct mu_auth_data **return_data, const struct passwd *pw)
-{
-  char *mailbox_name;
-  int rc;
-  
-  if (!pw)
-    return MU_ERR_AUTH_FAILURE;
-
-  rc = mu_construct_user_mailbox_url (&mailbox_name, pw->pw_name);
-  if (rc)
-    return rc; /* FIXME: Return code is lost */
-  
-  rc = mu_auth_data_alloc (return_data,
-                          pw->pw_name,
-                          pw->pw_passwd,
-                          pw->pw_uid,
-                          pw->pw_gid,
-                          pw->pw_gecos,
-                          pw->pw_dir,
-                          pw->pw_shell,
-                          mailbox_name,
-                          1);
-  free (mailbox_name);
-  return rc;
-}
-
-int
-mu_auth_system_by_name (struct mu_auth_data **return_data,
-                       const void *key,
-                       void *func_data MU_ARG_UNUSED,
-                       void *call_data MU_ARG_UNUSED)
-{
-  if (!key)
-    return EINVAL;
-  return mu_auth_system (return_data, getpwnam (key));
-}
-
-static int
-mu_auth_system_by_uid (struct mu_auth_data **return_data,
-                      const void *key,
-                      void *func_data MU_ARG_UNUSED,
-                      void *call_data MU_ARG_UNUSED)
-{
-  if (!key)
-    return EINVAL;
-  return mu_auth_system (return_data, getpwuid (*(uid_t*) key));
-}
-
-static int
-mu_authenticate_generic (struct mu_auth_data **return_data MU_ARG_UNUSED,
-                        const void *key,
-                        void *func_data MU_ARG_UNUSED,
-                        void *call_data)
-{
-  const struct mu_auth_data *auth_data = key;
-  char *pass = call_data;
-
-  if (!auth_data || !pass)
-    return EINVAL;
-  
-  return auth_data->passwd
-         && strcmp (auth_data->passwd, crypt (pass, auth_data->passwd)) == 0 ?
-          0 : MU_ERR_AUTH_FAILURE;
-}
-
-/* Called only if generic fails */
-static int
-mu_authenticate_system (struct mu_auth_data **return_data MU_ARG_UNUSED,
-                       const void *key,
-                       void *func_data MU_ARG_UNUSED,
-                       void *call_data)
-{
-  const struct mu_auth_data *auth_data = key;
-
-#ifdef HAVE_SHADOW_H
-  char *pass = call_data;
-  
-  if (auth_data)
-    {
-      struct spwd *spw;
-      spw = getspnam (auth_data->name);
-      if (spw)
-       return strcmp (spw->sp_pwdp, crypt (pass, spw->sp_pwdp)) == 0 ?
-               0 : MU_ERR_AUTH_FAILURE;
-    }
-#endif
-  return MU_ERR_AUTH_FAILURE;
-}
-
-
-struct mu_auth_module mu_auth_system_module = {
-  "system",
-  NULL,
-  mu_authenticate_system,
-  NULL,
-  mu_auth_system_by_name,
-  NULL,
-  mu_auth_system_by_uid,
-  NULL
-};
-
-
-struct mu_auth_module mu_auth_generic_module = {
-  "generic",
-  NULL,
-  mu_authenticate_generic,
-  NULL,
-  mu_auth_nosupport,
-  NULL,
-  mu_auth_nosupport,
-  NULL
-};
-
diff --git a/libmailutils/tcp.c b/libmailutils/tcp.c
deleted file mode 100644
index aea7809..0000000
--- a/libmailutils/tcp.c
+++ /dev/null
@@ -1,363 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2004, 2006, 2007, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <errno.h>
-#include <fcntl.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <sys/socket.h>
-#include <sys/types.h>
-
-#include <netinet/in.h>
-
-#include <arpa/inet.h>
-
-#include <mailutils/errno.h>
-#include <mailutils/stream.h>
-#include <mailutils/mutil.h>
-
-#include <mailutils/sys/stream.h>
-
-#define TCP_STATE_INIT                 1
-#define TCP_STATE_RESOLVE      2
-#define TCP_STATE_RESOLVING    3
-#define TCP_STATE_CONNECTING   4
-#define TCP_STATE_CONNECTED    5
-
-struct _tcp_instance
-{
-  struct _mu_stream stream;
-  int          fd;
-  char                 *host;
-  int          port;
-  int          state;
-  unsigned long        address;
-  unsigned long source_addr;
-};
-
-/* On solaris inet_addr() return -1.  */
-#ifndef INADDR_NONE
-# define INADDR_NONE (unsigned long)-1
-#endif
-
-static int
-_tcp_close (mu_stream_t stream)
-{
-  struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
-  int err = 0;
-
-  if (tcp->fd != -1)
-    {
-      if (close (tcp->fd) != 0)
-       {
-         err = errno;
-       }
-    }
-  tcp->fd = -1;
-  tcp->state = TCP_STATE_INIT;
-  return err;
-}
-
-static int
-resolve_hostname (const char *host, unsigned long *ip)
-{
-  unsigned long address = inet_addr (host);
-  if (address == INADDR_NONE)
-    {
-      struct hostent *phe = gethostbyname (host);
-      if (!phe)
-       return MU_ERR_GETHOSTBYNAME;
-      address = *(((unsigned long **) phe->h_addr_list)[0]);
-    }
-  *ip = address;
-  return 0;
-}
-
-static int
-_tcp_open (mu_stream_t stream)
-{
-  struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
-  int flgs, ret;
-  socklen_t namelen;
-  struct sockaddr_in peer_addr;
-  struct sockaddr_in soc_addr;
-  int flags;
-
-  mu_stream_get_flags (stream, &flags);
-
-  switch (tcp->state)
-    {
-    case TCP_STATE_INIT:
-      if (tcp->fd == -1)
-       {
-         if ((tcp->fd = socket (PF_INET, SOCK_STREAM, 0)) == -1)
-           return errno;
-       }
-      if (flags & MU_STREAM_NONBLOCK)
-       {
-         flgs = fcntl (tcp->fd, F_GETFL);
-         flgs |= O_NONBLOCK;
-         fcntl (tcp->fd, F_SETFL, flgs);
-         mu_stream_set_flags (stream, MU_STREAM_NONBLOCK);
-       }
-      if (tcp->source_addr != INADDR_ANY)
-       {
-         struct sockaddr_in s;
-         s.sin_family = AF_INET;
-         s.sin_addr.s_addr = tcp->source_addr;
-         s.sin_port = 0;
-         if (bind (tcp->fd, (struct sockaddr*) &s, sizeof(s)) < 0)
-           {
-             int e = errno;
-             close (tcp->fd);
-             tcp->fd = -1;
-             return e;
-           }
-       }
-      
-      tcp->state = TCP_STATE_RESOLVING;
-      
-    case TCP_STATE_RESOLVING:
-      if (!(tcp->host != NULL && tcp->port > 0))
-       {
-         _tcp_close (stream);
-         return EINVAL;
-       }
-      
-      if ((ret = resolve_hostname (tcp->host, &tcp->address)))
-       {
-         _tcp_close (stream);
-         return ret;
-       }
-      tcp->state = TCP_STATE_RESOLVE;
-      
-    case TCP_STATE_RESOLVE:
-      memset (&soc_addr, 0, sizeof (soc_addr));
-      soc_addr.sin_family = AF_INET;
-      soc_addr.sin_port = htons (tcp->port);
-      soc_addr.sin_addr.s_addr = tcp->address;
-
-      if ((connect (tcp->fd,
-                   (struct sockaddr *) &soc_addr, sizeof (soc_addr))) == -1)
-       {
-         ret = errno;
-         if (ret == EINPROGRESS || ret == EAGAIN)
-           {
-             tcp->state = TCP_STATE_CONNECTING;
-             ret = EAGAIN;
-           }
-         else
-           _tcp_close (stream);
-         return ret;
-       }
-      tcp->state = TCP_STATE_CONNECTING;
-      
-    case TCP_STATE_CONNECTING:
-      namelen = sizeof (peer_addr);
-      if (getpeername (tcp->fd,
-                      (struct sockaddr *) &peer_addr, &namelen) == 0)
-       tcp->state = TCP_STATE_CONNECTED;
-      else
-       {
-         ret = errno;
-         _tcp_close (stream);
-         return ret;
-       }
-      break;
-    }
-  return 0;
-}
-
-static int
-_tcp_ioctl (mu_stream_t stream, int code, void *ptr)
-{
-  struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
-  mu_transport_t *ptrans;
-
-  switch (code)
-    {
-    case MU_IOCTL_GET_TRANSPORT:
-      if (!ptr)
-       return EINVAL;
-      ptrans = ptr;
-      ptrans[0] = (mu_transport_t) tcp->fd;
-      ptrans[1] = NULL;
-      break;
-
-    default:
-      return ENOSYS;
-    }
-  return 0;
-}
-
-static int
-_tcp_read (mu_stream_t stream, char *buf, size_t size, size_t *pret)
-{
-  struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
-  ssize_t bytes;
-
-  if ((bytes = recv (tcp->fd, buf, size, 0)) == -1)
-    return errno;
-  *pret = bytes;
-  return 0;
-}
-
-static int
-_tcp_write (mu_stream_t stream, const char *buf, size_t size, size_t *pret)
-{
-  struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
-  ssize_t bytes;
-
-  if ((bytes = send (tcp->fd, buf, size, 0)) == -1)
-    return errno;
-  *pret = bytes;
-  return 0;
-}
-
-static void
-_tcp_done (mu_stream_t stream)
-{
-  struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
-
-  if (tcp->host)
-    free (tcp->host);
-  if (tcp->fd != -1)
-    close (tcp->fd);
-}
-
-int
-_tcp_wait (mu_stream_t stream, int *pflags, struct timeval *tvp)
-{
-  struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
-  if (tcp->fd == -1)
-    return EINVAL;
-  return mu_fd_wait (tcp->fd, pflags, tvp);
-}
-
-int
-_tcp_shutdown (mu_stream_t stream, int how)
-{
-  struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
-  int flag;
-  if (tcp->fd == -1)
-    return EINVAL;
-
-  switch (how)
-    {
-    case MU_STREAM_READ:
-      flag = SHUT_RD;
-      break;
-      
-    case MU_STREAM_WRITE:
-      flag = SHUT_WR;
-    }
-
-  if (shutdown (tcp->fd, flag))
-    return errno;
-  return 0;
-}
-
-static struct _tcp_instance *
-_create_tcp_stream (int flags)
-{
-  struct _tcp_instance *tcp =
-    (struct _tcp_instance *)_mu_stream_create (sizeof (*tcp), flags);
-
-  if (tcp)
-    {
-      tcp->stream.open = _tcp_open;
-      tcp->stream.close = _tcp_close;
-      tcp->stream.read = _tcp_read;
-      tcp->stream.write = _tcp_write;
-      tcp->stream.ctl = _tcp_ioctl;
-      tcp->stream.done = _tcp_done;
-      tcp->stream.wait = _tcp_wait;
-      tcp->stream.shutdown = _tcp_shutdown;
-      tcp->fd = -1;
-      tcp->state = TCP_STATE_INIT;
-    }
-  return tcp;
-}
-
-int
-mu_tcp_stream_create_with_source_ip (mu_stream_t *pstream,
-                                    const char *host, int port,
-                                    unsigned long source_ip,
-                                    int flags)
-{
-  int rc;
-  mu_stream_t stream;
-  struct _tcp_instance *tcp;
-
-  if (host == NULL)
-    return MU_ERR_TCP_NO_HOST;
-
-  if (port < 1)
-    return MU_ERR_TCP_NO_PORT;
-
-  tcp = _create_tcp_stream (flags | MU_STREAM_RDWR);
-  if (!tcp)
-    return ENOMEM;
-  tcp->host = strdup (host);
-  if (!tcp->host)
-    {
-      free (tcp);
-      return ENOMEM;
-    }
-  tcp->port = port;
-  tcp->state = TCP_STATE_INIT;
-  tcp->source_addr = source_ip;
-  stream = (mu_stream_t) tcp;
-  rc = mu_stream_open (stream);
-  if (rc == 0 || rc == EAGAIN || rc == EINPROGRESS)
-    *pstream = stream;
-  else
-    mu_stream_destroy (&stream);
-  return rc;
-}
-
-int
-mu_tcp_stream_create_with_source_host (mu_stream_t *stream,
-                                      const char *host, int port,
-                                      const char *source_host,
-                                      int flags)
-{
-  unsigned long source_addr;
-  int ret = resolve_hostname (source_host, &source_addr);
-  if (ret == 0)
-    ret = mu_tcp_stream_create_with_source_ip (stream, host, port,
-                                              source_addr, flags);
-  return ret;
-}
-       
-int
-mu_tcp_stream_create (mu_stream_t *stream, const char *host, int port,
-                     int flags)
-{
-  return mu_tcp_stream_create_with_source_ip (stream, host, port,
-                                             INADDR_ANY, flags);
-}
diff --git a/libmailutils/tests/Makefile.am b/libmailutils/tests/Makefile.am
index a8215fb..a0b9574 100644
--- a/libmailutils/tests/Makefile.am
+++ b/libmailutils/tests/Makefile.am
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/libmailutils/tests/addr.c b/libmailutils/tests/addr.c
index b6bdaa8..64eb884 100644
--- a/libmailutils/tests/addr.c
+++ b/libmailutils/tests/addr.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmailutils/tests/address.at b/libmailutils/tests/address.at
index 0a2bd26..5de3fcd 100644
--- a/libmailutils/tests/address.at
+++ b/libmailutils/tests/address.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/libmailutils/tests/argcv.at b/libmailutils/tests/argcv.at
index ca932e5..857f500 100644
--- a/libmailutils/tests/argcv.at
+++ b/libmailutils/tests/argcv.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/libmailutils/tests/argcv.c b/libmailutils/tests/argcv.c
index 3253feb..88c54a2 100644
--- a/libmailutils/tests/argcv.c
+++ b/libmailutils/tests/argcv.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmailutils/tests/base64d.at b/libmailutils/tests/base64d.at
index 9b68e3e..9983f58 100644
--- a/libmailutils/tests/base64d.at
+++ b/libmailutils/tests/base64d.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/libmailutils/tests/base64e.at b/libmailutils/tests/base64e.at
index 0799fcf..c0e0563 100644
--- a/libmailutils/tests/base64e.at
+++ b/libmailutils/tests/base64e.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/libmailutils/tests/decode2047.at b/libmailutils/tests/decode2047.at
index 2a5fa38..69e7b22 100644
--- a/libmailutils/tests/decode2047.at
+++ b/libmailutils/tests/decode2047.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/libmailutils/tests/decode2047.c b/libmailutils/tests/decode2047.c
index f7c36a9..22120b2 100644
--- a/libmailutils/tests/decode2047.c
+++ b/libmailutils/tests/decode2047.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmailutils/tests/encode2047.at b/libmailutils/tests/encode2047.at
index ed59672..2a47c37 100644
--- a/libmailutils/tests/encode2047.at
+++ b/libmailutils/tests/encode2047.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/libmailutils/tests/encode2047.c b/libmailutils/tests/encode2047.c
index dbf3620..208ef3f 100644
--- a/libmailutils/tests/encode2047.c
+++ b/libmailutils/tests/encode2047.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmailutils/tests/fltst.c b/libmailutils/tests/fltst.c
index d62a02b..e5c0ae1 100644
--- a/libmailutils/tests/fltst.c
+++ b/libmailutils/tests/fltst.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmailutils/tests/fromflt.at b/libmailutils/tests/fromflt.at
index e03bf11..0451451 100644
--- a/libmailutils/tests/fromflt.at
+++ b/libmailutils/tests/fromflt.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/libmailutils/tests/list.at b/libmailutils/tests/list.at
index 093a9d4..b1b1c74 100644
--- a/libmailutils/tests/list.at
+++ b/libmailutils/tests/list.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/libmailutils/tests/listop.c b/libmailutils/tests/listop.c
index 176dd20..564e1d3 100644
--- a/libmailutils/tests/listop.c
+++ b/libmailutils/tests/listop.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmailutils/tests/mailcap.at b/libmailutils/tests/mailcap.at
index e3673db..4a602e6 100644
--- a/libmailutils/tests/mailcap.at
+++ b/libmailutils/tests/mailcap.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/libmailutils/tests/mailcap.c b/libmailutils/tests/mailcap.c
index 136b971..7f50b27 100644
--- a/libmailutils/tests/mailcap.c
+++ b/libmailutils/tests/mailcap.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmailutils/tests/testsuite.at b/libmailutils/tests/testsuite.at
index 46e04b3..ed6e530 100644
--- a/libmailutils/tests/testsuite.at
+++ b/libmailutils/tests/testsuite.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/libmailutils/tests/url-parse.c b/libmailutils/tests/url-parse.c
index 3eb3d1c..92fd4f1 100644
--- a/libmailutils/tests/url-parse.c
+++ b/libmailutils/tests/url-parse.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmailutils/tests/url.at b/libmailutils/tests/url.at
index 010d328..9f933ea 100644
--- a/libmailutils/tests/url.at
+++ b/libmailutils/tests/url.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/libmailutils/ticket.c b/libmailutils/ticket.c
deleted file mode 100644
index ec7f609..0000000
--- a/libmailutils/ticket.c
+++ /dev/null
@@ -1,245 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <errno.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <termios.h>
-
-#include <mailutils/mutil.h>
-#include <mailutils/errno.h>
-#include <mailutils/secret.h>
-#include <mailutils/sys/auth.h>
-
-static void
-echo_off (struct termios *stored_settings)
-{
-  struct termios new_settings;
-  tcgetattr (0, stored_settings);
-  new_settings = *stored_settings;
-  new_settings.c_lflag &= (~ECHO);
-  tcsetattr (0, TCSANOW, &new_settings);
-}
-
-static void
-echo_on (struct termios *stored_settings)
-{
-  tcsetattr (0, TCSANOW, stored_settings);
-}
-
-int
-mu_ticket_create (mu_ticket_t *pticket, void *owner)
-{
-  mu_ticket_t ticket;
-  if (pticket == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  ticket = calloc (1, sizeof (*ticket));
-  if (ticket == NULL)
-    return ENOMEM;
-  ticket->owner = owner;
-  mu_ticket_ref (ticket);
-  *pticket = ticket;
-  return 0;
-}
-
-int
-mu_ticket_ref (mu_ticket_t ticket)
-{
-  if (!ticket)
-    return EINVAL;
-  ticket->refcnt++;
-  return 0;
-}
-  
-int
-mu_ticket_unref (mu_ticket_t ticket)
-{
-  if (!ticket)
-    return EINVAL;
-  if (ticket->refcnt)
-    ticket->refcnt--;
-  if (ticket->refcnt == 0)
-    {
-      if (ticket->plain)
-       free (ticket->plain);
-      if (ticket->secret)
-       mu_secret_destroy (&ticket->secret);
-      if (ticket->_destroy)
-       ticket->_destroy (ticket);
-      free (ticket);
-      return 0;
-    }
-  return MU_ERR_EXISTS;
-}
-      
-void
-mu_ticket_destroy (mu_ticket_t *pticket)
-{
-  if (pticket && *pticket && mu_ticket_unref (*pticket) == 0)
-    *pticket = NULL;
-}
-
-int
-mu_ticket_set_destroy (mu_ticket_t ticket,
-                      void (*_destroy) (mu_ticket_t), void *owner)
-{
-  if (ticket == NULL)
-    return EINVAL;
-  if (ticket->owner != owner)
-    return EACCES;
-  ticket->_destroy = _destroy;
-  return 0;
-}
-
-void *
-mu_ticket_get_owner (mu_ticket_t ticket)
-{
-  return (ticket) ? ticket->owner : NULL;
-}
-
-int
-mu_ticket_set_get_cred (mu_ticket_t ticket,
-                       int  (*_get_cred) (mu_ticket_t, mu_url_t,
-                                          const char *,
-                                          char **, mu_secret_t *),
-                       void *owner)
-{
-  if (ticket == NULL)
-    return EINVAL;
-  if (ticket->owner != owner)
-    return EACCES;
-  ticket->_get_cred = _get_cred;
-  return 0;
-}
-
-int
-mu_ticket_set_secret (mu_ticket_t ticket, mu_secret_t secret)
-{
-  if (ticket == NULL)
-    return EINVAL;
-  if (ticket->secret)
-    mu_secret_unref (ticket->secret);
-  mu_secret_ref (secret);
-  ticket->secret = secret;
-  return 0;
-}
-
-int
-mu_ticket_set_plain (mu_ticket_t ticket, const char *text)
-{
-  if (ticket == NULL)
-    return EINVAL;
-  if (ticket->plain)
-    free (ticket->plain);
-  ticket->plain = strdup (text);
-  if (!ticket->plain)
-    return ENOMEM;
-  return 0;
-}
-
-int
-mu_ticket_get_cred (mu_ticket_t ticket, mu_url_t url, const char *challenge,
-                   char **pplain, mu_secret_t *psec)
-{
-  int rc = 0;
-  char arg[256];
-  
-  if (ticket == NULL || (pplain && psec))
-    return EINVAL;
-  if (pplain == NULL && psec == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-
-  if (ticket->_get_cred)
-    {
-      int res = ticket->_get_cred (ticket, url, challenge, pplain, psec);
-      if (res == 0)
-       return res;
-    }
-
-  if (pplain && ticket->plain)
-    {
-      *pplain = strdup (ticket->plain);
-      if (!*pplain)
-       return ENOMEM;
-    }
-  
-  if (psec && ticket->secret)
-    {
-      mu_secret_ref (ticket->secret);
-      *psec = ticket->secret;
-      return 0;
-    }
-  
-  if (isatty (fileno (stdin)))
-    {
-      struct termios stored_settings;
-      int echo = pplain != NULL;
-
-      printf ("%s", challenge);
-      fflush (stdout);
-      if (!echo)
-       echo_off (&stored_settings);
-      fgets (arg, sizeof (arg), stdin);
-      if (!echo)
-       {
-         echo_on (&stored_settings);
-         putchar ('\n');
-         fflush (stdout);
-       }
-      arg [strlen (arg) - 1] = '\0'; /* nuke the trailing line.  */
-    }
-  else
-    return MU_ERR_FAILURE;
-  
-  if (pplain)
-    {
-      *pplain = strdup (arg);
-      if (!*pplain)
-       return ENOMEM;
-    }
-  else
-    rc = mu_secret_create (psec, arg, strlen (arg));
-  return rc;
-}
-
-void *
-mu_ticket_get_data (mu_ticket_t ticket)
-{
-  if (!ticket)
-    return NULL;
-  return ticket->data;
-}
-
-int
-mu_ticket_set_data (mu_ticket_t ticket, void *data, void *owner)
-{
-  if (ticket == NULL)
-    return EINVAL;
-  if (ticket->owner != owner)
-    return EACCES;
-  ticket->data = data;
-  return 0;
-}
diff --git a/libmailutils/url.c b/libmailutils/url.c
deleted file mode 100644
index d635157..0000000
--- a/libmailutils/url.c
+++ /dev/null
@@ -1,1140 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2007, 2008, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <ctype.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
-#endif
-
-#include <mailutils/mutil.h>
-#include <mailutils/errno.h>
-#include <mailutils/argcv.h>
-#include <mailutils/secret.h>
-#include <mailutils/cctype.h>
-#include <mailutils/cstr.h>
-#include <mailutils/sys/url.h>
-
-#define AC2(a,b) a ## b
-#define AC4(a,b,c,d) a ## b ## c ## d
-
-static int url_parse0 (mu_url_t, char *, size_t *poff, int *decode);
-
-static int
-parse_query (const char *query,
-            char *delim,
-            int *pargc, char ***pargv, const char **pend)
-{
-  size_t count, i;
-  char **v;
-  const char *p;
-
-  for (p = query, count = 0; ; count++)
-    {
-      size_t len = strcspn (p, delim);
-      p += len;
-      if (!*p || *p == delim[1])
-       break;
-      p++;
-    }
-
-  if (pend)
-    *pend = p;
-  if (p == query)
-    return 0;
-  count++;
-
-  v = calloc (count + 1, sizeof (v[0]));
-  for (i = 0, p = query; i < count; i++)
-    {
-      size_t len = strcspn (p, delim);
-      v[i] = mu_url_decode_len (p, len);
-      if (v[i] == NULL)
-       {
-         mu_argcv_free (i, v);
-         return 1;
-       }
-      p += len + 1;
-    }
-  v[i] = NULL;
-
-  *pargc = count;
-  *pargv = v;
-  return 0;
-}
-
-int
-mu_url_create (mu_url_t *purl, const char *name)
-{
-  mu_url_t url = calloc (1, sizeof (*url));
-  if (url == NULL)
-    return ENOMEM;
-
-  url->name = strdup (name);
-  if (url->name == NULL)
-    {
-      free (url);
-      return ENOMEM;
-    }
-  *purl = url;
-  return 0;
-}
-
-static char **
-argcv_copy (size_t argc, char **argv)
-{
-  size_t i;
-  char **nv = calloc (argc + 1, sizeof (nv[0]));
-  if (!nv)
-    return NULL;
-  for (i = 0; i < argc; i++)
-    if ((nv[i] = strdup (argv[i])) == NULL)
-      {
-       mu_argcv_free (i, nv);
-       free (nv);
-       return NULL;
-      }
-  return nv;
-}
-
-static int
-mu_url_copy0 (mu_url_t old_url, mu_url_t new_url)
-{
-  const char *str;
-  size_t argc;
-  char **argv;
-  int rc;
-  mu_secret_t sec;
-
-#define URLCOPY(what)                                          \
-  do                                                           \
-    {                                                          \
-      rc = AC2(mu_url_sget_,what) (old_url, &str);             \
-      if (rc == 0)                                             \
-       {                                                       \
-         if ((new_url->what = strdup (str)) == NULL)           \
-           return ENOMEM;                                      \
-       }                                                       \
-      else if (rc != MU_ERR_NOENT)                             \
-       return rc;                                              \
-    }                                                          \
-  while (0);
-
-  URLCOPY (scheme);
-  URLCOPY (user);
-
-  rc = mu_url_get_secret (old_url, &sec);
-  if (rc == MU_ERR_NOENT)
-    new_url->secret = NULL;
-  else if (rc)
-    return rc;
-  else
-    {
-      rc = mu_secret_dup (sec, &new_url->secret);
-      if (rc)
-       return rc;
-    }
-  
-  URLCOPY (auth);
-  URLCOPY (host);
-  new_url->port = old_url->port;
-  URLCOPY (path);
-
-  rc = mu_url_sget_fvpairs (old_url, &argc, &argv);
-  if (rc == 0 && argc)
-    {
-      if ((new_url->fvpairs = argcv_copy (argc, argv)) == NULL)
-       return ENOMEM;
-      new_url->fvcount = argc;
-    }
-
-  rc = mu_url_sget_query (old_url, &argc, &argv);
-  if (rc == 0 && argc)
-    {
-      if ((new_url->qargv = argcv_copy (argc, argv)) == NULL)
-       return ENOMEM;
-      new_url->qargc = argc;
-    }
-  return 0;
-#undef URLCOPY
-}
-
-int
-mu_url_dup (mu_url_t old_url, mu_url_t *new_url)
-{
-  mu_url_t url;
-  int rc = mu_url_create (&url, mu_url_to_string (old_url));
-
-  if (rc)
-    return rc;
-
-  rc = mu_url_copy0 (old_url, url);
-  if (rc == 0)
-    *new_url = url;
-  else
-    mu_url_destroy (&url);
-  return rc;
-}
-
-int
-mu_url_uplevel (mu_url_t url, mu_url_t *upurl)
-{
-  int rc;
-  char *p;
-  mu_url_t new_url;
-
-  if (url->_uplevel)
-    return url->_uplevel (url, upurl);
-
-  if (!url->path)
-    return MU_ERR_NOENT;
-  p = strrchr (url->path, '/');
-
-  rc = mu_url_dup (url, &new_url);
-  if (rc == 0)
-    {
-      if (!p || p == url->path)
-       {
-         free (new_url->path);
-         new_url->path = NULL;
-       }
-      else
-       {
-         size_t size = p - url->path;
-         new_url->path = realloc (new_url->path, size + 1);
-         if (!new_url->path)
-           {
-             mu_url_destroy (&new_url);
-             return ENOMEM;
-           }
-         memcpy (new_url->path, url->path, size);
-         new_url->path[size] = 0;
-       }
-      *upurl = new_url;
-    }
-  return rc;
-}
-
-void
-mu_url_destroy (mu_url_t * purl)
-{
-  if (purl && *purl)
-    {
-      mu_url_t url = (*purl);
-
-      if (url->_destroy)
-       url->_destroy (url);
-
-      if (url->name)
-       free (url->name);
-
-      if (url->scheme)
-       free (url->scheme);
-
-      if (url->user)
-       free (url->user);
-
-      mu_secret_destroy (&url->secret);
-
-      if (url->auth)
-       free (url->auth);
-
-      if (url->host)
-       free (url->host);
-
-      if (url->path)
-       free (url->path);
-
-      if (url->fvcount)
-       mu_argcv_free (url->fvcount, url->fvpairs);
-
-      mu_argcv_free (url->qargc, url->qargv);
-
-      free (url);
-
-      *purl = NULL;
-    }
-}
-
-int
-mu_url_parse (mu_url_t url)
-{
-  int err = 0;
-  char *n = NULL;
-  struct _mu_url u;
-  size_t pstart;
-  mu_secret_t newsec;
-  int want_decode;
-  
-  if (!url || !url->name)
-    return EINVAL;
-
-  memset (&u, 0, sizeof u);
-  /* can't have been parsed already */
-  if (url->scheme || url->user || url->secret || url->auth ||
-      url->host || url->path || url->qargc)
-    return EINVAL;
-
-  n = strdup (url->name);
-
-  if (!n)
-    return ENOMEM;
-
-  err = url_parse0 (&u, n, &pstart, &want_decode);
-
-  if (!err)
-    {
-      if (u.secret)
-       {
-         /* Obfuscate the password */
-#define PASS_REPL "***"
-#define PASS_REPL_LEN (sizeof (PASS_REPL) - 1)
-         size_t plen = mu_secret_length (u.secret);
-         size_t nlen = strlen (url->name);
-         size_t len = nlen - plen + PASS_REPL_LEN + 1;
-         char *newname;
-
-         memset (url->name + pstart, 0, plen);
-         newname = realloc (url->name, len);
-         if (!newname)
-           goto CLEANUP;
-         memmove (newname + pstart + PASS_REPL_LEN, newname + pstart + plen,
-                  nlen - (pstart + plen) + 1);
-         memcpy (newname + pstart, PASS_REPL, PASS_REPL_LEN);
-         url->name = newname;
-       }
-
-      /* Dup the strings we found. We wouldn't have to do this
-        if we did a single alloc of the source url name, and
-        kept it around. It's also a good time to do hex decoding,
-        though.
-       */
-
-#define UALLOC(X)                                                      \
-      if (u.X && u.X[0] &&                                             \
-         !(url->X = (want_decode ? mu_url_decode (u.X) : strdup (u.X)))) \
-       {                                                               \
-         err = ENOMEM;                                                 \
-         goto CLEANUP;                                                 \
-       }                                                               \
-      else                                                             \
-       {                                                               \
-         /* Set zero-length strings to NULL. */                        \
-         u.X = NULL;                                                   \
-       }
-
-      UALLOC (scheme);
-      UALLOC (user);
-
-      if (u.secret)
-       {
-         char *pass = mu_url_decode (mu_secret_password (u.secret));
-         err = mu_secret_create (&newsec, pass, strlen (pass));
-         memset (pass, 0, strlen (pass));
-         mu_secret_destroy (&u.secret);
-         if (err)
-           goto CLEANUP;
-
-         url->secret = newsec;
-       }
-
-      UALLOC (auth);
-      UALLOC (host);
-      UALLOC (path);
-
-#undef UALLOC
-      url->fvcount = u.fvcount;
-      url->fvpairs = u.fvpairs;
-
-      url->qargc = u.qargc;
-      url->qargv = u.qargv;
-
-      url->port = u.port;
-    }
-
-CLEANUP:
-  memset (n, 0, strlen (n));
-  free (n);
-
-  if (err)
-    {
-#define UFREE(X) if (X) { free(X); X = 0; }
-
-      UFREE (url->scheme);
-      UFREE (url->user);
-      mu_secret_destroy (&u.secret);
-      UFREE (url->auth);
-      UFREE (url->host);
-      UFREE (url->path);
-      mu_argcv_free (url->fvcount, url->fvpairs);
-      mu_argcv_free (url->qargc, url->qargv);
-#undef UFREE
-    }
-
-  return err;
-}
-
-/*
-
-Syntax, condensed from RFC 1738, and extended with the ;auth=
-of RFC 2384 (for POP) and RFC 2192 (for IMAP):
-
-url =
-    scheme ":" [ "//"
-
-    [ user [ ( ":" password ) | ( ";auth=" auth ) ] "@" ]
-
-    host [ ":" port ]
-
-    [ ( "/" urlpath ) | ( "?" query ) ] ]
-
-All hell will break loose in this parser if the user/pass/auth
-portion is missing, and the urlpath has any @ or : characters
-in it. A imap mailbox, say, named after the email address of
-the person the mail is from:
-
-  imap://imap.uniserve.com/address@hidden
-
-Is this required to be % quoted, though? I hope so!
-
-*/
-
-static int
-url_parse0 (mu_url_t u, char *name, size_t *poff, int *decode)
-{
-  char *start = name;
-  char *p;                     /* pointer into name */
-
-  /* reject the obvious */
-  if (name == NULL)
-    return EINVAL;
-
-  if (name[0] == '/')
-    {
-      u->scheme = "file";
-      *decode = 0;
-    }
-  else if (name[0] == '|')
-    {
-      int rc;
-      u->scheme = "prog";
-      *decode = 0;
-      rc = mu_argcv_get (name + 1, NULL, NULL, &u->qargc, &u->qargv);
-      if (rc == 0)
-       {
-         u->path = strdup (u->qargv[0]);
-         if (!u->path)
-           rc = ENOMEM;
-       }
-      return rc;
-    }
-  else
-    {
-      *decode = 1;
-      /* Parse out the SCHEME. */
-      p = strchr (name, ':');
-      if (p == NULL)
-       return MU_ERR_PARSE;
-
-      *p++ = 0;
-
-      u->scheme = name;
-
-      /* RFC 1738, section 2.1, lower the scheme case */
-      for (; name < p; name++)
-       *name = mu_tolower (*name);
-
-      name = p;
-    }
-
-  /* Check for nothing following the scheme. */
-  if (!*name)
-    return 0;
-
-  if (strncmp (name, "//", 2) == 0)
-    {
-      name += 2;
-
-      if (name[0] == '/')
-       {
-         u->path = name;
-         p = u->path + strcspn (u->path, ";?");
-       }
-      else
-       {
-         /* Split into LHS and RHS of the '@', and then parse each side. */
-         u->host = strchr (name, '@');
-         if (u->host == NULL)
-           u->host = name;
-         else
-           {
-             char *pass = NULL;
-
-             /* Parse the LHS into an identification/authentication pair. */
-             *u->host++ = 0;
-
-             u->user = name;
-
-             /* Try to split the user into a:
-                <user>:<password>
-                or
-                <user>:<password>;AUTH=<auth>
-             */
-
-             for (; *name; name++)
-               {
-                 if (*name == ':')
-                   {
-                     *name++ = 0;
-                     pass = name;
-                     *poff = pass - start;
-                   }
-                 else if (*name == ';')
-                   {
-                     /* Make sure it's the auth token. */
-                     if (mu_c_strncasecmp (name + 1, "auth=", 5) == 0)
-                       {
-                         *name++ = 0;
-                         name += 5;
-                         u->auth = name;
-                         break;
-                       }
-                   }
-               }
-
-             if (pass)
-               {
-                 if (mu_secret_create (&u->secret, pass, strlen (pass)))
-                   return ENOMEM;
-                 else
-                   /* Obfuscate password */
-                   memset (pass, 0, strlen (pass));
-               }
-           }
-
-         /* Parse the host and port from the RHS. */
-         p = strchr (u->host, ':');
-         if (p)
-           {
-             *p++ = 0;
-             u->port = strtol (p, &p, 10);
-
-             /* Check for garbage after the port: we should be on the start
-                of a path, a query, or at the end of the string. */
-             if (*p && strcspn (p, "/?") != 0)
-               return MU_ERR_PARSE;
-           }
-         else
-           p = u->host + strcspn (u->host, ";/?");
-       }
-    }
-  else
-    {
-      u->path = name;
-      p = u->path + strcspn (u->path, ";?");
-    }
-
-  /* Either way, if we're not at a nul, we're at a path or query. */
-  if (u->path == NULL && *p == '/')
-    {
-      /* found a path */
-      *p++ = 0;
-      u->path = p;
-      p = u->path + strcspn (u->path, ";?");
-    }
-
-  if (*p == ';')
-    {
-      *p++ = 0;
-      if (parse_query (p, ";?", &u->fvcount, &u->fvpairs, (const char **)&p))
-       return ENOMEM;
-    }
-
-  if (*p == '?')
-    {
-      /* found a query */
-      *p++ = 0;
-      if (parse_query (p, "&", &u->qargc, &u->qargv, NULL))
-       return ENOMEM;
-    }
-
-  return 0;
-}
-
-
-/* General accessors: */
-#define ACCESSOR(action,field) AC4(mu_url_,action,_,field)
-
-#define DECL_SGET(field)                                                 \
-int                                                                      \
-ACCESSOR(sget,field) (mu_url_t url, char const **sptr)                   \
-{                                                                        \
-  if (url == NULL)                                                       \
-    return EINVAL;                                                       \
-  if (!url->field)                                                       \
-    {                                                                    \
-      if (url->AC2(_get_,field))                                         \
-       {                                                                 \
-         size_t n;                                                       \
-         char *buf;                                                      \
-                                                                         \
-         int status = url->AC2(_get_,field) (url, NULL, 0, &n);          \
-         if (status)                                                     \
-           return status;                                                \
-                                                                         \
-         buf = malloc (n + 1);                                           \
-         if (!buf)                                                       \
-           return ENOMEM;                                                \
-                                                                         \
-         status = url->AC2(_get_,field) (url, buf, n + 1, NULL);         \
-         if (status)                                     \
-           return status;                                                \
-                                                                         \
-         if (buf[0])                                                     \
-           {                                                             \
-              url->field = mu_url_decode (buf);                          \
-              free (buf);                                                \
-           }                                                             \
-         else                                                            \
-           url->field = buf;                                             \
-         if (!url->field)                                                \
-           return ENOMEM;                                                \
-       }                                                                 \
-      else                                                               \
-       return MU_ERR_NOENT;                                              \
-    }                                                                    \
-  *sptr = url->field;                                                    \
-  return 0;                                                              \
-}
-
-#define DECL_GET(field)                                                        
  \
-int                                                                      \
-ACCESSOR(get,field) (mu_url_t url, char *buf, size_t len, size_t *n)      \
-{                                                                        \
-  size_t i;                                                              \
-  const char *str;                                                       \
-  int status = ACCESSOR(sget, field) (url, &str);                        \
-                                                                         \
-  if (status)                                                            \
-    return status;                                                       \
-                                                                         \
-  i = mu_cpystr (buf, str, len);                                         \
-  if (n)                                                                 \
-    *n = i;                                                              \
-  return 0;                                                              \
-}
-
-#define DECL_AGET(field)                                                 \
-int                                                                      \
-ACCESSOR(aget, field) (mu_url_t url, char **buf)                         \
-{                                                                        \
-  const char *str;                                                       \
-  int status = ACCESSOR(sget, field) (url, &str);                        \
-                                                                         \
-  if (status)                                                            \
-    return status;                                                       \
-                                                                         \
-  if (str)                                                               \
-    {                                                                    \
-      *buf = strdup (str);                                               \
-      if (!*buf)                                                         \
-       status = ENOMEM;                                                  \
-    }                                                                    \
-  else                                                                   \
-    *buf = NULL;                                                         \
-  return status;                                                         \
-}
-
-#define DECL_CMP(field)                                                        
  \
-int                                                                      \
-ACCESSOR(is_same,field) (mu_url_t url1, mu_url_t url2)                   \
-{                                                                        \
-  const char *s1, *s2;                                                   \
-  int status1, status2;                                                        
  \
-                                                                         \
-  status1 = ACCESSOR(sget, field) (url1, &s1);                           \
-  if (status1 && status1 != MU_ERR_NOENT)                                \
-    return 0;                                                            \
-  status2 = ACCESSOR(sget, field) (url2, &s2);                           \
-  if (status2 && status2 != MU_ERR_NOENT)                                \
-    return 0;                                                            \
-                                                                         \
-  if (status1 || status2)                                                \
-    return status1 == status2; /* Both fields are missing */             \
-  return mu_c_strcasecmp (s1, s2) == 0;                                        
  \
-}
-
-#define DECL_ACCESSORS(field)                                            \
-DECL_SGET(field)                                                         \
-DECL_GET(field)                                                                
  \
-DECL_AGET(field)                                                          \
-DECL_CMP(field)
-
-
-/* Declare particular accessors */
-DECL_ACCESSORS (scheme)
-DECL_ACCESSORS (user)
-DECL_ACCESSORS (auth)
-DECL_ACCESSORS (host)
-DECL_ACCESSORS (path)
-
-int
-mu_url_get_secret (const mu_url_t url, mu_secret_t *psecret)
-{
-  if (url->_get_secret)
-    return url->_get_secret (url, psecret);
-  if (url->secret == NULL)
-    return MU_ERR_NOENT;
-  mu_secret_ref (url->secret);
-  *psecret = url->secret;
-  return 0;
-}
-
-int
-mu_url_sget_query (const mu_url_t url, size_t *qc, char ***qv)
-{
-  if (url == NULL)
-    return EINVAL;
-  /* See FIXME below */
-  *qc = url->qargc;
-  *qv = url->qargv;
-  return 0;
-}
-
-int
-mu_url_aget_query (const mu_url_t url, size_t *qc, char ***qv)
-{
-  size_t qargc, i;
-  char **qargv;
-  char **qcopy;
-
-  int rc = mu_url_sget_fvpairs (url, &qargc, &qargv);
-  if (rc)
-    return rc;
-
-  qcopy = calloc (qargc + 1, sizeof (qcopy[0]));
-  if (!qcopy)
-    return errno;
-  for (i = 0; i < qargc; i++)
-    {
-      if (!(qcopy[i] = strdup (qargv[i])))
-       {
-         mu_argcv_free (i, qcopy);
-         return errno;
-       }
-    }
-  qcopy[i] = NULL;
-  *qc = qargc;
-  *qv = qcopy;
-  return 0;
-}
-
-/* field-value pairs accessors */
-int
-mu_url_sget_fvpairs (const mu_url_t url, size_t *fvc, char ***fvp)
-{
-  if (url == NULL)
-    return EINVAL;
-  /* FIXME: no _get_fvpairs method, but the method stuff needs to be rewritten
-     anyway */
-  *fvc = url->fvcount;
-  *fvp = url->fvpairs;
-  return 0;
-}
-
-int
-mu_url_aget_fvpairs (const mu_url_t url, size_t *pfvc, char ***pfvp)
-{
-  size_t fvc, i;
-  char **fvp;
-  char **fvcopy;
-
-  int rc = mu_url_sget_fvpairs (url, &fvc, &fvp);
-  if (rc)
-    return rc;
-
-  fvcopy = calloc (fvc + 1, sizeof (fvcopy[0]));
-  if (!fvcopy)
-    return errno;
-  for (i = 0; i < fvc; i++)
-    {
-      if (!(fvcopy[i] = strdup (fvp[i])))
-       {
-         mu_argcv_free (i, fvcopy);
-         return errno;
-       }
-    }
-  fvcopy[i] = NULL;
-  *pfvc = fvc;
-  *pfvp = fvcopy;
-  return 0;
-}
-
-int
-mu_url_get_port (const mu_url_t url, long *pport)
-{
-  if (url == NULL)
-    return EINVAL;
-  if (url->_get_port)
-    return url->_get_port (url, pport);
-  *pport = url->port;
-  return 0;
-}
-
-const char *
-mu_url_to_string (const mu_url_t url)
-{
-  if (url == NULL || url->name == NULL)
-    return "";
-  return url->name;
-}
-
-int
-mu_url_set_scheme (mu_url_t url, const char *scheme)
-{
-  char *p;
-  if (!url || !scheme)
-    return EINVAL;
-  p = realloc (url->scheme, strlen (scheme) + 1);
-  if (!p)
-    return ENOMEM;
-  strcpy (url->scheme, scheme);
-  return 0;
-}
-
-int
-mu_url_is_scheme (mu_url_t url, const char *scheme)
-{
-  if (url && scheme && url->scheme 
-      && mu_c_strcasecmp (url->scheme, scheme) == 0)
-    return 1;
-
-  return 0;
-}
-
-int
-mu_url_is_same_port (mu_url_t url1, mu_url_t url2)
-{
-  long p1 = 0, p2 = 0;
-
-  mu_url_get_port (url1, &p1);
-  mu_url_get_port (url2, &p2);
-  return (p1 == p2);
-}
-
-/* From RFC 1738, section 2.2 */
-char *
-mu_url_decode_len (const char *s, size_t len)
-{
-  char *d;
-  const char *eos = s + len;
-  int i;
-
-  d = malloc (len + 1);
-  if (!d)
-    return NULL;
-
-  for (i = 0; s < eos; i++)
-    {
-      if (*s != '%')
-       {
-         d[i] = *s;
-         s++;
-       }
-      else
-       {
-         unsigned long ul = 0;
-
-         s++;
-
-         /* don't check return value, it's correctly coded, or it's not,
-            in which case we just skip the garbage, this is a decoder,
-            not an AI project */
-
-         mu_hexstr2ul (&ul, s, 2);
-
-         s += 2;
-
-         d[i] = (char) ul;
-       }
-    }
-
-  d[i] = 0;
-
-  return d;
-}
-
-char *
-mu_url_decode (const char *s)
-{
-  return mu_url_decode_len (s, strlen (s));
-}
-
-static int
-defined (const char *s)
-{
-  if (s && strcmp ("*", s) != 0)
-    return 1;
-  return 0;
-}
-
-int
-mu_url_is_ticket (mu_url_t ticket, mu_url_t url)
-{
-  if (!ticket || !url)
-    return 0;
-
-  /* If ticket has a scheme, host, port, or path, then the queries
-     equivalent must be defined and match. */
-  if (defined (ticket->scheme))
-    {
-      if (!url->scheme || mu_c_strcasecmp (ticket->scheme, url->scheme) != 0)
-       return 0;
-    }
-  if (defined (ticket->host))
-    {
-      if (!url->host || mu_c_strcasecmp (ticket->host, url->host) != 0)
-       return 0;
-    }
-  if (ticket->port && ticket->port != url->port)
-    return 0;
-  /* If ticket has a user or pass, but url doesn't, that's OK, we were
-     urling for this info. But if url does have a user/pass, it
-     must match the ticket. */
-  if (url->user)
-    {
-      if (defined (ticket->user) && strcmp (ticket->user, url->user) != 0)
-       return 0;
-    }
-
-  /* Guess it matches. */
-  return 1;
-}
-
-int
-mu_url_init (mu_url_t url, int port, const char *scheme)
-{
-  int status = 0;
-
-  url->_destroy = NULL;
-
-  status = mu_url_parse (url);
-  if (status)
-    return status;
-
-  if (!mu_url_is_scheme (url, scheme))
-    return EINVAL;
-
-  if (url->port == 0)
-    url->port = port;
-
-  return status;
-}
-
-/* Default mailbox path generator */
-static char *
-_url_path_default (const char *spooldir, const char *user, int unused)
-{
-  char *mbox = malloc (strlen (spooldir) + strlen (user) + 2);
-  if (!mbox)
-    errno = ENOMEM;
-  else
-    sprintf (mbox, "%s/%s", spooldir, user);
-  return mbox;
-}
-
-/* Hashed indexing */
-static char *
-_url_path_hashed (const char *spooldir, const char *user, int param)
-{
-  int i;
-  int ulen = strlen (user);
-  char *mbox;
-  unsigned hash;
-
-  if (param > ulen)
-    param = ulen;
-  for (i = 0, hash = 0; i < param; i++)
-    hash += user[i];
-
-  mbox = malloc (ulen + strlen (spooldir) + 5);
-  sprintf (mbox, "%s/%02X/%s", spooldir, hash % 256, user);
-  return mbox;
-}
-
-static int transtab[] = {
-  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
-  'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
-  'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
-  'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f',
-  'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
-  'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
-  'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd',
-  'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
-  'm', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
-  'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
-  'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
-  'x', 'y', 'z', 'b', 'c', 'd', 'e', 'f',
-  'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
-  'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
-  'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
-  'x', 'y', 'z', 'b', 'c', 'd', 'e', 'f',
-  'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
-  'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
-  'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
-  'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
-  'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
-  'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
-  'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e',
-  'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
-  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
-  'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
-  'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
-  'y', 'z', 'b', 'c', 'd', 'e', 'f', 'g',
-  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
-  'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
-  'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
-  'y', 'z', 'b', 'c', 'd', 'e', 'f', 'g'
-};
-
-/* Forward Indexing */
-static char *
-_url_path_index (const char *spooldir, const char *iuser, int index_depth)
-{
-  const unsigned char* user = (const unsigned char*) iuser;
-  int i, ulen = strlen (iuser);
-  char *mbox, *p;
-
-  if (ulen == 0)
-    return NULL;
-
-  mbox = malloc (ulen + strlen (spooldir) + 2*index_depth + 2);
-  strcpy (mbox, spooldir);
-  p = mbox + strlen (mbox);
-  for (i = 0; i < index_depth && i < ulen; i++)
-    {
-      *p++ = '/';
-      *p++ = transtab[ user[i] ];
-    }
-  for (; i < index_depth; i++)
-    {
-      *p++ = '/';
-      *p++ = transtab[ user[ulen-1] ];
-    }
-  *p++ = '/';
-  strcpy (p, iuser);
-  return mbox;
-}
-
-/* Reverse Indexing */
-static char *
-_url_path_rev_index (const char *spooldir, const char *iuser, int index_depth)
-{
-  const unsigned char* user = (const unsigned char*) iuser;
-  int i, ulen = strlen (iuser);
-  char *mbox, *p;
-
-  if (ulen == 0)
-    return NULL;
-
-  mbox = malloc (ulen + strlen (spooldir) + 2*index_depth + 1);
-  strcpy (mbox, spooldir);
-  p = mbox + strlen (mbox);
-  for (i = 0; i < index_depth && i < ulen; i++)
-    {
-      *p++ = '/';
-      *p++ = transtab[ user[ulen - i - 1] ];
-    }
-  for (; i < index_depth; i++)
-    {
-      *p++ = '/';
-      *p++ = transtab[ user[0] ];
-    }
-  *p++ = '/';
-  strcpy (p, iuser);
-  return mbox;
-}
-
-static int
-rmselector (const char *p, void *data MU_ARG_UNUSED)
-{
-  return strncmp (p, "type=", 5) == 0
-        || strncmp (p, "user=", 5) == 0
-        || strncmp (p, "param=", 6) == 0;
-}
-
-int
-mu_url_expand_path (mu_url_t url)
-{
-  size_t i;
-  char *user = NULL;
-  int param = 0;
-  char *p;
-  char *(*fun) (const char *, const char *, int) = _url_path_default;
-
-  if (url->fvcount == 0)
-    return 0;
-
-  for (i = 0; i < url->fvcount; i++)
-    {
-      p = url->fvpairs[i];
-      if (strncmp (p, "type=", 5) == 0)
-       {
-         char *type = p + 5;
-
-         if (strcmp (type, "hash") == 0)
-           fun = _url_path_hashed;
-         else if (strcmp (type, "index") == 0)
-           fun = _url_path_index;
-         else if (strcmp (type, "rev-index") == 0)
-           fun = _url_path_rev_index;
-         else
-           return MU_ERR_NOENT;
-       }
-      else if (strncmp (p, "user=", 5) == 0)
-       {
-         user = p + 5;
-       }
-      else if (strncmp (p, "param=", 6) == 0)
-       {
-         param = strtoul (p + 6, NULL, 0);
-       }
-    }
-
-  if (user)
-    {
-      char *p = fun (url->path, user, param);
-      if (p)
-       {
-         free (url->path);
-         url->path = p;
-       }
-      mu_argcv_remove (&url->fvcount, &url->fvpairs, rmselector, NULL);
-    }
-  else
-    return MU_ERR_NOENT;
-
-  return 0;
-}
diff --git a/libmailutils/vasnprintf.c b/libmailutils/vasnprintf.c
deleted file mode 100644
index 0f4350e..0000000
--- a/libmailutils/vasnprintf.c
+++ /dev/null
@@ -1,87 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#if HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-
-#include <mailutils/io.h>
-
-int
-mu_vasnprintf (char **pbuf, size_t *psize, const char *fmt, va_list ap)
-{
-  char *buf = *pbuf;
-  size_t buflen = *psize;
-  int rc = 0;
-  
-  if (!buf)
-    {
-      if (buflen == 0)
-       buflen = 512; /* Initial allocation */
-      
-      buf = calloc (1, buflen);
-      if (buf == NULL)
-       return ENOMEM;
-    }
-  
-  for (;;)
-    {
-      ssize_t n = vsnprintf (buf, buflen, fmt, ap);
-      if (n < 0 || n >= buflen || !memchr (buf, '\0', n + 1))
-       {
-         char *newbuf;
-         size_t newlen = buflen * 2;
-         if (newlen < buflen)
-           {
-             rc = ENOMEM;
-             break;
-           }
-         newbuf = realloc (buf, newlen);
-         if (newbuf == NULL)
-           {
-             rc = ENOMEM;
-             break;
-           }
-         buflen = newlen;
-         buf = newbuf;
-       }
-      else
-       break;
-    }
-
-  if (rc)
-    {
-      if (!*pbuf)
-       {
-         /* We made first allocation, now free it */
-         free (buf);
-         buf = NULL;
-         buflen = 0;
-       }
-    }
-
-  *pbuf = buf;
-  *psize = buflen;
-  return rc;
-}
diff --git a/libmailutils/version.c b/libmailutils/version.c
deleted file mode 100644
index 1967dab..0000000
--- a/libmailutils/version.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   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
-   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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <mailutils/nls.h>
-#include <mailutils/version.h>
-#include <mailutils/cstr.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <confpaths.h>
-
-char *mu_license_text =
- N_("   GNU Mailutils is free software; you can redistribute it and/or 
modify\n"
-    "   it under the terms of the GNU General Public License as published by\n"
-    "   the Free Software Foundation; either version 3 of the License, or\n"
-    "   (at your option) any later version.\n"
-    "\n"
-    "   GNU Mailutils is distributed in the hope that it will be useful,\n"
-    "   but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
-    "   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
-    "   GNU General Public License for more details.\n"
-    "\n"
-    "   You should have received a copy of the GNU General Public License 
along\n"
-    "   with GNU Mailutils; if not, write to the Free Software Foundation,\n"
-    "   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n"
-    "\n"
-    "\n"
-);
-
-static struct mu_conf_option mu_conf_option[] = {
-  { "VERSION=" VERSION, N_("Version of this package") },
-  { "SYSCONFDIR=" SYSCONFDIR, N_("System configuration directory") },
-  { "MAILSPOOLDIR=" MU_PATH_MAILDIR, N_("Default mail spool directory") },
-  { "SCHEME=" MU_DEFAULT_SCHEME, N_("Default mailbox type") },
-  { "LOG_FACILITY=" LOG_FACILITY_STRING, N_("Default syslog facility") },
-#ifdef USE_LIBPAM
-  { "USE_LIBPAM", N_("PAM support") },
-#endif
-#ifdef HAVE_LIBLTDL
-  { "HAVE_LIBLTDL", N_("a portable `dlopen' wrapper library") },
-#endif
-#ifdef WITH_BDB2
-  { "WITH_BDB2", N_("Berkeley DB v. 2") },
-#endif
-#ifdef WITH_NDBM
-  { "WITH_NDBM", },
-#endif
-#ifdef WITH_OLD_DBM
-  { "WITH_OLD_DBM", N_("Old DBM support") },
-#endif
-#ifdef WITH_GDBM
-  { "WITH_GDBM", N_("GNU DBM") },
-#endif
-#ifdef WITH_TOKYOCABINET
-  { "WITH_TOKYOCABINET", N_("Tokyo Cabinet DBM") },
-#endif
-#ifdef WITH_GNUTLS
-  { "WITH_GNUTLS", N_("TLS support using GNU TLS") },
-#endif
-#ifdef WITH_GSASL
-  { "WITH_GSASL", N_("SASL support using GNU SASL") },
-#endif
-#ifdef WITH_GSSAPI
-  { "WITH_GSSAPI", N_("GSSAPI support") },
-#endif
-#ifdef WITH_GUILE
-  { "WITH_GUILE", N_("Support for Guile as extension language") },
-#endif
-#ifdef WITH_PYTHON
-  { "WITH_PYTHON", N_("Support for Python as extension language") },
-#endif
-#ifdef WITH_PTHREAD
-  { "WITH_PTHREAD", N_("Support for POSIX threads") },
-#endif
-#ifdef WITH_READLINE
-  { "WITH_READLINE", N_("GNU Readline") },
-#endif
-#ifdef HAVE_MYSQL
-  { "HAVE_MYSQL", N_("MySQL") },
-#endif
-#ifdef HAVE_PGSQL
-  { "HAVE_PGSQL", N_("PostgreSQL") },
-#endif
-#ifdef WITH_LDAP
-  { "WITH_LDAP", },
-#endif
-#ifdef WITH_LIBWRAP
-  { "WITH_LIBWRAP", N_("Support for TCP wrappers") },
-#endif
-#ifdef ENABLE_VIRTUAL_DOMAINS
-  { "ENABLE_VIRTUAL_DOMAINS", N_("Support for virtual mail domains") },
-#endif
-#ifdef ENABLE_IMAP
-  { "ENABLE_IMAP", N_("IMAP4 protocol support") },
-#endif
-#ifdef ENABLE_POP
-  { "ENABLE_POP",  N_("POP3 protocol support") },
-#endif
-#ifdef ENABLE_MH
-  { "ENABLE_MH", N_("MH mail storage support") },
-#endif
-#ifdef ENABLE_MAILDIR
-  { "ENABLE_MAILDIR", N_("Maildir mail storage support") },
-#endif
-#ifdef ENABLE_SMTP
-  { "ENABLE_SMTP", N_("SMTP protocol support") },
-#endif
-#ifdef ENABLE_SENDMAIL
-  { "ENABLE_SENDMAIL", N_("Sendmail command line interface support")},
-#endif
-#ifdef ENABLE_NNTP
-  { "ENABLE_NNTP", N_("NNTP protocol support") },
-#endif
-#ifdef ENABLE_RADIUS
-  { "ENABLE_RADIUS", N_("RADIUS protocol support") },
-#endif
-#ifdef WITH_INCLUDED_LIBINTL
-  { "WITH_INCLUDED_LIBINTL", N_("GNU libintl compiled in") },
-#endif
-  { NULL }
-};
-
-void
-mu_fprint_conf_option (FILE *fp, const struct mu_conf_option *opt, int verbose)
-{
-  fprintf (fp, "%s", opt->name);
-  if (verbose && opt->descr)
-    fprintf (fp, " \t- %s", _(opt->descr));
-  fputc('\n', fp);
-}
-
-void
-mu_fprint_options (FILE *fp, int verbose)
-{
-  int i;
-  
-  for (i = 0; mu_conf_option[i].name; i++)
-    mu_fprint_conf_option (fp, mu_conf_option + i, verbose);
-}
-
-void
-mu_print_options ()
-{
-  mu_fprint_options (stdout, 1);
-}
-
-const struct mu_conf_option *
-mu_check_option (char *name)
-{
-  int i;
-  
-  for (i = 0; mu_conf_option[i].name; i++)
-    {
-      int len;
-      char *q, *p = strchr (mu_conf_option[i].name, '=');
-      if (p)
-       len = p - mu_conf_option[i].name;
-      else
-       len = strlen (mu_conf_option[i].name);
-
-      if (mu_c_strncasecmp (mu_conf_option[i].name, name, len) == 0)
-       return &mu_conf_option[i];
-      else if ((q = strchr (mu_conf_option[i].name, '_')) != NULL
-              && mu_c_strncasecmp (q + 1, name,
-                              len - (q - mu_conf_option[i].name) - 1) == 0)
-       return &mu_conf_option[i];
-    }
-  return NULL;
-}  
-
diff --git a/libmailutils/wicket.c b/libmailutils/wicket.c
deleted file mode 100644
index 8b0fbbb..0000000
--- a/libmailutils/wicket.c
+++ /dev/null
@@ -1,357 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <pwd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <ctype.h>
-
-#include <mailutils/errno.h>
-#include <mailutils/mutil.h>
-#include <mailutils/mu_auth.h>
-#include <mailutils/stream.h>
-
-#include <mailutils/sys/auth.h>
-#include <mailutils/sys/url.h>
-
-int
-mu_wicket_create (mu_wicket_t *pwicket)
-{
-  mu_wicket_t wicket = calloc (1, sizeof (*wicket));
-  if (!wicket)
-    return ENOMEM;
-  wicket->refcnt = 1;
-  *pwicket = wicket;
-  return 0;
-}
-
-int
-mu_wicket_get_ticket (mu_wicket_t wicket, const char *user, mu_ticket_t 
*pticket)
-{
-  if (!wicket)
-    return EINVAL;
-  if (!pticket)
-    return EINVAL;
-  if (!wicket->_get_ticket)
-    return ENOSYS;
-  return wicket->_get_ticket (wicket, wicket->data, user, pticket);
-}
-
-int
-mu_wicket_ref (mu_wicket_t wicket)
-{
-  if (!wicket)
-    return EINVAL;
-  wicket->refcnt++;
-  return 0;
-}
-
-int
-mu_wicket_unref (mu_wicket_t wicket)
-{
-  if (!wicket)
-    return EINVAL;
-  if (wicket->refcnt)
-    wicket->refcnt--;
-  if (wicket->refcnt == 0)
-    {
-      if (wicket->_destroy)
-       wicket->_destroy (wicket);
-      free (wicket);
-      return 0;
-    }
-  return MU_ERR_EXISTS;
-}
-
-
-void
-mu_wicket_destroy (mu_wicket_t *pwicket)
-{
-  if (pwicket && *pwicket && mu_wicket_unref (*pwicket) == 0)
-    *pwicket = NULL;
-}
-
-int
-mu_wicket_set_destroy (mu_wicket_t wicket, void (*_destroy) (mu_wicket_t))
-{
-  if (!wicket)
-    return EINVAL;
-  wicket->_destroy = _destroy;
-  return 0;
-}
-
-int
-mu_wicket_set_data (mu_wicket_t wicket, void *data)
-{
-  if (!wicket)
-    return EINVAL;
-  wicket->data = data;
-  return 0;
-}
-
-void *
-mu_wicket_get_data (mu_wicket_t wicket)
-{
-  if (!wicket)
-    return NULL;
-  return wicket->data;
-}
-
-int
-mu_wicket_set_get_ticket (mu_wicket_t wicket,
-                         int (*_get_ticket) (mu_wicket_t, void *,
-                                             const char *, mu_ticket_t *))
-{
-  if (!wicket)
-    return EINVAL;
-  wicket->_get_ticket = _get_ticket;
-  return 0;
-}
-
-
-/* A "file wicket" implementation */
-
-struct file_wicket
-{
-  char *filename;
-};
-
-static void
-_file_wicket_destroy (mu_wicket_t wicket)
-{
-  struct file_wicket *fw = mu_wicket_get_data (wicket);
-  free (fw->filename);
-  free (fw);
-}
-
-struct file_ticket
-{
-  char *filename;
-  char *user;
-  mu_url_t tickurl;
-};
-
-static void
-file_ticket_destroy (mu_ticket_t ticket)
-{
-  struct file_ticket *ft = mu_ticket_get_data (ticket);
-  if (ft)
-    {
-      free (ft->filename);
-      free (ft->user);
-      mu_url_destroy (&ft->tickurl);
-      free (ft);
-    }
-}
-
-static int get_ticket_url (mu_ticket_t ticket, mu_url_t url, mu_url_t 
*pticket_url);
-
-int
-file_ticket_get_cred (mu_ticket_t ticket, mu_url_t url, const char *challenge,
-                     char **pplain, mu_secret_t *psec)
-{
-  struct file_ticket *ft = mu_ticket_get_data (ticket);
-
-  if (!ft->tickurl)
-    {
-      int rc = get_ticket_url (ticket, url, &ft->tickurl);
-      if (rc)
-       return rc;
-    }
-  if (pplain)
-    {
-      if (ft->user)
-       {
-         *pplain = strdup (ft->user);
-         if (!*pplain)
-           return ENOMEM;
-       }
-      else
-       return mu_url_aget_user (ft->tickurl, pplain);
-    }
-  else
-    return mu_url_get_secret (ft->tickurl, psec);
-}
-
-static int
-_file_wicket_get_ticket (mu_wicket_t wicket, void *data,
-                        const char *user, mu_ticket_t *pticket)
-{
-  int rc;
-  mu_ticket_t ticket;
-  struct file_wicket *fw = data;
-  struct file_ticket *ft = calloc (1, sizeof (*ft));
-  ft->filename = strdup (fw->filename);
-  if (!ft->filename)
-    {
-      free (ft);
-      return ENOMEM;
-    }
-  if (user)
-    {
-      ft->user = strdup (user);
-      if (!ft->user)
-       {
-         free (ft->filename);
-         free (ft);
-         return ENOMEM;
-       }
-    }
-  else
-    ft->user = NULL;
-
-  rc = mu_ticket_create (&ticket, NULL);
-  if (rc)
-    {
-      free (ft->filename);
-      free (ft->user);
-      free (ft);
-      return rc;
-    }
-       
-  mu_ticket_set_destroy (ticket, file_ticket_destroy, NULL);
-  mu_ticket_set_data (ticket, ft, NULL);
-  mu_ticket_set_get_cred (ticket, file_ticket_get_cred, NULL);
-
-  *pticket = ticket;
-  return 0;
-}
-  
-static int
-get_ticket_url (mu_ticket_t ticket, mu_url_t url, mu_url_t *pticket_url)
-{
-  mu_stream_t stream;
-  struct file_ticket *ft = mu_ticket_get_data (ticket);
-  int rc;
-  mu_url_t u = NULL;
-  char *buf = NULL;
-  size_t bufsize = 0;
-  size_t len;
-  
-  rc = mu_file_stream_create (&stream, ft->filename, MU_STREAM_READ);
-  if (rc)
-    return rc;
-    
-  while ((rc = mu_stream_getline (stream, &buf, &bufsize, &len)) == 0
-        && len > 0)
-    {
-      char *p;
-      int err;
-      
-      /* Truncate a trailing newline. */
-      if (len && buf[len - 1] == '\n')
-       buf[--len] = 0;
-      
-      /* Skip leading spaces  */
-      for (p = buf; *p == ' ' || *p == '\t'; p++)
-       ;
-      /* Skip trailing spaces */
-      for (; len > 0 && (p[len-1] == ' ' || p[len-1] == '\t'); )
-       p[--len] = 0;
-      
-      /* Skip empty lines and comments. */
-      if (*p == 0 || *p == '#')
-       continue;
-      
-      if ((err = mu_url_create (&u, p)) != 0)
-       {
-         /* Skip erroneous entry */
-         /* FIXME: Error message */
-         continue;
-       }
-      if ((err = mu_url_parse (u)) != 0)
-       {
-         /* FIXME: See above */
-         mu_url_destroy (&u);
-         continue;
-       }
-      
-      if (!mu_url_is_ticket (u, url))
-       {
-         mu_url_destroy (&u);
-         continue;
-       }
-      
-      if (ft->user)
-       {
-         if (u->name && strcmp (u->name, "*") != 0
-             && strcmp (ft->user, u->name) != 0)
-           {
-             mu_url_destroy (&u);
-             continue;
-           }
-       }
-      
-      break;
-    }
-  mu_stream_close (stream);
-  free (buf);
-    
-  mu_stream_destroy (&stream);
-
-  if (rc == 0)
-    {
-      if (u)
-       *pticket_url = u;
-      else
-       rc = MU_ERR_NOENT;
-    }
-  
-  return rc;
-}
-
-int
-mu_file_wicket_create (mu_wicket_t *pwicket, const char *filename)
-{
-  mu_wicket_t wicket;
-  int rc;
-  struct file_wicket *fw = calloc (1, sizeof (*fw));
-
-  if (!fw)
-    return ENOMEM;
-  fw->filename = strdup (filename);
-  if (!fw->filename)
-    {
-      free (fw);
-      return ENOMEM;
-    }
-  
-  rc = mu_wicket_create (&wicket);
-  if (rc)
-    {
-      free (fw->filename);
-      free (fw);
-      return rc;
-    }
-  mu_wicket_set_data (wicket, fw);
-  mu_wicket_set_destroy (wicket, _file_wicket_destroy);
-  mu_wicket_set_get_ticket (wicket, _file_wicket_get_ticket);
-  *pwicket = wicket;
-  return 0;
-}
-
diff --git a/libmu_argp/Makefile.am b/libmu_argp/Makefile.am
index 93c26d2..1045562 100644
--- a/libmu_argp/Makefile.am
+++ b/libmu_argp/Makefile.am
@@ -12,9 +12,7 @@
 # General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
-# along with GNU Mailutils; if not, write to the Free Software
-# Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 # This library uses gnulib calls and is always linked with gnulib, therefore
 # we use application includes here.
diff --git a/libmu_argp/auth.c b/libmu_argp/auth.c
index 929912a..86d48cf 100644
--- a/libmu_argp/auth.c
+++ b/libmu_argp/auth.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_argp/cmdline.c b/libmu_argp/cmdline.c
index 61b217f..26f84fa 100644
--- a/libmu_argp/cmdline.c
+++ b/libmu_argp/cmdline.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_argp/cmdline.h b/libmu_argp/cmdline.h
index fecb043..651ff0f 100644
--- a/libmu_argp/cmdline.h
+++ b/libmu_argp/cmdline.h
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include "mailutils/libcfg.h"
 #include "mailutils/libargp.h"
diff --git a/libmu_argp/common.c b/libmu_argp/common.c
index aa481de..a76e378 100644
--- a/libmu_argp/common.c
+++ b/libmu_argp/common.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_argp/mu_argp.c b/libmu_argp/mu_argp.c
index 75618f6..ec854e9 100644
--- a/libmu_argp/mu_argp.c
+++ b/libmu_argp/mu_argp.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_argp/muinit.c b/libmu_argp/muinit.c
index 85b65ed..413389b 100644
--- a/libmu_argp/muinit.c
+++ b/libmu_argp/muinit.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_argp/sieve.c b/libmu_argp/sieve.c
index 2bff3d3..5a39c31 100644
--- a/libmu_argp/sieve.c
+++ b/libmu_argp/sieve.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_argp/tls.c b/libmu_argp/tls.c
index b516062..408ec8b 100644
--- a/libmu_argp/tls.c
+++ b/libmu_argp/tls.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_auth/Makefile.am b/libmu_auth/Makefile.am
index 2533ffb..a239cd2 100644
--- a/libmu_auth/Makefile.am
+++ b/libmu_auth/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2002, 2003, 2005, 2006, 2010 Free Software
-##   Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2002, 2003, 2005, 2006, 2010 Free Software
+## Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   GNU Mailutils is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with GNU Mailutils; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 INCLUDES = @MU_LIB_COMMON_INCLUDES@ 
 AM_CFLAGS = -DSITE_VIRTUAL_PWDDIR=\"@address@hidden" \
diff --git a/libmu_auth/gsasl.c b/libmu_auth/gsasl.c
index c4e98f5..10b14bf 100644
--- a/libmu_auth/gsasl.c
+++ b/libmu_auth/gsasl.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #if HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_auth/ldap.c b/libmu_auth/ldap.c
index 419ea6c..f29472e 100644
--- a/libmu_auth/ldap.c
+++ b/libmu_auth/ldap.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_auth/pam.c b/libmu_auth/pam.c
index ff66c43..5ea88a3 100644
--- a/libmu_auth/pam.c
+++ b/libmu_auth/pam.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_auth/radius.c b/libmu_auth/radius.c
index b848b42..048a9c7 100644
--- a/libmu_auth/radius.c
+++ b/libmu_auth/radius.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_auth/sql.c b/libmu_auth/sql.c
index 87e3f60..e84911a 100644
--- a/libmu_auth/sql.c
+++ b/libmu_auth/sql.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_auth/sql.h b/libmu_auth/sql.h
index 3a6696d..985375a 100644
--- a/libmu_auth/sql.h
+++ b/libmu_auth/sql.h
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <sys/types.h>
 #include <stdlib.h>
diff --git a/libmu_auth/tls.c b/libmu_auth/tls.c
index e6e4551..01633c5 100644
--- a/libmu_auth/tls.c
+++ b/libmu_auth/tls.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #if HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_auth/virtual.c b/libmu_auth/virtual.c
index 1932ea4..ad15352 100644
--- a/libmu_auth/virtual.c
+++ b/libmu_auth/virtual.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library. If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_cfg/Makefile.am b/libmu_cfg/Makefile.am
index 2baa59f..d3ddabb 100644
--- a/libmu_cfg/Makefile.am
+++ b/libmu_cfg/Makefile.am
@@ -12,9 +12,7 @@
 # General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
-# along with GNU Mailutils; if not, write to the Free Software
-# Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 INCLUDES = @MU_LIB_COMMON_INCLUDES@ 
 AM_CFLAGS = -DSITE_VIRTUAL_PWDDIR=\"@address@hidden" \
diff --git a/libmu_cfg/acl.c b/libmu_cfg/acl.c
index d9b769c..0ad60e4 100644
--- a/libmu_cfg/acl.c
+++ b/libmu_cfg/acl.c
@@ -6,13 +6,13 @@
    published by the Free Software Foundation; either version 3, or (at
    your option) any later version.
 
-   This program is distributed in the hope that it will be useful, but
+   GNU Mailutils is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifdef HAVE_CONFIG_H
diff --git a/libmu_cfg/auth.c b/libmu_cfg/auth.c
index dde04f6..d19c8e3 100644
--- a/libmu_cfg/auth.c
+++ b/libmu_cfg/auth.c
@@ -6,13 +6,13 @@
    published by the Free Software Foundation; either version 3, or (at
    your option) any later version.
 
-   This program is distributed in the hope that it will be useful, but
+   GNU Mailutils is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifdef HAVE_CONFIG_H
diff --git a/libmu_cfg/common.c b/libmu_cfg/common.c
index 17c39c4..ec59b60 100644
--- a/libmu_cfg/common.c
+++ b/libmu_cfg/common.c
@@ -6,13 +6,13 @@
    published by the Free Software Foundation; either version 3, or (at
    your option) any later version.
 
-   This program is distributed in the hope that it will be useful, but
+   GNU Mailutils is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifdef HAVE_CONFIG_H
diff --git a/libmu_cfg/gsasl.c b/libmu_cfg/gsasl.c
index cd37d46..7d6690b 100644
--- a/libmu_cfg/gsasl.c
+++ b/libmu_cfg/gsasl.c
@@ -6,13 +6,13 @@
    published by the Free Software Foundation; either version 3, or (at
    your option) any later version.
 
-   This program is distributed in the hope that it will be useful, but
+   GNU Mailutils is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifdef HAVE_CONFIG_H
diff --git a/libmu_cfg/init.c b/libmu_cfg/init.c
index d9f84d6..1dcaa77 100644
--- a/libmu_cfg/init.c
+++ b/libmu_cfg/init.c
@@ -6,13 +6,13 @@
    published by the Free Software Foundation; either version 3, or (at
    your option) any later version.
 
-   This program is distributed in the hope that it will be useful, but
+   GNU Mailutils is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifdef HAVE_CONFIG_H
diff --git a/libmu_cfg/ldap.c b/libmu_cfg/ldap.c
index ea59a49..953fa3e 100644
--- a/libmu_cfg/ldap.c
+++ b/libmu_cfg/ldap.c
@@ -6,13 +6,13 @@
    published by the Free Software Foundation; either version 3, or (at
    your option) any later version.
 
-   This program is distributed in the hope that it will be useful, but
+   GNU Mailutils is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifdef HAVE_CONFIG_H
diff --git a/libmu_cfg/pam.c b/libmu_cfg/pam.c
index 502e306..4cd2fab 100644
--- a/libmu_cfg/pam.c
+++ b/libmu_cfg/pam.c
@@ -6,13 +6,13 @@
    published by the Free Software Foundation; either version 3, or (at
    your option) any later version.
 
-   This program is distributed in the hope that it will be useful, but
+   GNU Mailutils is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifdef HAVE_CONFIG_H
diff --git a/libmu_cfg/radius.c b/libmu_cfg/radius.c
index 62f6960..4f81efd 100644
--- a/libmu_cfg/radius.c
+++ b/libmu_cfg/radius.c
@@ -6,13 +6,13 @@
    published by the Free Software Foundation; either version 3, or (at
    your option) any later version.
 
-   This program is distributed in the hope that it will be useful, but
+   GNU Mailutils is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifdef HAVE_CONFIG_H
diff --git a/libmu_cfg/sieve.c b/libmu_cfg/sieve.c
index 5b4a5ed..911cedc 100644
--- a/libmu_cfg/sieve.c
+++ b/libmu_cfg/sieve.c
@@ -6,13 +6,13 @@
    published by the Free Software Foundation; either version 3, or (at
    your option) any later version.
 
-   This program is distributed in the hope that it will be useful, but
+   GNU Mailutils is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifdef HAVE_CONFIG_H
diff --git a/libmu_cfg/sql.c b/libmu_cfg/sql.c
index 360448d..daf91e9 100644
--- a/libmu_cfg/sql.c
+++ b/libmu_cfg/sql.c
@@ -6,13 +6,13 @@
    published by the Free Software Foundation; either version 3, or (at
    your option) any later version.
 
-   This program is distributed in the hope that it will be useful, but
+   GNU Mailutils is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifdef HAVE_CONFIG_H
diff --git a/libmu_cfg/tls.c b/libmu_cfg/tls.c
index 3e7cf38..16e80d3 100644
--- a/libmu_cfg/tls.c
+++ b/libmu_cfg/tls.c
@@ -6,13 +6,13 @@
    published by the Free Software Foundation; either version 3, or (at
    your option) any later version.
 
-   This program is distributed in the hope that it will be useful, but
+   GNU Mailutils is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifdef HAVE_CONFIG_H
diff --git a/libmu_cfg/virtdomain.c b/libmu_cfg/virtdomain.c
index 7c3217d..b114d9b 100644
--- a/libmu_cfg/virtdomain.c
+++ b/libmu_cfg/virtdomain.c
@@ -6,13 +6,13 @@
    published by the Free Software Foundation; either version 3, or (at
    your option) any later version.
 
-   This program is distributed in the hope that it will be useful, but
+   GNU Mailutils is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifdef HAVE_CONFIG_H
diff --git a/libmu_cpp/Makefile.am b/libmu_cpp/Makefile.am
index e6154de..b89cd22 100644
--- a/libmu_cpp/Makefile.am
+++ b/libmu_cpp/Makefile.am
@@ -1,22 +1,19 @@
-##   Process this file with GNU Automake to create Makefile.in
+## This file is part of GNU Mailutils.
+## Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software
+## Foundation, Inc.
 ##
-##   Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software
-##   Foundation, Inc.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
-##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 INCLUDES = @MU_LIB_COMMON_INCLUDES@ 
 
diff --git a/libmu_cpp/address.cc b/libmu_cpp/address.cc
index 7ed7dff..757cd28 100644
--- a/libmu_cpp/address.cc
+++ b/libmu_cpp/address.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/cpp/address.h>
 
diff --git a/libmu_cpp/attribute.cc b/libmu_cpp/attribute.cc
index 247c117..570cfcd 100644
--- a/libmu_cpp/attribute.cc
+++ b/libmu_cpp/attribute.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/cpp/attribute.h>
 
diff --git a/libmu_cpp/body.cc b/libmu_cpp/body.cc
index 93370a2..311013f 100644
--- a/libmu_cpp/body.cc
+++ b/libmu_cpp/body.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/cpp/body.h>
 
diff --git a/libmu_cpp/debug.cc b/libmu_cpp/debug.cc
index 4042137..95407c4 100644
--- a/libmu_cpp/debug.cc
+++ b/libmu_cpp/debug.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/cpp/debug.h>
 
diff --git a/libmu_cpp/envelope.cc b/libmu_cpp/envelope.cc
index e1fff64..7259b29 100644
--- a/libmu_cpp/envelope.cc
+++ b/libmu_cpp/envelope.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/cpp/envelope.h>
 
diff --git a/libmu_cpp/filter.cc b/libmu_cpp/filter.cc
index cf53e1b..1d392dc 100644
--- a/libmu_cpp/filter.cc
+++ b/libmu_cpp/filter.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/cpp/filter.h>
 
diff --git a/libmu_cpp/folder.cc b/libmu_cpp/folder.cc
index aa53941..85cf083 100644
--- a/libmu_cpp/folder.cc
+++ b/libmu_cpp/folder.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/cpp/folder.h>
 
diff --git a/libmu_cpp/header.cc b/libmu_cpp/header.cc
index cc44067..4ba2daa 100644
--- a/libmu_cpp/header.cc
+++ b/libmu_cpp/header.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/cpp/header.h>
 
diff --git a/libmu_cpp/iterator.cc b/libmu_cpp/iterator.cc
index b0aa161..2306923 100644
--- a/libmu_cpp/iterator.cc
+++ b/libmu_cpp/iterator.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/cpp/iterator.h>
 
diff --git a/libmu_cpp/list.cc b/libmu_cpp/list.cc
index 75dd945..9066c0c 100644
--- a/libmu_cpp/list.cc
+++ b/libmu_cpp/list.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/cpp/list.h>
 
diff --git a/libmu_cpp/mailbox.cc b/libmu_cpp/mailbox.cc
index b0e2d56..56761fc 100644
--- a/libmu_cpp/mailbox.cc
+++ b/libmu_cpp/mailbox.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/cpp/mailbox.h>
 
diff --git a/libmu_cpp/mailcap.cc b/libmu_cpp/mailcap.cc
index 14cb01c..00ff72e 100644
--- a/libmu_cpp/mailcap.cc
+++ b/libmu_cpp/mailcap.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/cpp/mailcap.h>
 
diff --git a/libmu_cpp/mailer.cc b/libmu_cpp/mailer.cc
index 8090fd4..cde47ee 100644
--- a/libmu_cpp/mailer.cc
+++ b/libmu_cpp/mailer.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/cpp/mailer.h>
 
diff --git a/libmu_cpp/message.cc b/libmu_cpp/message.cc
index a023600..eb4f7ff 100644
--- a/libmu_cpp/message.cc
+++ b/libmu_cpp/message.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include <cstdlib>
 #include <mailutils/cpp/message.h>
diff --git a/libmu_cpp/mime.cc b/libmu_cpp/mime.cc
index 483c211..81cd9e4 100644
--- a/libmu_cpp/mime.cc
+++ b/libmu_cpp/mime.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/cpp/mime.h>
 
diff --git a/libmu_cpp/mutil.cc b/libmu_cpp/mutil.cc
index e4ecceb..165cfa4 100644
--- a/libmu_cpp/mutil.cc
+++ b/libmu_cpp/mutil.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include <cstdlib>
 #include <mailutils/cpp/mutil.h>
diff --git a/libmu_cpp/pop3.cc b/libmu_cpp/pop3.cc
index 8ca7c5d..aa8c8e2 100644
--- a/libmu_cpp/pop3.cc
+++ b/libmu_cpp/pop3.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <cstdlib>
 #include <mailutils/cpp/pop3.h>
diff --git a/libmu_cpp/registrar.cc b/libmu_cpp/registrar.cc
index 26057bb..a4b6828 100644
--- a/libmu_cpp/registrar.cc
+++ b/libmu_cpp/registrar.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/cpp/registrar.h>
 
diff --git a/libmu_cpp/secret.cc b/libmu_cpp/secret.cc
index 4b5582e..59d352d 100644
--- a/libmu_cpp/secret.cc
+++ b/libmu_cpp/secret.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/cpp/secret.h>
 
diff --git a/libmu_cpp/sieve.cc b/libmu_cpp/sieve.cc
index c3be1b4..115840a 100644
--- a/libmu_cpp/sieve.cc
+++ b/libmu_cpp/sieve.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/cpp/sieve.h>
 
diff --git a/libmu_cpp/stream.cc b/libmu_cpp/stream.cc
index eb95740..fe1b98a 100644
--- a/libmu_cpp/stream.cc
+++ b/libmu_cpp/stream.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2009, 2010 Free Software Foundation,
    Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/cpp/stream.h>
 
diff --git a/libmu_cpp/url.cc b/libmu_cpp/url.cc
index 1ae8c00..9c9353c 100644
--- a/libmu_cpp/url.cc
+++ b/libmu_cpp/url.cc
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010 Free Software
    Foundation, Inc.
 
@@ -14,10 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/cpp/url.h>
 
diff --git a/libmu_scm/Makefile.am b/libmu_scm/Makefile.am
index 3a2ecb9..68b82b5 100644
--- a/libmu_scm/Makefile.am
+++ b/libmu_scm/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2001, 2002, 2006, 2007, 2009, 2010 Free Software
-##   Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2001, 2002, 2006, 2007, 2009, 2010 Free Software
+## Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 INCLUDES = -I. @MU_LIB_COMMON_INCLUDES@ @GUILE_INCLUDES@
 
diff --git a/libmu_scm/mailutils.scm.in b/libmu_scm/mailutils.scm.in
index d78a753..285a964 100644
--- a/libmu_scm/mailutils.scm.in
+++ b/libmu_scm/mailutils.scm.in
@@ -14,8 +14,7 @@
 ;;;; GNU General Public License for more details.
 ;;;; 
 ;;;; You should have received a copy of the GNU General Public License along
-;;;; with GNU Mailutils; if not, write to the Free Software Foundation,
-;;;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+;;;; with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 ;;;;
 changequote([,])dnl
 
diff --git a/libmu_scm/mu_address.c b/libmu_scm/mu_address.c
index 2df7dcb..bd20a32 100644
--- a/libmu_scm/mu_address.c
+++ b/libmu_scm/mu_address.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include "mu_scm.h"
 
diff --git a/libmu_scm/mu_body.c b/libmu_scm/mu_body.c
index a5c5cf5..7f3d85c 100644
--- a/libmu_scm/mu_body.c
+++ b/libmu_scm/mu_body.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include "mu_scm.h"
 
diff --git a/libmu_scm/mu_dbgport.c b/libmu_scm/mu_dbgport.c
index f118cb4..a847381 100644
--- a/libmu_scm/mu_dbgport.c
+++ b/libmu_scm/mu_dbgport.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include "mu_scm.h"
 
diff --git a/libmu_scm/mu_guile.c b/libmu_scm/mu_guile.c
index 39e1916..f912495 100644
--- a/libmu_scm/mu_guile.c
+++ b/libmu_scm/mu_guile.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include "mu_scm.h"
 #include <setjmp.h>
diff --git a/libmu_scm/mu_logger.c b/libmu_scm/mu_logger.c
index 01ebe00..5385fe2 100644
--- a/libmu_scm/mu_logger.c
+++ b/libmu_scm/mu_logger.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include "mu_scm.h"
 
diff --git a/libmu_scm/mu_mailbox.c b/libmu_scm/mu_mailbox.c
index 4252e65..4b488b8 100644
--- a/libmu_scm/mu_mailbox.c
+++ b/libmu_scm/mu_mailbox.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include "mu_scm.h"
 #include <mailutils/iterator.h>
diff --git a/libmu_scm/mu_message.c b/libmu_scm/mu_message.c
index 1cb06c0..f00dd4c 100644
--- a/libmu_scm/mu_message.c
+++ b/libmu_scm/mu_message.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include "mu_scm.h"
 
diff --git a/libmu_scm/mu_mime.c b/libmu_scm/mu_mime.c
index 2c90037..dea08b7 100644
--- a/libmu_scm/mu_mime.c
+++ b/libmu_scm/mu_mime.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include "mu_scm.h"
 
diff --git a/libmu_scm/mu_port.c b/libmu_scm/mu_port.c
index 0efa5e7..b090424 100644
--- a/libmu_scm/mu_port.c
+++ b/libmu_scm/mu_port.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include "mu_scm.h"
 #include <mailutils/io.h>
diff --git a/libmu_scm/mu_scm.c b/libmu_scm/mu_scm.c
index f5d3f4c..5f085b1 100644
--- a/libmu_scm/mu_scm.c
+++ b/libmu_scm/mu_scm.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include "mu_scm.h"
 
diff --git a/libmu_scm/mu_scm.h b/libmu_scm/mu_scm.h
index 1f5f70b..22956cf 100644
--- a/libmu_scm/mu_scm.h
+++ b/libmu_scm/mu_scm.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #if defined(HAVE_CONFIG_H)
 # include <config.h>
diff --git a/libmu_scm/mu_util.c b/libmu_scm/mu_util.c
index 8f3b232..0950b96 100644
--- a/libmu_scm/mu_util.c
+++ b/libmu_scm/mu_util.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include "mu_scm.h"
 
diff --git a/libmu_sieve/Makefile.am b/libmu_sieve/Makefile.am
index 1dc3027..8275a03 100644
--- a/libmu_sieve/Makefile.am
+++ b/libmu_sieve/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2002, 2003, 2004, 2005, 2007, 2009, 2010 Free
-##   Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2002, 2003, 2004, 2005, 2007, 2009, 2010 Free
+## Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 INCLUDES = @MU_LIB_COMMON_INCLUDES@ 
 
diff --git a/libmu_sieve/actions.c b/libmu_sieve/actions.c
index 952626a..98c00d1 100644
--- a/libmu_sieve/actions.c
+++ b/libmu_sieve/actions.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_sieve/comparator.c b/libmu_sieve/comparator.c
index 50fb672..b23ce8a 100644
--- a/libmu_sieve/comparator.c
+++ b/libmu_sieve/comparator.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_sieve/conf.c b/libmu_sieve/conf.c
index 9566a0b..dc9c050 100644
--- a/libmu_sieve/conf.c
+++ b/libmu_sieve/conf.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_sieve/extensions/Makefile.am 
b/libmu_sieve/extensions/Makefile.am
index cdbdcee..391d191 100644
--- a/libmu_sieve/extensions/Makefile.am
+++ b/libmu_sieve/extensions/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 Free Software
-##   Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 Free Software
+## Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 address@hidden@
 mod_LTLIBRARIES = \
diff --git a/libmu_sieve/extensions/list.c b/libmu_sieve/extensions/list.c
index 184caad..452228e 100644
--- a/libmu_sieve/extensions/list.c
+++ b/libmu_sieve/extensions/list.c
@@ -13,9 +13,8 @@
    GNU Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with GNU Mailutils; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   License along with GNU Mailutils.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 /* Implements "list" sieve extension test. See "Syntax:" below for the
    description */
diff --git a/libmu_sieve/extensions/moderator.c 
b/libmu_sieve/extensions/moderator.c
index f3dc8c4..b4508e9 100644
--- a/libmu_sieve/extensions/moderator.c
+++ b/libmu_sieve/extensions/moderator.c
@@ -12,9 +12,8 @@
    GNU Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with GNU Mailutils; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   License along with GNU Mailutils.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 /* Moderator robot for Mailman-driven mail archives.
    Mailman moderation request is a MIME message consisting of the three parts:
diff --git a/libmu_sieve/extensions/pipe.c b/libmu_sieve/extensions/pipe.c
index 664997d..e049cac 100644
--- a/libmu_sieve/extensions/pipe.c
+++ b/libmu_sieve/extensions/pipe.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 /* Syntax: pipe [:envelope] <program: string>
 
diff --git a/libmu_sieve/extensions/spamd.c b/libmu_sieve/extensions/spamd.c
index b679cd3..c94ef74 100644
--- a/libmu_sieve/extensions/spamd.c
+++ b/libmu_sieve/extensions/spamd.c
@@ -13,9 +13,8 @@
    GNU Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with GNU Mailutils; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   License along with GNU Mailutils.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 /* This module implements sieve extension test "spamd": an interface to
    the SpamAssassin spamd daemon. See "Usage:" below for the description */
diff --git a/libmu_sieve/extensions/timestamp.c 
b/libmu_sieve/extensions/timestamp.c
index 7cbcda8..8f03489 100644
--- a/libmu_sieve/extensions/timestamp.c
+++ b/libmu_sieve/extensions/timestamp.c
@@ -12,9 +12,8 @@
    GNU Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with GNU Mailutils; if not, write to the Free
-   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   License along with GNU Mailutils.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 /*  Syntax:   timestamp [":before"/":after"] <header-name: string>
               <date: datestring>
diff --git a/libmu_sieve/extensions/vacation.c 
b/libmu_sieve/extensions/vacation.c
index a41103a..323da50 100644
--- a/libmu_sieve/extensions/vacation.c
+++ b/libmu_sieve/extensions/vacation.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 /* Syntax: vacation [:days <ndays: number>]
                     [:subject <subject: string>]
diff --git a/libmu_sieve/load.c b/libmu_sieve/load.c
index 8c7f121..c35ae8b 100644
--- a/libmu_sieve/load.c
+++ b/libmu_sieve/load.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_sieve/prog.c b/libmu_sieve/prog.c
index bafdcfa..58ca94d 100644
--- a/libmu_sieve/prog.c
+++ b/libmu_sieve/prog.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_sieve/register.c b/libmu_sieve/register.c
index 251a088..a2e6c3b 100644
--- a/libmu_sieve/register.c
+++ b/libmu_sieve/register.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_sieve/relational.c b/libmu_sieve/relational.c
index 8f1c06c..e24d0ff 100644
--- a/libmu_sieve/relational.c
+++ b/libmu_sieve/relational.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_sieve/require.c b/libmu_sieve/require.c
index 21e072e..b7a770f 100644
--- a/libmu_sieve/require.c
+++ b/libmu_sieve/require.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_sieve/runtime.c b/libmu_sieve/runtime.c
index c2cb658..60bbc74 100644
--- a/libmu_sieve/runtime.c
+++ b/libmu_sieve/runtime.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_sieve/sieve-priv.h b/libmu_sieve/sieve-priv.h
index 0bea174..0a9e84b 100644
--- a/libmu_sieve/sieve-priv.h
+++ b/libmu_sieve/sieve-priv.h
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/sieve.h>
 #include <setjmp.h>
diff --git a/libmu_sieve/sieve.l b/libmu_sieve/sieve.l
index ffaaef3..87a5dc6 100644
--- a/libmu_sieve/sieve.l
+++ b/libmu_sieve/sieve.l
@@ -14,9 +14,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_sieve/sieve.y b/libmu_sieve/sieve.y
index c3ca2dc..c09dd37 100644
--- a/libmu_sieve/sieve.y
+++ b/libmu_sieve/sieve.y
@@ -14,9 +14,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_sieve/tests.c b/libmu_sieve/tests.c
index bbcbb6c..83aa7aa 100644
--- a/libmu_sieve/tests.c
+++ b/libmu_sieve/tests.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libmu_sieve/util.c b/libmu_sieve/util.c
index 2966950..05a8494 100644
--- a/libmu_sieve/util.c
+++ b/libmu_sieve/util.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/Makefile.am b/libproto/Makefile.am
index 3ba7d19..009985a 100644
--- a/libproto/Makefile.am
+++ b/libproto/Makefile.am
@@ -1,21 +1,18 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 if MU_COND_SUPPORT_POP
   POP_DIR = pop
diff --git a/libproto/imap/Makefile.am b/libproto/imap/Makefile.am
index dd37326..7c01741 100644
--- a/libproto/imap/Makefile.am
+++ b/libproto/imap/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2003, 2005, 2006, 2007, 2010 Free Software
-##   Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2003, 2005, 2006, 2007, 2010 Free Software
+## Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 INCLUDES = @MU_LIB_COMMON_INCLUDES@ 
 
diff --git a/libproto/imap/folder.c b/libproto/imap/folder.c
index e555c12..278294c 100644
--- a/libproto/imap/folder.c
+++ b/libproto/imap/folder.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/imap/mbox.c b/libproto/imap/mbox.c
index 5163eeb..00e8859 100644
--- a/libproto/imap/mbox.c
+++ b/libproto/imap/mbox.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/imap/url.c b/libproto/imap/url.c
index 8e3ae1a..051f45f 100644
--- a/libproto/imap/url.c
+++ b/libproto/imap/url.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/maildir/Makefile.am b/libproto/maildir/Makefile.am
index 939cd03..a43719f 100644
--- a/libproto/maildir/Makefile.am
+++ b/libproto/maildir/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2003, 2005, 2006, 2007, 2010 Free Software
-##   Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2003, 2005, 2006, 2007, 2010 Free Software
+## Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils  If not, see <http://www.gnu.org/licenses/>. 
 
 INCLUDES = @MU_LIB_COMMON_INCLUDES@ 
 
diff --git a/libproto/maildir/folder.c b/libproto/maildir/folder.c
index f6431a8..19ff4b3 100644
--- a/libproto/maildir/folder.c
+++ b/libproto/maildir/folder.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/maildir/maildir.h b/libproto/maildir/maildir.h
index 14a95e4..7796740 100644
--- a/libproto/maildir/maildir.h
+++ b/libproto/maildir/maildir.h
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #define PERMS 0700
 #define TMPSUF "tmp"
diff --git a/libproto/maildir/mbox.c b/libproto/maildir/mbox.c
index 8a8b197..c182958 100644
--- a/libproto/maildir/mbox.c
+++ b/libproto/maildir/mbox.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 /* First draft by Sergey Poznyakoff */
 
diff --git a/libproto/mailer/Makefile.am b/libproto/mailer/Makefile.am
index fbbb481..156dc1f 100644
--- a/libproto/mailer/Makefile.am
+++ b/libproto/mailer/Makefile.am
@@ -1,21 +1,18 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 INCLUDES = @MU_LIB_COMMON_INCLUDES@
 
diff --git a/libproto/mailer/mbox.c b/libproto/mailer/mbox.c
index ab6f905..30130a7 100644
--- a/libproto/mailer/mbox.c
+++ b/libproto/mailer/mbox.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
diff --git a/libproto/mailer/sendmail.c b/libproto/mailer/sendmail.c
index bc944d2..0a991a3 100644
--- a/libproto/mailer/sendmail.c
+++ b/libproto/mailer/sendmail.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/mailer/smtp.c b/libproto/mailer/smtp.c
index ae78cae..4db4398 100644
--- a/libproto/mailer/smtp.c
+++ b/libproto/mailer/smtp.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/mbox/Makefile.am b/libproto/mbox/Makefile.am
index b65cf1e..7cf8b0a 100644
--- a/libproto/mbox/Makefile.am
+++ b/libproto/mbox/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2003, 2005, 2006, 2007, 2010 Free Software
-##   Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2003, 2005, 2006, 2007, 2010 Free Software
+## Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 INCLUDES = @MU_LIB_COMMON_INCLUDES@ 
 
diff --git a/libproto/mbox/folder.c b/libproto/mbox/folder.c
index 4ae658b..84633d0 100644
--- a/libproto/mbox/folder.c
+++ b/libproto/mbox/folder.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/mbox/mbox.c b/libproto/mbox/mbox.c
index cc412ff..0411c23 100644
--- a/libproto/mbox/mbox.c
+++ b/libproto/mbox/mbox.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 /* First draft by Alain Magloire.
  * Completely rewritten by Sergey Poznyakoff.
diff --git a/libproto/mbox/mbox0.h b/libproto/mbox/mbox0.h
index 85e8408..382294f 100644
--- a/libproto/mbox/mbox0.h
+++ b/libproto/mbox/mbox0.h
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <stdlib.h>
 #include <stdio.h>
diff --git a/libproto/mbox/mboxscan.c b/libproto/mbox/mboxscan.c
index cb804c7..3a35e6f 100644
--- a/libproto/mbox/mboxscan.c
+++ b/libproto/mbox/mboxscan.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 /* Mailbox Parsing. */
 
diff --git a/libproto/mh/Makefile.am b/libproto/mh/Makefile.am
index a5be198..322d657 100644
--- a/libproto/mh/Makefile.am
+++ b/libproto/mh/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2003, 2005, 2006, 2007, 2010 Free Software
-##   Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2003, 2005, 2006, 2007, 2010 Free Software
+## Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 INCLUDES = @MU_LIB_COMMON_INCLUDES@
 
diff --git a/libproto/mh/folder.c b/libproto/mh/folder.c
index 1b2c033..074273f 100644
--- a/libproto/mh/folder.c
+++ b/libproto/mh/folder.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/mh/mbox.c b/libproto/mh/mbox.c
index 5995c5b..bb412b7 100644
--- a/libproto/mh/mbox.c
+++ b/libproto/mh/mbox.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 /* First draft by Sergey Poznyakoff */
 
diff --git a/libproto/nntp/Makefile.am b/libproto/nntp/Makefile.am
index aecc0c7..39a0cb3 100644
--- a/libproto/nntp/Makefile.am
+++ b/libproto/nntp/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2004, 2005, 2006, 2007, 2010 Free Software
-##   Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2004, 2005, 2006, 2007, 2010 Free Software
+## Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 INCLUDES = @MU_LIB_COMMON_INCLUDES@
 
diff --git a/libproto/nntp/folder.c b/libproto/nntp/folder.c
index 0e3b43d..4573559 100644
--- a/libproto/nntp/folder.c
+++ b/libproto/nntp/folder.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/mbox.c b/libproto/nntp/mbox.c
index 2d09be2..8ea6d67 100644
--- a/libproto/nntp/mbox.c
+++ b/libproto/nntp/mbox.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp0.h b/libproto/nntp/nntp0.h
index 5610b24..e667cdd 100644
--- a/libproto/nntp/nntp0.h
+++ b/libproto/nntp/nntp0.h
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_article.c b/libproto/nntp/nntp_article.c
index 9c3c58a..e9bb1cd 100644
--- a/libproto/nntp/nntp_article.c
+++ b/libproto/nntp/nntp_article.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_body.c b/libproto/nntp/nntp_body.c
index f06d034..9d9b878 100644
--- a/libproto/nntp/nntp_body.c
+++ b/libproto/nntp/nntp_body.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_carrier.c b/libproto/nntp/nntp_carrier.c
index 1209a67..69c66d7 100644
--- a/libproto/nntp/nntp_carrier.c
+++ b/libproto/nntp/nntp_carrier.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_connect.c b/libproto/nntp/nntp_connect.c
index 959f0b4..123b629 100644
--- a/libproto/nntp/nntp_connect.c
+++ b/libproto/nntp/nntp_connect.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_create.c b/libproto/nntp/nntp_create.c
index 005256c..90cd10a 100644
--- a/libproto/nntp/nntp_create.c
+++ b/libproto/nntp/nntp_create.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_date.c b/libproto/nntp/nntp_date.c
index e80459c..cf8371a 100644
--- a/libproto/nntp/nntp_date.c
+++ b/libproto/nntp/nntp_date.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_debug.c b/libproto/nntp/nntp_debug.c
index 54a8d6f..08f77db 100644
--- a/libproto/nntp/nntp_debug.c
+++ b/libproto/nntp/nntp_debug.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_destroy.c b/libproto/nntp/nntp_destroy.c
index 3725bec..ceb5b87 100644
--- a/libproto/nntp/nntp_destroy.c
+++ b/libproto/nntp/nntp_destroy.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_disconnect.c b/libproto/nntp/nntp_disconnect.c
index 7b8eabb..118945e 100644
--- a/libproto/nntp/nntp_disconnect.c
+++ b/libproto/nntp/nntp_disconnect.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_group.c b/libproto/nntp/nntp_group.c
index 7518efa..6d248d5 100644
--- a/libproto/nntp/nntp_group.c
+++ b/libproto/nntp/nntp_group.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_head.c b/libproto/nntp/nntp_head.c
index 6f1783f..0e5fd1d 100644
--- a/libproto/nntp/nntp_head.c
+++ b/libproto/nntp/nntp_head.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_help.c b/libproto/nntp/nntp_help.c
index 9930e75..0b312e1 100644
--- a/libproto/nntp/nntp_help.c
+++ b/libproto/nntp/nntp_help.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_ihave.c b/libproto/nntp/nntp_ihave.c
index a166754..81767b8 100644
--- a/libproto/nntp/nntp_ihave.c
+++ b/libproto/nntp/nntp_ihave.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_iterator.c b/libproto/nntp/nntp_iterator.c
index f147901..db8e49f 100644
--- a/libproto/nntp/nntp_iterator.c
+++ b/libproto/nntp/nntp_iterator.c
@@ -1,19 +1,18 @@
 /* GNU mailutils - a suite of utilities for electronic mail
    Copyright (C) 2004, 2005, 2007, 2010 Free Software Foundation, Inc.
 
-   This program is free software; you can redistribute it and/or modify
+   GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Library Public License as published by
    the Free Software Foundation; either version 3, or (at your option)
    any later version.
 
-   This program is distributed in the hope that it will be useful,
+   GNU Mailutils is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Library General Public License for more details.
 
    You should have received a copy of the GNU Library General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_last.c b/libproto/nntp/nntp_last.c
index e30e0b1..a332868 100644
--- a/libproto/nntp/nntp_last.c
+++ b/libproto/nntp/nntp_last.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_list_active.c b/libproto/nntp/nntp_list_active.c
index c45c11a..c7a5fe6 100644
--- a/libproto/nntp/nntp_list_active.c
+++ b/libproto/nntp/nntp_list_active.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_list_distribpats.c 
b/libproto/nntp/nntp_list_distribpats.c
index 511f1ee..065e7df 100644
--- a/libproto/nntp/nntp_list_distribpats.c
+++ b/libproto/nntp/nntp_list_distribpats.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_list_distributions.c 
b/libproto/nntp/nntp_list_distributions.c
index 9b990c1..eb0168d 100644
--- a/libproto/nntp/nntp_list_distributions.c
+++ b/libproto/nntp/nntp_list_distributions.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_list_extensions.c 
b/libproto/nntp/nntp_list_extensions.c
index d6a18ec..6bfda73 100644
--- a/libproto/nntp/nntp_list_extensions.c
+++ b/libproto/nntp/nntp_list_extensions.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_list_newsgroups.c 
b/libproto/nntp/nntp_list_newsgroups.c
index 5b5da42..eb778e9 100644
--- a/libproto/nntp/nntp_list_newsgroups.c
+++ b/libproto/nntp/nntp_list_newsgroups.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_list_times.c b/libproto/nntp/nntp_list_times.c
index e770d47..25f6713 100644
--- a/libproto/nntp/nntp_list_times.c
+++ b/libproto/nntp/nntp_list_times.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_mode_reader.c b/libproto/nntp/nntp_mode_reader.c
index 04854c8..12b0bad 100644
--- a/libproto/nntp/nntp_mode_reader.c
+++ b/libproto/nntp/nntp_mode_reader.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_newgroups.c b/libproto/nntp/nntp_newgroups.c
index b406423..ff3ee69 100644
--- a/libproto/nntp/nntp_newgroups.c
+++ b/libproto/nntp/nntp_newgroups.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_newnews.c b/libproto/nntp/nntp_newnews.c
index 4175205..07e4078 100644
--- a/libproto/nntp/nntp_newnews.c
+++ b/libproto/nntp/nntp_newnews.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_next.c b/libproto/nntp/nntp_next.c
index 510f074..61f8d25 100644
--- a/libproto/nntp/nntp_next.c
+++ b/libproto/nntp/nntp_next.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_post.c b/libproto/nntp/nntp_post.c
index 22eb37e..2758c7a 100644
--- a/libproto/nntp/nntp_post.c
+++ b/libproto/nntp/nntp_post.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_quit.c b/libproto/nntp/nntp_quit.c
index 802e009..5fcd091 100644
--- a/libproto/nntp/nntp_quit.c
+++ b/libproto/nntp/nntp_quit.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_readline.c b/libproto/nntp/nntp_readline.c
index b369f38..5551df0 100644
--- a/libproto/nntp/nntp_readline.c
+++ b/libproto/nntp/nntp_readline.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_response.c b/libproto/nntp/nntp_response.c
index fea1286..f4b7528 100644
--- a/libproto/nntp/nntp_response.c
+++ b/libproto/nntp/nntp_response.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_sendline.c b/libproto/nntp/nntp_sendline.c
index f1e1a10..4908829 100644
--- a/libproto/nntp/nntp_sendline.c
+++ b/libproto/nntp/nntp_sendline.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_stat.c b/libproto/nntp/nntp_stat.c
index 9b5c6f1..21e98bc 100644
--- a/libproto/nntp/nntp_stat.c
+++ b/libproto/nntp/nntp_stat.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_stream.c b/libproto/nntp/nntp_stream.c
index f2f50ac..de7cca6 100644
--- a/libproto/nntp/nntp_stream.c
+++ b/libproto/nntp/nntp_stream.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/nntp_timeout.c b/libproto/nntp/nntp_timeout.c
index 3682f58..8b35ed0 100644
--- a/libproto/nntp/nntp_timeout.c
+++ b/libproto/nntp/nntp_timeout.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/nntp/url.c b/libproto/nntp/url.c
index 73a66eb..5354750 100644
--- a/libproto/nntp/url.c
+++ b/libproto/nntp/url.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/Makefile.am b/libproto/pop/Makefile.am
index 5865e4e..749e515 100644
--- a/libproto/pop/Makefile.am
+++ b/libproto/pop/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010 Free Software
-##   Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010 Free Software
+## Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 INCLUDES = @MU_LIB_COMMON_INCLUDES@
 
diff --git a/libproto/pop/folder.c b/libproto/pop/folder.c
index b1ab364..82f8197 100644
--- a/libproto/pop/folder.c
+++ b/libproto/pop/folder.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/mbox.c b/libproto/pop/mbox.c
index eb25bcc..5bd14ca 100644
--- a/libproto/pop/mbox.c
+++ b/libproto/pop/mbox.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_apop.c b/libproto/pop/pop3_apop.c
index c358b93..22f69d0 100644
--- a/libproto/pop/pop3_apop.c
+++ b/libproto/pop/pop3_apop.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_capa.c b/libproto/pop/pop3_capa.c
index e6402af..ffca6aa 100644
--- a/libproto/pop/pop3_capa.c
+++ b/libproto/pop/pop3_capa.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_capatst.c b/libproto/pop/pop3_capatst.c
index 37d740b..4fd4466 100644
--- a/libproto/pop/pop3_capatst.c
+++ b/libproto/pop/pop3_capatst.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_carrier.c b/libproto/pop/pop3_carrier.c
index 485790f..265669d 100644
--- a/libproto/pop/pop3_carrier.c
+++ b/libproto/pop/pop3_carrier.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_connect.c b/libproto/pop/pop3_connect.c
index 5b9ffab..f115e11 100644
--- a/libproto/pop/pop3_connect.c
+++ b/libproto/pop/pop3_connect.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_create.c b/libproto/pop/pop3_create.c
index dc92360..dbb7a4b 100644
--- a/libproto/pop/pop3_create.c
+++ b/libproto/pop/pop3_create.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_dele.c b/libproto/pop/pop3_dele.c
index e4b06c4..0782d7d 100644
--- a/libproto/pop/pop3_dele.c
+++ b/libproto/pop/pop3_dele.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_destroy.c b/libproto/pop/pop3_destroy.c
index 010a063..de70748 100644
--- a/libproto/pop/pop3_destroy.c
+++ b/libproto/pop/pop3_destroy.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_disconnect.c b/libproto/pop/pop3_disconnect.c
index 1c3d231..5f9e5ef 100644
--- a/libproto/pop/pop3_disconnect.c
+++ b/libproto/pop/pop3_disconnect.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_iterator.c b/libproto/pop/pop3_iterator.c
index d7a2313..7712b20 100644
--- a/libproto/pop/pop3_iterator.c
+++ b/libproto/pop/pop3_iterator.c
@@ -1,19 +1,18 @@
 /* GNU mailutils - a suite of utilities for electronic mail
    Copyright (C) 2004, 2005, 2007, 2010 Free Software Foundation, Inc.
 
-   This program is free software; you can redistribute it and/or modify
+   GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Library Public License as published by
    the Free Software Foundation; either version 3, or (at your option)
    any later version.
 
-   This program is distributed in the hope that it will be useful,
+   GNU Mailutils is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Library General Public License for more details.
 
    You should have received a copy of the GNU Library General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_list.c b/libproto/pop/pop3_list.c
index e6bccb5..663c8c8 100644
--- a/libproto/pop/pop3_list.c
+++ b/libproto/pop/pop3_list.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_list_cmd.c b/libproto/pop/pop3_list_cmd.c
index 2917e21..ee6df29 100644
--- a/libproto/pop/pop3_list_cmd.c
+++ b/libproto/pop/pop3_list_cmd.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_lista.c b/libproto/pop/pop3_lista.c
index 4ce2ff1..5b5a345 100644
--- a/libproto/pop/pop3_lista.c
+++ b/libproto/pop/pop3_lista.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_listas.c b/libproto/pop/pop3_listas.c
index 0227650..59e1ebe 100644
--- a/libproto/pop/pop3_listas.c
+++ b/libproto/pop/pop3_listas.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_noop.c b/libproto/pop/pop3_noop.c
index beed039..82801b7 100644
--- a/libproto/pop/pop3_noop.c
+++ b/libproto/pop/pop3_noop.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_pass.c b/libproto/pop/pop3_pass.c
index d72c511..3870e9d 100644
--- a/libproto/pop/pop3_pass.c
+++ b/libproto/pop/pop3_pass.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_quit.c b/libproto/pop/pop3_quit.c
index 8ec8178..f38c948 100644
--- a/libproto/pop/pop3_quit.c
+++ b/libproto/pop/pop3_quit.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_rdlist.c b/libproto/pop/pop3_rdlist.c
index 3544a31..915d7ce 100644
--- a/libproto/pop/pop3_rdlist.c
+++ b/libproto/pop/pop3_rdlist.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_readline.c b/libproto/pop/pop3_readline.c
index 566735b..aeb5f94 100644
--- a/libproto/pop/pop3_readline.c
+++ b/libproto/pop/pop3_readline.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_response.c b/libproto/pop/pop3_response.c
index 2a106ab..63ecc7a 100644
--- a/libproto/pop/pop3_response.c
+++ b/libproto/pop/pop3_response.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_retr.c b/libproto/pop/pop3_retr.c
index 7cd8706..ca22c97 100644
--- a/libproto/pop/pop3_retr.c
+++ b/libproto/pop/pop3_retr.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_rset.c b/libproto/pop/pop3_rset.c
index d233ec4..41aca1a 100644
--- a/libproto/pop/pop3_rset.c
+++ b/libproto/pop/pop3_rset.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_sendline.c b/libproto/pop/pop3_sendline.c
index 0de5e6a..c7e5004 100644
--- a/libproto/pop/pop3_sendline.c
+++ b/libproto/pop/pop3_sendline.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_stat.c b/libproto/pop/pop3_stat.c
index 707fe7d..38f36b6 100644
--- a/libproto/pop/pop3_stat.c
+++ b/libproto/pop/pop3_stat.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_stls.c b/libproto/pop/pop3_stls.c
index 0cf617d..2f5f197 100644
--- a/libproto/pop/pop3_stls.c
+++ b/libproto/pop/pop3_stls.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_stream.c b/libproto/pop/pop3_stream.c
index 6df096c..046dfed 100644
--- a/libproto/pop/pop3_stream.c
+++ b/libproto/pop/pop3_stream.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_timeout.c b/libproto/pop/pop3_timeout.c
index 32b01f0..9e22265 100644
--- a/libproto/pop/pop3_timeout.c
+++ b/libproto/pop/pop3_timeout.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_top.c b/libproto/pop/pop3_top.c
index c060736..c43c6b3 100644
--- a/libproto/pop/pop3_top.c
+++ b/libproto/pop/pop3_top.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_trace.c b/libproto/pop/pop3_trace.c
index 5fa3d95..8ed7eab 100644
--- a/libproto/pop/pop3_trace.c
+++ b/libproto/pop/pop3_trace.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_uidl.c b/libproto/pop/pop3_uidl.c
index c97cc32..c2fcdd4 100644
--- a/libproto/pop/pop3_uidl.c
+++ b/libproto/pop/pop3_uidl.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_uidl_cmd.c b/libproto/pop/pop3_uidl_cmd.c
index 23d7866..fe7ff85 100644
--- a/libproto/pop/pop3_uidl_cmd.c
+++ b/libproto/pop/pop3_uidl_cmd.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_uidla.c b/libproto/pop/pop3_uidla.c
index 78ff0ff..9418ae9 100644
--- a/libproto/pop/pop3_uidla.c
+++ b/libproto/pop/pop3_uidla.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_uidlas.c b/libproto/pop/pop3_uidlas.c
index 82771fd..ba671d2 100644
--- a/libproto/pop/pop3_uidlas.c
+++ b/libproto/pop/pop3_uidlas.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/pop3_user.c b/libproto/pop/pop3_user.c
index 5298a42..ee0ef85 100644
--- a/libproto/pop/pop3_user.c
+++ b/libproto/pop/pop3_user.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/libproto/pop/url.c b/libproto/pop/url.c
index e98b3a6..86992b6 100644
--- a/libproto/pop/url.c
+++ b/libproto/pop/url.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/maidag/Makefile.am b/maidag/Makefile.am
index 50fb709..b1a22f5 100644
--- a/maidag/Makefile.am
+++ b/maidag/Makefile.am
@@ -5,15 +5,13 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 SUBDIRS = . tests
 
diff --git a/maidag/deliver.c b/maidag/deliver.c
index 7bdf29a..57684b9 100644
--- a/maidag/deliver.c
+++ b/maidag/deliver.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "maidag.h"
 
diff --git a/maidag/forward.c b/maidag/forward.c
index 3924eef..2bedd80 100644
--- a/maidag/forward.c
+++ b/maidag/forward.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* ".forward" support for GNU Maidag */
 
diff --git a/maidag/guile.c b/maidag/guile.c
index ca85618..e9af5ce 100644
--- a/maidag/guile.c
+++ b/maidag/guile.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "maidag.h"
 
diff --git a/maidag/lmtp.c b/maidag/lmtp.c
index 0595f30..77a54a4 100644
--- a/maidag/lmtp.c
+++ b/maidag/lmtp.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "maidag.h"
 #include <netinet/in.h>
diff --git a/maidag/maidag.c b/maidag/maidag.c
index af9abf8..f67b581 100644
--- a/maidag/maidag.c
+++ b/maidag/maidag.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "maidag.h"
 
diff --git a/maidag/maidag.h b/maidag/maidag.h
index 012230d..424df8b 100644
--- a/maidag/maidag.h
+++ b/maidag/maidag.h
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #if defined(HAVE_CONFIG_H)
 # include <config.h>
diff --git a/maidag/mailquota.c b/maidag/mailquota.c
index ef0d94e..3ead0e6 100644
--- a/maidag/mailquota.c
+++ b/maidag/mailquota.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "maidag.h"
 
diff --git a/maidag/python.c b/maidag/python.c
index 71ff506..787266f 100644
--- a/maidag/python.c
+++ b/maidag/python.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "maidag.h"
 
diff --git a/maidag/script.c b/maidag/script.c
index 280011e..96ca669 100644
--- a/maidag/script.c
+++ b/maidag/script.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "maidag.h"
 
diff --git a/maidag/sieve.c b/maidag/sieve.c
index f3cfd43..00b8a81 100644
--- a/maidag/sieve.c
+++ b/maidag/sieve.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "maidag.h"
 
diff --git a/maidag/tests/Makefile.am b/maidag/tests/Makefile.am
index eec3015..50c0e9f 100644
--- a/maidag/tests/Makefile.am
+++ b/maidag/tests/Makefile.am
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/maidag/util.c b/maidag/util.c
index 068f928..1549b22 100644
--- a/maidag/util.c
+++ b/maidag/util.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "maidag.h"
 
diff --git a/mail/Makefile.am b/mail/Makefile.am
index 3da9034..cca0beb 100644
--- a/mail/Makefile.am
+++ b/mail/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 1999, 2000, 2001, 2002, 2005, 2007, 2010 Free
-##   Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 1999, 2000, 2001, 2002, 2005, 2007, 2010 Free
+## Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 2, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 2, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 AM_YFLAGS=-vt
 INCLUDES = @MU_APP_COMMON_INCLUDES@ @MU_AUTHINCS@ 
diff --git a/mail/alias.c b/mail/alias.c
index 31532ff..7ff2085 100644
--- a/mail/alias.c
+++ b/mail/alias.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/alt.c b/mail/alt.c
index e38c6fb..c9545b3 100644
--- a/mail/alt.c
+++ b/mail/alt.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 #include <pwd.h>
diff --git a/mail/cd.c b/mail/cd.c
index 01c199f..785c29f 100644
--- a/mail/cd.c
+++ b/mail/cd.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/copy.c b/mail/copy.c
index 43087db..e1775be 100644
--- a/mail/copy.c
+++ b/mail/copy.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/decode.c b/mail/decode.c
index f508faf..09f22d1 100644
--- a/mail/decode.c
+++ b/mail/decode.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 #include "mailcap.h"
diff --git a/mail/delete.c b/mail/delete.c
index 55a7978..402a648 100644
--- a/mail/delete.c
+++ b/mail/delete.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/dp.c b/mail/dp.c
index d52ce1b..eebe354 100644
--- a/mail/dp.c
+++ b/mail/dp.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/echo.c b/mail/echo.c
index accafed..0579e20 100644
--- a/mail/echo.c
+++ b/mail/echo.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/edit.c b/mail/edit.c
index 27a394d..0006a25 100644
--- a/mail/edit.c
+++ b/mail/edit.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/eq.c b/mail/eq.c
index 99a509d..6a414d9 100644
--- a/mail/eq.c
+++ b/mail/eq.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/escape.c b/mail/escape.c
index 0f3f57e..f35bbe1 100644
--- a/mail/escape.c
+++ b/mail/escape.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* Functions for handling escape variables */
 
diff --git a/mail/exit.c b/mail/exit.c
index af2d7bc..5118568 100644
--- a/mail/exit.c
+++ b/mail/exit.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/file.c b/mail/file.c
index c0e3463..bf4acbd 100644
--- a/mail/file.c
+++ b/mail/file.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/folders.c b/mail/folders.c
index d832da7..b21316c 100644
--- a/mail/folders.c
+++ b/mail/folders.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/followup.c b/mail/followup.c
index 5c699d0..c8c5e26 100644
--- a/mail/followup.c
+++ b/mail/followup.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/from.c b/mail/from.c
index 66b4c29..9515138 100644
--- a/mail/from.c
+++ b/mail/from.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 #include <mu_umaxtostr.h>
diff --git a/mail/headers.c b/mail/headers.c
index 5e7e982..915e7c8 100644
--- a/mail/headers.c
+++ b/mail/headers.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/help.c b/mail/help.c
index c6442f1..3454109 100644
--- a/mail/help.c
+++ b/mail/help.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/hold.c b/mail/hold.c
index 8535cc9..2938125 100644
--- a/mail/hold.c
+++ b/mail/hold.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/if.c b/mail/if.c
index 8a93618..12c6744 100644
--- a/mail/if.c
+++ b/mail/if.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/inc.c b/mail/inc.c
index f0b6617..a9dec14 100644
--- a/mail/inc.c
+++ b/mail/inc.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/list.c b/mail/list.c
index c6c4844..a6eb18f 100644
--- a/mail/list.c
+++ b/mail/list.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/mail.c b/mail/mail.c
index 8a43b76..6cd68f3 100644
--- a/mail/mail.c
+++ b/mail/mail.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 #include "mailutils/libargp.h"
@@ -584,8 +582,7 @@ mail_warranty (int argc MU_ARG_UNUSED, char **argv 
MU_ARG_UNUSED)
     "   GNU General Public License for more details.\n"
     "\n"
     "   You should have received a copy of the GNU General Public License 
along\n"
-    "   with GNU Mailutils; if not, write to the Free Software Foundation,\n"
-    "   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n"
+    "   with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.\n" 
     "\n"
     "\n"
 ),
diff --git a/mail/mail.h b/mail/mail.h
index 6c419d5..0efe8d3 100644
--- a/mail/mail.h
+++ b/mail/mail.h
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAIL_H
 #define _MAIL_H 1
diff --git a/mail/mailline.c b/mail/mailline.c
index cc0df6d..95e3243 100644
--- a/mail/mailline.c
+++ b/mail/mailline.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 #include <sys/stat.h>
diff --git a/mail/mbox.c b/mail/mbox.c
index 2b093f2..c8a2337 100644
--- a/mail/mbox.c
+++ b/mail/mbox.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/msgset.y b/mail/msgset.y
index f2c2a52..8f6ae9d 100644
--- a/mail/msgset.y
+++ b/mail/msgset.y
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 %{
 #include "mail.h"
diff --git a/mail/next.c b/mail/next.c
index 4b48b5f..aea6367 100644
--- a/mail/next.c
+++ b/mail/next.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/page.c b/mail/page.c
index 760de42..952e4e2 100644
--- a/mail/page.c
+++ b/mail/page.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/pipe.c b/mail/pipe.c
index d057450..58fa64e 100644
--- a/mail/pipe.c
+++ b/mail/pipe.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/previous.c b/mail/previous.c
index 25ed10d..81ca149 100644
--- a/mail/previous.c
+++ b/mail/previous.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/print.c b/mail/print.c
index 89542f6..d851908 100644
--- a/mail/print.c
+++ b/mail/print.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/quit.c b/mail/quit.c
index 4efeaf4..9632c72 100644
--- a/mail/quit.c
+++ b/mail/quit.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/reply.c b/mail/reply.c
index 6a85ec7..ff5e8af 100644
--- a/mail/reply.c
+++ b/mail/reply.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/retain.c b/mail/retain.c
index 07656aa..08d76a8 100644
--- a/mail/retain.c
+++ b/mail/retain.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/save.c b/mail/save.c
index 0b681bd..b67a7f4 100644
--- a/mail/save.c
+++ b/mail/save.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/send.c b/mail/send.c
index 3f095b2..618f6a8 100644
--- a/mail/send.c
+++ b/mail/send.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 #include <sys/types.h>
diff --git a/mail/set.c b/mail/set.c
index 6daf381..ae9a9c9 100644
--- a/mail/set.c
+++ b/mail/set.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/setenv.c b/mail/setenv.c
index ed73abf..cccb4f6 100644
--- a/mail/setenv.c
+++ b/mail/setenv.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/shell.c b/mail/shell.c
index 3c44495..df710fa 100644
--- a/mail/shell.c
+++ b/mail/shell.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/size.c b/mail/size.c
index c21b8bd..186d36d 100644
--- a/mail/size.c
+++ b/mail/size.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/source.c b/mail/source.c
index c7aa43a..57a5ccb 100644
--- a/mail/source.c
+++ b/mail/source.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/summary.c b/mail/summary.c
index 4e7721b..95ab7b5 100644
--- a/mail/summary.c
+++ b/mail/summary.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/table.c b/mail/table.c
index c8996b8..3c2fd83 100644
--- a/mail/table.c
+++ b/mail/table.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/tag.c b/mail/tag.c
index 198b041..5719a5e 100644
--- a/mail/tag.c
+++ b/mail/tag.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/testsuite/Makefile.am b/mail/testsuite/Makefile.am
index bb8ddf8..0e41522 100644
--- a/mail/testsuite/Makefile.am
+++ b/mail/testsuite/Makefile.am
@@ -1,21 +1,18 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2002, 2007, 2010 Free Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2002, 2007, 2010 Free Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 AUTOMAKE_OPTIONS = dejagnu
 DEJATOOL = mail
diff --git a/mail/testsuite/if.mail b/mail/testsuite/if.mail
index 5fa6a01..acc3d73 100644
--- a/mail/testsuite/if.mail
+++ b/mail/testsuite/if.mail
@@ -1,20 +1,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2005, 2007, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 echo "Begin test"
 
diff --git a/mail/testsuite/lib/mail.exp b/mail/testsuite/lib/mail.exp
index b0b23e9..3728bc3 100644
--- a/mail/testsuite/lib/mail.exp
+++ b/mail/testsuite/lib/mail.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2002, 2007, 2009, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 source $top_srcdir/testsuite/lib/mailutils.exp
 
diff --git a/mail/testsuite/mail/alias.exp b/mail/testsuite/mail/alias.exp
index 71b5dd9..9291858 100644
--- a/mail/testsuite/mail/alias.exp
+++ b/mail/testsuite/mail/alias.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2002, 2007, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 mail_start "--file=%mbox1"
 
diff --git a/mail/testsuite/mail/folder.exp b/mail/testsuite/mail/folder.exp
index 70a284b..4ddcf06 100644
--- a/mail/testsuite/mail/folder.exp
+++ b/mail/testsuite/mail/folder.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2002, 2007, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 # Test mailbox name expansion and various aspects of `file' and `folders'
 # functionality.
diff --git a/mail/testsuite/mail/if.exp b/mail/testsuite/mail/if.exp
index e93c262..877b13d 100644
--- a/mail/testsuite/mail/if.exp
+++ b/mail/testsuite/mail/if.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2002, 2005, 2007, 2009, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 mu_prepare_spools
 
diff --git a/mail/testsuite/mail/read.exp b/mail/testsuite/mail/read.exp
index fbb52ae..7e02fe5 100644
--- a/mail/testsuite/mail/read.exp
+++ b/mail/testsuite/mail/read.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2002, 2005, 2007, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 mail_start "--file=%mbox1"
 mail_command "set readonly"
diff --git a/mail/testsuite/mail/send.exp b/mail/testsuite/mail/send.exp
index 916a546..16b5ebb 100644
--- a/mail/testsuite/mail/send.exp
+++ b/mail/testsuite/mail/send.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2002, 2006, 2007, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 mail_version
 
diff --git a/mail/testsuite/mail/tag.exp b/mail/testsuite/mail/tag.exp
index edb2270..ac50953 100644
--- a/mail/testsuite/mail/tag.exp
+++ b/mail/testsuite/mail/tag.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2002, 2007, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 mail_start "--file=%teaparty.mbox"
 mail_command "set readonly"
diff --git a/mail/testsuite/mail/write.exp b/mail/testsuite/mail/write.exp
index d2cce6f..4743f95 100644
--- a/mail/testsuite/mail/write.exp
+++ b/mail/testsuite/mail/write.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2002, 2007, 2009, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 mail_start "--file=%mbox1"
 
diff --git a/mail/testsuite/mail/z.exp b/mail/testsuite/mail/z.exp
index 39b876a..ce4a92e 100644
--- a/mail/testsuite/mail/z.exp
+++ b/mail/testsuite/mail/z.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2002, 2005, 2007, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 mail_start "--file=%teaparty.mbox"
 mail_command "set readonly"
diff --git a/mail/testsuite/makespool b/mail/testsuite/makespool
index 190ba85..5a72446 100755
--- a/mail/testsuite/makespool
+++ b/mail/testsuite/makespool
@@ -13,8 +13,7 @@
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
-# along with GNU Mailutils; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 
 if [ "$1" = "-r" ]; then
diff --git a/mail/top.c b/mail/top.c
index de030af..c70801f 100644
--- a/mail/top.c
+++ b/mail/top.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/touch.c b/mail/touch.c
index 6f232f3..969f4da 100644
--- a/mail/touch.c
+++ b/mail/touch.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/unalias.c b/mail/unalias.c
index 7370c24..d97c794 100644
--- a/mail/unalias.c
+++ b/mail/unalias.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/undelete.c b/mail/undelete.c
index ca99b32..cac68e6 100644
--- a/mail/undelete.c
+++ b/mail/undelete.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/unset.c b/mail/unset.c
index cbc6118..77e6fb4 100644
--- a/mail/unset.c
+++ b/mail/unset.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/util.c b/mail/util.c
index c64496d..683fdf9 100644
--- a/mail/util.c
+++ b/mail/util.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 #include <mailutils/mutil.h>
diff --git a/mail/version.c b/mail/version.c
index 0136278..12c907b 100644
--- a/mail/version.c
+++ b/mail/version.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/visual.c b/mail/visual.c
index 6103221..0f29ee1 100644
--- a/mail/visual.c
+++ b/mail/visual.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/write.c b/mail/write.c
index 13ad960..4840873 100644
--- a/mail/write.c
+++ b/mail/write.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mail/z.c b/mail/z.c
index a124cbe..52a90f5 100644
--- a/mail/z.c
+++ b/mail/z.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
 
diff --git a/mapi/MAPIAddress.c b/mapi/MAPIAddress.c
index 4466a02..c356bcf 100644
--- a/mapi/MAPIAddress.c
+++ b/mapi/MAPIAddress.c
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/mapi.h>
 
diff --git a/mapi/MAPIDeleteMail.c b/mapi/MAPIDeleteMail.c
index cf36a0b..8a5e14e 100644
--- a/mapi/MAPIDeleteMail.c
+++ b/mapi/MAPIDeleteMail.c
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/mapi.h>
 
diff --git a/mapi/MAPIDetails.c b/mapi/MAPIDetails.c
index c66ec84..3714487 100644
--- a/mapi/MAPIDetails.c
+++ b/mapi/MAPIDetails.c
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/mapi.h>
 
diff --git a/mapi/MAPIFindNext.c b/mapi/MAPIFindNext.c
index 1b87f36..88dd3d9 100644
--- a/mapi/MAPIFindNext.c
+++ b/mapi/MAPIFindNext.c
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/mapi.h>
 
diff --git a/mapi/MAPIFreeBuffer.c b/mapi/MAPIFreeBuffer.c
index ab1b0a9..13252a8 100644
--- a/mapi/MAPIFreeBuffer.c
+++ b/mapi/MAPIFreeBuffer.c
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/mapi.h>
 
diff --git a/mapi/MAPILogoff.c b/mapi/MAPILogoff.c
index 6cb0bac..0683f7e 100644
--- a/mapi/MAPILogoff.c
+++ b/mapi/MAPILogoff.c
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/mapi.h>
 
diff --git a/mapi/MAPILogon.c b/mapi/MAPILogon.c
index 95be7b7..1ddbd1a 100644
--- a/mapi/MAPILogon.c
+++ b/mapi/MAPILogon.c
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/mapi.h>
 
diff --git a/mapi/MAPIReadMail.c b/mapi/MAPIReadMail.c
index 0062355..f1a3502 100644
--- a/mapi/MAPIReadMail.c
+++ b/mapi/MAPIReadMail.c
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, 
+   see <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/mapi.h>
 
diff --git a/mapi/MAPISaveMail.c b/mapi/MAPISaveMail.c
index 3f36067..6e43f95 100644
--- a/mapi/MAPISaveMail.c
+++ b/mapi/MAPISaveMail.c
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/mapi.h>
 
diff --git a/mapi/MAPISendDocuments.c b/mapi/MAPISendDocuments.c
index 80bb5e7..8c97088 100644
--- a/mapi/MAPISendDocuments.c
+++ b/mapi/MAPISendDocuments.c
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/mapi.h>
 
diff --git a/mapi/MAPISendMail.c b/mapi/MAPISendMail.c
index 034fc68..62dbafe 100644
--- a/mapi/MAPISendMail.c
+++ b/mapi/MAPISendMail.c
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/mapi.h>
 
diff --git a/mapi/Makefile.am b/mapi/Makefile.am
index fddc3bf..19efbda 100644
--- a/mapi/Makefile.am
+++ b/mapi/Makefile.am
@@ -1,21 +1,18 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2001, 2002, 2007, 2010 Free Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2001, 2002, 2007, 2010 Free Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.
-##   59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 INCLUDES = @MU_LIB_COMMON_INCLUDES@
 
diff --git a/mapi/mapi.h b/mapi/mapi.h
index 4294b6f..8f63040 100644
--- a/mapi/mapi.h
+++ b/mapi/mapi.h
@@ -13,8 +13,8 @@
    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, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA  */
+   License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAPI_H
 #define _MAPI_H
diff --git a/messages/Makefile.am b/messages/Makefile.am
index dbbbdd7..4632cc1 100644
--- a/messages/Makefile.am
+++ b/messages/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2001, 2002, 2003, 2004, 2007, 2010 Free Software
-##   Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2001, 2002, 2003, 2004, 2007, 2010 Free Software
+## Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 INCLUDES = @MU_APP_COMMON_INCLUDES@ 
 
diff --git a/messages/messages.c b/messages/messages.c
index 62c38b8..e467a9b 100644
--- a/messages/messages.c
+++ b/messages/messages.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/messages/tests/Makefile.am b/messages/tests/Makefile.am
index b548c51..d587c2f 100644
--- a/messages/tests/Makefile.am
+++ b/messages/tests/Makefile.am
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/messages/tests/testsuite.at b/messages/tests/testsuite.at
index 627b1bb..ee855b0 100644
--- a/messages/tests/testsuite.at
+++ b/messages/tests/testsuite.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/mh/Makefile.am b/mh/Makefile.am
index 8cb3f09..2cceef0 100644
--- a/mh/Makefile.am
+++ b/mh/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2001, 2002, 2003, 2007, 2009, 2010 Free Software
-##   Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2001, 2002, 2003, 2007, 2009, 2010 Free Software
+## Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 bindir = @MH_BIN_DIR@
 mhlibdir = $(pkgdatadir)/mh
diff --git a/mh/ali.c b/mh/ali.c
index 0c357cf..fa11429 100644
--- a/mh/ali.c
+++ b/mh/ali.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH ali command */
 
diff --git a/mh/anno.c b/mh/anno.c
index efc22d3..aa16f32 100644
--- a/mh/anno.c
+++ b/mh/anno.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH annotate command */
 
diff --git a/mh/burst.c b/mh/burst.c
index b413c07..1078fda 100644
--- a/mh/burst.c
+++ b/mh/burst.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH burst command */
 
diff --git a/mh/comp.c b/mh/comp.c
index f65fab2..0f8830d 100644
--- a/mh/comp.c
+++ b/mh/comp.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH comp command */
 
diff --git a/mh/compcommon.c b/mh/compcommon.c
index e85da11..312faf3 100644
--- a/mh/compcommon.c
+++ b/mh/compcommon.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* Functions shared between comp and forw utilities */
 
diff --git a/mh/fmtcheck.c b/mh/fmtcheck.c
index 33c456a..216544d 100644
--- a/mh/fmtcheck.c
+++ b/mh/fmtcheck.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* fmtcheck */
 
diff --git a/mh/folder.c b/mh/folder.c
index c2baf4c..5394f2b 100644
--- a/mh/folder.c
+++ b/mh/folder.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH folder command */
 
diff --git a/mh/forw.c b/mh/forw.c
index 6e63d23..3889601 100644
--- a/mh/forw.c
+++ b/mh/forw.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH forw command */
 
diff --git a/mh/inc.c b/mh/inc.c
index 184a056..d2fb0a3 100644
--- a/mh/inc.c
+++ b/mh/inc.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH inc command */
 
diff --git a/mh/install-mh.c b/mh/install-mh.c
index a563c5f..1363a65 100644
--- a/mh/install-mh.c
+++ b/mh/install-mh.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <mh.h>
 
diff --git a/mh/mailutils-mh.eli b/mh/mailutils-mh.eli
index c3bc6a5..93330af 100644
--- a/mh/mailutils-mh.eli
+++ b/mh/mailutils-mh.eli
@@ -13,8 +13,7 @@
 ;;;; GNU General Public License for more details.
 ;;;; 
 ;;;; You should have received a copy of the GNU General Public License
-;;;; along with GNU Mailutils; if not, write to the Free Software
-;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  
USA  
+;;;; along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 (setq mh-progs "BINDIR")
 (setq mh-lib "MHLIBDIR")
diff --git a/mh/mark.c b/mh/mark.c
index 5f67a63..ec2e46e 100644
--- a/mh/mark.c
+++ b/mh/mark.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <mh.h>
 
diff --git a/mh/mh.h b/mh/mh.h
index 005a533..3f4566f 100644
--- a/mh/mh.h
+++ b/mh/mh.h
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/mh/mh_alias.l b/mh/mh_alias.l
index 926348c..b002343 100644
--- a/mh/mh_alias.l
+++ b/mh/mh_alias.l
@@ -14,9 +14,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/mh/mh_alias.y b/mh/mh_alias.y
index ca27e8b..e34509c 100644
--- a/mh/mh_alias.y
+++ b/mh/mh_alias.y
@@ -14,9 +14,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <mh.h>
 #include <pwd.h>
diff --git a/mh/mh_argp.c b/mh/mh_argp.c
index be7ed16..8978d4c 100644
--- a/mh/mh_argp.c
+++ b/mh/mh_argp.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* Coexistence between GNU long options, traditional UNIX-style short
    options and traditional MH long options. */
@@ -283,8 +281,7 @@ mh_license (const char *name)
     "   GNU General Public License for more details.\n"
     "\n"
     "   You should have received a copy of the GNU General Public License 
along\n"
-    "   with GNU Mailutils; if not, write to the Free Software Foundation,\n"
-    "   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n"
+    "   with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.\n"
     "\n"
     "\n"
 ));
diff --git a/mh/mh_ctx.c b/mh/mh_ctx.c
index 0b4795d..33a1069 100644
--- a/mh/mh_ctx.c
+++ b/mh/mh_ctx.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH context functions. */
   
diff --git a/mh/mh_fmtgram.y b/mh/mh_fmtgram.y
index 2727331..7af0d9f 100644
--- a/mh/mh_fmtgram.y
+++ b/mh/mh_fmtgram.y
@@ -14,9 +14,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <mh.h>
 #define obstack_chunk_alloc malloc
diff --git a/mh/mh_format.c b/mh/mh_format.c
index 7d548c0..f084f31 100644
--- a/mh/mh_format.c
+++ b/mh/mh_format.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* This module implements execution of MH format strings. */
 
diff --git a/mh/mh_format.h b/mh/mh_format.h
index de4f30b..64c1a66 100644
--- a/mh/mh_format.h
+++ b/mh/mh_format.h
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #define obstack_chunk_alloc malloc
 #define obstack_chunk_free free
diff --git a/mh/mh_getopt.c b/mh/mh_getopt.c
index 2a6c949..09b8a3e 100644
--- a/mh/mh_getopt.c
+++ b/mh/mh_getopt.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* Parse traditional MH options. */
 
diff --git a/mh/mh_getopt.h b/mh/mh_getopt.h
index beb6fff..9aff8c9 100644
--- a/mh/mh_getopt.h
+++ b/mh/mh_getopt.h
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/nls.h>
 #include "argp.h"
diff --git a/mh/mh_global.c b/mh/mh_global.c
index 7b5c054..9578a8f 100644
--- a/mh/mh_global.c
+++ b/mh/mh_global.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* Global MH state. */
 
diff --git a/mh/mh_init.c b/mh/mh_init.c
index 7043d1a..b1c20c9 100644
--- a/mh/mh_init.c
+++ b/mh/mh_init.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* Initialize MH applications. */
 
diff --git a/mh/mh_list.c b/mh/mh_list.c
index 4df743f..a414574 100644
--- a/mh/mh_list.c
+++ b/mh/mh_list.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH mhl command */
 
diff --git a/mh/mh_msgset.c b/mh/mh_msgset.c
index 4376732..f4706fd 100644
--- a/mh/mh_msgset.c
+++ b/mh/mh_msgset.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH message sets. */
 
diff --git a/mh/mh_sequence.c b/mh/mh_sequence.c
index a12407c..4e7f5cf 100644
--- a/mh/mh_sequence.c
+++ b/mh/mh_sequence.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <mh.h>
 
diff --git a/mh/mh_stream.c b/mh/mh_stream.c
index 0e2e6fe..9878503 100644
--- a/mh/mh_stream.c
+++ b/mh/mh_stream.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* This file implements an MH draftfile stream: a read-only stream used
    to transparently pass MH draftfiles to mailers. The only difference
diff --git a/mh/mh_whatnow.c b/mh/mh_whatnow.c
index 3ec4533..527e73a 100644
--- a/mh/mh_whatnow.c
+++ b/mh/mh_whatnow.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <mh.h>
 
diff --git a/mh/mh_whom.c b/mh/mh_whom.c
index df82cf8..4b70b25 100644
--- a/mh/mh_whom.c
+++ b/mh/mh_whom.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <mh.h>
 
diff --git a/mh/mhl.c b/mh/mhl.c
index 030fe42..5f6b6fc 100644
--- a/mh/mhl.c
+++ b/mh/mhl.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH mhl command */
 
diff --git a/mh/mhn.c b/mh/mhn.c
index d25932f..23c8872 100644
--- a/mh/mhn.c
+++ b/mh/mhn.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH mhn command */
 
diff --git a/mh/mhparam.c b/mh/mhparam.c
index f9b7a23..9149c1c 100644
--- a/mh/mhparam.c
+++ b/mh/mhparam.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH mhparam command */
 
diff --git a/mh/mhpath.c b/mh/mhpath.c
index 04d58f8..5051418 100644
--- a/mh/mhpath.c
+++ b/mh/mhpath.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH mhpath command */
 
diff --git a/mh/pick.c b/mh/pick.c
index f51a386..122734c 100644
--- a/mh/pick.c
+++ b/mh/pick.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH pick command */
 
diff --git a/mh/pick.h b/mh/pick.h
index 53c3fa3..4ef9e55 100644
--- a/mh/pick.h
+++ b/mh/pick.h
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 typedef enum
 {
diff --git a/mh/pick.y b/mh/pick.y
index 64248ec..b123849 100644
--- a/mh/pick.y
+++ b/mh/pick.y
@@ -14,9 +14,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <mh.h>
 #include <regex.h>  
diff --git a/mh/refile.c b/mh/refile.c
index f244e70..ab66730 100644
--- a/mh/refile.c
+++ b/mh/refile.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH refile command */
 
diff --git a/mh/repl.c b/mh/repl.c
index afb9233..5bfccba 100644
--- a/mh/repl.c
+++ b/mh/repl.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH repl command */
 
diff --git a/mh/rmf.c b/mh/rmf.c
index 31fb44e..469f770 100644
--- a/mh/rmf.c
+++ b/mh/rmf.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH rmf command */
 
diff --git a/mh/rmm.c b/mh/rmm.c
index e82ac79..a9bbfc8 100644
--- a/mh/rmm.c
+++ b/mh/rmm.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH rmm command */
 
diff --git a/mh/scan.c b/mh/scan.c
index 308d772..3bc3816 100644
--- a/mh/scan.c
+++ b/mh/scan.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH scan command */
 
diff --git a/mh/send.c b/mh/send.c
index 6ba5c46..a642d80 100644
--- a/mh/send.c
+++ b/mh/send.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH send command */
 
diff --git a/mh/sortm.c b/mh/sortm.c
index cdea0bd..fd40de6 100644
--- a/mh/sortm.c
+++ b/mh/sortm.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH sortm command */
 
diff --git a/mh/whatnow.c b/mh/whatnow.c
index 3075d5a..decf947 100644
--- a/mh/whatnow.c
+++ b/mh/whatnow.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* MH whatnow command */
 
diff --git a/mh/whom.c b/mh/whom.c
index 9db8446..b943e97 100644
--- a/mh/whom.c
+++ b/mh/whom.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <mh.h>
 
diff --git a/mimeview/Makefile.am b/mimeview/Makefile.am
index 86bcdc8..4dc8df8 100644
--- a/mimeview/Makefile.am
+++ b/mimeview/Makefile.am
@@ -1,21 +1,18 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2005, 2007, 2010 Free Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2005, 2007, 2010 Free Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 INCLUDES = @MU_APP_COMMON_INCLUDES@ 
 
diff --git a/mimeview/mimetypes.l b/mimeview/mimetypes.l
index f1e0b90..a4dbf20 100644
--- a/mimeview/mimetypes.l
+++ b/mimeview/mimetypes.l
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/mimeview/mimetypes.y b/mimeview/mimetypes.y
index 4f50773..50be133 100644
--- a/mimeview/mimetypes.y
+++ b/mimeview/mimetypes.y
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/mimeview/mimeview.c b/mimeview/mimeview.c
index 8b32311..0601255 100644
--- a/mimeview/mimeview.c
+++ b/mimeview/mimeview.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/mimeview/mimeview.h b/mimeview/mimeview.h
index 972f390..a77dc5a 100644
--- a/mimeview/mimeview.h
+++ b/mimeview/mimeview.h
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <stdlib.h>
 #include <stdio.h>
diff --git a/movemail/Makefile.am b/movemail/Makefile.am
index 7bc6228..9588330 100644
--- a/movemail/Makefile.am
+++ b/movemail/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 1999, 2000, 2001, 2002, 2006, 2007, 2010 Free
-##   Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 1999, 2000, 2001, 2002, 2006, 2007, 2010 Free
+## Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 INCLUDES = @MU_APP_COMMON_INCLUDES@ @MU_AUTHINCS@
 bin_PROGRAMS = movemail
diff --git a/movemail/movemail.c b/movemail/movemail.c
index ddbeb14..4218849 100644
--- a/movemail/movemail.c
+++ b/movemail/movemail.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #if defined(HAVE_CONFIG_H)
 # include <config.h>
diff --git a/mu-aux/Makefile.am b/mu-aux/Makefile.am
index 28a299b..7273a9f 100644
--- a/mu-aux/Makefile.am
+++ b/mu-aux/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2002, 2003, 2005, 2007, 2010 Free Software
-##   Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2002, 2003, 2005, 2007, 2010 Free Software
+## Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 EXTRA_DIST = \
  debugdef.m4\
diff --git a/mu-aux/debugdef.m4 b/mu-aux/debugdef.m4
index 34be1cd..ab9ee70 100644
--- a/mu-aux/debugdef.m4
+++ b/mu-aux/debugdef.m4
@@ -4,18 +4,18 @@ divert(-1)
 #
 # Initially written by Sergey Poznyakoff for Mailfromd project.
 #
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3, or (at your option)
 # any later version.
 #
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 changecom(/*,*/)
 
diff --git a/mu-aux/generr.awk b/mu-aux/generr.awk
index a40690c..e0efc71 100644
--- a/mu-aux/generr.awk
+++ b/mu-aux/generr.awk
@@ -6,17 +6,15 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
-# This program creates error reporting source files (muerrno.c and errno.h)
+# GNU Mailutils creates error reporting source files (muerrno.c and errno.h)
 # for GNU Mailutils.
 #
 # Usage:
diff --git a/mu-aux/gylwrap b/mu-aux/gylwrap
index 66dbdd0..20d9b40 100755
--- a/mu-aux/gylwrap
+++ b/mu-aux/gylwrap
@@ -15,8 +15,7 @@
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 
USA.
+# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 
 # Usage:
 #     ylwrap PROGRAM [ARGS] INPUT [OUTPUT DESIRED]... -- [-yy repl] [ARGS]...
diff --git a/mu-aux/texify.sed b/mu-aux/texify.sed
index 468001a..e344122 100644
--- a/mu-aux/texify.sed
+++ b/mu-aux/texify.sed
@@ -5,15 +5,13 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc.
-# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 1{s/\/\*/@comment  /
 b
diff --git a/mu/Makefile.am b/mu/Makefile.am
index d2a2f3d..e724b0c 100644
--- a/mu/Makefile.am
+++ b/mu/Makefile.am
@@ -7,13 +7,13 @@
 ## published by the Free Software Foundation; either version 2, or (at
 ## your option) any later version.
 ##
-## This program is distributed in the hope that it will be useful, but
+## GNU Mailutils is distributed in the hope that it will be useful, but
 ## WITHOUT ANY WARRANTY; without even the implied warranty of
 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 ## General Public License for more details.
 ##
 ## You should have received a copy of the GNU General Public License
-## along with this program.  If not, see <http://www.gnu.org/licenses/>.
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 bin_PROGRAMS = mu
 
diff --git a/paths b/paths
index 45ad28e..6efbee1 100644
--- a/paths
+++ b/paths
@@ -2,18 +2,18 @@
 #
 # Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3, or (at your option)
 # any later version.
 #
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 #
 # This file describes how to set various paths used by libraries and
diff --git a/po/POTFILES.in b/po/POTFILES.in
index a189a7d..30c0f15 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -120,25 +120,25 @@ mail/unalias.c
 mail/util.c
 mail/z.c
 
-libmailutils/cfg_driver.c
-libmailutils/cfg_format.c
-libmailutils/cfg_lexer.l
-libmailutils/cfg_parser.y
-libmailutils/debug.c
-libmailutils/diag.c
-libmailutils/errors
-libmailutils/file_stream.c
-libmailutils/filter_iconv.c
-libmailutils/gdebug.c
-libmailutils/gocs.c
-libmailutils/ipsrv.c
-libmailutils/message.c
-libmailutils/msrv.c
-libmailutils/mu_auth.c
-libmailutils/mutil.c
-libmailutils/parsedate.y
-libmailutils/registrar.c
-libmailutils/version.c
+libmailutils/cfg/driver.c
+libmailutils/cfg/format.c
+libmailutils/cfg/lexer.l
+libmailutils/cfg/parser.y
+libmailutils/cfg/gocs.c
+libmailutils/diag/debug.c
+libmailutils/diag/diag.c
+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
 
 messages/messages.c
 
diff --git a/pop3d/Makefile.am b/pop3d/Makefile.am
index 171733f..38576a6 100644
--- a/pop3d/Makefile.am
+++ b/pop3d/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2007, 2010 Free
-##   Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2007, 2010 Free
+## Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   GNU Mailutils is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with GNU Mailutils; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 INCLUDES = @MU_APP_COMMON_INCLUDES@ 
 
diff --git a/pop3d/bulletin.c b/pop3d/bulletin.c
index 031ad49..2d53a46 100644
--- a/pop3d/bulletin.c
+++ b/pop3d/bulletin.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
 
diff --git a/pop3d/expire.c b/pop3d/expire.c
index da19ef3..a43ee4e 100644
--- a/pop3d/expire.c
+++ b/pop3d/expire.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
 
diff --git a/pop3d/extra.c b/pop3d/extra.c
index a52fee2..d6f2116 100644
--- a/pop3d/extra.c
+++ b/pop3d/extra.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
 #include "mailutils/libargp.h"
diff --git a/pop3d/lock.c b/pop3d/lock.c
index 590b9e2..d3bbfe9 100644
--- a/pop3d/lock.c
+++ b/pop3d/lock.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
 
diff --git a/pop3d/logindelay.c b/pop3d/logindelay.c
index 5cab22c..7b3bf35 100644
--- a/pop3d/logindelay.c
+++ b/pop3d/logindelay.c
@@ -12,9 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
 
diff --git a/pop3d/pop3d.c b/pop3d/pop3d.c
index ab5ed7c..b058147 100644
--- a/pop3d/pop3d.c
+++ b/pop3d/pop3d.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
 #include "mailutils/pam.h"
diff --git a/pop3d/pop3d.h b/pop3d/pop3d.h
index 862ce72..b93284b 100644
--- a/pop3d/pop3d.h
+++ b/pop3d/pop3d.h
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifndef _POP3D_H
 #define _POP3D_H       1
diff --git a/pop3d/popauth.c b/pop3d/popauth.c
index f8505f9..b22cb66 100644
--- a/pop3d/popauth.c
+++ b/pop3d/popauth.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
 #include <mailutils/argcv.h>
diff --git a/pop3d/signal.c b/pop3d/signal.c
index b12bca7..a8a6f0c 100644
--- a/pop3d/signal.c
+++ b/pop3d/signal.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
 
diff --git a/pop3d/stat.c b/pop3d/stat.c
index 9daf3ed..f108b76 100644
--- a/pop3d/stat.c
+++ b/pop3d/stat.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
 
diff --git a/pop3d/testsuite/Makefile.am b/pop3d/testsuite/Makefile.am
index 0b9982f..9e8335a 100644
--- a/pop3d/testsuite/Makefile.am
+++ b/pop3d/testsuite/Makefile.am
@@ -1,21 +1,18 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2002, 2007, 2008, 2010 Free Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2002, 2007, 2008, 2010 Free Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 AUTOMAKE_OPTIONS = dejagnu
 DEJATOOL = pop3d
diff --git a/pop3d/testsuite/lib/pop3d.exp b/pop3d/testsuite/lib/pop3d.exp
index e75b24e..69de7d6 100644
--- a/pop3d/testsuite/lib/pop3d.exp
+++ b/pop3d/testsuite/lib/pop3d.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2002, 2007, 2008, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 source $top_srcdir/testsuite/lib/mailutils.exp
 
diff --git a/pop3d/testsuite/pop3d/read.exp b/pop3d/testsuite/pop3d/read.exp
index c748133..8e8cc7c 100644
--- a/pop3d/testsuite/pop3d/read.exp
+++ b/pop3d/testsuite/pop3d/read.exp
@@ -2,20 +2,18 @@
 # This file is part of Mailutils testsuite.
 # Copyright (C) 2002, 2007, 2010 Free Software Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 pop3d_start 
 pop3d_auth "user!passwd" "guessme"
diff --git a/python/Makefile.am b/python/Makefile.am
index fcbb7a2..097e5e0 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -1,21 +1,18 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 SUBDIRS = libmu_py mailutils
 
diff --git a/python/libmu_py/Makefile.am b/python/libmu_py/Makefile.am
index 4051143..4b70bff 100644
--- a/python/libmu_py/Makefile.am
+++ b/python/libmu_py/Makefile.am
@@ -1,21 +1,18 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 INCLUDES = @MU_LIB_COMMON_INCLUDES@ $(PYTHON_INCLUDES)
 
diff --git a/python/libmu_py/address.c b/python/libmu_py/address.c
index 611de20..c0dcb5f 100644
--- a/python/libmu_py/address.c
+++ b/python/libmu_py/address.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/attribute.c b/python/libmu_py/attribute.c
index df51fa3..46c8226 100644
--- a/python/libmu_py/attribute.c
+++ b/python/libmu_py/attribute.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/auth.c b/python/libmu_py/auth.c
index 6f342bc..678b8b9 100644
--- a/python/libmu_py/auth.c
+++ b/python/libmu_py/auth.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 #include <mailutils/pam.h>
diff --git a/python/libmu_py/body.c b/python/libmu_py/body.c
index 81606ea..8ddc517 100644
--- a/python/libmu_py/body.c
+++ b/python/libmu_py/body.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/c_api.c b/python/libmu_py/c_api.c
index 8914b20..aab2345 100644
--- a/python/libmu_py/c_api.c
+++ b/python/libmu_py/c_api.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/debug.c b/python/libmu_py/debug.c
index ac79d35..bb9da85 100644
--- a/python/libmu_py/debug.c
+++ b/python/libmu_py/debug.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/envelope.c b/python/libmu_py/envelope.c
index 617b398..81d52d3 100644
--- a/python/libmu_py/envelope.c
+++ b/python/libmu_py/envelope.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/error.c b/python/libmu_py/error.c
index 77013c9..028a8b5 100644
--- a/python/libmu_py/error.c
+++ b/python/libmu_py/error.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/filter.c b/python/libmu_py/filter.c
index 01c53b3..8e983e4 100644
--- a/python/libmu_py/filter.c
+++ b/python/libmu_py/filter.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/folder.c b/python/libmu_py/folder.c
index 4ba9ddf..e476efa 100644
--- a/python/libmu_py/folder.c
+++ b/python/libmu_py/folder.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/header.c b/python/libmu_py/header.c
index 3af10e0..8962d83 100644
--- a/python/libmu_py/header.c
+++ b/python/libmu_py/header.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/libmu_py.c b/python/libmu_py/libmu_py.c
index bf6da0c..e9792a2 100644
--- a/python/libmu_py/libmu_py.c
+++ b/python/libmu_py/libmu_py.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/libmu_py.h b/python/libmu_py/libmu_py.h
index 21dc560..b637858 100644
--- a/python/libmu_py/libmu_py.h
+++ b/python/libmu_py/libmu_py.h
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/python/libmu_py/list.c b/python/libmu_py/list.c
index a7a9818..eb0f2a4 100644
--- a/python/libmu_py/list.c
+++ b/python/libmu_py/list.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/mailbox.c b/python/libmu_py/mailbox.c
index b6eea4f..5fc79cc 100644
--- a/python/libmu_py/mailbox.c
+++ b/python/libmu_py/mailbox.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/mailcap.c b/python/libmu_py/mailcap.c
index 8f65cbe..6bafd42 100644
--- a/python/libmu_py/mailcap.c
+++ b/python/libmu_py/mailcap.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/mailer.c b/python/libmu_py/mailer.c
index 968ea02..b0e08e2 100644
--- a/python/libmu_py/mailer.c
+++ b/python/libmu_py/mailer.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/message.c b/python/libmu_py/message.c
index 58f9c5b..78600cf 100644
--- a/python/libmu_py/message.c
+++ b/python/libmu_py/message.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/mime.c b/python/libmu_py/mime.c
index fd9e1a0..85d872d 100644
--- a/python/libmu_py/mime.c
+++ b/python/libmu_py/mime.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/nls.c b/python/libmu_py/nls.c
index 2d54c5c..cd811eb 100644
--- a/python/libmu_py/nls.c
+++ b/python/libmu_py/nls.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/registrar.c b/python/libmu_py/registrar.c
index 88ef162..7878ac1 100644
--- a/python/libmu_py/registrar.c
+++ b/python/libmu_py/registrar.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/script.c b/python/libmu_py/script.c
index da49146..7aca9ee 100644
--- a/python/libmu_py/script.c
+++ b/python/libmu_py/script.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/secret.c b/python/libmu_py/secret.c
index 0033d02..c3ca0e3 100644
--- a/python/libmu_py/secret.c
+++ b/python/libmu_py/secret.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/sieve.c b/python/libmu_py/sieve.c
index 9c38fa2..43200a4 100644
--- a/python/libmu_py/sieve.c
+++ b/python/libmu_py/sieve.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/stream.c b/python/libmu_py/stream.c
index 0ef7385..4767376 100644
--- a/python/libmu_py/stream.c
+++ b/python/libmu_py/stream.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/url.c b/python/libmu_py/url.c
index 2b8a7dc..f1b7eee 100644
--- a/python/libmu_py/url.c
+++ b/python/libmu_py/url.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/libmu_py/util.c b/python/libmu_py/util.c
index 0741c25..929c74c 100644
--- a/python/libmu_py/util.c
+++ b/python/libmu_py/util.c
@@ -1,5 +1,4 @@
-/*
-   GNU Mailutils -- a suite of utilities for electronic mail
+/* GNU Mailutils -- a suite of utilities for electronic mail
    Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -13,10 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA
-*/
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #include "libmu_py.h"
 
diff --git a/python/mailutils/Makefile.am b/python/mailutils/Makefile.am
index 5cf261d..d994cf3 100644
--- a/python/mailutils/Makefile.am
+++ b/python/mailutils/Makefile.am
@@ -1,21 +1,18 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 address@hidden@
 pythonsite_PYTHON=\
diff --git a/python/mailutils/__init__.py b/python/mailutils/__init__.py
index bea528a..423a09d 100644
--- a/python/mailutils/__init__.py
+++ b/python/mailutils/__init__.py
@@ -12,9 +12,7 @@
 #  GNU General Public License for more details.
 #
 #  You should have received a copy of the GNU General Public License
-#  along with GNU Mailutils; if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-#  MA 02110-1301 USA
+#  along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 """
 A Python interface to Mailutils framework.
diff --git a/python/mailutils/address.py b/python/mailutils/address.py
index 759b03c..4f43232 100644
--- a/python/mailutils/address.py
+++ b/python/mailutils/address.py
@@ -1,4 +1,3 @@
-#
 #  GNU Mailutils -- a suite of utilities for electronic mail
 #  Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
@@ -13,10 +12,8 @@
 #  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, write to the
-#  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-#  Boston, MA 02110-1301 USA
-#
+#  Public License along with this library.  If not, see 
+#  <http://www.gnu.org/licenses/>. 
 
 import types
 from mailutils.c_api import address
diff --git a/python/mailutils/attribute.py b/python/mailutils/attribute.py
index 45fd710..7f22b29 100644
--- a/python/mailutils/attribute.py
+++ b/python/mailutils/attribute.py
@@ -1,4 +1,3 @@
-#
 #  GNU Mailutils -- a suite of utilities for electronic mail
 #  Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
@@ -13,10 +12,8 @@
 #  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, write to the
-#  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-#  Boston, MA 02110-1301 USA
-#
+#  Public License along with this library.  If not, see 
+#  <http://www.gnu.org/licenses/>. 
 
 import types
 from mailutils.c_api import attribute
diff --git a/python/mailutils/auth.py b/python/mailutils/auth.py
index 8b68edc..36ee8de 100644
--- a/python/mailutils/auth.py
+++ b/python/mailutils/auth.py
@@ -1,4 +1,3 @@
-#
 #  GNU Mailutils -- a suite of utilities for electronic mail
 #  Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
@@ -13,10 +12,8 @@
 #  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, write to the
-#  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-#  Boston, MA 02110-1301 USA
-#
+#  Public License along with this library.  If not, see 
+#  <http://www.gnu.org/licenses/>. 
 
 import types
 from mailutils.c_api import auth
diff --git a/python/mailutils/body.py b/python/mailutils/body.py
index 02af50b..44de502 100644
--- a/python/mailutils/body.py
+++ b/python/mailutils/body.py
@@ -1,4 +1,3 @@
-#
 #  GNU Mailutils -- a suite of utilities for electronic mail
 #  Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
@@ -13,10 +12,8 @@
 #  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, write to the
-#  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-#  Boston, MA 02110-1301 USA
-#
+#  Public License along with this library.  If not, see 
+#  <http://www.gnu.org/licenses/>. 
 
 from mailutils.c_api import body
 from mailutils import stream
diff --git a/python/mailutils/debug.py b/python/mailutils/debug.py
index 141dd8a..feafe78 100644
--- a/python/mailutils/debug.py
+++ b/python/mailutils/debug.py
@@ -1,4 +1,3 @@
-#
 #  GNU Mailutils -- a suite of utilities for electronic mail
 #  Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
@@ -13,10 +12,8 @@
 #  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, write to the
-#  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-#  Boston, MA 02110-1301 USA
-#
+#  Public License along with this library.  If not, see 
+#  <http://www.gnu.org/licenses/>.
 
 from mailutils.c_api import debug
 from mailutils.error import DebugError
diff --git a/python/mailutils/envelope.py b/python/mailutils/envelope.py
index 86926e3..7be7bdd 100644
--- a/python/mailutils/envelope.py
+++ b/python/mailutils/envelope.py
@@ -1,4 +1,3 @@
-#
 #  GNU Mailutils -- a suite of utilities for electronic mail
 #  Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
@@ -13,10 +12,8 @@
 #  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, write to the
-#  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-#  Boston, MA 02110-1301 USA
-#
+#  Public License along with this library.  If not, see 
+#  <http://www.gnu.org/licenses/>.
 
 from mailutils.c_api import envelope
 from mailutils.error import EnvelopeError
diff --git a/python/mailutils/error.py b/python/mailutils/error.py
index 4ef0b47..c6444dc 100644
--- a/python/mailutils/error.py
+++ b/python/mailutils/error.py
@@ -1,4 +1,3 @@
-#
 #  GNU Mailutils -- a suite of utilities for electronic mail
 #  Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
@@ -13,10 +12,8 @@
 #  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, write to the
-#  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-#  Boston, MA 02110-1301 USA
-#
+#  Public License along with this library.  If not, see 
+#  <http://www.gnu.org/licenses/>.
 
 from mailutils.c_api import error
 
diff --git a/python/mailutils/filter.py b/python/mailutils/filter.py
index e3242aa..7844fb5 100644
--- a/python/mailutils/filter.py
+++ b/python/mailutils/filter.py
@@ -1,4 +1,3 @@
-#
 #  GNU Mailutils -- a suite of utilities for electronic mail
 #  Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
@@ -13,10 +12,8 @@
 #  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, write to the
-#  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-#  Boston, MA 02110-1301 USA
-#
+#  Public License along with this library.  If not, see 
+#  <http://www.gnu.org/licenses/>.
 
 from mailutils.c_api import filter
 from mailutils.stream import *
diff --git a/python/mailutils/folder.py b/python/mailutils/folder.py
index 738f1ff..ba503f7 100644
--- a/python/mailutils/folder.py
+++ b/python/mailutils/folder.py
@@ -1,4 +1,3 @@
-#
 #  GNU Mailutils -- a suite of utilities for electronic mail
 #  Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
@@ -13,10 +12,8 @@
 #  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, write to the
-#  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-#  Boston, MA 02110-1301 USA
-#
+#  Public License along with this library.  If not, see 
+#  <http://www.gnu.org/licenses/>.
 
 from mailutils.c_api import folder
 from mailutils import stream
diff --git a/python/mailutils/header.py b/python/mailutils/header.py
index 78bfb2d..ea875cf 100644
--- a/python/mailutils/header.py
+++ b/python/mailutils/header.py
@@ -1,4 +1,3 @@
-#
 #  GNU Mailutils -- a suite of utilities for electronic mail
 #  Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
@@ -13,10 +12,8 @@
 #  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, write to the
-#  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-#  Boston, MA 02110-1301 USA
-#
+#  Public License along with this library.  If not, see
+#  <http://www.gnu.org/licenses/>.
 
 import types
 from mailutils.c_api import header
diff --git a/python/mailutils/mailbox.py b/python/mailutils/mailbox.py
index 1bde2c9..517da49 100644
--- a/python/mailutils/mailbox.py
+++ b/python/mailutils/mailbox.py
@@ -1,4 +1,3 @@
-#
 #  GNU Mailutils -- a suite of utilities for electronic mail
 #  Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
@@ -13,10 +12,8 @@
 #  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, write to the
-#  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-#  Boston, MA 02110-1301 USA
-#
+#  Public License along with this library.  If not, see
+#  <http://www.gnu.org/licenses/>.
 
 import types
 from mailutils.c_api import mailbox
diff --git a/python/mailutils/mailcap.py b/python/mailutils/mailcap.py
index a555364..5c10dfa 100644
--- a/python/mailutils/mailcap.py
+++ b/python/mailutils/mailcap.py
@@ -1,4 +1,3 @@
-#
 #  GNU Mailutils -- a suite of utilities for electronic mail
 #  Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
@@ -13,10 +12,8 @@
 #  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, write to the
-#  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-#  Boston, MA 02110-1301 USA
-#
+#  Public License along with this library.  If not, see 
+#  <http://www.gnu.org/licenses/>.
 
 from mailutils.c_api import mailcap
 from mailutils.error import MailcapError
diff --git a/python/mailutils/mailer.py b/python/mailutils/mailer.py
index 19cf665..0bbbd71 100644
--- a/python/mailutils/mailer.py
+++ b/python/mailutils/mailer.py
@@ -1,4 +1,3 @@
-#
 #  GNU Mailutils -- a suite of utilities for electronic mail
 #  Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
@@ -13,10 +12,8 @@
 #  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, write to the
-#  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-#  Boston, MA 02110-1301 USA
-#
+#  Public License along with this library.  If not, see
+#  <http://www.gnu.org/licenses/>.
 
 from mailutils.c_api import mailer
 from mailutils import address
diff --git a/python/mailutils/message.py b/python/mailutils/message.py
index 89aa984..85ad25e 100644
--- a/python/mailutils/message.py
+++ b/python/mailutils/message.py
@@ -1,4 +1,3 @@
-#
 #  GNU Mailutils -- a suite of utilities for electronic mail
 #  Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
@@ -13,10 +12,8 @@
 #  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, write to the
-#  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-#  Boston, MA 02110-1301 USA
-#
+#  Public License along with this library.  If not, see 
+#  <http://www.gnu.org/licenses/>.
 
 from mailutils.c_api import message
 from mailutils import envelope
diff --git a/python/mailutils/mime.py b/python/mailutils/mime.py
index 9937f66..3c28a89 100644
--- a/python/mailutils/mime.py
+++ b/python/mailutils/mime.py
@@ -1,4 +1,3 @@
-#
 #  GNU Mailutils -- a suite of utilities for electronic mail
 #  Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
@@ -13,10 +12,8 @@
 #  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, write to the
-#  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-#  Boston, MA 02110-1301 USA
-#
+#  Public License along with this library.  If not, see
+#  <http://www.gnu.org/licenses/>.
 
 from mailutils.c_api import mime
 from mailutils import message
diff --git a/python/mailutils/nls.py b/python/mailutils/nls.py
index 90eacb2..334b95f 100644
--- a/python/mailutils/nls.py
+++ b/python/mailutils/nls.py
@@ -1,4 +1,3 @@
-#
 #  GNU Mailutils -- a suite of utilities for electronic mail
 #  Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
@@ -13,10 +12,8 @@
 #  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, write to the
-#  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-#  Boston, MA 02110-1301 USA
-#
+#  Public License along with this library.  If not, see
+#  <http://www.gnu.org/licenses/>.
 
 from mailutils.c_api import nls
 
diff --git a/python/mailutils/registrar.py b/python/mailutils/registrar.py
index bdfa270..af90ad6 100644
--- a/python/mailutils/registrar.py
+++ b/python/mailutils/registrar.py
@@ -1,4 +1,3 @@
-#
 #  GNU Mailutils -- a suite of utilities for electronic mail
 #  Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
@@ -13,10 +12,8 @@
 #  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, write to the
-#  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-#  Boston, MA 02110-1301 USA
-#
+#  Public License along with this library.  If not, see
+#  <http://www.gnu.org/licenses/>.
 
 import types
 from mailutils.c_api import registrar
diff --git a/python/mailutils/secret.py b/python/mailutils/secret.py
index 51e91ba..f334d98 100644
--- a/python/mailutils/secret.py
+++ b/python/mailutils/secret.py
@@ -1,4 +1,3 @@
-#
 #  GNU Mailutils -- a suite of utilities for electronic mail
 #  Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
@@ -13,10 +12,8 @@
 #  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, write to the
-#  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-#  Boston, MA 02110-1301 USA
-#
+#  Public License along with this library.  If not, see 
+#  <http://www.gnu.org/licenses/>.
 
 from mailutils.c_api import secret
 from mailutils.error import SecretError
diff --git a/python/mailutils/sieve.py b/python/mailutils/sieve.py
index 36c5263..36b7e4a 100644
--- a/python/mailutils/sieve.py
+++ b/python/mailutils/sieve.py
@@ -1,4 +1,3 @@
-#
 #  GNU Mailutils -- a suite of utilities for electronic mail
 #  Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
@@ -13,10 +12,8 @@
 #  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, write to the
-#  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-#  Boston, MA 02110-1301 USA
-#
+#  Public License along with this library.  If not, see 
+#  <http://www.gnu.org/licenses/>.
 
 from mailutils.c_api import sieve
 from mailutils.error import SieveMachineError
diff --git a/python/mailutils/stream.py b/python/mailutils/stream.py
index 8a2fef2..dc909cb 100644
--- a/python/mailutils/stream.py
+++ b/python/mailutils/stream.py
@@ -1,4 +1,3 @@
-#
 #  GNU Mailutils -- a suite of utilities for electronic mail
 #  Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
@@ -13,10 +12,8 @@
 #  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, write to the
-#  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-#  Boston, MA 02110-1301 USA
-#
+#  Public License along with this library.  If not, see
+#  <http://www.gnu.org/licenses/>.
 
 from mailutils.c_api import stream
 from mailutils.error import StreamError
diff --git a/python/mailutils/url.py b/python/mailutils/url.py
index 3efeba0..a1b4d46 100644
--- a/python/mailutils/url.py
+++ b/python/mailutils/url.py
@@ -1,4 +1,3 @@
-#
 #  GNU Mailutils -- a suite of utilities for electronic mail
 #  Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
@@ -13,10 +12,8 @@
 #  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, write to the
-#  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-#  Boston, MA 02110-1301 USA
-#
+#  Public License along with this library.  If not, see 
+#  <http://www.gnu.org/licenses/>.
 
 from mailutils.c_api import url
 from mailutils import secret
diff --git a/python/mailutils/util.py b/python/mailutils/util.py
index 1bf0dc7..9aa1795 100644
--- a/python/mailutils/util.py
+++ b/python/mailutils/util.py
@@ -1,4 +1,3 @@
-#
 #  GNU Mailutils -- a suite of utilities for electronic mail
 #  Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 #
@@ -13,10 +12,8 @@
 #  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, write to the
-#  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-#  Boston, MA 02110-1301 USA
-#
+#  Public License along with this library.  If not, see
+#  <http://www.gnu.org/licenses/>.
 
 from mailutils.c_api import util
 
diff --git a/readmsg/Makefile.am b/readmsg/Makefile.am
index 0522a9e..05bc58f 100644
--- a/readmsg/Makefile.am
+++ b/readmsg/Makefile.am
@@ -1,22 +1,19 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2001, 2002, 2003, 2004, 2007, 2010 Free Software
-##   Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2001, 2002, 2003, 2004, 2007, 2010 Free Software
+## Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 INCLUDES = @MU_APP_COMMON_INCLUDES@ 
 
diff --git a/readmsg/msglist.c b/readmsg/msglist.c
index b42e325..0e9b38c 100644
--- a/readmsg/msglist.c
+++ b/readmsg/msglist.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "readmsg.h"
 
diff --git a/readmsg/readmsg.c b/readmsg/readmsg.c
index 7fdc63b..db60329 100644
--- a/readmsg/readmsg.c
+++ b/readmsg/readmsg.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/readmsg/readmsg.h b/readmsg/readmsg.h
index f1bd87c..9b12c23 100644
--- a/readmsg/readmsg.h
+++ b/readmsg/readmsg.h
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifndef _READMSG_H
 #define _READMSG_H
diff --git a/readmsg/tests/Makefile.am b/readmsg/tests/Makefile.am
index 662a627..8c6e849 100644
--- a/readmsg/tests/Makefile.am
+++ b/readmsg/tests/Makefile.am
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/readmsg/tests/all.at b/readmsg/tests/all.at
index 67ab085..fd54991 100644
--- a/readmsg/tests/all.at
+++ b/readmsg/tests/all.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/readmsg/tests/hdr.at b/readmsg/tests/hdr.at
index 08395c7..78cc482 100644
--- a/readmsg/tests/hdr.at
+++ b/readmsg/tests/hdr.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/readmsg/tests/nohdr.at b/readmsg/tests/nohdr.at
index 6ddf5e9..402588b 100644
--- a/readmsg/tests/nohdr.at
+++ b/readmsg/tests/nohdr.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/readmsg/tests/testsuite.at b/readmsg/tests/testsuite.at
index 49305aa..59b6839 100644
--- a/readmsg/tests/testsuite.at
+++ b/readmsg/tests/testsuite.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/readmsg/tests/twomsg.at b/readmsg/tests/twomsg.at
index 577af51..5de48b1 100644
--- a/readmsg/tests/twomsg.at
+++ b/readmsg/tests/twomsg.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/readmsg/tests/weed.at b/readmsg/tests/weed.at
index bf2c1fc..ca8519b 100644
--- a/readmsg/tests/weed.at
+++ b/readmsg/tests/weed.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/Makefile.am b/sieve/Makefile.am
index 1d9a0bb..669a689 100644
--- a/sieve/Makefile.am
+++ b/sieve/Makefile.am
@@ -1,21 +1,18 @@
-## Process this file with GNU Automake to create Makefile.in
-
-##   Copyright (C) 2001, 2002, 2007, 2010 Free Software Foundation, Inc.
+## This file is part of GNU Mailutils.
+## Copyright (C) 2001, 2002, 2007, 2010 Free Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 INCLUDES = @MU_APP_COMMON_INCLUDES@ 
 SUBDIRS  = . tests
diff --git a/sieve/sieve.c b/sieve/sieve.c
index 22374da..91adfbc 100644
--- a/sieve/sieve.c
+++ b/sieve/sieve.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/sieve/tests/Makefile.am b/sieve/tests/Makefile.am
index fc83481..967b60e 100644
--- a/sieve/tests/Makefile.am
+++ b/sieve/tests/Makefile.am
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/tests/action.at b/sieve/tests/action.at
index 2da7723..ef98b97 100644
--- a/sieve/tests/action.at
+++ b/sieve/tests/action.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/tests/address.at b/sieve/tests/address.at
index 88499dd..541b5c0 100644
--- a/sieve/tests/address.at
+++ b/sieve/tests/address.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/tests/allof.at b/sieve/tests/allof.at
index 369d32a..44688b2 100644
--- a/sieve/tests/allof.at
+++ b/sieve/tests/allof.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/tests/anyof.at b/sieve/tests/anyof.at
index ba4e9a1..0f22ec5 100644
--- a/sieve/tests/anyof.at
+++ b/sieve/tests/anyof.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/tests/compile.at b/sieve/tests/compile.at
index 8bdab9c..ccb06dd 100644
--- a/sieve/tests/compile.at
+++ b/sieve/tests/compile.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/tests/envelope.at b/sieve/tests/envelope.at
index 375accc..fc8baf6 100644
--- a/sieve/tests/envelope.at
+++ b/sieve/tests/envelope.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/tests/exists.at b/sieve/tests/exists.at
index 41095d9..24fb066 100644
--- a/sieve/tests/exists.at
+++ b/sieve/tests/exists.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/tests/ext.at b/sieve/tests/ext.at
index ab9fc92..bd06379 100644
--- a/sieve/tests/ext.at
+++ b/sieve/tests/ext.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/tests/false.at b/sieve/tests/false.at
index 5dae588..ec53582 100644
--- a/sieve/tests/false.at
+++ b/sieve/tests/false.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/tests/header.at b/sieve/tests/header.at
index ecb99be..134d23f 100644
--- a/sieve/tests/header.at
+++ b/sieve/tests/header.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/tests/i-casemap.at b/sieve/tests/i-casemap.at
index 3b34194..9d55b38 100644
--- a/sieve/tests/i-casemap.at
+++ b/sieve/tests/i-casemap.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/tests/i-numeric.at b/sieve/tests/i-numeric.at
index a62ff28..fcf1213 100644
--- a/sieve/tests/i-numeric.at
+++ b/sieve/tests/i-numeric.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/tests/i-octet.at b/sieve/tests/i-octet.at
index 13049ad..a2186c3 100644
--- a/sieve/tests/i-octet.at
+++ b/sieve/tests/i-octet.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/tests/mul-addr.at b/sieve/tests/mul-addr.at
index b11f4f5..e005c6a 100644
--- a/sieve/tests/mul-addr.at
+++ b/sieve/tests/mul-addr.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/tests/not.at b/sieve/tests/not.at
index cf4e4c5..3828604 100644
--- a/sieve/tests/not.at
+++ b/sieve/tests/not.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/tests/redirect.at b/sieve/tests/redirect.at
index 0449447..6a2f8ff 100644
--- a/sieve/tests/redirect.at
+++ b/sieve/tests/redirect.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/tests/reject.at b/sieve/tests/reject.at
index d7acfc0..91a6cfb 100644
--- a/sieve/tests/reject.at
+++ b/sieve/tests/reject.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/tests/relational.at b/sieve/tests/relational.at
index c68ab22..e9588e1 100644
--- a/sieve/tests/relational.at
+++ b/sieve/tests/relational.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/tests/size.at b/sieve/tests/size.at
index e809e82..5edf122 100644
--- a/sieve/tests/size.at
+++ b/sieve/tests/size.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/tests/testsuite.at b/sieve/tests/testsuite.at
index a9ee7ce..7f6a161 100644
--- a/sieve/tests/testsuite.at
+++ b/sieve/tests/testsuite.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/tests/true.at b/sieve/tests/true.at
index d1065de..5e5cf05 100644
--- a/sieve/tests/true.at
+++ b/sieve/tests/true.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sieve/tests/version.at b/sieve/tests/version.at
index ce951a9..f03eda4 100644
--- a/sieve/tests/version.at
+++ b/sieve/tests/version.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/sql/Makefile.am b/sql/Makefile.am
index 2ad125f..9c6274c 100644
--- a/sql/Makefile.am
+++ b/sql/Makefile.am
@@ -1,21 +1,18 @@
 ## This file is part of GNU Mailutils
-
-##   Copyright (C) 2004, 2005, 2007, 2010 Free Software Foundation, Inc.
+## Copyright (C) 2004, 2005, 2007, 2010 Free Software Foundation, Inc.
 ##
-##   GNU Mailutils is free software; you can redistribute it and/or
-##   modify it under the terms of the GNU General Public License as
-##   published by the Free Software Foundation; either version 3, or (at
-##   your option) any later version.
+## GNU Mailutils is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License as
+## published by the Free Software Foundation; either version 3, or (at
+## your option) any later version.
 ##
-##   This program is distributed in the hope that it will be useful, but
-##   WITHOUT ANY WARRANTY; without even the implied warranty of
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##   General Public License for more details.
+## GNU Mailutils is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
 ##
-##   You should have received a copy of the GNU General Public License
-##   along with this program; if not, write to the Free Software
-##   Foundation, Inc.  51 Franklin Street, Fifth Floor, Boston, MA
-##   02110-1301 USA
+## You should have received a copy of the GNU General Public License
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 address@hidden@
 EXTRA_LTLIBRARIES=libsql.la mysql.la postgres.la odbc.la
diff --git a/sql/mysql.c b/sql/mysql.c
index c573303..b3cb8ba 100644
--- a/sql/mysql.c
+++ b/sql/mysql.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/sql/odbc.c b/sql/odbc.c
index bb9e345..e2f1725 100644
--- a/sql/odbc.c
+++ b/sql/odbc.c
@@ -12,9 +12,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/sql/postgres.c b/sql/postgres.c
index e4e4c87..d7b5ba5 100644
--- a/sql/postgres.c
+++ b/sql/postgres.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/sql/sql.c b/sql/sql.c
index b256beb..d0bb950 100644
--- a/sql/sql.c
+++ b/sql/sql.c
@@ -13,9 +13,8 @@
    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, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301 USA */
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index f845683..5c243b1 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/testsuite/lib/mailutils.exp b/testsuite/lib/mailutils.exp
index 827f0d3..b2b2408 100644
--- a/testsuite/lib/mailutils.exp
+++ b/testsuite/lib/mailutils.exp
@@ -3,20 +3,18 @@
 # Copyright (C) 2002, 2005, 2007, 2008, 2009, 2010 Free Software 
 # Foundation, Inc.
 #  
-# This program is free software; you can redistribute it and/or modify
+# GNU Mailutils is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #   
-# This program is distributed in the hope that it will be useful,
+# GNU Mailutils is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #  
 # You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301 USA.
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
 verbose "STARTED" 1
 
diff --git a/testsuite/mbdel.at b/testsuite/mbdel.at
index 57dca63..99137e5 100644
--- a/testsuite/mbdel.at
+++ b/testsuite/mbdel.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/testsuite/mbdel.c b/testsuite/mbdel.c
index 802444b..e1c7339 100644
--- a/testsuite/mbdel.c
+++ b/testsuite/mbdel.c
@@ -12,7 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/testsuite/mime.at b/testsuite/mime.at
index ff39da6..cb023f7 100644
--- a/testsuite/mime.at
+++ b/testsuite/mime.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/testsuite/mimetest.c b/testsuite/mimetest.c
index 581eae7..245cf3a 100644
--- a/testsuite/mimetest.c
+++ b/testsuite/mimetest.c
@@ -13,9 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GNU Mailutils; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-   MA 02110-1301 USA */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */ 
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/testsuite/smtpsend.c b/testsuite/smtpsend.c
index 1b843e3..c93dcc0 100644
--- a/testsuite/smtpsend.c
+++ b/testsuite/smtpsend.c
@@ -12,7 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
diff --git a/testsuite/testsuite.at b/testsuite/testsuite.at
index 5686cfa..7bb3e05 100644
--- a/testsuite/testsuite.at
+++ b/testsuite/testsuite.at
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
diff --git a/testsuite/testsuite.inc b/testsuite/testsuite.inc
index 56f4538..363913f 100644
--- a/testsuite/testsuite.inc
+++ b/testsuite/testsuite.inc
@@ -6,7 +6,7 @@
 # published by the Free Software Foundation; either version 3, or (at
 # your option) any later version.
 #
-# This program is distributed in the hope that it will be useful, but
+# GNU Mailutils is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.


hooks/post-receive
-- 
GNU Mailutils



reply via email to

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