File indexing completed on 2025-03-23 11:10:20
0001 // SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org> 0002 // SPDX-License-Identifier: LGPL-2.0-or-later 0003 0004 #pragma once 0005 0006 #include <QObject> 0007 0008 #include <MailTransport/Transport> 0009 0010 #include "accounts/ispdb/ispdb.h" 0011 #include "accounts/setup/setupmanager.h" 0012 0013 /** 0014 * Object that is created in QML to facilitate the creation of a new email account. 0015 */ 0016 0017 class NewAccount : public QObject { 0018 Q_OBJECT 0019 Q_PROPERTY(QString email READ email WRITE setEmail NOTIFY emailChanged) 0020 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 0021 Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged) 0022 Q_PROPERTY(bool ispdbIsSearching READ ispdbIsSearching NOTIFY ispdbIsSearchingChanged) 0023 0024 // email server form 0025 Q_PROPERTY(ReceivingMailProtocol receivingMailProtocol READ receivingMailProtocol WRITE setReceivingMailProtocol NOTIFY receivingMailProtocolChanged) 0026 0027 // imap 0028 Q_PROPERTY(QString imapHost READ imapHost WRITE setImapHost NOTIFY imapHostChanged) 0029 Q_PROPERTY(int imapPort READ imapPort WRITE setImapPort NOTIFY imapPortChanged) 0030 Q_PROPERTY(QString imapUsername READ imapUsername WRITE setImapUsername NOTIFY imapUsernameChanged) 0031 Q_PROPERTY(QString imapPassword READ imapPassword WRITE setImapPassword NOTIFY imapPasswordChanged) 0032 Q_PROPERTY(AuthenticationType imapAuthenticationType READ imapAuthenticationType WRITE setImapAuthenticationType NOTIFY imapAuthenticationTypeChanged) 0033 Q_PROPERTY(SocketType imapSocketType READ imapSocketType WRITE setImapSocketType NOTIFY imapSocketTypeChanged) 0034 0035 // pop3 0036 Q_PROPERTY(QString pop3Host READ pop3Host WRITE setPop3Host NOTIFY pop3HostChanged) 0037 Q_PROPERTY(int pop3Port READ pop3Port WRITE setPop3Port NOTIFY pop3PortChanged) 0038 Q_PROPERTY(QString pop3Username READ pop3Username WRITE setPop3Username NOTIFY pop3UsernameChanged) 0039 Q_PROPERTY(QString pop3Password READ pop3Password WRITE setPop3Password NOTIFY pop3PasswordChanged) 0040 Q_PROPERTY(AuthenticationType pop3AuthenticationType READ pop3AuthenticationType WRITE setPop3AuthenticationType NOTIFY pop3AuthenticationTypeChanged) 0041 Q_PROPERTY(SocketType pop3SocketType READ pop3SocketType WRITE setPop3SocketType NOTIFY pop3SocketTypeChanged) 0042 0043 // smtp 0044 Q_PROPERTY(QString smtpHost READ smtpHost WRITE setSmtpHost NOTIFY smtpHostChanged) 0045 Q_PROPERTY(int smtpPort READ smtpPort WRITE setSmtpPort NOTIFY smtpPortChanged) 0046 Q_PROPERTY(QString smtpUsername READ smtpUsername WRITE setSmtpUsername NOTIFY smtpUsernameChanged) 0047 Q_PROPERTY(QString smtpPassword READ smtpPassword WRITE setSmtpPassword NOTIFY smtpPasswordChanged) 0048 Q_PROPERTY(AuthenticationType smtpAuthenticationType READ smtpAuthenticationType WRITE setSmtpAuthenticationType NOTIFY smtpAuthenticationTypeChanged) 0049 Q_PROPERTY(SocketType smtpSocketType READ smtpSocketType WRITE setSmtpSocketType NOTIFY smtpSocketTypeChanged) 0050 0051 public: 0052 NewAccount(QObject *parent = nullptr); 0053 virtual ~NewAccount() noexcept; 0054 0055 enum ReceivingMailProtocol { 0056 Pop3, 0057 Imap 0058 }; 0059 Q_ENUM(ReceivingMailProtocol) 0060 0061 enum SocketType { 0062 SSL, 0063 StartTLS, 0064 None 0065 }; 0066 Q_ENUM(SocketType) 0067 0068 enum AuthenticationType { 0069 Plain, 0070 CramMD5, 0071 NTLM, 0072 GSSAPI, 0073 OAuth2, 0074 NoAuth 0075 }; 0076 Q_ENUM(AuthenticationType) 0077 0078 QString &email(); 0079 void setEmail(const QString &email); 0080 0081 QString &name(); 0082 void setName(const QString &name); 0083 0084 QString &password(); 0085 void setPassword(const QString &password); 0086 0087 bool ispdbIsSearching(); 0088 0089 ReceivingMailProtocol receivingMailProtocol(); 0090 void setReceivingMailProtocol(ReceivingMailProtocol receivingMailProtocol); 0091 0092 // imap form 0093 QString &imapHost(); 0094 void setImapHost(QString host); 0095 0096 int imapPort(); 0097 void setImapPort(int port); 0098 0099 QString &imapUsername(); 0100 void setImapUsername(QString username); 0101 0102 QString &imapPassword(); 0103 void setImapPassword(QString password); 0104 0105 AuthenticationType imapAuthenticationType(); 0106 void setImapAuthenticationType(AuthenticationType authenticationType); 0107 0108 SocketType imapSocketType(); 0109 void setImapSocketType(SocketType socketType); 0110 0111 // pop3 form 0112 QString &pop3Host(); 0113 void setPop3Host(QString host); 0114 0115 int pop3Port(); 0116 void setPop3Port(int port); 0117 0118 QString &pop3Username(); 0119 void setPop3Username(QString username); 0120 0121 QString &pop3Password(); 0122 void setPop3Password(QString password); 0123 0124 AuthenticationType pop3AuthenticationType(); 0125 void setPop3AuthenticationType(AuthenticationType authenticationType); 0126 0127 SocketType pop3SocketType(); 0128 void setPop3SocketType(SocketType pop3SocketType); 0129 0130 // smtp form 0131 QString &smtpHost(); 0132 void setSmtpHost(QString host); 0133 0134 int smtpPort(); 0135 void setSmtpPort(int port); 0136 0137 QString &smtpUsername(); 0138 void setSmtpUsername(QString username); 0139 0140 QString &smtpPassword(); 0141 void setSmtpPassword(QString password); 0142 0143 AuthenticationType smtpAuthenticationType(); 0144 void setSmtpAuthenticationType(AuthenticationType authenticationType); 0145 0146 SocketType smtpSocketType(); 0147 void setSmtpSocketType(SocketType socketType); 0148 0149 // search online (mozilla db) for SMTP/IMAP/POP3 settings for the given email 0150 Q_INVOKABLE void searchIspdbForConfig(); 0151 0152 // add account with the current settings 0153 Q_INVOKABLE void addAccount(); 0154 0155 void configureImap(QString host, int port, QString username, QString password, AuthenticationType authentication, SocketType socket); 0156 void configurePop3(QString host, int port, QString username, QString password, AuthenticationType authentication, SocketType socket); 0157 void configureSmtp(QString host, int port, QString username, QString password, AuthenticationType authentication, SocketType socket); 0158 0159 public Q_SLOTS: 0160 void ispdbFinishedSearchingSlot(); 0161 0162 Q_SIGNALS: 0163 void emailChanged(); 0164 void nameChanged(); 0165 void passwordChanged(); 0166 void ispdbIsSearchingChanged(); 0167 void receivingMailProtocolChanged(); 0168 0169 void imapHostChanged(); 0170 void imapPortChanged(); 0171 void imapUsernameChanged(); 0172 void imapPasswordChanged(); 0173 void imapAuthenticationTypeChanged(); 0174 void imapSocketTypeChanged(); 0175 void pop3HostChanged(); 0176 void pop3PortChanged(); 0177 void pop3UsernameChanged(); 0178 void pop3PasswordChanged(); 0179 void pop3AuthenticationTypeChanged(); 0180 void pop3SocketTypeChanged(); 0181 void smtpHostChanged(); 0182 void smtpPortChanged(); 0183 void smtpUsernameChanged(); 0184 void smtpPasswordChanged(); 0185 void smtpAuthenticationTypeChanged(); 0186 void smtpSocketTypeChanged(); 0187 0188 void setupSucceeded(const QString &msg); 0189 void setupFailed(const QString &msg); 0190 void setupInfo(const QString &msg); 0191 0192 private: 0193 AuthenticationType ispdbTypeToAuth(Ispdb::authType authType); 0194 SocketType ispdbTypeToSocket(Ispdb::socketType socketType); 0195 0196 QString m_email; 0197 QString m_name; 0198 QString m_password; 0199 0200 bool m_ispdbIsSearching; 0201 Ispdb *m_ispdb; 0202 0203 SetupManager *m_setupManager; 0204 0205 ReceivingMailProtocol m_receivingMailProtocol; 0206 0207 QString m_imapHost; 0208 int m_imapPort; 0209 QString m_imapUsername; 0210 QString m_imapPassword; 0211 AuthenticationType m_imapAuthenticationType; 0212 SocketType m_imapSocketType; 0213 0214 QString m_pop3Host; 0215 int m_pop3Port; 0216 QString m_pop3Username; 0217 QString m_pop3Password; 0218 AuthenticationType m_pop3AuthenticationType; 0219 SocketType m_pop3SocketType; 0220 0221 QString m_smtpHost; 0222 int m_smtpPort; 0223 QString m_smtpUsername; 0224 QString m_smtpPassword; 0225 AuthenticationType m_smtpAuthenticationType; 0226 SocketType m_smtpSocketType; 0227 };