Mercurial > hg > mlmmj
annotate src/mlmmj-send.c @ 773:2add5c5f88f8
Fix some memory leaks
author | Ben Schmidt |
---|---|
date | Fri, 12 Nov 2010 00:53:36 +1100 |
parents | 179d5a0ed686 |
children | 62f9b36df5a5 |
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; |
773 | 251 char *reply, *reply2, *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); |
773 | 271 reply2 = checkwait_smtpreply(sockfd, MLMMJ_RSET); |
272 if (reply2 != NULL) myfree(reply2); | |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
273 return MLMMJ_FROM; |
0 | 274 } |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
275 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
|
276 if(retval) { |
39 | 277 log_error(LOG_ARGS, "Could not write RCPT TO:\n"); |
0 | 278 return retval; |
279 } | |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
280 |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
281 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
|
282 if(reply) { |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
283 write_rset(sockfd); |
773 | 284 reply2 = checkwait_smtpreply(sockfd, MLMMJ_RSET); |
285 if (reply2 != NULL) myfree(reply2); | |
225 | 286 if(mlmmjbounce && ((reply[0] == '4') || (reply[0] == '5')) |
287 && (reply[1] == '5')) { | |
245 | 288 myfree(reply); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
289 return bouncemail(listdir, mlmmjbounce, from); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
290 } else { |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
291 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
|
292 reply); |
245 | 293 myfree(reply); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
294 return MLMMJ_RCPTTO; |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
295 } |
0 | 296 } |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
297 |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
298 retval = write_data(sockfd); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
299 if(retval) { |
39 | 300 log_error(LOG_ARGS, "Could not write DATA\b"); |
0 | 301 return retval; |
302 } | |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
303 |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
304 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
|
305 if(reply) { |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
306 log_error(LOG_ARGS, "Error with DATA. Reply = [%s]", reply); |
245 | 307 myfree(reply); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
308 write_rset(sockfd); |
773 | 309 reply2 = checkwait_smtpreply(sockfd, MLMMJ_RSET); |
310 if (reply2 != NULL) myfree(reply2); | |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
311 return MLMMJ_DATA; |
0 | 312 } |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
313 |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
314 if(replyto) { |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
315 retval = write_replyto(sockfd, replyto); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
316 if(retval) { |
39 | 317 log_error(LOG_ARGS, "Could not write reply-to addr.\n"); |
0 | 318 return retval; |
319 } | |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
320 } |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
321 |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
322 if(addtohdr) |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
323 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
|
324 else |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
325 tohdr = NULL; |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
326 |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
327 if(prepmailinmem) { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
328 retval = writen(sockfd, hdrs, hdrslen); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
329 if(retval < 0) { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
330 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
|
331 return retval; |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
332 } |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
333 if(tohdr) { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
334 retval = writen(sockfd, tohdr, strlen(tohdr)); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
335 if(retval < 0) { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
336 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
|
337 return retval; |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
338 } |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
339 myfree(tohdr); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
340 } |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
341 retval = writen(sockfd, body, bodylen); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
342 if(retval < 0) { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
343 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
|
344 return retval; |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
345 } |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
346 } else { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
347 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
|
348 tohdr); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
349 if(retval) { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
350 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
|
351 return retval; |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
352 } |
0 | 353 } |
354 | |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
355 retval = write_dot(sockfd); |
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
356 if(retval) { |
39 | 357 log_error(LOG_ARGS, "Could not write <CR><LF>.<CR><LF>\n"); |
0 | 358 return retval; |
359 } | |
360 | |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
361 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
|
362 if(reply) { |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
363 log_error(LOG_ARGS, "Mailserver did not ack end of mail.\n" |
0 | 364 "<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
|
365 "avail. Reply = [%s]", reply); |
245 | 366 myfree(reply); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
367 write_rset(sockfd); |
773 | 368 reply2 = checkwait_smtpreply(sockfd, MLMMJ_RSET); |
369 if (reply2 != NULL) myfree(reply2); | |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
370 return MLMMJ_DOT; |
0 | 371 } |
372 | |
373 return 0; | |
374 } | |
375 | |
458 | 376 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
|
377 { |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
378 int retval = 0; |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
379 char *reply = NULL; |
99
6089f38bb228
Send our hostname in HELO and change the mlmmj-send output from
mmj
parents:
95
diff
changeset
|
380 char *myhostname = hostnamestr(); |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
381 |
458 | 382 init_sockfd(sockfd, relayhost, port); |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
383 |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
384 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
|
385 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
|
386 "Reply: [%s]", reply); |
245 | 387 myfree(reply); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
388 retval = MLMMJ_CONNECT; |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
389 /* FIXME: Queue etc. */ |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
390 } |
99
6089f38bb228
Send our hostname in HELO and change the mlmmj-send output from
mmj
parents:
95
diff
changeset
|
391 write_helo(*sockfd, myhostname); |
245 | 392 myfree(myhostname); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
393 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
|
394 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
|
395 /* FIXME: quit and tell admin to configure correctly */ |
245 | 396 myfree(reply); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
397 retval = MLMMJ_HELO; |
77
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 |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
400 return retval; |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
401 } |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
402 |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
403 int endsmtp(int *sockfd) |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
404 { |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
405 int retval = 0; |
426 | 406 char *reply = NULL; |
445 | 407 |
408 if(*sockfd == -1) | |
409 return retval; | |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
410 |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
411 write_quit(*sockfd); |
426 | 412 reply = checkwait_smtpreply(*sockfd, MLMMJ_QUIT); |
413 if(reply) { | |
414 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
|
415 log_error(LOG_ARGS, "Mailserver would not let us QUIT. " |
426 | 416 "We close the socket anyway though. " |
417 "Mailserver reply = [%s]", reply); | |
245 | 418 myfree(reply); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
419 retval = MLMMJ_QUIT; |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
420 } |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
421 |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
422 close(*sockfd); |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
423 |
465 | 424 *sockfd = -1; |
425 | |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
426 return retval; |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
427 } |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
428 |
426 | 429 int send_mail_verp(int sockfd, struct strlist *addrs, char *mailmap, |
430 size_t mailsize, const char *from, const char *listdir, | |
431 const char *hdrs, size_t hdrslen, const char *body, | |
432 size_t bodylen, const char *verpextra) | |
433 { | |
434 int retval, i; | |
773 | 435 char *reply, *reply2; |
426 | 436 |
437 retval = write_mail_from(sockfd, from, verpextra); | |
438 if(retval) { | |
439 log_error(LOG_ARGS, "Could not write MAIL FROM\n"); | |
440 return retval; | |
441 } | |
442 reply = checkwait_smtpreply(sockfd, MLMMJ_FROM); | |
443 if(reply) { | |
444 log_error(LOG_ARGS, "Error in MAIL FROM. Reply = [%s]", | |
445 reply); | |
446 myfree(reply); | |
447 write_rset(sockfd); | |
773 | 448 reply2 = checkwait_smtpreply(sockfd, MLMMJ_RSET); |
449 if (reply2 != NULL) myfree(reply2); | |
426 | 450 return MLMMJ_FROM; |
451 } | |
452 for(i = 0; i < addrs->count; i++) { | |
489 | 453 if(gotsigterm) { |
748
dfc9ab125fd4
Fix spelling of 'receive' and 'voodoo'; make mlmmj-recieve a symlink
Chris Webb
parents:
727
diff
changeset
|
454 log_error(LOG_ARGS, "TERM signal received, " |
489 | 455 "shutting down."); |
456 return -1; | |
457 } | |
472 | 458 if(strchr(addrs->strs[i], '@') == NULL) { |
459 errno = 0; | |
460 log_error(LOG_ARGS, "No @ in address, ignoring %s", | |
461 addrs->strs[i]); | |
462 continue; | |
463 } | |
426 | 464 retval = write_rcpt_to(sockfd, addrs->strs[i]); |
465 if(retval) { | |
466 log_error(LOG_ARGS, "Could not write RCPT TO:\n"); | |
467 return retval; | |
468 } | |
469 | |
470 reply = checkwait_smtpreply(sockfd, MLMMJ_RCPTTO); | |
471 if(reply) { | |
472 log_error(LOG_ARGS, "Error in RCPT TO. Reply = [%s]", | |
473 reply); | |
474 myfree(reply); | |
475 return MLMMJ_RCPTTO; | |
476 } | |
477 } | |
478 | |
479 retval = write_data(sockfd); | |
480 if(retval) { | |
481 log_error(LOG_ARGS, "Could not write DATA\b"); | |
482 return retval; | |
483 } | |
484 | |
485 reply = checkwait_smtpreply(sockfd, MLMMJ_DATA); | |
486 if(reply) { | |
487 log_error(LOG_ARGS, "Error with DATA. Reply = [%s]", reply); | |
488 myfree(reply); | |
489 write_rset(sockfd); | |
773 | 490 reply2 = checkwait_smtpreply(sockfd, MLMMJ_RSET); |
491 if (reply2 != NULL) myfree(reply2); | |
426 | 492 return MLMMJ_DATA; |
493 } | |
494 | |
495 if(prepmailinmem) { | |
496 retval = writen(sockfd, hdrs, hdrslen); | |
497 if(retval < 0) { | |
498 log_error(LOG_ARGS, "Could not write mailheaders.\n"); | |
499 return retval; | |
500 } | |
501 retval = writen(sockfd, body, bodylen); | |
502 if(retval < 0) { | |
503 log_error(LOG_ARGS, "Could not write mailbody.\n"); | |
504 return retval; | |
505 } | |
506 } else { | |
507 retval = write_mailbody_from_map(sockfd, mailmap, mailsize, | |
508 NULL); | |
509 if(retval) { | |
510 log_error(LOG_ARGS, "Could not write mail\n"); | |
511 return retval; | |
512 } | |
513 } | |
514 | |
515 retval = write_dot(sockfd); | |
516 if(retval) { | |
517 log_error(LOG_ARGS, "Could not write <CR><LF>.<CR><LF>\n"); | |
518 return retval; | |
519 } | |
520 | |
521 reply = checkwait_smtpreply(sockfd, MLMMJ_DOT); | |
522 if(reply) { | |
523 log_error(LOG_ARGS, "Mailserver did not ack end of mail.\n" | |
524 "<CR><LF>.<CR><LF> was written, to no" | |
525 "avail. Reply = [%s]", reply); | |
526 myfree(reply); | |
527 write_rset(sockfd); | |
773 | 528 reply2 = checkwait_smtpreply(sockfd, MLMMJ_RSET); |
529 if (reply2 != NULL) myfree(reply2); | |
426 | 530 return MLMMJ_DOT; |
531 } | |
532 | |
533 return 0; | |
534 } | |
535 | |
536 int send_mail_many_fd(int sockfd, const char *from, const char *replyto, | |
537 char *mailmap, size_t mailsize, int subfd, | |
520 | 538 const char *listaddr, const char *listdelim, |
539 const char *archivefilename, const char *listdir, | |
540 const char *mlmmjbounce, const char *hdrs, size_t hdrslen, | |
541 const char *body, size_t bodylen) | |
426 | 542 { |
543 int res, ret, i; | |
544 struct strlist stl; | |
545 | |
465 | 546 stl.strs = NULL; |
432 | 547 stl.count = 0; |
548 | |
426 | 549 do { |
550 res = getaddrsfromfd(&stl, subfd, maxverprecips); | |
551 if(stl.count == maxverprecips) { | |
552 ret = send_mail_many_list(sockfd, from, replyto, | |
553 mailmap, mailsize, &stl, listaddr, | |
520 | 554 listdelim, archivefilename, listdir, |
555 mlmmjbounce, hdrs, hdrslen, | |
556 body, bodylen); | |
426 | 557 for(i = 0; i < stl.count; i++) |
558 myfree(stl.strs[i]); | |
559 if(ret < 0) | |
560 return ret; | |
561 stl.count = 0; | |
562 } | |
563 } while(res > 0); | |
564 | |
565 if(stl.count) { | |
566 ret = send_mail_many_list(sockfd, from, replyto, mailmap, | |
520 | 567 mailsize, &stl, listaddr, listdelim, |
568 archivefilename, listdir, mlmmjbounce, | |
569 hdrs, hdrslen, body, bodylen); | |
426 | 570 for(i = 0; i < stl.count; i++) |
571 myfree(stl.strs[i]); | |
572 stl.count = 0; | |
573 return ret; | |
574 } | |
575 | |
576 return 0; | |
577 } | |
578 | |
579 int requeuemail(const char *listdir, const char *index, struct strlist *addrs, | |
580 int addrcount) | |
581 { | |
582 int addrfd, i; | |
583 char *dirname, *addrfilename, *addr; | |
584 | |
585 dirname = concatstr(3, listdir, "/requeue/", index); | |
586 if(mkdir(dirname, 0750) < 0 && errno != EEXIST) { | |
587 log_error(LOG_ARGS, "Could not mkdir(%s) for " | |
588 "requeueing. Mail cannot " | |
589 "be requeued.", dirname); | |
590 myfree(dirname); | |
591 return -1; | |
592 } | |
593 addrfilename = concatstr(2, dirname, "/subscribers"); | |
594 myfree(dirname); | |
595 addrfd = open(addrfilename, O_WRONLY|O_CREAT|O_APPEND, | |
596 S_IRUSR|S_IWUSR); | |
597 if(addrfd < 0) { | |
598 log_error(LOG_ARGS, "Could not open %s", | |
599 addrfilename); | |
600 myfree(addrfilename); | |
601 return -1; | |
602 } else { | |
603 /* Dump the remaining addresses. We dump the remaining before | |
604 * we write the failing address to ensure the potential good | |
605 * ones will be tried first when mlmmj-maintd sends out mails | |
606 * that have been requeued. addrcount was so far we were */ | |
607 for(i = addrcount + 1; i < addrs->count; i++) { | |
608 addr = concatstr(2, addrs->strs[i], "\n"); | |
609 if(writen(addrfd, addr, strlen(addr)) < 0) { | |
610 log_error(LOG_ARGS, "Could not add [%s] " | |
611 "to requeue file", addr); | |
612 return -1; | |
613 } | |
614 myfree(addr); | |
615 } | |
616 addr = concatstr(2, addrs->strs[addrcount], "\n"); | |
617 if(writen(addrfd, addr, strlen(addr)) < 0) { | |
618 log_error(LOG_ARGS, "Could not add [%s] to requeue " | |
619 "file", addr); | |
620 return -1; | |
621 } | |
622 myfree(addr); | |
623 } | |
624 myfree(addrfilename); | |
625 close(addrfd); | |
626 | |
627 return 0; | |
628 } | |
629 | |
630 int send_mail_many_list(int sockfd, const char *from, const char *replyto, | |
631 char *mailmap, size_t mailsize, struct strlist *addrs, | |
520 | 632 const char *listaddr, const char *listdelim, |
633 const char *archivefilename, const char *listdir, | |
634 const char *mlmmjbounce, const char *hdrs, size_t hdrslen, | |
635 const char *body, size_t bodylen) | |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
636 { |
601 | 637 int res = 0, i, status; |
426 | 638 char *bounceaddr, *addr, *index; |
177
503250510778
Use mmap to find the subscribers in the subscribers files
mmj
parents:
176
diff
changeset
|
639 |
426 | 640 for(i = 0; i < addrs->count; i++) { |
641 addr = addrs->strs[i]; | |
472 | 642 if(strchr(addr, '@') == NULL) { |
643 errno = 0; | |
644 log_error(LOG_ARGS, "No @ in address, ignoring %s", | |
645 addr); | |
646 continue; | |
647 } | |
493 | 648 if(gotsigterm && listaddr && archivefilename) { |
649 /* 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
|
650 log_error(LOG_ARGS, "TERM signal received, " |
493 | 651 "shutting down."); |
601 | 652 index = get_index_from_filename(archivefilename); |
653 status = requeuemail(listdir, index, addrs, i); | |
654 myfree(index); | |
655 return status; | |
493 | 656 } |
338 | 657 if(from) { |
426 | 658 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
|
659 mailmap, mailsize, listdir, NULL, |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
660 hdrs, hdrslen, body, bodylen); |
338 | 661 } else { |
520 | 662 bounceaddr = bounce_from_adr(addr, listaddr, listdelim, |
677
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
663 archivefilename, listdir); |
426 | 664 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
|
665 mailmap, mailsize, listdir, mlmmjbounce, |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
666 hdrs, hdrslen, body, bodylen); |
245 | 667 myfree(bounceaddr); |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
668 } |
493 | 669 if(res && listaddr && archivefilename) { |
670 /* we failed, so save the addresses and bail */ | |
601 | 671 index = get_index_from_filename(archivefilename); |
672 status = requeuemail(listdir, index, addrs, i); | |
673 myfree(index); | |
674 return status; | |
95 | 675 } |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
676 } |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
677 return 0; |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
678 } |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
679 |
102 | 680 static void print_help(const char *prg) |
681 { | |
756 | 682 printf("Usage: %s [-L /path/to/list -m /path/to/mail | -l listctrl]\n" |
683 " [-a] [-D] [-F sender@example.org] [-h] [-o address@example.org]\n" | |
684 " [-r 127.0.0.1] [-R reply@example.org] [-s /path/to/subscribers]\n" | |
685 " [-T recipient@example.org] [-V]\n" | |
116 | 686 " -a: Don't archive the mail\n" |
102 | 687 " -D: Don't delete the mail after it's sent\n" |
688 " -F: What to use as MAIL FROM:\n" | |
689 " -h: This help\n" | |
147
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
690 " -l: List control variable:\n", prg); |
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
691 printf(" '1' means 'send a single mail'\n" |
102 | 692 " '2' means 'mail to moderators'\n" |
184 | 693 " '3' means 'resend failed list mail'\n" |
272 | 694 " '4' means 'send to file with recipients'\n" |
695 " '5' means 'bounceprobe'\n" | |
298 | 696 " '6' means 'single listmail to single recipient'\n" |
756 | 697 " '7' means 'digest'\n"); |
698 printf(" -L: Full path to list directory\n" | |
102 | 699 " -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
|
700 " -o: Address to omit from distribution (normal mail only)\n" |
272 | 701 " -r: Relayhost IP address (defaults to 127.0.0.1)\n" |
102 | 702 " -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
|
703 " -s: Subscribers file name\n" |
102 | 704 " -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
|
705 " -V: Print version\n"); |
102 | 706 exit(EXIT_SUCCESS); |
707 } | |
708 | |
0 | 709 int main(int argc, char **argv) |
710 { | |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
711 size_t len = 0, hdrslen, bodylen; |
445 | 712 int sockfd = -1, mailfd = 0, opt, mindex = 0, subfd = 0, tmpfd, i; |
426 | 713 int deletewhensent = 1, sendres = 0, archive = 1, digest = 0; |
714 int ctrlarchive, res; | |
520 | 715 char *listaddr = NULL, *listdelim = NULL; |
727
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
716 char *mailfilename = NULL, *subfilename = NULL, *omit = NULL; |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
717 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
|
718 char *relayhost = NULL, *archivefilename = NULL, *tmpstr; |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
719 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
|
720 char *mlmmjbounce = NULL, *bindir, *mailmap, *probefile, *a; |
426 | 721 char *body = NULL, *hdrs = NULL, *memmailsizestr = NULL, *verp = NULL; |
722 char relay[16], *listname, *listfqdn, *verpfrom, *maxverprecipsstr; | |
601 | 723 char strindex[32], *reply, *strport, *requeuefilename; |
272 | 724 ssize_t memmailsize = 0; |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
725 DIR *subddir; |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
726 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
|
727 struct stat st; |
291 | 728 struct hostent *relayent; |
295 | 729 uid_t uid; |
426 | 730 struct strlist stl; |
458 | 731 unsigned short smtpport = 25; |
491 | 732 struct sigaction sigact; |
208
688011dbc4b7
Add a macro to make sure mlmmj binaries are invoked with full path
mmj
parents:
191
diff
changeset
|
733 |
688011dbc4b7
Add a macro to make sure mlmmj binaries are invoked with full path
mmj
parents:
191
diff
changeset
|
734 CHECKFULLPATH(argv[0]); |
0 | 735 |
736 log_set_name(argv[0]); | |
737 | |
124
4c8cc076c784
Use the nice new mydirname and fix a bug with the archive variable.
mmj
parents:
117
diff
changeset
|
738 bindir = mydirname(argv[0]); |
4c8cc076c784
Use the nice new mydirname and fix a bug with the archive variable.
mmj
parents:
117
diff
changeset
|
739 mlmmjbounce = concatstr(2, bindir, "/mlmmj-bounce"); |
245 | 740 myfree(bindir); |
112
eb5ec53ecbc7
Make mlmmj-send capable of handling a bounce from the relayhost and invoke
mmj
parents:
106
diff
changeset
|
741 |
489 | 742 /* install signal handler for SIGTERM */ |
491 | 743 sigact.sa_handler = catch_sig_term; |
493 | 744 sigemptyset(&sigact.sa_mask); |
491 | 745 sigact.sa_flags = 0; |
746 if(sigaction(SIGTERM, &sigact, NULL) < 0) | |
489 | 747 log_error(LOG_ARGS, "Could not install SIGTERM handler!"); |
748 | |
727
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
749 while ((opt = getopt(argc, argv, "aVDhm:l:L:R:F:T:r:s:o:")) != -1){ |
0 | 750 switch(opt) { |
116 | 751 case 'a': |
752 archive = 0; | |
117
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
116
diff
changeset
|
753 break; |
0 | 754 case 'D': |
755 deletewhensent = 0; | |
756 break; | |
757 case 'F': | |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
758 bounceaddr = optarg; |
0 | 759 break; |
760 case 'h': | |
761 print_help(argv[0]); | |
762 break; | |
69 | 763 case 'l': |
764 listctrl = optarg; | |
765 break; | |
0 | 766 case 'L': |
767 listdir = optarg; | |
768 break; | |
769 case 'm': | |
770 mailfilename = optarg; | |
771 break; | |
727
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
772 case 'o': |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
773 omit = optarg; |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
774 break; |
0 | 775 case 'r': |
776 relayhost = optarg; | |
777 break; | |
778 case 'R': | |
779 replyto = optarg; | |
780 break; | |
147
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
781 case 's': |
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
782 subfilename = optarg; |
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
783 break; |
0 | 784 case 'T': |
785 to_addr = optarg; | |
786 break; | |
787 case 'V': | |
788 print_version(argv[0]); | |
69 | 789 exit(EXIT_SUCCESS); |
0 | 790 } |
791 } | |
792 | |
69 | 793 if(mailfilename == NULL || (listdir == NULL && listctrl == NULL)) { |
794 fprintf(stderr, "You have to specify -m and -L or -l\n"); | |
0 | 795 fprintf(stderr, "%s -h for help\n", argv[0]); |
796 exit(EXIT_FAILURE); | |
797 } | |
69 | 798 |
295 | 799 /* Lets make sure no random user tries to send mail to the list */ |
800 if(listdir) { | |
801 if(stat(listdir, &st) == 0) { | |
802 uid = getuid(); | |
803 if(uid && uid != st.st_uid) { | |
804 log_error(LOG_ARGS, | |
805 "Have to invoke either as root " | |
806 "or as the user owning listdir"); | |
807 writen(STDERR_FILENO, | |
808 "Have to invoke either as root " | |
809 "or as the user owning listdir\n", 60); | |
810 exit(EXIT_FAILURE); | |
811 } | |
812 } else { | |
813 log_error(LOG_ARGS, "Could not stat %s", listdir); | |
814 exit(EXIT_FAILURE); | |
815 } | |
816 } | |
817 | |
69 | 818 if(!listctrl) |
245 | 819 listctrl = mystrdup("0"); |
69 | 820 |
821 | |
0 | 822 /* get the list address */ |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
823 if(listctrl[0] == '1' && (bounceaddr == NULL || to_addr == NULL)) { |
69 | 824 fprintf(stderr, "With -l 1 you need -F and -T\n"); |
825 exit(EXIT_FAILURE); | |
826 } | |
0 | 827 |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
828 if((listctrl[0] == '2' && (listdir == NULL || bounceaddr == NULL))) { |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
829 fprintf(stderr, "With -l 2 you need -L and -F\n"); |
69 | 830 exit(EXIT_FAILURE); |
831 } | |
832 | |
338 | 833 if((listctrl[0] == '7' && listdir == NULL)) { |
834 fprintf(stderr, "With -l 7 you need -L\n"); | |
835 exit(EXIT_FAILURE); | |
836 } | |
837 | |
426 | 838 verp = ctrlvalue(listdir, "verp"); |
839 chomp(verp); | |
449 | 840 if(verp == NULL) |
841 if(statctrl(listdir, "verp") == 1) | |
842 verp = mystrdup(""); | |
338 | 843 |
465 | 844 maxverprecipsstr = ctrlvalue(listdir, "maxverprecips"); |
845 if(verp && maxverprecipsstr) { | |
846 maxverprecips = atol(maxverprecipsstr); | |
847 myfree(maxverprecipsstr); | |
848 } | |
849 | |
850 if(maxverprecips <= 0) | |
851 maxverprecips = MAXVERPRECIPS; | |
852 | |
853 stl.strs = NULL; | |
854 stl.count = 0; | |
855 | |
264
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
856 switch(listctrl[0]) { |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
857 case '1': |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
858 case '2': |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
859 case '3': |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
860 case '4': |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
861 case '5': |
298 | 862 case '6': |
338 | 863 case '7': |
264
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
864 archive = 0; |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
865 default: |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
866 break; |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
867 } |
124
4c8cc076c784
Use the nice new mydirname and fix a bug with the archive variable.
mmj
parents:
117
diff
changeset
|
868 |
264
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
869 if(listdir && listctrl[0] != '5') |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
870 listaddr = getlistaddr(listdir); |
0 | 871 |
872 /* initialize file with mail to send */ | |
873 | |
401
c60351e368bd
Grab the lock right after we start sending, and not release before
mmj
parents:
383
diff
changeset
|
874 if((mailfd = open(mailfilename, O_RDWR)) < 0) { |
39 | 875 log_error(LOG_ARGS, "Could not open '%s'", mailfilename); |
0 | 876 exit(EXIT_FAILURE); |
877 } | |
878 | |
401
c60351e368bd
Grab the lock right after we start sending, and not release before
mmj
parents:
383
diff
changeset
|
879 if(myexcllock(mailfd) < 0) { |
c60351e368bd
Grab the lock right after we start sending, and not release before
mmj
parents:
383
diff
changeset
|
880 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
|
881 "Mail not sent!", mailfilename); |
c60351e368bd
Grab the lock right after we start sending, and not release before
mmj
parents:
383
diff
changeset
|
882 exit(EXIT_FAILURE); |
c60351e368bd
Grab the lock right after we start sending, and not release before
mmj
parents:
383
diff
changeset
|
883 } |
c60351e368bd
Grab the lock right after we start sending, and not release before
mmj
parents:
383
diff
changeset
|
884 |
174
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
885 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
|
886 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
|
887 exit(EXIT_FAILURE); |
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
888 } |
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
889 |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
890 memmailsizestr = ctrlvalue(listdir, "memorymailsize"); |
343
6d1f589dee87
This is post crash commit of working copy mmj. Will test compile etc.
mmj
parents:
338
diff
changeset
|
891 ctrlarchive = statctrl(listdir, "noarchive"); |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
892 if(memmailsizestr) { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
893 memmailsize = strtol(memmailsizestr, NULL, 10); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
894 myfree(memmailsizestr); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
895 } |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
896 |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
897 if(memmailsize == 0) |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
898 memmailsize = MEMORYMAILSIZE; |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
899 |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
900 if(st.st_size > memmailsize) { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
901 prepmailinmem = 0; |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
902 errno = 0; |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
903 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
|
904 "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
|
905 } else |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
906 prepmailinmem = 1; |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
907 |
174
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
908 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
|
909 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
|
910 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
|
911 exit(EXIT_FAILURE); |
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
912 } |
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
913 |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
914 if(prepmailinmem) { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
915 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
|
916 if(hdrs == NULL) { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
917 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
|
918 exit(EXIT_FAILURE); |
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 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
|
921 &bodylen); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
922 if(body == NULL) { |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
923 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
|
924 myfree(hdrs); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
925 exit(EXIT_FAILURE); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
926 } |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
927 } |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
928 |
520 | 929 if(listdir) |
930 listdelim = getlistdelim(listdir); | |
931 | |
69 | 932 switch(listctrl[0]) { |
933 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
|
934 case '5': |
69 | 935 break; |
936 case '2': /* Moderators */ | |
184 | 937 subfilename = concatstr(2, listdir, "/control/moderators"); |
171 | 938 if((subfd = open(subfilename, O_RDONLY)) < 0) { |
69 | 939 log_error(LOG_ARGS, "Could not open '%s':", |
940 subfilename); | |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
941 myfree(hdrs); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
942 myfree(body); |
245 | 943 myfree(subfilename); |
520 | 944 myfree(listdelim); |
69 | 945 /* No moderators is no error. Could be the sysadmin |
946 * likes to do it manually. | |
947 */ | |
948 exit(EXIT_SUCCESS); | |
949 } | |
950 break; | |
228
fda21d560980
Make it possible to specify several owner emailaddresses, not just one
mmj
parents:
225
diff
changeset
|
951 case '3': |
545 | 952 addtohdr = statctrl(listdir, "addtohdr"); |
228
fda21d560980
Make it possible to specify several owner emailaddresses, not just one
mmj
parents:
225
diff
changeset
|
953 case '4': /* sending mails to subfile */ |
171 | 954 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
|
955 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
|
956 subfilename); |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
957 myfree(hdrs); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
958 myfree(body); |
520 | 959 myfree(listdelim); |
147
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
960 exit(EXIT_FAILURE); |
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
961 } |
305 | 962 break; |
298 | 963 case '6': |
964 archive = 0; | |
965 deletewhensent = 0; | |
966 archivefilename = mystrdup(mailfilename); | |
520 | 967 bounceaddr = bounce_from_adr(to_addr, listaddr, listdelim, |
677
c8e85bb330ed
Added support for static bounce addresses (Thomas Jarosch)
mortenp
parents:
674
diff
changeset
|
968 archivefilename, listdir); |
298 | 969 break; |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
970 default: /* normal list mail -- now handled when forking */ |
545 | 971 addtohdr = statctrl(listdir, "addtohdr"); |
69 | 972 break; |
0 | 973 } |
974 | |
975 /* initialize the archive filename */ | |
116 | 976 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
|
977 mindex = incindexfile((const char *)listdir); |
0 | 978 len = strlen(listdir) + 9 + 20; |
245 | 979 archivefilename = mymalloc(len); |
67
b6828d24be7e
This is new function to quickly stat a control of the list. Example:
mmj
parents:
50
diff
changeset
|
980 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
|
981 mindex); |
0 | 982 } |
983 | |
426 | 984 itoa(mindex, strindex); |
985 | |
291 | 986 if(!relayhost) { |
987 relayhost = ctrlvalue(listdir, "relayhost"); | |
988 chomp(relayhost); | |
989 } | |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
990 if(!relayhost) |
291 | 991 strncpy(relay, RELAYHOST, sizeof(relay)); |
992 else { | |
993 relayent = gethostbyname(relayhost); | |
994 if(relayent == NULL) { | |
995 strncpy(relay, RELAYHOST, sizeof(relay)); | |
996 } else { | |
997 if(inet_ntop(relayent->h_addrtype, | |
998 relayent->h_addr_list[0], | |
999 relay, sizeof(relay)) == NULL) | |
1000 strncpy(relay, RELAYHOST, sizeof(relay)); | |
1001 } | |
1002 } | |
458 | 1003 strport = ctrlvalue(listdir, "smtpport"); |
1004 if(strport) | |
1005 smtpport = (unsigned short)atol(strport); | |
0 | 1006 |
69 | 1007 switch(listctrl[0]) { |
1008 case '1': /* A single mail is to be sent */ | |
298 | 1009 case '6': |
458 | 1010 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
|
1011 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
|
1012 mailmap, st.st_size, listdir, NULL, |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
1013 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
|
1014 endsmtp(&sockfd); |
bf4390ecc30b
Also dump MAIL FROM:, RCPT TO: and Reply To: variables in the case of an
mmj
parents:
102
diff
changeset
|
1015 if(sendres) { |
bf4390ecc30b
Also dump MAIL FROM:, RCPT TO: and Reply To: variables in the case of an
mmj
parents:
102
diff
changeset
|
1016 /* error, so keep it in the queue */ |
95 | 1017 deletewhensent = 0; |
509 | 1018 /* dump data we want when resending first check |
1019 * 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
|
1020 tmpstr = concatstr(2, mailfilename, ".mailfrom"); |
509 | 1021 if(stat(tmpstr, &st) == 0) { |
1022 myfree(tmpstr); | |
1023 break; | |
1024 } | |
171 | 1025 tmpfd = open(tmpstr, O_WRONLY|O_CREAT|O_TRUNC, |
1026 S_IRUSR|S_IWUSR); | |
245 | 1027 myfree(tmpstr); |
171 | 1028 if(tmpfd >= 0) { |
262
846d91ae6ebe
Don't litter the queue directory when rejecting posts for one reason or the
mmj
parents:
245
diff
changeset
|
1029 writen(tmpfd, bounceaddr, strlen(bounceaddr)); |
171 | 1030 fsync(tmpfd); |
1031 } | |
1032 close(tmpfd); | |
106 | 1033 tmpstr = concatstr(2, mailfilename, ".reciptto"); |
509 | 1034 if(stat(tmpstr, &st) == 0) { |
1035 myfree(tmpstr); | |
1036 break; | |
1037 } | |
171 | 1038 tmpfd = open(tmpstr, O_WRONLY|O_CREAT|O_TRUNC, |
1039 S_IRUSR|S_IWUSR); | |
245 | 1040 myfree(tmpstr); |
171 | 1041 if(tmpfd >= 0) { |
262
846d91ae6ebe
Don't litter the queue directory when rejecting posts for one reason or the
mmj
parents:
245
diff
changeset
|
1042 writen(tmpfd, to_addr, strlen(to_addr)); |
171 | 1043 fsync(tmpfd); |
1044 } | |
1045 close(tmpfd); | |
103
bf4390ecc30b
Also dump MAIL FROM:, RCPT TO: and Reply To: variables in the case of an
mmj
parents:
102
diff
changeset
|
1046 if(replyto) { |
bf4390ecc30b
Also dump MAIL FROM:, RCPT TO: and Reply To: variables in the case of an
mmj
parents:
102
diff
changeset
|
1047 tmpstr = concatstr(2, mailfilename, |
106 | 1048 ".reply-to"); |
509 | 1049 if(stat(tmpstr, &st) == 0) { |
1050 myfree(tmpstr); | |
1051 break; | |
1052 } | |
171 | 1053 tmpfd = open(tmpstr, O_WRONLY|O_CREAT|O_TRUNC, |
1054 S_IRUSR|S_IWUSR); | |
245 | 1055 myfree(tmpstr); |
171 | 1056 if(tmpfd >= 0) { |
1057 writen(tmpfd, replyto, | |
1058 strlen(replyto)); | |
1059 fsync(tmpfd); | |
1060 } | |
1061 close(tmpfd); | |
103
bf4390ecc30b
Also dump MAIL FROM:, RCPT TO: and Reply To: variables in the case of an
mmj
parents:
102
diff
changeset
|
1062 } |
bf4390ecc30b
Also dump MAIL FROM:, RCPT TO: and Reply To: variables in the case of an
mmj
parents:
102
diff
changeset
|
1063 } |
69 | 1064 break; |
1065 case '2': /* Moderators */ | |
458 | 1066 initsmtp(&sockfd, relay, smtpport); |
426 | 1067 if(send_mail_many_fd(sockfd, bounceaddr, NULL, mailmap, |
520 | 1068 st.st_size, subfd, NULL, NULL, NULL, |
1069 listdir, NULL, hdrs, hdrslen, | |
1070 body, bodylen)) | |
154 | 1071 close(sockfd); |
1072 else | |
1073 endsmtp(&sockfd); | |
69 | 1074 break; |
147
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
1075 case '3': /* resending earlier failed mails */ |
458 | 1076 initsmtp(&sockfd, relay, smtpport); |
426 | 1077 if(send_mail_many_fd(sockfd, NULL, NULL, mailmap, st.st_size, |
520 | 1078 subfd, listaddr, listdelim, mailfilename, |
1079 listdir, mlmmjbounce, hdrs, hdrslen, | |
1080 body, bodylen)) | |
154 | 1081 close(sockfd); |
1082 else | |
1083 endsmtp(&sockfd); | |
147
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
1084 unlink(subfilename); |
e53fe7b9022b
mlmmj-maintd now resends the ones that failed. Add listctrl switch to
mmj
parents:
146
diff
changeset
|
1085 break; |
228
fda21d560980
Make it possible to specify several owner emailaddresses, not just one
mmj
parents:
225
diff
changeset
|
1086 case '4': /* send mails to owner */ |
458 | 1087 initsmtp(&sockfd, relay, smtpport); |
426 | 1088 if(send_mail_many_fd(sockfd, bounceaddr, NULL, mailmap, |
520 | 1089 st.st_size, subfd, listaddr, listdelim, |
1090 mailfilename, listdir, mlmmjbounce, | |
1091 hdrs, hdrslen, body, bodylen)) | |
228
fda21d560980
Make it possible to specify several owner emailaddresses, not just one
mmj
parents:
225
diff
changeset
|
1092 close(sockfd); |
fda21d560980
Make it possible to specify several owner emailaddresses, not just one
mmj
parents:
225
diff
changeset
|
1093 else |
fda21d560980
Make it possible to specify several owner emailaddresses, not just one
mmj
parents:
225
diff
changeset
|
1094 endsmtp(&sockfd); |
fda21d560980
Make it possible to specify several owner emailaddresses, not just one
mmj
parents:
225
diff
changeset
|
1095 break; |
264
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1096 case '5': /* bounceprobe - handle relayhost local users bouncing*/ |
458 | 1097 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
|
1098 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
|
1099 mailmap, st.st_size, listdir, NULL, |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
1100 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
|
1101 endsmtp(&sockfd); |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1102 if(sendres) { |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1103 /* 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
|
1104 tmpstr = mystrdup(to_addr); |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1105 a = strchr(tmpstr, '@'); |
674 | 1106 MY_ASSERT(a); |
264
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1107 *a = '='; |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1108 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
|
1109 "-probe"); |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1110 unlink(probefile); |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1111 myfree(probefile); |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1112 myfree(tmpstr); |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1113 } |
d3ade2c1f058
Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents:
262
diff
changeset
|
1114 break; |
338 | 1115 case '7': |
1116 digest = 1; | |
383
7de4e23f2e8e
Add a To: header with the recipient's address when sending digests
mortenp
parents:
370
diff
changeset
|
1117 addtohdr = 1; |
370 | 1118 archivefilename = "digest"; |
338 | 1119 /* fall through */ |
69 | 1120 default: /* normal list mail */ |
338 | 1121 if (!digest) { |
1122 subddirname = concatstr(2, listdir, "/subscribers.d/"); | |
1123 } else { | |
1124 subddirname = concatstr(2, listdir, "/digesters.d/"); | |
1125 } | |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1126 if((subddir = opendir(subddirname)) == NULL) { |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1127 log_error(LOG_ARGS, "Could not opendir(%s)", |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1128 subddirname); |
520 | 1129 myfree(listdelim); |
245 | 1130 myfree(subddirname); |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
1131 myfree(hdrs); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
1132 myfree(body); |
117
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
116
diff
changeset
|
1133 exit(EXIT_FAILURE); |
0 | 1134 } |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1135 |
520 | 1136 listdelim = getlistdelim(listdir); |
426 | 1137 listname = genlistname(listaddr); |
1138 listfqdn = genlistfqdn(listaddr); | |
520 | 1139 verpfrom = concatstr(6, listname, listdelim, "bounces-", |
1140 strindex, "@", listfqdn); | |
426 | 1141 myfree(listname); |
1142 myfree(listfqdn); | |
1143 | |
445 | 1144 if(digest) |
1145 verp = NULL; | |
1146 | |
426 | 1147 if(verp && (strcmp(verp, "postfix") == 0)) { |
1148 myfree(verp); | |
1149 verp = mystrdup("XVERP=-="); | |
1150 } | |
1151 | |
1152 if(addtohdr && verp) { | |
445 | 1153 log_error(LOG_ARGS, "Cannot use VERP and add " |
1154 "To: header. Not sending with " | |
1155 "VERP."); | |
426 | 1156 verp = NULL; |
1157 } | |
427
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1158 |
426 | 1159 if(verp) { |
458 | 1160 initsmtp(&sockfd, relay, smtpport); |
426 | 1161 if(write_mail_from(sockfd, verpfrom, verp)) { |
1162 log_error(LOG_ARGS, | |
1163 "Could not write MAIL FROM\n"); | |
1164 verp = NULL; | |
1165 } else { | |
1166 reply = checkwait_smtpreply(sockfd, MLMMJ_FROM); | |
1167 if(reply) { | |
1168 log_error(LOG_ARGS, | |
1169 "Mailserver did not " | |
1170 "accept verp mail from. " | |
1171 "Not sending with VERP."); | |
1172 myfree(reply); | |
1173 verp = NULL; | |
1174 } | |
1175 } | |
1176 endsmtp(&sockfd); | |
1177 } | |
1178 | |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1179 while((dp = readdir(subddir)) != NULL) { |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1180 if(!strcmp(dp->d_name, ".")) |
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 if(!strcmp(dp->d_name, "..")) |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1183 continue; |
338 | 1184 subfilename = concatstr(2, subddirname, dp->d_name); |
171 | 1185 if((subfd = open(subfilename, O_RDONLY)) < 0) { |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1186 log_error(LOG_ARGS, "Could not open '%s'", |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1187 subfilename); |
245 | 1188 myfree(subfilename); |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1189 continue; |
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1190 } |
426 | 1191 do { |
1192 res = getaddrsfromfd(&stl, subfd, | |
1193 maxverprecips); | |
727
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1194 if(omit != NULL && maxverprecips > 1) { |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1195 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
|
1196 if(strcmp(stl.strs[i], omit) |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1197 == 0) { |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1198 myfree(stl.strs[i]); |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1199 stl.count--; |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1200 while (i < stl.count) { |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1201 stl.strs[i] = |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1202 stl.strs[i+1]; |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1203 i++; |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1204 } |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1205 stl.strs[stl.count] = NULL; |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1206 break; |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1207 } |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1208 } |
4575d3181ca1
Added notmetoo feature where posts are not mirrored to their senders.
Ben Schmidt
parents:
677
diff
changeset
|
1209 } |
426 | 1210 if(stl.count == maxverprecips) { |
458 | 1211 initsmtp(&sockfd, relay, smtpport); |
426 | 1212 if(verp) { |
1213 sendres = send_mail_verp( | |
1214 sockfd, &stl, | |
1215 mailmap, | |
1216 st.st_size, | |
1217 verpfrom, | |
1218 listdir, hdrs, | |
1219 hdrslen, body, | |
1220 bodylen, verp); | |
1221 if(sendres) | |
1222 requeuemail(listdir, | |
1223 strindex, | |
1224 &stl, 0); | |
1225 } else { | |
1226 sendres = send_mail_many_list( | |
1227 sockfd, NULL, | |
1228 NULL, mailmap, | |
1229 st.st_size, | |
1230 &stl, | |
1231 listaddr, | |
520 | 1232 listdelim, |
426 | 1233 archivefilename, |
1234 listdir, | |
1235 mlmmjbounce, | |
1236 hdrs, hdrslen, | |
1237 body, bodylen); | |
1238 } | |
1239 endsmtp(&sockfd); | |
1240 for(i = 0; i < stl.count; i++) | |
1241 myfree(stl.strs[i]); | |
1242 stl.count = 0; | |
1243 } | |
1244 } while(res > 0); | |
1245 myfree(subfilename); | |
1246 close(subfd); | |
1247 | |
427
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1248 } |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1249 if(stl.count) { |
458 | 1250 initsmtp(&sockfd, relay, smtpport); |
427
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1251 if(verp) { |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1252 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
|
1253 st.st_size, verpfrom, listdir, |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1254 hdrs, hdrslen, body, bodylen, |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1255 verp); |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1256 if(sendres) |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1257 requeuemail(listdir, strindex, &stl, |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1258 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
|
1259 } else { |
427
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1260 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
|
1261 NULL, mailmap, st.st_size, |
520 | 1262 &stl, listaddr, listdelim, |
427
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1263 archivefilename, listdir, |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1264 mlmmjbounce, hdrs, hdrslen, |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1265 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
|
1266 } |
427
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1267 endsmtp(&sockfd); |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1268 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
|
1269 myfree(stl.strs[i]); |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1270 stl.count = 0; |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1271 } |
427
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1272 |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1273 if (sendres) { |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1274 /* 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
|
1275 * 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
|
1276 * 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
|
1277 * (DATA for instance). */ |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1278 close(sockfd); |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1279 } else { |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1280 endsmtp(&sockfd); |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1281 } |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1282 myfree(stl.strs); |
df8e1e2f0ff6
Don't send the rest of the batch inside the while() loop
mmj
parents:
426
diff
changeset
|
1283 myfree(verpfrom); |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1284 closedir(subddir); |
338 | 1285 myfree(subddirname); |
69 | 1286 break; |
1287 } | |
77
66d950e9a550
mlmmj-send now forks multiple connections per subscriber.d/file
mmj
parents:
72
diff
changeset
|
1288 |
432 | 1289 for(i = 0; i < stl.count; i++) |
1290 myfree(stl.strs[i]); | |
1291 stl.count = 0; | |
1292 | |
520 | 1293 myfree(listdelim); |
268
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
1294 myfree(hdrs); |
1dbadf407849
mlmmj-send now prepares headers and mail, and To: header feature added
mmj
parents:
267
diff
changeset
|
1295 myfree(body); |
370 | 1296 myfree(mlmmjbounce); |
1297 close(sockfd); | |
174
8a565328fa73
Instead of reading 1 line at a time in mlmmj-send everytime we send the
mmj
parents:
171
diff
changeset
|
1298 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
|
1299 close(mailfd); |
426 | 1300 myfree(verp); |
401
c60351e368bd
Grab the lock right after we start sending, and not release before
mmj
parents:
383
diff
changeset
|
1301 |
116 | 1302 if(archive) { |
411
79355dd5ecc2
Make the envelope from match the new order (VERP prep) and also remove
mmj
parents:
401
diff
changeset
|
1303 if(!ctrlarchive) { |
522 | 1304 if(rename(mailfilename, archivefilename) < 0) { |
1305 log_error(LOG_ARGS, | |
1306 "Could not rename(%s,%s);", | |
1307 mailfilename, | |
1308 archivefilename); | |
1309 } | |
411
79355dd5ecc2
Make the envelope from match the new order (VERP prep) and also remove
mmj
parents:
401
diff
changeset
|
1310 } else { |
601 | 1311 len = strlen(listdir) + 9 + 20 + 9; |
1312 requeuefilename = mymalloc(len); | |
772
179d5a0ed686
Better logging when moving requeue mailfiles into place
Ben Schmidt
parents:
756
diff
changeset
|
1313 snprintf(requeuefilename, len, "%s/requeue/%d", |
179d5a0ed686
Better logging when moving requeue mailfiles into place
Ben Schmidt
parents:
756
diff
changeset
|
1314 listdir, mindex); |
179d5a0ed686
Better logging when moving requeue mailfiles into place
Ben Schmidt
parents:
756
diff
changeset
|
1315 if(stat(requeuefilename, &st) < 0) { |
179d5a0ed686
Better logging when moving requeue mailfiles into place
Ben Schmidt
parents:
756
diff
changeset
|
1316 /* Nothing was requeued and we don't keep |
179d5a0ed686
Better logging when moving requeue mailfiles into place
Ben Schmidt
parents:
756
diff
changeset
|
1317 * mail for a noarchive list. */ |
601 | 1318 unlink(mailfilename); |
772
179d5a0ed686
Better logging when moving requeue mailfiles into place
Ben Schmidt
parents:
756
diff
changeset
|
1319 } else { |
179d5a0ed686
Better logging when moving requeue mailfiles into place
Ben Schmidt
parents:
756
diff
changeset
|
1320 snprintf(requeuefilename, len, |
179d5a0ed686
Better logging when moving requeue mailfiles into place
Ben Schmidt
parents:
756
diff
changeset
|
1321 "%s/requeue/%d/mailfile", |
179d5a0ed686
Better logging when moving requeue mailfiles into place
Ben Schmidt
parents:
756
diff
changeset
|
1322 listdir, mindex); |
179d5a0ed686
Better logging when moving requeue mailfiles into place
Ben Schmidt
parents:
756
diff
changeset
|
1323 if (rename(mailfilename, requeuefilename) < 0) { |
179d5a0ed686
Better logging when moving requeue mailfiles into place
Ben Schmidt
parents:
756
diff
changeset
|
1324 log_error(LOG_ARGS, |
179d5a0ed686
Better logging when moving requeue mailfiles into place
Ben Schmidt
parents:
756
diff
changeset
|
1325 "Could not rename(%s,%s);", |
179d5a0ed686
Better logging when moving requeue mailfiles into place
Ben Schmidt
parents:
756
diff
changeset
|
1326 mailfilename, |
179d5a0ed686
Better logging when moving requeue mailfiles into place
Ben Schmidt
parents:
756
diff
changeset
|
1327 requeuefilename); |
179d5a0ed686
Better logging when moving requeue mailfiles into place
Ben Schmidt
parents:
756
diff
changeset
|
1328 } |
179d5a0ed686
Better logging when moving requeue mailfiles into place
Ben Schmidt
parents:
756
diff
changeset
|
1329 } |
601 | 1330 myfree(requeuefilename); |
411
79355dd5ecc2
Make the envelope from match the new order (VERP prep) and also remove
mmj
parents:
401
diff
changeset
|
1331 } |
245 | 1332 myfree(archivefilename); |
0 | 1333 } else if(deletewhensent) |
1334 unlink(mailfilename); | |
1335 | |
1336 return EXIT_SUCCESS; | |
1337 } |