When adding To: header, add only a single header. If there are multiple
addresses, make it multiline.

Signed-off-by: Aaro Koskinen <[email protected]>
---
 mailutils/sendmail.c |   22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/mailutils/sendmail.c b/mailutils/sendmail.c
index 323ad0a..320a259 100644
--- a/mailutils/sendmail.c
+++ b/mailutils/sendmail.c
@@ -172,7 +172,7 @@ static void rcptto_list(const char *_str)
 }
 
 int sendmail_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int sendmail_main(int argc UNUSED_PARAM, char **argv)
+int sendmail_main(int argc, char **argv)
 {
        char *opt_connect = opt_connect;
        char *opt_from;
@@ -218,7 +218,7 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
        // it is still under development.
        opts = getopt32(argv, "tf:o:iw:H:S:a::v", &opt_from, NULL,
                        &timeout, &opt_connect, &opt_connect, &list, &verbose);
-       //argc -= optind;
+       argc -= optind;
        argv += optind;
 
        // process -a[upm]<token> options
@@ -389,15 +389,29 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
                        // so stop "analyze headers" mode
  reenter:
                        // put recipients specified on cmdline
+                       check_hdr = 1;
                        while (*argv) {
                                char *t = sane_address(*argv);
                                rcptto(t);
                                //if (MAX_HEADERS && ++nheaders >= MAX_HEADERS)
                                //      goto bail;
-                               if (!has_to)
+                               if (!has_to) {
+                                       char const *hdr;
+
+                                       if (check_hdr && argc > 1)
+                                               hdr = "To: %s,";
+                                       else if (check_hdr)
+                                               hdr = "To: %s";
+                                       else if (argc > 1)
+                                               hdr = "To: %s," + 3;
+                                       else
+                                               hdr = "To: %s" + 3;
                                        llist_add_to_end(&list,
-                                                       xasprintf("To: %s", t));
+                                                        xasprintf(hdr, t));
+                                       check_hdr = 0;
+                               }
                                argv++;
+                               argc--;
                        }
                        // enter "put message" mode
                        // N.B. DATA fails iff no recipients were accepted (or 
even provided)
-- 
1.7.10.4

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to