Debian Codegraph @

Dekko/backend/accounts/AccountConfiguration.h

raw symbols SCIP
1 /* Copyright (C) 2016 - 2017 Dan Chapman <[email protected]>
2
3 This file is part of Dekko email client for Ubuntu devices
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef ACCOUNTCONFIGURATION_H
19 #define ACCOUNTCONFIGURATION_H
20
21 #include <QLoggingCategory>
22 #include <QObject>
23 #include <qmailaccountconfiguration.h>
24 #include <qmailserviceconfiguration.h>
25 #include <qmailtransport.h>
26 #include <qmailnamespace.h>
27
28 Q_DECLARE_LOGGING_CATEGORY(D_ACCOUNT_CONF)
29 /** @ingroup group_accounts */
30 struct AccountKeys {
31 // Base properties
32 static const QString name, email, password, server, port, encryption, acceptUntrustedCert;
33 //IMAP/POP3 properties
34 static const QString canDeleteMail, downloadAttachments, autoDownload, maxMailSize;
35 static const QString prefferedSubType, canIDLE, idleEnabled, baseFolder, pushFolders, checkInterval;
36 static const QString checkWhenRoaming, capabilities, timeTillLogout, searchLimit;
37 //SMTP
38 static const QString saslMechanism, username, authFromCaps, smtppassword, signature;
39 };
40
41 /** @ingroup group_accounts */
42 class AccountConfiguration : public QObject
43 {
44 Q_OBJECT
45 /** short Base properties supported by all service configurations */
46 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
47 Q_PROPERTY(QString email READ email WRITE setEmail NOTIFY emailChanged)
48 Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
49 Q_PROPERTY(QString server READ server WRITE setServer NOTIFY serverChanged)
50 Q_PROPERTY(QString port READ port WRITE setPort NOTIFY portChanged)
51 Q_PROPERTY(EncryptionMethod encryption READ encryption WRITE setEncryption NOTIFY encryptionChanged)
52 Q_PROPERTY(ServiceType serviceType READ serviceType CONSTANT)
53 Q_PROPERTY(bool acceptUntrustedCertificates READ acceptUntrustedCertificates WRITE setAcceptUntrustedCertificates NOTIFY acceptUntrustedCertChanged)
54
55 Q_ENUMS(ServiceType)
56 Q_ENUMS(EncryptionMethod)
57 Q_ENUMS(SaslMechanism)
58
59 public:
60 explicit AccountConfiguration(QObject *parent = 0);
61 AccountConfiguration(QObject *parent, QMailAccountConfiguration *config, const QString &serviceType);
62 ~AccountConfiguration();
63
64 enum ServiceType {
65 IMAP,
66 POP3,
67 SMTP
68 };
69
70 enum EncryptionMethod {
71 None = QMailTransport::Encrypt_NONE,
72 SSL = QMailTransport::Encrypt_SSL,
73 STARTTLS = QMailTransport::Encrypt_TLS
74 };
75
76 enum SaslMechanism {
77 NONE = QMail::NoMechanism,
78 LOGIN = QMail::LoginMechanism,
79 PLAIN = QMail::PlainMechanism,
80 CRAM_MD5 = QMail::CramMd5Mechanism
81 };
82
83 QString name() const;
84 QString email() const;
85 QString password() const;
86 QString server() const;
87 QString port() const;
88 EncryptionMethod encryption() const;
89 ServiceType serviceType() const;
90 bool acceptUntrustedCertificates() const;
91
92 Q_INVOKABLE QString customValue(const QString &ns, const QString &key);
93 Q_INVOKABLE void setCustomValue(const QString &ns, const QString &key, const QString &value);
94
95 signals:
96 void nameChanged(QString name);
97 void emailChanged(QString email);
98 void serverChanged(QString server);
99 void portChanged(QString port);
100 void encryptionChanged();
101 void passwordChanged();
102 void acceptUntrustedCertChanged();
103 void customValueChanged(QString key, QString value);
104
105 public slots:
106 void setName(const QString &name);
107 void setEmail(const QString &email);
108 void setPassword(const QString &pwd);
109 void setServer(const QString &server);
110 void setPort(const QString &port);
111 void setEncryption(EncryptionMethod method);
112 void setAcceptUntrustedCertificates(const bool accept);
113 virtual void emitConfigurationChanges();
114
115 protected:
116 void init(QMailAccountConfiguration *config, const QString &serviceType);
117 void addServiceType(ServiceType type);
118 void removeServiceType(ServiceType type);
119
120 QMailAccountConfiguration *m_config;
121 QMailServiceConfiguration *m_service;
122 QString m_serviceType;
123 };
124
125 /** @ingroup group_accounts */
126 class ImapAccountConfiguration : public AccountConfiguration
127 {
128 Q_OBJECT
129 Q_PROPERTY(SaslMechanism saslMechanism READ saslMechanism WRITE setSaslMechanism NOTIFY saslChanged)
130 Q_PROPERTY(bool canDeleteMail READ canDeleteMail WRITE setDeleteMail NOTIFY canDeleteMailChanged)
131 Q_PROPERTY(bool downloadAttachments READ downloadAttachments WRITE setDownloadAttachments NOTIFY downloadAttachmentsChanged)
132 Q_PROPERTY(bool isAutoDownload READ isAutoDownload WRITE setAutoDownload NOTIFY autoDownloadChanged)
133 Q_PROPERTY(int maxMailSize READ maxMailSize WRITE setMaxMailSize NOTIFY maxMailSizeChanged)
134 Q_PROPERTY(SubType preferredSubType READ preferredSubType WRITE setPreferredSubType NOTIFY preferredSubTypeChanged)
135 Q_PROPERTY(bool canIDLE READ canIDLE CONSTANT)
136 Q_PROPERTY(bool idleEnabled READ idleEnabled WRITE setIdleEnabled NOTIFY idleEnabledChanged)
137 Q_PROPERTY(QString baseFolder READ baseFolder WRITE setBaseFolder NOTIFY baseFolderChanged)
138 Q_PROPERTY(QStringList pushFolders READ pushFolders WRITE setPushFolders NOTIFY pushFolderChanged)
139 Q_PROPERTY(int checkInterval READ checkInterval WRITE setCheckInterval NOTIFY checkIntervalChanged)
140 Q_PROPERTY(bool checkWhenRoaming READ checkWhenRoaming WRITE setCheckWhenRoaming NOTIFY checkWhenRoamingChanged)
141 Q_PROPERTY(QStringList capabilities READ capabilities CONSTANT)
142 Q_PROPERTY(int timeTillLogout READ timeTillLogout CONSTANT)
143 Q_PROPERTY(int searchLimit READ searchLimit WRITE setSearchLimit NOTIFY searchLimitChanged)
144 Q_ENUMS(SubType)
145
146 public:
147 explicit ImapAccountConfiguration(QObject *parent = 0);
148 ImapAccountConfiguration(QObject *parent, QMailAccountConfiguration *config, const QString &serviceType) :
149 AccountConfiguration(parent, config, serviceType){}
150
151 enum SubType {
152 Plain,
153 Html
154 };
155
156 SaslMechanism saslMechanism() const;
157 bool canDeleteMail() const;
158 bool downloadAttachments() const;
159 bool isAutoDownload() const;
160 int maxMailSize() const;
161 SubType preferredSubType() const;
162 bool canIDLE() const;
163 bool idleEnabled() const;
164 QString baseFolder() const;
165 QStringList pushFolders() const;
166 int checkInterval() const;
167 bool checkWhenRoaming() const;
168 QStringList capabilities() const;
169 int timeTillLogout() const;
170 int searchLimit() const;
171
172 signals:
173 void saslChanged();
174 void canDeleteMailChanged();
175 void downloadAttachmentsChanged();
176 void autoDownloadChanged();
177 void maxMailSizeChanged();
178 void preferredSubTypeChanged();
179 void idleEnabledChanged();
180 void baseFolderChanged();
181 void pushFolderChanged();
182 void checkIntervalChanged();
183 void checkWhenRoamingChanged();
184 void searchLimitChanged();
185
186 public slots:
187 void setSaslMechanism(SaslMechanism sasl);
188 void setDeleteMail(const bool canDelete);
189 void setDownloadAttachments(const bool download);
190 void setAutoDownload(const bool autoDownload);
191 void setMaxMailSize(const int &size);
192 void setPreferredSubType(SubType subType);
193 void setIdleEnabled(const bool enabled);
194 void setBaseFolder(const QString &baseFolder);
195 void setPushFolders(const QStringList &pushFolders);
196 void appendPushFolder(const QString &folder) {
197 QStringList p = pushFolders();
198 if (p.contains(folder)) {
199 return;
200 }
201 qDebug() << "PUSH FOLDERS: " << p;
202 p.append(folder);
203 setPushFolders(p);
204 }
205
206 void setCheckInterval(const int &interval); // in milliseconds
207 void setCheckWhenRoaming(const bool check);
208 void setSearchLimit(const int &limit);
209 virtual void emitConfigurationChanges() override;
210
211 };
212
213 /** @ingroup group_accounts */
214 class SmtpAccountConfiguration : public AccountConfiguration
215 {
216 Q_OBJECT
217 Q_PROPERTY(SaslMechanism saslMechanism READ saslMechanism WRITE setSaslMechanism NOTIFY saslChanged)
218 Q_PROPERTY(QString username READ username WRITE setUsername NOTIFY usernameChanged)
219 Q_PROPERTY(QString initials READ initials CONSTANT)
220 Q_PROPERTY(bool authFromCaps READ authFromCaps WRITE setAuthFromCaps NOTIFY authFromCapsChanged)
221 Q_PROPERTY(QString signature READ signature WRITE setSignature NOTIFY signatureChanged)
222
223 public:
224 explicit SmtpAccountConfiguration(QObject *parent = 0);
225 SmtpAccountConfiguration(QObject *parent, QMailAccountConfiguration *config, const QString &serviceType) :
226 AccountConfiguration(parent, config, serviceType){}
227
228 SaslMechanism saslMechanism() const;
229 QString username() const;
230 bool authFromCaps() const;
231 QString initials();
232 QString signature() const;
233
234 signals:
235 void saslChanged();
236 void usernameChanged();
237 void authFromCapsChanged();
238 void signatureChanged();
239
240 public slots:
241 void setSaslMechanism(SaslMechanism sasl);
242 void setUsername(const QString &username);
243 void setAuthFromCaps(const bool use);
244 void setSignature(const QString &sig);
245 virtual void emitConfigurationChanges() override;
246 };
247
248 /** @ingroup group_accounts */
249 class PopAccountConfiguration : public AccountConfiguration
250 {
251 Q_OBJECT
252 Q_PROPERTY(bool canDeleteMail READ canDeleteMail WRITE setDeleteMail NOTIFY canDeleteMailChanged)
253 Q_PROPERTY(bool isAutoDownload READ isAutoDownload WRITE setAutoDownload NOTIFY autoDownloadChanged)
254 Q_PROPERTY(int maxMailSize READ maxMailSize WRITE setMaxMailSize NOTIFY maxMailSizeChanged)
255 Q_PROPERTY(int checkInterval READ checkInterval WRITE setCheckInterval NOTIFY checkIntervalChanged)
256 Q_PROPERTY(bool checkWhenRoaming READ checkWhenRoaming WRITE setCheckWhenRoaming NOTIFY checkWhenRoamingChanged)
257
258 public:
259 explicit PopAccountConfiguration(QObject *parent = 0);
260 PopAccountConfiguration(QObject *parent, QMailAccountConfiguration *config, const QString &serviceType) :
261 AccountConfiguration(parent, config, serviceType){}
262
263 bool canDeleteMail() const;
264 bool isAutoDownload() const;
265 int maxMailSize() const;
266 int checkInterval() const;
267 bool checkWhenRoaming() const;
268
269 signals:
270 void canDeleteMailChanged();
271 void autoDownloadChanged();
272 void maxMailSizeChanged();
273 void checkIntervalChanged();
274 void checkWhenRoamingChanged();
275
276 public slots:
277 void setDeleteMail(const bool setDelete);
278 void setAutoDownload(const bool autoDownload);
279 void setMaxMailSize(const int &maxSize);
280 void setCheckInterval(const int &interval);
281 void setCheckWhenRoaming(const bool check);
282 virtual void emitConfigurationChanges() override;
283
284 };
285
286 /** @ingroup group_accounts */
287 class PasswordHelper : public QMailServiceConfiguration
288 {
289 public:
290 static QString decodePassword(const QString &value) {
291 return decodeValue(value);
292 }
293 static QString encodePassword(const QString &value) {
294 return encodeValue(value);
295 }
296 };
297
298 #endif // ACCOUNTCONFIGURATION_H