annotate src/send_list.c @ 741:b72bcb7e08a2

Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header, and document \uNNNN substitution Also, the interface to prepstdreply() has changed; there is no longer a customheaders argument, which was never used anyway, and is now essentially redundant due to this patch.
author Ben Schmidt
date Mon, 20 Sep 2010 01:44:58 +1000
parents d7d67d5fa263
children c3ee2bfaeb02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
475
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
1 /* Copyright (C) 2005 Mads Martin Joergensen <mmj at mmj.dk>
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
2 *
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
3 * $Id$
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
4 *
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
6 * of this software and associated documentation files (the "Software"), to
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
7 * deal in the Software without restriction, including without limitation the
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
9 * sell copies of the Software, and to permit persons to whom the Software is
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
10 * furnished to do so, subject to the following conditions:
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
11 *
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
12 * The above copyright notice and this permission notice shall be included in
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
13 * all copies or substantial portions of the Software.
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
14 *
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
21 * IN THE SOFTWARE.
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
22 */
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
23
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
24 #include <stdio.h>
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
25 #include <stdlib.h>
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
26 #include <string.h>
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
27 #include <unistd.h>
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
28 #include <fcntl.h>
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
29 #include <sys/types.h>
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
30 #include <sys/stat.h>
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
31 #include <dirent.h>
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
32
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
33 #include "mlmmj.h"
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
34 #include "send_list.h"
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
35 #include "strgen.h"
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
36 #include "getlistaddr.h"
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 479
diff changeset
37 #include "getlistdelim.h"
475
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
38 #include "log_error.h"
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
39 #include "chomp.h"
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
40 #include "wrappers.h"
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
41 #include "mygetline.h"
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
42 #include "prepstdreply.h"
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
43 #include "memory.h"
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
44
701
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
45
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
46
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
47 static void print_subs(int cur_fd, char *dirname)
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
48 {
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
49 char *fileiter;
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
50 DIR *dirp;
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
51 struct dirent *dp;
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
52 int subfd;
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
53
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
54 dirp = opendir(dirname);
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
55 if(dirp == NULL) {
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
56 fprintf(stderr, "Could not opendir(%s);\n", dirname);
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
57 exit(EXIT_FAILURE);
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
58 }
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
59 while((dp = readdir(dirp)) != NULL) {
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
60 if((strcmp(dp->d_name, "..") == 0) ||
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
61 (strcmp(dp->d_name, ".") == 0))
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
62 continue;
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
63
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
64 fileiter = concatstr(2, dirname, dp->d_name);
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
65 subfd = open(fileiter, O_RDONLY);
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
66 if(subfd < 0) {
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
67 log_error(LOG_ARGS, "Could not open %s for reading",
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
68 fileiter);
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
69 myfree(fileiter);
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
70 continue;
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
71 }
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
72 if(dumpfd2fd(subfd, cur_fd) < 0) {
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
73 log_error(LOG_ARGS, "Error dumping subfile content"
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
74 " of %s to sub list mail",
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
75 fileiter);
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
76 }
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
77
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
78 close(subfd);
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
79 myfree(fileiter);
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
80 }
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
81 closedir(dirp);
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
82 }
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
83
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
84
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
85
475
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
86 void send_list(const char *listdir, const char *emailaddr,
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
87 const char *mlmmjsend)
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
88 {
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 479
diff changeset
89 char *queuefilename, *listaddr, *listdelim, *listname, *listfqdn;
701
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
90 char *fromaddr, *subdir, *nomaildir, *digestdir;
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
91 int fd;
475
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
92
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
93 listaddr = getlistaddr(listdir);
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 479
diff changeset
94 listdelim = getlistdelim(listdir);
475
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
95 listname = genlistname(listaddr);
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
96 listfqdn = genlistfqdn(listaddr);
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
97
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 479
diff changeset
98 fromaddr = concatstr(4, listname, listdelim, "bounces-help@", listfqdn);
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 479
diff changeset
99 myfree(listdelim);
475
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
100
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
101 queuefilename = prepstdreply(listdir, "listsubs", "$listowner$",
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 701
diff changeset
102 emailaddr, NULL, 0, NULL, NULL);
475
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
103 if(queuefilename == NULL) {
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
104 log_error(LOG_ARGS, "Could not prepare sub list mail");
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
105 exit(EXIT_FAILURE);
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
106 }
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
107
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
108 fd = open(queuefilename, O_WRONLY);
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
109 if(fd < 0) {
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
110 log_error(LOG_ARGS, "Could not open sub list mail");
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
111 exit(EXIT_FAILURE);
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
112 }
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
113
478
2a86af037236 Add a couple of missing newlines
mmj
parents: 475
diff changeset
114 if(lseek(fd, 0, SEEK_END) < 0) {
2a86af037236 Add a couple of missing newlines
mmj
parents: 475
diff changeset
115 log_error(LOG_ARGS, "Could not seek to send of file");
2a86af037236 Add a couple of missing newlines
mmj
parents: 475
diff changeset
116 exit(EXIT_FAILURE);
2a86af037236 Add a couple of missing newlines
mmj
parents: 475
diff changeset
117 }
2a86af037236 Add a couple of missing newlines
mmj
parents: 475
diff changeset
118
701
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
119 subdir = concatstr(2, listdir, "/subscribers.d/");
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
120 nomaildir = concatstr(2, listdir, "/nomailsubs.d/");
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
121 digestdir = concatstr(2, listdir, "/digesters.d/");
475
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
122
701
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
123 print_subs(fd, subdir);
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
124 writen(fd, "\n-- \n", 5);
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
125 print_subs(fd, nomaildir);
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
126 writen(fd, "\n-- \n", 5);
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
127 print_subs(fd, digestdir);
479
6ce0bff8ee30 README update
mmj
parents: 478
diff changeset
128 writen(fd, "\n-- \nend of output\n", 19);
478
2a86af037236 Add a couple of missing newlines
mmj
parents: 475
diff changeset
129
475
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
130 close(fd);
701
d7d67d5fa263 Added support for digest and nomail to +list (Christoph Wilke)
mortenp
parents: 660
diff changeset
131
475
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
132 myfree(listaddr);
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
133 myfree(listname);
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
134 myfree(listfqdn);
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
135
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
136 execlp(mlmmjsend, mlmmjsend,
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
137 "-l", "1",
529
d65b467b647d Pass on listdir to mlmmjsend so we can get the smtpport and relayhost also
mmj
parents: 520
diff changeset
138 "-L", listdir,
475
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
139 "-T", emailaddr,
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
140 "-F", fromaddr,
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
141 "-m", queuefilename, (char *)NULL);
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
142
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
143 log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend);
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
144 exit(EXIT_FAILURE);
d4c53b538aa7 listname+list, 1.2.5 and a FAQ entry -- not tested yet, but
mmj
parents:
diff changeset
145 }