]> code.citadel.org Git - citadel.git/blobdiff - webcit/messages.c
* Enhance the older/newer logic. It's still not quite right.
[citadel.git] / webcit / messages.c
index 8ca8a3126eb795451df86fec3f1e929c2e075dbc..b793f308c291554efe48c8ab65c66d9f485c751e 100644 (file)
@@ -63,7 +63,7 @@ int load_message(message_summary *Msg,
 
        /* begin everythingamundo table */
        HdrToken = NewStrBuf();
-       while ((StrBuf_ServGetln(Buf)>=0) && !Done) {
+       while (!Done && StrBuf_ServGetln(Buf)>=0) {
                if ( (StrLength(Buf)==3) && 
                    !strcmp(ChrPtr(Buf), "000")) 
                {
@@ -230,11 +230,12 @@ int read_message(StrBuf *Target, const char *tmpl, long tmpllen, long msgnum, co
                FreeStrBuf(&Error);
        }
 
-       /* strip the bare contenttype, so we ommit charset etc. */
+       /* Extract just the content-type (omit attributes such as "charset") */
        StrBufExtract_token(Buf, Msg->MsgBody->ContentType, 0, ';');
        StrBufTrim(Buf);
        StrBufLowerCase(Buf);
-       /* look up the renderer, that will convert this mimeitem into the htmlized form */
+
+       /* Locate a renderer capable of converting this MIME part into HTML */
        if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) &&
            (vHdr != NULL)) {
                RenderMimeFuncStruct *Render;
@@ -515,7 +516,7 @@ void display_headers(void) {
        serv_getln(buf, sizeof buf);
        if (buf[0] == '1') {
                while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
-                       wprintf("%s\n", buf);
+                       wc_printf("%s\n", buf);
                }
        }
 
@@ -750,7 +751,7 @@ typedef struct _RoomRenderer{
 /*
  * command loop for reading messages
  *
- * Set oper to "readnew" or "readold" or "readfwd" or "headers" or "readgt"
+ * Set oper to "readnew" or "readold" or "readfwd" or "headers" or "readgt" or "readlt" or "do_search"
  */
 void readloop(long oper)
 {
@@ -768,8 +769,18 @@ void readloop(long oper)
        SharedMessageStatus Stat;
        void *ViewSpecific;
 
-       if (havebstr("is_summary") && (1 == (ibstr("is_summary"))))
+       if (havebstr("is_summary") && (1 == (ibstr("is_summary")))) {
                WCC->wc_view = VIEW_MAILBOX;
+       }
+
+       if (havebstr("is_ajax") && (1 == (ibstr("is_ajax")))) {
+               WCC->is_ajax = 1;
+       }
+
+       if ((oper == do_search) && (WCC->wc_view == VIEW_WIKI)) {
+               display_wiki_pagelist();
+               return;
+       }
 
        memset(&Stat, 0, sizeof(SharedMessageStatus));
        Stat.maxload = 10000;
@@ -780,8 +791,9 @@ void readloop(long oper)
                WCC->wc_view = VIEW_BBS;
                GetHash(ReadLoopHandler, IKEY(WCC->wc_view), &vViewMsg);
        }
-       if (vViewMsg == NULL)
-               return;///TODO: print message
+       if (vViewMsg == NULL) {
+               return;                 // TODO: print message
+       }
 
        ViewMsg = (RoomRenderer*) vViewMsg;
        if (!WCC->is_ajax) {
@@ -818,7 +830,7 @@ void readloop(long oper)
        if (Stat.sortit) {
                CompareFunc SortIt;
                memset(&SubTP, 0, sizeof(WCTemplputParams));
-               SubTP.Filter.ContextType = CTX_NONE;
+               SubTP.Filter.ContextType = CTX_MAILSUM;
                SubTP.Context = NULL;
                SortIt =  RetrieveSort(&SubTP, NULL, 0,
                                       HKEY("date"), Stat.defaultsortorder);
@@ -896,6 +908,7 @@ void post_mime_to_server(void) {
        size_t encoded_length;
        size_t encoded_strlen;
        char *txtmail = NULL;
+       int include_text_alt = 0;       /* Set to nonzero to include multipart/alternative text/plain */
 
        sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
                ChrPtr(WCC->serv_info->serv_fqdn),
@@ -917,6 +930,11 @@ void post_mime_to_server(void) {
                is_multipart = 1;
        }
 
+       /* Only do multipart/alternative for mailboxes.  BBS and Wiki rooms don't need it. */
+       if (WC->wc_view == VIEW_MAILBOX) {
+               include_text_alt = 1;
+       }
+
        if (is_multipart) {
                /* Remember, serv_printf() appends an extra newline */
                serv_printf("Content-type: multipart/mixed; boundary=\"%s\"\n", top_boundary);
@@ -925,19 +943,21 @@ void post_mime_to_server(void) {
        }
 
        /* Remember, serv_printf() appends an extra newline */
-       serv_printf("Content-type: multipart/alternative; "
-               "boundary=\"%s\"\n", alt_boundary);
-       serv_printf("This is a multipart message in MIME format.\n");
-       serv_printf("--%s", alt_boundary);
+       if (include_text_alt) {
+               serv_printf("Content-type: multipart/alternative; "
+                       "boundary=\"%s\"\n", alt_boundary);
+               serv_printf("This is a multipart message in MIME format.\n");
+               serv_printf("--%s", alt_boundary);
 
-       serv_puts("Content-type: text/plain; charset=utf-8");
-       serv_puts("Content-Transfer-Encoding: quoted-printable");
-       serv_puts("");
-       txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
-        text_to_server_qp(txtmail);     /* Transmit message in quoted-printable encoding */
-        free(txtmail);
+               serv_puts("Content-type: text/plain; charset=utf-8");
+               serv_puts("Content-Transfer-Encoding: quoted-printable");
+               serv_puts("");
+               txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
+               text_to_server_qp(txtmail);     /* Transmit message in quoted-printable encoding */
+               free(txtmail);
 
-       serv_printf("--%s", alt_boundary);
+               serv_printf("--%s", alt_boundary);
+       }
 
        serv_puts("Content-type: text/html; charset=utf-8");
        serv_puts("Content-Transfer-Encoding: quoted-printable");
@@ -946,7 +966,9 @@ void post_mime_to_server(void) {
        text_to_server_qp(bstr("msgtext"));     /* Transmit message in quoted-printable encoding */
        serv_puts("</body></html>\r\n");
 
-       serv_printf("--%s--", alt_boundary);
+       if (include_text_alt) {
+               serv_printf("--%s--", alt_boundary);
+       }
        
        if (is_multipart) {
                long len;
@@ -1125,7 +1147,7 @@ void post_message(void)
                Recp = sbstr("recp");
                Cc = sbstr("cc");
                Bcc = sbstr("bcc");
-               Wikipage = sbstr("wikipage");
+               Wikipage = sbstr("page");
                my_email_addr = sbstr("my_email_addr");
                
                CmdBuf = NewStrBufPlain(NULL, 
@@ -1212,8 +1234,8 @@ void post_message(void)
        /*
         *  If we were editing a page in a wiki room, go to that page now.
         */
-       else if (havebstr("wikipage")) {
-               snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
+       else if (havebstr("page")) {
+               snprintf(buf, sizeof buf, "wiki?page=%s", bstr("page"));
                http_redirect(buf);
        }
        /*
@@ -1314,7 +1336,7 @@ void display_enter(void)
                Recp = sbstr("recp");
                Cc = sbstr("cc");
                Bcc = sbstr("bcc");
-               Wikipage = sbstr("wikipage");
+               Wikipage = sbstr("page");
                
                CmdBuf = NewStrBufPlain(NULL, 
                                        sizeof (CMD) + 
@@ -1344,7 +1366,7 @@ void display_enter(void)
                        }
                }
                else if (buf[0] != '2') {       /* Any other error means that we cannot continue */
-                       wprintf("<em>%s</em><br />\n", &buf[4]);        /* TODO -> important message */
+                       wc_printf("<em>%s</em><br />\n", &buf[4]);      /* TODO -> important message */
                        return;
                }
        }
@@ -1418,43 +1440,43 @@ void confirm_move_msg(void)
 
 
        output_headers(1, 1, 2, 0, 0, 0);
-       wprintf("<div id=\"banner\">\n");
-       wprintf("<h1>");
-       wprintf(_("Confirm move of message"));
-       wprintf("</h1>");
-       wprintf("</div>\n");
+       wc_printf("<div id=\"banner\">\n");
+       wc_printf("<h1>");
+       wc_printf(_("Confirm move of message"));
+       wc_printf("</h1>");
+       wc_printf("</div>\n");
 
-       wprintf("<div id=\"content\" class=\"service\">\n");
+       wc_printf("<div id=\"content\" class=\"service\">\n");
 
-       wprintf("<CENTER>");
+       wc_printf("<CENTER>");
 
-       wprintf(_("Move this message to:"));
-       wprintf("<br />\n");
+       wc_printf(_("Move this message to:"));
+       wc_printf("<br />\n");
 
-       wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
-       wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
-       wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
+       wc_printf("<form METHOD=\"POST\" action=\"move_msg\">\n");
+       wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
+       wc_printf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
 
-       wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
+       wc_printf("<SELECT NAME=\"target_room\" SIZE=5>\n");
        serv_puts("LKRA");
        serv_getln(buf, sizeof buf);
        if (buf[0] == '1') {
                while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
                        extract_token(targ, buf, 0, '|', sizeof targ);
-                       wprintf("<OPTION>");
+                       wc_printf("<OPTION>");
                        escputs(targ);
-                       wprintf("\n");
+                       wc_printf("\n");
                }
        }
-       wprintf("</SELECT>\n");
-       wprintf("<br />\n");
+       wc_printf("</SELECT>\n");
+       wc_printf("<br />\n");
 
-       wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
-       wprintf("&nbsp;");
-       wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
-       wprintf("</form></CENTER>\n");
+       wc_printf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
+       wc_printf("&nbsp;");
+       wc_printf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
+       wc_printf("</form></CENTER>\n");
 
-       wprintf("</CENTER>\n");
+       wc_printf("</CENTER>\n");
        wDumpContent(1);
 }
 
@@ -1489,7 +1511,7 @@ void postpart(StrBuf *partnum, StrBuf *filename, int force_download)
                output_headers(0, 0, 0, 0, 0, 0);
                hprintf("Content-Type: text/plain\r\n");
                begin_burst();
-               wprintf(_("An error occurred while retrieving this part: %s/%s\n"), 
+               wc_printf(_("An error occurred while retrieving this part: %s/%s\n"), 
                        ChrPtr(partnum), ChrPtr(filename));
                end_burst();
        }
@@ -1549,7 +1571,7 @@ void mimepart(int force_download)
                output_headers(0, 0, 0, 0, 0, 0);
                hprintf("Content-Type: text/plain\r\n");
                begin_burst();
-               wprintf(_("An error occurred while retrieving this part: %s\n"), 
+               wc_printf(_("An error occurred while retrieving this part: %s\n"), 
                        ChrPtr(Buf));
                end_burst();
        }
@@ -1651,6 +1673,7 @@ void h_readfwd(void) { readloop(readfwd);}
 void h_headers(void) { readloop(headers);}
 void h_do_search(void) { readloop(do_search);}
 void h_readgt(void) { readloop(readgt);}
+void h_readlt(void) { readloop(readlt);}
 
 void jsonMessageListHdr(void) 
 {
@@ -1721,30 +1744,31 @@ InitModule_MSG
                           NULL);
        RegisterPreference("mailbox",_("Mailbox view mode"), PRF_STRING, NULL);
 
-       WebcitAddUrlHandler(HKEY("readnew"), h_readnew, NEED_URL);
-       WebcitAddUrlHandler(HKEY("readold"), h_readold, NEED_URL);
-       WebcitAddUrlHandler(HKEY("readfwd"), h_readfwd, NEED_URL);
-       WebcitAddUrlHandler(HKEY("headers"), h_headers, NEED_URL);
-       WebcitAddUrlHandler(HKEY("readgt"), h_readgt, NEED_URL);
-       WebcitAddUrlHandler(HKEY("do_search"), h_do_search, 0);
-       WebcitAddUrlHandler(HKEY("display_enter"), display_enter, 0);
-       WebcitAddUrlHandler(HKEY("post"), post_message, 0);
-       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);
-       WebcitAddUrlHandler(HKEY("message"), handle_one_message, NEED_URL|XHTTP_COMMANDS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
-       WebcitAddUrlHandler(HKEY("printmsg"), print_message, NEED_URL);
-       WebcitAddUrlHandler(HKEY("mobilemsg"), mobile_message_view, NEED_URL);
-       WebcitAddUrlHandler(HKEY("msgheaders"), display_headers, NEED_URL);
-
-       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);
+       WebcitAddUrlHandler(HKEY("readnew"), "", 0, h_readnew, NEED_URL);
+       WebcitAddUrlHandler(HKEY("readold"), "", 0, h_readold, NEED_URL);
+       WebcitAddUrlHandler(HKEY("readfwd"), "", 0, h_readfwd, NEED_URL);
+       WebcitAddUrlHandler(HKEY("headers"), "", 0, h_headers, NEED_URL);
+       WebcitAddUrlHandler(HKEY("readgt"), "", 0, h_readgt, NEED_URL);
+       WebcitAddUrlHandler(HKEY("readlt"), "", 0, h_readlt, NEED_URL);
+       WebcitAddUrlHandler(HKEY("do_search"), "", 0, h_do_search, 0);
+       WebcitAddUrlHandler(HKEY("display_enter"), "", 0, display_enter, 0);
+       WebcitAddUrlHandler(HKEY("post"), "", 0, post_message, 0);
+       WebcitAddUrlHandler(HKEY("move_msg"), "", 0, move_msg, 0);
+       WebcitAddUrlHandler(HKEY("delete_msg"), "", 0, delete_msg, 0);
+       WebcitAddUrlHandler(HKEY("confirm_move_msg"), "", 0, confirm_move_msg, 0);
+       WebcitAddUrlHandler(HKEY("msg"), "", 0, embed_message, NEED_URL);
+       WebcitAddUrlHandler(HKEY("message"), "", 0, handle_one_message, NEED_URL|XHTTP_COMMANDS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
+       WebcitAddUrlHandler(HKEY("printmsg"), "", 0, print_message, NEED_URL);
+       WebcitAddUrlHandler(HKEY("mobilemsg"), "", 0, mobile_message_view, NEED_URL);
+       WebcitAddUrlHandler(HKEY("msgheaders"), "", 0, display_headers, NEED_URL);
+
+       WebcitAddUrlHandler(HKEY("mimepart"), "", 0, view_mimepart, NEED_URL);
+       WebcitAddUrlHandler(HKEY("mimepart_download"), "", 0, download_mimepart, NEED_URL);
+       WebcitAddUrlHandler(HKEY("postpart"), "", 0, view_postpart, NEED_URL);
+       WebcitAddUrlHandler(HKEY("postpart_download"), "", 0, download_postpart, NEED_URL);
 
        /* json */
-       WebcitAddUrlHandler(HKEY("roommsgs"), jsonMessageList,0);
+       WebcitAddUrlHandler(HKEY("roommsgs"), "", 0, jsonMessageList,0);
        return ;
 }