MIME-Renderers: change interface.
authorWilfried Goesgens <dothebart@citadel.org>
Sun, 28 Oct 2012 15:02:21 +0000 (16:02 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 28 Oct 2012 15:02:21 +0000 (16:02 +0100)
  - we now use the context stacking mechanism, so contexts are transparent through several levels of mime and other renderers
  - remove other parameters to harmonize the interface.

webcit/ical_subst.c
webcit/messages.c
webcit/messages.h
webcit/msg_renderers.c
webcit/smtpqueue.c

index 43a10f2eb503cbbb336425ec0d7b0de1b43fc7f5..428527eb49dd224a462dfc69d47697a642dd0302 100644 (file)
@@ -265,14 +265,16 @@ void tmplput_CtxICalPropertyDate(StrBuf *Target, WCTemplputParams *TP)
 
 
 
-void render_MIME_ICS_TPL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
+void render_MIME_ICS_TPL(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
 {
+       wc_mime_attachment *Mime = CTX(CTX_MIME_ATACH);
        icalproperty_method the_method = ICAL_METHOD_NONE;
        icalproperty *method = NULL;
        icalcomponent *cal;
        icalcomponent *c;
         WCTemplputParams SubTP;
         WCTemplputParams SuperTP;
+
        static int divcount = 0;
 
        if (StrLength(Mime->Data) == 0) {
@@ -288,6 +290,8 @@ void render_MIME_ICS_TPL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *Foun
        }
 
        putlbstr("divname",  ++divcount);
+
+
        putbstr("cal_partnum", NewStrBufDup(Mime->PartNum));
        putlbstr("msgnum", Mime->msgnum);
 
@@ -305,8 +309,12 @@ void render_MIME_ICS_TPL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *Foun
                the_method = icalproperty_get_method(method);
        }
 
-       SuperTP.Context = &the_method;
-       SuperTP.Filter.ContextType = CTX_ICALMETHOD,
+       StackContext (TP,
+                     &SuperTP,
+                     &the_method,
+                     CTX_ICALMETHOD,
+                     0,
+                     TP->Tokens);
 
        StackContext (&SuperTP, 
                      &SubTP, 
@@ -327,6 +335,7 @@ void render_MIME_ICS_TPL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *Foun
                "EnableOrDisableCheckButton();  \n"
        );
 
+       UnStackContext(&SuperTP);
        UnStackContext(&SubTP);
        icalcomponent_free(cal);
 }
@@ -368,10 +377,6 @@ int cond_ICalIsMethod(StrBuf *Target, WCTemplputParams *TP)
 
 
 
-
-
-
-
 void tmplput_Conflict(StrBuf *Target, WCTemplputParams *TP)
 {}
 
@@ -413,7 +418,6 @@ HashList* IterateGetAttendees()
 }
 
 
-
 void 
 InitModule_ICAL_SUBST
 (void)
index e891539ce500dbf4e6da49da42bc55f65f38318e..3f8108f0a97c54511b4f97df414caec04346b535 100644 (file)
@@ -188,6 +188,7 @@ int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, co
        void *vHdr;
        long len;
        const char *Key;
+       WCTemplputParams SuperTP;
        WCTemplputParams SubTP;
        StrBuf *Error = NULL;
 
@@ -211,38 +212,47 @@ int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, co
        StrBufTrim(Buf);
        StrBufLowerCase(Buf);
 
-       /* Locate a renderer capable of converting this MIME part into HTML */
-       if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) &&
-           (vHdr != NULL)) {
-               RenderMimeFuncStruct *Render;
-               Render = (RenderMimeFuncStruct*)vHdr;
-               Render->f(Msg->MsgBody, NULL, FoundCharset);
-       }
-
-       if (StrLength(Msg->reply_references)> 0) {
-               /* Trim down excessively long lists of thread references.  We eliminate the
-                * second one in the list so that the thread root remains intact.
-                */
-               int rrtok = num_tokens(ChrPtr(Msg->reply_references), '|');
-               int rrlen = StrLength(Msg->reply_references);
-               if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
-                       StrBufRemove_token(Msg->reply_references, 1, '|');
+       StackContext(NULL, &SuperTP, Msg, CTX_MAILSUM, 0, NULL);
+       {
+               /* Locate a renderer capable of converting this MIME part into HTML */
+               if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) &&
+                   (vHdr != NULL)) {
+                       WCTemplputParams SubTP;
+                       RenderMimeFuncStruct *Render;
+                       
+                       StackContext(&SuperTP, &SubTP, Msg->MsgBody, CTX_MIME_ATACH, 0, NULL);
+                       {
+                               Render = (RenderMimeFuncStruct*)vHdr;
+                               Render->f(Target, &SubTP, FoundCharset);
+                       }
+                       UnStackContext(&SubTP);
+               }
+               
+               if (StrLength(Msg->reply_references)> 0) {
+                       /* Trim down excessively long lists of thread references.  We eliminate the
+                        * second one in the list so that the thread root remains intact.
+                        */
+                       int rrtok = num_tokens(ChrPtr(Msg->reply_references), '|');
+                       int rrlen = StrLength(Msg->reply_references);
+                       if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
+                               StrBufRemove_token(Msg->reply_references, 1, '|');
+                       }
                }
-       }
 
-       /* now check if we need to translate some mimeparts, and remove the duplicate */
-       it = GetNewHashPos(Msg->AllAttach, 0);
-       while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) && 
-              (vMime != NULL)) {
-               wc_mime_attachment *Mime = (wc_mime_attachment*) vMime;
-               evaluate_mime_part(Msg, Mime);
-       }
-       DeleteHashPos(&it);
-       StackContext(NULL, &SubTP, Msg, CTX_MAILSUM, 0, NULL);
-       {
-               *OutMime = DoTemplate(tmpl, tmpllen, Target, &SubTP);
+               /* now check if we need to translate some mimeparts, and remove the duplicate */
+               it = GetNewHashPos(Msg->AllAttach, 0);
+               while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) && 
+                      (vMime != NULL)) {
+                       StackContext(&SuperTP, &SubTP, vMime, CTX_MIME_ATACH, 0, NULL);
+                       {
+                               evaluate_mime_part(Target, &SubTP);
+                       }
+                       UnStackContext(&SubTP);
+               }
+               DeleteHashPos(&it);
+               *OutMime = DoTemplate(tmpl, tmpllen, Target, &SuperTP);
        }
-       UnStackContext(&SubTP);
+       UnStackContext(&SuperTP);
 
        DestroyMessageSummary(Msg);
        FreeStrBuf(&FoundCharset);
index 3129b18e0ef825a7efefb90e55330f89f36e5d6a..e8ba1a3f7afc67fa9eaf3e2bd213c3f2074d5cb7 100644 (file)
@@ -1,9 +1,10 @@
 extern CtxType CTX_MAILSUM;
+extern CtxType CTX_MIME_ATACH;
 extern HashList *MsgHeaderHandler;
 extern HashList *MimeRenderHandler;
 extern HashList *ReadLoopHandler;
 typedef struct wc_mime_attachment wc_mime_attachment;
-typedef void (*RenderMimeFunc)(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset);
+typedef void (*RenderMimeFunc)(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset);
 typedef struct _RenderMimeFuncStruct {
        RenderMimeFunc f;
 } RenderMimeFuncStruct;
@@ -79,7 +80,7 @@ static inline message_summary* GetMessagePtrAt(int n, HashList *Summ)
 
 typedef void (*ExamineMsgHeaderFunc)(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset);
 
-void evaluate_mime_part(message_summary *Msg, wc_mime_attachment *Mime);
+void evaluate_mime_part(StrBuf *Target, WCTemplputParams *TP);
 
 
 typedef enum _eCustomRoomRenderer {
index 3fac04aec66d1e83e6d58e39784207527754ce37..47d749b266e43268ee0a84181c8b50eed2c6ddfd 100644 (file)
@@ -571,8 +571,9 @@ void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, WCTemplputParams *TP)
 
 
 
-void render_MAIL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
+void render_MAIL(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
 {
+       wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
        const StrBuf *TemplateMime;
 
        if (Mime->Data == NULL) 
@@ -593,8 +594,9 @@ void render_MAIL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset
 */
 }
 
-void render_MIME_VCard(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
+void render_MIME_VCard(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
 {
+       wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
        wcsession *WCC = WC;
        if (StrLength(Mime->Data) == 0)
                MimeLoadData(Mime);
@@ -619,8 +621,9 @@ void render_MIME_VCard(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundC
 
 }
 
-void render_MIME_ICS(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
+void render_MIME_ICS(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
 {
+       wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
        if (StrLength(Mime->Data) == 0) {
                MimeLoadData(Mime);
        }
@@ -711,8 +714,10 @@ void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundChars
 }
 
 
-void evaluate_mime_part(message_summary *Msg, wc_mime_attachment *Mime)
+void evaluate_mime_part(StrBuf *Target, WCTemplputParams *TP)
 {
+       message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
+       wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
        void *vMimeRenderer;
 
        /* just print the root-node */
@@ -956,23 +961,25 @@ void tmplput_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
 }
 
 
-void render_MAIL_variformat(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
+void render_MAIL_variformat(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
 {
        /* Messages in legacy Citadel variformat get handled thusly... */
-       StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
-       FmOut(Target, "JUSTIFY", Mime->Data);
+       wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
+       StrBuf *TTarget = NewStrBufPlain(NULL, StrLength(Mime->Data));
+       FmOut(TTarget, "JUSTIFY", Mime->Data);
        FreeStrBuf(&Mime->Data);
-       Mime->Data = Target;
+       Mime->Data = TTarget;
 }
 
-void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
+void render_MAIL_text_plain(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
 {
+       wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
        const char *ptr, *pte;
        const char *BufPtr = NULL;
        StrBuf *Line;
        StrBuf *Line1;
        StrBuf *Line2;
-       StrBuf *Target;
+       StrBuf *TTarget;
        long Linecount;
        long nEmptyLines;
        int bn = 0;
@@ -1019,7 +1026,7 @@ void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *F
        Line = NewStrBufPlain(NULL, SIZ);
        Line1 = NewStrBufPlain(NULL, SIZ);
        Line2 = NewStrBufPlain(NULL, SIZ);
-       Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
+       TTarget = NewStrBufPlain(NULL, StrLength(Mime->Data));
        Linecount = 0;
        nEmptyLines = 0;
        if (StrLength(Mime->Data) > 0) 
@@ -1046,26 +1053,26 @@ void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *F
                        if (StrLength(Line) == 0) {
                                if (Linecount == 0)
                                        continue;
-                               StrBufAppendBufPlain(Target, HKEY("<tt></tt><br>\n"), 0);
+                               StrBufAppendBufPlain(TTarget, HKEY("<tt></tt><br>\n"), 0);
 
                                nEmptyLines ++;
                                continue;
                        }
                        nEmptyLines = 0;
                        for (i = bn; i < bq; i++)                               
-                               StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
+                               StrBufAppendBufPlain(TTarget, HKEY("<blockquote>"), 0);
                        for (i = bq; i < bn; i++)                               
-                               StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
+                               StrBufAppendBufPlain(TTarget, HKEY("</blockquote>"), 0);
 #ifdef HAVE_ICONV
                        if (ConvertIt) {
                                StrBufConvert(Line, Line1, &ic);
                        }
 #endif
-                       StrBufAppendBufPlain(Target, HKEY("<tt>"), 0);
+                       StrBufAppendBufPlain(TTarget, HKEY("<tt>"), 0);
                        UrlizeText(Line1, Line, Line2);
 
-                       StrEscAppend(Target, Line1, NULL, 0, 0);
-                       StrBufAppendBufPlain(Target, HKEY("</tt><br>\n"), 0);
+                       StrEscAppend(TTarget, Line1, NULL, 0, 0);
+                       StrBufAppendBufPlain(TTarget, HKEY("</tt><br>\n"), 0);
                        bn = bq;
                        Linecount ++;
                }
@@ -1073,11 +1080,11 @@ void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *F
               (BufPtr != NULL));
 
        if (nEmptyLines > 0)
-               StrBufCutRight(Target, nEmptyLines * (sizeof ("<tt></tt><br>\n") - 1));
+               StrBufCutRight(TTarget, nEmptyLines * (sizeof ("<tt></tt><br>\n") - 1));
        for (i = 0; i < bn; i++)                                
-               StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
+               StrBufAppendBufPlain(TTarget, HKEY("</blockquote>"), 0);
 
-       StrBufAppendBufPlain(Target, HKEY("</i><br>"), 0);
+       StrBufAppendBufPlain(TTarget, HKEY("</i><br>"), 0);
 #ifdef HAVE_ICONV
        if (ic != (iconv_t)(-1) ) {
                iconv_close(ic);
@@ -1085,7 +1092,7 @@ void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *F
 #endif
 
        FreeStrBuf(&Mime->Data);
-       Mime->Data = Target;
+       Mime->Data = TTarget;
        FlushStrBuf(Mime->ContentType);
        StrBufAppendBufPlain(Mime->ContentType, HKEY("text/html"), 0);
        FlushStrBuf(Mime->Charset);
@@ -1095,8 +1102,9 @@ void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *F
        FreeStrBuf(&Line2);
 }
 
-void render_MAIL_html(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
+void render_MAIL_html(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
 {
+       wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
        StrBuf *Buf;
 
        if (StrLength(Mime->Data) == 0)
@@ -1113,8 +1121,9 @@ void render_MAIL_html(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCh
        Mime->Data = Buf;
 }
 
-void render_MAIL_UNKNOWN(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
+void render_MAIL_UNKNOWN(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
 {
+       wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
        /* Unknown weirdness */
        FlushStrBuf(Mime->Data);
        StrBufAppendBufPlain(Mime->Data, _("I don't know how to display "), -1, 0);
@@ -1195,7 +1204,7 @@ void tmplput_MIME_Data(StrBuf *Target, WCTemplputParams *TP)
 {
        wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
        if (mime->Renderer != NULL)
-               mime->Renderer->f(mime, NULL, NULL);
+               mime->Renderer->f(Target, TP, NULL);
        StrBufAppendTemplate(Target, TP, mime->Data, 0);
        /* TODO: check whether we need to load it now? */
 }
index 9013567e70e21cf6e466c35647deeef636d5746b..350a201f03e3edf781159baf610e06c9972f93f4 100644 (file)
@@ -296,19 +296,20 @@ void QItem_Handle_Attempted(OneQueItem *Item, StrBuf *Line, const char **Pos)
 
 
 
-
-
-
-
-void render_QUEUE(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
+void render_QUEUE(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
 {
+       wc_mime_attachment *Mime = CTX(CTX_MIME_ATACH);
        WCTemplputParams SubTP;
+       OneQueItem* Context;
+
+       Context = DeserializeQueueItem(Mime->Data, Mime->msgnum);
+       StackContext(TP, &SubTP, Context, CTX_MAILQITEM, 0, TP->Tokens);
+       {
+               DoTemplate(HKEY("view_mailq_message"), NULL, &SubTP);
+       }
+       UnStackContext(&SubTP);
 
-       memset(&SubTP, 0, sizeof(WCTemplputParams));
-       SubTP.Filter.ContextType = CTX_MAILQITEM;
-       SubTP.Context = DeserializeQueueItem(Mime->Data, Mime->msgnum);
-       DoTemplate(HKEY("view_mailq_message"),NULL, &SubTP);
-       FreeQueItem ((OneQueItem**)&SubTP.Context);
+       FreeQueItem (&Context);
 }
 
 void