Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit dff6d18b authored by Volker Krause's avatar Volker Krause

Fix vcard attachment rendering

This also updates rendertest to the what's in messagelib nowadays so we
get the improved normalization of random or system-dependent content.
parent 1b7fd0e1
From: Volker Krause <vkrause@kde.org>
To: vkrause@kde.org
Subject: vcard test attachment
Date: Thu, 21 Sep 2017 20:00:14 +0200
Message-ID: <4938516.GQA1Me2Nvk@vkpc5>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="nextPart4098239.4lZYQBrKDX"
Content-Transfer-Encoding: 7Bit
This is a multi-part message in MIME format.
--nextPart4098239.4lZYQBrKDX
Content-Transfer-Encoding: 7Bit
Content-Type: text/plain; charset="us-ascii"
body text
--nextPart4098239.4lZYQBrKDX
Content-Disposition: attachment; filename="Dr Konqui.vcf"
Content-Transfer-Encoding: 7Bit
Content-Type: text/x-vcard; charset="utf-8"; name="Dr Konqui.vcf"
BEGIN:VCARD
VERSION:3.0
CATEGORIES:KDE
EMAIL;TYPE=WORK:my-test-email@kde.org
FN:Dr Konqui
N:Konqui;Dr;;;
REV:2017-08-01T20:59:16Z
UID:152c6e04-2f94-4951-9204-c97b69024ff0
END:VCARD
--nextPart4098239.4lZYQBrKDX--
<?xml version="1.0" encoding="UTF8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<div style="position: relative; word-wrap: break-word">
<a name="att"/>
<div id="attachmentDiv">
<a name="att1"/>
<div id="attachmentDiv1">
<div class="noquote">
<div dir="ltr">body text</div>
</div>
</div>
<div align="center">
<h2>Attached business card</h2>
</div>
<div align="center">
<table cellpadding="3" cellspacing="1">
<tr>
<td align="right" valign="top" width="30%" rowspan="3">
<img src="file:user-identity.png" width="100" vspace="1"/>
</td>
<td colspan="2" align="left" width="70%">
<font size="+2">
<b>Dr Konqui</b>
</font>
</td>
</tr>
<tr>
<td colspan="2" align="left" width="70%"/>
</tr>
<tr>
<td colspan="2" align="left" width="70%"/>
</tr>
<tr valign="top">
<td align="right" valign="top" width="30%">
<b>
<font color="grey">Email</font>
</b>
</td>
<td colspan="2" align="left" valign="top" width="70%">
<font>
<a href="mailto:Dr%20Konqui%20%3Cmy-test-email%40kde.org%3E">my-test-email@kde.org</a>
</font>
</td>
</tr>
</table>
</div>
<div align="center">
<a href="x-kmail:/bodypart/0/2/addToAddressBook%3A0">[Add this contact to the address book]</a>
</div>
<br/>
<br/>
</div>
</div>
</body>
</html>
......@@ -10,8 +10,7 @@
<td dir="ltr">
<table cellspacing="0" cellpadding="0" width="100%">
<tr>
<td>Not enough information to check signature validity.
</td>
<td>Not enough information to check signature validity.</td>
<td align="right">
<a href="kmail:showSignatureDetails">Show Details</a>
</td>
......@@ -29,28 +28,23 @@
<div dir="ltr">test</div>
</div>
</div>
<style type="text/css">
table.key {
width: 100%;
border: 1px solid #000000;
<style type="text/css">table.key {
width: 100%;
border: 1px solid #000000;
}
table .keyH {
background-color: #000000;
color: #ffffff;
background-color: #000000;
color: #ffffff;
}
table .keyB {
}
</style>
}</style>
<table cellspacing="0" cellpadding="2" class="key">
<tr class="keyH">
<td>OpenPGP Key</td>
</tr>
<tr class="keyb">
<td>
<div style="padding: 10pt;"><p>This is an OpenPGP key, which can be used to sign or encrypt emails.
</p><a href="kmail:showSignatureDetails">Show key details ...</a>
| <a href="x-kmail:/bodypart/0/1.2/pgpkey?action=import">Import key</a>
</div>
<div style="padding: 10pt;"><p>This is an OpenPGP key, which can be used to sign or encrypt emails.</p><a href="kmail:showSignatureDetails">Show key details ...</a>| <a href="x-kmail:/bodypart/0/1.2/pgpkey?action=import">Import key</a></div>
</td>
</tr>
<tr class="keyH">
......
......@@ -97,7 +97,30 @@ void RenderTest::testRender()
fileWriter.write(QStringLiteral("</body></html>"));
fileWriter.end();
QVERIFY(QFile::exists(outFileName));
compareFile(outFileName, referenceFileName);
}
void RenderTest::compareFile(const QString &outFile, const QString &referenceFile)
{
QVERIFY(QFile::exists(outFile));
const QString htmlFile = outFile + QStringLiteral(".html");
// remove tailing newlines and spaces and make htmlmore uniform (breaks pre tags)
{
QFile f(outFile);
QVERIFY(f.open(QIODevice::ReadOnly));
QString content = QString::fromUtf8(f.readAll());
f.close();
content.replace(QRegExp(QStringLiteral("[\t ]+")), QStringLiteral(" "));
content.replace(QRegExp(QStringLiteral("[\t ]*\n+[\t ]*")), QStringLiteral("\n"));
content.replace(QRegExp(QStringLiteral("([\n\t ])\\1+")), QStringLiteral("\\1"));
content.replace(QRegExp(QStringLiteral(">\n+[\t ]*")), QStringLiteral(">"));
content.replace(QRegExp(QStringLiteral("[\t ]*\n+[\t ]*<")), QStringLiteral("<"));
content.replace(QLatin1String("&nbsp;"), QLatin1String("NBSP_ENTITY_PLACEHOLDER")); // xmlling chokes on &nbsp;
QVERIFY(f.open(QIODevice::WriteOnly | QIODevice::Truncate));
f.write(content.toUtf8());
f.close();
}
// validate xml and pretty-print for comparisson
// TODO add proper cmake check for xmllint and diff
......@@ -106,17 +129,21 @@ void RenderTest::testRender()
<< QStringLiteral("--encode")
<< QStringLiteral("UTF8")
<< QStringLiteral("--output")
<< htmlFileName
<< outFileName;
QCOMPARE(QProcess::execute(QLatin1String("xmllint"), args), 0);
<< htmlFile
<< outFile;
QCOMPARE(QProcess::execute(QStringLiteral("xmllint"), args), 0);
// get rid of system dependent or random paths
{
QFile f(htmlFileName);
QFile f(htmlFile);
QVERIFY(f.open(QIODevice::ReadOnly));
QString content = QString::fromUtf8(f.readAll());
f.close();
content.replace(QRegExp(QLatin1String("\"file:[^\"]*[/(?:%2F)]([^\"/(?:%2F)]*)\"")), QStringLiteral("\"file:\\1\""));
content.replace(QRegExp(QStringLiteral(
"\"file:[^\"]*[/(?:%2F)]([^\"/(?:%2F)]*)\"")),
QStringLiteral("\"file:\\1\""));
content.replace(QLatin1String("NBSP_ENTITY_PLACEHOLDER"), QLatin1String("&nbsp;")); // undo above transformation for xmllint
content.replace(QRegExp(QStringLiteral("/bodypart/\\d+/")), QStringLiteral("/bodypart/0/"));
QVERIFY(f.open(QIODevice::WriteOnly | QIODevice::Truncate));
f.write(content.toUtf8());
f.close();
......@@ -125,8 +152,8 @@ void RenderTest::testRender()
// compare to reference file
args = QStringList()
<< QStringLiteral("-u")
<< referenceFileName
<< htmlFileName;
<< referenceFile
<< htmlFile;
QProcess proc;
proc.setProcessChannelMode(QProcess::ForwardedChannels);
proc.start(QStringLiteral("diff"), args);
......
......@@ -29,6 +29,10 @@ class RenderTest : public QObject
private Q_SLOTS:
void testRender_data();
void testRender();
private:
void compareFile(const QString &outFile, const QString &referenceFile);
};
#endif
......@@ -100,7 +100,7 @@ public:
}
}
}
if (!count) {
if (!count && !memento) {
return AsIcon;
}
......@@ -155,7 +155,7 @@ public:
+bodyPart->makeLink(op)
+QStringLiteral("\">")
+addToLinkText
+QStringLiteral("</a></div><br><br>"));
+QStringLiteral("</a></div><br/><br/>"));
} else {
if (memento->address(count) != a) {
const QString addToLinkText = i18n("[Update this contact to the address book]");
......
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