Codebase list fdm / eac8773
Merge append/exec fulyl into write/pipe. Nicholas Marriott 16 years ago
10 changed file(s) with 62 addition(s) and 197 deletion(s). Raw diff Collapse all Expand all
00 10 August 2007
11
2 * Combine append into write and exec into pipe even more to get rid of
3 deliver-append.c and deliver-exec.c.
24 * add-from on stdout delivery is gone, an acceptable from line can be prepended
35 using rewrite.
46
3030 child-deliver.c child-fetch.c child.c \
3131 pcre.c re.c privsep.c replace.c shm-mmap.c strb.c db-tdb.c \
3232 xmalloc-debug.c xmalloc.c \
33 deliver-add-header.c deliver-append.c deliver-drop.c deliver-exec.c \
34 deliver-keep.c deliver-maildir.c deliver-mbox.c deliver-pipe.c \
35 deliver-remove-header.c deliver-rewrite.c deliver-smtp.c \
36 deliver-stdout.c deliver-tag.c deliver-to-cache.c deliver-write.c \
33 deliver-add-header.c deliver-drop.c deliver-keep.c deliver-maildir.c \
34 deliver-mbox.c deliver-pipe.c deliver-remove-header.c deliver-rewrite.c \
35 deliver-smtp.c deliver-stdout.c deliver-tag.c deliver-to-cache.c \
36 deliver-write.c \
3737 fetch-imap.c fetch-imappipe.c fetch-maildir.c fetch-nntp.c fetch-pop3.c \
3838 fetch-stdin.c fetch-mbox.c imap-common.c \
3939 mail-callback.c mail-state.c mail-time.c mail.c file.c \
1818 child-deliver.c child-fetch.c child.c \
1919 pcre.c re.c privsep.c replace.c shm-mmap.c strb.c db-tdb.c \
2020 xmalloc-debug.c xmalloc.c \
21 deliver-add-header.c deliver-append.c deliver-drop.c deliver-exec.c \
22 deliver-keep.c deliver-maildir.c deliver-mbox.c deliver-pipe.c \
23 deliver-remove-header.c deliver-rewrite.c deliver-smtp.c \
24 deliver-stdout.c deliver-tag.c deliver-to-cache.c deliver-write.c \
21 deliver-add-header.c deliver-drop.c deliver-keep.c deliver-maildir.c \
22 deliver-mbox.c deliver-pipe.c deliver-remove-header.c deliver-rewrite.c \
23 deliver-smtp.c deliver-stdout.c deliver-tag.c deliver-to-cache.c \
24 deliver-write.c \
2525 fetch-imap.c fetch-imappipe.c fetch-maildir.c fetch-nntp.c fetch-pop3.c \
2626 fetch-stdin.c fetch-mbox.c imap-common.c \
2727 mail-callback.c mail-state.c mail-time.c mail.c file.c \
+0
-52
deliver-append.c less more
0 /* $Id$ */
1
2 /*
3 * Copyright (c) 2006 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 #include <sys/types.h>
19
20 #include <errno.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
25
26 #include "fdm.h"
27 #include "deliver.h"
28
29 int deliver_append_deliver(struct deliver_ctx *, struct actitem *);
30 void deliver_append_desc(struct actitem *, char *, size_t);
31
32 struct deliver deliver_append = {
33 "append",
34 DELIVER_ASUSER,
35 deliver_append_deliver,
36 deliver_append_desc
37 };
38
39 int
40 deliver_append_deliver(struct deliver_ctx *dctx, struct actitem *ti)
41 {
42 return (do_write(dctx, ti, 1));
43 }
44
45 void
46 deliver_append_desc(struct actitem *ti, char *buf, size_t len)
47 {
48 struct deliver_write_data *data = ti->data;
49
50 xsnprintf(buf, len, "append \"%s\"", data->path.str);
51 }
+0
-52
deliver-exec.c less more
0 /* $Id$ */
1
2 /*
3 * Copyright (c) 2006 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 #include <sys/types.h>
19
20 #include <errno.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
25
26 #include "fdm.h"
27 #include "deliver.h"
28
29 int deliver_exec_deliver(struct deliver_ctx *, struct actitem *);
30 void deliver_exec_desc(struct actitem *, char *, size_t);
31
32 struct deliver deliver_exec = {
33 "exec",
34 DELIVER_ASUSER,
35 deliver_exec_deliver,
36 deliver_exec_desc
37 };
38
39 int
40 deliver_exec_deliver(struct deliver_ctx *dctx, struct actitem *ti)
41 {
42 return (do_pipe(dctx, ti, 0));
43 }
44
45 void
46 deliver_exec_desc(struct actitem *ti, char *buf, size_t len)
47 {
48 struct deliver_pipe_data *data = ti->data;
49
50 xsnprintf(buf, len, "exec \"%s\"", data->cmd.str);
51 }
3939 int
4040 deliver_pipe_deliver(struct deliver_ctx *dctx, struct actitem *ti)
4141 {
42 return (do_pipe(dctx, ti, 1));
43 }
44
45 void
46 deliver_pipe_desc(struct actitem *ti, char *buf, size_t len)
47 {
48 struct deliver_pipe_data *data = ti->data;
49
50 xsnprintf(buf, len, "pipe \"%s\"", data->cmd.str);
51 }
52
53 int
54 do_pipe(struct deliver_ctx *dctx, struct actitem *ti, int pipef)
55 {
5642 struct account *a = dctx->account;
5743 struct mail *m = dctx->mail;
5844 struct deliver_pipe_data *data = ti->data;
6854 goto error;
6955 }
7056
71 if (pipef)
57 if (data->pipe) {
7258 log_debug2("%s: piping to \"%s\"", a->name, s);
73 else
59 cmd = cmd_start(s, CMD_IN|CMD_ONCE, m->data, m->size, &cause);
60 } else {
7461 log_debug2("%s: executing \"%s\"", a->name, s);
75
76 if (pipef) {
77 cmd = cmd_start(s, CMD_IN|CMD_ONCE, m->data, m->size, &cause);
78 } else
7962 cmd = cmd_start(s, 0, NULL, 0, &cause);
63 }
8064 if (cmd == NULL)
8165 goto error_cause;
8266 log_debug3("%s: %s: started", a->name, s);
9276 goto error_cause;
9377 }
9478 if (status == 0 && err != NULL)
95 log_warnx("%s: %s: %s", a->name, s, err);
79 log_warnx("%s: %s: %s", a->name, s, err);
9680 } while (status == 0);
9781 status--;
9882
118102 xfree(s);
119103 return (DELIVER_FAILURE);
120104 }
105
106 void
107 deliver_pipe_desc(struct actitem *ti, char *buf, size_t len)
108 {
109 struct deliver_pipe_data *data = ti->data;
110
111 if (data->pipe)
112 xsnprintf(buf, len, "pipe \"%s\"", data->cmd.str);
113 else
114 xsnprintf(buf, len, "exec \"%s\"", data->cmd.str);
115 }
3939 int
4040 deliver_write_deliver(struct deliver_ctx *dctx, struct actitem *ti)
4141 {
42 return (do_write(dctx, ti, 0));
43 }
44
45 void
46 deliver_write_desc(struct actitem *ti, char *buf, size_t len)
47 {
48 struct deliver_write_data *data = ti->data;
49
50 xsnprintf(buf, len, "write \"%s\"", data->path.str);
51 }
52
53 int
54 do_write(struct deliver_ctx *dctx, struct actitem *ti, int appendf)
55 {
5642 struct account *a = dctx->account;
5743 struct mail *m = dctx->mail;
5844 struct deliver_write_data *data = ti->data;
6753 return (DELIVER_FAILURE);
6854 }
6955
70 if (appendf)
56 if (data->append) {
7157 log_debug2("%s: appending to %s", a->name, path);
72 else
58 f = fopen(path, "a");
59 } else {
7360 log_debug2("%s: writing to %s", a->name, path);
74
75 f = fopen(path, appendf ? "a" : "w");
61 f = fopen(path, "w");
62 }
7663 if (f == NULL) {
7764 log_warn("%s: %s: fopen", a->name, path);
7865 goto error;
9885 xfree(path);
9986 return (DELIVER_FAILURE);
10087 }
88
89
90 void
91 deliver_write_desc(struct actitem *ti, char *buf, size_t len)
92 {
93 struct deliver_write_data *data = ti->data;
94
95 if (data->append)
96 xsnprintf(buf, len, "append \"%s\"", data->path.str);
97 else
98 xsnprintf(buf, len, "write \"%s\"", data->path.str);
99 }
9393 /* Deliver write data. */
9494 struct deliver_write_data {
9595 struct replpath path;
96 int append;
9697 };
9798
9899 /* Deliver maildir data. */
108109 /* Deliver pipe data. */
109110 struct deliver_pipe_data {
110111 struct replpath cmd;
112 int pipe;
111113 };
112114
113115 /* Deliver tag data. */
138140
139141 /* deliver-pipe.c */
140142 extern struct deliver deliver_pipe;
141 int do_pipe(struct deliver_ctx *, struct actitem *, int);
142
143 /* deliver-exec.c */
144 extern struct deliver deliver_exec;
145143
146144 /* deliver-drop.c */
147145 extern struct deliver deliver_drop;
163161
164162 /* deliver-write.c */
165163 extern struct deliver deliver_write;
166 int do_write(struct deliver_ctx *, struct actitem *, int);
167
168 /* deliver-append.c */
169 extern struct deliver deliver_append;
170164
171165 /* deliver-rewrite.c */
172166 extern struct deliver deliver_rewrite;
391391 void
392392 free_actitem(struct actitem *ti)
393393 {
394 if (ti->deliver == &deliver_pipe || ti->deliver == &deliver_exec) {
394 if (ti->deliver == &deliver_pipe) {
395395 struct deliver_pipe_data *data = ti->data;
396396 xfree(data->cmd.str);
397397 } else if (ti->deliver == &deliver_rewrite) {
398398 struct deliver_rewrite_data *data = ti->data;
399399 xfree(data->cmd.str);
400 } else if (ti->deliver == &deliver_write ||
401 ti->deliver == &deliver_append) {
400 } else if (ti->deliver == &deliver_write) {
402401 struct deliver_write_data *data = ti->data;
403402 xfree(data->path.str);
404403 } else if (ti->deliver == &deliver_maildir) {
181181 %type <expritem> expritem
182182 %type <exprop> exprop
183183 %type <fetch> fetchtype
184 %type <flag> cont icase not disabled keep execpipe compress verify
184 %type <flag> cont icase not disabled keep execpipe writeappend compress verify
185185 %type <flag> poptype imaptype nntptype
186186 %type <gid> gid
187187 %type <locks> lock locklist
11041104 }
11051105
11061106 /** ACTITEM: <actitem> (struct actitem *) */
1107 actitem: TOKPIPE strv
1107 actitem: execpipe strv
11081108 /** [$2: strv (char *)] */
11091109 {
11101110 struct deliver_pipe_data *data;
11181118 data = xcalloc(1, sizeof *data);
11191119 $$->data = data;
11201120
1121 data->cmd.str = $2;
1122 }
1123 | TOKEXEC strv
1124 /** [$2: strv (char *)] */
1125 {
1126 struct deliver_pipe_data *data;
1127
1128 if (*$2 == '\0')
1129 yyerror("invalid command");
1130
1131 $$ = xcalloc(1, sizeof *$$);
1132 $$->deliver = &deliver_exec;
1133
1134 data = xcalloc(1, sizeof *data);
1135 $$->data = data;
1136
1121 data->pipe = $1;
11371122 data->cmd.str = $2;
11381123 }
11391124 | TOKREWRITE strv
11521137
11531138 data->cmd.str = $2;
11541139 }
1155 | TOKWRITE strv
1140 | writeappend strv
11561141 /** [$2: strv (char *)] */
11571142 {
11581143 struct deliver_write_data *data;
11661151 data = xcalloc(1, sizeof *data);
11671152 $$->data = data;
11681153
1169 data->path.str = $2;
1170 }
1171 | TOKAPPEND strv
1172 /** [$2: strv (char *)] */
1173 {
1174 struct deliver_write_data *data;
1175
1176 if (*$2 == '\0')
1177 yyerror("invalid path");
1178
1179 $$ = xcalloc(1, sizeof *$$);
1180 $$->deliver = &deliver_append;
1181
1182 data = xcalloc(1, sizeof *data);
1183 $$->data = data;
1184
1154 data->append = $1;
11851155 data->path.str = $2;
11861156 }
11871157 | TOKMAILDIR strv
15971567 {
15981568 $$ = 1;
15991569 }
1570
1571 /** WRITEAPPEND: <flag> (int) */
1572 writeappend: TOKWRITE
1573 {
1574 $$ = 0;
1575 }
1576 | TOKAPPEND
1577 {
1578 $$ = 1;
1579 }
16001580
16011581 /** EXPROP: <exprop> (enum exprop) */
16021582 exprop: TOKAND