Skip to content

Commit 3de4b2e

Browse files
authored
Merge pull request #32 from whitequark/match-localhost
Extend `POSTFIX_LOCAL_REGEX` to include mail received from localhost
2 parents 10ba22c + 612efb3 commit 3de4b2e

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

test/TlsIconTest.php

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,71 @@ public function testMessageHeadersInternal()
199199
], $headersProcessed);
200200
}
201201

202+
203+
public function testMessageHeadersInternalLocalhostIPv4()
204+
{
205+
$o = new tls_icon();
206+
$headersProcessed = $o->message_headers([
207+
'output' => [
208+
'subject' => [
209+
'value' => 'Sent to you',
210+
],
211+
],
212+
'headers' => (object)[
213+
'others' => [
214+
'received' => 'from mail.whitequark.org (localhost [127.0.0.1])
215+
by mail.whitequark.org (Postfix) with ESMTP id CDCA2E08B7',
216+
]
217+
]
218+
]);
219+
$this->assertEquals([
220+
'output' => [
221+
'subject' => [
222+
'value' => 'Sent to you' . $this->strInternal,
223+
'html' => 1,
224+
],
225+
],
226+
'headers' => (object)[
227+
'others' => [
228+
'received' => 'from mail.whitequark.org (localhost [127.0.0.1])
229+
by mail.whitequark.org (Postfix) with ESMTP id CDCA2E08B7',
230+
]
231+
]
232+
], $headersProcessed);
233+
}
234+
235+
public function testMessageHeadersInternalLocalhostIPv6()
236+
{
237+
$o = new tls_icon();
238+
$headersProcessed = $o->message_headers([
239+
'output' => [
240+
'subject' => [
241+
'value' => 'Sent to you',
242+
],
243+
],
244+
'headers' => (object)[
245+
'others' => [
246+
'received' => 'from mail.whitequark.org (localhost [IPv6:::1])
247+
by mail.whitequark.org (Postfix) with ESMTP id CDCA2E08B7',
248+
]
249+
]
250+
]);
251+
$this->assertEquals([
252+
'output' => [
253+
'subject' => [
254+
'value' => 'Sent to you' . $this->strInternal,
255+
'html' => 1,
256+
],
257+
],
258+
'headers' => (object)[
259+
'others' => [
260+
'received' => 'from mail.whitequark.org (localhost [IPv6:::1])
261+
by mail.whitequark.org (Postfix) with ESMTP id CDCA2E08B7',
262+
]
263+
]
264+
], $headersProcessed);
265+
}
266+
202267
public function testPostfixTLS13NewSyntax()
203268
{
204269
$header = 'from GVXPR05CU001.outbound.protection.outlook.com (mail-swedencentralazon11023139.outbound.protection.outlook.com [52.101.83.139])
@@ -279,7 +344,7 @@ public function testMessageHeadersMultiFromWithBadConfig()
279344
{
280345
$inputHeaders = [
281346
'from mail.example.org by mail.example.org with LMTP id pLzoBVClyGIiVgAA3BZZyA (envelope-from <[email protected]>) for <[email protected]>; Fri, 08 Jul 2022 21:44:48 +0000',
282-
'from localhost (localhost [127.0.0.1]) by mail.example.org (Postfix) with ESMTP id 0D33249414 for <[email protected]>; Fri, 8 Jul 2022 21:44:48 +0000 (UTC)',
347+
'from internalhost (internalhost [192.168.0.1]) by mail.example.org (Postfix) with ESMTP id 0D33249414 for <[email protected]>; Fri, 8 Jul 2022 21:44:48 +0000 (UTC)',
283348
'from xxxx-ord.mtasv.net (xxxx-ord.mtasv.net [255.255.255.255]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.example.org (Postfix) with ESMTPS id 73C3B461AF for <[email protected]>; Fri, 8 Jul 2022 21:44:39 +0000 (UTC)',
284349
'by xxxx-ord.mtasv.net id hp2il427tk41 for <[email protected]>; Fri, 8 Jul 2022 17:44:41 -0400 (envelope-from <[email protected]>)',
285350
];

tls_icon.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class tls_icon extends rcube_plugin
44
{
55
const POSTFIX_TLS_REGEX = "/\(using (TLS(?:[^()]|\([^()]*\))*)\)/im";
6-
const POSTFIX_LOCAL_REGEX = "/\([a-zA-Z]*, from userid [0-9]*\)/im";
6+
const POSTFIX_LOCAL_REGEX = "/\([a-zA-Z]*, from userid [0-9]*\)|\(localhost \[[^]]+\]\)/im";
77
const SENDMAIL_TLS_REGEX = "/\(version=(TLS.*)\)(\s+for|;)/im";
88

99
private $message_headers_done = false;
@@ -68,7 +68,6 @@ public function message_headers($p)
6868
} elseif (preg_match_all(tls_icon::POSTFIX_LOCAL_REGEX, $Received, $items, PREG_PATTERN_ORDER)) {
6969
$this->icon_img .= '<img class="lock_icon" src="plugins/tls_icon/blue_lock.svg" title="' . $this->gettext('internal') . '" />';
7070
} else {
71-
// TODO: Mails received from localhost but without TLS are currently flagged insecure
7271
$this->icon_img .= '<img class="lock_icon" src="plugins/tls_icon/unlock.svg" title="' . $this->gettext('unencrypted') . '" />';
7372
}
7473
}

0 commit comments

Comments
 (0)