]> code.citadel.org Git - citadel.git/blobdiff - webcit/messages.c
* output the mime type of the tepmlate in read_message so we can have different ones
[citadel.git] / webcit / messages.c
index 2edbafcdf07ad841d47dae30460d4a7cabb2bfe9..6b683a1e65b6332314f2c785d00b6d5272fcdd36 100644 (file)
@@ -67,7 +67,7 @@ int load_message(message_summary *Msg,
 
        /** begin everythingamundo table */
        HdrToken = NewStrBuf();
-       while ((StrBuf_ServGetlnBuffered(Buf)>=0) && !Done) {
+       while ((StrBuf_ServGetln(Buf)>=0) && !Done) {
                if ( (StrLength(Buf)==3) && 
                    !strcmp(ChrPtr(Buf), "000")) 
                {
@@ -206,7 +206,7 @@ int load_message(message_summary *Msg,
  * printable_view      Nonzero to display a printable view
  * section             Optional for encapsulated message/rfc822 submessage
  */
-int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, const StrBuf *PartNum) 
+int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, const StrBuf *PartNum, const StrBuf **OutMime
 {
        StrBuf *Buf;
        StrBuf *FoundCharset;
@@ -267,7 +267,7 @@ int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, co
        memset(&SubTP, 0, sizeof(WCTemplputParams));
        SubTP.Filter.ContextType = CTX_MAILSUM;
        SubTP.Context = Msg;
-       DoTemplate(tmpl, tmpllen, Target, &SubTP);
+       *OutMime = DoTemplate(tmpl, tmpllen, Target, &SubTP);
 
        DestroyMessageSummary(Msg);
        FreeStrBuf(&FoundCharset);
@@ -287,15 +287,40 @@ int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, co
  * msgnum_as_string == Message number, as a string instead of as a long int
  */
 void embed_message(void) {
+       const StrBuf *Mime;
        long msgnum = 0L;
        wcsession *WCC = WC;
-       const StrBuf *Tmpl = sbstr("template");
+       const StrBuf *Tmpl;
+       StrBuf *CmdBuf = NULL;
 
        msgnum = StrTol(WCC->UrlFragment2);
-       if (StrLength(Tmpl) > 0) 
-               read_message(WCC->WBuf, SKEY(Tmpl), msgnum, NULL);
-       else 
-               read_message(WCC->WBuf, HKEY("view_message"), msgnum, NULL);
+       switch (WCC->eReqType)
+       {
+       case eGET:
+       case ePOST:
+               Tmpl = sbstr("template");
+               if (StrLength(Tmpl) > 0) 
+                       read_message(WCC->WBuf, SKEY(Tmpl), msgnum, NULL, &Mime);
+               else 
+                       read_message(WCC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
+               http_transmit_thing(ChrPtr(Mime), 0);
+               break;
+       case eDELETE:
+               CmdBuf = NewStrBuf ();
+               if (WCC->wc_is_trash) { /** Delete from Trash is a real delete */
+                       serv_printf("DELE %ld", msgnum);        
+               }
+               else {                  /** Otherwise move it to Trash */
+                       serv_printf("MOVE %ld|_TRASH_|0", msgnum);
+               }
+               StrBuf_ServGetln(CmdBuf);
+               FlushStrBuf(WCC->ImportantMsg);
+               StrBufAppendBuf(WCC->ImportantMsg, CmdBuf, 4);
+               break;
+       default:
+               break;
+
+       }
 }
 
 
@@ -306,6 +331,7 @@ void embed_message(void) {
  */
 void print_message(void) {
        long msgnum = 0L;
+       const StrBuf *Mime;
 
        msgnum = StrTol(WC->UrlFragment2);
        output_headers(0, 0, 0, 0, 0, 0);
@@ -316,7 +342,7 @@ void print_message(void) {
 
        begin_burst();
 
-       read_message(WC->WBuf, HKEY("view_message_print"), msgnum, NULL);
+       read_message(WC->WBuf, HKEY("view_message_print"), msgnum, NULL, &Mime);
 
        wDumpContent(0);
 }
@@ -326,14 +352,17 @@ void print_message(void) {
  *
  * @param msg_num_as_string Message number as a string instead of as a long int 
  */
-void mobile_message_view(void) {
-  long msgnum = 0L;
-  msgnum = StrTol(WC->UrlFragment2);
-  output_headers(1, 0, 0, 0, 0, 1);
-  begin_burst();
-  do_template("msgcontrols", NULL);
-  read_message(WC->WBuf, HKEY("view_message"), msgnum, NULL);
-  wDumpContent(0);
+void mobile_message_view(void) 
+{
+       long msgnum = 0L;
+       const StrBuf *Mime;
+  
+       msgnum = StrTol(WC->UrlFragment2);
+       output_headers(1, 0, 0, 0, 0, 1);
+       begin_burst();
+       do_template("msgcontrols", NULL);
+       read_message(WC->WBuf, HKEY("view_message"), msgnum, NULL, &Mime);
+       wDumpContent(0);
 }
 
 /**
@@ -381,7 +410,7 @@ message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSu
 
        serv_printf("MSG0 %ld|1", MsgNum);      /* ask for headers only */
        
-       StrBuf_ServGetlnBuffered(Buf);
+       StrBuf_ServGetln(Buf);
        if (GetServerStatus(Buf, NULL) == 1) {
                FreeStrBuf(&Buf);
                return NULL;
@@ -389,7 +418,7 @@ message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSu
 
        Msg = (message_summary*)malloc(sizeof(message_summary));
        memset(Msg, 0, sizeof(message_summary));
-       while (len = StrBuf_ServGetlnBuffered(Buf),
+       while (len = StrBuf_ServGetln(Buf),
               ((len != 3)  ||
                strcmp(ChrPtr(Buf), "000")== 0)){
                buf = ChrPtr(Buf);
@@ -426,7 +455,7 @@ int load_msg_ptrs(const char *servcmd, int with_headers)
        long len;
        int n;
        int skipit;
-       const char *Ptr;
+       const char *Ptr = NULL;
 
        if (WCC->summ != NULL) {
                DeleteHash(&WCC->summ);
@@ -436,13 +465,13 @@ int load_msg_ptrs(const char *servcmd, int with_headers)
        
        Buf = NewStrBuf();
        serv_puts(servcmd);
-       StrBuf_ServGetlnBuffered(Buf);
+       StrBuf_ServGetln(Buf);
        if (GetServerStatus(Buf, NULL) != 1) {
                FreeStrBuf(&Buf);
                return (nummsgs);
        }
        Buf2 = NewStrBuf();
-       while (len = StrBuf_ServGetlnBuffered(Buf),
+       while (len = StrBuf_ServGetln(Buf),
               ((len != 3)  ||
                strcmp(ChrPtr(Buf), "000")!= 0))
        {
@@ -693,6 +722,7 @@ void readloop(long oper)
        int defaultsortorder = 0;
        WCTemplputParams SubTP;
        char *ab_name;
+       const StrBuf *Mime;
 
        if (havebstr("is_summary") && (1 == (ibstr("is_summary"))))
                WCC->wc_view = VIEW_MAILBOX;
@@ -884,6 +914,8 @@ void readloop(long oper)
                        case VIEW_ADDRESSBOOK:
                                ab_name = NULL;
                                fetch_ab_name(Msg, &ab_name);
+                               if (ab_name == NULL) 
+                                       break;
                                ++num_ab;
                                addrbook = realloc(addrbook,
                                                   (sizeof(addrbookent) * num_ab) );
@@ -924,7 +956,7 @@ void readloop(long oper)
                        /** if we do a split bbview in the future, begin messages div here */
                        
                        for (a=0; a<num_displayed; ++a) {
-                               read_message(WCC->WBuf, HKEY("view_message"), displayed_msgs[a], NULL);
+                               read_message(WCC->WBuf, HKEY("view_message"), displayed_msgs[a], NULL, &Mime);
                        }
                        
                        /** if we do a split bbview in the future, end messages div here */
@@ -958,7 +990,7 @@ DONE:
                break;
        case VIEW_ADDRESSBOOK:
                if (is_singlecard)
-                       read_message(WC->WBuf, HKEY("view_message"), lbstr("startmsg"), NULL);
+                       read_message(WC->WBuf, HKEY("view_message"), lbstr("startmsg"), NULL, &Mime);
                else
                        do_addrbook_view(addrbook, num_ab);     /** Render the address book */
                break;
@@ -1574,7 +1606,7 @@ void mimepart(int force_download)
 
        Buf = NewStrBuf();
        serv_printf("OPNA %s|%s", ChrPtr(WCC->UrlFragment2), ChrPtr(WCC->UrlFragment3));
-       StrBuf_ServGetlnBuffered(Buf);
+       StrBuf_ServGetln(Buf);
        if (GetServerStatus(Buf, NULL) == 2) {
                StrBufCutLeft(Buf, 4);
                bytes = StrBufExtract_long(Buf, 0, '|');
@@ -1584,7 +1616,7 @@ void mimepart(int force_download)
 
                read_server_binary(WCC->WBuf, bytes, Buf);
                serv_puts("CLOS");
-               StrBuf_ServGetlnBuffered(Buf);
+               StrBuf_ServGetln(Buf);
                CT = ChrPtr(ContentType);
 
                if (!force_download) {
@@ -1620,11 +1652,12 @@ StrBuf *load_mimepart(long msgnum, char *partnum)
        
        Buf = NewStrBuf();
        serv_printf("DLAT %ld|%s", msgnum, partnum);
-       StrBuf_ServGetlnBuffered(Buf);
+       StrBuf_ServGetln(Buf);
        if (GetServerStatus(Buf, NULL) == 6) {
                StrBufCutLeft(Buf, 4);
                bytes = StrBufExtract_long(Buf, 0, '|');
-
+               FreeStrBuf(&Buf);
+               Buf = NewStrBuf();
                StrBuf_ServGetBLOBBuffered(Buf, bytes);
                return(Buf);
        }
@@ -1644,7 +1677,7 @@ void MimeLoadData(wc_mime_attachment *Mime)
 /* TODO: is there a chance the contenttype is different  to the one we know?    */
        serv_printf("DLAT %ld|%s", Mime->msgnum, ChrPtr(Mime->PartNum));
        Buf = NewStrBuf();
-       StrBuf_ServGetlnBuffered(Buf);
+       StrBuf_ServGetln(Buf);
        if (GetServerStatus(Buf, NULL) == 6) {
                bytes = extract_long(&(ChrPtr(Buf)[4]), 0);
                                     
@@ -1749,7 +1782,7 @@ InitModule_MSG
        WebcitAddUrlHandler(HKEY("move_msg"), move_msg, 0);
        WebcitAddUrlHandler(HKEY("delete_msg"), delete_msg, 0);
        WebcitAddUrlHandler(HKEY("confirm_move_msg"), confirm_move_msg, 0);
-       WebcitAddUrlHandler(HKEY("msg"), embed_message, NEED_URL|AJAX);
+       WebcitAddUrlHandler(HKEY("msg"), embed_message, NEED_URL);
        WebcitAddUrlHandler(HKEY("printmsg"), print_message, NEED_URL);
        WebcitAddUrlHandler(HKEY("mobilemsg"), mobile_message_view, NEED_URL);
        WebcitAddUrlHandler(HKEY("msgheaders"), display_headers, NEED_URL);
@@ -1763,3 +1796,10 @@ InitModule_MSG
        WebcitAddUrlHandler(HKEY("roommsgs"), jsonMessageList,0);
        return ;
 }
+
+void
+SessionDetachModule_MSG
+(wcsession *sess)
+{
+       DeleteHash(&sess->summ);
+}