Commit 9b29aa98 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

run git clang-format

parent e5061b97
......@@ -13,8 +13,7 @@
using namespace MailTransport;
K_PLUGIN_FACTORY(MailTransportConfigFactory, registerPlugin<ConfigModule>();
)
K_PLUGIN_FACTORY(MailTransportConfigFactory, registerPlugin<ConfigModule>();)
ConfigModule::ConfigModule(QWidget *parent, const QVariantList &args)
: KCModule(parent, args)
......
......@@ -9,7 +9,8 @@
#include <KCModule>
namespace MailTransport {
namespace MailTransport
{
/**
KCModule for transport management.
*/
......
......@@ -11,11 +11,11 @@
/* Classes which are exported only for unit tests */
#ifdef BUILD_TESTING
# ifndef KMAILTRANSPORT_TESTS_EXPORT
# define KMAILTRANSPORT_TESTS_EXPORT MAILTRANSPORT_EXPORT
# endif
#ifndef KMAILTRANSPORT_TESTS_EXPORT
#define KMAILTRANSPORT_TESTS_EXPORT MAILTRANSPORT_EXPORT
#endif
#else /* not compiling tests */
# define KMAILTRANSPORT_TESTS_EXPORT
#define KMAILTRANSPORT_TESTS_EXPORT
#endif
#endif
......@@ -8,9 +8,9 @@
#include "fakeserver.h"
#include <QTest>
#include <QFile>
#include <QDebug>
#include <QFile>
#include <QTest>
FakeServer::FakeServer(QObject *parent)
: QThread(parent)
......@@ -26,18 +26,12 @@ QByteArray FakeServer::greeting()
QList<QByteArray> FakeServer::greetingAndEhlo(bool multiline)
{
return QList<QByteArray>() << greeting()
<< "C: EHLO 127.0.0.1"
<< QByteArray("S: 250") + (multiline ? '-' : ' ') + "Localhost ready to roll";
return QList<QByteArray>() << greeting() << "C: EHLO 127.0.0.1" << QByteArray("S: 250") + (multiline ? '-' : ' ') + "Localhost ready to roll";
}
QList<QByteArray> FakeServer::bye()
{
return {
"C: QUIT",
"S: 221 So long, and thanks for all the fish",
"X: "
};
return {"C: QUIT", "S: 221 So long, and thanks for all the fish", "X: "};
}
FakeServer::~FakeServer()
......@@ -74,7 +68,7 @@ void FakeServer::newConnection()
m_clientSockets << m_tcpServer->nextPendingConnection();
connect(m_clientSockets.last(), &QIODevice::readyRead, this, &FakeServer::dataAvailable);
//m_clientParsers << new KIMAP::ImapStreamParser( m_clientSockets.last(), true );
// m_clientParsers << new KIMAP::ImapStreamParser( m_clientSockets.last(), true );
QVERIFY(m_clientSockets.size() <= m_scenarios.size());
......@@ -127,7 +121,7 @@ void FakeServer::addScenarioFromFile(const QString &fileName)
// When loading from files we never have the authentication phase
// force jumping directly to authenticated state.
//scenario << preauth();
// scenario << preauth();
while (!file.atEnd()) {
scenario << file.readLine().trimmed();
......@@ -168,8 +162,7 @@ void FakeServer::writeServerPart(int scenarioNumber)
QList<QByteArray> scenario = m_scenarios[scenarioNumber];
QTcpSocket *clientSocket = m_clientSockets[scenarioNumber];
while (!scenario.isEmpty()
&& (scenario.first().startsWith("S: ") || scenario.first().startsWith("W: "))) {
while (!scenario.isEmpty() && (scenario.first().startsWith("S: ") || scenario.first().startsWith("W: "))) {
QByteArray rule = scenario.takeFirst();
if (rule.startsWith("S: ")) {
......
......@@ -9,10 +9,10 @@
#ifndef KSMTP_FAKESERVER_H
#define KSMTP_FAKESERVER_H
#include <QThread>
#include <QMutex>
#include <QTcpServer>
#include <QTcpSocket>
#include <QMutex>
#include <QThread>
Q_DECLARE_METATYPE(QList<QByteArray>)
......@@ -46,7 +46,7 @@ private:
void writeServerPart(int scenarioNumber);
void readClientPart(int scenarioNumber);
QList< QList<QByteArray> > m_scenarios;
QList<QList<QByteArray>> m_scenarios;
QTcpServer *m_tcpServer = nullptr;
mutable QMutex m_mutex;
QList<QTcpSocket *> m_clientSockets;
......
......@@ -11,8 +11,8 @@
#include "transportmanager.h"
#include <QObject>
#include <QTest>
#include <QStandardPaths>
#include <QTest>
Q_DECLARE_METATYPE(MailTransport::TransportBase::EnumAuthenticationType::type)
......@@ -28,7 +28,7 @@ private Q_SLOTS:
void smtpJobTest_data()
{
QTest::addColumn<QList<QByteArray> >("scenario");
QTest::addColumn<QList<QByteArray>>("scenario");
QTest::addColumn<MailTransport::TransportBase::EnumAuthenticationType::type>("authType");
QTest::addColumn<QString>("from");
QTest::addColumn<QStringList>("to");
......@@ -37,8 +37,7 @@ private Q_SLOTS:
QTest::addColumn<bool>("success");
QList<QByteArray> scenario;
scenario << FakeServer::greetingAndEhlo()
<< "S: 250 AUTH PLAIN LOGIN"
scenario << FakeServer::greetingAndEhlo() << "S: 250 AUTH PLAIN LOGIN"
<< "C: AUTH LOGIN"
<< "S: 334 VXNlcm5hbWU6"
<< "C: bG9naW4=" // "login".toBase64()
......@@ -56,16 +55,9 @@ private Q_SLOTS:
<< "C: Hi Bob"
<< "C: "
<< "C: ."
<< "S: 250 Ok transfer done"
<< FakeServer::bye();
QTest::newRow("simple") << scenario << MailTransport::TransportBase::EnumAuthenticationType::LOGIN
<< QStringLiteral("Foo Bar <foo@bar.com>")
<< QStringList{}
<< QStringList{
QStringLiteral("bar@foo.com"), QStringLiteral("<bar@bar.foo>")
}
<< QByteArray("Hi Bob")
<< true;
<< "S: 250 Ok transfer done" << FakeServer::bye();
QTest::newRow("simple") << scenario << MailTransport::TransportBase::EnumAuthenticationType::LOGIN << QStringLiteral("Foo Bar <foo@bar.com>")
<< QStringList{} << QStringList{QStringLiteral("bar@foo.com"), QStringLiteral("<bar@bar.foo>")} << QByteArray("Hi Bob") << true;
}
void smtpJobTest()
......
......@@ -6,14 +6,14 @@
#include "smtpconfigdialog.h"
#include "smtpconfigwidget.h"
#include "transport.h"
#include "transportmanager.h"
#include "transporttype.h"
#include "smtpconfigwidget.h"
#include <QDialogButtonBox>
#include <QVBoxLayout>
#include <QPushButton>
#include <QVBoxLayout>
using namespace MailTransport;
......
......@@ -9,7 +9,8 @@
#include <QDialog>
namespace MailTransport {
namespace MailTransport
{
class Transport;
class SMTPConfigWidget;
class SmtpConfigDialog : public QDialog
......
......@@ -14,19 +14,19 @@
#include "smtpconfigwidget.h"
#include "ui_smtpsettings.h"
#include "widgets/transportconfigwidget_p.h"
#include "transport.h"
#include "transportmanager.h"
#include "servertest.h"
#include "mailtransport_defs.h"
#include "mailtransportplugin_smtp_debug.h"
#include "servertest.h"
#include "transport.h"
#include "transportmanager.h"
#include "widgets/transportconfigwidget_p.h"
#include <QAbstractButton>
#include <QButtonGroup>
#include <KProtocolInfo>
#include "mailtransport_debug.h"
#include <KMessageBox>
#include <KProtocolInfo>
using namespace MailTransport;
......@@ -45,19 +45,14 @@ public:
static void addAuthenticationItem(QComboBox *combo, int authenticationType)
{
combo->addItem(Transport::authenticationTypeString(authenticationType),
QVariant(authenticationType));
combo->addItem(Transport::authenticationTypeString(authenticationType), QVariant(authenticationType));
}
void resetAuthCapabilities()
{
noEncCapa.clear();
noEncCapa << Transport::EnumAuthenticationType::LOGIN
<< Transport::EnumAuthenticationType::PLAIN
<< Transport::EnumAuthenticationType::CRAM_MD5
<< Transport::EnumAuthenticationType::DIGEST_MD5
<< Transport::EnumAuthenticationType::NTLM
<< Transport::EnumAuthenticationType::GSSAPI
noEncCapa << Transport::EnumAuthenticationType::LOGIN << Transport::EnumAuthenticationType::PLAIN << Transport::EnumAuthenticationType::CRAM_MD5
<< Transport::EnumAuthenticationType::DIGEST_MD5 << Transport::EnumAuthenticationType::NTLM << Transport::EnumAuthenticationType::GSSAPI
<< Transport::EnumAuthenticationType::XOAUTH2;
sslCapa = tlsCapa = noEncCapa;
updateAuthCapbilities();
......@@ -141,7 +136,7 @@ void SMTPConfigWidget::init()
d->serverTestFailed = false;
d->ui.setupUi(this);
d->manager->addWidget(this); // otherwise it doesn't find out about these widgets
d->manager->addWidget(this); // otherwise it doesn't find out about these widgets
d->manager->updateWidgets();
d->ui.password->setWhatsThis(i18n("The password to send to the server for authorization."));
......@@ -159,10 +154,8 @@ void SMTPConfigWidget::init()
d->resetAuthCapabilities();
if (!KProtocolInfo::capabilities(SMTP_PROTOCOL).contains(QLatin1String("SASL"))) {
d->ui.authCombo->removeItem(d->ui.authCombo->findData(
Transport::EnumAuthenticationType::NTLM));
d->ui.authCombo->removeItem(d->ui.authCombo->findData(
Transport::EnumAuthenticationType::GSSAPI));
d->ui.authCombo->removeItem(d->ui.authCombo->findData(Transport::EnumAuthenticationType::NTLM));
d->ui.authCombo->removeItem(d->ui.authCombo->findData(Transport::EnumAuthenticationType::GSSAPI));
}
connect(d->ui.checkCapabilities, &QPushButton::clicked, this, &SMTPConfigWidget::checkSmtpCapabilities);
......@@ -219,7 +212,7 @@ void SMTPConfigWidget::checkSmtpCapabilities()
qApp->setOverrideCursor(Qt::BusyCursor);
connect(d->serverTest, &ServerTest::finished, this, &SMTPConfigWidget::slotFinished);
connect(d->serverTest, &ServerTest::finished, qApp, [](){
connect(d->serverTest, &ServerTest::finished, qApp, []() {
qApp->restoreOverrideCursor();
});
d->ui.checkCapabilities->setEnabled(false);
......@@ -233,7 +226,7 @@ void SMTPConfigWidget::apply()
Q_ASSERT(d->manager);
d->manager->updateSettings();
if (!d->ui.kcfg_storePassword->isChecked() && d->ui.kcfg_requiresAuthentication->isChecked()) {
//Delete stored password
// Delete stored password
TransportManager::self()->removePasswordFromWallet(d->transport->id());
}
d->transport->setPassword(d->ui.password->password());
......@@ -300,7 +293,7 @@ void SMTPConfigWidget::slotFinished(const QVector<int> &results)
}
d->sslCapa = d->serverTest->secureProtocols();
d->updateAuthCapbilities();
//Show correct port from capabilities.
// Show correct port from capabilities.
if (d->ui.encryptionSsl->isEnabled()) {
const int portValue = d->serverTest->port(Transport::EnumEncryption::SSL);
d->ui.kcfg_port->setValue(portValue == -1 ? SMTPS_PORT : portValue);
......
......@@ -15,7 +15,8 @@
#include "widgets/transportconfigwidget.h"
class QAbstractButton;
namespace MailTransport {
namespace MailTransport
{
class Transport;
/**
......
......@@ -8,25 +8,25 @@
*/
#include "smtpjob.h"
#include "transport.h"
#include "mailtransport_defs.h"
#include "mailtransportplugin_smtp_debug.h"
#include "precommandjob.h"
#include "sessionuiproxy.h"
#include "mailtransportplugin_smtp_debug.h"
#include "transport.h"
#include <QHash>
#include <QPointer>
#include <KLocalizedString>
#include "mailtransport_debug.h"
#include <KLocalizedString>
#include <KPasswordDialog>
#include <KSMTP/LoginJob>
#include <KSMTP/SendJob>
#include <KGAPI/Account>
#include <KGAPI/AuthJob>
#include <KGAPI/AccountManager>
#include <KGAPI/AuthJob>
#define GOOGLE_API_KEY QStringLiteral("554041944266.apps.googleusercontent.com")
#define GOOGLE_API_SECRET QStringLiteral("mdT1DjzohxN3npUUzkENT0gO")
......@@ -44,8 +44,7 @@ public:
qCDebug(MAILTRANSPORT_SMTP_LOG) << "Removing session" << session << "from the pool";
int key = sessions.key(session);
if (key > 0) {
QObject::connect(session, &KSmtp::Session::stateChanged,
[session](KSmtp::Session::State state) {
QObject::connect(session, &KSmtp::Session::stateChanged, [session](KSmtp::Session::State state) {
if (state == KSmtp::Session::Disconnected) {
session->deleteLater();
}
......@@ -65,7 +64,8 @@ Q_GLOBAL_STATIC(SessionPool, s_sessionPool)
class SmtpJobPrivate
{
public:
SmtpJobPrivate(SmtpJob *parent) : q(parent)
SmtpJobPrivate(SmtpJob *parent)
: q(parent)
{
}
......@@ -74,9 +74,7 @@ public:
SmtpJob *const q;
KSmtp::Session *session = nullptr;
KSmtp::SessionUiProxy::Ptr uiProxy;
enum State {
Idle, Precommand, Smtp
} currentState;
enum State { Idle, Precommand, Smtp } currentState;
bool finished;
};
......@@ -113,9 +111,7 @@ void SmtpJob::doStart()
return;
}
if ((!s_sessionPool->sessions.isEmpty()
&& s_sessionPool->sessions.contains(transport()->id()))
|| transport()->precommand().isEmpty()) {
if ((!s_sessionPool->sessions.isEmpty() && s_sessionPool->sessions.contains(transport()->id())) || transport()->precommand().isEmpty()) {
d->currentState = SmtpJobPrivate::Smtp;
startSmtpJob();
} else {
......@@ -143,10 +139,8 @@ void SmtpJob::startSmtpJob()
s_sessionPool->sessions.insert(transport()->id(), d->session);
}
connect(d->session, &KSmtp::Session::stateChanged,
this, &SmtpJob::sessionStateChanged, Qt::UniqueConnection);
connect(d->session, &KSmtp::Session::connectionError,
this, [this](const QString &err) {
connect(d->session, &KSmtp::Session::stateChanged, this, &SmtpJob::sessionStateChanged, Qt::UniqueConnection);
connect(d->session, &KSmtp::Session::connectionError, this, [this](const QString &err) {
setError(KJob::UserDefinedError);
setErrorText(err);
s_sessionPool->removeSession(d->session);
......@@ -181,25 +175,22 @@ void SmtpJob::startPasswordRetrieval(bool forceRefresh)
}
if (transport()->authenticationType() == TransportBase::EnumAuthenticationType::XOAUTH2) {
auto promise = KGAPI2::AccountManager::instance()->findAccount(
GOOGLE_API_KEY, transport()->userName(), { KGAPI2::Account::mailScopeUrl() });
connect(promise, &KGAPI2::AccountPromise::finished,
this, [forceRefresh, this](KGAPI2::AccountPromise *promise) {
auto promise = KGAPI2::AccountManager::instance()->findAccount(GOOGLE_API_KEY, transport()->userName(), {KGAPI2::Account::mailScopeUrl()});
connect(promise, &KGAPI2::AccountPromise::finished, this, [forceRefresh, this](KGAPI2::AccountPromise *promise) {
if (promise->account()) {
if (forceRefresh) {
promise = KGAPI2::AccountManager::instance()->refreshTokens(
GOOGLE_API_KEY, GOOGLE_API_SECRET, transport()->userName());
promise = KGAPI2::AccountManager::instance()->refreshTokens(GOOGLE_API_KEY, GOOGLE_API_SECRET, transport()->userName());
} else {
onTokenRequestFinished(promise);
return;
}
} else {
promise = KGAPI2::AccountManager::instance()->getAccount(
GOOGLE_API_KEY, GOOGLE_API_SECRET, transport()->userName(),
{ KGAPI2::Account::mailScopeUrl() });
promise = KGAPI2::AccountManager::instance()->getAccount(GOOGLE_API_KEY,
GOOGLE_API_SECRET,
transport()->userName(),
{KGAPI2::Account::mailScopeUrl()});
}
connect(promise, &KGAPI2::AccountPromise::finished,
this, &SmtpJob::onTokenRequestFinished);
connect(promise, &KGAPI2::AccountPromise::finished, this, &SmtpJob::onTokenRequestFinished);
});
} else {
startLoginJob();
......@@ -217,8 +208,7 @@ void SmtpJob::onTokenRequestFinished(KGAPI2::AccountPromise *promise)
}
const auto account = promise->account();
const QString tokens = QStringLiteral("%1\001%2").arg(account->accessToken(),
account->refreshToken());
const QString tokens = QStringLiteral("%1\001%2").arg(account->accessToken(), account->refreshToken());
transport()->setPassword(tokens);
startLoginJob();
}
......@@ -232,16 +222,12 @@ void SmtpJob::startLoginJob()
auto user = transport()->userName();
auto passwd = transport()->password();
if ((user.isEmpty() || passwd.isEmpty())
&& transport()->authenticationType() != Transport::EnumAuthenticationType::GSSAPI) {
QPointer<KPasswordDialog> dlg
= new KPasswordDialog(
nullptr,
KPasswordDialog::ShowUsernameLine
|KPasswordDialog::ShowKeepPassword);
if ((user.isEmpty() || passwd.isEmpty()) && transport()->authenticationType() != Transport::EnumAuthenticationType::GSSAPI) {
QPointer<KPasswordDialog> dlg = new KPasswordDialog(nullptr, KPasswordDialog::ShowUsernameLine | KPasswordDialog::ShowKeepPassword);
dlg->setAttribute(Qt::WA_DeleteOnClose, true);
dlg->setPrompt(i18n("You need to supply a username and a password "
"to use this SMTP server."));
dlg->setPrompt(
i18n("You need to supply a username and a password "
"to use this SMTP server."));
dlg->setKeepPassword(transport()->storePassword());
dlg->addCommentLine(QString(), transport()->name());
dlg->setUsername(user);
......
......@@ -10,21 +10,24 @@
#ifndef MAILTRANSPORT_SMTPJOB_H
#define MAILTRANSPORT_SMTPJOB_H
#include <transportjob.h>
#include <KSMTP/Session>
#include <transportjob.h>
namespace KIO {
namespace KIO
{
class Job;
class Slave;
}
namespace KGAPI2 {
namespace KGAPI2
{
class AccountPromise;
}
class SmtpJobPrivate;
namespace MailTransport {
namespace MailTransport
{
/**
Mail transport job for SMTP.
Internally, all jobs for a specific transport are queued to use the same
......
......@@ -7,8 +7,8 @@
#include "smtpmailtransportplugin.h"
#include "smtpconfigdialog.h"
#include "smtpjob.h"
#include <KPluginFactory>
#include <KLocalizedString>
#include <KPluginFactory>
K_PLUGIN_CLASS_WITH_JSON(SMTPMailTransportPlugin, "smtpmailtransport.json")
......@@ -35,8 +35,7 @@ QVector<MailTransport::TransportAbstractPluginInfo> SMTPMailTransportPlugin::nam
bool SMTPMailTransportPlugin::configureTransport(const QString &identifier, MailTransport::Transport *transport, QWidget *parent)
{
Q_UNUSED(identifier)
QPointer<MailTransport::SmtpConfigDialog> transportConfigDialog
= new MailTransport::SmtpConfigDialog(transport, parent);
QPointer<MailTransport::SmtpConfigDialog> transportConfigDialog = new MailTransport::SmtpConfigDialog(transport, parent);
transportConfigDialog->setWindowTitle(i18nc("@title:window", "Configure account"));
bool okClicked = (transportConfigDialog->exec() == QDialog::Accepted);
delete transportConfigDialog;
......
......@@ -14,8 +14,7 @@ class SMTPMailTransportPlugin : public MailTransport::TransportAbstractPlugin
{
Q_OBJECT
public:
explicit SMTPMailTransportPlugin(QObject *parent = nullptr, const QList<QVariant> & = {
});
explicit SMTPMailTransportPlugin(QObject *parent = nullptr, const QList<QVariant> & = {});
~SMTPMailTransportPlugin() override;
Q_REQUIRED_RESULT QVector<MailTransport::TransportAbstractPluginInfo> names() const override;
......
......@@ -6,8 +6,8 @@
#include "transportmanagertest.h"
#include "kmailtransport/plugins/transportpluginmanager.h"
#include <QCoreApplication>
#include <MailTransport/TransportAbstractPlugin>
#include <QCoreApplication>
#include <QDebug>
TransportManagerTest::TransportManagerTest(QObject *parent)
......
......@@ -7,18 +7,18 @@
#ifndef TRANSPORTABSTRACTPLUGIN_H
#define TRANSPORTABSTRACTPLUGIN_H
#include "mailtransport_export.h"
#include <QObject>
#include <QVector>
#include "mailtransport_export.h"
namespace MailTransport {
namespace MailTransport
{
class TransportJob;
class Transport;
/**
* @brief The TransportAbstractPluginInfo struct
* @author Laurent Montel <montel@kde.org>
*/
struct MAILTRANSPORT_EXPORT TransportAbstractPluginInfo
{
struct MAILTRANSPORT_EXPORT TransportAbstractPluginInfo {
QString name;
QString identifier;
QString description;
......
......@@ -6,9 +6,9 @@
#include "transportpluginmanager.h"
#include "mailtransport_debug.h"
#include <kpluginmetadata.h>
#include <KPluginLoader>
#include <KPluginFactory>
#include <KPluginLoader>
#include <kpluginmetadata.h>
#include <MailTransport/TransportAbstractPlugin>
......@@ -24,7 +24,8 @@ public:
MailTransport::TransportAbstractPlugin *plugin = nullptr;
};
namespace {
namespace
{
QString pluginVersion()
{
return QStringLiteral("1.0");
......@@ -44,6 +45,7 @@ public:
QVector<MailTransport::TransportAbstractPlugin *> pluginsList() const;
QVector<MailTransportPluginInfo> mPluginList;
bool initializePlugins();
private:
TransportPluginManager *q;
};
......
......@@ -7,9 +7,10 @@
#ifndef TRANSPORTPLUGINMANAGER_H