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
6
Authors: Marc Mutz <marc@kdab.net>
8
KMail is free software; you can redistribute it and/or modify it
9
under the terms of the GNU General Public License, version 2, as
10
published by the Free Software Foundation.
12
KMail is distributed in the hope that it will be useful, but
13
WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
In addition, as a special exception, the copyright holders give
22
permission to link the code of this program with any edition of
23
the Qt library by Trolltech AS, Norway (or with modified versions
24
of Qt that use the same license as Qt), and distribute linked
25
combinations including the two. You must obey the GNU General
26
Public License in all respects for all of the code used other than
27
Qt. If you modify this file, you may extend this exception to
28
your version of the file, but you are not obligated to do so. If
29
you do not wish to do so, delete this exception statement from
33
#include "objecttreeparser_p.h"
35
#include <kleo/decryptverifyjob.h>
36
#include <kleo/verifydetachedjob.h>
37
#include <kleo/verifyopaquejob.h>
38
#include <kleo/keylistjob.h>
40
#include <gpgme++/keylistresult.h>
43
#include <qstringlist.h>
47
using namespace KMail;
49
using namespace GpgME;
51
CryptoBodyPartMemento::CryptoBodyPartMemento()
53
Interface::BodyPartMemento(),
60
CryptoBodyPartMemento::~CryptoBodyPartMemento() {}
62
void CryptoBodyPartMemento::setAuditLog( const Error & err, const QString & log ) {
63
m_auditLogError = err;
67
void CryptoBodyPartMemento::setRunning( bool running ) {
71
DecryptVerifyBodyPartMemento::DecryptVerifyBodyPartMemento( DecryptVerifyJob * job, const QByteArray & cipherText )
72
: CryptoBodyPartMemento(),
73
m_cipherText( cipherText ),
79
DecryptVerifyBodyPartMemento::~DecryptVerifyBodyPartMemento() {
84
bool DecryptVerifyBodyPartMemento::start() {
86
if ( const Error err = m_job->start( m_cipherText ) ) {
87
m_dr = DecryptionResult( err );
90
connect( m_job, SIGNAL(result(const GpgME::DecryptionResult&,const GpgME::VerificationResult&,const QByteArray&)),
91
this, SLOT(slotResult(const GpgME::DecryptionResult&,const GpgME::VerificationResult&,const QByteArray&)) );
96
void DecryptVerifyBodyPartMemento::exec() {
100
const std::pair<DecryptionResult,VerificationResult> p = m_job->exec( m_cipherText, plainText );
101
saveResult( p.first, p.second, plainText );
102
m_job->deleteLater(); // exec'ed jobs don't delete themselves
106
void DecryptVerifyBodyPartMemento::saveResult( const DecryptionResult & dr,
107
const VerificationResult & vr,
108
const QByteArray & plainText )
114
m_plainText = plainText;
115
setAuditLog( m_job->auditLogError(), m_job->auditLogAsHtml() );
118
void DecryptVerifyBodyPartMemento::slotResult( const DecryptionResult & dr,
119
const VerificationResult & vr,
120
const QByteArray & plainText )
122
saveResult( dr, vr, plainText );
130
VerifyDetachedBodyPartMemento::VerifyDetachedBodyPartMemento( VerifyDetachedJob * job,
132
const QByteArray & signature,
133
const QByteArray & plainText )
134
: CryptoBodyPartMemento(),
135
m_signature( signature ),
136
m_plainText( plainText ),
143
VerifyDetachedBodyPartMemento::~VerifyDetachedBodyPartMemento() {
147
m_keylistjob->slotCancel();
150
bool VerifyDetachedBodyPartMemento::start() {
152
if ( const Error err = m_job->start( m_signature, m_plainText ) ) {
153
m_vr = VerificationResult( err );
156
connect( m_job, SIGNAL(result(const GpgME::VerificationResult&)),
157
this, SLOT(slotResult(const GpgME::VerificationResult&)) );
162
void VerifyDetachedBodyPartMemento::exec() {
165
saveResult( m_job->exec( m_signature, m_plainText ) );
166
m_job->deleteLater(); // exec'ed jobs don't delete themselves
168
if ( canStartKeyListJob() ) {
169
std::vector<GpgME::Key> keys;
170
m_keylistjob->exec( keyListPattern(), /*secretOnly=*/false, keys );
175
m_keylistjob->deleteLater(); // exec'ed jobs don't delete themselves
180
bool VerifyDetachedBodyPartMemento::canStartKeyListJob() const
184
const char * const fpr = m_vr.signature( 0 ).fingerprint();
188
QStringList VerifyDetachedBodyPartMemento::keyListPattern() const
190
assert( canStartKeyListJob() );
191
return QStringList( QString::fromLatin1( m_vr.signature( 0 ).fingerprint() ) );
194
void VerifyDetachedBodyPartMemento::saveResult( const VerificationResult & vr )
198
setAuditLog( m_job->auditLogError(), m_job->auditLogAsHtml() );
201
void VerifyDetachedBodyPartMemento::slotResult( const VerificationResult & vr )
205
if ( canStartKeyListJob() && startKeyListJob() )
208
m_keylistjob->deleteLater();
214
bool VerifyDetachedBodyPartMemento::startKeyListJob()
216
assert( canStartKeyListJob() );
217
if ( const GpgME::Error err = m_keylistjob->start( keyListPattern() ) )
219
connect( m_keylistjob, SIGNAL(done()), this, SLOT(slotKeyListJobDone()) );
220
connect( m_keylistjob, SIGNAL(nextKey(const GpgME::Key&)),
221
this, SLOT(slotNextKey(const GpgME::Key&)) );
225
void VerifyDetachedBodyPartMemento::slotNextKey( const GpgME::Key & key )
230
void VerifyDetachedBodyPartMemento::slotKeyListJobDone()
238
VerifyOpaqueBodyPartMemento::VerifyOpaqueBodyPartMemento( VerifyOpaqueJob * job,
240
const QByteArray & signature )
241
: CryptoBodyPartMemento(),
242
m_signature( signature ),
249
VerifyOpaqueBodyPartMemento::~VerifyOpaqueBodyPartMemento() {
253
m_keylistjob->slotCancel();
256
bool VerifyOpaqueBodyPartMemento::start() {
258
if ( const Error err = m_job->start( m_signature ) ) {
259
m_vr = VerificationResult( err );
262
connect( m_job, SIGNAL(result(const GpgME::VerificationResult&,const QByteArray&)),
263
this, SLOT(slotResult(const GpgME::VerificationResult&,const QByteArray&)) );
268
void VerifyOpaqueBodyPartMemento::exec() {
271
QByteArray plainText;
272
saveResult( m_job->exec( m_signature, plainText ), plainText );
273
m_job->deleteLater(); // exec'ed jobs don't delete themselves
275
if ( canStartKeyListJob() ) {
276
std::vector<GpgME::Key> keys;
277
m_keylistjob->exec( keyListPattern(), /*secretOnly=*/false, keys );
282
m_keylistjob->deleteLater(); // exec'ed jobs don't delete themselves
287
bool VerifyOpaqueBodyPartMemento::canStartKeyListJob() const
291
const char * const fpr = m_vr.signature( 0 ).fingerprint();
295
QStringList VerifyOpaqueBodyPartMemento::keyListPattern() const
297
assert( canStartKeyListJob() );
298
return QStringList( QString::fromLatin1( m_vr.signature( 0 ).fingerprint() ) );
301
void VerifyOpaqueBodyPartMemento::saveResult( const VerificationResult & vr,
302
const QByteArray & plainText )
306
m_plainText = plainText;
307
setAuditLog( m_job->auditLogError(), m_job->auditLogAsHtml() );
310
void VerifyOpaqueBodyPartMemento::slotResult( const VerificationResult & vr,
311
const QByteArray & plainText )
313
saveResult( vr, plainText );
315
if ( canStartKeyListJob() && startKeyListJob() )
318
m_keylistjob->deleteLater();
324
bool VerifyOpaqueBodyPartMemento::startKeyListJob()
326
assert( canStartKeyListJob() );
327
if ( const GpgME::Error err = m_keylistjob->start( keyListPattern() ) )
329
connect( m_keylistjob, SIGNAL(done()), this, SLOT(slotKeyListJobDone()) );
330
connect( m_keylistjob, SIGNAL(nextKey(const GpgME::Key&)),
331
this, SLOT(slotNextKey(const GpgME::Key&)) );
335
void VerifyOpaqueBodyPartMemento::slotNextKey( const GpgME::Key & key )
340
void VerifyOpaqueBodyPartMemento::slotKeyListJobDone()
348
#include "objecttreeparser_p.moc"