--===============0393253324== Content-Type: multipart/signed; boundary="nextPart1939977.k3JFNqpPa0"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit --nextPart1939977.k3JFNqpPa0 Content-Type: multipart/mixed; boundary="Boundary-01=_A23fH/tzWFng3eP" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_A23fH/tzWFng3eP Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi all, attached is a patch that corrects the vcard parsing bug (kdelibs/kabc) deal= ing=20 with different charsets in vcards. It solves e.g. https://bugs.kde.org/show_bug.cgi?id=3D98790 This is mainly a backport from KDE4 where it's already solved. It also fixes the kdepim vcard thumbnailcreator and the kfile_vcf plugin. Is this ok to commit ? =2D-=20 Best regards/Sch=C3=B6ne Gr=C3=BC=C3=9Fe Martin () ascii ribbon campaign - against html mail=20 /\ - against microsoft attachments --Boundary-01=_A23fH/tzWFng3eP Content-Type: text/x-diff; charset="us-ascii"; name="charset.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="charset.patch" Index: vcardformatplugin.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- vcardformatplugin.cpp (revision 755969) +++ vcardformatplugin.cpp (working copy) @@ -41,7 +41,7 @@ QString data; =20 QTextStream t( file ); =2D t.setEncoding( QTextStream::UnicodeUTF8 ); + t.setEncoding( QTextStream::Latin1 ); data =3D t.read(); =20 VCardConverter converter; @@ -60,7 +60,7 @@ QString data; =20 QTextStream t( file ); =2D t.setEncoding( QTextStream::UnicodeUTF8 ); + t.setEncoding( QTextStream::Latin1 ); data =3D t.read(); =20 VCardConverter converter; Index: vcardparser/testread.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- vcardparser/testread.cpp (revision 755969) +++ vcardparser/testread.cpp (working copy) @@ -70,7 +70,7 @@ QString text; =20 QTextStream s( &file ); =2D s.setEncoding( QTextStream::UnicodeUTF8 ); + s.setEncoding( QTextStream::Latin1 ); text =3D s.read(); file.close(); =20 Index: vcardparser/vcardparser.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- vcardparser/vcardparser.cpp (revision 755969) +++ vcardparser/vcardparser.cpp (working copy) @@ -19,6 +19,7 @@ */ =20 #include +#include =20 #include =20 @@ -129,31 +130,44 @@ =20 removeEscapes( value ); =20 + QByteArray output; + bool wasBase64Encoded =3D false; + params =3D vCardLine.parameterList(); if ( params.findIndex( "encoding" ) !=3D -1 ) { // have to decode = the data =2D QByteArray input, output; =2D input =3D value.local8Bit(); + QByteArray input; + input =3D QCString(value.latin1()); if ( vCardLine.parameter( "encoding" ).lower() =3D=3D "b" || =2D vCardLine.parameter( "encoding" ).lower() =3D=3D "base64"= ) + vCardLine.parameter( "encoding" ).lower() =3D=3D "base64" )= { KCodecs::base64Decode( input, output ); + wasBase64Encoded =3D true; + } else if ( vCardLine.parameter( "encoding" ).lower() =3D=3D "quot= ed-printable" ) { // join any qp-folded lines while ( value.at( value.length() - 1 ) =3D=3D '=3D' && it !=3D= linesEnd ) { value =3D value.remove( value.length() - 1, 1 ) + (*it); ++it; } =2D input =3D value.local8Bit(); + input =3D QCString(value.latin1()); KCodecs::quotedPrintableDecode( input, output ); } =2D if ( vCardLine.parameter( "charset" ).lower() =3D=3D "utf-8" )= { =2D vCardLine.setValue( QString::fromUtf8( output.data(), output= =2Esize() ) ); + } else { + output =3D QCString(value.latin1()); + } + + if ( params.findIndex( "charset" ) !=3D -1 ) { // have to convert = the data + QTextCodec *codec =3D + QTextCodec::codecForName( vCardLine.parameter( "charset" ).lat= in1() ); + if ( codec ) { + vCardLine.setValue( codec->toUnicode( output ) ); } else { + vCardLine.setValue( QString::fromUtf8( output ) ); + } + } else if ( wasBase64Encoded ) { vCardLine.setValue( output ); =2D } =2D } else if ( vCardLine.parameter( "charset" ).lower() =3D=3D "utf= =2D8" ) { =2D vCardLine.setValue( QString::fromUtf8( value.ascii() ) ); =2D } else =2D vCardLine.setValue( value ); + } else { // if charset not given, assume it's in UTF-8 (as used i= n previous KDE versions) + vCardLine.setValue( QString::fromUtf8( output ) ); + } =20 currentVCard.addLine( vCardLine ); } --Boundary-01=_A23fH/tzWFng3eP Content-Type: text/x-diff; charset="us-ascii"; name="thumbnail.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="thumbnail.patch" Index: thumbnailcreator/ldifvcardcreator.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- thumbnailcreator/ldifvcardcreator.cpp (revision 756144) +++ thumbnailcreator/ldifvcardcreator.cpp (working copy) @@ -75,9 +75,7 @@ text.truncate(0); =20 // read the file =2D QTextStream t( &file ); =2D t.setEncoding( QTextStream::UnicodeUTF8 ); =2D QString contents =3D t.read(); + QString contents =3D file.readAll(); file.close(); =20 // convert the file contents to a KABC::Addressee address --Boundary-01=_A23fH/tzWFng3eP Content-Type: text/x-diff; charset="us-ascii"; name="vcf.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="vcf.patch" Index: Makefile.am =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- Makefile.am (revision 752148) +++ Makefile.am (working copy) @@ -10,7 +10,7 @@ =20 kfile_vcf_la_SOURCES =3D kfile_vcf.cpp=20 kfile_vcf_la_LDFLAGS =3D $(all_libraries) -module $(KDE_PLUGIN) =2Dkfile_vcf_la_LIBADD =3D $(LIB_KSYCOCA) +kfile_vcf_la_LIBADD =3D $(LIB_KSYCOCA) $(LIB_KABC) =20 # let automoc handle all of the meta source files (moc) METASOURCES =3D AUTO Index: kfile_vcf.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- kfile_vcf.cpp (revision 752148) +++ kfile_vcf.cpp (working copy) @@ -24,20 +24,11 @@ #include #include #include =2D#include +#include =20 #include =2D#include =2D#include #include =2D#include =20 =2D#if !defined(__osf__) =2D#include =2D#else =2Dtypedef unsigned short uint32_t; =2D#endif =2D typedef KGenericFactory VcfFactory; =20 K_EXPORT_COMPONENT_FACTORY(kfile_vcf, VcfFactory( "kfile_vcf" )) @@ -63,7 +54,6 @@ =20 bool KVcfPlugin::readInfo( KFileMetaInfo& info, uint /*what*/ ) { =2D QFile file(info.path()); =20 if (!file.open(IO_ReadOnly)) @@ -72,58 +62,38 @@ return false; } =20 =2D char id_name[] =3D "FN:"; =2D char id_email[] =3D "EMAIL;INTERNET:"; + // even the vcard thumbnail QString::fromUtf8(buf_name));creator reads= the full file ... + // The following is partly copied from there + QString contents =3D file.readAll(); + file.close(); =20 =2D // we need a buffer for lines =2D char linebuf[1000]; + KABC::VCardConverter converter; + KABC::Addressee addr =3D converter.parseVCard(contents); =20 =2D // we need a buffer for other stuff =2D char buf_name[1000] =3D ""; =2D char buf_email[1000] =3D ""; =2D buf_name[999] =3D '\0'; =2D buf_email[999] =3D '\0'; =2D char * myptr; + KFileMetaInfoGroup group =3D appendGroup(info, "Technical"); =20 =2D // FIXME: This is intensely inefficient!!! + // prepare the text + QString name =3D addr.formattedName().simplifyWhiteSpace(); + if ( name.isEmpty() ) + name =3D addr.givenName() + " " + addr.familyName(); + name =3D name.simplifyWhiteSpace(); =20 =2D bool done=3Dfalse; =2D while (!done) { + if ( ! name.isEmpty() ) + appendItem(group, "Name", name); =20 =2D // read a line =2D int r =3D file.readLine(linebuf, sizeof( linebuf )); + if ( ! addr.preferredEmail().isEmpty() ) + appendItem(group, "Email", addr.preferredEmail()); =20 =2D if ( r < 0 ) { =2D done =3D true; =2D break; =2D } =2D =2D // have we got something useful? =2D if (memcmp(linebuf, id_name, 3) =3D=3D 0) { =2D // we have a name =2D myptr =3D linebuf + 3; =2D strlcpy(buf_name, myptr, sizeof( buf_name )); =2D } else if (memcmp(linebuf, id_email, 15) =3D=3D 0) { =2D // we have an email =2D myptr =3D linebuf + 15; =2D strlcpy(buf_email, myptr, sizeof( buf_email )); =2D } =2D =2D // are we done yet? =2D if ((strlen(buf_name) > 0 && strlen(buf_email) > 0) || file.atEn= d()) =2D done =3D true; =2D + KABC::PhoneNumber::List pnList =3D addr.phoneNumbers(); + QStringList phoneNumbers; + for (unsigned int no=3D0; no 0) =2D appendItem(group, "Name", QString::fromUtf8(buf_name)); =2D =2D if (strlen(buf_email) > 0) =2D appendItem(group, "Email", buf_email); =2D return true; } =20 --Boundary-01=_A23fH/tzWFng3eP-- --nextPart1939977.k3JFNqpPa0 Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) iD8DBQBHf32AUeHBRvgua64RAsKjAJ4xjnyl5zYlCu6XvrqASK7KaMEM3ACfbqXZ Ra49p6nuKU4WGj6TefL7PCc= =UGkU -----END PGP SIGNATURE----- --nextPart1939977.k3JFNqpPa0-- --===============0393253324== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ KDE PIM mailing list kde-pim@kde.org https://mail.kde.org/mailman/listinfo/kde-pim KDE PIM home page at http://pim.kde.org/ --===============0393253324==--