kmail

bodyvisitor.cpp
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
4 
5 #include "bodyvisitor.h"
6 #include "kmmsgpart.h"
7 #include "attachmentstrategy.h"
8 #include <kdebug.h>
9 
10 namespace KMail {
11 
12  BodyVisitor* BodyVisitorFactory::getVisitor( const AttachmentStrategy* strategy )
13  {
14  if (strategy == AttachmentStrategy::smart())
15  {
16  return new BodyVisitorSmart();
17  } else if (strategy == AttachmentStrategy::iconic())
18  {
19  return new BodyVisitorHidden();
20  } else if (strategy == AttachmentStrategy::inlined())
21  {
22  return new BodyVisitorInline();
23  } else if (strategy == AttachmentStrategy::hidden())
24  {
25  return new BodyVisitorHidden();
26  }
27  // default
28  return new BodyVisitorSmart();
29  }
30 
31  //=============================================================================
32 
33  BodyVisitor::BodyVisitor()
34  {
35  // parts that are probably always ok to load
36  mBasicList.clear();
37  // body text
38  mBasicList += "TEXT/PLAIN";
39  mBasicList += "TEXT/HTML";
40  mBasicList += "MESSAGE/DELIVERY-STATUS";
41  // pgp stuff
42  mBasicList += "APPLICATION/PGP-SIGNATURE";
43  mBasicList += "APPLICATION/PGP";
44  mBasicList += "APPLICATION/PGP-ENCRYPTED";
45  mBasicList += "APPLICATION/PKCS7-SIGNATURE";
46  // groupware
47  mBasicList += "APPLICATION/MS-TNEF";
48  mBasicList += "TEXT/CALENDAR";
49  mBasicList += "TEXT/X-VCARD";
50  }
51 
52  //-----------------------------------------------------------------------------
53  BodyVisitor::~BodyVisitor()
54  {
55  }
56 
57  //-----------------------------------------------------------------------------
58  void BodyVisitor::visit( KMMessagePart * part )
59  {
60  mParts.append( part );
61  }
62 
63  //-----------------------------------------------------------------------------
64  void BodyVisitor::visit( TQPtrList<KMMessagePart> & list )
65  {
66  mParts = list;
67  }
68 
69  //-----------------------------------------------------------------------------
70  TQPtrList<KMMessagePart> BodyVisitor::partsToLoad()
71  {
72  TQPtrListIterator<KMMessagePart> it( mParts );
73  TQPtrList<KMMessagePart> selected;
74  KMMessagePart *part = 0;
75  bool headerCheck = false;
76  while ( (part = it.current()) != 0 )
77  {
78  ++it;
79  // skip this part if the parent part is already loading
80  if ( part->parent() &&
81  selected.contains( part->parent() ) &&
82  part->loadPart() )
83  continue;
84 
85  if ( part->originalContentTypeStr().contains("SIGNED") )
86  {
87  // signed messages have to be loaded completely
88  // so construct a new dummy part that loads the body
89  KMMessagePart *fake = new KMMessagePart();
90  fake->setPartSpecifier( "TEXT" );
91  fake->setOriginalContentTypeStr("");
92  fake->setLoadPart( true );
93  selected.append( fake );
94  break;
95  }
96 
97  if ( headerCheck && !part->partSpecifier().endsWith(".HEADER") )
98  {
99  // this is an embedded simple message (not multipart) so we get no header part
100  // from imap. As we probably need to load the header (e.g. in smart or inline mode)
101  // we add a fake part that is not included in the message itself
102  KMMessagePart *fake = new KMMessagePart();
103  TQString partId = part->partSpecifier().section( '.', 0, -2 )+".HEADER";
104  fake->setPartSpecifier( partId );
105  fake->setOriginalContentTypeStr("");
106  fake->setLoadPart( true );
107  if ( addPartToList( fake ) )
108  selected.append( fake );
109  }
110 
111  if ( part->originalContentTypeStr() == "MESSAGE/RFC822" )
112  headerCheck = true;
113  else
114  headerCheck = false;
115 
116  // check whether to load this part or not:
117  // look at the basic list, ask the subclass and check the parent
118  if ( mBasicList.contains( part->originalContentTypeStr() ) ||
119  parentNeedsLoading( part ) ||
120  addPartToList( part ) )
121  {
122  if ( part->typeStr() != "MULTIPART" ||
123  part->partSpecifier().endsWith(".HEADER") )
124  {
125  // load the part itself
126  part->setLoadPart( true );
127  }
128  }
129  if ( !part->partSpecifier().endsWith(".HEADER") &&
130  part->typeStr() != "MULTIPART" )
131  part->setLoadHeaders( true ); // load MIME header
132 
133  if ( part->loadHeaders() || part->loadPart() )
134  selected.append( part );
135  }
136  return selected;
137  }
138 
139  //-----------------------------------------------------------------------------
140  bool BodyVisitor::parentNeedsLoading( KMMessagePart *msgPart )
141  {
142  KMMessagePart *part = msgPart;
143  while ( part )
144  {
145  if ( part->parent() &&
146  ( part->parent()->originalContentTypeStr() == "MULTIPART/SIGNED" ||
147  ( msgPart->originalContentTypeStr() == "APPLICATION/OCTET-STREAM" &&
148  part->parent()->originalContentTypeStr() == "MULTIPART/ENCRYPTED" ) ) )
149  return true;
150 
151  part = part->parent();
152  }
153  return false;
154  }
155 
156  //=============================================================================
157 
158  BodyVisitorSmart::BodyVisitorSmart()
159  : BodyVisitor()
160  {
161  }
162 
163  //-----------------------------------------------------------------------------
164  bool BodyVisitorSmart::addPartToList( KMMessagePart * part )
165  {
166  // header of an encapsulated message
167  if ( part->partSpecifier().endsWith(".HEADER") )
168  return true;
169 
170  return false;
171  }
172 
173  //=============================================================================
174 
175  BodyVisitorInline::BodyVisitorInline()
176  : BodyVisitor()
177  {
178  }
179 
180  //-----------------------------------------------------------------------------
181  bool BodyVisitorInline::addPartToList( KMMessagePart * part )
182  {
183  // header of an encapsulated message
184  if ( part->partSpecifier().endsWith(".HEADER") )
185  return true;
186  else if ( part->typeStr() == "IMAGE" ) // images
187  return true;
188  else if ( part->typeStr() == "TEXT" ) // text, diff and stuff
189  return true;
190 
191  return false;
192  }
193 
194  //=============================================================================
195 
196  BodyVisitorHidden::BodyVisitorHidden()
197  : BodyVisitor()
198  {
199  }
200 
201  //-----------------------------------------------------------------------------
202  bool BodyVisitorHidden::addPartToList( KMMessagePart * part )
203  {
204  // header of an encapsulated message
205  if ( part->partSpecifier().endsWith(".HEADER") )
206  return true;
207 
208  return false;
209  }
210 
211 }
folderdiaquotatab.h
Definition: aboutdata.cpp:40