From f5dfb1faa646f3705a5789f7bdf3ece561697596 Mon Sep 17 00:00:00 2001 From: tpearson Date: Tue, 22 Jun 2010 21:54:39 +0000 Subject: Added new hidden vCard URI parameter for certain CardDAV systems (such as Zimbra) that do not handle UID properly git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1141499 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kabc/vcardparser/vcardparser.cpp | 86 ++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 38 deletions(-) (limited to 'kabc/vcardparser/vcardparser.cpp') diff --git a/kabc/vcardparser/vcardparser.cpp b/kabc/vcardparser/vcardparser.cpp index 34c13c68a..df622b22f 100644 --- a/kabc/vcardparser/vcardparser.cpp +++ b/kabc/vcardparser/vcardparser.cpp @@ -227,54 +227,64 @@ QString VCardParser::createVCards( const VCard::List& list ) // iterate over the lines for ( lineIt = lines.constBegin(); lineIt != lines.constEnd(); ++lineIt ) { if ( !(*lineIt).value().asString().isEmpty() ) { - if ( (*lineIt).hasGroup() ) - textLine = (*lineIt).group() + "." + (*lineIt).identifier(); - else - textLine = (*lineIt).identifier(); - - params = (*lineIt).parameterList(); - hasEncoding = false; - if ( params.count() > 0 ) { // we have parameters - for ( paramIt = params.begin(); paramIt != params.end(); ++paramIt ) { - if ( (*paramIt) == "encoding" ) { - hasEncoding = true; - encodingType = (*lineIt).parameter( "encoding" ).lower(); + if ((*lineIt).identifier() != QString("URI")) { + if ( (*lineIt).hasGroup() ) + textLine = (*lineIt).group() + "." + (*lineIt).identifier(); + else + textLine = (*lineIt).identifier(); + + params = (*lineIt).parameterList(); + hasEncoding = false; + if ( params.count() > 0 ) { // we have parameters + for ( paramIt = params.begin(); paramIt != params.end(); ++paramIt ) { + if ( (*paramIt) == "encoding" ) { + hasEncoding = true; + encodingType = (*lineIt).parameter( "encoding" ).lower(); + } + + values = (*lineIt).parameters( *paramIt ); + for ( valueIt = values.constBegin(); valueIt != values.constEnd(); ++valueIt ) { + textLine.append( ";" + (*paramIt).upper() ); + if ( !(*valueIt).isEmpty() ) + textLine.append( "=" + (*valueIt) ); + } } + } - values = (*lineIt).parameters( *paramIt ); - for ( valueIt = values.constBegin(); valueIt != values.constEnd(); ++valueIt ) { - textLine.append( ";" + (*paramIt).upper() ); - if ( !(*valueIt).isEmpty() ) - textLine.append( "=" + (*valueIt) ); + if ( hasEncoding ) { // have to encode the data + QByteArray input, output; + if ( encodingType == "b" ) { + input = (*lineIt).value().toByteArray(); + KCodecs::base64Encode( input, output ); + } else if ( encodingType == "quoted-printable" ) { + input = (*lineIt).value().toString().utf8(); + input.resize( input.size() - 1 ); // strip \0 + KCodecs::quotedPrintableEncode( input, output, false ); } - } - } - if ( hasEncoding ) { // have to encode the data - QByteArray input, output; - if ( encodingType == "b" ) { - input = (*lineIt).value().toByteArray(); - KCodecs::base64Encode( input, output ); - } else if ( encodingType == "quoted-printable" ) { - input = (*lineIt).value().toString().utf8(); - input.resize( input.size() - 1 ); // strip \0 - KCodecs::quotedPrintableEncode( input, output, false ); + QString value( output ); + addEscapes( value ); + textLine.append( ":" + value ); + } else { + QString value( (*lineIt).value().asString() ); + addEscapes( value ); + textLine.append( ":" + value ); } - QString value( output ); - addEscapes( value ); - textLine.append( ":" + value ); - } else { + if ( textLine.length() > FOLD_WIDTH ) { // we have to fold the line + for ( uint i = 0; i <= ( textLine.length() / FOLD_WIDTH ); ++i ) + text.append( ( i == 0 ? "" : " " ) + textLine.mid( i * FOLD_WIDTH, FOLD_WIDTH ) + "\r\n" ); + } else + text.append( textLine + "\r\n" ); + } + else { + // URIs can be full of weird symbols, etc. so bypass all checks + textLine = (*lineIt).identifier(); QString value( (*lineIt).value().asString() ); addEscapes( value ); textLine.append( ":" + value ); - } - - if ( textLine.length() > FOLD_WIDTH ) { // we have to fold the line - for ( uint i = 0; i <= ( textLine.length() / FOLD_WIDTH ); ++i ) - text.append( ( i == 0 ? "" : " " ) + textLine.mid( i * FOLD_WIDTH, FOLD_WIDTH ) + "\r\n" ); - } else text.append( textLine + "\r\n" ); + } } } } -- cgit v1.2.1