• 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
plainheaderstyle.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 "plainheaderstyle.h"
19 
20 #include "header/headerstyle_util.h"
21 
22 
23 #include "header/headerstrategy.h"
24 
25 #include <kpimutils/email.h>
26 #include <messagecore/utils/stringutil.h>
27 
28 #include <kdebug.h>
29 #include <KLocale>
30 #include <KApplication>
31 
32 #include <kmime/kmime_message.h>
33 
34 using namespace MessageCore;
35 
36 namespace MessageViewer {
37 //
38 // PlainHeaderStyle:
39 // show every header field on a line by itself,
40 // show subject larger
41 //
42 QString PlainHeaderStyle::format( KMime::Message *message ) const {
43  if ( !message )
44  return QString();
45  const HeaderStrategy *strategy = headerStrategy();
46  if ( !strategy )
47  strategy = HeaderStrategy::rich();
48 
49  // The direction of the header is determined according to the direction
50  // of the application layout.
51 
52  QString dir = QApplication::isRightToLeft() ? QLatin1String("rtl") : QLatin1String("ltr");
53 
54  // However, the direction of the message subject within the header is
55  // determined according to the contents of the subject itself. Since
56  // the "Re:" and "Fwd:" prefixes would always cause the subject to be
57  // considered left-to-right, they are ignored when determining its
58  // direction.
59 
60  const QString subjectDir = MessageViewer::HeaderStyleUtil::subjectDirectionString( message );
61  QString headerStr;
62 
63  if ( strategy->headersToDisplay().isEmpty()
64  && strategy->defaultPolicy() == HeaderStrategy::Display ) {
65  // crude way to emulate "all" headers - Note: no strings have
66  // i18n(), so direction should always be ltr.
67  headerStr= QLatin1String("<div class=\"header\" dir=\"ltr\">");
68  headerStr += formatAllMessageHeaders( message );
69  return headerStr + QLatin1String("</div>");
70  }
71 
72  headerStr = QString::fromLatin1("<div class=\"header\" dir=\"%1\">").arg(dir);
73 
74  //case HdrLong:
75  if ( strategy->showHeader( QLatin1String("subject") ) )
76  headerStr += QString::fromLatin1("<div dir=\"%1\"><b style=\"font-size:130%\">").arg(subjectDir) +
77  MessageViewer::HeaderStyleUtil::subjectString( message ) + QLatin1String("</b></div>\n");
78 
79  if ( strategy->showHeader( QLatin1String("date") ) )
80  headerStr.append(i18n("Date: ") + MessageViewer::HeaderStyleUtil::strToHtml( MessageViewer::HeaderStyleUtil::dateString(message, isPrinting(), /* short = */ false ) ) + QLatin1String("<br/>\n") );
81 
82  if ( strategy->showHeader( QLatin1String("from") ) ) {
83  /*FIXME(Andras) review if it is still needed
84  if ( fromStr.isEmpty() ) // no valid email in from, maybe just a name
85  fromStr = message->fromStrip(); // let's use that
86 */
87  headerStr.append( i18n("From: ") +
88  StringUtil::emailAddrAsAnchor( message->from(), StringUtil::DisplayFullAddress, QString(), StringUtil::ShowLink ) );
89  if ( !vCardName().isEmpty() )
90  headerStr.append(QLatin1String("&nbsp;&nbsp;<a href=\"") + vCardName() +
91  QLatin1String("\">") + i18n("[vCard]") + QLatin1String("</a>") );
92 
93  if ( strategy->showHeader( QLatin1String("organization") )
94  && message->headerByType("Organization"))
95  headerStr.append(QLatin1String("&nbsp;&nbsp;(") +
96  MessageViewer::HeaderStyleUtil::strToHtml(message->headerByType("Organization")->asUnicodeString()) + QLatin1Char(')'));
97  headerStr.append(QLatin1String("<br/>\n"));
98  }
99 
100  if ( strategy->showHeader( QLatin1String("to") ) )
101  headerStr.append( i18nc("To-field of the mailheader.", "To: ") +
102  StringUtil::emailAddrAsAnchor( message->to(), StringUtil::DisplayFullAddress ) + QLatin1String("<br/>\n") );
103 
104  if ( strategy->showHeader( QLatin1String("cc") ) && message->cc( false ) )
105  headerStr.append( i18n("CC: ") +
106  StringUtil::emailAddrAsAnchor( message->cc(), StringUtil::DisplayFullAddress ) + QLatin1String("<br/>\n") );
107 
108  if ( strategy->showHeader( QLatin1String("bcc") ) && message->bcc( false ) )
109  headerStr.append( i18n("BCC: ") +
110  StringUtil::emailAddrAsAnchor( message->bcc(), StringUtil::DisplayFullAddress ) + QLatin1String("<br/>\n") );
111 
112  if ( strategy->showHeader( QLatin1String("reply-to" )) && message->replyTo( false ) )
113  headerStr.append( i18n("Reply to: ") +
114  StringUtil::emailAddrAsAnchor( message->replyTo(), StringUtil::DisplayFullAddress ) + QLatin1String("<br/>\n") );
115 
116  headerStr += QLatin1String("</div>\n");
117 
118  return headerStr;
119 }
120 
121 QString PlainHeaderStyle::formatAllMessageHeaders( KMime::Message *message ) const {
122  QByteArray head = message->head();
123  KMime::Headers::Base *header = KMime::HeaderParsing::extractFirstHeader( head );
124  QString result;
125  while ( header ) {
126  result += MessageViewer::HeaderStyleUtil::strToHtml( QLatin1String(header->type()) + QLatin1String(": ") + header->asUnicodeString() );
127  result += QLatin1String( "<br />\n" );
128  delete header;
129  header = KMime::HeaderParsing::extractFirstHeader( head );
130  }
131 
132  return result;
133 }
134 }
MessageViewer::HeaderStyleUtil::dateString
QString dateString(KMime::Message *message, bool printing, bool shortDate)
Definition: headerstyle_util.cpp:54
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
plainheaderstyle.h
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