File indexing completed on 2026-06-07 13:13:44
0001 /* 0002 SPDX-FileCopyrightText: 2014 Sandro Knauß <knauss@kolabsys.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 // This code was taken from kmail-account-wizard 0008 0009 #include "setupispdb.h" 0010 #include "configfile.h" 0011 #include "identity.h" 0012 #include "accounts/ispdb/ispdb.h" 0013 #include "ldap.h" 0014 #include "resource.h" 0015 #include "transport.h" 0016 0017 #include <KLocalizedString> 0018 0019 SetupIspdb::SetupIspdb(QObject *parent) 0020 : SetupObject(parent) 0021 , mIspdb(new Ispdb(this)) 0022 { 0023 connect(mIspdb, &Ispdb::finished, this, &SetupIspdb::onIspdbFinished); 0024 } 0025 0026 SetupIspdb::~SetupIspdb() 0027 { 0028 delete mIspdb; 0029 } 0030 0031 QStringList SetupIspdb::relevantDomains() const 0032 { 0033 return mIspdb->relevantDomains(); 0034 } 0035 0036 QString SetupIspdb::name(int l) const 0037 { 0038 return mIspdb->name(static_cast<Ispdb::length>(l)); 0039 } 0040 0041 int SetupIspdb::defaultIdentity() const 0042 { 0043 return mIspdb->defaultIdentity(); 0044 } 0045 0046 int SetupIspdb::countIdentities() const 0047 { 0048 return mIspdb->identities().count(); 0049 } 0050 0051 void SetupIspdb::fillIdentity(int i, QObject *o) const 0052 { 0053 identity isp = mIspdb->identities().at(i); 0054 0055 auto *id = qobject_cast<Identity *>(o); 0056 0057 id->setIdentityName(isp.name); 0058 id->setRealName(isp.name); 0059 id->setEmail(isp.email); 0060 id->setOrganization(isp.organization); 0061 id->setSignature(isp.signature); 0062 } 0063 0064 void SetupIspdb::fillImapServer(int i, QObject *o) const 0065 { 0066 if (mIspdb->imapServers().isEmpty()) { 0067 return; 0068 } 0069 Server isp = mIspdb->imapServers().at(i); 0070 auto *imapRes = qobject_cast<Resource *>(o); 0071 0072 imapRes->setName(isp.hostname); 0073 imapRes->setOption(QStringLiteral("ImapServer"), isp.hostname); 0074 imapRes->setOption(QStringLiteral("UserName"), isp.username); 0075 imapRes->setOption(QStringLiteral("ImapPort"), isp.port); 0076 imapRes->setOption(QStringLiteral("Authentication"), isp.authentication); // TODO: setup with right authentication 0077 if (isp.socketType == Ispdb::None) { 0078 imapRes->setOption(QStringLiteral("Safety"), QStringLiteral("NONE")); 0079 } else if (isp.socketType == Ispdb::SSL) { 0080 imapRes->setOption(QStringLiteral("Safety"), QStringLiteral("SSL")); 0081 } else { 0082 imapRes->setOption(QStringLiteral("Safety"), QStringLiteral("STARTTLS")); 0083 } 0084 } 0085 0086 int SetupIspdb::countImapServers() const 0087 { 0088 return mIspdb->imapServers().count(); 0089 } 0090 0091 void SetupIspdb::fillSmtpServer(int i, QObject *o) const 0092 { 0093 Server isp = mIspdb->smtpServers().at(i); 0094 auto *smtpRes = qobject_cast<Transport *>(o); 0095 0096 smtpRes->setName(isp.hostname); 0097 smtpRes->setHost(isp.hostname); 0098 smtpRes->setPort(isp.port); 0099 smtpRes->setUsername(isp.username); 0100 0101 switch (isp.authentication) { 0102 case Ispdb::Plain: 0103 smtpRes->setAuthenticationType(QStringLiteral("plain")); 0104 break; 0105 case Ispdb::CramMD5: 0106 smtpRes->setAuthenticationType(QStringLiteral("cram-md5")); 0107 break; 0108 case Ispdb::NTLM: 0109 smtpRes->setAuthenticationType(QStringLiteral("ntlm")); 0110 break; 0111 case Ispdb::GSSAPI: 0112 smtpRes->setAuthenticationType(QStringLiteral("gssapi")); 0113 break; 0114 case Ispdb::ClientIP: 0115 case Ispdb::NoAuth: 0116 default: 0117 break; 0118 } 0119 switch (isp.socketType) { 0120 case Ispdb::None: 0121 smtpRes->setEncryption(QStringLiteral("none")); 0122 break; 0123 case Ispdb::SSL: 0124 smtpRes->setEncryption(QStringLiteral("ssl")); 0125 break; 0126 case Ispdb::StartTLS: 0127 smtpRes->setEncryption(QStringLiteral("tls")); 0128 break; 0129 } 0130 } 0131 0132 int SetupIspdb::countSmtpServers() const 0133 { 0134 return mIspdb->smtpServers().count(); 0135 } 0136 0137 void SetupIspdb::start() 0138 { 0139 mIspdb->start(); 0140 Q_EMIT info(i18n("Searching for autoconfiguration...")); 0141 } 0142 0143 void SetupIspdb::setEmail(const QString &email) 0144 { 0145 mIspdb->setEmail(email); 0146 } 0147 0148 void SetupIspdb::setPassword(const QString &password) 0149 { 0150 mIspdb->setPassword(password); 0151 } 0152 0153 void SetupIspdb::create() 0154 { 0155 } 0156 0157 void SetupIspdb::destroy() 0158 { 0159 } 0160 0161 void SetupIspdb::onIspdbFinished(bool status) 0162 { 0163 Q_EMIT ispdbFinished(status); 0164 if (status) { 0165 Q_EMIT info(i18n("Autoconfiguration found.")); 0166 } else { 0167 Q_EMIT info(i18n("Autoconfiguration failed.")); 0168 } 0169 }