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

Cosmetic changes to help messages
author Ben Schmidt
date Fri, 08 Oct 2010 01:47:46 +1100
parents b72bcb7e08a2
children c3ee2bfaeb02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
1 /* Copyright (C) 2004 Morten K. Poulsen <morten at afdelingp.dk>
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
2 *
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
3 * $Id$
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
4 *
225
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
6 * of this software and associated documentation files (the "Software"), to
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
7 * deal in the Software without restriction, including without limitation the
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
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: 216
diff changeset
10 * furnished to do so, subject to the following conditions:
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
11 *
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
12 * The above copyright notice and this permission notice shall be included in
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
13 * all copies or substantial portions of the Software.
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
14 *
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
diff changeset
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 216
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: 216
diff changeset
21 * IN THE SOFTWARE.
47
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
22 */
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
23
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
24 #include <stdio.h>
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
25 #include <stdlib.h>
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
26 #include <unistd.h>
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
27 #include <errno.h>
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
28 #include <string.h>
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
29 #include <sys/types.h>
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
30 #include <sys/stat.h>
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
31 #include <fcntl.h>
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
32 #include <time.h>
108
51a1695e9d4b Handle sub/unsub confirm mail bounces, and use subscribers.d/ not
mmj
parents: 102
diff changeset
33 #include <dirent.h>
193
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
34 #include <sys/mman.h>
450
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
35 #include <string.h>
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
36 #include <ctype.h>
47
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
37
192
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
38 #include "getlistaddr.h"
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 486
diff changeset
39 #include "getlistdelim.h"
47
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
40 #include "mlmmj.h"
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
41 #include "strgen.h"
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
42 #include "wrappers.h"
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
43 #include "log_error.h"
49
afd7356e8f2e mlmmj-bounce now checks if it's a subscribed address
mmj
parents: 47
diff changeset
44 #include "subscriberfuncs.h"
186
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
45 #include "mygetline.h"
193
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
46 #include "chomp.h"
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
47 #include "prepstdreply.h"
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 240
diff changeset
48 #include "memory.h"
450
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
49 #include "find_email_adr.h"
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
50 #include "gethdrline.h"
186
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
51
192
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
52 char *fetchindexes(const char *bouncefile)
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
53 {
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
54 int fd;
193
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
55 char *indexstr = NULL, *s, *start, *line, *cur, *colon, *next;
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
56 size_t len;
192
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
57 struct stat st;
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
58
192
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
59 fd = open(bouncefile, O_RDONLY);
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
60 if(fd < 0) {
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
61 log_error(LOG_ARGS, "Could not open bounceindexfile %s",
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
62 bouncefile);
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
63 return NULL;
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
64 }
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
65
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
66 if(fstat(fd, &st) < 0) {
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
67 log_error(LOG_ARGS, "Could not open bounceindexfile %s",
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
68 bouncefile);
193
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
69 }
192
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
70
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
71 if(st.st_size == 0) {
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
72 log_error(LOG_ARGS, "Bounceindexfile %s is size 0",
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
73 bouncefile);
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
74 return NULL;
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
75 }
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
76
192
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
77 start = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
78 if(start == MAP_FAILED) {
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
79 log_error(LOG_ARGS, "Could not mmap bounceindexfile");
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
80 return NULL;
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
81 }
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
82
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
83
192
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
84 for(next = cur = start; next < start + st.st_size; next++) {
193
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
85 if(*next == '\n') {
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
86 len = next - cur;
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 240
diff changeset
87 line = mymalloc(len + 1);
193
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
88 strncpy(line, cur, len);
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
89 line[len] = '\0';
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
90 cur = next + 1;
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
91 } else
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
92 continue;
192
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
93
193
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
94 colon = strchr(line, ':');
674
a81c74ff2995 Added more sanity checks (Thomas Jarosch)
mortenp
parents: 672
diff changeset
95 MY_ASSERT(colon);
193
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
96 *colon = '\0';
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
97 s = indexstr;
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
98 indexstr = concatstr(4, s, " ", line, "\n");
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 240
diff changeset
99 myfree(s);
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 240
diff changeset
100 myfree(line);
193
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
101 }
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
102
193
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
103 munmap(start, st.st_size);
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
104 close(fd);
192
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
105
193
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
106 return indexstr;
192
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
107 }
812715644566 Sorry I broke CVS, I'll fix ASAP. It was a commit by mistake.
mmj
parents: 191
diff changeset
108
186
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
109 void do_probe(const char *listdir, const char *mlmmjsend, const char *addr)
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
110 {
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 344
diff changeset
111 char *myaddr, *from, *a, *indexstr, *queuefilename, *listaddr;
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 486
diff changeset
112 char *listfqdn, *listname, *probefile, *listdelim=getlistdelim(listdir);
363
000cf869301c Further fixups to new prepstdreply. Seems to work now, needs more testing though
mmj
parents: 359
diff changeset
113 char *maildata[] = { "bouncenumbers", NULL };
193
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
114 int fd;
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
115 time_t t;
186
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
116
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 240
diff changeset
117 myaddr = mystrdup(addr);
186
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
118
191
2692060ffafb Plug memory leak in mlmmj-send
mmj
parents: 186
diff changeset
119 listaddr = getlistaddr(listdir);
2692060ffafb Plug memory leak in mlmmj-send
mmj
parents: 186
diff changeset
120 listname = genlistname(listaddr);
2692060ffafb Plug memory leak in mlmmj-send
mmj
parents: 186
diff changeset
121 listfqdn = genlistfqdn(listaddr);
2692060ffafb Plug memory leak in mlmmj-send
mmj
parents: 186
diff changeset
122
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 486
diff changeset
123 from = concatstr(6, listname, listdelim, "bounces-probe-", myaddr, "@",
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 486
diff changeset
124 listfqdn);
186
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
125
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 344
diff changeset
126 myfree(listaddr);
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 486
diff changeset
127 myfree(listdelim);
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 344
diff changeset
128 myfree(listfqdn);
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 344
diff changeset
129 myfree(listname);
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 344
diff changeset
130
344
410780151412 the last = is the @
mmj
parents: 312
diff changeset
131 a = strrchr(myaddr, '=');
186
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
132 if (!a) {
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 240
diff changeset
133 myfree(myaddr);
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 240
diff changeset
134 myfree(from);
186
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
135 log_error(LOG_ARGS, "do_probe(): malformed address");
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
136 exit(EXIT_FAILURE);
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 344
diff changeset
137
186
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
138 }
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
139 *a = '@';
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
140
193
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
141 indexstr = fetchindexes(addr);
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
142 if(indexstr == NULL) {
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
143 log_error(LOG_ARGS, "Could not fetch bounceindexes");
186
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
144 exit(EXIT_FAILURE);
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
145 }
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
146
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 344
diff changeset
147 maildata[1] = indexstr;
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 344
diff changeset
148 queuefilename = prepstdreply(listdir, "bounce-probe", "$listowner$",
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 674
diff changeset
149 myaddr, NULL, 1, maildata, NULL);
193
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
150 MY_ASSERT(queuefilename);
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 240
diff changeset
151 myfree(indexstr);
186
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
152
193
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
153 probefile = concatstr(4, listdir, "/bounce/", addr, "-probe");
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
154 MY_ASSERT(probefile);
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
155 t = time(NULL);
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 240
diff changeset
156 a = mymalloc(32);
193
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
157 snprintf(a, 31, "%ld", (long int)t);
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
158 a[31] = '\0';
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
159 unlink(probefile);
200
f53c9c408347 mlmmj-maintd work
mmj
parents: 199
diff changeset
160 fd = open(probefile, O_WRONLY|O_TRUNC|O_CREAT, S_IRUSR|S_IWUSR);
193
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
161 if(fd < 0)
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
162 log_error(LOG_ARGS, "Could not open %s", probefile);
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
163 else
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
164 if(writen(fd, a, strlen(a)) < 0)
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
165 log_error(LOG_ARGS, "Could not write time in probe");
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
166
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 240
diff changeset
167 myfree(probefile);
186
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
168
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
169 execlp(mlmmjsend, mlmmjsend,
264
d3ade2c1f058 Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents: 250
diff changeset
170 "-l", "5",
d3ade2c1f058 Make mlmmj-send capable of handling bouncing bounce probes to a local user on
mmj
parents: 250
diff changeset
171 "-L", listdir,
186
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
172 "-T", myaddr,
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
173 "-F", from,
435
65781b43a7b9 - subswitch, NULL);
mmj
parents: 414
diff changeset
174 "-m", queuefilename, (char *)NULL);
186
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
175
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
176 log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend);
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
177
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
178 exit(EXIT_FAILURE);
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
179 }
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
180
450
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
181 char *dsnparseaddr(const char *mailname)
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
182 {
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
183 int fd, indsn = 0, i;
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
184 char *line, *linedup, *search, *addr = NULL;
453
94fbccee8faa Init struct before usage
mmj
parents: 450
diff changeset
185 struct email_container emails = { 0, NULL };
450
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
186
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
187 fd = open(mailname, O_RDONLY);
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
188 if(fd < 0) {
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
189 log_error(LOG_ARGS, "Could not open bounceindexfile %s",
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
190 mailname);
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
191 return NULL;
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
192 }
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
193
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
194 while((line = gethdrline(fd))) {
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
195 linedup = mystrdup(line);
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
196 for(i = 0; line[i]; i++)
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
197 linedup[i] = tolower(line[i]);
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
198 search = strstr(linedup, "message/delivery-status");
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
199 myfree(linedup);
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
200 if(search)
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
201 indsn = 1;
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
202 if(indsn) {
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
203 i = strncasecmp(line, "Final-Recipient:", 16);
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
204 if(i == 0) {
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
205 find_email_adr(line, &emails);
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
206 if(emails.emailcount > 0) {
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
207 addr = mystrdup(emails.emaillist[0]);
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
208 for(i = 0; i < emails.emailcount; i++)
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
209 myfree(emails.emaillist[i]);
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
210 myfree(emails.emaillist);
450
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
211 } else {
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
212 addr = NULL;
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
213 }
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
214 myfree(line);
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
215 return addr;
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
216 }
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
217 }
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
218 myfree(line);
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
219 }
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
220
450
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
221 return NULL;
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
222 }
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
223
47
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
224 static void print_help(const char *prg)
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
225 {
756
f8f3f4525a2b Cosmetic changes to help messages
Ben Schmidt
parents: 741
diff changeset
226 printf("Usage: %s -L /path/to/list\n"
f8f3f4525a2b Cosmetic changes to help messages
Ben Schmidt
parents: 741
diff changeset
227 " -a john=doe.org [-n num | -p]\n"
f8f3f4525a2b Cosmetic changes to help messages
Ben Schmidt
parents: 741
diff changeset
228 " -a: Address string that bounces\n"
f8f3f4525a2b Cosmetic changes to help messages
Ben Schmidt
parents: 741
diff changeset
229 " -h: This help\n"
f8f3f4525a2b Cosmetic changes to help messages
Ben Schmidt
parents: 741
diff changeset
230 " -L: Full path to list directory\n"
f8f3f4525a2b Cosmetic changes to help messages
Ben Schmidt
parents: 741
diff changeset
231 " -n: Message number in the archive\n"
f8f3f4525a2b Cosmetic changes to help messages
Ben Schmidt
parents: 741
diff changeset
232 " -p: Send out a probe\n"
f8f3f4525a2b Cosmetic changes to help messages
Ben Schmidt
parents: 741
diff changeset
233 " -V: Print version\n", prg);
102
713e9d076c26 Clean up and extend help everywhere.
mmj
parents: 60
diff changeset
234
47
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
235 exit(EXIT_SUCCESS);
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
236 }
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
237
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
238 int main(int argc, char **argv)
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
239 {
531
427cc8c9fff2 Fix nasty bug with "bla,bla" <bla@bla>
mmj
parents: 520
diff changeset
240 int opt, fd, dsnbounce = 0, i = 0;
47
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
241 char *listdir = NULL, *address = NULL, *number = NULL;
250
0af98d48bdd0 Lets make sure it compiles :)
mmj
parents: 249
diff changeset
242 char *bindir, *mlmmjsend, *savename;
531
427cc8c9fff2 Fix nasty bug with "bla,bla" <bla@bla>
mmj
parents: 520
diff changeset
243 char *mailname = NULL, *bfilename, *a, *buf, *lowcaseaddr;
47
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
244 size_t len;
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
245 time_t t;
186
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
246 int probe = 0;
158
cb0bc373e796 3 things:
mmj
parents: 108
diff changeset
247 struct stat st;
297
cb6672e89943 uid check
mmj
parents: 264
diff changeset
248 uid_t uid;
47
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
249
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
250 log_set_name(argv[0]);
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
251
208
688011dbc4b7 Add a macro to make sure mlmmj binaries are invoked with full path
mmj
parents: 205
diff changeset
252 CHECKFULLPATH(argv[0]);
688011dbc4b7 Add a macro to make sure mlmmj binaries are invoked with full path
mmj
parents: 205
diff changeset
253
186
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
254 bindir = mydirname(argv[0]);
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
255 mlmmjsend = concatstr(2, bindir, "/mlmmj-send");
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 240
diff changeset
256 myfree(bindir);
186
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
257
450
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
258 while ((opt = getopt(argc, argv, "hdVL:a:n:m:p")) != -1) {
47
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
259 switch(opt) {
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
260 case 'L':
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
261 listdir = optarg;
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
262 break;
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
263 case 'a':
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
264 address = optarg;
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
265 break;
450
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
266 case 'd':
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
267 dsnbounce = 1;
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
268 break;
158
cb0bc373e796 3 things:
mmj
parents: 108
diff changeset
269 case 'm':
cb0bc373e796 3 things:
mmj
parents: 108
diff changeset
270 mailname = optarg;
cb0bc373e796 3 things:
mmj
parents: 108
diff changeset
271 break;
47
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
272 case 'n':
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
273 number = optarg;
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
274 break;
186
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
275 case 'p':
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
276 probe = 1;
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
277 break;
47
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
278 case 'h':
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
279 print_help(argv[0]);
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
280 break;
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
281 case 'V':
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
282 print_version(argv[0]);
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
283 exit(0);
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
284 }
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
285 }
297
cb6672e89943 uid check
mmj
parents: 264
diff changeset
286
450
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
287 if(listdir == NULL || (address == NULL && dsnbounce == 0)
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
288 || (number == NULL && probe == 0)) {
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
289 fprintf(stderr,
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
290 "You have to specify -L, -a or -d and -n or -p\n");
186
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
291 fprintf(stderr, "%s -h for help\n", argv[0]);
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
292 exit(EXIT_FAILURE);
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
293 }
297
cb6672e89943 uid check
mmj
parents: 264
diff changeset
294
cb6672e89943 uid check
mmj
parents: 264
diff changeset
295 /* Lets make sure no random user tries to do bouncehandling */
cb6672e89943 uid check
mmj
parents: 264
diff changeset
296 if(listdir) {
cb6672e89943 uid check
mmj
parents: 264
diff changeset
297 if(stat(listdir, &st) == 0) {
cb6672e89943 uid check
mmj
parents: 264
diff changeset
298 uid = getuid();
cb6672e89943 uid check
mmj
parents: 264
diff changeset
299 if(uid && uid != st.st_uid) {
cb6672e89943 uid check
mmj
parents: 264
diff changeset
300 log_error(LOG_ARGS,
cb6672e89943 uid check
mmj
parents: 264
diff changeset
301 "Have to invoke either as root "
cb6672e89943 uid check
mmj
parents: 264
diff changeset
302 "or as the user owning listdir");
cb6672e89943 uid check
mmj
parents: 264
diff changeset
303 writen(STDERR_FILENO,
cb6672e89943 uid check
mmj
parents: 264
diff changeset
304 "Have to invoke either as root "
cb6672e89943 uid check
mmj
parents: 264
diff changeset
305 "or as the user owning listdir\n", 60);
cb6672e89943 uid check
mmj
parents: 264
diff changeset
306 exit(EXIT_FAILURE);
cb6672e89943 uid check
mmj
parents: 264
diff changeset
307 }
cb6672e89943 uid check
mmj
parents: 264
diff changeset
308 } else {
cb6672e89943 uid check
mmj
parents: 264
diff changeset
309 log_error(LOG_ARGS, "Could not stat %s", listdir);
cb6672e89943 uid check
mmj
parents: 264
diff changeset
310 exit(EXIT_FAILURE);
cb6672e89943 uid check
mmj
parents: 264
diff changeset
311 }
cb6672e89943 uid check
mmj
parents: 264
diff changeset
312 }
450
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
313
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
314 if(dsnbounce) {
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
315 address = dsnparseaddr(mailname);
481
3d3c60ef5667 Clean up after us when we have successfully parsed DSN mail
mmj
parents: 455
diff changeset
316
3d3c60ef5667 Clean up after us when we have successfully parsed DSN mail
mmj
parents: 455
diff changeset
317 /* Delete the mailfile, no need for it anymore */
3d3c60ef5667 Clean up after us when we have successfully parsed DSN mail
mmj
parents: 455
diff changeset
318 if(mailname)
3d3c60ef5667 Clean up after us when we have successfully parsed DSN mail
mmj
parents: 455
diff changeset
319 unlink(mailname);
3d3c60ef5667 Clean up after us when we have successfully parsed DSN mail
mmj
parents: 455
diff changeset
320
3d3c60ef5667 Clean up after us when we have successfully parsed DSN mail
mmj
parents: 455
diff changeset
321 if(address == NULL)
450
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
322 exit(EXIT_SUCCESS);
481
3d3c60ef5667 Clean up after us when we have successfully parsed DSN mail
mmj
parents: 455
diff changeset
323
455
9cafbe08e06e Last fix, DSN is confirmed to work
mmj
parents: 453
diff changeset
324 a = strrchr(address, '@');
674
a81c74ff2995 Added more sanity checks (Thomas Jarosch)
mortenp
parents: 672
diff changeset
325 MY_ASSERT(a);
455
9cafbe08e06e Last fix, DSN is confirmed to work
mmj
parents: 453
diff changeset
326 *a = '=';
450
b57be6e2a98d Make mlmmj-bounce able to extract addresses from DSN's as specified in RFC1891
mmj
parents: 436
diff changeset
327 }
531
427cc8c9fff2 Fix nasty bug with "bla,bla" <bla@bla>
mmj
parents: 520
diff changeset
328
427cc8c9fff2 Fix nasty bug with "bla,bla" <bla@bla>
mmj
parents: 520
diff changeset
329 /* Make the address lowercase */
427cc8c9fff2 Fix nasty bug with "bla,bla" <bla@bla>
mmj
parents: 520
diff changeset
330 lowcaseaddr = mystrdup(address);
427cc8c9fff2 Fix nasty bug with "bla,bla" <bla@bla>
mmj
parents: 520
diff changeset
331 i = 0;
427cc8c9fff2 Fix nasty bug with "bla,bla" <bla@bla>
mmj
parents: 520
diff changeset
332 while(lowcaseaddr[i]) {
427cc8c9fff2 Fix nasty bug with "bla,bla" <bla@bla>
mmj
parents: 520
diff changeset
333 lowcaseaddr[i] = tolower(lowcaseaddr[i]);
427cc8c9fff2 Fix nasty bug with "bla,bla" <bla@bla>
mmj
parents: 520
diff changeset
334 i++;
427cc8c9fff2 Fix nasty bug with "bla,bla" <bla@bla>
mmj
parents: 520
diff changeset
335 }
427cc8c9fff2 Fix nasty bug with "bla,bla" <bla@bla>
mmj
parents: 520
diff changeset
336 address = lowcaseaddr;
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
337
186
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
338 if(number != NULL && probe != 0) {
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
339 fprintf(stderr, "You can only specify one of -n or -p\n");
47
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
340 fprintf(stderr, "%s -h for help\n", argv[0]);
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
341 exit(EXIT_FAILURE);
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
342 }
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
343
186
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
344 if (probe) {
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
345 /* send out a probe */
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
346 do_probe(listdir, mlmmjsend, address);
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
347 /* do_probe() will never return */
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
348 exit(EXIT_FAILURE);
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
349 }
304a883f5f40 primitive implementation of probe (-p option)
mortenp
parents: 158
diff changeset
350
436
b5ffd052ab59 #if 0 for debug info
mmj
parents: 435
diff changeset
351 #if 0
414
8e19d05d7a72 Fixup mlmmj-bounce to get the parameters correctly and everything.
mmj
parents: 363
diff changeset
352 log_error(LOG_ARGS, "listdir = [%s] address = [%s] number = [%s]", listdir, address, number);
60
c67aeccaf498 if 0 ... #endif out debug messages
mmj
parents: 56
diff changeset
353 #endif
108
51a1695e9d4b Handle sub/unsub confirm mail bounces, and use subscribers.d/ not
mmj
parents: 102
diff changeset
354
51a1695e9d4b Handle sub/unsub confirm mail bounces, and use subscribers.d/ not
mmj
parents: 102
diff changeset
355 /* check if it's sub/unsub requests bouncing, and in that case
51a1695e9d4b Handle sub/unsub confirm mail bounces, and use subscribers.d/ not
mmj
parents: 102
diff changeset
356 * simply remove the confirmation file. Variablenames address and
51a1695e9d4b Handle sub/unsub confirm mail bounces, and use subscribers.d/ not
mmj
parents: 102
diff changeset
357 * number are a bit misleading in this case due to the different
51a1695e9d4b Handle sub/unsub confirm mail bounces, and use subscribers.d/ not
mmj
parents: 102
diff changeset
358 * construction of the sub/unsub confirmation From header.
51a1695e9d4b Handle sub/unsub confirm mail bounces, and use subscribers.d/ not
mmj
parents: 102
diff changeset
359 */
414
8e19d05d7a72 Fixup mlmmj-bounce to get the parameters correctly and everything.
mmj
parents: 363
diff changeset
360 if(strcmp(number, "confsub") == 0) {
8e19d05d7a72 Fixup mlmmj-bounce to get the parameters correctly and everything.
mmj
parents: 363
diff changeset
361 a = concatstr(3, listdir, "/subconf/", address);
108
51a1695e9d4b Handle sub/unsub confirm mail bounces, and use subscribers.d/ not
mmj
parents: 102
diff changeset
362 unlink(a);
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 240
diff changeset
363 myfree(a);
483
ec080ab4e9e7 Cleanup confirmation bounces
mmj
parents: 481
diff changeset
364 if(mailname)
ec080ab4e9e7 Cleanup confirmation bounces
mmj
parents: 481
diff changeset
365 unlink(mailname);
108
51a1695e9d4b Handle sub/unsub confirm mail bounces, and use subscribers.d/ not
mmj
parents: 102
diff changeset
366 exit(EXIT_SUCCESS);
51a1695e9d4b Handle sub/unsub confirm mail bounces, and use subscribers.d/ not
mmj
parents: 102
diff changeset
367 }
414
8e19d05d7a72 Fixup mlmmj-bounce to get the parameters correctly and everything.
mmj
parents: 363
diff changeset
368 if(strcmp(number, "confunsub") == 0) {
8e19d05d7a72 Fixup mlmmj-bounce to get the parameters correctly and everything.
mmj
parents: 363
diff changeset
369 a = concatstr(3, listdir, "/unsubconf/", address);
108
51a1695e9d4b Handle sub/unsub confirm mail bounces, and use subscribers.d/ not
mmj
parents: 102
diff changeset
370 unlink(a);
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 240
diff changeset
371 myfree(a);
483
ec080ab4e9e7 Cleanup confirmation bounces
mmj
parents: 481
diff changeset
372 if(mailname)
ec080ab4e9e7 Cleanup confirmation bounces
mmj
parents: 481
diff changeset
373 unlink(mailname);
108
51a1695e9d4b Handle sub/unsub confirm mail bounces, and use subscribers.d/ not
mmj
parents: 102
diff changeset
374 exit(EXIT_SUCCESS);
51a1695e9d4b Handle sub/unsub confirm mail bounces, and use subscribers.d/ not
mmj
parents: 102
diff changeset
375 }
199
c3cb740c537b Handle bouncing bounce probes
mmj
parents: 193
diff changeset
376 /* Below checks for bounce probes bouncing. If they do, simply remove
414
8e19d05d7a72 Fixup mlmmj-bounce to get the parameters correctly and everything.
mmj
parents: 363
diff changeset
377 * the probe file and exit successfully. Yes, I know the variables
8e19d05d7a72 Fixup mlmmj-bounce to get the parameters correctly and everything.
mmj
parents: 363
diff changeset
378 * have horrible names, but please bear with me.
199
c3cb740c537b Handle bouncing bounce probes
mmj
parents: 193
diff changeset
379 */
414
8e19d05d7a72 Fixup mlmmj-bounce to get the parameters correctly and everything.
mmj
parents: 363
diff changeset
380 if(strcmp(number, "probe") == 0) {
199
c3cb740c537b Handle bouncing bounce probes
mmj
parents: 193
diff changeset
381 a = concatstr(4, listdir, "/bounce/", address, "-probe");
c3cb740c537b Handle bouncing bounce probes
mmj
parents: 193
diff changeset
382 unlink(a);
205
d4d6e5301970 Fix some directory leaks which could cause corruption, and dont leak the
mmj
parents: 200
diff changeset
383 unlink(mailname);
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 240
diff changeset
384 myfree(a);
199
c3cb740c537b Handle bouncing bounce probes
mmj
parents: 193
diff changeset
385 exit(EXIT_SUCCESS);
c3cb740c537b Handle bouncing bounce probes
mmj
parents: 193
diff changeset
386 }
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
387
55
bf3ca0ce00ff fixed subscription check (convert '=' to '@' before check)
mortenp
parents: 49
diff changeset
388 /* save the filename with '=' before replacing it with '@' */
bf3ca0ce00ff fixed subscription check (convert '=' to '@' before check)
mortenp
parents: 49
diff changeset
389 bfilename = concatstr(3, listdir, "/bounce/", address);
bf3ca0ce00ff fixed subscription check (convert '=' to '@' before check)
mortenp
parents: 49
diff changeset
390
344
410780151412 the last = is the @
mmj
parents: 312
diff changeset
391 a = strrchr(address, '=');
486
89a256e8f1d3 read() wrapper, and yet another littering hole plunged
mmj
parents: 483
diff changeset
392 if (!a) {
89a256e8f1d3 read() wrapper, and yet another littering hole plunged
mmj
parents: 483
diff changeset
393 if(mailname)
89a256e8f1d3 read() wrapper, and yet another littering hole plunged
mmj
parents: 483
diff changeset
394 unlink(mailname);
108
51a1695e9d4b Handle sub/unsub confirm mail bounces, and use subscribers.d/ not
mmj
parents: 102
diff changeset
395 exit(EXIT_SUCCESS); /* ignore malformed address */
486
89a256e8f1d3 read() wrapper, and yet another littering hole plunged
mmj
parents: 483
diff changeset
396 }
55
bf3ca0ce00ff fixed subscription check (convert '=' to '@' before check)
mortenp
parents: 49
diff changeset
397 *a = '@';
bf3ca0ce00ff fixed subscription check (convert '=' to '@' before check)
mortenp
parents: 49
diff changeset
398
bf3ca0ce00ff fixed subscription check (convert '=' to '@' before check)
mortenp
parents: 49
diff changeset
399 /* make sure it's a subscribed address */
108
51a1695e9d4b Handle sub/unsub confirm mail bounces, and use subscribers.d/ not
mmj
parents: 102
diff changeset
400 if(is_subbed(listdir, address)) {
486
89a256e8f1d3 read() wrapper, and yet another littering hole plunged
mmj
parents: 483
diff changeset
401 log_error(LOG_ARGS, "%s is bouncing but not subscribed?",
89a256e8f1d3 read() wrapper, and yet another littering hole plunged
mmj
parents: 483
diff changeset
402 address);
89a256e8f1d3 read() wrapper, and yet another littering hole plunged
mmj
parents: 483
diff changeset
403 if(mailname)
89a256e8f1d3 read() wrapper, and yet another littering hole plunged
mmj
parents: 483
diff changeset
404 unlink(mailname);
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 240
diff changeset
405 myfree(bfilename);
49
afd7356e8f2e mlmmj-bounce now checks if it's a subscribed address
mmj
parents: 47
diff changeset
406 exit(EXIT_SUCCESS); /* Not subbed, so exit silently */
56
43d088987482 Be nice and free some memory before exit
mmj
parents: 55
diff changeset
407 }
43d088987482 Be nice and free some memory before exit
mmj
parents: 55
diff changeset
408
158
cb0bc373e796 3 things:
mmj
parents: 108
diff changeset
409 if(lstat(bfilename, &st) == 0) {
cb0bc373e796 3 things:
mmj
parents: 108
diff changeset
410 if((st.st_mode & S_IFLNK) == S_IFLNK) {
cb0bc373e796 3 things:
mmj
parents: 108
diff changeset
411 log_error(LOG_ARGS, "%s is a symbolic link",
cb0bc373e796 3 things:
mmj
parents: 108
diff changeset
412 bfilename);
cb0bc373e796 3 things:
mmj
parents: 108
diff changeset
413 exit(EXIT_FAILURE);
cb0bc373e796 3 things:
mmj
parents: 108
diff changeset
414 }
cb0bc373e796 3 things:
mmj
parents: 108
diff changeset
415 }
cb0bc373e796 3 things:
mmj
parents: 108
diff changeset
416
55
bf3ca0ce00ff fixed subscription check (convert '=' to '@' before check)
mortenp
parents: 49
diff changeset
417 if ((fd = open(bfilename, O_WRONLY|O_APPEND|O_CREAT,
47
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
418 S_IRUSR|S_IWUSR)) < 0) {
55
bf3ca0ce00ff fixed subscription check (convert '=' to '@' before check)
mortenp
parents: 49
diff changeset
419 log_error(LOG_ARGS, "Could not open '%s'", bfilename);
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 240
diff changeset
420 myfree(bfilename);
47
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
421 exit(EXIT_FAILURE);
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
422 }
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
423
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
424 /* TODO check that the message is not already bounced */
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
425
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
426 /* XXX How long can the string representation of an integer be?
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
427 * It is not a security issue (we use snprintf()), but it would be
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
428 * bad mojo to cut the timestamp field -- mortenp 20040427 */
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
429
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
430 /* int + ":" + int + " # Wed Jun 30 21:49:08 1993\n" + NUL */
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
431 len = 20 + 1 + 20 + 28 + 1;
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
432
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 240
diff changeset
433 buf = mymalloc(len);
47
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
434 if (!buf) exit(EXIT_FAILURE);
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
435
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
436 t = time(NULL);
193
a1be08626b36 Bounce probes done. Review appreciated.
mmj
parents: 192
diff changeset
437 snprintf(buf, len-26, "%s:%ld # ", number, (long int)t);
47
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
438 ctime_r(&t, buf+strlen(buf));
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
439 writen(fd, buf, strlen(buf));
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
440 close(fd);
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
441
249
01de740a19f9 Also remove .lastmsg files in mlmmj-maintd
mmj
parents: 245
diff changeset
442 if(mailname) {
01de740a19f9 Also remove .lastmsg files in mlmmj-maintd
mmj
parents: 245
diff changeset
443 savename = concatstr(2, bfilename, ".lastmsg");
01de740a19f9 Also remove .lastmsg files in mlmmj-maintd
mmj
parents: 245
diff changeset
444 rename(mailname, savename);
250
0af98d48bdd0 Lets make sure it compiles :)
mmj
parents: 249
diff changeset
445 myfree(savename);
249
01de740a19f9 Also remove .lastmsg files in mlmmj-maintd
mmj
parents: 245
diff changeset
446 }
672
dfc3ec149b60 Remove trailing whitespaces and not mmap 0 sized bounce index file
mmj
parents: 660
diff changeset
447
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 240
diff changeset
448 myfree(bfilename);
453
94fbccee8faa Init struct before usage
mmj
parents: 450
diff changeset
449 if(dsnbounce && address)
94fbccee8faa Init struct before usage
mmj
parents: 450
diff changeset
450 myfree(address);
158
cb0bc373e796 3 things:
mmj
parents: 108
diff changeset
451
cb0bc373e796 3 things:
mmj
parents: 108
diff changeset
452 return EXIT_SUCCESS;
47
c4af2c82c631 added primitive bounce handling
mortenp
parents:
diff changeset
453 }