Skip to content

Commit

Permalink
Merge pull request #463 from henrique-borba/master
Browse files Browse the repository at this point in the history
Help links in emails (ex.: to unsubscribe from a mailing list) start email from current account
  • Loading branch information
jasonmunro authored Apr 5, 2021
2 parents 9c15b69 + 1100b5a commit 1accf48
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions modules/imap/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,7 @@ function format_list_headers($mod) {
$section = ' '.$mod->html_safe($name).': ';
foreach ($vals['email'] as $v) {
$sources[] = '<a href="?page=compose&compose_to='.urlencode($mod->html_safe($v)).
'&compose_from='.$mod->get('msg_headers')['Delivered-To'].
'">'.$mod->trans('email').'</a>';
}
foreach ($vals['links'] as $v) {
Expand Down
25 changes: 23 additions & 2 deletions modules/smtp/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ public function process() {
*/
class Hm_Handler_process_compose_form_submit extends Hm_Handler_Module {
public function process() {

/* not sending */
if (!array_key_exists('smtp_send', $this->request->post)) {
return;
Expand Down Expand Up @@ -511,6 +510,19 @@ public function process() {
}
}

/**
* Determine if composer_from is set
* @subpackage smtp/handler
*/
class Hm_Handler_smtp_from_replace extends Hm_Handler_Module {
public function process()
{
if (array_key_exists('compose_from', $this->request->get)) {
$this->out('compose_from', $this->request->get['compose_from']);
}
}
}

/**
* Determine if auto-bcc is active
* @subpackage smtp/handler
Expand Down Expand Up @@ -611,6 +623,8 @@ protected function output() {
$html = $this->get('smtp_compose_type', 0);
$msg_path = $this->get('list_path', '');
$msg_uid = $this->get('uid', '');
$from = $this->get('compose_from');

if (!$msg_path) {
$msg_path = $this->get('compose_msg_path', '');
}
Expand Down Expand Up @@ -693,6 +707,13 @@ protected function output() {
foreach ($files as $file) {
$res .= format_attachment_row($file, $this);
}

// If compose_from GET parameter is set, force $recip replacement.
// This ensures any module can force the selected dropdown SMTP server
if ($from) {
$recip = $from;
}

$res .= '</table>'.
smtp_server_dropdown($this->module_output(), $this, $recip, $smtp_id).
'<input class="smtp_send" type="submit" value="'.$this->trans('Send').'" name="smtp_send" '.$send_disabled.'/>'.
Expand Down Expand Up @@ -910,7 +931,7 @@ function smtp_server_dropdown($data, $output_mod, $recip, $selected_id=false) {
if (!$selected && $selected_id !== false && $id == $selected_id) {
$selected = $id;
}
elseif (!$selected && $recip && trim($recip) == trim($vals['user'])) {
if (!$selected && $recip && trim($recip) == trim($vals['user'])) {
$selected = $id;
}
}
Expand Down
2 changes: 2 additions & 0 deletions modules/smtp/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

add_module_to_all_pages('handler', 'smtp_default_server', true, 'smtp', 'load_user_data', 'after');
add_handler('compose', 'load_smtp_reply_to_details', true, 'smtp', 'load_user_data', 'after');
add_handler('compose', 'smtp_from_replace', true, 'smtp', 'load_user_data', 'after');
add_handler('compose', 'load_smtp_servers_from_config', true, 'smtp', 'load_smtp_reply_to_details', 'after');
add_handler('compose', 'add_smtp_servers_to_page_data', true, 'smtp', 'load_smtp_servers_from_config', 'after');
add_handler('compose', 'process_compose_form_submit', true, 'smtp', 'load_smtp_servers_from_config', 'after');
Expand Down Expand Up @@ -97,6 +98,7 @@
'draft_id' => FILTER_VALIDATE_INT,
'compose_to' => FILTER_SANITIZE_STRING,
'mailto_uri' => FILTER_SANITIZE_STRING,
'compose_from' => FILTER_SANITIZE_STRING
),
'allowed_output' => array(
'file_details' => array(FILTER_UNSAFE_RAW, false),
Expand Down

0 comments on commit 1accf48

Please sign in to comment.