]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
write mail: fix regression regarding RFC 5321
authorBaptiste Daroussin <bapt@FreeBSD.org>
Thu, 9 Nov 2023 10:20:41 +0000 (11:20 +0100)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Thu, 9 Nov 2023 10:24:32 +0000 (11:24 +0100)
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.

src/mail-functions.c
tests/mlmmj.c

index 393885ce808b66be44ba6b8638b76c95a8fd80bf..d51dfa449b3c33ef8f317653134d1ca32896f495 100644 (file)
@@ -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;
index bdc3b3e3c91a2e707765267d39f07206ae8f9364..764f26f727ef9524f81b10ece929917201b60dca 100644 (file)
@@ -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 .)");
        }