]> mj.ucw.cz Git - umpf.git/commitdiff
add From line
authorAnicka Bernathova <anicka@anicka.net>
Tue, 21 Jul 2009 16:26:34 +0000 (18:26 +0200)
committerAnicka Bernathova <anicka@anicka.net>
Tue, 21 Jul 2009 16:26:34 +0000 (18:26 +0200)
ham.c

diff --git a/ham.c b/ham.c
index 3e6dade23fc652ace1c8ff1b9a8fa004ddf193a0..e54ec5e3b099d191a5bd30464f16f6b5ed03c2a5 100644 (file)
--- a/ham.c
+++ b/ham.c
@@ -2,6 +2,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sysexits.h>
+#include <time.h>
 
 #include <unistd.h>
 
@@ -27,7 +28,10 @@ new_header(char* buf, struct list* h)
                new->value = xstrdup("");
        else {
                *p = 0;
-               new->value = xstrdup(p+1);
+               if (*(p + 1) == ' ')
+                       new->value = xstrdup(p + 2);
+               else
+                       new->value = xstrdup(p + 1);
                p = strrchr(new->value, '\n');
                if (p && !*(p+1))
                        *p = 0;
@@ -261,18 +265,19 @@ read_email(struct email* em)
                pos = 0;
 
                LIST_FOREACH(ph, em->headers){
-                       int needed = strlen(ph->name) + strlen(ph->value) + 3;
+                       int needed = strlen(ph->name) + strlen(ph->value) + 4;
                        if (curbufsize < pos + needed)
                                buf = xrealloc(buf, curbufsize*=2);
                        strcpy(buf + pos, ph->name);
                        pos += strlen(ph->name);
                        buf[pos++] = ':';
+                       buf[pos++] = ' ';
                        strcpy(buf + pos, ph->value);
                        pos += strlen(ph->value);
                        buf[pos++] = '\n';
        
                }
-               buf[pos] = '\n';
+               buf[pos++] = '\n';
                headers_sent = 1;
                chars_written = pos;
                return buf;
@@ -330,13 +335,43 @@ copy_email(int fd, struct email* email)
        mbox_write_err = 0;
        mbox_write_pos = 0;
 
-       /* headers */
+       /* From line */
        struct hlist* ph;
+       int i, len;
+       char* fromline;
+       char* from = NULL;
+       time_t t;
+       time(&t);
+       char* date = ctime(&t);
+       int datelen = strlen(date);
+       
+       LIST_FOREACH(ph, email->headers) {
+               if (!strcasecmp(ph->name, "From")) {
+                       from = ph->value;
+                       break;
+               }
+       }
+       len = 5 + datelen + 1; 
+       if (from)
+               len += strlen(from);
+       fromline = xmalloc(len);
+       if (from)
+               sprintf(fromline, "From %s %s", from, date);
+       else
+               sprintf(fromline, "From %s", date);
+
+       len = strlen(fromline);
+       for (i = 0; i < len; i++)
+               write_char_to_mailbox(fromline[i], fd);
+
+       /* headers */
        char* pc;
        LIST_FOREACH(ph, email->headers){
                for (pc = ph->name; *pc; pc++)
                        write_char_to_mailbox(*pc, fd);
                write_char_to_mailbox(':', fd); 
+               write_char_to_mailbox(' ', fd); 
                for (pc = ph->value; *pc; pc++)
                        write_char_to_mailbox(*pc, fd); 
                        write_char_to_mailbox('\n', fd);