Skip to content

Commit

Permalink
Better handling of errors when creating reply/forward data
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Mar 21, 2014
1 parent 7ef0efb commit 9073db0
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 59 deletions.
33 changes: 16 additions & 17 deletions imp/lib/Basic/Compose.php
Expand Up @@ -209,7 +209,7 @@ protected function _init()
case 'mailto':
try {
$contents = $this->_getContents();
} catch (IMP_Compose_Exception $e) {
} catch (IMP_Exception $e) {
$notification->push($e, 'horde.error');
break;
}
Expand Down Expand Up @@ -289,7 +289,7 @@ protected function _init()
case 'reply_list':
try {
$contents = $this->_getContents();
} catch (IMP_Compose_Exception $e) {
} catch (IMP_Exception $e) {
$notification->push($e, 'horde.error');
break;
}
Expand Down Expand Up @@ -353,39 +353,38 @@ protected function _init()

case 'replyall_revert':
case 'replylist_revert':
if ($contents = $imp_compose->getContentsOb()) {
try {
$reply_msg = $imp_compose->replyMessage(
IMP_Compose::REPLY_SENDER,
$contents
$imp_compose->getContentsOb()
);
$header = $this->_convertToHeader($reply_msg);
} else {
$notification->push(
_("Could not retrieve message data from the mail server."),
'horde.error'
);
} catch (IMP_Exception $e) {
$notification->push($e, 'horde.error');
}
break;

case 'forward_attach':
case 'forward_auto':
case 'forward_body':
case 'forward_both':
try {
$contents = $this->_getContents();
} catch (IMP_Compose_Exception $e) {
$notification->push($e, 'horde.error');
break;
}

$fwd_map = array(
'forward_attach' => IMP_Compose::FORWARD_ATTACH,
'forward_auto' => IMP_Compose::FORWARD_AUTO,
'forward_body' => IMP_Compose::FORWARD_BODY,
'forward_both' => IMP_Compose::FORWARD_BOTH
);

$fwd_msg = $imp_compose->forwardMessage($fwd_map[$this->vars->actionID], $contents);
try {
$fwd_msg = $imp_compose->forwardMessage(
$fwd_map[$this->vars->actionID],
$this->_getContents()
);
} catch (IMP_Exception $e) {
$notification->push($e, 'horde.error');
break;
}

$msg = $fwd_msg['body'];
$header = $this->_convertToHeader($fwd_msg);
$format = $fwd_msg['format'];
Expand Down
14 changes: 14 additions & 0 deletions imp/lib/Compose.php
Expand Up @@ -1780,11 +1780,18 @@ protected function _createMimeMessage(
* - subject: (string) Formatted subject.
* - type: (integer) The reply type used (either self::REPLY_ALL,
* self::REPLY_LIST, or self::REPLY_SENDER).
* @throws IMP_Exception
*/
public function replyMessage($type, $contents, array $opts = array())
{
global $injector, $language, $prefs;

if (!($contents instanceof IMP_Contents)) {
throw new IMP_Exception(
_("Could not retrieve message data from the mail server.")
);
}

$alist = new Horde_Mail_Rfc822_List();
$addr = array(
'to' => clone $alist,
Expand Down Expand Up @@ -2131,12 +2138,19 @@ protected function _msgTextFormat($opts, $pref_name)
* - subject: (string) Formatted subject.
* - title: (string) Title to use on page.
* - type: (integer) - The compose type.
* @throws IMP_Exception
*/
public function forwardMessage($type, $contents, $attach = true,
array $opts = array())
{
global $prefs;

if (!($contents instanceof IMP_Contents)) {
throw new IMP_Exception(
_("Could not retrieve message data from the mail server.")
);
}

if ($type == self::FORWARD_AUTO) {
switch ($prefs->getValue('forward_default')) {
case 'body':
Expand Down
44 changes: 21 additions & 23 deletions imp/lib/Dynamic/Compose.php
Expand Up @@ -84,16 +84,18 @@ protected function _init()
case 'reply_auto':
case 'reply_list':
try {
$contents = $this->_getContents();
} catch (IMP_Compose_Exception $e) {
$result = $imp_compose->replyMessage(
$compose_ajax->reply_map[$this->vars->type],
$this->_getContents(),
array(
'to' => isset($addr['to']) ? $addr['to'] : null
)
);
} catch (IMP_Exception $e) {
$notification->push($e, 'horde.error');
break;
}

$result = $imp_compose->replyMessage($compose_ajax->reply_map[$this->vars->type], $contents, array(
'to' => isset($addr['to']) ? $addr['to'] : null
));

$onload = $compose_ajax->getResponse($result);

switch ($result['type']) {
Expand All @@ -116,26 +118,22 @@ protected function _init()
case 'forward_auto':
case 'forward_body':
case 'forward_both':
if (count($this->indices) > 1) {
if (!in_array($this->vars->type, array('forward_attach', 'forward_auto'))) {
$notification->push(_("Multiple messages can only be forwarded as attachments."), 'horde.warning');
}
try {
if (count($this->indices) > 1) {
if (!in_array($this->vars->type, array('forward_attach', 'forward_auto'))) {
$notification->push(_("Multiple messages can only be forwarded as attachments."), 'horde.warning');
}

try {
$result = $imp_compose->forwardMultipleMessages($this->indices);
} catch (IMP_Compose_Exception $e) {
$notification->push($e, 'horde.error');
break;
}
} else {
try {
$contents = $this->_getContents();
} catch (IMP_Compose_Exception $e) {
$notification->push($e, 'horde.error');
break;
} else {
$result = $imp_compose->forwardMessage(
$compose_ajax->forward_map[$this->vars->type],
$this->_getContents()
);
}

$result = $imp_compose->forwardMessage($compose_ajax->forward_map[$this->vars->type], $contents);
} catch (IMP_Exception $e) {
$notification->push($e, 'horde.error');
break;
}

$onload = $compose_ajax->getResponse($result);
Expand Down
53 changes: 34 additions & 19 deletions imp/lib/Minimal/Compose.php
Expand Up @@ -183,23 +183,26 @@ protected function _init()
case 'r':
case 'ra':
case 'rl':
try {
$imp_contents = $this->_getContents();
} catch (IMP_Exception $e) {
$notification->push($e, 'horde.error');
break;
}

$actions = array(
'r' => IMP_Compose::REPLY_SENDER,
'ra' => IMP_Compose::REPLY_ALL,
'rl' => IMP_Compose::REPLY_LIST
);

$reply_msg = $imp_compose->replyMessage($actions[$this->vars->a], $imp_contents, array(
'format' => 'text',
'to' => $header['to']
));
try {
$reply_msg = $imp_compose->replyMessage(
$actions[$this->vars->a],
$this->_getContents(),
array(
'format' => 'text',
'to' => $header['to']
)
);
} catch (IMP_Exception $e) {
$notification->push($e, 'horde.error');
break;
}

$header = $this->_convertToHeader($reply_msg);

$notification->push(_("Reply text will be automatically appended to your outgoing message."), 'horde.message');
Expand All @@ -209,13 +212,16 @@ protected function _init()
// 'f' = forward
case 'f':
try {
$imp_contents = $this->_getContents();
$fwd_msg = $imp_compose->forwardMessage(
IMP_Compose::FORWARD_ATTACH,
$this->_getContents(),
false
);
} catch (IMP_Exception $e) {
$notification->push($e, 'horde.error');
break;
}

$fwd_msg = $imp_compose->forwardMessage(IMP_Compose::FORWARD_ATTACH, $imp_contents, false);
$header = $this->_convertToHeader($fwd_msg);

$notification->push(_("Forwarded message will be automatically added to your outgoing message."), 'horde.message');
Expand Down Expand Up @@ -264,16 +270,25 @@ protected function _init()

switch ($imp_compose->replyType(true)) {
case IMP_Compose::REPLY:
$reply_msg = $imp_compose->replyMessage(IMP_Compose::REPLY_SENDER, $imp_compose->getContentsOb(), array(
'to' => $f_to
));
$msg = $reply_msg['body'];
try {
$reply_msg = $imp_compose->replyMessage(IMP_Compose::REPLY_SENDER, $imp_compose->getContentsOb(), array(
'to' => $f_to
));
$msg = $reply_msg['body'];
} catch (IMP_Exception $e) {
$notification->push($e, 'horde.error');
$msg = '';
}
$message .= "\n" . $msg;
break;

case IMP_Compose::FORWARD:
$fwd_msg = $imp_compose->forwardMessage(IMP_Compose::FORWARD_ATTACH, $imp_compose->getContentsOb());
$msg = $fwd_msg['body'];
try {
$fwd_msg = $imp_compose->forwardMessage(IMP_Compose::FORWARD_ATTACH, $imp_compose->getContentsOb());
$msg = $fwd_msg['body'];
} catch (IMP_Exception $e) {
$notification->push($e, 'horde.error');
}
$message .= "\n" . $msg;
break;
}
Expand Down

0 comments on commit 9073db0

Please sign in to comment.