]> diplodocus.org Git - mdfrm/commitdiff
Apply patch from Doug Porter to compare headers case-insensitively and
authorepg <>
Mon, 8 Mar 2004 01:40:48 +0000 (01:40 +0000)
committerepg <>
Mon, 8 Mar 2004 01:40:48 +0000 (01:40 +0000)
trim leading whitespace on the From and Subject values printed.

mdfrm.c

diff --git a/mdfrm.c b/mdfrm.c
index 319bb07dea2e3b9747825d29ed626e1ab2126c0c..8977cdd0899c12d737fcf3c818137f00d467835d 100644 (file)
--- a/mdfrm.c
+++ b/mdfrm.c
@@ -7,6 +7,7 @@
 
 #include <sys/types.h>
 
 
 #include <sys/types.h>
 
+#include <ctype.h>
 #include <dirent.h>
 #include <err.h>
 #include <stdio.h>
 #include <dirent.h>
 #include <err.h>
 #include <stdio.h>
@@ -25,8 +26,8 @@
 #endif
 
 enum {
 #endif
 
 enum {
-    FROMLEN = 6,                /* "From: " */
-    SUBJLEN = 9,                /* "Subject: " */
+    FROMLEN = 5,                /* "From:" */
+    SUBJLEN = 8,                /* "Subject:" */
 
     /* Number of characters for each field we actually output.  This
      * must also be changed in the printf functions at the end of the
 
     /* Number of characters for each field we actually output.  This
      * must also be changed in the printf functions at the end of the
@@ -57,9 +58,13 @@ scan_message(char *filename, char *fromheader, char *subjheader)
         }
         --len;
 
         }
         --len;
 
-        if (len > FROMLEN && strncmp(line, "From: ", FROMLEN) == 0) {
+        if (len > FROMLEN && strncasecmp(line, "From:", FROMLEN) == 0) {
             line += FROMLEN;
             len -= FROMLEN;
             line += FROMLEN;
             len -= FROMLEN;
+            while (len > 0 && isspace(line[0])) {
+                line++;
+                len--;
+            }
             if (len < FROMCOUNT) {
                 fromcount = len;
             } else {
             if (len < FROMCOUNT) {
                 fromcount = len;
             } else {
@@ -67,9 +72,13 @@ scan_message(char *filename, char *fromheader, char *subjheader)
             }
             strncpy(fromheader, line, fromcount);
             fromheader[fromcount] = '\0';
             }
             strncpy(fromheader, line, fromcount);
             fromheader[fromcount] = '\0';
-        } else if (len > SUBJLEN && strncmp(line, "Subject: ", SUBJLEN) == 0) {
+        } else if (len > SUBJLEN && strncasecmp(line, "Subject:", SUBJLEN) == 0) {
             line += SUBJLEN;
             len -= SUBJLEN;
             line += SUBJLEN;
             len -= SUBJLEN;
+            while (len > 0 && isspace(line[0])) {
+                line++;
+                len--;
+            }
             if (len < SUBJCOUNT) {
                 subjcount = len;
             } else {
             if (len < SUBJCOUNT) {
                 subjcount = len;
             } else {