13 char mbox_write_buf[BUFSIZE];
18 new_header(char* buf, struct list* h)
23 new = xmalloc(sizeof(struct hlist));
27 new->value = xstrdup("");
30 new->value = xstrdup(p+1);
32 new->name = xstrdup(buf);
34 list_add_last(h, &new->car);
40 struct list* l = xmalloc(sizeof(struct list));
42 int i = 0; /* current position */
46 buf = xmalloc(BUFSIZE);
49 while ((c = getchar()) != EOF){
53 if (i >= curbufsize-2)
54 buf = xrealloc(buf, curbufsize *= 2);
60 if ((c = getchar()) != ' ' && c != '\t'){
81 int curbufsize = BUFSIZE;
83 buf = xmalloc(BUFSIZE);
84 while ((c = getchar()) != EOF){
87 if (i >= curbufsize - 1)
88 buf = xrealloc(buf, curbufsize *= 2);
97 print_headers(struct list* l)
102 printf("%s:%s",p->name,p->value);
106 write_char_to_mailbox(char c, int fd)
116 res = write(fd, mbox_write_buf, mbox_write_pos);
122 if (mbox_write_pos >= BUFSIZE){
123 res = write(fd, mbox_write_buf, BUFSIZE);
129 mbox_write_buf[mbox_write_pos++] = c;
132 /* try to copy e-mail to mailbox, if it fails,
133 truncate mailbox to the original size */
135 copy_email(int fd, struct email* email)
139 mb_end = lseek(fd, 0, SEEK_END);
150 LIST_FOREACH(ph, email->headers){
151 for (pc = ph->name; *pc; pc++)
152 write_char_to_mailbox(*pc, fd);
153 write_char_to_mailbox(':', fd);
154 write_char_to_mailbox(' ', fd);
155 for (pc = ph->value; *pc; pc++)
156 write_char_to_mailbox(*pc, fd);
157 write_char_to_mailbox('\n', fd);
160 write_char_to_mailbox('\n', fd);
162 //FIXME that nasty FROM
163 for (pc = email->body; *pc; pc++){
164 write_char_to_mailbox(*pc, fd);
167 /* flush the buffer */
168 write_char_to_mailbox(0, fd);
178 deliver_local_email(char* folder, struct email* email)
181 int is_default_mailbox = 0;
184 if (!strcmp(default_mailbox, folder))
185 is_default_mailbox = 1;
187 fd = open_mailbox(folder, is_default_mailbox);
189 if (is_default_mailbox)
191 else /* try to save to default mailbox instead */
192 return deliver_local_email(default_mailbox, email);
195 res = copy_email(fd, email);
198 /* try to deliver to the default mailbox */
199 if (is_default_mailbox)
202 return deliver_local_email(default_mailbox, email);
205 close_mailbox(fd, folder, is_default_mailbox);
211 do_action(struct action* a)
214 if (! a->r && !a->l ){
215 deliver_local_email(a->s, &a->e);