Bump to 4.6.7
[qBittorrent.git] / src / base / net / smtp.h
blob28c7cadebfdb1e22176a2652071f8825e687c8c4
1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2011 Christophe Dumez <chris@qbittorrent.org>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * In addition, as a special exception, the copyright holders give permission to
20 * link this program with the OpenSSL project's "OpenSSL" library (or with
21 * modified versions of it that use the same license as the "OpenSSL" library),
22 * and distribute the linked executables. You must obey the GNU General Public
23 * License in all respects for all of the code used other than "OpenSSL". If you
24 * modify file(s), you may extend this exception to your version of the file(s),
25 * but you are not obligated to do so. If you do not wish to do so, delete this
26 * exception statement from your version.
30 * This code is based on QxtSmtp from libqxt (http://libqxt.org)
33 #pragma once
35 #include <QAbstractSocket>
36 #include <QByteArray>
37 #include <QHash>
38 #include <QObject>
39 #include <QString>
41 #ifndef QT_NO_OPENSSL
42 class QSslSocket;
43 #else
44 class QTcpSocket;
45 #endif
46 class QTextCodec;
48 namespace Net
50 class Smtp : public QObject
52 Q_OBJECT
53 Q_DISABLE_COPY_MOVE(Smtp)
55 public:
56 Smtp(QObject *parent = nullptr);
57 ~Smtp();
59 void sendMail(const QString &from, const QString &to, const QString &subject, const QString &body);
61 private slots:
62 void readyRead();
63 void error(QAbstractSocket::SocketError socketError);
65 private:
66 enum States
68 Rcpt,
69 EhloSent,
70 HeloSent,
71 EhloDone,
72 EhloGreetReceived,
73 AuthRequestSent,
74 AuthSent,
75 AuthUsernameSent,
76 Authenticated,
77 StartTLSSent,
78 Data,
79 Init,
80 Body,
81 Quit,
82 Close
85 enum AuthType
87 AuthPlain,
88 AuthLogin,
89 AuthCramMD5
92 QByteArray encodeMimeHeader(const QString &key, const QString &value, const QByteArray &prefix = {});
93 void ehlo();
94 void helo();
95 void parseEhloResponse(const QByteArray &code, bool continued, const QString &line);
96 void authenticate();
97 void startTLS();
98 void authCramMD5(const QByteArray &challenge = {});
99 void authPlain();
100 void authLogin();
101 void logError(const QString &msg);
102 QString getCurrentDateTime() const;
104 QByteArray m_message;
105 #ifndef QT_NO_OPENSSL
106 QSslSocket *m_socket = nullptr;
107 #else
108 QTcpSocket *m_socket = nullptr;
109 #endif
110 QString m_from;
111 QString m_rcpt;
112 QString m_response;
113 int m_state = Init;
114 QHash<QString, QString> m_extensions;
115 QByteArray m_buffer;
116 bool m_useSsl = false;
117 AuthType m_authType = AuthPlain;
118 QString m_username;
119 QString m_password;