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 "objecttreeparser_p.h"
37 #include <kleo/decryptverifyjob.h>
38 #include <kleo/verifydetachedjob.h>
39 #include <kleo/verifyopaquejob.h>
40 #include <kleo/keylistjob.h>
42 #include <gpgme++/keylistresult.h>
45 #include <qstringlist.h>
50 using namespace GpgME
;
51 using namespace MessageViewer
;
53 CryptoBodyPartMemento::CryptoBodyPartMemento()
55 Interface::BodyPartMemento(),
61 CryptoBodyPartMemento::~CryptoBodyPartMemento() {}
63 void CryptoBodyPartMemento::setAuditLog( const Error
& err
, const QString
& log
) {
64 m_auditLogError
= err
;
68 void CryptoBodyPartMemento::setRunning( bool running
) {
72 void CryptoBodyPartMemento::detach()
74 disconnect( this, SIGNAL(update(Viewer::UpdateMode
)), 0, 0 );
77 DecryptVerifyBodyPartMemento::DecryptVerifyBodyPartMemento( DecryptVerifyJob
* job
, const QByteArray
& cipherText
)
78 : CryptoBodyPartMemento(),
79 m_cipherText( cipherText
),
85 DecryptVerifyBodyPartMemento::~DecryptVerifyBodyPartMemento() {
90 bool DecryptVerifyBodyPartMemento::start() {
92 if ( const Error err
= m_job
->start( m_cipherText
) ) {
93 m_dr
= DecryptionResult( err
);
96 connect( m_job
, SIGNAL(result(const GpgME::DecryptionResult
&,const GpgME::VerificationResult
&,const QByteArray
&)),
97 this, SLOT(slotResult(const GpgME::DecryptionResult
&,const GpgME::VerificationResult
&,const QByteArray
&)) );
102 void DecryptVerifyBodyPartMemento::exec() {
104 QByteArray plainText
;
106 const std::pair
<DecryptionResult
,VerificationResult
> p
= m_job
->exec( m_cipherText
, plainText
);
107 saveResult( p
.first
, p
.second
, plainText
);
108 m_job
->deleteLater(); // exec'ed jobs don't delete themselves
112 void DecryptVerifyBodyPartMemento::saveResult( const DecryptionResult
& dr
,
113 const VerificationResult
& vr
,
114 const QByteArray
& plainText
)
120 m_plainText
= plainText
;
121 setAuditLog( m_job
->auditLogError(), m_job
->auditLogAsHtml() );
124 void DecryptVerifyBodyPartMemento::slotResult( const DecryptionResult
& dr
,
125 const VerificationResult
& vr
,
126 const QByteArray
& plainText
)
128 saveResult( dr
, vr
, plainText
);
136 VerifyDetachedBodyPartMemento::VerifyDetachedBodyPartMemento( VerifyDetachedJob
* job
,
138 const QByteArray
& signature
,
139 const QByteArray
& plainText
)
140 : CryptoBodyPartMemento(),
141 m_signature( signature
),
142 m_plainText( plainText
),
149 VerifyDetachedBodyPartMemento::~VerifyDetachedBodyPartMemento() {
153 m_keylistjob
->slotCancel();
156 bool VerifyDetachedBodyPartMemento::start() {
158 if ( const Error err
= m_job
->start( m_signature
, m_plainText
) ) {
159 m_vr
= VerificationResult( err
);
162 connect( m_job
, SIGNAL(result(const GpgME::VerificationResult
&)),
163 this, SLOT(slotResult(const GpgME::VerificationResult
&)) );
168 void VerifyDetachedBodyPartMemento::exec() {
171 saveResult( m_job
->exec( m_signature
, m_plainText
) );
172 m_job
->deleteLater(); // exec'ed jobs don't delete themselves
174 if ( canStartKeyListJob() ) {
175 std::vector
<GpgME::Key
> keys
;
176 m_keylistjob
->exec( keyListPattern(), /*secretOnly=*/false, keys
);
181 m_keylistjob
->deleteLater(); // exec'ed jobs don't delete themselves
186 bool VerifyDetachedBodyPartMemento::canStartKeyListJob() const
190 const char * const fpr
= m_vr
.signature( 0 ).fingerprint();
194 QStringList
VerifyDetachedBodyPartMemento::keyListPattern() const
196 assert( canStartKeyListJob() );
197 return QStringList( QString::fromLatin1( m_vr
.signature( 0 ).fingerprint() ) );
200 void VerifyDetachedBodyPartMemento::saveResult( const VerificationResult
& vr
)
204 setAuditLog( m_job
->auditLogError(), m_job
->auditLogAsHtml() );
207 void VerifyDetachedBodyPartMemento::slotResult( const VerificationResult
& vr
)
211 if ( canStartKeyListJob() && startKeyListJob() )
214 m_keylistjob
->deleteLater();
220 bool VerifyDetachedBodyPartMemento::startKeyListJob()
222 assert( canStartKeyListJob() );
223 if ( const GpgME::Error err
= m_keylistjob
->start( keyListPattern() ) )
225 connect( m_keylistjob
, SIGNAL(done()), this, SLOT(slotKeyListJobDone()) );
226 connect( m_keylistjob
, SIGNAL(nextKey(const GpgME::Key
&)),
227 this, SLOT(slotNextKey(const GpgME::Key
&)) );
231 void VerifyDetachedBodyPartMemento::slotNextKey( const GpgME::Key
& key
)
236 void VerifyDetachedBodyPartMemento::slotKeyListJobDone()
243 VerifyOpaqueBodyPartMemento::VerifyOpaqueBodyPartMemento( VerifyOpaqueJob
* job
,
245 const QByteArray
& signature
)
246 : CryptoBodyPartMemento(),
247 m_signature( signature
),
254 VerifyOpaqueBodyPartMemento::~VerifyOpaqueBodyPartMemento() {
258 m_keylistjob
->slotCancel();
261 bool VerifyOpaqueBodyPartMemento::start() {
263 if ( const Error err
= m_job
->start( m_signature
) ) {
264 m_vr
= VerificationResult( err
);
267 connect( m_job
, SIGNAL(result(const GpgME::VerificationResult
&,const QByteArray
&)),
268 this, SLOT(slotResult(const GpgME::VerificationResult
&,const QByteArray
&)) );
273 void VerifyOpaqueBodyPartMemento::exec() {
276 QByteArray plainText
;
277 saveResult( m_job
->exec( m_signature
, plainText
), plainText
);
278 m_job
->deleteLater(); // exec'ed jobs don't delete themselves
280 if ( canStartKeyListJob() ) {
281 std::vector
<GpgME::Key
> keys
;
282 m_keylistjob
->exec( keyListPattern(), /*secretOnly=*/false, keys
);
287 m_keylistjob
->deleteLater(); // exec'ed jobs don't delete themselves
292 bool VerifyOpaqueBodyPartMemento::canStartKeyListJob() const
296 const char * const fpr
= m_vr
.signature( 0 ).fingerprint();
300 QStringList
VerifyOpaqueBodyPartMemento::keyListPattern() const
302 assert( canStartKeyListJob() );
303 return QStringList( QString::fromLatin1( m_vr
.signature( 0 ).fingerprint() ) );
306 void VerifyOpaqueBodyPartMemento::saveResult( const VerificationResult
& vr
,
307 const QByteArray
& plainText
)
311 m_plainText
= plainText
;
312 setAuditLog( m_job
->auditLogError(), m_job
->auditLogAsHtml() );
315 void VerifyOpaqueBodyPartMemento::slotResult( const VerificationResult
& vr
,
316 const QByteArray
& plainText
)
318 saveResult( vr
, plainText
);
320 if ( canStartKeyListJob() && startKeyListJob() )
323 m_keylistjob
->deleteLater();
329 bool VerifyOpaqueBodyPartMemento::startKeyListJob()
331 assert( canStartKeyListJob() );
332 if ( const GpgME::Error err
= m_keylistjob
->start( keyListPattern() ) )
334 connect( m_keylistjob
, SIGNAL(done()), this, SLOT(slotKeyListJobDone()) );
335 connect( m_keylistjob
, SIGNAL(nextKey(const GpgME::Key
&)),
336 this, SLOT(slotNextKey(const GpgME::Key
&)) );
340 void VerifyOpaqueBodyPartMemento::slotNextKey( const GpgME::Key
& key
)
345 void VerifyOpaqueBodyPartMemento::slotKeyListJobDone()
353 #include "objecttreeparser_p.moc"