From f81a5a37a8c492f1061c8cca886d820acc9e3fb6 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Wed, 5 Dec 2012 23:44:38 +0100 Subject: [PATCH] Choose default sender email address by envelope recipient - propagate the stored 'enVelopeto' to the citadel protocol as 'nvto' header; nvto may contain several recipients. - add handlers to read nvto in webcit - evaluate which should be the prefered chosen default sender while loading the GVEA Hash instead of while rendering the template - if we are replying to an email, base choice on the nvto-header if it exists. - in all other cases use the preference chosen in the prefs-screen --- citadel/msgbase.c | 50 ++++++++++--------- webcit/messages.c | 9 +++- webcit/messages.h | 1 + webcit/msg_renderers.c | 17 +++++++ webcit/preferences.c | 45 ++++++++++++++++- .../prefs/section_msg_sender_from_select.html | 2 +- 6 files changed, 96 insertions(+), 28 deletions(-) diff --git a/citadel/msgbase.c b/citadel/msgbase.c index f44dfe66c..dc407afdc 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -88,30 +88,32 @@ char *msgkeys[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - "from", - NULL, NULL, NULL, - "exti", - "rfca", - NULL, - "hnod", - "msgn", - "jrnl", - "rep2", - "list", - "text", - "node", - "room", - "path", - NULL, - "rcpt", - "spec", - "time", - "subj", - NULL, - "wefw", - NULL, - "cccc", - NULL + "from", /* A */ + NULL, /* B */ + NULL, /* C */ + NULL, /* D */ + "exti", /* E */ + "rfca", /* F */ + NULL, /* G */ + "hnod", /* H */ + "msgn", /* I */ + "jrnl", /* J */ + "rep2", /* K */ + "list", /* L */ + "text", /* M */ + "node", /* N */ + "room", /* O */ + "path", /* P */ + NULL, /* Q */ + "rcpt", /* R */ + "spec", /* S */ + "time", /* T */ + "subj", /* U */ + "nvto", /* V */ + "wefw", /* W */ + NULL, /* X */ + "cccc", /* Y */ + NULL /* Z */ }; /* diff --git a/webcit/messages.c b/webcit/messages.c index 6da0b55aa..4e45ea696 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -1335,6 +1335,7 @@ long l_cccc; long l_replyto; long l_node; long l_rfca; +long l_nvto; const char *ReplyToModeStrings [3] = { "reply", @@ -1454,6 +1455,7 @@ void display_enter(void) StrBuf *rcpt = NULL; StrBuf *cccc = NULL; StrBuf *replyto = NULL; + StrBuf *nvto = NULL; serv_printf("MSG0 %ld|1", replying_to); StrBuf_ServGetln(Line); @@ -1539,7 +1541,7 @@ void display_enter(void) } else if (which == l_replyto) { replyto = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5); - } + } else if (which == l_rfca) { StrBuf *FlatRFCA; rfca = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5); @@ -1548,6 +1550,10 @@ void display_enter(void) FreeStrBuf(&rfca); rfca = FlatRFCA; } + else if (which == l_nvto) { + nvto = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5); + putbstr("nvto", nvto); + } } @@ -2071,6 +2077,7 @@ InitModule_MSG l_replyto = FourHash("rep2", 4); l_node = FourHash("node", 4); l_rfca = FourHash("rfca", 4); + l_nvto = FourHash("nvto", 4); return ; } diff --git a/webcit/messages.h b/webcit/messages.h index e8ba1a3f7..050117b0e 100644 --- a/webcit/messages.h +++ b/webcit/messages.h @@ -47,6 +47,7 @@ typedef struct _message_summary { StrBuf *AllRcpt; StrBuf *Room; StrBuf *Rfca; + StrBuf *EnvTo; StrBuf *OtherNode; const StrBuf *PartNum; diff --git a/webcit/msg_renderers.c b/webcit/msg_renderers.c index 47d749b26..50a0f2271 100644 --- a/webcit/msg_renderers.c +++ b/webcit/msg_renderers.c @@ -51,6 +51,7 @@ void DestroyMessageSummary(void *vMsg) FreeStrBuf(&Msg->AllRcpt); FreeStrBuf(&Msg->Room); FreeStrBuf(&Msg->Rfca); + FreeStrBuf(&Msg->EnvTo); FreeStrBuf(&Msg->OtherNode); DeleteHash(&Msg->Attachments); /* list of Attachments */ @@ -484,6 +485,21 @@ int Conditional_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP) return StrLength(Msg->OtherNode) > 0; } +void examine_nvto(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) +{ + wcsession *WCC = WC; + + CheckConvertBufs(WCC); + FreeStrBuf(&Msg->EnvTo); + Msg->EnvTo = NewStrBufPlain(NULL, StrLength(HdrLine)); + StrBuf_RFC822_2_Utf8(Msg->EnvTo, + HdrLine, + WCC->DefaultCharset, + FoundCharset, + WCC->ConvertBuf1, + WCC->ConvertBuf2); +} + void examine_rcpt(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) { @@ -1598,6 +1614,7 @@ InitModule_MSGRENDERERS RegisterMsgHdr(HKEY("rfca"), examine_rfca, 0); RegisterMsgHdr(HKEY("node"), examine_node, 0); RegisterMsgHdr(HKEY("rcpt"), examine_rcpt, 0); + RegisterMsgHdr(HKEY("nvto"), examine_nvto, 0); RegisterMsgHdr(HKEY("time"), examine_time, 0); RegisterMsgHdr(HKEY("part"), examine_mime_part, 0); RegisterMsgHdr(HKEY("text"), examine_text, 1); diff --git a/webcit/preferences.c b/webcit/preferences.c index 260bdc7b3..1155a182d 100644 --- a/webcit/preferences.c +++ b/webcit/preferences.c @@ -1003,6 +1003,28 @@ int ConditionalHasPreference(StrBuf *Target, WCTemplputParams *TP) /******************************************************************************** * preferences stored discrete in citserver ********************************************************************************/ +CtxType CTX_VEA = CTX_NONE; +typedef struct __ValidEmailAddress { + StrBuf *Address; + int IsDefault; +}ValidEmailAddress; + +void DeleteValidEmailAddress(void *v) +{ + ValidEmailAddress *VEA = (ValidEmailAddress*)v; + FreeStrBuf(&VEA->Address); + free(VEA); +} +void tmplput_VEA(StrBuf *Target, WCTemplputParams *TP) +{ + ValidEmailAddress* VEA = (ValidEmailAddress*) CTX((CTX_VEA)); + StrBufAppendTemplate(Target, TP, VEA->Address, 0); +} +int ConditionalPreferenceIsDefaulVEA(StrBuf *Target, WCTemplputParams *TP) +{ + ValidEmailAddress* VEA = (ValidEmailAddress*) CTX((CTX_VEA)); + return VEA->IsDefault; +} HashList *GetGVEAHash(StrBuf *Target, WCTemplputParams *TP) { StrBuf *Rcp; @@ -1010,7 +1032,12 @@ HashList *GetGVEAHash(StrBuf *Target, WCTemplputParams *TP) int Done = 0; int i, n = 1; char N[64]; + StrBuf *DefaultFrom = NULL; + const StrBuf *EnvelopeTo; + ValidEmailAddress *VEA; + get_preference("defaultfrom", &DefaultFrom); + EnvelopeTo = sbstr("nvto"); Rcp = NewStrBuf(); serv_puts("GVEA"); StrBuf_ServGetln(Rcp); @@ -1024,9 +1051,18 @@ HashList *GetGVEAHash(StrBuf *Target, WCTemplputParams *TP) Done = 1; } else { + VEA = (ValidEmailAddress*) malloc(sizeof(ValidEmailAddress)); i = snprintf(N, sizeof(N), "%d", n); StrBufTrim(Rcp); - Put(List, N, i, Rcp, HFreeStrBuf); + VEA->Address = Rcp; + if (EnvelopeTo != NULL) + VEA->IsDefault = strstr(ChrPtr(EnvelopeTo), ChrPtr(Rcp)) != NULL; + else if (DefaultFrom != NULL) + VEA->IsDefault = !strcmp(ChrPtr(Rcp), ChrPtr(DefaultFrom)); + else + VEA->IsDefault = 0; + + Put(List, N, i, VEA, DeleteValidEmailAddress); Rcp = NewStrBuf(); } n++; @@ -1176,6 +1212,8 @@ void InitModule_PREFERENCES (void) { + RegisterCTX(CTX_VEA); + WebcitAddUrlHandler(HKEY("set_preferences"), "", 0, set_preferences, 0); WebcitAddUrlHandler(HKEY("change_start_page"), "", 0, change_start_page, 0); @@ -1193,7 +1231,10 @@ InitModule_PREFERENCES RegisterConditional("COND:ROOM:SET", 4, ConditionalHasRoomPreference, CTX_NONE); RegisterIterator("PREF:VALID:EMAIL:ADDR", 0, NULL, - GetGVEAHash, NULL, DeleteGVEAHash, CTX_STRBUF, CTX_NONE, IT_NOFLAG); + GetGVEAHash, NULL, DeleteGVEAHash, CTX_VEA, CTX_NONE, IT_NOFLAG); + RegisterNamespace("PREF:VALID:EMAIL:ADDR:STR", 1, 1, tmplput_VEA, NULL, CTX_VEA); + RegisterConditional("COND:PREF:VALID:EMAIL:ADDR:STR", 4, ConditionalPreferenceIsDefaulVEA, CTX_VEA); + RegisterIterator("PREF:VALID:EMAIL:NAME", 0, NULL, GetGVSNHash, NULL, DeleteGVSNHash, CTX_STRBUF, CTX_NONE, IT_NOFLAG); diff --git a/webcit/static/t/prefs/section_msg_sender_from_select.html b/webcit/static/t/prefs/section_msg_sender_from_select.html index b80b79cb8..e98771510 100644 --- a/webcit/static/t/prefs/section_msg_sender_from_select.html +++ b/webcit/static/t/prefs/section_msg_sender_from_select.html @@ -1 +1 @@ - + -- 2.30.2