File indexing completed on 2024-12-22 04:45:42
0001 /* 0002 SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #include "emailsettingswidget.h" 0007 #include <KLocalizedString> 0008 #include <KPasswordLineEdit> 0009 #include <QCheckBox> 0010 #include <QComboBox> 0011 #include <QFormLayout> 0012 #include <QLabel> 0013 #include <QLineEdit> 0014 #include <QPlainTextEdit> 0015 #include <QSpinBox> 0016 0017 EmailSettingsWidget::EmailSettingsWidget(RocketChatAccount *account, QWidget *parent) 0018 : SettingsWidgetBase(account, parent) 0019 , mSmtpProtocol(new QComboBox(this)) 0020 , mSmtpHost(new QLineEdit(this)) 0021 , mSmtpPort(new QSpinBox(this)) 0022 , mSmtpIgnoreTls(new QCheckBox(i18n("IgnoreTLS"), this)) 0023 , mSmtpUserName(new QLineEdit(this)) 0024 , mSmtpFromEmail(new QLineEdit(this)) 0025 , mSmtpPassword(new KPasswordLineEdit(this)) 0026 , mShowMessageEmailNotification(new QCheckBox(i18n("Show Message in Email Notification"), this)) 0027 , mAddSenderReplyTo(new QCheckBox(i18n("Add Sender to Reply-To"), this)) 0028 , mEnableDirectReply(new QCheckBox(i18n("Enable Direct Reply"), this)) 0029 , mDebugDirectReply(new QCheckBox(i18n("Debug Direct Reply"), this)) 0030 , mDirectMessageEmailSubject(new QPlainTextEdit(this)) 0031 , mMentionEmailSubject(new QPlainTextEdit(this)) 0032 , mMentionAllEmailSubject(new QPlainTextEdit(this)) 0033 , mVerificationSubject(new QLineEdit(this)) 0034 , mVerificationBody(new QPlainTextEdit(this)) 0035 , mForgotPasswordSubject(new QLineEdit(this)) 0036 , mForgotPasswordBody(new QPlainTextEdit(this)) 0037 , mEmailAddressChangedSubject(new QLineEdit(this)) 0038 , mEmailAddressChangedBody(new QPlainTextEdit(this)) 0039 , mInvitationSubject(new QLineEdit(this)) 0040 , mInvitationBody(new QPlainTextEdit(this)) 0041 , mPasswordChangedSubject(new QLineEdit(this)) 0042 , mPasswordChangedBody(new QPlainTextEdit(this)) 0043 { 0044 auto smtpLabel = createBoldLabel(i18n("SMTP")); 0045 smtpLabel->setObjectName(QStringLiteral("smtpLabel")); 0046 mMainLayout->addWidget(smtpLabel); 0047 0048 mSmtpProtocol->setObjectName(QStringLiteral("mSmtpProtocol")); 0049 const QMap<QString, QString> maps = { 0050 {QStringLiteral("smtp"), i18n("smtp")}, 0051 {QStringLiteral("smtps"), i18n("smtps")}, 0052 }; 0053 addComboBox(i18n("Protocol"), maps, mSmtpProtocol, QStringLiteral("SMTP_Protocol")); 0054 0055 mSmtpHost->setObjectName(QStringLiteral("mSmtpHost")); 0056 addLineEdit(i18n("Host"), mSmtpHost, QStringLiteral("SMTP_Host")); 0057 0058 mSmtpPort->setObjectName(QStringLiteral("mSmtpPort")); 0059 mSmtpPort->setMaximum(99999); 0060 addSpinbox(i18n("Port"), mSmtpPort, QStringLiteral("SMTP_Port")); 0061 0062 mSmtpIgnoreTls->setObjectName(QStringLiteral("mIgnoreTls")); 0063 mMainLayout->addWidget(mSmtpIgnoreTls); 0064 connectCheckBox(mSmtpIgnoreTls, QStringLiteral("SMTP_IgnoreTLS")); 0065 0066 mSmtpUserName->setObjectName(QStringLiteral("mUserName")); 0067 addLineEdit(i18n("Username"), mSmtpUserName, QStringLiteral("SMTP_Username")); 0068 0069 mSmtpPassword->setObjectName(QStringLiteral("mSmtpPassword")); 0070 addPasswordEdit(i18n("Password"), mSmtpPassword, QStringLiteral("SMTP_Password")); 0071 0072 mSmtpFromEmail->setObjectName(QStringLiteral("mFromEmail")); 0073 addLineEdit(i18n("From Email"), mSmtpFromEmail, QStringLiteral("From_Email")); 0074 0075 auto privacyLabel = createBoldLabel(i18n("Privacy")); 0076 privacyLabel->setObjectName(QStringLiteral("privacyLabel")); 0077 mMainLayout->addWidget(privacyLabel); 0078 0079 mShowMessageEmailNotification->setObjectName(QStringLiteral("mShowMessageEmailNotification")); 0080 mMainLayout->addWidget(mShowMessageEmailNotification); 0081 connectCheckBox(mShowMessageEmailNotification, QStringLiteral("Email_notification_show_message")); 0082 0083 mAddSenderReplyTo->setObjectName(QStringLiteral("mAddSenderReplyTo")); 0084 mMainLayout->addWidget(mAddSenderReplyTo); 0085 connectCheckBox(mAddSenderReplyTo, QStringLiteral("Add_Sender_To_ReplyTo")); 0086 0087 auto directReplyLabel = createBoldLabel(i18n("Direct Reply")); 0088 directReplyLabel->setObjectName(QStringLiteral("directReplyLabel")); 0089 mMainLayout->addWidget(directReplyLabel); 0090 0091 mEnableDirectReply->setObjectName(QStringLiteral("mEnableDirectReply")); 0092 mMainLayout->addWidget(mEnableDirectReply); 0093 mEnableDirectReply->setToolTip( 0094 i18n("[Attention!] If \"Direct Reply\" is enabled, Rocket.Chat will control the configured email mailbox.\n" 0095 "All unread e-mails are retrieved, marked as read and processed.\n" 0096 "\"Direct Reply\" should only be activated if the mailbox used is intended exclusively for access by Rocket.Chat\n" 0097 "and is not read/processed \"in parallel\" by humans.")); 0098 connectCheckBox(mEnableDirectReply, QStringLiteral("Direct_Reply_Enable")); 0099 0100 mDebugDirectReply->setObjectName(QStringLiteral("mDebugDirectReply")); 0101 mMainLayout->addWidget(mDebugDirectReply); 0102 mDebugDirectReply->setToolTip(i18n("[Beware] Enabling Debug mode would display your 'Plain Text Password' in Admin console.")); 0103 connectCheckBox(mDebugDirectReply, QStringLiteral("Direct_Reply_Debug")); 0104 0105 auto forgotPasswordLabel = createBoldLabel(i18n("Forgot password")); 0106 forgotPasswordLabel->setObjectName(QStringLiteral("forgotPasswordLabel")); 0107 mMainLayout->addWidget(forgotPasswordLabel); 0108 0109 mForgotPasswordSubject->setObjectName(QStringLiteral("mForgotPasswordSubject")); 0110 addLineEdit(i18n("Subject"), mForgotPasswordSubject, QStringLiteral("Forgot_Password_Email_Subject")); 0111 0112 mForgotPasswordBody->setObjectName(QStringLiteral("mForgotPasswordBody")); 0113 addPlainTextEdit(i18n("Body"), mForgotPasswordBody, QStringLiteral("Forgot_Password_Email")); 0114 0115 auto subjectLabel = createBoldLabel(i18n("Subject")); 0116 subjectLabel->setObjectName(QStringLiteral("subjectLabel")); 0117 mMainLayout->addWidget(subjectLabel); 0118 0119 mDirectMessageEmailSubject->setObjectName(QStringLiteral("mDirectMessageEmailSubject")); 0120 addPlainTextEdit(i18n("Direct Message Email Subject"), mDirectMessageEmailSubject, QStringLiteral("Offline_DM_Email")); 0121 0122 mMentionEmailSubject->setObjectName(QStringLiteral("mMentionEmailSubject")); 0123 addPlainTextEdit(i18n("Mention Email Subject"), mMentionEmailSubject, QStringLiteral("Offline_Mention_Email")); 0124 0125 mMentionAllEmailSubject->setObjectName(QStringLiteral("mMentionAllEmailSubject")); 0126 addPlainTextEdit(i18n("Mention All Email Subject"), mMentionAllEmailSubject, QStringLiteral("Offline_Mention_All_Email")); 0127 0128 auto verificationLabel = createBoldLabel(i18n("Verification")); 0129 verificationLabel->setObjectName(QStringLiteral("verificationLabel")); 0130 mMainLayout->addWidget(verificationLabel); 0131 0132 mVerificationSubject->setObjectName(QStringLiteral("mVerificationSubject")); 0133 addLineEdit(i18n("Subject"), mVerificationSubject, QStringLiteral("Verification_Email_Subject")); 0134 0135 mVerificationBody->setObjectName(QStringLiteral("mVerificationBody")); 0136 addPlainTextEdit(i18n("Body"), mVerificationBody, QStringLiteral("Verification_Email")); 0137 0138 auto emailAddressChangedLabel = createBoldLabel(i18n("Email Address Changed")); 0139 emailAddressChangedLabel->setObjectName(QStringLiteral("emailAddressChangedLabel")); 0140 mMainLayout->addWidget(emailAddressChangedLabel); 0141 0142 mEmailAddressChangedSubject->setObjectName(QStringLiteral("mEmailAddressChangedSubject")); 0143 addLineEdit(i18n("Subject"), mEmailAddressChangedSubject, QStringLiteral("Email_Changed_Email_Subject")); 0144 0145 mEmailAddressChangedBody->setObjectName(QStringLiteral("mEmailAddressChangedBody")); 0146 addPlainTextEdit(i18n("Body"), mEmailAddressChangedBody, QStringLiteral("Email_Changed_Email")); 0147 0148 auto invitationLabel = createBoldLabel(i18n("Invitation")); 0149 invitationLabel->setObjectName(QStringLiteral("invitationLabel")); 0150 mMainLayout->addWidget(invitationLabel); 0151 0152 mInvitationSubject->setObjectName(QStringLiteral("mInvitationSubject")); 0153 addLineEdit(i18n("Subject"), mInvitationSubject, QStringLiteral("Invitation_Subject")); 0154 0155 mInvitationBody->setObjectName(QStringLiteral("mInvitationBody")); 0156 addPlainTextEdit(i18n("Body"), mInvitationBody, QStringLiteral("Invitation_Email")); 0157 0158 auto passwordChangedLabel = createBoldLabel(i18n("Password Changed")); 0159 passwordChangedLabel->setObjectName(QStringLiteral("passwordChangedLabel")); 0160 mMainLayout->addWidget(passwordChangedLabel); 0161 0162 mPasswordChangedSubject->setObjectName(QStringLiteral("mPasswordChangedSubject")); 0163 addLineEdit(i18n("Subject"), mPasswordChangedSubject, QStringLiteral("Password_Changed_Email_Subject")); 0164 0165 mPasswordChangedBody->setObjectName(QStringLiteral("mPasswordChangedBody")); 0166 addPlainTextEdit(i18n("Body"), mPasswordChangedBody, QStringLiteral("Password_Changed_Email")); 0167 } 0168 0169 EmailSettingsWidget::~EmailSettingsWidget() = default; 0170 0171 void EmailSettingsWidget::initialize(const QMap<QString, QVariant> &mapSettings) 0172 { 0173 initializeWidget(mSmtpProtocol, mapSettings, QStringLiteral("smtp")); 0174 initializeWidget(mSmtpHost, mapSettings, QString()); 0175 initializeWidget(mSmtpPort, mapSettings, 0); 0176 initializeWidget(mSmtpIgnoreTls, mapSettings, true); 0177 initializeWidget(mSmtpUserName, mapSettings, QString()); 0178 initializeWidget(mSmtpFromEmail, mapSettings, QString()); 0179 initializeWidget(mSmtpPassword, mapSettings); 0180 initializeWidget(mShowMessageEmailNotification, mapSettings, true); 0181 initializeWidget(mAddSenderReplyTo, mapSettings, false); 0182 initializeWidget(mEnableDirectReply, mapSettings, false); 0183 initializeWidget(mDirectMessageEmailSubject, mapSettings, QStringLiteral("[[Site_Name]] You have been direct messaged by [User]")); 0184 initializeWidget(mMentionEmailSubject, mapSettings, QStringLiteral("[[Site_Name]] You have been mentioned by [User] in #[Room]")); 0185 initializeWidget(mMentionAllEmailSubject, mapSettings, QStringLiteral("[User] has posted a message in #[Room]")); 0186 initializeWidget(mVerificationSubject, mapSettings, QStringLiteral("[Site_Name] - Email address verification")); 0187 initializeWidget(mVerificationBody, mapSettings, QStringLiteral("Click <a href=\"[Verification_Url]\">here</a> to verify your email address.")); 0188 initializeWidget(mForgotPasswordSubject, mapSettings, QStringLiteral("[Site_Name] - Password Recovery")); 0189 initializeWidget(mForgotPasswordBody, mapSettings, QStringLiteral("Click <a href=\"[Forgot_Password_Url]\">here</a> to reset your password.")); 0190 0191 initializeWidget(mEmailAddressChangedSubject, mapSettings, QStringLiteral("[Site_Name] - Email address has been changed")); 0192 initializeWidget(mEmailAddressChangedBody, mapSettings, QStringLiteral("Click <a href=\"[Forgot_Password_Url]\">here</a> to reset your password.")); 0193 0194 initializeWidget(mInvitationSubject, mapSettings, QStringLiteral("You have been invited to [Site_Name]")); 0195 initializeWidget(mInvitationBody, 0196 mapSettings, 0197 QStringLiteral("<h2>{Welcome_to Site_Name}</h2><p>{Visit_Site_Url_and_try_the_best_open_source_chat_solution_available_today}</p><a " 0198 "class=\"btn\" href=\"[Site_URL]\">{Join_Chat}</a>")); 0199 0200 initializeWidget(mPasswordChangedSubject, mapSettings, QStringLiteral("{Password_Changed_Email_Subject}")); 0201 initializeWidget(mPasswordChangedBody, 0202 mapSettings, 0203 QStringLiteral("<h2>{Hi},</h2><p>{Your_password_was_changed_by_an_admin}</p><p>{Your_temporary_password_is_password}</p><a class=\"btn\" " 0204 "target=\"_blank\" href=\"[Site_URL]\">{Login}</a>")); 0205 } 0206 0207 #include "moc_emailsettingswidget.cpp"