]> mj.ucw.cz Git - umpf.git/commitdiff
nearly finished filter
authorAnicka Bernathova <anicka@anicka.net>
Tue, 21 Jul 2009 12:42:15 +0000 (14:42 +0200)
committerAnicka Bernathova <anicka@anicka.net>
Tue, 21 Jul 2009 12:42:15 +0000 (14:42 +0200)
ham.c
int.c
umpf.h

diff --git a/ham.c b/ham.c
index 363a671e47747d0cb4310e0752a46b372f62c269..0424d05a7b909d17fd606ef0ce02ce76828de27d 100644 (file)
--- a/ham.c
+++ b/ham.c
@@ -51,11 +51,13 @@ give_me_char(int fd)
                gmc_read = read(fd, gmc_buf, BUFSIZE);
                gmc_init = 1;
                gmc_unget = EOF;
+               curr_email_len = 0;
        }
 
        if (gmc_unget != EOF) {
                int a = gmc_unget;
                gmc_unget = EOF;
+               curr_email_len++;
                return a;
        }
 
@@ -65,6 +67,7 @@ give_me_char(int fd)
        }
 
        if (gmc_pos < gmc_read) {
+               curr_email_len++;
                return gmc_buf[gmc_pos++];
        } else {
                gmc_pos = 0;
@@ -74,6 +77,7 @@ give_me_char(int fd)
                        return EOF;
                }
                else {
+                       curr_email_len++;
                        return gmc_buf[gmc_pos++];
                }
        }
@@ -83,6 +87,7 @@ static void
 unget_me(int c)
 {
        gmc_unget = c;
+       curr_email_len--;
 }
 
 struct list*
diff --git a/int.c b/int.c
index 265003ee82568b9efd58683089aae82a9793b15e..b0cd3967412c153e43c6ec1153b01b48fc0d83be 100644 (file)
--- a/int.c
+++ b/int.c
@@ -19,8 +19,9 @@
 
 #define INT_TO_STRING_LEN ((sizeof(int)*4*CHAR_BIT)/10 + 6)
 
-struct tmpfile {
+struct procstat {
        int fd;
+       int exit;
        char* name;
 };
 
@@ -279,13 +280,35 @@ prepare_email(struct list* hash)
        return em;
 }
 
+static void
+destroy_headers(struct list* h)
+{
+       struct hlist* p;
+
+       while ((p = list_del_last(h))) {
+               free(p->name);
+               free(p->value);
+               free(p);
+       }
+       free(h);
+}
+
+static void
+destroy_body(struct email* b)
+{
+       if (b->tmpfile) {
+               unlink(b->tmpfile);
+               free(b->tmpfile);
+       }
+       if (b->body)
+               free(b->body);
+}
+
 static void
 destroy_email(struct email em)
 {
-       if (em.body)
-               free_string(em.body);
-       if(em.tmpfile)
-               free_string(em.tmpfile);
+       destroy_headers(em.headers);
+       destroy_body(&em);
 }
 
 static void
@@ -439,7 +462,7 @@ end:
        }
 }
 
-static struct tmpfile
+static struct procstat
 pipe_to(char* program, struct email* em)
 {
        int pd_in[2];
@@ -452,7 +475,7 @@ pipe_to(char* program, struct email* em)
        int nfds = 2;
        int data_pos = 0;
        int fd = mkstemp(name);
-       struct tmpfile* tmp = xmalloc(sizeof(struct tmpfile));
+       struct procstat* tmp = xmalloc(sizeof(struct procstat));
        char* e = NULL;
        if (fd < 0)
                return NULL;
@@ -533,7 +556,8 @@ pipe_to(char* program, struct email* em)
  
        close(pd_out[0]);
        wait(&status);
-
+       
+       tmp->exit = WEXITSTATUS(status);
        return tmp;
 bad:
        close(fd);
@@ -542,44 +566,30 @@ bad:
 }
 
 static void
-do_filter(char* program, int copy, struct list* hash)
+do_filter(char* program, struct list* hash)
 {
        struct email em = prepare_email(hash);
-       struct tmpfile* f;
+       struct procstat* f;
        int res = 0;
-       off_t pos;
 
        f = pipe_to(program, &em);
        if (!f) {
                res++;
                goto end;
        }
-       pos = lseek(f->fd, 0, SEEK_END);
        lseek(f->fd, 0, SEEK_SET);
 
-/*
-       FIXME: do some real work ;)
-
-       printf("Tmp filename %s, file is long %d\n", f->name, (int) pos);
-       
-       int i;
-       char c; 
-       for (i = 0; i < pos; i++) {
-               read(f->fd, &c, 1);
-               write(1, &c, 1);
-       }
+       destroy_headers(current_headers);
+       destroy_body(current_body);
+       current_headers = make_hlist(f->fd);
+       current_body = get_body(f->fd); 
+//     set_cur_mail_length_var(current_email_len);
+//     set_exit_code_var(f->exit);
 
-*/
        unlink(f->name);
        free(f);
 end:
        destroy_email(em);
-       if (!copy) {
-               if (!res)
-                       bye(EX_TEMPFAIL, "%m");
-               else
-                       bye(0, NULL);
-       }
 }
 
 void
@@ -639,8 +649,7 @@ interp(struct list* ins, struct list* hash)
                case OPC_PIPE:
                        break;
                case OPC_FILTER:
-                       do_filter(get_var(p->u.arrow.what), 
-                               p->u.arrow.copy, hash);
+                       do_filter(get_var(p->u.arrow.what), hash);
                        break;
                case OPC_MAIL:
                        send_mail(get_var(p->u.arrow.what), 
diff --git a/umpf.h b/umpf.h
index 32cd804e174d93edaa74863b07d8705e8d48e881..7c3bd8030df1bccd919207bc0a0f1d0ac1a06516 100644 (file)
--- a/umpf.h
+++ b/umpf.h
@@ -210,12 +210,13 @@ void __attribute__ ((noreturn)) bye(int code, char* msg, ...);
 /* ham.c */
 char* default_mailbox;
 int chars_written;
+int curr_email_len;
 
 struct list* current_headers;
 struct email* current_body;
-struct list* make_hlist(void);
+struct list* make_hlist(int fd);
 void print_headers(struct list* l);
-struct email* get_body(void);
+struct email* get_body(int fd);
 int deliver_local_email(char* folder, struct email* email);
 int write_email_to_fd(int fd, struct email* email);
 char* read_email(struct email* em);