]> code.citadel.org Git - citadel.git/blobdiff - webcit/messages.c
* collect sender / read / unread information for calendar items
[citadel.git] / webcit / messages.c
index 4fe27b2b9ea8f4ae34d96873bf66b3d9afbb850c..76dd1ab0f4ddf6b1b0b9c3a2894555fd995226a0 100644 (file)
@@ -60,7 +60,7 @@ iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode)
  * \param buf the stringbuffer to process
  */
 void utf8ify_rfc822_string(char *buf) {
-       char *start, *end;
+       char *start, *end, *next, *nextend, *ptr;
        char newbuf[1024];
        char charset[128];
        char encoding[16];
@@ -73,7 +73,7 @@ void utf8ify_rfc822_string(char *buf) {
        char *isav;                     /**< Saved pointer to input buffer */
        char *osav;                     /**< Saved pointer to output buffer */
        int passes = 0;
-       int i, len;
+       int i, len, delta;
        int illegal_non_rfc2047_encoding = 0;
 
        /** Sometimes, badly formed messages contain strings which were simply
@@ -112,6 +112,54 @@ void utf8ify_rfc822_string(char *buf) {
                }
        }
 
+       /* pre evaluate the first pair */
+       nextend = end = NULL;
+       len = strlen(buf);
+       start = strstr(buf, "=?");
+       if (start != NULL)
+               end = strstr(start, "?=");
+
+       while ((start != NULL) && (end != NULL))
+       {
+               next = strstr(end, "=?");
+               if (next != NULL)
+                       nextend = strstr(next, "?=");
+               if (nextend == NULL)
+                       next = NULL;
+
+               /* did we find two partitions */
+               if ((next != NULL) && 
+                   ((next - end) > 2))
+               {
+                       ptr = end + 2;
+                       while ((ptr < next) && 
+                              (isspace(*ptr) ||
+                               (*ptr == '\r') ||
+                               (*ptr == '\n') || 
+                               (*ptr == '\t')))
+                               ptr ++;
+                       /* did we find a gab just filled with blanks? */
+                       if (ptr == next)
+                       {
+                               memmove (end + 2,
+                                        next,
+                                        len - (next - start));
+
+                               /* now terminate the gab at the end */
+                               delta = (next - end) - 2;
+                               len -= delta;
+                               buf[len] = '\0';
+
+                               /* move next to its new location. */
+                               next -= delta;
+                               nextend -= delta;
+                       }
+               }
+               /* our next-pair is our new first pair now. */
+               start = next;
+               end = nextend;
+       }
+
        /** Now we handle foreign character sets properly encoded
         *  in RFC2047 format.
         */
@@ -445,7 +493,12 @@ void display_parsed_vcard(struct vCard *v, int full) {
                        }
                        
                        len = strlen(v->prop[i].value);
-       
+                       /* if we have some untagged QP, detect it here. */
+                       if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
+#ifdef HAVE_ICONV
+                               utf8ify_rfc822_string(v->prop[i].value);
+#endif
+
                        if (is_qp) {
                                // %ff can become 6 bytes in utf8 
                                thisvalue = malloc(len * 2 + 3); 
@@ -633,6 +686,9 @@ void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
 
        name = vcard_get_prop(v, "n", 1, 0, 0);
        if (name != NULL) {
+#ifdef HAVE_ICONV
+               utf8ify_rfc822_string(name);
+#endif
                strcpy(buf, name);
                this_alpha = buf[0];
        }
@@ -666,33 +722,33 @@ struct attach_link {
  */
 void read_message(long msgnum, int printable_view, char *section) {
        char buf[SIZ];
-       char mime_partnum[256];
-       char mime_name[256];
-       char mime_filename[256];
-       char escaped_mime_filename[256];
-       char mime_content_type[256];
-       char mime_charset[256];
-       char mime_disposition[256];
+       char mime_partnum[256] = "";
+       char mime_name[256] = "";
+       char mime_filename[256] = "";
+       char escaped_mime_filename[256] = "";
+       char mime_content_type[256] = "";
+       char mime_charset[256] = "";
+       char mime_disposition[256] = "";
        int mime_length;
        struct attach_link *attach_links = NULL;
        int num_attach_links = 0;
-       char mime_submessages[256];
-       char m_subject[256];
-       char m_cc[1024];
-       char from[256];
-       char node[256];
-       char rfca[256];
-       char reply_to[512];
-       char reply_all[4096];
-       char now[64];
+       char mime_submessages[256] = "";
+       char m_subject[256] = "";
+       char m_cc[1024] = "";
+       char from[256] = "";
+       char node[256] = "";
+       char rfca[256] = "";
+       char reply_to[512] = "";
+       char reply_all[4096] = "";
+       char now[64] = "";
        int format_type = 0;
        int nhdr = 0;
        int bq = 0;
        int i = 0;
-       char vcard_partnum[256];
-       char cal_partnum[256];
+       char vcard_partnum[256] = "";
+       char cal_partnum[256] = "";
        char *part_source = NULL;
-       char msg4_partnum[32];
+       char msg4_partnum[32] = "";
 #ifdef HAVE_ICONV
        iconv_t ic = (iconv_t)(-1) ;
        char *ibuf;                /**< Buffer of characters to be converted */
@@ -702,13 +758,6 @@ void read_message(long msgnum, int printable_view, char *section) {
        char *osav;                /**< Saved pointer to output buffer       */
 #endif
 
-       strcpy(from, "");
-       strcpy(node, "");
-       strcpy(rfca, "");
-       strcpy(reply_to, "");
-       strcpy(reply_all, "");
-       strcpy(vcard_partnum, "");
-       strcpy(cal_partnum, "");
        strcpy(mime_content_type, "text/plain");
        strcpy(mime_charset, "us-ascii");
        strcpy(mime_submessages, "");
@@ -1042,7 +1091,6 @@ void read_message(long msgnum, int printable_view, char *section) {
         */
        strcpy(mime_content_type, "text/plain");
        while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
-               lprintf(9, "GOT: <%s>\n", buf);
                if (!strcmp(buf, "000")) {
                        /* This is not necessarily an error condition.  See bug #226. */
                        goto ENDBODY;
@@ -1335,6 +1383,7 @@ void pullquote_message(long msgnum, int forward_attachments, int include_headers
        char from[256];
        char node[256];
        char rfca[256];
+       char to[256];
        char reply_to[512];
        char now[256];
        int format_type = 0;
@@ -1419,7 +1468,11 @@ void pullquote_message(long msgnum, int forward_attachments, int include_headers
                        }
                        if (!strncasecmp(buf, "rcpt=", 5)) {
                                wprintf(_("to "));
-                               wprintf("%s ", &buf[5]);
+                               strcpy(to, &buf[5]);
+#ifdef HAVE_ICONV
+                               utf8ify_rfc822_string(to);
+#endif
+                               wprintf("%s ", to);
                        }
                        if (!strncasecmp(buf, "time=", 5)) {
                                webcit_fmt_date(now, atol(&buf[5]), 0);
@@ -2293,7 +2346,7 @@ void readloop(char *oper)
         * new messages.
         */
        strcpy(old_msgs, "");
-       if (is_summary) {
+       if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR)){
                serv_puts("GTSN");
                serv_getln(buf, sizeof buf);
                if (buf[0] == '2') {
@@ -2305,7 +2358,7 @@ void readloop(char *oper)
 
        if (WCC->wc_default_view == VIEW_CALENDAR) {            /**< calendar */
                is_calendar = 1;
-               strcpy(cmd, "MSGS ALL");
+               strcpy(cmd, "MSGS ALL|||1");
                maxmsgs = 32767;
        }
        if (WCC->wc_default_view == VIEW_TASKS) {               /**< tasks */
@@ -2342,7 +2395,7 @@ void readloop(char *oper)
                goto DONE;
        }
 
-       if (is_summary) {
+       if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR)){
                for (a = 0; a < nummsgs; ++a) {
                        /** Are you a new message, or an old message? */
                        if (is_summary) {
@@ -2585,13 +2638,13 @@ void readloop(char *oper)
                                addrbook[num_ab-1].ab_msgnum = WCC->msgarr[a];
                        }
                        else if (is_calendar) {
-                               display_calendar(WCC->msgarr[a]);
+                               display_calendar(WCC->msgarr[a], WCC->summ[a].is_new);
                        }
                        else if (is_tasks) {
-                               display_task(WCC->msgarr[a]);
+                               display_task(WCC->msgarr[a], WCC->summ[a].is_new);
                        }
                        else if (is_notes) {
-                               display_note(WCC->msgarr[a]);
+                               display_note(WCC->msgarr[a], WCC->summ[a].is_new);
                        }
                        else {
                                if (displayed_msgs == NULL) {
@@ -3218,12 +3271,22 @@ void display_enter(void)
        wprintf("</td></tr>");
 
        if (recipient_required) {
-
+               char *ccraw;
+               char *copy;
+               size_t len;
                wprintf("<tr><th><label for=\"recp_id\"> ");
                wprintf(_("To:"));
                wprintf("</label></th>"
                        "<td><input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
-               escputs(bstr("recp"));
+               ccraw = bstr("recp");
+               len = strlen(ccraw);
+               copy = (char*) malloc(len * 2 + 1);
+               memcpy(copy, ccraw, len + 1); 
+#ifdef HAVE_ICONV
+               utf8ify_rfc822_string(copy);
+#endif
+               escputs(copy);
+               free(copy);
                wprintf("\" size=45 maxlength=1000 />");
                wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
                wprintf("</td><td rowspan=\"3\" align=\"left\" valign=\"top\">");
@@ -3245,7 +3308,15 @@ void display_enter(void)
                wprintf(_("CC:"));
                wprintf("</label></th>"
                        "<td><input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
-               escputs(bstr("cc"));
+               ccraw = bstr("cc");
+               len = strlen(ccraw);
+               copy = (char*) malloc(len * 2 + 1);
+               memcpy(copy, ccraw, len + 1); 
+#ifdef HAVE_ICONV
+               utf8ify_rfc822_string(copy);
+#endif
+               escputs(copy);
+               free(copy);
                wprintf("\" size=45 maxlength=1000 />");
                wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
                wprintf("</td></tr>");
@@ -3254,7 +3325,15 @@ void display_enter(void)
                wprintf(_("BCC:"));
                wprintf("</label></th>"
                        "<td><input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
-               escputs(bstr("bcc"));
+               ccraw = bstr("bcc");
+               len = strlen(ccraw);
+               copy = (char*) malloc(len * 2 + 1);
+               memcpy(copy, ccraw, len + 1); 
+#ifdef HAVE_ICONV
+               utf8ify_rfc822_string(copy);
+#endif
+               escputs(copy);
+               free(copy);
                wprintf("\" size=45 maxlength=1000 />");
                wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
                wprintf("</td></tr>");