* don't overrun our room list.
[citadel.git] / webcit / messages.c
index 3cd060b6c6e5fcde2a988ee0984758de57f42f0e..79d39fdf68c3754cb8abb6e30a036326569e5d6e 100644 (file)
@@ -8,7 +8,6 @@
  */
 /*@{*/
 #include "webcit.h"
-#include "vcard.h"
 #include "webserver.h"
 #include "groupdav.h"
 
@@ -210,7 +209,7 @@ void utf8ify_rfc822_string(char *buf) {
  * \param      maxlen          Maximum size of target buffer.
  * \param      source          Source string to be encoded.
  */
-void rfc2047encode(char *target, int maxlen, char *source)
+void webcit_rfc2047encode(char *target, int maxlen, char *source)
 {
        int need_to_encode = 0;
        int i, len;
@@ -492,16 +491,20 @@ void display_parsed_vcard(struct vCard *v, int full) {
                        }
        
                        else if (!strcasecmp(firsttoken, "email")) {
+                               size_t len;
                                if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
-                               long len;
                                strcat(mailto,
                                        "<a href=\"display_enter"
                                        "?force_room=_MAIL_?recp=");
 
-                               urlesc(&mailto[strlen(mailto)], fullname);
-                               urlesc(&mailto[strlen(mailto)], " <");
-                               urlesc(&mailto[strlen(mailto)], thisvalue);
-                               urlesc(&mailto[strlen(mailto)], ">");
+                               len = strlen(mailto);
+                               urlesc(&mailto[len], SIZ - len,  fullname);
+                               len = strlen(mailto);
+                               urlesc(&mailto[len], SIZ - len, " <");
+                               len = strlen(mailto);
+                               urlesc(&mailto[len], SIZ - len, thisvalue);
+                               len = strlen(mailto);
+                               urlesc(&mailto[len], SIZ - len, ">");
 
                                strcat(mailto, "\">");
                                len = strlen(mailto);
@@ -813,7 +816,7 @@ void read_message(long msgnum, int printable_view, char *section) {
                        wprintf(" ");
                }
                if (!strncasecmp(buf, "time=", 5)) {
-                       fmt_date(now, atol(&buf[5]), 0);
+                       webcit_fmt_date(now, atol(&buf[5]), 0);
                        wprintf("<span>");
                        wprintf("%s ", now);
                        wprintf("</span>");
@@ -858,7 +861,7 @@ void read_message(long msgnum, int printable_view, char *section) {
                                attach_links = realloc(attach_links,
                                        (num_attach_links*sizeof(struct attach_link)));
                                safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
-                               urlesc(escaped_mime_filename, mime_filename);
+                               urlesc(escaped_mime_filename, 265, mime_filename);
                                snprintf(attach_links[num_attach_links-1].html, 1024,
                                        "<img src=\"static/diskette_24x.gif\" "
                                        "border=0 align=middle>\n"
@@ -884,7 +887,8 @@ void read_message(long msgnum, int printable_view, char *section) {
                                strcpy(vcard_partnum, mime_partnum);
                        }
 
-                       if (!strcasecmp(mime_content_type, "text/calendar")) {
+                       if (  (!strcasecmp(mime_content_type, "text/calendar"))
+                          || (!strcasecmp(mime_content_type, "application/ics")) ) {
                                strcpy(cal_partnum, mime_partnum);
                        }
 
@@ -1418,7 +1422,7 @@ void pullquote_message(long msgnum, int forward_attachments, int include_headers
                                wprintf("%s ", &buf[5]);
                        }
                        if (!strncasecmp(buf, "time=", 5)) {
-                               fmt_date(now, atol(&buf[5]), 0);
+                               webcit_fmt_date(now, atol(&buf[5]), 0);
                                wprintf("%s ", now);
                        }
                }
@@ -1651,7 +1655,12 @@ void display_summarized(int num) {
        );
 
        wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
-       escputs(WC->summ[num].subj);
+
+#ifdef HAVE_ICONV
+       utf8ify_rfc822_string(WC->summ[num].subj);
+       utf8ify_rfc822_string(WC->summ[num].from);
+#endif 
+       escputs(WC->summ[num].subj);//////////////////////////////////TODO: QP DECODE
        wprintf("</td>");
 
        wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
@@ -1659,7 +1668,7 @@ void display_summarized(int num) {
        wprintf("</td>");
 
        wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
-       fmt_date(datebuf, WC->summ[num].date, 1);       /* brief */
+       webcit_fmt_date(datebuf, WC->summ[num].date, 1);        /* brief */
        escputs(datebuf);
        wprintf("</td>");
 
@@ -2474,7 +2483,7 @@ void readloop(char *oper)
         */
        if (is_bbview) {
                /** begin bbview scroller */
-               wprintf("<form name=\"msgomatictop\" class=\"selector_top\" >");
+               wprintf("<form name=\"msgomatictop\" class=\"selector_top\" > \n <p>");
                wprintf(_("Reading #"), lowest_displayed, highest_displayed);
 
                wprintf("<select name=\"whichones\" size=\"1\" "
@@ -2548,7 +2557,7 @@ void readloop(char *oper)
                wprintf(_("newest to oldest"));
                wprintf("\n");
        
-               wprintf("</select></form>\n");
+               wprintf("</p></form>\n");
                /** end bbview scroller */
        }
 
@@ -2559,7 +2568,6 @@ void readloop(char *oper)
 
 
 
-
        for (a = 0; a < nummsgs; ++a) {
                if ((WCC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
 
@@ -2646,7 +2654,7 @@ void readloop(char *oper)
         */
        if (is_bbview) {
                /** begin bbview scroller */
-               wprintf("<form name=\"msgomatic\" class=\"selector_bottom\" >");
+               wprintf("<form name=\"msgomatic\" class=\"selector_bottom\" > \n <p>");
                wprintf(_("Reading #"), lowest_displayed, highest_displayed);
 
                wprintf("<select name=\"whichones\" size=\"1\" "
@@ -2719,7 +2727,7 @@ void readloop(char *oper)
                wprintf(_("newest to oldest"));
                wprintf("\n");
 
-               wprintf("</form>\n");
+               wprintf("</p></form>\n");
                /** end bbview scroller */
        }
        
@@ -2835,7 +2843,7 @@ void post_mime_to_server(void) {
                        encoded_length = ((att->length * 150) / 100);
                        encoded = malloc(encoded_length);
                        if (encoded == NULL) break;
-                       encoded_strlen = CtdlEncodeBase64(&encoded, att->data, att->length, &encoded_length, 1);
+                       encoded_strlen = CtdlEncodeBase64(encoded, att->data, att->length, 1);
 
                        serv_printf("--%s", boundary);
                        serv_printf("Content-type: %s", att->content_type);
@@ -2875,6 +2883,10 @@ void post_message(void)
        int is_anonymous = 0;
        char *display_name;
 
+       if (!IsEmptyStr(bstr("force_room"))) {
+               gotoroom(bstr("force_room"));
+       }
+
        display_name = bstr("display_name");
        if (!strcmp(display_name, "__ANONYMOUS__")) {
                display_name = "";
@@ -2936,7 +2948,7 @@ void post_message(void)
                        _("Automatically cancelled because you have already "
                        "saved this message."));
        } else {
-               rfc2047encode(encoded_subject, sizeof encoded_subject, bstr("subject"));
+               webcit_rfc2047encode(encoded_subject, sizeof encoded_subject, bstr("subject"));
                sprintf(buf, "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s",
                        bstr("recp"),
                        is_anonymous,
@@ -3122,6 +3134,9 @@ void display_enter(void)
        }
        wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
        wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
+       wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
+       escputs(WC->wc_roomname);
+       wprintf("\">\n");
 
        /** submit or cancel buttons */
         wprintf("<p class=\"send_edit_msg\">");
@@ -3139,7 +3154,7 @@ void display_enter(void)
 
        wprintf("<img src=\"static/newmess3_24x.gif\" class=\"imgedit\">");
        wprintf("  ");  /** header bar */
-       fmt_date(buf, now, 0);
+       webcit_fmt_date(buf, now, 0);
        wprintf("%s", buf);
        wprintf("\n");  /** header bar */
 
@@ -3211,7 +3226,7 @@ void display_enter(void)
                escputs(bstr("recp"));
                wprintf("\" size=45 maxlength=1000 />");
                wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
-               wprintf("</td><td rowspan=\"3\" align=\"left\" valign=\"top\"");
+               wprintf("</td><td rowspan=\"3\" align=\"left\" valign=\"top\">");
 
                /** Pop open an address book -- begin **/
                wprintf(
@@ -3261,7 +3276,7 @@ void display_enter(void)
        }
        wprintf("</label></th>"
                "<td colspan=\"2\">"
-               "<input type=\"text\" name=\"subject\" id=\"subject_id\" value=\" ");
+               "<input type=\"text\" name=\"subject\" id=\"subject_id\" value=\"");
        escputs(bstr("subject"));
        wprintf("\" size=45 maxlength=70>\n");
        wprintf("</td></tr>");
@@ -3334,8 +3349,12 @@ void display_enter(void)
                }
        }
 
-       wprintf("</textarea>");
+       wprintf("</textarea>\n");
 
+       /** Make sure we only insert our signature once */
+       /** We don't care if it was there or not before, it needs to be there now. */
+       wprintf("<input type=\"hidden\" name=\"sig_inserted\" value=\"yes\">\n");
+       
        /**
         * The following template embeds the TinyMCE richedit control, and automatically
         * transforms the textarea into a richedit textarea.
@@ -3363,19 +3382,15 @@ void display_enter(void)
        wprintf(" <input name=\"attachfile\" class=\"attachfile\" "
                "size=16 type=\"file\">\n&nbsp;&nbsp;"
                "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
-       wprintf("</div>");
+       wprintf("</div>");      /* End of "attachment buttons" div */
 
 
-       /** Make sure we only insert our signature once */
-       if (strcmp(bstr("sig_inserted"), "yes")) {
-               wprintf("<input type=\"hidden\" name=\"sig_inserted\" value=\"yes\">\n");
-       }
-       
        wprintf("</td></tr></table>");
        
        wprintf("</form>\n");
-       wprintf("</div></div>\n");
+       wprintf("</div>\n");    /* end of "fix_scrollbar_bug" div */
 
+       /* NOTE: address_book_popup() will close the "content" div.  Don't close it here. */
 DONE:  address_book_popup();
        wDumpContent(1);
 }