* add a way to pass the workbuffers into the RFC-822 decoder, so we don't need to...
authorWilfried Goesgens <dothebart@citadel.org>
Mon, 25 Oct 2010 16:54:16 +0000 (18:54 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Mon, 25 Oct 2010 16:55:43 +0000 (18:55 +0200)
* add two temporary buffers to the WC Struct for that purpose
* add session logic to free them, and alloc them on need

libcitadel/lib/libcitadel.h
libcitadel/lib/stringbuf.c
webcit/messages.h
webcit/msg_renderers.c
webcit/webcit.h

index 188a13a5b431bcf483a0c456ff591b9d801795fe..c52fa6e2e0369689dfc2fafd657fc750737a111f 100644 (file)
@@ -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);
index 98acba78284590723c04fbe738fb1be0e51a984a..5d050e7502d0c1adec4a38ff134c3a949df335b6 100644 (file)
@@ -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);
 }
 
index a04529db25ddfcd9fc76db44669293053b57eb8c..62d290cbe0df62a56c1a2ebc2c511e20fa3432c0 100644 (file)
@@ -243,3 +243,6 @@ int ParseMessageListHeaders_Detail(StrBuf *Line,
                                   const char **pos, 
                                   message_summary *Msg, 
                                   StrBuf *ConversionBuffer);
+
+
+
index a7c819ba026a0a70a65e8df7d2bc0725ec187140..a58f64043a5dbb6aff7e6e5e56568c788fc6f0ed 100644 (file)
@@ -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);
 }
index 6b3de478d879568b783b2a26b214b1f8be254775..c00cf59e1bfa1328aa8a51978dc51bf099fe5bdd 100644 (file)
@@ -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