diff --git a/messageviewer/src/header/autotests/data/bcctest.tmpl b/messageviewer/src/header/autotests/data/bcctest.tmpl --- a/messageviewer/src/header/autotests/data/bcctest.tmpl +++ b/messageviewer/src/header/autotests/data/bcctest.tmpl @@ -1,7 +1,7 @@ -
nameOnly: {{ header.bccNameOnly|safe }}
+
nameOnly: {{ header.bcc.nameOnly|safe }}
isSet: {{ header.bcc.isSet|safe }}
-
fullAddress: {{ header.bcc|safe }}
-
str: {{ header.bccStr }}
-
expandable: {{ header.bccExpandableCc|safe }}
-
expandableTO: {{ header.bcc.expandableCC|safe }}
+
fullAddress: {{ header.bcc.fullAddress|safe }}
+
str: {{ header.bcc.str }}
+
expandable: {{ header.bcc.expandableBc|safe }}
+
expandableTO: {{ header.bcc.expandableBCC|safe }}
invalid: {{ header.bcc.invalid|safe }}
diff --git a/messageviewer/src/header/autotests/data/bcctest.tmpl.html b/messageviewer/src/header/autotests/data/bcctest.tmpl.html --- a/messageviewer/src/header/autotests/data/bcctest.tmpl.html +++ b/messageviewer/src/header/autotests/data/bcctest.tmpl.html @@ -5,11 +5,11 @@
nameOnly: blind copy recipient1, blind copy recipient2, blind copy recipient3, blind copy recipient4, blind copy recipient5, blind copy recipient6
-
isSet:
+
isSet: true
fullAddress: blind copy recipient1 <bccspam1@example.org>, blind copy recipient2 <bccspam2@example.org>, blind copy recipient3 <bccspam3@example.org>, blind copy recipient4 <bccspam4@example.org>, blind copy recipient5 <bccspam5@example.org>, blind copy recipient6 <bccspam6@example.org>
str: blind copy recipient1 <bccspam1@example.org>, blind copy recipient2 <bccspam2@example.org>, blind copy recipient3 <bccspam3@example.org>, blind copy recipient4 <bccspam4@example.org>, blind copy recipient5 <bccspam5@example.org>, blind copy recipient6 <bccspam6@example.org>
-
expandable:
-
expandableTO:
+
expandable: blind copy recipient1 <bccspam1@example.org>, blind copy recipient2 <bccspam2@example.org>, blind copy recipient3 <bccspam3@example.org>, blind copy recipient4 <bccspam4@example.org>blind copy recipient1 <bccspam1@example.org>, blind copy recipient2 <bccspam2@example.org>, blind copy recipient3 <bccspam3@example.org>, blind copy recipient4 <bccspam4@example.org>, blind copy recipient5 <bccspam5@example.org>, blind copy recipient6 <bccspam6@example.org>
+
expandableTO: blind copy recipient1 <bccspam1@example.org>, blind copy recipient2 <bccspam2@example.org>, blind copy recipient3 <bccspam3@example.org>, blind copy recipient4 <bccspam4@example.org>blind copy recipient1 <bccspam1@example.org>, blind copy recipient2 <bccspam2@example.org>, blind copy recipient3 <bccspam3@example.org>, blind copy recipient4 <bccspam4@example.org>, blind copy recipient5 <bccspam5@example.org>, blind copy recipient6 <bccspam6@example.org>
invalid:
diff --git a/messageviewer/src/header/autotests/data/cctest.tmpl b/messageviewer/src/header/autotests/data/cctest.tmpl --- a/messageviewer/src/header/autotests/data/cctest.tmpl +++ b/messageviewer/src/header/autotests/data/cctest.tmpl @@ -1,7 +1,7 @@ -
nameOnly: {{ header.ccNameOnly|safe }}
+
nameOnly: {{ header.cc.nameOnly|safe }}
isSet: {{ header.cc.isSet|safe }}
-
fullAddress: {{ header.cc|safe }}
-
str: {{ header.ccStr }}
-
expandable: {{ header.ccExpandable|safe }}
-
expandableTO: {{ header.cc.expandableTO|safe }}
+
fullAddress: {{ header.cc.fullAddress|safe }}
+
str: {{ header.cc.str }}
+
expandable: {{ header.cc.expandableCc|safe }}
+
expandableTO: {{ header.cc.expandableCC|safe }}
invalid: {{ header.cc.invalid|safe }}
diff --git a/messageviewer/src/header/autotests/data/cctest.tmpl.html b/messageviewer/src/header/autotests/data/cctest.tmpl.html --- a/messageviewer/src/header/autotests/data/cctest.tmpl.html +++ b/messageviewer/src/header/autotests/data/cctest.tmpl.html @@ -5,11 +5,11 @@
nameOnly: copy recipient1, copy recipient2, copy recipient3, copy recipient4, copy recipient5, copy recipient6
-
isSet:
+
isSet: true
fullAddress: copy recipient1 <ccspam1@example.org>, copy recipient2 <ccspam2@example.org>, copy recipient3 <ccspam3@example.org>, copy recipient4 <ccspam4@example.org>, copy recipient5 <ccspam5@example.org>, copy recipient6 <ccspam6@example.org>
str: copy recipient1 <ccspam1@example.org>, copy recipient2 <ccspam2@example.org>, copy recipient3 <ccspam3@example.org>, copy recipient4 <ccspam4@example.org>, copy recipient5 <ccspam5@example.org>, copy recipient6 <ccspam6@example.org>
expandable: copy recipient1 <ccspam1@example.org>, copy recipient2 <ccspam2@example.org>, copy recipient3 <ccspam3@example.org>, copy recipient4 <ccspam4@example.org>copy recipient1 <ccspam1@example.org>, copy recipient2 <ccspam2@example.org>, copy recipient3 <ccspam3@example.org>, copy recipient4 <ccspam4@example.org>, copy recipient5 <ccspam5@example.org>, copy recipient6 <ccspam6@example.org>
-
expandableTO:
+
expandableTO: copy recipient1 <ccspam1@example.org>, copy recipient2 <ccspam2@example.org>, copy recipient3 <ccspam3@example.org>, copy recipient4 <ccspam4@example.org>copy recipient1 <ccspam1@example.org>, copy recipient2 <ccspam2@example.org>, copy recipient3 <ccspam3@example.org>, copy recipient4 <ccspam4@example.org>, copy recipient5 <ccspam5@example.org>, copy recipient6 <ccspam6@example.org>
invalid:
diff --git a/messageviewer/src/header/autotests/data/datetest.tmpl b/messageviewer/src/header/autotests/data/datetest.tmpl --- a/messageviewer/src/header/autotests/data/datetest.tmpl +++ b/messageviewer/src/header/autotests/data/datetest.tmpl @@ -1,7 +1,7 @@ -str: {{ header.date|safe }} -short: {{ header.dateshort|safe }} -long: {{ header.datelong|safe }} -fancylong: {{ header.datefancylong|safe }} -fancyshort: {{ header.datefancyshort|safe }} -localelong: {{ header.datelocalelong|safe }} +str: {{ header.date.str|safe }} +short: {{ header.date.short|safe }} +long: {{ header.date.long|safe }} +fancylong: {{ header.date.fancylong|safe }} +fancyshort: {{ header.date.fancyshort|safe }} +localelong: {{ header.date.localelong|safe }} invalid: {{ header.date.invalid|safe }} diff --git a/messageviewer/src/header/autotests/data/fromtest.tmpl b/messageviewer/src/header/autotests/data/fromtest.tmpl --- a/messageviewer/src/header/autotests/data/fromtest.tmpl +++ b/messageviewer/src/header/autotests/data/fromtest.tmpl @@ -1,7 +1,7 @@ -
nameOnly: {{ header.fromNameOnly|safe }}
+
nameOnly: {{ header.from.nameOnly|safe }}
isSet: {{ header.from.isSet|safe }}
-
fullAddress: {{ header.from|safe }}
-
str: {{ header.fromStr }}
-
expandable: {{ header.fromExpandable|safe }}
+
fullAddress: {{ header.from.fullAddress|safe }}
+
str: {{ header.from.str }}
+
expandable: {{ header.from.expandableFrom|safe }}
expandableTO: {{ header.fromexpandableTO|safe }}
invalid: {{ header.from.invalid|safe }}
diff --git a/messageviewer/src/header/autotests/data/fromtest.tmpl.html b/messageviewer/src/header/autotests/data/fromtest.tmpl.html --- a/messageviewer/src/header/autotests/data/fromtest.tmpl.html +++ b/messageviewer/src/header/autotests/data/fromtest.tmpl.html @@ -4,11 +4,11 @@
-
nameOnly:
-
isSet:
+
nameOnly: admin, from2, from3, from4, from5, from6
+
isSet: true
fullAddress: admin <admin@ssrr.link>, from2 <from2@example.org>, from3 <from3@example.org>, from4 <from4@example.org>, from5 <from5@example.org>, from6 <from6@example.org>
str: admin <admin@ssrr.link>, from2 <from2@example.org>, from3 <from3@example.org>, from4 <from4@example.org>, from5 <from5@example.org>, from6 <from6@example.org>
-
expandable:
+
expandable: admin <admin@ssrr.link>, from2 <from2@example.org>, from3 <from3@example.org>, from4 <from4@example.org>admin <admin@ssrr.link>, from2 <from2@example.org>, from3 <from3@example.org>, from4 <from4@example.org>, from5 <from5@example.org>, from6 <from6@example.org>
expandableTO:
invalid:
diff --git a/messageviewer/src/header/autotests/data/replyTotest.tmpl b/messageviewer/src/header/autotests/data/replyTotest.tmpl --- a/messageviewer/src/header/autotests/data/replyTotest.tmpl +++ b/messageviewer/src/header/autotests/data/replyTotest.tmpl @@ -1,7 +1,7 @@ -
nameOnly: {{ header.replyToNameOnly|safe }}
+
nameOnly: {{ header.replyTo.nameOnly|safe }}
isSet: {{ header.replyTo.isSet|safe }}
-
fullAddress: {{ header.replyTo|safe }}
-
str: {{ header.replyToStr }}
-
expandable: {{ header.replyToExpandable|safe }}
-
expandableTO: {{ header.replyToexpandableTO|safe }}
+
fullAddress: {{ header.replyTo.fullAddress|safe }}
+
str: {{ header.replyTo.str }}
+
expandable: {{ header.replyTo.expandable|safe }}
+
expandableTO: {{ header.replyTo.expandableTO|safe }}
invalid: {{ header.replyTo.invalid|safe }}
diff --git a/messageviewer/src/header/autotests/data/replyTotest.tmpl.html b/messageviewer/src/header/autotests/data/replyTotest.tmpl.html --- a/messageviewer/src/header/autotests/data/replyTotest.tmpl.html +++ b/messageviewer/src/header/autotests/data/replyTotest.tmpl.html @@ -5,11 +5,11 @@
nameOnly: me, me3, me3, me4, me5, me6
-
isSet:
+
isSet: true
fullAddress: me <reply-to@example.org>, me3 <reply-to3@example.org>, me3 <reply-to3@example.org>, me4 <reply-to4@example.org>, me5 <reply-to5@example.org>, me6 <reply-to6@example.org>
str: me <reply-to@example.org>, me3 <reply-to3@example.org>, me3 <reply-to3@example.org>, me4 <reply-to4@example.org>, me5 <reply-to5@example.org>, me6 <reply-to6@example.org>
-
expandable:
-
expandableTO:
+
expandable: me <reply-to@example.org>, me3 <reply-to3@example.org>, me3 <reply-to3@example.org>, me4 <reply-to4@example.org>me <reply-to@example.org>, me3 <reply-to3@example.org>, me3 <reply-to3@example.org>, me4 <reply-to4@example.org>, me5 <reply-to5@example.org>, me6 <reply-to6@example.org>
+
expandableTO: me <reply-to@example.org>, me3 <reply-to3@example.org>, me3 <reply-to3@example.org>, me4 <reply-to4@example.org>me <reply-to@example.org>, me3 <reply-to3@example.org>, me3 <reply-to3@example.org>, me4 <reply-to4@example.org>, me5 <reply-to5@example.org>, me6 <reply-to6@example.org>
invalid:
diff --git a/messageviewer/src/header/autotests/data/resentfromtest.tmpl b/messageviewer/src/header/autotests/data/resentfromtest.tmpl --- a/messageviewer/src/header/autotests/data/resentfromtest.tmpl +++ b/messageviewer/src/header/autotests/data/resentfromtest.tmpl @@ -1,7 +1,7 @@ -
nameOnly: {{ header.resentfromNameOnly|safe }}
+
nameOnly: {{ header.resentfrom.nameOnly|safe }}
isSet: {{ header.resentfrom.isSet|safe }}
-
fullAddress: {{ header.resentfrom|safe }}
-
str: {{ header.resentfromStr }}
-
expandable: {{ header.resentfromExpandable|safe }}
-
expandableTO: {{ header.resentfromexpandableTO|safe }}
+
fullAddress: {{ header.resentfrom.fullAddress|safe }}
+
str: {{ header.resentfrom.str }}
+
expandable: {{ header.resentfrom.expandableResentFrom|safe }}
+
expandableTO: {{ header.resentfrom.expandableTO|safe }}
invalid: {{ header.resentfrom.invalid|safe }}
diff --git a/messageviewer/src/header/autotests/data/resentfromtest.tmpl.html b/messageviewer/src/header/autotests/data/resentfromtest.tmpl.html --- a/messageviewer/src/header/autotests/data/resentfromtest.tmpl.html +++ b/messageviewer/src/header/autotests/data/resentfromtest.tmpl.html @@ -4,12 +4,12 @@
-
nameOnly:
-
isSet:
+
nameOnly: resent-from@example.org, resent-from2@example.org, resent-from3@example.org, resent-from4@example.org, resent-to5@example.org, resent-to6@example.org
+
isSet: true
fullAddress: resent-from@example.org, resent-from2@example.org, resent-from3@example.org, resent-from4@example.org, resent-to5@example.org, resent-to6@example.org
-
str:
-
expandable:
-
expandableTO:
+
str: resent-from@example.org, resent-from2@example.org, resent-from3@example.org, resent-from4@example.org, resent-to5@example.org, resent-to6@example.org
+
expandable: resent-from@example.org, resent-from2@example.org, resent-from3@example.org, resent-from4@example.orgresent-from@example.org, resent-from2@example.org, resent-from3@example.org, resent-from4@example.org, resent-to5@example.org, resent-to6@example.org
+
expandableTO: resent-from@example.org, resent-from2@example.org, resent-from3@example.org, resent-from4@example.orgresent-from@example.org, resent-from2@example.org, resent-from3@example.org, resent-from4@example.org, resent-to5@example.org, resent-to6@example.org
invalid:
diff --git a/messageviewer/src/header/autotests/data/resenttotest.tmpl b/messageviewer/src/header/autotests/data/resenttotest.tmpl --- a/messageviewer/src/header/autotests/data/resenttotest.tmpl +++ b/messageviewer/src/header/autotests/data/resenttotest.tmpl @@ -1,7 +1,7 @@ -
nameOnly: {{ header.resenttoNameOnly|safe }}
+
nameOnly: {{ header.resentto.nameOnly|safe }}
isSet: {{ header.resentto.isSet|safe }}
-
fullAddress: {{ header.resentto|safe }}
-
str: {{ header.resenttoStr }}
-
expandable: {{ header.resenttoExpandable|safe }}
-
expandableTO: {{ header.resenttoexpandableTO|safe }}
+
fullAddress: {{ header.resentto.fullAddress|safe }}
+
str: {{ header.resentto.str }}
+
expandable: {{ header.resentto.expandableResentto|safe }}
+
expandableTO: {{ header.resentto.expandableTO|safe }}
invalid: {{ header.resentto.invalid|safe }}
diff --git a/messageviewer/src/header/autotests/data/resenttotest.tmpl.html b/messageviewer/src/header/autotests/data/resenttotest.tmpl.html --- a/messageviewer/src/header/autotests/data/resenttotest.tmpl.html +++ b/messageviewer/src/header/autotests/data/resenttotest.tmpl.html @@ -4,12 +4,12 @@
-
nameOnly:
-
isSet:
+
nameOnly: resent-to@example.org, resent-to2@example.org, resent-to3@example.org, resent-to4@example.org, resent-to5@example.org, resent-to6@example.org
+
isSet: true
fullAddress: resent-to@example.org, resent-to2@example.org, resent-to3@example.org, resent-to4@example.org, resent-to5@example.org, resent-to6@example.org
-
str:
-
expandable:
-
expandableTO:
+
str: resent-to@example.org, resent-to2@example.org, resent-to3@example.org, resent-to4@example.org, resent-to5@example.org, resent-to6@example.org
+
expandable: resent-to@example.org, resent-to2@example.org, resent-to3@example.org, resent-to4@example.orgresent-to@example.org, resent-to2@example.org, resent-to3@example.org, resent-to4@example.org, resent-to5@example.org, resent-to6@example.org
+
expandableTO: resent-to@example.org, resent-to2@example.org, resent-to3@example.org, resent-to4@example.orgresent-to@example.org, resent-to2@example.org, resent-to3@example.org, resent-to4@example.org, resent-to5@example.org, resent-to6@example.org
invalid:
diff --git a/messageviewer/src/header/autotests/data/totest.tmpl b/messageviewer/src/header/autotests/data/totest.tmpl --- a/messageviewer/src/header/autotests/data/totest.tmpl +++ b/messageviewer/src/header/autotests/data/totest.tmpl @@ -1,7 +1,7 @@ -
nameOnly: {{ header.toNameOnly|safe }}
+
nameOnly: {{ header.to.nameOnly|safe }}
isSet: {{ header.to.isSet|safe }}
-
fullAddress: {{ header.to|safe }}
-
str: {{ header.toStr}}
-
expandable: {{ header.toExpandable|safe }}
+
fullAddress: {{ header.to.fullAddress|safe }}
+
str: {{ header.to.str}}
+
expandable: {{ header.to.expandableTo|safe }}
expandableTO: {{ header.to.expandableTO|safe }}
invalid: {{ header.to.invalid|safe }}
diff --git a/messageviewer/src/header/autotests/data/totest.tmpl.html b/messageviewer/src/header/autotests/data/totest.tmpl.html --- a/messageviewer/src/header/autotests/data/totest.tmpl.html +++ b/messageviewer/src/header/autotests/data/totest.tmpl.html @@ -5,11 +5,11 @@
nameOnly: direct recipient1, direct recipient2, direct recipient3, direct recipient4, direct recipient5, direct recipient6
-
isSet:
+
isSet: true
fullAddress: direct recipient1 <tospam1@example.org>, direct recipient2 <tospam2@example.org>, direct recipient3 <tospam3@example.org>, direct recipient4 <tospam4@example.org>, direct recipient5 <tospam5@example.org>, direct recipient6 <tospam6@example.org>
str: direct recipient1 <tospam1@example.org>, direct recipient2 <tospam2@example.org>, direct recipient3 <tospam3@example.org>, direct recipient4 <tospam4@example.org>, direct recipient5 <tospam5@example.org>, direct recipient6 <tospam6@example.org>
expandable: direct recipient1 <tospam1@example.org>, direct recipient2 <tospam2@example.org>, direct recipient3 <tospam3@example.org>, direct recipient4 <tospam4@example.org>direct recipient1 <tospam1@example.org>, direct recipient2 <tospam2@example.org>, direct recipient3 <tospam3@example.org>, direct recipient4 <tospam4@example.org>, direct recipient5 <tospam5@example.org>, direct recipient6 <tospam6@example.org>
-
expandableTO:
+
expandableTO: direct recipient1 <tospam1@example.org>, direct recipient2 <tospam2@example.org>, direct recipient3 <tospam3@example.org>, direct recipient4 <tospam4@example.org>direct recipient1 <tospam1@example.org>, direct recipient2 <tospam2@example.org>, direct recipient3 <tospam3@example.org>, direct recipient4 <tospam4@example.org>, direct recipient5 <tospam5@example.org>, direct recipient6 <tospam6@example.org>
invalid:
diff --git a/messageviewer/src/header/grantleeheaderformatter.cpp b/messageviewer/src/header/grantleeheaderformatter.cpp --- a/messageviewer/src/header/grantleeheaderformatter.cpp +++ b/messageviewer/src/header/grantleeheaderformatter.cpp @@ -33,18 +33,127 @@ #include #include -#include #include +#include +#include using namespace MessageCore; using namespace MessageViewer; +Q_DECLARE_METATYPE(const KMime::Headers::Generics::AddressList *) +Q_DECLARE_METATYPE(const KMime::Headers::Generics::MailboxList *) +Q_DECLARE_METATYPE(QSharedPointer) +Q_DECLARE_METATYPE(const KMime::Headers::Date *) + +// Read-only introspection of KMime::Headers::Generics::AddressList object. +namespace Grantlee { +template<> +inline QVariant TypeAccessor::lookUp(const KMime::Headers::Generics::AddressList *const object, const QString &property) +{ + if (property == QStringLiteral("nameOnly")) { + return StringUtil::emailAddrAsAnchor(object, StringUtil::DisplayNameOnly); + } else if (property == QStringLiteral("isSet")) { + return !object->asUnicodeString().isEmpty(); + } else if (property == QStringLiteral("fullAddress")) { + return StringUtil::emailAddrAsAnchor(object, StringUtil::DisplayFullAddress); + } else if (property == QStringLiteral("str")) { + return object->asUnicodeString(); + } else if (property.startsWith(QStringLiteral("expandable"))) { + const auto &name = property.mid(10); + const QString val = MessageCore::StringUtil::emailAddrAsAnchor( + object, MessageCore::StringUtil::DisplayFullAddress, + QString(), MessageCore::StringUtil::ShowLink, + MessageCore::StringUtil::ExpandableAddresses, + QStringLiteral("Full") + name + QStringLiteral("AddressList")); + return val; + } + return QVariant(); +} +} + +// Read-only introspection of KMime::Headers::Generics::MailboxList object. +namespace Grantlee { +template<> +inline QVariant TypeAccessor::lookUp(const KMime::Headers::Generics::MailboxList *const object, const QString &property) +{ + if (property == QStringLiteral("nameOnly")) { + return StringUtil::emailAddrAsAnchor(object, StringUtil::DisplayNameOnly); + } else if (property == QStringLiteral("isSet")) { + return !object->asUnicodeString().isEmpty(); + } else if (property == QStringLiteral("fullAddress")) { + return StringUtil::emailAddrAsAnchor(object, StringUtil::DisplayFullAddress); + } else if (property == QStringLiteral("str")) { + return object->asUnicodeString(); + } else if (property.startsWith(QStringLiteral("expandable"))) { + const auto &name = property.mid(10); + const QString val = MessageCore::StringUtil::emailAddrAsAnchor( + object, MessageCore::StringUtil::DisplayFullAddress, + QString(), MessageCore::StringUtil::ShowLink, + MessageCore::StringUtil::ExpandableAddresses, + QStringLiteral("Full") + name + QStringLiteral("AddressList")); + return val; + } + return QVariant(); +} +} + +GRANTLEE_BEGIN_LOOKUP(QSharedPointer) + if (property == QStringLiteral("nameOnly")) { + return StringUtil::emailAddrAsAnchor(object.data(), StringUtil::DisplayNameOnly); + } else if (property == QStringLiteral("isSet")) { + return !object->asUnicodeString().isEmpty(); + } else if (property == QStringLiteral("fullAddress")) { + return StringUtil::emailAddrAsAnchor(object.data(), StringUtil::DisplayFullAddress); + } else if (property == QStringLiteral("str")) { + return object->asUnicodeString(); + } else if (property.startsWith(QStringLiteral("expandable"))) { + const auto &name = property.mid(10); + const QString val = MessageCore::StringUtil::emailAddrAsAnchor( + object.data(), MessageCore::StringUtil::DisplayFullAddress, + QString(), MessageCore::StringUtil::ShowLink, + MessageCore::StringUtil::ExpandableAddresses, + QStringLiteral("Full") + name + QStringLiteral("AddressList")); + return val; + } +GRANTLEE_END_LOOKUP + + +namespace Grantlee { +template<> +inline QVariant TypeAccessor::lookUp(const KMime::Headers::Date *const object, const QString &property) +{ + MessageViewer::HeaderStyleUtil::HeaderStyleUtilDateFormat dateFormat; + if (property == QStringLiteral("str")) { + return HeaderStyleUtil::dateStr(object->dateTime()); + } else if (property == QStringLiteral("short")) { + dateFormat = MessageViewer::HeaderStyleUtil::ShortDate; + } else if (property == QStringLiteral("long")) { + dateFormat = MessageViewer::HeaderStyleUtil::CustomDate; + } else if (property == QStringLiteral("fancylong")) { + dateFormat = MessageViewer::HeaderStyleUtil::FancyLongDate; + } else if (property == QStringLiteral("fancyshort")) { + dateFormat = MessageViewer::HeaderStyleUtil::FancyShortDate; + } else if(property == QStringLiteral("localelong")){ + dateFormat = MessageViewer::HeaderStyleUtil::LongDate; + } else { + return QVariant(); + } + + return HeaderStyleUtil::strToHtml(HeaderStyleUtil::dateString(object, dateFormat)); +} +} + + class Q_DECL_HIDDEN MessageViewer::GrantleeHeaderFormatter::Private { public: Private() { + Grantlee::registerMetaType(); + Grantlee::registerMetaType(); + Grantlee::registerMetaType>(); + Grantlee::registerMetaType(); iconSize = KIconLoader::global()->currentSize(KIconLoader::Toolbar); engine = new Grantlee::Engine; templateLoader = QSharedPointer( @@ -133,72 +242,30 @@ if (message->to(false)) { headerObject.insert(QStringLiteral("toi18n"), i18n("To:")); - headerObject.insert(QStringLiteral("to"), - StringUtil::emailAddrAsAnchor(message->to(), - StringUtil::DisplayFullAddress)); - headerObject.insert(QStringLiteral("toNameOnly"), - StringUtil::emailAddrAsAnchor( - message->to(), StringUtil::DisplayNameOnly)); - headerObject.insert(QStringLiteral("toStr"), message->to()->asUnicodeString()); - const QString val = MessageCore::StringUtil::emailAddrAsAnchor( - message->to(), MessageCore::StringUtil::DisplayFullAddress, - QString(), MessageCore::StringUtil::ShowLink, - MessageCore::StringUtil::ExpandableAddresses, - QStringLiteral("FullToAddressList")); - headerObject.insert(QStringLiteral("toExpandable"), val); - headerObject.insert(QStringLiteral("toMailbox"), QVariant::fromValue(message->to())); + headerObject.insert(QStringLiteral("to"), QVariant::fromValue(static_cast(message->to()))); } if (message->replyTo(false)) { headerObject.insert(QStringLiteral("replyToi18n"), i18n("Reply to:")); - headerObject.insert(QStringLiteral("replyTo"), - StringUtil::emailAddrAsAnchor(message->replyTo(), - StringUtil::DisplayFullAddress)); - headerObject.insert(QStringLiteral("replyToStr"), message->replyTo()->asUnicodeString()); - headerObject.insert(QStringLiteral("replyToNameOnly"), - StringUtil::emailAddrAsAnchor(message->replyTo(), - StringUtil::DisplayNameOnly)); + headerObject.insert(QStringLiteral("replyTo"), QVariant::fromValue(static_cast(message->replyTo()))); } if (message->cc(false)) { headerObject.insert(QStringLiteral("cci18n"), i18n("CC:")); - headerObject.insert(QStringLiteral("cc"), - StringUtil::emailAddrAsAnchor(message->cc(), - StringUtil::DisplayFullAddress)); - headerObject.insert(QStringLiteral("ccStr"), message->cc()->asUnicodeString()); - headerObject.insert(QStringLiteral("ccNameOnly"), - StringUtil::emailAddrAsAnchor( - message->cc(), StringUtil::DisplayNameOnly)); - headerObject.insert(QStringLiteral("ccMailbox"), QVariant::fromValue(message->cc())); - const QString val = MessageCore::StringUtil::emailAddrAsAnchor( - message->cc(), MessageCore::StringUtil::DisplayFullAddress, - QString(), MessageCore::StringUtil::ShowLink, - MessageCore::StringUtil::ExpandableAddresses, - QStringLiteral("FullCcAddressList")); - headerObject.insert(QStringLiteral("ccExpandable"), val); + headerObject.insert(QStringLiteral("cc"), QVariant::fromValue(static_cast(message->cc()))); } if (message->bcc(false)) { headerObject.insert(QStringLiteral("bcci18n"), i18n("BCC:")); - headerObject.insert(QStringLiteral("bcc"), - StringUtil::emailAddrAsAnchor(message->bcc(), - StringUtil::DisplayFullAddress)); - headerObject.insert(QStringLiteral("bccNameOnly"), - StringUtil::emailAddrAsAnchor(message->bcc(), - StringUtil::DisplayNameOnly)); - headerObject.insert(QStringLiteral("bccStr"), message->bcc()->asUnicodeString()); - headerObject.insert(QStringLiteral("bccMailbox"), QVariant::fromValue(message->bcc())); + headerObject.insert(QStringLiteral("bcc"), QVariant::fromValue(static_cast(message->bcc()))); } headerObject.insert(QStringLiteral("fromi18n"), i18n("From:")); - headerObject.insert(QStringLiteral("from"), - StringUtil::emailAddrAsAnchor(message->from(), - StringUtil::DisplayFullAddress)); - headerObject.insert(QStringLiteral("fromStr"), message->from()->asUnicodeString()); + headerObject.insert(QStringLiteral("from"), QVariant::fromValue(static_cast(message->from()))); //Sender + headerObject.insert(QStringLiteral("senderi18n"), i18n("Sender:")); headerObject.insert(QStringLiteral("sender"), d->headerStyleUtil.strToHtml(message->sender()->asUnicodeString())); - headerObject.insert(QStringLiteral("senderi18n"), i18n("Sender:")); headerObject.insert(QStringLiteral("listidi18n"), i18n("List-Id:")); if (auto hrd = message->headerByType("List-Id")) { @@ -210,57 +277,22 @@ headerObject.insert(QStringLiteral("spamstatusi18n"), i18n("Spam Status:")); headerObject.insert(QStringLiteral("spamHTML"), spamHtml); } - headerObject.insert(QStringLiteral("datei18n"), i18n("Date:")); - headerObject.insert(QStringLiteral("dateshort"), - d->headerStyleUtil.strToHtml(d->headerStyleUtil.dateString(message, - isPrinting, - MessageViewer:: - HeaderStyleUtil:: - ShortDate))); - headerObject.insert(QStringLiteral("datelong"), - d->headerStyleUtil.strToHtml(d->headerStyleUtil.dateString(message, - isPrinting, - MessageViewer:: - HeaderStyleUtil:: - CustomDate))); - headerObject.insert(QStringLiteral("date"), - d->headerStyleUtil.dateStr(message->date()->dateTime())); - headerObject.insert(QStringLiteral("datefancylong"), - d->headerStyleUtil.strToHtml(d->headerStyleUtil.dateString(message, - isPrinting, - MessageViewer:: - HeaderStyleUtil:: - FancyLongDate))); - headerObject.insert(QStringLiteral("datefancyshort"), - d->headerStyleUtil.strToHtml(d->headerStyleUtil.dateString(message, - isPrinting, - MessageViewer:: - HeaderStyleUtil:: - FancyShortDate))); - headerObject.insert(QStringLiteral("datelocalelong"), - d->headerStyleUtil.strToHtml(d->headerStyleUtil.dateString(message, - isPrinting, - MessageViewer:: - HeaderStyleUtil:: - LongDate))); + headerObject.insert(QStringLiteral("datei18n"), i18n("Date:")); + headerObject.insert(QStringLiteral("date"), QVariant::fromValue(static_cast(message->date()))); if (message->hasHeader("Resent-From")) { headerObject.insert(QStringLiteral("resentfromi18n"), i18n("resent from")); - const QVector resentFrom - = d->headerStyleUtil.resentFromList(message); headerObject.insert(QStringLiteral("resentfrom"), - StringUtil::emailAddrAsAnchor(resentFrom, - StringUtil::DisplayFullAddress)); + QVariant::fromValue(HeaderStyleUtil::resentFromList(message))); } if (message->hasHeader("Resent-To")) { - const QVector resentTo = d->headerStyleUtil.resentToList(message); + auto resentTo = HeaderStyleUtil::resentToList(message); headerObject.insert(QStringLiteral("resenttoi18n"), - i18np("receiver was", "receivers were", resentTo.count())); + i18np("receiver was", "receivers were", resentTo->mailboxes().count())); headerObject.insert(QStringLiteral("resentto"), - StringUtil::emailAddrAsAnchor(resentTo, - StringUtil::DisplayFullAddress)); + QVariant::fromValue(HeaderStyleUtil::resentToList(message))); } if (auto organization = message->organization(false)) { diff --git a/messageviewer/src/header/headerstyle_util.h b/messageviewer/src/header/headerstyle_util.h --- a/messageviewer/src/header/headerstyle_util.h +++ b/messageviewer/src/header/headerstyle_util.h @@ -61,22 +61,23 @@ Q_REQUIRED_RESULT QString directionOf(const QString &str) const; - Q_REQUIRED_RESULT QString strToHtml(const QString &str, KTextToHTML::Options flags = KTextToHTML::PreserveSpaces) const; + static Q_REQUIRED_RESULT QString strToHtml(const QString &str, KTextToHTML::Options flags = KTextToHTML::PreserveSpaces); + static Q_REQUIRED_RESULT QString dateString(KMime::Message *message, HeaderStyleUtilDateFormat dateFormat); + static Q_REQUIRED_RESULT QString dateString(const KMime::Headers::Date *date, HeaderStyleUtilDateFormat dateFormat); - Q_REQUIRED_RESULT QString dateString(KMime::Message *message, bool printing, HeaderStyleUtilDateFormat dateFormat) const; Q_REQUIRED_RESULT QString subjectString(KMime::Message *message, KTextToHTML::Options flags = KTextToHTML::PreserveSpaces) const; Q_REQUIRED_RESULT QString subjectDirectionString(KMime::Message *message) const; Q_REQUIRED_RESULT QString spamStatus(KMime::Message *message) const; - Q_REQUIRED_RESULT QString dateStr(const QDateTime &dateTime) const; + static Q_REQUIRED_RESULT QString dateStr(const QDateTime &dateTime); - Q_REQUIRED_RESULT QString dateShortStr(const QDateTime &dateTime) const; + static Q_REQUIRED_RESULT QString dateShortStr(const QDateTime &dateTime); + static Q_REQUIRED_RESULT QSharedPointer resentFromList(KMime::Message *message); - Q_REQUIRED_RESULT QVector resentFromList(KMime::Message *message) const; - Q_REQUIRED_RESULT QVector resentToList(KMime::Message *message) const; + static Q_REQUIRED_RESULT QSharedPointer resentToList(KMime::Message *message); Q_REQUIRED_RESULT xfaceSettings xface(const HeaderStyle *style, KMime::Message *message) const; private: diff --git a/messageviewer/src/header/headerstyle_util.cpp b/messageviewer/src/header/headerstyle_util.cpp --- a/messageviewer/src/header/headerstyle_util.cpp +++ b/messageviewer/src/header/headerstyle_util.cpp @@ -56,38 +56,39 @@ return str.isRightToLeft() ? QStringLiteral("rtl") : QStringLiteral("ltr"); } -QString HeaderStyleUtil::strToHtml(const QString &str, KTextToHTML::Options flags) const +QString HeaderStyleUtil::strToHtml(const QString &str, KTextToHTML::Options flags) { return KTextToHTML::convertToHtml(str, flags, 4096, 512); } -// Prepare the date string (when printing always use the localized date) -QString HeaderStyleUtil::dateString(KMime::Message *message, bool printing, HeaderStyleUtilDateFormat dateFormat) const +// Prepare the date string +QString HeaderStyleUtil::dateString(KMime::Message *message, HeaderStyleUtilDateFormat dateFormat) { - const QDateTime dateTime = message->date()->dateTime(); + return dateString(message->date(), dateFormat); +} + +QString HeaderStyleUtil::dateString(const KMime::Headers::Date *date, HeaderStyleUtilDateFormat dateFormat) +{ + const QDateTime dateTime = date->dateTime(); if (!dateTime.isValid()) { qCDebug(MESSAGEVIEWER_LOG) << "Unable to parse date"; return i18nc("Unknown date", "Unknown"); } - const time_t unixTime = dateTime.toSecsSinceEpoch(); - if (printing) { + const time_t unixTime = dateTime.toTime_t(); + switch (dateFormat) { + case ShortDate: return KMime::DateFormatter::formatDate(KMime::DateFormatter::Localized, unixTime); - } else { - switch (dateFormat) { - case ShortDate: - return KMime::DateFormatter::formatDate(KMime::DateFormatter::Localized, unixTime); - case LongDate: - return KMime::DateFormatter::formatDate(KMime::DateFormatter::CTime, unixTime); - case FancyShortDate: - return KMime::DateFormatter::formatDate(KMime::DateFormatter::Fancy, unixTime); - case FancyLongDate: - //Laurent fix me - //TODO return QLocale::system().toString(dateTime, QLocale::LongFormat); - case CustomDate: - default: - return dateStr(dateTime); - } + case LongDate: + return KMime::DateFormatter::formatDate(KMime::DateFormatter::CTime, unixTime); + case FancyShortDate: + return KMime::DateFormatter::formatDate(KMime::DateFormatter::Fancy, unixTime); + case FancyLongDate: + //Laurent fix me + //TODO return QLocale::system().toString(dateTime, QLocale::LongFormat); + case CustomDate: + default: + return dateStr(dateTime); } } @@ -236,57 +237,43 @@ QString::fromLatin1(ba.toBase64())); } -QString HeaderStyleUtil::dateStr(const QDateTime &dateTime) const +QString HeaderStyleUtil::dateStr(const QDateTime &dateTime) { const time_t unixTime = dateTime.toSecsSinceEpoch(); return KMime::DateFormatter::formatDate( static_cast( MessageCore::MessageCoreSettings::self()->dateFormat()), unixTime, MessageCore::MessageCoreSettings::self()->customDateFormat()); } -QString HeaderStyleUtil::dateShortStr(const QDateTime &dateTime) const +QString HeaderStyleUtil::dateShortStr(const QDateTime &dateTime) { KMime::DateFormatter formatter(KMime::DateFormatter::Fancy); return formatter.dateString(dateTime); } -QVector HeaderStyleUtil::resentFromList(KMime::Message *message) const +QSharedPointer mailboxesFromHeader(const KMime::Headers::Base *hrd) +{ + QSharedPointer mailboxList(new KMime::Headers::Generics::MailboxList()); + const QByteArray &data = hrd->as7BitString(false); + mailboxList->from7BitString(data); + return mailboxList; +} + +QSharedPointer HeaderStyleUtil::resentFromList(KMime::Message *message) { - // Get the resent-from header into a Mailbox - QVector resentFrom; if (auto hrd = message->headerByType("Resent-From")) { - const QByteArray data = hrd->as7BitString(false); - const char *start = data.data(); - const char *end = start + data.length(); - KMime::Types::AddressList addressList; - KMime::HeaderParsing::parseAddressList(start, end, addressList); - for (const KMime::Types::Address &addr : qAsConst(addressList)) { - for (const KMime::Types::Mailbox &mbox : qAsConst(addr.mailboxList)) { - resentFrom.append(mbox); - } - } + return mailboxesFromHeader(hrd); } - return resentFrom; + return nullptr; } -QVector HeaderStyleUtil::resentToList(KMime::Message *message) const +QSharedPointer HeaderStyleUtil::resentToList(KMime::Message *message) { - // Get the resent-from header into a Mailbox - QVector resentTo; if (auto hrd = message->headerByType("Resent-To")) { - const QByteArray data = hrd->as7BitString(false); - const char *start = data.data(); - const char *end = start + data.length(); - KMime::Types::AddressList addressList; - KMime::HeaderParsing::parseAddressList(start, end, addressList); - for (const KMime::Types::Address &addr : qAsConst(addressList)) { - for (const KMime::Types::Mailbox &mbox : qAsConst(addr.mailboxList)) { - resentTo.append(mbox); - } - } + return mailboxesFromHeader(hrd); } - return resentTo; + return nullptr; } void HeaderStyleUtil::updateXFaceSettings(QImage photo, xfaceSettings &settings) const diff --git a/messageviewer/src/header/plainheaderstyle.cpp b/messageviewer/src/header/plainheaderstyle.cpp --- a/messageviewer/src/header/plainheaderstyle.cpp +++ b/messageviewer/src/header/plainheaderstyle.cpp @@ -121,14 +121,10 @@ } if (strategy->showHeader(QStringLiteral("date"))) { + const auto dateFormat = isPrinting()? MessageViewer::HeaderStyleUtil::ShortDate : MessageViewer::HeaderStyleUtil::CustomDate; headerStr.append(i18n("Date: ") - + d->mHeaderStyleUtil.strToHtml(d->mHeaderStyleUtil.dateString(message, - isPrinting(), - /* short = */ - MessageViewer - :: - HeaderStyleUtil - ::CustomDate)) + + HeaderStyleUtil::strToHtml(HeaderStyleUtil::dateString(message, + dateFormat)) + QLatin1String("
\n")); } diff --git a/messageviewer/src/messageviewerheaderplugins/defaultgrantleeheaderstyleplugin/theme/5.2/header.html b/messageviewer/src/messageviewerheaderplugins/defaultgrantleeheaderstyleplugin/theme/5.2/header.html --- a/messageviewer/src/messageviewerheaderplugins/defaultgrantleeheaderstyleplugin/theme/5.2/header.html +++ b/messageviewer/src/messageviewerheaderplugins/defaultgrantleeheaderstyleplugin/theme/5.2/header.html @@ -13,9 +13,9 @@
{{ header.fromi18n }}
- {{ header.from|safe }} - {% if header.resentfrom %} - {{ header.resentfromi18n }}: {{ header.resentfrom|safe }} + {{ header.from.fullAddress|safe }} + {% if header.resentfrom.isSet %} + {{ header.resentfromi18n }}: {{ header.resentfrom.fullAddress|safe }} {% endif %} {% if header.vcardname %} {{ header.vcardi18n }} @@ -25,22 +25,22 @@ {% endif %}
- {% if header.to %} + {% if header.to.isSet %}
{{ header.toi18n }}
-
{{ header.toExpandable|safe }}
+
{{ header.to.expandableTo|safe }}
{% endif %} - {% if header.cc %} + {% if header.cc.isSet %}
{{ header.cci18n }}
-
{{ header.ccExpandable|safe }}
+
{{ header.cc.expandableCc|safe }}
{% endif %} - {% if header.bcc %} + {% if header.bcc.isSet %}
{{ header.bcci18n }}
-
{{ header.bcc|safe }}
+
{{ header.bcc.fullAddress|safe }}
{% endif %} {% if header.sender %} @@ -57,7 +57,7 @@ {% endif %}
{{ header.datei18n }}
-
{{ header.dateshort }}
+
{{ header.date.short }}
{% if header.spamHTML %}