|
|
@ -227,54 +227,64 @@ QString VCardParser::createVCards( const VCard::List& list )
|
|
|
|
// iterate over the lines
|
|
|
|
// iterate over the lines
|
|
|
|
for ( lineIt = lines.constBegin(); lineIt != lines.constEnd(); ++lineIt ) {
|
|
|
|
for ( lineIt = lines.constBegin(); lineIt != lines.constEnd(); ++lineIt ) {
|
|
|
|
if ( !(*lineIt).value().asString().isEmpty() ) {
|
|
|
|
if ( !(*lineIt).value().asString().isEmpty() ) {
|
|
|
|
if ( (*lineIt).hasGroup() )
|
|
|
|
if ((*lineIt).identifier() != QString("URI")) {
|
|
|
|
textLine = (*lineIt).group() + "." + (*lineIt).identifier();
|
|
|
|
if ( (*lineIt).hasGroup() )
|
|
|
|
else
|
|
|
|
textLine = (*lineIt).group() + "." + (*lineIt).identifier();
|
|
|
|
textLine = (*lineIt).identifier();
|
|
|
|
else
|
|
|
|
|
|
|
|
textLine = (*lineIt).identifier();
|
|
|
|
params = (*lineIt).parameterList();
|
|
|
|
|
|
|
|
hasEncoding = false;
|
|
|
|
params = (*lineIt).parameterList();
|
|
|
|
if ( params.count() > 0 ) { // we have parameters
|
|
|
|
hasEncoding = false;
|
|
|
|
for ( paramIt = params.begin(); paramIt != params.end(); ++paramIt ) {
|
|
|
|
if ( params.count() > 0 ) { // we have parameters
|
|
|
|
if ( (*paramIt) == "encoding" ) {
|
|
|
|
for ( paramIt = params.begin(); paramIt != params.end(); ++paramIt ) {
|
|
|
|
hasEncoding = true;
|
|
|
|
if ( (*paramIt) == "encoding" ) {
|
|
|
|
encodingType = (*lineIt).parameter( "encoding" ).lower();
|
|
|
|
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 );
|
|
|
|
if ( hasEncoding ) { // have to encode the data
|
|
|
|
for ( valueIt = values.constBegin(); valueIt != values.constEnd(); ++valueIt ) {
|
|
|
|
QByteArray input, output;
|
|
|
|
textLine.append( ";" + (*paramIt).upper() );
|
|
|
|
if ( encodingType == "b" ) {
|
|
|
|
if ( !(*valueIt).isEmpty() )
|
|
|
|
input = (*lineIt).value().toByteArray();
|
|
|
|
textLine.append( "=" + (*valueIt) );
|
|
|
|
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
|
|
|
|
QString value( output );
|
|
|
|
QByteArray input, output;
|
|
|
|
addEscapes( value );
|
|
|
|
if ( encodingType == "b" ) {
|
|
|
|
textLine.append( ":" + value );
|
|
|
|
input = (*lineIt).value().toByteArray();
|
|
|
|
} else {
|
|
|
|
KCodecs::base64Encode( input, output );
|
|
|
|
QString value( (*lineIt).value().asString() );
|
|
|
|
} else if ( encodingType == "quoted-printable" ) {
|
|
|
|
addEscapes( value );
|
|
|
|
input = (*lineIt).value().toString().utf8();
|
|
|
|
textLine.append( ":" + value );
|
|
|
|
input.resize( input.size() - 1 ); // strip \0
|
|
|
|
|
|
|
|
KCodecs::quotedPrintableEncode( input, output, false );
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString value( output );
|
|
|
|
if ( textLine.length() > FOLD_WIDTH ) { // we have to fold the line
|
|
|
|
addEscapes( value );
|
|
|
|
for ( uint i = 0; i <= ( textLine.length() / FOLD_WIDTH ); ++i )
|
|
|
|
textLine.append( ":" + value );
|
|
|
|
text.append( ( i == 0 ? "" : " " ) + textLine.mid( i * FOLD_WIDTH, FOLD_WIDTH ) + "\r\n" );
|
|
|
|
} else {
|
|
|
|
} 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() );
|
|
|
|
QString value( (*lineIt).value().asString() );
|
|
|
|
addEscapes( value );
|
|
|
|
addEscapes( value );
|
|
|
|
textLine.append( ":" + 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" );
|
|
|
|
text.append( textLine + "\r\n" );
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|