Removed the condition on the preceding blank line for mail separation.
authorFrancois Fleuret <francois@fleuret.org>
Wed, 6 Feb 2013 21:55:55 +0000 (22:55 +0100)
committerFrancois Fleuret <francois@fleuret.org>
Wed, 6 Feb 2013 21:55:55 +0000 (22:55 +0100)
mymail.c

index 5d16bb3..b890b4b 100644 (file)
--- a/mymail.c
+++ b/mymail.c
@@ -232,9 +232,22 @@ int ignore_entry(const char *name) {
     (name[0] == '.' && name[1] != '/');
 }
 
-int is_a_leading_from_line(char *s) {
-  return strncmp(s, "From ", 5) == 0 &&
-    regexec(&leading_from_line_regexp, s, 0, 0, 0) == 0;
+int is_a_leading_from_line(int last_mbox_line_was_empty, char *mbox_line) {
+  return
+
+    /*
+
+      The mbox man page in qmail documentation states:
+
+       > The reader should not attempt to take advantage of the fact
+       > that every From_ line (past the beginning of the file) is
+       > preceded by a blank line.
+
+    */
+
+    /* last_mbox_line_was_empty && */
+    strncmp(mbox_line, "From ", 5) == 0 &&
+    regexec(&leading_from_line_regexp, mbox_line, 0, 0, 0) == 0;
 }
 
 int mbox_line_match_search(struct search_condition *condition,
@@ -321,8 +334,7 @@ void update_body_hits(char *mail_filename, int position_in_mail,
       }
 
       if(!fgets(raw_mbox_line, BUFFER_SIZE, mail_file) ||
-         (last_mbox_line_was_empty &&
-          is_a_leading_from_line(raw_mbox_line)))
+         (is_a_leading_from_line(last_mbox_line_was_empty, raw_mbox_line)))
         break;
     }
   }
@@ -444,8 +456,7 @@ void search_in_db(const char *db_filename,
               fprintf(output_file, "%s", raw_mbox_line);
               while(1) {
                 if(!fgets(raw_mbox_line, BUFFER_SIZE, mail_file) ||
-                   (last_mbox_line_was_empty &&
-                    is_a_leading_from_line(raw_mbox_line))
+                   (is_a_leading_from_line(last_mbox_line_was_empty, raw_mbox_line))
                    )
                   break;
                 last_mbox_line_was_empty = (raw_mbox_line[0] == '\n');
@@ -571,8 +582,7 @@ void index_mbox(const char *mbox_filename,
   last_mbox_line_was_empty = 1;
 
   while(fgets(raw_mbox_line, BUFFER_SIZE, file)) {
-    if(last_mbox_line_was_empty &&
-       is_a_leading_from_line(raw_mbox_line)) {
+    if(is_a_leading_from_line(last_mbox_line_was_empty, raw_mbox_line)) {
       if(in_header) {
         fprintf(stderr,
                 "Got a ^\"From \" in the header in %s:%lu.\n",