]> mj.ucw.cz Git - umpf.git/commitdiff
really do local delivery
authorAnicka Bernathova <anicka@anicka.net>
Thu, 16 Jul 2009 20:21:51 +0000 (22:21 +0200)
committerAnicka Bernathova <anicka@anicka.net>
Thu, 16 Jul 2009 20:21:51 +0000 (22:21 +0200)
code.c
ham.c
int.c
lock.c
umpf.c
umpf.h

diff --git a/code.c b/code.c
index bf3906f9525838915175380dc07ad63250779413..4a84d18c7dcc3e2af57a07431b3f4003f4a28cff 100644 (file)
--- 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 f0b7dbbb115a1a64b4ef99c0abeb28bb38426663..f06fdf3cca2ee88da1d84be33ece973ca45e75e1 100644 (file)
--- 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 436181b748b13d9b92574b25e8e6f9b4c7d50069..4133f3453e6ca3564178517060bd0e30a341d7df 100644 (file)
--- 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 1dfa7ebdd58ac1781af2e430828e6c18e2f7ec55..5aa6a7aab0d01b75553bc76f589a627d35c6c66d 100644 (file)
--- 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 8b4627cfcd2d7fb04ce0e58a9b8178e3ad3ca6e1..3dfef8199fb21f047ab9e6b6ba1f6f732e2e8136 100644 (file)
--- 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 926c4768b55efbf3a9f6920e383977e5d5f7d00c..080159ce8729fc9c87ea926106b2fe0e94d11556 100644 (file)
--- 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);