File indexing completed on 2024-12-22 04:52:48
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 "clawsmailsettings.h" 0008 #include "importwizardutil.h" 0009 0010 #include <MailCommon/MailUtil> 0011 #include <MailTransport/TransportManager> 0012 0013 #include <KIdentityManagementCore/Identity> 0014 0015 #include "clawsmailplugin_debug.h" 0016 #include <KConfig> 0017 #include <KConfigGroup> 0018 #include <QFileInfo> 0019 0020 #include <QRegularExpression> 0021 0022 ClawsMailSettings::ClawsMailSettings() = default; 0023 0024 ClawsMailSettings::~ClawsMailSettings() = default; 0025 0026 void ClawsMailSettings::importSettings(const QString &filename, const QString &path) 0027 { 0028 bool checkMailOnStartup = true; 0029 int intervalCheckMail = -1; 0030 const QString clawsmailrc = path + QLatin1StringView("/clawsrc"); 0031 if (QFileInfo::exists(clawsmailrc)) { 0032 KConfig configCommon(clawsmailrc); 0033 if (configCommon.hasGroup(QLatin1StringView("Common"))) { 0034 KConfigGroup common = configCommon.group(QStringLiteral("Common")); 0035 checkMailOnStartup = (common.readEntry("check_on_startup", 1) == 1); 0036 if (common.readEntry(QStringLiteral("autochk_newmail"), 1) == 1) { 0037 intervalCheckMail = common.readEntry(QStringLiteral("autochk_interval"), -1); 0038 } 0039 readGlobalSettings(common); 0040 } 0041 } 0042 KConfig config(filename); 0043 const QStringList accountList = config.groupList().filter(QRegularExpression(QStringLiteral("Account: \\d+"))); 0044 const QStringList::const_iterator end(accountList.constEnd()); 0045 for (QStringList::const_iterator it = accountList.constBegin(); it != end; ++it) { 0046 KConfigGroup group = config.group(*it); 0047 readAccount(group, checkMailOnStartup, intervalCheckMail); 0048 readIdentity(group); 0049 } 0050 const QString customheaderrc = path + QLatin1StringView("/customheaderrc"); 0051 QFile customHeaderFile(customheaderrc); 0052 if (customHeaderFile.exists()) { 0053 if (!customHeaderFile.open(QIODevice::ReadOnly)) { 0054 qCDebug(CLAWSMAILPLUGIN_LOG) << " We can't open file" << customheaderrc; 0055 } else { 0056 readCustomHeader(&customHeaderFile); 0057 } 0058 } 0059 } 0060 0061 void ClawsMailSettings::readSettingsColor(const KConfigGroup &group) 0062 { 0063 const bool enableColor = group.readEntry("enable_color", false); 0064 if (enableColor) { 0065 const QString colorLevel1 = group.readEntry("quote_level1_color"); 0066 if (!colorLevel1.isEmpty()) { 0067 const QColor col = QColor(colorLevel1); 0068 if (col.isValid()) { 0069 addKmailConfig(QStringLiteral("Reader"), QStringLiteral("QuotedText1"), writeColor(col)); 0070 } 0071 //[Reader] QuotedText1 0072 } 0073 const QString colorLevel2 = group.readEntry("quote_level2_color"); 0074 if (!colorLevel2.isEmpty()) { 0075 const QColor col = QColor(colorLevel2); 0076 if (col.isValid()) { 0077 addKmailConfig(QStringLiteral("Reader"), QStringLiteral("QuotedText2"), writeColor(col)); 0078 } 0079 //[Reader] QuotedText2 0080 } 0081 const QString colorLevel3 = group.readEntry("quote_level3_color"); 0082 if (!colorLevel3.isEmpty()) { 0083 const QColor col = QColor(colorLevel3); 0084 if (col.isValid()) { 0085 addKmailConfig(QStringLiteral("Reader"), QStringLiteral("QuotedText3"), writeColor(col)); 0086 } 0087 //[Reader] QuotedText3 0088 } 0089 const QString misspellColor = group.readEntry(QStringLiteral("misspelled_color")); 0090 if (!misspellColor.isEmpty()) { 0091 const QColor col = QColor(misspellColor); 0092 if (col.isValid()) { 0093 addKmailConfig(QStringLiteral("Reader"), QStringLiteral("MisspelledColor"), writeColor(col)); 0094 } 0095 } 0096 const QString uriColor = group.readEntry(QStringLiteral("uri_color")); 0097 if (!uriColor.isEmpty()) { 0098 const QColor col(uriColor); 0099 if (col.isValid()) { 0100 addKmailConfig(QStringLiteral("Reader"), QStringLiteral("LinkColor"), writeColor(col)); 0101 } 0102 } 0103 const QString newColor = group.readEntry(QStringLiteral("color_new")); 0104 if (!newColor.isEmpty()) { 0105 const QColor col(newColor); 0106 if (col.isValid()) { 0107 addKmailConfig(QStringLiteral("MessageListView::Colors"), QStringLiteral("UnreadMessageColor"), writeColor(col)); 0108 } 0109 } 0110 } 0111 } 0112 0113 QString ClawsMailSettings::writeColor(const QColor &col) 0114 { 0115 QStringList list; 0116 list.insert(0, QString::number(col.red())); 0117 list.insert(1, QString::number(col.green())); 0118 list.insert(2, QString::number(col.blue())); 0119 if (col.alpha() != 255) { 0120 list.insert(3, QString::number(col.alpha())); 0121 } 0122 return list.join(QLatin1Char(',')); 0123 } 0124 0125 void ClawsMailSettings::readTemplateFormat(const KConfigGroup &group) 0126 { 0127 SylpheedSettings::readTemplateFormat(group); 0128 const QString composerNewMessage = group.readEntry(QStringLiteral("compose_body_format")); 0129 if (!composerNewMessage.isEmpty()) { 0130 addKmailConfig(QStringLiteral("TemplateParser"), QStringLiteral("TemplateNewMessage"), convertToKmailTemplate(composerNewMessage)); 0131 } 0132 } 0133 0134 void ClawsMailSettings::readGlobalSettings(const KConfigGroup &group) 0135 { 0136 SylpheedSettings::readGlobalSettings(group); 0137 if (group.readEntry(QStringLiteral("check_while_typing"), 0) == 1) { 0138 addKmailConfig(QStringLiteral("Spelling"), QStringLiteral("backgroundCheckerEnabled"), true); 0139 } 0140 const int markAsRead = group.readEntry(QStringLiteral("mark_as_read_delay"), -1); 0141 if (markAsRead != -1) { 0142 addKmailConfig(QStringLiteral("Behaviour"), QStringLiteral("DelayedMarkTime"), markAsRead); 0143 addKmailConfig(QStringLiteral("Behaviour"), QStringLiteral("DelayedMarkAsRead"), true); 0144 } 0145 0146 const int warnLargeFileInserting = group.readEntry(QStringLiteral("warn_large_insert"), 0); 0147 if (warnLargeFileInserting == 0) { 0148 addKmailConfig(QStringLiteral("Composer"), QStringLiteral("MaximumAttachmentSize"), -1); 0149 } else { 0150 const int warnLargeFileSize = group.readEntry(QStringLiteral("warn_large_insert_size"), -1); 0151 if (warnLargeFileSize > 0) { 0152 addKmailConfig(QStringLiteral("Composer"), QStringLiteral("MaximumAttachmentSize"), warnLargeFileSize * 1024); 0153 } 0154 } 0155 } 0156 0157 void ClawsMailSettings::readTagColor(const KConfigGroup &group) 0158 { 0159 const QString customColorPattern(QStringLiteral("custom_color%1")); 0160 const QString customColorLabelPattern(QStringLiteral("custom_colorlabel%1")); 0161 QList<tagStruct> listTag; 0162 for (int i = 1; i <= 15; ++i) { 0163 if (group.hasKey(customColorPattern.arg(i)) && group.hasKey(customColorLabelPattern.arg(i))) { 0164 tagStruct tag; 0165 const QString colorStr = group.readEntry(customColorPattern.arg(i)); 0166 const QString labelStr = group.readEntry(customColorLabelPattern.arg(i)); 0167 if (!colorStr.isEmpty() && !labelStr.isEmpty()) { 0168 tag.color = QColor(colorStr).name(); 0169 tag.name = labelStr; 0170 listTag << tag; 0171 } 0172 } 0173 } 0174 if (!listTag.isEmpty()) { 0175 ImportWizardUtil::addAkonadiTag(listTag); 0176 } 0177 }