]>
Commit | Line | Data |
---|---|---|
2744b234 LT |
1 | /* |
2 | * Another stupid program, this one parsing the headers of an | |
3 | * email to figure out authorship and subject | |
4 | */ | |
f1f909e3 | 5 | #include "cache.h" |
34488e3c | 6 | #include "builtin.h" |
b45974a6 | 7 | #include "utf8.h" |
3b6121f6 | 8 | #include "strbuf.h" |
2744b234 | 9 | |
34488e3c | 10 | static FILE *cmitmsg, *patchfile, *fin, *fout; |
2744b234 | 11 | |
96f1e58f | 12 | static int keep_subject; |
17635fc9 | 13 | static int keep_non_patch_brackets_in_subject; |
96f1e58f | 14 | static const char *metainfo_charset; |
3b6121f6 LS |
15 | static struct strbuf line = STRBUF_INIT; |
16 | static struct strbuf name = STRBUF_INIT; | |
17 | static struct strbuf email = STRBUF_INIT; | |
2744b234 | 18 | |
d4a9ce78 | 19 | static enum { |
4b05548f | 20 | TE_DONTCARE, TE_QP, TE_BASE64 |
d4a9ce78 | 21 | } transfer_encoding; |
d4a9ce78 | 22 | |
3b6121f6 | 23 | static struct strbuf charset = STRBUF_INIT; |
96f1e58f | 24 | static int patch_lines; |
3b6121f6 | 25 | static struct strbuf **p_hdr_data, **s_hdr_data; |
017678b4 | 26 | static int use_scissors; |
d25e5159 | 27 | static int use_inbody_headers = 1; |
87ab7992 DZ |
28 | |
29 | #define MAX_HDR_PARSED 10 | |
30 | #define MAX_BOUNDARIES 5 | |
d4a9ce78 | 31 | |
08e6710f KS |
32 | static void cleanup_space(struct strbuf *sb); |
33 | ||
34 | ||
3b6121f6 | 35 | static void get_sane_name(struct strbuf *out, struct strbuf *name, struct strbuf *email) |
2744b234 | 36 | { |
3b6121f6 LS |
37 | struct strbuf *src = name; |
38 | if (name->len < 3 || 60 < name->len || strchr(name->buf, '@') || | |
39 | strchr(name->buf, '<') || strchr(name->buf, '>')) | |
40 | src = email; | |
41 | else if (name == out) | |
42 | return; | |
43 | strbuf_reset(out); | |
44 | strbuf_addbuf(out, src); | |
2744b234 LT |
45 | } |
46 | ||
3b6121f6 | 47 | static void parse_bogus_from(const struct strbuf *line) |
e0e3ba20 JH |
48 | { |
49 | /* John Doe <johndoe> */ | |
e0e3ba20 | 50 | |
3b6121f6 | 51 | char *bra, *ket; |
e0e3ba20 JH |
52 | /* This is fallback, so do not bother if we already have an |
53 | * e-mail address. | |
34488e3c | 54 | */ |
3b6121f6 LS |
55 | if (email.len) |
56 | return; | |
e0e3ba20 | 57 | |
3b6121f6 | 58 | bra = strchr(line->buf, '<'); |
e0e3ba20 | 59 | if (!bra) |
3b6121f6 | 60 | return; |
e0e3ba20 JH |
61 | ket = strchr(bra, '>'); |
62 | if (!ket) | |
3b6121f6 | 63 | return; |
e0e3ba20 | 64 | |
3b6121f6 LS |
65 | strbuf_reset(&email); |
66 | strbuf_add(&email, bra + 1, ket - bra - 1); | |
67 | ||
68 | strbuf_reset(&name); | |
69 | strbuf_add(&name, line->buf, bra - line->buf); | |
70 | strbuf_trim(&name); | |
71 | get_sane_name(&name, &name, &email); | |
e0e3ba20 JH |
72 | } |
73 | ||
3b6121f6 | 74 | static void handle_from(const struct strbuf *from) |
2744b234 | 75 | { |
2dec02b1 | 76 | char *at; |
3b6121f6 LS |
77 | size_t el; |
78 | struct strbuf f; | |
2744b234 | 79 | |
3b6121f6 LS |
80 | strbuf_init(&f, from->len); |
81 | strbuf_addbuf(&f, from); | |
82 | ||
83 | at = strchr(f.buf, '@'); | |
84 | if (!at) { | |
85 | parse_bogus_from(from); | |
86 | return; | |
87 | } | |
2744b234 LT |
88 | |
89 | /* | |
90 | * If we already have one email, don't take any confusing lines | |
91 | */ | |
3b6121f6 LS |
92 | if (email.len && strchr(at + 1, '@')) { |
93 | strbuf_release(&f); | |
94 | return; | |
95 | } | |
2744b234 | 96 | |
d4a9ce78 | 97 | /* Pick up the string around '@', possibly delimited with <> |
3b6121f6 | 98 | * pair; that is the email part. |
d4a9ce78 | 99 | */ |
3b6121f6 | 100 | while (at > f.buf) { |
2744b234 | 101 | char c = at[-1]; |
d4a9ce78 JH |
102 | if (isspace(c)) |
103 | break; | |
104 | if (c == '<') { | |
105 | at[-1] = ' '; | |
2744b234 | 106 | break; |
d4a9ce78 | 107 | } |
2744b234 LT |
108 | at--; |
109 | } | |
3b6121f6 LS |
110 | el = strcspn(at, " \n\t\r\v\f>"); |
111 | strbuf_reset(&email); | |
112 | strbuf_add(&email, at, el); | |
e9d7d10a | 113 | strbuf_remove(&f, at - f.buf, el + (at[el] ? 1 : 0)); |
2744b234 | 114 | |
08e6710f KS |
115 | /* The remainder is name. It could be |
116 | * | |
117 | * - "John Doe <john.doe@xz>" (a), or | |
118 | * - "john.doe@xz (John Doe)" (b), or | |
119 | * - "John (zzz) Doe <john.doe@xz> (Comment)" (c) | |
120 | * | |
121 | * but we have removed the email part, so | |
122 | * | |
123 | * - remove extra spaces which could stay after email (case 'c'), and | |
124 | * - trim from both ends, possibly removing the () pair at the end | |
125 | * (cases 'a' and 'b'). | |
d4a9ce78 | 126 | */ |
08e6710f | 127 | cleanup_space(&f); |
3b6121f6 | 128 | strbuf_trim(&f); |
0d4ede9f PB |
129 | if (f.buf[0] == '(' && f.len && f.buf[f.len - 1] == ')') { |
130 | strbuf_remove(&f, 0, 1); | |
3b6121f6 | 131 | strbuf_setlen(&f, f.len - 1); |
0d4ede9f | 132 | } |
2744b234 | 133 | |
3b6121f6 LS |
134 | get_sane_name(&name, &f, &email); |
135 | strbuf_release(&f); | |
2744b234 LT |
136 | } |
137 | ||
3b6121f6 | 138 | static void handle_header(struct strbuf **out, const struct strbuf *line) |
62c1f6b4 | 139 | { |
3b6121f6 LS |
140 | if (!*out) { |
141 | *out = xmalloc(sizeof(struct strbuf)); | |
142 | strbuf_init(*out, line->len); | |
143 | } else | |
144 | strbuf_reset(*out); | |
87ab7992 | 145 | |
3b6121f6 | 146 | strbuf_addbuf(*out, line); |
d4a9ce78 JH |
147 | } |
148 | ||
149 | /* NOTE NOTE NOTE. We do not claim we do full MIME. We just attempt | |
150 | * to have enough heuristics to grok MIME encoded patches often found | |
151 | * on our mailing lists. For example, we do not even treat header lines | |
152 | * case insensitively. | |
153 | */ | |
154 | ||
3b6121f6 | 155 | static int slurp_attr(const char *line, const char *name, struct strbuf *attr) |
d4a9ce78 | 156 | { |
554fe20d | 157 | const char *ends, *ap = strcasestr(line, name); |
d4a9ce78 JH |
158 | size_t sz; |
159 | ||
176943b9 JH |
160 | strbuf_setlen(attr, 0); |
161 | if (!ap) | |
d4a9ce78 | 162 | return 0; |
d4a9ce78 JH |
163 | ap += strlen(name); |
164 | if (*ap == '"') { | |
165 | ap++; | |
166 | ends = "\""; | |
167 | } | |
168 | else | |
169 | ends = "; \t"; | |
170 | sz = strcspn(ap, ends); | |
3b6121f6 | 171 | strbuf_add(attr, ap, sz); |
d4a9ce78 JH |
172 | return 1; |
173 | } | |
174 | ||
3b6121f6 | 175 | static struct strbuf *content[MAX_BOUNDARIES]; |
87ab7992 | 176 | |
3b6121f6 | 177 | static struct strbuf **content_top = content; |
87ab7992 | 178 | |
3b6121f6 | 179 | static void handle_content_type(struct strbuf *line) |
d4a9ce78 | 180 | { |
3b6121f6 LS |
181 | struct strbuf *boundary = xmalloc(sizeof(struct strbuf)); |
182 | strbuf_init(boundary, line->len); | |
87ab7992 | 183 | |
3b6121f6 LS |
184 | if (slurp_attr(line->buf, "boundary=", boundary)) { |
185 | strbuf_insert(boundary, 0, "--", 2); | |
289796dd | 186 | if (++content_top > &content[MAX_BOUNDARIES]) { |
87ab7992 DZ |
187 | fprintf(stderr, "Too many boundaries to handle\n"); |
188 | exit(1); | |
189 | } | |
3b6121f6 LS |
190 | *content_top = boundary; |
191 | boundary = NULL; | |
b893f091 | 192 | } |
ed1e3985 | 193 | slurp_attr(line->buf, "charset=", &charset); |
3b6121f6 LS |
194 | |
195 | if (boundary) { | |
196 | strbuf_release(boundary); | |
197 | free(boundary); | |
d4a9ce78 | 198 | } |
d4a9ce78 JH |
199 | } |
200 | ||
3b6121f6 | 201 | static void handle_content_transfer_encoding(const struct strbuf *line) |
d4a9ce78 | 202 | { |
3b6121f6 | 203 | if (strcasestr(line->buf, "base64")) |
d4a9ce78 | 204 | transfer_encoding = TE_BASE64; |
3b6121f6 | 205 | else if (strcasestr(line->buf, "quoted-printable")) |
d4a9ce78 JH |
206 | transfer_encoding = TE_QP; |
207 | else | |
208 | transfer_encoding = TE_DONTCARE; | |
2744b234 LT |
209 | } |
210 | ||
3b6121f6 | 211 | static int is_multipart_boundary(const struct strbuf *line) |
d4a9ce78 | 212 | { |
a9fd1383 JH |
213 | return (((*content_top)->len <= line->len) && |
214 | !memcmp(line->buf, (*content_top)->buf, (*content_top)->len)); | |
d4a9ce78 JH |
215 | } |
216 | ||
3b6121f6 | 217 | static void cleanup_subject(struct strbuf *subject) |
2744b234 | 218 | { |
17635fc9 JH |
219 | size_t at = 0; |
220 | ||
221 | while (at < subject->len) { | |
222 | char *pos; | |
223 | size_t remove; | |
224 | ||
225 | switch (subject->buf[at]) { | |
2744b234 | 226 | case 'r': case 'R': |
17635fc9 | 227 | if (subject->len <= at + 3) |
3b6121f6 | 228 | break; |
d5b4d80d JH |
229 | if ((subject->buf[at + 1] == 'e' || |
230 | subject->buf[at + 1] == 'E') && | |
231 | subject->buf[at + 2] == ':') { | |
17635fc9 | 232 | strbuf_remove(subject, at, 3); |
2744b234 LT |
233 | continue; |
234 | } | |
17635fc9 | 235 | at++; |
2744b234 LT |
236 | break; |
237 | case ' ': case '\t': case ':': | |
17635fc9 | 238 | strbuf_remove(subject, at, 1); |
2744b234 | 239 | continue; |
2744b234 | 240 | case '[': |
17635fc9 JH |
241 | pos = strchr(subject->buf + at, ']'); |
242 | if (!pos) | |
243 | break; | |
244 | remove = pos - subject->buf + at + 1; | |
245 | if (!keep_non_patch_brackets_in_subject || | |
246 | (7 <= remove && | |
247 | memmem(subject->buf + at, remove, "PATCH", 5))) | |
248 | strbuf_remove(subject, at, remove); | |
ee2d1cb4 | 249 | else { |
17635fc9 | 250 | at += remove; |
ee2d1cb4 TR |
251 | /* |
252 | * If the input had a space after the ], keep | |
253 | * it. We don't bother with finding the end of | |
254 | * the space, since we later normalize it | |
255 | * anyway. | |
256 | */ | |
257 | if (isspace(subject->buf[at])) | |
258 | at += 1; | |
259 | } | |
17635fc9 | 260 | continue; |
2744b234 | 261 | } |
17635fc9 | 262 | break; |
2744b234 | 263 | } |
17635fc9 | 264 | strbuf_trim(subject); |
34488e3c | 265 | } |
2744b234 | 266 | |
3b6121f6 | 267 | static void cleanup_space(struct strbuf *sb) |
2744b234 | 268 | { |
3b6121f6 LS |
269 | size_t pos, cnt; |
270 | for (pos = 0; pos < sb->len; pos++) { | |
271 | if (isspace(sb->buf[pos])) { | |
272 | sb->buf[pos] = ' '; | |
273 | for (cnt = 0; isspace(sb->buf[pos + cnt + 1]); cnt++); | |
274 | strbuf_remove(sb, pos + 1, cnt); | |
2744b234 LT |
275 | } |
276 | } | |
277 | } | |
278 | ||
3b6121f6 | 279 | static void decode_header(struct strbuf *line); |
538dfe73 | 280 | static const char *header[MAX_HDR_PARSED] = { |
87ab7992 | 281 | "From","Subject","Date", |
d4a9ce78 JH |
282 | }; |
283 | ||
3b6121f6 | 284 | static inline int cmp_header(const struct strbuf *line, const char *hdr) |
d4a9ce78 | 285 | { |
3b6121f6 LS |
286 | int len = strlen(hdr); |
287 | return !strncasecmp(line->buf, hdr, len) && line->len > len && | |
288 | line->buf[len] == ':' && isspace(line->buf[len + 1]); | |
289 | } | |
d4a9ce78 | 290 | |
2da1f366 JK |
291 | static int is_format_patch_separator(const char *line, int len) |
292 | { | |
85de86a1 ES |
293 | static const char SAMPLE[] = |
294 | "From e6807f3efca28b30decfecb1732a56c7db1137ee Mon Sep 17 00:00:00 2001\n"; | |
2da1f366 JK |
295 | const char *cp; |
296 | ||
297 | if (len != strlen(SAMPLE)) | |
298 | return 0; | |
299 | if (!skip_prefix(line, "From ", &cp)) | |
300 | return 0; | |
301 | if (strspn(cp, "0123456789abcdef") != 40) | |
302 | return 0; | |
303 | cp += 40; | |
304 | return !memcmp(SAMPLE + (cp - line), cp, strlen(SAMPLE) - (cp - line)); | |
305 | } | |
306 | ||
3b6121f6 LS |
307 | static int check_header(const struct strbuf *line, |
308 | struct strbuf *hdr_data[], int overwrite) | |
309 | { | |
310 | int i, ret = 0, len; | |
311 | struct strbuf sb = STRBUF_INIT; | |
87ab7992 DZ |
312 | /* search for the interesting parts */ |
313 | for (i = 0; header[i]; i++) { | |
314 | int len = strlen(header[i]); | |
3b6121f6 | 315 | if ((!hdr_data[i] || overwrite) && cmp_header(line, header[i])) { |
33504530 EB |
316 | /* Unwrap inline B and Q encoding, and optionally |
317 | * normalize the meta information to utf8. | |
318 | */ | |
3b6121f6 LS |
319 | strbuf_add(&sb, line->buf + len + 2, line->len - len - 2); |
320 | decode_header(&sb); | |
321 | handle_header(&hdr_data[i], &sb); | |
322 | ret = 1; | |
323 | goto check_header_out; | |
d4a9ce78 JH |
324 | } |
325 | } | |
d4a9ce78 | 326 | |
87ab7992 | 327 | /* Content stuff */ |
3b6121f6 LS |
328 | if (cmp_header(line, "Content-Type")) { |
329 | len = strlen("Content-Type: "); | |
330 | strbuf_add(&sb, line->buf + len, line->len - len); | |
331 | decode_header(&sb); | |
332 | strbuf_insert(&sb, 0, "Content-Type: ", len); | |
333 | handle_content_type(&sb); | |
334 | ret = 1; | |
335 | goto check_header_out; | |
336 | } | |
337 | if (cmp_header(line, "Content-Transfer-Encoding")) { | |
338 | len = strlen("Content-Transfer-Encoding: "); | |
339 | strbuf_add(&sb, line->buf + len, line->len - len); | |
340 | decode_header(&sb); | |
341 | handle_content_transfer_encoding(&sb); | |
342 | ret = 1; | |
343 | goto check_header_out; | |
87ab7992 DZ |
344 | } |
345 | ||
346 | /* for inbody stuff */ | |
59556548 | 347 | if (starts_with(line->buf, ">From") && isspace(line->buf[5])) { |
2da1f366 | 348 | ret = is_format_patch_separator(line->buf + 1, line->len - 1); |
3b6121f6 LS |
349 | goto check_header_out; |
350 | } | |
59556548 | 351 | if (starts_with(line->buf, "[PATCH]") && isspace(line->buf[7])) { |
87ab7992 | 352 | for (i = 0; header[i]; i++) { |
b1a013dd | 353 | if (!strcmp("Subject", header[i])) { |
3b6121f6 LS |
354 | handle_header(&hdr_data[i], line); |
355 | ret = 1; | |
356 | goto check_header_out; | |
87ab7992 DZ |
357 | } |
358 | } | |
359 | } | |
360 | ||
3b6121f6 LS |
361 | check_header_out: |
362 | strbuf_release(&sb); | |
363 | return ret; | |
d4a9ce78 JH |
364 | } |
365 | ||
3b6121f6 | 366 | static int is_rfc2822_header(const struct strbuf *line) |
ef29c117 JH |
367 | { |
368 | /* | |
369 | * The section that defines the loosest possible | |
370 | * field name is "3.6.8 Optional fields". | |
371 | * | |
372 | * optional-field = field-name ":" unstructured CRLF | |
373 | * field-name = 1*ftext | |
374 | * ftext = %d33-57 / %59-126 | |
375 | */ | |
376 | int ch; | |
3b6121f6 | 377 | char *cp = line->buf; |
34fc5cef LT |
378 | |
379 | /* Count mbox From headers as headers */ | |
59556548 | 380 | if (starts_with(cp, "From ") || starts_with(cp, ">From ")) |
34fc5cef LT |
381 | return 1; |
382 | ||
ef29c117 JH |
383 | while ((ch = *cp++)) { |
384 | if (ch == ':') | |
3b6121f6 | 385 | return 1; |
ef29c117 JH |
386 | if ((33 <= ch && ch <= 57) || |
387 | (59 <= ch && ch <= 126)) | |
388 | continue; | |
389 | break; | |
390 | } | |
391 | return 0; | |
392 | } | |
393 | ||
3b6121f6 | 394 | static int read_one_header_line(struct strbuf *line, FILE *in) |
d4a9ce78 | 395 | { |
34fc5cef | 396 | /* Get the first part of the line. */ |
3b6121f6 | 397 | if (strbuf_getline(line, in, '\n')) |
34fc5cef LT |
398 | return 0; |
399 | ||
400 | /* | |
401 | * Is it an empty line or not a valid rfc2822 header? | |
402 | * If so, stop here, and return false ("not a header") | |
403 | */ | |
3b6121f6 LS |
404 | strbuf_rtrim(line); |
405 | if (!line->len || !is_rfc2822_header(line)) { | |
34fc5cef | 406 | /* Re-add the newline */ |
3b6121f6 | 407 | strbuf_addch(line, '\n'); |
34fc5cef LT |
408 | return 0; |
409 | } | |
410 | ||
411 | /* | |
412 | * Now we need to eat all the continuation lines.. | |
413 | * Yuck, 2822 header "folding" | |
414 | */ | |
415 | for (;;) { | |
3b6121f6 LS |
416 | int peek; |
417 | struct strbuf continuation = STRBUF_INIT; | |
34fc5cef | 418 | |
f30b2028 EB |
419 | peek = fgetc(in); ungetc(peek, in); |
420 | if (peek != ' ' && peek != '\t') | |
421 | break; | |
3b6121f6 | 422 | if (strbuf_getline(&continuation, in, '\n')) |
34fc5cef | 423 | break; |
5b38456e | 424 | continuation.buf[0] = ' '; |
3b6121f6 LS |
425 | strbuf_rtrim(&continuation); |
426 | strbuf_addbuf(line, &continuation); | |
d4a9ce78 | 427 | } |
34fc5cef LT |
428 | |
429 | return 1; | |
d4a9ce78 JH |
430 | } |
431 | ||
3b6121f6 | 432 | static struct strbuf *decode_q_segment(const struct strbuf *q_seg, int rfc2047) |
d4a9ce78 | 433 | { |
3b6121f6 | 434 | const char *in = q_seg->buf; |
d4a9ce78 | 435 | int c; |
3b6121f6 LS |
436 | struct strbuf *out = xmalloc(sizeof(struct strbuf)); |
437 | strbuf_init(out, q_seg->len); | |
438 | ||
439 | while ((c = *in++) != 0) { | |
d4a9ce78 JH |
440 | if (c == '=') { |
441 | int d = *in++; | |
442 | if (d == '\n' || !d) | |
443 | break; /* drop trailing newline */ | |
3b6121f6 | 444 | strbuf_addch(out, (hexval(d) << 4) | hexval(*in++)); |
75731930 | 445 | continue; |
d4a9ce78 | 446 | } |
75731930 JH |
447 | if (rfc2047 && c == '_') /* rfc2047 4.2 (2) */ |
448 | c = 0x20; | |
3b6121f6 | 449 | strbuf_addch(out, c); |
d4a9ce78 | 450 | } |
3b6121f6 | 451 | return out; |
d4a9ce78 JH |
452 | } |
453 | ||
3b6121f6 | 454 | static struct strbuf *decode_b_segment(const struct strbuf *b_seg) |
d4a9ce78 JH |
455 | { |
456 | /* Decode in..ep, possibly in-place to ot */ | |
457 | int c, pos = 0, acc = 0; | |
3b6121f6 LS |
458 | const char *in = b_seg->buf; |
459 | struct strbuf *out = xmalloc(sizeof(struct strbuf)); | |
460 | strbuf_init(out, b_seg->len); | |
d4a9ce78 | 461 | |
3b6121f6 | 462 | while ((c = *in++) != 0) { |
d4a9ce78 JH |
463 | if (c == '+') |
464 | c = 62; | |
465 | else if (c == '/') | |
466 | c = 63; | |
467 | else if ('A' <= c && c <= 'Z') | |
468 | c -= 'A'; | |
469 | else if ('a' <= c && c <= 'z') | |
470 | c -= 'a' - 26; | |
471 | else if ('0' <= c && c <= '9') | |
472 | c -= '0' - 52; | |
d4a9ce78 JH |
473 | else |
474 | continue; /* garbage */ | |
475 | switch (pos++) { | |
476 | case 0: | |
477 | acc = (c << 2); | |
478 | break; | |
479 | case 1: | |
3b6121f6 | 480 | strbuf_addch(out, (acc | (c >> 4))); |
d4a9ce78 JH |
481 | acc = (c & 15) << 4; |
482 | break; | |
483 | case 2: | |
3b6121f6 | 484 | strbuf_addch(out, (acc | (c >> 2))); |
d4a9ce78 JH |
485 | acc = (c & 3) << 6; |
486 | break; | |
487 | case 3: | |
3b6121f6 | 488 | strbuf_addch(out, (acc | c)); |
d4a9ce78 JH |
489 | acc = pos = 0; |
490 | break; | |
491 | } | |
492 | } | |
3b6121f6 | 493 | return out; |
d4a9ce78 JH |
494 | } |
495 | ||
3b6121f6 | 496 | static void convert_to_utf8(struct strbuf *line, const char *charset) |
d4a9ce78 | 497 | { |
b59d398b LT |
498 | char *out; |
499 | ||
08a94a14 LT |
500 | if (!charset || !*charset) |
501 | return; | |
b45974a6 | 502 | |
0e18bcd5 | 503 | if (same_encoding(metainfo_charset, charset)) |
7296096c | 504 | return; |
3b6121f6 | 505 | out = reencode_string(line->buf, metainfo_charset, charset); |
bb1091a4 | 506 | if (!out) |
d7530708 | 507 | die("cannot convert from %s to %s", |
b59d398b | 508 | charset, metainfo_charset); |
3b6121f6 | 509 | strbuf_attach(line, out, strlen(out), strlen(out)); |
d4a9ce78 JH |
510 | } |
511 | ||
3b6121f6 | 512 | static int decode_header_bq(struct strbuf *it) |
d4a9ce78 | 513 | { |
3b6121f6 LS |
514 | char *in, *ep, *cp; |
515 | struct strbuf outbuf = STRBUF_INIT, *dec; | |
516 | struct strbuf charset_q = STRBUF_INIT, piecebuf = STRBUF_INIT; | |
b75bf2c3 | 517 | int rfc2047 = 0; |
d4a9ce78 | 518 | |
3b6121f6 LS |
519 | in = it->buf; |
520 | while (in - it->buf <= it->len && (ep = strstr(in, "=?")) != NULL) { | |
521 | int encoding; | |
522 | strbuf_reset(&charset_q); | |
523 | strbuf_reset(&piecebuf); | |
b75bf2c3 JH |
524 | rfc2047 = 1; |
525 | ||
d4a9ce78 | 526 | if (in != ep) { |
353aaf2f KS |
527 | /* |
528 | * We are about to process an encoded-word | |
529 | * that begins at ep, but there is something | |
530 | * before the encoded word. | |
531 | */ | |
532 | char *scan; | |
533 | for (scan = in; scan < ep; scan++) | |
534 | if (!isspace(*scan)) | |
535 | break; | |
536 | ||
537 | if (scan != ep || in == it->buf) { | |
538 | /* | |
539 | * We should not lose that "something", | |
540 | * unless we have just processed an | |
541 | * encoded-word, and there is only LWS | |
542 | * before the one we are about to process. | |
543 | */ | |
544 | strbuf_add(&outbuf, in, ep - in); | |
545 | } | |
d4a9ce78 JH |
546 | } |
547 | /* E.g. | |
548 | * ep : "=?iso-2022-jp?B?GyR...?= foo" | |
549 | * ep : "=?ISO-8859-1?Q?Foo=FCbar?= baz" | |
550 | */ | |
551 | ep += 2; | |
3b6121f6 LS |
552 | |
553 | if (ep - it->buf >= it->len || !(cp = strchr(ep, '?'))) | |
554 | goto decode_header_bq_out; | |
555 | ||
556 | if (cp + 3 - it->buf > it->len) | |
557 | goto decode_header_bq_out; | |
558 | strbuf_add(&charset_q, ep, cp - ep); | |
3b6121f6 | 559 | |
d4a9ce78 JH |
560 | encoding = cp[1]; |
561 | if (!encoding || cp[2] != '?') | |
3b6121f6 | 562 | goto decode_header_bq_out; |
d4a9ce78 JH |
563 | ep = strstr(cp + 3, "?="); |
564 | if (!ep) | |
3b6121f6 LS |
565 | goto decode_header_bq_out; |
566 | strbuf_add(&piecebuf, cp + 3, ep - cp - 3); | |
d4a9ce78 JH |
567 | switch (tolower(encoding)) { |
568 | default: | |
3b6121f6 | 569 | goto decode_header_bq_out; |
d4a9ce78 | 570 | case 'b': |
3b6121f6 | 571 | dec = decode_b_segment(&piecebuf); |
d4a9ce78 JH |
572 | break; |
573 | case 'q': | |
3b6121f6 | 574 | dec = decode_q_segment(&piecebuf, 1); |
d4a9ce78 JH |
575 | break; |
576 | } | |
650e4be5 | 577 | if (metainfo_charset) |
3b6121f6 | 578 | convert_to_utf8(dec, charset_q.buf); |
8dabdfcc | 579 | |
3b6121f6 LS |
580 | strbuf_addbuf(&outbuf, dec); |
581 | strbuf_release(dec); | |
582 | free(dec); | |
d4a9ce78 JH |
583 | in = ep + 2; |
584 | } | |
3b6121f6 LS |
585 | strbuf_addstr(&outbuf, in); |
586 | strbuf_reset(it); | |
587 | strbuf_addbuf(it, &outbuf); | |
588 | decode_header_bq_out: | |
589 | strbuf_release(&outbuf); | |
590 | strbuf_release(&charset_q); | |
591 | strbuf_release(&piecebuf); | |
b75bf2c3 JH |
592 | return rfc2047; |
593 | } | |
594 | ||
3b6121f6 | 595 | static void decode_header(struct strbuf *it) |
b75bf2c3 | 596 | { |
3b6121f6 | 597 | if (decode_header_bq(it)) |
b75bf2c3 JH |
598 | return; |
599 | /* otherwise "it" is a straight copy of the input. | |
600 | * This can be binary guck but there is no charset specified. | |
601 | */ | |
602 | if (metainfo_charset) | |
3b6121f6 | 603 | convert_to_utf8(it, ""); |
d4a9ce78 JH |
604 | } |
605 | ||
3b6121f6 | 606 | static void decode_transfer_encoding(struct strbuf *line) |
d4a9ce78 | 607 | { |
3b6121f6 | 608 | struct strbuf *ret; |
d4a9ce78 JH |
609 | |
610 | switch (transfer_encoding) { | |
611 | case TE_QP: | |
3b6121f6 LS |
612 | ret = decode_q_segment(line, 0); |
613 | break; | |
d4a9ce78 | 614 | case TE_BASE64: |
3b6121f6 LS |
615 | ret = decode_b_segment(line); |
616 | break; | |
d4a9ce78 | 617 | case TE_DONTCARE: |
9aa23094 | 618 | default: |
3b6121f6 | 619 | return; |
d4a9ce78 | 620 | } |
3b6121f6 LS |
621 | strbuf_reset(line); |
622 | strbuf_addbuf(line, ret); | |
623 | strbuf_release(ret); | |
624 | free(ret); | |
d4a9ce78 JH |
625 | } |
626 | ||
3b6121f6 | 627 | static void handle_filter(struct strbuf *line); |
87ab7992 DZ |
628 | |
629 | static int find_boundary(void) | |
2744b234 | 630 | { |
3b6121f6 | 631 | while (!strbuf_getline(&line, fin, '\n')) { |
289796dd | 632 | if (*content_top && is_multipart_boundary(&line)) |
87ab7992 DZ |
633 | return 1; |
634 | } | |
635 | return 0; | |
636 | } | |
637 | ||
638 | static int handle_boundary(void) | |
639 | { | |
3b6121f6 LS |
640 | struct strbuf newline = STRBUF_INIT; |
641 | ||
642 | strbuf_addch(&newline, '\n'); | |
87ab7992 | 643 | again: |
3b6121f6 LS |
644 | if (line.len >= (*content_top)->len + 2 && |
645 | !memcmp(line.buf + (*content_top)->len, "--", 2)) { | |
87ab7992 DZ |
646 | /* we hit an end boundary */ |
647 | /* pop the current boundary off the stack */ | |
3b6121f6 LS |
648 | strbuf_release(*content_top); |
649 | free(*content_top); | |
650 | *content_top = NULL; | |
87ab7992 DZ |
651 | |
652 | /* technically won't happen as is_multipart_boundary() | |
653 | will fail first. But just in case.. | |
654 | */ | |
289796dd | 655 | if (--content_top < content) { |
87ab7992 DZ |
656 | fprintf(stderr, "Detected mismatched boundaries, " |
657 | "can't recover\n"); | |
658 | exit(1); | |
659 | } | |
3b6121f6 LS |
660 | handle_filter(&newline); |
661 | strbuf_release(&newline); | |
87ab7992 DZ |
662 | |
663 | /* skip to the next boundary */ | |
664 | if (!find_boundary()) | |
665 | return 0; | |
666 | goto again; | |
667 | } | |
668 | ||
669 | /* set some defaults */ | |
670 | transfer_encoding = TE_DONTCARE; | |
3b6121f6 | 671 | strbuf_reset(&charset); |
d4a9ce78 | 672 | |
87ab7992 | 673 | /* slurp in this section's info */ |
3b6121f6 LS |
674 | while (read_one_header_line(&line, fin)) |
675 | check_header(&line, p_hdr_data, 0); | |
2744b234 | 676 | |
3b6121f6 | 677 | strbuf_release(&newline); |
a9fd1383 JH |
678 | /* replenish line */ |
679 | if (strbuf_getline(&line, fin, '\n')) | |
680 | return 0; | |
681 | strbuf_addch(&line, '\n'); | |
682 | return 1; | |
d4a9ce78 JH |
683 | } |
684 | ||
3b6121f6 | 685 | static inline int patchbreak(const struct strbuf *line) |
f0658cf2 | 686 | { |
3b6121f6 LS |
687 | size_t i; |
688 | ||
f0658cf2 | 689 | /* Beginning of a "diff -" header? */ |
59556548 | 690 | if (starts_with(line->buf, "diff -")) |
f0658cf2 DZ |
691 | return 1; |
692 | ||
693 | /* CVS "Index: " line? */ | |
59556548 | 694 | if (starts_with(line->buf, "Index: ")) |
f0658cf2 DZ |
695 | return 1; |
696 | ||
697 | /* | |
698 | * "--- <filename>" starts patches without headers | |
699 | * "---<sp>*" is a manual separator | |
700 | */ | |
3b6121f6 LS |
701 | if (line->len < 4) |
702 | return 0; | |
703 | ||
59556548 | 704 | if (starts_with(line->buf, "---")) { |
f0658cf2 | 705 | /* space followed by a filename? */ |
3b6121f6 | 706 | if (line->buf[3] == ' ' && !isspace(line->buf[4])) |
f0658cf2 DZ |
707 | return 1; |
708 | /* Just whitespace? */ | |
3b6121f6 LS |
709 | for (i = 3; i < line->len; i++) { |
710 | unsigned char c = line->buf[i]; | |
f0658cf2 DZ |
711 | if (c == '\n') |
712 | return 1; | |
713 | if (!isspace(c)) | |
714 | break; | |
715 | } | |
716 | return 0; | |
717 | } | |
718 | return 0; | |
719 | } | |
720 | ||
200c75f0 JH |
721 | static int is_scissors_line(const struct strbuf *line) |
722 | { | |
723 | size_t i, len = line->len; | |
724 | int scissors = 0, gap = 0; | |
725 | int first_nonblank = -1; | |
726 | int last_nonblank = 0, visible, perforation = 0, in_perforation = 0; | |
727 | const char *buf = line->buf; | |
728 | ||
729 | for (i = 0; i < len; i++) { | |
730 | if (isspace(buf[i])) { | |
731 | if (in_perforation) { | |
732 | perforation++; | |
733 | gap++; | |
734 | } | |
735 | continue; | |
736 | } | |
737 | last_nonblank = i; | |
738 | if (first_nonblank < 0) | |
739 | first_nonblank = i; | |
740 | if (buf[i] == '-') { | |
741 | in_perforation = 1; | |
742 | perforation++; | |
743 | continue; | |
744 | } | |
745 | if (i + 1 < len && | |
9974e290 JN |
746 | (!memcmp(buf + i, ">8", 2) || !memcmp(buf + i, "8<", 2) || |
747 | !memcmp(buf + i, ">%", 2) || !memcmp(buf + i, "%<", 2))) { | |
200c75f0 JH |
748 | in_perforation = 1; |
749 | perforation += 2; | |
750 | scissors += 2; | |
751 | i++; | |
752 | continue; | |
753 | } | |
754 | in_perforation = 0; | |
755 | } | |
756 | ||
757 | /* | |
758 | * The mark must be at least 8 bytes long (e.g. "-- >8 --"). | |
759 | * Even though there can be arbitrary cruft on the same line | |
760 | * (e.g. "cut here"), in order to avoid misidentification, the | |
761 | * perforation must occupy more than a third of the visible | |
762 | * width of the line, and dashes and scissors must occupy more | |
763 | * than half of the perforation. | |
764 | */ | |
765 | ||
766 | visible = last_nonblank - first_nonblank + 1; | |
767 | return (scissors && 8 <= visible && | |
768 | visible < perforation * 3 && | |
769 | gap * 2 < perforation); | |
770 | } | |
771 | ||
3b6121f6 | 772 | static int handle_commit_msg(struct strbuf *line) |
d4a9ce78 | 773 | { |
87ab7992 DZ |
774 | static int still_looking = 1; |
775 | ||
d4a9ce78 JH |
776 | if (!cmitmsg) |
777 | return 0; | |
2744b234 | 778 | |
87ab7992 | 779 | if (still_looking) { |
470b4526 | 780 | if (!line->len || (line->len == 1 && line->buf[0] == '\n')) |
3b6121f6 | 781 | return 0; |
d25e5159 LS |
782 | } |
783 | ||
784 | if (use_inbody_headers && still_looking) { | |
200c75f0 JH |
785 | still_looking = check_header(line, s_hdr_data, 0); |
786 | if (still_looking) | |
87ab7992 | 787 | return 0; |
d25e5159 LS |
788 | } else |
789 | /* Only trim the first (blank) line of the commit message | |
790 | * when ignoring in-body headers. | |
791 | */ | |
792 | still_looking = 0; | |
8b4525fb | 793 | |
86747c13 DZ |
794 | /* normalize the log message to UTF-8. */ |
795 | if (metainfo_charset) | |
3b6121f6 | 796 | convert_to_utf8(line, charset.buf); |
86747c13 | 797 | |
017678b4 | 798 | if (use_scissors && is_scissors_line(line)) { |
200c75f0 | 799 | int i; |
1be224ba JH |
800 | if (fseek(cmitmsg, 0L, SEEK_SET)) |
801 | die_errno("Could not rewind output message file"); | |
802 | if (ftruncate(fileno(cmitmsg), 0)) | |
803 | die_errno("Could not truncate output message file at scissors"); | |
200c75f0 JH |
804 | still_looking = 1; |
805 | ||
806 | /* | |
807 | * We may have already read "secondary headers"; purge | |
808 | * them to give ourselves a clean restart. | |
809 | */ | |
810 | for (i = 0; header[i]; i++) { | |
811 | if (s_hdr_data[i]) | |
812 | strbuf_release(s_hdr_data[i]); | |
813 | s_hdr_data[i] = NULL; | |
814 | } | |
815 | return 0; | |
816 | } | |
817 | ||
f0658cf2 | 818 | if (patchbreak(line)) { |
87ab7992 DZ |
819 | fclose(cmitmsg); |
820 | cmitmsg = NULL; | |
821 | return 1; | |
822 | } | |
8b4525fb | 823 | |
3b6121f6 | 824 | fputs(line->buf, cmitmsg); |
d4a9ce78 | 825 | return 0; |
2744b234 LT |
826 | } |
827 | ||
3b6121f6 | 828 | static void handle_patch(const struct strbuf *line) |
2744b234 | 829 | { |
3b6121f6 | 830 | fwrite(line->buf, 1, line->len, patchfile); |
87ab7992 | 831 | patch_lines++; |
2744b234 LT |
832 | } |
833 | ||
3b6121f6 | 834 | static void handle_filter(struct strbuf *line) |
2744b234 | 835 | { |
87ab7992 | 836 | static int filter = 0; |
2744b234 | 837 | |
3b6121f6 | 838 | /* filter tells us which part we left off on */ |
87ab7992 DZ |
839 | switch (filter) { |
840 | case 0: | |
3b6121f6 | 841 | if (!handle_commit_msg(line)) |
d4a9ce78 | 842 | break; |
87ab7992 DZ |
843 | filter++; |
844 | case 1: | |
3b6121f6 LS |
845 | handle_patch(line); |
846 | break; | |
2744b234 LT |
847 | } |
848 | } | |
849 | ||
87ab7992 | 850 | static void handle_body(void) |
1d8fa411 | 851 | { |
3b6121f6 | 852 | struct strbuf prev = STRBUF_INIT; |
d4a9ce78 JH |
853 | |
854 | /* Skip up to the first boundary */ | |
3b6121f6 | 855 | if (*content_top) { |
87ab7992 | 856 | if (!find_boundary()) |
3b6121f6 | 857 | goto handle_body_out; |
87ab7992 DZ |
858 | } |
859 | ||
860 | do { | |
861 | /* process any boundary lines */ | |
3b6121f6 | 862 | if (*content_top && is_multipart_boundary(&line)) { |
87ab7992 | 863 | /* flush any leftover */ |
a9fd1383 JH |
864 | if (prev.len) { |
865 | handle_filter(&prev); | |
866 | strbuf_reset(&prev); | |
867 | } | |
87ab7992 | 868 | if (!handle_boundary()) |
3b6121f6 | 869 | goto handle_body_out; |
87ab7992 DZ |
870 | } |
871 | ||
86747c13 | 872 | /* Unwrap transfer encoding */ |
3b6121f6 | 873 | decode_transfer_encoding(&line); |
87ab7992 DZ |
874 | |
875 | switch (transfer_encoding) { | |
876 | case TE_BASE64: | |
87f1b884 | 877 | case TE_QP: |
87ab7992 | 878 | { |
3b6121f6 LS |
879 | struct strbuf **lines, **it, *sb; |
880 | ||
881 | /* Prepend any previous partial lines */ | |
882 | strbuf_insert(&line, 0, prev.buf, prev.len); | |
883 | strbuf_reset(&prev); | |
87ab7992 | 884 | |
9aa23094 JH |
885 | /* |
886 | * This is a decoded line that may contain | |
87ab7992 DZ |
887 | * multiple new lines. Pass only one chunk |
888 | * at a time to handle_filter() | |
889 | */ | |
3b6121f6 LS |
890 | lines = strbuf_split(&line, '\n'); |
891 | for (it = lines; (sb = *it); it++) { | |
892 | if (*(it + 1) == NULL) /* The last line */ | |
893 | if (sb->buf[sb->len - 1] != '\n') { | |
894 | /* Partial line, save it for later. */ | |
895 | strbuf_addbuf(&prev, sb); | |
896 | break; | |
897 | } | |
898 | handle_filter(sb); | |
899 | } | |
9aa23094 | 900 | /* |
3b6121f6 | 901 | * The partial chunk is saved in "prev" and will be |
9aa23094 | 902 | * appended by the next iteration of read_line_with_nul(). |
87ab7992 | 903 | */ |
3b6121f6 | 904 | strbuf_list_free(lines); |
d4a9ce78 | 905 | break; |
1d8fa411 | 906 | } |
87ab7992 | 907 | default: |
3b6121f6 | 908 | handle_filter(&line); |
d4a9ce78 | 909 | } |
87ab7992 | 910 | |
c8f373a5 | 911 | } while (!strbuf_getwholeline(&line, fin, '\n')); |
3b6121f6 LS |
912 | |
913 | handle_body_out: | |
914 | strbuf_release(&prev); | |
1d8fa411 JH |
915 | } |
916 | ||
3b6121f6 | 917 | static void output_header_lines(FILE *fout, const char *hdr, const struct strbuf *data) |
d7f6bae2 | 918 | { |
3b6121f6 | 919 | const char *sp = data->buf; |
d7f6bae2 | 920 | while (1) { |
3b6121f6 | 921 | char *ep = strchr(sp, '\n'); |
d7f6bae2 JH |
922 | int len; |
923 | if (!ep) | |
3b6121f6 | 924 | len = strlen(sp); |
d7f6bae2 | 925 | else |
3b6121f6 LS |
926 | len = ep - sp; |
927 | fprintf(fout, "%s: %.*s\n", hdr, len, sp); | |
d7f6bae2 JH |
928 | if (!ep) |
929 | break; | |
3b6121f6 | 930 | sp = ep + 1; |
d7f6bae2 JH |
931 | } |
932 | } | |
933 | ||
87ab7992 | 934 | static void handle_info(void) |
2744b234 | 935 | { |
3b6121f6 | 936 | struct strbuf *hdr; |
87ab7992 DZ |
937 | int i; |
938 | ||
939 | for (i = 0; header[i]; i++) { | |
87ab7992 DZ |
940 | /* only print inbody headers if we output a patch file */ |
941 | if (patch_lines && s_hdr_data[i]) | |
942 | hdr = s_hdr_data[i]; | |
943 | else if (p_hdr_data[i]) | |
944 | hdr = p_hdr_data[i]; | |
945 | else | |
946 | continue; | |
947 | ||
b1a013dd | 948 | if (!strcmp(header[i], "Subject")) { |
3b6121f6 LS |
949 | if (!keep_subject) { |
950 | cleanup_subject(hdr); | |
951 | cleanup_space(hdr); | |
d7f6bae2 | 952 | } |
3b6121f6 | 953 | output_header_lines(fout, "Subject", hdr); |
b1a013dd | 954 | } else if (!strcmp(header[i], "From")) { |
ddfb3696 | 955 | cleanup_space(hdr); |
87ab7992 | 956 | handle_from(hdr); |
3b6121f6 LS |
957 | fprintf(fout, "Author: %s\n", name.buf); |
958 | fprintf(fout, "Email: %s\n", email.buf); | |
87ab7992 DZ |
959 | } else { |
960 | cleanup_space(hdr); | |
3b6121f6 | 961 | fprintf(fout, "%s: %s\n", header[i], hdr->buf); |
87ab7992 | 962 | } |
d4a9ce78 | 963 | } |
87ab7992 | 964 | fprintf(fout, "\n"); |
2744b234 LT |
965 | } |
966 | ||
606417bc | 967 | static int mailinfo(FILE *in, FILE *out, const char *msg, const char *patch) |
34488e3c | 968 | { |
f88a545a | 969 | int peek; |
34488e3c LS |
970 | fin = in; |
971 | fout = out; | |
972 | ||
973 | cmitmsg = fopen(msg, "w"); | |
974 | if (!cmitmsg) { | |
975 | perror(msg); | |
976 | return -1; | |
977 | } | |
978 | patchfile = fopen(patch, "w"); | |
979 | if (!patchfile) { | |
980 | perror(patch); | |
981 | fclose(cmitmsg); | |
982 | return -1; | |
983 | } | |
87ab7992 | 984 | |
3b6121f6 LS |
985 | p_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*p_hdr_data)); |
986 | s_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*s_hdr_data)); | |
87ab7992 | 987 | |
f88a545a SS |
988 | do { |
989 | peek = fgetc(in); | |
990 | } while (isspace(peek)); | |
991 | ungetc(peek, in); | |
992 | ||
87ab7992 | 993 | /* process the email header */ |
3b6121f6 LS |
994 | while (read_one_header_line(&line, fin)) |
995 | check_header(&line, p_hdr_data, 1); | |
87ab7992 DZ |
996 | |
997 | handle_body(); | |
998 | handle_info(); | |
34488e3c LS |
999 | |
1000 | return 0; | |
1001 | } | |
1002 | ||
43485d3d JH |
1003 | static int git_mailinfo_config(const char *var, const char *value, void *unused) |
1004 | { | |
59556548 | 1005 | if (!starts_with(var, "mailinfo.")) |
43485d3d JH |
1006 | return git_default_config(var, value, unused); |
1007 | if (!strcmp(var, "mailinfo.scissors")) { | |
1008 | use_scissors = git_config_bool(var, value); | |
1009 | return 0; | |
1010 | } | |
1011 | /* perhaps others here */ | |
1012 | return 0; | |
1013 | } | |
1014 | ||
6bff6a60 | 1015 | static const char mailinfo_usage[] = |
d268cb94 | 1016 | "git mailinfo [-k|-b] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] msg patch < mail >info"; |
d4a9ce78 | 1017 | |
a633fca0 | 1018 | int cmd_mailinfo(int argc, const char **argv, const char *prefix) |
2744b234 | 1019 | { |
bb1091a4 JH |
1020 | const char *def_charset; |
1021 | ||
f1f909e3 JH |
1022 | /* NEEDSWORK: might want to do the optional .git/ directory |
1023 | * discovery | |
1024 | */ | |
43485d3d | 1025 | git_config(git_mailinfo_config, NULL); |
f1f909e3 | 1026 | |
a6fa5992 | 1027 | def_charset = get_commit_output_encoding(); |
bb1091a4 JH |
1028 | metainfo_charset = def_charset; |
1029 | ||
6bff6a60 JH |
1030 | while (1 < argc && argv[1][0] == '-') { |
1031 | if (!strcmp(argv[1], "-k")) | |
1032 | keep_subject = 1; | |
17635fc9 JH |
1033 | else if (!strcmp(argv[1], "-b")) |
1034 | keep_non_patch_brackets_in_subject = 1; | |
d4a9ce78 | 1035 | else if (!strcmp(argv[1], "-u")) |
bb1091a4 JH |
1036 | metainfo_charset = def_charset; |
1037 | else if (!strcmp(argv[1], "-n")) | |
1038 | metainfo_charset = NULL; | |
59556548 | 1039 | else if (starts_with(argv[1], "--encoding=")) |
9f63892b | 1040 | metainfo_charset = argv[1] + 11; |
017678b4 JH |
1041 | else if (!strcmp(argv[1], "--scissors")) |
1042 | use_scissors = 1; | |
1043 | else if (!strcmp(argv[1], "--no-scissors")) | |
1044 | use_scissors = 0; | |
d25e5159 LS |
1045 | else if (!strcmp(argv[1], "--no-inbody-headers")) |
1046 | use_inbody_headers = 0; | |
d4a9ce78 | 1047 | else |
f1f909e3 | 1048 | usage(mailinfo_usage); |
6bff6a60 JH |
1049 | argc--; argv++; |
1050 | } | |
1051 | ||
a196d8d4 | 1052 | if (argc != 3) |
f1f909e3 | 1053 | usage(mailinfo_usage); |
34488e3c | 1054 | |
606417bc | 1055 | return !!mailinfo(stdin, stdout, argv[1], argv[2]); |
2744b234 | 1056 | } |