Remove whitespace at end of canonicalized header lines master
authorArt Cancro <ajc@citadel.org>
Sun, 12 May 2024 20:24:32 +0000 (20:24 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 12 May 2024 20:24:32 +0000 (20:24 +0000)
citadel/server/modules/smtp/dkim.c
citadel/tests/dkimtester/dkimtester.c

index 0ee289e73580d2f22009bf0c6e8a8bc8963a2116..81cf04d1a49c7f3712d8f9a1f5042078a9564f63 100644 (file)
@@ -255,6 +255,20 @@ void dkim_canonicalize_unfolded_headers(StrBuf *headers) {
                }
                char *end_of_this_line = strstr(ptr, "\r\n");
 
+               // remove whitespace at the end of the line
+               int replaced_something;
+               do {
+                       replaced_something = 0;
+                       char *trailing_space = strstr(ptr, " \r\n");            // line ends in a space?
+                       if (!trailing_space) {                                  // no?
+                               trailing_space = strstr(ptr, "\t\r\n");         // how about a tab?
+                       }
+                       if (trailing_space) {
+                               StrBufReplaceToken(headers, (long)(trailing_space-cheaders), 3, HKEY("\r\n"));
+                               ++replaced_something;
+                       }
+               } while (replaced_something);
+
                // Convert header field names to all lower case
                for (char *c = start_of_this_line; c<colon; ++c) {
                        cheaders[c-cheaders] = tolower(cheaders[c-cheaders]);
@@ -262,6 +276,7 @@ void dkim_canonicalize_unfolded_headers(StrBuf *headers) {
 
                ptr = end_of_this_line + 2;                                     // Advance to the beginning of the next line
        }
+       fprintf(stderr, "\033[7m%s\033[0m", (char *)ChrPtr(headers));
 }
 
 
index b54c9047a81381870d3b710a1fcb10d81d899e31..f255e141dda430d622e0927e7bec1b26ab40b460 100644 (file)
@@ -62,7 +62,7 @@ int main(int argc, char *argv[]) {
                "From: Fred Bloggs <bloggs@dev.citadel.org>\r\n"
                "X-irrelevant-header: wow mom 303\r\n"
                "To: Bread Floggs <bf@example.com>\r\n"
-               "Subject: The ultimate test message!\r\n"
+               "Subject: The ultimate test message!      \r\n"
                "Message-ID: <73294856-8726543-473298@dev.citadel.org>\r\n"
                "\r\n"
                "Hi.\r\n"
@@ -70,6 +70,8 @@ int main(int argc, char *argv[]) {
                "Bhille Disassemble.  Highly recommend.\r\n"
                "\r\n"
                "--Fred\r\n"
+
+
        ));
 
        // create signature