Skip to content

Commit

Permalink
repopulate the compose form on a sending error
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmunro committed Mar 17, 2017
1 parent c4c7f66 commit 18895ca
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion modules/smtp/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ public function process() {
$smtp_details = Hm_SMTP_List::dump($form['smtp_server_id'], true);
if (!$smtp_details) {
Hm_Msgs::add('ERRCould not use the selected SMTP server');
repopulate_compose_form($draft, $this);
return;
}

Expand All @@ -460,6 +461,7 @@ public function process() {
$smtp = Hm_SMTP_List::connect($form['smtp_server_id'], false);
if (!$smtp || $smtp->state != 'authed') {
Hm_Msgs::add("ERRFailed to authenticate to the SMTP server");
repopulate_compose_form($draft, $this);
return;
}

Expand All @@ -474,13 +476,15 @@ public function process() {
$recipients = $mime->get_recipient_addresses();
if (empty($recipients)) {
Hm_Msgs::add("ERRNo valid receipts found");
repopulate_compose_form($draft, $this);
return;
}

/* send the message */
$err_msg = $smtp->send_message($from, $recipients, $mime->get_mime_msg());
$err_msg = 'test'; //$smtp->send_message($from, $recipients, $mime->get_mime_msg());
if ($err_msg) {
Hm_Msgs::add(sprintf("ERR%s", $err_msg));
repopulate_compose_form($draft, $this);
return;
}

Expand Down Expand Up @@ -606,6 +610,12 @@ protected function output() {
$html = $this->get('smtp_compose_type', 0);
$msg_path = $this->get('list_path', '');
$msg_uid = $this->get('uid', '');
if (!$msg_path) {
$msg_path = $this->get('compose_msg_path', '');
}
if (!$msg_uid) {
$msg_uid = $this->get('compose_msg_uid', '');
}
$smtp_id = false;
$draft_id = $this->get('compose_draft_id', 0);
if (!empty($reply)) {
Expand Down Expand Up @@ -1169,3 +1179,19 @@ function outbound_address_check($mod, $from, $reply_to) {
return array($from, $reply_to);
}

/**
* @subpackage smtp/functions
*/
function repopulate_compose_form($draft, $handler_mod) {
$handler_mod->out('no_redirect', true);
$handler_mod->out('compose_draft', $draft);
if (array_key_exists('compose_msg_path', $handler_mod->request->post)
&& $handler_mod->request->post['compose_msg_path']) {
$handler_mod->out('compose_msg_path', $handler_mod->request->post['compose_msg_path']);
}
if (array_key_exists('compose_msg_uid', $handler_mod->request->post)
&& $handler_mod->request->post['compose_msg_uid']) {
$handler_mod->out('compose_msg_uid', $handler_mod->request->post['compose_msg_uid']);
}
}

0 comments on commit 18895ca

Please sign in to comment.