annotate src/mlmmj-process.c @ 756:f8f3f4525a2b

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