1. 08 Sep, 2010 40 commits
    • * include/mailutils/stream.h (MU_IOCTL_SWAP_STREAM): New ioctl op.
      (mu_stream_seterr): New function.
      * include/mailutils/sys/stream.h (_MU_SWAP_FIRST_ONLY)
      (_MU_SWAP_IOCTL_MUST_SUCCEED): New defines.
      (_mu_stream_swap_streams): New proto.
      * mailbox/amd.c (amd_body_stream_read): Always update *pnread.
      * mailbox/errors (MU_ERR_NO_TRANSPORT): New error code.
      
      * mailbox/stream.c (_stream_seterror): Rename to mu_stream_seterr,
      remove static qualifier. All uses updated.
      (_mu_stream_swap_streams): New function.
      
      * mailbox/filter_iconv.c (_icvt_ioctl): Implement MU_IOCTL_SWAP_STREAM.
      * mailbox/iostream.c (_iostream_ctl): Likewise.
      * mailbox/xscript-stream.c (_xscript_ctl): Likewise.
      
      * pop3d/extra.c (real_istream, real_ostream): Remove statics.
      (pop3d_init_tls_server): Use MU_IOCTL_SWAP_STREAM to replace
      bottom-level transport layers without recreating the entire stream
      chain.
      Sergey Poznyakoff authored
    • If a stream takes another stream(s) as a transport, it
      always increases its reference count.  This means that
      when that stream is destroyed the underlying stream is
      not destroyed by default (its refcount is decreased, that's
      all). To force destruction of the underlying stream,
      the caller must explicitly unreference it after creating
      the stream that uses it (or give its creation function
      the MU_STREAM_AUTOCLOSE flag, if it supports flags).
      
      Similarly, if a stream uses a non-stream object (e.g. a file
      descriptor) as the transport, it will not destroy it, unless
      it has been created with the MU_STREAM_AUTOCLOSE flag. This
      differs from the previous behavior.
      
      The MU_STREAM_NO_CHECK and MU_STREAM_NO_CLOSE flags are removed.
      
      * examples/base64.c (main): Call mu_filter_create with the
      MU_STREAM_AUTOCLOSE flag.
      * examples/mimetest.c (message_display_parts): Likewise.
      * examples/murun.c (main): Unref the input stream after
      passing it to mu_filter_prog_stream_create.
      * imap4d/fetch.c (fetch_io): Update arguments to mu_filter_create
      and mu_memory_stream_create.
      * imap4d/preauth.c (decode64_buf)
      (do_preauth_ident): Update arguments to mu_memory_stream_create and
      mu_tcp_stream_create.
      * imap4d/util.c (util_setio): Update arguments to mu_filter_create and
      mu_stdio_stream_create.
      * include/mailutils/stream.h (MU_STREAM_NO_CLOSE)
      (MU_STREAM_NO_CHECK): Remove.
      (MU_STREAM_AUTOCLOSE): New flag.
      (mu_iostream_create): Remove the `flags' argument.
      * libmu_argp/muinit.c (mu_app_init): Update arguments to
      mu_stdio_stream_create.
      * libmu_auth/ldap.c: Update arguments to
      mu_memory_stream_create and mu_filter_create.
      * libmu_auth/tls.c (_tls_io_close, _tls_close): Always try to close the
      transport stream. Rely on refcount to protect it.
      (_tls_io_done, _tls_done): Likewise, always unreference it.
      (_mu_tls_io_stream_create): Increase reference counter on the
      transport stream, unless MU_STREAM_AUTOCLOSE is requested.
      (_mu_tls_stream_create): Rewrite using the new MU_STREAM_AUTOCLOSE
      logic.
      * libmu_sieve/extensions/spamd.c (spamd_connect_tcp): Update arguments to
      mu_tcp_stream_create.
      (spamd_connect_tcp): Update arguments to mu_socket_stream_create and
      mu_filter_create.
      * libmu_sieve/extensions/vacation.c (build_mime): Update arguments to
      mu_filter_create.
      * mail/decode.c (display_submessage): Update arguments to
      mu_filter_create.
      * mailbox/attachment.c (mu_message_save_attachment): Update arguments to
      mu_filter_create.
      * mailbox/cfg_driver.c (mu_cfg_tree_reduce): Update arguments to
      mu_stdio_stream_create.
      * mailbox/dbgstream.c (_dbg_done): Use MU_STREAM_AUTOCLOSE bit to
      decide whether to destroy the debug object.
      (mu_dbgstream_create): Use MU_STREAM_AUTOCLOSE instead of
      MU_STREAM_NO_CLOSE.
      * mailbox/file_stream.c (fd_close): Use MU_STREAM_AUTOCLOSE bit to
      decide whether to close the descriptor.
      (mu_file_stream_create): Force MU_STREAM_AUTOCLOSE bit.
      * mailbox/filter.c (filter_create_rd, filter_create_wr): Change
      substream creation logic.
      * mailbox/filter_iconv.c (_icvt_close): Always try to close the
      transport stream. Rely on refcount to protect it.
      (_icvt_done): Ditto for destroying it.
      (mu_filter_iconv_create): Increase refcount on the transport stream,
      unless MU_STREAM_AUTOCLOSE is requested.
      * mailbox/fltstream.c (filter_done): Always dereference the
      transport stream. Rely on refcount to protect it.
      (filter_close): Ditto for closing it.
      (mu_filter_stream_create): Increase refcount on the transport stream,
      unless MU_STREAM_AUTOCLOSE is requested.
      * mailbox/iostream.c (_iostream_close) : Always try to close the
      transport stream. Rely on refcount to protect it.
      (_iostream_done): Ditto for closing it.
      (mu_iostream_create): Remove the use of MU_STREAM_NO_CLOSE.
      * mailbox/mimehdr.c (mu_mimehdr_decode_param): Remove the use of
      MU_STREAM_NO_CLOSE.
      * mailbox/mutil.c (mu_decode_filter) Change substream creation logic.
      * mailbox/prog_stream.c (_prog_open): Use MU_STREAM_AUTOCLOSE bit
      in arguments to mu_stdio_stream_create.
      (mu_filter_prog_stream_create): Increase refcount on the transport
      (input) stream.
      * mailbox/rfc2047.c (mu_rfc2047_decode): Dereference in_stream after
      passing it to mu_decode_filter.
      Pass MU_STREAM_AUTOCLOSE in flags to mu_filter_create.
      * mailbox/socket_stream.c (mu_socket_stream_create): Force
      MU_STREAM_AUTOCLOSE bit.
      * mailbox/streamref.c (_streamref_close): Always close the
      transport stream (refcount will protect it, if necessary).
      (mu_streamref_create_abridged): Mask out the MU_STREAM_AUTOCLOSE bit.
      * mailbox/temp_file_stream.c (mu_temp_file_stream_create: Force
      MU_STREAM_AUTOCLOSE bit.
      * mailbox/xscript-stream.c (_xscript_close): Always close the
      transport stream (refcount will protect it, if necessary).
      (mu_xscript_stream_create): Increase refcounts on both underlying streams,
      unless MU_STREAM_AUTOCLOSE is set.
      * pop3d/extra.c (pop3d_setio): Remove uses of MU_STREAM_NO_CLOSE.
      
      * examples/nntpclient.c: Remove uses of MU_STREAM_NO_CHECK/MU_STREAM_NO_CLOSE.
      * examples/pop3client.c: Likewise.
      * libmu_auth/gsasl.c: Likewise.
      * libproto/nntp/nntp_stream.c: Likewise.
      * libproto/pop/pop3_stream.c: Likewise.
      * mailbox/tcp.c: Likewise.
      * mailbox/vartab.c: Likewise.
      * mh/mh_list.c: Likewise.
      * mimeview/mimeview.c: Likewise.
      * mh/mhn.c: Likewise.
      (edit_mime): Use MU_STREAM_AUTOCLOSE.
      
      Bugfixes:
      
      * mailbox/fltstream.c (init_iobuf): Fix input initialization.
      (filter_write_internal): Bugfix.
      * mailbox/stream.c (_stream_buffer_freespace): New macro.
      (_stream_buffer_is_full): New macro.
      (BUFFER_FULL_P): Remove, use _stream_buffer_is_full instead. All callers
      updated.
      (_stream_flush_buffer): Operation for full buffered streams does not
      depend on the `all' flag.
      (mu_stream_write): Fix calculation of the bytes available in the
      buffer.
      Sergey Poznyakoff authored
    • * include/mailutils/stream.h (MU_STREAM_RDTHRU)
      (MU_STREAM_WRTHRU,MU_IOCTL_SET_TRANSPORT): New flags.
      (mu_xscript_stream_create, mu_iostream_create)
      (mu_dbgstream_create): New prototypes.
      * include/mailutils/sys/dbgstream.h: New header.
      * include/mailutils/sys/iostream.h: New header.
      * include/mailutils/sys/xscript-stream.h: New header.
      * include/mailutils/sys/Makefile.am (sysinclude_HEADERS): Add
      dbgstream.h, iostream.h and xscript-stream.h
      * mailbox/dbgstream.c: New file.
      * mailbox/iostream.c: New file.
      * mailbox/xscript-stream.c: New file.
      * mailbox/Makefile.am (libmailutils_la_SOURCES): Add dbgstream.c,
      iostream.c and xscript-stream.c
      * mailbox/filter_iconv.c (_icvt_ioctl): Simplify the declaration
      of ptrans.
      * mailbox/mapfile_stream.c (_mapfile_ioctl): Likewise.
      * mailbox/memory_stream.c (_memory_ioctl): Likewise.
      * mailbox/prog_stream.c (_prog_ioctl): Likewise.
      * mailbox/tcp.c (_tcp_ioctl): Likewise.
      * mailbox/fltstream.c (filter_ctl): Likewise.
      (filter_read_through, filter_write_through): New methods.
      (mu_filter_stream_create): Allow for use of MU_STREAM_RDTHRU
      and MU_STREAM_WRTHRU to create two-way filters (writing
      triggers filtering while reading is transparent or vice versa).
      * pop3d/extra.c (istream, ostream): Remove globals.
      (iostream): New variable.
      (real_istream, real_ostream): New variables.
      (pop3d_setio): Set transcript stream on top of the I/O one,
      if required.
      (pop3d_init_tls_server): Rewrite. Revert the meaning of the
      return code to match the usual convention (0 - success).
      (transcript): Removed.
      (pop3d_outf): Remove calls to transcript.
      * pop3d/pop3d.h (istream, ostream): Remove externs.
      (iostream): New extern.
      * pop3d/retr.c: Use iostream, instear of ostream.
      * pop3d/top.c: Likewise.
      * pop3d/stls.c: Update the call to pop3d_init_tls_server.
      
      * mailbox/stream_vprintf.c (mu_stream_vprintf): Fix return
      value to match the usual convention.
      Sergey Poznyakoff authored
    • STLS in pop3d is already working.
      
      * include/mailutils/sys/tls-stream.h: New header.
      * include/mailutils/tls.h (mu_tls_stream_create)
      (mu_tls_stream_create_client)
      (mu_tls_stream_create_client_from_tcp): Remove.
      (mu_tls_server_stream_create, mu_tls_client_stream_create): New
      protos.
      * libmu_auth/tls.c: Rewrite.
      
      * imap4d/util.c: Use mu_tls_server_stream_create.
      * libproto/pop/mbox.c: Use mu_tls_server_stream_create/
      mu_tls_client_stream_create.
      * libproto/pop/pop3_stls.c: Use mu_tls_client_stream_create.
      * libproto/imap/folder.c: Use mu_tls_client_stream_create.
      
      * pop3d/capa.c (pop3d_capa): CAPA is allowed in both states.
      * pop3d/extra.c (pop3d_setio): Rewrite.
      Sergey Poznyakoff authored
    • * mailbox/amd.c (amd_body_stream_readdelim): Fix the logic.
      * mailbox/message.c (_message_stream_seek): Fix seeks in
      backward direction.
      * pop3d/top.c: Fix output of the body.
      Sergey Poznyakoff authored
    • * imap4d/append.c: Add a comment.
      * imap4d/imap4d.h (imap4d_child_signal_setup): New proto.
      * libmu_sieve/extensions/pipe.c (sieve_action_pipe): Use
      mu_stream_copy, rewrite error handling.
      * libmu_sieve/extensions/spamd.c (spamd_send_message): se
      mu_stream_copy.
      (spamd_test): Honor dry-run mode.
      * libmu_sieve/extensions/vacation.c (build_mime): Remove
      misleading FIXME. Use mu_stream_copy.
      * libmu_sieve/extensions/moderator.c (moderator_message_get_part): Use
      mu_body_get_streamref.
      * examples/header.c (hstream): New global.
      (cmd_load, cmd_free, cmd_remove, cmd_insert): Discard hstream.
      (cmd_readline): Use hstream. Obtain it using mu_stream_readline.
      * libproto/mbox/mbox.c (mbox_envelope_date): Remove trailing
      newline from the obtained envelope line.
      * mailbox/amd.c (amd_body_stream_seek): Allow for off == size
      (imprtant for empty bodies).
      Sergey Poznyakoff authored
    • * libmu_sieve/actions.c (mime_create_quote): Use mu_stream_copy.
      Sergey Poznyakoff authored
    • * pop3d/pop3d.h: Include filter.h.
      (istream, ostream): New externs.
      * pop3d/extra.c (pop3d_setio): Set a crlf filter on the
      output stream. This allows to forget about \r in the rest of
      the code.
      * pop3d/retr.c (pop3d_retr): Use mu_stream_copy instead of
      copying streams manually.
      * pop3d/top.c (pop3d_top): Rewrite using streamrefs and
      mu_stream_copy.
      * all sources: Use \n instead of \r\n in output strings.
      Sergey Poznyakoff authored
    • * examples/mta.c (finalize_option): New variable.
      (message_finalize): Don't modify the message if finalize_option
      is 0.
      * include/mailutils/sys/message.h (_mu_message)
      <orig_header_size>: New member.
      * include/mailutils/sys/mime.h (_mu_mime) <part_stream>: New member.
      * libmu_sieve/actions.c (mime_create_reason)
      (mime_create_ds): Use mu_body_get_streamref.
      (mime_create_quote): Use mu_body_get_streamref/mu_message_get_streamref.
      (sieve_action_reject): Set the To: header.
      * mailbox/message.c (mu_message_get_header): Set orig_header_size.
      (mu_message_get_body): Use orig_header_size instead of relying
      on mu_header_size.
      * mailbox/mime.c (_mime_part_size): New static.
      (_mime_body_stream_size): New method.
      (_mime_body_seek): Rename to _mime_body_stream_seek.
      (_mime_body_read): Rewrite and rename to _mime_body_stream_read.
      (_mime_body_ioctl): Rename to _mime_body_stream_ioctl.
      (create_mime_body_stream): Take mu_mime_t as the 2nd parameter.
      Initialize sp->stream.size and sp->mime.
      (_mime_body_size): Rewrite using _mime_part_size.
      (mu_mime_destroy): Destroy part_stream.
      * sieve/testsuite/Redirect: Reflect new mta behavior.
      * sieve/testsuite/Reject: Likewise.
      Sergey Poznyakoff authored
    • * libproto/mbox/mbox.c (_msg_stream_setup): Fix abridgement limits.
      (mbox_expunge_unlocked): Don't write extra newline after each
      message.
      * mailbox/stream.c (mu_stream_seek): ESPIPE does not constitute
      a permanent error.
      Sergey Poznyakoff authored
    • * mailbox/mime.c (mu_mime_get_part): Fix the end limit for the
      part's abridgement.
      * mailbox/streamref.c (_streamref_seek): Fix ESPIPE condition.
      Sergey Poznyakoff authored
    • * include/mailutils/message.h (mu_message_set_stream): Mark as deprecated.
      * pop3d/retr.c (pop3d_retr): Rewind the stream obtained from
      mu_message_get_stream.
      * pop3d/top.c (pop3d_top): Rewind the streams obtained from
      mu_body_get_stream and mu_header_get_stream.
      Sergey Poznyakoff authored
    • * mailbox/base64.c (_base64_encoder): Fix the use
      of uninitialized variable.
      * mailbox/rfc2047.c (mu_rfc2047_encode): Rewind the
      input stream before reading from it.
      Sergey Poznyakoff authored
    • * mailbox/filter_iconv.c (mu_filter_iconv_create): Set filter flags.
      * mailbox/fltstream.c (mu_filter_stream_create): Likewise.
      * mailbox/qpflt.c (_qp_decoder): Handle '_'.
      Sergey Poznyakoff authored
    • * examples/base64.c (c_copy): Handle printable mode (-p).
      (reset_line_length): New function.
      (main): New option -lN sets the maximum length for output
      lines to N (0 means unlimited).
      * mailbox/testsuite/mailbox/base64.exp: Use -l0 in the
      Decode test.
      Sergey Poznyakoff authored
    • * include/mailutils/header.h (mu_header_invalidate): New proto.
      * mailbox/header.c (mu_header_invalidate): New function.
      
      * libmu_argp/muinit.c (get_canonical_name): Avoid coredumping
      if argp_program_version is NULL.
      * mailbox/base64.c (mu_base64_decode): Fix inconsistent return
      code.
      * mailbox/debug.c (mu_debug_destroy): Allow for debug->stream == NULL.
      
      * mailbox/mapfile_stream.c (_mapfile_truncate): Incorrect size
      was used when unmapping.
      * mailbox/message.c (mu_message_create_copy): Use a temporary
      memory stream.
      (mu_message_get_body): Comment out the check for MESSAGE_INTERNAL_STREAM.
      (_message_get_stream): Initialize message header and body.
      
      * mailbox/progmailer.c (mu_progmailer_send): Check  return
      from the mu_header_get_streamref.
      
      * mailbox/stream.c (_stream_scandelim, _stream_readdelim): If
      size is 0, return MU_ERR_BUFSPACE.
      Sergey Poznyakoff authored
    • Fix readmsg. · 85b56e79
      Readmsg passes all tests successfully.
      
      * readmsg/msglist.c (msglist): Check return from mu_message_get_streamref.
      * readmsg/readmsg.c (print_header, print_body): Check return values.
      Sergey Poznyakoff authored
    • * mailbox/header.c (header_seek): Do not dereference
      hstr->hdr->size directly, because it may not be initialized yet.
      Use mu_header_size instead.
      * mailbox/message.c (_message_stream_readdelim): Break the loop
      if mu_stream_readdelim returned error or EOF.
      Sergey Poznyakoff authored
    • Imap4d successfully passes all tests.
      
      * imap4d/close.c (imap4d_close0): Fix improper use of MU_STREAM_READ
      (flags changed their semantics since then).
      * imap4d/fetch.c: Send \n terminated lines, rely on filters to recode
      line terminators to \r\n.
      (fetch_io): Rewrite using CRLF encoder and util_copy_out.
      (_frt_header_fields): Rewind memory stream before reading from it.
      
      * imap4d/auth_gsasl.c: Send \n terminated lines, rely on filters
      to recode line terminators to \r\n.
      * imap4d/auth_gss.c: Likewise.
      * imap4d/capability.c: Likewise.
      * imap4d/copy.c: Likewise.
      * imap4d/id.c: Likewise.
      * imap4d/idle.c: Likewise.
      * imap4d/list.c: Likewise.
      * imap4d/namespace.c: Likewise.
      * imap4d/preauth.c: Likewise.
      * imap4d/search.c: Likewise.
      * imap4d/status.c: Likewise.
      * imap4d/store.c: Likewise.
      * imap4d/select.c: Likewise.
      (imap4d_select_status): Fix improper use of MU_STREAM_READ.
      
      * imap4d/util.c: Send \n terminated lines, rely on filters
      to recode line terminators to \r\n.
      (util_setio): Apply CRLF filters to both input and output streams
      (in opposite directions).
      (util_copy_out): New function.
      (remove_cr): Remove.
      * imap4d/imap4d.h (util_copy_out): New prototype.
      Sergey Poznyakoff authored
    • * libproto/mbox/mbox.c (append_message_to_stream): Add \n after each
      message (scanner relies on this to determine message sizes).
      Sergey Poznyakoff authored
    • * mailbox/fltstream.c (filter_read): Do not try to get more input until
      the output buffer is drained.
      * mailbox/mapfile_stream.c (_mapfile_seek): Fix conditional.
      * mailbox/stream.c (_stream_fill_buffer): Fix increment.
      (mu_stream_skip_input_bytes): Bugfixes.
      Sergey Poznyakoff authored
    • * 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.
      Sergey Poznyakoff authored
    • * 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.
      Sergey Poznyakoff authored
    • * 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.
      Sergey Poznyakoff authored
    • * .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.
      Sergey Poznyakoff authored
    • * 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.
      Sergey Poznyakoff authored
    • * 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.
      Sergey Poznyakoff authored
    • * 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.
      Sergey Poznyakoff authored
    • 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.
      Sergey Poznyakoff authored
    • * 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.
      Sergey Poznyakoff authored
    • * 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.
      Sergey Poznyakoff authored
    • * mailbox/filter_iconv.c (mu_filter_iconv_create): Return
      the created stream in *s.
      Sergey Poznyakoff authored
    • * 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.
      Sergey Poznyakoff authored
    • * 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
      Sergey Poznyakoff authored
    • * 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.
      Sergey Poznyakoff authored
    • * examples/header.c: Use streamrefs.
      * examples/mimetest.c: Likewise.
      * examples/mta.c: Likewise.
      * examples/nntpclient.c: Remove an unused variable.
      Sergey Poznyakoff authored
    • * mimeview/mimeview.c (mimeview_fp): Restore the variable.
      Sergey Poznyakoff authored
    • 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.
      Sergey Poznyakoff authored
    • * 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.
      Sergey Poznyakoff authored
    • * 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.
      Sergey Poznyakoff authored