]> mj.ucw.cz Git - checkmail.git/commitdiff
Added parsing of sender addresses and two new options controlling which
authorMartin Mares <mj@ucw.cz>
Mon, 25 Jun 2007 17:22:33 +0000 (19:22 +0200)
committerMartin Mares <mj@ucw.cz>
Mon, 25 Jun 2007 17:22:33 +0000 (19:22 +0200)
parts of the name of the sender get included in the snippet.

charset.c
charset.h
cm.c

index 606d8dc55bf5dc5cdb6a3a19817cc4f97eefd1f5..280e42d1bf9dd827753bc29075100634097bf038 100644 (file)
--- a/charset.c
+++ b/charset.c
@@ -25,6 +25,7 @@
  */
 
 #include "util.h"
+#include "rfc822.h"
 #include "charset.h"
 
 #include <ctype.h>
@@ -378,8 +379,8 @@ charset_init(void)
   debug("Charset is %s\n", system_charset);
 }
 
-static void
-do_add_snippet(char **ppos, char *term, unsigned char *add)
+void
+add_snippet(char **ppos, char *term, char *add)
 {
   char *pos = *ppos;
   int space = 1;
@@ -415,10 +416,51 @@ do_add_snippet(char **ppos, char *term, unsigned char *add)
 }
 
 void
-add_snippet(char **ppos, char *term, char *add)
+add_subject_snippet(char **ppos, char *term, char *add)
 {
   char *buf = xstrdup(add);
   rfc2047_decode(&buf);
-  do_add_snippet(ppos, term, buf);
+  add_snippet(ppos, term, buf);
   free(buf);
 }
+
+void
+add_addr_snippet(char **ppos, char *term, char *add, int add_mbox, int add_personal)
+{
+  ADDRESS *addr = rfc822_parse_adrlist(NULL, add);
+  if (!addr)
+    {
+      debug("%s: Cannot parse address (%s)\n", add, rfc822_error(RFC822Error));
+      add_subject_snippet(ppos, term, add);
+      return;
+    }
+  // debug("%s: pers=%s mbox=%s\n", add, addr->personal, addr->mailbox);
+  rfc2047_decode(&addr->personal);
+  if (!addr->mailbox || !addr->mailbox[0])
+    add_mbox = 0;
+  if (!addr->personal || !addr->personal[0])
+    {
+      if (addr->mailbox && addr->mailbox[0])
+       {
+         char *c = strchr(addr->mailbox, '@');
+         if (c)
+           *c = 0;
+         add_mbox = 1;
+       }
+      add_personal = 0;
+    }
+  if (add_mbox || add_personal)
+    {
+      if (add_personal)
+       add_snippet(ppos, term, addr->personal);
+      if (add_mbox && add_personal)
+       add_snippet(ppos, term, " <");
+      if (add_mbox)
+       add_snippet(ppos, term, addr->mailbox);
+      if (add_mbox && add_personal)
+       add_snippet(ppos, term, ">");
+    }
+  else
+    add_snippet(ppos, term, "???");
+  rfc822_free_address(&addr);
+}
index bb3bf27a79d33f500a6d3a35f7c77fc03701cdab..32f628ad97eea12ef17c92dda112ea55f8935c39 100644 (file)
--- a/charset.h
+++ b/charset.h
@@ -1,4 +1,6 @@
-/* Charset handling */
+/* Charset conversion and text snippets */
 
+void add_subject_snippet(char **ppos, char *term, char *add);
+void add_addr_snippet(char **ppos, char *term, char *add, int add_mbox, int add_personal);
 void add_snippet(char **ppos, char *term, char *add);
 void charset_init(void);
diff --git a/cm.c b/cm.c
index 963fe049541f4b031d53c3fc5e20f70bc3e97600..36a29e9145e86904a10acb9bac8d0788cad1f56c 100644 (file)
--- a/cm.c
+++ b/cm.c
@@ -37,6 +37,8 @@ struct options {
   int beep;
   int snippets;
   int show_flagged;
+  int sender_personal;
+  int sender_mbox;
 };
 
 struct option_node {
@@ -52,7 +54,9 @@ struct pattern_node {
 };
 
 static clist options, patterns;
-static struct options global_options;
+static struct options global_options = {
+  .sender_personal = 1
+};
 
 struct mbox {
   cnode n;
@@ -115,6 +119,8 @@ init_options(struct options *o)
   o->highlight = -1;
   o->snippets = -1;
   o->show_flagged = -1;
+  o->sender_personal = -1;
+  o->sender_mbox = -1;
 }
 
 static void
@@ -133,6 +139,8 @@ setup_options(struct mbox *b)
        MERGE(beep);
        MERGE(snippets);
        MERGE(show_flagged);
+       MERGE(sender_personal);
+       MERGE(sender_mbox);
       }
 }
 
@@ -214,13 +222,13 @@ prepare_snippet(struct mbox *b, char *sender, char *subject)
 
   char *pos = b->snippet;
   char *term = b->snippet + sizeof(b->snippet) - 1;
-  if (sender[0])
+  if (sender[0] && (b->o.sender_mbox || b->o.sender_personal))
     {
-      add_snippet(&pos, term, sender);
+      add_addr_snippet(&pos, term, sender, b->o.sender_mbox, b->o.sender_personal);
       add_snippet(&pos, term, ": ");
     }
   if (subject[0])
-    add_snippet(&pos, term, subject);
+    add_subject_snippet(&pos, term, subject);
   else
     add_snippet(&pos, term, "No subject");
 }
@@ -795,6 +803,8 @@ b\t\t\tBeep when a message arrives\n\
 e\t\t\tHide from display if empty\n\
 f\t\t\tShow flagged messages if there are no new ones\n\
 h\t\t\tHide from display\n\
+m\t\t\tShow mailbox name of the sender\n\
+p\t\t\tShow personal info (full name) of the sender\n\
 s\t\t\tShow message snippets\n\
 t\t\t\tHighlight the entry\n\
 \n\
@@ -843,6 +853,12 @@ parse_options(char *c)
          case 'h':
            o->hide = value;
            break;
+         case 'm':
+           o->sender_mbox = value;
+           break;
+         case 'p':
+           o->sender_personal = value;
+           break;
          case 's':
            o->snippets = value;
            break;