* display attachments in messages as view/download links
authorWilfried Göesgens <willi@citadel.org>
Fri, 7 Nov 2008 20:57:16 +0000 (20:57 +0000)
committerWilfried Göesgens <willi@citadel.org>
Fri, 7 Nov 2008 20:57:16 +0000 (20:57 +0000)
webcit/messages.c
webcit/static/t/view_message.html
webcit/static/t/view_message_list_attach.html [new file with mode: 0644]
webcit/webcit.h

index d05d988efbd9d8a3c5dea55cf71777b71eaaa1ce..baa2255d86e4b871ad503f4151aa87443fbd7064 100644 (file)
@@ -361,6 +361,11 @@ void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, int nArgs, WCTemplateToken *Tok
        StrBufAppendBuf(Target, Msg->reply_inreplyto, 0);
 }
 
+int Conditional_MAIL_SUMM_UNREAD(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       message_summary *Msg = (message_summary*) Context;
+       return Msg->is_new != 0;
+}
 
 void examine_wefw(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
 {
@@ -657,10 +662,29 @@ void tmplput_MAIL_SUMM_N(StrBuf *Target, int nArgs, WCTemplateToken *Token, void
 }
 
 
-int Conditional_MAIL_SUMM_UNREAD(WCTemplateToken *Tokens, void *Context, int ContextType)
+
+int Conditional_MAIL_MIME_ALL(WCTemplateToken *Tokens, void *Context, int ContextType)
 {
        message_summary *Msg = (message_summary*) Context;
-       return Msg->is_new != 0;
+       return GetCount(Msg->Attachments) > 0;
+}
+
+int Conditional_MAIL_MIME_SUBMESSAGES(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       message_summary *Msg = (message_summary*) Context;
+       return GetCount(Msg->Submessages) > 0;
+}
+
+int Conditional_MAIL_MIME_ATTACHLINKS(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       message_summary *Msg = (message_summary*) Context;
+       return GetCount(Msg->AttachLinks) > 0;
+}
+
+int Conditional_MAIL_MIME_ATTACH(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       message_summary *Msg = (message_summary*) Context;
+       return GetCount(Msg->AllAttach) > 0;
 }
 
 
@@ -814,7 +838,7 @@ 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;
+       return Msg->Attachments;
 }
 HashList *iterate_get_mime_Submessages(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
 {
@@ -832,12 +856,59 @@ HashList *iterate_get_mime_Attachments(StrBuf *Target, int nArgs, WCTemplateToke
        return Msg->AllAttach;
 }
 
+void tmplput_MIME_Name(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
+{
+       wc_mime_attachment *mime = (wc_mime_attachment*) Context;
+       StrBufAppendBuf(Target, mime->Name, 0);
+}
+
+void tmplput_MIME_FileName(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
+{
+       wc_mime_attachment *mime = (wc_mime_attachment*) Context;
+       StrBufAppendBuf(Target, mime->FileName, 0);
+}
 
-void tmplput_MIME_ATTACH(StrBuf *TemplBuffer, void *Context, WCTemplateToken *Token)
+void tmplput_MIME_PartNum(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
 {
+       wc_mime_attachment *mime = (wc_mime_attachment*) Context;
+       StrBufAppendBuf(Target, mime->PartNum, 0);
 }
 
+void tmplput_MIME_MsgNum(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
+{
+       wc_mime_attachment *mime = (wc_mime_attachment*) Context;
+       StrBufAppendPrintf(Target, "%ld", mime->msgnum);
+}
 
+void tmplput_MIME_Disposition(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
+{
+       wc_mime_attachment *mime = (wc_mime_attachment*) Context;
+       StrBufAppendBuf(Target, mime->Disposition, 0);
+}
+
+void tmplput_MIME_ContentType(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
+{
+       wc_mime_attachment *mime = (wc_mime_attachment*) Context;
+       StrBufAppendBuf(Target, mime->ContentType, 0);
+}
+
+void tmplput_MIME_Charset(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
+{
+       wc_mime_attachment *mime = (wc_mime_attachment*) Context;
+       StrBufAppendBuf(Target, mime->Charset, 0);
+}
+
+void tmplput_MIME_Data(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
+{
+       wc_mime_attachment *mime = (wc_mime_attachment*) Context;
+       StrBufAppendBuf(Target, mime->Data, 0); /// TODO: check whether we need to load it now?
+}
+
+void tmplput_MIME_Length(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
+{
+       wc_mime_attachment *mime = (wc_mime_attachment*) Context;
+       StrBufAppendPrintf(Target, "%ld", mime->length);
+}
 
 
 
@@ -3911,15 +3982,32 @@ InitModule_MSG
        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);
 
+       RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH"), 0, Conditional_MAIL_MIME_ALL, CTX_MAILSUM);
+       RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:SUBMESSAGES"), 0, Conditional_MAIL_MIME_SUBMESSAGES, CTX_MAILSUM);
+       RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:LINKS"), 0, Conditional_MAIL_MIME_ATTACHLINKS, CTX_MAILSUM);
+       RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:ATT"), 0, Conditional_MAIL_MIME_ATTACH, CTX_MAILSUM);
+
 
        RegisterIterator("MAIL:MIME:ATTACH", 0, NULL, iterate_get_mime_All, 
-                        tmplput_MIME_ATTACH, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
+                        NULL, 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);
+                        NULL, 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);
+                        NULL, 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);
+                        NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
+
+       RegisterNamespace("MAIL:MIME:NAME", 0, 2, tmplput_MIME_Name, CTX_MIME_ATACH);
+       RegisterNamespace("MAIL:MIME:FILENAME", 0, 2, tmplput_MIME_FileName, CTX_MIME_ATACH);
+       RegisterNamespace("MAIL:MIME:PARTNUM", 0, 2, tmplput_MIME_PartNum, CTX_MIME_ATACH);
+       RegisterNamespace("MAIL:MIME:MSGNUM", 0, 2, tmplput_MIME_MsgNum, CTX_MIME_ATACH);
+       RegisterNamespace("MAIL:MIME:DISPOSITION", 0, 2, tmplput_MIME_Disposition, CTX_MIME_ATACH);
+       RegisterNamespace("MAIL:MIME:CONTENTTYPE", 0, 2, tmplput_MIME_ContentType, CTX_MIME_ATACH);
+       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);
+
+
 
        RegisterMimeRenderer(HKEY("text/x-citadel-variformat"), render_MAIL_variformat);
        RegisterMimeRenderer(HKEY("text/plain"), render_MAIL_text_plain);
index 29040b7cee48e820ad240033df1abe2857a1b9cd..9a43a3a2035f8e225003d7baa95edd5124c17cfb 100644 (file)
@@ -25,4 +25,8 @@ onMouseOut=document.getElementById("msg<?MAIL:SUMM:N>").style.visibility="hidden
 <div class="message_content"><div align="justify">
 <?MAIL:BODY>    
 </div>
+<?!("COND:MAIL:MIME:ATTACH:LINKS", 1)>
+<?ITERATE("MAIL:MIME:ATTACH:LINKS", "view_message_list_attach")>
+<?!("X", 1)>
+
 </div>
diff --git a/webcit/static/t/view_message_list_attach.html b/webcit/static/t/view_message_list_attach.html
new file mode 100644 (file)
index 0000000..e15d40d
--- /dev/null
@@ -0,0 +1,4 @@
+<img src="display_mime_icon?type=<?MAIL:MIME:CONTENTTYPE("U")>" border=0 align=middle>
+<?MAIL:MIME:FILENAME("X")>  (<?MAIL:MIME:CONTENTTYPE>, <?MAIL:MIME:LENGTH> bytes) 
+[ <a href="mimepart/<?MAIL:MIME:MSGNUM>/<?MAIL:MIME:PARTNUM>/<?MAIL:MIME:FILENAME("U")>" target="wc.<?MAIL:MIME:MSGNUM>.<?MAIL:MIME:PARTNUM>"><?_("View")></a> | 
+ <a href="mimepart_download/<?MAIL:MIME:MSGNUM>/<?MAIL:MIME:PARTNUM>/<?MAIL:MIME:FILENAME("U")>"><?_("Download")></a> ]<br />
index 0848579dade6d490314879d2344741b708420919..bbc026ebaed7b1bdb8e9114f8ea4a15de0201c34 100644 (file)
@@ -337,14 +337,14 @@ void RegisterConditional(const char *Name, long len,
 typedef void (*SubTemplFunc)(StrBuf *TemplBuffer, void *Context, WCTemplateToken *Token);
 typedef HashList *(*RetrieveHashlistFunc)(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType);
 typedef void (*HashDestructorFunc) (HashList **KillMe);
-void RegisterITERATOR(const char *Name, long len,
-                     int AdditionalParams, 
-                     HashList *StaticList, 
-                     RetrieveHashlistFunc GetHash, 
-                     SubTemplFunc DoSubTempl,
-                     HashDestructorFunc Destructor,
-                     int ContextType, 
-                     int XPectContextType);
+void RegisterITERATOR(const char *Name, long len, /* Our identifier */
+                     int AdditionalParams,       /* doe we use more parameters? */
+                     HashList *StaticList,       /* pointer to webcit lifetime hashlists */
+                     RetrieveHashlistFunc GetHash, /* else retrieve the hashlist by calling this function */
+                     SubTemplFunc DoSubTempl,       /* call this function on each iteration for svput & friends */
+                     HashDestructorFunc Destructor, /* use this function to shut down the hash; NULL if its a reference */
+                     int ContextType,               /* which context do we provide to the subtemplate? */
+                     int XPectContextType);         /* which context do we expct to be called in? */
 #define RegisterIterator(a, b, c, d, e, f, g, h) RegisterITERATOR(a, sizeof(a)-1, b, c, d, e, f, g, h)
 
 void SVPut(char *keyname, size_t keylen, int keytype, char *Data);