From: Anicka Bernathova Date: Sun, 31 Aug 2008 12:16:08 +0000 (+0200) Subject: rename to umpf, guess default mailbox X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=fe8a488cd0901903cf93448366b3164c94674ac9;p=umpf.git rename to umpf, guess default mailbox --- diff --git a/Makefile b/Makefile index 7979cc9..6277232 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ -all: brum +all: umpf CC=gcc CFLAGS=-Wall -W -Wno-pointer-sign -Wstrict-prototypes -Wmissing-prototypes -O2 -g LDLIBS=-lpcre -brum: brum.c cond.tab.o int.o lex.o ham.o lists.o lock.o +umpf: umpf.c cond.tab.o int.o lex.o ham.o lists.o lock.o gcc -o $@ $^ $(LDLIBS) lock.o: lex.o cond.tab.o @@ -23,4 +23,4 @@ cond.tab.c: cond.y bison -dvt cond.y clean: - rm -rf cond.tab.[ch] cond.output cond brum *.o core + rm -rf cond.tab.[ch] cond.output cond umpf *.o core diff --git a/brum.c b/brum.c deleted file mode 100644 index facd0f9..0000000 --- a/brum.c +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include "brum.h" - -int -main(int argc, char** argv) -{ - int res; - - if (argc < 2) - die("Usage: ./brum conf_file"); - - save_gids(); - read_conf(argv[1]); - //FIXME: - get_default_mailbox("/var/mail/anicka"); - -// yydebug=1; - res = yyparse (); - - if (res) - return res; - -// print_tree(input_tree,0); - - var_hash = new_var_hash(); - - current_headers = make_hlist(); - current_body = get_body(); -// print_headers(current_headers); - - save_current_headers(var_hash); - interp(input_tree, var_hash); - -// print_vars(var_hash); - - return 0; -} diff --git a/brum.h b/brum.h deleted file mode 100644 index c72f7ac..0000000 --- a/brum.h +++ /dev/null @@ -1,127 +0,0 @@ -#include "lists.h" - -/* cond.h */ -int yylex (void); -void yyerror (char const *); - -struct tree { - enum { - ST_IF, - ST_COND, - ST_BLOCK, - ST_ASS, - ST_LEAF, - ST_EMPTY, - ST_ARROW, - ST_OP - } st; /* subtree type */ - union { - struct { - struct tree* c; /* condition */ - struct tree* i; /* if */ - struct tree* e; /* else */ - } tif; - - struct { - int op; - enum { - OP_REL, - OP_BOOL - } type; - struct tree* left; - struct tree* right; - } cond; /* binary operator */ - - struct { - struct tree* head; - struct tree* tail; - } block; - - struct { - struct tree* left; - struct tree* right; - } ass; - - struct { - enum { - L_VAR, - L_CONST, - } type; - char* value; - } leaf; - - struct { - char* kw_left; - char* kw_right; - struct tree* s; - } arrow; - - struct { - int op; - struct tree* left; - struct tree* right; - } op; - - } pt; -}; - -struct tree* input_tree; - -/* lex.c */ -#define CC(a,b) ((a<<8)|b) -void* xmalloc(size_t size); -void* xrealloc(void* buf, size_t size); -char* xstrdup(char* s); -void __attribute__ ((noreturn)) die(char* msg, ...); -void read_conf(char* filename); -int line; -FILE* conf; - -/* int.c */ -struct variable { - struct node car; - char* name; - char* value; - int modified; -}; - -struct hlist { - struct node car; - char* name; - char* value; -}; - -struct email { - struct list* headers; - char* body; - int body_len; -}; - -struct action { - char* l; - char* r; - char* s; - struct email e; -}; - -struct list* var_hash; -char* default_mailbox; - -void print_tree(struct tree* t, int ind); -void interp(struct tree* t, struct list* hash); -struct list* new_var_hash(void); -void print_vars(struct list* hash); -void save_current_headers(struct list* hash); - -/* ham.c */ -struct list* current_headers; -struct email* current_body; -struct list* make_hlist(void); -void print_headers(struct list* l); -void do_action(struct action* a); -struct email* get_body(void); - -/* lock.c */ -void save_gids(void); -void close_mailbox(int fd, char* path, int is_default_mailbox); -int open_mailbox(char* path, int is_default_mailbox); diff --git a/cond.y b/cond.y index fd5dc30..6ae17e8 100644 --- a/cond.y +++ b/cond.y @@ -3,7 +3,7 @@ #include #include -#include "brum.h" +#include "umpf.h" static struct tree* tree_malloc(int type); diff --git a/ham.c b/ham.c index 03102e7..d74a1bf 100644 --- a/ham.c +++ b/ham.c @@ -4,7 +4,7 @@ #include -#include "brum.h" +#include "umpf.h" #define BUFSIZE 1024 @@ -163,9 +163,16 @@ copy_email(int fd, struct email* email) write_char_to_mailbox('\n', fd); /* body */ - //FIXME that nasty FROM - for (pc = email->body; *pc; pc++){ - write_char_to_mailbox(*pc, fd); + /* FIXME: do not forget change Content-Length */ + for (pc = email->body; pc < email->body + email->body_len; pc++){ + write_char_to_mailbox(*pc, fd); + if (*pc == '\n'){ + if ((pc + 5 < email->body + email->body_len) + && pc[1] == 'F' && pc[2] == 'r' + && pc[3] == 'o' && pc[4] == 'm' + && pc[5] == ' ') + write_char_to_mailbox('>', fd); + } } flush_mbox_buffer(fd); diff --git a/int.c b/int.c index 80cf663..f7fe023 100644 --- a/int.c +++ b/int.c @@ -4,7 +4,7 @@ #include #include "cond.tab.h" -#include "brum.h" +#include "umpf.h" #define OVECCOUNT 3 #define HASHSIZE 103 diff --git a/lex.c b/lex.c index 4beb8bb..d1c7b4e 100644 --- a/lex.c +++ b/lex.c @@ -5,7 +5,7 @@ #include #include "cond.tab.h" -#include "brum.h" +#include "umpf.h" #define BUFSIZE 4096 #define KLEN 10 diff --git a/lock.c b/lock.c index d6d1155..1dfa7eb 100644 --- a/lock.c +++ b/lock.c @@ -9,7 +9,7 @@ #include #include -#include "brum.h" +#include "umpf.h" #define LOCK_MAX_TRIES 3 gid_t rgid, egid, sgid; @@ -45,7 +45,7 @@ random_sleep(unsigned int about, unsigned int offset) usleep(about * 1000000 + myrand * 500000); } -static char* +char* cat(char* l, char* r) { char* res = xmalloc(strlen(l) + strlen (r) + 1); diff --git a/umpf.c b/umpf.c new file mode 100644 index 0000000..266fe7a --- /dev/null +++ b/umpf.c @@ -0,0 +1,43 @@ +#include +#include + +#include "umpf.h" + +int +main(int argc, char** argv) +{ + int res; + + //FIXME: + struct passwd* p; + p = getpwuid(getuid()); + char* default_mbox = cat("/var/mail/", p->pw_name); + get_default_mailbox(default_mbox); + + if (argc < 2) + die("Usage: ./umpf conf_file"); + + save_gids(); + read_conf(argv[1]); + +// yydebug=1; + res = yyparse (); + + if (res) + return res; + +// print_tree(input_tree,0); + + var_hash = new_var_hash(); + + current_headers = make_hlist(); + current_body = get_body(); +// print_headers(current_headers); + + save_current_headers(var_hash); + interp(input_tree, var_hash); + +// print_vars(var_hash); + + return 0; +} diff --git a/umpf.h b/umpf.h new file mode 100644 index 0000000..7cac968 --- /dev/null +++ b/umpf.h @@ -0,0 +1,128 @@ +#include "lists.h" + +/* cond.h */ +int yylex (void); +void yyerror (char const *); + +struct tree { + enum { + ST_IF, + ST_COND, + ST_BLOCK, + ST_ASS, + ST_LEAF, + ST_EMPTY, + ST_ARROW, + ST_OP + } st; /* subtree type */ + union { + struct { + struct tree* c; /* condition */ + struct tree* i; /* if */ + struct tree* e; /* else */ + } tif; + + struct { + int op; + enum { + OP_REL, + OP_BOOL + } type; + struct tree* left; + struct tree* right; + } cond; /* binary operator */ + + struct { + struct tree* head; + struct tree* tail; + } block; + + struct { + struct tree* left; + struct tree* right; + } ass; + + struct { + enum { + L_VAR, + L_CONST, + } type; + char* value; + } leaf; + + struct { + char* kw_left; + char* kw_right; + struct tree* s; + } arrow; + + struct { + int op; + struct tree* left; + struct tree* right; + } op; + + } pt; +}; + +struct tree* input_tree; + +/* lex.c */ +#define CC(a,b) ((a<<8)|b) +void* xmalloc(size_t size); +void* xrealloc(void* buf, size_t size); +char* xstrdup(char* s); +void __attribute__ ((noreturn)) die(char* msg, ...); +void read_conf(char* filename); +int line; +FILE* conf; + +/* int.c */ +struct variable { + struct node car; + char* name; + char* value; + int modified; +}; + +struct hlist { + struct node car; + char* name; + char* value; +}; + +struct email { + struct list* headers; + char* body; + int body_len; +}; + +struct action { + char* l; + char* r; + char* s; + struct email e; +}; + +struct list* var_hash; +char* default_mailbox; + +void print_tree(struct tree* t, int ind); +void interp(struct tree* t, struct list* hash); +struct list* new_var_hash(void); +void print_vars(struct list* hash); +void save_current_headers(struct list* hash); + +/* ham.c */ +struct list* current_headers; +struct email* current_body; +struct list* make_hlist(void); +void print_headers(struct list* l); +void do_action(struct action* a); +struct email* get_body(void); + +/* lock.c */ +void save_gids(void); +void close_mailbox(int fd, char* path, int is_default_mailbox); +int open_mailbox(char* path, int is_default_mailbox); +char* cat(char* l, char* r);