Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMTP Client improvements. #2802

Merged
merged 8 commits into from
Jun 14, 2024

Conversation

slaff
Copy link
Contributor

@slaff slaff commented Jun 12, 2024

  • Continue plain-text communication if SSL is not compiled
  • Fix memory leaks in MailMessage
  • Expose TcpConnection::enableSsl(hostName) which allows a plain-text TCP connection to be changed to SSL one after the tcp connection is established.

@slaff slaff added this to the 5.2.0 milestone Jun 12, 2024
Comment on lines 41 to 48
~MailMessage()
{
delete stream;
for(auto attachment : attachments) {
delete attachment.headers;
delete attachment.stream;
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like stream should be unique_ptr. Also not sure it's necessary to destroy attachments, should happen automatically when vector is destroyed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just done some checking and of course attachment has no destructor...

Comment on lines 440 to 442
if(hostName) {
ssl->hostName = hostName;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is check necessary? Or is that in case there's an sslInit callback registered which might do it. Maybe document to clarify? Or Just assign ssl->hostName = hostName

Comment on lines 444 to 443
useSsl = true;
useSsl = (internalOnConnected(ERR_OK) == ERR_OK);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove redundant useSsl = true;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that the code looks a bit wierd but in internalOnConnected() useSsl has to be true to kick start the SSL connection.

err_t TcpConnection::internalOnConnected(err_t err)
{
	debug_tcp_d("connected: useSSL: %d, Error: %d", useSsl, err);

	if(useSsl && err == ERR_OK) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I suggest a comment and/or slight rewrite:

useSsl = true;
if (internalOnConnected(ERR_OK) != ERR_OK) {
  useSsl = false;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I suggest a comment and/or slight rewrite:

Sure. I will apply your change in a minute.

@slaff slaff force-pushed the feature/tcp-connection-enablessl branch from d0f2185 to 6228d34 Compare June 12, 2024 13:05
@slaff slaff force-pushed the feature/tcp-connection-enablessl branch from f8a2858 to 30c0838 Compare June 12, 2024 15:51
@slaff
Copy link
Contributor Author

slaff commented Jun 13, 2024

@mikee47 shall I merge this PR with the applied review changes?

Copy link
Contributor

@mikee47 mikee47 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing further ATM, thanks slaff.

@@ -288,7 +289,7 @@ void SmtpClient::sendMailHeaders(MailMessage* mail)

if(!mail->headers.contains(HTTP_HEADER_CONTENT_TRANSFER_ENCODING)) {
mail->headers[HTTP_HEADER_CONTENT_TRANSFER_ENCODING] = _F("quoted-printable");
mail->stream = new QuotedPrintableOutputStream(mail->stream);
mail->stream.reset(new QuotedPrintableOutputStream(mail->stream.release()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mail->stream = std::make_unique<QuotedPrintableOutputStream>(mail->stream.release());

@slaff slaff merged commit e7fd787 into SmingHub:develop Jun 14, 2024
39 checks passed
@slaff slaff mentioned this pull request Jul 4, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants