]> code.citadel.org Git - citadel.git/blobdiff - webcit/messages.c
* remove unneeded vcard function...
[citadel.git] / webcit / messages.c
index a3e17dbb56936d2c5d60903e989652cab8fdbb35..9579688559610499737438d17e9ec94d337f5460 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")) 
                {
@@ -382,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 */
@@ -442,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 */
@@ -572,9 +572,10 @@ message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSu
  *
  * servcmd:            the citadel command to send to the citserver
  */
-int load_msg_ptrs(const char *servcmd, SharedMessageStatus *Stat)
+int load_msg_ptrs(const char *servcmd, 
+                 SharedMessageStatus *Stat, 
+                 load_msg_ptrs_detailheaders LH)
 {
-       StrBuf* FoundCharset = NULL;
         wcsession *WCC = WC;
        message_summary *Msg;
        StrBuf *Buf, *Buf2;
@@ -633,47 +634,11 @@ int load_msg_ptrs(const char *servcmd, SharedMessageStatus *Stat)
                                if (StrLength(Buf) < 32) 
                                        skipit = 1;
                        }
-                       if (!skipit) {
-                               Msg->from = NewStrBufPlain(NULL, StrLength(Buf));
-                               StrBufExtract_NextToken(Buf2, Buf, &Ptr, '|');
-                               if (StrLength(Buf2) != 0) {
-                                       /* Handle senders with RFC2047 encoding */
-                                       StrBuf_RFC822_to_Utf8(Msg->from, Buf2, WCC->DefaultCharset, FoundCharset);
-                               }
-                       
-                               /* node name */
-                               StrBufExtract_NextToken(Buf2, Buf, &Ptr, '|');
-                               if ((StrLength(Buf2) !=0 ) &&
-                                   ( ((WCC->room_flags & QR_NETWORK)
-                                      || ((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);
-                               }
-
-                               /* Internet address (not used)
-                                *      StrBufExtract_token(Msg->inetaddr, Buf, 4, '|');
-                                */
-                               StrBufSkip_NTokenS(Buf, &Ptr, '|', 1);
-                               Msg->subj = NewStrBufPlain(NULL, StrLength(Buf));
-                               StrBufExtract_NextToken(Buf2,  Buf, &Ptr, '|');
-                               if (StrLength(Buf2) == 0)
-                                       StrBufAppendBufPlain(Msg->subj, _("(no subject)"), -1,0);
-                               else {
-                                       StrBuf_RFC822_to_Utf8(Msg->subj, Buf2, WCC->DefaultCharset, FoundCharset);
-                                       if ((StrLength(Msg->subj) > 75) && 
-                                           (StrBuf_Utf8StrLen(Msg->subj) > 75)) {
-                                               StrBuf_Utf8StrCut(Msg->subj, 72);
-                                               StrBufAppendBufPlain(Msg->subj, HKEY("..."), 0);
-                                       }
-                               }
-
-                               if ((StrLength(Msg->from) > 25) && 
-                                   (StrBuf_Utf8StrLen(Msg->from) > 25)) {
-                                       StrBuf_Utf8StrCut(Msg->from, 23);
-                                       StrBufAppendBufPlain(Msg->from, HKEY("..."), 0);
-                               }
+                       if ((!skipit) && (LH != NULL)) {
+                               if (!LH(Buf, &Ptr, Msg, Buf2)){
+                                       free(Msg);
+                                       continue;
+                               }                                       
                        }
                        n = Msg->msgnum;
                        Put(WCC->summ, (const char *)&n, sizeof(n), Msg, DestroyMessageSummary);
@@ -745,15 +710,16 @@ typedef struct _RoomRenderer{
        LoadMsgFromServer_func LoadMsgFromServer;
        RenderView_or_Tail_func RenderView_or_Tail;
        View_Cleanup_func ViewCleanup;
+       load_msg_ptrs_detailheaders LHParse;
 } 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)
+void readloop(long oper, eCustomRoomRenderer ForceRenderer)
 {
        RoomRenderer *ViewMsg;
        void *vViewMsg;
@@ -769,25 +735,39 @@ 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);
+       if (ForceRenderer == eUseDefault)
+               GetHash(ReadLoopHandler, IKEY(WCC->CurRoom.view), &vViewMsg);
+       else 
+               GetHash(ReadLoopHandler, IKEY(ForceRenderer), &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();
        }
 
@@ -814,7 +794,7 @@ void readloop(long oper)
                break;
        }
        if (!IsEmptyStr(cmd))
-               Stat.nummsgs = load_msg_ptrs(cmd, &Stat);
+               Stat.nummsgs = load_msg_ptrs(cmd, &Stat, ViewMsg->LHParse);
 
        if (Stat.sortit) {
                CompareFunc SortIt;
@@ -826,8 +806,9 @@ void readloop(long oper)
                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();
        
@@ -844,7 +825,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. 
@@ -920,7 +901,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;
        }
 
@@ -1136,7 +1117,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, 
@@ -1178,13 +1159,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;
@@ -1203,7 +1184,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;
@@ -1223,15 +1204,15 @@ 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);
        }
        /*
         *  Otherwise, just go to the "read messages" loop.
         */
        else {
-               readloop(readnew);
+               readloop(readnew, eUseDefault);
        }
 }
 
@@ -1273,7 +1254,7 @@ void display_enter(void)
        }
        else if (buf[0] != '2') {               /* Any other error means that we cannot continue */
                sprintf(WCC->ImportantMessage, "%s", &buf[4]);
-               readloop(readnew);
+               readloop(readnew, eUseDefault);
                return;
        }
 
@@ -1286,8 +1267,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;
        }
 
@@ -1295,7 +1276,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;
        }
@@ -1304,7 +1285,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;
        }
@@ -1325,7 +1306,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) + 
@@ -1380,7 +1361,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 */
@@ -1389,7 +1370,7 @@ void delete_msg(void)
 
        serv_getln(buf, sizeof buf);
        sprintf(WC->ImportantMessage, "%s", &buf[4]);
-       readloop(readnew);
+       readloop(readnew, eUseDefault);
 }
 
 
@@ -1412,7 +1393,7 @@ void move_msg(void)
                sprintf(WC->ImportantMessage, (_("The message was not moved.")));
        }
 
-       readloop(readnew);
+       readloop(readnew, eUseDefault);
 }
 
 
@@ -1600,14 +1581,20 @@ StrBuf *load_mimepart(long msgnum, char *partnum)
 void MimeLoadData(wc_mime_attachment *Mime)
 {
        StrBuf *Buf;
+       const char *Ptr;
        off_t bytes;
        /* TODO: is there a chance the content type is different from the one we know? */
+
        serv_printf("DLAT %ld|%s", Mime->msgnum, ChrPtr(Mime->PartNum));
        Buf = NewStrBuf();
        StrBuf_ServGetln(Buf);
        if (GetServerStatus(Buf, NULL) == 6) {
-               bytes = extract_long(&(ChrPtr(Buf)[4]), 0);
-                                    
+               Ptr = &(ChrPtr(Buf)[4]);
+               bytes = StrBufExtractNext_long(Buf, &Ptr, '|');
+               StrBufSkip_NTokenS(Buf, &Ptr, '|', 3);  /* filename, cbtype, mimetype */
+               if (Mime->Charset == NULL) Mime->Charset = NewStrBuf();
+               StrBufExtract_NextToken(Mime->Charset, Buf, &Ptr, '|');
+               
                if (Mime->Data == NULL)
                        Mime->Data = NewStrBufPlain(NULL, bytes);
                StrBuf_ServGetBLOBBuffered(Mime->Data, bytes);
@@ -1656,12 +1643,13 @@ void download_postpart(void) {
        FreeStrBuf(&partnum);
 }
 
-void h_readnew(void) { readloop(readnew);}
-void h_readold(void) { readloop(readold);}
-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_readnew(void) { readloop(readnew, eUseDefault);}
+void h_readold(void) { readloop(readold, eUseDefault);}
+void h_readfwd(void) { readloop(readfwd, eUseDefault);}
+void h_headers(void) { readloop(headers, eUseDefault);}
+void h_do_search(void) { readloop(do_search, eUseDefault);}
+void h_readgt(void) { readloop(readgt, eUseDefault);}
+void h_readlt(void) { readloop(readlt, eUseDefault);}
 
 void jsonMessageListHdr(void) 
 {
@@ -1681,7 +1669,7 @@ void jsonMessageList(void) {
        long oper = (havebstr("query")) ? do_search : readnew;
        WC->is_ajax = 1; 
        gotoroom(room);
-       readloop(oper);
+       readloop(oper, eUseDefault);
        WC->is_ajax = 0;
 }
 
@@ -1689,6 +1677,7 @@ void RegisterReadLoopHandlerset(
        int RoomType,
        GetParamsGetServerCall_func GetParamsGetServerCall,
        PrintViewHeader_func PrintViewHeader,
+       load_msg_ptrs_detailheaders LH,
        LoadMsgFromServer_func LoadMsgFromServer,
        RenderView_or_Tail_func RenderView_or_Tail,
        View_Cleanup_func ViewCleanup
@@ -1704,6 +1693,7 @@ void RegisterReadLoopHandlerset(
        Handler->LoadMsgFromServer = LoadMsgFromServer;
        Handler->RenderView_or_Tail = RenderView_or_Tail;
        Handler->ViewCleanup = ViewCleanup;
+       Handler->LHParse = LH;
 
        Put(ReadLoopHandler, IKEY(RoomType), Handler, NULL);
 }
@@ -1737,6 +1727,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);