16#include <QNetworkProxy>
18#include "mailtransport_debug.h"
20using namespace MailTransport;
22namespace MailTransport
29 QSslSocket *socket =
nullptr;
38 void slotModeChanged(QSslSocket::SslMode state);
39 void slotSocketRead();
47SocketPrivate::SocketPrivate(
Socket *s)
52void SocketPrivate::slotConnected()
54 qCDebug(MAILTRANSPORT_LOG);
57 qCDebug(MAILTRANSPORT_LOG) <<
"normal connect";
60 qCDebug(MAILTRANSPORT_LOG) <<
"encrypted connect";
61 socket->startClientEncryption();
68 qCDebug(MAILTRANSPORT_LOG) <<
"State is now:" << (int)state;
75void SocketPrivate::slotModeChanged(QSslSocket::SslMode state)
78 qCDebug(MAILTRANSPORT_LOG) <<
"Mode is now:" << state;
80 if (state == QSslSocket::SslClientMode) {
85void SocketPrivate::slotSocketRead()
87 qCDebug(MAILTRANSPORT_LOG);
100 qCDebug(MAILTRANSPORT_LOG) << socket->isEncrypted() << m_msg.
trimmed();
103 Q_EMIT q->
data(m_msg);
109 qCDebug(MAILTRANSPORT_LOG);
112 socket->ignoreSslErrors();
120 , d(new SocketPrivate(this))
122 qCDebug(MAILTRANSPORT_LOG);
127 qCDebug(MAILTRANSPORT_LOG);
132 qCDebug(MAILTRANSPORT_LOG) <<
"Connecting to:" << d->server <<
":" << d->port;
142 d->socket =
new QSslSocket(
this);
144 d->socket->connectToHost(d->server, d->port);
149 connect(d->socket, SIGNAL(modeChanged(QSslSocket::SslMode)), SLOT(slotModeChanged(QSslSocket::SslMode)));
151 connect(d->socket, SIGNAL(readyRead()), SLOT(slotSocketRead()));
165 QByteArray cs = (text +
"\r\n"_L1).toLatin1();
168 qCDebug(MAILTRANSPORT_LOG) <<
"C :" << cs;
171 d->socket->write(cs.
data(), cs.
size());
185 d->socket->startClientEncryption();
213#include "moc_socket.cpp"
Responsible for communicating with the server, it's designed to work with the ServerTest class.
void connected()
emitted when there is a connection (ready to send something).
Socket(QObject *parent)
Constructor, it will not auto connect.
void setServer(const QString &server)
set the server to use
void setPort(int port)
set the port to use.
virtual void reconnect()
Existing connection will be closed and a new connection will be made.
void failed()
emitted when not connected.
int port() const
returns the used port.
void data(const QString &)
emits the incoming data
void setSecure(bool what)
this will be a secure connection
void setProtocol(const QString &proto)
set the protocol to use
virtual void write(const QString &text)
Write text to the socket.
~Socket() override
Destructor.
void tlsDone()
emitted when startShake() is completed.
void startTLS()
If you want to start TLS encryption, call this.
qsizetype size() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
QString trimmed() const const