Stream support rewritten from scratch.

Does not compile yet.

New files:
* mailbox/streamref.c
* include/mailutils/sys/streamref.h
* include/mailutils/sys/file_stream.h
* include/mailutils/sys/header_stream.h
* include/mailutils/sys/mapfile_stream.h
* include/mailutils/sys/memory_stream.h
* include/mailutils/sys/message_stream.h
* include/mailutils/sys/prog_stream.h
* include/mailutils/sys/socket_stream.h
* include/mailutils/sys/stdio_stream.h
* include/mailutils/sys/stream.h
* include/mailutils/sys/streamtrans.h
* mailbox/prog_stream.c
* mailbox/stdio_stream.c
* mailbox/stream_printf.c
* mailbox/stream_vprintf.c
* mailbox/temp_file_stream.c
* mailbox/streamcpy.c
* mailbox/binflt.c
* mailbox/crlfflt.c
* mailbox/fltstream.c
* mailbox/qpflt.c
* mailbox/linelenflt.c

Removed files:
* mailbox/filter_rfc822.c
* mailbox/filter_trans.c

Moved files (with edits):
* libproto/include/filter0.h -> include/mailutils/sys/filter.h
* libproto/include/header0.h -> include/mailutils/sys/header.h
* libproto/include/message0.h -> include/mailutils/sys/message.h
* libproto/include/mime0.h -> include/mailutils/sys/mime.h

Modified files:
* comsat/action.c
* config/mailutils-config.c
* examples/base64.c
* examples/cpp/msg-send.cc
* examples/header.c
* examples/http.c
* examples/iconv.c
* examples/mimetest.c
* examples/msg-send.c
* examples/mta.c
* examples/murun.c
* examples/nntpclient.c
* examples/pop3client.c
* imap4d/append.c
* imap4d/auth_gsasl.c
* imap4d/fetch.c
* imap4d/preauth.c
* imap4d/search.c
* imap4d/util.c
* include/mailutils/body.h
* include/mailutils/folder.h
* include/mailutils/header.h
* include/mailutils/mailbox.h
* include/mailutils/mailer.h
* include/mailutils/mailutils.h
* include/mailutils/message.h
* include/mailutils/stream.h
* include/mailutils/sys/Makefile.am
* include/mailutils/sys/filter.h
* include/mailutils/sys/header.h
* include/mailutils/sys/message.h
* include/mailutils/sys/mime.h
* include/mailutils/sys/nntp.h
* include/mailutils/sys/pop3.h
* include/mailutils/sys/stream.h
* include/mailutils/types.hin
* lib/mailcap.c
* lib/mu_dbm.h
* libmu_argp/muinit.c
* libmu_auth/ldap.c
* libmu_auth/tls.c
* libmu_scm/Makefile.am
* libmu_scm/mu_body.c
* libmu_scm/mu_message.c
* libmu_scm/mu_port.c
* libmu_sieve/actions.c
* libmu_sieve/extensions/pipe.c
* libmu_sieve/extensions/spamd.c
* libmu_sieve/extensions/vacation.c
* libproto/mailer/smtp.c
* libproto/mbox/mboxscan.c
* libproto/mbox/mbox.c
* libproto/mbox/mbox0.h
* libproto/nntp/nntp_article.c
* libproto/nntp/nntp_carrier.c
* libproto/nntp/nntp_destroy.c
* libproto/nntp/nntp_ihave.c
* libproto/nntp/nntp_post.c
* libproto/nntp/nntp_readline.c
* libproto/nntp/nntp_sendline.c
* libproto/pop/pop3_carrier.c
* libproto/pop/pop3_destroy.c
* libproto/pop/pop3_readline.c
* libproto/pop/pop3_sendline.c
* libproto/pop/pop3_stat.c
* maidag/mailtmp.c
* mail/decode.c
* mail/escape.c
* mail/msgset.y
* mail/pipe.c
* mail/print.c
* mail/send.c
* mail/top.c
* mail/util.c
* mail/write.c
* mailbox/Makefile.am
* mailbox/amd.c
* mailbox/attachment.c
* mailbox/body.c
* mailbox/cfg_driver.c
* mailbox/cfg_format.c
* mailbox/debug.c
* mailbox/file_stream.c
* mailbox/folder.c
* mailbox/hdritr.c
* mailbox/header.c
* mailbox/mailbox.c
* mailbox/mailcap.c
* mailbox/mailer.c
* mailbox/mapfile_stream.c
* mailbox/memory_stream.c
* mailbox/message.c
* mailbox/message_stream.c
* mailbox/mime.c
* mailbox/mimehdr.c
* mailbox/mutil.c
* mailbox/prog_stream.c
* mailbox/progmailer.c
* mailbox/rfc2047.c
* mailbox/socket_stream.c
* mailbox/stream.c
* mailbox/stream_vprintf.c
* mailbox/tcp.c
* mailbox/vartab.c
* mailbox/wicket.c
* mh/burst.c
* mh/comp.c
* mh/compcommon.c
* mh/forw.c
* mh/mh_ctx.c
* mh/mh_format.c
* mh/mh_init.c
* mh/mh_list.c
* mh/mh_whatnow.c
* mh/mhl.c
* mh/mhn.c
* mh/pick.y
* mh/repl.c
* mimeview/mimeview.c
* mu-aux/generr.awk
* pop3d/extra.c
* pop3d/pop3d.h
* pop3d/retr.c
* pop3d/top.c
* readmsg/msglist.c
* readmsg/readmsg.c
* sieve/sieve.c
Bugfixes.

* examples/sfrom.c (main): Check return from mu_mailbox_messages_count.
* include/mailutils/sys/stream.h (_MU_STR_WRT): New constant.
* libproto/mbox/mbox.c (_msg_stream_setup): Fix 3rd argument to
mu_streamref_create_abridged.
* libproto/mbox/mboxscan.c (mbox_scan_internal): Don't use mailbox->stream
directly, because its offsets may get shifted by observers. Use streamref
instead.
* mailbox/argcv.c (argcv_get): Do nothing if argc <= 0.
* mailbox/mapfile_stream.c (_mapfile_seek): Fill the *presult.
* mailbox/memory_stream.c (_memory_done): Remove leftover free.
* mailbox/stream.c: Reorder functions.
(_mu_stream_create): Increase reference count (i.e. set it to 1)
before returning.
(mu_stream_seek): Call _stream_flush_buffer instead of
mu_stream_flush.
(mu_stream_read_unbuffered): Return 0 on EOF.
(mu_stream_write_unbuffered): Set _MU_STR_WRT bit.
(mu_stream_readline, mu_stream_getdelim): Check the actual
number of bytes read.
(mu_stream_flush): Call flush method only if _MU_STR_WRT is set.
Clear it.
* mailbox/streamref.c (_streamref_seek): Optimization for off==0 and
whence == MU_SEEK_CUR.
(_streamref_seek): Return new offset in ppos.
(mu_streamref_create_abridged): Set MU_STREAM_NO_CLOSE.
* mailbox/memory_stream.c (_memory_seek) : Return new offset in presult.
* mailbox/message_stream.c (_message_seek): Likewise.
* mailbox/stdio_stream.c (stdio_seek): Fix prototype.
Bugfixes in stream code.

* mailbox/amd.c (amd_body_stream_seek): Fix boundary checking.
Return ESPIPE on boundary error.
* mailbox/header.c (header_seek): Likewise.
* mailbox/memory_stream.c (_memory_seek): Likewise.
* mailbox/message.c (_message_stream_seek): Likewise.
* mailbox/message_stream.c (_message_seek): Likewise.
* mailbox/stdio_stream.c (stdio_seek): Likewise.

* mailbox/file_stream.c (fd_open): Invert error condition.
Fix computation of open flags.
Return immediately if open returns -1.
(fd_seek): Fix boundary checking.
Return ESPIPE on boundary error.
* mailbox/mapfile_stream.c (_mapfile_open): Fix flags calculation.
(_mapfile_seek): Fix boundary checking.
Return ESPIPE on boundary error.

* mailbox/streamref.c (_streamref_read): Fix calculation of the
top size boundary.
Return 0 bytes if seek returns ESPIPE.
(_streamref_seek): Return ESPIPE on boundary error.

* mailbox/base64.c (_base64_decoder, _base64_encoder): Do
not dereference iobuf if cmd is mu_filter_init or mu_filter_done.
* mailbox/binflt.c (_copy_codec, _bit7_coder): Likewise.
* mailbox/crlfflt.c (_crlf_encoder, _crlf_decoder): Likewise.
* mailbox/linelenflt.c (_ll_encoder): Likewise.
* mailbox/qpflt.c (_qp_decoder, _qp_encoder): Likewise.

* mailbox/mailcap.c (mu_mailcap_parse): Fix loop condition.
Fix UNIX mbox driver and mail utility.

The `mail' and `frm' utilities pass tests.

* include/mailutils/stream.h (mu_stream_err): New proto.
* libproto/mbox/mbox.c (_msg_stream_setup)
(_msg_body_setup): Fix stream abridgement.
(mbox_envelope_date, mbox_envelope_sender): Fix seek position.
(uid_to_stream): Fix invocation of mu_stream_printf.
(append_message_to_stream): Likewise.
(mbox_expunge_unlocked): Rewind tempstr before copying its
contents back to the mailbox.
(mbox_expunge0): Open tempstr.
* libproto/mbox/mbox0.h (_mbox_message)<header_from>: Rename to
envel_from.
<header_from_end>: Rename to envel_from_end. All uses changed.
* libproto/mbox/mboxscan.c: Minor changes.

* mail/decode.c: Use streamrefs.
* mail/escape.c: Likewise.
* mail/msgset.y: Likewise.
* mail/pipe.c: Likewise.
* mail/print.c: Likewise.
* mail/top.c: Likewise.
* mail/write.c: Likewise.

* mail/send.c: Use streamrefs.
(mail_send0): Reset env->header after assigning it to
the message.

* mailbox/body.c (_body_seek): Fix a typo which produced
a recursive call.
* mailbox/file_stream.c (fd_truncate): New function.
(_mu_file_stream_create): Initialize str->stream.truncate.

* mailbox/header.c (header_parse): Fix parsing of blurbs lacking
terminating empty line.
(header_seek): Fix boundary checks.
Return new position in presult.
* mailbox/message.c (string_find_eoh): Rewrite to handle \n\n
split between two successive invocations.
(_header_fill): Update the invocation of string_find_eoh.

* mailbox/stream.c (mu_stream_destroy): Call mu_stream_close.
(mu_stream_get_flags, mu_stream_set_flags)
(mu_stream_clr_flags): Ignore internal
bits.
(mu_stream_err): New function.
(mu_stream_close): Close the stream only if it is not used by anyone else.
* mailbox/streamref.c (_streamref_read): Clear transport error if
ESPIPE is returned.
(_streamref_size): Take into account sp->end and sp->start.
(mu_streamref_create_abridged): Set pointer to 0.
Fix compilation of mimeview.

* mimeview/mimeview.c (mimeview_fp): Restore the variable.
Fix compilation of several example programs.

* examples/header.c: Use streamrefs.
* examples/mimetest.c: Likewise.
* examples/mta.c: Likewise.
* examples/nntpclient.c: Remove an unused variable.
Fix compilation of libmu_scm.

* libmu_scm/mu_body.c (mu_scm_body_free): Unref the stream.
Return 0.
(mu-body-read-line, mu-body-write): Use stringrefs.
* libmu_scm/mu_mailbox.c (mu-mailbox-get-port): Use stringrefs.
* libmu_scm/mu_message.c (mu-message-copy): Use stringrefs.
Use mu_stream_copy instead of manually copying stream contents.
(mu-message-get-port): Use stringrefs.
* libmu_scm/mu_port.c (mu_port_free): Unref the stream.
Use stringrefs, add some guidelines for further editing.

* comsat/action.c
* imap4d/fetch.c
* imap4d/search.c
* mh/burst.c
* mh/comp.c
* mh/forw.c
* mh/mh_ctx.c
* mh/mh_format.c
* mh/mh_list.c
* mh/mhn.c
* mh/pick.y
* pop3d/retr.c
* pop3d/top.c
* readmsg/msglist.c
* readmsg/readmsg.c
Keep track of the current offset in the _mu_stream structure.

* include/mailutils/sys/stream.h (_mu_stream)<offset>: New member.
* mailbox/stream.c (_stream_fill_buffer): Propagate return value
from mu_stream_read_unbuffered.
(_stream_flush_buffer): Use stream->offset. Honor the `all' argument.
(mu_stream_seek): Rewrite using the `offset' member.
(mu_stream_read_unbuffered)
(mu_stream_write_unbuffered): Update offset.
(mu_stream_readline): Return EINVAL if size is 0.
Bugfix in filter_iconv.

* mailbox/filter_iconv.c (mu_filter_iconv_create): Return
the created stream in *s.
Bugfixes

* mailbox/message.c (_check_stream_state): Bugfix.
(_message_stream_seek): Bugfix.
(_message_stream_read): Always try to fill out the buffer.
(_message_stream_create): Set MU_STREAM_SEEK flag bit.
Fix amd

* mailbox/amd.c (_amd_attach_message): Store body.
(amd_scan_message): Scan the message only if it has been modified
after the last scan.
Fix loop condition.
Store mhm->mtime on success.
(amd_message_stream_open): Enforce full buffering.
(amd_body_stream_read): Fix.
(amd_body_stream_seek): Don't call mu_stream_seek on mhm->stream.
Optimize readline/readdelim/getdelim calls.

This speeds up common reading operations by factor of 4-6.

* include/mailutils/stream.h (mu_stream_readdelim): New proto.
* include/mailutils/sys/stream.h (_mu_stream) <readdelim>: New method.
* mailbox/stream.c (_stream_scandelim, _stream_readdelim): New functions.
(mu_stream_readdelim): New function.
(mu_stream_readline): Rewrite using mu_stream_readdelim.
(mu_stream_getdelim): Optimize.

* mailbox/amd.c (amd_body_stream_readdelim): New function.
(_amd_attach_message): Set the readdelim method.
* mailbox/header.c: Add a placeholder for readdelim method.
* mailbox/message.c (_message_stream_readdelim): New function.
(_message_stream_create): Set the readdelim method.
* mailbox/streamref.c (_streamref_readdelim): New function.
(mu_streamref_create_abridged): Set the readdelim method.
Bugfixes.

* mailbox/rfc2047.c (mu_rfc2047_decode): Rewind in_stream.
* mailbox/stream.c (_stream_scandelim): Break the loop when
the delimiter is found.
* mailbox/streamref.c (_streamref_readdelim): Take into account
the abridgement.
Improve CRLF filter.

* include/mailutils/filter.h (mu_filter_new_data_t): Change prototype.
* mailbox/filter.c (mu_filter_create): Reflect the above.
* mailbox/crlfflt.c (crlf_state): New enum.
(_crlf_encoder): Keep state info in xd. Do not modify eventual input
CRLFs.
(alloc_state): New function.
(_rfc822_filter,_crlf_filter): Provide the `newdata' method.
Simplify stream->seek.

* include/mailutils/sys/stream.h (_mu_stream) <seek>: Remove the
`whence' parameter.
* mailbox/stream.c (mu_stream_seek): Update the seek method call.

* mailbox/streamref.c (_streamref_seek): Fix the signature. Remove
unnecessary code.
* mailbox/amd.c (amd_body_stream_seek): Likewise.
* mailbox/body.c (_body_seek): Likewise.
* mailbox/file_stream.c (fd_seek): Likewise.
* mailbox/filter_iconv.c (_icvt_seek): Likewise.
* mailbox/fltstream.c (filter_seek): Likewise.
* mailbox/header.c (header_seek): Likewise.
* mailbox/mapfile_stream.c (_mapfile_seek): Likewise.
* mailbox/memory_stream.c (_memory_seek): Likewise.
* mailbox/message.c (_message_stream_seek): Likewise.
* mailbox/message_stream.c (_message_stream_seek): Likewise.
* mailbox/mime.c (_mime_body_seek): Likewise.
* mailbox/stdio_stream.c (stdio_seek): Likewise.
Fix conditional compilation.

* .gitignore: Add git-describe and git-describe.h.
* Makefile.am (MU_COND_LIBMU_CPP): Replaced with MU_COND_SUPPORT_CXX
(SUBDIRS): Begin with .
(EXTRA_DIST, BUILT_SOURCES): Add git-describe and git-describe.h.
(git-describe, git-describe.h): New rules.
(alpha, alphacheck): Use git-describe to produce additional suffix.
* enable.m4 (MU_ENABLE_SUPPORT): Create an Automake condition.
* configure.ac: Fix MU_ENABLE_SUPPORT calls.
(--without-python): Replace with --disable-python.
* examples/Makefile.am: Disable components based on MU_COND conditions.
* libproto/Makefile.am: Likewise.
* include/mailutils/Makefile.am (MU_COND_LIBMU_CPP): Replace with
MU_COND_SUPPORT_CXX.

* mailbox/nullrec.c: New file.
* mailbox/Makefile.am (libmailutils_la_SOURCES): Add nullrec.c.

* mail/decode.c: Remove unused variable.
* mailbox/streamref.c: Likewise.
For alpha version, include git tag info in the version output.

* include/mailutils/libargp.h (mu_program_version_hook): New proto.
* libmu_argp/Makefile.am (libmu_argp_a_SOURCES): Remove mu_argp.h.
* libmu_argp/mu_argp.h: Remove.
* libmu_argp/muinit.c [MU_ALPHA_RELEASE]: Include git-describe.h
(mu_program_version_hook): New function.
(mu_argp_init): Set mu_program_version_hook, unless vers is given.

* comsat/comsat.c (main): Call mu_argp_init with NULL arguments.
* config/mailutils-config.c: Likewise.
* dotlock/dotlock.c: Likewise.
* examples/muauth.c: Likewise.
* frm/frm.c: Likewise.
* frm/from.c: Likewise.
* guimb/main.c: Likewise.
* imap4d/imap4d.c: Likewise.
* maidag/maidag.c: Likewise.
* mail/mail.c: Likewise.
* messages/messages.c: Likewise.
* mimeview/mimeview.c: Likewise.
* movemail/movemail.c: Likewise.
* pop3d/pop3d.c: Likewise.
* pop3d/popauth.c: Likewise.
* readmsg/readmsg.c: Likewise.
* sieve/sieve.c: Likewise.
Make version output of the MH utilities more informative.

* mh/mh_argp.c [MU_ALPHA_RELEASE}: Include git-describe.h
(mh_program_version_hook): New function.
(mh_argp_init): Take no arguments. Set argp_program_version_hook.
* mh/mh_getopt.h (ARG_LICENSE): Remove.
(mh_argp_init): Change proto.

All sources: Fix calls to mh_argp_init, remove --license option.
Implement seek on filters in read-only mode.

* include/mailutils/stream.h (mu_stream_skip_input_bytes): New proto.
* mailbox/stream.c (mu_stream_skip_input_bytes): New function.
* mailbox/fltstream.c (filter_seek): Re-implement on top of
mu_stream_skip_input_bytes.
(mu_filter_stream_create): Fix flag validity checking.

* examples/base64.c: Add new option (-s) for testing seek operations
on filters.