Skip to content

Commit

Permalink
Merge pull request #5 from williamdes/improvements
Browse files Browse the repository at this point in the history
Minor project improvements
  • Loading branch information
GermanCoding authored Jul 8, 2022
2 parents f2be525 + 2b449df commit e51fd27
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.gitignore export-ignore
.gitattributes export-ignore
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor
/composer.lock
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
Displays a small icon after the subject line that displays the (presumed) encryption state of received mails.
This plugin parses the "Received" header for the last hop and checks if TLS was used. This requires TLS logging in the receiving MTA.

In Postfix this can be enabled by setting `smtpd_tls_received_header = yes`. The regex used to parse the header has only been tested against Postfix.
In Postfix this can be enabled by setting [`smtpd_tls_received_header = yes`](https://www.postfix.org/postconf.5.html#smtpd_tls_received_header). The regex used to parse the header has only been tested against Postfix.

Note that while this talks about "encryption", this does not imply security. An encrypted mail may still be insecure, mostly because mailservers generally use "opportunistic TLS", where MITM attacks are possible.
This also only validates the last hop of an email - some emails may run through multiple hops and we don't know anything about the security of these.

Inspired by https://github.com/SS88UK/roundcube-easy-unsubscribe
Inspired by [roundcube-easy-unsubscribe](https://github.com/SS88UK/roundcube-easy-unsubscribe)

![Example screenshot](tls_icon_example.png)
![Example screenshot](tls_icon_example.png)

## Installation

The [composer library](https://packagist.org/packages/germancoding/tls_icon) name is: `germancoding/tls_icon`.

The plugin name to add to your config file is: `tls_icon`.
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@
],
"require": {
"roundcube/plugin-installer": ">=0.1.6"
},
"config": {
"allow-plugins": {
"roundcube/plugin-installer": true
}
}
}
}
6 changes: 6 additions & 0 deletions localization/fr_FR.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

$labels = array();

$labels['internal'] = 'Cet e-mail est interne';
$labels['unencrypted'] = 'E-mail reçu via une connexion non chiffrée !';
16 changes: 8 additions & 8 deletions tls_icon.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

class tls_icon extends rcube_plugin
{
{
private $message_headers_done = false;
private $icon_img;
private $rcmail;
Expand All @@ -13,12 +13,12 @@ function init()

$this->add_hook('message_headers_output', array($this, 'message_headers'));
$this->add_hook('storage_init', array($this, 'storage_init'));

$this->include_stylesheet('tls_icon.css');

$this->add_texts('localization/');
}

function get_received_header_content($Received_Header)
{
$Received = null;
Expand All @@ -41,7 +41,7 @@ public function storage_init($p)
$p['fetch_headers'] = trim(($p['fetch_headers']?? '') . ' ' . strtoupper('Received'));
return $p;
}

public function message_headers($p)
{
if($this->message_headers_done===false)
Expand All @@ -50,12 +50,12 @@ public function message_headers($p)

$Received_Header = $p['headers']->others['received'] ?? null;
$Received = $this->get_received_header_content($Received_Header);

if($Received == null) {
// There was no Received Header. Possibly an outbound mail. Do nothing.
return $p;
}

if ( preg_match_all('/\(using TLS.*.*\) \(/im', $Received, $items, PREG_PATTERN_ORDER) ) {
$data = $items[0][0];

Expand All @@ -66,11 +66,11 @@ public function message_headers($p)
$needle = ") (";
$pos = strrpos($data, $needle);
$data = substr_replace($data, "", $pos, strlen($needle));

$this->icon_img .= '<img class="lock_icon" src="plugins/tls_icon/lock.svg" title="'. htmlentities($data) .'" />';
} else if(preg_match_all('/\([a-zA-Z]*, from userid [0-9]*\)/im', $Received, $items, PREG_PATTERN_ORDER)){
$this->icon_img .= '<img class="lock_icon" src="plugins/tls_icon/blue_lock.svg" title="' . $this->gettext('internal') . '" />';
}
}
else {
// TODO: Mails received from localhost but without TLS are currently flagged insecure
$this->icon_img .= '<img class="lock_icon" src="plugins/tls_icon/unlock.svg" title="' . $this->gettext('unencrypted') . '" />';
Expand Down

0 comments on commit e51fd27

Please sign in to comment.