annotate src/prepstdreply.c @ 741:b72bcb7e08a2

Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header, and document \uNNNN substitution Also, the interface to prepstdreply() has changed; there is no longer a customheaders argument, which was never used anyway, and is now essentially redundant due to this patch.
author Ben Schmidt
date Mon, 20 Sep 2010 01:44:58 +1000
parents 4a8acfd3f95f
children b00eb39643c1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
190
c37f95babe75 Add GPL header
mmj
parents: 189
diff changeset
1 /* Copyright (C) 2004 Mads Martin Joergensen <mmj at mmj.dk>
652
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
2 * Copyright (C) 2007 Morten K. Poulsen <morten at afdelingp.dk>
190
c37f95babe75 Add GPL header
mmj
parents: 189
diff changeset
3 *
c37f95babe75 Add GPL header
mmj
parents: 189
diff changeset
4 * $Id$
c37f95babe75 Add GPL header
mmj
parents: 189
diff changeset
5 *
225
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 190
diff changeset
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 190
diff changeset
7 * of this software and associated documentation files (the "Software"), to
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 190
diff changeset
8 * deal in the Software without restriction, including without limitation the
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 190
diff changeset
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 190
diff changeset
10 * sell copies of the Software, and to permit persons to whom the Software is
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 190
diff changeset
11 * furnished to do so, subject to the following conditions:
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 190
diff changeset
12 *
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 190
diff changeset
13 * The above copyright notice and this permission notice shall be included in
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 190
diff changeset
14 * all copies or substantial portions of the Software.
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 190
diff changeset
15 *
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 190
diff changeset
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 190
diff changeset
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 190
diff changeset
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 190
diff changeset
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 190
diff changeset
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 190
diff changeset
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
3f177909efc8 Goodbye GPL license, Welcome MIT
mmj
parents: 190
diff changeset
22 * IN THE SOFTWARE.
190
c37f95babe75 Add GPL header
mmj
parents: 189
diff changeset
23 */
c37f95babe75 Add GPL header
mmj
parents: 189
diff changeset
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
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
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
f745db86c61c free() -> myfree()
mmj
parents: 422
diff changeset
42 #include "mlmmj.h"
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 518
diff changeset
43 #include "getlistdelim.h"
652
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
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
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 518
diff changeset
46 char *substitute(const char *line, const char *listaddr, const char *listdelim,
660
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
47 size_t datacount, char **data, const char *mailname)
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
660
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
51 s1 = substitute_one(line, listaddr, listdelim, datacount, data, mailname);
365
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 364
diff changeset
52 while(s1) {
660
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
53 s2 = substitute_one(s1, listaddr, listdelim, datacount, data, mailname);
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
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 518
diff changeset
64 char *substitute_one(const char *line, const char *listaddr,
660
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
65 const char *listdelim, size_t datacount, char **data,
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
66 const char* mailname)
365
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 364
diff changeset
67 {
363
000cf869301c Further fixups to new prepstdreply. Seems to work now, needs more testing though
mmj
parents: 362
diff changeset
68 char *fqdn, *listname, *d1, *d2, *token, *value = NULL;
365
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 364
diff changeset
69 char *retstr, *origline;
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
70 size_t len, i;
365
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 364
diff changeset
71
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 364
diff changeset
72 if(line == NULL)
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 364
diff changeset
73 return NULL;
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 origline = mystrdup(line);
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 364
diff changeset
76
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
77 d1 = strchr(origline, '$');
362
4c1afa9908ab *GRRR* FFS
mmj
parents: 361
diff changeset
78
365
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 364
diff changeset
79 if(d1 == NULL) {
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 364
diff changeset
80 myfree(origline);
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 364
diff changeset
81 return NULL;
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 364
diff changeset
82 } else
362
4c1afa9908ab *GRRR* FFS
mmj
parents: 361
diff changeset
83 d2 = strchr(d1 + 1, '$');
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
84
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
85 if(d1 && d2) {
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
86 len = d2 - d1;
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
87 token = mymalloc(len + 1);
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
88 snprintf(token, len, "%s", d1 + 1);
365
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 364
diff changeset
89 } else {
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 364
diff changeset
90 myfree(origline);
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 364
diff changeset
91 return NULL;
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 364
diff changeset
92 }
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
93
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
94 *d1 = '\0';
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
95
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
96 fqdn = genlistfqdn(listaddr);
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
97 listname = genlistname(listaddr);
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 if(strcmp(token, "listaddr") == 0) {
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
100 value = mystrdup(listaddr);
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
101 goto concatandreturn;
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
102 } else if(strcmp(token, "listowner") == 0) {
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 518
diff changeset
103 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
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, "helpaddr") == 0) {
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 518
diff changeset
106 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
107 goto concatandreturn;
610
af32f7ed5d3d Added list FAQ feature (Henne Vogelsang)
mortenp
parents: 607
diff changeset
108 } else if(strcmp(token, "faqaddr") == 0) {
af32f7ed5d3d Added list FAQ feature (Henne Vogelsang)
mortenp
parents: 607
diff changeset
109 value = concatstr(4, listname, listdelim, "faq@", fqdn);
af32f7ed5d3d Added list FAQ feature (Henne Vogelsang)
mortenp
parents: 607
diff changeset
110 goto concatandreturn;
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
111 } else if(strcmp(token, "listgetN") == 0) {
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 518
diff changeset
112 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
113 goto concatandreturn;
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
114 } else if(strcmp(token, "listunsubaddr") == 0) {
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 518
diff changeset
115 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
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, "digestunsubaddr") == 0) {
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 518
diff changeset
118 value = concatstr(4, listname, listdelim,
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 518
diff changeset
119 "unsubscribe-digest@", fqdn);
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
120 goto concatandreturn;
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
121 } else if(strcmp(token, "nomailunsubaddr") == 0) {
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 518
diff changeset
122 value = concatstr(4, listname, listdelim,
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 518
diff changeset
123 "unsubscribe-nomail@", fqdn);
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
124 goto concatandreturn;
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
125 } else if(strcmp(token, "listsubaddr") == 0) {
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 518
diff changeset
126 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
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, "digestsubaddr") == 0) {
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 518
diff changeset
129 value = concatstr(4, listname, listdelim, "subscribe-digest@",
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 518
diff changeset
130 fqdn);
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
131 goto concatandreturn;
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
132 } else if(strcmp(token, "nomailsubaddr") == 0) {
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 518
diff changeset
133 value = concatstr(4, listname, listdelim, "subscribe-nomail@",
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 518
diff changeset
134 fqdn);
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
135 goto concatandreturn;
660
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
136 } else if(strcmp(token, "originalmail") == 0) {
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
137 /* append the first 100 lines of the mail inline */
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
138 int mailfd;
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
139 if(mailname &&
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
140 ((mailfd = open(mailname, O_RDONLY)) > 0)){
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
141 size_t count = 0;
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
142 char* str = NULL;
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
143 while(count < 100 && (str = mygetline(mailfd))) {
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
144 char* tmp = value;
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
145 value = concatstr(3, value, " ", str);
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
146 if(tmp)
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
147 myfree(tmp);
716
4a8acfd3f95f Fixed memory leak in substitute_one() (Ben Schmidt)
mortenp
parents: 660
diff changeset
148 myfree(str);
660
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
149 count++;
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
150 }
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
151 close(mailfd);
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
152 }else{
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
153 log_error(LOG_ARGS, "Could not substitute $originalmail$ (mailname == %s)",mailname);
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
154 }
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
155 goto concatandreturn;
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
156 }
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
157 if(data) {
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
158 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
159 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
160 value = mystrdup(data[(i*2)+1]);
365
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 364
diff changeset
161 goto concatandreturn;
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
162 }
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
163 }
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
164 }
365
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 364
diff changeset
165
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 364
diff changeset
166 myfree(origline);
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 364
diff changeset
167 return NULL;
24a86824b6b8 Substitute all of them and convert moderation to prepstdreply
mmj
parents: 364
diff changeset
168
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
169 concatandreturn:
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
170 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
171 myfree(origline);
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
172 myfree(value);
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
173 myfree(token);
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
174 myfree(fqdn);
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
175 myfree(listname);
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
176
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
177 return retstr;
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
178 }
189
cb46caab2621 New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff changeset
179
652
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
180
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
181 int open_listtext(const char *listdir, const char *filename)
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
182 {
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
183 char *tmp;
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
184 int fd;
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
185
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
186 tmp = concatstr(3, listdir, "/text/", filename);
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
187 fd = open(tmp, O_RDONLY);
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
188 myfree(tmp);
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
189 if (fd >= 0)
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
190 return fd;
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
191
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
192 tmp = concatstr(2, DEFAULTTEXTDIR "/default/", filename);
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
193 fd = open(tmp, O_RDONLY);
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
194 myfree(tmp);
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
195 if (fd >= 0)
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
196 return fd;
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
197
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
198 tmp = concatstr(2, DEFAULTTEXTDIR "/en/", filename);
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
199 fd = open(tmp, O_RDONLY);
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
200 myfree(tmp);
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
201 if (fd >= 0)
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
202 return fd;
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
203
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
204 log_error(LOG_ARGS, "Could not open listtext '%s'", filename);
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
205 return -1;
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
206 }
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
207
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
208
189
cb46caab2621 New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff changeset
209 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
210 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
211 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
212 {
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
213 size_t i, len;
189
cb46caab2621 New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff changeset
214 int infd, outfd;
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
215 char *listaddr, *listdelim, *tmp, *retstr = NULL;
652
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
216 char *listfqdn, *line, *utfline, *utfsub, *utfsub2;
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
217 char *str = NULL;
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
218 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
219
652
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
220 if ((infd = open_listtext(listdir, filename)) < 0) {
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
221 return NULL;
189
cb46caab2621 New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff changeset
222 }
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 listaddr = getlistaddr(listdir);
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 518
diff changeset
225 listdelim = getlistdelim(listdir);
641
436eea81bc20 Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents: 610
diff changeset
226 listfqdn = genlistfqdn(listaddr);
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
227
278
45501498e5a8 Another EEXIST check and some myfree's added
mmj
parents: 264
diff changeset
228 do {
281
97634188c50c standard replies did not work before
mmj
parents: 278
diff changeset
229 tmp = random_str();
278
45501498e5a8 Another EEXIST check and some myfree's added
mmj
parents: 264
diff changeset
230 myfree(retstr);
45501498e5a8 Another EEXIST check and some myfree's added
mmj
parents: 264
diff changeset
231 retstr = concatstr(3, listdir, "/queue/", tmp);
45501498e5a8 Another EEXIST check and some myfree's added
mmj
parents: 264
diff changeset
232 myfree(tmp);
45501498e5a8 Another EEXIST check and some myfree's added
mmj
parents: 264
diff changeset
233
281
97634188c50c standard replies did not work before
mmj
parents: 278
diff changeset
234 outfd = open(retstr, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
278
45501498e5a8 Another EEXIST check and some myfree's added
mmj
parents: 264
diff changeset
235
45501498e5a8 Another EEXIST check and some myfree's added
mmj
parents: 264
diff changeset
236 } while ((outfd < 0) && (errno == EEXIST));
45501498e5a8 Another EEXIST check and some myfree's added
mmj
parents: 264
diff changeset
237
189
cb46caab2621 New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff changeset
238 if(outfd < 0) {
281
97634188c50c standard replies did not work before
mmj
parents: 278
diff changeset
239 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
240 myfree(listaddr);
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 518
diff changeset
241 myfree(listdelim);
641
436eea81bc20 Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents: 610
diff changeset
242 myfree(listfqdn);
189
cb46caab2621 New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff changeset
243 return NULL;
cb46caab2621 New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff changeset
244 }
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents: 281
diff changeset
245
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
246 tmp = substitute(from, listaddr, listdelim,
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
247 tokencount, data, NULL);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
248 headers[0] = concatstr(2, "From: ", tmp);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
249 myfree(tmp);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
250 tmp = substitute(to, listaddr, listdelim,
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
251 tokencount, data, NULL);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
252 headers[1] = concatstr(2, "To: ", tmp);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
253 myfree(tmp);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
254 headers[2] = genmsgid(listfqdn);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
255 chomp(headers[2]);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
256 headers[3] = gendatestr();
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
257 chomp(headers[3]);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
258 headers[4] = mystrdup("Subject: mlmmj administrivia");
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
259 headers[5] = mystrdup("MIME-Version: 1.0");
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
260 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
261 headers[7] = mystrdup("Content-Transfer-Encoding: 8bit");
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
262
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
263 if(replyto) {
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
264 tmp = substitute(replyto, listaddr, listdelim,
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
265 tokencount, data, NULL);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
266 headers[8] = concatstr(2, "Reply-To: ", 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 }
189
cb46caab2621 New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff changeset
269
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
270 for(;;) {
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
271 line = mygetline(infd);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
272 if (!line) {
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
273 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
274 filename);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
275 break;
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
276 }
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
277 if (*line == '\n') {
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
278 /* end of headers */
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
279 myfree(line);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
280 line = NULL;
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
281 break;
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
282 }
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
283 chomp(line);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
284 if (*line == ' ' || *line == '\t') {
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
285 /* line beginning with linear whitespace is a
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
286 continuation of previous header line */
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
287 utfsub = unistr_escaped_to_utf8(line);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
288 str = substitute(utfsub, listaddr, listdelim,
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
289 tokencount, data, NULL);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
290 myfree(utfsub);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
291 len = strlen(str);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
292 str[len] = '\n';
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
293 if(writen(outfd, str, len+1) < 0) {
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
294 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
295 myfree(str);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
296 myfree(line);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
297 myfree(listaddr);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
298 myfree(listdelim);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
299 myfree(listfqdn);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
300 return NULL;
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
301 }
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
302 myfree(str);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
303 } else {
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
304 tmp = line;
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
305 len = 0;
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
306 while (*tmp && *tmp != ':') {
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
307 tmp++;
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
308 len++;
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
309 }
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
310 if (!*tmp) {
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
311 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
312 "header in '%s' listtext",
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
313 filename);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
314 break;
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
315 }
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
316 tmp++;
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
317 len++;
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
318 /* remove the standard header if one matches */
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
319 for (i=0; headers[i] != NULL; i++) {
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
320 if (strncasecmp(line, headers[i], len) == 0) {
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
321 myfree(headers[i]);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
322 while (headers[i] != NULL) {
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
323 headers[i] = headers[i+1];
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
324 i++;
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
325 }
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
326 break;
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
327 }
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
328 }
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
329 utfsub = unistr_escaped_to_utf8(tmp);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
330 *tmp = '\0';
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
331 utfsub2 = substitute(utfsub, listaddr, listdelim,
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
332 tokencount, data, NULL);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
333 myfree(utfsub);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
334 if (strncasecmp(line, "Subject:", len) == 0) {
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
335 tmp = unistr_utf8_to_header(utfsub2);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
336 myfree(utfsub2);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
337 str = concatstr(2, line, tmp);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
338 myfree(tmp);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
339 } else {
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
340 str = concatstr(2, line, utfsub2);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
341 myfree(utfsub2);
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 len = strlen(str);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
344 str[len] = '\n';
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
345 if(writen(outfd, str, len+1) < 0) {
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
346 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
347 myfree(str);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
348 myfree(line);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
349 myfree(listaddr);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
350 myfree(listdelim);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
351 myfree(listfqdn);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
352 return NULL;
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
353 }
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
354 myfree(str);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
355 }
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
356 myfree(line);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
357 }
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
358
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
359 for (i=0; headers[i] != NULL; i++) {
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
360 len = strlen(headers[i]);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
361 headers[i][len] = '\n';
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
362 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
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 if (line)
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
365 myfree(line);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
366 myfree(str);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
367 myfree(listaddr);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
368 myfree(listdelim);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
369 myfree(listfqdn);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
370 return NULL;
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 }
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 /* end the headers */
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
375 if(writen(outfd, "\n", 1) < 0) {
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
376 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
377 myfree(str);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
378 if (line)
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
379 myfree(line);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
380 myfree(listaddr);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
381 myfree(listdelim);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
382 myfree(listfqdn);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
383 return NULL;
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
384 }
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
385
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
386 if (line) {
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
387 str = concatstr(2, line, "\n");
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
388 myfree(line);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
389 } else {
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
390 str = mygetline(infd);
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
391 }
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
392 while(str) {
652
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
393 utfline = unistr_escaped_to_utf8(str);
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
394 myfree(str);
652
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
395
660
c26e97a2207b Added support for the 'originalmail' keyword (Sascha Sommer)
mortenp
parents: 654
diff changeset
396 str = substitute(utfline, listaddr, listdelim, tokencount, data, mailname);
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
397 myfree(utfline);
652
00a1c5697fa6 Added unicode support to listtexts
mortenp
parents: 646
diff changeset
398
189
cb46caab2621 New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff changeset
399 if(writen(outfd, str, strlen(str)) < 0) {
278
45501498e5a8 Another EEXIST check and some myfree's added
mmj
parents: 264
diff changeset
400 myfree(str);
641
436eea81bc20 Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents: 610
diff changeset
401 myfree(listaddr);
520
734ce7aa42bb 1.2.9-RC1 with recipdelim patch
mmj
parents: 518
diff changeset
402 myfree(listdelim);
641
436eea81bc20 Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents: 610
diff changeset
403 myfree(listfqdn);
189
cb46caab2621 New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff changeset
404 log_error(LOG_ARGS, "Could not write std mail");
cb46caab2621 New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff changeset
405 return NULL;
cb46caab2621 New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff changeset
406 }
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
407 myfree(str);
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
408 str = mygetline(infd);
189
cb46caab2621 New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff changeset
409 }
741
b72bcb7e08a2 Arbitrary headers in listtexts, fix default Content-Transfer-Encoding: header,
Ben Schmidt
parents: 716
diff changeset
410
189
cb46caab2621 New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff changeset
411 fsync(outfd);
cb46caab2621 New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff changeset
412 close(outfd);
cb46caab2621 New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff changeset
413
641
436eea81bc20 Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents: 610
diff changeset
414 myfree(listaddr);
436eea81bc20 Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents: 610
diff changeset
415 myfree(listdelim);
436eea81bc20 Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents: 610
diff changeset
416 myfree(listfqdn);
436eea81bc20 Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents: 610
diff changeset
417
189
cb46caab2621 New function to prepare a standard mail in an easy way, and make send_help
mmj
parents:
diff changeset
418 return retstr;
245
00eadc106b34 changed to use the new memory wrappers
mortenp
parents: 225
diff changeset
419 }