| 475 | } |
| 476 | |
| 477 | static void decode_header(struct mailinfo *mi, struct strbuf *it) |
| 478 | { |
| 479 | char *in, *ep, *cp; |
| 480 | struct strbuf outbuf = STRBUF_INIT, dec = STRBUF_INIT; |
| 481 | struct strbuf charset_q = STRBUF_INIT, piecebuf = STRBUF_INIT; |
| 482 | int found_error = 1; /* pessimism */ |
| 483 | |
| 484 | in = it->buf; |
| 485 | while (in - it->buf <= it->len && (ep = strstr(in, "=?")) != NULL) { |
| 486 | int encoding; |
| 487 | strbuf_reset(&charset_q); |
| 488 | strbuf_reset(&piecebuf); |
| 489 | |
| 490 | if (in != ep) { |
| 491 | /* |
| 492 | * We are about to process an encoded-word |
| 493 | * that begins at ep, but there is something |
| 494 | * before the encoded word. |
| 495 | */ |
| 496 | char *scan; |
| 497 | for (scan = in; scan < ep; scan++) |
| 498 | if (!isspace(*scan)) |
| 499 | break; |
| 500 | |
| 501 | if (scan != ep || in == it->buf) { |
| 502 | /* |
| 503 | * We should not lose that "something", |
| 504 | * unless we have just processed an |
| 505 | * encoded-word, and there is only LWS |
| 506 | * before the one we are about to process. |
| 507 | */ |
| 508 | strbuf_add(&outbuf, in, ep - in); |
| 509 | } |
| 510 | } |
| 511 | /* E.g. |
| 512 | * ep : "=?iso-2022-jp?B?GyR...?= foo" |
| 513 | * ep : "=?ISO-8859-1?Q?Foo=FCbar?= baz" |
| 514 | */ |
| 515 | ep += 2; |
| 516 | |
| 517 | if (ep - it->buf >= it->len || !(cp = strchr(ep, '?'))) |
| 518 | goto release_return; |
| 519 | |
| 520 | if (cp + 3 - it->buf > it->len) |
| 521 | goto release_return; |
| 522 | strbuf_add(&charset_q, ep, cp - ep); |
| 523 | |
| 524 | encoding = cp[1]; |
| 525 | if (!encoding || cp[2] != '?') |
| 526 | goto release_return; |
| 527 | ep = strstr(cp + 3, "?="); |
| 528 | if (!ep) |
| 529 | goto release_return; |
| 530 | strbuf_add(&piecebuf, cp + 3, ep - cp - 3); |
| 531 | switch (tolower(encoding)) { |
| 532 | default: |
| 533 | goto release_return; |
| 534 | case 'b': |
no test coverage detected