(smtp_send_message): Use header
Use header and body streams sequentially instead of using message stream. This allows to catch the modified/added headers.
Showing
1 changed file
with
33 additions
and
1 deletions
... | @@ -696,16 +696,21 @@ smtp_send_message (mailer_t mailer, message_t argmsg, address_t argfrom, | ... | @@ -696,16 +696,21 @@ smtp_send_message (mailer_t mailer, message_t argmsg, address_t argfrom, |
696 | stream_t stream; | 696 | stream_t stream; |
697 | size_t n = 0; | 697 | size_t n = 0; |
698 | char data[256] = ""; | 698 | char data[256] = ""; |
699 | header_t hdr; | ||
700 | body_t body; | ||
701 | int found_nl; | ||
699 | 702 | ||
700 | /* We may be here after an EAGAIN so check if we have something | 703 | /* We may be here after an EAGAIN so check if we have something |
701 | in the buffer and flush it. */ | 704 | in the buffer and flush it. */ |
702 | status = smtp_write (smtp); | 705 | status = smtp_write (smtp); |
703 | CHECK_EAGAIN (smtp, status); | 706 | CHECK_EAGAIN (smtp, status); |
704 | 707 | ||
705 | message_get_stream (smtp->msg, &stream); | 708 | message_get_header (smtp->msg, &hdr); |
709 | header_get_stream (hdr, &stream); | ||
706 | while ((status = stream_readline (stream, data, sizeof (data) - 1, | 710 | while ((status = stream_readline (stream, data, sizeof (data) - 1, |
707 | smtp->offset, &n)) == 0 && n > 0) | 711 | smtp->offset, &n)) == 0 && n > 0) |
708 | { | 712 | { |
713 | found_nl = (n == 1 && data[0] == '\n'); | ||
709 | if (data[n - 1] == '\n') | 714 | if (data[n - 1] == '\n') |
710 | data[n - 1] = '\0'; | 715 | data[n - 1] = '\0'; |
711 | if (data[0] == '.') | 716 | if (data[0] == '.') |
... | @@ -723,6 +728,33 @@ smtp_send_message (mailer_t mailer, message_t argmsg, address_t argfrom, | ... | @@ -723,6 +728,33 @@ smtp_send_message (mailer_t mailer, message_t argmsg, address_t argfrom, |
723 | } | 728 | } |
724 | smtp->offset += n; | 729 | smtp->offset += n; |
725 | } | 730 | } |
731 | |||
732 | if (!found_nl) | ||
733 | { | ||
734 | status = smtp_writeline (smtp, "\r\n"); | ||
735 | CHECK_ERROR (smtp, status); | ||
736 | status = smtp_write (smtp); | ||
737 | CHECK_EAGAIN (smtp, status); | ||
738 | } | ||
739 | |||
740 | message_get_body (smtp->msg, &body); | ||
741 | body_get_stream (body, &stream); | ||
742 | smtp->offset = 0; | ||
743 | while ((status = stream_readline (stream, data, sizeof (data) - 1, | ||
744 | smtp->offset, &n)) == 0 && n > 0) | ||
745 | { | ||
746 | if (data[n - 1] == '\n') | ||
747 | data[n - 1] = '\0'; | ||
748 | if (data[0] == '.') | ||
749 | status = smtp_writeline (smtp, ".%s\r\n", data); | ||
750 | else | ||
751 | status = smtp_writeline (smtp, "%s\r\n", data); | ||
752 | CHECK_ERROR (smtp, status); | ||
753 | status = smtp_write (smtp); | ||
754 | CHECK_EAGAIN (smtp, status); | ||
755 | smtp->offset += n; | ||
756 | } | ||
757 | |||
726 | smtp->offset = 0; | 758 | smtp->offset = 0; |
727 | status = smtp_writeline (smtp, ".\r\n"); | 759 | status = smtp_writeline (smtp, ".\r\n"); |
728 | CHECK_ERROR (smtp, status); | 760 | CHECK_ERROR (smtp, status); | ... | ... |
-
Please register or sign in to post a comment