Codebase list fdm / 5c03781
More renaming. Nicholas Marriott 17 years ago
9 changed file(s) with 99 addition(s) and 94 deletion(s). Raw diff Collapse all Expand all
3535 int deliver_mbox_deliver(struct deliver_ctx *, struct action *);
3636 void deliver_mbox_desc(struct action *, char *, size_t);
3737
38 int mbox_write(int, gzFile, const void *, size_t);
38 int deliver_mbox_write(int, gzFile, const void *, size_t);
3939
4040 struct deliver deliver_mbox = {
4141 DELIVER_ASUSER,
4444 };
4545
4646 int
47 mbox_write(int fd, gzFile gzf, const void *buf, size_t len)
47 deliver_mbox_write(int fd, gzFile gzf, const void *buf, size_t len)
4848 {
4949 ssize_t n;
5050
141141 }
142142
143143 /* write the from line */
144 if (mbox_write(fd, gzf, from, strlen(from)) < 0) {
144 if (deliver_mbox_write(fd, gzf, from, strlen(from)) < 0) {
145145 log_warn("%s: %s: write", a->name, path);
146146 goto out;
147147 }
148 if (mbox_write(fd, gzf, "\n", 1) < 0) {
148 if (deliver_mbox_write(fd, gzf, "\n", 1) < 0) {
149149 log_warn("%s: %s: write", a->name, path);
150150 goto out;
151151 }
164164 if (len2 >= 5 && strncmp(ptr2, "From ", 5) == 0) {
165165 log_debug2("%s: quoting from line: %.*s",
166166 a->name, (int) len - 1, ptr);
167 if (mbox_write(fd, gzf, ">", 1) < 0) {
167 if (deliver_mbox_write(fd, gzf, ">", 1) < 0) {
168168 log_warn("%s: %s: write", a->name,
169169 path);
170170 goto out;
172172 }
173173 }
174174
175 if (mbox_write(fd, gzf, ptr, len) < 0) {
175 if (deliver_mbox_write(fd, gzf, ptr, len) < 0) {
176176 log_warn("%s: %s: write", a->name, path);
177177 goto out;
178178 }
180180 line_next(m, &ptr, &len);
181181 }
182182 len = m->data[m->size - 1] == '\n' ? 1 : 2;
183 if (mbox_write(fd, gzf, "\n\n", len) < 0) {
183 if (deliver_mbox_write(fd, gzf, "\n\n", len) < 0) {
184184 log_warn("%s: %s: write", a->name, path);
185185 goto out;
186186 }
3030 int deliver_smtp_deliver(struct deliver_ctx *, struct action *);
3131 void deliver_smtp_desc(struct action *, char *, size_t);
3232
33 int smtp_code(char *);
33 int deliver_smtp_code(char *);
3434
3535 struct deliver deliver_smtp = {
3636 DELIVER_ASUSER,
3939 };
4040
4141 int
42 smtp_code(char *line)
42 deliver_smtp_code(char *line)
4343 {
4444 char ch;
4545 const char *errstr;
6969 int done, code;
7070 struct io *io;
7171 char *cause, *to, *from, *line, *ptr, *lbuf;
72 enum smtp_state state;
72 enum deliver_smtp_state state;
7373 size_t len, llen;
7474
7575 io = connectproxy(&data->server, conf.proxy, IO_CRLF,
102102 case -1:
103103 goto error;
104104 }
105 code = smtp_code(line);
105 code = deliver_smtp_code(line);
106106
107107 switch (state) {
108108 case SMTP_CONNECTING:
5252 };
5353
5454 /* Deliver smtp states. */
55 enum smtp_state {
55 enum deliver_smtp_state {
5656 SMTP_CONNECTING,
5757 SMTP_HELO,
5858 SMTP_FROM,
2626 int fetch_imap_disconnect(struct account *);
2727 void fetch_imap_desc(struct account *, char *, size_t);
2828
29 int printflike2 imap_putln(struct account *, const char *, ...);
30 char *imap_getln(struct account *, int);
31 void imap_flush(struct account *);
29 int printflike2 fetch_imap_putln(struct account *, const char *, ...);
30 char *fetch_imap_getln(struct account *, int);
31 void fetch_imap_flush(struct account *);
3232
3333 struct fetch fetch_imap = {
3434 { "imap", "imaps" },
4545 };
4646
4747 int printflike2
48 imap_putln(struct account *a, const char *fmt, ...)
48 fetch_imap_putln(struct account *a, const char *fmt, ...)
4949 {
5050 struct fetch_imap_data *data = a->data;
5151
5959 }
6060
6161 char *
62 imap_getln(struct account *a, int type)
62 fetch_imap_getln(struct account *a, int type)
6363 {
6464 struct fetch_imap_data *data = a->data;
6565 char **lbuf = &data->lbuf;
110110 }
111111
112112 void
113 imap_flush(struct account *a)
113 fetch_imap_flush(struct account *a)
114114 {
115115 struct fetch_imap_data *data = a->data;
116116
133133 if (conf.debug > 3 && !conf.syslog)
134134 data->io->dup_fd = STDOUT_FILENO;
135135
136 data->getln = imap_getln;
137 data->putln = imap_putln;
138 data->flush = imap_flush;
136 data->getln = fetch_imap_getln;
137 data->putln = fetch_imap_putln;
138 data->flush = fetch_imap_flush;
139139 data->src = data->server.host;
140140
141141 if (imap_login(a) != 0)
2626 int fetch_imappipe_disconnect(struct account *);
2727 void fetch_imappipe_desc(struct account *, char *, size_t);
2828
29 int printflike2 imappipe_putln(struct account *, const char *, ...);
30 char *imappipe_getln(struct account *, int);
31 void imappipe_flush(struct account *);
29 int printflike2 fetch_imappipe_putln(struct account *, const char *, ...);
30 char *fetch_imappipe_getln(struct account *, int);
31 void fetch_imappipe_flush(struct account *);
3232
3333 struct fetch fetch_imappipe = {
3434 { NULL, NULL },
4545 };
4646
4747 int printflike2
48 imappipe_putln(struct account *a, const char *fmt, ...)
48 fetch_imappipe_putln(struct account *a, const char *fmt, ...)
4949 {
5050 struct fetch_imap_data *data = a->data;
5151
5959 }
6060
6161 char *
62 imappipe_getln(struct account *a, int type)
62 fetch_imappipe_getln(struct account *a, int type)
6363 {
6464 struct fetch_imap_data *data = a->data;
6565 char **lbuf = &data->lbuf;
117117 }
118118
119119 void
120 imappipe_flush(struct account *a)
120 fetch_imappipe_flush(struct account *a)
121121 {
122122 struct fetch_imap_data *data = a->data;
123123
141141 data->cmd->io_out->dup_fd = STDOUT_FILENO;
142142 }
143143
144 data->getln = imappipe_getln;
145 data->putln = imappipe_putln;
146 data->flush = imappipe_flush;
144 data->getln = fetch_imappipe_getln;
145 data->putln = fetch_imappipe_putln;
146 data->flush = fetch_imappipe_flush;
147147 data->src = NULL;
148148
149149 if (imap_login(a) != 0)
3838 int fetch_maildir_delete(struct account *);
3939 void fetch_maildir_desc(struct account *, char *, size_t);
4040
41 int maildir_makepaths(struct account *);
42 void maildir_freepaths(struct account *);
41 int fetch_maildir_makepaths(struct account *);
42 void fetch_maildir_freepaths(struct account *);
4343
4444 struct fetch fetch_maildir = {
4545 { NULL, NULL },
5757
5858 /* Make an array of all the paths to visit. */
5959 int
60 maildir_makepaths(struct account *a)
60 fetch_maildir_makepaths(struct account *a)
6161 {
6262 struct fetch_maildir_data *data = a->data;
6363 char *s, *path;
121121 error:
122122 if (s != NULL)
123123 xfree(s);
124 maildir_freepaths(a);
124 fetch_maildir_freepaths(a);
125125
126126 strb_destroy(&tags);
127127 return (1);
129129
130130 /* Free the array. */
131131 void
132 maildir_freepaths(struct account *a)
132 fetch_maildir_freepaths(struct account *a)
133133 {
134134 struct fetch_maildir_data *data = a->data;
135135 u_int i;
149149
150150 data->path = NULL;
151151
152 if (maildir_makepaths(a) != 0)
152 if (fetch_maildir_makepaths(a) != 0)
153153 return (1);
154154 data->index = 0;
155155
312312 {
313313 struct fetch_maildir_data *data = a->data;
314314
315 maildir_freepaths(a);
315 fetch_maildir_freepaths(a);
316316
317317 if (data->dirp != NULL)
318318 closedir(data->dirp);
3838 int fetch_nntp_keep(struct account *);
3939 void fetch_nntp_desc(struct account *, char *, size_t);
4040
41 int nntp_code(char *);
42 char *nntp_line(struct account *, char **, size_t *);
43 char *nntp_check(struct account *, char **, size_t *, int *, u_int, ...);
44 int nntp_group(struct account *, char **, size_t *);
45 int nntp_parse223(char *, u_int *, char **);
46
47 int nntp_load(struct account *);
48 int nntp_save(struct account *);
41 int fetch_nntp_code(char *);
42 char *fetch_nntp_line(struct account *, char **, size_t *);
43 char *fetch_nntp_check(struct account *, char **, size_t *, int *, u_int,
44 ...);
45 int fetch_nntp_group(struct account *, char **, size_t *);
46 int fetch_nntp_parse223(char *, u_int *, char **);
47
48 int fetch_nntp_load(struct account *);
49 int fetch_nntp_save(struct account *);
4950
5051 #define GET_GROUP(d, i) ARRAY_ITEM(&d->groups, i, struct fetch_nntp_group *)
5152 #define CURRENT_GROUP(d) GET_GROUP(d, d->group)
5859 fetch_nntp_connect,
5960 fetch_nntp_poll,
6061 fetch_nntp_fetch,
61 nntp_save,
62 fetch_nntp_save,
6263 NULL,
6364 NULL,
6465 fetch_nntp_disconnect,
6768 };
6869
6970 int
70 nntp_code(char *line)
71 fetch_nntp_code(char *line)
7172 {
7273 char ch;
7374 const char *errstr;
8990 }
9091
9192 char *
92 nntp_line(struct account *a, char **lbuf, size_t *llen)
93 fetch_nntp_line(struct account *a, char **lbuf, size_t *llen)
9394 {
9495 struct fetch_nntp_data *data = a->data;
9596 char *line, *cause;
108109 }
109110
110111 char *
111 nntp_check(struct account *a, char **lbuf, size_t *llen, int *cdp, u_int n, ...)
112 fetch_nntp_check(struct account *a, char **lbuf, size_t *llen, int *cdp,
113 u_int n, ...)
112114 {
113115 char *line;
114116 va_list ap;
119121 cdp = &code;
120122
121123 do {
122 if ((line = nntp_line(a, lbuf, llen)) == NULL)
124 if ((line = fetch_nntp_line(a, lbuf, llen)) == NULL)
123125 return (NULL);
124126
125 *cdp = nntp_code(line);
127 *cdp = fetch_nntp_code(line);
126128 if (*cdp == -1)
127129 goto error;
128130 } while (*cdp >= 100 && *cdp <= 199);
145147 }
146148
147149 int
148 nntp_parse223(char *line, u_int *n, char **id)
150 fetch_nntp_parse223(char *line, u_int *n, char **id)
149151 {
150152 char *ptr, *ptr2;
151153
168170 }
169171
170172 int
171 nntp_group(struct account *a, char **lbuf, size_t *llen)
173 fetch_nntp_group(struct account *a, char **lbuf, size_t *llen)
172174 {
173175 struct fetch_nntp_data *data = a->data;
174176 struct fetch_nntp_group *group;
179181 log_debug("%s: fetching group: %s", a->name, group->name);
180182
181183 io_writeline(data->io, "GROUP %s", group->name);
182 if ((line = nntp_check(a, lbuf, llen, NULL, 1, 211)) == NULL)
184 if ((line = fetch_nntp_check(a, lbuf, llen, NULL, 1, 211)) == NULL)
183185 return (1);
184186 if (sscanf(line, "211 %u %*u %u", &group->size, &last) != 2) {
185187 log_warnx("%s: invalid response: %s", a->name, line);
194196 group->size = last - group->last;
195197
196198 io_writeline(data->io, "STAT %u", group->last);
197 if ((line = nntp_check(a, lbuf, llen, NULL, 1, 223)) == NULL)
198 return (1);
199
200 if (nntp_parse223(line, &n, &id) != 0)
199 if ((line = fetch_nntp_check(a, lbuf, llen, NULL, 1, 223)) == NULL)
200 return (1);
201
202 if (fetch_nntp_parse223(line, &n, &id) != 0)
201203 goto invalid;
202204 if (n != group->last) {
203205 log_warnx("%s: unexpected message number", a->name);
217219 log_warnx("%s: last message not found. resetting group", a->name);
218220
219221 io_writeline(data->io, "GROUP %s", group->name);
220 if ((line = nntp_check(a, lbuf, llen, NULL, 1, 211)) == NULL)
222 if ((line = fetch_nntp_check(a, lbuf, llen, NULL, 1, 211)) == NULL)
221223 return (1);
222224 if (sscanf(line, "211 %u %*u %*u", &group->size) != 1) {
223225 log_warnx("%s: invalid response: %s", a->name, line);
234236 }
235237
236238 int
237 nntp_load(struct account *a)
239 fetch_nntp_load(struct account *a)
238240 {
239241 struct fetch_nntp_data *data = a->data;
240242 struct fetch_nntp_group *group;
288290 break;
289291 }
290292 if (i == TOTAL_GROUPS(data)) {
291 /* not found. add it so it is saved when nntp_save is
292 called, but with ignore set so it is fetched */
293 /*
294 * Not found. add it so it is saved when the file is
295 * resaved, but with ignore set so it isn't fetched.
296 */
293297 group = xcalloc(1, sizeof *group);
294298 ADD_GROUP(data, group);
295299 group->ignore = 1;
319323 }
320324
321325 int
322 nntp_save(struct account *a)
326 fetch_nntp_save(struct account *a)
323327 {
324328 struct fetch_nntp_data *data = a->data;
325329 struct fetch_nntp_group *group;
428432 llen = IO_LINESIZE;
429433 lbuf = xmalloc(llen);
430434
431 if (nntp_load(a) != 0)
435 if (fetch_nntp_load(a) != 0)
432436 goto error;
433437 data->group = 0;
434438 if (CURRENT_GROUP(data)->ignore) {
441445 } while (CURRENT_GROUP(data)->ignore);
442446 }
443447
444 if ((line = nntp_check(a, &lbuf, &llen, NULL, 1, 200)) == NULL)
445 goto error;
446
447 if (nntp_group(a, &lbuf, &llen) != 0)
448 if ((line = fetch_nntp_check(a, &lbuf, &llen, NULL, 1, 200)) == NULL)
449 goto error;
450
451 if (fetch_nntp_group(a, &lbuf, &llen) != 0)
448452 goto error;
449453
450454 xfree(lbuf);
468472 char *lbuf, *line;
469473 size_t llen;
470474
471 nntp_save(a);
475 fetch_nntp_save(a);
472476
473477 llen = IO_LINESIZE;
474478 lbuf = xmalloc(llen);
475479
476480 io_writeline(data->io, "QUIT");
477 if ((line = nntp_check(a, &lbuf, &llen, NULL, 1, 205)) == NULL)
481 if ((line = fetch_nntp_check(a, &lbuf, &llen, NULL, 1, 205)) == NULL)
478482 goto error;
479483
480484 io_close(data->io);
512516 if (CURRENT_GROUP(data)->ignore)
513517 continue;
514518
515 if (nntp_group(a, &lbuf, &llen) != 0)
519 if (fetch_nntp_group(a, &lbuf, &llen) != 0)
516520 goto error;
517521 (*n) += CURRENT_GROUP(data)->size;
518522 }
540544
541545 restart:
542546 io_writeline(data->io, "NEXT");
543 if ((line = nntp_check(a, &lbuf, &llen, &code, 2, 223, 421)) == NULL)
547 line = fetch_nntp_check(a, &lbuf, &llen, &code, 2, 223, 421);
548 if (line == NULL)
544549 goto error;
545550 if (code == 421) {
546551 do {
550555 return (FETCH_COMPLETE);
551556 }
552557 } while (CURRENT_GROUP(data)->ignore);
553 if (nntp_group(a, &lbuf, &llen) != 0)
558 if (fetch_nntp_group(a, &lbuf, &llen) != 0)
554559 goto error;
555560 goto restart;
556561 }
557562
558563 /* fill this in as the last article */
559 if (nntp_parse223(line, &n, &id) != 0) {
564 if (fetch_nntp_parse223(line, &n, &id) != 0) {
560565 log_warnx("%s: malformed response: %s", a->name, line);
561566 goto restart;
562567 }
572577
573578 /* retrieve the article */
574579 io_writeline(data->io, "ARTICLE");
575 line = nntp_check(a, &lbuf, &llen, &code, 3, 220, 423, 430);
580 line = fetch_nntp_check(a, &lbuf, &llen, &code, 3, 220, 423, 430);
576581 if (line == NULL)
577582 goto error;
578583 if (code == 423 || code == 430)
587592 flushing = 0;
588593 off = lines = 0;
589594 for (;;) {
590 if ((line = nntp_line(a, &lbuf, &llen)) == NULL)
595 if ((line = fetch_nntp_line(a, &lbuf, &llen)) == NULL)
591596 goto error;
592597
593598 if (line[0] == '.' && line[1] == '.')
3737 int fetch_pop3_keep(struct account *);
3838 void fetch_pop3_desc(struct account *, char *, size_t);
3939
40 char *pop3_line(struct account *, char **, size_t *);
41 char *pop3_check(struct account *, char **, size_t *);
40 char *fetch_pop3_line(struct account *, char **, size_t *);
41 char *fetch_pop3_check(struct account *, char **, size_t *);
4242
4343 struct fetch fetch_pop3 = {
4444 { "pop3", "pop3s" },
5555 };
5656
5757 char *
58 pop3_line(struct account *a, char **lbuf, size_t *llen)
58 fetch_pop3_line(struct account *a, char **lbuf, size_t *llen)
5959 {
6060 struct fetch_pop3_data *data = a->data;
6161 char *line, *cause;
7474 }
7575
7676 char *
77 pop3_check(struct account *a, char **lbuf, size_t *llen)
77 fetch_pop3_check(struct account *a, char **lbuf, size_t *llen)
7878 {
7979 char *line;
8080
81 if ((line = pop3_line(a, lbuf, llen)) == NULL)
81 if ((line = fetch_pop3_line(a, lbuf, llen)) == NULL)
8282 return (NULL);
8383
8484 if (strncmp(line, "+OK", 3) != 0) {
135135 llen = IO_LINESIZE;
136136 lbuf = xmalloc(llen);
137137
138 if (pop3_check(a, &lbuf, &llen) == NULL)
138 if (fetch_pop3_check(a, &lbuf, &llen) == NULL)
139139 goto error;
140140
141141 /* log the user in */
142142 io_writeline(data->io, "USER %s", data->user);
143 if (pop3_check(a, &lbuf, &llen) == NULL)
143 if (fetch_pop3_check(a, &lbuf, &llen) == NULL)
144144 goto error;
145145 io_writeline(data->io, "PASS %s", data->pass);
146 if (pop3_check(a, &lbuf, &llen) == NULL)
146 if (fetch_pop3_check(a, &lbuf, &llen) == NULL)
147147 goto error;
148148
149149 /* find the number of messages */
150150 io_writeline(data->io, "STAT");
151 if ((line = pop3_check(a, &lbuf, &llen)) == NULL)
151 if ((line = fetch_pop3_check(a, &lbuf, &llen)) == NULL)
152152 goto error;
153153 if (sscanf(line, "+OK %u %*u", &data->num) != 1) {
154154 log_warnx("%s: invalid response: %s", a->name, line);
181181 lbuf = xmalloc(llen);
182182
183183 io_writeline(data->io, "QUIT");
184 if (pop3_check(a, &lbuf, &llen) == NULL)
184 if (fetch_pop3_check(a, &lbuf, &llen) == NULL)
185185 goto error;
186186
187187 io_close(data->io);
230230 restart:
231231 /* list the current message to get its size */
232232 io_writeline(data->io, "LIST %u", data->cur);
233 if ((line = pop3_check(a, &lbuf, &llen)) == NULL)
233 if ((line = fetch_pop3_check(a, &lbuf, &llen)) == NULL)
234234 goto error;
235235 if (sscanf(line, "+OK %*u %zu", &size) != 1) {
236236 log_warnx("%s: invalid response: %s", a->name, line);
248248
249249 /* find and store the UID */
250250 io_writeline(data->io, "UIDL %u", data->cur);
251 if ((line = pop3_check(a, &lbuf, &llen)) == NULL)
251 if ((line = fetch_pop3_check(a, &lbuf, &llen)) == NULL)
252252 goto error;
253253 if (sscanf(line, "+OK %u ", &n) != 1) {
254254 log_warnx("%s: invalid response: %s", a->name, line);
288288
289289 /* retrieve the message */
290290 io_writeline(data->io, "RETR %u", data->cur);
291 if (pop3_check(a, &lbuf, &llen) == NULL)
291 if (fetch_pop3_check(a, &lbuf, &llen) == NULL)
292292 goto error;
293293
294294 mail_open(m, IO_ROUND(size));
301301 off = lines = 0;
302302 bodylines = -1;
303303 for (;;) {
304 if ((line = pop3_line(a, &lbuf, &llen)) == NULL)
304 if ((line = fetch_pop3_line(a, &lbuf, &llen)) == NULL)
305305 goto error;
306306
307307 if (line[0] == '.' && line[1] == '.')
376376 lbuf = xmalloc(llen);
377377
378378 io_writeline(data->io, "DELE %u", data->cur);
379 if (pop3_check(a, &lbuf, &llen) == NULL)
379 if (fetch_pop3_check(a, &lbuf, &llen) == NULL)
380380 goto error;
381381
382382 xfree(lbuf);
2727 int match_age_match(struct match_ctx *, struct expritem *);
2828 void match_age_desc(struct expritem *, char *, size_t);
2929
30 int age_tzlookup(const char *, int *);
30 int match_age_tzlookup(const char *, int *);
3131
3232 struct match match_age = {
3333 match_age_match,
4242 * using tzset, which catches the few most common abbreviations.
4343 */
4444 int
45 age_tzlookup(const char *tz, int *off)
45 match_age_tzlookup(const char *tz, int *off)
4646 {
4747 char *saved_tz;
4848 struct tm *tm;
130130 tz = strtonum(endptr, -2359, 2359, &errstr);
131131 if (errstr != NULL) {
132132 /* try it using tzset */
133 if (age_tzlookup(endptr, &tz) != 0) {
133 if (match_age_tzlookup(endptr, &tz) != 0) {
134134 xfree(s);
135135 goto invalid;
136136 }