]> code.citadel.org Git - citadel.git/blobdiff - webcit/messages.c
* create function to parse the output of goto into our folder structure
[citadel.git] / webcit / messages.c
index 7e0f8f047f90b3aa7f7590ecf54f72c295f2e5c8..39a1ecf955f6dbd7a123b436b32d846bff74b374 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;
@@ -381,7 +382,7 @@ void handle_one_message(void)
                break;
        case eDELETE:
                CmdBuf = NewStrBuf ();
-               if (WCC->wc_is_trash) { /* Delete from Trash is a real delete */
+               if ((WCC->CurRoom.RAFlags & UA_ISTRASH) != 0) { /* Delete from Trash is a real delete */
                        serv_printf("DELE %ld", msgnum);        
                }
                else {                  /* Otherwise move it to Trash */
@@ -441,7 +442,7 @@ void embed_message(void) {
                break;
        case eDELETE:
                CmdBuf = NewStrBuf ();
-               if (WCC->wc_is_trash) { /* Delete from Trash is a real delete */
+               if ((WCC->CurRoom.RAFlags & UA_ISTRASH) != 0) { /* Delete from Trash is a real delete */
                        serv_printf("DELE %ld", msgnum);        
                }
                else {                  /* Otherwise move it to Trash */
@@ -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);
                }
        }
 
@@ -643,7 +644,7 @@ int load_msg_ptrs(const char *servcmd, SharedMessageStatus *Stat)
                                /* node name */
                                StrBufExtract_NextToken(Buf2, Buf, &Ptr, '|');
                                if ((StrLength(Buf2) !=0 ) &&
-                                   ( ((WCC->room_flags & QR_NETWORK)
+                                   ( ((WCC->CurRoom.QRFlags & QR_NETWORK)
                                       || ((strcasecmp(ChrPtr(Buf2), ChrPtr(WCC->serv_info->serv_nodename))
                                            && (strcasecmp(ChrPtr(Buf2), ChrPtr(WCC->serv_info->serv_fqdn))))))))
                                {
@@ -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,25 +769,36 @@ void readloop(long oper)
        SharedMessageStatus Stat;
        void *ViewSpecific;
 
-       if (havebstr("is_summary") && (1 == (ibstr("is_summary"))))
-               WCC->wc_view = VIEW_MAILBOX;
+       if (havebstr("is_summary") && (1 == (ibstr("is_summary")))) {
+               WCC->CurRoom.view = VIEW_MAILBOX;
+       }
+
+       if (havebstr("is_ajax") && (1 == (ibstr("is_ajax")))) {
+               WCC->is_ajax = 1;
+       }
+
+       if ((oper == do_search) && (WCC->CurRoom.view == VIEW_WIKI)) {
+               display_wiki_pagelist();
+               return;
+       }
 
        memset(&Stat, 0, sizeof(SharedMessageStatus));
        Stat.maxload = 10000;
        Stat.lowest_found = (-1);
        Stat.highest_found = (-1);
-       GetHash(ReadLoopHandler, IKEY(WCC->wc_view), &vViewMsg);
+       GetHash(ReadLoopHandler, IKEY(WCC->CurRoom.view), &vViewMsg);
        if (vViewMsg == NULL) {
-               WCC->wc_view = VIEW_BBS;
-               GetHash(ReadLoopHandler, IKEY(WCC->wc_view), &vViewMsg);
+               WCC->CurRoom.view = VIEW_BBS;
+               GetHash(ReadLoopHandler, IKEY(WCC->CurRoom.view), &vViewMsg);
+       }
+       if (vViewMsg == NULL) {
+               return;                 // TODO: print message
        }
-       if (vViewMsg == NULL)
-               return;///TODO: print message
 
        ViewMsg = (RoomRenderer*) vViewMsg;
        if (!WCC->is_ajax) {
                output_headers(1, 1, 1, 0, 0, 0);
-       } else if (WCC->wc_view == VIEW_MAILBOX) {
+       } else if (WCC->CurRoom.view == VIEW_MAILBOX) {
                jsonMessageListHdr();
        }
 
@@ -818,15 +830,16 @@ 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);
                if (SortIt != NULL)
                        SortByPayload(WCC->summ, SortIt);
        }
-       if (Stat.startmsg < 0) 
-               Stat.startmsg = (Stat.reverse) ? Stat.nummsgs - 1 : 0;
+       if (Stat.startmsg < 0) {
+               Stat.startmsg =  0;
+       }
 
        if (Stat.load_seen) load_seen_flags();
        
@@ -843,7 +856,7 @@ void readloop(long oper)
        /* Put some helpful data in vars for mailsummary_json */
        svputlong("READLOOP:TOTALMSGS", Stat.nummsgs);
        svputlong("READLOOP:STARTMSG", Stat.startmsg);
-       svputlong("WCVIEW", WCC->wc_view);
+       svputlong("WCVIEW", WCC->CurRoom.view);
 
        /*
         * iterate over each message. if we need to load an attachment, do it here. 
@@ -919,7 +932,7 @@ void post_mime_to_server(void) {
        }
 
        /* Only do multipart/alternative for mailboxes.  BBS and Wiki rooms don't need it. */
-       if (WC->wc_view == VIEW_MAILBOX) {
+       if (WC->CurRoom.view == VIEW_MAILBOX) {
                include_text_alt = 1;
        }
 
@@ -1135,7 +1148,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, 
@@ -1177,13 +1190,13 @@ void post_message(void)
                                        serv_printf("Cc: %s", ChrPtr(Cc));
                                        serv_printf("Bcc: %s", ChrPtr(Bcc));
                                } else {
-                                       serv_printf("X-Citadel-Room: %s", ChrPtr(WC->wc_roomname));
+                                       serv_printf("X-Citadel-Room: %s", ChrPtr(WC->CurRoom.name));
                                }
                        }
                        post_mime_to_server();
                        if (save_to_drafts) {
                                StrBufAppendBufPlain(WCC->ImportantMsg, _("Message has been saved to Drafts.\n"), -1, 0);
-                               gotoroom(WCC->wc_roomname);
+                               gotoroom(WCC->CurRoom.name);
                                display_enter();
                                FreeStrBuf(&Buf);
                                return;
@@ -1202,7 +1215,7 @@ void post_message(void)
 
                        lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, ChrPtr(Buf));
                        StrBufAppendBuf(WCC->ImportantMsg, Buf, 0);
-                       if (save_to_drafts) gotoroom(WCC->wc_roomname);
+                       if (save_to_drafts) gotoroom(WCC->CurRoom.name);
                        display_enter();
                        FreeStrBuf(&Buf);
                        return;
@@ -1222,8 +1235,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);
        }
        /*
@@ -1285,8 +1298,8 @@ void display_enter(void)
         * Are we perhaps in an address book view?  If so, then an "enter
         * message" command really means "add new entry."
         */
-       if (WCC->wc_default_view == VIEW_ADDRESSBOOK) {
-               do_edit_vcard(-1, "", NULL, NULL, "",  ChrPtr(WCC->wc_roomname));
+       if (WCC->CurRoom.defview == VIEW_ADDRESSBOOK) {
+               do_edit_vcard(-1, "", NULL, NULL, "",  ChrPtr(WCC->CurRoom.name));
                return;
        }
 
@@ -1294,7 +1307,7 @@ void display_enter(void)
         * Are we perhaps in a calendar room?  If so, then an "enter
         * message" command really means "add new calendar item."
         */
-       if (WCC->wc_default_view == VIEW_CALENDAR) {
+       if (WCC->CurRoom.defview == VIEW_CALENDAR) {
                display_edit_event();
                return;
        }
@@ -1303,7 +1316,7 @@ void display_enter(void)
         * Are we perhaps in a tasks view?  If so, then an "enter
         * message" command really means "add new task."
         */
-       if (WCC->wc_default_view == VIEW_TASKS) {
+       if (WCC->CurRoom.defview == VIEW_TASKS) {
                display_edit_task();
                return;
        }
@@ -1324,7 +1337,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) + 
@@ -1354,7 +1367,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;
                }
        }
@@ -1379,7 +1392,7 @@ void delete_msg(void)
 
        msgid = lbstr("msgid");
 
-       if (WC->wc_is_trash) {  /* Delete from Trash is a real delete */
+       if ((WC->CurRoom.RAFlags & UA_ISTRASH) != 0) {  /* Delete from Trash is a real delete */
                serv_printf("DELE %ld", msgid); 
        }
        else {                  /* Otherwise move it to Trash */
@@ -1428,43 +1441,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);
 }
 
@@ -1499,7 +1512,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();
        }
@@ -1559,7 +1572,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();
        }
@@ -1661,6 +1674,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) 
 {
@@ -1736,6 +1750,7 @@ InitModule_MSG
        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);