From 74210f758b7a01766b7a84bf02015469e98f2105 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Sun, 28 Oct 2012 16:02:21 +0100 Subject: [PATCH] MIME-Renderers: change interface. - 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 | 20 ++++++++----- webcit/messages.c | 68 ++++++++++++++++++++++++------------------ webcit/messages.h | 5 ++-- webcit/msg_renderers.c | 57 ++++++++++++++++++++--------------- webcit/smtpqueue.c | 21 ++++++------- 5 files changed, 98 insertions(+), 73 deletions(-) diff --git a/webcit/ical_subst.c b/webcit/ical_subst.c index 43a10f2eb..428527eb4 100644 --- a/webcit/ical_subst.c +++ b/webcit/ical_subst.c @@ -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) diff --git a/webcit/messages.c b/webcit/messages.c index e891539ce..3f8108f0a 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -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); diff --git a/webcit/messages.h b/webcit/messages.h index 3129b18e0..e8ba1a3f7 100644 --- a/webcit/messages.h +++ b/webcit/messages.h @@ -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 { diff --git a/webcit/msg_renderers.c b/webcit/msg_renderers.c index 3fac04aec..47d749b26 100644 --- a/webcit/msg_renderers.c +++ b/webcit/msg_renderers.c @@ -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("
\n"), 0); + StrBufAppendBufPlain(TTarget, HKEY("
\n"), 0); nEmptyLines ++; continue; } nEmptyLines = 0; for (i = bn; i < bq; i++) - StrBufAppendBufPlain(Target, HKEY("
"), 0); + StrBufAppendBufPlain(TTarget, HKEY("
"), 0); for (i = bq; i < bn; i++) - StrBufAppendBufPlain(Target, HKEY("
"), 0); + StrBufAppendBufPlain(TTarget, HKEY("
"), 0); #ifdef HAVE_ICONV if (ConvertIt) { StrBufConvert(Line, Line1, &ic); } #endif - StrBufAppendBufPlain(Target, HKEY(""), 0); + StrBufAppendBufPlain(TTarget, HKEY(""), 0); UrlizeText(Line1, Line, Line2); - StrEscAppend(Target, Line1, NULL, 0, 0); - StrBufAppendBufPlain(Target, HKEY("
\n"), 0); + StrEscAppend(TTarget, Line1, NULL, 0, 0); + StrBufAppendBufPlain(TTarget, HKEY("

\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 ("
\n") - 1)); + StrBufCutRight(TTarget, nEmptyLines * (sizeof ("
\n") - 1)); for (i = 0; i < bn; i++) - StrBufAppendBufPlain(Target, HKEY(""), 0); + StrBufAppendBufPlain(TTarget, HKEY(""), 0); - StrBufAppendBufPlain(Target, HKEY("
"), 0); + StrBufAppendBufPlain(TTarget, HKEY("
"), 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? */ } diff --git a/webcit/smtpqueue.c b/webcit/smtpqueue.c index 9013567e7..350a201f0 100644 --- a/webcit/smtpqueue.c +++ b/webcit/smtpqueue.c @@ -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 -- 2.30.2