#define INT_TO_STRING_LEN ((sizeof(int)*4*CHAR_BIT)/10 + 6)
-struct tmpfile {
+struct procstat {
int fd;
+ int exit;
char* name;
};
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
}
}
-static struct tmpfile*
+static struct procstat*
pipe_to(char* program, struct email* em)
{
int pd_in[2];
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;
close(pd_out[0]);
wait(&status);
-
+
+ tmp->exit = WEXITSTATUS(status);
return tmp;
bad:
close(fd);
}
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
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),