From: Baptiste Daroussin Date: Thu, 9 Nov 2023 10:20:41 +0000 (+0100) Subject: write mail: fix regression regarding RFC 5321 X-Git-Tag: RELEASE_1_4_0rc3~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b502a85f5bc6f12c24950e20f424e4be2b831dec;p=thirdparty%2Fmlmmj.git write mail: fix regression regarding RFC 5321 if a line on the email to write only contains a dot, then the dot should be doubled otherwise the mail server will consider it as the end of the DATA and will prematurely terminate the email. --- diff --git a/src/mail-functions.c b/src/mail-functions.c index 393885ce..d51dfa44 100644 --- a/src/mail-functions.c +++ b/src/mail-functions.c @@ -90,6 +90,12 @@ write_mailbody(int sockfd, FILE *fp, const char *tohdr) } next = fgetc(fp); dprintf(sockfd, "\r\n"); + if (next == '.') { + c = fgetc(fp); + if (c == EOF || c == '\n') + dprintf(sockfd, "."); + ungetc(c, fp); + } if (addhdr && tohdr != NULL && next == '\n') { dprintf(sockfd, "To: %s\r\n", tohdr); addhdr = false; diff --git a/tests/mlmmj.c b/tests/mlmmj.c index bdc3b3e3..764f26f7 100644 --- a/tests/mlmmj.c +++ b/tests/mlmmj.c @@ -590,7 +590,7 @@ ATF_TC_BODY(write_mailbody, tc) atf_tc_fail("Unexpected output (a single new line)"); } - /* With a single new line with a . */ + /* With a single new line with a single . */ atf_utils_create_file("myemailbody.txt", "line\n."); fp = fopen("myemailbody.txt", "r"); ATF_REQUIRE(fp != NULL); @@ -598,7 +598,20 @@ ATF_TC_BODY(write_mailbody, tc) write_mailbody(fd, fp, "test@plop.meh"); close(fd); fclose(fp); - if (!atf_utils_compare_file("out.txt", "line\r\n.")) { + if (!atf_utils_compare_file("out.txt", "line\r\n..")) { + atf_utils_cat_file("out.txt", ">"); + atf_tc_fail("Unexpected output (single new line with a .)"); + } + + /* New line starting with a dot */ + atf_utils_create_file("myemailbody.txt", "line\n.no"); + fp = fopen("myemailbody.txt", "r"); + ATF_REQUIRE(fp != NULL); + fd = open("out.txt", O_CREAT|O_TRUNC|O_WRONLY, 0644); + write_mailbody(fd, fp, "test@plop.meh"); + close(fd); + fclose(fp); + if (!atf_utils_compare_file("out.txt", "line\r\n.no")) { atf_utils_cat_file("out.txt", ">"); atf_tc_fail("Unexpected output (single new line with a .)"); }