• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

messageviewer

  • sources
  • kde-4.12
  • kdepim
  • messageviewer
  • header
customheaderstyle.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 
19 #include "customheaderstyle.h"
20 #include "header/headerstyle_util.h"
21 
22 #include "header/headerstrategy.h"
23 #include <kpimutils/linklocator.h>
24 using KPIMUtils::LinkLocator;
25 #include "settings/globalsettings.h"
26 #include "viewer/nodehelper.h"
27 
28 #include <kpimutils/email.h>
29 #include <messagecore/utils/stringutil.h>
30 
31 #include <kdebug.h>
32 #include <klocale.h>
33 #include <kglobal.h>
34 
35 #include <KApplication>
36 
37 #include <kmime/kmime_message.h>
38 #include <kmime/kmime_dateformatter.h>
39 
40 using namespace MessageCore;
41 using KPIMUtils::LinkLocator;
42 using namespace MessageViewer;
43 
44 namespace MessageViewer {
45 
46 //
47 // CustomHeaderStyle:
48 // show every header field on a line by itself,
49 // show subject larger
50 //
51 QString CustomHeaderStyle::format( KMime::Message *message ) const {
52  if ( !message )
53  return QString();
54  const HeaderStrategy *strategy = headerStrategy();
55  if ( !strategy )
56  strategy = HeaderStrategy::custom();
57 
58  // The direction of the header is determined according to the direction
59  // of the application layout.
60 
61  const QString dir = ( QApplication::isRightToLeft() ? QLatin1String("rtl") : QLatin1String("ltr") );
62 
63  // However, the direction of the message subject within the header is
64  // determined according to the contents of the subject itself. Since
65  // the "Re:" and "Fwd:" prefixes would always cause the subject to be
66  // considered left-to-right, they are ignored when determining its
67  // direction.
68 
69  const QString subjectDir = MessageViewer::HeaderStyleUtil::subjectDirectionString( message );
70  QString headerStr;
71 
72  const QStringList headersToDisplay = strategy->headersToDisplay();
73 
74  if ( (strategy->defaultPolicy() == HeaderStrategy::Hide) ||
75  (headersToDisplay.isEmpty() && strategy->defaultPolicy() == HeaderStrategy::Display )) {
76  // crude way to emulate "all" headers - Note: no strings have
77  // i18n(), so direction should always be ltr.
78  headerStr= QLatin1String("<div class=\"header\" dir=\"ltr\">");
79  const QStringList headersToHide = strategy->headersToHide();
80  headerStr += formatAllMessageHeaders( message, headersToHide );
81  return headerStr + QLatin1String("</div>");
82  }
83 
84  headerStr = QString::fromLatin1("<div class=\"header\" dir=\"%1\">").arg(dir);
85 
86 
87  Q_FOREACH (const QString &headerToDisplay, headersToDisplay) {
88  if ( headerToDisplay.toLower() == QLatin1String("subject")) {
89  headerStr += QString::fromLatin1("<div dir=\"%1\"><b style=\"font-size:130%\">").arg(subjectDir) +
90  MessageViewer::HeaderStyleUtil::subjectString( message ) + QLatin1String("</b></div>\n");
91  } else if (headerToDisplay.toLower() == QLatin1String("date")) {
92  headerStr.append(i18n("Date: ") + MessageViewer::HeaderStyleUtil::strToHtml( MessageViewer::HeaderStyleUtil::dateString(message, isPrinting(), /* short = */ false ) ) + QLatin1String("<br/>\n") );
93  } else if (headerToDisplay.toLower() == QLatin1String("from")) {
94  headerStr.append( i18n("From: ") +
95  StringUtil::emailAddrAsAnchor( message->from(), StringUtil::DisplayFullAddress, QString(), StringUtil::ShowLink ) );
96  if ( !vCardName().isEmpty() )
97  headerStr.append(QLatin1String("&nbsp;&nbsp;<a href=\"") + vCardName() +
98  QLatin1String("\">") + i18n("[vCard]") + QLatin1String("</a>") );
99 
100  if ( strategy->showHeader( QLatin1String("organization") )
101  && message->headerByType("Organization"))
102  headerStr.append(QLatin1String("&nbsp;&nbsp;(") +
103  MessageViewer::HeaderStyleUtil::strToHtml(message->headerByType("Organization")->asUnicodeString()) + QLatin1Char(')'));
104  headerStr.append(QLatin1String("<br/>\n"));
105  } else if (headerToDisplay.toLower() == QLatin1String("to")) {
106  headerStr.append( i18nc("To-field of the mailheader.", "To: ") +
107  StringUtil::emailAddrAsAnchor( message->to(), StringUtil::DisplayFullAddress ) + QLatin1String("<br/>\n") );
108  } else if (headerToDisplay.toLower() == QLatin1String("cc")) {
109  if (message->cc( false )) {
110  headerStr.append( i18n("CC: ") +
111  StringUtil::emailAddrAsAnchor( message->cc(), StringUtil::DisplayFullAddress ) + QLatin1String("<br/>\n") );
112  }
113  } else if (headerToDisplay.toLower() == QLatin1String("bcc")) {
114  if (message->bcc( false )) {
115  headerStr.append( i18n("BCC: ") +
116  StringUtil::emailAddrAsAnchor( message->bcc(), StringUtil::DisplayFullAddress ) + QLatin1String("<br/>\n") );
117  }
118  } else if (headerToDisplay.toLower() == QLatin1String("reply-to")) {
119  if (message->replyTo( false )) {
120  headerStr.append( i18n("Reply to: ") +
121  StringUtil::emailAddrAsAnchor( message->replyTo(), StringUtil::DisplayFullAddress ) + QLatin1String("<br/>\n") );
122  }
123  } else {
124  const QByteArray header = headerToDisplay.toLatin1();
125  if (message->headerByType(header)) {
126  headerStr.append( MessageViewer::HeaderStyleUtil::strToHtml(i18n("%1: ",headerToDisplay) + message->headerByType(header)->asUnicodeString()) + QLatin1String("<br/>\n") );
127  }
128  }
129  }
130  headerStr += QLatin1String("</div>\n");
131  return headerStr;
132 }
133 
134 QString CustomHeaderStyle::formatAllMessageHeaders( KMime::Message *message, const QStringList &headersToHide ) const
135 {
136  QByteArray head = message->head();
137  KMime::Headers::Base *header = KMime::HeaderParsing::extractFirstHeader( head );
138  QString result;
139  while ( header ) {
140  const QString headerType = QLatin1String(header->type());
141  if (!headersToHide.contains(headerType) || !headersToHide.contains(headerType.toLower())) {
142  result += MessageViewer::HeaderStyleUtil::strToHtml(headerType) + QLatin1String(": ") + header->asUnicodeString();
143  result += QLatin1String( "<br />\n" );
144  }
145  delete header;
146  header = KMime::HeaderParsing::extractFirstHeader( head );
147  }
148  return result;
149 }
150 }
globalsettings.h
customheaderstyle.h
MessageViewer::HeaderStyleUtil::dateString
QString dateString(KMime::Message *message, bool printing, bool shortDate)
Definition: headerstyle_util.cpp:54
MessageViewer::HeaderStrategy::headersToHide
virtual QStringList headersToHide() const
Definition: headerstrategy.cpp:58
nodehelper.h
MessageViewer::HeaderStrategy
Definition: headerstrategy.h:42
MessageViewer::HeaderStrategy::defaultPolicy
virtual DefaultPolicy defaultPolicy() const =0
MessageViewer::HeaderStyleUtil::subjectDirectionString
QString subjectDirectionString(KMime::Message *message)
Definition: headerstyle_util.cpp:84
MessageViewer::HeaderStyleUtil::subjectString
QString subjectString(KMime::Message *message, int flags)
Definition: headerstyle_util.cpp:69
headerstyle_util.h
MessageViewer::HeaderStrategy::showHeader
virtual bool showHeader(const QString &header) const
Definition: headerstrategy.cpp:62
MessageViewer::HeaderStrategy::headersToDisplay
virtual QStringList headersToDisplay() const
Definition: headerstrategy.cpp:54
headerstrategy.h
MessageViewer::HeaderStyleUtil::strToHtml
QString strToHtml(const QString &str, int flags)
Definition: headerstyle_util.cpp:49
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:57 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

messageviewer

Skip menu "messageviewer"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal