Mercurial > hg > mlmmj
annotate src/prepstdreply.c @ 778:af2d036b7d0c
Insignificant change: zero is a valid file descriptor
author | Ben Schmidt |
---|---|
date | Mon, 15 Nov 2010 09:31:15 +1100 |
parents | ecb991e41a4c |
children | 6f8df4842d91 |
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" |
754 | 35 #include "ctrlvalue.h" |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
36 #include "strgen.h" |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
37 #include "chomp.h" |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
38 #include "log_error.h" |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
39 #include "mygetline.h" |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
40 #include "wrappers.h" |
245 | 41 #include "memory.h" |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
42 #include "getlistaddr.h" |
518 | 43 #include "mlmmj.h" |
520 | 44 #include "getlistdelim.h" |
652 | 45 #include "unistr.h" |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
46 |
520 | 47 char *substitute(const char *line, const char *listaddr, const char *listdelim, |
754 | 48 size_t datacount, char **data, const char *listdir) |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
49 { |
365
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
50 char *s1, *s2; |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
51 |
754 | 52 s1 = substitute_one(line, listaddr, listdelim, datacount, data, |
53 listdir); | |
365
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
54 while(s1) { |
754 | 55 s2 = substitute_one(s1, listaddr, listdelim, datacount, data, |
56 listdir); | |
365
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
57 if(s2) { |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
58 myfree(s1); |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
59 s1 = s2; |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
60 } else |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
61 return s1; |
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 |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
64 return mystrdup(line); |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
65 } |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
66 |
520 | 67 char *substitute_one(const char *line, const char *listaddr, |
754 | 68 const char *listdelim, size_t datacount, char **data, |
69 const char *listdir) | |
365
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
70 { |
363
000cf869301c
Further fixups to new prepstdreply. Seems to work now, needs more testing though
mmj
parents:
362
diff
changeset
|
71 char *fqdn, *listname, *d1, *d2, *token, *value = NULL; |
365
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
72 char *retstr, *origline; |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
73 size_t len, i; |
365
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
74 |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
75 if(line == NULL) |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
76 return NULL; |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
77 |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
78 origline = mystrdup(line); |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
79 |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
80 d1 = strchr(origline, '$'); |
362 | 81 |
365
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
82 if(d1 == NULL) { |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
83 myfree(origline); |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
84 return NULL; |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
85 } else |
362 | 86 d2 = strchr(d1 + 1, '$'); |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
87 |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
88 if(d1 && d2) { |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
89 len = d2 - d1; |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
90 token = mymalloc(len + 1); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
91 snprintf(token, len, "%s", d1 + 1); |
365
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
92 } else { |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
93 myfree(origline); |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
94 return NULL; |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
95 } |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
96 |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
97 *d1 = '\0'; |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
98 |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
99 fqdn = genlistfqdn(listaddr); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
100 listname = genlistname(listaddr); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
101 |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
102 if(strcmp(token, "listaddr") == 0) { |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
103 value = mystrdup(listaddr); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
104 goto concatandreturn; |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
105 } else if(strcmp(token, "listowner") == 0) { |
520 | 106 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
|
107 goto concatandreturn; |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
108 } else if(strcmp(token, "helpaddr") == 0) { |
520 | 109 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
|
110 goto concatandreturn; |
610 | 111 } else if(strcmp(token, "faqaddr") == 0) { |
112 value = concatstr(4, listname, listdelim, "faq@", fqdn); | |
113 goto concatandreturn; | |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
114 } else if(strcmp(token, "listgetN") == 0) { |
520 | 115 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
|
116 goto concatandreturn; |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
117 } else if(strcmp(token, "listunsubaddr") == 0) { |
520 | 118 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
|
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, "digestunsubaddr") == 0) { |
520 | 121 value = concatstr(4, listname, listdelim, |
122 "unsubscribe-digest@", 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, "nomailunsubaddr") == 0) { |
520 | 125 value = concatstr(4, listname, listdelim, |
126 "unsubscribe-nomail@", fqdn); | |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
127 goto concatandreturn; |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
128 } else if(strcmp(token, "listsubaddr") == 0) { |
520 | 129 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
|
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, "digestsubaddr") == 0) { |
520 | 132 value = concatstr(4, listname, listdelim, "subscribe-digest@", |
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 } else if(strcmp(token, "nomailsubaddr") == 0) { |
520 | 136 value = concatstr(4, listname, listdelim, "subscribe-nomail@", |
137 fqdn); | |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
138 goto concatandreturn; |
754 | 139 } else if(strncmp(token, "control", 7) == 0) { |
140 value = token + 7; | |
141 if(*value == '\0') { | |
142 value = mystrdup(""); | |
143 goto concatandreturn; | |
144 } | |
145 for(; *value != '\0'; value++) { | |
146 if(*value >= '0' && *value <= '9') continue; | |
147 if(*value >= 'A' && *value <= 'Z') continue; | |
148 if(*value >= 'a' && *value <= 'z') continue; | |
149 break; | |
150 } | |
151 if(*value != '\0') { | |
152 value = mystrdup(token + 7); | |
153 goto concatandreturn; | |
154 } | |
155 value = token + 7; | |
156 value = ctrlcontent(listdir, value); | |
157 if (value == NULL) | |
158 value = mystrdup(""); | |
159 goto concatandreturn; | |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
160 } |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
161 if(data) { |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
162 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
|
163 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
|
164 value = mystrdup(data[(i*2)+1]); |
365
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
165 goto concatandreturn; |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
166 } |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
167 } |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
168 } |
365
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
169 |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
170 myfree(origline); |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
171 return NULL; |
24a86824b6b8
Substitute all of them and convert moderation to prepstdreply
mmj
parents:
364
diff
changeset
|
172 |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
173 concatandreturn: |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
174 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
|
175 myfree(origline); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
176 myfree(value); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
177 myfree(token); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
178 myfree(fqdn); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
179 myfree(listname); |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
180 |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
181 return retstr; |
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
182 } |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
183 |
652 | 184 |
185 int open_listtext(const char *listdir, const char *filename) | |
186 { | |
187 char *tmp; | |
188 int fd; | |
189 | |
190 tmp = concatstr(3, listdir, "/text/", filename); | |
191 fd = open(tmp, O_RDONLY); | |
192 myfree(tmp); | |
193 if (fd >= 0) | |
194 return fd; | |
195 | |
196 tmp = concatstr(2, DEFAULTTEXTDIR "/default/", filename); | |
197 fd = open(tmp, O_RDONLY); | |
198 myfree(tmp); | |
199 if (fd >= 0) | |
200 return fd; | |
201 | |
202 tmp = concatstr(2, DEFAULTTEXTDIR "/en/", filename); | |
203 fd = open(tmp, O_RDONLY); | |
204 myfree(tmp); | |
205 if (fd >= 0) | |
206 return fd; | |
207 | |
208 log_error(LOG_ARGS, "Could not open listtext '%s'", filename); | |
209 return -1; | |
210 } | |
211 | |
212 | |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
213 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
|
214 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
|
215 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
|
216 { |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
217 size_t i, len; |
742 | 218 int infd, outfd, mailfd; |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
219 char *listaddr, *listdelim, *tmp, *retstr = NULL; |
652 | 220 char *listfqdn, *line, *utfline, *utfsub, *utfsub2; |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
221 char *str = NULL; |
745 | 222 char **moredata; |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
223 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
|
224 |
652 | 225 if ((infd = open_listtext(listdir, filename)) < 0) { |
226 return NULL; | |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
227 } |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
228 |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
229 listaddr = getlistaddr(listdir); |
520 | 230 listdelim = getlistdelim(listdir); |
641
436eea81bc20
Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents:
610
diff
changeset
|
231 listfqdn = genlistfqdn(listaddr); |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
232 |
278 | 233 do { |
281 | 234 tmp = random_str(); |
745 | 235 if (retstr) |
236 myfree(retstr); | |
278 | 237 retstr = concatstr(3, listdir, "/queue/", tmp); |
238 myfree(tmp); | |
239 | |
281 | 240 outfd = open(retstr, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); |
278 | 241 |
242 } while ((outfd < 0) && (errno == EEXIST)); | |
243 | |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
244 if(outfd < 0) { |
281 | 245 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
|
246 myfree(listaddr); |
520 | 247 myfree(listdelim); |
641
436eea81bc20
Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents:
610
diff
changeset
|
248 myfree(listfqdn); |
745 | 249 myfree(retstr); |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
250 return NULL; |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
251 } |
359
ca217febcfbd
Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
281
diff
changeset
|
252 |
745 | 253 moredata = mymalloc(2*(tokencount+6) * sizeof(char *)); |
254 for (i=0; i<2*tokencount; i++) { | |
255 moredata[i] = data[i]; | |
256 } | |
754 | 257 for (i=0; i<6; i++) { |
745 | 258 moredata[2*(tokencount+i)] = mystrdup("randomN"); |
259 moredata[2*(tokencount+i)][6] = '0' + i; | |
260 moredata[2*(tokencount+i)+1] = random_str(); | |
261 } | |
262 tokencount += 6; | |
263 | |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
264 tmp = substitute(from, listaddr, listdelim, |
754 | 265 tokencount, moredata, listdir); |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
266 headers[0] = concatstr(2, "From: ", tmp); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
267 myfree(tmp); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
268 tmp = substitute(to, listaddr, listdelim, |
754 | 269 tokencount, moredata, listdir); |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
270 headers[1] = concatstr(2, "To: ", tmp); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
271 myfree(tmp); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
272 headers[2] = genmsgid(listfqdn); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
273 chomp(headers[2]); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
274 headers[3] = gendatestr(); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
275 chomp(headers[3]); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
276 headers[4] = mystrdup("Subject: mlmmj administrivia"); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
277 headers[5] = mystrdup("MIME-Version: 1.0"); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
278 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
|
279 headers[7] = mystrdup("Content-Transfer-Encoding: 8bit"); |
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 if(replyto) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
282 tmp = substitute(replyto, listaddr, listdelim, |
754 | 283 tokencount, moredata, listdir); |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
284 headers[8] = concatstr(2, "Reply-To: ", tmp); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
285 myfree(tmp); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
286 } |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
287 |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
288 for(;;) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
289 line = mygetline(infd); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
290 if (!line) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
291 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
|
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 if (*line == '\n') { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
296 /* end of headers */ |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
297 myfree(line); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
298 line = NULL; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
299 break; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
300 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
301 chomp(line); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
302 if (*line == ' ' || *line == '\t') { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
303 /* line beginning with linear whitespace is a |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
304 continuation of previous header line */ |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
305 utfsub = unistr_escaped_to_utf8(line); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
306 str = substitute(utfsub, listaddr, listdelim, |
754 | 307 tokencount, moredata, listdir); |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
308 myfree(utfsub); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
309 len = strlen(str); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
310 str[len] = '\n'; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
311 if(writen(outfd, str, len+1) < 0) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
312 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
|
313 myfree(str); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
314 myfree(line); |
745 | 315 myfree(retstr); |
316 retstr = NULL; | |
317 goto freeandreturn; | |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
318 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
319 myfree(str); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
320 } else { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
321 tmp = line; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
322 len = 0; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
323 while (*tmp && *tmp != ':') { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
324 tmp++; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
325 len++; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
326 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
327 if (!*tmp) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
328 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
|
329 "header in '%s' listtext", |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
330 filename); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
331 break; |
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 tmp++; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
334 len++; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
335 /* remove the standard header if one matches */ |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
336 for (i=0; headers[i] != NULL; i++) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
337 if (strncasecmp(line, headers[i], len) == 0) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
338 myfree(headers[i]); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
339 while (headers[i] != NULL) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
340 headers[i] = headers[i+1]; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
341 i++; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
342 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
343 break; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
344 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
345 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
346 utfsub = unistr_escaped_to_utf8(tmp); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
347 *tmp = '\0'; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
348 utfsub2 = substitute(utfsub, listaddr, listdelim, |
754 | 349 tokencount, moredata, listdir); |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
350 myfree(utfsub); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
351 if (strncasecmp(line, "Subject:", len) == 0) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
352 tmp = unistr_utf8_to_header(utfsub2); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
353 myfree(utfsub2); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
354 str = concatstr(2, line, tmp); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
355 myfree(tmp); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
356 } else { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
357 str = concatstr(2, line, utfsub2); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
358 myfree(utfsub2); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
359 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
360 len = strlen(str); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
361 str[len] = '\n'; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
362 if(writen(outfd, str, len+1) < 0) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
363 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
|
364 myfree(str); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
365 myfree(line); |
745 | 366 myfree(retstr); |
367 retstr = NULL; | |
368 goto freeandreturn; | |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
369 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
370 myfree(str); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
371 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
372 myfree(line); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
373 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
374 |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
375 for (i=0; headers[i] != NULL; i++) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
376 len = strlen(headers[i]); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
377 headers[i][len] = '\n'; |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
378 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
|
379 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
|
380 if (line) |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
381 myfree(line); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
382 myfree(str); |
745 | 383 myfree(retstr); |
384 retstr = NULL; | |
385 goto freeandreturn; | |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
386 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
387 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
388 |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
389 /* end the headers */ |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
390 if(writen(outfd, "\n", 1) < 0) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
391 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
|
392 myfree(str); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
393 if (line) |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
394 myfree(line); |
745 | 395 myfree(retstr); |
396 retstr = NULL; | |
397 goto freeandreturn; | |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
398 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
399 |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
400 if (line) { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
401 str = concatstr(2, line, "\n"); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
402 myfree(line); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
403 } else { |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
404 str = mygetline(infd); |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
405 } |
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
406 while(str) { |
652 | 407 utfline = unistr_escaped_to_utf8(str); |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
408 myfree(str); |
652 | 409 |
742 | 410 tmp = utfline; |
411 while (*tmp && (*tmp == ' ' || *tmp == '\t')) { | |
412 tmp++; | |
413 } | |
414 if (strncmp(tmp,"$originalmail",13) == 0) { | |
415 *tmp = '\0'; | |
416 tmp += 13; | |
417 str = tmp; | |
418 while (*tmp >= '0' && *tmp <= '9') | |
419 tmp++; | |
420 if (*tmp == '$') { | |
421 *tmp = '\0'; | |
422 len = 100; | |
423 if (str != tmp) | |
424 len = atol(str); | |
425 if (mailname && | |
778
af2d036b7d0c
Insignificant change: zero is a valid file descriptor
Ben Schmidt
parents:
754
diff
changeset
|
426 ((mailfd = open(mailname, O_RDONLY)) >= 0)){ |
742 | 427 str = NULL; |
428 i = 0; | |
429 while (i < len && | |
430 (str = mygetline(mailfd))) { | |
431 tmp = str; | |
432 str = concatstr(2,utfline,str); | |
433 myfree(tmp); | |
434 if(writen(outfd,str,strlen(str)) < 0) { | |
435 myfree(str); | |
436 myfree(utfline); | |
437 log_error(LOG_ARGS, "Could not write std mail"); | |
745 | 438 myfree(retstr); |
439 retstr = NULL; | |
440 goto freeandreturn; | |
742 | 441 } |
442 myfree(str); | |
443 i++; | |
444 } | |
445 close(mailfd); | |
446 } else { | |
447 log_error(LOG_ARGS, "Could not substitute $originalmail%d$ (mailname == %s)",len,mailname); | |
448 } | |
449 } else { | |
450 log_error(LOG_ARGS, "Bad $originalmailNNN$ substitution"); | |
451 } | |
452 myfree(utfline); | |
453 } else { | |
454 str = substitute(utfline, listaddr, listdelim, | |
754 | 455 tokencount, moredata, listdir); |
742 | 456 myfree(utfline); |
457 if(writen(outfd, str, strlen(str)) < 0) { | |
458 myfree(str); | |
459 log_error(LOG_ARGS, "Could not write std mail"); | |
745 | 460 myfree(retstr); |
461 retstr = NULL; | |
462 goto freeandreturn; | |
742 | 463 } |
278 | 464 myfree(str); |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
465 } |
742 | 466 |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
467 str = mygetline(infd); |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
468 } |
741
b72bcb7e08a2
Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents:
716
diff
changeset
|
469 |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
470 fsync(outfd); |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
471 close(outfd); |
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
472 |
745 | 473 freeandreturn: |
641
436eea81bc20
Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents:
610
diff
changeset
|
474 myfree(listaddr); |
436eea81bc20
Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents:
610
diff
changeset
|
475 myfree(listdelim); |
436eea81bc20
Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents:
610
diff
changeset
|
476 myfree(listfqdn); |
436eea81bc20
Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents:
610
diff
changeset
|
477 |
745 | 478 for (i=tokencount-6; i<tokencount; i++) { |
479 myfree(moredata[2*i]); | |
480 myfree(moredata[2*i+1]); | |
481 } | |
482 myfree(moredata); | |
483 | |
189
cb46caab2621
New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff
changeset
|
484 return retstr; |
245 | 485 } |