More renaming.
Nicholas Marriott
17 years ago
35 | 35 | int deliver_mbox_deliver(struct deliver_ctx *, struct action *); |
36 | 36 | void deliver_mbox_desc(struct action *, char *, size_t); |
37 | 37 | |
38 | int mbox_write(int, gzFile, const void *, size_t); | |
38 | int deliver_mbox_write(int, gzFile, const void *, size_t); | |
39 | 39 | |
40 | 40 | struct deliver deliver_mbox = { |
41 | 41 | DELIVER_ASUSER, |
44 | 44 | }; |
45 | 45 | |
46 | 46 | 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) | |
48 | 48 | { |
49 | 49 | ssize_t n; |
50 | 50 | |
141 | 141 | } |
142 | 142 | |
143 | 143 | /* 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) { | |
145 | 145 | log_warn("%s: %s: write", a->name, path); |
146 | 146 | goto out; |
147 | 147 | } |
148 | if (mbox_write(fd, gzf, "\n", 1) < 0) { | |
148 | if (deliver_mbox_write(fd, gzf, "\n", 1) < 0) { | |
149 | 149 | log_warn("%s: %s: write", a->name, path); |
150 | 150 | goto out; |
151 | 151 | } |
164 | 164 | if (len2 >= 5 && strncmp(ptr2, "From ", 5) == 0) { |
165 | 165 | log_debug2("%s: quoting from line: %.*s", |
166 | 166 | a->name, (int) len - 1, ptr); |
167 | if (mbox_write(fd, gzf, ">", 1) < 0) { | |
167 | if (deliver_mbox_write(fd, gzf, ">", 1) < 0) { | |
168 | 168 | log_warn("%s: %s: write", a->name, |
169 | 169 | path); |
170 | 170 | goto out; |
172 | 172 | } |
173 | 173 | } |
174 | 174 | |
175 | if (mbox_write(fd, gzf, ptr, len) < 0) { | |
175 | if (deliver_mbox_write(fd, gzf, ptr, len) < 0) { | |
176 | 176 | log_warn("%s: %s: write", a->name, path); |
177 | 177 | goto out; |
178 | 178 | } |
180 | 180 | line_next(m, &ptr, &len); |
181 | 181 | } |
182 | 182 | 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) { | |
184 | 184 | log_warn("%s: %s: write", a->name, path); |
185 | 185 | goto out; |
186 | 186 | } |
30 | 30 | int deliver_smtp_deliver(struct deliver_ctx *, struct action *); |
31 | 31 | void deliver_smtp_desc(struct action *, char *, size_t); |
32 | 32 | |
33 | int smtp_code(char *); | |
33 | int deliver_smtp_code(char *); | |
34 | 34 | |
35 | 35 | struct deliver deliver_smtp = { |
36 | 36 | DELIVER_ASUSER, |
39 | 39 | }; |
40 | 40 | |
41 | 41 | int |
42 | smtp_code(char *line) | |
42 | deliver_smtp_code(char *line) | |
43 | 43 | { |
44 | 44 | char ch; |
45 | 45 | const char *errstr; |
69 | 69 | int done, code; |
70 | 70 | struct io *io; |
71 | 71 | char *cause, *to, *from, *line, *ptr, *lbuf; |
72 | enum smtp_state state; | |
72 | enum deliver_smtp_state state; | |
73 | 73 | size_t len, llen; |
74 | 74 | |
75 | 75 | io = connectproxy(&data->server, conf.proxy, IO_CRLF, |
102 | 102 | case -1: |
103 | 103 | goto error; |
104 | 104 | } |
105 | code = smtp_code(line); | |
105 | code = deliver_smtp_code(line); | |
106 | 106 | |
107 | 107 | switch (state) { |
108 | 108 | case SMTP_CONNECTING: |
52 | 52 | }; |
53 | 53 | |
54 | 54 | /* Deliver smtp states. */ |
55 | enum smtp_state { | |
55 | enum deliver_smtp_state { | |
56 | 56 | SMTP_CONNECTING, |
57 | 57 | SMTP_HELO, |
58 | 58 | SMTP_FROM, |
26 | 26 | int fetch_imap_disconnect(struct account *); |
27 | 27 | void fetch_imap_desc(struct account *, char *, size_t); |
28 | 28 | |
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 *); | |
32 | 32 | |
33 | 33 | struct fetch fetch_imap = { |
34 | 34 | { "imap", "imaps" }, |
45 | 45 | }; |
46 | 46 | |
47 | 47 | int printflike2 |
48 | imap_putln(struct account *a, const char *fmt, ...) | |
48 | fetch_imap_putln(struct account *a, const char *fmt, ...) | |
49 | 49 | { |
50 | 50 | struct fetch_imap_data *data = a->data; |
51 | 51 | |
59 | 59 | } |
60 | 60 | |
61 | 61 | char * |
62 | imap_getln(struct account *a, int type) | |
62 | fetch_imap_getln(struct account *a, int type) | |
63 | 63 | { |
64 | 64 | struct fetch_imap_data *data = a->data; |
65 | 65 | char **lbuf = &data->lbuf; |
110 | 110 | } |
111 | 111 | |
112 | 112 | void |
113 | imap_flush(struct account *a) | |
113 | fetch_imap_flush(struct account *a) | |
114 | 114 | { |
115 | 115 | struct fetch_imap_data *data = a->data; |
116 | 116 | |
133 | 133 | if (conf.debug > 3 && !conf.syslog) |
134 | 134 | data->io->dup_fd = STDOUT_FILENO; |
135 | 135 | |
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; | |
139 | 139 | data->src = data->server.host; |
140 | 140 | |
141 | 141 | if (imap_login(a) != 0) |
26 | 26 | int fetch_imappipe_disconnect(struct account *); |
27 | 27 | void fetch_imappipe_desc(struct account *, char *, size_t); |
28 | 28 | |
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 *); | |
32 | 32 | |
33 | 33 | struct fetch fetch_imappipe = { |
34 | 34 | { NULL, NULL }, |
45 | 45 | }; |
46 | 46 | |
47 | 47 | int printflike2 |
48 | imappipe_putln(struct account *a, const char *fmt, ...) | |
48 | fetch_imappipe_putln(struct account *a, const char *fmt, ...) | |
49 | 49 | { |
50 | 50 | struct fetch_imap_data *data = a->data; |
51 | 51 | |
59 | 59 | } |
60 | 60 | |
61 | 61 | char * |
62 | imappipe_getln(struct account *a, int type) | |
62 | fetch_imappipe_getln(struct account *a, int type) | |
63 | 63 | { |
64 | 64 | struct fetch_imap_data *data = a->data; |
65 | 65 | char **lbuf = &data->lbuf; |
117 | 117 | } |
118 | 118 | |
119 | 119 | void |
120 | imappipe_flush(struct account *a) | |
120 | fetch_imappipe_flush(struct account *a) | |
121 | 121 | { |
122 | 122 | struct fetch_imap_data *data = a->data; |
123 | 123 | |
141 | 141 | data->cmd->io_out->dup_fd = STDOUT_FILENO; |
142 | 142 | } |
143 | 143 | |
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; | |
147 | 147 | data->src = NULL; |
148 | 148 | |
149 | 149 | if (imap_login(a) != 0) |
38 | 38 | int fetch_maildir_delete(struct account *); |
39 | 39 | void fetch_maildir_desc(struct account *, char *, size_t); |
40 | 40 | |
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 *); | |
43 | 43 | |
44 | 44 | struct fetch fetch_maildir = { |
45 | 45 | { NULL, NULL }, |
57 | 57 | |
58 | 58 | /* Make an array of all the paths to visit. */ |
59 | 59 | int |
60 | maildir_makepaths(struct account *a) | |
60 | fetch_maildir_makepaths(struct account *a) | |
61 | 61 | { |
62 | 62 | struct fetch_maildir_data *data = a->data; |
63 | 63 | char *s, *path; |
121 | 121 | error: |
122 | 122 | if (s != NULL) |
123 | 123 | xfree(s); |
124 | maildir_freepaths(a); | |
124 | fetch_maildir_freepaths(a); | |
125 | 125 | |
126 | 126 | strb_destroy(&tags); |
127 | 127 | return (1); |
129 | 129 | |
130 | 130 | /* Free the array. */ |
131 | 131 | void |
132 | maildir_freepaths(struct account *a) | |
132 | fetch_maildir_freepaths(struct account *a) | |
133 | 133 | { |
134 | 134 | struct fetch_maildir_data *data = a->data; |
135 | 135 | u_int i; |
149 | 149 | |
150 | 150 | data->path = NULL; |
151 | 151 | |
152 | if (maildir_makepaths(a) != 0) | |
152 | if (fetch_maildir_makepaths(a) != 0) | |
153 | 153 | return (1); |
154 | 154 | data->index = 0; |
155 | 155 | |
312 | 312 | { |
313 | 313 | struct fetch_maildir_data *data = a->data; |
314 | 314 | |
315 | maildir_freepaths(a); | |
315 | fetch_maildir_freepaths(a); | |
316 | 316 | |
317 | 317 | if (data->dirp != NULL) |
318 | 318 | closedir(data->dirp); |
38 | 38 | int fetch_nntp_keep(struct account *); |
39 | 39 | void fetch_nntp_desc(struct account *, char *, size_t); |
40 | 40 | |
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 *); | |
49 | 50 | |
50 | 51 | #define GET_GROUP(d, i) ARRAY_ITEM(&d->groups, i, struct fetch_nntp_group *) |
51 | 52 | #define CURRENT_GROUP(d) GET_GROUP(d, d->group) |
58 | 59 | fetch_nntp_connect, |
59 | 60 | fetch_nntp_poll, |
60 | 61 | fetch_nntp_fetch, |
61 | nntp_save, | |
62 | fetch_nntp_save, | |
62 | 63 | NULL, |
63 | 64 | NULL, |
64 | 65 | fetch_nntp_disconnect, |
67 | 68 | }; |
68 | 69 | |
69 | 70 | int |
70 | nntp_code(char *line) | |
71 | fetch_nntp_code(char *line) | |
71 | 72 | { |
72 | 73 | char ch; |
73 | 74 | const char *errstr; |
89 | 90 | } |
90 | 91 | |
91 | 92 | char * |
92 | nntp_line(struct account *a, char **lbuf, size_t *llen) | |
93 | fetch_nntp_line(struct account *a, char **lbuf, size_t *llen) | |
93 | 94 | { |
94 | 95 | struct fetch_nntp_data *data = a->data; |
95 | 96 | char *line, *cause; |
108 | 109 | } |
109 | 110 | |
110 | 111 | 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, ...) | |
112 | 114 | { |
113 | 115 | char *line; |
114 | 116 | va_list ap; |
119 | 121 | cdp = &code; |
120 | 122 | |
121 | 123 | do { |
122 | if ((line = nntp_line(a, lbuf, llen)) == NULL) | |
124 | if ((line = fetch_nntp_line(a, lbuf, llen)) == NULL) | |
123 | 125 | return (NULL); |
124 | 126 | |
125 | *cdp = nntp_code(line); | |
127 | *cdp = fetch_nntp_code(line); | |
126 | 128 | if (*cdp == -1) |
127 | 129 | goto error; |
128 | 130 | } while (*cdp >= 100 && *cdp <= 199); |
145 | 147 | } |
146 | 148 | |
147 | 149 | int |
148 | nntp_parse223(char *line, u_int *n, char **id) | |
150 | fetch_nntp_parse223(char *line, u_int *n, char **id) | |
149 | 151 | { |
150 | 152 | char *ptr, *ptr2; |
151 | 153 | |
168 | 170 | } |
169 | 171 | |
170 | 172 | int |
171 | nntp_group(struct account *a, char **lbuf, size_t *llen) | |
173 | fetch_nntp_group(struct account *a, char **lbuf, size_t *llen) | |
172 | 174 | { |
173 | 175 | struct fetch_nntp_data *data = a->data; |
174 | 176 | struct fetch_nntp_group *group; |
179 | 181 | log_debug("%s: fetching group: %s", a->name, group->name); |
180 | 182 | |
181 | 183 | 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) | |
183 | 185 | return (1); |
184 | 186 | if (sscanf(line, "211 %u %*u %u", &group->size, &last) != 2) { |
185 | 187 | log_warnx("%s: invalid response: %s", a->name, line); |
194 | 196 | group->size = last - group->last; |
195 | 197 | |
196 | 198 | 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) | |
201 | 203 | goto invalid; |
202 | 204 | if (n != group->last) { |
203 | 205 | log_warnx("%s: unexpected message number", a->name); |
217 | 219 | log_warnx("%s: last message not found. resetting group", a->name); |
218 | 220 | |
219 | 221 | 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) | |
221 | 223 | return (1); |
222 | 224 | if (sscanf(line, "211 %u %*u %*u", &group->size) != 1) { |
223 | 225 | log_warnx("%s: invalid response: %s", a->name, line); |
234 | 236 | } |
235 | 237 | |
236 | 238 | int |
237 | nntp_load(struct account *a) | |
239 | fetch_nntp_load(struct account *a) | |
238 | 240 | { |
239 | 241 | struct fetch_nntp_data *data = a->data; |
240 | 242 | struct fetch_nntp_group *group; |
288 | 290 | break; |
289 | 291 | } |
290 | 292 | 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 | */ | |
293 | 297 | group = xcalloc(1, sizeof *group); |
294 | 298 | ADD_GROUP(data, group); |
295 | 299 | group->ignore = 1; |
319 | 323 | } |
320 | 324 | |
321 | 325 | int |
322 | nntp_save(struct account *a) | |
326 | fetch_nntp_save(struct account *a) | |
323 | 327 | { |
324 | 328 | struct fetch_nntp_data *data = a->data; |
325 | 329 | struct fetch_nntp_group *group; |
428 | 432 | llen = IO_LINESIZE; |
429 | 433 | lbuf = xmalloc(llen); |
430 | 434 | |
431 | if (nntp_load(a) != 0) | |
435 | if (fetch_nntp_load(a) != 0) | |
432 | 436 | goto error; |
433 | 437 | data->group = 0; |
434 | 438 | if (CURRENT_GROUP(data)->ignore) { |
441 | 445 | } while (CURRENT_GROUP(data)->ignore); |
442 | 446 | } |
443 | 447 | |
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) | |
448 | 452 | goto error; |
449 | 453 | |
450 | 454 | xfree(lbuf); |
468 | 472 | char *lbuf, *line; |
469 | 473 | size_t llen; |
470 | 474 | |
471 | nntp_save(a); | |
475 | fetch_nntp_save(a); | |
472 | 476 | |
473 | 477 | llen = IO_LINESIZE; |
474 | 478 | lbuf = xmalloc(llen); |
475 | 479 | |
476 | 480 | 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) | |
478 | 482 | goto error; |
479 | 483 | |
480 | 484 | io_close(data->io); |
512 | 516 | if (CURRENT_GROUP(data)->ignore) |
513 | 517 | continue; |
514 | 518 | |
515 | if (nntp_group(a, &lbuf, &llen) != 0) | |
519 | if (fetch_nntp_group(a, &lbuf, &llen) != 0) | |
516 | 520 | goto error; |
517 | 521 | (*n) += CURRENT_GROUP(data)->size; |
518 | 522 | } |
540 | 544 | |
541 | 545 | restart: |
542 | 546 | 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) | |
544 | 549 | goto error; |
545 | 550 | if (code == 421) { |
546 | 551 | do { |
550 | 555 | return (FETCH_COMPLETE); |
551 | 556 | } |
552 | 557 | } while (CURRENT_GROUP(data)->ignore); |
553 | if (nntp_group(a, &lbuf, &llen) != 0) | |
558 | if (fetch_nntp_group(a, &lbuf, &llen) != 0) | |
554 | 559 | goto error; |
555 | 560 | goto restart; |
556 | 561 | } |
557 | 562 | |
558 | 563 | /* fill this in as the last article */ |
559 | if (nntp_parse223(line, &n, &id) != 0) { | |
564 | if (fetch_nntp_parse223(line, &n, &id) != 0) { | |
560 | 565 | log_warnx("%s: malformed response: %s", a->name, line); |
561 | 566 | goto restart; |
562 | 567 | } |
572 | 577 | |
573 | 578 | /* retrieve the article */ |
574 | 579 | 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); | |
576 | 581 | if (line == NULL) |
577 | 582 | goto error; |
578 | 583 | if (code == 423 || code == 430) |
587 | 592 | flushing = 0; |
588 | 593 | off = lines = 0; |
589 | 594 | for (;;) { |
590 | if ((line = nntp_line(a, &lbuf, &llen)) == NULL) | |
595 | if ((line = fetch_nntp_line(a, &lbuf, &llen)) == NULL) | |
591 | 596 | goto error; |
592 | 597 | |
593 | 598 | if (line[0] == '.' && line[1] == '.') |
37 | 37 | int fetch_pop3_keep(struct account *); |
38 | 38 | void fetch_pop3_desc(struct account *, char *, size_t); |
39 | 39 | |
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 *); | |
42 | 42 | |
43 | 43 | struct fetch fetch_pop3 = { |
44 | 44 | { "pop3", "pop3s" }, |
55 | 55 | }; |
56 | 56 | |
57 | 57 | char * |
58 | pop3_line(struct account *a, char **lbuf, size_t *llen) | |
58 | fetch_pop3_line(struct account *a, char **lbuf, size_t *llen) | |
59 | 59 | { |
60 | 60 | struct fetch_pop3_data *data = a->data; |
61 | 61 | char *line, *cause; |
74 | 74 | } |
75 | 75 | |
76 | 76 | char * |
77 | pop3_check(struct account *a, char **lbuf, size_t *llen) | |
77 | fetch_pop3_check(struct account *a, char **lbuf, size_t *llen) | |
78 | 78 | { |
79 | 79 | char *line; |
80 | 80 | |
81 | if ((line = pop3_line(a, lbuf, llen)) == NULL) | |
81 | if ((line = fetch_pop3_line(a, lbuf, llen)) == NULL) | |
82 | 82 | return (NULL); |
83 | 83 | |
84 | 84 | if (strncmp(line, "+OK", 3) != 0) { |
135 | 135 | llen = IO_LINESIZE; |
136 | 136 | lbuf = xmalloc(llen); |
137 | 137 | |
138 | if (pop3_check(a, &lbuf, &llen) == NULL) | |
138 | if (fetch_pop3_check(a, &lbuf, &llen) == NULL) | |
139 | 139 | goto error; |
140 | 140 | |
141 | 141 | /* log the user in */ |
142 | 142 | 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) | |
144 | 144 | goto error; |
145 | 145 | 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) | |
147 | 147 | goto error; |
148 | 148 | |
149 | 149 | /* find the number of messages */ |
150 | 150 | io_writeline(data->io, "STAT"); |
151 | if ((line = pop3_check(a, &lbuf, &llen)) == NULL) | |
151 | if ((line = fetch_pop3_check(a, &lbuf, &llen)) == NULL) | |
152 | 152 | goto error; |
153 | 153 | if (sscanf(line, "+OK %u %*u", &data->num) != 1) { |
154 | 154 | log_warnx("%s: invalid response: %s", a->name, line); |
181 | 181 | lbuf = xmalloc(llen); |
182 | 182 | |
183 | 183 | io_writeline(data->io, "QUIT"); |
184 | if (pop3_check(a, &lbuf, &llen) == NULL) | |
184 | if (fetch_pop3_check(a, &lbuf, &llen) == NULL) | |
185 | 185 | goto error; |
186 | 186 | |
187 | 187 | io_close(data->io); |
230 | 230 | restart: |
231 | 231 | /* list the current message to get its size */ |
232 | 232 | 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) | |
234 | 234 | goto error; |
235 | 235 | if (sscanf(line, "+OK %*u %zu", &size) != 1) { |
236 | 236 | log_warnx("%s: invalid response: %s", a->name, line); |
248 | 248 | |
249 | 249 | /* find and store the UID */ |
250 | 250 | 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) | |
252 | 252 | goto error; |
253 | 253 | if (sscanf(line, "+OK %u ", &n) != 1) { |
254 | 254 | log_warnx("%s: invalid response: %s", a->name, line); |
288 | 288 | |
289 | 289 | /* retrieve the message */ |
290 | 290 | 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) | |
292 | 292 | goto error; |
293 | 293 | |
294 | 294 | mail_open(m, IO_ROUND(size)); |
301 | 301 | off = lines = 0; |
302 | 302 | bodylines = -1; |
303 | 303 | for (;;) { |
304 | if ((line = pop3_line(a, &lbuf, &llen)) == NULL) | |
304 | if ((line = fetch_pop3_line(a, &lbuf, &llen)) == NULL) | |
305 | 305 | goto error; |
306 | 306 | |
307 | 307 | if (line[0] == '.' && line[1] == '.') |
376 | 376 | lbuf = xmalloc(llen); |
377 | 377 | |
378 | 378 | 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) | |
380 | 380 | goto error; |
381 | 381 | |
382 | 382 | xfree(lbuf); |
27 | 27 | int match_age_match(struct match_ctx *, struct expritem *); |
28 | 28 | void match_age_desc(struct expritem *, char *, size_t); |
29 | 29 | |
30 | int age_tzlookup(const char *, int *); | |
30 | int match_age_tzlookup(const char *, int *); | |
31 | 31 | |
32 | 32 | struct match match_age = { |
33 | 33 | match_age_match, |
42 | 42 | * using tzset, which catches the few most common abbreviations. |
43 | 43 | */ |
44 | 44 | int |
45 | age_tzlookup(const char *tz, int *off) | |
45 | match_age_tzlookup(const char *tz, int *off) | |
46 | 46 | { |
47 | 47 | char *saved_tz; |
48 | 48 | struct tm *tm; |
130 | 130 | tz = strtonum(endptr, -2359, 2359, &errstr); |
131 | 131 | if (errstr != NULL) { |
132 | 132 | /* try it using tzset */ |
133 | if (age_tzlookup(endptr, &tz) != 0) { | |
133 | if (match_age_tzlookup(endptr, &tz) != 0) { | |
134 | 134 | xfree(s); |
135 | 135 | goto invalid; |
136 | 136 | } |