annotate src/mlmmj-process.c @ 741:b72bcb7e08a2

Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header, and document \uNNNN substitution Also, the interface to prepstdreply() has changed; there is no longer a customheaders argument, which was never used anyway, and is now essentially redundant due to this patch.
author Ben Schmidt
date Mon, 20 Sep 2010 01:44:58 +1000
parents ada79809aac0
children 926f184eec44
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
484
2855bbfb74fe Allow bounces with no From:
mmj
parents: 459
diff changeset
1 /* Copyright (C) 2003, 2003, 2004 Mads Martin Joergensen <mmj at mmj.dk>
0
21ce01de8109 Initial revision
mmj
parents:
diff changeset
2 *
21ce01de8109 Initial revision
mmj
parents:
diff changeset
3 * $Id$
21ce01de8109 Initial revision
mmj
parents:
diff changeset
4 *
225
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 221
diff changeset
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 221
diff changeset
6 * of this software and associated documentation files (the "Software"), to
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 221
diff changeset
7 * deal in the Software without restriction, including without limitation the
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 221
diff changeset
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 221
diff changeset
9 * sell copies of the Software, and to permit persons to whom the Software is
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 221
diff changeset
10 * furnished to do so, subject to the following conditions:
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 221
diff changeset
11 *
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 221
diff changeset
12 * The above copyright notice and this permission notice shall be included in
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 221
diff changeset
13 * all copies or substantial portions of the Software.
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 221
diff changeset
14 *
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 221
diff changeset
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 221
diff changeset
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 221
diff changeset
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 221
diff changeset
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 221
diff changeset
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 221
diff changeset
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 221
diff changeset
21 * IN THE SOFTWARE.
0
21ce01de8109 Initial revision
mmj
parents:
diff changeset
22 */
21ce01de8109 Initial revision
mmj
parents:
diff changeset
23
21ce01de8109 Initial revision
mmj
parents:
diff changeset
24 #include <stdio.h>
21ce01de8109 Initial revision
mmj
parents:
diff changeset
25 #include <stdlib.h>
21ce01de8109 Initial revision
mmj
parents:
diff changeset
26 #include <unistd.h>
21ce01de8109 Initial revision
mmj
parents:
diff changeset
27 #include <errno.h>
21ce01de8109 Initial revision
mmj
parents:
diff changeset
28 #include <string.h>
21ce01de8109 Initial revision
mmj
parents:
diff changeset
29 #include <sys/types.h>
21ce01de8109 Initial revision
mmj
parents:
diff changeset
30 #include <sys/stat.h>
21ce01de8109 Initial revision
mmj
parents:
diff changeset
31 #include <fcntl.h>
37
6b61ded65896 Send around the full path to the binaries
mmj
parents: 25
diff changeset
32 #include <libgen.h>
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
33 #include <regex.h>
0
21ce01de8109 Initial revision
mmj
parents:
diff changeset
34
21ce01de8109 Initial revision
mmj
parents:
diff changeset
35 #include "mlmmj.h"
21ce01de8109 Initial revision
mmj
parents:
diff changeset
36 #include "wrappers.h"
21ce01de8109 Initial revision
mmj
parents:
diff changeset
37 #include "find_email_adr.h"
21ce01de8109 Initial revision
mmj
parents:
diff changeset
38 #include "incindexfile.h"
21ce01de8109 Initial revision
mmj
parents:
diff changeset
39 #include "getlistaddr.h"
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 487
diff changeset
40 #include "getlistdelim.h"
0
21ce01de8109 Initial revision
mmj
parents:
diff changeset
41 #include "listcontrol.h"
21ce01de8109 Initial revision
mmj
parents:
diff changeset
42 #include "strgen.h"
11
8e1ebc68ee62 do_all_the_voodo_here introducton plus a massive cleanup
mmj
parents: 1
diff changeset
43 #include "do_all_the_voodo_here.h"
25
65d01831c0eb log_error is it's own object now
mmj
parents: 18
diff changeset
44 #include "log_error.h"
69
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
45 #include "mygetline.h"
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
46 #include "statctrl.h"
89
mmj
parents: 69
diff changeset
47 #include "ctrlvalue.h"
233
3b4fa52561d6 Implement control/delheaders in where one can specify all the headers
mmj
parents: 228
diff changeset
48 #include "ctrlvalues.h"
221
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
49 #include "getlistaddr.h"
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
50 #include "prepstdreply.h"
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
51 #include "subscriberfuncs.h"
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
52 #include "memory.h"
430
4ec6c541b7c0 Logging
mmj
parents: 386
diff changeset
53 #include "log_oper.h"
459
42501eca3d2a Alternate listaddresses
mmj
parents: 445
diff changeset
54 #include "chomp.h"
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
55
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
56 enum action {
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
57 ALLOW,
719
30e6e309891d Added "send" keyword to control/access handling (Ben Schmidt)
mortenp
parents: 705
diff changeset
58 SEND,
386
7a484c4b7925 Add moderate tag to access rules
mmj
parents: 382
diff changeset
59 DENY,
640
3770bb64ea17 Added support for 'discard' keyword in access rules (Sascha Sommer)
mortenp
parents: 629
diff changeset
60 MODERATE,
3770bb64ea17 Added support for 'discard' keyword in access rules (Sascha Sommer)
mortenp
parents: 629
diff changeset
61 DISCARD
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
62 };
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
63
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
64
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
65 static char *action_strs[] = {
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
66 "allowed",
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
67 "denied",
640
3770bb64ea17 Added support for 'discard' keyword in access rules (Sascha Sommer)
mortenp
parents: 629
diff changeset
68 "moderated",
3770bb64ea17 Added support for 'discard' keyword in access rules (Sascha Sommer)
mortenp
parents: 629
diff changeset
69 "discarded"
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
70 };
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
71
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
72
69
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
73 void newmoderated(const char *listdir, const char *mailfilename,
705
79dd917e0150 ifmodsendonlymodmoderate
mmj
parents: 672
diff changeset
74 const char *mlmmjsend, const char *efromsender)
69
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
75 {
365
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 363
diff changeset
76 char *from, *listfqdn, *listname, *moderators = NULL;
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 487
diff changeset
77 char *buf, *replyto, *listaddr = getlistaddr(listdir), *listdelim;
705
79dd917e0150 ifmodsendonlymodmoderate
mmj
parents: 672
diff changeset
78 char *queuefilename = NULL, *moderatorsfilename, *efromismod = NULL;
365
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 363
diff changeset
79 char *mailbasename = mybasename(mailfilename), *tmp, *to;
729
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
80 int moderatorsfd, foundaddr = 0, notifymod = 0, status;
365
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 363
diff changeset
81 char *maildata[4] = { "moderateaddr", NULL, "moderators", NULL };
729
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
82 pid_t childpid, pid;
181
724a6f752256 Cleanup printf()'s and errorhandling
mmj
parents: 163
diff changeset
83 #if 0
69
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
84 printf("mailfilename = [%s], mailbasename = [%s]\n", mailfilename,
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
85 mailbasename);
181
724a6f752256 Cleanup printf()'s and errorhandling
mmj
parents: 163
diff changeset
86 #endif
365
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 363
diff changeset
87 listfqdn = genlistfqdn(listaddr);
69
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
88 listname = genlistname(listaddr);
365
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 363
diff changeset
89
184
86d7d42fe996 Assorted bugfixes.
mmj
parents: 183
diff changeset
90 moderatorsfilename = concatstr(2, listdir, "/control/moderators");
163
39c46b88720d Lets get rid of stdio shall we :-)
mmj
parents: 135
diff changeset
91 if((moderatorsfd = open(moderatorsfilename, O_RDONLY)) < 0) {
69
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
92 log_error(LOG_ARGS, "Could not open '%s'", moderatorsfilename);
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
93 myfree(moderatorsfilename);
69
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
94 exit(EXIT_FAILURE);
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
95 }
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
96 myfree(moderatorsfilename);
69
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
97
705
79dd917e0150 ifmodsendonlymodmoderate
mmj
parents: 672
diff changeset
98 if(statctrl(listdir, "ifmodsendonlymodmoderate"))
79dd917e0150 ifmodsendonlymodmoderate
mmj
parents: 672
diff changeset
99 efromismod = concatstr(2, efromsender, "\n");
79dd917e0150 ifmodsendonlymodmoderate
mmj
parents: 672
diff changeset
100
365
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 363
diff changeset
101 while((buf = mygetline(moderatorsfd))) {
705
79dd917e0150 ifmodsendonlymodmoderate
mmj
parents: 672
diff changeset
102 if(efromismod && strcmp(buf, efromismod) == 0)
79dd917e0150 ifmodsendonlymodmoderate
mmj
parents: 672
diff changeset
103 foundaddr = 1;
365
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 363
diff changeset
104 tmp = moderators;
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 363
diff changeset
105 moderators = concatstr(2, moderators, buf);
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 363
diff changeset
106 myfree(buf);
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 363
diff changeset
107 myfree(tmp);
69
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
108 }
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
109
705
79dd917e0150 ifmodsendonlymodmoderate
mmj
parents: 672
diff changeset
110 if(!foundaddr) {
79dd917e0150 ifmodsendonlymodmoderate
mmj
parents: 672
diff changeset
111 myfree(efromismod);
79dd917e0150 ifmodsendonlymodmoderate
mmj
parents: 672
diff changeset
112 efromismod = NULL;
79dd917e0150 ifmodsendonlymodmoderate
mmj
parents: 672
diff changeset
113 }
79dd917e0150 ifmodsendonlymodmoderate
mmj
parents: 672
diff changeset
114
365
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 363
diff changeset
115 close(moderatorsfd);
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 363
diff changeset
116
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 487
diff changeset
117 listdelim = getlistdelim(listdir);
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 487
diff changeset
118 replyto = concatstr(6, listname, listdelim, "moderate-", mailbasename,
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 487
diff changeset
119 "@", listfqdn);
365
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 363
diff changeset
120
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 363
diff changeset
121 maildata[1] = replyto;
705
79dd917e0150 ifmodsendonlymodmoderate
mmj
parents: 672
diff changeset
122 if(efromismod) {
79dd917e0150 ifmodsendonlymodmoderate
mmj
parents: 672
diff changeset
123 myfree(moderators);
79dd917e0150 ifmodsendonlymodmoderate
mmj
parents: 672
diff changeset
124 maildata[3] = efromismod;
79dd917e0150 ifmodsendonlymodmoderate
mmj
parents: 672
diff changeset
125 } else
79dd917e0150 ifmodsendonlymodmoderate
mmj
parents: 672
diff changeset
126 maildata[3] = moderators;
275
9a847bfdc764 Don't fail in mlmmj-process b/c of EEXIST on the queuefilenames
mmj
parents: 262
diff changeset
127
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 487
diff changeset
128 from = concatstr(4, listname, listdelim, "owner@", listfqdn);
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 487
diff changeset
129 to = concatstr(3, listname, "-moderators@", listfqdn); /* FIXME JFA: Should this be converted? Why, why not? */
275
9a847bfdc764 Don't fail in mlmmj-process b/c of EEXIST on the queuefilenames
mmj
parents: 262
diff changeset
130
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 487
diff changeset
131 myfree(listdelim);
365
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 363
diff changeset
132 myfree(listname);
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 363
diff changeset
133 myfree(listfqdn);
275
9a847bfdc764 Don't fail in mlmmj-process b/c of EEXIST on the queuefilenames
mmj
parents: 262
diff changeset
134
365
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 363
diff changeset
135 queuefilename = prepstdreply(listdir, "moderation", "$listowner$",
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 739
diff changeset
136 to, replyto, 2, maildata,
729
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
137 mailfilename);
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
138
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
139 /* we might need to exec more than one mlmmj-send */
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
140
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
141 notifymod = !efromismod && statctrl(listdir,"notifymod");
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
142
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
143 if (notifymod) {
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
144 childpid = fork();
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
145 if(childpid < 0)
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
146 log_error(LOG_ARGS, "Could not fork; poster not notified");
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
147 } else
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
148 childpid = -1;
69
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
149
729
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
150 if(childpid != 0) {
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
151 if(childpid > 0) {
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
152 do /* Parent waits for the child */
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
153 pid = waitpid(childpid, &status, 0);
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
154 while(pid == -1 && errno == EINTR);
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
155 }
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
156 if(efromismod)
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
157 execlp(mlmmjsend, mlmmjsend,
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
158 "-l", "1",
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
159 "-L", listdir,
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
160 "-F", from,
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
161 "-m", queuefilename,
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
162 "-T", efromsender, (char *)NULL);
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
163 else
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
164 execlp(mlmmjsend, mlmmjsend,
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
165 "-l", "2",
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
166 "-L", listdir,
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
167 "-F", from,
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
168 "-m", queuefilename, (char *)NULL);
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
169 log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend);
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
170 exit(EXIT_FAILURE);
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
171 }
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
172
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
173 myfree(queuefilename);
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
174
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
175 /* send mail to poster that the list is moderated */
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
176
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
177 queuefilename = prepstdreply(listdir, "moderation-poster",
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
178 "$listowner$", efromsender,
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 739
diff changeset
179 NULL, 1, maildata+2, mailfilename);
729
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
180
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
181 execlp(mlmmjsend, mlmmjsend,
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
182 "-l", "1",
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
183 "-L", listdir,
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
184 "-F", from,
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
185 "-m", queuefilename,
d78eb18576b0 Added feature to notify users when their posts are moderated
Ben Schmidt
parents: 727
diff changeset
186 "-T", efromsender, (char *)NULL);
69
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
187
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
188 log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend);
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
189 exit(EXIT_FAILURE);
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
190 }
18
f54f95a4c53e changed to use log_error() all over
mortenp
parents: 17
diff changeset
191
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
192
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
193 static enum action do_access(struct strlist *rule_strs, struct strlist *hdrs,
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
194 const char *from, const char *listdir)
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
195 {
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
196 int i, j;
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
197 unsigned int match;
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
198 char *rule_ptr;
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
199 char errbuf[128];
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
200 int err;
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
201 enum action act;
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
202 unsigned int not;
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
203 regex_t regexp;
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
204 char *hdr;
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
205
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
206 for (i=0; i<rule_strs->count; i++) {
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
207
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
208 rule_ptr = rule_strs->strs[i];
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
209
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
210 if (strncmp(rule_ptr, "allow", 5) == 0) {
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
211 rule_ptr += 5;
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
212 act = ALLOW;
719
30e6e309891d Added "send" keyword to control/access handling (Ben Schmidt)
mortenp
parents: 705
diff changeset
213 } else if (strncmp(rule_ptr, "send", 4) == 0) {
30e6e309891d Added "send" keyword to control/access handling (Ben Schmidt)
mortenp
parents: 705
diff changeset
214 rule_ptr += 4;
30e6e309891d Added "send" keyword to control/access handling (Ben Schmidt)
mortenp
parents: 705
diff changeset
215 act = SEND;
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
216 } else if (strncmp(rule_ptr, "deny", 4) == 0) {
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
217 rule_ptr += 4;
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
218 act = DENY;
386
7a484c4b7925 Add moderate tag to access rules
mmj
parents: 382
diff changeset
219 } else if (strncmp(rule_ptr, "moderate", 8) == 0) {
7a484c4b7925 Add moderate tag to access rules
mmj
parents: 382
diff changeset
220 rule_ptr += 8;
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
221 act = MODERATE;
640
3770bb64ea17 Added support for 'discard' keyword in access rules (Sascha Sommer)
mortenp
parents: 629
diff changeset
222 } else if (strncmp(rule_ptr, "discard", 7) == 0) {
3770bb64ea17 Added support for 'discard' keyword in access rules (Sascha Sommer)
mortenp
parents: 629
diff changeset
223 rule_ptr += 7;
3770bb64ea17 Added support for 'discard' keyword in access rules (Sascha Sommer)
mortenp
parents: 629
diff changeset
224 act = DISCARD;
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
225 } else {
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
226 errno = 0;
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
227 log_error(LOG_ARGS, "Unable to parse rule #%d \"%s\":"
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
228 " Missing action keyword. Denying post from \"%s\"",
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
229 i, rule_strs->strs[i], from);
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
230 log_oper(listdir, OPLOGFNAME, "Unable to parse rule #%d \"%s\":"
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
231 " Missing action keyword. Denying post from \"%s\"",
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
232 i, rule_strs->strs[i], from);
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
233 return DENY;
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
234 }
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
235
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
236 if (*rule_ptr == ' ') {
257
0d37e01a3f93 Fix a typo.
mmj
parents: 254
diff changeset
237 rule_ptr++;
0d37e01a3f93 Fix a typo.
mmj
parents: 254
diff changeset
238 } else if (*rule_ptr == '\0') {
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
239 /* the rule is a keyword and no regexp */
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
240 log_oper(listdir, OPLOGFNAME, "mlmmj-process: access -"
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
241 " A mail from \"%s\" was %s by rule #%d \"%s\"",
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
242 from, action_strs[act], i, rule_strs->strs[i]);
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
243 return act;
257
0d37e01a3f93 Fix a typo.
mmj
parents: 254
diff changeset
244 } else {
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
245 /* we must have space or end of string */
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
246 errno = 0;
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
247 log_error(LOG_ARGS, "Unable to parse rule #%d \"%s\":"
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
248 " Invalid character after action keyword."
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
249 " Denying post from \"%s\"", i, rule_strs->strs[i], from);
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
250 log_oper(listdir, OPLOGFNAME, "Unable to parse rule #%d \"%s\":"
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
251 " Invalid character after action keyword."
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
252 " Denying post from \"%s\"", i, rule_strs->strs[i], from);
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
253 return DENY;
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
254 }
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
255
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
256 if (*rule_ptr == '!') {
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
257 rule_ptr++;
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
258 not = 1;
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
259 } else {
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
260 not = 0;
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
261 }
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
262
292
958a3ecff04c Remove unanchored dot-star from beginning of regexp
mmj
parents: 291
diff changeset
263 /* remove unanchored ".*" from beginning of regexp to stop the
958a3ecff04c Remove unanchored dot-star from beginning of regexp
mmj
parents: 291
diff changeset
264 * regexp matching to loop so long time it seems like it's
958a3ecff04c Remove unanchored dot-star from beginning of regexp
mmj
parents: 291
diff changeset
265 * hanging */
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
266 if (strncmp(rule_ptr, "^.*", 3) == 0) {
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
267 rule_ptr += 3;
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
268 }
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
269 while (strncmp(rule_ptr, ".*", 2) == 0) {
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
270 rule_ptr += 2;
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
271 }
292
958a3ecff04c Remove unanchored dot-star from beginning of regexp
mmj
parents: 291
diff changeset
272
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
273 if ((err = regcomp(&regexp, rule_ptr,
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
274 REG_EXTENDED | REG_NOSUB | REG_ICASE))) {
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
275 regerror(err, &regexp, errbuf, sizeof(errbuf));
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
276 regfree(&regexp);
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
277 errno = 0;
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
278 log_error(LOG_ARGS, "regcomp() failed for rule #%d \"%s\""
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
279 " (message: '%s') (expression: '%s')"
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
280 " Denying post from \"%s\"",
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
281 i, rule_strs->strs[i], errbuf, rule_ptr, from);
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
282 log_oper(listdir, OPLOGFNAME, "regcomp() failed for rule"
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
283 " #%d \"%s\" (message: '%s') (expression: '%s')"
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
284 " Denying post from \"%s\"",
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
285 i, rule_strs->strs[i], errbuf, rule_ptr, from);
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
286 return DENY;
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
287 }
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
288
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
289 match = 0;
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
290 for (j=0; j<hdrs->count; j++) {
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
291 if (regexec(&regexp, hdrs->strs[j], 0, NULL, 0)
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
292 == 0) {
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
293 match = 1;
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
294 break;
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
295 }
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
296 }
386
7a484c4b7925 Add moderate tag to access rules
mmj
parents: 382
diff changeset
297
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
298 regfree(&regexp);
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
299
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
300 if (match != not) {
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
301 if (match) {
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
302 hdr = mystrdup(hdrs->strs[j]);
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
303 chomp(hdr);
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
304 log_oper(listdir, OPLOGFNAME, "mlmmj-process: access -"
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
305 " A mail from \"%s\" with header \"%s\" was %s by"
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
306 " rule #%d \"%s\"", from, hdr, action_strs[act],
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
307 i, rule_strs->strs[i]);
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
308 myfree(hdr);
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
309 } else {
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
310 log_oper(listdir, OPLOGFNAME, "mlmmj-process: access -"
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
311 " A mail from \"%s\" was %s by rule #%d \"%s\""
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
312 " because no header matched.", from,
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
313 action_strs[act], i, rule_strs->strs[i]);
386
7a484c4b7925 Add moderate tag to access rules
mmj
parents: 382
diff changeset
314 }
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
315 return act;
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
316 }
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
317
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
318 }
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
319
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
320 log_oper(listdir, OPLOGFNAME, "mlmmj-process: access -"
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
321 " A mail from \"%s\" didn't match any rules, and"
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
322 " was denied by default.", from);
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
323 return DENY;
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
324 }
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
325
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
326
568
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
327 static char *recipient_extra(const char *listdir, const char *addr)
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
328 {
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
329 char *listdelim;
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
330 char *delim, *atsign, *ret;
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
331 size_t len;
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
332
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
333 if (!addr)
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
334 return NULL;
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
335
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
336 listdelim = getlistdelim(listdir);
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
337
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
338 delim = strstr(addr, listdelim);
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
339 if (!delim) {
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
340 myfree(listdelim);
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
341 return NULL;
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
342 }
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
343 delim += strlen(listdelim);
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
344 myfree(listdelim);
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
345
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
346 atsign = strrchr(delim, '@');
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
347 if (!atsign)
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
348 return NULL;
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
349
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
350 len = atsign - delim;
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
351 ret = (char *)mymalloc(len + 1);
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
352 strncpy(ret, delim, len);
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
353 ret[len] = '\0';
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
354
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
355 return ret;
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
356 }
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
357
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
358
0
21ce01de8109 Initial revision
mmj
parents:
diff changeset
359 static void print_help(const char *prg)
21ce01de8109 Initial revision
mmj
parents:
diff changeset
360 {
102
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 89
diff changeset
361 printf("Usage: %s -L /path/to/list -m /path/to/mail [-h] [-P] [-V]\n"
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 89
diff changeset
362 " -h: This help\n"
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 89
diff changeset
363 " -L: Full path to list directory\n"
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 89
diff changeset
364 " -m: Full path to mail file\n"
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 89
diff changeset
365 " -P: Don't execute mlmmj-send\n"
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 89
diff changeset
366 " -V: Print version\n", prg);
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 89
diff changeset
367
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 89
diff changeset
368 exit(EXIT_SUCCESS);
0
21ce01de8109 Initial revision
mmj
parents:
diff changeset
369 }
21ce01de8109 Initial revision
mmj
parents:
diff changeset
370
21ce01de8109 Initial revision
mmj
parents:
diff changeset
371 int main(int argc, char **argv)
21ce01de8109 Initial revision
mmj
parents:
diff changeset
372 {
459
42501eca3d2a Alternate listaddresses
mmj
parents: 445
diff changeset
373 int i, j, opt, noprocess = 0, moderated = 0;
727
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
374 int hdrfd, footfd, rawmailfd, donemailfd, omitfd;
602
0b274cc500de modnonsubposts
mmj
parents: 594
diff changeset
375 int subonlypost = 0, addrtocc = 1, intocc = 0, modnonsubposts = 0;
629
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
376 int maxmailsize = 0;
439
b75073f25e60 Add switches to control whether or not mlmmj sends out mails explaining
mmj
parents: 435
diff changeset
377 int notoccdenymails = 0, noaccessdenymails = 0, nosubonlydenymails = 0;
629
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
378 int nomaxmailsizedenymails = 0;
727
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
379 int notmetoo = 0;
11
8e1ebc68ee62 do_all_the_voodo_here introducton plus a massive cleanup
mmj
parents: 1
diff changeset
380 char *listdir = NULL, *mailfile = NULL, *headerfilename = NULL;
8e1ebc68ee62 do_all_the_voodo_here introducton plus a massive cleanup
mmj
parents: 1
diff changeset
381 char *footerfilename = NULL, *donemailname = NULL;
727
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
382 char *randomstr = NULL, *mqueuename, *omitfilename;
47
c4af2c82c631 added primitive bounce handling
mortenp
parents: 39
diff changeset
383 char *mlmmjsend, *mlmmjsub, *mlmmjunsub, *mlmmjbounce;
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 487
diff changeset
384 char *bindir, *subjectprefix, *discardname, *listaddr, *listdelim;
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 350
diff changeset
385 char *listfqdn, *listname, *fromaddr;
568
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
386 char *queuefilename, *recipextra = NULL, *owner = NULL;
629
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
387 char *maxmailsizestr;
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
388 char *maildata[4] = { "posteraddr", NULL, "maxmailsize", NULL };
568
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
389 char *envstr, *efrom;
295
db3bd20566aa uid check et al
mmj
parents: 292
diff changeset
390 struct stat st;
db3bd20566aa uid check et al
mmj
parents: 292
diff changeset
391 uid_t uid;
127
b525c4f78ef7 Use listdir/moderation for the mails up for moderation and use
mmj
parents: 117
diff changeset
392 struct email_container fromemails = { 0, NULL };
11
8e1ebc68ee62 do_all_the_voodo_here introducton plus a massive cleanup
mmj
parents: 1
diff changeset
393 struct email_container toemails = { 0, NULL };
135
ede1002bf6dd get Cc: header as well
mmj
parents: 132
diff changeset
394 struct email_container ccemails = { 0, NULL };
568
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
395 struct email_container rpemails = { 0, NULL };
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
396 struct email_container dtemails = { 0, NULL };
259
3eeb78d058a8 Make sure we initialize
mmj
parents: 258
diff changeset
397 struct strlist *access_rules = NULL;
3eeb78d058a8 Make sure we initialize
mmj
parents: 258
diff changeset
398 struct strlist *delheaders = NULL;
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
399 struct strlist allheaders;
459
42501eca3d2a Alternate listaddresses
mmj
parents: 445
diff changeset
400 struct strlist *alternates = NULL;
11
8e1ebc68ee62 do_all_the_voodo_here introducton plus a massive cleanup
mmj
parents: 1
diff changeset
401 struct mailhdr readhdrs[] = {
127
b525c4f78ef7 Use listdir/moderation for the mails up for moderation and use
mmj
parents: 117
diff changeset
402 { "From:", 0, NULL },
b525c4f78ef7 Use listdir/moderation for the mails up for moderation and use
mmj
parents: 117
diff changeset
403 { "To:", 0, NULL },
135
ede1002bf6dd get Cc: header as well
mmj
parents: 132
diff changeset
404 { "Cc:", 0, NULL },
304
2825f29bb451 Small updates
mmj
parents: 295
diff changeset
405 { "Return-Path:", 0, NULL },
2825f29bb451 Small updates
mmj
parents: 295
diff changeset
406 { "Delivered-To:", 0, NULL },
127
b525c4f78ef7 Use listdir/moderation for the mails up for moderation and use
mmj
parents: 117
diff changeset
407 { NULL, 0, NULL }
11
8e1ebc68ee62 do_all_the_voodo_here introducton plus a massive cleanup
mmj
parents: 1
diff changeset
408 };
38
7f4c75a4a346 dirname(argv[0]) -> dirname(argv0);
mmj
parents: 37
diff changeset
409
208
688011dbc4b7 Add a macro to make sure mlmmj binaries are invoked with full path
mmj
parents: 184
diff changeset
410 CHECKFULLPATH(argv[0]);
688011dbc4b7 Add a macro to make sure mlmmj binaries are invoked with full path
mmj
parents: 184
diff changeset
411
47
c4af2c82c631 added primitive bounce handling
mortenp
parents: 39
diff changeset
412 log_set_name(argv[0]);
c4af2c82c631 added primitive bounce handling
mortenp
parents: 39
diff changeset
413
117
9a39dff171fa added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents: 103
diff changeset
414 bindir = mydirname(argv[0]);
9a39dff171fa added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents: 103
diff changeset
415 mlmmjsend = concatstr(2, bindir, "/mlmmj-send");
9a39dff171fa added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents: 103
diff changeset
416 mlmmjsub = concatstr(2, bindir, "/mlmmj-sub");
9a39dff171fa added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents: 103
diff changeset
417 mlmmjunsub = concatstr(2, bindir, "/mlmmj-unsub");
9a39dff171fa added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents: 103
diff changeset
418 mlmmjbounce = concatstr(2, bindir, "/mlmmj-bounce");
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
419 myfree(bindir);
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
420
12
dd4349f8129d Also add the P option to getopt, not only to the case
mmj
parents: 11
diff changeset
421 while ((opt = getopt(argc, argv, "hVPm:L:")) != -1) {
0
21ce01de8109 Initial revision
mmj
parents:
diff changeset
422 switch(opt) {
21ce01de8109 Initial revision
mmj
parents:
diff changeset
423 case 'L':
21ce01de8109 Initial revision
mmj
parents:
diff changeset
424 listdir = optarg;
21ce01de8109 Initial revision
mmj
parents:
diff changeset
425 break;
21ce01de8109 Initial revision
mmj
parents:
diff changeset
426 case 'm':
21ce01de8109 Initial revision
mmj
parents:
diff changeset
427 mailfile = optarg;
21ce01de8109 Initial revision
mmj
parents:
diff changeset
428 break;
21ce01de8109 Initial revision
mmj
parents:
diff changeset
429 case 'h':
21ce01de8109 Initial revision
mmj
parents:
diff changeset
430 print_help(argv[0]);
21ce01de8109 Initial revision
mmj
parents:
diff changeset
431 break;
11
8e1ebc68ee62 do_all_the_voodo_here introducton plus a massive cleanup
mmj
parents: 1
diff changeset
432 case 'P':
8e1ebc68ee62 do_all_the_voodo_here introducton plus a massive cleanup
mmj
parents: 1
diff changeset
433 noprocess = 1;
8e1ebc68ee62 do_all_the_voodo_here introducton plus a massive cleanup
mmj
parents: 1
diff changeset
434 break;
0
21ce01de8109 Initial revision
mmj
parents:
diff changeset
435 case 'V':
21ce01de8109 Initial revision
mmj
parents:
diff changeset
436 print_version(argv[0]);
69
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
437 exit(EXIT_SUCCESS);
0
21ce01de8109 Initial revision
mmj
parents:
diff changeset
438 }
21ce01de8109 Initial revision
mmj
parents:
diff changeset
439 }
295
db3bd20566aa uid check et al
mmj
parents: 292
diff changeset
440
11
8e1ebc68ee62 do_all_the_voodo_here introducton plus a massive cleanup
mmj
parents: 1
diff changeset
441 if(listdir == NULL || mailfile == NULL) {
0
21ce01de8109 Initial revision
mmj
parents:
diff changeset
442 fprintf(stderr, "You have to specify -L and -m\n");
21ce01de8109 Initial revision
mmj
parents:
diff changeset
443 fprintf(stderr, "%s -h for help\n", argv[0]);
21ce01de8109 Initial revision
mmj
parents:
diff changeset
444 exit(EXIT_FAILURE);
21ce01de8109 Initial revision
mmj
parents:
diff changeset
445 }
21ce01de8109 Initial revision
mmj
parents:
diff changeset
446
295
db3bd20566aa uid check et al
mmj
parents: 292
diff changeset
447 /* Lets make sure no random user tries to send mail to the list */
db3bd20566aa uid check et al
mmj
parents: 292
diff changeset
448 if(listdir) {
db3bd20566aa uid check et al
mmj
parents: 292
diff changeset
449 if(stat(listdir, &st) == 0) {
db3bd20566aa uid check et al
mmj
parents: 292
diff changeset
450 uid = getuid();
db3bd20566aa uid check et al
mmj
parents: 292
diff changeset
451 if(uid && uid != st.st_uid) {
db3bd20566aa uid check et al
mmj
parents: 292
diff changeset
452 log_error(LOG_ARGS,
db3bd20566aa uid check et al
mmj
parents: 292
diff changeset
453 "Have to invoke either as root "
db3bd20566aa uid check et al
mmj
parents: 292
diff changeset
454 "or as the user owning listdir");
db3bd20566aa uid check et al
mmj
parents: 292
diff changeset
455 writen(STDERR_FILENO,
db3bd20566aa uid check et al
mmj
parents: 292
diff changeset
456 "Have to invoke either as root "
db3bd20566aa uid check et al
mmj
parents: 292
diff changeset
457 "or as the user owning listdir\n", 60);
db3bd20566aa uid check et al
mmj
parents: 292
diff changeset
458 exit(EXIT_FAILURE);
db3bd20566aa uid check et al
mmj
parents: 292
diff changeset
459 }
db3bd20566aa uid check et al
mmj
parents: 292
diff changeset
460 } else {
db3bd20566aa uid check et al
mmj
parents: 292
diff changeset
461 log_error(LOG_ARGS, "Could not stat %s", listdir);
db3bd20566aa uid check et al
mmj
parents: 292
diff changeset
462 exit(EXIT_FAILURE);
db3bd20566aa uid check et al
mmj
parents: 292
diff changeset
463 }
db3bd20566aa uid check et al
mmj
parents: 292
diff changeset
464 }
db3bd20566aa uid check et al
mmj
parents: 292
diff changeset
465
275
9a847bfdc764 Don't fail in mlmmj-process b/c of EEXIST on the queuefilenames
mmj
parents: 262
diff changeset
466 do {
9a847bfdc764 Don't fail in mlmmj-process b/c of EEXIST on the queuefilenames
mmj
parents: 262
diff changeset
467 myfree(donemailname);
9a847bfdc764 Don't fail in mlmmj-process b/c of EEXIST on the queuefilenames
mmj
parents: 262
diff changeset
468 myfree(randomstr);
9a847bfdc764 Don't fail in mlmmj-process b/c of EEXIST on the queuefilenames
mmj
parents: 262
diff changeset
469 randomstr = random_str();
9a847bfdc764 Don't fail in mlmmj-process b/c of EEXIST on the queuefilenames
mmj
parents: 262
diff changeset
470 donemailname = concatstr(3, listdir, "/queue/", randomstr);
9a847bfdc764 Don't fail in mlmmj-process b/c of EEXIST on the queuefilenames
mmj
parents: 262
diff changeset
471
9a847bfdc764 Don't fail in mlmmj-process b/c of EEXIST on the queuefilenames
mmj
parents: 262
diff changeset
472 donemailfd = open(donemailname, O_RDWR|O_CREAT|O_EXCL,
9a847bfdc764 Don't fail in mlmmj-process b/c of EEXIST on the queuefilenames
mmj
parents: 262
diff changeset
473 S_IRUSR|S_IWUSR);
9a847bfdc764 Don't fail in mlmmj-process b/c of EEXIST on the queuefilenames
mmj
parents: 262
diff changeset
474
9a847bfdc764 Don't fail in mlmmj-process b/c of EEXIST on the queuefilenames
mmj
parents: 262
diff changeset
475 } while ((donemailfd < 0) && (errno == EEXIST));
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
476
163
39c46b88720d Lets get rid of stdio shall we :-)
mmj
parents: 135
diff changeset
477 if(donemailfd < 0) {
275
9a847bfdc764 Don't fail in mlmmj-process b/c of EEXIST on the queuefilenames
mmj
parents: 262
diff changeset
478 log_error(LOG_ARGS, "could not create %s", donemailname);
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
479 myfree(donemailname);
0
21ce01de8109 Initial revision
mmj
parents:
diff changeset
480 exit(EXIT_FAILURE);
21ce01de8109 Initial revision
mmj
parents:
diff changeset
481 }
163
39c46b88720d Lets get rid of stdio shall we :-)
mmj
parents: 135
diff changeset
482 #if 0
39c46b88720d Lets get rid of stdio shall we :-)
mmj
parents: 135
diff changeset
483 log_error(LOG_ARGS, "donemailname = [%s]\n", donemailname);
39c46b88720d Lets get rid of stdio shall we :-)
mmj
parents: 135
diff changeset
484 #endif
39c46b88720d Lets get rid of stdio shall we :-)
mmj
parents: 135
diff changeset
485 if((rawmailfd = open(mailfile, O_RDONLY)) < 0) {
487
cecbb0d77eb2 Another one
mmj
parents: 484
diff changeset
486 unlink(donemailname);
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
487 myfree(donemailname);
163
39c46b88720d Lets get rid of stdio shall we :-)
mmj
parents: 135
diff changeset
488 log_error(LOG_ARGS, "could not open() input mail file");
0
21ce01de8109 Initial revision
mmj
parents:
diff changeset
489 exit(EXIT_FAILURE);
21ce01de8109 Initial revision
mmj
parents:
diff changeset
490 }
21ce01de8109 Initial revision
mmj
parents:
diff changeset
491
308
5582a75b0a2a added comments about - seemingly - unchecked open() calls
mortenp
parents: 305
diff changeset
492 /* hdrfd is checked in do_all_the_voodo_here(), because the
5582a75b0a2a added comments about - seemingly - unchecked open() calls
mortenp
parents: 305
diff changeset
493 * customheaders file might not exist */
132
24134b985e79 Move footer and customheader to control/. I've been meaning to do this
mmj
parents: 127
diff changeset
494 headerfilename = concatstr(2, listdir, "/control/customheaders");
163
39c46b88720d Lets get rid of stdio shall we :-)
mmj
parents: 135
diff changeset
495 hdrfd = open(headerfilename, O_RDONLY);
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
496 myfree(headerfilename);
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
497
308
5582a75b0a2a added comments about - seemingly - unchecked open() calls
mortenp
parents: 305
diff changeset
498 /* footfd is checked in do_all_the_voodo_here(), see above */
132
24134b985e79 Move footer and customheader to control/. I've been meaning to do this
mmj
parents: 127
diff changeset
499 footerfilename = concatstr(2, listdir, "/control/footer");
163
39c46b88720d Lets get rid of stdio shall we :-)
mmj
parents: 135
diff changeset
500 footfd = open(footerfilename, O_RDONLY);
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
501 myfree(footerfilename);
233
3b4fa52561d6 Implement control/delheaders in where one can specify all the headers
mmj
parents: 228
diff changeset
502
3b4fa52561d6 Implement control/delheaders in where one can specify all the headers
mmj
parents: 228
diff changeset
503 delheaders = ctrlvalues(listdir, "delheaders");
3b4fa52561d6 Implement control/delheaders in where one can specify all the headers
mmj
parents: 228
diff changeset
504 if(delheaders == NULL) {
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
505 delheaders = mymalloc(sizeof(struct strlist));
233
3b4fa52561d6 Implement control/delheaders in where one can specify all the headers
mmj
parents: 228
diff changeset
506 delheaders->count = 0;
3b4fa52561d6 Implement control/delheaders in where one can specify all the headers
mmj
parents: 228
diff changeset
507 delheaders->strs = NULL;
3b4fa52561d6 Implement control/delheaders in where one can specify all the headers
mmj
parents: 228
diff changeset
508 }
3b4fa52561d6 Implement control/delheaders in where one can specify all the headers
mmj
parents: 228
diff changeset
509
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
510 delheaders->strs = myrealloc(delheaders->strs,
233
3b4fa52561d6 Implement control/delheaders in where one can specify all the headers
mmj
parents: 228
diff changeset
511 (delheaders->count+3) * sizeof(char *));
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
512 delheaders->strs[delheaders->count++] = mystrdup("From ");
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
513 delheaders->strs[delheaders->count++] = mystrdup("Return-Path:");
381
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
514 delheaders->strs[delheaders->count] = NULL;
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
515
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
516 subjectprefix = ctrlvalue(listdir, "prefix");
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
517
163
39c46b88720d Lets get rid of stdio shall we :-)
mmj
parents: 135
diff changeset
518 if(do_all_the_voodo_here(rawmailfd, donemailfd, hdrfd, footfd,
233
3b4fa52561d6 Implement control/delheaders in where one can specify all the headers
mmj
parents: 228
diff changeset
519 (const char**)delheaders->strs, readhdrs,
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
520 &allheaders, subjectprefix) < 0) {
183
2ec251b9a2f8 getlistaddr was tought that listaddress moved to control/listaddress
mmj
parents: 181
diff changeset
521 log_error(LOG_ARGS, "Error in do_all_the_voodo_here");
163
39c46b88720d Lets get rid of stdio shall we :-)
mmj
parents: 135
diff changeset
522 exit(EXIT_FAILURE);
39c46b88720d Lets get rid of stdio shall we :-)
mmj
parents: 135
diff changeset
523 }
0
21ce01de8109 Initial revision
mmj
parents:
diff changeset
524
233
3b4fa52561d6 Implement control/delheaders in where one can specify all the headers
mmj
parents: 228
diff changeset
525 for(i = 0; i < delheaders->count; i++)
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
526 myfree(delheaders->strs[i]);
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
527 myfree(delheaders->strs);
233
3b4fa52561d6 Implement control/delheaders in where one can specify all the headers
mmj
parents: 228
diff changeset
528
163
39c46b88720d Lets get rid of stdio shall we :-)
mmj
parents: 135
diff changeset
529 close(rawmailfd);
39c46b88720d Lets get rid of stdio shall we :-)
mmj
parents: 135
diff changeset
530 close(donemailfd);
0
21ce01de8109 Initial revision
mmj
parents:
diff changeset
531
350
f88b108b82b6 Add one free() and do a little fd cleanup
mmj
parents: 347
diff changeset
532 if(hdrfd >= 0)
163
39c46b88720d Lets get rid of stdio shall we :-)
mmj
parents: 135
diff changeset
533 close(hdrfd);
350
f88b108b82b6 Add one free() and do a little fd cleanup
mmj
parents: 347
diff changeset
534 if(footfd >= 0)
163
39c46b88720d Lets get rid of stdio shall we :-)
mmj
parents: 135
diff changeset
535 close(footfd);
11
8e1ebc68ee62 do_all_the_voodo_here introducton plus a massive cleanup
mmj
parents: 1
diff changeset
536
568
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
537 /* From: addresses */
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
538 for(i = 0; i < readhdrs[0].valuecount; i++) {
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
539 find_email_adr(readhdrs[0].values[i], &fromemails);
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
540 }
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
541
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
542 /* To: addresses */
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
543 for(i = 0; i < readhdrs[1].valuecount; i++) {
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
544 find_email_adr(readhdrs[1].values[i], &toemails);
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
545 }
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
546
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
547 /* Cc: addresses */
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
548 for(i = 0; i < readhdrs[2].valuecount; i++) {
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
549 find_email_adr(readhdrs[2].values[i], &ccemails);
11
8e1ebc68ee62 do_all_the_voodo_here introducton plus a massive cleanup
mmj
parents: 1
diff changeset
550 }
8e1ebc68ee62 do_all_the_voodo_here introducton plus a massive cleanup
mmj
parents: 1
diff changeset
551
568
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
552 /* Return-Path: addresses */
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
553 for(i = 0; i < readhdrs[3].valuecount; i++) {
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
554 find_email_adr(readhdrs[3].values[i], &rpemails);
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
555 }
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
556
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
557 /* Delivered-To: addresses */
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
558 for(i = 0; i < readhdrs[4].valuecount; i++) {
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
559 find_email_adr(readhdrs[4].values[i], &dtemails);
127
b525c4f78ef7 Use listdir/moderation for the mails up for moderation and use
mmj
parents: 117
diff changeset
560 }
135
ede1002bf6dd get Cc: header as well
mmj
parents: 132
diff changeset
561
568
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
562 /* envelope from */
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
563 if((envstr = getenv("SENDER")) != NULL) {
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
564 /* qmail, postfix, exim */
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
565 efrom = mystrdup(envstr);
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
566 } else if(rpemails.emailcount >= 1) {
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
567 /* the (first) Return-Path: header */
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
568 efrom = mystrdup(rpemails.emaillist[0]);
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
569 } else {
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
570 efrom = mystrdup("");
127
b525c4f78ef7 Use listdir/moderation for the mails up for moderation and use
mmj
parents: 117
diff changeset
571 }
227
f6d2166f10c8 +owner functionality
mmj
parents: 225
diff changeset
572
568
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
573 /* address extension (the "foo" part of "user+foo@domain.tld") */
594
9d4d9beb8642 Changed mlmmj-process to look at environment variable DEFAULT instead of EXT for qmail
mortenp
parents: 568
diff changeset
574 if((envstr = getenv("DEFAULT")) != NULL) {
568
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
575 /* qmail */
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
576 recipextra = mystrdup(envstr);
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
577 } else if((envstr = getenv("EXTENSION")) != NULL) {
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
578 /* postfix */
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
579 recipextra = mystrdup(envstr);
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
580 } else if((envstr = getenv("LOCAL_PART_SUFFIX")) != NULL) {
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
581 /* exim */
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
582 listdelim = getlistdelim(listdir);
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
583 if (strncmp(envstr, listdelim, strlen(listdelim)) == 0) {
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
584 recipextra = mystrdup(envstr + strlen(listdelim));
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
585 } else {
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
586 recipextra = mystrdup(envstr);
227
f6d2166f10c8 +owner functionality
mmj
parents: 225
diff changeset
587 }
568
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
588 myfree(listdelim);
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
589 } else if(dtemails.emailcount >= 1) {
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
590 /* parse the (first) Delivered-To: header */
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
591 recipextra = recipient_extra(listdir, dtemails.emaillist[0]);
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
592 } else if(toemails.emailcount >= 1) {
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
593 /* parse the (first) To: header */
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
594 recipextra = recipient_extra(listdir, toemails.emaillist[0]);
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
595 } else {
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
596 recipextra = NULL;
304
2825f29bb451 Small updates
mmj
parents: 295
diff changeset
597 }
2825f29bb451 Small updates
mmj
parents: 295
diff changeset
598
568
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
599 if(recipextra && (strlen(recipextra) == 0)) {
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
600 myfree(recipextra);
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
601 recipextra = NULL;
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
602 }
347
b15e8c2dc97f When using Delivered-To: for spotting the recipient delimiter we
mmj
parents: 340
diff changeset
603
568
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
604 /* Why is this here, and not in listcontrol() ? -- mortenp 20060409 */
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 487
diff changeset
605 if(recipextra) {
291
7da5c55b9330 0.8.3 commit
mmj
parents: 287
diff changeset
606 owner = concatstr(2, listdir, "/control/owner");
568
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
607 if(owner && strcmp(recipextra, "owner") == 0) {
381
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
608 /* strip envelope from before resending */
382
7ff4d8124226 Don't try to realloc unless we own already
mmj
parents: 381
diff changeset
609 delheaders->count = 0;
7ff4d8124226 Don't try to realloc unless we own already
mmj
parents: 381
diff changeset
610 delheaders->strs = NULL;
381
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
611 delheaders->strs = myrealloc(delheaders->strs,
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
612 (delheaders->count+3) * sizeof(char *));
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
613 delheaders->strs[delheaders->count++] =
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
614 mystrdup("From ");
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
615 delheaders->strs[delheaders->count++] =
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
616 mystrdup("Return-Path:");
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
617 delheaders->strs[delheaders->count] = NULL;
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
618 if((rawmailfd = open(mailfile, O_RDONLY)) < 0) {
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
619 log_error(LOG_ARGS, "could not open() "
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
620 "input mail file");
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
621 exit(EXIT_FAILURE);
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
622 }
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
623 if((donemailfd = open(donemailname,
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
624 O_WRONLY|O_TRUNC)) < 0) {
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
625 log_error(LOG_ARGS, "could not open() "
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
626 "output mail file");
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
627 exit(EXIT_FAILURE);
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
628 }
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
629 if(do_all_the_voodo_here(rawmailfd, donemailfd, -1,
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
630 -1, (const char**)delheaders->strs,
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
631 NULL, &allheaders, NULL) < 0) {
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
632 log_error(LOG_ARGS, "do_all_the_voodo_here");
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
633 exit(EXIT_FAILURE);
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
634 }
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
635 close(rawmailfd);
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
636 close(donemailfd);
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
637 unlink(mailfile);
430
4ec6c541b7c0 Logging
mmj
parents: 386
diff changeset
638 log_oper(listdir, OPLOGFNAME, "mlmmj-recieve: sending"
4ec6c541b7c0 Logging
mmj
parents: 386
diff changeset
639 " mail from %s to owner",
568
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
640 efrom);
227
f6d2166f10c8 +owner functionality
mmj
parents: 225
diff changeset
641 execlp(mlmmjsend, mlmmjsend,
228
fda21d560980 Make it possible to specify several owner emailaddresses, not just one
mmj
parents: 227
diff changeset
642 "-l", "4",
529
d65b467b647d Pass on listdir to mlmmjsend so we can get the smtpport and relayhost also
mmj
parents: 523
diff changeset
643 "-L", listdir,
568
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
644 "-F", efrom,
228
fda21d560980 Make it possible to specify several owner emailaddresses, not just one
mmj
parents: 227
diff changeset
645 "-s", owner,
227
f6d2166f10c8 +owner functionality
mmj
parents: 225
diff changeset
646 "-a",
435
65781b43a7b9 - subswitch, NULL);
mmj
parents: 430
diff changeset
647 "-m", donemailname, (char *)NULL);
227
f6d2166f10c8 +owner functionality
mmj
parents: 225
diff changeset
648 log_error(LOG_ARGS, "execlp() of '%s' failed",
f6d2166f10c8 +owner functionality
mmj
parents: 225
diff changeset
649 mlmmjsend);
f6d2166f10c8 +owner functionality
mmj
parents: 225
diff changeset
650 exit(EXIT_FAILURE);
f6d2166f10c8 +owner functionality
mmj
parents: 225
diff changeset
651 }
58
990e1a4ae6d0 Small typo and bouncehandling now works
mmj
parents: 52
diff changeset
652 #if 0
127
b525c4f78ef7 Use listdir/moderation for the mails up for moderation and use
mmj
parents: 117
diff changeset
653 log_error(LOG_ARGS, "listcontrol(from, %s, %s, %s, %s, %s, %s)\n", listdir, toemails.emaillist[0], mlmmjsub, mlmmjunsub, mlmmjsend, mlmmjbounce);
58
990e1a4ae6d0 Small typo and bouncehandling now works
mmj
parents: 52
diff changeset
654 #endif
227
f6d2166f10c8 +owner functionality
mmj
parents: 225
diff changeset
655 unlink(mailfile);
568
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
656 listcontrol(&fromemails, listdir, recipextra,
163
39c46b88720d Lets get rid of stdio shall we :-)
mmj
parents: 135
diff changeset
657 mlmmjsub, mlmmjunsub, mlmmjsend, mlmmjbounce,
39c46b88720d Lets get rid of stdio shall we :-)
mmj
parents: 135
diff changeset
658 donemailname);
536
ccb245244750 added unlink()ing of listcontrol messages (was in listcontrol.c)
mortenp
parents: 534
diff changeset
659
11
8e1ebc68ee62 do_all_the_voodo_here introducton plus a massive cleanup
mmj
parents: 1
diff changeset
660 return EXIT_SUCCESS;
8e1ebc68ee62 do_all_the_voodo_here introducton plus a massive cleanup
mmj
parents: 1
diff changeset
661 }
221
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
662
629
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
663 listaddr = getlistaddr(listdir);
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
664 alternates = ctrlvalues(listdir, "listaddress");
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
665
629
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
666 /* checking incoming mail's size */
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
667 maxmailsizestr = ctrlvalue(listdir, "maxmailsize");
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
668 if(maxmailsizestr) {
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
669 maxmailsize = atol(maxmailsizestr);
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
670 if(stat(donemailname, &st) < 0) {
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
671 log_error(LOG_ARGS, "stat(%s,..) failed", donemailname);
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
672 exit(EXIT_FAILURE);
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
673 }
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
674
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
675 if(st.st_size > maxmailsize) {
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
676
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
677 nomaxmailsizedenymails = statctrl(listdir, "nomaxmailsizedenymails");
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
678 if (nomaxmailsizedenymails) {
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
679 errno = 0;
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
680 log_error(LOG_ARGS, "Discarding %s due to"
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
681 " size limit (%d bytes too big)",
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
682 donemailname, (st.st_size - maxmailsize));
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
683 unlink(donemailname);
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
684 unlink(mailfile);
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
685 myfree(donemailname);
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
686 myfree(maxmailsizestr);
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
687 exit(EXIT_SUCCESS);
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
688 }
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
689
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
690 listdelim = getlistdelim(listdir);
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
691 listname = genlistname(listaddr);
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
692 listfqdn = genlistfqdn(listaddr);
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
693 fromaddr = concatstr(4, listname, listdelim,
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
694 "bounces-help@", listfqdn);
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
695 maildata[3] = maxmailsizestr;
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
696 queuefilename = prepstdreply(listdir,
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
697 "maxmailsize", "$listowner$",
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
698 fromemails.emaillist[0],
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 739
diff changeset
699 NULL, 1, maildata+2, donemailname);
629
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
700 MY_ASSERT(queuefilename)
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
701 myfree(listdelim);
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
702 myfree(listname);
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
703 myfree(listfqdn);
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
704 unlink(donemailname);
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
705 unlink(mailfile);
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
706 myfree(donemailname);
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
707 myfree(maxmailsizestr);
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
708 execlp(mlmmjsend, mlmmjsend,
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
709 "-l", "1",
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
710 "-L", listdir,
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
711 "-T", fromemails.emaillist[0],
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
712 "-F", fromaddr,
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
713 "-m", queuefilename, (char *)NULL);
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
714
629
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
715 log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend);
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
716 exit(EXIT_FAILURE);
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
717 }
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
718 }
61e93e5c3ecf Added support for mail size limit (Christoph Wilke)
mortenp
parents: 626
diff changeset
719
484
2855bbfb74fe Allow bounces with no From:
mmj
parents: 459
diff changeset
720 /* discard malformed mail with invalid From: */
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
721 if(fromemails.emailcount != 1) {
532
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
722 for(i = 0; i < fromemails.emailcount; i++)
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
723 printf("fromemails.emaillist[%d] = %s\n",
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
724 i, fromemails.emaillist[i]);
484
2855bbfb74fe Allow bounces with no From:
mmj
parents: 459
diff changeset
725 discardname = concatstr(3, listdir,
2855bbfb74fe Allow bounces with no From:
mmj
parents: 459
diff changeset
726 "/queue/discarded/", randomstr);
532
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
727 log_error(LOG_ARGS, "Discarding %s due to invalid From:",
67d663145da5 Make sub/unsub/bounce lowercase all the time
mmj
parents: 529
diff changeset
728 mailfile);
533
40c505c297f5 README and logging of discarded From: emails
mmj
parents: 532
diff changeset
729 for(i = 0; i < fromemails.emailcount; i++)
40c505c297f5 README and logging of discarded From: emails
mmj
parents: 532
diff changeset
730 log_error(LOG_ARGS, "fromemails.emaillist[%d] = %s\n",
40c505c297f5 README and logging of discarded From: emails
mmj
parents: 532
diff changeset
731 i, fromemails.emaillist[i]);
484
2855bbfb74fe Allow bounces with no From:
mmj
parents: 459
diff changeset
732 rename(mailfile, discardname);
2855bbfb74fe Allow bounces with no From:
mmj
parents: 459
diff changeset
733 unlink(donemailname);
2855bbfb74fe Allow bounces with no From:
mmj
parents: 459
diff changeset
734 myfree(donemailname);
2855bbfb74fe Allow bounces with no From:
mmj
parents: 459
diff changeset
735 myfree(discardname);
2855bbfb74fe Allow bounces with no From:
mmj
parents: 459
diff changeset
736 myfree(randomstr);
2855bbfb74fe Allow bounces with no From:
mmj
parents: 459
diff changeset
737 /* TODO: free emailstructs */
2855bbfb74fe Allow bounces with no From:
mmj
parents: 459
diff changeset
738 exit(EXIT_SUCCESS);
2855bbfb74fe Allow bounces with no From:
mmj
parents: 459
diff changeset
739 }
2855bbfb74fe Allow bounces with no From:
mmj
parents: 459
diff changeset
740
381
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
741 myfree(delheaders);
12d91031f1c7 Before sending the mail to +owner, we should strip
mmj
parents: 365
diff changeset
742
568
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
743 if(strcmp(efrom, "") == 0) { /* don't send mails with <> in From
305
743c858b21c3 See ChangeLog
mmj
parents: 304
diff changeset
744 to the list */
743c858b21c3 See ChangeLog
mmj
parents: 304
diff changeset
745 discardname = concatstr(3, listdir,
743c858b21c3 See ChangeLog
mmj
parents: 304
diff changeset
746 "/queue/discarded/",
743c858b21c3 See ChangeLog
mmj
parents: 304
diff changeset
747 randomstr);
568
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
748 errno = 0;
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
749 log_error(LOG_ARGS, "Discarding %s due to missing envelope"
99f493df54af Add support for qmail (envelope from address in environment variable)
mortenp
parents: 562
diff changeset
750 " from address", mailfile);
333
d70614c2d99e Save the raw incoming mail when discarding, not the processed one.
mmj
parents: 312
diff changeset
751 rename(mailfile, discardname);
d70614c2d99e Save the raw incoming mail when discarding, not the processed one.
mmj
parents: 312
diff changeset
752 unlink(donemailname);
305
743c858b21c3 See ChangeLog
mmj
parents: 304
diff changeset
753 myfree(donemailname);
743c858b21c3 See ChangeLog
mmj
parents: 304
diff changeset
754 myfree(discardname);
743c858b21c3 See ChangeLog
mmj
parents: 304
diff changeset
755 myfree(randomstr);
743c858b21c3 See ChangeLog
mmj
parents: 304
diff changeset
756 /* TODO: free emailstructs */
743c858b21c3 See ChangeLog
mmj
parents: 304
diff changeset
757 exit(EXIT_SUCCESS);
743c858b21c3 See ChangeLog
mmj
parents: 304
diff changeset
758 }
743c858b21c3 See ChangeLog
mmj
parents: 304
diff changeset
759
333
d70614c2d99e Save the raw incoming mail when discarding, not the processed one.
mmj
parents: 312
diff changeset
760 unlink(mailfile);
d70614c2d99e Save the raw incoming mail when discarding, not the processed one.
mmj
parents: 312
diff changeset
761
221
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
762 addrtocc = !(statctrl(listdir, "tocc"));
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
763 if(addrtocc) {
459
42501eca3d2a Alternate listaddresses
mmj
parents: 445
diff changeset
764 for(i = 0; i < toemails.emailcount; i++) {
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
765 log_error(LOG_ARGS, "Found To: %s",
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
766 toemails.emaillist[i]);
459
42501eca3d2a Alternate listaddresses
mmj
parents: 445
diff changeset
767 for(j = 0; j < alternates->count; j++) {
42501eca3d2a Alternate listaddresses
mmj
parents: 445
diff changeset
768 chomp(alternates->strs[j]);
523
87b58797c92d *** empty log message ***
mmj
parents: 520
diff changeset
769 if(strcasecmp(alternates->strs[j],
459
42501eca3d2a Alternate listaddresses
mmj
parents: 445
diff changeset
770 toemails.emaillist[i]) == 0)
42501eca3d2a Alternate listaddresses
mmj
parents: 445
diff changeset
771 intocc = 1;
42501eca3d2a Alternate listaddresses
mmj
parents: 445
diff changeset
772 }
42501eca3d2a Alternate listaddresses
mmj
parents: 445
diff changeset
773 }
42501eca3d2a Alternate listaddresses
mmj
parents: 445
diff changeset
774 for(i = 0; i < ccemails.emailcount; i++) {
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
775 log_error(LOG_ARGS, "Found Cc: %s",
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
776 ccemails.emaillist[i]);
459
42501eca3d2a Alternate listaddresses
mmj
parents: 445
diff changeset
777 for(j = 0; j < alternates->count; j++) {
42501eca3d2a Alternate listaddresses
mmj
parents: 445
diff changeset
778 chomp(alternates->strs[j]);
523
87b58797c92d *** empty log message ***
mmj
parents: 520
diff changeset
779 if(strcasecmp(alternates->strs[j],
459
42501eca3d2a Alternate listaddresses
mmj
parents: 445
diff changeset
780 ccemails.emaillist[i]) == 0)
42501eca3d2a Alternate listaddresses
mmj
parents: 445
diff changeset
781 intocc = 1;
42501eca3d2a Alternate listaddresses
mmj
parents: 445
diff changeset
782 }
42501eca3d2a Alternate listaddresses
mmj
parents: 445
diff changeset
783 }
221
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
784 }
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
785
459
42501eca3d2a Alternate listaddresses
mmj
parents: 445
diff changeset
786 for(i = 0; i < alternates->count; i++)
42501eca3d2a Alternate listaddresses
mmj
parents: 445
diff changeset
787 myfree(alternates->strs[i]);
42501eca3d2a Alternate listaddresses
mmj
parents: 445
diff changeset
788
439
b75073f25e60 Add switches to control whether or not mlmmj sends out mails explaining
mmj
parents: 435
diff changeset
789 notoccdenymails = statctrl(listdir, "notoccdenymails");
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
790
221
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
791 if(addrtocc && !intocc) {
339
6ec796e27f54 Sanity checks
mmj
parents: 333
diff changeset
792 /* Don't send a mail about denial to the list, but silently
439
b75073f25e60 Add switches to control whether or not mlmmj sends out mails explaining
mmj
parents: 435
diff changeset
793 * discard and exit. Also don't in case of it being turned off
b75073f25e60 Add switches to control whether or not mlmmj sends out mails explaining
mmj
parents: 435
diff changeset
794 */
b75073f25e60 Add switches to control whether or not mlmmj sends out mails explaining
mmj
parents: 435
diff changeset
795 if ((strcasecmp(listaddr, fromemails.emaillist[0]) == 0) ||
b75073f25e60 Add switches to control whether or not mlmmj sends out mails explaining
mmj
parents: 435
diff changeset
796 notoccdenymails) {
534
4f099cb2099b Added log messages at points where mail is discarded
mortenp
parents: 533
diff changeset
797 log_error(LOG_ARGS, "Discarding %s because list"
4f099cb2099b Added log messages at points where mail is discarded
mortenp
parents: 533
diff changeset
798 " address was not in To: or Cc:,"
4f099cb2099b Added log messages at points where mail is discarded
mortenp
parents: 533
diff changeset
799 " and From: was the list or"
4f099cb2099b Added log messages at points where mail is discarded
mortenp
parents: 533
diff changeset
800 " notoccdenymails was set",
4f099cb2099b Added log messages at points where mail is discarded
mortenp
parents: 533
diff changeset
801 mailfile);
339
6ec796e27f54 Sanity checks
mmj
parents: 333
diff changeset
802 myfree(listaddr);
6ec796e27f54 Sanity checks
mmj
parents: 333
diff changeset
803 unlink(donemailname);
6ec796e27f54 Sanity checks
mmj
parents: 333
diff changeset
804 myfree(donemailname);
6ec796e27f54 Sanity checks
mmj
parents: 333
diff changeset
805 exit(EXIT_SUCCESS);
6ec796e27f54 Sanity checks
mmj
parents: 333
diff changeset
806 }
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 487
diff changeset
807 listdelim = getlistdelim(listdir);
221
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
808 listname = genlistname(listaddr);
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
809 listfqdn = genlistfqdn(listaddr);
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 487
diff changeset
810 fromaddr = concatstr(4, listname, listdelim, "bounces-help@",
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 487
diff changeset
811 listfqdn);
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 350
diff changeset
812 queuefilename = prepstdreply(listdir, "notintocc",
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 350
diff changeset
813 "$listowner$", fromemails.emaillist[0],
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 739
diff changeset
814 NULL, 0, NULL, donemailname);
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
815 MY_ASSERT(queuefilename)
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 487
diff changeset
816 myfree(listdelim);
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
817 myfree(listname);
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
818 myfree(listfqdn);
262
846d91ae6ebe Don't litter the queue directory when rejecting posts for one reason or the
mmj
parents: 259
diff changeset
819 unlink(donemailname);
846d91ae6ebe Don't litter the queue directory when rejecting posts for one reason or the
mmj
parents: 259
diff changeset
820 myfree(donemailname);
221
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
821 execlp(mlmmjsend, mlmmjsend,
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
822 "-l", "1",
529
d65b467b647d Pass on listdir to mlmmjsend so we can get the smtpport and relayhost also
mmj
parents: 523
diff changeset
823 "-L", listdir,
221
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
824 "-T", fromemails.emaillist[0],
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
825 "-F", fromaddr,
435
65781b43a7b9 - subswitch, NULL);
mmj
parents: 430
diff changeset
826 "-m", queuefilename, (char *)NULL);
221
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
827
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
828 log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend);
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
829 exit(EXIT_FAILURE);
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
830 }
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
831
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
832 subonlypost = statctrl(listdir, "subonlypost");
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
833 if(subonlypost) {
339
6ec796e27f54 Sanity checks
mmj
parents: 333
diff changeset
834 /* Don't send a mail about denial to the list, but silently
440
ba5a6cda33af Move nosubonlydenymails check to the right place
mmj
parents: 439
diff changeset
835 * discard and exit. */
ba5a6cda33af Move nosubonlydenymails check to the right place
mmj
parents: 439
diff changeset
836 if (strcasecmp(listaddr, fromemails.emaillist[0]) == 0) {
534
4f099cb2099b Added log messages at points where mail is discarded
mortenp
parents: 533
diff changeset
837 log_error(LOG_ARGS, "Discarding %s because"
4f099cb2099b Added log messages at points where mail is discarded
mortenp
parents: 533
diff changeset
838 " subonlypost was set and From: was"
4f099cb2099b Added log messages at points where mail is discarded
mortenp
parents: 533
diff changeset
839 " the list address",
4f099cb2099b Added log messages at points where mail is discarded
mortenp
parents: 533
diff changeset
840 mailfile);
339
6ec796e27f54 Sanity checks
mmj
parents: 333
diff changeset
841 myfree(listaddr);
6ec796e27f54 Sanity checks
mmj
parents: 333
diff changeset
842 unlink(donemailname);
6ec796e27f54 Sanity checks
mmj
parents: 333
diff changeset
843 myfree(donemailname);
6ec796e27f54 Sanity checks
mmj
parents: 333
diff changeset
844 exit(EXIT_SUCCESS);
6ec796e27f54 Sanity checks
mmj
parents: 333
diff changeset
845 }
221
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
846 if(is_subbed(listdir, fromemails.emaillist[0]) != 0) {
602
0b274cc500de modnonsubposts
mmj
parents: 594
diff changeset
847 modnonsubposts = statctrl(listdir,
0b274cc500de modnonsubposts
mmj
parents: 594
diff changeset
848 "modnonsubposts");
0b274cc500de modnonsubposts
mmj
parents: 594
diff changeset
849 if(modnonsubposts) {
0b274cc500de modnonsubposts
mmj
parents: 594
diff changeset
850 moderated = 1;
0b274cc500de modnonsubposts
mmj
parents: 594
diff changeset
851 goto startaccess;
0b274cc500de modnonsubposts
mmj
parents: 594
diff changeset
852 }
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
853
602
0b274cc500de modnonsubposts
mmj
parents: 594
diff changeset
854 nosubonlydenymails = statctrl(listdir,
0b274cc500de modnonsubposts
mmj
parents: 594
diff changeset
855 "nosubonlydenymails");
0b274cc500de modnonsubposts
mmj
parents: 594
diff changeset
856
440
ba5a6cda33af Move nosubonlydenymails check to the right place
mmj
parents: 439
diff changeset
857 if(nosubonlydenymails) {
534
4f099cb2099b Added log messages at points where mail is discarded
mortenp
parents: 533
diff changeset
858 log_error(LOG_ARGS, "Discarding %s because"
4f099cb2099b Added log messages at points where mail is discarded
mortenp
parents: 533
diff changeset
859 " subonlypost and"
4f099cb2099b Added log messages at points where mail is discarded
mortenp
parents: 533
diff changeset
860 " nosubonlydenymails was set",
4f099cb2099b Added log messages at points where mail is discarded
mortenp
parents: 533
diff changeset
861 mailfile);
440
ba5a6cda33af Move nosubonlydenymails check to the right place
mmj
parents: 439
diff changeset
862 myfree(listaddr);
ba5a6cda33af Move nosubonlydenymails check to the right place
mmj
parents: 439
diff changeset
863 unlink(donemailname);
ba5a6cda33af Move nosubonlydenymails check to the right place
mmj
parents: 439
diff changeset
864 myfree(donemailname);
ba5a6cda33af Move nosubonlydenymails check to the right place
mmj
parents: 439
diff changeset
865 exit(EXIT_SUCCESS);
ba5a6cda33af Move nosubonlydenymails check to the right place
mmj
parents: 439
diff changeset
866 }
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 487
diff changeset
867 listdelim = getlistdelim(listdir);
221
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
868 listname = genlistname(listaddr);
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
869 listfqdn = genlistfqdn(listaddr);
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 350
diff changeset
870 maildata[1] = fromemails.emaillist[0];
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 487
diff changeset
871 fromaddr = concatstr(4, listname, listdelim,
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 487
diff changeset
872 "bounces-help@", listfqdn);
221
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
873 queuefilename = prepstdreply(listdir, "subonlypost",
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 350
diff changeset
874 "$listowner$", fromemails.emaillist[0],
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 739
diff changeset
875 NULL, 1, maildata, donemailname);
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
876 MY_ASSERT(queuefilename)
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
877 myfree(listaddr);
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 487
diff changeset
878 myfree(listdelim);
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
879 myfree(listname);
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
880 myfree(listfqdn);
262
846d91ae6ebe Don't litter the queue directory when rejecting posts for one reason or the
mmj
parents: 259
diff changeset
881 unlink(donemailname);
846d91ae6ebe Don't litter the queue directory when rejecting posts for one reason or the
mmj
parents: 259
diff changeset
882 myfree(donemailname);
221
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
883 execlp(mlmmjsend, mlmmjsend,
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
884 "-l", "1",
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
885 "-T", fromemails.emaillist[0],
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
886 "-F", fromaddr,
435
65781b43a7b9 - subswitch, NULL);
mmj
parents: 430
diff changeset
887 "-m", queuefilename, (char *)NULL);
221
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
888
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
889 log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend);
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
890 exit(EXIT_FAILURE);
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
891 }
1673fe779f37 Add functionality for subscribers only posting and to only allow posts with
mmj
parents: 208
diff changeset
892 }
11
8e1ebc68ee62 do_all_the_voodo_here introducton plus a massive cleanup
mmj
parents: 1
diff changeset
893
602
0b274cc500de modnonsubposts
mmj
parents: 594
diff changeset
894 startaccess:
727
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
895
719
30e6e309891d Added "send" keyword to control/access handling (Ben Schmidt)
mortenp
parents: 705
diff changeset
896 if(!moderated)
30e6e309891d Added "send" keyword to control/access handling (Ben Schmidt)
mortenp
parents: 705
diff changeset
897 moderated = statctrl(listdir, "moderated");
30e6e309891d Added "send" keyword to control/access handling (Ben Schmidt)
mortenp
parents: 705
diff changeset
898
439
b75073f25e60 Add switches to control whether or not mlmmj sends out mails explaining
mmj
parents: 435
diff changeset
899 noaccessdenymails = statctrl(listdir, "noaccessdenymails");
b75073f25e60 Add switches to control whether or not mlmmj sends out mails explaining
mmj
parents: 435
diff changeset
900
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
901 access_rules = ctrlvalues(listdir, "access");
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
902 if (access_rules) {
386
7a484c4b7925 Add moderate tag to access rules
mmj
parents: 382
diff changeset
903 enum action accret;
339
6ec796e27f54 Sanity checks
mmj
parents: 333
diff changeset
904 /* Don't send a mail about denial to the list, but silently
439
b75073f25e60 Add switches to control whether or not mlmmj sends out mails explaining
mmj
parents: 435
diff changeset
905 * discard and exit. Also do this in case it's turned off */
626
a07129231d84 cleaned up do_access() and added more logging
mortenp
parents: 602
diff changeset
906 accret = do_access(access_rules, &allheaders,
705
79dd917e0150 ifmodsendonlymodmoderate
mmj
parents: 672
diff changeset
907 fromemails.emaillist[0], listdir);
386
7a484c4b7925 Add moderate tag to access rules
mmj
parents: 382
diff changeset
908 if (accret == DENY) {
445
e4494aa175f5 Bugfixes and 1.2.2
mmj
parents: 440
diff changeset
909 if ((strcasecmp(listaddr, fromemails.emaillist[0]) ==
e4494aa175f5 Bugfixes and 1.2.2
mmj
parents: 440
diff changeset
910 0) || noaccessdenymails) {
534
4f099cb2099b Added log messages at points where mail is discarded
mortenp
parents: 533
diff changeset
911 log_error(LOG_ARGS, "Discarding %s because"
4f099cb2099b Added log messages at points where mail is discarded
mortenp
parents: 533
diff changeset
912 " it was denied by an access"
4f099cb2099b Added log messages at points where mail is discarded
mortenp
parents: 533
diff changeset
913 " rule, and From: was the list"
4f099cb2099b Added log messages at points where mail is discarded
mortenp
parents: 533
diff changeset
914 " address or noaccessdenymails"
4f099cb2099b Added log messages at points where mail is discarded
mortenp
parents: 533
diff changeset
915 " was set",
4f099cb2099b Added log messages at points where mail is discarded
mortenp
parents: 533
diff changeset
916 mailfile);
445
e4494aa175f5 Bugfixes and 1.2.2
mmj
parents: 440
diff changeset
917 myfree(listaddr);
e4494aa175f5 Bugfixes and 1.2.2
mmj
parents: 440
diff changeset
918 unlink(donemailname);
e4494aa175f5 Bugfixes and 1.2.2
mmj
parents: 440
diff changeset
919 myfree(donemailname);
e4494aa175f5 Bugfixes and 1.2.2
mmj
parents: 440
diff changeset
920 exit(EXIT_SUCCESS);
e4494aa175f5 Bugfixes and 1.2.2
mmj
parents: 440
diff changeset
921 }
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 487
diff changeset
922 listdelim = getlistdelim(listdir);
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
923 listname = genlistname(listaddr);
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
924 listfqdn = genlistfqdn(listaddr);
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 487
diff changeset
925 fromaddr = concatstr(4, listname, listdelim,
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 487
diff changeset
926 "bounces-help@", listfqdn);
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
927 queuefilename = prepstdreply(listdir, "access",
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 350
diff changeset
928 "$listowner$",
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
929 fromemails.emaillist[0],
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 739
diff changeset
930 NULL, 0, NULL, donemailname);
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
931 MY_ASSERT(queuefilename)
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
932 myfree(listaddr);
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 487
diff changeset
933 myfree(listdelim);
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
934 myfree(listname);
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
935 myfree(listfqdn);
262
846d91ae6ebe Don't litter the queue directory when rejecting posts for one reason or the
mmj
parents: 259
diff changeset
936 unlink(donemailname);
846d91ae6ebe Don't litter the queue directory when rejecting posts for one reason or the
mmj
parents: 259
diff changeset
937 myfree(donemailname);
275
9a847bfdc764 Don't fail in mlmmj-process b/c of EEXIST on the queuefilenames
mmj
parents: 262
diff changeset
938 myfree(randomstr);
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
939 execlp(mlmmjsend, mlmmjsend,
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
940 "-l", "1",
529
d65b467b647d Pass on listdir to mlmmjsend so we can get the smtpport and relayhost also
mmj
parents: 523
diff changeset
941 "-L", listdir,
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
942 "-T", fromemails.emaillist[0],
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
943 "-F", fromaddr,
435
65781b43a7b9 - subswitch, NULL);
mmj
parents: 430
diff changeset
944 "-m", queuefilename, (char *)NULL);
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
945
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
946 log_error(LOG_ARGS, "execlp() of '%s' failed",
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
947 mlmmjsend);
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
948 exit(EXIT_FAILURE);
386
7a484c4b7925 Add moderate tag to access rules
mmj
parents: 382
diff changeset
949 } else if (accret == MODERATE) {
7a484c4b7925 Add moderate tag to access rules
mmj
parents: 382
diff changeset
950 moderated = 1;
640
3770bb64ea17 Added support for 'discard' keyword in access rules (Sascha Sommer)
mortenp
parents: 629
diff changeset
951 } else if (accret == DISCARD) {
3770bb64ea17 Added support for 'discard' keyword in access rules (Sascha Sommer)
mortenp
parents: 629
diff changeset
952 discardname = concatstr(3, listdir,
3770bb64ea17 Added support for 'discard' keyword in access rules (Sascha Sommer)
mortenp
parents: 629
diff changeset
953 "/queue/discarded/", randomstr);
3770bb64ea17 Added support for 'discard' keyword in access rules (Sascha Sommer)
mortenp
parents: 629
diff changeset
954 myfree(randomstr);
3770bb64ea17 Added support for 'discard' keyword in access rules (Sascha Sommer)
mortenp
parents: 629
diff changeset
955 if(rename(donemailname, discardname) < 0) {
3770bb64ea17 Added support for 'discard' keyword in access rules (Sascha Sommer)
mortenp
parents: 629
diff changeset
956 log_error(LOG_ARGS, "could not rename(%s,%s)",
3770bb64ea17 Added support for 'discard' keyword in access rules (Sascha Sommer)
mortenp
parents: 629
diff changeset
957 donemailname, discardname);
3770bb64ea17 Added support for 'discard' keyword in access rules (Sascha Sommer)
mortenp
parents: 629
diff changeset
958 myfree(donemailname);
3770bb64ea17 Added support for 'discard' keyword in access rules (Sascha Sommer)
mortenp
parents: 629
diff changeset
959 myfree(discardname);
3770bb64ea17 Added support for 'discard' keyword in access rules (Sascha Sommer)
mortenp
parents: 629
diff changeset
960 exit(EXIT_FAILURE);
3770bb64ea17 Added support for 'discard' keyword in access rules (Sascha Sommer)
mortenp
parents: 629
diff changeset
961 }
3770bb64ea17 Added support for 'discard' keyword in access rules (Sascha Sommer)
mortenp
parents: 629
diff changeset
962 myfree(donemailname);
3770bb64ea17 Added support for 'discard' keyword in access rules (Sascha Sommer)
mortenp
parents: 629
diff changeset
963 myfree(discardname);
3770bb64ea17 Added support for 'discard' keyword in access rules (Sascha Sommer)
mortenp
parents: 629
diff changeset
964 exit(EXIT_SUCCESS);
719
30e6e309891d Added "send" keyword to control/access handling (Ben Schmidt)
mortenp
parents: 705
diff changeset
965 } else if (accret == SEND) {
30e6e309891d Added "send" keyword to control/access handling (Ben Schmidt)
mortenp
parents: 705
diff changeset
966 moderated = 0;
30e6e309891d Added "send" keyword to control/access handling (Ben Schmidt)
mortenp
parents: 705
diff changeset
967 } else if (accret == ALLOW) {
30e6e309891d Added "send" keyword to control/access handling (Ben Schmidt)
mortenp
parents: 705
diff changeset
968 /* continue processing as normal */
254
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
969 }
31a34f710c27 added access control
mortenp
parents: 245
diff changeset
970 }
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
971
727
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
972 notmetoo = statctrl(listdir, "notmetoo");
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
973
69
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
974 if(moderated) {
127
b525c4f78ef7 Use listdir/moderation for the mails up for moderation and use
mmj
parents: 117
diff changeset
975 mqueuename = concatstr(3, listdir, "/moderation/",
b525c4f78ef7 Use listdir/moderation for the mails up for moderation and use
mmj
parents: 117
diff changeset
976 randomstr);
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
977 myfree(randomstr);
69
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
978 if(rename(donemailname, mqueuename) < 0) {
163
39c46b88720d Lets get rid of stdio shall we :-)
mmj
parents: 135
diff changeset
979 log_error(LOG_ARGS, "could not rename(%s,%s)",
69
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
980 donemailname, mqueuename);
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
981 myfree(donemailname);
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
982 myfree(mqueuename);
69
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
983 exit(EXIT_FAILURE);
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
984 }
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
985 myfree(donemailname);
727
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
986 if (notmetoo) {
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
987 omitfilename = concatstr(2, mqueuename, ".omit");
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
988 omitfd = open(omitfilename, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
989 if (omitfd < 0) {
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
990 log_error(LOG_ARGS, "could not open %s",
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
991 omitfilename);
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
992 myfree(mqueuename);
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
993 myfree(omitfilename);
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
994 exit(EXIT_FAILURE);
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
995 }
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
996 myfree(omitfilename);
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
997 if(writen(omitfd, fromemails.emaillist[0],
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
998 strlen(fromemails.emaillist[0])) < 0) {
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
999 log_error(LOG_ARGS,
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
1000 "could not write omit file");
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
1001 myfree(mqueuename);
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
1002 exit(EXIT_FAILURE);
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
1003 }
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
1004 fsync(omitfd);
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
1005 close(omitfd);
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
1006 }
705
79dd917e0150 ifmodsendonlymodmoderate
mmj
parents: 672
diff changeset
1007 newmoderated(listdir, mqueuename, mlmmjsend, efrom);
69
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
1008 return EXIT_SUCCESS;
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
1009 }
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
1010
275
9a847bfdc764 Don't fail in mlmmj-process b/c of EEXIST on the queuefilenames
mmj
parents: 262
diff changeset
1011 myfree(randomstr);
69
4e9e7f2d2e09 Bouncehandling, and massive cleanups around.
mmj
parents: 58
diff changeset
1012
11
8e1ebc68ee62 do_all_the_voodo_here introducton plus a massive cleanup
mmj
parents: 1
diff changeset
1013 if(noprocess) {
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
1014 myfree(donemailname);
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 233
diff changeset
1015 /* XXX: toemails and ccemails etc. have to be myfree() */
11
8e1ebc68ee62 do_all_the_voodo_here introducton plus a massive cleanup
mmj
parents: 1
diff changeset
1016 exit(EXIT_SUCCESS);
8e1ebc68ee62 do_all_the_voodo_here introducton plus a massive cleanup
mmj
parents: 1
diff changeset
1017 }
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
1018
727
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
1019 if (notmetoo)
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
1020 execlp(mlmmjsend, mlmmjsend,
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
1021 "-L", listdir,
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
1022 "-o", fromemails.emaillist[0],
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
1023 "-m", donemailname, (char *)NULL);
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
1024 else
4575d3181ca1 Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents: 719
diff changeset
1025 execlp(mlmmjsend, mlmmjsend,
0
21ce01de8109 Initial revision
mmj
parents:
diff changeset
1026 "-L", listdir,
435
65781b43a7b9 - subswitch, NULL);
mmj
parents: 430
diff changeset
1027 "-m", donemailname, (char *)NULL);
39
3509e8837988 changed log_error() to be a function (no C99 here)
mortenp
parents: 38
diff changeset
1028 log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend);
18
f54f95a4c53e changed to use log_error() all over
mortenp
parents: 17
diff changeset
1029
0
21ce01de8109 Initial revision
mmj
parents:
diff changeset
1030 return EXIT_FAILURE;
21ce01de8109 Initial revision
mmj
parents:
diff changeset
1031 }