* typedef wcsession, so we don't always need to say gcc again its a struct.
[citadel.git] / webcit / msg_renderers.c
index 11a2613a0a59878efa6dad8e3cbf40a2f4e2c665..c10c7cd987364b16cb4491add469fa4ea4791714 100644 (file)
@@ -6,6 +6,7 @@
  * message index functions
  */
 
+
 void DestroyMimeParts(wc_mime_attachment *Mime)
 {
        FreeStrBuf(&Mime->Name);
@@ -175,9 +176,10 @@ int summcmp_rdate(const void *s1, const void *s2) {
 }
 
 /*----------------------------------------------------------------------------*/
-
-
-
+/* Don't wanna know... or? */
+void examine_pref(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
+void examine_suff(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
+void examine_path(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
 
 void examine_nhdr(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
 {
@@ -354,6 +356,10 @@ void tmplput_MAIL_SUMM_ALLRCPT(StrBuf *Target, int nArgs, WCTemplateToken *Token
 }
 
 
+HashList *iterate_get_mailsumm_All(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       return WC->summ;
+}
 
 void examine_time(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
 {
@@ -382,7 +388,7 @@ void render_MAIL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset
        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 * /
+                       / ** use printable_view to suppress buttons * /
                        wprintf("<blockquote>");
                        read_message(Mime->msgnum, 1, ChrPtr(Mime->Section));
                        wprintf("</blockquote>");
@@ -908,6 +914,34 @@ void tmplput_MIME_Data(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void
  /// TODO: check whether we need to load it now?
 }
 
+void tmplput_MIME_LoadData(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       wcsession *WCC = WC;    
+       wc_mime_attachment *mime = (wc_mime_attachment*) Context;
+       wc_mime_attachment *att;
+       
+       if ( (!strcasecmp(ChrPtr(mime->Disposition), "inline"))||
+            (!strcasecmp(ChrPtr(mime->Disposition), "attachment")) ) 
+       {
+               
+               int n;
+               char N[64];
+               /* steal this mime part... */
+               att = malloc(sizeof(wc_mime_attachment));
+               memcpy(att, mime, sizeof(wc_mime_attachment));
+               memset(mime, 0, sizeof(wc_mime_attachment));
+
+               if (att->Data == NULL) 
+                       MimeLoadData(att);
+
+               if (WCC->attachments == NULL)
+                       WCC->attachments = NewHash(1, NULL);
+               /* And add it to the list. */
+               n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
+               Put(WCC->attachments, N, n, att, DestroyMime);
+       }
+}
+
 void tmplput_MIME_Length(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
 {
        wc_mime_attachment *mime = (wc_mime_attachment*) Context;
@@ -919,24 +953,45 @@ HashList *iterate_get_registered_Attachments(StrBuf *Target, int nArgs, WCTempla
        return WC->attachments;
 }
 
-void tmplput_ATT_Length(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void servcmd_do_search(char *buf, long bufsize)
 {
-       wc_attachment *att = (wc_attachment*) Context;
-       StrBufAppendPrintf(Target, "%ld", att->length);
+       snprintf(buf, bufsize, "MSGS SEARCH|%s", bstr("query"));
 }
 
-void tmplput_ATT_Contenttype(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void servcmd_headers(char *buf, long bufsize)
 {
-       wc_attachment *att = (wc_attachment*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, att->content_type, 0);
+       snprintf(buf, bufsize, "MSGS ALL");
 }
 
-void tmplput_ATT_FileName(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+void servcmd_readfwd(char *buf, long bufsize)
 {
-       wc_attachment *att = (wc_attachment*) Context;
-       StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, att->filename, 0);
+       snprintf(buf, bufsize, "MSGS ALL");
 }
 
+void servcmd_readnew(char *buf, long bufsize)
+{
+       snprintf(buf, bufsize, "MSGS NEW");
+}
+
+void servcmd_readold(char *buf, long bufsize)
+{
+       snprintf(buf, bufsize, "MSGS OLD");
+}
+
+
+readloop_struct rlid[] = {
+       { {HKEY("do_search")}, servcmd_do_search},
+       { {HKEY("headers")},   servcmd_headers},
+       { {HKEY("readfwd")},   servcmd_readfwd},
+       { {HKEY("readnew")},   servcmd_readnew},
+       { {HKEY("readold")},   servcmd_readold}
+};
+
+
+
+
+               
+
 
 
 
@@ -960,6 +1015,9 @@ InitModule_MSGRENDERERS
                         summcmp_rsender,
                         CTX_MAILSUM);
 
+       RegisterIterator("MAIL:SUMM:MSGS", 0, NULL, iterate_get_mailsumm_All,
+                        NULL,NULL, CTX_MAILSUM, CTX_NONE);
+
        RegisterNamespace("MAIL:SUMM:DATESTR", 0, 0, tmplput_MAIL_SUMM_DATE_STR, CTX_MAILSUM);
        RegisterNamespace("MAIL:SUMM:DATENO",  0, 0, tmplput_MAIL_SUMM_DATE_NO,  CTX_MAILSUM);
        RegisterNamespace("MAIL:SUMM:N",       0, 0, tmplput_MAIL_SUMM_N,        CTX_MAILSUM);
@@ -977,11 +1035,8 @@ InitModule_MSGRENDERERS
        RegisterNamespace("MAIL:SUMM:INREPLYTO", 0, 2, tmplput_MAIL_SUMM_INREPLYTO,  CTX_MAILSUM);
        RegisterNamespace("MAIL:BODY", 0, 2, tmplput_MAIL_BODY,  CTX_MAILSUM);
        RegisterNamespace("MAIL:QUOTETEXT", 1, 2, tmplput_QUOTED_MAIL_BODY,  CTX_NONE);
-       RegisterNamespace("ATT:SIZE", 0, 1, tmplput_ATT_Length, CTX_ATT);
-       RegisterNamespace("ATT:TYPE", 0, 1, tmplput_ATT_Contenttype, CTX_ATT);
-       RegisterNamespace("ATT:FILENAME", 0, 1, tmplput_ATT_FileName, CTX_ATT);
 
-       RegisterConditional(HKEY("MAIL:SUMM:RFCA"), 0, Conditional_MAIL_SUMM_RFCA,  CTX_MAILSUM);
+       RegisterConditional(HKEY("COND:MAIL:SUMM:RFCA"), 0, Conditional_MAIL_SUMM_RFCA,  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);
@@ -1010,9 +1065,10 @@ InitModule_MSGRENDERERS
        RegisterNamespace("MAIL:MIME:CHARSET", 0, 2, tmplput_MIME_Charset, CTX_MIME_ATACH);
        RegisterNamespace("MAIL:MIME:LENGTH", 0, 2, tmplput_MIME_Length, CTX_MIME_ATACH);
        RegisterNamespace("MAIL:MIME:DATA", 0, 2, tmplput_MIME_Data, CTX_MIME_ATACH);
+       RegisterNamespace("MAIL:MIME:LOADDATA", 0, 0, tmplput_MIME_LoadData, CTX_MIME_ATACH);
 
        RegisterIterator("MSG:ATTACHNAMES", 0, NULL, iterate_get_registered_Attachments, 
-                        NULL, NULL, CTX_ATT, CTX_NONE);
+                        NULL, NULL, CTX_MIME_ATACH, CTX_NONE);
 
        RegisterMimeRenderer(HKEY("message/rfc822"), render_MAIL);
        RegisterMimeRenderer(HKEY("text/x-vcard"), render_MIME_VCard);
@@ -1046,4 +1102,9 @@ InitModule_MSGRENDERERS
        RegisterMsgHdr(HKEY("Content-length"), examine_content_lengh, 0);
        RegisterMsgHdr(HKEY("Content-transfer-encoding"), examine_content_encoding, 0);
        RegisterMsgHdr(HKEY("charset"), examine_charset, 0);
+
+       /* Don't care... */
+       RegisterMsgHdr(HKEY("pref"), examine_pref, 0);
+       RegisterMsgHdr(HKEY("suff"), examine_suff, 0);
+       RegisterMsgHdr(HKEY("path"), examine_path, 0);
 }