]> code.citadel.org Git - citadel.git/blobdiff - webcit/messages.c
* Added utility functions for displaying vcalendar timestamps in web forms
[citadel.git] / webcit / messages.c
index d70184a2e206e3e4cf9afdeb08705e1b8e52ebc4..f6a88c416f6a1c0b058815d0bce16221a448eb3e 100644 (file)
@@ -25,6 +25,7 @@
 #include <signal.h>
 #include "webcit.h"
 #include "vcard.h"
+#include "webserver.h"
 
 
 /*
@@ -69,10 +70,10 @@ char buf[];
                        end = pos;
        }
 
-       safestrncpy(urlbuf, &buf[start], end - start);
+       strncpy(urlbuf, &buf[start], end - start);
        urlbuf[end - start] = 0;
 
-       safestrncpy(outbuf, buf, start);
+       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);
        strcat(outbuf, &buf[end]);
@@ -194,8 +195,9 @@ void display_vcard(char *vcard_source, char alpha, int full) {
 
 
 
-
-
+/*
+ * I wanna SEE that message!
+ */
 void read_message(long msgnum) {
        char buf[SIZ];
        char mime_partnum[SIZ];
@@ -214,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]);
@@ -238,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)
@@ -329,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 ***/
+
                }
 
        }
@@ -398,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;
                        }
@@ -418,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))
@@ -440,11 +480,23 @@ void read_message(long msgnum) {
                        }
 
                        /* In all cases, display the full card */
-                       display_vcard(vcard_source, 0, 1);
-                       free(vcard_source);
+                       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;
+       }
+
 }
 
 
@@ -620,6 +672,8 @@ void readloop(char *oper)
        int num_displayed = 0;
        int is_summary = 0;
        int is_addressbook = 0;
+       int is_calendar = 0;
+       int is_tasks = 0;
        int remaining_messages;
        int lo, hi;
        int lowest_displayed = (-1);
@@ -676,6 +730,17 @@ void readloop(char *oper)
                else wprintf("<A HREF=\"/readfwd?alpha=1\">(other)</A>\n");
                wprintf("<HR width=100%%>\n");
        }
+       if (WC->wc_view == 3) {         /* calendar */
+               is_calendar = 1;
+               strcpy(cmd, "MSGS ALL");
+               maxmsgs = 32767;
+       }
+       if (WC->wc_view == 4) {         /* tasks */
+               is_tasks = 1;
+               strcpy(cmd, "MSGS ALL");
+               maxmsgs = 32767;
+               wprintf("<UL>");
+       }
 
        nummsgs = load_msg_ptrs(cmd);
        if (nummsgs == 0) {
@@ -740,6 +805,12 @@ void readloop(char *oper)
                        else if (is_addressbook) {
                                display_addressbook(WC->msgarr[a], alpha);
                        }
+                       else if (is_calendar) {
+                               display_calendar(WC->msgarr[a]);
+                       }
+                       else if (is_tasks) {
+                               display_task(WC->msgarr[a]);
+                       }
                        else {
                                read_message(WC->msgarr[a]);
                        }
@@ -765,6 +836,13 @@ void readloop(char *oper)
                wprintf("</TABLE>\n");
        }
 
+       if (is_tasks) {
+               wprintf("</UL>\n"
+                       "<A HREF=\"/display_edit_task?msgnum=0\">"
+                       "Add new task</A>\n"
+               );
+       }
+
        /* Bump these because although we're thinking in zero base, the user
         * is a drooling idiot and is thinking in one base.
         */
@@ -904,13 +982,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"));