Skip to content

Commit e6b53a8

Browse files
authored
Merge pull request #1754 from mercihabam/fix-dsn
fix(frontend/backend): some servers do not support delivery status notification, so show a notice to users so that they don't expect any delivery receipt
2 parents d8c903a + 28769d8 commit e6b53a8

File tree

5 files changed

+52
-5
lines changed

5 files changed

+52
-5
lines changed

modules/smtp/hm-smtp.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class Hm_SMTP {
8989
private $scramAuthenticator;
9090
private $supports_tls;
9191
private $supports_auth;
92+
private $supports_dsn;
9293
private $max_message_size;
9394

9495
function __construct($conf) {
@@ -250,6 +251,9 @@ function capabilities($ehlo_response) {
250251
$auth_mecs = array_slice($line[1], 1);
251252
$this->supports_auth = array_map(function($v) { return mb_strtolower($v); }, $auth_mecs);
252253
break;
254+
case 'dsn': // supports delivery status notifications
255+
$this->supports_dsn = true;
256+
break;
253257
case 'size': // advisary maximum message size
254258
if(isset($line[1][1]) && is_numeric($line[1][1])) {
255259
$this->max_message_size = $line[1][1];
@@ -634,6 +638,10 @@ function send_message($from, $recipients, $message, $from_params = '', $recipien
634638
return $result;
635639
}
636640

641+
function supports_dsn() {
642+
return $this->supports_dsn;
643+
}
644+
637645
function puke() {
638646
return
639647
print_r($this->debug, true).

modules/smtp/js_modules/route_handlers.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,25 @@ function applySmtpComposePageHandlers() {
217217
$('textarea[name="compose_body"]').focus();
218218
}
219219
}
220+
221+
const getSmtpProfileCallback = (res) => {
222+
const deliveryReceiptCheckBox = $('#compose_delivery_receipt');
223+
if (! res.dsn_supported) {
224+
deliveryReceiptCheckBox.prop('checked', false);
225+
deliveryReceiptCheckBox.prop('disabled', true);
226+
deliveryReceiptCheckBox.next('label').after('<span class="badge bg-warning text-dark ms-2">Not supported by the selected SMTP server</span>');
227+
} else {
228+
deliveryReceiptCheckBox.prop('disabled', false);
229+
deliveryReceiptCheckBox.prop('checked', true);
230+
deliveryReceiptCheckBox.next('label').next('span.badge').remove();
231+
}
232+
};
233+
220234
if ($('.sys_messages').text() != 'Message Sent') {
221-
get_smtp_profile($('.compose_server').val());
235+
get_smtp_profile($('.compose_server').val(), getSmtpProfileCallback);
222236
}
223237
$('.compose_server').on('change', function() {
224-
get_smtp_profile($('.compose_server').val());
238+
get_smtp_profile($('.compose_server').val(), getSmtpProfileCallback);
225239
});
226240
if($('.compose_attach_button').attr('disabled') == 'disabled'){
227241
check_attachment_dir_access();

modules/smtp/modules.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,27 @@ public function process() {
564564
}
565565
}
566566

567+
class Hm_Handler_smtp_supports_dsn extends Hm_Handler_Module {
568+
public function process() {
569+
if (! $this->user_config->get('enable_compose_delivery_receipt_setting')) {
570+
return;
571+
}
572+
573+
Hm_SMTP_List::init($this->user_config, $this->session);
574+
575+
$smtp_id = server_from_compose_smtp_id($this->request->post['compose_smtp_id']);
576+
$smtp_details = Hm_SMTP_List::dump($smtp_id, true);
577+
$mailbox = Hm_SMTP_List::connect($smtp_id, false, $smtp_details['user'], $smtp_details['pass']);
578+
if (! $mailbox || ! $mailbox->authed()) {
579+
Hm_Msgs::add("Failed to determine Delivery Status Notification. The server refused connection. user is: ".$smtp_details['user'], "danger");
580+
$this->out('dsn_supported', false);
581+
return;
582+
}
583+
584+
$this->out('dsn_supported', $mailbox->get_connection()->supports_dsn());
585+
}
586+
}
587+
567588
if (!hm_exists('get_mime_type')) {
568589
function get_mime_type($filename)
569590
{
@@ -1193,7 +1214,7 @@ protected function output() {
11931214
(!$html ? '<label for="compose_body">'.$this->trans('Message').'</label>': '').
11941215
'</div>';
11951216
if($this->get('enable_compose_delivery_receipt_setting')) {
1196-
$res .= '<div class="form-check mb-3"><input value="1" name="compose_delivery_receipt" id="compose_delivery_receipt" type="checkbox" class="form-check-input" checked/><label for="compose_delivery_receipt" class="form-check-label">'.$this->trans('Request a delivery receipt').'</label></div>';
1217+
$res .= '<div class="form-check mb-3"><input value="1" name="compose_delivery_receipt" disabled id="compose_delivery_receipt" type="checkbox" class="form-check-input" checked/><label for="compose_delivery_receipt" class="form-check-label">'.$this->trans('Request a delivery receipt').'</label></div>';
11971218
}
11981219
if ($html == 2) {
11991220
$res .= '<link href="'.WEB_ROOT.'modules/smtp/assets/markdown/editor.css" rel="stylesheet" />'.

modules/smtp/setup.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
setup_base_ajax_page('ajax_profiles_status', 'core');
9797
add_handler('ajax_profiles_status', 'load_imap_servers_from_config', true, 'imap', 'load_user_data', 'after');
9898
add_handler('ajax_profiles_status', 'profile_status', true, 'smtp', 'load_imap_servers_from_config', 'after');
99+
add_handler('ajax_profiles_status', 'smtp_supports_dsn', true, 'smtp', 'profile_status', 'after');
99100

100101
/* resumable clear chunks */
101102
add_handler('ajax_clear_attachment_chunks', 'login', false, 'core');
@@ -164,6 +165,7 @@
164165
'sent_msg_id' => array(FILTER_VALIDATE_BOOLEAN, false),
165166
'enable_attachment_reminder' => array(FILTER_VALIDATE_BOOLEAN, false),
166167
'scheduled_msg_count' => array(FILTER_VALIDATE_INT, false),
168+
'dsn_supported' => array(FILTER_VALIDATE_BOOLEAN, false),
167169
),
168170
'allowed_post' => array(
169171
'post_archive' => FILTER_VALIDATE_INT,

modules/smtp/site.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
'use strict';
22

3-
var get_smtp_profile = function(profile_value) {
3+
var get_smtp_profile = function(profile_value, callback) {
44
if (typeof profile_value === "undefined" || profile_value == "0" || profile_value == "") {
55
Hm_Notices.show('Please create a profile for saving sent messages option', 'warning');
66
}
77
else {
88
Hm_Ajax.request(
99
[{'name': 'hm_ajax_hook', 'value': 'ajax_profiles_status'},
10-
{'name': 'profile_value', 'value': profile_value}],
10+
{'name': 'profile_value', 'value': profile_value},
11+
{'name': 'compose_smtp_id', 'value': profile_value}],
1112
function(res) {
13+
callback(res);
1214
}
1315
);
1416
}

0 commit comments

Comments
 (0)