]> mj.ucw.cz Git - umpf.git/commitdiff
body can have 0 now
authorAnicka Bernathova <anicka@anicka.net>
Sat, 30 Aug 2008 16:20:56 +0000 (18:20 +0200)
committerAnicka Bernathova <anicka@anicka.net>
Sat, 30 Aug 2008 16:20:56 +0000 (18:20 +0200)
brum.h
ham.c
int.c

diff --git a/brum.h b/brum.h
index c3931b2319a064a1ce4ebcafc06480362a0d72b9..c72f7aca947c5173acc114e95b45798cd3656de0 100644 (file)
--- a/brum.h
+++ b/brum.h
@@ -94,6 +94,7 @@ struct hlist {
 struct email {
        struct list* headers;
        char* body;
+       int body_len;
 };
 
 struct action {
@@ -114,11 +115,11 @@ void save_current_headers(struct list* hash);
 
 /* ham.c */
 struct list* current_headers;
-char* current_body;
+struct email* current_body;
 struct list* make_hlist(void);
 void print_headers(struct list* l);
 void do_action(struct action* a);
-char* get_body(void);
+struct email* get_body(void);
 
 /* lock.c */
 void save_gids(void);
diff --git a/ham.c b/ham.c
index ddc8e3ce5680ec660c287c2bdc4427de45bef77e..03102e720a125a282166fae869be91da6ab59e19 100644 (file)
--- a/ham.c
+++ b/ham.c
@@ -72,10 +72,11 @@ make_hlist(void)
        return l;
 }
 
-char*
+struct email*
 get_body(void)
 {
        char* buf;
+       struct email* b;
        int c;
        int i = 0;
        int curbufsize = BUFSIZE;
@@ -88,9 +89,11 @@ get_body(void)
                        buf = xrealloc(buf, curbufsize *= 2);
        }
 
-       buf[i] = 0;
+       b = xmalloc(sizeof(struct email));
+       b->body = buf;
+       b->body_len = i;
 
-       return buf
+       return b; 
 }
 
 void
@@ -103,22 +106,23 @@ print_headers(struct list* l)
 }
 
 static void
-write_char_to_mailbox(char c, int fd)
+flush_mbox_buffer(int fd)
 {
+       if (mbox_write_err || !mbox_write_pos)
+               return;
+
        int res;
+       res = write(fd, mbox_write_buf, mbox_write_pos);
+       if (res < 0)
+               mbox_write_err++;
+       mbox_write_pos = 0;
+}
 
-       if (mbox_write_err)
-               return;
+static void
+write_char_to_mailbox(char c, int fd)
+{
+       int res;
 
-       if (!c){
-               if (!mbox_write_pos)
-                       return;
-               res = write(fd, mbox_write_buf, mbox_write_pos);
-               if (res < 0)
-                       mbox_write_err++;
-               mbox_write_pos = 0;
-               return;
-       }
        if (mbox_write_pos >= BUFSIZE){
                res = write(fd, mbox_write_buf, BUFSIZE);
                if (res < 0)
@@ -137,7 +141,7 @@ copy_email(int fd, struct email* email)
        off_t mb_end;
 
        mb_end = lseek(fd, 0, SEEK_END);
-       if (mb_end < 1)
+       if (mb_end < 0)
                return -1;
 
        /* init globals */
@@ -164,12 +168,14 @@ copy_email(int fd, struct email* email)
                        write_char_to_mailbox(*pc, fd); 
        }       
 
-       /* flush the buffer */
-       write_char_to_mailbox(0, fd);
+       flush_mbox_buffer(fd);
 
        /* errors? */
-       if (mbox_write_err)
-               return -1;      
+       if (mbox_write_err){
+               /* try to truncate to the original length */
+               ftruncate(fd, mb_end);  
+               return -1;
+       }       
 
        return 0; 
 }
diff --git a/int.c b/int.c
index 13a307703a583caaf35704f9b578c52abfa062cf..80cf6639f2ca231a186e46e2cbec3c29b08213d4 100644 (file)
--- a/int.c
+++ b/int.c
@@ -292,7 +292,9 @@ new_action(char* l, char* r, char* s, struct list* hash)
 
        modify_headers(current_headers, hash);
        a->e.headers = copy_headers(current_headers);
-       a->e.body = xstrdup(current_body);
+       a->e.body_len = current_body->body_len; 
+       a->e.body = xmalloc(a->e.body_len);
+       memcpy(a->e.body, current_body->body, a->e.body_len);
        a->l = l;
        a->r = r;
        a->s = s;