File indexing completed on 2024-12-15 04:47:02
0001 /* 0002 SPDX-FileCopyrightText: 2012-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "pmailsettings.h" 0008 #include <ImportWizard/ImportWizardUtil> 0009 0010 #include <MailCommon/MailUtil> 0011 #include <MailTransport/TransportManager> 0012 0013 #include <KIdentityManagementCore/Identity> 0014 0015 #include <KConfig> 0016 #include <KConfigGroup> 0017 #include <QFile> 0018 #include <QFileInfo> 0019 #include <QRegularExpression> 0020 0021 PMailSettings::PMailSettings(const QString &filename) 0022 : mFileName(filename) 0023 { 0024 } 0025 0026 void PMailSettings::importSettings() 0027 { 0028 if (QFileInfo::exists(mFileName)) { 0029 KConfig config(mFileName); 0030 0031 const QStringList accountList = config.groupList().filter(QRegularExpression(QStringLiteral("WinPMail Identity - *"))); 0032 const QStringList::const_iterator end(accountList.constEnd()); 0033 for (QStringList::const_iterator it = accountList.constBegin(); it != end; ++it) { 0034 KConfigGroup group = config.group(*it); 0035 readIdentity(group); 0036 } 0037 } 0038 } 0039 0040 PMailSettings::~PMailSettings() 0041 { 0042 } 0043 0044 void PMailSettings::readIdentity(const KConfigGroup &group) 0045 { 0046 QString personalNameStr = QStringLiteral("Personal name "); 0047 QString personalName; 0048 if (group.hasKey(personalNameStr)) { 0049 personalName = group.readEntry(personalNameStr); 0050 personalName.remove(0, 1); // Remove first space 0051 } 0052 KIdentityManagementCore::Identity *newIdentity = createIdentity(personalName); 0053 newIdentity->setFullName(personalName); 0054 newIdentity->setIdentityName(personalName); 0055 0056 const QString emailStr = QStringLiteral("Internet E-mail Address "); 0057 if (group.hasKey(emailStr)) { 0058 QString email = group.readEntry(emailStr); 0059 email.remove(0, 1); // Remove first space 0060 newIdentity->setPrimaryEmailAddress(email); 0061 } 0062 const QString replytoStr = QStringLiteral("Default reply-to address "); 0063 if (group.hasKey(replytoStr)) { 0064 QString reply = group.readEntry(replytoStr); 0065 reply.remove(0, 1); // Remove first space 0066 newIdentity->setReplyToAddr(reply); 0067 } 0068 storeIdentity(newIdentity); 0069 }