diff --git a/imp/lib/Basic/Compose.php b/imp/lib/Basic/Compose.php index 219329d537a..ff096b2b6aa 100644 --- a/imp/lib/Basic/Compose.php +++ b/imp/lib/Basic/Compose.php @@ -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; } @@ -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; } @@ -353,17 +353,14 @@ 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; @@ -371,13 +368,6 @@ protected function _init() 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, @@ -385,7 +375,16 @@ protected function _init() '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']; diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index 291d04cf1db..4dd4dfd472b 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -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, @@ -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': diff --git a/imp/lib/Dynamic/Compose.php b/imp/lib/Dynamic/Compose.php index 49f4c1992e2..0555e81984f 100644 --- a/imp/lib/Dynamic/Compose.php +++ b/imp/lib/Dynamic/Compose.php @@ -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']) { @@ -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); diff --git a/imp/lib/Minimal/Compose.php b/imp/lib/Minimal/Compose.php index 5d30e91d29f..7b92c955c4c 100644 --- a/imp/lib/Minimal/Compose.php +++ b/imp/lib/Minimal/Compose.php @@ -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'); @@ -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'); @@ -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; }