]> code.citadel.org Git - citadel.git/blobdiff - webcit/messages.c
+ add non-TP-Related Wildfire enabled error logging function
[citadel.git] / webcit / messages.c
index 171b73e0237f6481cf3442932f682954768cc0ff..d60b2eefb9ecf4647418774814a6a4f1daeb394a 100644 (file)
@@ -43,7 +43,9 @@ typedef struct _MsgPartEvaluatorStruct {
  * 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, int printable_view, const StrBuf *PartNum) {
+int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, int printable_view, const StrBuf *PartNum) 
+{
+       wcsession *WCC = WC;
        StrBuf *Buf;
        StrBuf *HdrToken;
        StrBuf *FoundCharset;
@@ -120,7 +122,10 @@ int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, in
                                        state++;
                                }
                        }
-                       else lprintf(1, "don't know how to handle message header[%s]\n", ChrPtr(HdrToken));
+                       else LogError(Target, 
+                                     __FUNCTION__,  
+                                     "don't know how to handle message header[%s]\n", 
+                                     ChrPtr(HdrToken));
                        break;
                case 1:/* Message Mime Header */
                        if (StrLength(Buf) == 0) {
@@ -208,8 +213,8 @@ int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, in
        else 
        {
                if ((StrLength(Msg->OtherNode)>0) && 
-                   (strcasecmp(ChrPtr(Msg->OtherNode), ChrPtr(serv_info.serv_nodename))) &&
-                   (strcasecmp(ChrPtr(Msg->OtherNode), ChrPtr(serv_info.serv_humannode)) ))
+                   (strcasecmp(ChrPtr(Msg->OtherNode), ChrPtr(WCC->serv_info->serv_nodename))) &&
+                   (strcasecmp(ChrPtr(Msg->OtherNode), ChrPtr(WCC->serv_info->serv_humannode)) ))
                {
                        if (Msg->reply_to == NULL)
                                Msg->reply_to = NewStrBuf();
@@ -256,13 +261,14 @@ int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, in
  */
 void embed_message(void) {
        long msgnum = 0L;
+       wcsession *WCC = WC;
        const StrBuf *Tmpl = sbstr("template");
 
-       msgnum = StrTol(WC->UrlFragment2);
+       msgnum = StrTol(WCC->UrlFragment2);
        if (StrLength(Tmpl) > 0) 
-               read_message(WC->WBuf, SKEY(Tmpl), msgnum, 0, NULL);
+               read_message(WCC->WBuf, SKEY(Tmpl), msgnum, 0, NULL);
        else 
-               read_message(WC->WBuf, HKEY("view_message"), msgnum, 0, NULL);
+               read_message(WCC->WBuf, HKEY("view_message"), msgnum, 0, NULL);
 }
 
 
@@ -440,8 +446,8 @@ int load_msg_ptrs(char *servcmd, int with_headers)
                                StrBufExtract_token(Buf2, Buf, 3, '|');
                                if ((StrLength(Buf2) !=0 ) &&
                                    ( ((WCC->room_flags & QR_NETWORK)
-                                      || ((strcasecmp(ChrPtr(Buf2), ChrPtr(serv_info.serv_nodename))
-                                           && (strcasecmp(ChrPtr(Buf2), ChrPtr(serv_info.serv_fqdn))))))))
+                                      || ((strcasecmp(ChrPtr(Buf2), ChrPtr(WCC->serv_info->serv_nodename))
+                                           && (strcasecmp(ChrPtr(Buf2), ChrPtr(WCC->serv_info->serv_fqdn))))))))
                                {
                                        StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
                                        StrBufAppendBuf(Msg->from, Buf2, 0);
@@ -963,12 +969,12 @@ void post_mime_to_server(void) {
        char *txtmail = NULL;
 
        sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
-               ChrPtr(serv_info.serv_fqdn),
+               ChrPtr(WCC->serv_info->serv_fqdn),
                getpid(),
                ++seq
        );
        sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
-               ChrPtr(serv_info.serv_fqdn),
+               ChrPtr(WCC->serv_info->serv_fqdn),
                getpid(),
                ++seq
        );
@@ -1106,11 +1112,11 @@ void post_message(void)
                 */
                pch = strrchr(ChrPtr(att->FileName), '/');
                if (pch != NULL) {
-                       StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName));
+                       StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1);
                }
                pch = strrchr(ChrPtr(att->FileName), '\\');
                if (pch != NULL) {
-                       StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName));
+                       StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName) + 1);
                }
 
                /**
@@ -1526,13 +1532,16 @@ void postpart(StrBuf *partnum, StrBuf *filename, int force_download)
  * partnum             The MIME part to be output
  * force_download      Nonzero to force set the Content-Type: header to "application/octet-stream"
  */
-void mimepart(const char *msgnum, const char *partnum, int force_download)
+void mimepart(int force_download)
 {
+       wcsession *WCC = WC;
+
        char buf[256];
        off_t bytes;
        char content_type[256];
-       
-       serv_printf("OPNA %s|%s", msgnum, partnum);
+       const char *ContentType = &content_type[0];
+
+       serv_printf("OPNA %s|%s", ChrPtr(WCC->UrlFragment2), ChrPtr(WCC->UrlFragment3));
        serv_getln(buf, sizeof buf);
        if (buf[0] == '2') {
                bytes = extract_long(&buf[4], 0);
@@ -1542,12 +1551,21 @@ void mimepart(const char *msgnum, const char *partnum, int force_download)
                else {
                        extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
                }
-               output_headers(0, 0, 0, 0, 0, 0);
 
-               read_server_binary(WC->WBuf, bytes);
+               read_server_binary(WCC->WBuf, bytes);
                serv_puts("CLOS");
                serv_getln(buf, sizeof buf);
-               http_transmit_thing(content_type, 0);
+
+               if (!force_download) {
+                       if (!strcasecmp(ContentType, "application/octet-stream")) {
+                               ContentType = GuessMimeByFilename(SKEY(WCC->UrlFragment4));
+                       }
+                       if (!strcasecmp(ContentType, "application/octet-stream")) {
+                               ContentType = GuessMimeType(SKEY(WCC->WBuf));
+                       }
+               }
+               output_headers(0, 0, 0, 0, 0, 0);
+               http_transmit_thing(ContentType, 0);
        } else {
                hprintf("HTTP/1.1 404 %s\n", &buf[4]);
                output_headers(0, 0, 0, 0, 0, 0);
@@ -1613,15 +1631,11 @@ void MimeLoadData(wc_mime_attachment *Mime)
 
 
 void view_mimepart(void) {
-       mimepart(ChrPtr(WC->UrlFragment2),
-                ChrPtr(WC->UrlFragment3),
-                0);
+       mimepart(0);
 }
 
 void download_mimepart(void) {
-       mimepart(ChrPtr(WC->UrlFragment2),
-                ChrPtr(WC->UrlFragment3),
-                1);
+       mimepart(1);
 }
 
 void view_postpart(void) {
@@ -1647,7 +1661,7 @@ void jsonMessageListHdr(void)
        /* TODO: make a generic function */
   hprintf("HTTP/1.1 200 OK\r\n");
   hprintf("Content-type: application/json; charset=utf-8\r\n");
-  hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(serv_info.serv_software));
+  hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
   hprintf("Connection: close\r\n");
   hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
   begin_burst();
@@ -1662,8 +1676,8 @@ void new_summary_view(void) {
 /** Output message list in JSON-format */
 void jsonMessageList(void) {
   const StrBuf *room = sbstr("room");
-  WC->is_ajax = 1; 
   long oper = (havebstr("query")) ? do_search : readnew;
+  WC->is_ajax = 1; 
   gotoroom(room);
   readloop(oper);
   WC->is_ajax = 0;
@@ -1673,25 +1687,25 @@ void
 InitModule_MSG
 (void)
 {
-       RegisterPreference(HKEY("use_sig"), 
+       RegisterPreference("use_sig",
                           _("Attach signature to email messages?"), 
                           PRF_YESNO, 
                           NULL);
-       RegisterPreference(HKEY("signature"), _("Use this signature:"), PRF_QP_STRING, NULL);
-       RegisterPreference(HKEY("default_header_charset")
+       RegisterPreference("signature", _("Use this signature:"), PRF_QP_STRING, NULL);
+       RegisterPreference("default_header_charset"
                           _("Default character set for email headers:"), 
                           PRF_STRING, 
                           NULL);
-       RegisterPreference(HKEY("defaultfrom"), _("Preferred email address"), PRF_STRING, NULL);
-       RegisterPreference(HKEY("defaultname")
+       RegisterPreference("defaultfrom", _("Preferred email address"), PRF_STRING, NULL);
+       RegisterPreference("defaultname"
                           _("Preferred display name for email messages"), 
                           PRF_STRING, 
                           NULL);
-       RegisterPreference(HKEY("defaulthandle")
+       RegisterPreference("defaulthandle"
                           _("Preferred display name for bulletin board posts"), 
                           PRF_STRING, 
                           NULL);
-       RegisterPreference(HKEY("mailbox"),_("Mailbox view mode"), PRF_STRING, NULL);
+       RegisterPreference("mailbox",_("Mailbox view mode"), PRF_STRING, NULL);
 
        WebcitAddUrlHandler(HKEY("readnew"), h_readnew, NEED_URL);
        WebcitAddUrlHandler(HKEY("readold"), h_readold, NEED_URL);
@@ -1715,11 +1729,5 @@ InitModule_MSG
 
        /* json */
        WebcitAddUrlHandler(HKEY("roommsgs"), jsonMessageList,0);
-
-       WebcitAddUrlHandler(HKEY("mimepart"), view_mimepart, NEED_URL);
-       WebcitAddUrlHandler(HKEY("mimepart_download"), download_mimepart, NEED_URL);
-       WebcitAddUrlHandler(HKEY("postpart"), view_postpart, NEED_URL);
-       WebcitAddUrlHandler(HKEY("postpart_download"), download_postpart, NEED_URL);
-
        return ;
 }