summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS5
-rw-r--r--doc/texinfo/programs.texi13
-rw-r--r--libmailutils/cli/cli.c3
-rw-r--r--mail/mail.c15
-rw-r--r--mail/mail.h3
-rw-r--r--mail/send.c26
6 files changed, 55 insertions, 10 deletions
diff --git a/NEWS b/NEWS
index 79d09c5fe..1885cf269 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 f7f7a3c7f..edff7ff3a 100644
--- a/doc/texinfo/programs.texi
+++ b/doc/texinfo/programs.texi
@@ -3044,6 +3044,13 @@ Cause interrupts to terminate program.
Sets the return email address for outgoing mail.
@xref{return-address}.
+@item --skip-empty-attachments
+@itemx --no-skip-empty-attachments
+Don't create attachments that would have zero-size body. This
+option affects all attachments created by @option{--attach} and
+@option{--attach-fd} options appearing after it in the command line.
+To cancel its effect, use the @option{--no-skip-empty-attachments} option.
+
@item -s @var{subj}
@itemx --subject=@var{subj}
Send a message with a Subject of @var{subj}. Valid only in sending
@@ -3531,6 +3538,12 @@ 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
+@option{--attach-fd} options appearing after it in the command line.
+To cancel its effect, use the @option{--no-skip-empty-attachments} option.
+
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/libmailutils/cli/cli.c b/libmailutils/cli/cli.c
index 33bc417d3..41b289bdd 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/mail/mail.c b/mail/mail.c
index ca3f08e19..3647586bb 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 35a81d3a6..690409e52 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 8456ad854..51c4fe0f8 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);

Return to:

Send suggestions and report system problems to the System administrator.