Mercurial > hg > mlmmj
annotate src/prepstdreply.c @ 742:b00eb39643c1
Changes to how $originalmail$ works
- No longer buffer the whole mail in memory, but copy a line at a time
- Allow a line-count
- Change to the indent/whitespace behaviour; to essentially get current
behaviour, a space must be prepended to the lines currently containing
$originalmail$ in the listtexts
The interface to substitute() and substitute_one() has changed. They no longer
take the original mail filename, and cannot be used to do $originalmail$
substitution. This was never used except by prepstdreply() which now
incorporates that substitution itself.
author | Ben Schmidt |
---|---|
date | Mon, 20 Sep 2010 02:05:31 +1000 |
parents | b72bcb7e08a2 |
children | 5edfa9eef6c7 |
rev | line source |
---|---|
190 | 1 /* Copyright (C) 2004 Mads Martin Joergensen <mmj at mmj.dk> |
652 | 2 * Copyright (C) 2007 Morten K. Poulsen <morten at afdelingp.dk> |
190 | 3 * |
4 * $Id$ | |
5 * | |
225 | 6 * Permission is hereby granted, free of charge, to any person obtaining a copy |
7 * of this software and associated documentation files (the "Software"), to | |
8 * deal in the Software without restriction, including without limitation the | |
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |
10 * sell copies of the Software, and to permit persons to whom the Software is | |
11 * furnished to do so, subject to the following conditions: | |
12 * | |
13 * The above copyright notice and this permission notice shall be included in | |
14 * all copies or substantial portions of the Software. | |
15 * | |
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
22 * IN THE SOFTWARE. | |
190 | 23 */ |
24 | |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
25 #include <stdlib.h> |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
26 #include <stdio.h> |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
27 #include <unistd.h> |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
28 #include <sys/types.h> |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
29 #include <sys/stat.h> |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
30 #include <fcntl.h> |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
31 #include <string.h> |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
32 #include <errno.h> |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
33 |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
34 #include "prepstdreply.h" |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
35 #include "strgen.h" |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
36 #include "chomp.h" |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
37 #include "log_error.h" |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
38 #include "mygetline.h" |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
39 #include "wrappers.h" |
245 | 40 #include "memory.h" |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
41 #include "getlistaddr.h" |
518 | 42 #include "mlmmj.h" |
520 | 43 #include "getlistdelim.h" |
652 | 44 #include "unistr.h" |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
45 |
520 | 46 char *substitute(const char *line, const char *listaddr, const char *listdelim, |
742 | 47 size_t datacount, char **data) |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
48 { |
365
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
49 char *s1, *s2; |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
50 |
742 | 51 s1 = substitute_one(line, listaddr, listdelim, datacount, data); |
365
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
52 while(s1) { |
742 | 53 s2 = substitute_one(s1, listaddr, listdelim, datacount, data); |
365
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
54 if(s2) { |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
55 myfree(s1); |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
56 s1 = s2; |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
57 } else |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
58 return s1; |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
59 } |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
60 |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
61 return mystrdup(line); |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
62 } |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
63 |
520 | 64 char *substitute_one(const char *line, const char *listaddr, |
742 | 65 const char *listdelim, size_t datacount, char **data) |
365
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
66 { |
363
000cf869301c
Further fixups to new prepstdreply. Seems to work now, needs more testing though
mmj
parents:
362
diff
changeset
|
67 char *fqdn, *listname, *d1, *d2, *token, *value = NULL; |
365
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
68 char *retstr, *origline; |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
69 size_t len, i; |
365
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
70 |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
71 if(line == NULL) |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
72 return NULL; |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
73 |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
74 origline = mystrdup(line); |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
75 |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
76 d1 = strchr(origline, '$'); |
362 | 77 |
365
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
78 if(d1 == NULL) { |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
79 myfree(origline); |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
80 return NULL; |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
81 } else |
362 | 82 d2 = strchr(d1 + 1, '$'); |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
83 |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
84 if(d1 && d2) { |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
85 len = d2 - d1; |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
86 token = mymalloc(len + 1); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
87 snprintf(token, len, "%s", d1 + 1); |
365
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
88 } else { |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
89 myfree(origline); |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
90 return NULL; |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
91 } |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
92 |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
93 *d1 = '\0'; |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
94 |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
95 fqdn = genlistfqdn(listaddr); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
96 listname = genlistname(listaddr); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
97 |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
98 if(strcmp(token, "listaddr") == 0) { |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
99 value = mystrdup(listaddr); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
100 goto concatandreturn; |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
101 } else if(strcmp(token, "listowner") == 0) { |
520 | 102 value = concatstr(4, listname, listdelim, "owner@", fqdn); |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
103 goto concatandreturn; |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
104 } else if(strcmp(token, "helpaddr") == 0) { |
520 | 105 value = concatstr(4, listname, listdelim, "help@", fqdn); |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
106 goto concatandreturn; |
610 | 107 } else if(strcmp(token, "faqaddr") == 0) { |
108 value = concatstr(4, listname, listdelim, "faq@", fqdn); | |
109 goto concatandreturn; | |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
110 } else if(strcmp(token, "listgetN") == 0) { |
520 | 111 value = concatstr(4, listname, listdelim, "get-N@", fqdn); |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
112 goto concatandreturn; |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
113 } else if(strcmp(token, "listunsubaddr") == 0) { |
520 | 114 value = concatstr(4, listname, listdelim, "unsubscribe@", fqdn); |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
115 goto concatandreturn; |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
116 } else if(strcmp(token, "digestunsubaddr") == 0) { |
520 | 117 value = concatstr(4, listname, listdelim, |
118 "unsubscribe-digest@", fqdn); | |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
119 goto concatandreturn; |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
120 } else if(strcmp(token, "nomailunsubaddr") == 0) { |
520 | 121 value = concatstr(4, listname, listdelim, |
122 "unsubscribe-nomail@", fqdn); | |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
123 goto concatandreturn; |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
124 } else if(strcmp(token, "listsubaddr") == 0) { |
520 | 125 value = concatstr(4, listname, listdelim, "subscribe@", fqdn); |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
126 goto concatandreturn; |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
127 } else if(strcmp(token, "digestsubaddr") == 0) { |
520 | 128 value = concatstr(4, listname, listdelim, "subscribe-digest@", |
129 fqdn); | |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
130 goto concatandreturn; |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
131 } else if(strcmp(token, "nomailsubaddr") == 0) { |
520 | 132 value = concatstr(4, listname, listdelim, "subscribe-nomail@", |
133 fqdn); | |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
134 goto concatandreturn; |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
135 } |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
136 if(data) { |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
137 for(i = 0; i < datacount; i++) { |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
138 if(strcmp(token, data[i*2]) == 0) { |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
139 value = mystrdup(data[(i*2)+1]); |
365
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
140 goto concatandreturn; |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
141 } |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
142 } |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
143 } |
365
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
144 |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
145 myfree(origline); |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
146 return NULL; |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
147 |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
148 concatandreturn: |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
149 retstr = concatstr(3, origline, value, d2 + 1); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
150 myfree(origline); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
151 myfree(value); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
152 myfree(token); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
153 myfree(fqdn); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
154 myfree(listname); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
155 |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
156 return retstr; |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
157 } |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
158 |
652 | 159 |
160 int open_listtext(const char *listdir, const char *filename) | |
161 { | |
162 char *tmp; | |
163 int fd; | |
164 | |
165 tmp = concatstr(3, listdir, "/text/", filename); | |
166 fd = open(tmp, O_RDONLY); | |
167 myfree(tmp); | |
168 if (fd >= 0) | |
169 return fd; | |
170 | |
171 tmp = concatstr(2, DEFAULTTEXTDIR "/default/", filename); | |
172 fd = open(tmp, O_RDONLY); | |
173 myfree(tmp); | |
174 if (fd >= 0) | |
175 return fd; | |
176 | |
177 tmp = concatstr(2, DEFAULTTEXTDIR "/en/", filename); | |
178 fd = open(tmp, O_RDONLY); | |
179 myfree(tmp); | |
180 if (fd >= 0) | |
181 return fd; | |
182 | |
183 log_error(LOG_ARGS, "Could not open listtext '%s'", filename); | |
184 return -1; | |
185 } | |
186 | |
187 | |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
188 char *prepstdreply(const char *listdir, const char *filename, const char *from, |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
189 const char *to, const char *replyto, size_t tokencount, |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
190 char **data, const char *mailname) |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
191 { |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
192 size_t i, len; |
742 | 193 int infd, outfd, mailfd; |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
194 char *listaddr, *listdelim, *tmp, *retstr = NULL; |
652 | 195 char *listfqdn, *line, *utfline, *utfsub, *utfsub2; |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
196 char *str = NULL; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
197 char *headers[10] = { NULL }; /* relies on NULL to flag end */ |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
198 |
652 | 199 if ((infd = open_listtext(listdir, filename)) < 0) { |
200 return NULL; | |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
201 } |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
202 |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
203 listaddr = getlistaddr(listdir); |
520 | 204 listdelim = getlistdelim(listdir); |
641
436eea81bc20
Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents:
610
diff
changeset
|
205 listfqdn = genlistfqdn(listaddr); |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
206 |
278 | 207 do { |
281 | 208 tmp = random_str(); |
278 | 209 myfree(retstr); |
210 retstr = concatstr(3, listdir, "/queue/", tmp); | |
211 myfree(tmp); | |
212 | |
281 | 213 outfd = open(retstr, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); |
278 | 214 |
215 } while ((outfd < 0) && (errno == EEXIST)); | |
216 | |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
217 if(outfd < 0) { |
281 | 218 log_error(LOG_ARGS, "Could not open std mail %s", retstr); |
641
436eea81bc20
Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents:
610
diff
changeset
|
219 myfree(listaddr); |
520 | 220 myfree(listdelim); |
641
436eea81bc20
Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents:
610
diff
changeset
|
221 myfree(listfqdn); |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
222 return NULL; |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
223 } |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
224 |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
225 tmp = substitute(from, listaddr, listdelim, |
742 | 226 tokencount, data); |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
227 headers[0] = concatstr(2, "From: ", tmp); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
228 myfree(tmp); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
229 tmp = substitute(to, listaddr, listdelim, |
742 | 230 tokencount, data); |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
231 headers[1] = concatstr(2, "To: ", tmp); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
232 myfree(tmp); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
233 headers[2] = genmsgid(listfqdn); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
234 chomp(headers[2]); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
235 headers[3] = gendatestr(); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
236 chomp(headers[3]); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
237 headers[4] = mystrdup("Subject: mlmmj administrivia"); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
238 headers[5] = mystrdup("MIME-Version: 1.0"); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
239 headers[6] = mystrdup("Content-Type: text/plain; charset=utf-8"); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
240 headers[7] = mystrdup("Content-Transfer-Encoding: 8bit"); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
241 |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
242 if(replyto) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
243 tmp = substitute(replyto, listaddr, listdelim, |
742 | 244 tokencount, data); |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
245 headers[8] = concatstr(2, "Reply-To: ", tmp); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
246 myfree(tmp); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
247 } |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
248 |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
249 for(;;) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
250 line = mygetline(infd); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
251 if (!line) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
252 log_error(LOG_ARGS, "No body in '%s' listtext", |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
253 filename); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
254 break; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
255 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
256 if (*line == '\n') { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
257 /* end of headers */ |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
258 myfree(line); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
259 line = NULL; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
260 break; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
261 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
262 chomp(line); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
263 if (*line == ' ' || *line == '\t') { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
264 /* line beginning with linear whitespace is a |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
265 continuation of previous header line */ |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
266 utfsub = unistr_escaped_to_utf8(line); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
267 str = substitute(utfsub, listaddr, listdelim, |
742 | 268 tokencount, data); |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
269 myfree(utfsub); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
270 len = strlen(str); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
271 str[len] = '\n'; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
272 if(writen(outfd, str, len+1) < 0) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
273 log_error(LOG_ARGS, "Could not write std mail"); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
274 myfree(str); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
275 myfree(line); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
276 myfree(listaddr); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
277 myfree(listdelim); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
278 myfree(listfqdn); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
279 return NULL; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
280 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
281 myfree(str); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
282 } else { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
283 tmp = line; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
284 len = 0; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
285 while (*tmp && *tmp != ':') { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
286 tmp++; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
287 len++; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
288 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
289 if (!*tmp) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
290 log_error(LOG_ARGS, "No headers or invalid " |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
291 "header in '%s' listtext", |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
292 filename); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
293 break; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
294 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
295 tmp++; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
296 len++; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
297 /* remove the standard header if one matches */ |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
298 for (i=0; headers[i] != NULL; i++) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
299 if (strncasecmp(line, headers[i], len) == 0) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
300 myfree(headers[i]); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
301 while (headers[i] != NULL) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
302 headers[i] = headers[i+1]; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
303 i++; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
304 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
305 break; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
306 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
307 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
308 utfsub = unistr_escaped_to_utf8(tmp); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
309 *tmp = '\0'; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
310 utfsub2 = substitute(utfsub, listaddr, listdelim, |
742 | 311 tokencount, data); |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
312 myfree(utfsub); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
313 if (strncasecmp(line, "Subject:", len) == 0) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
314 tmp = unistr_utf8_to_header(utfsub2); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
315 myfree(utfsub2); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
316 str = concatstr(2, line, tmp); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
317 myfree(tmp); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
318 } else { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
319 str = concatstr(2, line, utfsub2); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
320 myfree(utfsub2); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
321 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
322 len = strlen(str); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
323 str[len] = '\n'; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
324 if(writen(outfd, str, len+1) < 0) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
325 log_error(LOG_ARGS, "Could not write std mail"); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
326 myfree(str); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
327 myfree(line); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
328 myfree(listaddr); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
329 myfree(listdelim); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
330 myfree(listfqdn); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
331 return NULL; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
332 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
333 myfree(str); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
334 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
335 myfree(line); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
336 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
337 |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
338 for (i=0; headers[i] != NULL; i++) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
339 len = strlen(headers[i]); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
340 headers[i][len] = '\n'; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
341 if(writen(outfd, headers[i], len+1) < 0) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
342 log_error(LOG_ARGS, "Could not write std mail"); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
343 if (line) |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
344 myfree(line); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
345 myfree(str); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
346 myfree(listaddr); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
347 myfree(listdelim); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
348 myfree(listfqdn); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
349 return NULL; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
350 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
351 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
352 |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
353 /* end the headers */ |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
354 if(writen(outfd, "\n", 1) < 0) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
355 log_error(LOG_ARGS, "Could not write std mail"); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
356 myfree(str); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
357 if (line) |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
358 myfree(line); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
359 myfree(listaddr); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
360 myfree(listdelim); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
361 myfree(listfqdn); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
362 return NULL; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
363 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
364 |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
365 if (line) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
366 str = concatstr(2, line, "\n"); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
367 myfree(line); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
368 } else { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
369 str = mygetline(infd); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
370 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
371 while(str) { |
652 | 372 utfline = unistr_escaped_to_utf8(str); |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
373 myfree(str); |
652 | 374 |
742 | 375 tmp = utfline; |
376 while (*tmp && (*tmp == ' ' || *tmp == '\t')) { | |
377 tmp++; | |
378 } | |
379 if (strncmp(tmp,"$originalmail",13) == 0) { | |
380 *tmp = '\0'; | |
381 tmp += 13; | |
382 str = tmp; | |
383 while (*tmp >= '0' && *tmp <= '9') | |
384 tmp++; | |
385 if (*tmp == '$') { | |
386 *tmp = '\0'; | |
387 len = 100; | |
388 if (str != tmp) | |
389 len = atol(str); | |
390 if (mailname && | |
391 ((mailfd = open(mailname, O_RDONLY)) > 0)){ | |
392 str = NULL; | |
393 i = 0; | |
394 while (i < len && | |
395 (str = mygetline(mailfd))) { | |
396 tmp = str; | |
397 str = concatstr(2,utfline,str); | |
398 myfree(tmp); | |
399 if(writen(outfd,str,strlen(str)) < 0) { | |
400 myfree(str); | |
401 myfree(utfline); | |
402 myfree(listaddr); | |
403 myfree(listdelim); | |
404 myfree(listfqdn); | |
405 log_error(LOG_ARGS, "Could not write std mail"); | |
406 return NULL; | |
407 } | |
408 myfree(str); | |
409 i++; | |
410 } | |
411 close(mailfd); | |
412 } else { | |
413 log_error(LOG_ARGS, "Could not substitute $originalmail%d$ (mailname == %s)",len,mailname); | |
414 } | |
415 } else { | |
416 log_error(LOG_ARGS, "Bad $originalmailNNN$ substitution"); | |
417 } | |
418 myfree(utfline); | |
419 } else { | |
420 str = substitute(utfline, listaddr, listdelim, | |
421 tokencount, data); | |
422 myfree(utfline); | |
423 if(writen(outfd, str, strlen(str)) < 0) { | |
424 myfree(str); | |
425 myfree(listaddr); | |
426 myfree(listdelim); | |
427 myfree(listfqdn); | |
428 log_error(LOG_ARGS, "Could not write std mail"); | |
429 return NULL; | |
430 } | |
278 | 431 myfree(str); |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
432 } |
742 | 433 |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
434 str = mygetline(infd); |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
435 } |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
436 |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
437 fsync(outfd); |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
438 close(outfd); |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
439 |
641
436eea81bc20
Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents:
610
diff
changeset
|
440 myfree(listaddr); |
436eea81bc20
Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents:
610
diff
changeset
|
441 myfree(listdelim); |
436eea81bc20
Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents:
610
diff
changeset
|
442 myfree(listfqdn); |
436eea81bc20
Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents:
610
diff
changeset
|
443 |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
444 return retstr; |
245 | 445 } |