]> mj.ucw.cz Git - umpf.git/blobdiff - int.c
nearly finished filter
[umpf.git] / int.c
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),