Skip to content

Commit d995617

Browse files
Fix issue 185: Enforce CRLF and sanitize header fields (#186)
* Added sanitizing header fields (remove \r, \n) preventing malicious injection. Added replacing naked LFs and CRs with CRLF to be compliant with SMTP standard (RFC 5321). In SmtpClient.h, replace Q_ENUMS with individual Q_ENUM, added string() function for enum types. * Corrected choice of variables. MAde QRegularExpressions static. * Made QRegExpressions const, added QRegularExpression::DontCaptureOption. Made names more expressive. * Roll back "sanitization" changes. * Fix empty line mismatch in rollback.
1 parent ddfe7ee commit d995617

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/smtpclient.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2011-2012 - Tőkés Attila
2+
Copyright (c) 2011-2025 - Tőkés Attila
33
44
This file is part of SmtpClient for Qt.
55
@@ -19,6 +19,8 @@
1919
#ifndef SMTPCLIENT_H
2020
#define SMTPCLIENT_H
2121

22+
#include <QMetaEnum>
23+
2224
#include <QObject>
2325
#include <QtNetwork/QSslSocket>
2426
#include <QEventLoop>
@@ -29,7 +31,6 @@
2931
class SMTP_MIME_EXPORT SmtpClient : public QObject
3032
{
3133
Q_OBJECT
32-
Q_ENUMS (AuthMethod SmtpError ConnectionType ClientState)
3334
public:
3435

3536
/* [0] Enumerations */
@@ -39,6 +40,7 @@ class SMTP_MIME_EXPORT SmtpClient : public QObject
3940
AuthPlain,
4041
AuthLogin
4142
};
43+
Q_ENUM(AuthMethod)
4244

4345
enum SmtpError
4446
{
@@ -50,13 +52,15 @@ class SMTP_MIME_EXPORT SmtpClient : public QObject
5052
ClientError = 5, // 5xx smtp error
5153
SocketError = 6
5254
};
55+
Q_ENUM(SmtpError)
5356

5457
enum ConnectionType
5558
{
5659
TcpConnection = 0,
5760
SslConnection = 1,
5861
TlsConnection = 2 // STARTTLS
5962
};
63+
Q_ENUM(ConnectionType)
6064

6165
enum ClientState {
6266
UnconnectedState = 0,
@@ -99,6 +103,14 @@ class SMTP_MIME_EXPORT SmtpClient : public QObject
99103
_MAIL_3_DATA = 84,
100104
_MAIL_4_SEND_DATA = 85
101105
};
106+
Q_ENUM(ClientState)
107+
108+
template <typename enumType>
109+
static QString string(enumType v)
110+
{
111+
static QMetaEnum metaEnum = QMetaEnum::fromType<enumType>();
112+
return metaEnum.valueToKey(static_cast<int>(v));
113+
}
102114

103115
/* [0] --- */
104116

0 commit comments

Comments
 (0)