Commit e2cc5024 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Try to abstract mailtransport

parent bab64eeb
......@@ -1331,3 +1331,200 @@ void ImportMailJobInterface::convertCollectionStrToAkonadiId(const KSharedConfig
(void)convertRealPathToCollection(eventGroup, key, false);
}
}
SmtpMailTransport::SmtpMailTransport(const KConfigGroup &group)
{
setName(group.readEntry(QStringLiteral("name")));
const QString hostStr(QStringLiteral("host"));
if (group.hasKey(hostStr)) {
setHost(group.readEntry(hostStr));
}
const QString portStr(QStringLiteral("port"));
if (group.hasKey(portStr)) {
setPort(group.readEntry(portStr, -1));
}
const QString userNameStr(QStringLiteral("user"));
if (group.hasKey(userNameStr)) {
setUserName(group.readEntry(userNameStr));
}
const QString precommandStr(QStringLiteral("precommand"));
if (group.hasKey(precommandStr)) {
setPrecommand(group.readEntry(precommandStr));
}
const QString requiresAuthenticationStr(QStringLiteral("auth"));
if (group.hasKey(requiresAuthenticationStr)) {
setRequiresAuthentication(group.readEntry(requiresAuthenticationStr, false));
}
const QString specifyHostnameStr(QStringLiteral("specifyHostname"));
if (group.hasKey(specifyHostnameStr)) {
setSpecifyHostname(group.readEntry(specifyHostnameStr, false));
}
const QString localHostnameStr(QStringLiteral("localHostname"));
if (group.hasKey(localHostnameStr)) {
setLocalHostname(group.readEntry(localHostnameStr));
}
const QString specifySenderOverwriteAddressStr(QStringLiteral("specifySenderOverwriteAddress"));
if (group.hasKey(specifySenderOverwriteAddressStr)) {
setSpecifySenderOverwriteAddress(group.readEntry(specifySenderOverwriteAddressStr, false));
}
const QString storePasswordStr(QStringLiteral("storepass"));
if (group.hasKey(storePasswordStr)) {
setStorePassword(group.readEntry(storePasswordStr, false));
}
const QString senderOverwriteAddressStr(QStringLiteral("senderOverwriteAddress"));
if (group.hasKey(senderOverwriteAddressStr)) {
setSenderOverwriteAddress(group.readEntry(senderOverwriteAddressStr));
}
const QString encryptionStr(QStringLiteral("encryption"));
if (group.hasKey(encryptionStr)) {
const QString encryptionType = group.readEntry(encryptionStr, QString());
if (!encryptionType.isEmpty()) {
if (encryptionType == QLatin1String("TLS")) {
setEncryption(static_cast<int>(MailTransport::TransportBase::EnumEncryption::TLS));
} else if (encryptionType == QLatin1String("SSL")) {
setEncryption(static_cast<int>(MailTransport::TransportBase::EnumEncryption::SSL));
} else if (encryptionType == QLatin1String("None")) {
setEncryption(static_cast<int>(MailTransport::TransportBase::EnumEncryption::None));
} else {
qCWarning(PIMDATAEXPORTERCORE_LOG) << "Unknown encryption type " << encryptionType;
}
} else {
qCWarning(PIMDATAEXPORTERCORE_LOG) << "Encryption type is empty. It's a bug";
}
setEncryption(group.readEntry(encryptionStr, 1)); //TODO verify
}
const QString authenticationTypeStr(QStringLiteral("authtype"));
if (group.hasKey(authenticationTypeStr)) {
setAuthenticationType(group.readEntry(authenticationTypeStr, 1)); //TODO verify
}
}
QString SmtpMailTransport::name() const
{
return mName;
}
void SmtpMailTransport::setName(const QString &name)
{
mName = name;
}
QString SmtpMailTransport::host() const
{
return mHost;
}
void SmtpMailTransport::setHost(const QString &host)
{
mHost = host;
}
int SmtpMailTransport::port() const
{
return mPort;
}
void SmtpMailTransport::setPort(int port)
{
mPort = port;
}
QString SmtpMailTransport::userName() const
{
return mUserName;
}
void SmtpMailTransport::setUserName(const QString &userName)
{
mUserName = userName;
}
QString SmtpMailTransport::precommand() const
{
return mPrecommand;
}
void SmtpMailTransport::setPrecommand(const QString &precommand)
{
mPrecommand = precommand;
}
bool SmtpMailTransport::requiresAuthentication() const
{
return mRequiresAuthentication;
}
void SmtpMailTransport::setRequiresAuthentication(bool requiresAuthentication)
{
mRequiresAuthentication = requiresAuthentication;
}
bool SmtpMailTransport::specifyHostname() const
{
return mSpecifyHostname;
}
void SmtpMailTransport::setSpecifyHostname(bool specifyHostname)
{
mSpecifyHostname = specifyHostname;
}
QString SmtpMailTransport::localHostname() const
{
return mLocalHostname;
}
void SmtpMailTransport::setLocalHostname(const QString &localHostname)
{
mLocalHostname = localHostname;
}
bool SmtpMailTransport::specifySenderOverwriteAddress() const
{
return mSpecifySenderOverwriteAddress;
}
void SmtpMailTransport::setSpecifySenderOverwriteAddress(bool specifySenderOverwriteAddress)
{
mSpecifySenderOverwriteAddress = specifySenderOverwriteAddress;
}
bool SmtpMailTransport::storePassword() const
{
return mStorePassword;
}
void SmtpMailTransport::setStorePassword(bool storePassword)
{
mStorePassword = storePassword;
}
QString SmtpMailTransport::senderOverwriteAddress() const
{
return mSenderOverwriteAddress;
}
void SmtpMailTransport::setSenderOverwriteAddress(const QString &senderOverwriteAddress)
{
mSenderOverwriteAddress = senderOverwriteAddress;
}
int SmtpMailTransport::encryption() const
{
return mEncryption;
}
void SmtpMailTransport::setEncryption(int encryption)
{
mEncryption = encryption;
}
int SmtpMailTransport::authenticationType() const
{
return mAuthenticationType;
}
void SmtpMailTransport::setAuthenticationType(int authenticationType)
{
mAuthenticationType = authenticationType;
}
......@@ -36,6 +36,67 @@ class Transport;
namespace MailCommon {
class MailFilter;
}
class PIMDATAEXPORTER_TESTS_EXPORT SmtpMailTransport
{
explicit SmtpMailTransport(const KConfigGroup &group);
public:
Q_REQUIRED_RESULT QString name() const;
void setName(const QString &name);
Q_REQUIRED_RESULT QString host() const;
void setHost(const QString &host);
Q_REQUIRED_RESULT int port() const;
void setPort(int port);
Q_REQUIRED_RESULT QString userName() const;
void setUserName(const QString &userName);
Q_REQUIRED_RESULT QString precommand() const;
void setPrecommand(const QString &precommand);
Q_REQUIRED_RESULT bool requiresAuthentication() const;
void setRequiresAuthentication(bool requiresAuthentication);
Q_REQUIRED_RESULT bool specifyHostname() const;
void setSpecifyHostname(bool specifyHostname);
Q_REQUIRED_RESULT QString localHostname() const;
void setLocalHostname(const QString &localHostname);
Q_REQUIRED_RESULT bool specifySenderOverwriteAddress() const;
void setSpecifySenderOverwriteAddress(bool specifySenderOverwriteAddress);
Q_REQUIRED_RESULT bool storePassword() const;
void setStorePassword(bool storePassword);
Q_REQUIRED_RESULT QString senderOverwriteAddress() const;
void setSenderOverwriteAddress(const QString &senderOverwriteAddress);
Q_REQUIRED_RESULT int encryption() const;
void setEncryption(int encryption);
Q_REQUIRED_RESULT int authenticationType() const;
void setAuthenticationType(int authenticationType);
private:
QString mName;
QString mHost;
QString mUserName;
QString mPrecommand;
QString mLocalHostname;
QString mSenderOverwriteAddress;
int mPort = -1;
int mEncryption = -1;
int mAuthenticationType = 1;
bool mRequiresAuthentication = false;
bool mSpecifyHostname = false;
bool mSpecifySenderOverwriteAddress = false;
bool mStorePassword = false;
};
class PIMDATAEXPORTER_TESTS_EXPORT ImportMailJobInterface : public AbstractImportExportJob
{
Q_OBJECT
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment