else {
*p = 0;
new->value = xstrdup(p+1);
+ p = strrchr(new->value, '\n');
+ if (p && !*(p+1))
+ *p = 0;
}
new->name = xstrdup(buf);
struct hlist* p;
LIST_FOREACH(p,l)
- printf("%s:%s",p->name,p->value);
+ printf("%s:%s\n",p->name,p->value);
}
static void
return 0;
}
-static int
+int
deliver_local_email(char* folder, struct email* email)
{
int res = -1;
return res;
}
-
-void
-do_action(struct action* a)
-{
- /* -> address */
- if (! a->r && !a->l ){
- deliver_local_email(a->s, &a->e);
- }
-}
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
struct code* p;
char* result;
int v;
+
+ var_tab = xmalloc(max_varcode * sizeof(char*));
LIST_FOREACH(p, ins) {
switch (p->opcode) {
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;
exit(0);
break;
}}
- deliver(default_mailbox, 0, 1, hash);
+ deliver(default_mailbox, 0, hash);
}
void
char* res = xmalloc(strlen(l) + strlen (r) + 1);
strcpy(res, l);
strcat(res, r);
-
+
return res;
}
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) {
break;
/* FIXME: deal with old locks */
-
random_sleep(1, 1);
}
+ drop_gid();
free(lockfile);
return res;
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]);
compile(input_tree, NULL);
current_headers = make_hlist();
+// print_headers(current_headers);
current_body = get_body();
save_current_headers(var_hash);