]> mj.ucw.cz Git - umpf.git/commitdiff
let us start debugging
authorAnicka Bernathova <anicka@anicka.net>
Sat, 30 Aug 2008 15:53:15 +0000 (17:53 +0200)
committerAnicka Bernathova <anicka@anicka.net>
Sat, 30 Aug 2008 15:53:15 +0000 (17:53 +0200)
brum.c
brum.h
ham.c
int.c
lock.c

diff --git a/brum.c b/brum.c
index d72fa6adb1028377c9ee1ac39147ffd83e2b3a77..facd0f968f100848a2571b52d31b55924c11d36c 100644 (file)
--- a/brum.c
+++ b/brum.c
@@ -11,6 +11,8 @@ main(int argc, char** argv)
 
        save_gids();
        read_conf(argv[1]);
+       //FIXME:
+       get_default_mailbox("/var/mail/anicka");
 
 //     yydebug=1;
        res = yyparse ();
@@ -18,7 +20,7 @@ main(int argc, char** argv)
        if (res)
                return res;
 
-       print_tree(input_tree,0);
+//     print_tree(input_tree,0);
 
        var_hash = new_var_hash();
 
@@ -29,7 +31,7 @@ main(int argc, char** argv)
        save_current_headers(var_hash);
        interp(input_tree, var_hash);
        
-       print_vars(var_hash);
+//     print_vars(var_hash);
 
        return 0;
 }
diff --git a/brum.h b/brum.h
index 9942a92070028d18c8f634050078a0f506635ebe..c3931b2319a064a1ce4ebcafc06480362a0d72b9 100644 (file)
--- a/brum.h
+++ b/brum.h
@@ -104,6 +104,7 @@ struct action {
 };
 
 struct list* var_hash;
+char* default_mailbox;
 
 void print_tree(struct tree* t, int ind);
 void interp(struct tree* t, struct list* hash);
diff --git a/ham.c b/ham.c
index 16d7b36cc115ce8d7e271b06e8d60d13128e136a..ddc8e3ce5680ec660c287c2bdc4427de45bef77e 100644 (file)
--- a/ham.c
+++ b/ham.c
@@ -2,12 +2,18 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <unistd.h>
+
 #include "brum.h"
 
 #define BUFSIZE 1024 
 
 int curbufsize;
 
+char mbox_write_buf[BUFSIZE];
+int mbox_write_pos;
+int mbox_write_err;
+
 static void
 new_header(char* buf, struct list* h)
 {
@@ -96,15 +102,116 @@ print_headers(struct list* l)
                printf("%s:%s",p->name,p->value);
 }
 
-void
-do_action(struct action* a)
+static void
+write_char_to_mailbox(char c, int fd)
+{
+       int res;
+
+       if (mbox_write_err)
+               return;
+
+       if (!c){
+               if (!mbox_write_pos)
+                       return;
+               res = write(fd, mbox_write_buf, mbox_write_pos);
+               if (res < 0)
+                       mbox_write_err++;
+               mbox_write_pos = 0;
+               return;
+       }
+       if (mbox_write_pos >= BUFSIZE){
+               res = write(fd, mbox_write_buf, BUFSIZE);
+               if (res < 0)
+                       mbox_write_err++;
+               mbox_write_pos = 0;
+               return;
+       }
+       mbox_write_buf[mbox_write_pos++] = c;
+}
+
+/* try to copy e-mail to mailbox, if it fails,
+ truncate mailbox to the original size */
+static int
+copy_email(int fd, struct email* email)
 {
-       //just deliver e-mail, do not look at left side now
-/*     if (! a->r ){
+       off_t mb_end;
+
+       mb_end = lseek(fd, 0, SEEK_END);
+       if (mb_end < 1)
+               return -1;
+
+       /* init globals */
+       mbox_write_err = 0;
+       mbox_write_pos = 0;
+
+       /* headers */
+       struct hlist* ph;
+       char* pc;
+       LIST_FOREACH(ph, email->headers){
+               for (pc = ph->name; *pc; pc++)
+                       write_char_to_mailbox(*pc, fd);
+               write_char_to_mailbox(':', fd); 
+               write_char_to_mailbox(' ', fd); 
+               for (pc = ph->value; *pc; pc++)
+                       write_char_to_mailbox(*pc, fd); 
+                       write_char_to_mailbox('\n', fd);        
+       }
 
-       } else if (!strcmp(a->r,"pipe")){
-               1;
+       write_char_to_mailbox('\n', fd);
+       /* body */
+       //FIXME that nasty FROM
+       for (pc = email->body; *pc; pc++){
+                       write_char_to_mailbox(*pc, fd); 
        }       
-*/
 
+       /* flush the buffer */
+       write_char_to_mailbox(0, fd);
+
+       /* errors? */
+       if (mbox_write_err)
+               return -1;      
+
+       return 0; 
+}
+
+static int
+deliver_local_email(char* folder, struct email* email)
+{
+       int res = -1;
+       int is_default_mailbox = 0;
+       int fd;
+
+       if (!strcmp(default_mailbox, folder))   
+               is_default_mailbox = 1;
+
+       fd = open_mailbox(folder, is_default_mailbox);
+       if (fd < 0){
+               if (is_default_mailbox)
+                       return res;
+               else /* try to save to default mailbox instead */
+                       return deliver_local_email(default_mailbox, email);
+       }
+
+       res = copy_email(fd, email);
+       if (res < 0){
+
+               /* try to deliver to the default mailbox */
+               if (is_default_mailbox)
+                       return res;
+               else
+                       return deliver_local_email(default_mailbox, email);
+       }
+
+       close_mailbox(fd, folder, is_default_mailbox);  
+
+       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 795b843bd6ccbfa9c2765b1e44a69be2b7046466..13a307703a583caaf35704f9b578c52abfa062cf 100644 (file)
--- a/int.c
+++ b/int.c
@@ -386,3 +386,9 @@ save_current_headers(struct list* hash)
        }
 
 }
+
+void
+get_default_mailbox(char* mb)
+{
+       default_mailbox = mb;
+}
diff --git a/lock.c b/lock.c
index 571de8d0b2b6e24b4c1b222293da00a257d2dd1c..d6d1155660ec9fe6ca6935d31d837cae22ec81f2 100644 (file)
--- a/lock.c
+++ b/lock.c
@@ -11,7 +11,7 @@
 
 #include "brum.h"
 
-#define LOCK_MAX_TRIES 30
+#define LOCK_MAX_TRIES 3
 gid_t rgid, egid, sgid;
 
 void