2007-12-07 [colin] 3.1.0cvs66
authorColin Leroy <colin@colino.net>
Fri, 7 Dec 2007 17:21:21 +0000 (17:21 +0000)
committerColin Leroy <colin@colino.net>
Fri, 7 Dec 2007 17:21:21 +0000 (17:21 +0000)
* src/vcard.c
Fix QP decoding (and UTF8)

ChangeLog
PATCHSETS
configure.ac
src/vcard.c

index 12c957b93b7d1ecf57c32f60cbe44e053550dda7..f4c6ed970588499c3b4341afabd6a4bd9056766e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-12-07 [colin]     3.1.0cvs66
+
+       * src/vcard.c
+               Fix QP decoding (and UTF8)
+
 2007-12-07 [colin]     3.1.0cvs65
 
        * src/addrcustomattr.c
index c6eb85ce601ec92d083cc9812a3bd38f220946ae..ec8bfb621ada308241e7cc2be35112946c34a1e1 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.1.2.2 -r 1.1.2.3 src/common/w32_time.c;  cvs diff -u -r 1.1.2.3 -r 1.1.2.4 src/common/w32lib.h;  cvs diff -u -r 1.1.4.9 -r 1.1.4.10 src/etpan/etpan-thread-manager.c;  cvs diff -u -r 1.1.4.93 -r 1.1.4.94 src/etpan/imap-thread.c;  cvs diff -u -r 1.1.2.3 -r 1.1.2.4 src/etpan/nntp-thread.c;  cvs diff -u -r 1.20.2.15 -r 1.20.2.16 src/gtk/Makefile.am;  ) > 3.1.0cvs63.patchset
 ( cvs diff -u -r 1.213.2.171 -r 1.213.2.172 src/folder.c;  ) > 3.1.0cvs64.patchset
 ( cvs diff -u -r 1.1.2.1 -r 1.1.2.2 src/addrcustomattr.c;  ) > 3.1.0cvs65.patchset
+( cvs diff -u -r 1.14.2.12 -r 1.14.2.13 src/vcard.c;  ) > 3.1.0cvs66.patchset
index da78e24d435a0c44713e60df871f4b047d3cfccc..38223665c18edee42ecffcb5a035e8f30d9a516f 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=1
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=65
+EXTRA_VERSION=66
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index b14abd34268778ba1004c7034b77b0e229a4222f..ab64d7bbe64b7c9c9a05656db28a9160dac60fcb 100644 (file)
@@ -374,48 +374,25 @@ static void vcard_build_items(
 }
 
 /* Unescape characters in quoted-printable string. */
-static void vcard_unescape_qp( gchar *value ) {
-       gchar *ptr, *src, *dest;
-       gint d, v = 0;
-       gchar ch;
-       gboolean gotch;
-       ptr = value;
-       while( *ptr ) {
-               gotch = FALSE;
-               if( *ptr == '=' ) {
-                       v = 0;
-                       ch = *(ptr + 1);
-                       if( ch ) {
-                               if( ch > '0' && ch < '8' ) v = ch - '0';
-                       }
-                       d = -1;
-                       ch = *(ptr + 2);
-                       if( ch ) {
-                               if( ch > '\x60' ) ch -= '\x20';
-                               if( ch > '0' && ch < ' ' ) d = ch - '0';
-                               d = ch - '0';
-                               if( d > 9 ) d -= 7;
-                               if( d > -1 && d < 16 ) {
-                                       v = ( 16 * v ) + d;
-                                       gotch = TRUE;
-                               }
-                       }
-               }
-               if( gotch ) {
-                       /* Replace = with char and move down in buffer */
-                       *ptr = v;
-                       src = ptr + 3;
-                       dest = ptr + 1;
-                       while( *src ) {
-                               *dest++ = *src++;
-                       }
-                       *dest = '\0';
-               }
-               ptr++;
+static gchar *vcard_unescape_qp( gchar *value ) {
+       gchar *res = NULL;
+       gint len;
+       if (value == NULL)
+               return NULL;
+               
+       len = strlen(value);
+       res = g_malloc(len);
+       qp_decode_const(res, len-1, value);
+       if (!g_utf8_validate(res, -1, NULL)) {
+               gchar *mybuf = g_malloc(strlen(res)*2 +1);
+               conv_localetodisp(mybuf, strlen(res)*2 +1, res);
+               g_free(res);
+               res = mybuf;
        }
+       return res;
 }
 
-/*
+ /*
 * Read file data into root folder.
 * Note that one vCard can have multiple E-Mail addresses (MAIL tags);
 * these are broken out into separate address items. An address item
@@ -463,9 +440,12 @@ static void vcard_read_file( VCardFile *cardFile ) {
                /* g_print( "\tvalue: %s\n", tagvalue ); */
 
                if( g_utf8_collate( tagtype, VCARD_TYPE_QP ) == 0 ) {
+                       gchar *tmp;
                        /* Quoted-Printable: could span multiple lines */
                        tagvalue = vcard_read_qp( cardFile, tagvalue );
-                       vcard_unescape_qp( tagvalue );
+                       tmp = vcard_unescape_qp( tagvalue );
+                       g_free(tagvalue);
+                       tagvalue=tmp;
                        /* g_print( "QUOTED-PRINTABLE !!! final\n>%s<\n", tagvalue ); */
                }
 
@@ -677,9 +657,12 @@ gint vcard_test_read_file( const gchar *fileSpec ) {
                        }
 
                        if( g_utf8_collate( tagtype, VCARD_TYPE_QP ) == 0 ) {
+                               gchar *tmp;
                                /* Quoted-Printable: could span multiple lines */
                                tagvalue = vcard_read_qp( cardFile, tagvalue );
-                               vcard_unescape_qp( tagvalue );
+                               tmp = vcard_unescape_qp( tagvalue );
+                               g_free(tagvalue);
+                               tagvalue=tmp;
                        }
                        if( g_utf8_collate( tagname, VCARD_TAG_START ) == 0 &&
                                g_ascii_strcasecmp( tagvalue, VCARD_NAME ) == 0 ) {