try {
$notification->push($imp_compose->saveDraft($header, $message, Horde_Nls::getCharset(), false), 'horde.success');
if ($prefs->getValue('close_draft')) {
- $imp_compose->destroy();
+ $imp_compose->destroy('save_draft');
require IMP_BASE . '/mailbox-mimp.php';
exit;
}
try {
if ($imp_compose->buildAndSendMessage($message, $header, Horde_Nls::getEmailCharset(), false, $options)) {
- $imp_compose->destroy();
+ $imp_compose->destroy('send');
$notification->push(_("Message sent successfully."), 'horde.success');
require IMP_BASE . '/mailbox-mimp.php';
break;
case _("Cancel"):
- $imp_compose->destroy(false);
+ $imp_compose->destroy('cancel');
require IMP_BASE . '/mailbox-mimp.php';
exit;
}
try {
$imp_ui->redirectMessage($f_to, $imp_compose, $imp_contents);
- $imp_compose->destroy();
+ $imp_compose->destroy('send');
if ($isPopup) {
if ($prefs->getValue('compose_confirm')) {
$notification->push(_("Message redirected successfully."), 'horde.success');
if ($vars->actionID == 'save_draft') {
if ($isPopup) {
if ($prefs->getValue('close_draft')) {
- $imp_compose->destroy();
+ $imp_compose->destroy('save_draft');
echo Horde::wrapInlineScript(array('window.close();'));
exit;
} else {
} else {
$notification->push($result, 'horde.success');
if ($prefs->getValue('close_draft')) {
- $imp_compose->destroy();
+ $imp_compose->destroy('save_draft');
header('Location: ' . $imp_ui->mailboxReturnUrl(false));
exit;
}
try {
$sent = $imp_compose->buildAndSendMessage($message, $header, $charset, $rtemode, $options);
- $imp_compose->destroy();
+ $imp_compose->destroy('send');
} catch (IMP_Compose_Exception $e) {
$get_sig = false;
$code = $e->getCode();
break;
case 'cancel_compose':
- $imp_compose->destroy(false);
+ $imp_compose->destroy('cancel');
if ($isPopup) {
echo Horde::wrapInlineScript(array('window.close();'));
} else {
public function cancelCompose()
{
$imp_compose = IMP_Compose::singleton($this->_vars->imp_compose);
- $imp_compose->destroy(false);
+ $imp_compose->destroy('cancel');
return true;
}
*/
public function deleteDraft()
{
- $imp_compose = IMP_Compose::singleton($this->_vars->imp_compose);
- $imp_compose->destroy(false);
-
- if ($draft_uid = $imp_compose->getMetadata('draft_uid')) {
- $idx_array = array($draft_uid . IMP::IDX_SEP . IMP::folderPref($GLOBALS['prefs']->getValue('drafts_folder'), true));
- $GLOBALS['injector']->getInstance('IMP_Message')->delete($idx_array, array('nuke' => true));
- }
-
+ IMP_Compose::singleton($this->_vars->imp_compose)->destroy('cancel');
return true;
}
}
}
- $imp_compose->destroy();
+ $imp_compose->destroy('send');
$result->mailbox = $this->_getMailboxResponse($imptree);
} else {
$GLOBALS['notification']->push($res);
if ($GLOBALS['prefs']->getValue('close_draft')) {
- $imp_compose->destroy();
+ $imp_compose->destroy('save_draft');
}
}
} catch (IMP_Compose_Exception $e) {
/**
* Destroys an IMP_Compose instance.
*
- * @param boolean $success Was the message sent successfully?
+ * @param string $action The action performed to cause the end of this
+ * instance. Either 'cancel', 'save_draft', or
+ * 'send'.
*/
- public function destroy($success = true)
+ public function destroy($action)
{
- /* Delete draft if we were auto saving and this wasn't a resume
- * draft request, -or- if this was a resume draft request,
- * auto_delete_drafts was true, and we successfully sent the
- * message. */
- if ((($GLOBALS['prefs']->getValue('auto_save_drafts') &&
- !$this->getMetadata('resume')) ||
- ($success && $GLOBALS['prefs']->getValue('auto_delete_drafts'))) &&
- ($uid = $this->getMetadata('draft_uid'))) {
- $GLOBALS['injector']->getInstance('IMP_Message')->delete(array($uid . IMP::IDX_SEP . IMP::folderPref($GLOBALS['prefs']->getValue('drafts_folder'), true)), array('nuke' => true));
+ $uids = array();
+
+ switch ($action) {
+ case 'save_draft':
+ /* Don't delete any drafts. */
+ break;
+
+ case 'send':
+ /* Delete the auto-draft and the original resumed draft. */
+ $uids[] = $this->getMetadata('draft_uid_resume');
+ // Fall-through
+
+ case 'cancel':
+ /* Delete the auto-draft, but save the original resume draft. */
+ $uids[] = $this->getMetadata('draft_uid');
+ $uids = array_filter($uids);
+ break;
+ }
+
+ if (!empty($uids)) {
+ $GLOBALS['injector']->getInstance('IMP_Message')->delete($uids, array('nuke' => true));
}
$this->deleteAllAttachments();
/* Get the message ID. */
$headers = Horde_Mime_Headers::parseHeaders($data);
+ $drafts_mbox = IMP::folderPref($GLOBALS['prefs']->getValue('drafts_folder'), true);
+ $old_uid = $this->getMetadata('draft_uid');
+
/* Add the message to the mailbox. */
try {
- $old_uid = $this->getMetadata('autodraft')
- ? $this->getMetadata('draft_uid')
- : null;
-
$ids = $GLOBALS['imp_imap']->ob()->append($drafts_mbox, array(array('data' => $data, 'flags' => $append_flags, 'messageid' => $headers->getValue('message-id'))));
if ($old_uid) {
- $idx_array = array($old_uid . IMP::IDX_SEP . IMP::folderPref($GLOBALS['prefs']->getValue('drafts_folder'), true));
- $GLOBALS['injector']->getInstance('IMP_Message')->delete($idx_array, array('nuke' => true));
+ $GLOBALS['injector']->getInstance('IMP_Message')->delete(array($old_uid), array('nuke' => true));
}
- $this->_metadata['draft_uid'] = reset($ids);
- $this->_metadata['autodraft'] = true;
+ $this->_metadata['draft_uid'] = reset($ids) . IMP::IDX_SEP . $drafts_mbox;
$this->_modified = true;
return sprintf(_("The draft has been saved to the \"%s\" folder."), IMP::displayFolder($drafts_mbox));
} catch (Horde_Imap_Client_Exception $e) {
- unset($this->_metadata['draft_uid']);
- $this->_modified = true;
return _("The draft was not successfully saved.");
}
}
} catch (Horde_Exception $e) {}
}
- list($this->_metadata['draft_uid'],) = explode(IMP::IDX_SEP, $uid);
- $this->_metadata['resume'] = 1;
+ $this->_metadata['draft_uid_resume'] = $uid;
$this->_modified = true;
return array(