Try to gather originator information from the From_ line if there is
authorJoey Schulze <joey@infodrom.org>
Tue, 23 Nov 2004 09:39:43 +0000 (09:39 +0000)
committerJoey Schulze <joey@infodrom.org>
Tue, 23 Nov 2004 09:39:43 +0000 (09:39 +0000)
no From: line in the header.

mbox.c

diff --git a/mbox.c b/mbox.c
index 15887f7..c9791a4 100644 (file)
--- a/mbox.c
+++ b/mbox.c
@@ -128,6 +128,23 @@ char *realname(char *from)
   return name;
 }
 
+/*
+ * Tries to extract useful content from the From_ line
+ */
+char *reduce_from_(char *from_)
+{
+  static char name[HDR_LEN];
+  char *cpl, *cpr;
+
+  for (cpl=from_; *cpl &&  isspace(*cpl); cpl++);
+  for (cpr=cpl;   *cpr && !isspace(*cpr); cpr++);
+
+  if (cpr > cpl)
+    stringcopy(name, cpl, 
+              sizeof(name) < cpr-cpl+1?sizeof(name):cpr-cpl+1);
+  return name;
+}
+
 int inspect_mbox(char *path, char *prefix, off_t size, int opt_flags)
 {
   FILE *f;
@@ -158,6 +175,8 @@ int inspect_mbox(char *path, char *prefix, off_t size, int opt_flags)
       continue;
     if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n') {
       buf[strlen(buf)-1] = '\0';
+      if (strlen(buf) > 0 && buf[strlen(buf)-1] == '\r')
+       buf[strlen(buf)-1] = '\0';
     } else {
       while (!feof(f) && fgets(tmp, sizeof(tmp), f) != NULL) {
        if (strlen(tmp) > 0 && tmp[strlen(tmp)-1] == '\n')
@@ -172,10 +191,8 @@ int inspect_mbox(char *path, char *prefix, off_t size, int opt_flags)
 
        if (strlen(from))
          stringcopy(realfrom, realname(from), sizeof(realfrom));
-#ifdef todo
        else
          stringcopy(realfrom, reduce_from_(from_), sizeof(realfrom));
-#endif
 
        emit(prefix, realfrom, subject, priority, opt_flags);