]> code.citadel.org Git - citadel.git/blobdiff - webcit/calendar.c
* persistantly handle the bufferlengths for dates; snprintf doesn't terminate strings...
[citadel.git] / webcit / calendar.c
index 01c6e40f10cb58ba0305ed5c6069c8b6db8b7239..8808618c06f2b4448c19e929acb275a5d2cd20ef 100644 (file)
@@ -125,7 +125,7 @@ void cal_process_object(StrBuf *Target,
                        }
                        else {
                                tt = icaltime_as_timet(t);
-                               webcit_fmt_date(buf, tt, DATEFMT_FULL);
+                               webcit_fmt_date(buf, 256, tt, DATEFMT_FULL);
                                StrBufAppendPrintf(Target, "<dt>");
                                StrBufAppendPrintf(Target, _("Starting date/time:"));
                                StrBufAppendPrintf(Target, "</dt><dd>%s</dd>", buf);
@@ -136,7 +136,7 @@ void cal_process_object(StrBuf *Target,
                if (p != NULL) {
                        t = icalproperty_get_dtend(p);
                        tt = icaltime_as_timet(t);
-                       webcit_fmt_date(buf, tt, DATEFMT_FULL);
+                       webcit_fmt_date(buf, 256, tt, DATEFMT_FULL);
                        StrBufAppendPrintf(Target, "<dt>");
                        StrBufAppendPrintf(Target, _("Ending date/time:"));
                        StrBufAppendPrintf(Target, "</dt><dd>%s</dd>", buf);
@@ -1017,6 +1017,11 @@ void load_ical_object(long msgnum, int unread,
        char *relevant_source = NULL;
        icalcomponent *cal, *c;
        int phase = 0;                          /* 0 = citadel headers, 1 = mime headers, 2 = body */
+       char msg4_content_type[256] = "";
+       char msg4_content_encoding[256] = "";
+       int msg4_content_length = 0;
+       int msg4_content_alloc = 0;
+       int body_bytes = 0;
 
        relevant_partnum[0] = '\0';
        sprintf(buf, "MSG4 %ld", msgnum);       /* we need the mime headers */
@@ -1049,18 +1054,47 @@ void load_ical_object(long msgnum, int unread,
                }
                else if ((phase == 1) && (IsEmptyStr(bptr))) {
                        phase = 2;
+
+                       if (
+                               (msg4_content_length > 0)
+                               && (!strcasecmp(msg4_content_encoding, "7bit"))
+                               && (    (!strcasecmp(mime_content_type, "text/calendar"))
+                                       || (!strcasecmp(mime_content_type, "application/ics"))
+                                       || (!strcasecmp(mime_content_type, "text/vtodo"))
+                               )
+                       ) {
+                               if (relevant_source != NULL) free(relevant_source);
+                               msg4_content_alloc = msg4_content_length * 2;
+                               relevant_source = malloc(msg4_content_alloc);
+                               relevant_source[0] = 0;
+                               body_bytes = 0;
+                       }
+
                }
-/**
- ** FIXME optimize here
- **
-               else if ((phase == 1) && (!strncasecmp(bptr, "Content-type:", 13))) {
-                       lprintf(9, "%s\n", bptr);
+               else if ((phase == 1) && (!strncasecmp(bptr, "Content-type: ", 14))) {
+                       safestrncpy(msg4_content_type, &bptr[14], sizeof msg4_content_type);
+                       striplt(msg4_content_type);
+               }
+               else if ((phase == 1) && (!strncasecmp(bptr, "Content-transfer-encoding: ", 27))) {
+                       safestrncpy(msg4_content_encoding, &bptr[27], sizeof msg4_content_encoding);
+                       striplt(msg4_content_type);
+               }
+               else if ((phase == 1) && (!strncasecmp(bptr, "Content-length: ", 16))) {
+                       msg4_content_length = atoi(&bptr[16]);
+               }
+               else if (relevant_source != NULL) {
+                       safestrncpy(&relevant_source[body_bytes], bptr, msg4_content_alloc-body_bytes);
+                       body_bytes += BufLen;
+                       safestrncpy(&relevant_source[body_bytes], "\r\n", msg4_content_alloc-body_bytes);
+                       body_bytes += 2;
                }
- **/
        }
        FreeStrBuf(&Buf);
 
-       if (!IsEmptyStr(relevant_partnum)) {
+       /* If MSG4 didn't give us the part we wanted, but we know that we can find it
+        * as one of the other MIME parts, attempt to load it now.
+        */
+       if ((relevant_source == NULL) && (!IsEmptyStr(relevant_partnum))) {
                relevant_source = load_mimepart(msgnum, relevant_partnum);
        }