]> code.citadel.org Git - citadel.git/blobdiff - webcit/messages.c
* put filename reference into token, so we can put in errormessages where we wouldn...
[citadel.git] / webcit / messages.c
index 50b53ef3a32c97c8999d24fcfa22d006dd97e93b..d05d988efbd9d8a3c5dea55cf71777b71eaaa1ce 100644 (file)
@@ -241,8 +241,23 @@ int summcmp_rdate(const void *s1, const void *s2) {
  * message index functions
  */
 
+void DestroyMimeParts(wc_mime_attachment *Mime)
+{
+       FreeStrBuf(&Mime->Name);
+       FreeStrBuf(&Mime->FileName);
+       FreeStrBuf(&Mime->PartNum);
+       FreeStrBuf(&Mime->Disposition);
+       FreeStrBuf(&Mime->ContentType);
+       FreeStrBuf(&Mime->Charset);
+       FreeStrBuf(&Mime->Data);
+}
 
-
+void DestroyMime(void *vMime)
+{
+       wc_mime_attachment *Mime = (wc_mime_attachment*)vMime;
+       DestroyMimeParts(Mime);
+       free(Mime);
+}
 
 void DestroyMessageSummary(void *vMsg)
 {
@@ -260,6 +275,15 @@ void DestroyMessageSummary(void *vMsg)
        FreeStrBuf(&Msg->Rfca);
        FreeStrBuf(&Msg->OtherNode);
 
+       FreeStrBuf(&Msg->reply_to);
+
+       DeleteHash(&Msg->Attachments);  /**< list of Accachments */
+       DeleteHash(&Msg->Submessages);
+       DeleteHash(&Msg->AttachLinks);
+       DeleteHash(&Msg->AllAttach);
+
+       DestroyMimeParts(&Msg->MsgBody);
+
        free(Msg);
 }
 
@@ -472,36 +496,47 @@ void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundChars
 
        mime = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
        memset(mime, 0, sizeof(wc_mime_attachment));
-       Buf=NewStrBuf();
+       Buf = NewStrBuf();
 
        mime->Name = NewStrBuf();
        StrBufExtract_token(mime->Name, HdrLine, 0, '|');
+
        StrBufExtract_token(Buf, HdrLine, 1, '|');
+       mime->FileName = NewStrBuf();
        StrBuf_RFC822_to_Utf8(mime->FileName, Buf, WC->DefaultCharset, FoundCharset);
+
        mime->PartNum = NewStrBuf();
        StrBufExtract_token(mime->PartNum, HdrLine, 2, '|');
+
        mime->Disposition = NewStrBuf();
        StrBufExtract_token(mime->Disposition, HdrLine, 3, '|');
+
        mime->ContentType = NewStrBuf();
        StrBufExtract_token(mime->ContentType, HdrLine, 4, '|');
+
        mime->length = StrBufExtract_int(HdrLine, 5, '|');
 
        StrBufTrim(mime->Name);
        StrBufTrim(mime->FileName);
+
        if ( (StrLength(mime->FileName) == 0) && (StrLength(mime->Name) > 0) ) {
                StrBufAppendBuf(mime->FileName, mime->Name, 0);
        }
 
+       if (Msg->AllAttach == NULL)
+               Msg->AllAttach = NewHash(1,NULL);
+       Put(Msg->AllAttach, SKEY(mime->PartNum), mime, DestroyMime);
+
        if (!strcasecmp(ChrPtr(mime->ContentType), "message/rfc822")) {
                if (Msg->Submessages == NULL)
                        Msg->Submessages = NewHash(1,NULL);
-               Put(Msg->Submessages, SKEY(mime->PartNum), mime->PartNum, reference_free_handler);
+               Put(Msg->Submessages, SKEY(mime->PartNum), mime, reference_free_handler);
        }
        else if ((!strcasecmp(ChrPtr(mime->Disposition), "inline"))
                 && (!strncasecmp(ChrPtr(mime->ContentType), "image/", 6)) ){
                if (Msg->AttachLinks == NULL)
                        Msg->AttachLinks = NewHash(1,NULL);
-               Put(Msg->AttachLinks, SKEY(mime->PartNum), mime->PartNum, reference_free_handler);
+               Put(Msg->AttachLinks, SKEY(mime->PartNum), mime, reference_free_handler);
        }
        else if ((StrLength(mime->ContentType) > 0) &&
                  ( (!strcasecmp(ChrPtr(mime->Disposition), "attachment")) 
@@ -511,7 +546,7 @@ void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundChars
                
                if (Msg->AttachLinks == NULL)
                        Msg->AttachLinks = NewHash(1,NULL);
-               Put(Msg->AttachLinks, SKEY(mime->PartNum), mime->PartNum, reference_free_handler);
+               Put(Msg->AttachLinks, SKEY(mime->PartNum), mime, reference_free_handler);
                if (strcasecmp(ChrPtr(mime->ContentType), "application/octet-stream") == 0) {
                        FlushStrBuf(mime->ContentType);
                        StrBufAppendBufPlain(mime->ContentType,
@@ -530,6 +565,9 @@ void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundChars
                Msg->cal_partnum_ref = mime;
        }
        /** end handler prep ***/
+
+       FreeStrBuf(&Buf);
+
 }
 void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
 {
@@ -773,6 +811,35 @@ void render_MAIL_UNKNOWN(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *Foun
 
 
 
+HashList *iterate_get_mime_All(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       message_summary *Msg = (message_summary*) Context;
+       return Msg->AllAttach;
+}
+HashList *iterate_get_mime_Submessages(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       message_summary *Msg = (message_summary*) Context;
+       return Msg->Submessages;
+}
+HashList *iterate_get_mime_AttachLinks(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       message_summary *Msg = (message_summary*) Context;
+       return Msg->AttachLinks;
+}
+HashList *iterate_get_mime_Attachments(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       message_summary *Msg = (message_summary*) Context;
+       return Msg->AllAttach;
+}
+
+
+void tmplput_MIME_ATTACH(StrBuf *TemplBuffer, void *Context, WCTemplateToken *Token)
+{
+}
+
+
+
+
 
 /*
  * Look for URL's embedded in a buffer and make them linkable.  We use a
@@ -1296,7 +1363,7 @@ void read_message(long msgnum, int printable_view, char *section) {
        StrBuf *Buf;
        StrBuf *Token;
        StrBuf *FoundCharset;
-       message_summary *Msg;
+       message_summary *Msg = NULL;
        headereval *Hdr;
        void *vHdr;
        char buf[SIZ];
@@ -1413,9 +1480,11 @@ void read_message(long msgnum, int printable_view, char *section) {
                        break;
                }
        }
-
-
-       if (GetHash(MimeRenderHandler, SKEY(Msg->MsgBody.ContentType), &vHdr) &&
+       
+       /* strip the bare contenttype, so we ommit charset etc. */
+       StrBufExtract_token(Buf, Msg->MsgBody.ContentType, 0, ';');
+       StrBufTrim(Buf);
+       if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) &&
            (vHdr != NULL)) {
                RenderMimeFunc Render;
                Render = (RenderMimeFunc)vHdr;
@@ -1470,22 +1539,6 @@ void read_message(long msgnum, int printable_view, char *section) {
        if (nhdr == 1) {
                wprintf("****");
        }
-
-       if (StrLength(Msg->cccc)> 0) {
-               StrBuf *tmp;
-               tmp = Msg->cccc;
-               Msg->cccc = Buf;
-               StrBuf_RFC822_to_Utf8(Msg->cccc, tmp, WCC->DefaultCharset, FoundCharset);
-               Buf = tmp;
-       }
-       if (StrLength(Msg->subj)> 0) {
-               StrBuf *tmp;
-               tmp = Msg->subj;
-               Msg->subj = Buf;
-               StrBuf_RFC822_to_Utf8(Msg->subj, tmp, WCC->DefaultCharset, FoundCharset);
-               Buf = tmp;
-       }
-
        DoTemplate(HKEY("view_message"), NULL, Msg, CTX_MAILSUM);
 
 
@@ -1556,7 +1609,10 @@ void read_message(long msgnum, int printable_view, char *section) {
        if (num_attach_links > 0) {
                free(attach_links);
        }
+       DestroyMessageSummary(Msg);
        FreeStrBuf(&FoundCharset);
+       FreeStrBuf(&Token);
+       FreeStrBuf(&Buf);
 }
 
 
@@ -3851,6 +3907,19 @@ InitModule_MSG
        RegisterNamespace("MAIL:BODY", 0, 2, tmplput_MAIL_BODY,  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);
+
+
+       RegisterIterator("MAIL:MIME:ATTACH", 0, NULL, iterate_get_mime_All, 
+                        tmplput_MIME_ATTACH, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
+       RegisterIterator("MAIL:MIME:ATTACH:SUBMESSAGES", 0, NULL, iterate_get_mime_Submessages, 
+                        tmplput_MIME_ATTACH, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
+       RegisterIterator("MAIL:MIME:ATTACH:LINKS", 0, NULL, iterate_get_mime_AttachLinks, 
+                        tmplput_MIME_ATTACH, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
+       RegisterIterator("MAIL:MIME:ATTACH:ATT", 0, NULL, iterate_get_mime_Attachments, 
+                        tmplput_MIME_ATTACH, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
 
        RegisterMimeRenderer(HKEY("text/x-citadel-variformat"), render_MAIL_variformat);
        RegisterMimeRenderer(HKEY("text/plain"), render_MAIL_text_plain);
@@ -3858,11 +3927,6 @@ InitModule_MSG
        RegisterMimeRenderer(HKEY("text/html"), render_MAIL_html);
        RegisterMimeRenderer(HKEY(""), render_MAIL_UNKNOWN);
 
-
-       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);
-
        RegisterMsgHdr(HKEY("nhdr"), examine_nhdr, 0);
        RegisterMsgHdr(HKEY("type"), examine_type, 0);
        RegisterMsgHdr(HKEY("from"), examine_from, 0);