]> code.citadel.org Git - citadel.git/blobdiff - webcit/messages.c
* catch more render bugs
[citadel.git] / webcit / messages.c
index b67465d6841f4c824f31fb685582353a6d36b2a7..ffbfab310826fa6d01c555fc9e1372c6f3a98a50 100644 (file)
@@ -228,39 +228,35 @@ int summcmp_rdate(const void *s1, const void *s2) {
  * printable_view      Nonzero to display a printable view
  * section             Optional for encapsulated message/rfc822 submessage
  */
-void read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, int printable_view, const char *section) {
+int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, int printable_view, const StrBuf *PartNum) {
        StrBuf *Buf;
        StrBuf *Token;
        StrBuf *FoundCharset;
+       HashPos  *it;
+       void *vMime;
        message_summary *Msg = NULL;
        headereval *Hdr;
        void *vHdr;
        char buf[SIZ];
-       struct attach_link *attach_links = NULL;
-       int num_attach_links = 0;
 //     char mime_submessages[256] = "";
        char reply_references[1024] = "";
-       int i = 0;
        int Done = 0;
        int state=0;
-       char vcard_partnum[256] = "";
-       char cal_partnum[256] = "";
-       char *part_source = NULL;
-       char msg4_partnum[32] = "";
-
-////   strcpy(mime_submessages, "");
+       long len;
+       const char *Key;
 
        Buf = NewStrBuf();
-       serv_printf("MSG4 %ld|%s", msgnum, section);
+       lprintf(1, "----------%s---------MSG4 %ld|%s--------------\n", tmpl, msgnum, ChrPtr(PartNum));
+       serv_printf("MSG4 %ld|%s", msgnum, ChrPtr(PartNum));
        StrBuf_ServGetln(Buf);
        if (GetServerStatus(Buf, NULL) != 1) {
                StrBufAppendPrintf(Target, "<strong>");
                StrBufAppendPrintf(Target, _("ERROR:"));
                StrBufAppendPrintf(Target, "</strong> %s<br />\n", &buf[4]);
                FreeStrBuf(&Buf);
-               return;
+               return 0;
        }
-       svputlong("MsgPrintable", printable_view);
+
        /** begin everythingamundo table */
 
 
@@ -268,6 +264,9 @@ void read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, i
        Msg = (message_summary *)malloc(sizeof(message_summary));
        memset(Msg, 0, sizeof(message_summary));
        Msg->msgnum = msgnum;
+       Msg->PartNum = PartNum;
+       Msg->MsgBody =  (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
+       memset(Msg->MsgBody, 0, sizeof(wc_mime_attachment));
        FoundCharset = NewStrBuf();
        while ((StrBuf_ServGetln(Buf)>=0) && !Done) {
                if ( (StrLength(Buf)==3) && 
@@ -275,6 +274,7 @@ void read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, i
                {
                        Done = 1;
                        if (state < 2) {
+                               lprintf(1, _("unexpected end of message"));
                                StrBufAppendPrintf(Target, "<i>");
                                StrBufAppendPrintf(Target, _("unexpected end of message"));
                                StrBufAppendPrintf(Target, " (1)</i><br /><br />\n");
@@ -283,7 +283,7 @@ void read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, i
                                FreeStrBuf(&Token);
                                DestroyMessageSummary(Msg);
                                FreeStrBuf(&FoundCharset);
-                               return;
+                               return 0;
                        }
                        else {
                                break;
@@ -312,9 +312,9 @@ void read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, i
                case 1:/* Message Mime Header */
                        if (StrLength(Buf) == 0) {
                                state++;
-                               if (Msg->MsgBody.ContentType == NULL)
+                               if (Msg->MsgBody->ContentType == NULL)
                                        /* end of header or no header? */
-                                       Msg->MsgBody.ContentType = NewStrBufPlain(HKEY("text/plain"));
+                                       Msg->MsgBody->ContentType = NewStrBufPlain(HKEY("text/plain"));
                                 /* usual end of mime header */
                        }
                        else
@@ -333,34 +333,38 @@ void read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, i
                        }
                case 2: /* Message Body */
                        
-                       if (Msg->MsgBody.size_known > 0) {
-                               StrBuf_ServGetBLOB(Msg->MsgBody.Data, Msg->MsgBody.length);
+                       if (Msg->MsgBody->size_known > 0) {
+                               StrBuf_ServGetBLOB(Msg->MsgBody->Data, Msg->MsgBody->length);
                                state ++;
                                        /// todo: check next line, if not 000, append following lines
                        }
                        else if (1){
-                               if (StrLength(Msg->MsgBody.Data) > 0)
-                                       StrBufAppendBufPlain(Msg->MsgBody.Data, "\n", 1, 0);
-                               StrBufAppendBuf(Msg->MsgBody.Data, Buf, 0);
+                               if (StrLength(Msg->MsgBody->Data) > 0)
+                                       StrBufAppendBufPlain(Msg->MsgBody->Data, "\n", 1, 0);
+                               StrBufAppendBuf(Msg->MsgBody->Data, Buf, 0);
                        }
                        break;
                case 3:
-                       StrBufAppendBuf(Msg->MsgBody.Data, Buf, 0);
+                       StrBufAppendBuf(Msg->MsgBody->Data, Buf, 0);
                        break;
                }
        }
+
+       if (Msg->AllAttach == NULL)
+               Msg->AllAttach = NewHash(1,NULL);
+       Put(Msg->AllAttach, SKEY(Msg->MsgBody->PartNum), Msg->MsgBody, DestroyMime);
+
        
        /* strip the bare contenttype, so we ommit charset etc. */
-       StrBufExtract_token(Buf, Msg->MsgBody.ContentType, 0, ';');
+       StrBufExtract_token(Buf, Msg->MsgBody->ContentType, 0, ';');
        StrBufTrim(Buf);
        if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) &&
            (vHdr != NULL)) {
                RenderMimeFunc Render;
                Render = (RenderMimeFunc)vHdr;
-               Render(&Msg->MsgBody, NULL, FoundCharset);
+               Render(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.
@@ -404,76 +408,21 @@ void read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, i
                        StrBufAppendBuf(Msg->reply_to, Msg->from, 0);
                }
        }
-       DoTemplate(tmpl, tmpllen, Target, Msg, CTX_MAILSUM);
-
-
-
-//// put message renderer lookup here.
-///ENDBODY:    /* If there are attached submessages, display them now... */
-///
-///    if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
-///            for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
-///                    extract_token(buf, mime_submessages, i, '|', sizeof buf);
-///                    /** use printable_view to suppress buttons */
-///                    wprintf("<blockquote>");
-///                    read_message(msgnum, 1, buf);
-///                    wprintf("</blockquote>");
-///            }
-///    }
-
-
-       /* Afterwards, offer links to download attachments 'n' such */
-       if ( (num_attach_links > 0) && (!section[0]) ) {
-               for (i=0; i<num_attach_links; ++i) {
-                       if (strcasecmp(attach_links[i].partnum, msg4_partnum)) {
-                               wprintf("%s", attach_links[i].html);
-                       }
-               }
+       it = GetNewHashPos();
+       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);
 
-       /* Handler for vCard parts */
-       if (!IsEmptyStr(vcard_partnum)) {
-               part_source = load_mimepart(msgnum, vcard_partnum);
-               if (part_source != NULL) {
-
-                       /** If it's my vCard I can edit it */
-                       if (    (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
-                               || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
-                               || (WC->wc_view == VIEW_ADDRESSBOOK)
-                       ) {
-                               wprintf("<a href=\"edit_vcard?msgnum=%ld&partnum=%s\">",
-                                       msgnum, vcard_partnum);
-                               wprintf("[%s]</a>", _("edit"));
-                       }
-
-                       /* In all cases, display the full card */
-                       display_vcard(WC->WBuf, part_source, 0, 1, NULL,msgnum);
-               }
-       }
-
-       /* Handler for calendar parts */
-       if (!IsEmptyStr(cal_partnum)) {
-       }
-
-       if (part_source) {
-               free(part_source);
-               part_source = NULL;
-       }
-
-       wprintf("</div>\n");
-
-       /* end everythingamundo table */
-       if (!printable_view) {
-               wprintf("</div>\n");
-       }
+       DoTemplate(tmpl, tmpllen, Target, Msg, CTX_MAILSUM);
 
-       if (num_attach_links > 0) {
-               free(attach_links);
-       }
        DestroyMessageSummary(Msg);
        FreeStrBuf(&FoundCharset);
        FreeStrBuf(&Token);
        FreeStrBuf(&Buf);
+       return 1;
 }
 
 
@@ -490,9 +439,9 @@ void embed_message(void) {
 
        msgnum = StrTol(WC->UrlFragment1);
        if (StrLength(Tmpl) > 0) 
-               read_message(WC->WBuf, SKEY(Tmpl), msgnum, 0, "");
+               read_message(WC->WBuf, SKEY(Tmpl), msgnum, 0, NULL);
        else 
-               read_message(WC->WBuf, HKEY("view_message"), msgnum, 0, "");
+               read_message(WC->WBuf, HKEY("view_message"), msgnum, 0, NULL);
 }
 
 
@@ -513,7 +462,7 @@ void print_message(void) {
 
        begin_burst();
 
-       read_message(WC->WBuf, HKEY("view_message_print"), msgnum, 1, "");
+       read_message(WC->WBuf, HKEY("view_message_print"), msgnum, 1, NULL);
 
        wDumpContent(0);
 }
@@ -529,7 +478,7 @@ void mobile_message_view(void) {
   output_headers(1, 0, 0, 0, 0, 1);
   begin_burst();
   do_template("msgcontrols", NULL);
-  read_message(WC->WBuf, HKEY("view_message"), msgnum,1, "");
+  read_message(WC->WBuf, HKEY("view_message"), msgnum,1, NULL);
   wDumpContent(0);
 }
 
@@ -894,22 +843,6 @@ ENDBODY:
 
 
 
-void EvaluateMimePart(message_summary *Sum, StrBuf *Buf)
-{//// paert=; TODO
-/*
-       extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
-       extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
-       extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
-       extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
-       mime_length = extract_int(&buf[5], 5);
-       
-       if (  (!strcasecmp(mime_content_type, "text/x-vcard"))
-             || (!strcasecmp(mime_content_type, "text/vcard")) ) {
-               strcpy(vcard_partnum, mime_partnum);
-       }
-*/
-}
-
 message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSubject, long MsgNum) 
 {
        void                 *vEval;
@@ -1610,7 +1543,7 @@ void readloop(char *oper)
                /** if we do a split bbview in the future, begin messages div here */
 
                for (a=0; a<num_displayed; ++a) {
-                       read_message(WC->WBuf, HKEY("view_message"), displayed_msgs[a], 0, "");
+                       read_message(WC->WBuf, HKEY("view_message"), displayed_msgs[a], 0, NULL);
                }
 
                /** if we do a split bbview in the future, end messages div here */