| 386 | } |
| 387 | |
| 388 | bool rfc2047::decode_finish(const char* toCharset, |
| 389 | string* out, bool addInvalid /* = true */) |
| 390 | { |
| 391 | std::list<rfc2047_entry*>::const_iterator cit = m_List.begin(); |
| 392 | string buf1; |
| 393 | string buf2; |
| 394 | mime_base64 base64; |
| 395 | mime_quoted_printable qp; |
| 396 | |
| 397 | // ѡ��һ��Ĭ�ϵĽ�������Ȼ�������Ҫ�仯 |
| 398 | mime_code* pDecoder = &base64; |
| 399 | const char *fromCharset = NULL; |
| 400 | charset_conv conv; |
| 401 | conv.set_add_invalid(addInvalid); |
| 402 | |
| 403 | for (; cit != m_List.end(); ++cit) { |
| 404 | if ((*cit)->coding == 'Q') { |
| 405 | if (pDecoder != &qp || !EQ((*cit)->pCharset->c_str(), fromCharset)) { |
| 406 | if (fromCharset == NULL) { |
| 407 | fromCharset = (*cit)->pCharset->c_str(); |
| 408 | } |
| 409 | if (*fromCharset == 0) { |
| 410 | fromCharset = NULL; |
| 411 | } |
| 412 | if (fromCharset == NULL || toCharset == NULL) { |
| 413 | decoder_finish(pDecoder, NULL, out, |
| 414 | &buf1, &buf2); |
| 415 | } else { |
| 416 | conv.update_begin(fromCharset, toCharset); |
| 417 | decoder_finish(pDecoder, &conv, out, |
| 418 | &buf1, &buf2); |
| 419 | } |
| 420 | pDecoder->reset(); |
| 421 | } |
| 422 | pDecoder = &qp; // qp ���� |
| 423 | fromCharset = (*cit)->pCharset->c_str(); |
| 424 | if (*fromCharset == 0) { |
| 425 | fromCharset = NULL; |
| 426 | } |
| 427 | decoder_update(*cit, fromCharset, toCharset, |
| 428 | pDecoder, &conv, out, &buf1, &buf2); |
| 429 | } else if ((*cit)->coding == 'B') { |
| 430 | if (pDecoder != &base64 || !EQ((*cit)->pCharset->c_str(), fromCharset)) { |
| 431 | if (fromCharset == NULL) { |
| 432 | fromCharset = (*cit)->pCharset->c_str(); |
| 433 | } |
| 434 | if (*fromCharset == 0) { |
| 435 | fromCharset = NULL; |
| 436 | } |
| 437 | if (fromCharset == NULL && toCharset == NULL) { |
| 438 | decoder_finish(pDecoder, NULL, out, |
| 439 | &buf1, &buf2); |
| 440 | } else { |
| 441 | conv.update_begin(fromCharset, toCharset); |
| 442 | decoder_finish(pDecoder, &conv, out, |
| 443 | &buf1, &buf2); |
| 444 | } |
| 445 | pDecoder->reset(); |
no test coverage detected