Mass renaming round 1. Move some stuff into new header files.
Nicholas Marriott
17 years ago
28 | 28 | #include <unistd.h> |
29 | 29 | |
30 | 30 | #include "fdm.h" |
31 | #include "deliver.h" | |
32 | #include "fetch.h" | |
33 | #include "match.h" | |
31 | 34 | |
32 | 35 | int poll_account(struct io *, struct account *); |
33 | 36 | int fetch_account(struct io *, struct account *, double); |
20 | 20 | #include <string.h> |
21 | 21 | |
22 | 22 | #include "fdm.h" |
23 | #include "deliver.h" | |
23 | 24 | |
24 | int add_header_deliver(struct deliver_ctx *, struct action *); | |
25 | void add_header_desc(struct action *, char *, size_t); | |
25 | int deliver_add_header_deliver(struct deliver_ctx *, struct action *); | |
26 | void deliver_add_header_desc(struct action *, char *, size_t); | |
26 | 27 | |
27 | struct deliver deliver_add_header = { DELIVER_INCHILD, | |
28 | add_header_deliver, | |
29 | add_header_desc }; | |
28 | struct deliver deliver_add_header = { | |
29 | DELIVER_INCHILD, | |
30 | deliver_add_header_deliver, | |
31 | deliver_add_header_desc | |
32 | }; | |
30 | 33 | |
31 | 34 | int |
32 | add_header_deliver(struct deliver_ctx *dctx, struct action *t) | |
35 | deliver_add_header_deliver(struct deliver_ctx *dctx, struct action *t) | |
33 | 36 | { |
34 | 37 | struct account *a = dctx->account; |
35 | 38 | struct mail *m = dctx->mail; |
61 | 64 | } |
62 | 65 | |
63 | 66 | void |
64 | add_header_desc(struct action *t, char *buf, size_t len) | |
67 | deliver_add_header_desc(struct action *t, char *buf, size_t len) | |
65 | 68 | { |
66 | 69 | struct add_header_data *data = t->data; |
67 | 70 |
21 | 21 | #include <vis.h> |
22 | 22 | |
23 | 23 | #include "fdm.h" |
24 | #include "deliver.h" | |
24 | 25 | |
25 | int append_string_deliver(struct deliver_ctx *, struct action *); | |
26 | void append_string_desc(struct action *, char *, size_t); | |
26 | int deliver_append_string_deliver(struct deliver_ctx *, struct action *); | |
27 | void deliver_append_string_desc(struct action *, char *, size_t); | |
27 | 28 | |
28 | struct deliver deliver_append_string = { DELIVER_INCHILD, | |
29 | append_string_deliver, | |
30 | append_string_desc }; | |
29 | struct deliver deliver_append_string = { | |
30 | DELIVER_INCHILD, | |
31 | deliver_append_string_deliver, | |
32 | deliver_append_string_desc | |
33 | }; | |
31 | 34 | |
32 | 35 | int |
33 | append_string_deliver(struct deliver_ctx *dctx, struct action *t) | |
36 | deliver_append_string_deliver(struct deliver_ctx *dctx, struct action *t) | |
34 | 37 | { |
35 | 38 | struct mail *m = dctx->mail; |
36 | 39 | char *ptr = t->data; |
45 | 48 | } |
46 | 49 | |
47 | 50 | void |
48 | append_string_desc(struct action *t, char *buf, size_t len) | |
51 | deliver_append_string_desc(struct action *t, char *buf, size_t len) | |
49 | 52 | { |
50 | 53 | size_t sz; |
51 | 54 |
24 | 24 | #include <unistd.h> |
25 | 25 | |
26 | 26 | #include "fdm.h" |
27 | #include "deliver.h" | |
27 | 28 | |
28 | int append_deliver(struct deliver_ctx *, struct action *); | |
29 | void append_desc(struct action *, char *, size_t); | |
29 | int deliver_append_deliver(struct deliver_ctx *, struct action *); | |
30 | void deliver_append_desc(struct action *, char *, size_t); | |
30 | 31 | |
31 | struct deliver deliver_append = { DELIVER_ASUSER, append_deliver, append_desc }; | |
32 | struct deliver deliver_append = { | |
33 | DELIVER_ASUSER, | |
34 | deliver_append_deliver, | |
35 | deliver_append_desc | |
36 | }; | |
32 | 37 | |
33 | 38 | int |
34 | append_deliver(struct deliver_ctx *dctx, struct action *t) | |
39 | deliver_append_deliver(struct deliver_ctx *dctx, struct action *t) | |
35 | 40 | { |
36 | 41 | return (do_write(dctx, t, 1)); |
37 | 42 | } |
38 | 43 | |
39 | 44 | void |
40 | append_desc(struct action *t, char *buf, size_t len) | |
45 | deliver_append_desc(struct action *t, char *buf, size_t len) | |
41 | 46 | { |
42 | 47 | xsnprintf(buf, len, "append \"%s\"", (char *) t->data); |
43 | 48 | } |
20 | 20 | #include <string.h> |
21 | 21 | |
22 | 22 | #include "fdm.h" |
23 | #include "deliver.h" | |
23 | 24 | |
24 | int drop_deliver(struct deliver_ctx *, struct action *); | |
25 | void drop_desc(struct action *, char *, size_t); | |
25 | int deliver_drop_deliver(struct deliver_ctx *, struct action *); | |
26 | void deliver_drop_desc(struct action *, char *, size_t); | |
26 | 27 | |
27 | struct deliver deliver_drop = { DELIVER_INCHILD, drop_deliver, drop_desc }; | |
28 | struct deliver deliver_drop = { | |
29 | DELIVER_INCHILD, | |
30 | deliver_drop_deliver, | |
31 | deliver_drop_desc | |
32 | }; | |
28 | 33 | |
29 | 34 | int |
30 | drop_deliver(struct deliver_ctx *dctx, unused struct action *t) | |
35 | deliver_drop_deliver(struct deliver_ctx *dctx, unused struct action *t) | |
31 | 36 | { |
32 | 37 | *dctx->decision = DECISION_DROP; |
33 | 38 | |
35 | 40 | } |
36 | 41 | |
37 | 42 | void |
38 | drop_desc(unused struct action *t, char *buf, size_t len) | |
43 | deliver_drop_desc(unused struct action *t, char *buf, size_t len) | |
39 | 44 | { |
40 | 45 | strlcpy(buf, "drop", len); |
41 | 46 | } |
24 | 24 | #include <unistd.h> |
25 | 25 | |
26 | 26 | #include "fdm.h" |
27 | #include "deliver.h" | |
27 | 28 | |
28 | int exec_deliver(struct deliver_ctx *, struct action *); | |
29 | void exec_desc(struct action *, char *, size_t); | |
29 | int deliver_exec_deliver(struct deliver_ctx *, struct action *); | |
30 | void deliver_exec_desc(struct action *, char *, size_t); | |
30 | 31 | |
31 | struct deliver deliver_exec = { DELIVER_ASUSER, exec_deliver, exec_desc }; | |
32 | struct deliver deliver_exec = { | |
33 | DELIVER_ASUSER, | |
34 | deliver_exec_deliver, | |
35 | deliver_exec_desc | |
36 | }; | |
32 | 37 | |
33 | 38 | int |
34 | exec_deliver(struct deliver_ctx *dctx, struct action *t) | |
39 | deliver_exec_deliver(struct deliver_ctx *dctx, struct action *t) | |
35 | 40 | { |
36 | 41 | return (do_pipe(dctx, t, 0)); |
37 | 42 | } |
38 | 43 | |
39 | 44 | void |
40 | exec_desc(struct action *t, char *buf, size_t len) | |
45 | deliver_exec_desc(struct action *t, char *buf, size_t len) | |
41 | 46 | { |
42 | 47 | xsnprintf(buf, len, "exec \"%s\"", (char *) t->data); |
43 | 48 | } |
20 | 20 | #include <string.h> |
21 | 21 | |
22 | 22 | #include "fdm.h" |
23 | #include "deliver.h" | |
23 | 24 | |
24 | int keep_deliver(struct deliver_ctx *, struct action *); | |
25 | void keep_desc(struct action *, char *, size_t); | |
25 | int deliver_keep_deliver(struct deliver_ctx *, struct action *); | |
26 | void deliver_keep_desc(struct action *, char *, size_t); | |
26 | 27 | |
27 | struct deliver deliver_keep = { DELIVER_INCHILD, keep_deliver, keep_desc }; | |
28 | struct deliver deliver_keep = { | |
29 | DELIVER_INCHILD, | |
30 | deliver_keep_deliver, | |
31 | deliver_keep_desc | |
32 | }; | |
28 | 33 | |
29 | 34 | int |
30 | keep_deliver(struct deliver_ctx *dctx, unused struct action *t) | |
35 | deliver_keep_deliver(struct deliver_ctx *dctx, unused struct action *t) | |
31 | 36 | { |
32 | 37 | *dctx->decision = DECISION_KEEP; |
33 | 38 | |
35 | 40 | } |
36 | 41 | |
37 | 42 | void |
38 | keep_desc(unused struct action *t, char *buf, size_t len) | |
43 | deliver_keep_desc(unused struct action *t, char *buf, size_t len) | |
39 | 44 | { |
40 | 45 | strlcpy(buf, "keep", len); |
41 | 46 | } |
27 | 27 | #include <unistd.h> |
28 | 28 | |
29 | 29 | #include "fdm.h" |
30 | ||
31 | int maildir_deliver(struct deliver_ctx *, struct action *); | |
32 | void maildir_desc(struct action *, char *, size_t); | |
33 | ||
34 | struct deliver deliver_maildir = { DELIVER_ASUSER, maildir_deliver, | |
35 | maildir_desc }; | |
30 | #include "deliver.h" | |
31 | ||
32 | int deliver_maildir_deliver(struct deliver_ctx *, struct action *); | |
33 | void deliver_maildir_desc(struct action *, char *, size_t); | |
34 | ||
35 | struct deliver deliver_maildir = { | |
36 | DELIVER_ASUSER, | |
37 | deliver_maildir_deliver, | |
38 | deliver_maildir_desc | |
39 | }; | |
36 | 40 | |
37 | 41 | int |
38 | maildir_deliver(struct deliver_ctx *dctx, struct action *t) | |
42 | deliver_maildir_deliver(struct deliver_ctx *dctx, struct action *t) | |
39 | 43 | { |
40 | 44 | struct account *a = dctx->account; |
41 | 45 | struct mail *m = dctx->mail; |
228 | 232 | } |
229 | 233 | |
230 | 234 | void |
231 | maildir_desc(struct action *t, char *buf, size_t len) | |
235 | deliver_maildir_desc(struct action *t, char *buf, size_t len) | |
232 | 236 | { |
233 | 237 | xsnprintf(buf, len, "maildir \"%s\"", (char *) t->data); |
234 | 238 | } |
27 | 27 | #include <unistd.h> |
28 | 28 | |
29 | 29 | #include "fdm.h" |
30 | #include "deliver.h" | |
30 | 31 | |
31 | 32 | /* With gcc 2.95.x, you can't include zlib.h before openssl.h. */ |
32 | 33 | #include <zlib.h> |
33 | 34 | |
34 | int mbox_deliver(struct deliver_ctx *, struct action *); | |
35 | void mbox_desc(struct action *, char *, size_t); | |
35 | int deliver_mbox_deliver(struct deliver_ctx *, struct action *); | |
36 | void deliver_mbox_desc(struct action *, char *, size_t); | |
36 | 37 | |
37 | 38 | int mbox_write(int, gzFile, const void *, size_t); |
38 | 39 | |
39 | struct deliver deliver_mbox = { DELIVER_ASUSER, mbox_deliver, mbox_desc }; | |
40 | struct deliver deliver_mbox = { | |
41 | DELIVER_ASUSER, | |
42 | deliver_mbox_deliver, | |
43 | deliver_mbox_desc | |
44 | }; | |
40 | 45 | |
41 | 46 | int |
42 | 47 | mbox_write(int fd, gzFile gzf, const void *buf, size_t len) |
59 | 64 | } |
60 | 65 | |
61 | 66 | int |
62 | mbox_deliver(struct deliver_ctx *dctx, struct action *t) | |
67 | deliver_mbox_deliver(struct deliver_ctx *dctx, struct action *t) | |
63 | 68 | { |
64 | 69 | struct account *a = dctx->account; |
65 | 70 | struct mail *m = dctx->mail; |
193 | 198 | } |
194 | 199 | |
195 | 200 | void |
196 | mbox_desc(struct action *t, char *buf, size_t len) | |
201 | deliver_mbox_desc(struct action *t, char *buf, size_t len) | |
197 | 202 | { |
198 | 203 | struct mbox_data *data = t->data; |
199 | 204 |
24 | 24 | #include <unistd.h> |
25 | 25 | |
26 | 26 | #include "fdm.h" |
27 | #include "deliver.h" | |
27 | 28 | |
28 | int pipe_deliver(struct deliver_ctx *, struct action *); | |
29 | void pipe_desc(struct action *, char *, size_t); | |
29 | int deliver_pipe_deliver(struct deliver_ctx *, struct action *); | |
30 | void deliver_pipe_desc(struct action *, char *, size_t); | |
30 | 31 | |
31 | struct deliver deliver_pipe = { DELIVER_ASUSER, pipe_deliver, pipe_desc }; | |
32 | struct deliver deliver_pipe = { | |
33 | DELIVER_ASUSER, | |
34 | deliver_pipe_deliver, | |
35 | deliver_pipe_desc | |
36 | }; | |
32 | 37 | |
33 | 38 | int |
34 | pipe_deliver(struct deliver_ctx *dctx, struct action *t) | |
39 | deliver_pipe_deliver(struct deliver_ctx *dctx, struct action *t) | |
35 | 40 | { |
36 | 41 | return (do_pipe(dctx, t, 1)); |
37 | 42 | } |
38 | 43 | |
39 | 44 | void |
40 | pipe_desc(struct action *t, char *buf, size_t len) | |
45 | deliver_pipe_desc(struct action *t, char *buf, size_t len) | |
41 | 46 | { |
42 | 47 | xsnprintf(buf, len, "pipe \"%s\"", (char *) t->data); |
43 | 48 | } |
20 | 20 | #include <string.h> |
21 | 21 | |
22 | 22 | #include "fdm.h" |
23 | #include "deliver.h" | |
23 | 24 | |
24 | int remove_header_deliver(struct deliver_ctx *, struct action *); | |
25 | void remove_header_desc(struct action *, char *, size_t); | |
25 | int deliver_remove_header_deliver(struct deliver_ctx *, struct action *); | |
26 | void deliver_remove_header_desc(struct action *, char *, size_t); | |
26 | 27 | |
27 | struct deliver deliver_remove_header = { DELIVER_INCHILD, | |
28 | remove_header_deliver, | |
29 | remove_header_desc }; | |
28 | struct deliver deliver_remove_header = { | |
29 | DELIVER_INCHILD, | |
30 | deliver_remove_header_deliver, | |
31 | deliver_remove_header_desc | |
32 | }; | |
30 | 33 | |
31 | 34 | int |
32 | remove_header_deliver(struct deliver_ctx *dctx, struct action *t) | |
35 | deliver_remove_header_deliver(struct deliver_ctx *dctx, struct action *t) | |
33 | 36 | { |
34 | 37 | struct mail *m = dctx->mail; |
35 | 38 | char *ptr; |
77 | 80 | } |
78 | 81 | |
79 | 82 | void |
80 | remove_header_desc(struct action *t, char *buf, size_t len) | |
83 | deliver_remove_header_desc(struct action *t, char *buf, size_t len) | |
81 | 84 | { |
82 | 85 | xsnprintf(buf, len, "remove-header \"%s\"", (char *) t->data); |
83 | 86 | } |
26 | 26 | #include <unistd.h> |
27 | 27 | |
28 | 28 | #include "fdm.h" |
29 | #include "deliver.h" | |
29 | 30 | |
30 | int rewrite_deliver(struct deliver_ctx *, struct action *); | |
31 | void rewrite_desc(struct action *, char *, size_t); | |
31 | int deliver_rewrite_deliver(struct deliver_ctx *, struct action *); | |
32 | void deliver_rewrite_desc(struct action *, char *, size_t); | |
32 | 33 | |
33 | struct deliver deliver_rewrite = { DELIVER_WRBACK, rewrite_deliver, | |
34 | rewrite_desc }; | |
34 | struct deliver deliver_rewrite = { | |
35 | DELIVER_WRBACK, | |
36 | deliver_rewrite_deliver, | |
37 | deliver_rewrite_desc | |
38 | }; | |
35 | 39 | |
36 | 40 | int |
37 | rewrite_deliver(struct deliver_ctx *dctx, struct action *t) | |
41 | deliver_rewrite_deliver(struct deliver_ctx *dctx, struct action *t) | |
38 | 42 | { |
39 | 43 | struct account *a = dctx->account; |
40 | 44 | struct mail *m = dctx->mail; |
124 | 128 | } |
125 | 129 | |
126 | 130 | void |
127 | rewrite_desc(struct action *t, char *buf, size_t len) | |
131 | deliver_rewrite_desc(struct action *t, char *buf, size_t len) | |
128 | 132 | { |
129 | 133 | xsnprintf(buf, len, "rewrite \"%s\"", (char *) t->data); |
130 | 134 | } |
25 | 25 | #include <unistd.h> |
26 | 26 | |
27 | 27 | #include "fdm.h" |
28 | ||
29 | int smtp_deliver(struct deliver_ctx *, struct action *); | |
30 | void smtp_desc(struct action *, char *, size_t); | |
28 | #include "deliver.h" | |
29 | ||
30 | int deliver_smtp_deliver(struct deliver_ctx *, struct action *); | |
31 | void deliver_smtp_desc(struct action *, char *, size_t); | |
31 | 32 | |
32 | 33 | int smtp_code(char *); |
33 | 34 | |
34 | struct deliver deliver_smtp = { DELIVER_ASUSER, smtp_deliver, smtp_desc }; | |
35 | struct deliver deliver_smtp = { | |
36 | DELIVER_ASUSER, | |
37 | deliver_smtp_deliver, | |
38 | deliver_smtp_desc | |
39 | }; | |
35 | 40 | |
36 | 41 | int |
37 | 42 | smtp_code(char *line) |
56 | 61 | } |
57 | 62 | |
58 | 63 | int |
59 | smtp_deliver(struct deliver_ctx *dctx, struct action *t) | |
64 | deliver_smtp_deliver(struct deliver_ctx *dctx, struct action *t) | |
60 | 65 | { |
61 | 66 | struct account *a = dctx->account; |
62 | 67 | struct mail *m = dctx->mail; |
189 | 194 | } |
190 | 195 | |
191 | 196 | void |
192 | smtp_desc(struct action *t, char *buf, size_t len) | |
197 | deliver_smtp_desc(struct action *t, char *buf, size_t len) | |
193 | 198 | { |
194 | 199 | struct smtp_data *data = t->data; |
195 | 200 |
21 | 21 | #include <string.h> |
22 | 22 | |
23 | 23 | #include "fdm.h" |
24 | #include "deliver.h" | |
24 | 25 | |
25 | int stdout_deliver(struct deliver_ctx *, struct action *); | |
26 | void stdout_desc(struct action *, char *, size_t); | |
26 | int deliver_stdout_deliver(struct deliver_ctx *, struct action *); | |
27 | void deliver_stdout_desc(struct action *, char *, size_t); | |
27 | 28 | |
28 | struct deliver deliver_stdout = { DELIVER_INCHILD, | |
29 | stdout_deliver, | |
30 | stdout_desc }; | |
29 | struct deliver deliver_stdout = { | |
30 | DELIVER_INCHILD, | |
31 | deliver_stdout_deliver, | |
32 | deliver_stdout_desc | |
33 | }; | |
31 | 34 | |
32 | 35 | int |
33 | stdout_deliver(struct deliver_ctx *dctx, struct action *t) | |
36 | deliver_stdout_deliver(struct deliver_ctx *dctx, struct action *t) | |
34 | 37 | { |
35 | 38 | struct account *a = dctx->account; |
36 | 39 | struct mail *m = dctx->mail; |
63 | 66 | } |
64 | 67 | |
65 | 68 | void |
66 | stdout_desc(struct action *t, char *buf, size_t len) | |
69 | deliver_stdout_desc(struct action *t, char *buf, size_t len) | |
67 | 70 | { |
68 | 71 | struct stdout_data *data = t->data; |
69 | 72 |
24 | 24 | #include <unistd.h> |
25 | 25 | |
26 | 26 | #include "fdm.h" |
27 | #include "deliver.h" | |
27 | 28 | |
28 | int write_deliver(struct deliver_ctx *, struct action *); | |
29 | void write_desc(struct action *, char *, size_t); | |
29 | int deliver_write_deliver(struct deliver_ctx *, struct action *); | |
30 | void deliver_write_desc(struct action *, char *, size_t); | |
30 | 31 | |
31 | struct deliver deliver_write = { DELIVER_ASUSER, write_deliver, write_desc }; | |
32 | struct deliver deliver_write = { | |
33 | DELIVER_ASUSER, | |
34 | deliver_write_deliver, | |
35 | deliver_write_desc | |
36 | }; | |
32 | 37 | |
33 | 38 | int |
34 | write_deliver(struct deliver_ctx *dctx, struct action *t) | |
39 | deliver_write_deliver(struct deliver_ctx *dctx, struct action *t) | |
35 | 40 | { |
36 | 41 | return (do_write(dctx, t, 0)); |
37 | 42 | } |
38 | 43 | |
39 | 44 | void |
40 | write_desc(struct action *t, char *buf, size_t len) | |
45 | deliver_write_desc(struct action *t, char *buf, size_t len) | |
41 | 46 | { |
42 | 47 | xsnprintf(buf, len, "write \"%s\"", (char *) t->data); |
43 | 48 | } |
0 | /* $Id$ */ | |
1 | ||
2 | /* | |
3 | * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> | |
4 | * | |
5 | * Permission to use, copy, modify, and distribute this software for any | |
6 | * purpose with or without fee is hereby granted, provided that the above | |
7 | * copyright notice and this permission notice appear in all copies. | |
8 | * | |
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
13 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER | |
14 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING | |
15 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
16 | */ | |
17 | ||
18 | #ifndef DELIVER_H | |
19 | #define DELIVER_H | |
20 | ||
21 | /* Deliver return codes. */ | |
22 | #define DELIVER_SUCCESS 0 | |
23 | #define DELIVER_FAILURE 1 | |
24 | ||
25 | /* Deliver context. */ | |
26 | struct deliver_ctx { | |
27 | struct account *account; | |
28 | struct mail *mail; | |
29 | ||
30 | struct mail wr_mail; | |
31 | ||
32 | enum decision *decision; | |
33 | ||
34 | int *pm_valid; | |
35 | regmatch_t pm[NPMATCH]; | |
36 | }; | |
37 | ||
38 | /* Delivery types. */ | |
39 | enum delivertype { | |
40 | DELIVER_INCHILD, /* do not pass up to parent */ | |
41 | DELIVER_ASUSER, /* do pass up to parent to drop privs */ | |
42 | DELIVER_WRBACK /* modifies mail: pass up to parent and expect | |
43 | a new mail back */ | |
44 | }; | |
45 | ||
46 | /* Deliver functions. */ | |
47 | struct deliver { | |
48 | enum delivertype type; | |
49 | ||
50 | int (*deliver)(struct deliver_ctx *, struct action *); | |
51 | void (*desc)(struct action *, char *, size_t); | |
52 | }; | |
53 | ||
54 | /* Deliver smtp states. */ | |
55 | enum smtp_state { | |
56 | SMTP_CONNECTING, | |
57 | SMTP_HELO, | |
58 | SMTP_FROM, | |
59 | SMTP_TO, | |
60 | SMTP_DATA, | |
61 | SMTP_DONE, | |
62 | SMTP_QUIT | |
63 | }; | |
64 | ||
65 | /* Deliver smtp data. */ | |
66 | struct smtp_data { | |
67 | struct server server; | |
68 | char *to; | |
69 | }; | |
70 | ||
71 | /* Deliver mbox data. */ | |
72 | struct mbox_data { | |
73 | char *path; | |
74 | int compress; | |
75 | }; | |
76 | ||
77 | /* Deliver stdout data. */ | |
78 | struct stdout_data { | |
79 | int add_from; | |
80 | }; | |
81 | ||
82 | /* Deliver add-header data. */ | |
83 | struct add_header_data { | |
84 | char *hdr; | |
85 | char *value; | |
86 | }; | |
87 | ||
88 | /* deliver-smtp.c */ | |
89 | extern struct deliver deliver_smtp; | |
90 | ||
91 | /* deliver-smtp.c */ | |
92 | extern struct deliver deliver_stdout; | |
93 | ||
94 | /* deliver-pipe.c */ | |
95 | extern struct deliver deliver_pipe; | |
96 | int do_pipe(struct deliver_ctx *, struct action *, int); | |
97 | ||
98 | /* deliver-exec.c */ | |
99 | extern struct deliver deliver_exec; | |
100 | ||
101 | /* deliver-drop.c */ | |
102 | extern struct deliver deliver_drop; | |
103 | ||
104 | /* deliver-keep.c */ | |
105 | extern struct deliver deliver_keep; | |
106 | ||
107 | /* deliver-maildir.c */ | |
108 | extern struct deliver deliver_maildir; | |
109 | ||
110 | /* deliver-remove-header.c */ | |
111 | extern struct deliver deliver_remove_header; | |
112 | ||
113 | /* deliver-add-header.c */ | |
114 | extern struct deliver deliver_add_header; | |
115 | ||
116 | /* deliver-append-string.c */ | |
117 | extern struct deliver deliver_append_string; | |
118 | ||
119 | /* deliver-mbox.c */ | |
120 | extern struct deliver deliver_mbox; | |
121 | ||
122 | /* deliver-write.c */ | |
123 | extern struct deliver deliver_write; | |
124 | int do_write(struct deliver_ctx *, struct action *, int); | |
125 | ||
126 | /* deliver-append.c */ | |
127 | extern struct deliver deliver_append; | |
128 | ||
129 | /* deliver-rewrite.c */ | |
130 | extern struct deliver deliver_rewrite; | |
131 | ||
132 | #endif |
589 | 589 | struct io *io_err; |
590 | 590 | }; |
591 | 591 | |
592 | /* Poll return codes. */ | |
593 | #define POLL_SUCCESS FETCH_SUCCESS | |
594 | #define POLL_ERROR FETCH_ERROR | |
595 | ||
596 | /* Fetch return codes. */ | |
597 | #define FETCH_SUCCESS 0 | |
598 | #define FETCH_ERROR 1 | |
599 | #define FETCH_OVERSIZE 2 | |
600 | #define FETCH_COMPLETE 3 | |
601 | ||
602 | /* Fetch functions. */ | |
603 | struct fetch { | |
604 | const char *ports[2]; /* normal port, ssl port */ | |
605 | ||
606 | int (*init)(struct account *); | |
607 | int (*connect)(struct account *); | |
608 | int (*poll)(struct account *, u_int *); | |
609 | int (*fetch)(struct account *, struct mail *); | |
610 | int (*purge)(struct account *); | |
611 | int (*delete)(struct account *); | |
612 | int (*keep)(struct account *); | |
613 | int (*disconnect)(struct account *); | |
614 | int (*free)(struct account *); | |
615 | void (*desc)(struct account *, char *, size_t); | |
616 | }; | |
617 | ||
618 | /* Deliver context. */ | |
619 | struct deliver_ctx { | |
620 | struct account *account; | |
621 | struct mail *mail; | |
622 | ||
623 | struct mail wr_mail; | |
624 | ||
625 | enum decision *decision; | |
626 | ||
627 | int *pm_valid; | |
628 | regmatch_t pm[NPMATCH]; | |
629 | }; | |
630 | ||
631 | /* Deliver return codes. */ | |
632 | #define DELIVER_SUCCESS 0 | |
633 | #define DELIVER_FAILURE 1 | |
634 | ||
635 | /* Delivery types. */ | |
636 | enum delivertype { | |
637 | DELIVER_INCHILD, /* do not pass up to parent */ | |
638 | DELIVER_ASUSER, /* do pass up to parent to drop privs */ | |
639 | DELIVER_WRBACK /* modifies mail: pass up to parent and expect | |
640 | a new mail back */ | |
641 | }; | |
642 | ||
643 | /* Deliver functions. */ | |
644 | struct deliver { | |
645 | enum delivertype type; | |
646 | ||
647 | int (*deliver)(struct deliver_ctx *, struct action *); | |
648 | void (*desc)(struct action *, char *, size_t); | |
649 | }; | |
650 | ||
651 | #define MATCH_FALSE 0 | |
652 | #define MATCH_TRUE 1 | |
653 | #define MATCH_ERROR 2 | |
654 | ||
655 | /* Match context. */ | |
656 | struct match_ctx { | |
657 | struct io *io; | |
658 | struct account *account; | |
659 | struct mail *mail; | |
660 | ||
661 | enum decision decision; | |
662 | ||
663 | int matched; | |
664 | int stopped; | |
665 | ||
666 | int pm_valid; | |
667 | regmatch_t pm[NPMATCH]; | |
668 | }; | |
669 | ||
670 | /* Match functions. */ | |
671 | struct match { | |
672 | int (*match)(struct match_ctx *, struct expritem *); | |
673 | void (*desc)(struct expritem *, char *, size_t); | |
674 | }; | |
675 | ||
676 | 592 | /* Privsep message types. */ |
677 | 593 | enum msgtype { |
678 | 594 | MSG_ACTION, |
714 | 630 | CMP_LT, |
715 | 631 | CMP_GT |
716 | 632 | }; |
717 | ||
718 | /* Match attachment data. */ | |
719 | struct attachment_data { | |
720 | enum { | |
721 | ATTACHOP_COUNT, | |
722 | ATTACHOP_TOTALSIZE, | |
723 | ATTACHOP_ANYSIZE, | |
724 | ATTACHOP_ANYTYPE, | |
725 | ATTACHOP_ANYNAME | |
726 | } op; | |
727 | ||
728 | enum cmp cmp; | |
729 | union { | |
730 | size_t size; | |
731 | long long num; | |
732 | char *str; | |
733 | struct re re; | |
734 | } value; | |
735 | }; | |
736 | ||
737 | /* Match age data. */ | |
738 | struct age_data { | |
739 | long long time; | |
740 | enum cmp cmp; | |
741 | }; | |
742 | ||
743 | /* Match size data. */ | |
744 | struct size_data { | |
745 | size_t size; | |
746 | enum cmp cmp; | |
747 | }; | |
748 | ||
749 | /* Match tagged data. */ | |
750 | struct tagged_data { | |
751 | char *tag; | |
752 | }; | |
753 | ||
754 | /* Match string data. */ | |
755 | struct string_data { | |
756 | struct re re; | |
757 | ||
758 | char *str; | |
759 | }; | |
760 | ||
761 | /* Match regexp data. */ | |
762 | struct regexp_data { | |
763 | struct re re; | |
764 | ||
765 | enum area area; | |
766 | }; | |
767 | ||
768 | /* Match command data. */ | |
769 | struct command_data { | |
770 | char *cmd; | |
771 | uid_t uid; | |
772 | int pipe; /* pipe mail to command */ | |
773 | ||
774 | struct re re; /* re->re NULL to not check */ | |
775 | int ret; /* -1 to not check */ | |
776 | }; | |
777 | ||
778 | /* Fetch maildir data. */ | |
779 | struct maildir_data { | |
780 | struct strings *maildirs; | |
781 | ||
782 | struct strings *paths; | |
783 | u_int index; | |
784 | ||
785 | DIR *dirp; | |
786 | char *path; | |
787 | char entry[MAXPATHLEN]; | |
788 | char maildir[MAXPATHLEN]; | |
789 | }; | |
790 | ||
791 | /* NNTP group entry. */ | |
792 | struct nntp_group { | |
793 | char *name; | |
794 | int ignore; | |
795 | ||
796 | u_int size; | |
797 | u_int last; | |
798 | char *id; | |
799 | }; | |
800 | ||
801 | /* NNTP group list. */ | |
802 | ARRAY_DECL(nntp_groups, struct nntp_group *); | |
803 | ||
804 | /* Fetch nntp data. */ | |
805 | struct nntp_data { | |
806 | char *path; | |
807 | ||
808 | struct server server; | |
809 | struct strings *names; | |
810 | ||
811 | u_int group; | |
812 | struct nntp_groups groups; | |
813 | ||
814 | struct io *io; | |
815 | }; | |
816 | #define GET_GROUP(d, i) ARRAY_ITEM(&d->groups, i, struct nntp_group *) | |
817 | #define CURRENT_GROUP(d) GET_GROUP(d, d->group) | |
818 | #define TOTAL_GROUPS(d) ARRAY_LENGTH(&d->groups) | |
819 | #define ADD_GROUP(d, g) ARRAY_ADD(&d->groups, g, struct nntp_group *) | |
820 | ||
821 | /* Fetch stdin data. */ | |
822 | struct stdin_data { | |
823 | int complete; | |
824 | ||
825 | struct io *io; | |
826 | }; | |
827 | ||
828 | /* Fetch pop3 data. */ | |
829 | struct pop3_data { | |
830 | char *user; | |
831 | char *pass; | |
832 | ||
833 | struct server server; | |
834 | ||
835 | u_int cur; | |
836 | u_int num; | |
837 | ||
838 | char *uid; | |
839 | struct strings kept; | |
840 | ||
841 | struct io *io; | |
842 | }; | |
843 | ||
844 | /* IMAP tag types. */ | |
845 | #define IMAP_TAG_NONE -1 | |
846 | #define IMAP_TAG_CONTINUE -2 | |
847 | #define IMAP_TAG_ERROR -3 | |
848 | ||
849 | /* IMAP line types. */ | |
850 | #define IMAP_TAGGED 0 | |
851 | #define IMAP_CONTINUE 1 | |
852 | #define IMAP_UNTAGGED 2 | |
853 | #define IMAP_RAW 3 | |
854 | ||
855 | /* Fetch imap data. */ | |
856 | struct imap_data { | |
857 | struct server server; | |
858 | char *pipecmd; | |
859 | ||
860 | struct io *io; | |
861 | struct cmd *cmd; | |
862 | ||
863 | char *user; | |
864 | char *pass; | |
865 | char *folder; | |
866 | ||
867 | int tag; | |
868 | u_int cur; | |
869 | u_int num; | |
870 | ||
871 | u_int uid; | |
872 | ARRAY_DECL(, u_int) kept; | |
873 | ||
874 | char *src; | |
875 | ||
876 | size_t llen; | |
877 | char *lbuf; | |
878 | ||
879 | char *(*getln)(struct account *a, int); | |
880 | int (*putln)(struct account *a, const char *, ...); | |
881 | void (*flush)(struct account *a); | |
882 | }; | |
883 | ||
884 | /* Deliver smtp states. */ | |
885 | enum smtp_state { | |
886 | SMTP_CONNECTING, | |
887 | SMTP_HELO, | |
888 | SMTP_FROM, | |
889 | SMTP_TO, | |
890 | SMTP_DATA, | |
891 | SMTP_DONE, | |
892 | SMTP_QUIT | |
893 | }; | |
894 | ||
895 | /* Deliver smtp data. */ | |
896 | struct smtp_data { | |
897 | struct server server; | |
898 | char *to; | |
899 | }; | |
900 | ||
901 | /* Deliver mbox data. */ | |
902 | struct mbox_data { | |
903 | char *path; | |
904 | int compress; | |
905 | }; | |
906 | ||
907 | /* Deliver stdout data. */ | |
908 | struct stdout_data { | |
909 | int add_from; | |
910 | }; | |
911 | ||
912 | /* Deliver add-header data. */ | |
913 | struct add_header_data { | |
914 | char *hdr; | |
915 | char *value; | |
916 | }; | |
917 | ||
918 | /* match-age.c */ | |
919 | extern struct match match_age; | |
920 | ||
921 | /* match-attachment.c */ | |
922 | extern struct match match_attachment; | |
923 | ||
924 | /* match-matched.c */ | |
925 | extern struct match match_matched; | |
926 | ||
927 | /* match-unmatched.c */ | |
928 | extern struct match match_unmatched; | |
929 | ||
930 | /* match-size.c */ | |
931 | extern struct match match_size; | |
932 | ||
933 | /* match-tagged.c */ | |
934 | extern struct match match_tagged; | |
935 | ||
936 | /* match-string.c */ | |
937 | extern struct match match_string; | |
938 | ||
939 | /* match-command.c */ | |
940 | extern struct match match_command; | |
941 | ||
942 | /* match-regexp.c */ | |
943 | extern struct match match_regexp; | |
944 | ||
945 | /* fetch-maildir.c */ | |
946 | extern struct fetch fetch_maildir; | |
947 | ||
948 | /* fetch-stdin.c */ | |
949 | extern struct fetch fetch_stdin; | |
950 | ||
951 | /* fetch-nntp.c */ | |
952 | extern struct fetch fetch_nntp; | |
953 | ||
954 | /* fetch-pop3.c */ | |
955 | extern struct fetch fetch_pop3; | |
956 | ||
957 | /* fetch-imap.c */ | |
958 | extern struct fetch fetch_imap; | |
959 | ||
960 | /* fetch-imappipe.c */ | |
961 | extern struct fetch fetch_imappipe; | |
962 | ||
963 | /* deliver-smtp.c */ | |
964 | extern struct deliver deliver_smtp; | |
965 | ||
966 | /* deliver-smtp.c */ | |
967 | extern struct deliver deliver_stdout; | |
968 | ||
969 | /* deliver-pipe.c */ | |
970 | extern struct deliver deliver_pipe; | |
971 | int do_pipe(struct deliver_ctx *, struct action *, int); | |
972 | ||
973 | /* deliver-exec.c */ | |
974 | extern struct deliver deliver_exec; | |
975 | ||
976 | /* deliver-drop.c */ | |
977 | extern struct deliver deliver_drop; | |
978 | ||
979 | /* deliver-keep.c */ | |
980 | extern struct deliver deliver_keep; | |
981 | ||
982 | /* deliver-maildir.c */ | |
983 | extern struct deliver deliver_maildir; | |
984 | ||
985 | /* deliver-remove-header.c */ | |
986 | extern struct deliver deliver_remove_header; | |
987 | ||
988 | /* deliver-add-header.c */ | |
989 | extern struct deliver deliver_add_header; | |
990 | ||
991 | /* deliver-append-string.c */ | |
992 | extern struct deliver deliver_append_string; | |
993 | ||
994 | /* deliver-mbox.c */ | |
995 | extern struct deliver deliver_mbox; | |
996 | ||
997 | /* deliver-write.c */ | |
998 | extern struct deliver deliver_write; | |
999 | int do_write(struct deliver_ctx *, struct action *, int); | |
1000 | ||
1001 | /* deliver-append.c */ | |
1002 | extern struct deliver deliver_append; | |
1003 | ||
1004 | /* deliver-rewrite.c */ | |
1005 | extern struct deliver deliver_rewrite; | |
1006 | 633 | |
1007 | 634 | #ifdef NO_SETRESUID |
1008 | 635 | #define setresuid(r, e, s) setreuid(r, e) |
20 | 20 | #include <unistd.h> |
21 | 21 | |
22 | 22 | #include "fdm.h" |
23 | #include "fetch.h" | |
23 | 24 | |
24 | int imap_connect(struct account *); | |
25 | int imap_disconnect(struct account *); | |
26 | void imap_desc(struct account *, char *, size_t); | |
25 | int fetch_imap_connect(struct account *); | |
26 | int fetch_imap_disconnect(struct account *); | |
27 | void fetch_imap_desc(struct account *, char *, size_t); | |
27 | 28 | |
28 | 29 | int printflike2 imap_putln(struct account *, const char *, ...); |
29 | 30 | char *imap_getln(struct account *, int); |
30 | 31 | void imap_flush(struct account *); |
31 | 32 | |
32 | struct fetch fetch_imap = { { "imap", "imaps" }, | |
33 | imap_init, /* from imap-common.c */ | |
34 | imap_connect, | |
35 | imap_poll, /* from imap-common.c */ | |
36 | imap_fetch, /* from imap-common.c */ | |
37 | imap_purge, /* from imap-common.c */ | |
38 | imap_delete, /* from imap-common.c */ | |
39 | imap_keep, /* from imap-common.c */ | |
40 | imap_disconnect, | |
41 | imap_free, /* from imap-common.c */ | |
42 | imap_desc | |
33 | struct fetch fetch_imap = { | |
34 | { "imap", "imaps" }, | |
35 | imap_init, /* from imap-common.c */ | |
36 | fetch_imap_connect, | |
37 | imap_poll, /* from imap-common.c */ | |
38 | imap_fetch, /* from imap-common.c */ | |
39 | imap_purge, /* from imap-common.c */ | |
40 | imap_delete, /* from imap-common.c */ | |
41 | imap_keep, /* from imap-common.c */ | |
42 | fetch_imap_disconnect, | |
43 | imap_free, /* from imap-common.c */ | |
44 | fetch_imap_desc | |
43 | 45 | }; |
44 | 46 | |
45 | 47 | int printflike2 |
116 | 118 | } |
117 | 119 | |
118 | 120 | int |
119 | imap_connect(struct account *a) | |
121 | fetch_imap_connect(struct account *a) | |
120 | 122 | { |
121 | 123 | struct imap_data *data = a->data; |
122 | 124 | char *cause; |
148 | 150 | } |
149 | 151 | |
150 | 152 | int |
151 | imap_disconnect(struct account *a) | |
153 | fetch_imap_disconnect(struct account *a) | |
152 | 154 | { |
153 | 155 | struct imap_data *data = a->data; |
154 | 156 | |
172 | 174 | } |
173 | 175 | |
174 | 176 | void |
175 | imap_desc(struct account *a, char *buf, size_t len) | |
177 | fetch_imap_desc(struct account *a, char *buf, size_t len) | |
176 | 178 | { |
177 | 179 | struct imap_data *data = a->data; |
178 | 180 |
20 | 20 | #include <unistd.h> |
21 | 21 | |
22 | 22 | #include "fdm.h" |
23 | #include "fetch.h" | |
23 | 24 | |
24 | int imappipe_connect(struct account *); | |
25 | int imappipe_disconnect(struct account *); | |
26 | void imappipe_desc(struct account *, char *, size_t); | |
25 | int fetch_imappipe_connect(struct account *); | |
26 | int fetch_imappipe_disconnect(struct account *); | |
27 | void fetch_imappipe_desc(struct account *, char *, size_t); | |
27 | 28 | |
28 | 29 | int printflike2 imappipe_putln(struct account *, const char *, ...); |
29 | 30 | char *imappipe_getln(struct account *, int); |
30 | 31 | void imappipe_flush(struct account *); |
31 | 32 | |
32 | struct fetch fetch_imappipe = { { NULL, NULL }, | |
33 | imap_init, /* from imap-common.c */ | |
34 | imappipe_connect, | |
35 | imap_poll, /* from imap-common.c */ | |
36 | imap_fetch, /* from imap-common.c */ | |
37 | imap_purge, /* from imap-common.c */ | |
38 | imap_delete, /* from imap-common.c */ | |
39 | imap_keep, /* from imap-common.c */ | |
40 | imappipe_disconnect, | |
41 | imap_free, /* from imap-common.c */ | |
42 | imappipe_desc, | |
33 | struct fetch fetch_imappipe = { | |
34 | { NULL, NULL }, | |
35 | imap_init, /* from imap-common.c */ | |
36 | fetch_imappipe_connect, | |
37 | imap_poll, /* from imap-common.c */ | |
38 | imap_fetch, /* from imap-common.c */ | |
39 | imap_purge, /* from imap-common.c */ | |
40 | imap_delete, /* from imap-common.c */ | |
41 | imap_keep, /* from imap-common.c */ | |
42 | fetch_imappipe_disconnect, | |
43 | imap_free, /* from imap-common.c */ | |
44 | fetch_imappipe_desc, | |
43 | 45 | }; |
44 | 46 | |
45 | 47 | int printflike2 |
123 | 125 | } |
124 | 126 | |
125 | 127 | int |
126 | imappipe_connect(struct account *a) | |
128 | fetch_imappipe_connect(struct account *a) | |
127 | 129 | { |
128 | 130 | struct imap_data *data = a->data; |
129 | 131 | char *cause; |
156 | 158 | } |
157 | 159 | |
158 | 160 | int |
159 | imappipe_disconnect(struct account *a) | |
161 | fetch_imappipe_disconnect(struct account *a) | |
160 | 162 | { |
161 | 163 | struct imap_data *data = a->data; |
162 | 164 | |
178 | 180 | } |
179 | 181 | |
180 | 182 | void |
181 | imappipe_desc(struct account *a, char *buf, size_t len) | |
183 | fetch_imappipe_desc(struct account *a, char *buf, size_t len) | |
182 | 184 | { |
183 | 185 | struct imap_data *data = a->data; |
184 | 186 |
29 | 29 | #include <unistd.h> |
30 | 30 | |
31 | 31 | #include "fdm.h" |
32 | ||
33 | int maildir_connect(struct account *); | |
34 | int maildir_disconnect(struct account *); | |
35 | int maildir_poll(struct account *, u_int *); | |
36 | int maildir_fetch(struct account *, struct mail *); | |
37 | int maildir_delete(struct account *); | |
38 | /* conflicts with deliver-maildir.c */ | |
39 | void maildir_desc2(struct account *, char *, size_t); | |
32 | #include "fetch.h" | |
33 | ||
34 | int fetch_maildir_connect(struct account *); | |
35 | int fetch_maildir_disconnect(struct account *); | |
36 | int fetch_maildir_poll(struct account *, u_int *); | |
37 | int fetch_maildir_fetch(struct account *, struct mail *); | |
38 | int fetch_maildir_delete(struct account *); | |
39 | void fetch_maildir_desc(struct account *, char *, size_t); | |
40 | 40 | |
41 | 41 | int maildir_makepaths(struct account *); |
42 | 42 | void maildir_freepaths(struct account *); |
43 | 43 | |
44 | struct fetch fetch_maildir = { { NULL, NULL }, | |
45 | NULL, | |
46 | maildir_connect, | |
47 | maildir_poll, | |
48 | maildir_fetch, | |
49 | NULL, | |
50 | maildir_delete, | |
51 | NULL, | |
52 | maildir_disconnect, | |
53 | NULL, | |
54 | maildir_desc2 | |
44 | struct fetch fetch_maildir = { | |
45 | { NULL, NULL }, | |
46 | NULL, | |
47 | fetch_maildir_connect, | |
48 | fetch_maildir_poll, | |
49 | fetch_maildir_fetch, | |
50 | NULL, | |
51 | fetch_maildir_delete, | |
52 | NULL, | |
53 | fetch_maildir_disconnect, | |
54 | NULL, | |
55 | fetch_maildir_desc | |
55 | 56 | }; |
56 | 57 | |
57 | 58 | /* Make an array of all the paths to visit. */ |
140 | 141 | } |
141 | 142 | |
142 | 143 | int |
143 | maildir_connect(struct account *a) | |
144 | fetch_maildir_connect(struct account *a) | |
144 | 145 | { |
145 | 146 | struct maildir_data *data = a->data; |
146 | 147 | |
156 | 157 | } |
157 | 158 | |
158 | 159 | int |
159 | maildir_poll(struct account *a, u_int *n) | |
160 | fetch_maildir_poll(struct account *a, u_int *n) | |
160 | 161 | { |
161 | 162 | struct maildir_data *data = a->data; |
162 | 163 | u_int i; |
201 | 202 | } |
202 | 203 | |
203 | 204 | int |
204 | maildir_fetch(struct account *a, struct mail *m) | |
205 | fetch_maildir_fetch(struct account *a, struct mail *m) | |
205 | 206 | { |
206 | 207 | struct maildir_data *data = a->data; |
207 | 208 | struct dirent *dp; |
294 | 295 | } |
295 | 296 | |
296 | 297 | int |
297 | maildir_delete(struct account *a) | |
298 | fetch_maildir_delete(struct account *a) | |
298 | 299 | { |
299 | 300 | struct maildir_data *data = a->data; |
300 | 301 | |
307 | 308 | } |
308 | 309 | |
309 | 310 | int |
310 | maildir_disconnect(struct account *a) | |
311 | fetch_maildir_disconnect(struct account *a) | |
311 | 312 | { |
312 | 313 | struct maildir_data *data = a->data; |
313 | 314 | |
320 | 321 | } |
321 | 322 | |
322 | 323 | void |
323 | maildir_desc2(struct account *a, char *buf, size_t len) | |
324 | fetch_maildir_desc(struct account *a, char *buf, size_t len) | |
324 | 325 | { |
325 | 326 | struct maildir_data *data = a->data; |
326 | 327 | char *maildirs; |
26 | 26 | #include <unistd.h> |
27 | 27 | |
28 | 28 | #include "fdm.h" |
29 | ||
30 | int nntp_init(struct account *); | |
31 | int nntp_free(struct account *); | |
32 | int nntp_connect(struct account *); | |
33 | int nntp_disconnect(struct account *); | |
34 | int nntp_poll(struct account *, u_int *); | |
35 | int nntp_fetch(struct account *, struct mail *); | |
36 | int nntp_delete(struct account *); | |
37 | int nntp_keep(struct account *); | |
38 | void nntp_desc(struct account *, char *, size_t); | |
29 | #include "fetch.h" | |
30 | ||
31 | int fetch_nntp_init(struct account *); | |
32 | int fetch_nntp_free(struct account *); | |
33 | int fetch_nntp_connect(struct account *); | |
34 | int fetch_nntp_disconnect(struct account *); | |
35 | int fetch_nntp_poll(struct account *, u_int *); | |
36 | int fetch_nntp_fetch(struct account *, struct mail *); | |
37 | int fetch_nntp_delete(struct account *); | |
38 | int fetch_nntp_keep(struct account *); | |
39 | void fetch_nntp_desc(struct account *, char *, size_t); | |
39 | 40 | |
40 | 41 | int nntp_code(char *); |
41 | 42 | char *nntp_line(struct account *, char **, size_t *); |
46 | 47 | int nntp_load(struct account *); |
47 | 48 | int nntp_save(struct account *); |
48 | 49 | |
49 | struct fetch fetch_nntp = { { "nntp", NULL }, | |
50 | nntp_init, | |
51 | nntp_connect, | |
52 | nntp_poll, | |
53 | nntp_fetch, | |
54 | nntp_save, | |
55 | NULL, | |
56 | NULL, | |
57 | nntp_disconnect, | |
58 | nntp_free, | |
59 | nntp_desc | |
50 | struct fetch fetch_nntp = { | |
51 | { "nntp", NULL }, | |
52 | fetch_nntp_init, | |
53 | fetch_nntp_connect, | |
54 | fetch_nntp_poll, | |
55 | fetch_nntp_fetch, | |
56 | nntp_save, | |
57 | NULL, | |
58 | NULL, | |
59 | fetch_nntp_disconnect, | |
60 | fetch_nntp_free, | |
61 | fetch_nntp_desc | |
60 | 62 | }; |
61 | 63 | |
62 | 64 | int |
362 | 364 | } |
363 | 365 | |
364 | 366 | int |
365 | nntp_init(struct account *a) | |
367 | fetch_nntp_init(struct account *a) | |
366 | 368 | { |
367 | 369 | struct nntp_data *data = a->data; |
368 | 370 | struct nntp_group *group; |
383 | 385 | } |
384 | 386 | |
385 | 387 | int |
386 | nntp_free(struct account *a) | |
388 | fetch_nntp_free(struct account *a) | |
387 | 389 | { |
388 | 390 | struct nntp_data *data = a->data; |
389 | 391 | struct nntp_group *group; |
402 | 404 | } |
403 | 405 | |
404 | 406 | int |
405 | nntp_connect(struct account *a) | |
407 | fetch_nntp_connect(struct account *a) | |
406 | 408 | { |
407 | 409 | struct nntp_data *data = a->data; |
408 | 410 | char *lbuf, *line, *cause; |
455 | 457 | } |
456 | 458 | |
457 | 459 | int |
458 | nntp_disconnect(struct account *a) | |
460 | fetch_nntp_disconnect(struct account *a) | |
459 | 461 | { |
460 | 462 | struct nntp_data *data = a->data; |
461 | 463 | char *lbuf, *line; |
488 | 490 | } |
489 | 491 | |
490 | 492 | int |
491 | nntp_poll(struct account *a, u_int *n) | |
493 | fetch_nntp_poll(struct account *a, u_int *n) | |
492 | 494 | { |
493 | 495 | struct nntp_data *data = a->data; |
494 | 496 | char *lbuf; |
519 | 521 | } |
520 | 522 | |
521 | 523 | int |
522 | nntp_fetch(struct account *a, struct mail *m) | |
524 | fetch_nntp_fetch(struct account *a, struct mail *m) | |
523 | 525 | { |
524 | 526 | struct nntp_data *data = a->data; |
525 | 527 | struct nntp_group *group; |
619 | 621 | } |
620 | 622 | |
621 | 623 | void |
622 | nntp_desc(struct account *a, char *buf, size_t len) | |
624 | fetch_nntp_desc(struct account *a, char *buf, size_t len) | |
623 | 625 | { |
624 | 626 | struct nntp_data *data = a->data; |
625 | 627 | char *names; |
24 | 24 | #include <unistd.h> |
25 | 25 | |
26 | 26 | #include "fdm.h" |
27 | ||
28 | int pop3_init(struct account *); | |
29 | int pop3_free(struct account *); | |
30 | int pop3_connect(struct account *); | |
31 | int pop3_disconnect(struct account *); | |
32 | int pop3_poll(struct account *, u_int *); | |
33 | int pop3_fetch(struct account *, struct mail *); | |
34 | int pop3_purge(struct account *); | |
35 | int pop3_delete(struct account *); | |
36 | int pop3_keep(struct account *); | |
37 | void pop3_desc(struct account *, char *, size_t); | |
27 | #include "fetch.h" | |
28 | ||
29 | int fetch_pop3_init(struct account *); | |
30 | int fetch_pop3_free(struct account *); | |
31 | int fetch_pop3_connect(struct account *); | |
32 | int fetch_pop3_disconnect(struct account *); | |
33 | int fetch_pop3_poll(struct account *, u_int *); | |
34 | int fetch_pop3_fetch(struct account *, struct mail *); | |
35 | int fetch_pop3_purge(struct account *); | |
36 | int fetch_pop3_delete(struct account *); | |
37 | int fetch_pop3_keep(struct account *); | |
38 | void fetch_pop3_desc(struct account *, char *, size_t); | |
38 | 39 | |
39 | 40 | char *pop3_line(struct account *, char **, size_t *); |
40 | 41 | char *pop3_check(struct account *, char **, size_t *); |
41 | 42 | |
42 | struct fetch fetch_pop3 = { { "pop3", "pop3s" }, | |
43 | pop3_init, | |
44 | pop3_connect, | |
45 | pop3_poll, | |
46 | pop3_fetch, | |
47 | pop3_purge, | |
48 | pop3_delete, | |
49 | pop3_keep, | |
50 | pop3_disconnect, | |
51 | pop3_free, | |
52 | pop3_desc | |
43 | struct fetch fetch_pop3 = { | |
44 | { "pop3", "pop3s" }, | |
45 | fetch_pop3_init, | |
46 | fetch_pop3_connect, | |
47 | fetch_pop3_poll, | |
48 | fetch_pop3_fetch, | |
49 | fetch_pop3_purge, | |
50 | fetch_pop3_delete, | |
51 | fetch_pop3_keep, | |
52 | fetch_pop3_disconnect, | |
53 | fetch_pop3_free, | |
54 | fetch_pop3_desc | |
53 | 55 | }; |
54 | 56 | |
55 | 57 | char * |
88 | 90 | } |
89 | 91 | |
90 | 92 | int |
91 | pop3_free(struct account *a) | |
93 | fetch_pop3_free(struct account *a) | |
92 | 94 | { |
93 | 95 | struct pop3_data *data = a->data; |
94 | 96 | u_int i; |
104 | 106 | } |
105 | 107 | |
106 | 108 | int |
107 | pop3_init(struct account *a) | |
109 | fetch_pop3_init(struct account *a) | |
108 | 110 | { |
109 | 111 | struct pop3_data *data = a->data; |
110 | 112 | |
114 | 116 | } |
115 | 117 | |
116 | 118 | int |
117 | pop3_connect(struct account *a) | |
119 | fetch_pop3_connect(struct account *a) | |
118 | 120 | { |
119 | 121 | struct pop3_data *data = a->data; |
120 | 122 | char *lbuf, *line, *cause; |
169 | 171 | } |
170 | 172 | |
171 | 173 | int |
172 | pop3_disconnect(struct account *a) | |
174 | fetch_pop3_disconnect(struct account *a) | |
173 | 175 | { |
174 | 176 | struct pop3_data *data = a->data; |
175 | 177 | char *lbuf; |
200 | 202 | } |
201 | 203 | |
202 | 204 | int |
203 | pop3_poll(struct account *a, u_int *n) | |
205 | fetch_pop3_poll(struct account *a, u_int *n) | |
204 | 206 | { |
205 | 207 | struct pop3_data *data = a->data; |
206 | 208 | |
210 | 212 | } |
211 | 213 | |
212 | 214 | int |
213 | pop3_fetch(struct account *a, struct mail *m) | |
215 | fetch_pop3_fetch(struct account *a, struct mail *m) | |
214 | 216 | { |
215 | 217 | struct pop3_data *data = a->data; |
216 | 218 | char *lbuf, *line, *uid; |
356 | 358 | } |
357 | 359 | |
358 | 360 | int |
359 | pop3_purge(struct account *a) | |
360 | { | |
361 | if (pop3_disconnect(a) != 0) | |
361 | fetch_pop3_purge(struct account *a) | |
362 | { | |
363 | if (fetch_pop3_disconnect(a) != 0) | |
362 | 364 | return (1); |
363 | return (pop3_connect(a)); | |
364 | } | |
365 | ||
366 | int | |
367 | pop3_delete(struct account *a) | |
365 | return (fetch_pop3_connect(a)); | |
366 | } | |
367 | ||
368 | int | |
369 | fetch_pop3_delete(struct account *a) | |
368 | 370 | { |
369 | 371 | struct pop3_data *data = a->data; |
370 | 372 | char *lbuf; |
386 | 388 | } |
387 | 389 | |
388 | 390 | int |
389 | pop3_keep(struct account *a) | |
391 | fetch_pop3_keep(struct account *a) | |
390 | 392 | { |
391 | 393 | struct pop3_data *data = a->data; |
392 | 394 | |
396 | 398 | } |
397 | 399 | |
398 | 400 | void |
399 | pop3_desc(struct account *a, char *buf, size_t len) | |
401 | fetch_pop3_desc(struct account *a, char *buf, size_t len) | |
400 | 402 | { |
401 | 403 | struct pop3_data *data = a->data; |
402 | 404 |
25 | 25 | #include <unistd.h> |
26 | 26 | |
27 | 27 | #include "fdm.h" |
28 | #include "fetch.h" | |
28 | 29 | |
29 | int stdin_connect(struct account *); | |
30 | int stdin_disconnect(struct account *); | |
31 | int stdin_fetch(struct account *, struct mail *); | |
32 | int stdin_delete(struct account *); | |
33 | void stdin_desc(struct account *, char *, size_t); | |
30 | int fetch_stdin_connect(struct account *); | |
31 | int fetch_stdin_disconnect(struct account *); | |
32 | int fetch_stdin_fetch(struct account *, struct mail *); | |
33 | int fetch_stdin_delete(struct account *); | |
34 | void fetch_stdin_desc(struct account *, char *, size_t); | |
34 | 35 | |
35 | struct fetch fetch_stdin = { { NULL, NULL }, | |
36 | NULL, | |
37 | stdin_connect, | |
38 | NULL, | |
39 | stdin_fetch, | |
40 | NULL, | |
41 | stdin_delete, | |
42 | NULL, | |
43 | stdin_disconnect, | |
44 | NULL, | |
45 | stdin_desc | |
36 | struct fetch fetch_stdin = { | |
37 | { NULL, NULL }, | |
38 | NULL, | |
39 | fetch_stdin_connect, | |
40 | NULL, | |
41 | fetch_stdin_fetch, | |
42 | NULL, | |
43 | fetch_stdin_delete, | |
44 | NULL, | |
45 | fetch_stdin_disconnect, | |
46 | NULL, | |
47 | fetch_stdin_desc | |
46 | 48 | }; |
47 | 49 | |
48 | 50 | int |
49 | stdin_connect(struct account *a) | |
51 | fetch_stdin_connect(struct account *a) | |
50 | 52 | { |
51 | 53 | struct stdin_data *data = a->data; |
52 | 54 | |
72 | 74 | } |
73 | 75 | |
74 | 76 | int |
75 | stdin_disconnect(struct account *a) | |
77 | fetch_stdin_disconnect(struct account *a) | |
76 | 78 | { |
77 | 79 | struct stdin_data *data = a->data; |
78 | 80 | |
84 | 86 | } |
85 | 87 | |
86 | 88 | int |
87 | stdin_delete(struct account *a) | |
89 | fetch_stdin_delete(struct account *a) | |
88 | 90 | { |
89 | 91 | struct stdin_data *data = a->data; |
90 | 92 | char *line, *lbuf; |
101 | 103 | } |
102 | 104 | |
103 | 105 | int |
104 | stdin_fetch(struct account *a, struct mail *m) | |
106 | fetch_stdin_fetch(struct account *a, struct mail *m) | |
105 | 107 | { |
106 | 108 | struct stdin_data *data = a->data; |
107 | 109 | u_int lines; |
180 | 182 | } |
181 | 183 | |
182 | 184 | void |
183 | stdin_desc(unused struct account *a, char *buf, size_t len) | |
185 | fetch_stdin_desc(unused struct account *a, char *buf, size_t len) | |
184 | 186 | { |
185 | 187 | strlcpy(buf, "stdin", len); |
186 | 188 | } |
0 | /* $Id$ */ | |
1 | ||
2 | /* | |
3 | * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> | |
4 | * | |
5 | * Permission to use, copy, modify, and distribute this software for any | |
6 | * purpose with or without fee is hereby granted, provided that the above | |
7 | * copyright notice and this permission notice appear in all copies. | |
8 | * | |
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
13 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER | |
14 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING | |
15 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
16 | */ | |
17 | ||
18 | #ifndef FETCH_H | |
19 | #define FETCH_H | |
20 | ||
21 | /* Poll return codes. */ | |
22 | #define POLL_SUCCESS FETCH_SUCCESS | |
23 | #define POLL_ERROR FETCH_ERROR | |
24 | ||
25 | /* Fetch return codes. */ | |
26 | #define FETCH_SUCCESS 0 | |
27 | #define FETCH_ERROR 1 | |
28 | #define FETCH_OVERSIZE 2 | |
29 | #define FETCH_COMPLETE 3 | |
30 | ||
31 | /* Fetch functions. */ | |
32 | struct fetch { | |
33 | const char *ports[2]; /* normal port, ssl port */ | |
34 | ||
35 | int (*init)(struct account *); | |
36 | int (*connect)(struct account *); | |
37 | int (*poll)(struct account *, u_int *); | |
38 | int (*fetch)(struct account *, struct mail *); | |
39 | int (*purge)(struct account *); | |
40 | int (*delete)(struct account *); | |
41 | int (*keep)(struct account *); | |
42 | int (*disconnect)(struct account *); | |
43 | int (*free)(struct account *); | |
44 | void (*desc)(struct account *, char *, size_t); | |
45 | }; | |
46 | ||
47 | /* Fetch maildir data. */ | |
48 | struct maildir_data { | |
49 | struct strings *maildirs; | |
50 | ||
51 | struct strings *paths; | |
52 | u_int index; | |
53 | ||
54 | DIR *dirp; | |
55 | char *path; | |
56 | char entry[MAXPATHLEN]; | |
57 | char maildir[MAXPATHLEN]; | |
58 | }; | |
59 | ||
60 | /* NNTP group entry. */ | |
61 | struct nntp_group { | |
62 | char *name; | |
63 | int ignore; | |
64 | ||
65 | u_int size; | |
66 | u_int last; | |
67 | char *id; | |
68 | }; | |
69 | ||
70 | /* NNTP group list. */ | |
71 | ARRAY_DECL(nntp_groups, struct nntp_group *); | |
72 | ||
73 | /* Fetch nntp data. */ | |
74 | struct nntp_data { | |
75 | char *path; | |
76 | ||
77 | struct server server; | |
78 | struct strings *names; | |
79 | ||
80 | u_int group; | |
81 | struct nntp_groups groups; | |
82 | ||
83 | struct io *io; | |
84 | }; | |
85 | #define GET_GROUP(d, i) ARRAY_ITEM(&d->groups, i, struct nntp_group *) | |
86 | #define CURRENT_GROUP(d) GET_GROUP(d, d->group) | |
87 | #define TOTAL_GROUPS(d) ARRAY_LENGTH(&d->groups) | |
88 | #define ADD_GROUP(d, g) ARRAY_ADD(&d->groups, g, struct nntp_group *) | |
89 | ||
90 | /* Fetch stdin data. */ | |
91 | struct stdin_data { | |
92 | int complete; | |
93 | ||
94 | struct io *io; | |
95 | }; | |
96 | ||
97 | /* Fetch pop3 data. */ | |
98 | struct pop3_data { | |
99 | char *user; | |
100 | char *pass; | |
101 | ||
102 | struct server server; | |
103 | ||
104 | u_int cur; | |
105 | u_int num; | |
106 | ||
107 | char *uid; | |
108 | struct strings kept; | |
109 | ||
110 | struct io *io; | |
111 | }; | |
112 | ||
113 | /* IMAP tag types. */ | |
114 | #define IMAP_TAG_NONE -1 | |
115 | #define IMAP_TAG_CONTINUE -2 | |
116 | #define IMAP_TAG_ERROR -3 | |
117 | ||
118 | /* IMAP line types. */ | |
119 | #define IMAP_TAGGED 0 | |
120 | #define IMAP_CONTINUE 1 | |
121 | #define IMAP_UNTAGGED 2 | |
122 | #define IMAP_RAW 3 | |
123 | ||
124 | /* Fetch imap data. */ | |
125 | struct imap_data { | |
126 | struct server server; | |
127 | char *pipecmd; | |
128 | ||
129 | struct io *io; | |
130 | struct cmd *cmd; | |
131 | ||
132 | char *user; | |
133 | char *pass; | |
134 | char *folder; | |
135 | ||
136 | int tag; | |
137 | u_int cur; | |
138 | u_int num; | |
139 | ||
140 | u_int uid; | |
141 | ARRAY_DECL(, u_int) kept; | |
142 | ||
143 | char *src; | |
144 | ||
145 | size_t llen; | |
146 | char *lbuf; | |
147 | ||
148 | char *(*getln)(struct account *a, int); | |
149 | int (*putln)(struct account *a, const char *, ...); | |
150 | void (*flush)(struct account *a); | |
151 | }; | |
152 | ||
153 | /* fetch-maildir.c */ | |
154 | extern struct fetch fetch_maildir; | |
155 | ||
156 | /* fetch-stdin.c */ | |
157 | extern struct fetch fetch_stdin; | |
158 | ||
159 | /* fetch-nntp.c */ | |
160 | extern struct fetch fetch_nntp; | |
161 | ||
162 | /* fetch-pop3.c */ | |
163 | extern struct fetch fetch_pop3; | |
164 | ||
165 | /* fetch-imap.c */ | |
166 | extern struct fetch fetch_imap; | |
167 | ||
168 | /* fetch-imappipe.c */ | |
169 | extern struct fetch fetch_imappipe; | |
170 | ||
171 | #endif |
20 | 20 | #include <string.h> |
21 | 21 | |
22 | 22 | #include "fdm.h" |
23 | #include "fetch.h" | |
23 | 24 | |
24 | 25 | int imap_okay(struct account *, char *); |
25 | 26 |
22 | 22 | #include <string.h> |
23 | 23 | |
24 | 24 | #include "fdm.h" |
25 | #include "match.h" | |
25 | 26 | |
26 | int age_match(struct match_ctx *, struct expritem *); | |
27 | void age_desc(struct expritem *, char *, size_t); | |
27 | int match_age_match(struct match_ctx *, struct expritem *); | |
28 | void match_age_desc(struct expritem *, char *, size_t); | |
28 | 29 | |
29 | 30 | int age_tzlookup(const char *, int *); |
30 | 31 | |
31 | struct match match_age = { age_match, age_desc }; | |
32 | struct match match_age = { | |
33 | match_age_match, | |
34 | match_age_desc | |
35 | }; | |
32 | 36 | |
33 | 37 | /* |
34 | 38 | * Some mailers, notably AOL's, use the timezone string instead of an offset |
74 | 78 | } |
75 | 79 | |
76 | 80 | int |
77 | age_match(struct match_ctx *mctx, struct expritem *ei) | |
81 | match_age_match(struct match_ctx *mctx, struct expritem *ei) | |
78 | 82 | { |
79 | 83 | struct age_data *data = ei->data; |
80 | 84 | struct account *a = mctx->account; |
167 | 171 | } |
168 | 172 | |
169 | 173 | void |
170 | age_desc(struct expritem *ei, char *buf, size_t len) | |
174 | match_age_desc(struct expritem *ei, char *buf, size_t len) | |
171 | 175 | { |
172 | 176 | struct age_data *data = ei->data; |
173 | 177 | const char *cmp = ""; |
20 | 20 | #include <fnmatch.h> |
21 | 21 | |
22 | 22 | #include "fdm.h" |
23 | #include "match.h" | |
23 | 24 | |
24 | int attachment_match(struct match_ctx *, struct expritem *); | |
25 | void attachment_desc(struct expritem *, char *, size_t); | |
25 | int match_attachment_match(struct match_ctx *, struct expritem *); | |
26 | void match_attachment_desc(struct expritem *, char *, size_t); | |
26 | 27 | |
27 | struct match match_attachment = { attachment_match, attachment_desc }; | |
28 | struct match match_attachment = { | |
29 | match_attachment_match, | |
30 | match_attachment_desc | |
31 | }; | |
28 | 32 | |
29 | 33 | int |
30 | attachment_match(struct match_ctx *mctx, struct expritem *ei) | |
34 | match_attachment_match(struct match_ctx *mctx, struct expritem *ei) | |
31 | 35 | { |
32 | 36 | struct attachment_data *data = ei->data; |
33 | 37 | struct account *a = mctx->account; |
142 | 146 | } |
143 | 147 | |
144 | 148 | void |
145 | attachment_desc(struct expritem *ei, char *buf, size_t len) | |
149 | match_attachment_desc(struct expritem *ei, char *buf, size_t len) | |
146 | 150 | { |
147 | 151 | struct attachment_data *data = ei->data; |
148 | 152 | const char *cmp = ""; |
20 | 20 | #include <string.h> |
21 | 21 | |
22 | 22 | #include "fdm.h" |
23 | #include "match.h" | |
23 | 24 | |
24 | int command_match(struct match_ctx *, struct expritem *); | |
25 | void command_desc(struct expritem *, char *, size_t); | |
25 | int match_command_match(struct match_ctx *, struct expritem *); | |
26 | void match_command_desc(struct expritem *, char *, size_t); | |
26 | 27 | |
27 | struct match match_command = { command_match, command_desc }; | |
28 | struct match match_command = { | |
29 | match_command_match, | |
30 | match_command_desc | |
31 | }; | |
28 | 32 | |
29 | 33 | int |
30 | command_match(struct match_ctx *mctx, struct expritem *ei) | |
34 | match_command_match(struct match_ctx *mctx, struct expritem *ei) | |
31 | 35 | { |
32 | 36 | struct command_data *data = ei->data; |
33 | 37 | struct account *a = mctx->account; |
59 | 63 | } |
60 | 64 | |
61 | 65 | void |
62 | command_desc(struct expritem *ei, char *buf, size_t len) | |
66 | match_command_desc(struct expritem *ei, char *buf, size_t len) | |
63 | 67 | { |
64 | 68 | struct command_data *data = ei->data; |
65 | 69 | char ret[11]; |
20 | 20 | #include <string.h> |
21 | 21 | |
22 | 22 | #include "fdm.h" |
23 | #include "match.h" | |
23 | 24 | |
24 | int matched_match(struct match_ctx *, struct expritem *); | |
25 | void matched_desc(struct expritem *, char *, size_t); | |
25 | int match_matched_match(struct match_ctx *, struct expritem *); | |
26 | void match_matched_desc(struct expritem *, char *, size_t); | |
26 | 27 | |
27 | struct match match_matched = { matched_match, matched_desc }; | |
28 | struct match match_matched = { | |
29 | match_matched_match, | |
30 | match_matched_desc | |
31 | }; | |
28 | 32 | |
29 | 33 | int |
30 | matched_match(struct match_ctx *mctx, unused struct expritem *ei) | |
34 | match_matched_match(struct match_ctx *mctx, unused struct expritem *ei) | |
31 | 35 | { |
32 | 36 | if (mctx->matched) |
33 | 37 | return (MATCH_TRUE); |
35 | 39 | } |
36 | 40 | |
37 | 41 | void |
38 | matched_desc(unused struct expritem *ei, char *buf, size_t len) | |
42 | match_matched_desc(unused struct expritem *ei, char *buf, size_t len) | |
39 | 43 | { |
40 | 44 | strlcpy(buf, "matched", len); |
41 | 45 | } |
20 | 20 | #include <regex.h> |
21 | 21 | |
22 | 22 | #include "fdm.h" |
23 | #include "match.h" | |
23 | 24 | |
24 | int regexp_match(struct match_ctx *, struct expritem *); | |
25 | void regexp_desc(struct expritem *, char *, size_t); | |
25 | int match_regexp_match(struct match_ctx *, struct expritem *); | |
26 | void match_regexp_desc(struct expritem *, char *, size_t); | |
26 | 27 | |
27 | struct match match_regexp = { regexp_match, regexp_desc }; | |
28 | struct match match_regexp = { | |
29 | match_regexp_match, | |
30 | match_regexp_desc | |
31 | }; | |
28 | 32 | |
29 | 33 | int |
30 | regexp_match(struct match_ctx *mctx, struct expritem *ei) | |
34 | match_regexp_match(struct match_ctx *mctx, struct expritem *ei) | |
31 | 35 | { |
32 | 36 | struct regexp_data *data = ei->data; |
33 | 37 | struct account *a = mctx->account; |
71 | 75 | } |
72 | 76 | |
73 | 77 | void |
74 | regexp_desc(struct expritem *ei, char *buf, size_t len) | |
78 | match_regexp_desc(struct expritem *ei, char *buf, size_t len) | |
75 | 79 | { |
76 | 80 | struct regexp_data *data = ei->data; |
77 | 81 | const char *area = NULL; |
20 | 20 | #include <string.h> |
21 | 21 | |
22 | 22 | #include "fdm.h" |
23 | #include "match.h" | |
23 | 24 | |
24 | int size_match(struct match_ctx *, struct expritem *); | |
25 | void size_desc(struct expritem *, char *, size_t); | |
25 | int match_size_match(struct match_ctx *, struct expritem *); | |
26 | void match_size_desc(struct expritem *, char *, size_t); | |
26 | 27 | |
27 | struct match match_size = { size_match, size_desc }; | |
28 | struct match match_size = { | |
29 | match_size_match, | |
30 | match_size_desc | |
31 | }; | |
28 | 32 | |
29 | 33 | int |
30 | size_match(struct match_ctx *mctx, struct expritem *ei) | |
34 | match_size_match(struct match_ctx *mctx, struct expritem *ei) | |
31 | 35 | { |
32 | 36 | struct size_data *data = ei->data; |
33 | 37 | struct mail *m = mctx->mail; |
40 | 44 | } |
41 | 45 | |
42 | 46 | void |
43 | size_desc(struct expritem *ei, char *buf, size_t len) | |
47 | match_size_desc(struct expritem *ei, char *buf, size_t len) | |
44 | 48 | { |
45 | 49 | struct size_data *data = ei->data; |
46 | 50 | const char *cmp = ""; |
21 | 21 | #include <string.h> |
22 | 22 | |
23 | 23 | #include "fdm.h" |
24 | #include "match.h" | |
24 | 25 | |
25 | int string_match(struct match_ctx *, struct expritem *); | |
26 | void string_desc(struct expritem *, char *, size_t); | |
26 | int match_string_match(struct match_ctx *, struct expritem *); | |
27 | void match_string_desc(struct expritem *, char *, size_t); | |
27 | 28 | |
28 | struct match match_string = { string_match, string_desc }; | |
29 | struct match match_string = { | |
30 | match_string_match, | |
31 | match_string_desc | |
32 | }; | |
29 | 33 | |
30 | 34 | int |
31 | string_match(struct match_ctx *mctx, struct expritem *ei) | |
35 | match_string_match(struct match_ctx *mctx, struct expritem *ei) | |
32 | 36 | { |
33 | 37 | struct string_data *data = ei->data; |
34 | 38 | struct account *a = mctx->account; |
59 | 63 | } |
60 | 64 | |
61 | 65 | void |
62 | string_desc(struct expritem *ei, char *buf, size_t len) | |
66 | match_string_desc(struct expritem *ei, char *buf, size_t len) | |
63 | 67 | { |
64 | 68 | struct string_data *data = ei->data; |
65 | 69 |
21 | 21 | #include <string.h> |
22 | 22 | |
23 | 23 | #include "fdm.h" |
24 | #include "match.h" | |
24 | 25 | |
25 | int tagged_match(struct match_ctx *, struct expritem *); | |
26 | void tagged_desc(struct expritem *, char *, size_t); | |
26 | int match_tagged_match(struct match_ctx *, struct expritem *); | |
27 | void match_tagged_desc(struct expritem *, char *, size_t); | |
27 | 28 | |
28 | struct match match_tagged = { tagged_match, tagged_desc }; | |
29 | struct match match_tagged = { | |
30 | match_tagged_match, | |
31 | match_tagged_desc | |
32 | }; | |
29 | 33 | |
30 | 34 | int |
31 | tagged_match(struct match_ctx *mctx, struct expritem *ei) | |
35 | match_tagged_match(struct match_ctx *mctx, struct expritem *ei) | |
32 | 36 | { |
33 | 37 | struct tagged_data *data = ei->data; |
34 | 38 | struct mail *m = mctx->mail; |
39 | 43 | } |
40 | 44 | |
41 | 45 | void |
42 | tagged_desc(struct expritem *ei, char *buf, size_t len) | |
46 | match_tagged_desc(struct expritem *ei, char *buf, size_t len) | |
43 | 47 | { |
44 | 48 | struct tagged_data *data = ei->data; |
45 | 49 |
20 | 20 | #include <string.h> |
21 | 21 | |
22 | 22 | #include "fdm.h" |
23 | #include "match.h" | |
23 | 24 | |
24 | int unmatched_match(struct match_ctx *, struct expritem *); | |
25 | void unmatched_desc(struct expritem *, char *, size_t); | |
25 | int match_unmatched_match(struct match_ctx *, struct expritem *); | |
26 | void match_unmatched_desc(struct expritem *, char *, size_t); | |
26 | 27 | |
27 | struct match match_unmatched = { unmatched_match, unmatched_desc }; | |
28 | struct match match_unmatched = { | |
29 | match_unmatched_match, | |
30 | match_unmatched_desc | |
31 | }; | |
28 | 32 | |
29 | 33 | int |
30 | unmatched_match(struct match_ctx *mctx, unused struct expritem *ei) | |
34 | match_unmatched_match(struct match_ctx *mctx, unused struct expritem *ei) | |
31 | 35 | { |
32 | 36 | if (mctx->matched) |
33 | 37 | return (MATCH_FALSE); |
35 | 39 | } |
36 | 40 | |
37 | 41 | void |
38 | unmatched_desc(unused struct expritem *ei, char *buf, size_t len) | |
42 | match_unmatched_desc(unused struct expritem *ei, char *buf, size_t len) | |
39 | 43 | { |
40 | 44 | strlcpy(buf, "unmatched", len); |
41 | 45 | } |
0 | /* $Id$ */ | |
1 | ||
2 | /* | |
3 | * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> | |
4 | * | |
5 | * Permission to use, copy, modify, and distribute this software for any | |
6 | * purpose with or without fee is hereby granted, provided that the above | |
7 | * copyright notice and this permission notice appear in all copies. | |
8 | * | |
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
13 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER | |
14 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING | |
15 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
16 | */ | |
17 | ||
18 | #ifndef MATCH_H | |
19 | #define MATCH_H | |
20 | ||
21 | /* Match return codes. */ | |
22 | #define MATCH_FALSE 0 | |
23 | #define MATCH_TRUE 1 | |
24 | #define MATCH_ERROR 2 | |
25 | ||
26 | /* Match context. */ | |
27 | struct match_ctx { | |
28 | struct io *io; | |
29 | struct account *account; | |
30 | struct mail *mail; | |
31 | ||
32 | enum decision decision; | |
33 | ||
34 | int matched; | |
35 | int stopped; | |
36 | ||
37 | int pm_valid; | |
38 | regmatch_t pm[NPMATCH]; | |
39 | }; | |
40 | ||
41 | /* Match functions. */ | |
42 | struct match { | |
43 | int (*match)(struct match_ctx *, struct expritem *); | |
44 | void (*desc)(struct expritem *, char *, size_t); | |
45 | }; | |
46 | ||
47 | /* Match attachment data. */ | |
48 | struct attachment_data { | |
49 | enum { | |
50 | ATTACHOP_COUNT, | |
51 | ATTACHOP_TOTALSIZE, | |
52 | ATTACHOP_ANYSIZE, | |
53 | ATTACHOP_ANYTYPE, | |
54 | ATTACHOP_ANYNAME | |
55 | } op; | |
56 | ||
57 | enum cmp cmp; | |
58 | union { | |
59 | size_t size; | |
60 | long long num; | |
61 | char *str; | |
62 | struct re re; | |
63 | } value; | |
64 | }; | |
65 | ||
66 | /* Match age data. */ | |
67 | struct age_data { | |
68 | long long time; | |
69 | enum cmp cmp; | |
70 | }; | |
71 | ||
72 | /* Match size data. */ | |
73 | struct size_data { | |
74 | size_t size; | |
75 | enum cmp cmp; | |
76 | }; | |
77 | ||
78 | /* Match tagged data. */ | |
79 | struct tagged_data { | |
80 | char *tag; | |
81 | }; | |
82 | ||
83 | /* Match string data. */ | |
84 | struct string_data { | |
85 | struct re re; | |
86 | ||
87 | char *str; | |
88 | }; | |
89 | ||
90 | /* Match regexp data. */ | |
91 | struct regexp_data { | |
92 | struct re re; | |
93 | ||
94 | enum area area; | |
95 | }; | |
96 | ||
97 | /* Match command data. */ | |
98 | struct command_data { | |
99 | char *cmd; | |
100 | uid_t uid; | |
101 | int pipe; /* pipe mail to command */ | |
102 | ||
103 | struct re re; /* re->re NULL to not check */ | |
104 | int ret; /* -1 to not check */ | |
105 | }; | |
106 | ||
107 | /* match-age.c */ | |
108 | extern struct match match_age; | |
109 | ||
110 | /* match-attachment.c */ | |
111 | extern struct match match_attachment; | |
112 | ||
113 | /* match-matched.c */ | |
114 | extern struct match match_matched; | |
115 | ||
116 | /* match-unmatched.c */ | |
117 | extern struct match match_unmatched; | |
118 | ||
119 | /* match-size.c */ | |
120 | extern struct match match_size; | |
121 | ||
122 | /* match-tagged.c */ | |
123 | extern struct match match_tagged; | |
124 | ||
125 | /* match-string.c */ | |
126 | extern struct match match_string; | |
127 | ||
128 | /* match-command.c */ | |
129 | extern struct match match_command; | |
130 | ||
131 | /* match-regexp.c */ | |
132 | extern struct match match_regexp; | |
133 | ||
134 | #endif |