kmail

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