6#include "findaccountinfojob.h"
7#include "abstractakonadiimapsettinginterface.h"
8#include "akonadiimapsettinginterface.h"
9#include "libksievecore_debug.h"
10#include "sieveimappasswordprovider.h"
11#include <MailTransport/Transport>
12#include <PimCommon/PimUtil>
15#include <pimcommon/imapresourcesettings.h>
17using namespace KSieveCore;
18FindAccountInfoJob::FindAccountInfoJob(
QObject *parent)
23FindAccountInfoJob::~FindAccountInfoJob() =
default;
25bool FindAccountInfoJob::canStart()
const
30void FindAccountInfoJob::setCustomImapSettingsInterface(AbstractAkonadiImapSettingInterface *newCustomImapSettingsInterface)
32 mCustomImapSettingsInterface = newCustomImapSettingsInterface;
35void FindAccountInfoJob::sendAccountInfo()
38 Q_EMIT findAccountInfoFinished(mAccountInfo);
41void FindAccountInfoJob::start()
44 qCWarning(LIBKSIEVECORE_LOG) <<
"Impossible to start findAccountInfoJob";
48 if (!mPasswordProvider) {
53 mInterfaceImap.reset(PimCommon::Util::createImapSettingsInterface(mIdentifier));
54 mInterface = std::make_unique<KSieveCore::AkonadiImapSettingInterface>(mInterfaceImap);
55 if (!mCustomImapSettingsInterface) {
56 mCustomImapSettingsInterface = mInterface.get();
59 if (!mCustomImapSettingsInterface->sieveSupport()) {
65 const QString reply = mCustomImapSettingsInterface->imapServer();
73 connect(mPasswordProvider, &SieveImapPasswordProvider::passwordsRequested,
this, &FindAccountInfoJob::slotPasswordsRequested);
75 mPasswordProvider->passwords(mIdentifier);
78void FindAccountInfoJob::slotPasswordsRequested(
const QString &sievePassword,
const QString &sieveCustomPassword)
82 sieveUrl.
setScheme(QStringLiteral(
"sieve"));
84 if (mCustomImapSettingsInterface->sieveReuseConfig()) {
86 const QString userName = mCustomImapSettingsInterface->userName();
87 mAccountInfo.sieveImapAccountSettings.setServerName(server);
88 mAccountInfo.sieveImapAccountSettings.setUserName(userName);
94 mAccountInfo.sieveImapAccountSettings.setPassword(sievePassword);
95 mAccountInfo.sieveImapAccountSettings.setPort(mCustomImapSettingsInterface->imapPort());
96 sieveUrl.
setPort(mCustomImapSettingsInterface->sievePort());
98 mAccountInfo.sieveImapAccountSettings.setAuthenticationType(
99 static_cast<SieveImapAccountSettings::AuthenticationMode
>((
int)mCustomImapSettingsInterface->authentication()));
100 switch (mCustomImapSettingsInterface->authentication()) {
101 case MailTransport::Transport::EnumAuthenticationType::CLEAR:
102 case MailTransport::Transport::EnumAuthenticationType::PLAIN:
103 authStr = QStringLiteral(
"PLAIN");
105 case MailTransport::Transport::EnumAuthenticationType::LOGIN:
106 authStr = QStringLiteral(
"LOGIN");
108 case MailTransport::Transport::EnumAuthenticationType::CRAM_MD5:
109 authStr = QStringLiteral(
"CRAM-MD5");
111 case MailTransport::Transport::EnumAuthenticationType::DIGEST_MD5:
112 authStr = QStringLiteral(
"DIGEST-MD5");
114 case MailTransport::Transport::EnumAuthenticationType::GSSAPI:
115 authStr = QStringLiteral(
"GSSAPI");
117 case MailTransport::Transport::EnumAuthenticationType::ANONYMOUS:
118 authStr = QStringLiteral(
"ANONYMOUS");
121 authStr = QStringLiteral(
"PLAIN");
125 query.addQueryItem(QStringLiteral(
"x-mech"), authStr);
126 const QString resultSafety = mCustomImapSettingsInterface->safety();
128 mAccountInfo.sieveImapAccountSettings.setEncryptionMode(SieveImapAccountSettings::Unencrypted);
129 query.addQueryItem(QStringLiteral(
"x-allow-unencrypted"), QStringLiteral(
"true"));
135 mAccountInfo.sieveImapAccountSettings.setEncryptionMode(SieveImapAccountSettings::Unencrypted);
139 const QString userName = mCustomImapSettingsInterface->userName();
140 mAccountInfo.sieveImapAccountSettings.setServerName(server);
141 mAccountInfo.sieveImapAccountSettings.setUserName(userName);
142 mAccountInfo.sieveImapAccountSettings.setAuthenticationType(
143 static_cast<SieveImapAccountSettings::AuthenticationMode
>((
int)mCustomImapSettingsInterface->authentication()));
144 mAccountInfo.sieveImapAccountSettings.setPassword(sievePassword);
145 mAccountInfo.sieveImapAccountSettings.setPort(mCustomImapSettingsInterface->imapPort());
147 sieveUrl.
setHost(mCustomImapSettingsInterface->sieveAlternateUrl());
148 sieveUrl.
setPort(mCustomImapSettingsInterface->sievePort());
150 const QString resultSafety = mCustomImapSettingsInterface->safety();
151 switch (mCustomImapSettingsInterface->alternateAuthentication()) {
152 case MailTransport::Transport::EnumAuthenticationType::CLEAR:
153 case MailTransport::Transport::EnumAuthenticationType::PLAIN:
154 authStr = QStringLiteral(
"PLAIN");
156 case MailTransport::Transport::EnumAuthenticationType::LOGIN:
157 authStr = QStringLiteral(
"LOGIN");
159 case MailTransport::Transport::EnumAuthenticationType::CRAM_MD5:
160 authStr = QStringLiteral(
"CRAM-MD5");
162 case MailTransport::Transport::EnumAuthenticationType::DIGEST_MD5:
163 authStr = QStringLiteral(
"DIGEST-MD5");
165 case MailTransport::Transport::EnumAuthenticationType::GSSAPI:
166 authStr = QStringLiteral(
"GSSAPI");
168 case MailTransport::Transport::EnumAuthenticationType::ANONYMOUS:
169 authStr = QStringLiteral(
"ANONYMOUS");
172 authStr = QStringLiteral(
"PLAIN");
176 query.addQueryItem(QStringLiteral(
"x-mech"), authStr);
179 mAccountInfo.sieveImapAccountSettings.setEncryptionMode(SieveImapAccountSettings::Unencrypted);
180 query.addQueryItem(QStringLiteral(
"x-allow-unencrypted"), QStringLiteral(
"true"));
186 mAccountInfo.sieveImapAccountSettings.setEncryptionMode(SieveImapAccountSettings::Unencrypted);
191 const QString resultCustomAuthentication = mCustomImapSettingsInterface->sieveCustomAuthentification();
193 sieveUrl.
setUserName(mCustomImapSettingsInterface->userName());
194 const QString imapPwd = sievePassword;
196 }
else if (resultCustomAuthentication ==
QLatin1StringView(
"CustomUserPassword")) {
197 const QString customPwd = sieveCustomPassword;
199 sieveUrl.
setUserName(mCustomImapSettingsInterface->sieveCustomUsername());
201 qCWarning(LIBKSIEVECORE_LOG) <<
"resultCustomAuthentication undefined " << resultCustomAuthentication;
205 if (mWithVacationFileName) {
206 sieveUrl.
setPath(sieveUrl.
path() +
QLatin1Char(
'/') + mCustomImapSettingsInterface->sieveVacationFilename());
208 mAccountInfo.sieveUrl = sieveUrl;
212QString FindAccountInfoJob::identifier()
const
217void FindAccountInfoJob::setIdentifier(
const QString &newIdentifier)
219 mIdentifier = newIdentifier;
222bool FindAccountInfoJob::withVacationFileName()
const
224 return mWithVacationFileName;
227void FindAccountInfoJob::setWithVacationFileName(
bool newWithVacationFileName)
229 mWithVacationFileName = newWithVacationFileName;
234 return mPasswordProvider;
239 mPasswordProvider = newProvider;
242#include "moc_findaccountinfojob.cpp"
The SieveImapPasswordProvider class.
KSERVICE_EXPORT KService::List query(FilterFunc filterFunc)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QVariant property(const char *name) const const
QObject * sender() const const
bool setProperty(const char *name, QVariant &&value)
bool isEmpty() const const
QString section(QChar sep, qsizetype start, qsizetype end, SectionFlags flags) const const
QUrl adjusted(FormattingOptions options) const const
QString path(ComponentFormattingOptions options) const const
void setHost(const QString &host, ParsingMode mode)
void setPassword(const QString &password, ParsingMode mode)
void setPath(const QString &path, ParsingMode mode)
void setQuery(const QString &query, ParsingMode mode)
void setScheme(const QString &scheme)
void setUserName(const QString &userName, ParsingMode mode)
QString toString() const const