[prev in list] [next in list] [prev in thread] [next in thread]
List: kmail-devel
Subject: [PATCH] unify (and change) planting of partNode trees
From: Marc Mutz <mutz () kde ! org>
Date: 2004-01-17 21:55:16
Message-ID: 200401172255.21711.mutz () kde ! org
[Download RAW message or body]
[Attachment #2 (multipart/signed)]
[Attachment #4 (multipart/mixed)]
Hi!
This patch refactors the creation of a partNode tree from a KMMessage
object from three places into a new static member on partNode. It's
already committed to aegypten_branch, but please check it out
nonetheless. The change (after two iterations of the patch) basically
boils down to: We want the DwMessage to be a DwBodyPart, so make it
one. For more information read the patch and the two commit logs in
ae_b.
Marc
--
If free-software authors lose the right to disclaim all warranties and
find themselves getting sued over the performance of the programs
they've written, they'll stop contributing free software to the world.
-- Bruce Perens: Open Sources: Voices from the Open Source Revolution
["partNode-planting.diff" (text/x-diff)]
Index: partNode.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/partNode.cpp,v
retrieving revision 1.41.2.1
retrieving revision 1.41.2.3
diff -u -3 -p -r1.41.2.1 -r1.41.2.3
--- partNode.cpp 16 Jan 2004 20:33:04 -0000 1.41.2.1
+++ partNode.cpp 17 Jan 2004 19:24:37 -0000 1.41.2.3
@@ -101,6 +101,34 @@ partNode::partNode( DwBodyPart* dwPart,
#endif
}
+partNode * partNode::fromMessage( const KMMessage * msg ) {
+ if ( !msg )
+ return 0;
+
+ int mainType = msg->type();
+ int mainSubType = msg->subtype();
+ if( (DwMime::kTypeNull == mainType)
+ || (DwMime::kTypeUnknown == mainType) ){
+ mainType = DwMime::kTypeText;
+ mainSubType = DwMime::kSubtypePlain;
+ }
+
+ // we don't want to treat the top-level part special. mimelib does
+ // (Message vs. BodyPart, with common base class Entity). But we
+ // used DwBodyPart, not DwEntiy everywhere. *shrug*. DwStrings are
+ // subscrib-shared, so we just force mimelib to parse the whole mail
+ // as just another DwBodyPart...
+ DwBodyPart * mainBody = new DwBodyPart( msg->asDwString(), 0 );
+ mainBody->Parse();
+
+ partNode * root = new partNode( mainBody, mainType, mainSubType, true );
+ root->buildObjectTree();
+
+ root->setFromAddress( msg->from() );
+ root->dump();
+ return root;
+}
+
partNode::partNode( bool deleteDwBodyPart, DwBodyPart* dwPart )
: mRoot( 0 ), mNext( 0 ), mChild( 0 ),
mWasProcessed( false ),
Index: kmcommands.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmcommands.cpp,v
retrieving revision 1.87.2.7
retrieving revision 1.87.2.8
diff -u -3 -p -r1.87.2.7 -r1.87.2.8
--- kmcommands.cpp 17 Jan 2004 11:34:22 -0000 1.87.2.7
+++ kmcommands.cpp 17 Jan 2004 14:38:18 -0000 1.87.2.8
@@ -1710,39 +1710,10 @@ void KMSaveAttachmentsCommand::execute()
}
KMMessage *msg = 0;
QPtrList<KMMessage> lst = retrievedMsgs();
- QPtrListIterator<KMMessage> itr( lst );
-
- while ( itr.current() ) {
- msg = itr.current();
- ++itr;
-
- int mainType = msg->type();
- int mainSubType = msg->subtype();
- DwBodyPart* mainBody = 0;
- DwBodyPart* firstBodyPart = msg->getFirstDwBodyPart();
- if( !firstBodyPart ) {
- // ATTENTION: This definitely /should/ be optimized.
- // Copying the message text into a new body part
- // surely is not the most efficient way to go.
- // I decided to do so for being able to get a
- // solution working for old style (== non MIME)
- // mails without spending much time on implementing.
- // During code revisal when switching to KMime
- // all this will probably disappear anyway (or it
- // will be optimized, resp.). (khz, 6.12.2001)
- kdDebug(5006) << "*no* first body part found, creating one from Message" << endl;
- mainBody = new DwBodyPart( msg->asDwString(), 0 );
- mainBody->Parse();
- }
- partNode *rootNode = new partNode( mainBody, mainType, mainSubType, true );
- rootNode->setFromAddress( msg->from() );
-
- if ( firstBodyPart ) {
- partNode* curNode = new partNode(firstBodyPart);
- rootNode->setFirstChild( curNode );
- curNode->buildObjectTree();
- }
+ for ( QPtrListIterator<KMMessage> itr( lst ) ; itr.current() ; ++itr ) {
+ partNode *rootNode = partNode::fromMessage( itr.current() );
parse( rootNode );
+ // FIXME: delete rootNode; too early?
}
}
Index: kmmessage.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmmessage.cpp,v
retrieving revision 1.443.2.8
retrieving revision 1.443.2.9
diff -u -3 -p -r1.443.2.8 -r1.443.2.9
--- kmmessage.cpp 17 Jan 2004 11:34:22 -0000 1.443.2.8
+++ kmmessage.cpp 17 Jan 2004 14:38:17 -0000 1.443.2.9
@@ -647,32 +647,18 @@ static QString smartQuote( const QString
//-----------------------------------------------------------------------------
-void KMMessage::parseTextStringFromDwPart( DwBodyPart * mainBody,
- DwBodyPart * firstBodyPart,
+void KMMessage::parseTextStringFromDwPart( partNode * root,
QCString& parsedString,
const QTextCodec*& codec,
bool& isHTML ) const
{
isHTML = false;
- int mainType = type();
- int mainSubType = subtype();
- if( (DwMime::kTypeNull == mainType)
- || (DwMime::kTypeUnknown == mainType) ){
- mainType = DwMime::kTypeText;
- mainSubType = DwMime::kSubtypePlain;
- }
- partNode rootNode( mainBody, mainType, mainSubType);
- if ( firstBodyPart ) {
- partNode * curNode = new partNode( firstBodyPart );
- rootNode.setFirstChild( curNode );
- curNode->buildObjectTree();
- }
// initialy parse the complete message to decrypt any encrypted parts
{
ObjectTreeParser otp( 0, 0, true, false, true );
- otp.parseObjectTree( &rootNode );
+ otp.parseObjectTree( root );
}
- partNode * curNode = rootNode.findType( DwMime::kTypeText,
+ partNode * curNode = root->findType( DwMime::kTypeText,
DwMime::kSubtypeUnknown,
true,
false );
@@ -695,20 +681,9 @@ QString KMMessage::asPlainText( bool aSt
bool isHTML = false;
const QTextCodec * codec = 0;
- if ( numBodyParts() == 0 ) {
- DwBodyPart * mainBody = 0;
- DwBodyPart * firstBodyPart = getFirstDwBodyPart();
- if ( !firstBodyPart ) {
- mainBody = new DwBodyPart( asDwString(), 0 );
- mainBody->Parse();
- }
- parseTextStringFromDwPart( mainBody, firstBodyPart, parsedString, codec,
- isHTML );
- } else {
- DwBodyPart * dwPart = getFirstDwBodyPart();
- if ( dwPart )
- parseTextStringFromDwPart( 0, dwPart, parsedString, codec, isHTML );
- }
+ partNode * root = partNode::fromMessage( this );
+ parseTextStringFromDwPart( root, parsedString, codec, isHTML );
+ delete root;
if ( mOverrideCodec || !codec )
codec = this->codec();
Index: kmmessage.h
===================================================================
RCS file: /home/kde/kdepim/kmail/kmmessage.h,v
retrieving revision 1.156.2.1
retrieving revision 1.156.2.2
diff -u -3 -p -r1.156.2.1 -r1.156.2.2
--- kmmessage.h 19 Dec 2003 20:43:11 -0000 1.156.2.1
+++ kmmessage.h 17 Jan 2004 14:38:17 -0000 1.156.2.2
@@ -48,6 +48,8 @@ class DwBodyPart;
class DwMediaType;
class DwHeaders;
+class partNode;
+
namespace KMail {
enum ReplyStrategy { ReplySmart = 0,
ReplyAuthor,
@@ -261,8 +263,7 @@ public:
by function asQuotedString().
THIS FUNCTION WILL BE REPLACED ONCE KMime IS FULLY INTEGRATED
(khz, June 05 2002)*/
- void parseTextStringFromDwPart( DwBodyPart * mainBody,
- DwBodyPart * firstBodyPart,
+ void parseTextStringFromDwPart( partNode * root,
QCString& parsedString,
const QTextCodec*& codec,
bool& isHTML ) const;
Index: kmreaderwin.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmreaderwin.cpp,v
retrieving revision 1.721.2.7
retrieving revision 1.721.2.8
diff -u -3 -p -r1.721.2.7 -r1.721.2.8
--- kmreaderwin.cpp 17 Jan 2004 11:34:22 -0000 1.721.2.7
+++ kmreaderwin.cpp 17 Jan 2004 14:38:18 -0000 1.721.2.8
@@ -1087,43 +1087,9 @@ void KMReaderWin::parseMsg(KMMessage* aM
assert(aMsg!=0);
- int mainType = aMsg->type();
- int mainSubType = aMsg->subtype();
- QString mainCntTypeStr;
- if( (DwMime::kTypeNull == mainType)
- || (DwMime::kTypeUnknown == mainType) ){
- mainType = DwMime::kTypeText;
- mainSubType = DwMime::kSubtypePlain;
- mainCntTypeStr = "text/plain";
- } else {
- mainCntTypeStr = aMsg->typeStr() + '/' + aMsg->subtypeStr();
- }
-
- // store message body in mRootNode if *no* body parts found
- // (please read the comment below before crying about me) :-)
- DwBodyPart* mainBody = 0;
- DwBodyPart* firstBodyPart = aMsg->getFirstDwBodyPart();
- if( !firstBodyPart ) {
- // ATTENTION: This definitely /should/ be optimized.
- // Copying the message text into a new body part
- // surely is not the most efficient way to go.
- // I decided to do so for being able to get a
- // solution working for old style (== non MIME)
- // mails without spending much time on implementing.
- // During code revisal when switching to KMime
- // all this will probably disappear anyway (or it
- // will be optimized, resp.). (khz, 6.12.2001)
- kdDebug(5006) << "*no* first body part found, creating one from Message" << endl;
- mainBody = new DwBodyPart(aMsg->asDwString(), 0);
- mainBody->Parse();
- }
-
delete mRootNode;
- if ( firstBodyPart && mainType == DwMime::kTypeText )
- mRootNode = new partNode( firstBodyPart );
- else
- mRootNode = new partNode( mainBody, mainType, mainSubType, true );
- mRootNode->setFromAddress( aMsg->from() );
+ mRootNode = partNode::fromMessage( aMsg );
+ const QCString mainCntTypeStr = mRootNode->typeString() + '/' + mRootNode->subTypeString();
QString cntDesc = aMsg->subject();
if( cntDesc.isEmpty() )
@@ -1135,29 +1101,13 @@ void KMReaderWin::parseMsg(KMMessage* aM
else
cntEnc = aMsg->contentTransferEncodingStr();
- if( firstBodyPart ) {
-kdDebug(5006) << "\n -----> First body part *was* found, filling the Mime Part Tree" << endl;
- // store pointers to the MIME objects in our fast access tree
- partNode* curNode = new partNode(firstBodyPart);
- mRootNode->setFirstChild( curNode );
- curNode->buildObjectTree();
- // fill the MIME part tree viewer
- mRootNode->fillMimePartTree( 0,
- mMimePartTree,
- cntDesc,
- mainCntTypeStr,
- cntEnc,
- cntSize );
- } else {
-kdDebug(5006) << "\n -----> Inserting Root Node into the Mime Part Tree" << endl;
- mRootNode->fillMimePartTree( 0,
- mMimePartTree,
- cntDesc,
- mainCntTypeStr,
- cntEnc,
- cntSize );
-kdDebug(5006) << "\n <----- Finished inserting Root Node into Mime Part Tree" << endl;
- }
+ // fill the MIME part tree viewer
+ mRootNode->fillMimePartTree( 0,
+ mMimePartTree,
+ cntDesc,
+ mainCntTypeStr,
+ cntEnc,
+ cntSize );
partNode* vCardNode = mRootNode->findType( DwMime::kTypeText, DwMime::kSubtypeXVCard );
bool hasVCard = false;
Index: partNode.h
===================================================================
RCS file: /home/kde/kdepim/kmail/partNode.h,v
retrieving revision 1.30.2.1
retrieving revision 1.30.2.2
diff -u -3 -p -r1.30.2.1 -r1.30.2.2
--- partNode.h 16 Jan 2004 20:33:04 -0000 1.30.2.1
+++ partNode.h 17 Jan 2004 14:38:18 -0000 1.30.2.2
@@ -2,7 +2,7 @@
partNode.h A node in a MIME tree.
This file is part of KMail, the KDE mail client.
- Copyright (c) 2002 Klarälvdalens Datakonsult AB
+ Copyright (c) 2002,2004 Klarälvdalens Datakonsult AB
KMail is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
@@ -66,6 +66,8 @@ class partNode
int findId, partNode** findNode );
public:
+ static partNode * fromMessage( const KMMessage * msg );
+
partNode( DwBodyPart* dwPart,
int explicitType = DwMime::kTypeUnknown,
int explicitSubType = DwMime::kSubtypeUnknown,
["smime.p7s" (application/pkcs7-signature)]
_______________________________________________
KMail developers mailing list
KMail-devel@kde.org
https://mail.kde.org/mailman/listinfo/kmail-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic