Commit bf0d09cd authored by Laurent Montel's avatar Laurent Montel 😁

Merge remote-tracking branch 'origin/Applications/17.04'

parents 1666c706 4918895a
...@@ -33,8 +33,8 @@ inline bool initSASL() ...@@ -33,8 +33,8 @@ inline bool initSASL()
#ifdef Q_OS_WIN32 //krazy:exclude=cpp #ifdef Q_OS_WIN32 //krazy:exclude=cpp
QByteArray libInstallPath(QFile::encodeName(QDir::toNativeSeparators(KGlobal::dirs()->installPath("lib") + QLatin1String("sasl2")))); QByteArray libInstallPath(QFile::encodeName(QDir::toNativeSeparators(KGlobal::dirs()->installPath("lib") + QLatin1String("sasl2"))));
QByteArray configPath(QFile::encodeName(QDir::toNativeSeparators(KGlobal::dirs()->installPath("config") + QLatin1String("sasl2")))); QByteArray configPath(QFile::encodeName(QDir::toNativeSeparators(KGlobal::dirs()->installPath("config") + QLatin1String("sasl2"))));
if (sasl_set_path(SASL_PATH_TYPE_PLUGIN, libInstallPath.data()) != SASL_OK || if (sasl_set_path(SASL_PATH_TYPE_PLUGIN, libInstallPath.data()) != SASL_OK
sasl_set_path(SASL_PATH_TYPE_CONFIG, configPath.data()) != SASL_OK) { || sasl_set_path(SASL_PATH_TYPE_CONFIG, configPath.data()) != SASL_OK) {
fprintf(stderr, "SASL path initialization failed!\n"); fprintf(stderr, "SASL path initialization failed!\n");
return false; return false;
} }
......
...@@ -32,17 +32,15 @@ ...@@ -32,17 +32,15 @@
#include "capabilities.h" #include "capabilities.h"
#include "response.h" #include "response.h"
namespace KioSMTP namespace KioSMTP {
{
Capabilities Capabilities::fromResponse(const Response &ehlo) Capabilities Capabilities::fromResponse(const Response &ehlo)
{ {
Capabilities c; Capabilities c;
// first, check whether the response was valid and indicates success: // first, check whether the response was valid and indicates success:
if (!ehlo.isOk() if (!ehlo.isOk()
|| ehlo.code() / 10 != 25 // ### restrict to 250 only? || ehlo.code() / 10 != 25 // ### restrict to 250 only?
|| ehlo.lines().empty()) { || ehlo.lines().empty()) {
return c; return c;
} }
...@@ -109,7 +107,7 @@ QStringList Capabilities::saslMethodsQSL() const ...@@ -109,7 +107,7 @@ QStringList Capabilities::saslMethodsQSL() const
{ {
QStringList result; QStringList result;
for (QMap<QString, QStringList>::const_iterator it = mCapabilities.begin(); for (QMap<QString, QStringList>::const_iterator it = mCapabilities.begin();
it != mCapabilities.end(); ++it) { it != mCapabilities.end(); ++it) {
if (it.key() == QLatin1String("AUTH")) { if (it.key() == QLatin1String("AUTH")) {
result += it.value(); result += it.value();
} else if (it.key().startsWith(QLatin1String("AUTH="))) { } else if (it.key().startsWith(QLatin1String("AUTH="))) {
...@@ -120,5 +118,4 @@ QStringList Capabilities::saslMethodsQSL() const ...@@ -120,5 +118,4 @@ QStringList Capabilities::saslMethodsQSL() const
result.removeDuplicates(); result.removeDuplicates();
return result; return result;
} }
} // namespace KioSMTP } // namespace KioSMTP
...@@ -36,9 +36,7 @@ ...@@ -36,9 +36,7 @@
#include <QStringList> #include <QStringList>
namespace KioSMTP namespace KioSMTP {
{
class Response; class Response;
class Capabilities class Capabilities
...@@ -61,10 +59,12 @@ public: ...@@ -61,10 +59,12 @@ public:
{ {
return mCapabilities.find(cap.toUpper()) != mCapabilities.end(); return mCapabilities.find(cap.toUpper()) != mCapabilities.end();
} }
bool have(const QByteArray &cap) const bool have(const QByteArray &cap) const
{ {
return have(QString::fromLatin1(cap)); return have(QString::fromLatin1(cap));
} }
bool have(const char *cap) const bool have(const char *cap) const
{ {
return have(QString::fromLatin1(cap)); return have(QString::fromLatin1(cap));
...@@ -81,7 +81,6 @@ private: ...@@ -81,7 +81,6 @@ private:
QMap<QString, QStringList> mCapabilities; QMap<QString, QStringList> mCapabilities;
}; };
} // namespace KioSMTP } // namespace KioSMTP
#endif // __KIOSMTP_CAPABILITIES_H__ #endif // __KIOSMTP_CAPABILITIES_H__
...@@ -43,9 +43,7 @@ ...@@ -43,9 +43,7 @@
#include <assert.h> #include <assert.h>
namespace KioSMTP namespace KioSMTP {
{
static const sasl_callback_t callbacks[] = { static const sasl_callback_t callbacks[] = {
{ SASL_CB_ECHOPROMPT, nullptr, nullptr }, { SASL_CB_ECHOPROMPT, nullptr, nullptr },
{ SASL_CB_NOECHOPROMPT, nullptr, nullptr }, { SASL_CB_NOECHOPROMPT, nullptr, nullptr },
...@@ -156,7 +154,7 @@ bool EHLOCommand::processResponse(const Response &r, TransactionState *ts) ...@@ -156,7 +154,7 @@ bool EHLOCommand::processResponse(const Response &r, TransactionState *ts)
return true; return true;
} }
mComplete = true; mComplete = true;
if (r.code() / 10 == 25) { // 25x: success if (r.code() / 10 == 25) { // 25x: success
parseFeatures(r); parseFeatures(r);
return true; return true;
} }
...@@ -207,15 +205,12 @@ bool StartTLSCommand::processResponse(const Response &r, TransactionState *ts) ...@@ -207,15 +205,12 @@ bool StartTLSCommand::processResponse(const Response &r, TransactionState *ts)
#define SASLERROR mSMTP->error(KIO::ERR_COULD_NOT_AUTHENTICATE, \ #define SASLERROR mSMTP->error(KIO::ERR_COULD_NOT_AUTHENTICATE, \
i18n("An error occurred during authentication: %1", \ i18n("An error occurred during authentication: %1", \
QString::fromUtf8( sasl_errdetail( conn ) ))); QString::fromUtf8(sasl_errdetail(conn))));
// //
// AUTH - rfc 2554 // AUTH - rfc 2554
// //
AuthCommand::AuthCommand(SMTPSessionInterface *smtp, AuthCommand::AuthCommand(SMTPSessionInterface *smtp, const char *mechanisms, const QString &aFQDN, KIO::AuthInfo &ai)
const char *mechanisms,
const QString &aFQDN,
KIO::AuthInfo &ai)
: Command(smtp, CloseConnectionOnError | OnlyLastInPipeline) : Command(smtp, CloseConnectionOnError | OnlyLastInPipeline)
, mAi(&ai) , mAi(&ai)
, mFirstTime(true) , mFirstTime(true)
...@@ -242,7 +237,7 @@ AuthCommand::AuthCommand(SMTPSessionInterface *smtp, ...@@ -242,7 +237,7 @@ AuthCommand::AuthCommand(SMTPSessionInterface *smtp,
if (result == SASL_INTERACT) { if (result == SASL_INTERACT) {
if (!saslInteract(client_interact)) { if (!saslInteract(client_interact)) {
return; return;
}; }
} }
} while (result == SASL_INTERACT); } while (result == SASL_INTERACT);
if (result != SASL_CONTINUE && result != SASL_OK) { if (result != SASL_CONTINUE && result != SASL_OK) {
...@@ -267,14 +262,13 @@ AuthCommand::~AuthCommand() ...@@ -267,14 +262,13 @@ AuthCommand::~AuthCommand()
bool AuthCommand::saslInteract(void *in) bool AuthCommand::saslInteract(void *in)
{ {
qCDebug(SMTP_LOG) << "saslInteract: "; qCDebug(SMTP_LOG) << "saslInteract: ";
sasl_interact_t *interact = (sasl_interact_t *) in; sasl_interact_t *interact = (sasl_interact_t *)in;
//some mechanisms do not require username && pass, so don't need a popup //some mechanisms do not require username && pass, so don't need a popup
//window for getting this info //window for getting this info
for (; interact->id != SASL_CB_LIST_END; interact++) { for (; interact->id != SASL_CB_LIST_END; interact++) {
if (interact->id == SASL_CB_AUTHNAME || if (interact->id == SASL_CB_AUTHNAME
interact->id == SASL_CB_PASS) { || interact->id == SASL_CB_PASS) {
if (mAi->username.isEmpty() || mAi->password.isEmpty()) { if (mAi->username.isEmpty() || mAi->password.isEmpty()) {
if (!mSMTP->openPasswordDialog(*mAi)) { if (!mSMTP->openPasswordDialog(*mAi)) {
mSMTP->error(KIO::ERR_ABORTED, i18n("No authentication details supplied.")); mSMTP->error(KIO::ERR_ABORTED, i18n("No authentication details supplied."));
...@@ -285,22 +279,24 @@ bool AuthCommand::saslInteract(void *in) ...@@ -285,22 +279,24 @@ bool AuthCommand::saslInteract(void *in)
} }
} }
interact = (sasl_interact_t *) in; interact = (sasl_interact_t *)in;
while (interact->id != SASL_CB_LIST_END) { while (interact->id != SASL_CB_LIST_END) {
switch (interact->id) { switch (interact->id) {
case SASL_CB_USER: case SASL_CB_USER:
case SASL_CB_AUTHNAME: { case SASL_CB_AUTHNAME:
{
qCDebug(SMTP_LOG) << "SASL_CB_[USER|AUTHNAME]: " << mAi->username; qCDebug(SMTP_LOG) << "SASL_CB_[USER|AUTHNAME]: " << mAi->username;
const QByteArray baUserName = mAi->username.toUtf8(); const QByteArray baUserName = mAi->username.toUtf8();
interact->result = strdup(baUserName.constData()); interact->result = strdup(baUserName.constData());
interact->len = strlen((const char *) interact->result); interact->len = strlen((const char *)interact->result);
break; break;
} }
case SASL_CB_PASS: { case SASL_CB_PASS:
{
qCDebug(SMTP_LOG) << "SASL_CB_PASS: [HIDDEN]"; qCDebug(SMTP_LOG) << "SASL_CB_PASS: [HIDDEN]";
const QByteArray baPassword = mAi->password.toUtf8(); const QByteArray baPassword = mAi->password.toUtf8();
interact->result = strdup(baPassword.constData()); interact->result = strdup(baPassword.constData());
interact->len = strlen((const char *) interact->result); interact->len = strlen((const char *)interact->result);
break; break;
} }
default: default:
...@@ -362,7 +358,7 @@ QByteArray AuthCommand::nextCommandLine(TransactionState *ts) ...@@ -362,7 +358,7 @@ QByteArray AuthCommand::nextCommandLine(TransactionState *ts)
if (result == SASL_INTERACT) { if (result == SASL_INTERACT) {
if (!saslInteract(client_interact)) { if (!saslInteract(client_interact)) {
return ""; return "";
}; }
} }
} while (result == SASL_INTERACT); } while (result == SASL_INTERACT);
if (result != SASL_CONTINUE && result != SASL_OK) { if (result != SASL_CONTINUE && result != SASL_OK) {
...@@ -649,5 +645,4 @@ QByteArray QuitCommand::nextCommandLine(TransactionState *ts) ...@@ -649,5 +645,4 @@ QByteArray QuitCommand::nextCommandLine(TransactionState *ts)
mNeedResponse = true; mNeedResponse = true;
return "QUIT\r\n"; return "QUIT\r\n";
} }
} // namespace KioSMTP } // namespace KioSMTP
...@@ -41,9 +41,7 @@ extern "C" { ...@@ -41,9 +41,7 @@ extern "C" {
#include <kio/authinfo.h> #include <kio/authinfo.h>
namespace KioSMTP namespace KioSMTP {
{
class Response; class Response;
class TransactionState; class TransactionState;
class SMTPSessionInterface; class SMTPSessionInterface;
...@@ -145,10 +143,12 @@ public: ...@@ -145,10 +143,12 @@ public:
{ {
return mFlags & CloseConnectionOnError; return mFlags & CloseConnectionOnError;
} }
bool mustBeLastInPipeline() const bool mustBeLastInPipeline() const
{ {
return mFlags & OnlyLastInPipeline; return mFlags & OnlyLastInPipeline;
} }
bool mustBeFirstInPipeline() const bool mustBeFirstInPipeline() const
{ {
return mFlags & OnlyFirstInPipeline; return mFlags & OnlyFirstInPipeline;
...@@ -200,8 +200,7 @@ public: ...@@ -200,8 +200,7 @@ public:
class AuthCommand : public Command class AuthCommand : public Command
{ {
public: public:
AuthCommand(SMTPSessionInterface *smtp, const char *mechanisms, AuthCommand(SMTPSessionInterface *smtp, const char *mechanisms, const QString &aFQDN, KIO::AuthInfo &ai);
const QString &aFQDN, KIO::AuthInfo &ai);
~AuthCommand(); ~AuthCommand();
bool doNotExecute(const TransactionState *ts) const Q_DECL_OVERRIDE; bool doNotExecute(const TransactionState *ts) const Q_DECL_OVERRIDE;
QByteArray nextCommandLine(TransactionState *ts) Q_DECL_OVERRIDE; QByteArray nextCommandLine(TransactionState *ts) Q_DECL_OVERRIDE;
...@@ -226,8 +225,7 @@ private: ...@@ -226,8 +225,7 @@ private:
class MailFromCommand : public Command class MailFromCommand : public Command
{ {
public: public:
MailFromCommand(SMTPSessionInterface *smtp, const QByteArray &addr, MailFromCommand(SMTPSessionInterface *smtp, const QByteArray &addr, bool eightBit = false, unsigned int size = 0)
bool eightBit = false, unsigned int size = 0)
: Command(smtp) : Command(smtp)
, mAddr(addr) , mAddr(addr)
, m8Bit(eightBit) , m8Bit(eightBit)
...@@ -328,7 +326,6 @@ public: ...@@ -328,7 +326,6 @@ public:
QByteArray nextCommandLine(TransactionState *ts) Q_DECL_OVERRIDE; QByteArray nextCommandLine(TransactionState *ts) Q_DECL_OVERRIDE;
}; };
} // namespace KioSMTP } // namespace KioSMTP
#endif // __KIOSMTP_COMMAND_H__ #endif // __KIOSMTP_COMMAND_H__
...@@ -23,9 +23,7 @@ ...@@ -23,9 +23,7 @@
#include "smtpsessioninterface.h" #include "smtpsessioninterface.h"
#include "smtp.h" #include "smtp.h"
namespace KioSMTP namespace KioSMTP {
{
class KioSlaveSession : public SMTPSessionInterface class KioSlaveSession : public SMTPSessionInterface
{ {
public: public:
...@@ -46,7 +44,6 @@ public: ...@@ -46,7 +44,6 @@ public:
private: private:
SMTPProtocol *m_protocol; SMTPProtocol *m_protocol;
}; };
} }
#endif #endif
...@@ -38,9 +38,7 @@ ...@@ -38,9 +38,7 @@
#include <assert.h> #include <assert.h>
namespace KioSMTP namespace KioSMTP {
{
Request Request::fromURL(const QUrl &url) Request Request::fromURL(const QUrl &url)
{ {
Request request; Request request;
...@@ -192,5 +190,4 @@ QByteArray Request::headerFields(const QString &fromRealName) const ...@@ -192,5 +190,4 @@ QByteArray Request::headerFields(const QString &fromRealName) const
} }
return result; return result;
} }
} // namespace KioSMTP } // namespace KioSMTP
...@@ -37,9 +37,7 @@ ...@@ -37,9 +37,7 @@
class QUrl; class QUrl;
namespace KioSMTP namespace KioSMTP {
{
class Request class Request
{ {
public: public:
...@@ -57,10 +55,12 @@ public: ...@@ -57,10 +55,12 @@ public:
{ {
return mProfileName; return mProfileName;
} }
void setProfileName(const QString &profileName) void setProfileName(const QString &profileName)
{ {
mProfileName = profileName; mProfileName = profileName;
} }
bool hasProfile() const bool hasProfile() const
{ {
return !profileName().isNull(); return !profileName().isNull();
...@@ -70,6 +70,7 @@ public: ...@@ -70,6 +70,7 @@ public:
{ {
return mSubject; return mSubject;
} }
void setSubject(const QString &subject) void setSubject(const QString &subject)
{ {
mSubject = subject; mSubject = subject;
...@@ -79,10 +80,12 @@ public: ...@@ -79,10 +80,12 @@ public:
{ {
return mFromAddress; return mFromAddress;
} }
void setFromAddress(const QString &fromAddress) void setFromAddress(const QString &fromAddress)
{ {
mFromAddress = fromAddress; mFromAddress = fromAddress;
} }
bool hasFromAddress() const bool hasFromAddress() const
{ {
return !mFromAddress.isEmpty(); return !mFromAddress.isEmpty();
...@@ -92,6 +95,7 @@ public: ...@@ -92,6 +95,7 @@ public:
{ {
return to() + cc() + bcc(); return to() + cc() + bcc();
} }
bool hasRecipients() const bool hasRecipients() const
{ {
return !to().empty() || !cc().empty() || !bcc().empty(); return !to().empty() || !cc().empty() || !bcc().empty();
...@@ -101,22 +105,27 @@ public: ...@@ -101,22 +105,27 @@ public:
{ {
return mTo; return mTo;
} }
QStringList cc() const QStringList cc() const
{ {
return mCc; return mCc;
} }
QStringList bcc() const QStringList bcc() const
{ {
return mBcc; return mBcc;
} }
void addTo(const QString &to) void addTo(const QString &to)
{ {
mTo.push_back(to); mTo.push_back(to);
} }
void addCc(const QString &cc) void addCc(const QString &cc)
{ {
mCc.push_back(cc); mCc.push_back(cc);
} }
void addBcc(const QString &bcc) void addBcc(const QString &bcc)
{ {
mBcc.push_back(bcc); mBcc.push_back(bcc);
...@@ -126,6 +135,7 @@ public: ...@@ -126,6 +135,7 @@ public:
{ {
return mHeloHostname; return mHeloHostname;
} }
QByteArray heloHostnameCString() const; QByteArray heloHostnameCString() const;
void setHeloHostname(const QString &hostname) void setHeloHostname(const QString &hostname)
{ {
...@@ -136,6 +146,7 @@ public: ...@@ -136,6 +146,7 @@ public:
{ {
return mEmitHeaders; return mEmitHeaders;
} }
void setEmitHeaders(bool emitHeaders) void setEmitHeaders(bool emitHeaders)
{ {
mEmitHeaders = emitHeaders; mEmitHeaders = emitHeaders;
...@@ -145,6 +156,7 @@ public: ...@@ -145,6 +156,7 @@ public:
{ {
return m8Bit; return m8Bit;
} }
void set8BitBody(bool a8Bit) void set8BitBody(bool a8Bit)
{ {
m8Bit = a8Bit; m8Bit = a8Bit;
...@@ -154,6 +166,7 @@ public: ...@@ -154,6 +166,7 @@ public:
{ {
return mSize; return mSize;
} }
void setSize(unsigned int size) void setSize(unsigned int size)
{ {
mSize = size; mSize = size;
...@@ -174,7 +187,6 @@ private: ...@@ -174,7 +187,6 @@ private:
bool m8Bit; bool m8Bit;
unsigned int mSize; unsigned int mSize;
}; };
} // namespace KioSMTP } // namespace KioSMTP
#endif // __KIOSMTP_REQUEST_H__ #endif // __KIOSMTP_REQUEST_H__
...@@ -36,12 +36,9 @@ ...@@ -36,12 +36,9 @@
#include <QByteArray> #include <QByteArray>
namespace KioSMTP namespace KioSMTP {
{
void Response::parseLine(const char *line, int len) void Response::parseLine(const char *line, int len)
{ {
if (!isWellFormed()) { if (!isWellFormed()) {
return; // don't bother return; // don't bother