1 /* -*- mode: C++; c-file-style: "gnu" -*-
4 This file is part of KMail, the KDE mail client.
5 Copyright (C) 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net
6 Copyright (c) 2009 Klarälvdalens Datakonsult AB
7 Authors: Marc Mutz <marc@kdab.net>
8 Copyright (c) 2009 Andras Mantia <andras@kdab.net>
10 KMail is free software; you can redistribute it and/or modify it
11 under the terms of the GNU General Public License, version 2, as
12 published by the Free Software Foundation.
14 KMail is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 In addition, as a special exception, the copyright holders give
24 permission to link the code of this program with any edition of
25 the Qt library by Trolltech AS, Norway (or with modified versions
26 of Qt that use the same license as Qt), and distribute linked
27 combinations including the two. You must obey the GNU General
28 Public License in all respects for all of the code used other than
29 Qt. If you modify this file, you may extend this exception to
30 your version of the file, but you are not obligated to do so. If
31 you do not wish to do so, delete this exception statement from
35 #include <config-messageviewer.h>
37 #include "objecttreeparser_p.h"
40 #include <kleo/decryptverifyjob.h>
41 #include <kleo/verifydetachedjob.h>
42 #include <kleo/verifyopaquejob.h>
43 #include <kleo/keylistjob.h>
45 #include <gpgme++/keylistresult.h>
48 #include <qstringlist.h>
53 using namespace GpgME
;
54 using namespace MessageViewer
;
56 CryptoBodyPartMemento::CryptoBodyPartMemento()
58 Interface::BodyPartMemento(),
64 CryptoBodyPartMemento::~CryptoBodyPartMemento() {}
66 void CryptoBodyPartMemento::setAuditLog( const Error
& err
, const QString
& log
) {
67 m_auditLogError
= err
;
71 void CryptoBodyPartMemento::setRunning( bool running
) {
75 void CryptoBodyPartMemento::detach()
77 disconnect( this, SIGNAL(update(MessageViewer::Viewer::UpdateMode
)), 0, 0 );
80 DecryptVerifyBodyPartMemento::DecryptVerifyBodyPartMemento( DecryptVerifyJob
* job
, const QByteArray
& cipherText
)
81 : CryptoBodyPartMemento(),
82 m_cipherText( cipherText
),
88 DecryptVerifyBodyPartMemento::~DecryptVerifyBodyPartMemento() {
93 bool DecryptVerifyBodyPartMemento::start() {
95 if ( const Error err
= m_job
->start( m_cipherText
) ) {
96 m_dr
= DecryptionResult( err
);
99 connect( m_job
, SIGNAL(result(GpgME::DecryptionResult
,GpgME::VerificationResult
,QByteArray
)),
100 this, SLOT(slotResult(GpgME::DecryptionResult
,GpgME::VerificationResult
,QByteArray
)) );
105 void DecryptVerifyBodyPartMemento::exec() {
107 QByteArray plainText
;
109 const std::pair
<DecryptionResult
,VerificationResult
> p
= m_job
->exec( m_cipherText
, plainText
);
110 saveResult( p
.first
, p
.second
, plainText
);
111 m_job
->deleteLater(); // exec'ed jobs don't delete themselves
115 void DecryptVerifyBodyPartMemento::saveResult( const DecryptionResult
& dr
,
116 const VerificationResult
& vr
,
117 const QByteArray
& plainText
)
123 m_plainText
= plainText
;
124 setAuditLog( m_job
->auditLogError(), m_job
->auditLogAsHtml() );
127 void DecryptVerifyBodyPartMemento::slotResult( const DecryptionResult
& dr
,
128 const VerificationResult
& vr
,
129 const QByteArray
& plainText
)
131 saveResult( dr
, vr
, plainText
);
139 VerifyDetachedBodyPartMemento::VerifyDetachedBodyPartMemento( VerifyDetachedJob
* job
,
141 const QByteArray
& signature
,
142 const QByteArray
& plainText
)
143 : CryptoBodyPartMemento(),
144 m_signature( signature
),
145 m_plainText( plainText
),
152 VerifyDetachedBodyPartMemento::~VerifyDetachedBodyPartMemento() {
156 m_keylistjob
->slotCancel();
159 bool VerifyDetachedBodyPartMemento::start() {
161 #ifdef DEBUG_SIGNATURE
162 kDebug() << "tokoe: VerifyDetachedBodyPartMemento started";
164 connect( m_job
, SIGNAL(result(GpgME::VerificationResult
)),
165 this, SLOT(slotResult(GpgME::VerificationResult
)) );
166 if ( const Error err
= m_job
->start( m_signature
, m_plainText
) ) {
167 m_vr
= VerificationResult( err
);
168 #ifdef DEBUG_SIGNATURE
169 kDebug() << "tokoe: VerifyDetachedBodyPartMemento stopped with error";
177 void VerifyDetachedBodyPartMemento::exec() {
180 #ifdef DEBUG_SIGNATURE
181 kDebug() << "tokoe: VerifyDetachedBodyPartMemento execed";
183 saveResult( m_job
->exec( m_signature
, m_plainText
) );
184 m_job
->deleteLater(); // exec'ed jobs don't delete themselves
186 #ifdef DEBUG_SIGNATURE
187 kDebug() << "tokoe: VerifyDetachedBodyPartMemento after execed";
189 if ( canStartKeyListJob() ) {
190 std::vector
<GpgME::Key
> keys
;
191 m_keylistjob
->exec( keyListPattern(), /*secretOnly=*/false, keys
);
196 m_keylistjob
->deleteLater(); // exec'ed jobs don't delete themselves
201 bool VerifyDetachedBodyPartMemento::canStartKeyListJob() const
205 const char * const fpr
= m_vr
.signature( 0 ).fingerprint();
209 QStringList
VerifyDetachedBodyPartMemento::keyListPattern() const
211 assert( canStartKeyListJob() );
212 return QStringList( QString::fromLatin1( m_vr
.signature( 0 ).fingerprint() ) );
215 void VerifyDetachedBodyPartMemento::saveResult( const VerificationResult
& vr
)
218 #ifdef DEBUG_SIGNATURE
219 kDebug() << "tokoe: VerifyDetachedBodyPartMemento::saveResult called";
222 setAuditLog( m_job
->auditLogError(), m_job
->auditLogAsHtml() );
225 void VerifyDetachedBodyPartMemento::slotResult( const VerificationResult
& vr
)
227 #ifdef DEBUG_SIGNATURE
228 kDebug() << "tokoe: VerifyDetachedBodyPartMemento::slotResult called";
232 if ( canStartKeyListJob() && startKeyListJob() ) {
233 #ifdef DEBUG_SIGNATURE
234 kDebug() << "tokoe: VerifyDetachedBodyPartMemento: canStartKeyListJob && startKeyListJob";
239 m_keylistjob
->deleteLater();
245 bool VerifyDetachedBodyPartMemento::startKeyListJob()
247 assert( canStartKeyListJob() );
248 if ( const GpgME::Error err
= m_keylistjob
->start( keyListPattern() ) )
250 connect( m_keylistjob
, SIGNAL(done()), this, SLOT(slotKeyListJobDone()) );
251 connect( m_keylistjob
, SIGNAL(nextKey(GpgME::Key
)),
252 this, SLOT(slotNextKey(GpgME::Key
)) );
256 void VerifyDetachedBodyPartMemento::slotNextKey( const GpgME::Key
& key
)
258 #ifdef DEBUG_SIGNATURE
259 kDebug() << "tokoe: VerifyDetachedBodyPartMemento::slotNextKey called";
264 void VerifyDetachedBodyPartMemento::slotKeyListJobDone()
266 #ifdef DEBUG_SIGNATURE
267 kDebug() << "tokoe: VerifyDetachedBodyPartMemento::slotKeyListJobDone called";
274 VerifyOpaqueBodyPartMemento::VerifyOpaqueBodyPartMemento( VerifyOpaqueJob
* job
,
276 const QByteArray
& signature
)
277 : CryptoBodyPartMemento(),
278 m_signature( signature
),
285 VerifyOpaqueBodyPartMemento::~VerifyOpaqueBodyPartMemento() {
289 m_keylistjob
->slotCancel();
292 bool VerifyOpaqueBodyPartMemento::start() {
294 #ifdef DEBUG_SIGNATURE
295 kDebug() << "tokoe: VerifyOpaqueBodyPartMemento started";
297 if ( const Error err
= m_job
->start( m_signature
) ) {
298 m_vr
= VerificationResult( err
);
299 #ifdef DEBUG_SIGNATURE
300 kDebug() << "tokoe: VerifyOpaqueBodyPartMemento stopped with error";
304 connect( m_job
, SIGNAL(result(GpgME::VerificationResult
,QByteArray
)),
305 this, SLOT(slotResult(GpgME::VerificationResult
,QByteArray
)) );
310 void VerifyOpaqueBodyPartMemento::exec() {
313 QByteArray plainText
;
314 #ifdef DEBUG_SIGNATURE
315 kDebug() << "tokoe: VerifyOpaqueBodyPartMemento execed";
317 saveResult( m_job
->exec( m_signature
, plainText
), plainText
);
318 #ifdef DEBUG_SIGNATURE
319 kDebug() << "tokoe: VerifyOpaqueBodyPartMemento after execed";
321 m_job
->deleteLater(); // exec'ed jobs don't delete themselves
323 if ( canStartKeyListJob() ) {
324 std::vector
<GpgME::Key
> keys
;
325 m_keylistjob
->exec( keyListPattern(), /*secretOnly=*/false, keys
);
330 m_keylistjob
->deleteLater(); // exec'ed jobs don't delete themselves
335 bool VerifyOpaqueBodyPartMemento::canStartKeyListJob() const
339 const char * const fpr
= m_vr
.signature( 0 ).fingerprint();
343 QStringList
VerifyOpaqueBodyPartMemento::keyListPattern() const
345 assert( canStartKeyListJob() );
346 return QStringList( QString::fromLatin1( m_vr
.signature( 0 ).fingerprint() ) );
349 void VerifyOpaqueBodyPartMemento::saveResult( const VerificationResult
& vr
,
350 const QByteArray
& plainText
)
353 #ifdef DEBUG_SIGNATURE
354 kDebug() << "tokoe: VerifyOpaqueBodyPartMemento::saveResult called";
357 m_plainText
= plainText
;
358 setAuditLog( m_job
->auditLogError(), m_job
->auditLogAsHtml() );
361 void VerifyOpaqueBodyPartMemento::slotResult( const VerificationResult
& vr
,
362 const QByteArray
& plainText
)
364 #ifdef DEBUG_SIGNATURE
365 kDebug() << "tokoe: VerifyOpaqueBodyPartMemento::slotResult called";
367 saveResult( vr
, plainText
);
369 if ( canStartKeyListJob() && startKeyListJob() ) {
370 #ifdef DEBUG_SIGNATURE
371 kDebug() << "tokoe: VerifyOpaqueBodyPartMemento: canStartKeyListJob && startKeyListJob";
376 m_keylistjob
->deleteLater();
382 bool VerifyOpaqueBodyPartMemento::startKeyListJob()
384 assert( canStartKeyListJob() );
385 if ( const GpgME::Error err
= m_keylistjob
->start( keyListPattern() ) )
387 connect( m_keylistjob
, SIGNAL(done()), this, SLOT(slotKeyListJobDone()) );
388 connect( m_keylistjob
, SIGNAL(nextKey(GpgME::Key
)),
389 this, SLOT(slotNextKey(GpgME::Key
)) );
393 void VerifyOpaqueBodyPartMemento::slotNextKey( const GpgME::Key
& key
)
395 #ifdef DEBUG_SIGNATURE
396 kDebug() << "tokoe: VerifyOpaqueBodyPartMemento::slotNextKey called";
401 void VerifyOpaqueBodyPartMemento::slotKeyListJobDone()
403 #ifdef DEBUG_SIGNATURE
404 kDebug() << "tokoe: VerifyOpaqueBodyPartMemento::slotKeyListJobDone called";
412 #include "objecttreeparser_p.moc"