| 412 | } |
| 413 | |
| 414 | bool mail_message::append_multipart(ofstream& fp) |
| 415 | { |
| 416 | string boundary; |
| 417 | |
| 418 | // ���� MIME ����Ψһ�ָ��� |
| 419 | create_boundary("0001", boundary); |
| 420 | |
| 421 | string buf(8192); |
| 422 | |
| 423 | // ���ʼ�ͷ������ MIME ��ص���Ϣͷ |
| 424 | buf.format("Content-Type: multipart/mixed;\r\n" |
| 425 | "\tcharset=\"%s\";\r\n" |
| 426 | "\tboundary=\"%s\"\r\n\r\n", |
| 427 | charset_, boundary.c_str()); |
| 428 | |
| 429 | const char *prompt = "This is a multi-part message in MIME format."; |
| 430 | buf.format_append("%s\r\n\r\n", prompt); |
| 431 | |
| 432 | // ���������� |
| 433 | if (body_ != NULL) { |
| 434 | buf.format_append("--%s\r\n", boundary.c_str()); |
| 435 | if (!body_->save_to(buf)) { |
| 436 | return false; |
| 437 | } |
| 438 | |
| 439 | buf.append("\r\n"); |
| 440 | } |
| 441 | |
| 442 | if (fp.write(buf) == -1) { |
| 443 | logger_error("write to %s error %s", |
| 444 | fp.file_path(), last_serror()); |
| 445 | return false; |
| 446 | } |
| 447 | |
| 448 | // �����и������ݽ��� BASE64 ��������Ŀ���ļ��� |
| 449 | |
| 450 | mime_base64 base64(true, false); |
| 451 | |
| 452 | std::vector<mail_attach*>::const_iterator cit; |
| 453 | for (cit = attachments_.begin(); cit != attachments_.end(); ++cit) { |
| 454 | if (fp.format("--%s\r\n", boundary.c_str()) == -1) { |
| 455 | logger_error("write boundary to %s error %s", |
| 456 | fp.file_path(), last_serror()); |
| 457 | return false; |
| 458 | } |
| 459 | |
| 460 | if (!(*cit)->save_to(&base64, fp)) { |
| 461 | logger_error("write attachment header to %s error %s", |
| 462 | fp.file_path(), last_serror()); |
| 463 | return false; |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | // �������ķָ������ʼ�β�� |
| 468 | |
| 469 | if (fp.format("--%s--\r\n", boundary.c_str()) == -1) { |
| 470 | logger_error("write boundary end to %s error %s", |
| 471 | fp.file_path(), last_serror()); |