Mercurial > hg > mlmmj
annotate src/strgen.c @ 764:dd5b87ddd51e
Make *all* random strings produced the same length
author | Ben Schmidt |
---|---|
date | Wed, 20 Oct 2010 12:34:28 +1100 |
parents | e29893b9f581 |
children |
rev | line source |
---|---|
0 | 1 /* Copyright (C) 2003 Mads Martin Joergensen <mmj at mmj.dk> |
2 * | |
3 * $Id$ | |
4 * | |
225 | 5 * Permission is hereby granted, free of charge, to any person obtaining a copy |
6 * of this software and associated documentation files (the "Software"), to | |
7 * deal in the Software without restriction, including without limitation the | |
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |
9 * sell copies of the Software, and to permit persons to whom the Software is | |
10 * furnished to do so, subject to the following conditions: | |
11 * | |
12 * The above copyright notice and this permission notice shall be included in | |
13 * all copies or substantial portions of the Software. | |
14 * | |
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
21 * IN THE SOFTWARE. | |
0 | 22 */ |
23 | |
24 #include <stdio.h> | |
25 #include <stdlib.h> | |
26 #include <string.h> | |
27 #include <stdarg.h> | |
99
6089f38bb228
Send our hostname in HELO and change the mlmmj-send output from
mmj
parents:
1
diff
changeset
|
28 #include <unistd.h> |
6089f38bb228
Send our hostname in HELO and change the mlmmj-send output from
mmj
parents:
1
diff
changeset
|
29 #include <netdb.h> |
117
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
30 #include <libgen.h> |
320
b2fe9c6cb9fe
Bouncelife and crontab entry fix and a commented out genmsgid() function
mmj
parents:
316
diff
changeset
|
31 #include <time.h> |
597 | 32 #include <ctype.h> |
605
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
33 #include <errno.h> |
0 | 34 |
674 | 35 #include "mlmmj.h" |
0 | 36 #include "strgen.h" |
37 #include "wrappers.h" | |
245 | 38 #include "memory.h" |
674 | 39 #include "log_error.h" |
0 | 40 |
41 char *random_str() | |
42 { | |
731
e29893b9f581
Make the random strings produced always the same length rather the
Ben Schmidt
parents:
674
diff
changeset
|
43 size_t len = 17; |
245 | 44 char *dest = mymalloc(len); |
0 | 45 |
731
e29893b9f581
Make the random strings produced always the same length rather the
Ben Schmidt
parents:
674
diff
changeset
|
46 snprintf(dest, len, "%08x%08x", random_int(), random_int()); |
0 | 47 |
48 return dest; | |
49 } | |
50 | |
51 char *random_plus_addr(const char *addr) | |
52 { | |
314 | 53 size_t len = strlen(addr) + 128; |
245 | 54 char *dest = mymalloc(len); |
0 | 55 char *atsign; |
56 char *tmpstr; | |
57 | |
245 | 58 tmpstr = mymalloc(len); |
0 | 59 snprintf(tmpstr, len, "%s", addr); |
60 | |
328
80129335dbbb
Replace index with strchr since it warns a lot on older SunOS versions
mmj
parents:
320
diff
changeset
|
61 atsign = strchr(tmpstr, '@'); |
674 | 62 MY_ASSERT(atsign); |
0 | 63 *atsign = '='; |
64 | |
764
dd5b87ddd51e
Make *all* random strings produced the same length
Ben Schmidt
parents:
731
diff
changeset
|
65 snprintf(dest, len, "%08x%08x-%s", random_int(), random_int(), tmpstr); |
0 | 66 |
245 | 67 myfree(tmpstr); |
0 | 68 |
69 return dest; | |
70 } | |
71 | |
72 char *headerstr(const char *headertoken, const char *str) | |
73 { | |
74 size_t len = strlen(headertoken) + strlen(str) + 2; | |
245 | 75 char *dest = mymalloc(len); |
0 | 76 |
77 snprintf(dest, len, "%s%s\n", headertoken, str); | |
78 | |
79 return dest; | |
80 } | |
81 | |
82 char *genlistname(const char *listaddr) | |
83 { | |
84 size_t len; | |
85 char *dest, *atsign; | |
86 | |
328
80129335dbbb
Replace index with strchr since it warns a lot on older SunOS versions
mmj
parents:
320
diff
changeset
|
87 atsign = strchr(listaddr, '@'); |
674 | 88 MY_ASSERT(atsign); |
0 | 89 len = atsign - listaddr + 1; |
245 | 90 dest = mymalloc(len); |
0 | 91 |
92 snprintf(dest, len, "%s", listaddr); | |
93 | |
94 return dest; | |
95 } | |
96 | |
97 char *genlistfqdn(const char *listaddr) | |
98 { | |
99 size_t len; | |
100 char *dest, *atsign; | |
101 | |
328
80129335dbbb
Replace index with strchr since it warns a lot on older SunOS versions
mmj
parents:
320
diff
changeset
|
102 atsign = strchr(listaddr, '@'); |
674 | 103 MY_ASSERT(atsign); |
0 | 104 len = strlen(listaddr) - (atsign - listaddr); |
245 | 105 dest = mymalloc(len); |
0 | 106 snprintf(dest, len, "%s", atsign + 1); |
107 | |
108 return dest; | |
109 } | |
110 | |
111 char *concatstr(int count, ...) | |
112 { | |
113 va_list arg; | |
114 const char *str; | |
115 int i; | |
116 size_t len = 0; | |
117 char *retstr; | |
118 | |
119 va_start(arg, count); | |
120 | |
121 for(i = 0; i < count; i++) { | |
122 str = va_arg(arg, const char *); | |
123 if(str) | |
124 len += strlen(str); | |
125 } | |
126 | |
245 | 127 retstr = mymalloc(len + 1); |
0 | 128 retstr[0] = retstr[len] = 0; |
129 | |
130 va_start(arg, count); | |
131 | |
132 for(i = 0; i < count; i++) { | |
133 str = va_arg(arg, const char *); | |
134 if(str) | |
135 strcat(retstr, str); | |
136 } | |
137 | |
138 va_end(arg); | |
139 | |
140 return retstr; | |
141 } | |
142 | |
99
6089f38bb228
Send our hostname in HELO and change the mlmmj-send output from
mmj
parents:
1
diff
changeset
|
143 char *hostnamestr() |
6089f38bb228
Send our hostname in HELO and change the mlmmj-send output from
mmj
parents:
1
diff
changeset
|
144 { |
605
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
145 struct hostent *hostlookup; |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
146 char *hostname = NULL; |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
147 size_t len = 512; |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
148 |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
149 for (;;) { |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
150 len *= 2; |
674 | 151 myfree(hostname); |
605
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
152 |
674 | 153 hostname = mymalloc(len); |
605
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
154 hostname[len-1] = '\0'; |
99
6089f38bb228
Send our hostname in HELO and change the mlmmj-send output from
mmj
parents:
1
diff
changeset
|
155 |
605
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
156 /* gethostname() is allowed to: |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
157 * a) return -1 and undefined in hostname |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
158 * b) return 0 and an unterminated string in hostname |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
159 * c) return 0 and a NUL-terminated string in hostname |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
160 * |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
161 * We keep expanding the buffer until the hostname is |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
162 * NUL-terminated (and pray that it is not truncated) |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
163 * or an error occurs. |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
164 */ |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
165 if (gethostname(hostname, len - 1)) { |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
166 if (errno == ENAMETOOLONG) { |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
167 continue; |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
168 } |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
169 myfree(hostname); |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
170 return mystrdup("localhost"); |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
171 } |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
172 |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
173 if (hostname[len-1] == '\0') { |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
174 break; |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
175 } |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
176 } |
99
6089f38bb228
Send our hostname in HELO and change the mlmmj-send output from
mmj
parents:
1
diff
changeset
|
177 |
605
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
178 if (strchr(hostname, '.')) { |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
179 /* hostname is FQDN */ |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
180 return hostname; |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
181 } |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
182 |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
183 if ((hostlookup = gethostbyname(hostname))) { |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
184 myfree(hostname); |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
185 return mystrdup(hostlookup->h_name); |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
186 } |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
187 |
eb2985b8de7e
Fixed hostnamestr() for hosts that can't find themselves using gethostbyname() (Benoit Dolez)
mortenp
parents:
597
diff
changeset
|
188 return hostname; |
99
6089f38bb228
Send our hostname in HELO and change the mlmmj-send output from
mmj
parents:
1
diff
changeset
|
189 } |
6089f38bb228
Send our hostname in HELO and change the mlmmj-send output from
mmj
parents:
1
diff
changeset
|
190 |
117
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
191 char *mydirname(const char *path) |
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
192 { |
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
193 char *mypath, *dname, *ret; |
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
194 |
245 | 195 mypath = mystrdup(path); |
117
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
196 dname = dirname(mypath); |
245 | 197 ret = mystrdup(dname); |
117
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
198 |
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
199 /* We don't free mypath until we have strdup()'ed dname, because |
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
200 * dirname() returns a pointer into mypath -- mortenp 20040527 */ |
245 | 201 myfree(mypath); |
117
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
202 |
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
203 return ret; |
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
204 } |
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
205 |
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
206 char *mybasename(const char *path) |
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
207 { |
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
208 char *mypath, *bname, *ret; |
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
209 |
245 | 210 mypath = mystrdup(path); |
117
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
211 bname = basename(mypath); |
245 | 212 ret = mystrdup(bname); |
117
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
213 |
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
214 /* We don't free mypath until we have strdup()'ed bname, because |
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
215 * basename() returns a pointer into mypath -- mortenp 20040527 */ |
245 | 216 myfree(mypath); |
117
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
217 |
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
218 return ret; |
9a39dff171fa
added mydirname() and mybasename() which doesn't mess with their argument, and
mortenp
parents:
100
diff
changeset
|
219 } |
265
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
220 |
351 | 221 char *cleanquotedp(const char *qpstr) |
265
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
222 { |
351 | 223 char *retstr; |
224 char qc[3]; | |
225 const char *c = qpstr; | |
265
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
226 long qcval; |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
227 int i = 0; |
351 | 228 size_t len; |
265
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
229 |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
230 /* XXX: We only use this function for checking whether the subject |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
231 * prefix is only present, so the recoding is neither guaranteed |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
232 * complete nor correct */ |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
233 |
351 | 234 len = strlen(qpstr); |
235 retstr = mymalloc(len + 1); | |
236 retstr[len] = '\0'; | |
265
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
237 qc[2] = '\0'; |
597 | 238 while(c < qpstr+len) { |
265
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
239 switch(*c) { |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
240 case '=': |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
241 c++; |
597 | 242 if (!isxdigit(*c)) |
243 break; | |
244 qc[0] = *(c++); | |
245 if (!isxdigit(*c)) | |
246 break; | |
247 qc[1] = *(c++); | |
265
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
248 qcval = strtol(qc, NULL, 16); |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
249 if(qcval) |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
250 retstr[i++] = (char)qcval; |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
251 break; |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
252 case '_': |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
253 retstr[i++] = ' '; |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
254 c++; |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
255 break; |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
256 default: |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
257 retstr[i++] = *(c++); |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
258 break; |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
259 } |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
260 } |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
261 |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
262 retstr[i] = '\0'; |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
263 |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
264 return retstr; |
f28ab75abba7
Quoted printable subjects are now matched against prefix as well
mmj
parents:
245
diff
changeset
|
265 } |
320
b2fe9c6cb9fe
Bouncelife and crontab entry fix and a commented out genmsgid() function
mmj
parents:
316
diff
changeset
|
266 |
641
436eea81bc20
Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents:
605
diff
changeset
|
267 char *genmsgid(const char *fqdn) |
320
b2fe9c6cb9fe
Bouncelife and crontab entry fix and a commented out genmsgid() function
mmj
parents:
316
diff
changeset
|
268 { |
641
436eea81bc20
Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents:
605
diff
changeset
|
269 char buf[256]; |
320
b2fe9c6cb9fe
Bouncelife and crontab entry fix and a commented out genmsgid() function
mmj
parents:
316
diff
changeset
|
270 |
764
dd5b87ddd51e
Make *all* random strings produced the same length
Ben Schmidt
parents:
731
diff
changeset
|
271 snprintf(buf, sizeof(buf), "Message-ID: <%ld-%d-mlmmj-%08x@%s>\n", |
641
436eea81bc20
Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents:
605
diff
changeset
|
272 (long int)time(NULL), (int)getpid(), random_int(), fqdn); |
320
b2fe9c6cb9fe
Bouncelife and crontab entry fix and a commented out genmsgid() function
mmj
parents:
316
diff
changeset
|
273 |
641
436eea81bc20
Changed Message-ID headers to include FQDN (Ansgar Burchardt)
mortenp
parents:
605
diff
changeset
|
274 return mystrdup(buf); |
320
b2fe9c6cb9fe
Bouncelife and crontab entry fix and a commented out genmsgid() function
mmj
parents:
316
diff
changeset
|
275 } |
422 | 276 |
277 char *gendatestr() | |
278 { | |
279 time_t t; | |
280 struct tm gmttm, lttm; | |
281 int dayyear; | |
282 char *timestr; | |
448 | 283 const char *weekday = NULL, *month = NULL; |
422 | 284 |
285 /* 6 + 26 + ' ' + timezone which is 5 + '\n\0' == 40 */ | |
674 | 286 timestr = (char *)mymalloc(40); |
422 | 287 t = time(NULL); |
288 | |
289 localtime_r(&t, <tm); | |
290 gmtime_r(&t, &gmttm); | |
291 | |
292 t = (((lttm.tm_hour - gmttm.tm_hour) * 60) + | |
293 (lttm.tm_min - gmttm.tm_min)) * 60; | |
294 | |
295 dayyear = lttm.tm_yday - gmttm.tm_yday; | |
296 if(dayyear) { | |
297 if (dayyear == -1 || dayyear > 1) | |
298 t -= 24 * 60 * 60; | |
299 else | |
300 t += 24 * 60 * 60; | |
301 } | |
448 | 302 |
303 switch(lttm.tm_wday) { | |
304 case 0: weekday = "Sun"; | |
305 break; | |
306 case 1: weekday = "Mon"; | |
307 break; | |
308 case 2: weekday = "Tue"; | |
309 break; | |
310 case 3: weekday = "Wed"; | |
311 break; | |
312 case 4: weekday = "Thu"; | |
313 break; | |
314 case 5: weekday = "Fri"; | |
315 break; | |
316 case 6: weekday = "Sat"; | |
317 break; | |
318 default: | |
319 break; | |
320 } | |
321 switch(lttm.tm_mon) { | |
322 case 0: month = "Jan"; | |
323 break; | |
324 case 1: month = "Feb"; | |
325 break; | |
326 case 2: month = "Mar"; | |
327 break; | |
328 case 3: month = "Apr"; | |
329 break; | |
330 case 4: month = "May"; | |
331 break; | |
332 case 5: month = "Jun"; | |
333 break; | |
334 case 6: month = "Jul"; | |
335 break; | |
336 case 7: month = "Aug"; | |
337 break; | |
338 case 8: month = "Sep"; | |
339 break; | |
340 case 9: month = "Oct"; | |
341 break; | |
342 case 10: month = "Nov"; | |
343 break; | |
344 case 11: month = "Dec"; | |
345 break; | |
346 default: | |
347 break; | |
348 } | |
349 | |
422 | 350 |
508 | 351 snprintf(timestr, 40, "Date: %s, %02d %s %04d %02d:%02d:%02d %+05d\n", |
448 | 352 weekday, lttm.tm_mday, month, lttm.tm_year + 1900, |
353 lttm.tm_hour, lttm.tm_min, lttm.tm_sec, ((int)t)/36); | |
422 | 354 |
355 return timestr; | |
356 } |