Commit 72f03799 authored by Laurent Montel's avatar Laurent Montel 😁

Move in own file.

parent d936cdbe
......@@ -80,7 +80,6 @@ set(libmessageviewer_viewer_SRCS
viewer/attachmenttemporaryfilesdirs.cpp
viewer/objecttreeemptysource.cpp
viewer/objecttreeparser.cpp
viewer/objecttreeparser_p.cpp
viewer/objecttreeviewersource.cpp
viewer/partnodebodypart.cpp
viewer/pluginloaderbase.cpp
......@@ -89,6 +88,10 @@ set(libmessageviewer_viewer_SRCS
viewer/messagedisplayformatattribute.cpp
viewer/urlhandlermanager.cpp
viewer/mimeparttreeview.cpp
viewer/cryptobodypartmemento.cpp
viewer/decryptverifybodypartmemento.cpp
viewer/verifydetachedbodypartmemento.cpp
viewer/verifyopaquebodypartmemento.cpp
)
set(libmessageviewer_widgets_SRCS
......
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "cryptobodypartmemento.h"
#include <kdebug.h>
#include <kleo/decryptverifyjob.h>
#include <kleo/verifydetachedjob.h>
#include <kleo/verifyopaquejob.h>
#include <kleo/keylistjob.h>
#include <gpgme++/keylistresult.h>
using namespace Kleo;
using namespace GpgME;
using namespace MessageViewer;
CryptoBodyPartMemento::CryptoBodyPartMemento()
: QObject( 0 ),
Interface::BodyPartMemento(),
m_running( false )
{
}
CryptoBodyPartMemento::~CryptoBodyPartMemento()
{
}
bool CryptoBodyPartMemento::isRunning() const
{
return m_running;
}
void CryptoBodyPartMemento::setAuditLog( const Error & err, const QString & log )
{
m_auditLogError = err;
m_auditLog = log;
}
void CryptoBodyPartMemento::setRunning( bool running )
{
m_running = running;
}
void CryptoBodyPartMemento::detach()
{
disconnect( this, SIGNAL(update(MessageViewer::Viewer::UpdateMode)), 0, 0 );
}
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef CRYPTOBODYPARTMEMENTO_H
#define CRYPTOBODYPARTMEMENTO_H
#include <gpgme++/verificationresult.h>
#include <gpgme++/decryptionresult.h>
#include <gpgme++/key.h>
#include <QObject>
#include <QString>
#include "interfaces/bodypart.h"
#include "viewer/viewer.h"
namespace MessageViewer {
class CryptoBodyPartMemento
: public QObject,
public Interface::BodyPartMemento
{
Q_OBJECT
public:
CryptoBodyPartMemento();
~CryptoBodyPartMemento();
bool isRunning() const;
const QString & auditLogAsHtml() const { return m_auditLog; }
GpgME::Error auditLogError() const { return m_auditLogError; }
void detach();
signals:
void update(MessageViewer::Viewer::UpdateMode);
protected slots:
void notify() {
emit update(Viewer::Force);
}
protected:
void setAuditLog( const GpgME::Error & err, const QString & log );
void setRunning( bool running );
private:
bool m_running;
QString m_auditLog;
GpgME::Error m_auditLogError;
};
}
#endif // CRYPTOBODYPARTMEMENTO_H
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "decryptverifybodypartmemento.h"
#include <kdebug.h>
#include <kleo/decryptverifyjob.h>
#include <gpgme++/keylistresult.h>
#include <qstringlist.h>
using namespace Kleo;
using namespace GpgME;
using namespace MessageViewer;
DecryptVerifyBodyPartMemento::DecryptVerifyBodyPartMemento( DecryptVerifyJob * job, const QByteArray & cipherText )
: CryptoBodyPartMemento(),
m_cipherText( cipherText ),
m_job( job )
{
assert( m_job );
}
DecryptVerifyBodyPartMemento::~DecryptVerifyBodyPartMemento() {
if ( m_job )
m_job->slotCancel();
}
bool DecryptVerifyBodyPartMemento::start() {
assert( m_job );
if ( const Error err = m_job->start( m_cipherText ) ) {
m_dr = DecryptionResult( err );
return false;
}
connect( m_job, SIGNAL(result(GpgME::DecryptionResult,GpgME::VerificationResult,QByteArray)),
this, SLOT(slotResult(GpgME::DecryptionResult,GpgME::VerificationResult,QByteArray)) );
setRunning( true );
return true;
}
void DecryptVerifyBodyPartMemento::exec() {
assert( m_job );
QByteArray plainText;
setRunning( true );
const std::pair<DecryptionResult,VerificationResult> p = m_job->exec( m_cipherText, plainText );
saveResult( p.first, p.second, plainText );
m_job->deleteLater(); // exec'ed jobs don't delete themselves
m_job = 0;
}
void DecryptVerifyBodyPartMemento::saveResult( const DecryptionResult & dr,
const VerificationResult & vr,
const QByteArray & plainText )
{
assert( m_job );
setRunning( false );
m_dr = dr;
m_vr = vr;
m_plainText = plainText;
setAuditLog( m_job->auditLogError(), m_job->auditLogAsHtml() );
}
void DecryptVerifyBodyPartMemento::slotResult( const DecryptionResult & dr,
const VerificationResult & vr,
const QByteArray & plainText )
{
saveResult( dr, vr, plainText );
m_job = 0;
notify();
}
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef DECRYPTVERIFYBODYPARTMEMENTO_H
#define DECRYPTVERIFYBODYPARTMEMENTO_H
#include "cryptobodypartmemento.h"
#include <gpgme++/verificationresult.h>
#include <gpgme++/decryptionresult.h>
#include <gpgme++/key.h>
#include <QObject>
#include <QString>
#include <QPointer>
#include "interfaces/bodypart.h"
#include "viewer/viewer.h"
namespace Kleo {
class DecryptVerifyJob;
}
namespace MessageViewer {
class DecryptVerifyBodyPartMemento
: public CryptoBodyPartMemento
{
Q_OBJECT
public:
DecryptVerifyBodyPartMemento( Kleo::DecryptVerifyJob * job, const QByteArray & cipherText );
~DecryptVerifyBodyPartMemento();
bool start();
void exec();
const QByteArray & plainText() const { return m_plainText; }
const GpgME::DecryptionResult & decryptResult() const { return m_dr; }
const GpgME::VerificationResult & verifyResult() const { return m_vr; }
private slots:
void slotResult( const GpgME::DecryptionResult & dr,
const GpgME::VerificationResult & vr,
const QByteArray & plainText );
private:
void saveResult( const GpgME::DecryptionResult &,
const GpgME::VerificationResult &,
const QByteArray & );
private:
// input:
const QByteArray m_cipherText;
QPointer<Kleo::DecryptVerifyJob> m_job;
// output:
GpgME::DecryptionResult m_dr;
GpgME::VerificationResult m_vr;
QByteArray m_plainText;
};
}
#endif // DECRYPTVERIFYBODYPARTMEMENTO_H
......@@ -36,7 +36,10 @@
#include "objecttreeparser.h"
#include "objecttreeparser_p.h"
#include "verifydetachedbodypartmemento.h"
#include "verifyopaquebodypartmemento.h"
#include "cryptobodypartmemento.h"
#include "decryptverifybodypartmemento.h"
#include "objecttreesourceif.h"
#include "utils/autoqpointer.h"
#include "viewer/viewer_p.h"
......
/* -*- mode: C++; c-file-style: "gnu" -*-
objecttreeparser_p.h
This file is part of KMail, the KDE mail client.
Copyright (C) 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net
Copyright (c) 2009 Andras Mantia <andras@kdab.net>
KMail is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
KMail is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#ifndef _MESSAGEVIEWER_OBJECTTREEPARSER_P_H_
#define _MESSAGEVIEWER_OBJECTTREEPARSER_P_H_
#include <gpgme++/verificationresult.h>
#include <gpgme++/decryptionresult.h>
#include <gpgme++/key.h>
#include <QObject>
#include <QString>
#include <QPointer>
#include "interfaces/bodypart.h"
#include "viewer/viewer.h"
namespace Kleo {
class DecryptVerifyJob;
class VerifyDetachedJob;
class VerifyOpaqueJob;
class KeyListJob;
}
class QStringList;
namespace MessageViewer {
class CryptoBodyPartMemento
: public QObject,
public Interface::BodyPartMemento
{
Q_OBJECT
public:
CryptoBodyPartMemento();
~CryptoBodyPartMemento();
bool isRunning() const { return m_running; }
const QString & auditLogAsHtml() const { return m_auditLog; }
GpgME::Error auditLogError() const { return m_auditLogError; }
void detach();
signals:
void update(MessageViewer::Viewer::UpdateMode);
protected slots:
void notify() {
emit update(Viewer::Force);
}
protected:
void setAuditLog( const GpgME::Error & err, const QString & log );
void setRunning( bool running );
private:
bool m_running;
QString m_auditLog;
GpgME::Error m_auditLogError;
};
class DecryptVerifyBodyPartMemento
: public CryptoBodyPartMemento
{
Q_OBJECT
public:
DecryptVerifyBodyPartMemento( Kleo::DecryptVerifyJob * job, const QByteArray & cipherText );
~DecryptVerifyBodyPartMemento();
bool start();
void exec();
const QByteArray & plainText() const { return m_plainText; }
const GpgME::DecryptionResult & decryptResult() const { return m_dr; }
const GpgME::VerificationResult & verifyResult() const { return m_vr; }
private slots:
void slotResult( const GpgME::DecryptionResult & dr,
const GpgME::VerificationResult & vr,
const QByteArray & plainText );
private:
void saveResult( const GpgME::DecryptionResult &,
const GpgME::VerificationResult &,
const QByteArray & );
private:
// input:
const QByteArray m_cipherText;
QPointer<Kleo::DecryptVerifyJob> m_job;
// output:
GpgME::DecryptionResult m_dr;
GpgME::VerificationResult m_vr;
QByteArray m_plainText;
};
class VerifyDetachedBodyPartMemento
: public CryptoBodyPartMemento
{
Q_OBJECT
public:
VerifyDetachedBodyPartMemento( Kleo::VerifyDetachedJob * job,
Kleo::KeyListJob * klj,
const QByteArray & signature,
const QByteArray & plainText );
~VerifyDetachedBodyPartMemento();
bool start();
void exec();
const GpgME::VerificationResult & verifyResult() const { return m_vr; }
const GpgME::Key & signingKey() const { return m_key; }
private slots:
void slotResult( const GpgME::VerificationResult & vr );
void slotKeyListJobDone();
void slotNextKey( const GpgME::Key & );
private:
void saveResult( const GpgME::VerificationResult & );
bool canStartKeyListJob() const;
QStringList keyListPattern() const;
bool startKeyListJob();
private:
// input:
const QByteArray m_signature;
const QByteArray m_plainText;
QPointer<Kleo::VerifyDetachedJob> m_job;
QPointer<Kleo::KeyListJob> m_keylistjob;
// output:
GpgME::VerificationResult m_vr;
GpgME::Key m_key;
};
class VerifyOpaqueBodyPartMemento
: public CryptoBodyPartMemento
{
Q_OBJECT
public:
VerifyOpaqueBodyPartMemento( Kleo::VerifyOpaqueJob * job,
Kleo::KeyListJob * klj,
const QByteArray & signature );
~VerifyOpaqueBodyPartMemento();
bool start();
void exec();
const QByteArray & plainText() const { return m_plainText; }
const GpgME::VerificationResult & verifyResult() const { return m_vr; }
const GpgME::Key & signingKey() const { return m_key; }
private slots:
void slotResult( const GpgME::VerificationResult & vr,
const QByteArray & plainText );
void slotKeyListJobDone();
void slotNextKey( const GpgME::Key & );
private:
void saveResult( const GpgME::VerificationResult &,
const QByteArray & );
bool canStartKeyListJob() const;
QStringList keyListPattern() const;
bool startKeyListJob();
private:
// input:
const QByteArray m_signature;
QPointer<Kleo::VerifyOpaqueJob> m_job;
QPointer<Kleo::KeyListJob> m_keylistjob;
// output:
GpgME::VerificationResult m_vr;
QByteArray m_plainText;
GpgME::Key m_key;
};
}
#endif // _KMAIL_OBJECTTREEPARSER_H_
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "verifydetachedbodypartmemento.h"
#include <kdebug.h>
#include <kleo/verifydetachedjob.h>
#include <kleo/keylistjob.h>
#include <gpgme++/keylistresult.h>
#include <qstringlist.h>
#include <cassert>
using namespace Kleo;
using namespace GpgME;
using namespace MessageViewer;
VerifyDetachedBodyPartMemento::VerifyDetachedBodyPartMemento( VerifyDetachedJob * job,
KeyListJob * klj,
const QByteArray & signature,
const QByteArray & plainText )
: CryptoBodyPartMemento(),
m_signature( signature ),
m_plainText( plainText ),
m_job( job ),
m_keylistjob( klj )
{
assert( m_job );
}
VerifyDetachedBodyPartMemento::~VerifyDetachedBodyPartMemento() {
if ( m_job )
m_job->slotCancel();
if ( m_keylistjob )
m_keylistjob->slotCancel();
}
bool VerifyDetachedBodyPartMemento::start() {
assert( m_job );
#ifdef DEBUG_SIGNATURE
kDebug() << "tokoe: VerifyDetachedBodyPartMemento started";
#endif
connect( m_job, SIGNAL(result(GpgME::VerificationResult)),
this, SLOT(slotResult(GpgME::VerificationResult)) );
if ( const Error err = m_job->start( m_signature, m_plainText ) ) {
m_vr = VerificationResult( err );
#ifdef DEBUG_SIGNATURE
kDebug() << "tokoe: VerifyDetachedBodyPartMemento stopped with error";
#endif
return false;
}
setRunning( true );
return true;
}
void VerifyDetachedBodyPartMemento::exec() {
assert( m_job );
setRunning( true );
#ifdef DEBUG_SIGNATURE
kDebug() << "tokoe: VerifyDetachedBodyPartMemento execed";
#endif
saveResult( m_job->exec( m_signature, m_plainText ) );
m_job->deleteLater(); // exec'ed jobs don't delete themselves
m_job = 0;
#ifdef DEBUG_SIGNATURE
kDebug() << "tokoe: VerifyDetachedBodyPartMemento after execed";
#endif
if ( canStartKeyListJob() ) {
std::vector<GpgME::Key> keys;
m_keylistjob->exec( keyListPattern(), /*secretOnly=*/false, keys );
if ( !keys.empty() )
m_key = keys.back();
}
if ( m_keylistjob )
m_keylistjob->deleteLater(); // exec'ed jobs don't delete themselves
m_keylistjob = 0;
setRunning( false );
}
bool VerifyDetachedBodyPartMemento::canStartKeyListJob() const
{
if ( !m_keylistjob )
return false;
const char * const fpr = m_vr.signature( 0 ).fingerprint();