<<< Date Index >>>     <<< Thread Index >>>

[PATCH] Re: attach multiple files from command line



Re: To Mutt Developers 2007-03-21 <20070321193650.GB2707@xxxxxxxx>
> The syntax is even "almost" backwards compatible:
> 
> mutt -a filelist -- rcptlist
> mutt -a file rcptlist

Here's a patch that implements this. (And does likewise for mutt -A
and -Q.)

# HG changeset patch
# User Christoph Berg <cb@xxxxxxxx>
# Date 1174745950 -3600
# Node ID 27272858b80f6944e42ee35c95816812d636a305
# Parent  888a57a2b5f2bac6dc4333ff653ddb284485ff7d
All non-option arguments before -- are considered attachments. Declutter mutt 
-h message.

diff -r 888a57a2b5f2 -r 27272858b80f doc/manual.xml.head
--- a/doc/manual.xml.head       Fri Mar 23 10:32:29 2007 -0700
+++ b/doc/manual.xml.head       Sat Mar 24 15:19:10 2007 +0100
@@ -5973,7 +5973,8 @@ To compose a new message
 </para>
 
 <para>
-<literal>mutt</literal> &lsqb; -n &rsqb; &lsqb; -F <emphasis>muttrc</emphasis> 
&rsqb; &lsqb; -a <emphasis>file</emphasis> &rsqb; &lsqb; -c 
<emphasis>address</emphasis> &rsqb; &lsqb; -i <emphasis>filename</emphasis> 
&rsqb; &lsqb; -s <emphasis>subject</emphasis> &rsqb; 
<emphasis>address</emphasis> &lsqb; <emphasis>address</emphasis> ... &rsqb; 
+<literal>mutt</literal> &lsqb; -n &rsqb; &lsqb; -F <emphasis>muttrc</emphasis> 
&rsqb; &lsqb; -a <emphasis>file</emphasis> &rsqb; &lsqb; -c 
<emphasis>address</emphasis> &rsqb; &lsqb; -i <emphasis>filename</emphasis> 
&rsqb; &lsqb; -s <emphasis>subject</emphasis> &rsqb;
+&lsqb; &lsqb; <emphasis>file</emphasis> ... &rsqb; -- &rsqb; 
<emphasis>address</emphasis> &lsqb; <emphasis>address</emphasis> ... &rsqb; 
 </para>
 
 <para>
@@ -5992,6 +5993,12 @@ of the file ``&tilde;/run2.dat''.
 of the file ``&tilde;/run2.dat''.
 </para>
 
+<para>
+All files passed with -a <emphasis>file</emphasis> will be attached as a MIME
+part to the message. To attach several files, use ``--'' to separate files and
+recipient addresses: <literal>mutt -a *.png -- some@xxxxxxx</literal>
+</para>
+
 </sect1>
 
 <sect1 id="commands">
diff -r 888a57a2b5f2 -r 27272858b80f doc/mutt.man
--- a/doc/mutt.man      Fri Mar 23 10:32:29 2007 -0700
+++ b/doc/mutt.man      Sat Mar 24 15:19:10 2007 +0100
@@ -36,7 +36,7 @@ mutt \- The Mutt Mail User Agent
 [-s \fIsubj\fP]
 [-b \fIaddr\fP]
 [-c \fIaddr\fP]
-[--]
+[[\fIfile\fP [...] --]
 \fIaddr\fP [...]
 .PP
 .B mutt
@@ -119,6 +119,7 @@ command which contains new mail.
 command which contains new mail.
 .IP "--"
 Treat remaining arguments as \fIaddr\fP even if they start with a dash.
+All non-option arguments before "\-\-" are considered attachments.
 .SH ENVIRONMENT
 .PP
 .IP "EDITOR"
diff -r 888a57a2b5f2 -r 27272858b80f main.c
--- a/main.c    Fri Mar 23 10:32:29 2007 -0700
+++ b/main.c    Sat Mar 24 15:19:10 2007 +0100
@@ -105,12 +105,12 @@ static void mutt_usage (void)
   puts (mutt_make_version ());
 
   puts _(
-"usage: mutt [ -nRyzZ ] [ -e <cmd> ] [ -F <file> ] [ -m <type> ] [ -f <file> 
]\n\
-       mutt [ -nR ] [ -e <cmd> ] [ -F <file> ] -Q <query> [ -Q <query> ] 
[...]\n\
-       mutt [ -nR ] [ -e <cmd> ] [ -F <file> ] -A <alias> [ -A <alias> ] 
[...]\n\
-       mutt [ -nR ] [ -e <cmd> ] [ -F <file> ] -D\n\
-       mutt [ -nx ] [ -e <cmd> ] [ -a <file> ] [ -F <file> ] [ -H <file> ] [ 
-i <file> ] [ -s <subj> ] [ -b <addr> ] [ -c <addr> ] [ -- ] <addr> [ ... ]\n\
-       mutt [ -n ] [ -e <cmd> ] [ -F <file> ] -p\n\
+"usage: mutt [<options>] [-z] [-f <file> | -yZ]\n\
+       mutt [<options>] [-x] [-aHi <file>] [-s <subj>] [-bc <addr>] [[<file> 
[...]] --] <addr> [...]\n\
+       mutt [<options>] -p\n\
+       mutt [<options>] -A <alias> [...]\n\
+       mutt [<options>] -Q <query> [...]\n\
+       mutt [<options>] -D\n\
        mutt -v[v]\n");
 
   puts _("\
@@ -143,7 +143,8 @@ options:\n\
   -z\t\texit immediately if there are no messages in the mailbox\n\
   -Z\t\topen the first folder with new message, exit immediately if none\n\
   -h\t\tthis help message");
-  puts _("  --\t\ttreat remaining arguments as addr even if starting with a 
dash");
+  puts _("  --\t\ttreat remaining arguments as addr even if starting with a 
dash\n\
+\t\tall non-option arguments before -- are attachments");
 
   exit (0);
 }
@@ -541,6 +542,7 @@ int main (int argc, char **argv)
   int dump_variables = 0;
   extern char *optarg;
   extern int optind;
+  int attach_sep = 0;
 
   /* sanity check against stupid administrators */
   
@@ -567,7 +569,14 @@ int main (int argc, char **argv)
 
   memset (Options, 0, sizeof (Options));
   memset (QuadOptions, 0, sizeof (QuadOptions));
-  
+
+  for (i = 1; i < argc; i++)
+    if (!strcmp(argv[i], "--"))
+    {
+      attach_sep = i;
+      break;
+    }
+
   while ((i = getopt (argc, argv, "A:a:b:F:f:c:Dd:e:H:s:i:hm:npQ:RvxyzZ")) != 
EOF)
     switch (i)
     {
@@ -709,7 +718,11 @@ int main (int argc, char **argv)
   crypt_init ();
 
   if (queries)
+  {
+    for (; optind < argc; optind++)
+      queries = mutt_add_list (queries, argv[optind]);
     return mutt_query_variables (queries);
+  }
   if (dump_variables)
     return mutt_dump_variables();
 
@@ -717,6 +730,8 @@ int main (int argc, char **argv)
   {
     int rv = 0;
     ADDRESS *a;
+    for (; optind < argc; optind++)
+      alias_queries = mutt_add_list (alias_queries, argv[optind]);
     for (; alias_queries; alias_queries = alias_queries->next)
     {
       if ((a = mutt_lookup_alias (alias_queries->data)))
@@ -733,7 +748,11 @@ int main (int argc, char **argv)
     }
     return rv;
   }
-  
+
+  /* all non-option arguments before -- are considered attachments */
+  for (; optind <= attach_sep; optind++)
+    attach = mutt_add_list (attach, argv[optind]);
+
   if (newMagic)
     mx_set_magic (newMagic);
 

Christoph
-- 
cb@xxxxxxxx | http://www.df7cb.de/

Attachment: signature.asc
Description: Digital signature