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