annotate src/mlmmj-send.c @ 777:5f038f36f66f

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