Reply logic: handle reply to appropriate.
authorWilfried Goesgens <dothebart@citadel.org>
Wed, 18 Jul 2012 15:06:03 +0000 (17:06 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Wed, 18 Jul 2012 15:06:03 +0000 (17:06 +0200)
  - 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
webcit/messages.h
webcit/msg_renderers.c

index c362b2f6369cca696c1b44dfb3d5aa239138b255..88404111839f02762a9c6c85536aac0eb097d604 100644 (file)
@@ -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);
 
index a063170e046c0d96ae688b75555f1e36bed785a8..21ae4746782909142e936b19f54e4e4f5a7548a0 100644 (file)
@@ -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;
index 8e215262fd2f28af15a40b2c2aa9c5b47b475b43..3e5c29fcef4d1c93ee0e575c381161bbe0c10cba 100644 (file)
@@ -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);