Move over deprecated function, adopt to new handler structures
[citadel.git] / webcit / msg_renderers.c
index 922ff6201728fabef530c1b07a8bcaf4e2db7276..9c63236903813da9046d502827dc2c5930e4a8a4 100644 (file)
@@ -5,7 +5,7 @@
 CtxType CTX_MAILSUM = CTX_NONE;
 CtxType CTX_MIME_ATACH = CTX_NONE;
 
-inline void CheckConvertBufs(struct wcsession *WCC)
+static inline void CheckConvertBufs(struct wcsession *WCC)
 {
        if (WCC->ConvertBuf1 == NULL)
                WCC->ConvertBuf1 = NewStrBuf();
@@ -877,6 +877,50 @@ void examine_content_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCh
        }
 }
 
+
+message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSubject, StrBuf *FoundCharset, long MsgNum) 
+{
+       void *vHdr;
+       headereval *Hdr;
+       message_summary      *Msg;
+       StrBuf *Buf;
+       const char *buf;
+       const char *ebuf;
+       int nBuf;
+       long len;
+       
+       Buf = NewStrBuf();
+
+       serv_printf("MSG0 %ld|1", MsgNum);      /* ask for headers only */
+       
+       StrBuf_ServGetln(Buf);
+       if (GetServerStatus(Buf, NULL) == 1) {
+               FreeStrBuf(&Buf);
+               return NULL;
+       }
+
+       Msg = (message_summary*)malloc(sizeof(message_summary));
+       memset(Msg, 0, sizeof(message_summary));
+       while (len = StrBuf_ServGetln(Buf),
+              (len >= 0) && 
+              ((len != 3)  ||
+               strcmp(ChrPtr(Buf), "000")))
+       {
+               buf = ChrPtr(Buf);
+               ebuf = strchr(ChrPtr(Buf), '=');
+               nBuf = ebuf - buf;
+               
+               if (GetHash(MsgHeaderHandler, buf, nBuf, &vHdr) &&
+                   (vHdr != NULL)) {
+                       Hdr = (headereval*)vHdr;
+                       StrBufCutLeft(Buf, nBuf + 1);
+                       Hdr->evaluator(Msg, Buf, FoundCharset);
+               }
+               else syslog(LOG_INFO, "Don't know how to handle Message Headerline [%s]", ChrPtr(Buf));
+       }
+       return Msg;
+}
+
 void tmplput_MAIL_SUMM_N(StrBuf *Target, WCTemplputParams *TP)
 {
        message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
@@ -958,6 +1002,7 @@ void tmplput_EDIT_WIKI_BODY(StrBuf *Target, WCTemplputParams *TP)
         */
        if (!havebstr("attach_button")) {
                char *wikipage = strdup(bstr("page"));
+               putbstr("format", NewStrBufPlain(HKEY("plain")));
                str_wiki_index(wikipage);
                msgnum = locate_message_by_uid(wikipage);
                free(wikipage);
@@ -1150,20 +1195,26 @@ void render_MAIL_markdown(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCha
        wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
        MMIOT *doc;
        char *md_as_html = NULL;
+       const char *format;
 
        if (StrLength(Mime->Data) == 0)
                return;
 
-       doc = mkd_string(ChrPtr(Mime->Data), StrLength(Mime->Data), 0);
-       mkd_basename(doc, "/wiki?page=");
-       mkd_compile(doc, 0);
-       if (mkd_document(doc, &md_as_html) != EOF) {
-               FreeStrBuf(&Mime->Data);
-               Mime->Data = NewStrBufPlain(md_as_html, -1);
-       }
-//     free(md_as_html);
-       mkd_cleanup(doc);
+       format = bstr("format");
 
+       if ((format == NULL) || 
+           strcmp(format, "plain"))
+       {
+               doc = mkd_string(ChrPtr(Mime->Data), StrLength(Mime->Data), 0);
+               mkd_basename(doc, "/wiki?page=");
+               mkd_compile(doc, 0);
+               if (mkd_document(doc, &md_as_html) != EOF) {
+                       FreeStrBuf(&Mime->Data);
+                       Mime->Data = NewStrBufPlain(md_as_html, -1);
+               }
+//     free(md_as_html);
+               mkd_cleanup(doc);
+       }
 }
 #endif