From 47a39cf3eb2172230625cdbca9513bce688e0ec3 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 25 Jun 2007 19:22:33 +0200 Subject: [PATCH] Added parsing of sender addresses and two new options controlling which parts of the name of the sender get included in the snippet. --- charset.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- charset.h | 4 +++- cm.c | 24 ++++++++++++++++++++---- 3 files changed, 69 insertions(+), 9 deletions(-) diff --git a/charset.c b/charset.c index 606d8dc..280e42d 100644 --- a/charset.c +++ b/charset.c @@ -25,6 +25,7 @@ */ #include "util.h" +#include "rfc822.h" #include "charset.h" #include @@ -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); +} diff --git a/charset.h b/charset.h index bb3bf27..32f628a 100644 --- 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 963fe04..36a29e9 100644 --- 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; -- 2.39.2