From 8fae1a3f7a2c53606f1c7418637f141e424e5b26 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Wed, 18 Jul 2012 17:06:03 +0200 Subject: [PATCH] Reply logic: handle reply to appropriate. - if we're aware of a reply-to header, reply will now prefer this address over all others - reply-all & forward will ignore it. --- webcit/messages.c | 49 ++++++++++++++++++++++++++++++++++-------- webcit/messages.h | 1 + webcit/msg_renderers.c | 34 +++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 9 deletions(-) diff --git a/webcit/messages.c b/webcit/messages.c index c362b2f63..884041118 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -1318,14 +1318,28 @@ long l_msgn; long l_from; long l_rcpt; long l_cccc; +long l_replyto; long l_node; long l_rfca; +const char *ReplyToModeStrings [3] = { + "reply", + "replyalle", + "forward" +}; +typedef enum _eReplyToNodes { + eReply, + eReplyAll, + eForward +}eReplyToNodes; + /* * display the message entry screen */ void display_enter(void) { + const char *ReplyingModeStr; + eReplyToNodes ReplyMode = eReply; StrBuf *Line; long Result; int rc; @@ -1402,6 +1416,15 @@ void display_enter(void) } + ReplyingModeStr = bstr("replying_mode"); + if (ReplyingModeStr != NULL) for (i = 0; i < 3; i++) { + if (strcmp(ReplyingModeStr, ReplyToModeStrings[i]) == 0) { + ReplyMode = (eReplyToNodes) i; + break; + } + } + + /* * If the "replying_to" variable is set, it refers to a message * number from which we must extract some header fields... @@ -1416,6 +1439,7 @@ void display_enter(void) StrBuf *rfca = NULL; StrBuf *rcpt = NULL; StrBuf *cccc = NULL; + StrBuf *replyto = NULL; serv_printf("MSG0 %ld|1", replying_to); StrBuf_ServGetln(Line); @@ -1435,7 +1459,7 @@ void display_enter(void) StrBuf *subj = NewStrBuf(); StrBuf *FlatSubject; - if (!strcasecmp(bstr("replying_mode"), "forward")) { + if (ReplyMode == eForward) { if (strncasecmp(ChrPtr(Line) + 5, "Fw:", 3)) { StrBufAppendBufPlain(subj, HKEY("Fw: "), 0); } @@ -1499,7 +1523,9 @@ void display_enter(void) else if (which == l_node) { node = NewStrBufPlain(ChrPtr(Line) + 5, StrLength(Line) - 5); } - + 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); @@ -1530,11 +1556,14 @@ void display_enter(void) /* * If this is a Reply or a ReplyAll, copy the sender's email into the To: field */ - if ( (!strcasecmp(bstr("replying_mode"), "reply")) - || (!strcasecmp(bstr("replying_mode"), "replyall")) - ) { + if ((ReplyMode == eReply) || (ReplyMode == eReplyAll)) + { StrBuf *to_rcpt; - if (StrLength(rfca) > 0) { + if ((StrLength(replyto) > 0) && (ReplyMode == eReplyAll)) { + to_rcpt = NewStrBuf(); + StrBufAppendBuf(to_rcpt, replyto, 0); + } + else if (StrLength(rfca) > 0) { to_rcpt = NewStrBuf(); StrBufAppendBuf(to_rcpt, from, 0); StrBufAppendBufPlain(to_rcpt, HKEY(" <"), 0); @@ -1557,11 +1586,12 @@ void display_enter(void) /* * Only if this is a ReplyAll, copy all recipients into the Cc: field */ - if ( (!strcasecmp(bstr("replying_mode"), "replyall")) - ) { + if (ReplyMode == eReplyAll) + { StrBuf *cc_rcpt = rcpt; rcpt = NULL; - if (StrLength(cccc) > 0) { + if ((StrLength(cccc) > 0) && (StrLength(replyto) == 0)) + { if (cc_rcpt != NULL) { StrBufAppendPrintf(cc_rcpt, ", "); StrBufAppendBuf(cc_rcpt, cccc, 0); @@ -2024,6 +2054,7 @@ InitModule_MSG l_from = FourHash("from", 4); l_rcpt = FourHash("rcpt", 4); l_cccc = FourHash("cccc", 4); + l_replyto = FourHash("rep2", 4); l_node = FourHash("node", 4); l_rfca = FourHash("rfca", 4); diff --git a/webcit/messages.h b/webcit/messages.h index a063170e0..21ae47467 100644 --- a/webcit/messages.h +++ b/webcit/messages.h @@ -40,6 +40,7 @@ typedef struct _message_summary { StrBuf *subj; /* the title / subject */ StrBuf *reply_inreplyto; StrBuf *reply_references; + StrBuf *ReplyTo; StrBuf *cccc; StrBuf *hnod; StrBuf *AllRcpt; diff --git a/webcit/msg_renderers.c b/webcit/msg_renderers.c index 8e215262f..3e5c29fce 100644 --- a/webcit/msg_renderers.c +++ b/webcit/msg_renderers.c @@ -45,6 +45,7 @@ void DestroyMessageSummary(void *vMsg) FreeStrBuf(&Msg->reply_inreplyto); FreeStrBuf(&Msg->reply_references); FreeStrBuf(&Msg->cccc); + FreeStrBuf(&Msg->ReplyTo); FreeStrBuf(&Msg->hnod); FreeStrBuf(&Msg->AllRcpt); FreeStrBuf(&Msg->Room); @@ -365,6 +366,31 @@ void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, WCTemplputParams *TP) StrBufAppendTemplate(Target, TP, Msg->reply_references, 0); } +void examine_replyto(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) +{ + wcsession *WCC = WC; + + CheckConvertBufs(WCC); + FreeStrBuf(&Msg->ReplyTo); + Msg->ReplyTo = NewStrBufPlain(NULL, StrLength(HdrLine)); + StrBuf_RFC822_2_Utf8(Msg->ReplyTo, + HdrLine, + WCC->DefaultCharset, + FoundCharset, + WCC->ConvertBuf1, + WCC->ConvertBuf2); + if (Msg->AllRcpt == NULL) + Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine)); + if (StrLength(Msg->AllRcpt) > 0) { + StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0); + } + StrBufAppendBuf(Msg->AllRcpt, Msg->ReplyTo, 0); +} +void tmplput_MAIL_SUMM_REPLYTO(StrBuf *Target, WCTemplputParams *TP) +{ + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); + StrBufAppendTemplate(Target, TP, Msg->ReplyTo, 0); +} void examine_cccc(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) { @@ -428,6 +454,11 @@ int Conditional_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP) message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); return StrLength(Msg->cccc) > 0; } +int Conditional_MAIL_SUMM_REPLYTO(StrBuf *Target, WCTemplputParams *TP) +{ + message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM); + return StrLength(Msg->ReplyTo) > 0; +} void examine_node(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) { @@ -1505,6 +1536,7 @@ InitModule_MSGRENDERERS RegisterNamespace("MAIL:SUMM:SUBJECT", 0, 4, tmplput_MAIL_SUMM_SUBJECT, NULL, CTX_MAILSUM); RegisterNamespace("MAIL:SUMM:NTATACH", 0, 0, tmplput_MAIL_SUMM_NATTACH, NULL, CTX_MAILSUM); RegisterNamespace("MAIL:SUMM:CCCC", 0, 2, tmplput_MAIL_SUMM_CCCC, NULL, CTX_MAILSUM); + RegisterNamespace("MAIL:SUMM:REPLYTO", 0, 2, tmplput_MAIL_SUMM_REPLYTO, NULL, CTX_MAILSUM); RegisterNamespace("MAIL:SUMM:H_NODE", 0, 2, tmplput_MAIL_SUMM_H_NODE, NULL, CTX_MAILSUM); RegisterNamespace("MAIL:SUMM:ALLRCPT", 0, 2, tmplput_MAIL_SUMM_ALLRCPT, NULL, CTX_MAILSUM); RegisterNamespace("MAIL:SUMM:ORGROOM", 0, 2, tmplput_MAIL_SUMM_ORGROOM, NULL, CTX_MAILSUM); @@ -1518,6 +1550,7 @@ InitModule_MSGRENDERERS RegisterNamespace("MAIL:EDITWIKI", 1, 2, tmplput_EDIT_WIKI_BODY, NULL, CTX_NONE); RegisterConditional(HKEY("COND:MAIL:SUMM:RFCA"), 0, Conditional_MAIL_SUMM_RFCA, CTX_MAILSUM); RegisterConditional(HKEY("COND:MAIL:SUMM:CCCC"), 0, Conditional_MAIL_SUMM_CCCC, CTX_MAILSUM); + RegisterConditional(HKEY("COND:MAIL:SUMM:REPLYTO"), 0, Conditional_MAIL_SUMM_REPLYTO, CTX_MAILSUM); RegisterConditional(HKEY("COND:MAIL:SUMM:UNREAD"), 0, Conditional_MAIL_SUMM_UNREAD, CTX_MAILSUM); RegisterConditional(HKEY("COND:MAIL:SUMM:H_NODE"), 0, Conditional_MAIL_SUMM_H_NODE, CTX_MAILSUM); RegisterConditional(HKEY("COND:MAIL:SUMM:OTHERNODE"), 0, Conditional_MAIL_SUMM_OTHERNODE, CTX_MAILSUM); @@ -1580,6 +1613,7 @@ InitModule_MSGRENDERERS RegisterMsgHdr(HKEY("msgn"), examine_msgn, 0); RegisterMsgHdr(HKEY("wefw"), examine_wefw, 0); RegisterMsgHdr(HKEY("cccc"), examine_cccc, 0); + RegisterMsgHdr(HKEY("rep2"), examine_replyto, 0); RegisterMsgHdr(HKEY("hnod"), examine_hnod, 0); RegisterMsgHdr(HKEY("room"), examine_room, 0); RegisterMsgHdr(HKEY("rfca"), examine_rfca, 0); -- 2.30.2