]> code.citadel.org Git - citadel.git/blobdiff - citadel/server/modules/smtp/dkim.c
Remove whitespace at end of canonicalized header lines
[citadel.git] / citadel / server / modules / smtp / dkim.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));
 }