Changeset View
Changeset View
Standalone View
Standalone View
messageviewer/src/header/grantleeheaderformatter.cpp
Show All 19 Lines | |||||
20 | #include "grantleeheaderformatter.h" | 20 | #include "grantleeheaderformatter.h" | ||
21 | #include "headerstyle_util.h" | 21 | #include "headerstyle_util.h" | ||
22 | #include "grantleetheme/grantleetheme.h" | 22 | #include "grantleetheme/grantleetheme.h" | ||
23 | #include "settings/messageviewersettings.h" | 23 | #include "settings/messageviewersettings.h" | ||
24 | #include "utils/iconnamecache.h" | 24 | #include "utils/iconnamecache.h" | ||
25 | #include "config-messageviewer.h" | 25 | #include "config-messageviewer.h" | ||
26 | 26 | | |||
27 | #include <MessageCore/StringUtil> | 27 | #include <MessageCore/StringUtil> | ||
28 | #include <MimeTreeParser/NodeHelper> | ||||
28 | 29 | | |||
29 | #include <kmime/kmime_message.h> | 30 | #include <kmime/kmime_message.h> | ||
30 | #include <kmime/kmime_dateformatter.h> | 31 | #include <kmime/kmime_dateformatter.h> | ||
31 | 32 | | |||
32 | #include <KLocalizedString> | 33 | #include <KLocalizedString> | ||
33 | #include <KIconLoader> | 34 | #include <KIconLoader> | ||
34 | #include <KColorScheme> | 35 | #include <KColorScheme> | ||
35 | 36 | | |||
▲ Show 20 Lines • Show All 176 Lines • ▼ Show 20 Line(s) | 208 | { | |||
212 | } | 213 | } | ||
213 | return format(absolutPath, headerTemplate, displayExtraHeaders, isPrinting, style, message); | 214 | return format(absolutPath, headerTemplate, displayExtraHeaders, isPrinting, style, message); | ||
214 | } | 215 | } | ||
215 | 216 | | |||
216 | QString GrantleeHeaderFormatter::format(const QString &absolutePath, const Grantlee::Template &headerTemplate, const QStringList &displayExtraHeaders, bool isPrinting, | 217 | QString GrantleeHeaderFormatter::format(const QString &absolutePath, const Grantlee::Template &headerTemplate, const QStringList &displayExtraHeaders, bool isPrinting, | ||
217 | const MessageViewer::HeaderStyle *style, KMime::Message *message, bool showEmoticons) const | 218 | const MessageViewer::HeaderStyle *style, KMime::Message *message, bool showEmoticons) const | ||
218 | { | 219 | { | ||
219 | QVariantHash headerObject; | 220 | QVariantHash headerObject; | ||
221 | const auto nodeHelper = style->nodeHelper(); | ||||
220 | 222 | | |||
221 | // However, the direction of the message subject within the header is | 223 | // However, the direction of the message subject within the header is | ||
222 | // determined according to the contents of the subject itself. Since | 224 | // determined according to the contents of the subject itself. Since | ||
223 | // the "Re:" and "Fwd:" prefixes would always cause the subject to be | 225 | // the "Re:" and "Fwd:" prefixes would always cause the subject to be | ||
224 | // considered left-to-right, they are ignored when determining its | 226 | // considered left-to-right, they are ignored when determining its | ||
225 | // direction. | 227 | // direction. | ||
226 | const QString absoluteThemePath = QUrl::fromLocalFile(absolutePath + QLatin1Char('/')).url(); | 228 | const QString absoluteThemePath = QUrl::fromLocalFile(absolutePath + QLatin1Char('/')).url(); | ||
227 | headerObject.insert(QStringLiteral("absoluteThemePath"), absoluteThemePath); | 229 | headerObject.insert(QStringLiteral("absoluteThemePath"), absoluteThemePath); | ||
228 | headerObject.insert(QStringLiteral("applicationDir"), | 230 | headerObject.insert(QStringLiteral("applicationDir"), | ||
229 | QApplication::isRightToLeft() ? QStringLiteral("rtl") : QStringLiteral( | 231 | QApplication::isRightToLeft() ? QStringLiteral("rtl") : QStringLiteral( | ||
230 | "ltr")); | 232 | "ltr")); | ||
231 | headerObject.insert(QStringLiteral("subjectDir"), | 233 | headerObject.insert(QStringLiteral("subjectDir"), | ||
232 | d->headerStyleUtil.subjectDirectionString(message)); | 234 | d->headerStyleUtil.subjectDirectionString(message)); | ||
233 | 235 | | |||
234 | headerObject.insert(QStringLiteral("subjecti18n"), i18n("Subject:")); | 236 | headerObject.insert(QStringLiteral("subjecti18n"), i18n("Subject:")); | ||
235 | KTextToHTML::Options flags = KTextToHTML::PreserveSpaces; | 237 | KTextToHTML::Options flags = KTextToHTML::PreserveSpaces; | ||
236 | if (showEmoticons) { | 238 | if (showEmoticons) { | ||
237 | flags |= KTextToHTML::ReplaceSmileys; | 239 | flags |= KTextToHTML::ReplaceSmileys; | ||
238 | } | 240 | } | ||
239 | 241 | | |||
240 | headerObject.insert(QStringLiteral("subject"), | 242 | headerObject.insert(QStringLiteral("subject"), | ||
241 | d->headerStyleUtil.subjectString(message, flags)); | 243 | d->headerStyleUtil.subjectString(message, flags)); | ||
242 | 244 | | |||
243 | if (message->to(false)) { | 245 | if (nodeHelper->hasMailHeader("to", message)) { | ||
246 | const auto value = nodeHelper->mailHeaderAsAddressList("to",message); | ||||
244 | headerObject.insert(QStringLiteral("toi18n"), i18n("To:")); | 247 | headerObject.insert(QStringLiteral("toi18n"), i18n("To:")); | ||
245 | headerObject.insert(QStringLiteral("to"), QVariant::fromValue(static_cast<const KMime::Headers::Generics::AddressList *>(message->to()))); | 248 | headerObject.insert(QStringLiteral("to"), QVariant::fromValue(static_cast<const KMime::Headers::Generics::AddressList *>(value))); | ||
246 | } | 249 | } | ||
247 | 250 | | |||
248 | if (message->replyTo(false)) { | 251 | if (nodeHelper->hasMailHeader("replyTo", message)) { | ||
252 | const auto value = nodeHelper->mailHeaderAsAddressList("replyTo",message); | ||||
249 | headerObject.insert(QStringLiteral("replyToi18n"), i18n("Reply to:")); | 253 | headerObject.insert(QStringLiteral("replyToi18n"), i18n("Reply to:")); | ||
250 | headerObject.insert(QStringLiteral("replyTo"), QVariant::fromValue(static_cast<const KMime::Headers::Generics::AddressList *>(message->replyTo()))); | 254 | headerObject.insert(QStringLiteral("replyTo"), QVariant::fromValue(static_cast<const KMime::Headers::Generics::AddressList *>(value))); | ||
251 | } | 255 | } | ||
252 | 256 | | |||
253 | if (message->cc(false)) { | 257 | if (nodeHelper->hasMailHeader("cc", message)) { | ||
258 | const auto value = nodeHelper->mailHeaderAsAddressList("cc",message); | ||||
254 | headerObject.insert(QStringLiteral("cci18n"), i18n("CC:")); | 259 | headerObject.insert(QStringLiteral("cci18n"), i18n("CC:")); | ||
255 | headerObject.insert(QStringLiteral("cc"), QVariant::fromValue(static_cast<const KMime::Headers::Generics::AddressList *>(message->cc()))); | 260 | headerObject.insert(QStringLiteral("cc"), QVariant::fromValue(static_cast<const KMime::Headers::Generics::AddressList *>(value))); | ||
256 | } | 261 | } | ||
257 | 262 | | |||
258 | if (message->bcc(false)) { | 263 | if (nodeHelper->hasMailHeader("bcc", message)) { | ||
264 | const auto value = nodeHelper->mailHeaderAsAddressList("bcc",message); | ||||
259 | headerObject.insert(QStringLiteral("bcci18n"), i18n("BCC:")); | 265 | headerObject.insert(QStringLiteral("bcci18n"), i18n("BCC:")); | ||
260 | headerObject.insert(QStringLiteral("bcc"), QVariant::fromValue(static_cast<const KMime::Headers::Generics::AddressList *>(message->bcc()))); | 266 | headerObject.insert(QStringLiteral("bcc"), QVariant::fromValue(static_cast<const KMime::Headers::Generics::AddressList *>(value))); | ||
261 | } | 267 | } | ||
262 | headerObject.insert(QStringLiteral("fromi18n"), i18n("From:")); | | |||
263 | headerObject.insert(QStringLiteral("from"), QVariant::fromValue(static_cast<const KMime::Headers::Generics::MailboxList *>(message->from()))); | | |||
264 | 268 | | |||
269 | { | ||||
270 | const auto value = nodeHelper->mailHeaderAsAddressList("from",message); | ||||
271 | headerObject.insert(QStringLiteral("fromi18n"), i18n("From:")); | ||||
272 | headerObject.insert(QStringLiteral("from"), QVariant::fromValue(static_cast<const KMime::Headers::Generics::AddressList *>(value))); | ||||
273 | } | ||||
265 | //Sender | 274 | //Sender | ||
266 | headerObject.insert(QStringLiteral("senderi18n"), i18n("Sender:")); | 275 | headerObject.insert(QStringLiteral("senderi18n"), i18n("Sender:")); | ||
267 | headerObject.insert(QStringLiteral("sender"), | 276 | headerObject.insert(QStringLiteral("sender"), | ||
268 | HeaderStyleUtil::strToHtml(message->sender()->asUnicodeString())); | 277 | HeaderStyleUtil::strToHtml(nodeHelper->mailHeaderAsBase("sender", message)->asUnicodeString())); | ||
269 | headerObject.insert(QStringLiteral("listidi18n"), i18n("List-Id:")); | 278 | headerObject.insert(QStringLiteral("listidi18n"), i18n("List-Id:")); | ||
270 | 279 | | |||
271 | if (auto hrd = message->headerByType("List-Id")) { | 280 | if (nodeHelper->hasMailHeader("List-Id", message)) { | ||
272 | headerObject.insert(QStringLiteral("listid"), hrd->asUnicodeString()); | 281 | const auto value = nodeHelper->mailHeaderAsAddressList("List-Id", message); | ||
282 | headerObject.insert(QStringLiteral("listid"), value->asUnicodeString()); | ||||
273 | } | 283 | } | ||
274 | 284 | | |||
275 | const QString spamHtml = d->headerStyleUtil.spamStatus(message); | 285 | const QString spamHtml = d->headerStyleUtil.spamStatus(message); | ||
276 | if (!spamHtml.isEmpty()) { | 286 | if (!spamHtml.isEmpty()) { | ||
277 | headerObject.insert(QStringLiteral("spamstatusi18n"), i18n("Spam Status:")); | 287 | headerObject.insert(QStringLiteral("spamstatusi18n"), i18n("Spam Status:")); | ||
278 | headerObject.insert(QStringLiteral("spamHTML"), spamHtml); | 288 | headerObject.insert(QStringLiteral("spamHTML"), spamHtml); | ||
279 | } | 289 | } | ||
280 | 290 | | |||
291 | { | ||||
292 | const auto value = nodeHelper->dateHeader(message); | ||||
281 | headerObject.insert(QStringLiteral("datei18n"), i18n("Date:")); | 293 | headerObject.insert(QStringLiteral("datei18n"), i18n("Date:")); | ||
294 | // TODO: rewrite that QDateTime is expected in GRANTLEE | ||||
282 | headerObject.insert(QStringLiteral("date"), QVariant::fromValue(static_cast<const KMime::Headers::Date *>(message->date()))); | 295 | headerObject.insert(QStringLiteral("date"), QVariant::fromValue(static_cast<const KMime::Headers::Date *>(message->date()))); | ||
296 | } | ||||
283 | 297 | | |||
284 | if (message->hasHeader("Resent-From")) { | 298 | if (nodeHelper->hasMailHeader("Resent-From", message)) { | ||
299 | const auto value = nodeHelper->mailHeaderAsAddressList("Resent-From", message); | ||||
285 | headerObject.insert(QStringLiteral("resentfromi18n"), i18n("resent from")); | 300 | headerObject.insert(QStringLiteral("resentfromi18n"), i18n("resent from")); | ||
286 | headerObject.insert(QStringLiteral("resentfrom"), | 301 | headerObject.insert(QStringLiteral("resentfrom"), QVariant::fromValue(static_cast<const KMime::Headers::Generics::AddressList *>(value))); | ||
287 | QVariant::fromValue(HeaderStyleUtil::resentFromList(message))); | | |||
288 | } | 302 | } | ||
289 | 303 | | |||
290 | if (message->hasHeader("Resent-To")) { | 304 | if (nodeHelper->hasMailHeader("Resent-To", message)) { | ||
291 | auto resentTo = HeaderStyleUtil::resentToList(message); | 305 | const auto resentTo = nodeHelper->mailHeaderAsAddressList("Resent-From", message); | ||
knauss: should be Resent-To :D | |||||
292 | headerObject.insert(QStringLiteral("resenttoi18n"), | 306 | headerObject.insert(QStringLiteral("resenttoi18n"), | ||
293 | i18np("receiver was", "receivers were", resentTo->mailboxes().count())); | 307 | i18np("receiver was", "receivers were", resentTo->mailboxes().count())); | ||
294 | headerObject.insert(QStringLiteral("resentto"), | 308 | headerObject.insert(QStringLiteral("resentto"), QVariant::fromValue(static_cast<const KMime::Headers::Generics::AddressList *>(resentTo))); | ||
295 | QVariant::fromValue(HeaderStyleUtil::resentToList(message))); | | |||
296 | } | 309 | } | ||
297 | 310 | | |||
298 | if (auto organization = message->organization(false)) { | 311 | if (auto organization = message->organization(false)) { | ||
299 | headerObject.insert(QStringLiteral("organization"), | 312 | headerObject.insert(QStringLiteral("organization"), | ||
300 | HeaderStyleUtil::strToHtml(organization->asUnicodeString())); | 313 | HeaderStyleUtil::strToHtml(organization->asUnicodeString())); | ||
301 | } | 314 | } | ||
302 | 315 | | |||
303 | if (!style->vCardName().isEmpty()) { | 316 | if (!style->vCardName().isEmpty()) { | ||
▲ Show 20 Lines • Show All 99 Lines • Show Last 20 Lines |
should be Resent-To :D