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-3.1.1-35-g57c987c


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-3.1.1-35-g57c987c
Date: Mon, 16 Jan 2017 08:36:32 +0000 (UTC)

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=57c987c11677924928716730abdd68c3d75ea044

The branch, master has been updated
       via  57c987c11677924928716730abdd68c3d75ea044 (commit)
       via  5b77e1ad4728547db2bb8a5edd62ecdc09fba80f (commit)
       via  96dd35f02fe175507d5ff91ccdcc2c59ff5a24fd (commit)
      from  888e2a9a7cbac3e3c072f04a5bd45894c9d296ad (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 57c987c11677924928716730abdd68c3d75ea044
Author: Sergey Poznyakoff <address@hidden>
Date:   Mon Jan 16 10:24:10 2017 +0200

    Improve the --skip-empty-attachment functionality
    
    This also includes small bugfixes in the MIME library code.
    
    The --skip-empty-attachment option now affects the original
    body as well.  If the option is in effect, and the body is empty,
    it will not be included to the composed message.
    
    * libmailutils/mime/mime.c (_mime_body_stream_read): Return EOF
    if there are no parts in the message.
    (mu_mime_get_num_parts): If message is not multipart, report 1 part
    without setting mime->nmtp_parts.  Setting it caused coredump in
    other MIME functions (namely, in mu_mime_add_part.
    * mail/send.c (add_body): New function.  Adds original body to
    the MIME, honoring the --skip-empty-attachment option.
    * doc/texinfo/programs.texi: Update.

commit 5b77e1ad4728547db2bb8a5edd62ecdc09fba80f
Author: Sergey Poznyakoff <address@hidden>
Date:   Mon Jan 16 07:58:02 2017 +0200

    imap4d: log client identity
    
    * imap4d/id.c (eat_args): Log the client identity using the info channel.
    * imap4d/list.c: tiny change

commit 96dd35f02fe175507d5ff91ccdcc2c59ff5a24fd
Author: Sergey Poznyakoff <address@hidden>
Date:   Mon Jan 16 07:42:26 2017 +0200

    mail: new option --skip-empty-attachments
    
    * libmailutils/cli/cli.c (mu_cli): Use "no-" prefix to indicate negation
    * mail/mail.c (skip_empty_attachments): New global.
    (mail_options): New option --skip-empty-attachments
    * mail/mail.h (skip_empty_attachments): New extern.
    * mail/send.c (atchinfo) <skip_empty>: New field.
    (send_attach_file): Initialize skip_empty
    (saveatt): Optionally skip empty attachments
    
    * NEWS: Mention the new option.
    * doc/texinfo/programs.texi: Document the new option.

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

Summary of changes:
 NEWS                      |    5 +-
 doc/texinfo/programs.texi |   46 +++++++++++++++++
 imap4d/id.c               |    7 +++
 imap4d/list.c             |    2 +-
 libmailutils/cli/cli.c    |    3 ++
 libmailutils/mime/mime.c  |   10 +++-
 mail/mail.c               |   15 +++---
 mail/mail.h               |    3 +-
 mail/send.c               |  124 ++++++++++++++++++++++++++++++++++-----------
 9 files changed, 175 insertions(+), 40 deletions(-)

diff --git a/NEWS b/NEWS
index 79d09c5..1885cf2 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-GNU mailutils NEWS -- history of user-visible changes. 2017-01-13
+GNU mailutils NEWS -- history of user-visible changes. 2017-01-16
 Copyright (C) 2002-2017 Free Software Foundation, Inc.
 See the end of file for copying conditions.
 
@@ -40,6 +40,9 @@ obvious reasons, the interactive mode is suppressed in this 
case.
 The `--attach-fd' option is useful when calling `mail' from another
 program.
 
+The new option `--skip-empty-attachments' instructs `mail' to omit
+attachments that have zero-size body.
+
 Example:
 
 Suppose that the 'mail' binary is opened at file descriptor 5 and
diff --git a/doc/texinfo/programs.texi b/doc/texinfo/programs.texi
index f7f7a3c..7b5892b 100644
--- a/doc/texinfo/programs.texi
+++ b/doc/texinfo/programs.texi
@@ -3044,6 +3044,15 @@ Cause interrupts to terminate program.
 Sets the return email address for outgoing mail.
 @xref{return-address}.
 
address@hidden --skip-empty-attachments
address@hidden --no-skip-empty-attachments
+Don't create attachments that would have zero-size body.  This
+option affects all attachments created by @option{--attach} and
address@hidden options appearing after it in the command line,
+as well as the body of the original message.
+
+To cancel its effect, use the @option{--no-skip-empty-attachments} option.
+
 @item -s @var{subj}
 @itemx address@hidden
 Send a message with a Subject of @var{subj}.  Valid only in sending
@@ -3531,6 +3540,43 @@ Attachments created with this option have neither 
filename nor
 description set, so normally the use of @option{--content-name} and/or
 @option{--content-filename} is advised.
 
+The option @option{--skip-empty-attachments} instructs @command{mail}
+to skip creating attachments that would have zero-size body.  This
+option affects all attachments created by @option{--attach} and
address@hidden options appearing after it in the command line.
+It also affects the handling of the original message body.  To cancel
+its effect, use the @option{--no-skip-empty-attachments} option. 
+
+Here are some examples illustrating how it works.
+
+First, consider the following command line
+
address@hidden
+$ mail --attach=archive.tar </dev/null
address@hidden example
+
+Assume that @file{archive.tar} is not empty.
+
+This will create a MIME message of two parts: the first part having
address@hidden/html} type and empty body, and the second part of type
address@hidden/octet-stream}, with the content copied from the file
address@hidden
+
+Now, if you do:
+
address@hidden
+$ mail --attach=archive.tar --skip-empty-attachments </dev/null
address@hidden example
+
address@hidden
+then the created MIME message will contain only one part: that
+containing @file{archive.tar}.
+
+If the file @file{archive.tar} has zero length, the resulting archive
+will still contain the @samp{application/octet-stream} part of zero
+length.  However, if you place the @option{--skip-empty-attachments}
+option before @option{--attach}, then the produced message will be empty.
+
 The following Perl program serves as an example of using
 @command{mail} from a script to construct a MIME message on the fly.
 It scans all mounted file systems for executable files that have
diff --git a/imap4d/id.c b/imap4d/id.c
index 65d5337..13a10f1 100644
--- a/imap4d/id.c
+++ b/imap4d/id.c
@@ -39,16 +39,23 @@ eat_args (imap4d_tokbuf_t tok)
   else if (p[0] != '(')
     return RESP_BAD;
 
+  mu_diag_init ();  
+  mu_stream_printf (mu_strerr, "\033s<%d>%s", MU_DIAG_INFO,
+                   _("client identification: "));
+
   /* Collect arguments */
   while ((p = imap4d_tokbuf_getarg (tok, n++)))
     {
       if (p[0] == ')')
        {
+         mu_stream_printf (mu_strerr, "\n");
          if (imap4d_tokbuf_getarg (tok, n))
            return RESP_BAD;
          return RESP_OK;
        }
+      mu_stream_printf (mu_strerr, "%s%c", p, (n % 2) ? ' ' : '=');
     }
+  mu_stream_printf (mu_strerr, "\n");
   return RESP_BAD;
 }
 
diff --git a/imap4d/list.c b/imap4d/list.c
index 4a25905..decaaba 100644
--- a/imap4d/list.c
+++ b/imap4d/list.c
@@ -210,7 +210,7 @@ imap4d_list (struct imap4d_session *session,
       
       if (pfx->ns == NS_OTHER
          && strcmp (ref, pfx->prefix) == 0
-         && *mu_str_skip_cset_comp (wcard, "*%"))
+         && strpbrk (wcard, "*%"))
        {
          /* [A] server MAY return NO to such a LIST command, requiring that a
             user name be included with the Other Users' Namespace prefix
diff --git a/libmailutils/cli/cli.c b/libmailutils/cli/cli.c
index 33bc417..41b289b 100644
--- a/libmailutils/cli/cli.c
+++ b/libmailutils/cli/cli.c
@@ -710,6 +710,9 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, 
char **capa,
   pohint.po_version_hook = mu_version_hook;
   pohint.po_flags |= MU_PARSEOPT_VERSION_HOOK;
 
+  pohint.po_negation = "no-";
+  pohint.po_flags |= MU_PARSEOPT_NEGATION;
+  
   cfhint.site_file = mu_site_config_file ();
   cfhint.flags = MU_CFHINT_SITE_FILE | MU_CFHINT_PER_USER_FILE;
   
diff --git a/libmailutils/mime/mime.c b/libmailutils/mime/mime.c
index d34415d..f69cbc8 100644
--- a/libmailutils/mime/mime.c
+++ b/libmailutils/mime/mime.c
@@ -662,7 +662,10 @@ _mime_body_stream_read (mu_stream_t stream, char *buf, 
size_t buflen, size_t *nb
   size_t             total = 0;
   
   if (mime->nmtp_parts == 0)
-    return EINVAL;
+    {
+      *nbytes = 0;
+      return 0;
+    }
   
   if ((ret = _mime_set_content_type (mime)) == 0)
     {
@@ -1055,7 +1058,10 @@ mu_mime_get_num_parts (mu_mime_t mime, size_t 
*nmtp_parts)
            return (ret);
        }
       else
-       mime->nmtp_parts = 1;
+       {
+         *nmtp_parts = 1;
+         return 0;
+       }
     }
   *nmtp_parts = mime->nmtp_parts;
   return (ret);
diff --git a/mail/mail.c b/mail/mail.c
index ca3f08e..3647586 100644
--- a/mail/mail.c
+++ b/mail/mail.c
@@ -36,10 +36,11 @@ int hint;
 char *file;
 char *user;
 
+int skip_empty_attachments;
 char *default_encoding;
 char *default_content_type;
-char *content_name;
-char *content_filename;
+static char *content_name;
+static char *content_filename;
 
 static void
 cli_f_option (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
@@ -108,14 +109,12 @@ cli_command_option (struct mu_parseopt *po, struct 
mu_option *opt,
       break;
 
     case 0:
-      mu_parseopt_error (po,
-                        _("--%s: option should have been recognized"),
+      mu_parseopt_error (po, _("--%s: option should have been recognized"),
                         opt->opt_long);
       exit (po->po_exit_error);
       
     default:
-      mu_parseopt_error (po,
-                        _("-%c: option should have been recognized"),
+      mu_parseopt_error (po, _("-%c: option should have been recognized"),
                         opt->opt_short);
       exit (po->po_exit_error);
     }      
@@ -240,6 +239,10 @@ static struct mu_option mail_options[] = {
   { "append",   'a', N_("HEADER: VALUE"), MU_OPTION_DEFAULT,
     N_("append given header to the message being sent"),
     mu_c_string, NULL, cli_append },
+
+  { "skip-empty-attachments", 0, NULL, MU_OPTION_DEFAULT,
+    N_("skip attachments with empty body"),
+    mu_c_bool, &skip_empty_attachments },
     
   { "exec" ,    'E', N_("COMMAND"), MU_OPTION_DEFAULT,
     N_("execute COMMAND"),
diff --git a/mail/mail.h b/mail/mail.h
index 35a81d3..690409e 100644
--- a/mail/mail.h
+++ b/mail/mail.h
@@ -173,7 +173,8 @@ extern int interactive;
 extern const char *program_version;
 extern char *default_encoding;
 extern char *default_content_type;
-
+extern int skip_empty_attachments;
+  
 /* Functions */
 extern int mail_alias (int argc, char **argv);
 extern int mail_alt (int argc, char **argv);   /* command alternates */
diff --git a/mail/send.c b/mail/send.c
index 8456ad8..c369626 100644
--- a/mail/send.c
+++ b/mail/send.c
@@ -140,6 +140,7 @@ struct atchinfo
   char *name;
   char *filename;
   mu_stream_t source;
+  int skip_empty;
 };
 
 static mu_list_t attlist;
@@ -256,6 +257,7 @@ send_attach_file (int fd,
   aptr->name = content_name ? mu_strdup (content_name) : NULL;
   aptr->filename = content_filename ? mu_strdup (content_filename) : NULL;
   aptr->source = stream;
+  aptr->skip_empty = skip_empty_attachments;
   rc = mu_list_append (attlist, aptr);
   if (rc)
     {
@@ -363,11 +365,31 @@ saveatt (void *item, void *data)
   rc = mu_attachment_copy_from_stream (part, aptr->source, aptr->encoding);
   if (rc)
     {
-      mu_error (_("cannot attach %s: %s"), aptr->filename,
-               mu_strerror (rc));
+      mu_error (_("cannot attach %s: %s"), aptr->id, mu_strerror (rc));
       return 1;
     }
 
+  if (aptr->skip_empty)
+    {
+      mu_body_t body;
+      size_t size;
+      
+      rc = mu_message_get_body (part, &body);
+      if (rc)
+       {
+         mu_diag_funcall (MU_DIAG_ERROR, "mu_message_get_body", aptr->id, rc);
+         return 1;
+       }
+      rc = mu_body_size (body, &size);
+      if (rc)
+       {
+         mu_diag_funcall (MU_DIAG_ERROR, "mu_body_size", aptr->id, rc);
+         return 1;
+       }
+      if (size == 0)
+       return 0;
+    }
+      
   mu_mime_get_num_parts        (mime, &nparts);
   mu_message_get_header (part, &hdr);
   mu_rfc2822_msg_id (nparts, &p);
@@ -386,50 +408,52 @@ saveatt (void *item, void *data)
 }
 
 static int
-add_attachments (mu_message_t *pmsg, mu_mime_t *pmime)
+add_body (mu_message_t inmsg, mu_iterator_t itr, mu_mime_t mime)
 {
-  mu_message_t inmsg, outmsg, part;
   mu_body_t body;
-  mu_header_t inhdr, outhdr;
-  mu_iterator_t itr;
-  mu_mime_t mime;
+  mu_message_t part;
   mu_stream_t str, output;
-  int rc;
+  mu_header_t outhdr;
   char *p;
+  int rc;
   
-  if (mu_list_is_empty (attlist))
+  mu_message_get_body (inmsg, &body);
+  if (skip_empty_attachments)
     {
-      *pmime = NULL;
-      return 0;
+      size_t size;
+      rc = mu_body_size (body, &size);
+      if (rc)
+       {
+         mu_diag_funcall (MU_DIAG_ERROR, "mu_body_size", NULL, rc);
+         return -1;
+       }
+      if (size == 0)
+       return 0;
     }
+    
+  /* Add original message as the first part */
   
-  inmsg = *pmsg;
-
-  /* Create a mime object */
-  rc = mu_mime_create (&mime, NULL, 0);
-  if (rc)
+  /* 1. Create the part and obtain a reference to its stream */
+  if ((rc = mu_message_create (&part, NULL)) == 0)
     {
-      mu_diag_funcall (MU_DIAG_ERROR, "mu_mime_create", NULL, rc);
-      return 1;
+      mu_body_t pbody;
+      
+      mu_message_get_body (part, &pbody);
+      mu_body_get_streamref (pbody, &output);
     }
-
-  /* Add original message as its first part */
-  /* 1. Create the part and obtain a reference to its stream */
-  mu_message_create (&part, NULL);
-  mu_message_get_body (part, &body);
-  mu_body_get_streamref (body, &output);
-
+  else
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_message_create", NULL, rc);
+      return -1;
+    }
+  
   /* 2. Get original body stream and copy it out to the part's body */
-  mu_message_get_body (inmsg, &body);
   mu_body_get_streamref (body, &str);
   mu_stream_copy (output, str, 0, NULL);
 
   mu_stream_close (output);
   mu_stream_destroy (&output);
 
-  mu_message_get_header (inmsg, &inhdr);
-  mu_header_get_iterator (inhdr, &itr);
-
   /* 3. Copy "Content-*" headers from the original message */
   mu_message_get_header (part, &outhdr);
   for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
@@ -455,11 +479,50 @@ add_attachments (mu_message_t *pmsg, mu_mime_t *pmime)
   mu_mime_add_part (mime, part);
   mu_message_unref (part);
 
+  return 0;
+}  
+
+static int
+add_attachments (mu_message_t *pmsg, mu_mime_t *pmime)
+{
+  mu_message_t inmsg, outmsg;
+  mu_header_t inhdr, outhdr;
+  mu_iterator_t itr;
+  mu_mime_t mime;  
+  int rc;
+  
+  if (mu_list_is_empty (attlist))
+    {
+      *pmime = NULL;
+      return 0;
+    }
+  
+  inmsg = *pmsg;
+
+  /* Create a mime object */
+  rc = mu_mime_create (&mime, NULL, 0);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_mime_create", NULL, rc);
+      return 1;
+    }
+
+  mu_message_get_header (inmsg, &inhdr);
+  mu_header_get_iterator (inhdr, &itr);
+
+  if (add_body (inmsg, itr, mime))
+    {
+      mu_mime_destroy (&mime);
+      mu_iterator_destroy (&itr);
+      return 1;
+    }
+
   /* Add the respective attachments */
   rc = mu_list_foreach (attlist, saveatt, mime);
   if (rc)
     {
       mu_mime_destroy (&mime);
+      mu_iterator_destroy (&itr);
       return 1;
     }
 
@@ -470,6 +533,7 @@ add_attachments (mu_message_t *pmsg, mu_mime_t *pmime)
     {
       mu_diag_funcall (MU_DIAG_ERROR, "mu_mime_get_message", NULL, rc);
       mu_mime_destroy (&mime);
+      mu_iterator_destroy (&itr);
       return 1;
     }
 
@@ -493,6 +557,7 @@ add_attachments (mu_message_t *pmsg, mu_mime_t *pmime)
 
   mu_message_unref (outmsg);
   mu_message_unref (inmsg);
+
   *pmsg = outmsg;
   *pmime = mime;
   return 0;
@@ -1171,6 +1236,7 @@ mail_send0 (compose_env_t *env, int save_to)
          status = mu_message_create (&msg, NULL);
          if (status)
            break;
+         
          /* Fill the body. */
          mu_stream_seek (env->compstr, 0, MU_SEEK_SET, NULL);
          status = fill_body (msg, env->compstr);


hooks/post-receive
-- 
GNU Mailutils



reply via email to

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