From 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kmail/bodyvisitor.cpp | 211 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 kmail/bodyvisitor.cpp (limited to 'kmail/bodyvisitor.cpp') diff --git a/kmail/bodyvisitor.cpp b/kmail/bodyvisitor.cpp new file mode 100644 index 00000000..99af6619 --- /dev/null +++ b/kmail/bodyvisitor.cpp @@ -0,0 +1,211 @@ +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "bodyvisitor.h" +#include "kmmsgpart.h" +#include "attachmentstrategy.h" +#include + +namespace KMail { + + BodyVisitor* BodyVisitorFactory::getVisitor( const AttachmentStrategy* strategy ) + { + if (strategy == AttachmentStrategy::smart()) + { + return new BodyVisitorSmart(); + } else if (strategy == AttachmentStrategy::iconic()) + { + return new BodyVisitorHidden(); + } else if (strategy == AttachmentStrategy::inlined()) + { + return new BodyVisitorInline(); + } else if (strategy == AttachmentStrategy::hidden()) + { + return new BodyVisitorHidden(); + } + // default + return new BodyVisitorSmart(); + } + + //============================================================================= + + BodyVisitor::BodyVisitor() + { + // parts that are probably always ok to load + mBasicList.clear(); + // body text + mBasicList += "TEXT/PLAIN"; + mBasicList += "TEXT/HTML"; + mBasicList += "MESSAGE/DELIVERY-STATUS"; + // pgp stuff + mBasicList += "APPLICATION/PGP-SIGNATURE"; + mBasicList += "APPLICATION/PGP"; + mBasicList += "APPLICATION/PGP-ENCRYPTED"; + mBasicList += "APPLICATION/PKCS7-SIGNATURE"; + // groupware + mBasicList += "APPLICATION/MS-TNEF"; + mBasicList += "TEXT/CALENDAR"; + mBasicList += "TEXT/X-VCARD"; + } + + //----------------------------------------------------------------------------- + BodyVisitor::~BodyVisitor() + { + } + + //----------------------------------------------------------------------------- + void BodyVisitor::visit( KMMessagePart * part ) + { + mParts.append( part ); + } + + //----------------------------------------------------------------------------- + void BodyVisitor::visit( QPtrList & list ) + { + mParts = list; + } + + //----------------------------------------------------------------------------- + QPtrList BodyVisitor::partsToLoad() + { + QPtrListIterator it( mParts ); + QPtrList selected; + KMMessagePart *part = 0; + bool headerCheck = false; + while ( (part = it.current()) != 0 ) + { + ++it; + // skip this part if the parent part is already loading + if ( part->parent() && + selected.contains( part->parent() ) && + part->loadPart() ) + continue; + + if ( part->originalContentTypeStr().contains("SIGNED") ) + { + // signed messages have to be loaded completely + // so construct a new dummy part that loads the body + KMMessagePart *fake = new KMMessagePart(); + fake->setPartSpecifier( "TEXT" ); + fake->setOriginalContentTypeStr(""); + fake->setLoadPart( true ); + selected.append( fake ); + break; + } + + if ( headerCheck && !part->partSpecifier().endsWith(".HEADER") ) + { + // this is an embedded simple message (not multipart) so we get no header part + // from imap. As we probably need to load the header (e.g. in smart or inline mode) + // we add a fake part that is not included in the message itself + KMMessagePart *fake = new KMMessagePart(); + QString partId = part->partSpecifier().section( '.', 0, -2 )+".HEADER"; + fake->setPartSpecifier( partId ); + fake->setOriginalContentTypeStr(""); + fake->setLoadPart( true ); + if ( addPartToList( fake ) ) + selected.append( fake ); + } + + if ( part->originalContentTypeStr() == "MESSAGE/RFC822" ) + headerCheck = true; + else + headerCheck = false; + + // check whether to load this part or not: + // look at the basic list, ask the subclass and check the parent + if ( mBasicList.contains( part->originalContentTypeStr() ) || + parentNeedsLoading( part ) || + addPartToList( part ) ) + { + if ( part->typeStr() != "MULTIPART" || + part->partSpecifier().endsWith(".HEADER") ) + { + // load the part itself + part->setLoadPart( true ); + } + } + if ( !part->partSpecifier().endsWith(".HEADER") && + part->typeStr() != "MULTIPART" ) + part->setLoadHeaders( true ); // load MIME header + + if ( part->loadHeaders() || part->loadPart() ) + selected.append( part ); + } + return selected; + } + + //----------------------------------------------------------------------------- + bool BodyVisitor::parentNeedsLoading( KMMessagePart *msgPart ) + { + KMMessagePart *part = msgPart; + while ( part ) + { + if ( part->parent() && + ( part->parent()->originalContentTypeStr() == "MULTIPART/SIGNED" || + ( msgPart->originalContentTypeStr() == "APPLICATION/OCTET-STREAM" && + part->parent()->originalContentTypeStr() == "MULTIPART/ENCRYPTED" ) ) ) + return true; + + part = part->parent(); + } + return false; + } + + //============================================================================= + + BodyVisitorSmart::BodyVisitorSmart() + : BodyVisitor() + { + } + + //----------------------------------------------------------------------------- + bool BodyVisitorSmart::addPartToList( KMMessagePart * part ) + { + // header of an encapsulated message + if ( part->partSpecifier().endsWith(".HEADER") ) + return true; + + return false; + } + + //============================================================================= + + BodyVisitorInline::BodyVisitorInline() + : BodyVisitor() + { + } + + //----------------------------------------------------------------------------- + bool BodyVisitorInline::addPartToList( KMMessagePart * part ) + { + // header of an encapsulated message + if ( part->partSpecifier().endsWith(".HEADER") ) + return true; + else if ( part->typeStr() == "IMAGE" ) // images + return true; + else if ( part->typeStr() == "TEXT" ) // text, diff and stuff + return true; + + return false; + } + + //============================================================================= + + BodyVisitorHidden::BodyVisitorHidden() + : BodyVisitor() + { + } + + //----------------------------------------------------------------------------- + bool BodyVisitorHidden::addPartToList( KMMessagePart * part ) + { + // header of an encapsulated message + if ( part->partSpecifier().endsWith(".HEADER") ) + return true; + + return false; + } + +} -- cgit v1.2.3