Skip to content

Commit 6896b72

Browse files
authored
Merge pull request #28 from christiaangoossens/patch-tls-13-postfix
Fix TLS v1.3 on modern Postfix
2 parents 1b23b48 + 1f07132 commit 6896b72

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

test/TlsIconTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ final class TlsIconTest extends TestCase
3333
/** @var string */
3434
private $strStalwartCryptedTlsv13WithCipher = '<img class="lock_icon" src="plugins/tls_icon/lock.svg" title="TLSv1.3 with cipher TLS13_AES_256_GCM_SHA384" />';
3535

36+
/** @var string */
37+
private $strNewPostfixTLSv13 = '<img class="lock_icon" src="plugins/tls_icon/lock.svg" title="TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature RSA-PSS (4096 bits) server-digest SHA256" />';
38+
3639
public function testInstance()
3740
{
3841
$o = new tls_icon();
@@ -196,6 +199,43 @@ public function testMessageHeadersInternal()
196199
], $headersProcessed);
197200
}
198201

202+
public function testPostfixTLS13NewSyntax()
203+
{
204+
$header = 'from GVXPR05CU001.outbound.protection.outlook.com (mail-swedencentralazon11023139.outbound.protection.outlook.com [52.101.83.139])
205+
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature RSA-PSS (4096 bits) server-digest SHA256)
206+
(No client certificate requested)
207+
by example.com with ESMTPS id EXAMPLE
208+
for <[email protected]>; Tue, 16 Sep 2025 12:26:17 +0200 (CEST)';
209+
210+
$o = new tls_icon();
211+
$headersProcessed = $o->message_headers([
212+
'output' => [
213+
'subject' => [
214+
'value' => 'Sent to you',
215+
],
216+
],
217+
'headers' => (object)[
218+
'others' => [
219+
'received' => $header,
220+
]
221+
]
222+
]);
223+
$this->assertEquals([
224+
'output' => [
225+
'subject' => [
226+
'value' => 'Sent to you' . $this->strNewPostfixTLSv13,
227+
'html' => 1,
228+
],
229+
],
230+
'headers' => (object)[
231+
'others' => [
232+
'received' => $header,
233+
]
234+
]
235+
], $headersProcessed);
236+
}
237+
238+
199239
public function testMessageHeadersMultiFromWithConfig()
200240
{
201241
$inputHeaders = [

tls_icon.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class tls_icon extends rcube_plugin
44
{
5-
const POSTFIX_TLS_REGEX = "/\(using (TLS[^()]+(?:\([^)]+\))?)\)/im";
5+
const POSTFIX_TLS_REGEX = "/\(using (TLS(?:[^()]|\([^()]*\))*)\)/im";
66
const POSTFIX_LOCAL_REGEX = "/\([a-zA-Z]*, from userid [0-9]*\)/im";
77
const SENDMAIL_TLS_REGEX = "/\(version=(TLS.*)\)(\s+for|;)/im";
88

@@ -59,8 +59,10 @@ public function message_headers($p)
5959
return $p;
6060
}
6161

62-
if (preg_match_all(tls_icon::POSTFIX_TLS_REGEX, $Received, $items, PREG_PATTERN_ORDER) ||
63-
preg_match_all(tls_icon::SENDMAIL_TLS_REGEX, $Received, $items, PREG_PATTERN_ORDER)) {
62+
if (
63+
preg_match_all(tls_icon::POSTFIX_TLS_REGEX, $Received, $items, PREG_PATTERN_ORDER) ||
64+
preg_match_all(tls_icon::SENDMAIL_TLS_REGEX, $Received, $items, PREG_PATTERN_ORDER)
65+
) {
6466
$data = $items[1][0];
6567
$this->icon_img .= '<img class="lock_icon" src="plugins/tls_icon/lock.svg" title="' . htmlentities($data) . '" />';
6668
} elseif (preg_match_all(tls_icon::POSTFIX_LOCAL_REGEX, $Received, $items, PREG_PATTERN_ORDER)) {

0 commit comments

Comments
 (0)