File indexing completed on 2024-12-22 04:52:51
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 "thunderbirdsettings.h" 0008 #include <MailCommon/MailUtil> 0009 #include <MailTransport/TransportManager> 0010 0011 #include <KIdentityManagementCore/Identity> 0012 #include <KIdentityManagementCore/Signature> 0013 0014 #include "thunderbirdplugin_debug.h" 0015 #include <KContacts/VCardConverter> 0016 #include <QDir> 0017 #include <QFile> 0018 #include <QFileInfo> 0019 #include <QStandardPaths> 0020 #include <QTextStream> 0021 #include <QUrl> 0022 0023 ThunderbirdSettings::ThunderbirdSettings(const QString &filename) 0024 : mFileName(filename) 0025 { 0026 } 0027 0028 ThunderbirdSettings::~ThunderbirdSettings() = default; 0029 0030 void ThunderbirdSettings::importSettings() 0031 { 0032 QFile file(mFileName); 0033 if (!file.open(QIODevice::ReadOnly)) { 0034 qCDebug(THUNDERBIRDPLUGIN_LOG) << " We can't open file" << mFileName; 0035 return; 0036 } 0037 QTextStream stream(&file); 0038 while (!stream.atEnd()) { 0039 const QString line = stream.readLine(); 0040 if (line.startsWith(QLatin1StringView("user_pref"))) { 0041 if (line.contains(QLatin1StringView("mail.smtpserver")) || line.contains(QLatin1StringView("mail.server.")) 0042 || line.contains(QLatin1StringView("mail.identity.")) || line.contains(QLatin1StringView("mail.account.")) 0043 || line.contains(QLatin1StringView("mail.accountmanager.")) || line.contains(QLatin1StringView("mailnews.")) 0044 || line.contains(QLatin1StringView("mail.compose.")) || line.contains(QLatin1StringView("mail.spellcheck")) 0045 || line.contains(QLatin1StringView("mail.SpellCheckBeforeSend")) || line.contains(QLatin1StringView("spellchecker.dictionary")) 0046 || line.contains(QLatin1StringView("ldap_")) || line.contains(QLatin1StringView("mail.biff.")) 0047 || line.contains(QLatin1StringView("mailnews.tags.")) || line.contains(QLatin1StringView("extensions.AutoResizeImage.")) 0048 || line.contains(QLatin1StringView("mail.phishing.")) || line.contains(QLatin1StringView("mail.display_glyph")) 0049 || line.contains(QLatin1StringView("extensions.sieve.account."))) { 0050 insertIntoMap(line); 0051 } 0052 } else { 0053 if (!line.startsWith(QLatin1Char('#')) || line.isEmpty() || line.startsWith(QLatin1StringView("/*")) || line.startsWith(QLatin1StringView(" */")) 0054 || line.startsWith(QLatin1StringView(" *"))) { 0055 qCDebug(THUNDERBIRDPLUGIN_LOG) << " unstored line :" << line; 0056 } 0057 } 0058 } 0059 const QString mailAccountPreference = mHashConfig.value(QStringLiteral("mail.accountmanager.accounts")).toString(); 0060 if (mailAccountPreference.isEmpty()) { 0061 return; 0062 } 0063 mAccountList = mailAccountPreference.split(QLatin1Char(',')); 0064 readTransport(); 0065 readAccount(); 0066 readGlobalSettings(); 0067 readLdapSettings(); 0068 readTagSettings(); 0069 readExtensionsSettings(); 0070 } 0071 0072 void ThunderbirdSettings::readExtensionsSettings() 0073 { 0074 // AutoResizeImage 0075 const QString filterPatternEnabledStr = QStringLiteral("extensions.AutoResizeImage.filterPatterns"); 0076 if (mHashConfig.contains(filterPatternEnabledStr)) { 0077 const int filterPatternType = mHashConfig.value(filterPatternEnabledStr).toInt(); 0078 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("filter-source-type"), filterPatternType); 0079 } 0080 const QString filterPatternListStr = QStringLiteral("extensions.AutoResizeImage.filteringPatternsList"); 0081 if (mHashConfig.contains(filterPatternListStr)) { 0082 const QString filterPatternList = mHashConfig.value(filterPatternListStr).toString(); 0083 // TODO decode it. 0084 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("filter-source-pattern"), filterPatternList); 0085 } 0086 0087 const QString enlargeImagesStr = QStringLiteral("extensions.AutoResizeImage.enlargeImages"); 0088 if (mHashConfig.contains(enlargeImagesStr)) { 0089 const bool enlargeImages = mHashConfig.value(enlargeImagesStr).toBool(); 0090 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("enlarge-image-to-minimum"), enlargeImages); 0091 } 0092 0093 const QString maxResolutionXStr = QStringLiteral("extensions.AutoResizeImage.maxResolutionX"); 0094 if (mHashConfig.contains(maxResolutionXStr)) { 0095 const int val = mHashConfig.value(maxResolutionXStr).toInt(); 0096 int adaptedValue = adaptAutoResizeResolution(val, QStringLiteral("extensions.AutoResizeImage.maxResolutionXList")); 0097 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("maximum-width"), adaptedValue); 0098 } 0099 const QString maxResolutionYStr = QStringLiteral("extensions.AutoResizeImage.maxResolutionY"); 0100 if (mHashConfig.contains(maxResolutionYStr)) { 0101 const int val = mHashConfig.value(maxResolutionYStr).toInt(); 0102 int adaptedValue = adaptAutoResizeResolution(val, QStringLiteral("extensions.AutoResizeImage.maxResolutionYList")); 0103 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("maximum-height"), adaptedValue); 0104 } 0105 const QString minResolutionXStr = QStringLiteral("extensions.AutoResizeImage.minResolutionX"); 0106 if (mHashConfig.contains(minResolutionXStr)) { 0107 const int val = mHashConfig.value(minResolutionXStr).toInt(); 0108 int adaptedValue = adaptAutoResizeResolution(val, QStringLiteral("extensions.AutoResizeImage.minResolutionXList")); 0109 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("minimum-width"), adaptedValue); 0110 } 0111 const QString minResolutionYStr = QStringLiteral("extensions.AutoResizeImage.minResolutionY"); 0112 if (mHashConfig.contains(minResolutionYStr)) { 0113 const int val = mHashConfig.value(minResolutionYStr).toInt(); 0114 int adaptedValue = adaptAutoResizeResolution(val, QStringLiteral("extensions.AutoResizeImage.minResolutionYList")); 0115 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("minimum-height"), adaptedValue); 0116 } 0117 0118 // Default is true. 0119 const QString reduceImageStr(QStringLiteral("extensions.AutoResizeImage.reduceImages")); 0120 if (mHashConfig.contains(reduceImageStr)) { 0121 const bool reduce = mHashConfig.value(reduceImageStr).toBool(); 0122 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("reduce-image-to-maximum"), reduce); 0123 } else { 0124 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("reduce-image-to-maximum"), false); 0125 } 0126 0127 const QString filterMinimumStr(QStringLiteral("extensions.AutoResizeImage.filterMinimumSize")); 0128 if (mHashConfig.contains(filterMinimumStr)) { 0129 const bool filterMinimum = mHashConfig.value(filterMinimumStr).toBool(); 0130 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("skip-image-lower-size-enabled"), filterMinimum); 0131 } 0132 const QString skipMinimumSizeStr(QStringLiteral("extensions.AutoResizeImage.minimumSize")); 0133 if (mHashConfig.contains(skipMinimumSizeStr)) { 0134 const int skipMinimumSize = mHashConfig.value(skipMinimumSizeStr).toInt(); 0135 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("skip-image-lower-size"), skipMinimumSize); 0136 } 0137 const QString confirmBeforeResizingStr(QStringLiteral("extensions.AutoResizeImage.confirmResizing")); 0138 if (mHashConfig.contains(confirmBeforeResizingStr)) { 0139 const bool confirmBeforeResizing = mHashConfig.value(confirmBeforeResizingStr).toBool(); 0140 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("ask-before-resizing"), confirmBeforeResizing); 0141 } 0142 // extensions.AutoResizeImage.convertImages : not implemented in kmail 0143 0144 const QString conversionFormatStr(QStringLiteral("extensions.AutoResizeImage.conversionFormat")); 0145 if (mHashConfig.contains(conversionFormatStr)) { 0146 QString conversionFormat = mHashConfig.value(conversionFormatStr).toString(); 0147 if (conversionFormat == QLatin1StringView("png")) { 0148 conversionFormat = QStringLiteral("PNG"); 0149 } else { 0150 conversionFormat = QStringLiteral("JPG"); 0151 } 0152 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("write-format"), conversionFormat); 0153 } 0154 0155 const QString filterRecipientsStr(QStringLiteral("extensions.AutoResizeImage.filterRecipients")); 0156 if (mHashConfig.contains(filterRecipientsStr)) { 0157 const int filterRecipients = mHashConfig.value(filterRecipientsStr).toInt(); 0158 switch (filterRecipients) { 0159 case 0: 0160 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("FilterRecipientType"), QStringLiteral("NoFilter")); 0161 break; 0162 case 1: 0163 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("FilterRecipientType"), QStringLiteral("ResizeEachEmailsContainsPattern")); 0164 break; 0165 case 2: 0166 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("FilterRecipientType"), QStringLiteral("ResizeOneEmailContainsPattern")); 0167 break; 0168 case 3: 0169 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("FilterRecipientType"), QStringLiteral("DontResizeEachEmailsContainsPattern")); 0170 break; 0171 case 4: 0172 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("FilterRecipientType"), QStringLiteral("DontResizeOneEmailContainsPattern")); 0173 break; 0174 default: 0175 qCDebug(THUNDERBIRDPLUGIN_LOG) << " unknown FilterRecipientType: " << filterRecipients; 0176 break; 0177 } 0178 } 0179 0180 const QString filteringRecipientsPatternsWhiteListStr(QStringLiteral("extensions.AutoResizeImage.filteringRecipientsPatternsWhiteList")); 0181 if (mHashConfig.contains(filteringRecipientsPatternsWhiteListStr)) { 0182 const QString filteringRecipientsPatternsWhiteList = mHashConfig.value(filteringRecipientsPatternsWhiteListStr).toString(); 0183 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("resize-emails-pattern"), filteringRecipientsPatternsWhiteList); 0184 } 0185 0186 const QString filteringRecipientsPatternsBlackListStr(QStringLiteral("extensions.AutoResizeImage.filteringRecipientsPatternsBlackList")); 0187 if (mHashConfig.contains(filteringRecipientsPatternsBlackListStr)) { 0188 const QString filteringRecipientsPatternsBlackList = mHashConfig.value(filteringRecipientsPatternsBlackListStr).toString(); 0189 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("do-not-resize-emails-pattern"), filteringRecipientsPatternsBlackList); 0190 } 0191 0192 const QString filteringRenamingPatternStr(QStringLiteral("extensions.AutoResizeImage.renamingPattern")); 0193 if (mHashConfig.contains(filteringRenamingPatternStr)) { 0194 QString filteringRenamingPattern = mHashConfig.value(filteringRenamingPatternStr).toString(); 0195 filteringRenamingPattern.replace(QLatin1StringView("%3Fn"), QLatin1StringView("%n")); 0196 filteringRenamingPattern.replace(QLatin1StringView("%3Ft"), QLatin1StringView("%t")); 0197 filteringRenamingPattern.replace(QLatin1StringView("%3Fd"), QLatin1StringView("%d")); 0198 filteringRenamingPattern.replace(QLatin1StringView("%3Fe"), QLatin1StringView("%e")); 0199 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("rename-resized-images-pattern"), filteringRenamingPattern); 0200 } 0201 0202 const QString filteringRenamingImageStr(QStringLiteral("extensions.AutoResizeImage.renameResizedImages")); 0203 if (mHashConfig.contains(filteringRenamingImageStr)) { 0204 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("rename-resized-images"), true); 0205 } 0206 0207 const QString filteringImageFormatsStr(QStringLiteral("extensions.AutoResizeImage.imageFormats")); 0208 if (mHashConfig.contains(filteringImageFormatsStr)) { 0209 const QString filteringImageFormats = mHashConfig.value(filteringImageFormatsStr).toString(); 0210 // convert it. 0211 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("resize-image-with-formats-type"), filteringImageFormats); 0212 } 0213 0214 const QString filteringImageFormatsEnabledStr(QStringLiteral("extensions.AutoResizeImage.filterFormats")); 0215 if (mHashConfig.contains(filteringImageFormatsEnabledStr)) { 0216 const bool filteringImageFormatsEnabled = mHashConfig.value(filteringImageFormatsEnabledStr).toBool(); 0217 addKmailConfig(QStringLiteral("AutoResizeImage"), QStringLiteral("resize-image-with-formats"), filteringImageFormatsEnabled); 0218 } 0219 } 0220 0221 int ThunderbirdSettings::adaptAutoResizeResolution(int index, const QString &configStrList) 0222 { 0223 switch (index) { 0224 case 0: 0225 return 240; 0226 case 1: 0227 return 320; 0228 case 2: 0229 return 512; 0230 case 3: 0231 return 640; 0232 case 4: 0233 return 800; 0234 case 5: 0235 return 1024; 0236 case 6: 0237 return 1280; 0238 case 7: 0239 return 2048; 0240 case 8: 0241 return 1024; 0242 case 9: { // custom case 0243 if (mHashConfig.contains(configStrList)) { 0244 const QString res = mHashConfig.value(configStrList).toString(); 0245 const QStringList lst = res.split(QLatin1Char(';')); 0246 int val = lst.last().toInt(); 0247 return val; 0248 } 0249 [[fallthrough]]; 0250 } 0251 default: 0252 return -1; 0253 } 0254 } 0255 0256 void ThunderbirdSettings::readTagSettings() 0257 { 0258 QList<tagStruct> v; 0259 v.reserve(mHashTag.size()); 0260 for (const tagStruct &tag : std::as_const(mHashTag)) { 0261 v.push_back(tag); 0262 } 0263 0264 ImportWizardUtil::addAkonadiTag(v); 0265 } 0266 0267 void ThunderbirdSettings::readLdapSettings() 0268 { 0269 // qCDebug(THUNDERBIRDPLUGIN_LOG)<<" mLdapAccountList:"<<mLdapAccountList; 0270 for (const QString &ldapAccountName : std::as_const(mLdapAccountList)) { 0271 ldapStruct ldap; 0272 const QString ldapDescription = QStringLiteral("%1.description").arg(ldapAccountName); 0273 if (mHashConfig.contains(ldapDescription)) { 0274 ldap.description = mHashConfig.value(ldapDescription).toString(); 0275 } 0276 const QString ldapAuthDn = QStringLiteral("%1.auth.dn").arg(ldapAccountName); 0277 if (mHashConfig.contains(ldapAuthDn)) { 0278 ldap.dn = mHashConfig.value(ldapAuthDn).toString(); 0279 } 0280 const QString ldapAuthSaslMech = QStringLiteral("%1.auth.saslmech").arg(ldapAccountName); 0281 if (mHashConfig.contains(ldapAuthSaslMech)) { 0282 ldap.saslMech = mHashConfig.value(ldapAuthSaslMech).toString(); 0283 } 0284 const QString ldapFilename = QStringLiteral("%1.filename").arg(ldapAccountName); 0285 if (mHashConfig.contains(ldapFilename)) { 0286 ldap.fileName = mHashConfig.value(ldapFilename).toString(); 0287 } 0288 const QString ldapMaxHits = QStringLiteral("%1.maxHits").arg(ldapAccountName); 0289 if (mHashConfig.contains(ldapMaxHits)) { 0290 ldap.maxHint = mHashConfig.value(ldapMaxHits).toInt(); 0291 } 0292 const QString ldapUri = QStringLiteral("%1.uri").arg(ldapAccountName); 0293 if (mHashConfig.contains(ldapUri)) { 0294 ldap.ldapUrl = QUrl(mHashConfig.value(ldapUri).toString()); 0295 ldap.port = ldap.ldapUrl.port(); 0296 0297 if (ldap.ldapUrl.scheme() == QLatin1StringView("ldaps")) { 0298 ldap.useSSL = true; 0299 } else if (ldap.ldapUrl.scheme() == QLatin1StringView("ldap")) { 0300 ldap.useSSL = false; 0301 } else { 0302 qCDebug(THUNDERBIRDPLUGIN_LOG) << " Security not implemented :" << ldap.ldapUrl.scheme(); 0303 } 0304 } 0305 ImportWizardUtil::mergeLdap(ldap); 0306 } 0307 } 0308 0309 void ThunderbirdSettings::readGlobalSettings() 0310 { 0311 const QString markMessageReadStr = QStringLiteral("mailnews.mark_message_read.delay"); 0312 if (mHashConfig.contains(markMessageReadStr)) { 0313 const bool markMessageRead = mHashConfig.value(markMessageReadStr).toBool(); 0314 addKmailConfig(QStringLiteral("Behaviour"), QStringLiteral("DelayedMarkAsRead"), markMessageRead); 0315 } else { 0316 // Default value 0317 addKmailConfig(QStringLiteral("Behaviour"), QStringLiteral("DelayedMarkAsRead"), true); 0318 } 0319 const QString markMessageReadIntervalStr = QStringLiteral("mailnews.mark_message_read.delay.interval"); 0320 if (mHashConfig.contains(markMessageReadIntervalStr)) { 0321 bool found = false; 0322 const int markMessageReadInterval = mHashConfig.value(markMessageReadIntervalStr).toInt(&found); 0323 if (found) { 0324 addKmailConfig(QStringLiteral("Behaviour"), QStringLiteral("DelayedMarkTime"), markMessageReadInterval); 0325 } 0326 } else { 0327 // Default 5 seconds 0328 addKmailConfig(QStringLiteral("Behaviour"), QStringLiteral("DelayedMarkTime"), 5); 0329 } 0330 0331 const QString mailComposeAttachmentReminderStr = QStringLiteral("mail.compose.attachment_reminder"); 0332 if (mHashConfig.contains(mailComposeAttachmentReminderStr)) { 0333 const bool mailComposeAttachmentReminder = mHashConfig.value(mailComposeAttachmentReminderStr).toBool(); 0334 addKmailConfig(QStringLiteral("Composer"), QStringLiteral("showForgottenAttachmentWarning"), mailComposeAttachmentReminder); 0335 } else { 0336 addKmailConfig(QStringLiteral("Composer"), QStringLiteral("showForgottenAttachmentWarning"), true); 0337 } 0338 0339 const QString mailComposeAttachmentReminderKeywordsStr = QStringLiteral("mail.compose.attachment_reminder_keywords"); 0340 if (mHashConfig.contains(mailComposeAttachmentReminderKeywordsStr)) { 0341 const QString mailComposeAttachmentReminderKeywords = mHashConfig.value(mailComposeAttachmentReminderKeywordsStr).toString(); 0342 addKmailConfig(QStringLiteral("Composer"), QStringLiteral("attachment-keywords"), mailComposeAttachmentReminderKeywords); 0343 } // not default value keep kmail use one default value 0344 0345 const QString mailComposeAutosaveStr = QStringLiteral("mail.compose.autosave"); 0346 if (mHashConfig.contains(mailComposeAutosaveStr)) { 0347 const bool mailComposeAutosave = mHashConfig.value(mailComposeAutosaveStr).toBool(); 0348 if (mailComposeAutosave) { 0349 const QString mailComposeAutosaveintervalStr = QStringLiteral("mail.compose.autosaveinterval"); 0350 if (mHashConfig.contains(mailComposeAutosaveintervalStr)) { 0351 bool found = false; 0352 const int mailComposeAutosaveinterval = mHashConfig.value(mailComposeAutosaveintervalStr).toInt(&found); 0353 if (found) { 0354 addKmailConfig(QStringLiteral("Composer"), QStringLiteral("autosave"), mailComposeAutosaveinterval); 0355 } else { 0356 addKmailConfig(QStringLiteral("Composer"), QStringLiteral("autosave"), 5); 0357 } 0358 } else { 0359 // Default value 0360 addKmailConfig(QStringLiteral("Composer"), QStringLiteral("autosave"), 5); 0361 } 0362 } else { 0363 // Don't autosave 0364 addKmailConfig(QStringLiteral("Composer"), QStringLiteral("autosave"), 0); 0365 } 0366 } 0367 0368 const QString mailSpellCheckInlineStr = QStringLiteral("mail.spellcheck.inline"); 0369 if (mHashConfig.contains(mailSpellCheckInlineStr)) { 0370 const bool mailSpellCheckInline = mHashConfig.value(mailSpellCheckInlineStr).toBool(); 0371 addKmailConfig(QStringLiteral("Spelling"), QStringLiteral("backgroundCheckerEnabled"), mailSpellCheckInline); 0372 } else { 0373 addKmailConfig(QStringLiteral("Spelling"), QStringLiteral("backgroundCheckerEnabled"), false); 0374 } 0375 0376 const QString mailAlertShowSubjectStr = QStringLiteral("mail.biff.alert.show_subject"); 0377 if (mHashConfig.contains(mailAlertShowSubjectStr)) { 0378 const bool mailAlertShowSubject = mHashConfig.value(mailAlertShowSubjectStr).toBool(); 0379 addNewMailNotifier(QStringLiteral("General"), QStringLiteral("showSubject"), mailAlertShowSubject); 0380 } else { 0381 // Default value in thunderbird 0382 addNewMailNotifier(QStringLiteral("General"), QStringLiteral("showSubject"), true); 0383 } 0384 0385 const QString mailAlertShowPreviewStr = QStringLiteral("mail.biff.alert.show_preview"); 0386 // TODO add show preview 0387 if (mHashConfig.contains(mailAlertShowPreviewStr)) { 0388 const bool mailAlertShowPreview = mHashConfig.value(mailAlertShowPreviewStr).toBool(); 0389 // addNewMailNotifier(QStringLiteral("General"),QStringLiteral("showSubject"), mailAlertShowPreview); 0390 } else { 0391 // Default value in thunderbird 0392 // addNewMailNotifier(QStringLiteral("General"),QStringLiteral("showSubject"), true); 0393 } 0394 0395 const QString mailAlertShowSenderStr = QStringLiteral("mail.biff.alert.show_sender"); 0396 if (mHashConfig.contains(mailAlertShowSenderStr)) { 0397 const bool mailAlertShowSender = mHashConfig.value(mailAlertShowSenderStr).toBool(); 0398 addNewMailNotifier(QStringLiteral("General"), QStringLiteral("showFrom"), mailAlertShowSender); 0399 } else { 0400 // Default value in thunderbird 0401 addNewMailNotifier(QStringLiteral("General"), QStringLiteral("showFrom"), true); 0402 } 0403 0404 const QString mailSpellCheckBeforeSendStr = QStringLiteral("mail.SpellCheckBeforeSend"); 0405 if (mHashConfig.contains(mailSpellCheckBeforeSendStr)) { 0406 const bool mailSpellCheckBeforeSend = mHashConfig.value(mailSpellCheckBeforeSendStr).toBool(); 0407 addKmailConfig(QStringLiteral("Composer"), QStringLiteral("check-spelling-before-send"), mailSpellCheckBeforeSend); 0408 } else { 0409 addKmailConfig(QStringLiteral("Composer"), QStringLiteral("check-spelling-before-send"), false); 0410 } 0411 0412 const QString mailSpellCheckLanguageStr = QStringLiteral("spellchecker.dictionary"); 0413 if (mHashConfig.contains(mailSpellCheckLanguageStr)) { 0414 const QString mailSpellCheckLanguage = mHashConfig.value(mailSpellCheckLanguageStr).toString(); 0415 addKmailConfig(QStringLiteral("Spelling"), QStringLiteral("defaultLanguage"), mailSpellCheckLanguage); 0416 // TODO create map to convert thunderbird name to aspell name 0417 } 0418 0419 const QString mailPhishingDetectionStr = QStringLiteral("mail.phishing.detection.enabled"); 0420 if (mHashConfig.contains(mailPhishingDetectionStr)) { 0421 const bool mailPhishingDetectionEnabled = mHashConfig.value(mailPhishingDetectionStr).toBool(); 0422 addKmailConfig(QStringLiteral("Reader"), QStringLiteral("ScamDetectionEnabled"), mailPhishingDetectionEnabled); 0423 } else { // Default 0424 addKmailConfig(QStringLiteral("Reader"), QStringLiteral("ScamDetectionEnabled"), true); 0425 } 0426 0427 const QString mailDisplayGlyphStr = QStringLiteral("mail.display_glyph"); 0428 if (mHashConfig.contains(mailDisplayGlyphStr)) { 0429 const bool mailDisplayGlyphEnabled = mHashConfig.value(mailDisplayGlyphStr).toBool(); 0430 addKmailConfig(QStringLiteral("Reader"), QStringLiteral("ShowEmoticons"), mailDisplayGlyphEnabled); 0431 } else { // Default 0432 addKmailConfig(QStringLiteral("Reader"), QStringLiteral("ShowEmoticons"), true); 0433 } 0434 } 0435 0436 void ThunderbirdSettings::importSieveSettings(QMap<QString, QVariant> &settings, const QString &userName, const QString &imapServerName) 0437 { 0438 QString userNameSieveConverted = userName; 0439 userNameSieveConverted.replace(QLatin1Char('@'), QStringLiteral("%40")); 0440 0441 const QString sieveKeyServerUserName = QStringLiteral("extensions.sieve.account.") + userNameSieveConverted + QLatin1Char('@') + imapServerName; 0442 // user_pref("extensions.sieve.account.<username>@<server>.enabled", true); 0443 if (mHashConfig.value(sieveKeyServerUserName + QStringLiteral(".enabled"), false).toBool()) { 0444 settings.insert(QStringLiteral("SieveSupport"), true); 0445 settings.insert(QStringLiteral("SievePort"), mHashConfig.value(sieveKeyServerUserName + QStringLiteral(".port"), 4190).toInt()); 0446 // TODO add more 0447 } 0448 #if 0 0449 <group name="siever"> 0450 <entry name="SieveSupport" type="Bool"> 0451 <label>Define if server supports sieve</label> 0452 <default>false</default> 0453 </entry> 0454 <entry name="SieveReuseConfig" type="Bool"> 0455 <label>Define if we reuse host and login configuration</label> 0456 <default>true</default> 0457 </entry> 0458 <entry name="SievePort" type="Int"> 0459 <label>Define sieve port</label> 0460 <default>4190</default> 0461 </entry> 0462 <entry name="SieveAlternateUrl" type="String"> 0463 <label>Define alternate URL</label> 0464 </entry> 0465 <entry name="AlternateAuthentication" type="Int"> 0466 <label>Defines the authentication type to use for alternate server</label> 0467 <default>1</default> 0468 </entry> 0469 <entry name="SieveVacationFilename" type="String"> 0470 <label>Define default sieve vacation filename</label> 0471 <default>kmail-vacation.siv</default> 0472 </entry> 0473 <entry name="SieveCustomUsername" type="String"> 0474 <label>Define username used from custom server sieve url</label> 0475 <default></default> 0476 </entry> 0477 <entry name="SieveCustomAuthentification" type="String"> 0478 <label>Defines the type of identification used by custom sieve server</label> 0479 <default>ImapUserPassword</default> 0480 </entry> 0481 </group> 0482 0483 #endif 0484 #if 0 0485 if (mHashConfig.value(sieveKeyServerUserName + QStringLiteral(".enabled"), false).toBool()) { 0486 //TODO 0487 //user_pref("extensions.sieve.account.<username>@<server>.TLS", true); 0488 //user_pref("extensions.sieve.account.<username>@<server>.TLS.forced", true); 0489 //user_pref("extensions.sieve.account.<username>@<server>.activeAuthorization", 1); 0490 //user_pref("extensions.sieve.account.<username>@<server>.activeHost", 1); 0491 //user_pref("extensions.sieve.account.<username>@<server>.activeLogin", 1); 0492 SieveEditorUtil::SieveServerConfig config; 0493 //0 4190 0494 //1 2000 0495 //2 custom 0496 //Default == 4190 0497 //user_pref("extensions.sieve.account.<username>@<server>.port", 1255); 0498 config.sieveSettings.port = mHashConfig.value(sieveKeyServerUserName + QStringLiteral(".port"), 4190).toInt(); 0499 //not necessary to import this one : user_pref("extensions.sieve.account.<username>@<server>.port.type", 1); 0500 0501 //user_pref("extensions.sieve.account.<username>@<server>.hostname", "sdfsfsqsdf"); 0502 const QString sieveHostName = mHashConfig.value(sieveKeyServerUserName + QStringLiteral(".hostname")).toString(); 0503 if (sieveHostName.isEmpty()) { 0504 config.sieveSettings.serverName = imapServerName; 0505 } else { 0506 config.sieveSettings.serverName = sieveHostName; 0507 } 0508 0509 const QString sieveUserName = mHashConfig.value(sieveKeyServerUserName + QStringLiteral(".login.username")).toString(); 0510 //user_pref("extensions.sieve.account.<username>@<server>.login.username", "newuser"); 0511 if (sieveUserName.isEmpty()) { 0512 config.sieveSettings.userName = userName; 0513 } else { 0514 config.sieveSettings.userName = sieveUserName; 0515 } 0516 0517 //not necessary to import this one : user_pref("extensions.sieve.account.<username>@<server>.proxy.type", 1); 0518 0519 0520 ////FIXME qCDebug(SIEVEEDITOR_LOG) << "imap account " << accountName; 0521 const QString name = mHashConfig.value(accountName + QStringLiteral(".name")).toString(); 0522 bool found; 0523 const int sievePort = mHashConfig.value(accountName + QStringLiteral(".port")).toInt(&found); 0524 if (found) { 0525 config.sieveImapAccountSettings.setPort(sievePort); 0526 } 0527 encryption(config, accountName); 0528 addAuth(config, accountName); 0529 config.sieveImapAccountSettings.setUserName(userName); 0530 config.sieveImapAccountSettings.setServerName(imapServerName); 0531 0532 if (config.isValid()) { 0533 atLeastAnAccountFound = true; 0534 Q_EMIT importSetting(name, config); 0535 } 0536 } 0537 0538 #endif 0539 } 0540 0541 void ThunderbirdSettings::addAuth(QMap<QString, QVariant> &settings, const QString &argument, const QString &accountName) 0542 { 0543 bool found = false; 0544 if (mHashConfig.contains(accountName + QStringLiteral(".authMethod"))) { 0545 const int authMethod = mHashConfig.value(accountName + QStringLiteral(".authMethod")).toInt(&found); 0546 if (found) { 0547 switch (authMethod) { 0548 case 0: 0549 settings.insert(argument, MailTransport::Transport::EnumAuthenticationType::PLAIN); //???? 0550 break; 0551 case 4: // Encrypted password ??? 0552 settings.insert(argument, MailTransport::Transport::EnumAuthenticationType::LOGIN); //???? 0553 qCDebug(THUNDERBIRDPLUGIN_LOG) << " authmethod == encrypt password"; 0554 break; 0555 case 5: // GSSAPI 0556 settings.insert(argument, MailTransport::Transport::EnumAuthenticationType::GSSAPI); 0557 break; 0558 case 6: // NTLM 0559 settings.insert(argument, MailTransport::Transport::EnumAuthenticationType::NTLM); 0560 break; 0561 case 7: // TLS 0562 qCDebug(THUNDERBIRDPLUGIN_LOG) << " authmethod method == TLS"; //???? 0563 break; 0564 case 10: // OAuth2 verify it. 0565 settings.insert(argument, MailTransport::Transport::EnumAuthenticationType::XOAUTH2); 0566 qCDebug(THUNDERBIRDPLUGIN_LOG) << " authmethod method == OAuth2"; //???? 0567 break; 0568 default: 0569 qCDebug(THUNDERBIRDPLUGIN_LOG) << " ThunderbirdSettings::addAuth unknown :" << authMethod; 0570 break; 0571 } 0572 } 0573 } 0574 } 0575 0576 void ThunderbirdSettings::readAccount() 0577 { 0578 for (const QString &account : std::as_const(mAccountList)) { 0579 const QString serverName = mHashConfig.value(QStringLiteral("mail.account.%1").arg(account) + QStringLiteral(".server")).toString(); 0580 const QString accountName = QStringLiteral("mail.server.%1").arg(serverName); 0581 const QString host = mHashConfig.value(accountName + QStringLiteral(".hostname")).toString(); 0582 const QString userName = mHashConfig.value(accountName + QStringLiteral(".userName")).toString(); 0583 const QString name = mHashConfig.value(accountName + QStringLiteral(".name")).toString(); 0584 0585 const QString type = mHashConfig.value(accountName + QStringLiteral(".type")).toString(); 0586 // TODO use it ? 0587 // const QString directory = mHashConfig.value(accountName + QStringLiteral(".directory")).toString(); 0588 0589 const QString loginAtStartupStr = accountName + QStringLiteral(".login_at_startup"); 0590 bool loginAtStartup = true; // Default for thunderbird; 0591 if (mHashConfig.contains(loginAtStartupStr)) { 0592 loginAtStartup = mHashConfig.value(loginAtStartupStr).toBool(); 0593 } 0594 bool found = false; 0595 if (type == QLatin1StringView("imap")) { 0596 QMap<QString, QVariant> settings; 0597 settings.insert(QStringLiteral("ImapServer"), host); 0598 settings.insert(QStringLiteral("UserName"), userName); 0599 const int port = mHashConfig.value(accountName + QStringLiteral(".port")).toInt(&found); 0600 if (found) { 0601 settings.insert(QStringLiteral("ImapPort"), port); 0602 } 0603 addAuth(settings, QStringLiteral("Authentication"), accountName); 0604 const QString offline = accountName + QStringLiteral(".offline_download"); 0605 if (mHashConfig.contains(offline)) { 0606 const bool offlineStatus = mHashConfig.value(offline).toBool(); 0607 if (offlineStatus) { 0608 settings.insert(QStringLiteral("DisconnectedModeEnabled"), offlineStatus); 0609 } 0610 } else { 0611 // default value == true 0612 settings.insert(QStringLiteral("DisconnectedModeEnabled"), true); 0613 } 0614 0615 found = false; 0616 const int socketType = mHashConfig.value(accountName + QStringLiteral(".socketType")).toInt(&found); 0617 if (found) { 0618 switch (socketType) { 0619 case 0: 0620 // None 0621 settings.insert(QStringLiteral("Safety"), QStringLiteral("None")); 0622 break; 0623 case 2: 0624 // STARTTLS 0625 settings.insert(QStringLiteral("Safety"), QStringLiteral("STARTTLS")); 0626 break; 0627 case 3: 0628 // SSL/TLS 0629 settings.insert(QStringLiteral("Safety"), QStringLiteral("SSL")); 0630 break; 0631 default: 0632 qCDebug(THUNDERBIRDPLUGIN_LOG) << " socketType " << socketType; 0633 break; 0634 } 0635 } 0636 const QString checkNewMailStr = accountName + QStringLiteral(".check_new_mail"); 0637 if (mHashConfig.contains(checkNewMailStr)) { 0638 const bool checkNewMail = mHashConfig.value(checkNewMailStr).toBool(); 0639 settings.insert(QStringLiteral("IntervalCheckEnabled"), checkNewMail); 0640 } 0641 0642 const QString checkTimeStr = accountName + QStringLiteral(".check_time"); 0643 if (mHashConfig.contains(checkTimeStr)) { 0644 found = false; 0645 const int checkTime = mHashConfig.value(checkTimeStr).toInt(&found); 0646 if (found) { 0647 settings.insert(QStringLiteral("IntervalCheckTime"), checkTime); 0648 } 0649 } else { 0650 // Default value from thunderbird 0651 settings.insert(QStringLiteral("IntervalCheckTime"), 10); 0652 } 0653 const QString trashFolderStr = accountName + QStringLiteral(".trash_folder_name"); 0654 if (mHashConfig.contains(trashFolderStr)) { 0655 settings.insert(QStringLiteral("TrashCollection"), 0656 MailCommon::Util::convertFolderPathToCollectionId(mHashConfig.value(trashFolderStr).toString())); 0657 } 0658 importSieveSettings(settings, userName, serverName); 0659 0660 const QString agentIdentifyName = LibImportWizard::AbstractBase::createResource(QStringLiteral("akonadi_imap_resource"), name, settings); 0661 addCheckMailOnStartup(agentIdentifyName, loginAtStartup); 0662 // Not find a method to disable it in thunderbird 0663 addToManualCheck(agentIdentifyName, true); 0664 } else if (type == QLatin1StringView("pop3")) { 0665 QMap<QString, QVariant> settings; 0666 settings.insert(QStringLiteral("Host"), host); 0667 settings.insert(QStringLiteral("Login"), userName); 0668 0669 const bool leaveOnServer = mHashConfig.value(accountName + QStringLiteral(".leave_on_server")).toBool(); 0670 if (leaveOnServer) { 0671 settings.insert(QStringLiteral("LeaveOnServer"), leaveOnServer); 0672 } 0673 0674 found = false; 0675 const int numberDayToLeave = mHashConfig.value(accountName + QStringLiteral(".num_days_to_leave_on_server")).toInt(&found); 0676 if (found) { 0677 settings.insert(QStringLiteral("LeaveOnServerDays"), numberDayToLeave); 0678 } 0679 0680 found = false; 0681 const int port = mHashConfig.value(accountName + QStringLiteral(".port")).toInt(&found); 0682 if (found) { 0683 settings.insert(QStringLiteral("Port"), port); 0684 } 0685 0686 found = false; 0687 const int socketType = mHashConfig.value(accountName + QStringLiteral(".socketType")).toInt(&found); 0688 if (found) { 0689 switch (socketType) { 0690 case 0: 0691 // None 0692 // nothing 0693 break; 0694 case 2: 0695 // STARTTLS 0696 settings.insert(QStringLiteral("UseTLS"), true); 0697 break; 0698 case 3: 0699 // SSL/TLS 0700 settings.insert(QStringLiteral("UseSSL"), true); 0701 break; 0702 default: 0703 qCDebug(THUNDERBIRDPLUGIN_LOG) << " socketType " << socketType; 0704 break; 0705 } 0706 } 0707 addAuth(settings, QStringLiteral("AuthenticationMethod"), accountName); 0708 const QString checkNewMailStr = accountName + QStringLiteral(".check_new_mail"); 0709 if (mHashConfig.contains(checkNewMailStr)) { 0710 const bool checkNewMail = mHashConfig.value(checkNewMailStr).toBool(); 0711 settings.insert(QStringLiteral("IntervalCheckEnabled"), checkNewMail); 0712 } 0713 const QString checkTimeStr = accountName + QStringLiteral(".check_time"); 0714 if (mHashConfig.contains(checkTimeStr)) { 0715 found = false; 0716 const int checkTime = mHashConfig.value(checkTimeStr).toInt(&found); 0717 if (found) { 0718 settings.insert(QStringLiteral("IntervalCheckInterval"), checkTime); 0719 } 0720 } else { 0721 // Default value from thunderbird 0722 settings.insert(QStringLiteral("IntervalCheckInterval"), 10); 0723 } 0724 0725 const QString agentIdentifyName = LibImportWizard::AbstractBase::createResource(QStringLiteral("akonadi_pop3_resource"), name, settings); 0726 addCheckMailOnStartup(agentIdentifyName, loginAtStartup); 0727 // Not find a method to disable it in thunderbird 0728 addToManualCheck(agentIdentifyName, true); 0729 } else if (type == QLatin1StringView("none")) { 0730 // FIXME look at if we can implement it 0731 qCDebug(THUNDERBIRDPLUGIN_LOG) << " account type none!"; 0732 } else if (type == QLatin1StringView("rss") || type == QLatin1StringView("nntp") || type == QLatin1StringView("movemail")) { 0733 qCDebug(THUNDERBIRDPLUGIN_LOG) << QStringLiteral("%1 rss resource needs to be implemented").arg(type); 0734 continue; 0735 } else { 0736 qCDebug(THUNDERBIRDPLUGIN_LOG) << " type unknown : " << type; 0737 continue; 0738 } 0739 0740 const QString identityConfig = QStringLiteral("mail.account.%1").arg(account) + QStringLiteral(".identities"); 0741 if (mHashConfig.contains(identityConfig)) { 0742 const QStringList idList = mHashConfig.value(identityConfig).toString().split(QLatin1Char(',')); 0743 for (const QString &id : idList) { 0744 readIdentity(id); 0745 } 0746 } 0747 } 0748 } 0749 0750 void ThunderbirdSettings::readTransport() 0751 { 0752 const QString mailSmtpServer = mHashConfig.value(QStringLiteral("mail.smtpservers")).toString(); 0753 if (mailSmtpServer.isEmpty()) { 0754 return; 0755 } 0756 const QStringList smtpList = mailSmtpServer.split(QLatin1Char(',')); 0757 QString defaultSmtp = mHashConfig.value(QStringLiteral("mail.smtp.defaultserver")).toString(); 0758 if (smtpList.count() == 1 && defaultSmtp.isEmpty()) { 0759 // Be sure to define default smtp 0760 defaultSmtp = smtpList.at(0); 0761 } 0762 0763 for (const QString &smtp : smtpList) { 0764 const QString smtpName = QStringLiteral("mail.smtpserver.%1").arg(smtp); 0765 MailTransport::Transport *mt = createTransport(); 0766 mt->setIdentifier(QStringLiteral("SMTP")); 0767 const QString name = mHashConfig.value(smtpName + QStringLiteral(".description")).toString(); 0768 mt->setName(name); 0769 const QString hostName = mHashConfig.value(smtpName + QStringLiteral(".hostname")).toString(); 0770 mt->setHost(hostName); 0771 0772 const int port = mHashConfig.value(smtpName + QStringLiteral(".port")).toInt(); 0773 if (port > 0) { 0774 mt->setPort(port); 0775 } 0776 0777 const int authMethod = mHashConfig.value(smtpName + QStringLiteral(".authMethod")).toInt(); 0778 switch (authMethod) { 0779 case 0: 0780 break; 0781 case 1: // No authentication 0782 mt->setAuthenticationType(MailTransport::Transport::EnumAuthenticationType::PLAIN); //???? 0783 break; 0784 case 3: // Unencrypted password 0785 mt->setAuthenticationType(MailTransport::Transport::EnumAuthenticationType::CLEAR); //??? 0786 break; 0787 case 4: // crypted password 0788 mt->setAuthenticationType(MailTransport::Transport::EnumAuthenticationType::LOGIN); //??? 0789 break; 0790 case 5: // GSSAPI 0791 mt->setAuthenticationType(MailTransport::Transport::EnumAuthenticationType::GSSAPI); 0792 break; 0793 case 6: // NTLM 0794 mt->setAuthenticationType(MailTransport::Transport::EnumAuthenticationType::NTLM); 0795 break; 0796 default: 0797 qCDebug(THUNDERBIRDPLUGIN_LOG) << " authMethod unknown :" << authMethod; 0798 break; 0799 } 0800 0801 const int trySsl = mHashConfig.value(smtpName + QStringLiteral(".try_ssl")).toInt(); 0802 switch (trySsl) { 0803 case 0: 0804 mt->setEncryption(MailTransport::Transport::EnumEncryption::None); 0805 break; 0806 case 2: 0807 mt->setEncryption(MailTransport::Transport::EnumEncryption::TLS); 0808 break; 0809 case 3: 0810 mt->setEncryption(MailTransport::Transport::EnumEncryption::SSL); 0811 break; 0812 default: 0813 qCDebug(THUNDERBIRDPLUGIN_LOG) << " trySsl unknown :" << trySsl; 0814 break; 0815 } 0816 0817 const QString userName = mHashConfig.value(smtpName + QStringLiteral(".username")).toString(); 0818 if (!userName.isEmpty()) { 0819 mt->setUserName(userName); 0820 if (authMethod > 1) { 0821 mt->setRequiresAuthentication(true); 0822 } 0823 } 0824 0825 storeTransport(mt, (smtp == defaultSmtp)); 0826 mHashSmtp.insert(smtp, QString::number(mt->id())); 0827 } 0828 } 0829 0830 QString convertThunderbirdPath(const QString &path) 0831 { 0832 QString newPath; 0833 QUrl url(path); 0834 newPath = url.path(); 0835 newPath.remove(0, 1); 0836 return MailCommon::Util::convertFolderPathToCollectionStr(newPath); 0837 } 0838 0839 void ThunderbirdSettings::readIdentity(const QString &account) 0840 { 0841 const QString identity = QStringLiteral("mail.identity.%1").arg(account); 0842 QString fullName = mHashConfig.value(identity + QStringLiteral(".fullName")).toString(); 0843 KIdentityManagementCore::Identity *newIdentity = createIdentity(fullName); 0844 0845 const QString smtpServer = mHashConfig.value(identity + QStringLiteral(".smtpServer")).toString(); 0846 if (!smtpServer.isEmpty() && mHashSmtp.contains(smtpServer)) { 0847 newIdentity->setTransport(mHashSmtp.value(smtpServer)); 0848 } 0849 0850 const QString userEmail = mHashConfig.value(identity + QStringLiteral(".useremail")).toString(); 0851 newIdentity->setPrimaryEmailAddress(userEmail); 0852 0853 newIdentity->setFullName(fullName); 0854 newIdentity->setIdentityName(fullName); 0855 0856 const QString organization = mHashConfig.value(identity + QStringLiteral(".organization")).toString(); 0857 newIdentity->setOrganization(organization); 0858 0859 bool doBcc = mHashConfig.value(identity + QStringLiteral(".doBcc")).toBool(); 0860 if (doBcc) { 0861 const QString bcc = mHashConfig.value(identity + QStringLiteral(".doBccList")).toString(); 0862 newIdentity->setBcc(bcc); 0863 } 0864 0865 bool doCc = mHashConfig.value(identity + QStringLiteral(".doCc")).toBool(); 0866 if (doCc) { 0867 const QString cc = mHashConfig.value(identity + QStringLiteral(".doCcList")).toString(); 0868 newIdentity->setCc(cc); 0869 } 0870 0871 const QString replyTo = mHashConfig.value(identity + QStringLiteral(".reply_to")).toString(); 0872 newIdentity->setReplyToAddr(replyTo); 0873 0874 KIdentityManagementCore::Signature signature; 0875 const bool signatureHtml = mHashConfig.value(identity + QStringLiteral(".htmlSigFormat")).toBool(); 0876 if (signatureHtml) { 0877 signature.setInlinedHtml(true); 0878 } 0879 0880 const bool attachSignature = mHashConfig.value(identity + QStringLiteral(".attach_signature")).toBool(); 0881 if (attachSignature) { 0882 const QString fileSignature = mHashConfig.value(identity + QStringLiteral(".sig_file")).toString(); 0883 signature.setType(KIdentityManagementCore::Signature::FromFile); 0884 signature.setPath(fileSignature, false); 0885 } else { 0886 const QString textSignature = mHashConfig.value(identity + QStringLiteral(".htmlSigText")).toString(); 0887 signature.setType(KIdentityManagementCore::Signature::Inlined); 0888 signature.setText(textSignature); 0889 } 0890 0891 if (mHashConfig.contains(identity + QStringLiteral(".drafts_folder_picker_mode"))) { 0892 const int useSpecificDraftFolder = mHashConfig.value(identity + QStringLiteral(".drafts_folder_picker_mode")).toInt(); 0893 if (useSpecificDraftFolder == 1) { 0894 const QString draftFolder = convertThunderbirdPath(mHashConfig.value(identity + QStringLiteral(".draft_folder")).toString()); 0895 newIdentity->setDrafts(draftFolder); 0896 } 0897 } 0898 0899 if (mHashConfig.contains(identity + QStringLiteral(".fcc"))) { 0900 const bool fccEnabled = mHashConfig.value(identity + QStringLiteral(".fcc")).toBool(); 0901 newIdentity->setDisabledFcc(!fccEnabled); 0902 } 0903 0904 // fcc_reply_follows_parent not implemented in kmail 0905 // fcc_folder_picker_mode is just a flag for thunderbird. Not necessary during import. 0906 // if ( mHashConfig.contains( identity + QStringLiteral( ".fcc_folder_picker_mode" ) ) ) 0907 { 0908 if (mHashConfig.contains(identity + QStringLiteral(".fcc_folder"))) { 0909 const QString fccFolder = convertThunderbirdPath(mHashConfig.value(identity + QStringLiteral(".fcc_folder")).toString()); 0910 newIdentity->setFcc(fccFolder); 0911 } 0912 } 0913 0914 // if ( mHashConfig.contains( identity + QStringLiteral( ".tmpl_folder_picker_mode" ) ) ) 0915 { 0916 if (mHashConfig.contains(identity + QStringLiteral(".stationery_folder"))) { 0917 const QString templateFolder = convertThunderbirdPath(mHashConfig.value(identity + QStringLiteral(".stationery_folder")).toString()); 0918 newIdentity->setTemplates(templateFolder); 0919 } 0920 } 0921 0922 const QString attachVcardStr(identity + QStringLiteral(".attach_vcard")); 0923 if (mHashConfig.contains(attachVcardStr)) { 0924 const bool attachVcard = mHashConfig.value(attachVcardStr).toBool(); 0925 newIdentity->setAttachVcard(attachVcard); 0926 } 0927 const QString attachVcardContentStr(identity + QStringLiteral(".escapedVCard")); 0928 if (mHashConfig.contains(attachVcardContentStr)) { 0929 const QString str = mHashConfig.value(attachVcardContentStr).toString(); 0930 QByteArray vcard = QByteArray::fromPercentEncoding(str.toLocal8Bit()); 0931 KContacts::VCardConverter converter; 0932 KContacts::Addressee addr = converter.parseVCard(vcard); 0933 0934 const QString filename = 0935 QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + QLatin1Char('/') + newIdentity->identityName() + QStringLiteral(".vcf"); 0936 QFileInfo fileInfo(filename); 0937 QDir().mkpath(fileInfo.absolutePath()); 0938 QFile file(filename); 0939 if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { 0940 const QByteArray data = converter.exportVCard(addr, KContacts::VCardConverter::v3_0); 0941 file.write(data); 0942 file.flush(); 0943 file.close(); 0944 newIdentity->setVCardFile(filename); 0945 } 0946 } 0947 const QString signMailStr(identity + QStringLiteral(".sign_mail")); 0948 if (mHashConfig.contains(signMailStr)) { 0949 const bool signMail = mHashConfig.value(signMailStr).toBool(); 0950 newIdentity->setPgpAutoSign(signMail); 0951 } 0952 0953 // const QString composeHtmlStr(identity + QStringLiteral(".compose_html")); 0954 // TODO: implement it in kmail 0955 0956 newIdentity->setSignature(signature); 0957 0958 storeIdentity(newIdentity); 0959 } 0960 0961 void ThunderbirdSettings::insertIntoMap(const QString &line) 0962 { 0963 QString newLine = line; 0964 newLine.remove(QStringLiteral("user_pref(\"")); 0965 newLine.remove(QStringLiteral(");")); 0966 const int pos = newLine.indexOf(QLatin1Char(',')); 0967 QString key = newLine.left(pos); 0968 key.remove(key.length() - 1, 1); 0969 QString valueStr = newLine.right(newLine.length() - pos - 2); 0970 if (valueStr.at(0) == QLatin1Char('"')) { 0971 valueStr.remove(0, 1); 0972 const int pos(valueStr.length() - 1); 0973 if (valueStr.at(pos) == QLatin1Char('"')) { 0974 valueStr.remove(pos, 1); 0975 } 0976 // Store as String 0977 mHashConfig.insert(key, valueStr); 0978 } else { 0979 if (valueStr == QLatin1StringView("true")) { 0980 mHashConfig.insert(key, true); 0981 } else if (valueStr == QLatin1StringView("false")) { 0982 mHashConfig.insert(key, false); 0983 } else { 0984 // Store as integer 0985 const int value = valueStr.toInt(); 0986 mHashConfig.insert(key, value); 0987 } 0988 } 0989 if (key.contains(QLatin1StringView("ldap_")) && key.endsWith(QLatin1StringView(".description"))) { 0990 QString ldapAccountName = key; 0991 mLdapAccountList.append(ldapAccountName.remove(QStringLiteral(".description"))); 0992 } 0993 if (key.contains(QLatin1StringView("mailnews.tags.")) && (key.endsWith(QLatin1StringView(".color")) || key.endsWith(QLatin1StringView(".tag")))) { 0994 QString name = key; 0995 name.remove(QStringLiteral("mailnews.tags.")); 0996 name.remove(QStringLiteral(".color")); 0997 name.remove(QStringLiteral(".tag")); 0998 tagStruct tag; 0999 if (mHashTag.contains(name)) { 1000 tag = mHashTag.value(name); 1001 mHashTag.remove(name); 1002 } 1003 if (key.endsWith(QLatin1StringView(".color"))) { 1004 tag.color = QColor(mHashConfig.value(key).toString()); 1005 } else { 1006 tag.name = mHashConfig.value(key).toString(); 1007 } 1008 mHashTag.insert(name, tag); 1009 qCDebug(THUNDERBIRDPLUGIN_LOG) << " tag :" << name << " tag.name" << tag.name << " color :" << tag.color; 1010 } 1011 } 1012 1013 void ThunderbirdSettings::addNewMailNotifier(const QString &group, const QString &key, bool value) 1014 { 1015 KConfig config(QStringLiteral("akonadi_newmailnotifier_agentrc")); 1016 KConfigGroup grp = config.group(group); 1017 grp.writeEntry(key, value); 1018 }