From 91c7cf82503b5dcbea2ee032aa9f683501591a9a Mon Sep 17 00:00:00 2001 From: George Staikos Date: Sat, 2 Sep 2000 15:58:18 +0000 Subject: [PATCH] More vCard fixes - quoted printable handled better, and base64 now works. svn path=/trunk/kdenetwork/kmail/; revision=62470 --- kmdisplayvcard.cpp | 1 + vcard.cpp | 35 ++++++++++++++++++++++++++--------- vcard.h | 3 +++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/kmdisplayvcard.cpp b/kmdisplayvcard.cpp index 0551874fe..af5b60ed3 100644 --- a/kmdisplayvcard.cpp +++ b/kmdisplayvcard.cpp @@ -221,6 +221,7 @@ QValueList values; // try to add each type of phone number if we have them QString thisnum; int row = 3; + // note: don't use i18n with this macro - it does it for you DO_PHONENUMBER(VCARD_TEL_HOME, "Home"); DO_PHONENUMBER(VCARD_TEL_WORK, "Work"); DO_PHONENUMBER(VCARD_TEL_PREF, "Preferred"); diff --git a/vcard.cpp b/vcard.cpp index 869ec7efb..a0c82b9a8 100644 --- a/vcard.cpp +++ b/vcard.cpp @@ -187,6 +187,7 @@ QValueList lines; //QValueList nametokens = tokenizeBy(linetokens[0], ';'); QValueList nametokens = tokenizeBy(linetokens[0], QRegExp(";")); bool qp = false, first_pass = true; + bool b64 = false; if (nametokens.count() > 0) { _vcl.qualified = false; @@ -195,11 +196,14 @@ QValueList lines; for (QValueListIterator z = nametokens.begin(); z != nametokens.end(); ++z) { - if (*z == VCARD_QUOTED_PRINTABLE) { + QString zz = (*z).lower(); + if (zz == VCARD_QUOTED_PRINTABLE || zz == VCARD_ENCODING_QUOTED_PRINTABLE) { qp = true; + } else if (zz == VCARD_BASE64) { + b64 = true; } else if (!first_pass) { _vcl.qualified = true; - _vcl.qualifiers.append((*z).lower()); + _vcl.qualifiers.append(zz); } first_pass = false; } @@ -219,13 +223,26 @@ QValueList lines; // split into tokens by ; // add to parameters vector //_vcl.parameters = tokenizeBy(linetokens[1], ';'); - _vcl.parameters = tokenizeBy(linetokens[1], QRegExp(";"), true); - if (qp) { - for (QValueListIterator z = _vcl.parameters.begin(); - z != _vcl.parameters.end(); - ++z) { - _vcl.qpDecode(*z); - } + if (b64) { + if (linetokens[1][linetokens[1].length()-1] != '=') + do { + linetokens[1] += *(++j); + } while ((*j)[(*j).length()-1] != '='); + } else { + if (qp) { // join any split lines + while (linetokens[1][linetokens[1].length()-1] == '=') { + linetokens[1].remove(linetokens[1].length()-1, 1); + linetokens[1].append(*(++j)); + } + } + _vcl.parameters = tokenizeBy(linetokens[1], QRegExp(";"), true); + if (qp) { // decode the quoted printable + for (QValueListIterator z = _vcl.parameters.begin(); + z != _vcl.parameters.end(); + ++z) { + _vcl.qpDecode(*z); + } + } } } else { _err = VC_ERR_INTERNAL; diff --git a/vcard.h b/vcard.h index bf42f683d..2ce8a2255 100644 --- a/vcard.h +++ b/vcard.h @@ -95,6 +95,9 @@ #define VCARD_KEY_PGP "pgp" #define VCARD_QUOTED_PRINTABLE "quoted-printable" +// this one is a temporary hack until we support TYPE=VALUE +#define VCARD_ENCODING_QUOTED_PRINTABLE "encoding=quoted-printable" +#define VCARD_BASE64 "base64" /* X-xxxxx also usable */