This quick patch should fix the problem of ssmtp eating lines when there are no headers supplied on stdin, as Martin Schulze remarked before.

Ssmtp expects to receive 'headers - empty line - body', and when only the body is included, it tries to put all lines in the header and creatively eats some at the end.

On its way, MTAs usually add real headers to the message, making the body appear again but incomplete.

What this patch does, is checking the first line for a colon and jumping out of the headers routine if the message doesn't appear to have a header.

Can somebody verify if this fixes at least that problem?


Regards,

  Wouter
--- ssmtp-2.61/ssmtp.c  2005-09-04 18:05:20.000000000 +0200
+++ ssmtp-2.61-wvh/ssmtp.c      2005-09-04 19:19:53.000000000 +0200
@@ -727,11 +727,12 @@
 /*
 header_parse() -- Break headers into seperate entries
 */
-void header_parse(FILE *stream)
+char *header_parse(FILE *stream)
 {
        size_t size = BUF_SZ, len = 0;
        char *p = (char *)NULL, *q;
        bool_t in_header = True;
+       bool_t on_first_line = True;
        char l = (char)NULL;
        int c;
 
@@ -749,7 +750,15 @@
                }
                len++;
 
+               /* -wvh- sniff out the first line to see if it really is a 
header */
+               if (on_first_line && c == '\n' && strchr(p, ':') == (char 
*)NULL) {
+                       in_header = False;
+               }
+
                if(l == '\n') {
+
+                       on_first_line = False;
+
                        switch(c) {
                                case ' ':
                                case '\t':
@@ -781,7 +790,14 @@
 
                l = c;
        }
+
+       if (!in_header && on_first_line) {
+               return (p);
+       }
+
        (void)free(p);
+
+       return (char *)NULL;
 }
 
 /*
@@ -1319,6 +1335,7 @@
        struct passwd *pw;
        int i, sock;
        uid_t uid;
+       char *head_body = (char *)NULL;
 
        outbytes = 0;
 
@@ -1347,7 +1364,7 @@
        ht = &headers;
        rt = &rcpt_list;
 
-       header_parse(stdin);
+       head_body = header_parse(stdin);
 
 #if 1
        /* With FromLineOverride=YES set, try to recover sane MAIL FROM address 
*/
@@ -1528,6 +1545,11 @@
        /* End of headers, start body */
        outbytes += smtp_write(sock, "");
 
+       if ((char *)head_body != (char *)NULL) {
+               standardise(head_body);
+               outbytes += smtp_write(sock, "%s", head_body);
+        }
+
        /*prevent blocking on pipes, we really shouldnt be using
          stdio functions like fgets in the first place */
        fcntl(STDIN_FILENO,F_SETFL,O_NONBLOCK);

Reply via email to