From ddaac140fa1f2ceb26cb61417aa43624fe685e4a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 20 Jan 2004 12:42:56 +0000 Subject: [PATCH] from aegytpen_branch: Small cleanup. Get rid of partNode::CryptoType, which wasn't used for anything. Determine the CryptPlug to use for mp/signed by looking at the protocol parameter instead of searching for app/{pgp,pkcs7}-signature children. (without the CryptPlugFactory) --and-- candidate_for_3_2_1: Don't interpret application/pkcs7-mime; smime-type=certs-only as a signed message, but show an icon instead (until we have integrated enough of gpgme to be able to show a nice summary of the import as inline HTML). svn path=/trunk/kdepim/; revision=281273 --- objecttreeparser.cpp | 28 ++++++++++------------------ partNode.cpp | 35 ++++++++++++++++++++++------------- partNode.h | 25 +++---------------------- 3 files changed, 35 insertions(+), 53 deletions(-) diff --git a/objecttreeparser.cpp b/objecttreeparser.cpp index b0f91e70c..7dfd77504 100644 --- a/objecttreeparser.cpp +++ b/objecttreeparser.cpp @@ -295,15 +295,9 @@ namespace KMail { void ProcessResult::adjustCryptoStatesOfNode( partNode * node ) const { if ( ( inlineSignatureState() != KMMsgNotSigned ) || ( inlineEncryptionState() != KMMsgNotEncrypted ) ) { - if ( partNode::CryptoTypeUnknown == node->cryptoType() - || partNode::CryptoTypeNone == node->cryptoType() ){ - node->setCryptoType( partNode::CryptoTypeInlinePGP ); - } node->setSignatureState( inlineSignatureState() ); node->setEncryptionState( inlineEncryptionState() ); } - if ( partNode::CryptoTypeUnknown == node->cryptoType() ) - node->setCryptoType( partNode::CryptoTypeNone ); } ////////////////// @@ -1151,7 +1145,6 @@ namespace KMail { data = child->findTypeNot( DwMime::kTypeApplication, DwMime::kSubtypePgpSignature, false, true ); if ( data ) { - node->setCryptoType( partNode::CryptoTypeOpenPgpMIME ); useThisCryptPlug = kmkernel->cryptPlugList()->findForLibName( "openpgp" ); } } else { @@ -1162,7 +1155,6 @@ namespace KMail { data = child->findTypeNot( DwMime::kTypeApplication, DwMime::kSubtypePkcs7Signature, false, true ); if ( data ) { - node->setCryptoType( partNode::CryptoTypeSMIME ); useThisCryptPlug = kmkernel->cryptPlugList()->findForLibName( "smime" ); } } else { @@ -1227,14 +1219,12 @@ namespace KMail { partNode * data = child->findType( DwMime::kTypeApplication, DwMime::kSubtypeOctetStream, false, true ); if ( data ) { - node->setCryptoType( partNode::CryptoTypeOpenPgpMIME ); useThisCryptPlug = kmkernel->cryptPlugList()->findForLibName( "openpgp" ); } if ( !data ) { data = child->findType( DwMime::kTypeApplication, DwMime::kSubtypePkcs7Mime, false, true ); if ( data ) { - node->setCryptoType( partNode::CryptoTypeSMIME ); useThisCryptPlug = kmkernel->cryptPlugList()->findForLibName( "smime" ); } } @@ -1400,7 +1390,6 @@ namespace KMail { && DwMime::kSubtypeEncrypted == node->parentNode()->subType() ) { kdDebug(5006) << "\n-----> Initially processing encrypted data\n" << endl; node->setEncryptionState( KMMsgFullyEncrypted ); - node->setCryptoType( partNode::CryptoTypeOpenPgpMIME ); if ( keepEncryptions() ) { const QCString cstr = node->msgPart().bodyDecoded(); if ( mReader ) @@ -1473,8 +1462,15 @@ namespace KMail { return true; } + const QString smimeType = node->contentTypeParameter("smime-type").lower(); + + if ( smimeType == "certs-only" ) { + // will become an icon: + result.setNeverDisplayInline( true ); + return false; + } + kdDebug(5006) << "\n-----> Initially processing signed and/or encrypted data\n" << endl; - node->setCryptoType( partNode::CryptoTypeSMIME ); if ( !node->dwPart() || !node->dwPart()->hasHeaders() ) return false; @@ -1483,12 +1479,8 @@ namespace KMail { return false; CryptPlugWrapperSaver cpws( this, smimeCrypto ); - DwHeaders & headers( node->dwPart()->Headers() ); - QCString ctypStr( headers.ContentType().AsString().c_str() ); - // ### ugh. - ctypStr.replace( "\"", "" ); - bool isSigned = 0 <= ctypStr.find("smime-type=signed-data", 0, false); - bool isEncrypted = 0 <= ctypStr.find("smime-type=enveloped-data", 0, false); + bool isSigned = smimeType == "signed-data"; + bool isEncrypted = smimeType == "enveloped-data"; // Analyze "signTestNode" node to find/verify a signature. // If zero this verification was successfully done after diff --git a/partNode.cpp b/partNode.cpp index 0ab3a9803..21a0cb1b7 100644 --- a/partNode.cpp +++ b/partNode.cpp @@ -56,7 +56,6 @@ partNode::partNode() mDwPart( 0 ), mType( DwMime::kTypeUnknown ), mSubType( DwMime::kSubtypeUnknown ), - mCryptoType( CryptoTypeUnknown ), mEncryptionState( KMMsgNotEncrypted ), mSignatureState( KMMsgNotSigned ), mMsgPartOk( false ), @@ -72,7 +71,6 @@ partNode::partNode( DwBodyPart* dwPart, int explicitType, int explicitSubType, : mRoot( 0 ), mNext( 0 ), mChild( 0 ), mWasProcessed( false ), mDwPart( dwPart ), - mCryptoType( CryptoTypeUnknown ), mEncryptionState( KMMsgNotEncrypted ), mSignatureState( KMMsgNotSigned ), mMsgPartOk( false ), @@ -135,7 +133,6 @@ partNode::partNode( bool deleteDwBodyPart, DwBodyPart* dwPart ) : mRoot( 0 ), mNext( 0 ), mChild( 0 ), mWasProcessed( false ), mDwPart( dwPart ), - mCryptoType( CryptoTypeUnknown ), mEncryptionState( KMMsgNotEncrypted ), mSignatureState( KMMsgNotSigned ), mMsgPartOk( false ), @@ -227,18 +224,30 @@ QCString partNode::subTypeString() const { return s.c_str(); } -partNode::CryptoType partNode::firstCryptoType() const -{ - CryptoType ret = cryptoType(); - if( (CryptoTypeUnknown == ret || CryptoTypeNone == ret) - && mChild ) - ret = mChild->firstCryptoType(); - if( (CryptoTypeUnknown == ret || CryptoTypeNone == ret) - && mNext ) - ret = mNext->firstCryptoType(); - return ret; +int partNode::childCount() const { + int count = 0; + for ( partNode * child = firstChild() ; child ; child = child->nextSibling() ) + ++ count; + return count; } +QString partNode::contentTypeParameter( const char * name ) const { + if ( !mDwPart || !mDwPart->hasHeaders() ) + return QString::null; + DwHeaders & headers = mDwPart->Headers(); + if ( !headers.HasContentType() ) + return QString::null; + DwString attr = name; + attr.ConvertToLowerCase(); + for ( DwParameter * param = headers.ContentType().FirstParameter() ; param ; param = param->Next() ) { + DwString this_attr = param->Attribute(); + this_attr.ConvertToLowerCase(); // what a braindead design! + if ( this_attr == attr ) + return QString::fromLatin1( param->Value().data(), param->Value().size() ); + // warning: misses rfc2231 handling! + } + return QString::null; +} KMMsgEncryptionState partNode::overallEncryptionState() const { diff --git a/partNode.h b/partNode.h index 48fb3f974..02cd03e31 100644 --- a/partNode.h +++ b/partNode.h @@ -60,15 +60,6 @@ class KMMimePartTree; */ class partNode { -public: - enum CryptoType { CryptoTypeUnknown, - CryptoTypeNone, - CryptoTypeInlinePGP, - CryptoTypeOpenPgpMIME, - CryptoTypeSMIME, - CryptoType3rdParty }; - -private: partNode(); int calcNodeIdOrFindNode( int& curId, const partNode* calcNode, @@ -138,18 +129,6 @@ public: return mSubType == subType; } - void setCryptoType( CryptoType cryptoType ) { - mCryptoType = cryptoType; - } - - CryptoType cryptoType() const { - return mCryptoType; - } - - // return first not-unknown and not-none crypto type - // or return none (or unknown, resp.) if no other crypto type set - CryptoType firstCryptoType() const ; - void setEncryptionState( KMMsgEncryptionState state ) { mEncryptionState = state; } @@ -231,11 +210,14 @@ public: bool hasContentDispositionInline() const; + QString contentTypeParameter( const char * name ) const; + const QString& trueFromAddress() const; partNode * parentNode() const { return mRoot; } partNode * nextSibling() const { return mNext; } partNode * firstChild() const { return mChild; } + int childCount() const; bool processed() const { return mWasProcessed; } private: @@ -250,7 +232,6 @@ private: QString mFromAddress; int mType; int mSubType; - CryptoType mCryptoType; KMMsgEncryptionState mEncryptionState; KMMsgSignatureState mSignatureState; mutable bool mMsgPartOk;