File indexing completed on 2024-12-29 04:44:30
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 "sylpheedsettings.h" 0008 #include "sylpheedsettingsutils.h" 0009 #include <MailCommon/MailUtil> 0010 #include <MailTransport/TransportManager> 0011 #include <QFileInfo> 0012 0013 #include <KIdentityManagementCore/Identity> 0014 #include <KIdentityManagementCore/Signature> 0015 0016 #include "sylpheedplugin_debug.h" 0017 #include <KConfig> 0018 #include <KConfigGroup> 0019 0020 #include <QFile> 0021 #include <QRegularExpression> 0022 #include <QStringList> 0023 0024 SylpheedSettings::SylpheedSettings() = default; 0025 0026 SylpheedSettings::~SylpheedSettings() = default; 0027 0028 void SylpheedSettings::importSettings(const QString &filename, const QString &path) 0029 { 0030 bool checkMailOnStartup = true; 0031 int intervalCheckMail = -1; 0032 const QString sylpheedrc = path + QLatin1StringView("/sylpheedrc"); 0033 if (QFileInfo::exists(sylpheedrc)) { 0034 KConfig configCommon(sylpheedrc); 0035 if (configCommon.hasGroup(QLatin1StringView("Common"))) { 0036 KConfigGroup common = configCommon.group(QStringLiteral("Common")); 0037 checkMailOnStartup = (common.readEntry("check_on_startup", 1) == 1); 0038 0039 if (common.readEntry(QStringLiteral("autochk_newmail"), 1) == 1) { 0040 intervalCheckMail = common.readEntry(QStringLiteral("autochk_interval"), -1); 0041 } 0042 readGlobalSettings(common); 0043 } 0044 } 0045 KConfig config(filename); 0046 const QStringList accountList = config.groupList().filter(QRegularExpression(QStringLiteral("Account: \\d+"))); 0047 const QStringList::const_iterator end(accountList.constEnd()); 0048 for (QStringList::const_iterator it = accountList.constBegin(); it != end; ++it) { 0049 KConfigGroup group = config.group(*it); 0050 readAccount(group, checkMailOnStartup, intervalCheckMail); 0051 readIdentity(group); 0052 } 0053 const QString customheaderrc = path + QLatin1StringView("/customheaderrc"); 0054 QFile customHeaderFile(customheaderrc); 0055 if (customHeaderFile.exists()) { 0056 if (!customHeaderFile.open(QIODevice::ReadOnly)) { 0057 qCDebug(SYLPHEEDPLUGIN_LOG) << " We can't open file" << customheaderrc; 0058 } else { 0059 readCustomHeader(&customHeaderFile); 0060 } 0061 } 0062 } 0063 0064 void SylpheedSettings::readCustomHeader(QFile *customHeaderFile) 0065 { 0066 // In sylpheed we define custom header from account. 0067 // In kmail it's global 0068 QTextStream stream(customHeaderFile); 0069 QMap<QString, QString> header; 0070 while (!stream.atEnd()) { 0071 const QString line = stream.readLine(); 0072 const QStringList lst = line.split(QLatin1Char(':')); 0073 if (lst.count() == 3) { 0074 QString str = lst.at(2); 0075 str.remove(0, 1); 0076 header.insert(lst.at(1), str); 0077 } 0078 } 0079 if (!header.isEmpty()) { 0080 const int oldValue = readKmailSettings(QStringLiteral("General"), QStringLiteral("mime-header-count")); 0081 int newValue = header.count(); 0082 if (oldValue != -1) { 0083 newValue += oldValue; 0084 } 0085 addKmailConfig(QStringLiteral("General"), QStringLiteral("mime-header-count"), newValue); 0086 int currentHeader = (oldValue > 0) ? oldValue : 0; 0087 for (QMapIterator<QString, QString> it(header); it.hasNext();) { 0088 it.next(); 0089 addComposerHeaderGroup(QStringLiteral("Mime #%1").arg(currentHeader), (it).key(), (it).value()); 0090 ++currentHeader; 0091 } 0092 } 0093 } 0094 0095 void SylpheedSettings::readGlobalSettings(const KConfigGroup &group) 0096 { 0097 const bool showTrayIcon = (group.readEntry("show_trayicon", 0) == 1); 0098 addKmailConfig(QStringLiteral("General"), QStringLiteral("SystemTrayEnabled"), showTrayIcon); 0099 0100 const bool cleanTrashOnExit = (group.readEntry("clean_trash_on_exit", 0) == 1); 0101 addKmailConfig(QStringLiteral("General"), QStringLiteral("empty-trash-on-exit"), cleanTrashOnExit); 0102 0103 const bool alwaysMarkReadOnShowMsg = (group.readEntry("always_mark_read_on_show_msg", 0) == 1); 0104 if (alwaysMarkReadOnShowMsg) { 0105 addKmailConfig(QStringLiteral("Behaviour"), QStringLiteral("DelayedMarkAsRead"), true); 0106 addKmailConfig(QStringLiteral("Behaviour"), QStringLiteral("DelayedMarkTime"), 0); 0107 } 0108 0109 if (group.readEntry("enable_autosave", 0) == 1) { 0110 const int autosaveInterval = group.readEntry("autosave_interval", 5); 0111 addKmailConfig(QStringLiteral("Composer"), QStringLiteral("autosave"), autosaveInterval); 0112 } 0113 const bool checkAttach = (group.readEntry("check_attach", 0) == 1); 0114 addKmailConfig(QStringLiteral("Composer"), QStringLiteral("showForgottenAttachmentWarning"), checkAttach); 0115 0116 const QString attachStr = group.readEntry("check_attach_str"); 0117 if (!attachStr.isEmpty()) { 0118 addKmailConfig(QStringLiteral("Composer"), QStringLiteral("attachment-keywords"), attachStr); 0119 } 0120 0121 const int lineWrap = group.readEntry("linewrap_length", 80); 0122 addKmailConfig(QStringLiteral("Composer"), QStringLiteral("break-at"), lineWrap); 0123 addKmailConfig(QStringLiteral("Composer"), QStringLiteral("word-wrap"), true); 0124 0125 if (group.readEntry(QStringLiteral("recycle_quote_colors"), 0) == 1) { 0126 addKmailConfig(QStringLiteral("Reader"), QStringLiteral("RecycleQuoteColors"), true); 0127 } 0128 0129 if (group.readEntry(QStringLiteral("auto_signature"), 0) == 0) { 0130 addKmailConfig(QStringLiteral("Composer"), QStringLiteral("signature"), QStringLiteral("manual")); 0131 } 0132 0133 if (group.readEntry(QStringLiteral("auto_ext_editor"), -1) == 1) { 0134 addKmailConfig(QStringLiteral("General"), QStringLiteral("use-external-editor"), true); 0135 0136 const QString externalEditor = group.readEntry(QStringLiteral("mime_open_command")); 0137 if (!externalEditor.isEmpty()) { 0138 addKmailConfig(QStringLiteral("General"), QStringLiteral("external-editor"), externalEditor); 0139 } 0140 } 0141 0142 readSettingsColor(group); 0143 readTemplateFormat(group); 0144 readTagColor(group); 0145 readDateFormat(group); 0146 } 0147 0148 void SylpheedSettings::readTemplateFormat(const KConfigGroup &group) 0149 { 0150 const QString replyQuote = group.readEntry(QStringLiteral("reply_quote_mark")); 0151 if (!replyQuote.isEmpty()) { 0152 addKmailConfig(QStringLiteral("TemplateParser"), QStringLiteral("QuoteString"), replyQuote); 0153 } 0154 const QString forwardQuote = group.readEntry(QStringLiteral("forward_quote_mark")); 0155 if (!forwardQuote.isEmpty()) { 0156 // Not implemented in kmail 0157 } 0158 const QString replyQuoteFormat = group.readEntry(QStringLiteral("reply_quote_format")); 0159 if (!replyQuoteFormat.isEmpty()) { 0160 addKmailConfig(QStringLiteral("TemplateParser"), QStringLiteral("TemplateReply"), convertToKmailTemplate(replyQuoteFormat)); 0161 } 0162 const QString forwardQuoteFormat = group.readEntry(QStringLiteral("forward_quote_format")); 0163 if (!forwardQuoteFormat.isEmpty()) { 0164 addKmailConfig(QStringLiteral("TemplateParser"), QStringLiteral("TemplateForward"), convertToKmailTemplate(forwardQuoteFormat)); 0165 } 0166 } 0167 0168 void SylpheedSettings::readDateFormat(const KConfigGroup &group) 0169 { 0170 const QString dateFormat = group.readEntry(QStringLiteral("date_format")); 0171 if (!dateFormat.isEmpty()) { 0172 addKmailConfig(QStringLiteral("General"), QStringLiteral("customDateFormat"), dateFormat); 0173 } 0174 } 0175 0176 void SylpheedSettings::readTagColor(const KConfigGroup &group) 0177 { 0178 Q_UNUSED(group) 0179 // TODO 0180 } 0181 0182 void SylpheedSettings::readSettingsColor(const KConfigGroup &group) 0183 { 0184 const bool enableColor = group.readEntry("enable_color", false); 0185 if (enableColor) { 0186 const int colorLevel1 = group.readEntry("quote_level1_color", -1); 0187 if (colorLevel1 != -1) { 0188 //[Reader] QuotedText1 0189 } 0190 const int colorLevel2 = group.readEntry("quote_level2_color", -1); 0191 if (colorLevel2 != -1) { 0192 //[Reader] QuotedText2 0193 } 0194 const int colorLevel3 = group.readEntry("quote_level3_color", -1); 0195 if (colorLevel3 != -1) { 0196 //[Reader] QuotedText3 0197 } 0198 } 0199 } 0200 0201 QString SylpheedSettings::convertToKmailTemplate(const QString &templateStr) 0202 { 0203 QString newTemplate = templateStr; 0204 newTemplate.replace(QLatin1StringView("%date"), QLatin1StringView("%DATE")); 0205 newTemplate.replace(QLatin1StringView("%d"), QLatin1StringView("%DATE")); 0206 newTemplate.replace(QLatin1StringView("%from"), QLatin1StringView("%OTONAME")); 0207 newTemplate.replace(QLatin1StringView("%f"), QLatin1StringView("%OTONAME")); 0208 newTemplate.replace(QLatin1StringView("%to"), QLatin1StringView("%TONAME")); 0209 newTemplate.replace(QLatin1StringView("%t"), QLatin1StringView("%TONAME")); 0210 newTemplate.replace(QLatin1StringView("%cc"), QLatin1StringView("%CCNAME")); 0211 newTemplate.replace(QLatin1StringView("%c"), QLatin1StringView("%CCNAME")); 0212 0213 newTemplate.replace(QLatin1StringView("%email"), QLatin1StringView("%OFROMNAME")); 0214 newTemplate.replace(QLatin1StringView("%A"), QLatin1StringView("%OFROMNAME")); 0215 0216 newTemplate.replace(QLatin1StringView("%cursor"), QLatin1StringView("%CURSOR")); 0217 newTemplate.replace(QLatin1StringView("%X"), QLatin1StringView("%CURSOR")); 0218 0219 newTemplate.replace(QLatin1StringView("%msg"), QLatin1StringView("%TEXT")); 0220 newTemplate.replace(QLatin1StringView("%M"), QLatin1StringView("%TEXT")); 0221 0222 newTemplate.replace(QLatin1StringView("%quoted_msg"), QLatin1StringView("%QUOTE")); 0223 newTemplate.replace(QLatin1StringView("%Q"), QLatin1StringView("%QUOTE")); 0224 0225 newTemplate.replace(QLatin1StringView("%subject"), QLatin1StringView("%OFULLSUBJECT")); 0226 newTemplate.replace(QLatin1StringView("%s"), QLatin1StringView("%OFULLSUBJECT")); 0227 0228 newTemplate.replace(QLatin1StringView("%messageid"), QLatin1StringView("%MSGID")); 0229 newTemplate.replace(QLatin1StringView("%i"), QLatin1StringView("%MSGID")); 0230 0231 newTemplate.replace(QLatin1StringView("%firstname"), QLatin1StringView("%OFROMNAME")); 0232 newTemplate.replace(QLatin1StringView("%F"), QLatin1StringView("%OFROMNAME")); 0233 0234 newTemplate.replace(QLatin1StringView("%lastname"), QLatin1StringView("%OFROMLNAME")); 0235 newTemplate.replace(QLatin1StringView("%L"), QLatin1StringView("%OFROMLNAME")); 0236 0237 newTemplate.replace(QLatin1StringView("%fullname"), QLatin1StringView("%OFROMFNAME")); 0238 newTemplate.replace(QLatin1StringView("%N"), QLatin1StringView("%OFROMFNAME")); 0239 // TODO add more variable 0240 return newTemplate; 0241 } 0242 0243 void SylpheedSettings::readSignature(const KConfigGroup &accountConfig, KIdentityManagementCore::Identity *identity) 0244 { 0245 KIdentityManagementCore::Signature signature; 0246 const int signatureType = accountConfig.readEntry("signature_type", 0); 0247 switch (signatureType) { 0248 case 0: // File 0249 signature.setType(KIdentityManagementCore::Signature::FromFile); 0250 signature.setPath(accountConfig.readEntry("signature_path"), false); 0251 break; 0252 case 1: // Output 0253 signature.setType(KIdentityManagementCore::Signature::FromCommand); 0254 signature.setPath(accountConfig.readEntry("signature_path"), true); 0255 break; 0256 case 2: // Text 0257 signature.setType(KIdentityManagementCore::Signature::Inlined); 0258 signature.setText(accountConfig.readEntry("signature_text")); 0259 break; 0260 default: 0261 qCDebug(SYLPHEEDPLUGIN_LOG) << " signature type unknown :" << signatureType; 0262 break; 0263 } 0264 const int signatureEnabled = accountConfig.readEntry("auto_signature", -1); 0265 switch (signatureEnabled) { 0266 case -1: 0267 break; 0268 case 0: 0269 signature.setEnabledSignature(false); 0270 break; 0271 case 1: 0272 signature.setEnabledSignature(true); 0273 break; 0274 default: 0275 qCDebug(SYLPHEEDPLUGIN_LOG) << " auto_signature undefined " << signatureEnabled; 0276 break; 0277 } 0278 0279 // TODO const bool signatureBeforeQuote = ( accountConfig.readEntry( "signature_before_quote", 0 ) == 1 ); not implemented in kmail 0280 0281 identity->setSignature(signature); 0282 } 0283 0284 void SylpheedSettings::readPop3Account(const KConfigGroup &accountConfig, bool checkMailOnStartup, int intervalCheckMail) 0285 { 0286 QMap<QString, QVariant> settings; 0287 const QString host = accountConfig.readEntry("receive_server"); 0288 settings.insert(QStringLiteral("Host"), host); 0289 0290 const QString name = accountConfig.readEntry(QStringLiteral("name")); 0291 const QString inbox = MailCommon::Util::convertFolderPathToCollectionStr(accountConfig.readEntry(QStringLiteral("inbox"))); 0292 settings.insert(QStringLiteral("TargetCollection"), inbox); 0293 int port = 0; 0294 if (SylpheedSettingsUtils::readConfig(QStringLiteral("pop_port"), accountConfig, port, true)) { 0295 settings.insert(QStringLiteral("Port"), port); 0296 } 0297 if (accountConfig.hasKey(QStringLiteral("ssl_pop"))) { 0298 const int sslPop = accountConfig.readEntry(QStringLiteral("ssl_pop"), 0); 0299 switch (sslPop) { 0300 case 0: 0301 // Nothing 0302 break; 0303 case 1: 0304 settings.insert(QStringLiteral("UseSSL"), true); 0305 break; 0306 case 2: 0307 settings.insert(QStringLiteral("UseTLS"), true); 0308 break; 0309 default: 0310 qCDebug(SYLPHEEDPLUGIN_LOG) << " unknown ssl_pop value " << sslPop; 0311 break; 0312 } 0313 } 0314 if (accountConfig.hasKey(QStringLiteral("remove_mail"))) { 0315 const bool removeMail = (accountConfig.readEntry(QStringLiteral("remove_mail"), 1) == 1); 0316 settings.insert(QStringLiteral("LeaveOnServer"), removeMail); 0317 } 0318 0319 if (accountConfig.hasKey(QStringLiteral("message_leave_time"))) { 0320 settings.insert(QStringLiteral("LeaveOnServerDays"), accountConfig.readEntry(QStringLiteral("message_leave_time"))); 0321 } 0322 const QString user = accountConfig.readEntry(QStringLiteral("user_id")); 0323 settings.insert(QStringLiteral("Login"), user); 0324 0325 const QString password = accountConfig.readEntry(QStringLiteral("password")); 0326 settings.insert(QStringLiteral("Password"), password); 0327 0328 // use_apop_auth 0329 if (accountConfig.hasKey(QStringLiteral("use_apop_auth"))) { 0330 const bool useApop = (accountConfig.readEntry(QStringLiteral("use_apop_auth"), 1) == 1); 0331 if (useApop) { 0332 settings.insert(QStringLiteral("AuthenticationMethod"), MailTransport::Transport::EnumAuthenticationType::APOP); 0333 } 0334 } 0335 if (intervalCheckMail != -1) { 0336 settings.insert(QStringLiteral("IntervalCheckEnabled"), true); 0337 settings.insert(QStringLiteral("IntervalCheckInterval"), intervalCheckMail); 0338 } 0339 0340 const QString agentIdentifyName = LibImportWizard::AbstractBase::createResource(QStringLiteral("akonadi_pop3_resource"), name, settings); 0341 addCheckMailOnStartup(agentIdentifyName, checkMailOnStartup); 0342 const bool enableManualCheck = (accountConfig.readEntry(QStringLiteral("receive_at_get_all"), 0) == 1); 0343 addToManualCheck(agentIdentifyName, enableManualCheck); 0344 } 0345 0346 void SylpheedSettings::readImapAccount(const KConfigGroup &accountConfig, bool checkMailOnStartup, int intervalCheckMail) 0347 { 0348 QMap<QString, QVariant> settings; 0349 const QString host = accountConfig.readEntry("receive_server"); 0350 settings.insert(QStringLiteral("ImapServer"), host); 0351 0352 const QString name = accountConfig.readEntry(QStringLiteral("name")); 0353 const int sslimap = accountConfig.readEntry(QStringLiteral("ssl_imap"), 0); 0354 switch (sslimap) { 0355 case 0: 0356 // None 0357 settings.insert(QStringLiteral("Safety"), QStringLiteral("NONE")); 0358 break; 0359 case 1: 0360 // SSL 0361 settings.insert(QStringLiteral("Safety"), QStringLiteral("SSL")); 0362 break; 0363 case 2: 0364 // TLS 0365 settings.insert(QStringLiteral("Safety"), QStringLiteral("STARTTLS")); 0366 break; 0367 default: 0368 qCDebug(SYLPHEEDPLUGIN_LOG) << " sslimap unknown " << sslimap; 0369 break; 0370 } 0371 0372 int port = 0; 0373 if (SylpheedSettingsUtils::readConfig(QStringLiteral("imap_port"), accountConfig, port, true)) { 0374 settings.insert(QStringLiteral("ImapPort"), port); 0375 } 0376 0377 QString trashFolder; 0378 if (SylpheedSettingsUtils::readConfig(QStringLiteral("trash_folder"), accountConfig, trashFolder, false)) { 0379 settings.insert(QStringLiteral("TrashCollection"), MailCommon::Util::convertFolderPathToCollectionId(trashFolder)); 0380 } 0381 0382 const int auth = accountConfig.readEntry(QStringLiteral("imap_auth_method"), 0); 0383 switch (auth) { 0384 case 0: 0385 break; 0386 case 1: // Login 0387 settings.insert(QStringLiteral("Authentication"), MailTransport::Transport::EnumAuthenticationType::LOGIN); 0388 break; 0389 case 2: // Cram-md5 0390 settings.insert(QStringLiteral("Authentication"), MailTransport::Transport::EnumAuthenticationType::CRAM_MD5); 0391 break; 0392 case 4: // Plain 0393 settings.insert(QStringLiteral("Authentication"), MailTransport::Transport::EnumAuthenticationType::PLAIN); 0394 break; 0395 default: 0396 qCDebug(SYLPHEEDPLUGIN_LOG) << " imap auth unknown " << auth; 0397 break; 0398 } 0399 0400 if (intervalCheckMail != -1) { 0401 settings.insert(QStringLiteral("IntervalCheckEnabled"), true); 0402 settings.insert(QStringLiteral("IntervalCheckTime"), intervalCheckMail); 0403 } 0404 0405 const QString password = accountConfig.readEntry(QStringLiteral("password")); 0406 settings.insert(QStringLiteral("Password"), password); 0407 0408 const QString agentIdentifyName = LibImportWizard::AbstractBase::createResource(QStringLiteral("akonadi_imap_resource"), name, settings); 0409 addCheckMailOnStartup(agentIdentifyName, checkMailOnStartup); 0410 0411 const bool enableManualCheck = (accountConfig.readEntry(QStringLiteral("receive_at_get_all"), 0) == 1); 0412 addToManualCheck(agentIdentifyName, enableManualCheck); 0413 } 0414 0415 void SylpheedSettings::readAccount(const KConfigGroup &accountConfig, bool checkMailOnStartup, int intervalCheckMail) 0416 { 0417 if (accountConfig.hasKey(QStringLiteral("protocol"))) { 0418 const int protocol = accountConfig.readEntry(QStringLiteral("protocol"), 0); 0419 switch (protocol) { 0420 case 0: 0421 readPop3Account(accountConfig, checkMailOnStartup, intervalCheckMail); 0422 break; 0423 case 3: 0424 // imap 0425 readImapAccount(accountConfig, checkMailOnStartup, intervalCheckMail); 0426 break; 0427 case 4: 0428 qCDebug(SYLPHEEDPLUGIN_LOG) << " Add it when nntp resource will implemented"; 0429 // news 0430 break; 0431 case 5: 0432 // local 0433 break; 0434 default: 0435 qCDebug(SYLPHEEDPLUGIN_LOG) << " protocol not defined" << protocol; 0436 break; 0437 } 0438 } 0439 } 0440 0441 void SylpheedSettings::readIdentity(const KConfigGroup &accountConfig) 0442 { 0443 QString name = accountConfig.readEntry(QStringLiteral("name")); 0444 KIdentityManagementCore::Identity *identity = createIdentity(name); 0445 0446 identity->setFullName(name); 0447 identity->setIdentityName(name); 0448 const QString organization = accountConfig.readEntry(QStringLiteral("organization"), QString()); 0449 identity->setOrganization(organization); 0450 const QString email = accountConfig.readEntry(QStringLiteral("address")); 0451 identity->setPrimaryEmailAddress(email); 0452 0453 QString value; 0454 if (SylpheedSettingsUtils::readConfig(QStringLiteral("auto_bcc"), accountConfig, value, true)) { 0455 identity->setBcc(value); 0456 } 0457 if (SylpheedSettingsUtils::readConfig(QStringLiteral("auto_cc"), accountConfig, value, true)) { 0458 identity->setCc(value); 0459 } 0460 if (SylpheedSettingsUtils::readConfig(QStringLiteral("auto_replyto"), accountConfig, value, true)) { 0461 identity->setReplyToAddr(value); 0462 } 0463 0464 if (SylpheedSettingsUtils::readConfig(QStringLiteral("daft_folder"), accountConfig, value, false)) { 0465 identity->setDrafts(MailCommon::Util::convertFolderPathToCollectionStr(value)); 0466 } 0467 0468 if (SylpheedSettingsUtils::readConfig(QStringLiteral("sent_folder"), accountConfig, value, false)) { 0469 identity->setFcc(MailCommon::Util::convertFolderPathToCollectionStr(value)); 0470 } 0471 0472 const QString transportId = readTransport(accountConfig); 0473 if (!transportId.isEmpty()) { 0474 identity->setTransport(transportId); 0475 } 0476 readSignature(accountConfig, identity); 0477 storeIdentity(identity); 0478 } 0479 0480 QString SylpheedSettings::readTransport(const KConfigGroup &accountConfig) 0481 { 0482 const QString smtpserver = accountConfig.readEntry("smtp_server"); 0483 0484 if (!smtpserver.isEmpty()) { 0485 MailTransport::Transport *mt = createTransport(); 0486 mt->setIdentifier(QStringLiteral("SMTP")); 0487 mt->setName(smtpserver); 0488 mt->setHost(smtpserver); 0489 int port = 0; 0490 if (SylpheedSettingsUtils::readConfig(QStringLiteral("smtp_port"), accountConfig, port, true)) { 0491 mt->setPort(port); 0492 } 0493 const QString user = accountConfig.readEntry(QStringLiteral("smtp_user_id")); 0494 0495 if (!user.isEmpty()) { 0496 mt->setUserName(user); 0497 mt->setRequiresAuthentication(true); 0498 } 0499 const QString password = accountConfig.readEntry(QStringLiteral("smtp_password")); 0500 if (!password.isEmpty()) { 0501 mt->setStorePassword(true); 0502 mt->setPassword(password); 0503 } 0504 if (accountConfig.readEntry(QStringLiteral("use_smtp_auth"), 0) == 1) { 0505 const int authMethod = accountConfig.readEntry(QStringLiteral("smtp_auth_method"), 0); 0506 switch (authMethod) { 0507 case 0: // Automatic: 0508 mt->setAuthenticationType(MailTransport::Transport::EnumAuthenticationType::PLAIN); //???? 0509 break; 0510 case 1: // Login 0511 mt->setAuthenticationType(MailTransport::Transport::EnumAuthenticationType::LOGIN); 0512 break; 0513 case 2: // Cram-MD5 0514 mt->setAuthenticationType(MailTransport::Transport::EnumAuthenticationType::CRAM_MD5); 0515 break; 0516 case 8: // Plain 0517 mt->setAuthenticationType(MailTransport::Transport::EnumAuthenticationType::PLAIN); 0518 break; 0519 default: 0520 qCDebug(SYLPHEEDPLUGIN_LOG) << " smtp authentication unknown :" << authMethod; 0521 break; 0522 } 0523 } 0524 const int sslSmtp = accountConfig.readEntry(QStringLiteral("ssl_smtp"), 0); 0525 switch (sslSmtp) { 0526 case 0: 0527 mt->setEncryption(MailTransport::Transport::EnumEncryption::None); 0528 break; 0529 case 1: 0530 mt->setEncryption(MailTransport::Transport::EnumEncryption::SSL); 0531 break; 0532 case 2: 0533 mt->setEncryption(MailTransport::Transport::EnumEncryption::TLS); 0534 break; 0535 default: 0536 qCDebug(SYLPHEEDPLUGIN_LOG) << " smtp ssl config unknown :" << sslSmtp; 0537 break; 0538 } 0539 QString domainName; 0540 if (SylpheedSettingsUtils::readConfig(QStringLiteral("domain"), accountConfig, domainName, false)) { 0541 mt->setLocalHostname(domainName); 0542 } 0543 0544 storeTransport(mt, true); 0545 return QString::number(mt->id()); 0546 } 0547 return {}; 0548 }