From fe58a4c2ebb3d4ff4649e58f67324214d7f6f863 Mon Sep 17 00:00:00 2001 From: Anicka Bernathova Date: Thu, 16 Jul 2009 22:21:51 +0200 Subject: [PATCH] really do local delivery --- code.c | 2 ++ ham.c | 16 ++++-------- int.c | 82 +++++++--------------------------------------------------- lock.c | 5 ++-- umpf.c | 5 ++-- umpf.h | 2 ++ 6 files changed, 25 insertions(+), 87 deletions(-) diff --git a/code.c b/code.c index bf3906f..4a84d18 100644 --- a/code.c +++ b/code.c @@ -313,6 +313,8 @@ do_arrow(struct tree* t, struct list* where) static void reset_temp_var_count(void) { + if (current_varcode > max_varcode) + max_varcode = current_varcode; current_varcode = temp_varcode_start; } diff --git a/ham.c b/ham.c index f0b7dbb..f06fdf3 100644 --- a/ham.c +++ b/ham.c @@ -26,6 +26,9 @@ new_header(char* buf, struct list* h) else { *p = 0; new->value = xstrdup(p+1); + p = strrchr(new->value, '\n'); + if (p && !*(p+1)) + *p = 0; } new->name = xstrdup(buf); @@ -100,7 +103,7 @@ print_headers(struct list* l) struct hlist* p; LIST_FOREACH(p,l) - printf("%s:%s",p->name,p->value); + printf("%s:%s\n",p->name,p->value); } static void @@ -185,7 +188,7 @@ copy_email(int fd, struct email* email) return 0; } -static int +int deliver_local_email(char* folder, struct email* email) { int res = -1; @@ -217,12 +220,3 @@ deliver_local_email(char* folder, struct email* email) return res; } - -void -do_action(struct action* a) -{ - /* -> address */ - if (! a->r && !a->l ){ - deliver_local_email(a->s, &a->e); - } -} diff --git a/int.c b/int.c index 436181b..4133f34 100644 --- a/int.c +++ b/int.c @@ -253,80 +253,16 @@ eval_cond(int var) return !!v; } -static int -last_rescue(void) -{ - //FIXME: add some magic - return 1; -} - static void -deliver(char* where, int copy, int last_try, struct list* hash) +deliver(char* where, int copy, struct list* hash) { - int ok = 0; - int fd, len, written; - off_t off; + int res = 0; struct email em = prepare_email(hash); - struct hlist* p; - - fd = open_mailbox(where, last_try); - if (fd < 0) - goto end; - off = lseek(fd, 0, SEEK_END); - if (off < 0) - goto end; - LIST_FOREACH(p, em.headers) { - len = strlen(p->name); - written = write(fd, p->name, len); - if (written < len) { - ftruncate(fd, off); - goto end; - } - - written = write(fd, ": ", 2); - if (written < 2) { - ftruncate(fd, off); - goto end; - } - - len = strlen(p->value); - written = write(fd, p->value, len); - if (written < len) { - ftruncate(fd, off); - goto end; - } - - written = write(fd, "\n", 1); - if (written < len) { - ftruncate(fd, off); - goto end; - } - } - written = write(fd, "\n", 1); - if (written < 1) { - ftruncate(fd, off); - goto end; - } - - written = write(fd, em.body, em.body_len); - if (written < em.body_len) { - ftruncate(fd, off); - goto end; - } - - ok = 1; - close_mailbox(fd, where, last_try); - -end: - if (ok) { - if (!copy || last_try) - exit(0); - } else { - if (!copy || last_try) - ok = last_rescue(); - exit(ok); - } + res = deliver_local_email(where, &em); + + if (!copy) + exit(-res); } void @@ -335,6 +271,8 @@ interp(struct list* ins, struct list* hash) struct code* p; char* result; int v; + + var_tab = xmalloc(max_varcode * sizeof(char*)); LIST_FOREACH(p, ins) { switch (p->opcode) { @@ -389,7 +327,7 @@ interp(struct list* ins, struct list* hash) break; case OPC_DELIVER: deliver(get_var(p->u.arrow.what), - p->u.arrow.copy, 0, hash); + p->u.arrow.copy, hash); break; case OPC_CALL_EXT: break; @@ -397,7 +335,7 @@ interp(struct list* ins, struct list* hash) exit(0); break; }} - deliver(default_mailbox, 0, 1, hash); + deliver(default_mailbox, 0, hash); } void diff --git a/lock.c b/lock.c index 1dfa7eb..5aa6a7a 100644 --- a/lock.c +++ b/lock.c @@ -51,7 +51,7 @@ cat(char* l, char* r) char* res = xmalloc(strlen(l) + strlen (r) + 1); strcpy(res, l); strcat(res, r); - + return res; } @@ -64,6 +64,7 @@ dot_lock(char* path) int res = -1; char* lockfile = cat(path, ".lock"); + raise_gid(); for (i = 0; i < LOCK_MAX_TRIES; i++){ if ((fd = open(lockfile, O_WRONLY | O_EXCL | O_CREAT, 0)) >= 0) { @@ -76,9 +77,9 @@ dot_lock(char* path) break; /* FIXME: deal with old locks */ - random_sleep(1, 1); } + drop_gid(); free(lockfile); return res; diff --git a/umpf.c b/umpf.c index 8b4627c..3dfef81 100644 --- a/umpf.c +++ b/umpf.c @@ -24,9 +24,9 @@ main(int argc, char** argv) struct passwd* p; p = getpwuid(getuid()); if (argc < 3) - default_mailbox = argv[2]; - else default_mailbox = cat("/var/mail/", p->pw_name); + else + default_mailbox = argv[2]; save_gids(); read_conf(argv[1]); @@ -41,6 +41,7 @@ main(int argc, char** argv) compile(input_tree, NULL); current_headers = make_hlist(); +// print_headers(current_headers); current_body = get_body(); save_current_headers(var_hash); diff --git a/umpf.h b/umpf.h index 926c476..080159c 100644 --- a/umpf.h +++ b/umpf.h @@ -168,6 +168,7 @@ struct variable { struct list input_code; struct list* var_hash; int current_varcode; +int max_varcode; int temp_varcode_start; char** var_tab; char** const_tab; @@ -208,6 +209,7 @@ struct email* current_body; struct list* make_hlist(void); void print_headers(struct list* l); struct email* get_body(void); +int deliver_local_email(char* folder, struct email* email); /* lock.c */ void save_gids(void); -- 2.39.2