Commit dbbd5a1a authored by Laurent Montel's avatar Laurent Montel 😁

Fix key vcard4 support

parent 31fef833
......@@ -103,12 +103,46 @@ void KeyTest::serializeTest()
void KeyTest::shouldExportVCard3()
{
//TODO
KContacts::AddresseeList lst;
KContacts::Addressee addr;
addr.setEmails(QStringList() << QStringLiteral("foo@kde.org"));
addr.setUid(QStringLiteral("testuid"));
KContacts::Key key1(QStringLiteral("https://foo.org/sherlock-holmes.pub.asc"), KContacts::Key::PGP);
addr.setKeys(KContacts::Key::List{key1});
lst << addr;
KContacts::VCardTool vcard;
const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v3_0);
QByteArray expected("BEGIN:VCARD\r\n"
"VERSION:3.0\r\n"
"EMAIL:foo@kde.org\r\n"
"KEY;TYPE=PGP:https://foo.org/sherlock-holmes.pub.asc\r\n"
"N:;;;;\r\n"
"UID:testuid\r\n"
"END:VCARD\r\n\r\n");
QCOMPARE(ba, expected);
}
void KeyTest::shouldExportVCard4()
{
//TODO
KContacts::AddresseeList lst;
KContacts::Addressee addr;
addr.setEmails(QStringList() << QStringLiteral("foo@kde.org"));
addr.setUid(QStringLiteral("testuid"));
KContacts::Key key1(QStringLiteral("https://foo.org/sherlock-holmes.pub.asc"), KContacts::Key::PGP);
addr.setKeys(KContacts::Key::List{key1});
lst << addr;
KContacts::VCardTool vcard;
const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0);
QByteArray expected("BEGIN:VCARD\r\n"
"VERSION:4.0\r\n"
"EMAIL:foo@kde.org\r\n"
"KEY;MEDIATYPE=application/pgp-keys:https://foo.org/sherlock-holmes.pub.asc\r\n"
"N:;;;;\r\n"
"UID:testuid\r\n"
"END:VCARD\r\n\r\n");
QCOMPARE(ba, expected);
}
void KeyTest::shouldParseVcard3()
......
......@@ -1387,12 +1387,22 @@ VCardLine VCardTool::createKey(const Key &key, VCard::Version version) const
line.setValue(key.textData());
}
if (key.type() == Key::X509) {
line.addParameter(QStringLiteral("type"), QStringLiteral("X509"));
} else if (key.type() == Key::PGP) {
line.addParameter(QStringLiteral("type"), QStringLiteral("PGP"));
} else if (key.type() == Key::Custom) {
line.addParameter(QStringLiteral("type"), key.customTypeString());
if (version == VCard::v4_0) {
if (key.type() == Key::X509) {
line.addParameter(QStringLiteral("MEDIATYPE"), QStringLiteral("X509"));
} else if (key.type() == Key::PGP) {
line.addParameter(QStringLiteral("MEDIATYPE"), QStringLiteral("application/pgp-keys"));
} else if (key.type() == Key::Custom) {
line.addParameter(QStringLiteral("MEDIATYPE"), key.customTypeString());
}
} else {
if (key.type() == Key::X509) {
line.addParameter(QStringLiteral("type"), QStringLiteral("X509"));
} else if (key.type() == Key::PGP) {
line.addParameter(QStringLiteral("type"), QStringLiteral("PGP"));
} else if (key.type() == Key::Custom) {
line.addParameter(QStringLiteral("type"), key.customTypeString());
}
}
return line;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment