From: Wilfried Goesgens Date: Mon, 25 Oct 2010 16:54:16 +0000 (+0200) Subject: * add a way to pass the workbuffers into the RFC-822 decoder, so we don't need to... X-Git-Tag: v8.01~638^2 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=4749c0d69445c9475aece3211ecef389e6e29c43 * add a way to pass the workbuffers into the RFC-822 decoder, so we don't need to realloc it over and over * add two temporary buffers to the WC Struct for that purpose * add session logic to free them, and alloc them on need --- diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index 188a13a5b..c52fa6e2e 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -279,7 +279,15 @@ void StrBufReplaceChars(StrBuf *buf, char search, char replace); int CompressBuffer(StrBuf *Buf); void StrBufConvert(StrBuf *ConvertBuf, StrBuf *TmpBuf, void *pic); void ctdl_iconv_open(const char *tocode, const char *fromcode, void *pic); +void StrBuf_RFC822_2_Utf8(StrBuf *Target, + const StrBuf *DecodeMe, + const StrBuf* DefaultCharset, + StrBuf *FoundCharset, + StrBuf *ConvertBuf, + StrBuf *ConvertBuf2); +/* deprecated old version: */ void StrBuf_RFC822_to_Utf8(StrBuf *Target, const StrBuf *DecodeMe, const StrBuf* DefaultCharset, StrBuf *FoundCharset); + int StrBufDecodeBase64(StrBuf *Buf); int StrBufDecodeHex(StrBuf *Buf); int StrBufRFC2047encode(StrBuf **target, const StrBuf *source); diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index 98acba782..5d050e750 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -2985,7 +2985,7 @@ inline static void DecodeSegment(StrBuf *Target, /** * @ingroup StrBuf_DeEnCoder - * @brief Handle subjects with RFC2047 encoding such as: + * @brief Handle subjects with RFC2047 encoding such as: [deprecated old syntax!] * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?= * @param Target where to put the decoded string to * @param DecodeMe buffer with encoded string @@ -2994,9 +2994,42 @@ inline static void DecodeSegment(StrBuf *Target, * put it here for later use where no string might be known. */ void StrBuf_RFC822_to_Utf8(StrBuf *Target, const StrBuf *DecodeMe, const StrBuf* DefaultCharset, StrBuf *FoundCharset) +{ + StrBuf *ConvertBuf; + StrBuf *ConvertBuf2; + ConvertBuf = NewStrBufPlain(NULL, StrLength(DecodeMe)); + ConvertBuf2 = NewStrBufPlain(NULL, StrLength(DecodeMe)); + + StrBuf_RFC822_2_Utf8(Target, + DecodeMe, + DefaultCharset, + FoundCharset, + ConvertBuf, + ConvertBuf2); + FreeStrBuf(&ConvertBuf); + FreeStrBuf(&ConvertBuf2); +} + +/** + * @ingroup StrBuf_DeEnCoder + * @brief Handle subjects with RFC2047 encoding such as: + * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?= + * @param Target where to put the decoded string to + * @param DecodeMe buffer with encoded string + * @param DefaultCharset if we don't find one, which should we use? + * @param FoundCharset overrides DefaultCharset if non-empty; If we find a charset inside of the string, + * put it here for later use where no string might be known. + * @param ConvertBuf workbuffer. feed in, you shouldn't care about its content. + * @param ConvertBuf2 workbuffer. feed in, you shouldn't care about its content. + */ +void StrBuf_RFC822_2_Utf8(StrBuf *Target, + const StrBuf *DecodeMe, + const StrBuf* DefaultCharset, + StrBuf *FoundCharset, + StrBuf *ConvertBuf, + StrBuf *ConvertBuf2) { StrBuf *DecodedInvalidBuf = NULL; - StrBuf *ConvertBuf, *ConvertBuf2; const StrBuf *DecodeMee = DecodeMe; const char *start, *end, *next, *nextend, *ptr = NULL; #ifdef HAVE_ICONV @@ -3022,7 +3055,6 @@ void StrBuf_RFC822_to_Utf8(StrBuf *Target, const StrBuf *DecodeMe, const StrBuf* } } - ConvertBuf = NewStrBufPlain(NULL, StrLength(DecodeMe)); if ((illegal_non_rfc2047_encoding) && (strcasecmp(ChrPtr(DefaultCharset), "UTF-8")) && (strcasecmp(ChrPtr(DefaultCharset), "us-ascii")) ) @@ -3047,12 +3079,10 @@ void StrBuf_RFC822_to_Utf8(StrBuf *Target, const StrBuf *DecodeMe, const StrBuf* end = FindNextEnd (DecodeMee, start); else { StrBufAppendBuf(Target, DecodeMee, 0); - FreeStrBuf(&ConvertBuf); FreeStrBuf(&DecodedInvalidBuf); return; } - ConvertBuf2 = NewStrBufPlain(NULL, StrLength(DecodeMee)); if (start != DecodeMee->buf) { long nFront; @@ -3131,8 +3161,6 @@ void StrBuf_RFC822_to_Utf8(StrBuf *Target, const StrBuf *DecodeMe, const StrBuf* if (ptr < nextend) StrBufAppendBufPlain(Target, end, nextend - end, 0); } - FreeStrBuf(&ConvertBuf); - FreeStrBuf(&ConvertBuf2); FreeStrBuf(&DecodedInvalidBuf); } diff --git a/webcit/messages.h b/webcit/messages.h index a04529db2..62d290cbe 100644 --- a/webcit/messages.h +++ b/webcit/messages.h @@ -243,3 +243,6 @@ int ParseMessageListHeaders_Detail(StrBuf *Line, const char **pos, message_summary *Msg, StrBuf *ConversionBuffer); + + + diff --git a/webcit/msg_renderers.c b/webcit/msg_renderers.c index a7c819ba0..a58f64043 100644 --- a/webcit/msg_renderers.c +++ b/webcit/msg_renderers.c @@ -2,6 +2,16 @@ #include "webserver.h" #include "groupdav.h" + + +inline void CheckConvertBufs(struct wcsession *WCC) +{ + if (WCC->ConvertBuf1 == NULL) + WCC->ConvertBuf1 = NewStrBuf(); + if (WCC->ConvertBuf2 == NULL) + WCC->ConvertBuf2 = NewStrBuf(); +} + /* * message index functions */ @@ -251,9 +261,17 @@ void examine_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) void examine_from(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) { + wcsession *WCC = WC; + + CheckConvertBufs(WCC); FreeStrBuf(&Msg->from); Msg->from = NewStrBufPlain(NULL, StrLength(HdrLine)); - StrBuf_RFC822_to_Utf8(Msg->from, HdrLine, WC->DefaultCharset, FoundCharset); + StrBuf_RFC822_2_Utf8(Msg->from, + HdrLine, + WCC->DefaultCharset, + FoundCharset, + WCC->ConvertBuf1, + WCC->ConvertBuf2); } void tmplput_MAIL_SUMM_FROM(StrBuf *Target, WCTemplputParams *TP) { @@ -263,9 +281,17 @@ void tmplput_MAIL_SUMM_FROM(StrBuf *Target, WCTemplputParams *TP) void examine_subj(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) { + wcsession *WCC = WC; + + CheckConvertBufs(WCC); FreeStrBuf(&Msg->subj); Msg->subj = NewStrBufPlain(NULL, StrLength(HdrLine)); - StrBuf_RFC822_to_Utf8(Msg->subj, HdrLine, WC->DefaultCharset, FoundCharset); + StrBuf_RFC822_2_Utf8(Msg->subj, + HdrLine, + WCC->DefaultCharset, + FoundCharset, + WCC->ConvertBuf1, + WCC->ConvertBuf2); } void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP) { @@ -297,9 +323,17 @@ int Conditional_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP) void examine_msgn(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) { + wcsession *WCC = WC; + + CheckConvertBufs(WCC); FreeStrBuf(&Msg->reply_inreplyto); Msg->reply_inreplyto = NewStrBufPlain(NULL, StrLength(HdrLine)); - StrBuf_RFC822_to_Utf8(Msg->reply_inreplyto, HdrLine, WC->DefaultCharset, FoundCharset); + StrBuf_RFC822_2_Utf8(Msg->reply_inreplyto, + HdrLine, + WCC->DefaultCharset, + FoundCharset, + WCC->ConvertBuf1, + WCC->ConvertBuf2); } void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, WCTemplputParams *TP) { @@ -315,9 +349,17 @@ int Conditional_MAIL_SUMM_UNREAD(StrBuf *Target, WCTemplputParams *TP) void examine_wefw(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) { + wcsession *WCC = WC; + + CheckConvertBufs(WCC); FreeStrBuf(&Msg->reply_references); Msg->reply_references = NewStrBufPlain(NULL, StrLength(HdrLine)); - StrBuf_RFC822_to_Utf8(Msg->reply_references, HdrLine, WC->DefaultCharset, FoundCharset); + StrBuf_RFC822_2_Utf8(Msg->reply_references, + HdrLine, + WCC->DefaultCharset, + FoundCharset, + WCC->ConvertBuf1, + WCC->ConvertBuf2); } void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, WCTemplputParams *TP) { @@ -328,9 +370,17 @@ void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, WCTemplputParams *TP) void examine_cccc(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) { + wcsession *WCC = WC; + + CheckConvertBufs(WCC); FreeStrBuf(&Msg->cccc); Msg->cccc = NewStrBufPlain(NULL, StrLength(HdrLine)); - StrBuf_RFC822_to_Utf8(Msg->cccc, HdrLine, WC->DefaultCharset, FoundCharset); + StrBuf_RFC822_2_Utf8(Msg->cccc, + HdrLine, + WCC->DefaultCharset, + FoundCharset, + WCC->ConvertBuf1, + WCC->ConvertBuf2); if (Msg->AllRcpt == NULL) Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine)); if (StrLength(Msg->AllRcpt) > 0) { @@ -407,9 +457,17 @@ int Conditional_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP) void examine_rcpt(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) { + wcsession *WCC = WC; + + CheckConvertBufs(WCC); FreeStrBuf(&Msg->to); Msg->to = NewStrBufPlain(NULL, StrLength(HdrLine)); - StrBuf_RFC822_to_Utf8(Msg->to, HdrLine, WC->DefaultCharset, FoundCharset); + StrBuf_RFC822_2_Utf8(Msg->to, + HdrLine, + WCC->DefaultCharset, + FoundCharset, + WCC->ConvertBuf1, + WCC->ConvertBuf2); if (Msg->AllRcpt == NULL) Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine)); if (StrLength(Msg->AllRcpt) > 0) { @@ -582,7 +640,9 @@ void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundChars const char *Ptr = NULL; wc_mime_attachment *Mime; StrBuf *Buf; - + wcsession *WCC = WC; + + CheckConvertBufs(WCC); Mime = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment)); memset(Mime, 0, sizeof(wc_mime_attachment)); Mime->msgnum = Msg->msgnum; @@ -590,12 +650,22 @@ void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundChars Mime->Name = NewStrBuf(); StrBufExtract_NextToken(Buf, HdrLine, &Ptr, '|'); - StrBuf_RFC822_to_Utf8(Mime->Name, Buf, WC->DefaultCharset, FoundCharset); + StrBuf_RFC822_2_Utf8(Mime->Name, + Buf, + WCC->DefaultCharset, + FoundCharset, + WCC->ConvertBuf1, + WCC->ConvertBuf2); StrBufTrim(Mime->Name); StrBufExtract_NextToken(Buf, HdrLine, &Ptr, '|'); Mime->FileName = NewStrBuf(); - StrBuf_RFC822_to_Utf8(Mime->FileName, Buf, WC->DefaultCharset, FoundCharset); + StrBuf_RFC822_2_Utf8(Mime->FileName, + Buf, + WCC->DefaultCharset, + FoundCharset, + WCC->ConvertBuf1, + WCC->ConvertBuf2); StrBufTrim(Mime->FileName); Mime->PartNum = NewStrBuf(); @@ -694,9 +764,17 @@ void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, WCTemplputParams *TP) void examine_hnod(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) { + wcsession *WCC = WC; + + CheckConvertBufs(WCC); FreeStrBuf(&Msg->hnod); Msg->hnod = NewStrBufPlain(NULL, StrLength(HdrLine)); - StrBuf_RFC822_to_Utf8(Msg->hnod, HdrLine, WC->DefaultCharset, FoundCharset); + StrBuf_RFC822_2_Utf8(Msg->hnod, + HdrLine, + WCC->DefaultCharset, + FoundCharset, + WCC->ConvertBuf1, + WCC->ConvertBuf2); } void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP) { @@ -1198,11 +1276,18 @@ int ParseMessageListHeaders_Detail(StrBuf *Line, { wcsession *WCC = WC; + CheckConvertBufs(WCC); + Msg->from = NewStrBufPlain(NULL, StrLength(Line)); StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|'); if (StrLength(ConversionBuffer) != 0) { /* Handle senders with RFC2047 encoding */ - StrBuf_RFC822_to_Utf8(Msg->from, ConversionBuffer, WCC->DefaultCharset, NULL); + StrBuf_RFC822_2_Utf8(Msg->from, + ConversionBuffer, + WCC->DefaultCharset, + NULL, + WCC->ConvertBuf1, + WCC->ConvertBuf2); } /* node name */ @@ -1241,7 +1326,12 @@ int ParseMessageListHeaders_Detail(StrBuf *Line, if (StrLength(ConversionBuffer) == 0) StrBufAppendBufPlain(Msg->subj, _("(no subject)"), -1,0); else { - StrBuf_RFC822_to_Utf8(Msg->subj, ConversionBuffer, WCC->DefaultCharset, NULL); + StrBuf_RFC822_2_Utf8(Msg->subj, + ConversionBuffer, + WCC->DefaultCharset, + NULL, + WCC->ConvertBuf1, + WCC->ConvertBuf2); } return 1; @@ -1474,4 +1564,6 @@ SessionDestroyModule_MSGRENDERERS (wcsession *sess) { DeleteHash(&sess->attachments); + FreeStrBuf(&sess->ConvertBuf1); + FreeStrBuf(&sess->ConvertBuf2); } diff --git a/webcit/webcit.h b/webcit/webcit.h index 6b3de478d..c00cf59e1 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -555,7 +555,9 @@ struct wcsession { long *IBSettingsVec; /* which icons should be shown / not shown? */ const StrBuf *floordiv_expanded; /* which floordiv currently expanded */ - +/* Transcoding cache buffers; used to avoid to frequent realloc */ + StrBuf *ConvertBuf1; + StrBuf *ConvertBuf2; /* cache stuff for templates. TODO: find a smartrer way */ HashList *ServCfg; /* cache our server config for editing */ @@ -581,7 +583,6 @@ enum { MAX_SEMAPHORES }; - #ifndef num_parms #define num_parms(source) num_tokens(source, '|') #endif