File indexing completed on 2024-12-22 05:07:40
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Sandro Knauß <knauss@kolabsys.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 // This code was taken from kmail-account-wizard 0008 0009 #include "autoconfigkolabmail.h" 0010 #include <QDomDocument> 0011 0012 AutoconfigKolabMail::AutoconfigKolabMail(QObject *parent) 0013 : Ispdb(parent) 0014 { 0015 } 0016 0017 void AutoconfigKolabMail::startJob(const QUrl &url) 0018 { 0019 mData.clear(); 0020 QMap<QString, QVariant> map; 0021 map[QStringLiteral("errorPage")] = false; 0022 map[QStringLiteral("no-auth-prompt")] = true; 0023 map[QStringLiteral("no-www-auth")] = true; 0024 0025 KIO::TransferJob *job = KIO::get(url, KIO::NoReload, KIO::HideProgressInfo); 0026 job->setMetaData(map); 0027 connect(job, &KIO::TransferJob::result, this, &AutoconfigKolabMail::slotResult); 0028 connect(job, &KIO::TransferJob::data, this, &AutoconfigKolabMail::dataArrived); 0029 } 0030 0031 void AutoconfigKolabMail::slotResult(KJob *job) 0032 { 0033 if (job->error()) { 0034 if (job->error() == KIO::ERR_INTERNAL_SERVER // error 500 0035 || job->error() == KIO::ERR_UNKNOWN_HOST // unknown host 0036 || job->error() == KIO::ERR_CANNOT_CONNECT || job->error() == KIO::ERR_DOES_NOT_EXIST) { // error 404 0037 if (serverType() == DataBase) { 0038 setServerType(IspAutoConfig); 0039 lookupInDb(false, false); 0040 } else if (serverType() == IspAutoConfig) { 0041 setServerType(IspWellKnow); 0042 lookupInDb(false, false); 0043 } else { 0044 Q_EMIT finished(false); 0045 } 0046 } else { 0047 // qCDebug(ACCOUNTWIZARD_LOG) << "Fetching failed" << job->error() << job->errorString(); 0048 Q_EMIT finished(false); 0049 } 0050 return; 0051 } 0052 0053 auto *tjob = qobject_cast<KIO::TransferJob *>(job); 0054 0055 int responsecode = tjob->queryMetaData(QStringLiteral("responsecode")).toInt(); 0056 0057 if (responsecode == 401) { 0058 lookupInDb(true, true); 0059 return; 0060 } else if (responsecode != 200 && responsecode != 0 && responsecode != 304) { 0061 // qCDebug(ACCOUNTWIZARD_LOG) << "Fetching failed with" << responsecode; 0062 Q_EMIT finished(false); 0063 return; 0064 } 0065 0066 QDomDocument document; 0067 bool ok = document.setContent(mData); 0068 if (!ok) { 0069 // qCDebug(ACCOUNTWIZARD_LOG) << "Could not parse xml" << mData; 0070 Q_EMIT finished(false); 0071 return; 0072 } 0073 parseResult(document); 0074 }