• 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
fancyheaderstyle.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 #include "fancyheaderstyle.h"
19 
20 #include "header/headerstyle.h"
21 #include "header/headerstyle_util.h"
22 
23 
24 #include "header/headerstrategy.h"
25 #include <kpimutils/linklocator.h>
26 using KPIMUtils::LinkLocator;
27 #include "settings/globalsettings.h"
28 #include "viewer/nodehelper.h"
29 
30 #include <kpimutils/email.h>
31 #include <messagecore/utils/stringutil.h>
32 
33 #include <kdebug.h>
34 #include <klocale.h>
35 #include <kglobal.h>
36 #include <kcodecs.h>
37 #include <KColorScheme>
38 
39 #include <KDateTime>
40 #include <QBuffer>
41 #include <QBitmap>
42 #include <QImage>
43 #include <QApplication>
44 #include <QRegExp>
45 #include <QFontMetrics>
46 
47 #include <kstandarddirs.h>
48 #include <KApplication>
49 
50 #include <kmime/kmime_message.h>
51 #include <kmime/kmime_dateformatter.h>
52 
53 using namespace MessageCore;
54 
55 namespace MessageViewer {
56 //
57 // FancyHeaderStyle:
58 // Like PlainHeaderStyle, but with slick frames and background colours.
59 //
60 
61 QString FancyHeaderStyle::format( KMime::Message *message ) const {
62  if ( !message )
63  return QString();
64  const HeaderStrategy *strategy = headerStrategy();
65  if ( !strategy )
66  strategy = HeaderStrategy::rich();
67 
68  // ### from kmreaderwin begin
69  // The direction of the header is determined according to the direction
70  // of the application layout.
71 
72  const QString dir = QApplication::isRightToLeft() ? QLatin1String("rtl") : QLatin1String("ltr");
73  QString headerStr = QString::fromLatin1("<div class=\"fancy header\" dir=\"%1\">\n").arg(dir);
74 
75  // However, the direction of the message subject within the header is
76  // determined according to the contents of the subject itself. Since
77  // the "Re:" and "Fwd:" prefixes would always cause the subject to be
78  // considered left-to-right, they are ignored when determining its
79  // direction.
80 
81  const QString subjectDir = MessageViewer::HeaderStyleUtil::subjectDirectionString( message );
82 
83  // Spam header display.
84  // If the spamSpamStatus config value is true then we look for headers
85  // from a few spam filters and try to create visually meaningful graphics
86  // out of the spam scores.
87 
88  const QString spamHTML = MessageViewer::HeaderStyleUtil::spamStatus(message);
89 
90  QString userHTML;
91  MessageViewer::HeaderStyleUtil::xfaceSettings xface = MessageViewer::HeaderStyleUtil::xface(this, message);
92  if( !xface.photoURL.isEmpty() )
93  {
94  //kDebug() << "Got a photo:" << photoURL;
95  userHTML = QString::fromLatin1("<img src=\"%1\" width=\"%2\" height=\"%3\">")
96  .arg( xface.photoURL ).arg( xface.photoWidth ).arg( xface.photoHeight );
97  userHTML = QLatin1String("<div class=\"senderpic\">") + userHTML + QLatin1String("</div>");
98  }
99 
100  // the subject line and box below for details
101  if ( strategy->showHeader( QLatin1String("subject") ) ) {
102  const int flags = LinkLocator::PreserveSpaces |
103  ( GlobalSettings::self()->showEmoticons() ?
104  LinkLocator::ReplaceSmileys : 0 );
105 
106  headerStr += QString::fromLatin1("<div dir=\"%1\">%2</div>\n")
107  .arg(subjectDir)
108  .arg( MessageViewer::HeaderStyleUtil::subjectString( message, flags ) );
109  }
110  headerStr += QLatin1String("<table class=\"outer\"><tr><td width=\"100%\"><table>\n");
111  //headerStr += "<table>\n";
112  // from line
113  // the mailto: URLs can contain %3 etc., therefore usage of multiple
114  // QString::arg is not possible
115  if ( strategy->showHeader( QLatin1String("from") ) ) {
116 
117  const QList<KMime::Types::Mailbox> resentFrom = MessageViewer::HeaderStyleUtil::resentFromList(message);
118  headerStr += QString::fromLatin1("<tr><th>%1</th>\n"
119  "<td>")
120  .arg(i18n("From: "))
121  + StringUtil::emailAddrAsAnchor( message->from(), StringUtil::DisplayFullAddress )
122  + ( message->headerByType( "Resent-From" ) ? QLatin1String("&nbsp;")
123  + i18n( "(resent from %1)",
124  StringUtil::emailAddrAsAnchor(
125  resentFrom, StringUtil::DisplayFullAddress ) )
126  : QString() )
127  + ( !vCardName().isEmpty() ? QLatin1String("&nbsp;&nbsp;<a href=\"") + vCardName() + QLatin1String("\">")
128  + i18n("[vCard]") + QLatin1String("</a>")
129  : QString() )
130  + ( !message->headerByType("Organization")
131  ? QString()
132  : QLatin1String("&nbsp;&nbsp;(")
133  + MessageViewer::HeaderStyleUtil::strToHtml(message->headerByType("Organization")->asUnicodeString())
134  + QLatin1Char(')'))
135  + QLatin1String("</td></tr>\n");
136  }
137  // to line
138  if ( strategy->showHeader( QLatin1String("to") ) ) {
139  const QList<KMime::Types::Mailbox> resentTo = MessageViewer::HeaderStyleUtil::resentToList(message);
140 
141  QString to;
142  if (message->headerByType( "Resent-To" )) {
143  to = StringUtil::emailAddrAsAnchor(resentTo, StringUtil::DisplayFullAddress ) + QLatin1Char(' ') +i18n( "(receiver was %1)", StringUtil::emailAddrAsAnchor( message->to(), StringUtil::DisplayFullAddress,
144  QString(), StringUtil::ShowLink, StringUtil::ExpandableAddresses,
145  QLatin1String("FullToAddressList"),
146  GlobalSettings::self()->numberOfAddressesToShow() ));
147  } else {
148  to = StringUtil::emailAddrAsAnchor( message->to(), StringUtil::DisplayFullAddress,
149  QString(), StringUtil::ShowLink, StringUtil::ExpandableAddresses,
150  QLatin1String("FullToAddressList"),
151  GlobalSettings::self()->numberOfAddressesToShow() );
152  }
153 
154  headerStr.append(QString::fromLatin1("<tr><th>%1</th>\n"
155  "<td>%2</td></tr>\n")
156  .arg( i18nc( "To-field of the mail header.","To: " ))
157  .arg( to ));
158  }
159 
160  // cc line, if an
161  if ( strategy->showHeader( QLatin1String("cc") ) && message->cc(false))
162  headerStr.append(QString::fromLatin1("<tr><th>%1</th>\n"
163  "<td>%2</td></tr>\n")
164  .arg( i18n( "CC: " ) )
165  .arg( StringUtil::emailAddrAsAnchor(message->cc(), StringUtil::DisplayFullAddress,
166  QString(), StringUtil::ShowLink, StringUtil::ExpandableAddresses,
167  QLatin1String("FullCcAddressList"),
168  GlobalSettings::self()->numberOfAddressesToShow() ) ) );
169 
170  // Bcc line, if any
171  if ( strategy->showHeader( QLatin1String("bcc") ) && message->bcc(false))
172  headerStr.append(QString::fromLatin1("<tr><th>%1</th>\n"
173  "<td>%2</td></tr>\n")
174  .arg( i18n( "BCC: " ) )
175  .arg( StringUtil::emailAddrAsAnchor( message->bcc(), StringUtil::DisplayFullAddress ) ) );
176 
177  if ( strategy->showHeader( QLatin1String("date") ) )
178  headerStr.append(QString::fromLatin1("<tr><th>%1</th>\n"
179  "<td dir=\"%2\">%3</td></tr>\n")
180  .arg(i18n("Date: "))
181  .arg( MessageViewer::HeaderStyleUtil::directionOf( MessageViewer::HeaderStyleUtil::dateStr( message->date()->dateTime() ) ) )
182  .arg(MessageViewer::HeaderStyleUtil::strToHtml( MessageViewer::HeaderStyleUtil::dateString( message, isPrinting(), /* short = */ false ) ) ) );
183  if ( GlobalSettings::self()->showUserAgent() ) {
184  if ( strategy->showHeader( QLatin1String("user-agent") ) ) {
185  if ( message->headerByType("User-Agent") ) {
186  headerStr.append(QString::fromLatin1("<tr><th>%1</th>\n"
187  "<td>%2</td></tr>\n")
188  .arg(i18n("User-Agent: "))
189  .arg( MessageViewer::HeaderStyleUtil::strToHtml( QLatin1String(message->headerByType("User-Agent")->as7BitString() )) ) );
190  }
191  }
192 
193  if ( strategy->showHeader( QLatin1String("x-mailer") ) ) {
194  if ( message->headerByType("X-Mailer") ) {
195  headerStr.append(QString::fromLatin1("<tr><th>%1</th>\n"
196  "<td>%2</td></tr>\n")
197  .arg(i18n("X-Mailer: "))
198  .arg( MessageViewer::HeaderStyleUtil::strToHtml( QLatin1String(message->headerByType("X-Mailer")->as7BitString() ) ) ) );
199  }
200  }
201  }
202 
203  if ( strategy->showHeader( QLatin1String("x-bugzilla-url") ) && message->headerByType("X-Bugzilla-URL") ) {
204  const QString product = message->headerByType("X-Bugzilla-Product") ? message->headerByType("X-Bugzilla-Product")->asUnicodeString() : QString();
205  const QString component = message->headerByType("X-Bugzilla-Component") ? message->headerByType("X-Bugzilla-Component")->asUnicodeString() : QString();
206  const QString status = message->headerByType("X-Bugzilla-Status") ? message->headerByType("X-Bugzilla-Status")->asUnicodeString() : QString();
207  headerStr.append(QString::fromLatin1("<tr><th>%1</th>\n"
208  "<td>%2/%3, <strong>%4</strong></td></tr>\n")
209  .arg(i18n("Bugzilla: "))
210  .arg( MessageViewer::HeaderStyleUtil::strToHtml( product ) )
211  .arg( MessageViewer::HeaderStyleUtil::strToHtml( component ) )
212  .arg( MessageViewer::HeaderStyleUtil::strToHtml( status) ) );
213  }
214 
215  headerStr.append( QLatin1String( "<tr><td colspan=\"2\"><div id=\"attachmentInjectionPoint\"></div></td></tr>" ) );
216  headerStr.append(
217  QString::fromLatin1( "</table></td><td align=\"center\">%1</td></tr></table>\n" ).arg(userHTML) );
218 
219  if ( !spamHTML.isEmpty() )
220  headerStr.append( QString::fromLatin1( "<div class=\"spamheader\" dir=\"%1\"><b>%2</b>&nbsp;<span style=\"padding-left: 20px;\">%3</span></div>\n")
221  .arg( subjectDir, i18n("Spam Status:"), spamHTML ) );
222 
223  headerStr += QLatin1String("</div>\n\n");
224  return headerStr;
225 }
226 
227 }
MessageViewer::HeaderStyleUtil::directionOf
QString directionOf(const QString &str)
Definition: headerstyle_util.cpp:45
globalsettings.h
MessageViewer::HeaderStyleUtil::dateString
QString dateString(KMime::Message *message, bool printing, bool shortDate)
Definition: headerstyle_util.cpp:54
MessageViewer::HeaderStyleUtil::resentToList
QList< KMime::Types::Mailbox > resentToList(KMime::Message *message)
Definition: headerstyle_util.cpp:243
MessageViewer::HeaderStyleUtil::xface
xfaceSettings xface(const MessageViewer::HeaderStyle *style, KMime::Message *message)
Definition: headerstyle_util.cpp:262
MessageViewer::HeaderStyleUtil::xfaceSettings::photoHeight
int photoHeight
Definition: headerstyle_util.h:70
MessageViewer::HeaderStyleUtil::xfaceSettings::photoWidth
int photoWidth
Definition: headerstyle_util.h:69
nodehelper.h
MessageViewer::HeaderStyleUtil::xfaceSettings
Definition: headerstyle_util.h:61
MessageViewer::HeaderStrategy
Definition: headerstrategy.h:42
headerstyle.h
MessageViewer::HeaderStyleUtil::dateStr
QString dateStr(const KDateTime &dateTime)
Definition: headerstyle_util.cpp:209
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
MessageViewer::HeaderStyleUtil::spamStatus
QString spamStatus(KMime::Message *message)
Definition: headerstyle_util.cpp:94
headerstyle_util.h
MessageViewer::HeaderStrategy::showHeader
virtual bool showHeader(const QString &header) const
Definition: headerstrategy.cpp:62
headerstrategy.h
fancyheaderstyle.h
MessageViewer::HeaderStyleUtil::resentFromList
QList< KMime::Types::Mailbox > resentFromList(KMime::Message *message)
Definition: headerstyle_util.cpp:224
MessageViewer::HeaderStyleUtil::xfaceSettings::photoURL
QString photoURL
Definition: headerstyle_util.h:68
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