Skip to content

Commit

Permalink
[qmf] Mask login information in the SMTP debug logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
Valerio Valerio committed Dec 14, 2014
1 parent a51e0f5 commit 236975e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
22 changes: 16 additions & 6 deletions qmf/src/plugins/messageservices/smtp/smtpclient.cpp
Expand Up @@ -361,7 +361,7 @@ void SmtpClient::readyRead()
incomingData();
}

void SmtpClient::sendCommand(const char *data, int len)
void SmtpClient::sendCommand(const char *data, int len, bool maskDebug)
{
if (len == -1)
len = ::strlen(data);
Expand All @@ -372,17 +372,27 @@ void SmtpClient::sendCommand(const char *data, int len)

++outstandingResponses;

qMailLog(SMTP) << "SEND:" << data;
if (maskDebug) {
qMailLog(SMTP) << "SEND: <login hidden>";
} else {
QString logCmd = QString::fromLatin1(data);
QRegExp loginExp("^AUTH\\s[^\\s]+\\s");
if (loginExp.indexIn(data) != -1) {
logCmd = logCmd.left(loginExp.matchedLength()) + "<login hidden>";
}

qMailLog(SMTP) << "SEND:" << logCmd;
}
}

void SmtpClient::sendCommand(const QString &cmd)
{
sendCommand(cmd.toLatin1());
}

void SmtpClient::sendCommand(const QByteArray &cmd)
void SmtpClient::sendCommand(const QByteArray &cmd, bool maskDebug)
{
sendCommand(cmd.data(), cmd.length());
sendCommand(cmd.data(), cmd.length(), maskDebug);
}

void SmtpClient::sendCommands(const QStringList &cmds)
Expand Down Expand Up @@ -676,8 +686,8 @@ void SmtpClient::nextAction(const QString &response)
#endif

if (!response.isEmpty()) {
// Send the response as Base64 encoded
sendCommand(response.toBase64());
// Send the response as Base64 encoded, mask the debug output
sendCommand(response.toBase64(), true);
bufferedResponse.clear();
return;
} else {
Expand Down
4 changes: 2 additions & 2 deletions qmf/src/plugins/messageservices/smtp/smtpclient.h
Expand Up @@ -113,9 +113,9 @@ private slots:
#endif

private:
void sendCommand(const char *data, int len = -1);
void sendCommand(const char *data, int len = -1, bool maskDebug = false);
void sendCommand(const QString &cmd);
void sendCommand(const QByteArray &cmd);
void sendCommand(const QByteArray &cmd, bool maskDebug = false);
void sendCommands(const QStringList &cmds);
void incomingData();
void nextAction(const QString &response);
Expand Down

0 comments on commit 236975e

Please sign in to comment.