]> code.citadel.org Git - citadel.git/blobdiff - webcit/messages.c
* Changed decode_base64() to CtdlDecodeBase64() to avoid conflict with
[citadel.git] / webcit / messages.c
index bf44814d938bf7d22a96c3506da347cefed2ebd8..d5d98b155e6b187a267cfbbfb07dfd181c0d89a5 100644 (file)
@@ -25,6 +25,7 @@
 #include <signal.h>
 #include "webcit.h"
 #include "vcard.h"
+#include "webserver.h"
 
 
 /*
@@ -72,7 +73,6 @@ char buf[];
        strncpy(urlbuf, &buf[start], end - start);
        urlbuf[end - start] = 0;
 
-
        strncpy(outbuf, buf, start);
        sprintf(&outbuf[start], "%cA HREF=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
                LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
@@ -84,10 +84,28 @@ char buf[];
 
 /* display_vcard() calls this after parsing the textual vCard into
  * our 'struct vCard' data object.
+ *
+ * Set 'full' to nonzero to display the full card, otherwise it will only
+ * show a summary line.
  */
-void display_parsed_vcard(struct vCard *v) {
+void display_parsed_vcard(struct vCard *v, int full) {
        int i, j;
        char buf[SIZ];
+       char *name;
+
+       if (!full) {
+               wprintf("<TD>");
+               name = vcard_get_prop(v, "n", 1, 0, 0);
+               if (name != NULL) {
+                       strcpy(buf, name);
+                       escputs(buf);
+               }
+               else {
+                       wprintf("&nbsp;");
+               }
+               wprintf("</TD>");
+               return;
+       }
 
        wprintf("<TABLE bgcolor=#888888>");
        if (v->numprops) for (i=0; i<(v->numprops); ++i) {
@@ -144,9 +162,11 @@ void display_parsed_vcard(struct vCard *v) {
 
 
 /*
- * Experimental output type of thing
+ * Display a textual vCard
+ * (Converts to a vCard object and then calls the actual display function)
+ * Set 'full' to nonzero to display the whole card instead of a one-liner
  */
-void display_vcard(char *vcard_source, char alpha) {
+void display_vcard(char *vcard_source, char alpha, int full) {
        struct vCard *v;
        char *name;
        char buf[SIZ];
@@ -165,7 +185,7 @@ void display_vcard(char *vcard_source, char alpha) {
           || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
           || ((!isalpha(alpha)) && (!isalpha(this_alpha))) ) {
 
-               display_parsed_vcard(v);
+               display_parsed_vcard(v, full);
 
        }
 
@@ -175,8 +195,9 @@ void display_vcard(char *vcard_source, char alpha) {
 
 
 
-
-
+/*
+ * I wanna SEE that message!
+ */
 void read_message(long msgnum) {
        char buf[SIZ];
        char mime_partnum[SIZ];
@@ -195,16 +216,17 @@ void read_message(long msgnum) {
        int nhdr = 0;
        int bq = 0;
        char vcard_partnum[SIZ];
-       char *vcard_source = NULL;
+       char cal_partnum[SIZ];
+       char *part_source = NULL;
 
        strcpy(from, "");
        strcpy(node, "");
        strcpy(rfca, "");
        strcpy(reply_to, "");
        strcpy(vcard_partnum, "");
+       strcpy(cal_partnum, "");
 
-       sprintf(buf, "MSG0 %ld", msgnum);
-       serv_puts(buf);
+       serv_printf("MSG4 %ld", msgnum);
        serv_gets(buf);
        if (buf[0] != '1') {
                wprintf("<STRONG>ERROR:</STRONG> %s<BR>\n", &buf[4]);
@@ -219,7 +241,7 @@ void read_message(long msgnum) {
        wprintf("COLOR=\"000000\"> ");
        strcpy(m_subject, "");
 
-       while (serv_gets(buf), strncasecmp(buf, "text", 4)) {
+       while (serv_gets(buf), strcasecmp(buf, "text")) {
                if (!strncasecmp(buf, "nhdr=yes", 8))
                        nhdr = 1;
                if (nhdr == 1)
@@ -310,10 +332,17 @@ void read_message(long msgnum) {
                                        msgnum, mime_partnum);
                        }
 
+                       /*** begin handler prep ***/
                        if (!strcasecmp(mime_content_type, "text/x-vcard")) {
                                strcpy(vcard_partnum, mime_partnum);
                        }
 
+                       if (!strcasecmp(mime_content_type, "text/calendar")) {
+                               strcpy(cal_partnum, mime_partnum);
+                       }
+
+                       /*** end handler prep ***/
+
                }
 
        }
@@ -379,18 +408,33 @@ void read_message(long msgnum) {
 
        wprintf("</TR></TABLE>\n");
 
-       if (format_type == 0) {
+       /* 
+        * Learn the content type
+        */
+       strcpy(mime_content_type, "text/plain");
+       while (serv_gets(buf), (strlen(buf) > 0)) {
+               if (!strncasecmp(buf, "Content-type: ", 14)) {
+                       safestrncpy(mime_content_type, &buf[14],
+                               sizeof(mime_content_type));
+               }
+       }
+
+       /* Messages in legacy Citadel variformat get handled thusly... */
+       if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
                fmout(NULL);
-       } else {
+       }
+
+       /* Boring old 80-column fixed format text gets handled this way... */
+       else if (!strcasecmp(mime_content_type, "text/plain")) {
                while (serv_gets(buf), strcmp(buf, "000")) {
                        while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
                                buf[strlen(buf) - 1] = 0;
                        if ((bq == 0) &&
-                           ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
+                       ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
                                wprintf("<FONT COLOR=\"000044\"><I>");
                                bq = 1;
                        } else if ((bq == 1) &&
-                                  (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
+                               (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
                                wprintf("</FONT></I>");
                                bq = 0;
                        }
@@ -399,17 +443,32 @@ void read_message(long msgnum) {
                        escputs(buf);
                        wprintf("</TT><BR>\n");
                }
+               wprintf("</I><BR>");
+       }
+
+       else /* HTML is fun, but we've got to strip it first */
+       if (!strcasecmp(mime_content_type, "text/html")) {
+               output_html();
+       }
+
+       /* Unknown weirdness */
+       else {
+               wprintf("I don't know how to display %s<BR>\n",
+                       mime_content_type);
+               while (serv_gets(buf), strcmp(buf, "000")) { }
        }
-       wprintf("</I><BR>");
 
+
+       /* Afterwards, offer links to download attachments 'n' such */
        if (mime_http != NULL) {
                wprintf("%s", mime_http);
                free(mime_http);
        }
 
+       /* Handler for vCard parts */
        if (strlen(vcard_partnum) > 0) {
-               vcard_source = load_mimepart(msgnum, vcard_partnum);
-               if (vcard_source != NULL) {
+               part_source = load_mimepart(msgnum, vcard_partnum);
+               if (part_source != NULL) {
 
                        /* If it's my vCard I can edit it */
                        if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
@@ -420,12 +479,24 @@ void read_message(long msgnum) {
                                wprintf("(edit)</A>");
                        }
 
-                       /* In all cases, display it */
-                       display_vcard(vcard_source, 0);
-                       free(vcard_source);
+                       /* In all cases, display the full card */
+                       display_vcard(part_source, 0, 1);
                }
        }
 
+       /* Handler for calendar parts */
+       if (strlen(cal_partnum) > 0) {
+               part_source = load_mimepart(msgnum, cal_partnum);
+               if (part_source != NULL) {
+                       cal_process_attachment(part_source);
+               }
+       }
+
+       if (part_source) {
+               free(part_source);
+               part_source = NULL;
+       }
+
 }
 
 
@@ -543,6 +614,9 @@ void display_addressbook(long msgnum, char alpha) {
                vcard_source = load_mimepart(msgnum, vcard_partnum);
                if (vcard_source != NULL) {
 
+                       /* Display the summary line */
+                       display_vcard(vcard_source, alpha, 0);
+
                        /* If it's my vCard I can edit it */
                        if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
                           || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))) {
@@ -552,8 +626,6 @@ void display_addressbook(long msgnum, char alpha) {
                                wprintf("(edit)</A>");
                        }
 
-                       /* In all cases, display it */
-                       display_vcard(vcard_source, alpha);
                        free(vcard_source);
                }
        }
@@ -652,7 +724,8 @@ void readloop(char *oper)
                        }
                        wprintf("&nbsp;");
                }
-               wprintf("<A HREF=\"/readfwd?alpha=1\">(other)</A>\n");
+               if (!isalpha(alpha)) wprintf("<FONT SIZE=+2>(other)</FONT>\n");
+               else wprintf("<A HREF=\"/readfwd?alpha=1\">(other)</A>\n");
                wprintf("<HR width=100%%>\n");
        }
 
@@ -690,6 +763,12 @@ void readloop(char *oper)
                );
        }
 
+       if (is_addressbook) {
+               wprintf("<TABLE border=0 cellspacing=0 "
+                       "cellpadding=0 width=100%%>\n"
+               );
+       }
+
        for (a = 0; a < nummsgs; ++a) {
                if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
 
@@ -698,14 +777,17 @@ void readloop(char *oper)
                        if (a > 0) pn_previous = WC->msgarr[a-1];
                        if (a < (nummsgs-1)) pn_next = WC->msgarr[a+1];
 
-                       /* Display the message */
-                       if (is_summary) {
+                       /* If a tabular view, set up the line */
+                       if ( (is_summary) || (is_addressbook) ) {
                                bg = 1 - bg;
                                wprintf("<TR BGCOLOR=%s>",
                                        (bg ? "DDDDDD" : "FFFFFF")
                                );
+                       }
+
+                       /* Display the message */
+                       if (is_summary) {
                                summarize_message(WC->msgarr[a]);
-                               wprintf("</TR>\n");
                        }
                        else if (is_addressbook) {
                                display_addressbook(WC->msgarr[a], alpha);
@@ -713,6 +795,12 @@ void readloop(char *oper)
                        else {
                                read_message(WC->msgarr[a]);
                        }
+
+                       /* If a tabular view, finish the line */
+                       if ( (is_summary) || (is_addressbook) ) {
+                               wprintf("</TR>\n");
+                       }
+
                        if (lowest_displayed < 0) lowest_displayed = a;
                        highest_displayed = a;
 
@@ -725,6 +813,10 @@ void readloop(char *oper)
                wprintf("</TABLE>\n");
        }
 
+       if (is_addressbook) {
+               wprintf("</TABLE>\n");
+       }
+
        /* Bump these because although we're thinking in zero base, the user
         * is a drooling idiot and is thinking in one base.
         */
@@ -864,13 +956,15 @@ void post_message(void)
                wprintf("Automatically cancelled because you have already "
                        "saved this message.<BR>\n");
        } else {
-               sprintf(buf, "ENT0 1|%s|0|0|%s",
+               sprintf(buf, "ENT0 1|%s|0|4|%s",
                        bstr("recp"),
                        bstr("subject") );
                serv_puts(buf);
                serv_gets(buf);
                if (buf[0] == '4') {
-                       text_to_server(bstr("msgtext"));
+                       serv_puts("Content-type: text/html");
+                       serv_puts("");
+                       text_to_server(bstr("msgtext"), 1);
                        serv_puts("000");
                        wprintf("Message has been posted.<BR>\n");
                        dont_post = atol(bstr("postseq"));
@@ -906,7 +1000,7 @@ void display_enter(void)
                if (strlen(bstr("recp")) > 0) {
                        wprintf("<EM>%s</EM><BR>\n", &buf[4]);
                }
-               do_template("prompt_for_recipient.html");
+               do_template("prompt_for_recipient");
                goto DONE;
        }
        if (buf[0] != '2') {