Mercurial > hg > mlmmj
annotate src/mlmmj-send.c @ 748:dfc9ab125fd4
Fix spelling of 'receive' and 'voodoo'; make mlmmj-recieve a symlink
author | Chris Webb |
---|---|
date | Sun, 03 Oct 2010 21:40:42 +1100 |
parents | 4575d3181ca1 |
children | f8f3f4525a2b |
rev | line source |
---|---|
486 | 1 /* Copyright (C) 2004, 2003, 2004 Mads Martin Joergensen <mmj at mmj.dk> |
0 | 2 * |
3 * $Id$ | |
4 * | |
225 | 5 * Permission is hereby granted, free of charge, to any person obtaining a copy |
6 * of this software and associated documentation files (the "Software"), to | |
7 * deal in the Software without restriction, including without limitation the | |
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |
9 * sell copies of the Software, and to permit persons to whom the Software is | |
10 * furnished to do so, subject to the following conditions: | |
11 * | |
12 * The above copyright notice and this permission notice shall be included in | |
13 * all copies or substantial portions of the Software. | |
14 * | |
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
21 * IN THE SOFTWARE. | |
0 | 22 */ |
23 | |
24 #include <stdio.h> | |
25 #include <stdlib.h> | |
26 #include <unistd.h> | |
27 #include <errno.h> | |
28 #include <string.h> | |
29 #include <sys/stat.h> | |
30 #include <fcntl.h> | |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
31 #include <sys/types.h> |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
32 #include <dirent.h> |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
33 #include <sys/wait.h> |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
34 #include <signal.h> |
95 | 35 #include <libgen.h> |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
36 #include <syslog.h> |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
37 #include <stdarg.h> |
174
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
38 #include <sys/mman.h> |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
39 #include <limits.h> |
291 | 40 #include <netdb.h> |
41 #include <sys/socket.h> | |
42 #include <netinet/in.h> | |
43 #include <arpa/inet.h> | |
489 | 44 #include <signal.h> |
0 | 45 |
426 | 46 #include "mlmmj.h" |
0 | 47 #include "mlmmj-send.h" |
48 #include "mail-functions.h" | |
49 #include "itoa.h" | |
50 #include "incindexfile.h" | |
51 #include "chomp.h" | |
52 #include "checkwait_smtpreply.h" | |
53 #include "getlistaddr.h" | |
520 | 54 #include "getlistdelim.h" |
0 | 55 #include "init_sockfd.h" |
56 #include "strgen.h" | |
25 | 57 #include "log_error.h" |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
58 #include "mygetline.h" |
171 | 59 #include "wrappers.h" |
245 | 60 #include "memory.h" |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
61 #include "statctrl.h" |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
62 #include "ctrlvalue.h" |
411
79355dd5ecc2
Make the envelope from match the new order (VERP prep) and also remove
mmj
parents:
401
diff
changeset
|
63 #include "mylocking.h" |
426 | 64 #include "getaddrsfromfd.h" |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
65 |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
66 static int addtohdr = 0; |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
67 static int prepmailinmem = 0; |
426 | 68 static int maxverprecips = MAXVERPRECIPS; |
489 | 69 static int gotsigterm = 0; |
70 | |
71 void catch_sig_term(int sig) | |
72 { | |
490 | 73 gotsigterm = 1; |
489 | 74 } |
0 | 75 |
601 | 76 char *get_index_from_filename(const char *filename) |
77 { | |
78 char *myfilename, *indexstr, *ret; | |
79 size_t len; | |
80 | |
81 myfilename = mystrdup(filename); | |
82 if (!myfilename) { | |
83 return NULL; | |
84 } | |
85 | |
86 len = strlen(myfilename); | |
87 if (len > 9 && (strcmp(myfilename + len - 9, "/mailfile") == 0)) { | |
88 myfilename[len - 9] = '\0'; | |
89 } | |
90 | |
91 indexstr = strrchr(myfilename, '/'); | |
92 if (indexstr) { | |
93 indexstr++; /* skip the slash */ | |
94 } else { | |
95 indexstr = myfilename; | |
96 } | |
97 | |
98 ret = mystrdup(indexstr); | |
99 myfree(myfilename); | |
100 | |
101 return ret; | |
102 } | |
103 | |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
104 char *bounce_from_adr(const char *recipient, const char *listadr, |
677
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
105 const char *listdelim, const char *mailfilename, |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
106 const char *listdir) |
0 | 107 { |
677
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
108 char *bounceaddr, *myrecipient, *mylistadr; |
465 | 109 char *indexstr, *listdomain, *a = NULL, *mymailfilename; |
677
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
110 char *staticbounceaddr, *staticbounceaddr_localpart; |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
111 char *staticbounceaddr_domain; |
7 | 112 size_t len; |
113 | |
245 | 114 mymailfilename = mystrdup(mailfilename); |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
115 if (!mymailfilename) { |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
116 return NULL; |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
117 } |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
118 |
601 | 119 indexstr = get_index_from_filename(mymailfilename); |
677
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
120 if (!indexstr) { |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
121 myfree(mymailfilename); |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
122 return NULL; |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
123 } |
0 | 124 |
245 | 125 myrecipient = mystrdup(recipient); |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
126 if (!myrecipient) { |
245 | 127 myfree(mymailfilename); |
7 | 128 return NULL; |
129 } | |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
130 a = strchr(myrecipient, '@'); |
465 | 131 if (a) |
132 *a = '='; | |
0 | 133 |
245 | 134 mylistadr = mystrdup(listadr); |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
135 if (!mylistadr) { |
245 | 136 myfree(mymailfilename); |
137 myfree(myrecipient); | |
7 | 138 return NULL; |
139 } | |
140 | |
520 | 141 listdomain = strchr(mylistadr, '@'); |
142 if (!listdomain) { | |
143 myfree(mymailfilename); | |
144 myfree(myrecipient); | |
145 myfree(mylistadr); | |
146 return NULL; | |
147 } | |
7 | 148 *listdomain++ = '\0'; |
0 | 149 |
520 | 150 /* 11 = "bounces-" + "-" + "@" + NUL */ |
677
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
151 len = strlen(mylistadr) + strlen(listdelim) + strlen(myrecipient) |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
152 + strlen(indexstr) + strlen(listdomain) + 11; |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
153 |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
154 staticbounceaddr = ctrlvalue(listdir, "staticbounceaddr"); |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
155 if (staticbounceaddr) { |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
156 staticbounceaddr_localpart = genlistname(staticbounceaddr); |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
157 staticbounceaddr_domain = genlistfqdn(staticbounceaddr); |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
158 |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
159 /* localpart + "-" + domain */ |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
160 len += strlen(staticbounceaddr_localpart) + 1 |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
161 + strlen(staticbounceaddr_domain); |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
162 } else { |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
163 staticbounceaddr_localpart = NULL; |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
164 staticbounceaddr_domain = NULL; |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
165 } |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
166 |
245 | 167 bounceaddr = mymalloc(len); |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
168 if (!bounceaddr) { |
677
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
169 myfree(staticbounceaddr); |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
170 myfree(staticbounceaddr_localpart); |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
171 myfree(staticbounceaddr_domain); |
245 | 172 myfree(myrecipient); |
173 myfree(mylistadr); | |
7 | 174 return NULL; |
175 } | |
677
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
176 |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
177 if (staticbounceaddr) { |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
178 snprintf(bounceaddr, len, "%s%s%s-bounces-%s-%s@%s", |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
179 staticbounceaddr_localpart, listdelim, mylistadr, |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
180 indexstr, myrecipient, staticbounceaddr_domain); |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
181 |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
182 myfree(staticbounceaddr); |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
183 myfree(staticbounceaddr_localpart); |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
184 myfree(staticbounceaddr_domain); |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
185 } else { |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
186 snprintf(bounceaddr, len, "%s%sbounces-%s-%s@%s", mylistadr, listdelim, |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
187 indexstr, myrecipient, listdomain); |
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
188 } |
0 | 189 |
245 | 190 myfree(myrecipient); |
191 myfree(mylistadr); | |
601 | 192 myfree(indexstr); |
245 | 193 myfree(mymailfilename); |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
194 |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
195 return bounceaddr; |
0 | 196 } |
197 | |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
198 int bouncemail(const char *listdir, const char *mlmmjbounce, const char *from) |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
199 { |
245 | 200 char *myfrom = mystrdup(from); |
520 | 201 char *listdelim = getlistdelim(listdir); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
202 char *addr, *num, *c; |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
203 size_t len; |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
204 pid_t pid = 0; |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
205 |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
206 if((c = strchr(myfrom, '@')) == NULL) { |
245 | 207 myfree(myfrom); |
520 | 208 myfree(listdelim); |
147
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
209 return 0; /* Success when malformed 'from' */ |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
210 } |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
211 *c = '\0'; |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
212 num = strrchr(myfrom, '-'); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
213 num++; |
520 | 214 c = strstr(myfrom, listdelim); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
215 myfrom = strchr(c, '-'); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
216 myfrom++; |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
217 len = num - myfrom - 1; |
245 | 218 addr = mymalloc(len + 1); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
219 addr[len] = '\0'; |
115 | 220 strncpy(addr, myfrom, len); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
221 |
520 | 222 myfree(listdelim); |
223 | |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
224 pid = fork(); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
225 |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
226 if(pid < 0) { |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
227 log_error(LOG_ARGS, "fork() failed!"); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
228 return 1; |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
229 } |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
230 |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
231 if(pid > 0) |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
232 return 0; |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
233 |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
234 execlp(mlmmjbounce, mlmmjbounce, |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
235 "-L", listdir, |
426 | 236 "-a", num, |
435 | 237 "-n", addr, (char *)NULL); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
238 |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
239 log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjbounce); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
240 |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
241 return 1; |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
242 } |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
243 |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
244 int send_mail(int sockfd, const char *from, const char *to, |
174
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
245 const char *replyto, char *mailmap, size_t mailsize, |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
246 const char *listdir, const char *mlmmjbounce, |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
247 const char *hdrs, size_t hdrslen, const char *body, |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
248 size_t bodylen) |
0 | 249 { |
95 | 250 int retval = 0; |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
251 char *reply, *tohdr; |
472 | 252 |
253 if(strchr(to, '@') == NULL) { | |
254 errno = 0; | |
255 log_error(LOG_ARGS, "No @ in address, ignoring %s", | |
256 to); | |
257 return 0; | |
258 } | |
174
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
259 |
426 | 260 retval = write_mail_from(sockfd, from, ""); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
261 if(retval) { |
39 | 262 log_error(LOG_ARGS, "Could not write MAIL FROM\n"); |
0 | 263 return retval; |
264 } | |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
265 reply = checkwait_smtpreply(sockfd, MLMMJ_FROM); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
266 if(reply) { |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
267 log_error(LOG_ARGS, "Error in MAIL FROM. Reply = [%s]", |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
268 reply); |
245 | 269 myfree(reply); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
270 write_rset(sockfd); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
271 checkwait_smtpreply(sockfd, MLMMJ_RSET); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
272 return MLMMJ_FROM; |
0 | 273 } |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
274 retval = write_rcpt_to(sockfd, to); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
275 if(retval) { |
39 | 276 log_error(LOG_ARGS, "Could not write RCPT TO:\n"); |
0 | 277 return retval; |
278 } | |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
279 |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
280 reply = checkwait_smtpreply(sockfd, MLMMJ_RCPTTO); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
281 if(reply) { |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
282 write_rset(sockfd); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
283 checkwait_smtpreply(sockfd, MLMMJ_RSET); |
225 | 284 if(mlmmjbounce && ((reply[0] == '4') || (reply[0] == '5')) |
285 && (reply[1] == '5')) { | |
245 | 286 myfree(reply); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
287 return bouncemail(listdir, mlmmjbounce, from); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
288 } else { |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
289 log_error(LOG_ARGS, "Error in RCPT TO. Reply = [%s]", |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
290 reply); |
245 | 291 myfree(reply); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
292 return MLMMJ_RCPTTO; |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
293 } |
0 | 294 } |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
295 |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
296 retval = write_data(sockfd); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
297 if(retval) { |
39 | 298 log_error(LOG_ARGS, "Could not write DATA\b"); |
0 | 299 return retval; |
300 } | |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
301 |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
302 reply = checkwait_smtpreply(sockfd, MLMMJ_DATA); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
303 if(reply) { |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
304 log_error(LOG_ARGS, "Error with DATA. Reply = [%s]", reply); |
245 | 305 myfree(reply); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
306 write_rset(sockfd); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
307 checkwait_smtpreply(sockfd, MLMMJ_RSET); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
308 return MLMMJ_DATA; |
0 | 309 } |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
310 |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
311 if(replyto) { |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
312 retval = write_replyto(sockfd, replyto); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
313 if(retval) { |
39 | 314 log_error(LOG_ARGS, "Could not write reply-to addr.\n"); |
0 | 315 return retval; |
316 } | |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
317 } |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
318 |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
319 if(addtohdr) |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
320 tohdr = concatstr(3, "To: ", to, "\r\n"); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
321 else |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
322 tohdr = NULL; |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
323 |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
324 if(prepmailinmem) { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
325 retval = writen(sockfd, hdrs, hdrslen); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
326 if(retval < 0) { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
327 log_error(LOG_ARGS, "Could not write mailheaders.\n"); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
328 return retval; |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
329 } |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
330 if(tohdr) { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
331 retval = writen(sockfd, tohdr, strlen(tohdr)); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
332 if(retval < 0) { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
333 log_error(LOG_ARGS, "Could not write To:.\n"); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
334 return retval; |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
335 } |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
336 myfree(tohdr); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
337 } |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
338 retval = writen(sockfd, body, bodylen); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
339 if(retval < 0) { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
340 log_error(LOG_ARGS, "Could not write mailbody.\n"); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
341 return retval; |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
342 } |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
343 } else { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
344 retval = write_mailbody_from_map(sockfd, mailmap, mailsize, |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
345 tohdr); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
346 if(retval) { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
347 log_error(LOG_ARGS, "Could not write mail\n"); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
348 return retval; |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
349 } |
0 | 350 } |
351 | |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
352 retval = write_dot(sockfd); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
353 if(retval) { |
39 | 354 log_error(LOG_ARGS, "Could not write <CR><LF>.<CR><LF>\n"); |
0 | 355 return retval; |
356 } | |
357 | |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
358 reply = checkwait_smtpreply(sockfd, MLMMJ_DOT); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
359 if(reply) { |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
360 log_error(LOG_ARGS, "Mailserver did not ack end of mail.\n" |
0 | 361 "<CR><LF>.<CR><LF> was written, to no" |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
362 "avail. Reply = [%s]", reply); |
245 | 363 myfree(reply); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
364 write_rset(sockfd); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
365 checkwait_smtpreply(sockfd, MLMMJ_RSET); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
366 return MLMMJ_DOT; |
0 | 367 } |
368 | |
369 return 0; | |
370 } | |
371 | |
458 | 372 int initsmtp(int *sockfd, const char *relayhost, unsigned short port) |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
373 { |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
374 int retval = 0; |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
375 char *reply = NULL; |
99
6089f38bb228
Send our hostname in HELO and change the mlmmj-send output from
mmj
parents:
95
diff
changeset
|
376 char *myhostname = hostnamestr(); |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
377 |
458 | 378 init_sockfd(sockfd, relayhost, port); |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
379 |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
380 if((reply = checkwait_smtpreply(*sockfd, MLMMJ_CONNECT)) != NULL) { |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
381 log_error(LOG_ARGS, "No proper greeting to our connect" |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
382 "Reply: [%s]", reply); |
245 | 383 myfree(reply); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
384 retval = MLMMJ_CONNECT; |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
385 /* FIXME: Queue etc. */ |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
386 } |
99
6089f38bb228
Send our hostname in HELO and change the mlmmj-send output from
mmj
parents:
95
diff
changeset
|
387 write_helo(*sockfd, myhostname); |
245 | 388 myfree(myhostname); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
389 if((reply = checkwait_smtpreply(*sockfd, MLMMJ_HELO)) != NULL) { |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
390 log_error(LOG_ARGS, "Error with HELO. Reply: [%s]", reply); |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
391 /* FIXME: quit and tell admin to configure correctly */ |
245 | 392 myfree(reply); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
393 retval = MLMMJ_HELO; |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
394 } |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
395 |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
396 return retval; |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
397 } |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
398 |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
399 int endsmtp(int *sockfd) |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
400 { |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
401 int retval = 0; |
426 | 402 char *reply = NULL; |
445 | 403 |
404 if(*sockfd == -1) | |
405 return retval; | |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
406 |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
407 write_quit(*sockfd); |
426 | 408 reply = checkwait_smtpreply(*sockfd, MLMMJ_QUIT); |
409 if(reply) { | |
410 printf("reply from quit: %s\n", reply); | |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
411 log_error(LOG_ARGS, "Mailserver would not let us QUIT. " |
426 | 412 "We close the socket anyway though. " |
413 "Mailserver reply = [%s]", reply); | |
245 | 414 myfree(reply); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
415 retval = MLMMJ_QUIT; |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
416 } |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
417 |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
418 close(*sockfd); |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
419 |
465 | 420 *sockfd = -1; |
421 | |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
422 return retval; |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
423 } |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
424 |
426 | 425 int send_mail_verp(int sockfd, struct strlist *addrs, char *mailmap, |
426 size_t mailsize, const char *from, const char *listdir, | |
427 const char *hdrs, size_t hdrslen, const char *body, | |
428 size_t bodylen, const char *verpextra) | |
429 { | |
430 int retval, i; | |
431 char *reply; | |
432 | |
433 retval = write_mail_from(sockfd, from, verpextra); | |
434 if(retval) { | |
435 log_error(LOG_ARGS, "Could not write MAIL FROM\n"); | |
436 return retval; | |
437 } | |
438 reply = checkwait_smtpreply(sockfd, MLMMJ_FROM); | |
439 if(reply) { | |
440 log_error(LOG_ARGS, "Error in MAIL FROM. Reply = [%s]", | |
441 reply); | |
442 myfree(reply); | |
443 write_rset(sockfd); | |
444 checkwait_smtpreply(sockfd, MLMMJ_RSET); | |
445 return MLMMJ_FROM; | |
446 } | |
447 for(i = 0; i < addrs->count; i++) { | |
489 | 448 if(gotsigterm) { |
748
dfc9ab125fd4
Fix spelling of 'receive' and 'voodoo'; make mlmmj-recieve a symlink
Chris Webb
parents:
727
diff
changeset
|
449 log_error(LOG_ARGS, "TERM signal received, " |
489 | 450 "shutting down."); |
451 return -1; | |
452 } | |
472 | 453 if(strchr(addrs->strs[i], '@') == NULL) { |
454 errno = 0; | |
455 log_error(LOG_ARGS, "No @ in address, ignoring %s", | |
456 addrs->strs[i]); | |
457 continue; | |
458 } | |
426 | 459 retval = write_rcpt_to(sockfd, addrs->strs[i]); |
460 if(retval) { | |
461 log_error(LOG_ARGS, "Could not write RCPT TO:\n"); | |
462 return retval; | |
463 } | |
464 | |
465 reply = checkwait_smtpreply(sockfd, MLMMJ_RCPTTO); | |
466 if(reply) { | |
467 log_error(LOG_ARGS, "Error in RCPT TO. Reply = [%s]", | |
468 reply); | |
469 myfree(reply); | |
470 return MLMMJ_RCPTTO; | |
471 } | |
472 } | |
473 | |
474 retval = write_data(sockfd); | |
475 if(retval) { | |
476 log_error(LOG_ARGS, "Could not write DATA\b"); | |
477 return retval; | |
478 } | |
479 | |
480 reply = checkwait_smtpreply(sockfd, MLMMJ_DATA); | |
481 if(reply) { | |
482 log_error(LOG_ARGS, "Error with DATA. Reply = [%s]", reply); | |
483 myfree(reply); | |
484 write_rset(sockfd); | |
485 checkwait_smtpreply(sockfd, MLMMJ_RSET); | |
486 return MLMMJ_DATA; | |
487 } | |
488 | |
489 if(prepmailinmem) { | |
490 retval = writen(sockfd, hdrs, hdrslen); | |
491 if(retval < 0) { | |
492 log_error(LOG_ARGS, "Could not write mailheaders.\n"); | |
493 return retval; | |
494 } | |
495 retval = writen(sockfd, body, bodylen); | |
496 if(retval < 0) { | |
497 log_error(LOG_ARGS, "Could not write mailbody.\n"); | |
498 return retval; | |
499 } | |
500 } else { | |
501 retval = write_mailbody_from_map(sockfd, mailmap, mailsize, | |
502 NULL); | |
503 if(retval) { | |
504 log_error(LOG_ARGS, "Could not write mail\n"); | |
505 return retval; | |
506 } | |
507 } | |
508 | |
509 retval = write_dot(sockfd); | |
510 if(retval) { | |
511 log_error(LOG_ARGS, "Could not write <CR><LF>.<CR><LF>\n"); | |
512 return retval; | |
513 } | |
514 | |
515 reply = checkwait_smtpreply(sockfd, MLMMJ_DOT); | |
516 if(reply) { | |
517 log_error(LOG_ARGS, "Mailserver did not ack end of mail.\n" | |
518 "<CR><LF>.<CR><LF> was written, to no" | |
519 "avail. Reply = [%s]", reply); | |
520 myfree(reply); | |
521 write_rset(sockfd); | |
522 checkwait_smtpreply(sockfd, MLMMJ_RSET); | |
523 return MLMMJ_DOT; | |
524 } | |
525 | |
526 return 0; | |
527 } | |
528 | |
529 int send_mail_many_fd(int sockfd, const char *from, const char *replyto, | |
530 char *mailmap, size_t mailsize, int subfd, | |
520 | 531 const char *listaddr, const char *listdelim, |
532 const char *archivefilename, const char *listdir, | |
533 const char *mlmmjbounce, const char *hdrs, size_t hdrslen, | |
534 const char *body, size_t bodylen) | |
426 | 535 { |
536 int res, ret, i; | |
537 struct strlist stl; | |
538 | |
465 | 539 stl.strs = NULL; |
432 | 540 stl.count = 0; |
541 | |
426 | 542 do { |
543 res = getaddrsfromfd(&stl, subfd, maxverprecips); | |
544 if(stl.count == maxverprecips) { | |
545 ret = send_mail_many_list(sockfd, from, replyto, | |
546 mailmap, mailsize, &stl, listaddr, | |
520 | 547 listdelim, archivefilename, listdir, |
548 mlmmjbounce, hdrs, hdrslen, | |
549 body, bodylen); | |
426 | 550 for(i = 0; i < stl.count; i++) |
551 myfree(stl.strs[i]); | |
552 if(ret < 0) | |
553 return ret; | |
554 stl.count = 0; | |
555 } | |
556 } while(res > 0); | |
557 | |
558 if(stl.count) { | |
559 ret = send_mail_many_list(sockfd, from, replyto, mailmap, | |
520 | 560 mailsize, &stl, listaddr, listdelim, |
561 archivefilename, listdir, mlmmjbounce, | |
562 hdrs, hdrslen, body, bodylen); | |
426 | 563 for(i = 0; i < stl.count; i++) |
564 myfree(stl.strs[i]); | |
565 stl.count = 0; | |
566 return ret; | |
567 } | |
568 | |
569 return 0; | |
570 } | |
571 | |
572 int requeuemail(const char *listdir, const char *index, struct strlist *addrs, | |
573 int addrcount) | |
574 { | |
575 int addrfd, i; | |
576 char *dirname, *addrfilename, *addr; | |
577 | |
578 dirname = concatstr(3, listdir, "/requeue/", index); | |
579 if(mkdir(dirname, 0750) < 0 && errno != EEXIST) { | |
580 log_error(LOG_ARGS, "Could not mkdir(%s) for " | |
581 "requeueing. Mail cannot " | |
582 "be requeued.", dirname); | |
583 myfree(dirname); | |
584 return -1; | |
585 } | |
586 addrfilename = concatstr(2, dirname, "/subscribers"); | |
587 myfree(dirname); | |
588 addrfd = open(addrfilename, O_WRONLY|O_CREAT|O_APPEND, | |
589 S_IRUSR|S_IWUSR); | |
590 if(addrfd < 0) { | |
591 log_error(LOG_ARGS, "Could not open %s", | |
592 addrfilename); | |
593 myfree(addrfilename); | |
594 return -1; | |
595 } else { | |
596 /* Dump the remaining addresses. We dump the remaining before | |
597 * we write the failing address to ensure the potential good | |
598 * ones will be tried first when mlmmj-maintd sends out mails | |
599 * that have been requeued. addrcount was so far we were */ | |
600 for(i = addrcount + 1; i < addrs->count; i++) { | |
601 addr = concatstr(2, addrs->strs[i], "\n"); | |
602 if(writen(addrfd, addr, strlen(addr)) < 0) { | |
603 log_error(LOG_ARGS, "Could not add [%s] " | |
604 "to requeue file", addr); | |
605 return -1; | |
606 } | |
607 myfree(addr); | |
608 } | |
609 addr = concatstr(2, addrs->strs[addrcount], "\n"); | |
610 if(writen(addrfd, addr, strlen(addr)) < 0) { | |
611 log_error(LOG_ARGS, "Could not add [%s] to requeue " | |
612 "file", addr); | |
613 return -1; | |
614 } | |
615 myfree(addr); | |
616 } | |
617 myfree(addrfilename); | |
618 close(addrfd); | |
619 | |
620 return 0; | |
621 } | |
622 | |
623 int send_mail_many_list(int sockfd, const char *from, const char *replyto, | |
624 char *mailmap, size_t mailsize, struct strlist *addrs, | |
520 | 625 const char *listaddr, const char *listdelim, |
626 const char *archivefilename, const char *listdir, | |
627 const char *mlmmjbounce, const char *hdrs, size_t hdrslen, | |
628 const char *body, size_t bodylen) | |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
629 { |
601 | 630 int res = 0, i, status; |
426 | 631 char *bounceaddr, *addr, *index; |
177
503250510778
Use mmap to find the subscribers in the subscribers files
mmj
parents:
176
diff
changeset
|
632 |
426 | 633 for(i = 0; i < addrs->count; i++) { |
634 addr = addrs->strs[i]; | |
472 | 635 if(strchr(addr, '@') == NULL) { |
636 errno = 0; | |
637 log_error(LOG_ARGS, "No @ in address, ignoring %s", | |
638 addr); | |
639 continue; | |
640 } | |
493 | 641 if(gotsigterm && listaddr && archivefilename) { |
642 /* we got SIGTERM, so save the addresses and bail */ | |
748
dfc9ab125fd4
Fix spelling of 'receive' and 'voodoo'; make mlmmj-recieve a symlink
Chris Webb
parents:
727
diff
changeset
|
643 log_error(LOG_ARGS, "TERM signal received, " |
493 | 644 "shutting down."); |
601 | 645 index = get_index_from_filename(archivefilename); |
646 status = requeuemail(listdir, index, addrs, i); | |
647 myfree(index); | |
648 return status; | |
493 | 649 } |
338 | 650 if(from) { |
426 | 651 res = send_mail(sockfd, from, addr, replyto, |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
652 mailmap, mailsize, listdir, NULL, |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
653 hdrs, hdrslen, body, bodylen); |
338 | 654 } else { |
520 | 655 bounceaddr = bounce_from_adr(addr, listaddr, listdelim, |
677
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
656 archivefilename, listdir); |
426 | 657 res = send_mail(sockfd, bounceaddr, addr, replyto, |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
658 mailmap, mailsize, listdir, mlmmjbounce, |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
659 hdrs, hdrslen, body, bodylen); |
245 | 660 myfree(bounceaddr); |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
661 } |
493 | 662 if(res && listaddr && archivefilename) { |
663 /* we failed, so save the addresses and bail */ | |
601 | 664 index = get_index_from_filename(archivefilename); |
665 status = requeuemail(listdir, index, addrs, i); | |
666 myfree(index); | |
667 return status; | |
95 | 668 } |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
669 } |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
670 return 0; |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
671 } |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
672 |
102 | 673 static void print_help(const char *prg) |
674 { | |
727
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
675 printf("Usage: %s [-L /path/to/list || -l listctrl] \n" |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
676 " -m /path/to/mail [-a] [-D] [-F] [-h] [-o] [-r] [-R] " |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
677 "[-R] [-s] [-T] [-V]\n" |
116 | 678 " -a: Don't archive the mail\n" |
102 | 679 " -D: Don't delete the mail after it's sent\n" |
680 " -F: What to use as MAIL FROM:\n" | |
681 " -h: This help\n" | |
147
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
682 " -l: List control variable:\n", prg); |
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
683 printf(" '1' means 'send a single mail'\n" |
102 | 684 " '2' means 'mail to moderators'\n" |
184 | 685 " '3' means 'resend failed list mail'\n" |
272 | 686 " '4' means 'send to file with recipients'\n" |
687 " '5' means 'bounceprobe'\n" | |
298 | 688 " '6' means 'single listmail to single recipient'\n" |
338 | 689 " '7' means 'digest'\n" |
102 | 690 " -L: Full path to list directory\n" |
691 " -m: Full path to mail file\n" | |
727
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
692 " -o: Address to omit from distribution (normal mail only)\n" |
272 | 693 " -r: Relayhost IP address (defaults to 127.0.0.1)\n" |
102 | 694 " -R: What to use as Reply-To: header\n" |
147
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
695 " -s: Subscribers file name\n" |
102 | 696 " -T: What to use as RCPT TO:\n" |
147
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
697 " -V: Print version\n"); |
102 | 698 exit(EXIT_SUCCESS); |
699 } | |
700 | |
0 | 701 int main(int argc, char **argv) |
702 { | |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
703 size_t len = 0, hdrslen, bodylen; |
445 | 704 int sockfd = -1, mailfd = 0, opt, mindex = 0, subfd = 0, tmpfd, i; |
426 | 705 int deletewhensent = 1, sendres = 0, archive = 1, digest = 0; |
706 int ctrlarchive, res; | |
520 | 707 char *listaddr = NULL, *listdelim = NULL; |
727
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
708 char *mailfilename = NULL, *subfilename = NULL, *omit = NULL; |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
709 char *replyto = NULL, *bounceaddr = NULL, *to_addr = NULL; |
103
bf4390ecc30b
Also dump MAIL FROM:, RCPT TO: and Reply To: variables in the case of an
mmj
parents:
102
diff
changeset
|
710 char *relayhost = NULL, *archivefilename = NULL, *tmpstr; |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
711 char *listctrl = NULL, *subddirname = NULL, *listdir = NULL; |
264
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
712 char *mlmmjbounce = NULL, *bindir, *mailmap, *probefile, *a; |
426 | 713 char *body = NULL, *hdrs = NULL, *memmailsizestr = NULL, *verp = NULL; |
714 char relay[16], *listname, *listfqdn, *verpfrom, *maxverprecipsstr; | |
601 | 715 char strindex[32], *reply, *strport, *requeuefilename; |
272 | 716 ssize_t memmailsize = 0; |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
717 DIR *subddir; |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
718 struct dirent *dp; |
174
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
719 struct stat st; |
291 | 720 struct hostent *relayent; |
295 | 721 uid_t uid; |
426 | 722 struct strlist stl; |
458 | 723 unsigned short smtpport = 25; |
491 | 724 struct sigaction sigact; |
208
688011dbc4b7
Add a macro to make sure mlmmj binaries are invoked with full path
mmj
parents:
191
diff
changeset
|
725 |
688011dbc4b7
Add a macro to make sure mlmmj binaries are invoked with full path
mmj
parents:
191
diff
changeset
|
726 CHECKFULLPATH(argv[0]); |
0 | 727 |
728 log_set_name(argv[0]); | |
729 | |
124
4c8cc076c784
Use the nice new mydirname and fix a bug with the archive variable.
mmj
parents:
117
diff
changeset
|
730 bindir = mydirname(argv[0]); |
4c8cc076c784
Use the nice new mydirname and fix a bug with the archive variable.
mmj
parents:
117
diff
changeset
|
731 mlmmjbounce = concatstr(2, bindir, "/mlmmj-bounce"); |
245 | 732 myfree(bindir); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
733 |
489 | 734 /* install signal handler for SIGTERM */ |
491 | 735 sigact.sa_handler = catch_sig_term; |
493 | 736 sigemptyset(&sigact.sa_mask); |
491 | 737 sigact.sa_flags = 0; |
738 if(sigaction(SIGTERM, &sigact, NULL) < 0) | |
489 | 739 log_error(LOG_ARGS, "Could not install SIGTERM handler!"); |
740 | |
727
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
741 while ((opt = getopt(argc, argv, "aVDhm:l:L:R:F:T:r:s:o:")) != -1){ |
0 | 742 switch(opt) { |
116 | 743 case 'a': |
744 archive = 0; | |
117
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
116
diff
changeset
|
745 break; |
0 | 746 case 'D': |
747 deletewhensent = 0; | |
748 break; | |
749 case 'F': | |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
750 bounceaddr = optarg; |
0 | 751 break; |
752 case 'h': | |
753 print_help(argv[0]); | |
754 break; | |
69 | 755 case 'l': |
756 listctrl = optarg; | |
757 break; | |
0 | 758 case 'L': |
759 listdir = optarg; | |
760 break; | |
761 case 'm': | |
762 mailfilename = optarg; | |
763 break; | |
727
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
764 case 'o': |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
765 omit = optarg; |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
766 break; |
0 | 767 case 'r': |
768 relayhost = optarg; | |
769 break; | |
770 case 'R': | |
771 replyto = optarg; | |
772 break; | |
147
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
773 case 's': |
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
774 subfilename = optarg; |
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
775 break; |
0 | 776 case 'T': |
777 to_addr = optarg; | |
778 break; | |
779 case 'V': | |
780 print_version(argv[0]); | |
69 | 781 exit(EXIT_SUCCESS); |
0 | 782 } |
783 } | |
784 | |
69 | 785 if(mailfilename == NULL || (listdir == NULL && listctrl == NULL)) { |
786 fprintf(stderr, "You have to specify -m and -L or -l\n"); | |
0 | 787 fprintf(stderr, "%s -h for help\n", argv[0]); |
788 exit(EXIT_FAILURE); | |
789 } | |
69 | 790 |
295 | 791 /* Lets make sure no random user tries to send mail to the list */ |
792 if(listdir) { | |
793 if(stat(listdir, &st) == 0) { | |
794 uid = getuid(); | |
795 if(uid && uid != st.st_uid) { | |
796 log_error(LOG_ARGS, | |
797 "Have to invoke either as root " | |
798 "or as the user owning listdir"); | |
799 writen(STDERR_FILENO, | |
800 "Have to invoke either as root " | |
801 "or as the user owning listdir\n", 60); | |
802 exit(EXIT_FAILURE); | |
803 } | |
804 } else { | |
805 log_error(LOG_ARGS, "Could not stat %s", listdir); | |
806 exit(EXIT_FAILURE); | |
807 } | |
808 } | |
809 | |
69 | 810 if(!listctrl) |
245 | 811 listctrl = mystrdup("0"); |
69 | 812 |
813 | |
0 | 814 /* get the list address */ |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
815 if(listctrl[0] == '1' && (bounceaddr == NULL || to_addr == NULL)) { |
69 | 816 fprintf(stderr, "With -l 1 you need -F and -T\n"); |
817 exit(EXIT_FAILURE); | |
818 } | |
0 | 819 |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
820 if((listctrl[0] == '2' && (listdir == NULL || bounceaddr == NULL))) { |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
821 fprintf(stderr, "With -l 2 you need -L and -F\n"); |
69 | 822 exit(EXIT_FAILURE); |
823 } | |
824 | |
338 | 825 if((listctrl[0] == '7' && listdir == NULL)) { |
826 fprintf(stderr, "With -l 7 you need -L\n"); | |
827 exit(EXIT_FAILURE); | |
828 } | |
829 | |
426 | 830 verp = ctrlvalue(listdir, "verp"); |
831 chomp(verp); | |
449 | 832 if(verp == NULL) |
833 if(statctrl(listdir, "verp") == 1) | |
834 verp = mystrdup(""); | |
338 | 835 |
465 | 836 maxverprecipsstr = ctrlvalue(listdir, "maxverprecips"); |
837 if(verp && maxverprecipsstr) { | |
838 maxverprecips = atol(maxverprecipsstr); | |
839 myfree(maxverprecipsstr); | |
840 } | |
841 | |
842 if(maxverprecips <= 0) | |
843 maxverprecips = MAXVERPRECIPS; | |
844 | |
845 stl.strs = NULL; | |
846 stl.count = 0; | |
847 | |
264
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
848 switch(listctrl[0]) { |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
849 case '1': |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
850 case '2': |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
851 case '3': |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
852 case '4': |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
853 case '5': |
298 | 854 case '6': |
338 | 855 case '7': |
264
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
856 archive = 0; |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
857 default: |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
858 break; |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
859 } |
124
4c8cc076c784
Use the nice new mydirname and fix a bug with the archive variable.
mmj
parents:
117
diff
changeset
|
860 |
264
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
861 if(listdir && listctrl[0] != '5') |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
862 listaddr = getlistaddr(listdir); |
0 | 863 |
864 /* initialize file with mail to send */ | |
865 | |
401
c60351e368bd
Grab the lock right after we start sending, and not release before
mmj
parents:
383
diff
changeset
|
866 if((mailfd = open(mailfilename, O_RDWR)) < 0) { |
39 | 867 log_error(LOG_ARGS, "Could not open '%s'", mailfilename); |
0 | 868 exit(EXIT_FAILURE); |
869 } | |
870 | |
401
c60351e368bd
Grab the lock right after we start sending, and not release before
mmj
parents:
383
diff
changeset
|
871 if(myexcllock(mailfd) < 0) { |
c60351e368bd
Grab the lock right after we start sending, and not release before
mmj
parents:
383
diff
changeset
|
872 log_error(LOG_ARGS, "Could not lock '%s'." |
c60351e368bd
Grab the lock right after we start sending, and not release before
mmj
parents:
383
diff
changeset
|
873 "Mail not sent!", mailfilename); |
c60351e368bd
Grab the lock right after we start sending, and not release before
mmj
parents:
383
diff
changeset
|
874 exit(EXIT_FAILURE); |
c60351e368bd
Grab the lock right after we start sending, and not release before
mmj
parents:
383
diff
changeset
|
875 } |
c60351e368bd
Grab the lock right after we start sending, and not release before
mmj
parents:
383
diff
changeset
|
876 |
174
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
877 if(fstat(mailfd, &st) < 0) { |
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
878 log_error(LOG_ARGS, "Could not stat mailfd"); |
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
879 exit(EXIT_FAILURE); |
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
880 } |
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
881 |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
882 memmailsizestr = ctrlvalue(listdir, "memorymailsize"); |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
883 ctrlarchive = statctrl(listdir, "noarchive"); |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
884 if(memmailsizestr) { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
885 memmailsize = strtol(memmailsizestr, NULL, 10); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
886 myfree(memmailsizestr); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
887 } |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
888 |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
889 if(memmailsize == 0) |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
890 memmailsize = MEMORYMAILSIZE; |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
891 |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
892 if(st.st_size > memmailsize) { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
893 prepmailinmem = 0; |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
894 errno = 0; |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
895 log_error(LOG_ARGS, "Not preparing in memory. " |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
896 "Mail is %ld bytes", (long)st.st_size); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
897 } else |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
898 prepmailinmem = 1; |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
899 |
174
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
900 mailmap = mmap(0, st.st_size, PROT_READ, MAP_SHARED, mailfd, 0); |
176
186c65c5f81d
Use MAP_FAILED to indicate failed mmap rather than (void \*)-1
mmj
parents:
174
diff
changeset
|
901 if(mailmap == MAP_FAILED) { |
174
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
902 log_error(LOG_ARGS, "Could not mmap mailfd"); |
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
903 exit(EXIT_FAILURE); |
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
904 } |
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
905 |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
906 if(prepmailinmem) { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
907 hdrs = get_preppedhdrs_from_map(mailmap, &hdrslen); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
908 if(hdrs == NULL) { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
909 log_error(LOG_ARGS, "Could not prepare headers"); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
910 exit(EXIT_FAILURE); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
911 } |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
912 body = get_prepped_mailbody_from_map(mailmap, st.st_size, |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
913 &bodylen); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
914 if(body == NULL) { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
915 log_error(LOG_ARGS, "Could not prepare mailbody"); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
916 myfree(hdrs); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
917 exit(EXIT_FAILURE); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
918 } |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
919 } |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
920 |
520 | 921 if(listdir) |
922 listdelim = getlistdelim(listdir); | |
923 | |
69 | 924 switch(listctrl[0]) { |
925 case '1': /* A single mail is to be sent, do nothing */ | |
264
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
926 case '5': |
69 | 927 break; |
928 case '2': /* Moderators */ | |
184 | 929 subfilename = concatstr(2, listdir, "/control/moderators"); |
171 | 930 if((subfd = open(subfilename, O_RDONLY)) < 0) { |
69 | 931 log_error(LOG_ARGS, "Could not open '%s':", |
932 subfilename); | |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
933 myfree(hdrs); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
934 myfree(body); |
245 | 935 myfree(subfilename); |
520 | 936 myfree(listdelim); |
69 | 937 /* No moderators is no error. Could be the sysadmin |
938 * likes to do it manually. | |
939 */ | |
940 exit(EXIT_SUCCESS); | |
941 } | |
942 break; | |
228
fda21d560980
Make it possible to specify several owner emailaddresses, not just one
mmj
parents:
225
diff
changeset
|
943 case '3': |
545 | 944 addtohdr = statctrl(listdir, "addtohdr"); |
228
fda21d560980
Make it possible to specify several owner emailaddresses, not just one
mmj
parents:
225
diff
changeset
|
945 case '4': /* sending mails to subfile */ |
171 | 946 if((subfd = open(subfilename, O_RDONLY)) < 0) { |
147
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
947 log_error(LOG_ARGS, "Could not open '%s':", |
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
948 subfilename); |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
949 myfree(hdrs); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
950 myfree(body); |
520 | 951 myfree(listdelim); |
147
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
952 exit(EXIT_FAILURE); |
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
953 } |
305 | 954 break; |
298 | 955 case '6': |
956 archive = 0; | |
957 deletewhensent = 0; | |
958 archivefilename = mystrdup(mailfilename); | |
520 | 959 bounceaddr = bounce_from_adr(to_addr, listaddr, listdelim, |
677
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
960 archivefilename, listdir); |
298 | 961 break; |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
962 default: /* normal list mail -- now handled when forking */ |
545 | 963 addtohdr = statctrl(listdir, "addtohdr"); |
69 | 964 break; |
0 | 965 } |
966 | |
967 /* initialize the archive filename */ | |
116 | 968 if(archive) { |
72
42d75f6f0a3d
changed incindexfile() - removed incflag, changed error return to be 0, and it now saves last used index in the file
mortenp
parents:
71
diff
changeset
|
969 mindex = incindexfile((const char *)listdir); |
0 | 970 len = strlen(listdir) + 9 + 20; |
245 | 971 archivefilename = mymalloc(len); |
67
b6828d24be7e
This is new function to quickly stat a control of the list. Example:
mmj
parents:
50
diff
changeset
|
972 snprintf(archivefilename, len, "%s/archive/%d", listdir, |
b6828d24be7e
This is new function to quickly stat a control of the list. Example:
mmj
parents:
50
diff
changeset
|
973 mindex); |
0 | 974 } |
975 | |
426 | 976 itoa(mindex, strindex); |
977 | |
291 | 978 if(!relayhost) { |
979 relayhost = ctrlvalue(listdir, "relayhost"); | |
980 chomp(relayhost); | |
981 } | |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
982 if(!relayhost) |
291 | 983 strncpy(relay, RELAYHOST, sizeof(relay)); |
984 else { | |
985 relayent = gethostbyname(relayhost); | |
986 if(relayent == NULL) { | |
987 strncpy(relay, RELAYHOST, sizeof(relay)); | |
988 } else { | |
989 if(inet_ntop(relayent->h_addrtype, | |
990 relayent->h_addr_list[0], | |
991 relay, sizeof(relay)) == NULL) | |
992 strncpy(relay, RELAYHOST, sizeof(relay)); | |
993 } | |
994 } | |
458 | 995 strport = ctrlvalue(listdir, "smtpport"); |
996 if(strport) | |
997 smtpport = (unsigned short)atol(strport); | |
0 | 998 |
69 | 999 switch(listctrl[0]) { |
1000 case '1': /* A single mail is to be sent */ | |
298 | 1001 case '6': |
458 | 1002 initsmtp(&sockfd, relay, smtpport); |
174
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
1003 sendres = send_mail(sockfd, bounceaddr, to_addr, replyto, |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
1004 mailmap, st.st_size, listdir, NULL, |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
1005 hdrs, hdrslen, body, bodylen); |
103
bf4390ecc30b
Also dump MAIL FROM:, RCPT TO: and Reply To: variables in the case of an
mmj
parents:
102
diff
changeset
|
1006 endsmtp(&sockfd); |
bf4390ecc30b
Also dump MAIL FROM:, RCPT TO: and Reply To: variables in the case of an
mmj
parents:
102
diff
changeset
|
1007 if(sendres) { |
bf4390ecc30b
Also dump MAIL FROM:, RCPT TO: and Reply To: variables in the case of an
mmj
parents:
102
diff
changeset
|
1008 /* error, so keep it in the queue */ |
95 | 1009 deletewhensent = 0; |
509 | 1010 /* dump data we want when resending first check |
1011 * if it already exists. In that case continue */ | |
103
bf4390ecc30b
Also dump MAIL FROM:, RCPT TO: and Reply To: variables in the case of an
mmj
parents:
102
diff
changeset
|
1012 tmpstr = concatstr(2, mailfilename, ".mailfrom"); |
509 | 1013 if(stat(tmpstr, &st) == 0) { |
1014 myfree(tmpstr); | |
1015 break; | |
1016 } | |
171 | 1017 tmpfd = open(tmpstr, O_WRONLY|O_CREAT|O_TRUNC, |
1018 S_IRUSR|S_IWUSR); | |
245 | 1019 myfree(tmpstr); |
171 | 1020 if(tmpfd >= 0) { |
262
846d91ae6ebe
Don't litter the queue directory when rejecting posts for one reason or the
mmj
parents:
245
diff
changeset
|
1021 writen(tmpfd, bounceaddr, strlen(bounceaddr)); |
171 | 1022 fsync(tmpfd); |
1023 } | |
1024 close(tmpfd); | |
106 | 1025 tmpstr = concatstr(2, mailfilename, ".reciptto"); |
509 | 1026 if(stat(tmpstr, &st) == 0) { |
1027 myfree(tmpstr); | |
1028 break; | |
1029 } | |
171 | 1030 tmpfd = open(tmpstr, O_WRONLY|O_CREAT|O_TRUNC, |
1031 S_IRUSR|S_IWUSR); | |
245 | 1032 myfree(tmpstr); |
171 | 1033 if(tmpfd >= 0) { |
262
846d91ae6ebe
Don't litter the queue directory when rejecting posts for one reason or the
mmj
parents:
245
diff
changeset
|
1034 writen(tmpfd, to_addr, strlen(to_addr)); |
171 | 1035 fsync(tmpfd); |
1036 } | |
1037 close(tmpfd); | |
103
bf4390ecc30b
Also dump MAIL FROM:, RCPT TO: and Reply To: variables in the case of an
mmj
parents:
102
diff
changeset
|
1038 if(replyto) { |
bf4390ecc30b
Also dump MAIL FROM:, RCPT TO: and Reply To: variables in the case of an
mmj
parents:
102
diff
changeset
|
1039 tmpstr = concatstr(2, mailfilename, |
106 | 1040 ".reply-to"); |
509 | 1041 if(stat(tmpstr, &st) == 0) { |
1042 myfree(tmpstr); | |
1043 break; | |
1044 } | |
171 | 1045 tmpfd = open(tmpstr, O_WRONLY|O_CREAT|O_TRUNC, |
1046 S_IRUSR|S_IWUSR); | |
245 | 1047 myfree(tmpstr); |
171 | 1048 if(tmpfd >= 0) { |
1049 writen(tmpfd, replyto, | |
1050 strlen(replyto)); | |
1051 fsync(tmpfd); | |
1052 } | |
1053 close(tmpfd); | |
103
bf4390ecc30b
Also dump MAIL FROM:, RCPT TO: and Reply To: variables in the case of an
mmj
parents:
102
diff
changeset
|
1054 } |
bf4390ecc30b
Also dump MAIL FROM:, RCPT TO: and Reply To: variables in the case of an
mmj
parents:
102
diff
changeset
|
1055 } |
69 | 1056 break; |
1057 case '2': /* Moderators */ | |
458 | 1058 initsmtp(&sockfd, relay, smtpport); |
426 | 1059 if(send_mail_many_fd(sockfd, bounceaddr, NULL, mailmap, |
520 | 1060 st.st_size, subfd, NULL, NULL, NULL, |
1061 listdir, NULL, hdrs, hdrslen, | |
1062 body, bodylen)) | |
154 | 1063 close(sockfd); |
1064 else | |
1065 endsmtp(&sockfd); | |
69 | 1066 break; |
147
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
1067 case '3': /* resending earlier failed mails */ |
458 | 1068 initsmtp(&sockfd, relay, smtpport); |
426 | 1069 if(send_mail_many_fd(sockfd, NULL, NULL, mailmap, st.st_size, |
520 | 1070 subfd, listaddr, listdelim, mailfilename, |
1071 listdir, mlmmjbounce, hdrs, hdrslen, | |
1072 body, bodylen)) | |
154 | 1073 close(sockfd); |
1074 else | |
1075 endsmtp(&sockfd); | |
147
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
1076 unlink(subfilename); |
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
1077 break; |
228
fda21d560980
Make it possible to specify several owner emailaddresses, not just one
mmj
parents:
225
diff
changeset
|
1078 case '4': /* send mails to owner */ |
458 | 1079 initsmtp(&sockfd, relay, smtpport); |
426 | 1080 if(send_mail_many_fd(sockfd, bounceaddr, NULL, mailmap, |
520 | 1081 st.st_size, subfd, listaddr, listdelim, |
1082 mailfilename, listdir, mlmmjbounce, | |
1083 hdrs, hdrslen, body, bodylen)) | |
228
fda21d560980
Make it possible to specify several owner emailaddresses, not just one
mmj
parents:
225
diff
changeset
|
1084 close(sockfd); |
fda21d560980
Make it possible to specify several owner emailaddresses, not just one
mmj
parents:
225
diff
changeset
|
1085 else |
fda21d560980
Make it possible to specify several owner emailaddresses, not just one
mmj
parents:
225
diff
changeset
|
1086 endsmtp(&sockfd); |
fda21d560980
Make it possible to specify several owner emailaddresses, not just one
mmj
parents:
225
diff
changeset
|
1087 break; |
264
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1088 case '5': /* bounceprobe - handle relayhost local users bouncing*/ |
458 | 1089 initsmtp(&sockfd, relay, smtpport); |
264
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1090 sendres = send_mail(sockfd, bounceaddr, to_addr, replyto, |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
1091 mailmap, st.st_size, listdir, NULL, |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
1092 hdrs, hdrslen, body, bodylen); |
264
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1093 endsmtp(&sockfd); |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1094 if(sendres) { |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1095 /* error, so remove the probefile */ |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1096 tmpstr = mystrdup(to_addr); |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1097 a = strchr(tmpstr, '@'); |
674 | 1098 MY_ASSERT(a); |
264
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1099 *a = '='; |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1100 probefile = concatstr(4, listdir, "/bounce/", tmpstr, |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1101 "-probe"); |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1102 unlink(probefile); |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1103 myfree(probefile); |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1104 myfree(tmpstr); |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1105 } |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1106 break; |
338 | 1107 case '7': |
1108 digest = 1; | |
383
7de4e23f2e8e
Add a To: header with the recipient's address when sending digests
mortenp
parents:
370
diff
changeset
|
1109 addtohdr = 1; |
370 | 1110 archivefilename = "digest"; |
338 | 1111 /* fall through */ |
69 | 1112 default: /* normal list mail */ |
338 | 1113 if (!digest) { |
1114 subddirname = concatstr(2, listdir, "/subscribers.d/"); | |
1115 } else { | |
1116 subddirname = concatstr(2, listdir, "/digesters.d/"); | |
1117 } | |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1118 if((subddir = opendir(subddirname)) == NULL) { |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1119 log_error(LOG_ARGS, "Could not opendir(%s)", |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1120 subddirname); |
520 | 1121 myfree(listdelim); |
245 | 1122 myfree(subddirname); |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
1123 myfree(hdrs); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
1124 myfree(body); |
117
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
116
diff
changeset
|
1125 exit(EXIT_FAILURE); |
0 | 1126 } |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1127 |
520 | 1128 listdelim = getlistdelim(listdir); |
426 | 1129 listname = genlistname(listaddr); |
1130 listfqdn = genlistfqdn(listaddr); | |
520 | 1131 verpfrom = concatstr(6, listname, listdelim, "bounces-", |
1132 strindex, "@", listfqdn); | |
426 | 1133 myfree(listname); |
1134 myfree(listfqdn); | |
1135 | |
445 | 1136 if(digest) |
1137 verp = NULL; | |
1138 | |
426 | 1139 if(verp && (strcmp(verp, "postfix") == 0)) { |
1140 myfree(verp); | |
1141 verp = mystrdup("XVERP=-="); | |
1142 } | |
1143 | |
1144 if(addtohdr && verp) { | |
445 | 1145 log_error(LOG_ARGS, "Cannot use VERP and add " |
1146 "To: header. Not sending with " | |
1147 "VERP."); | |
426 | 1148 verp = NULL; |
1149 } | |
427
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1150 |
426 | 1151 if(verp) { |
458 | 1152 initsmtp(&sockfd, relay, smtpport); |
426 | 1153 if(write_mail_from(sockfd, verpfrom, verp)) { |
1154 log_error(LOG_ARGS, | |
1155 "Could not write MAIL FROM\n"); | |
1156 verp = NULL; | |
1157 } else { | |
1158 reply = checkwait_smtpreply(sockfd, MLMMJ_FROM); | |
1159 if(reply) { | |
1160 log_error(LOG_ARGS, | |
1161 "Mailserver did not " | |
1162 "accept verp mail from. " | |
1163 "Not sending with VERP."); | |
1164 myfree(reply); | |
1165 verp = NULL; | |
1166 } | |
1167 } | |
1168 endsmtp(&sockfd); | |
1169 } | |
1170 | |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1171 while((dp = readdir(subddir)) != NULL) { |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1172 if(!strcmp(dp->d_name, ".")) |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1173 continue; |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1174 if(!strcmp(dp->d_name, "..")) |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1175 continue; |
338 | 1176 subfilename = concatstr(2, subddirname, dp->d_name); |
171 | 1177 if((subfd = open(subfilename, O_RDONLY)) < 0) { |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1178 log_error(LOG_ARGS, "Could not open '%s'", |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1179 subfilename); |
245 | 1180 myfree(subfilename); |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1181 continue; |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1182 } |
426 | 1183 do { |
1184 res = getaddrsfromfd(&stl, subfd, | |
1185 maxverprecips); | |
727
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1186 if(omit != NULL && maxverprecips > 1) { |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1187 for(i = 0; i < stl.count; i++) { |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1188 if(strcmp(stl.strs[i], omit) |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1189 == 0) { |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1190 myfree(stl.strs[i]); |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1191 stl.count--; |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1192 while (i < stl.count) { |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1193 stl.strs[i] = |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1194 stl.strs[i+1]; |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1195 i++; |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1196 } |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1197 stl.strs[stl.count] = NULL; |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1198 break; |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1199 } |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1200 } |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1201 } |
426 | 1202 if(stl.count == maxverprecips) { |
458 | 1203 initsmtp(&sockfd, relay, smtpport); |
426 | 1204 if(verp) { |
1205 sendres = send_mail_verp( | |
1206 sockfd, &stl, | |
1207 mailmap, | |
1208 st.st_size, | |
1209 verpfrom, | |
1210 listdir, hdrs, | |
1211 hdrslen, body, | |
1212 bodylen, verp); | |
1213 if(sendres) | |
1214 requeuemail(listdir, | |
1215 strindex, | |
1216 &stl, 0); | |
1217 } else { | |
1218 sendres = send_mail_many_list( | |
1219 sockfd, NULL, | |
1220 NULL, mailmap, | |
1221 st.st_size, | |
1222 &stl, | |
1223 listaddr, | |
520 | 1224 listdelim, |
426 | 1225 archivefilename, |
1226 listdir, | |
1227 mlmmjbounce, | |
1228 hdrs, hdrslen, | |
1229 body, bodylen); | |
1230 } | |
1231 endsmtp(&sockfd); | |
1232 for(i = 0; i < stl.count; i++) | |
1233 myfree(stl.strs[i]); | |
1234 stl.count = 0; | |
1235 } | |
1236 } while(res > 0); | |
1237 myfree(subfilename); | |
1238 close(subfd); | |
1239 | |
427
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1240 } |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1241 if(stl.count) { |
458 | 1242 initsmtp(&sockfd, relay, smtpport); |
427
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1243 if(verp) { |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1244 sendres = send_mail_verp(sockfd, &stl, mailmap, |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1245 st.st_size, verpfrom, listdir, |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1246 hdrs, hdrslen, body, bodylen, |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1247 verp); |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1248 if(sendres) |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1249 requeuemail(listdir, strindex, &stl, |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1250 0); |
155
f844a6213c62
"Resolving" the conflict by committing my version anyway (it has a nice comment). That guy is fast.
mortenp
parents:
154
diff
changeset
|
1251 } else { |
427
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1252 sendres = send_mail_many_list(sockfd, NULL, |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1253 NULL, mailmap, st.st_size, |
520 | 1254 &stl, listaddr, listdelim, |
427
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1255 archivefilename, listdir, |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1256 mlmmjbounce, hdrs, hdrslen, |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1257 body, bodylen); |
155
f844a6213c62
"Resolving" the conflict by committing my version anyway (it has a nice comment). That guy is fast.
mortenp
parents:
154
diff
changeset
|
1258 } |
427
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1259 endsmtp(&sockfd); |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1260 for(i = 0; i < stl.count; i++) |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1261 myfree(stl.strs[i]); |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1262 stl.count = 0; |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1263 } |
427
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1264 |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1265 if (sendres) { |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1266 /* If send_mail_many() failed we close the |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1267 * connection to the mail server in a brutal |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1268 * manner, because we could be in any state |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1269 * (DATA for instance). */ |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1270 close(sockfd); |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1271 } else { |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1272 endsmtp(&sockfd); |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1273 } |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1274 myfree(stl.strs); |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1275 myfree(verpfrom); |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1276 closedir(subddir); |
338 | 1277 myfree(subddirname); |
69 | 1278 break; |
1279 } | |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1280 |
432 | 1281 for(i = 0; i < stl.count; i++) |
1282 myfree(stl.strs[i]); | |
1283 stl.count = 0; | |
1284 | |
520 | 1285 myfree(listdelim); |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
1286 myfree(hdrs); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
1287 myfree(body); |
370 | 1288 myfree(mlmmjbounce); |
1289 close(sockfd); | |
174
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
1290 munmap(mailmap, st.st_size); |
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
1291 close(mailfd); |
426 | 1292 myfree(verp); |
401
c60351e368bd
Grab the lock right after we start sending, and not release before
mmj
parents:
383
diff
changeset
|
1293 |
116 | 1294 if(archive) { |
411
79355dd5ecc2
Make the envelope from match the new order (VERP prep) and also remove
mmj
parents:
401
diff
changeset
|
1295 if(!ctrlarchive) { |
522 | 1296 if(rename(mailfilename, archivefilename) < 0) { |
1297 log_error(LOG_ARGS, | |
1298 "Could not rename(%s,%s);", | |
1299 mailfilename, | |
1300 archivefilename); | |
1301 } | |
411
79355dd5ecc2
Make the envelope from match the new order (VERP prep) and also remove
mmj
parents:
401
diff
changeset
|
1302 } else { |
601 | 1303 len = strlen(listdir) + 9 + 20 + 9; |
1304 requeuefilename = mymalloc(len); | |
1305 snprintf(requeuefilename, len, "%s/requeue/%d/mailfile", listdir, | |
1306 mindex); | |
1307 if (rename(mailfilename, requeuefilename) < 0) | |
1308 unlink(mailfilename); | |
1309 myfree(requeuefilename); | |
411
79355dd5ecc2
Make the envelope from match the new order (VERP prep) and also remove
mmj
parents:
401
diff
changeset
|
1310 } |
245 | 1311 myfree(archivefilename); |
0 | 1312 } else if(deletewhensent) |
1313 unlink(mailfilename); | |
1314 | |
1315 return EXIT_SUCCESS; | |
1316 } |