5 #include "bodyvisitor.h"
7 #include "attachmentstrategy.h"
12 BodyVisitor* BodyVisitorFactory::getVisitor(
const AttachmentStrategy* strategy )
14 if (strategy == AttachmentStrategy::smart())
16 return new BodyVisitorSmart();
17 }
else if (strategy == AttachmentStrategy::iconic())
19 return new BodyVisitorHidden();
20 }
else if (strategy == AttachmentStrategy::inlined())
22 return new BodyVisitorInline();
23 }
else if (strategy == AttachmentStrategy::hidden())
25 return new BodyVisitorHidden();
28 return new BodyVisitorSmart();
33 BodyVisitor::BodyVisitor()
38 mBasicList +=
"TEXT/PLAIN";
39 mBasicList +=
"TEXT/HTML";
40 mBasicList +=
"MESSAGE/DELIVERY-STATUS";
42 mBasicList +=
"APPLICATION/PGP-SIGNATURE";
43 mBasicList +=
"APPLICATION/PGP";
44 mBasicList +=
"APPLICATION/PGP-ENCRYPTED";
45 mBasicList +=
"APPLICATION/PKCS7-SIGNATURE";
47 mBasicList +=
"APPLICATION/MS-TNEF";
48 mBasicList +=
"TEXT/CALENDAR";
49 mBasicList +=
"TEXT/X-VCARD";
53 BodyVisitor::~BodyVisitor()
58 void BodyVisitor::visit( KMMessagePart * part )
60 mParts.append( part );
64 void BodyVisitor::visit( TQPtrList<KMMessagePart> & list )
70 TQPtrList<KMMessagePart> BodyVisitor::partsToLoad()
72 TQPtrListIterator<KMMessagePart> it( mParts );
73 TQPtrList<KMMessagePart> selected;
74 KMMessagePart *part = 0;
75 bool headerCheck =
false;
76 while ( (part = it.current()) != 0 )
80 if ( part->parent() &&
81 selected.contains( part->parent() ) &&
85 if ( part->originalContentTypeStr().contains(
"SIGNED") )
89 KMMessagePart *fake =
new KMMessagePart();
90 fake->setPartSpecifier(
"TEXT" );
91 fake->setOriginalContentTypeStr(
"");
92 fake->setLoadPart(
true );
93 selected.append( fake );
97 if ( headerCheck && !part->partSpecifier().endsWith(
".HEADER") )
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 );
111 if ( part->originalContentTypeStr() ==
"MESSAGE/RFC822" )
118 if ( mBasicList.contains( part->originalContentTypeStr() ) ||
119 parentNeedsLoading( part ) ||
120 addPartToList( part ) )
122 if ( part->typeStr() !=
"MULTIPART" ||
123 part->partSpecifier().endsWith(
".HEADER") )
126 part->setLoadPart(
true );
129 if ( !part->partSpecifier().endsWith(
".HEADER") &&
130 part->typeStr() !=
"MULTIPART" )
131 part->setLoadHeaders(
true );
133 if ( part->loadHeaders() || part->loadPart() )
134 selected.append( part );
140 bool BodyVisitor::parentNeedsLoading( KMMessagePart *msgPart )
142 KMMessagePart *part = msgPart;
145 if ( part->parent() &&
146 ( part->parent()->originalContentTypeStr() ==
"MULTIPART/SIGNED" ||
147 ( msgPart->originalContentTypeStr() ==
"APPLICATION/OCTET-STREAM" &&
148 part->parent()->originalContentTypeStr() ==
"MULTIPART/ENCRYPTED" ) ) )
151 part = part->parent();
158 BodyVisitorSmart::BodyVisitorSmart()
164 bool BodyVisitorSmart::addPartToList( KMMessagePart * part )
167 if ( part->partSpecifier().endsWith(
".HEADER") )
175 BodyVisitorInline::BodyVisitorInline()
181 bool BodyVisitorInline::addPartToList( KMMessagePart * part )
184 if ( part->partSpecifier().endsWith(
".HEADER") )
186 else if ( part->typeStr() ==
"IMAGE" )
188 else if ( part->typeStr() ==
"TEXT" )
196 BodyVisitorHidden::BodyVisitorHidden()
202 bool BodyVisitorHidden::addPartToList( KMMessagePart * part )
205 if ( part->partSpecifier().endsWith(
".HEADER") )