* fix display of quoted-printable names in addressbook views
authorWilfried Göesgens <willi@citadel.org>
Mon, 2 Mar 2009 22:24:09 +0000 (22:24 +0000)
committerWilfried Göesgens <willi@citadel.org>
Mon, 2 Mar 2009 22:24:09 +0000 (22:24 +0000)
webcit/messages.c
webcit/vcard_edit.c
webcit/webcit.h

index d60b2eefb9ecf4647418774814a6a4f1daeb394a..c3303792bee553215325cbf60829a4c961a44382 100644 (file)
@@ -663,6 +663,7 @@ void readloop(long oper)
        int sortit = 0;
        int defaultsortorder = 0;
        WCTemplputParams SubTP;
+       char *ab_name;
 
        if (havebstr("is_summary") && (1 == (ibstr("is_summary"))))
                WCC->wc_view = VIEW_MAILBOX;
@@ -852,13 +853,15 @@ void readloop(long oper)
                                display_note(Msg, Msg->is_new);
                                break;
                        case VIEW_ADDRESSBOOK:
-                               fetch_ab_name(Msg, buf);
+                               ab_name = NULL;
+                               fetch_ab_name(Msg, &ab_name);
                                ++num_ab;
                                addrbook = realloc(addrbook,
                                                   (sizeof(addrbookent) * num_ab) );
-                               safestrncpy(addrbook[num_ab-1].ab_name, buf,
+                               safestrncpy(addrbook[num_ab-1].ab_name, ab_name,
                                            sizeof(addrbook[num_ab-1].ab_name));
                                addrbook[num_ab-1].ab_msgnum = Msg->msgnum;
+                               free(ab_name);
                                break;
                        case VIEW_BBS: /* Tag the mails we want to show in bbview... */
                        default:
index 97ef83fa988c572ba30bf0f002b20c9be5ba3333..3a983ac4cb91ddd8e0714351c2e89be6d8014043 100644 (file)
@@ -58,7 +58,7 @@ void display_addressbook(long msgnum, char alpha) {
                if (vcard_source != NULL) {
 
                        /** Display the summary line */
-                       display_vcard(WC->WBuf, vcard_source, alpha, 0, NULL,msgnum);
+                       display_vcard(WC->WBuf, vcard_source, alpha, 0, NULL, msgnum);
 
                        /** If it's my vCard I can edit it */
                        if (    (!strcasecmp(ChrPtr(WC->wc_roomname), USERCONFIGROOM))
@@ -105,7 +105,7 @@ void lastfirst_firstlast(char *namebuf) {
  * \param msgnum the citadel message number
  * \param namebuf where to put the name in???
  */
-void fetch_ab_name(message_summary *Msg, char *namebuf) {
+void fetch_ab_name(message_summary *Msg, char **namebuf) {
        char buf[SIZ];
        char mime_partnum[SIZ];
        char mime_filename[SIZ];
@@ -118,7 +118,6 @@ void fetch_ab_name(message_summary *Msg, char *namebuf) {
        message_summary summ;/// TODO this will lak
 
        if (namebuf == NULL) return;
-       strcpy(namebuf, "");
 
        memset(&summ, 0, sizeof(summ));
        //////safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
@@ -154,14 +153,19 @@ void fetch_ab_name(message_summary *Msg, char *namebuf) {
                        free(vcard_source);
                }
        }
-
-       lastfirst_firstlast(namebuf);
-       striplt(namebuf);
-       len = strlen(namebuf);
-       for (i=0; i<len; ++i) {
-               if (namebuf[i] != ';') return;
+       if (*namebuf != NULL) {
+               lastfirst_firstlast(*namebuf);
+               striplt(*namebuf);
+               len = strlen(*namebuf);
+               for (i=0; i<len; ++i) {
+                       if ((*namebuf)[i] != ';') return;
+               }
+               free (*namebuf);
+               (*namebuf) = strdup(_("(no name)"));
+       }
+       else {
+               (*namebuf) = strdup(_("(no name)"));
        }
-       strcpy(namebuf, _("(no name)"));
 }
 
 
@@ -214,14 +218,49 @@ void vcard_n_prettyize(char *name)
  * \param v the vcard to retrieve the name from
  * \param storename where to put the name at
  */
-void fetchname_parsed_vcard(struct vCard *v, char *storename) {
+void fetchname_parsed_vcard(struct vCard *v, char **storename) {
        char *name;
+       char *prop;
+       char buf[SIZ];
+       int j, n, len;
+       int is_qp = 0;
+       int is_b64 = 0;
 
-       strcpy(storename, "");
+       *storename = NULL;
 
        name = vcard_get_prop(v, "n", 1, 0, 0);
        if (name != NULL) {
-               strcpy(storename, name);
+               len = strlen(name);
+               prop = vcard_get_prop(v, "n", 1, 0, 1);
+               n = num_tokens(prop, ';');
+
+               for (j=0; j<n; ++j) {
+                       extract_token(buf, prop, j, ';', sizeof buf);
+                       if (!strcasecmp(buf, "encoding=quoted-printable")) {
+                               is_qp = 1;
+                       }
+                       if (!strcasecmp(buf, "encoding=base64")) {
+                               is_b64 = 1;
+                       }
+               }
+               if (is_qp) {
+                       // %ff can become 6 bytes in utf8 
+                       *storename = malloc(len * 2 + 3); 
+                       j = CtdlDecodeQuotedPrintable(
+                               *storename, name,
+                               len);
+                       (*storename)[j] = 0;
+               }
+               else if (is_b64) {
+                       // ff will become one byte..
+                       *storename = malloc(len + 50);
+                       CtdlDecodeBase64(
+                               *storename, name,
+                               len);
+               }
+               else {
+                       *storename = strdup(name);
+               }
                /* vcard_n_prettyize(storename); */
        }
 
@@ -499,8 +538,13 @@ void display_parsed_vcard(StrBuf *Target, struct vCard *v, int full, long msgnum
  * \param storename where to store???
  * \param msgnum Citadel message pointer
  */
-void display_vcard(StrBuf *Target, const char *vcard_source, char alpha, int full, char *storename, 
-       long msgnum) {
+void display_vcard(StrBuf *Target, 
+                  const char *vcard_source, 
+                  char alpha, 
+                  int full, 
+                  char **storename, 
+                  long msgnum) 
+{
        struct vCard *v;
        char *name;
        StrBuf *Buf;
index 8bd95462ac20b5b30c7871264abb43c474ef891d..74083d41ce7c9e9538e6f28128d3a7f501c6e643 100644 (file)
@@ -586,8 +586,8 @@ void serv_read(char *buf, int bytes);
 
 void SetAccessCommand(long Oper);
 void do_addrbook_view(addrbookent *addrbook, int num_ab);
-void fetch_ab_name(message_summary *Msg, char *namebuf);
-void display_vcard(StrBuf *Target, const char *vcard_source, char alpha, int full, char *storename, long msgnum);
+void fetch_ab_name(message_summary *Msg, char **namebuf);
+void display_vcard(StrBuf *Target, const char *vcard_source, char alpha, int full, char **storename, long msgnum);
 void jsonMessageList(void);
 void new_summary_view(void);
 void getseen(void);