Branch 'kolab/integration/4.13.0' - kmail/editor kmail/kmcommands.cpp messagecomposer/composer messagecomposer/tests
Sandro Knauß
knauss at kolabsys.com
Tue Apr 28 10:25:05 CEST 2015
kmail/editor/kmcomposewin.cpp | 2
kmail/kmcommands.cpp | 7 -
messagecomposer/composer/composerviewbase.cpp | 20 +++
messagecomposer/composer/composerviewbase.h | 1
messagecomposer/tests/cryptocomposertest.cpp | 137 +++++++++++++++++++++++++-
messagecomposer/tests/cryptocomposertest.h | 6 +
6 files changed, 165 insertions(+), 8 deletions(-)
New commits:
commit b8144ef825dccfd8a7eacc62671e49a76ec9015f
Author: Sandro Knauà <knauss at kolabsys.com>
Date: Sat Apr 11 13:53:03 2015 +0200
Fix #318323: No Message body after 'Send Againâ¦' of encrypted email
Search for attachments in the decrypted message and not only in the
unencrypted one.
BUG: 318323
REVIEW: 123415
diff --git a/kmail/editor/kmcomposewin.cpp b/kmail/editor/kmcomposewin.cpp
index d362dcf..2896253 100644
--- a/kmail/editor/kmcomposewin.cpp
+++ b/kmail/editor/kmcomposewin.cpp
@@ -1593,7 +1593,7 @@ void KMComposeWin::setMessage( const KMime::Message::Ptr &newMsg, bool lastSignS
if ( lastEncryptState )
mLastEncryptActionState = true;
- mComposerBase->setMessage( newMsg );
+ mComposerBase->setMessage( newMsg, allowDecryption );
mMsg = newMsg;
KPIMIdentities::IdentityManager * im = KMKernel::self()->identityManager();
diff --git a/kmail/kmcommands.cpp b/kmail/kmcommands.cpp
index 85fbd6d..bf52513 100644
--- a/kmail/kmcommands.cpp
+++ b/kmail/kmcommands.cpp
@@ -542,9 +542,8 @@ KMCommand::Result KMEditMessageCommand::execute()
bool lastEncrypt = false;
bool lastSign = false;
KMail::Util::lastEncryptAndSignState(lastEncrypt, lastSign, mMessage);
- win->setMessage( mMessage, lastSign, lastEncrypt, false, false );
+ win->setMessage( mMessage, lastSign, lastEncrypt, true, true );
win->show();
- win->setModified( true );
return OK;
}
@@ -584,7 +583,7 @@ KMCommand::Result KMEditItemCommand::execute()
bool lastEncrypt = false;
bool lastSign = false;
KMail::Util::lastEncryptAndSignState(lastEncrypt, lastSign, msg);
- win->setMessage( msg, lastSign, lastEncrypt, false, true );
+ win->setMessage( msg, lastSign, lastEncrypt, true, true );
win->setFolder( item.parentCollection() );
@@ -1567,7 +1566,7 @@ KMCommand::Result KMResendMessageCommand::execute()
bool lastEncrypt = false;
bool lastSign = false;
KMail::Util::lastEncryptAndSignState(lastEncrypt, lastSign, msg);
- win->setMessage( newMsg, lastSign, lastEncrypt, false, true );
+ win->setMessage( newMsg, lastSign, lastEncrypt, true, true );
win->show();
diff --git a/messagecomposer/composer/composerviewbase.cpp b/messagecomposer/composer/composerviewbase.cpp
index b81a551..bd42002 100644
--- a/messagecomposer/composer/composerviewbase.cpp
+++ b/messagecomposer/composer/composerviewbase.cpp
@@ -127,7 +127,12 @@ bool MessageComposer::ComposerViewBase::isComposing() const
return !m_composers.isEmpty();
}
-void MessageComposer::ComposerViewBase::setMessage ( const KMime::Message::Ptr& msg )
+void MessageComposer::ComposerViewBase::setMessage(const KMime::Message::Ptr &newMsg)
+{
+ setMessage(newMsg, false); // Do not decrypt message by default (old behaviour)
+}
+
+void MessageComposer::ComposerViewBase::setMessage ( const KMime::Message::Ptr& msg, bool allowDecryption )
{
foreach( MessageCore::AttachmentPart::Ptr attachment, m_attachmentModel->attachments() )
@@ -165,6 +170,7 @@ void MessageComposer::ComposerViewBase::setMessage ( const KMime::Message::Ptr&
msgContent->parse();
MessageViewer::EmptySource emptySource;
MessageViewer::ObjectTreeParser otp( &emptySource );//All default are ok
+ emptySource.setAllowDecryption(allowDecryption);
otp.parseObjectTree( msgContent );
// Load the attachments
@@ -173,7 +179,17 @@ void MessageComposer::ComposerViewBase::setMessage ( const KMime::Message::Ptr&
std::vector<KMime::Content*>::const_iterator end( ac.attachments().end() );
for ( std::vector<KMime::Content*>::const_iterator it = ac.attachments().begin();
it != end ; ++it ) {
- addAttachmentPart( *it );
+ if (otp.nodeHelper()->partMetaData((*it)->parent()).isEncrypted) { // gpg mime has a msg.asc as subelement, that is recognized as attachment
+ MessageCore::AttachmentCollector acEnc;
+ acEnc.collectAttachmentsFrom(otp.nodeHelper()->decryptedNodeForContent((*it)->parent()));
+ std::vector<KMime::Content*>::const_iterator endEnc( acEnc.attachments().end() );
+ for ( std::vector<KMime::Content*>::const_iterator itEnc = acEnc.attachments().begin();
+ itEnc != endEnc ; ++itEnc ) {
+ addAttachmentPart( *itEnc );
+ }
+ } else {
+ addAttachmentPart( *it );
+ }
}
int transportId = -1;
diff --git a/messagecomposer/composer/composerviewbase.h b/messagecomposer/composer/composerviewbase.h
index bcc085a..4cc0d02 100644
--- a/messagecomposer/composer/composerviewbase.h
+++ b/messagecomposer/composer/composerviewbase.h
@@ -90,6 +90,7 @@ public:
* keep track of it.
*/
void setMessage( const KMime::Message::Ptr& newMsg );
+ void setMessage( const KMime::Message::Ptr& newMsg, bool allowDecryption );
void updateTemplate ( const KMime::Message::Ptr& msg );
diff --git a/messagecomposer/tests/cryptocomposertest.cpp b/messagecomposer/tests/cryptocomposertest.cpp
index d5f75fa..e37acde 100644
--- a/messagecomposer/tests/cryptocomposertest.cpp
+++ b/messagecomposer/tests/cryptocomposertest.cpp
@@ -35,9 +35,14 @@
using namespace KMime;
#include <messagecomposer/composer/composer.h>
+#include <messagecomposer/composer/composerviewbase.h>
+#include <kmeditor.h>
#include <messagecomposer/part/globalpart.h>
#include <messagecomposer/part/infopart.h>
#include <messagecomposer/part/textpart.h>
+#include <attachment/attachmentmodel.h>
+#include <attachment/attachmentcontrollerbase.h>
+#include <recipientseditor.h>
using namespace MessageComposer;
#include <messagecore/attachment/attachmentpart.h>
@@ -51,6 +56,8 @@ using MessageCore::AttachmentPart;
#include <gpgme++/key.h>
+Q_DECLARE_METATYPE(MessageCore::AttachmentPart)
+
QTEST_KDEMAIN( CryptoComposerTest, GUI )
void CryptoComposerTest::initTestCase()
@@ -168,6 +175,134 @@ void CryptoComposerTest::testEncryptSameAttachments()
}
+void CryptoComposerTest::testEditEncryptAttachments_data()
+{
+ QTest::addColumn<int>( "format" );
+ QTest::newRow( "OpenPGPMime" ) << (int) Kleo::OpenPGPMIMEFormat;
+ //TODO: SMIME should also be tested
+}
+
+void CryptoComposerTest::testEditEncryptAttachments()
+{
+ QFETCH( int, format );
+ Composer *composer = new Composer;
+ QString data( QString::fromLatin1( "All happy families are alike; each unhappy family is unhappy in its own way." ) );
+ fillComposerData( composer, data );
+ fillComposerCryptoData( composer );
+
+ AttachmentPart::Ptr attachment = AttachmentPart::Ptr( new AttachmentPart );
+ const QString fileName = QLatin1String( "anattachment.txt" );
+ const QByteArray fileData = "abc";
+ attachment->setData( fileData );
+ attachment->setMimeType( "x-some/x-type" );
+ attachment->setFileName( fileName );
+ attachment->setEncrypted( true );
+ attachment->setSigned( false );
+ composer->addAttachmentPart( attachment );
+
+ composer->setSignAndEncrypt( false, true );
+ composer->setMessageCryptoFormat( (Kleo::CryptoMessageFormat) format );
+
+ VERIFYEXEC( composer );
+ QCOMPARE( composer->resultMessages().size(), 1 );
+
+ KMime::Message::Ptr message = composer->resultMessages().first();
+ delete composer;
+ composer = 0;
+
+ // setup a viewer
+ ComposerViewBase view(this, 0);
+ AttachmentModel model(this);
+ AttachmentControllerBase controller(&model,0,0);
+ RecipientsEditor recipientEditor;
+ KMeditor editor;
+ view.setAttachmentModel(&model);
+ view.setAttachmentController(&controller);
+ view.setRecipientsEditor(&recipientEditor);
+ view.setEditor(&editor);
+
+ // Let's load the email to the viewer
+ view.setMessage(message, true);
+
+ QModelIndex index = model.index(0,0);
+ QCOMPARE (editor.toPlainText(), data);
+ QCOMPARE(model.rowCount(), 1);
+ QCOMPARE(model.data(index, AttachmentModel::NameRole).toString(), fileName);
+ AttachmentPart::Ptr part = model.attachments()[0];
+ QCOMPARE(part->data(), fileData);
+ QCOMPARE(part->fileName(), fileName);
+}
+
+void CryptoComposerTest::testEditEncryptAndLateAttachments_data()
+{
+ QTest::addColumn<int>( "format" );
+ QTest::newRow( "OpenPGPMime" ) << (int) Kleo::OpenPGPMIMEFormat;
+ //TODO: SMIME should also be tested
+}
+
+void CryptoComposerTest::testEditEncryptAndLateAttachments()
+{
+ QFETCH( int, format );
+ Composer *composer = new Composer;
+ QString data( QString::fromLatin1( "All happy families are alike; each unhappy family is unhappy in its own way." ) );
+ fillComposerData( composer, data );
+ fillComposerCryptoData( composer );
+
+ AttachmentPart::Ptr attachment = AttachmentPart::Ptr( new AttachmentPart );
+ const QString fileName = QLatin1String( "anattachment.txt" );
+ const QByteArray fileData = "abc";
+ const QString fileName2 = QLatin1String( "nonencrypt.txt" );
+ const QByteArray fileData2 = "readable";
+ attachment->setData( fileData );
+ attachment->setMimeType( "x-some/x-type" );
+ attachment->setFileName( fileName );
+ attachment->setEncrypted( true );
+ attachment->setSigned( false );
+ composer->addAttachmentPart( attachment );
+
+ attachment = AttachmentPart::Ptr( new AttachmentPart );
+ attachment->setData( fileData2 );
+ attachment->setMimeType( "x-some/x-type2" );
+ attachment->setFileName( fileName2 );
+ attachment->setEncrypted( false );
+ attachment->setSigned( false );
+ composer->addAttachmentPart( attachment );
+
+ composer->setSignAndEncrypt( false, true );
+ composer->setMessageCryptoFormat( (Kleo::CryptoMessageFormat) format );
+
+ VERIFYEXEC( composer );
+ QCOMPARE( composer->resultMessages().size(), 1 );
+
+ KMime::Message::Ptr message = composer->resultMessages().first();
+ delete composer;
+ composer = 0;
+
+ // setup a viewer
+ ComposerViewBase view(this, 0);
+ AttachmentModel model(this);
+ AttachmentControllerBase controller(&model,0,0);
+ RecipientsEditor recipientEditor;
+ KMeditor editor;
+ view.setAttachmentModel(&model);
+ view.setAttachmentController(&controller);
+ view.setRecipientsEditor(&recipientEditor);
+ view.setEditor(&editor);
+
+ // Let's load the email to the viewer
+ view.setMessage(message, true);
+
+ QModelIndex index = model.index(0,0);
+ QCOMPARE (editor.toPlainText(), data);
+ QCOMPARE(model.rowCount(), 2);
+ AttachmentPart::Ptr part = model.attachments()[0];
+ QCOMPARE(part->fileName(), fileName);
+ QCOMPARE(part->data(), fileData);
+ part = model.attachments()[1];
+ QCOMPARE(part->fileName(), fileName2);
+ QCOMPARE(part->data(), fileData2);
+}
+
void CryptoComposerTest::testSignEncryptLateAttachments_data()
{
QTest::addColumn<int>( "format" );
@@ -211,7 +346,7 @@ void CryptoComposerTest::testSignEncryptLateAttachments()
QCOMPARE( message->to()->asUnicodeString(), QString::fromLocal8Bit( "you at you.you" ) );
// now check the attachment separately
- QCOMPARE( QString::fromAscii( MessageCore::NodeHelper::nextSibling( MessageCore::NodeHelper::firstChild( message.get() ) )->body() ), QString::fromAscii( "abc" ) );
+ QCOMPARE( QString::fromAscii( MessageCore::NodeHelper::nextSibling( b )->body() ), QString::fromAscii( "abc" ) );
}
diff --git a/messagecomposer/tests/cryptocomposertest.h b/messagecomposer/tests/cryptocomposertest.h
index 71976b0..c928d38 100644
--- a/messagecomposer/tests/cryptocomposertest.h
+++ b/messagecomposer/tests/cryptocomposertest.h
@@ -45,6 +45,12 @@ class CryptoComposerTest : public QObject
void testSignEncryptLateAttachments();
void testSignEncryptLateAttachments_data();
+ void testEditEncryptAttachments();
+ void testEditEncryptAttachments_data();
+
+ void testEditEncryptAndLateAttachments();
+ void testEditEncryptAndLateAttachments_data();
+
// secondary recipients
void testBCCEncrypt();
void testBCCEncrypt_data();
More information about the commits
mailing list