kmail

partNode.h
1 /*
2  partNode.h A node in a MIME tree.
3 
4  This file is part of KMail, the KDE mail client.
5  Copyright (c) 2002,2004 Klarälvdalens Datakonsult AB
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 #ifndef PARTNODE_H
33 #define PARTNODE_H
34 
35 #include "kmmsgpart.h"
36 #include "kmmsgbase.h"
37 #include "kmmessage.h"
38 
39 #include "interfaces/bodypart.h"
40 
41 #include <mimelib/mimepp.h>
42 #include <mimelib/body.h>
43 #include <mimelib/utility.h>
44 
45 #include <tdeio/global.h>
46 #include <kdebug.h>
47 
48 #include <map>
49 
50 class KMMimePartTreeItem;
51 class KMMimePartTree;
52 
53 class KMReaderWin;
54 
55 /*
56  ===========================================================================
57 
58 
59  S T A R T O F T E M P O R A R Y M I M E C O D E
60 
61 
62  ===========================================================================
63  N O T E : The partNode structure will most likely be replaced by KMime.
64  It's purpose: Speed optimization for KDE 3. (khz, 28.11.01)
65  ===========================================================================
66 */
67 class partNode
68 {
69  partNode();
70 
71  int calcNodeIdOrFindNode( int& curId, const partNode* calcNode,
72  int findId, partNode** findNode );
73 
74  partNode( KMReaderWin * win, DwBodyPart* dwPart,
75  int explicitType = DwMime::kTypeUnknown,
76  int explicitSubType = DwMime::kSubtypeUnknown,
77  bool deleteDwBodyPart = false );
78 
79 public:
80 
81  struct AttachmentDisplayInfo
82  {
83  TQString label;
84  TQString icon;
85  bool displayInHeader;
86  };
87 
88  static partNode * fromMessage( const KMMessage * msg, KMReaderWin * win=0 );
89 
90  partNode( bool deleteDwBodyPart,
91  DwBodyPart* dwPart );
92 
93  ~partNode();
94 
95  void dump( int chars=0 ) const;
96 
97  void buildObjectTree( bool processSiblings=true );
98 
99  DwBodyPart* dwPart() const {
100  return mDwPart;
101  }
102 
103  void setDwPart( DwBodyPart* part ) {
104  mDwPart = part;
105  mMsgPartOk = false;
106  }
107 
108  KMMessagePart& msgPart() const {
109  if( !mMsgPartOk ) {
110  KMMessage::bodyPart(mDwPart, &mMsgPart);
111  mMsgPartOk = true;
112  }
113  return mMsgPart;
114  }
115 
116  const TQCString & encodedBody();
117 
118  void setType( int type ) {
119  mType = type;
120  }
121 
122  void setSubType( int subType ) {
123  mSubType = subType;
124  }
125 
126  int type() const {
127  return mType;
128  }
129 
130  TQCString typeString() const;
131 
132  int subType() const {
133  return mSubType;
134  }
135 
136  TQCString subTypeString() const;
137 
138  bool hasType( int type ) {
139  return mType == type;
140  }
141 
142  bool hasSubType( int subType ) {
143  return mSubType == subType;
144  }
145 
146  void setEncryptionState( KMMsgEncryptionState state ) {
147  mEncryptionState = state;
148  }
149  KMMsgEncryptionState encryptionState() const {
150  return mEncryptionState;
151  }
152 
153  // look at the encryption states of all children and return result
154  KMMsgEncryptionState overallEncryptionState() const ;
155 
156  // look at the signature states of all children and return result
157  KMMsgSignatureState overallSignatureState() const ;
158 
159  void setSignatureState( KMMsgSignatureState state ) {
160  mSignatureState = state;
161  }
162  KMMsgSignatureState signatureState() const {
163  return mSignatureState;
164  }
165 
166  // path is a hierarchical path to this partNode. It is designed to
167  // be stable under decryption, where new child nodes are
168  // added. Treat it as an opaque string.
169  TQCString path() const;
170 
171  int nodeId() const; // node ids start at 1 (this is the top level root node)
172 
173  partNode* findId( int id ); // returns the node which has the given id (or 0, resp.)
174 
175  partNode* findType( int type, int subType, bool deep=true, bool wide=true );
176 
177  partNode* findTypeNot( int type, int subType, bool deep=true,
178  bool wide=true );
179 
180  partNode* findNodeForDwPart( DwBodyPart* part );
181 
182  void fillMimePartTree( KMMimePartTreeItem* parentItem,
183  KMMimePartTree* mimePartTree,
184  TQString labelDescr = TQString(),
185  TQString labelCntType = TQString(),
186  TQString labelEncoding = TQString(),
187  TDEIO::filesize_t size=0,
188  bool revertOrder = false );
189 
190  void adjustDefaultType( partNode* node );
191 
192  void setNext( partNode* next ) {
193  mNext = next;
194  if( mNext ){
195  mNext->mRoot = mRoot;
196  adjustDefaultType( mNext );
197  }
198  }
199 
200  void setFirstChild( partNode* child ) {
201  mChild = child;
202  if( mChild ) {
203  mChild->mRoot = this;
204  adjustDefaultType( mChild );
205  }
206  }
207 
208  void setProcessed( bool processed, bool recurse ) {
209  mWasProcessed = processed;
210  if ( recurse ) {
211  if( mChild )
212  mChild->setProcessed( processed, true );
213  if( mNext )
214  mNext->setProcessed( processed, true );
215  }
216  }
217 
218  void setMimePartTreeItem( KMMimePartTreeItem* item ) {
219  mMimePartTreeItem = item;
220  }
221 
222  KMMimePartTreeItem* mimePartTreeItem() const {
223  return mMimePartTreeItem;
224  }
225 
226  void setFromAddress( const TQString& address ) {
227  mFromAddress = address;
228  }
229 
230  bool isAttachment() const;
231  bool isHeuristicalAttachment() const;
235  bool isFirstTextPart() const;
236 
237  bool isToltecMessage() const;
238 
242  bool isInEncapsulatedMessage() const;
243 
244  bool hasContentDispositionInline() const;
245 
246  TQString contentTypeParameter( const char * name ) const;
247 
248  const TQString& trueFromAddress() const;
249 
250  const partNode * topLevelParent() const;
251  partNode * parentNode() const { return mRoot; }
252  partNode * nextSibling() const { return mNext; }
253  partNode * firstChild() const { return mChild; }
254  partNode * next( bool allowChildren=true ) const;
255  int childCount() const;
256  int totalChildCount() const;
257  bool processed() const { return mWasProcessed; }
258 
259  KMail::Interface::BodyPartMemento * bodyPartMemento( const TQCString & which ) const;
260  void setBodyPartMemento( const TQCString & which, KMail::Interface::BodyPartMemento * memento );
261 
262  // A flag to remember if the node was embedded. This is useful for attachment nodes, the reader
263  // needs to know if they were displayed inline or not.
264  bool isDisplayedEmbedded() const;
265  void setDisplayedEmbedded( bool displayedEmbedded );
266 
267  // Same as above, but this time determines if the node was hidden or not
268  bool isDisplayedHidden() const;
269  void setDisplayedHidden( bool displayedHidden );
270 
271  // Get a href in the form attachment:<nodeId>?place=<place>, used by ObjectTreeParser and
272  // UrlHandlerManager.
273  TQString asHREF( const TQString &place ) const;
274 
275  AttachmentDisplayInfo attachmentDisplayInfo() const;
276 
277 private:
278  KMReaderWin * reader() const {
279  return mReader ? mReader : mRoot ? mRoot->reader() : 0 ;
280  }
281  KMail::Interface::BodyPartMemento * internalBodyPartMemento( const TQCString & ) const;
282  void internalSetBodyPartMemento( const TQCString & which, KMail::Interface::BodyPartMemento * memento );
283 
284 private:
285  partNode* mRoot;
286  partNode* mNext;
287  partNode* mChild;
288  bool mWasProcessed; // to be used by parseObjectTree()
289 private:
290  DwBodyPart* mDwPart; // may be zero
291  mutable KMMessagePart mMsgPart; // is valid - even if mDwPart is zero
292  TQCString mEncodedBody;
293  TQString mFromAddress;
294  int mType;
295  int mSubType;
296  KMMsgEncryptionState mEncryptionState;
297  KMMsgSignatureState mSignatureState;
298  mutable bool mMsgPartOk;
299  bool mEncodedOk;
300  bool mDeleteDwBodyPart;
301  KMMimePartTreeItem* mMimePartTreeItem;
302  std::map<TQCString,KMail::Interface::BodyPartMemento*> mBodyPartMementoMap;
303  KMReaderWin * mReader;
304  bool mDisplayedEmbedded;
305  bool mDisplayedHidden;
306 };
307 
308 #endif
This is a Mime Message.
Definition: kmmessage.h:68
static void bodyPart(DwBodyPart *aDwBodyPart, KMMessagePart *aPart, bool withBody=true)
Fill the KMMessagePart structure for a given DwBodyPart.
Definition: kmmessage.cpp:3110
This class implements a "reader window", that is a window used for reading or viewing messages.
Definition: kmreaderwin.h:75
interface of classes that implement status for BodyPartFormatters.
Definition: bodypart.h:51