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

Updated to support Stalwart Mail server #22

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tls_icon.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class tls_icon extends rcube_plugin
const POSTFIX_TLS_REGEX = "/\(using (TLS.*)\) \(/im";
const POSTFIX_LOCAL_REGEX = "/\([a-zA-Z]*, from userid [0-9]*\)/im";
const SENDMAIL_TLS_REGEX = "/\(version=(TLS.*)\)(\s+for|;)/im";
const STALWART_TLS_REGEX = "/\(using (TLSv1\.[23] with cipher .+)\) by .+ \(Stalwart SMTP\)/im";
Copy link
Owner

Choose a reason for hiding this comment

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

This regex appears similar to the Postfix regex. Is there a specific reason why the existing Postfix regex doesn't work for Stalwart?

Copy link
Owner

@GermanCoding GermanCoding Sep 17, 2024

Choose a reason for hiding this comment

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

Also, I don't like having overly specific regexes. Currently, TLSv1.2 and TLSv1.3 are the only protocol versions commonly used, but to anticipate a future TLSv1.4 or TLSv2.0 I don't think the regex needs to match only TLSv1\.[23].

Copy link
Contributor

Choose a reason for hiding this comment

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

For reference the name seems to be hard coded: https://github.com/stalwartlabs/mail-server/blob/24df9a0352a948f67ad58ab0d7d7423002863d43/crates/smtp/src/inbound/data.rs#L947

But I do not see the point of keeping it in the regex

Suggested change
const STALWART_TLS_REGEX = "/\(using (TLSv1\.[23] with cipher .+)\) by .+ \(Stalwart SMTP\)/im";
const STALWART_TLS_REGEX = "/\(using (TLSv1\.[23] with cipher .+)\)/im";


private $message_headers_done = false;
private $icon_img;
Expand Down Expand Up @@ -60,7 +61,8 @@ public function message_headers($p)
}

if (preg_match_all(tls_icon::POSTFIX_TLS_REGEX, $Received, $items, PREG_PATTERN_ORDER) ||
preg_match_all(tls_icon::SENDMAIL_TLS_REGEX, $Received, $items, PREG_PATTERN_ORDER)) {
preg_match_all(tls_icon::SENDMAIL_TLS_REGEX, $Received, $items, PREG_PATTERN_ORDER) ||
preg_match_all(tls_icon::STALWART_TLS_REGEX, $Received, $items, PREG_PATTERN_ORDER)) {
$data = $items[1][0];
$this->icon_img .= '<img class="lock_icon" src="plugins/tls_icon/lock.svg" title="' . htmlentities($data) . '" />';
} elseif (preg_match_all(tls_icon::POSTFIX_LOCAL_REGEX, $Received, $items, PREG_PATTERN_ORDER)) {
Expand Down
Loading