Finalize vcard editing:
[citadel.git] / webcit / msg_renderers.c
index 2132a2dd42f2271c196cf0d5c6e9e38e846eb4af..ed8de1fe96b56f26fbd66f6b68c5290f7071224a 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();
@@ -329,6 +329,7 @@ void examine_msgn(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
        CheckConvertBufs(WCC);
        FreeStrBuf(&Msg->reply_inreplyto);
        Msg->reply_inreplyto = NewStrBufPlain(NULL, StrLength(HdrLine));
+       Msg->reply_inreplyto_hash = ThreadIdHash(HdrLine);
        StrBuf_RFC822_2_Utf8(Msg->reply_inreplyto, 
                             HdrLine, 
                             WCC->DefaultCharset,
@@ -355,6 +356,7 @@ void examine_wefw(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
        CheckConvertBufs(WCC);
        FreeStrBuf(&Msg->reply_references);
        Msg->reply_references = NewStrBufPlain(NULL, StrLength(HdrLine));
+       Msg->reply_references_hash = ThreadIdHash(HdrLine);
        StrBuf_RFC822_2_Utf8(Msg->reply_references, 
                             HdrLine, 
                             WCC->DefaultCharset, 
@@ -621,8 +623,9 @@ void render_MIME_VCard(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharse
                Buf = NewStrBuf();
                /** If it's my vCard I can edit it */
                if (    (!strcasecmp(ChrPtr(WCC->CurRoom.name), USERCONFIGROOM))
-                       || (!strcasecmp(&(ChrPtr(WCC->CurRoom.name)[11]), USERCONFIGROOM))
-                       || (WC->CurRoom.view == VIEW_ADDRESSBOOK)
+                       || ((StrLength(WCC->CurRoom.name) > 11) &&
+                           (!strcasecmp(&(ChrPtr(WCC->CurRoom.name)[11]), USERCONFIGROOM)))
+                       || (WCC->CurRoom.view == VIEW_ADDRESSBOOK)
                        ) {
                        StrBufAppendPrintf(Buf, "<a href=\"edit_vcard?msgnum=%ld?partnum=%s\">",
                                Mime->msgnum, ChrPtr(Mime->PartNum));
@@ -877,6 +880,43 @@ void examine_content_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCh
        }
 }
 
+
+int ReadOneMessageSummary(message_summary *Msg, StrBuf *FoundCharset, StrBuf *Buf)
+{
+       void *vHdr;
+       headereval *Hdr;
+       const char *buf;
+       const char *ebuf;
+       int nBuf;
+       long len;
+       
+       serv_printf("MSG0 %ld|1", Msg->msgnum); /* ask for headers only */
+       
+       StrBuf_ServGetln(Buf);
+       if (GetServerStatus(Buf, NULL) != 1) {
+               return 0;
+       }
+
+       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 1;
+}
+
 void tmplput_MAIL_SUMM_N(StrBuf *Target, WCTemplputParams *TP)
 {
        message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
@@ -887,12 +927,20 @@ void tmplput_MAIL_SUMM_N(StrBuf *Target, WCTemplputParams *TP)
 void tmplput_MAIL_SUMM_PERMALINK(StrBuf *Target, WCTemplputParams *TP)
 {
        message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
-       char perma_link[1024];
-
-       strcpy(perma_link, "/readfwd?go=");
-       urlesc(&perma_link[12], sizeof(perma_link) - 12, (char *)ChrPtr(WC->CurRoom.name) );
-       sprintf(&perma_link[strlen(perma_link)], "?start_reading_at=%ld#%ld", Msg->msgnum, Msg->msgnum);
-       StrBufAppendPrintf(Target, "%s", perma_link);
+       StrBuf *perma_link;
+       const StrBuf *View;
+
+       perma_link = NewStrBufPlain(HKEY("/readfwd?go="));
+       StrBufUrlescAppend(perma_link, WC->CurRoom.name, NULL);
+       View = sbstr("view");
+       if (View != NULL) {
+               StrBufAppendBufPlain(perma_link, HKEY("?view="), 0);
+               StrBufAppendBuf(perma_link, View, 0);
+       }
+       StrBufAppendBufPlain(perma_link, HKEY("?start_reading_at="), 0);
+       StrBufAppendPrintf(perma_link, "%ld#%ld", Msg->msgnum, Msg->msgnum);
+       StrBufAppendBuf(Target, perma_link, 0);
+       FreeStrBuf(&perma_link);
 }
 
 
@@ -958,6 +1006,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);
@@ -1138,25 +1187,37 @@ void render_MAIL_html(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset
 }
 
 #ifdef HAVE_MARKDOWN
+/*
+char * MarkdownHandleURL(const char* SourceURL, const int len, void* something)
+{
+
+}
+*/
 void render_MAIL_markdown(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
 {
 #include <mkdio.h>
        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_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);
+               }
+               mkd_cleanup(doc);
+       }
 }
 #endif