• 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
  • viewer
attachmentstrategy.cpp
Go to the documentation of this file.
1 /* -*- c++ -*-
2  attachmentstrategy.cpp
3 
4  This file is part of KMail, the KDE mail client.
5  Copyright (c) 2003 Marc Mutz <mutz@kde.org>
6  Copyright (C) 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net
7  Copyright (c) 2009 Andras Mantia <andras@kdab.net>
8 
9  KMail is free software; you can redistribute it and/or modify it
10  under the terms of the GNU General Public License, version 2, as
11  published by the Free Software Foundation.
12 
13  KMail is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22  In addition, as a special exception, the copyright holders give
23  permission to link the code of this program with any edition of
24  the Qt library by Trolltech AS, Norway (or with modified versions
25  of Qt that use the same license as Qt), and distribute linked
26  combinations including the two. You must obey the GNU General
27  Public License in all respects for all of the code used other than
28  Qt. If you modify this file, you may extend this exception to
29  your version of the file, but you are not obligated to do so. If
30  you do not wish to do so, delete this exception statement from
31  your version.
32 */
33 
34 
35 
36 #include "attachmentstrategy.h"
37 
38 #include "viewer/nodehelper.h"
39 
40 #include <kmime/kmime_content.h>
41 #include <kdebug.h>
42 
43 #include <messagecore/helpers/nodehelper.h>
44 
45 namespace MessageViewer {
46 
47 static AttachmentStrategy::Display smartDisplay( KMime::Content *node )
48 {
49  if ( node->contentDisposition()->disposition() == KMime::Headers::CDinline )
50  // explict "inline" disposition:
51  return AttachmentStrategy::Inline;
52  if ( MessageCore::NodeHelper::isAttachment( node ) )
53  // explicit "attachment" disposition:
54  return AttachmentStrategy::AsIcon;
55  if ( node->contentType()->isText() &&
56  node->contentDisposition()->filename().trimmed().isEmpty() &&
57  node->contentType()->name().trimmed().isEmpty() )
58  // text/* w/o filename parameter:
59  return AttachmentStrategy::Inline;
60  return AttachmentStrategy::AsIcon;
61 }
62 
63 //
64 // IconicAttachmentStrategy:
65 // show everything but the first text/plain body as icons
66 //
67 
68 class IconicAttachmentStrategy : public AttachmentStrategy {
69  friend class AttachmentStrategy;
70 protected:
71  IconicAttachmentStrategy() : AttachmentStrategy() {}
72  virtual ~IconicAttachmentStrategy() {}
73 
74 public:
75  const char * name() const { return "iconic"; }
76  const AttachmentStrategy * next() const { return smart(); }
77  const AttachmentStrategy * prev() const { return headerOnly(); }
78 
79  bool inlineNestedMessages() const { return false; }
80  Display defaultDisplay( KMime::Content * node ) const {
81  if ( node->contentType()->isText() &&
82  node->contentDisposition()->filename().trimmed().isEmpty() &&
83  node->contentType()->name().trimmed().isEmpty() )
84  // text/* w/o filename parameter:
85  return Inline;
86  return AsIcon;
87  }
88 };
89 
90 //
91 // SmartAttachmentStrategy:
92 // in addition to Iconic, show all body parts
93 // with content-disposition == "inline" and
94 // all text parts without a filename or name parameter inline
95 //
96 
97 class SmartAttachmentStrategy : public AttachmentStrategy {
98  friend class AttachmentStrategy;
99 protected:
100  SmartAttachmentStrategy() : AttachmentStrategy() {}
101  virtual ~SmartAttachmentStrategy() {}
102 
103 public:
104  const char * name() const { return "smart"; }
105  const AttachmentStrategy * next() const { return inlined(); }
106  const AttachmentStrategy * prev() const { return iconic(); }
107 
108  bool inlineNestedMessages() const { return true; }
109  Display defaultDisplay( KMime::Content * node ) const {
110  return smartDisplay( node );
111  }
112 };
113 
114 //
115 // InlinedAttachmentStrategy:
116 // show everything possible inline
117 //
118 
119 class InlinedAttachmentStrategy : public AttachmentStrategy {
120  friend class AttachmentStrategy;
121 protected:
122  InlinedAttachmentStrategy() : AttachmentStrategy() {}
123  virtual ~InlinedAttachmentStrategy() {}
124 
125 public:
126  const char * name() const { return "inlined"; }
127  const AttachmentStrategy * next() const { return hidden(); }
128  const AttachmentStrategy * prev() const { return smart(); }
129 
130  bool inlineNestedMessages() const { return true; }
131  Display defaultDisplay( KMime::Content * ) const { return Inline; }
132 };
133 
134 //
135 // HiddenAttachmentStrategy
136 // show nothing except the first text/plain body part _at all_
137 //
138 
139 class HiddenAttachmentStrategy : public AttachmentStrategy {
140  friend class AttachmentStrategy;
141 protected:
142  HiddenAttachmentStrategy() : AttachmentStrategy() {}
143  virtual ~HiddenAttachmentStrategy() {}
144 
145 public:
146  const char * name() const { return "hidden"; }
147  const AttachmentStrategy * next() const { return headerOnly(); }
148  const AttachmentStrategy * prev() const { return inlined(); }
149 
150  bool inlineNestedMessages() const { return false; }
151  Display defaultDisplay( KMime::Content * node ) const {
152  if ( node->contentType()->isText() &&
153  node->contentDisposition()->filename().trimmed().isEmpty() &&
154  node->contentType()->name().trimmed().isEmpty() )
155  // text/* w/o filename parameter:
156  return Inline;
157  if (!node->parent())
158  return Inline;
159 
160  if ( node->parent() && node->parent()->contentType()->isMultipart() &&
161  node->parent()->contentType()->subType() == "related" )
162  return Inline;
163 
164  return None;
165  }
166 };
167 
168 class HeaderOnlyAttachmentStrategy : public AttachmentStrategy {
169  friend class AttachmentStrategy;
170 protected:
171  HeaderOnlyAttachmentStrategy() : AttachmentStrategy() {}
172  virtual ~HeaderOnlyAttachmentStrategy() {}
173 
174 public:
175  const char * name() const { return "headerOnly"; }
176  const AttachmentStrategy * next() const { return iconic(); }
177  const AttachmentStrategy * prev() const { return hidden(); }
178 
179  bool inlineNestedMessages() const {
180  return true;
181  }
182 
183  Display defaultDisplay( KMime::Content * node ) const {
184  if ( NodeHelper::isInEncapsulatedMessage( node ) ) {
185  return smartDisplay( node );
186  }
187 
188  NodeHelper::AttachmentDisplayInfo info = NodeHelper::attachmentDisplayInfo( node );
189  if ( info.displayInHeader ) {
190  // The entire point about this attachment strategy: Hide attachments in the body that are
191  // already displayed in the attachment quick list
192  return None;
193  } else {
194  return smartDisplay( node );
195  }
196  }
197 
198  virtual bool requiresAttachmentListInHeader() const {
199  return true;
200  }
201 };
202 
203 //
204 // AttachmentStrategy abstract base:
205 //
206 
207 AttachmentStrategy::AttachmentStrategy() {
208 
209 }
210 
211 AttachmentStrategy::~AttachmentStrategy() {
212 
213 }
214 
215 const AttachmentStrategy * AttachmentStrategy::create( Type type ) {
216  switch ( type ) {
217  case Iconic: return iconic();
218  case Smart: return smart();
219  case Inlined: return inlined();
220  case Hidden: return hidden();
221  case HeaderOnly: return headerOnly();
222  }
223  kFatal() << "Unknown attachment startegy ( type =="
224  << (int)type << ") requested!";
225  return 0; // make compiler happy
226 }
227 
228 const AttachmentStrategy * AttachmentStrategy::create( const QString & type ) {
229  const QString lowerType = type.toLower();
230  if ( lowerType == QLatin1String( "iconic" ) ) return iconic();
231  //if ( lowerType == "smart" ) return smart(); // not needed, see below
232  if ( lowerType == QLatin1String( "inlined" ) ) return inlined();
233  if ( lowerType == QLatin1String( "hidden" ) ) return hidden();
234  if ( lowerType == QLatin1String( "headeronly" ) ) return headerOnly();
235  // don't kFatal here, b/c the strings are user-provided
236  // (KConfig), so fail gracefully to the default:
237  return smart();
238 }
239 
240 static const AttachmentStrategy * iconicStrategy = 0;
241 static const AttachmentStrategy * smartStrategy = 0;
242 static const AttachmentStrategy * inlinedStrategy = 0;
243 static const AttachmentStrategy * hiddenStrategy = 0;
244 static const AttachmentStrategy * headerOnlyStrategy = 0;
245 
246 const AttachmentStrategy * AttachmentStrategy::iconic() {
247  if ( !iconicStrategy )
248  iconicStrategy = new IconicAttachmentStrategy();
249  return iconicStrategy;
250 }
251 
252 const AttachmentStrategy * AttachmentStrategy::smart() {
253  if ( !smartStrategy )
254  smartStrategy = new SmartAttachmentStrategy();
255  return smartStrategy;
256 }
257 
258 const AttachmentStrategy * AttachmentStrategy::inlined() {
259  if ( !inlinedStrategy )
260  inlinedStrategy = new InlinedAttachmentStrategy();
261  return inlinedStrategy;
262 }
263 
264 const AttachmentStrategy * AttachmentStrategy::hidden() {
265  if ( !hiddenStrategy )
266  hiddenStrategy = new HiddenAttachmentStrategy();
267  return hiddenStrategy;
268 }
269 
270 const AttachmentStrategy* AttachmentStrategy::headerOnly()
271 {
272  if ( !headerOnlyStrategy )
273  headerOnlyStrategy = new HeaderOnlyAttachmentStrategy();
274  return headerOnlyStrategy;
275 }
276 
277 }
MessageViewer::AttachmentStrategy::Iconic
Definition: attachmentstrategy.h:56
attachmentstrategy.h
MessageViewer::AttachmentStrategy::smart
static const AttachmentStrategy * smart()
Definition: attachmentstrategy.cpp:252
MessageViewer::hiddenStrategy
static const AttachmentStrategy * hiddenStrategy
Definition: attachmentstrategy.cpp:243
MessageViewer::smartDisplay
static AttachmentStrategy::Display smartDisplay(KMime::Content *node)
Definition: attachmentstrategy.cpp:47
MessageViewer::AttachmentStrategy::hidden
static const AttachmentStrategy * hidden()
Definition: attachmentstrategy.cpp:264
MessageViewer::AttachmentStrategy::AttachmentStrategy
AttachmentStrategy()
Definition: attachmentstrategy.cpp:207
MessageViewer::AttachmentStrategy::Inlined
Definition: attachmentstrategy.h:56
MessageViewer::AttachmentStrategy::headerOnly
static const AttachmentStrategy * headerOnly()
Definition: attachmentstrategy.cpp:270
nodehelper.h
MessageViewer::iconicStrategy
static const AttachmentStrategy * iconicStrategy
Definition: attachmentstrategy.cpp:240
MessageViewer::AttachmentStrategy::None
Definition: attachmentstrategy.h:79
MessageViewer::headerOnlyStrategy
static const AttachmentStrategy * headerOnlyStrategy
Definition: attachmentstrategy.cpp:244
MessageViewer::AttachmentStrategy::Type
Type
Definition: attachmentstrategy.h:56
MessageViewer::AttachmentStrategy::Display
Display
Definition: attachmentstrategy.h:79
MessageViewer::AttachmentStrategy::Hidden
Definition: attachmentstrategy.h:56
MessageViewer::AttachmentStrategy::inlined
static const AttachmentStrategy * inlined()
Definition: attachmentstrategy.cpp:258
MessageViewer::AttachmentStrategy::create
static const AttachmentStrategy * create(Type type)
Definition: attachmentstrategy.cpp:215
MessageViewer::inlinedStrategy
static const AttachmentStrategy * inlinedStrategy
Definition: attachmentstrategy.cpp:242
MessageViewer::AttachmentStrategy::Smart
Definition: attachmentstrategy.h:56
MessageViewer::AttachmentStrategy::HeaderOnly
Definition: attachmentstrategy.h:56
MessageViewer::AttachmentStrategy::~AttachmentStrategy
virtual ~AttachmentStrategy()
Definition: attachmentstrategy.cpp:211
MessageViewer::AttachmentStrategy::Inline
Definition: attachmentstrategy.h:79
type
const char * type
Definition: bodypartformatter.cpp:192
MessageViewer::AttachmentStrategy
Definition: attachmentstrategy.h:46
MessageViewer::AttachmentStrategy::iconic
static const AttachmentStrategy * iconic()
Definition: attachmentstrategy.cpp:246
MessageViewer::smartStrategy
static const AttachmentStrategy * smartStrategy
Definition: attachmentstrategy.cpp:241
MessageViewer::NodeHelper::isInEncapsulatedMessage
static bool isInEncapsulatedMessage(KMime::Content *node)
Definition: nodehelper.cpp:350
MessageViewer::AttachmentStrategy::AsIcon
Definition: attachmentstrategy.h:79
MessageViewer::NodeHelper::attachmentDisplayInfo
static AttachmentDisplayInfo attachmentDisplayInfo(KMime::Content *node)
Definition: nodehelper.cpp:899
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