From f79f4a520cbf7286a6fa0f6ba9f6fdf994b7d178 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 15 Mar 2010 20:11:18 -0600 Subject: [PATCH] Add checkbox interface to mailbox page for advanced mobile browsers (MIMP) --- imp/config/hooks.php.dist | 33 +++++++++++++++++++++++ imp/docs/CHANGES | 2 ++ imp/lib/Ui/Mimp.php | 29 +++++++++++++++++++++ imp/mailbox-mimp.php | 46 +++++++++++++++++++++++++++++++-- imp/message-mimp.php | 25 ++++++++---------- imp/templates/mailbox/mailbox-mimp.html | 25 ++++++++++++++++++ 6 files changed, 144 insertions(+), 16 deletions(-) diff --git a/imp/config/hooks.php.dist b/imp/config/hooks.php.dist index 7b5b64c5e..b5de25f38 100644 --- a/imp/config/hooks.php.dist +++ b/imp/config/hooks.php.dist @@ -745,4 +745,37 @@ class IMP_Hooks // return empty($ob['personal']) ? $ob['address'] : $ob['personal']; // } + + /** + * MIMP: Activate various advanced features in the minimal view. + * + * The combination of the rapid pace of development for both mobile + * devices and their browsers, coupled with the limited resources of an + * open source project to test and track these developments, make it + * near impossible to accurately identify a list of mobile browsers + * that can handle a interface with more features than the base + * minimal view. Therefore, this hook provides a wait for a site + * administrator to best decide when (and if) they want to allow this + * advanced functionality to be available in the minimal view. + * + * @param string $feature The advanced feature. One of the following: + *
+     * 'checkbox' - Adds a checkbox interface to selecting messages on the
+     *              mailbox listing page.
+     * 
+ * + * @return boolean If true, activates the feature. By default, these + * advanced features are NOT active. + */ +// function mimp_advanced($feature) +// { +// switch ($feature) { +// case 'checkbox': +// // Activate the mailbox checkbox interface. +// return true; +// } +// +// return false; +// } + } diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index e096bcda1..89483b052 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -2,6 +2,8 @@ v5.0-git -------- +[mms] Add checkbox interface to mailbox page for advanced mobile browsers + (MIMP). [mms] Add preference to allow viewing of all inline parts by default (MIMP). [mms] Add hook to alter composed message details before sending. [mms] DIMP now honors the 'allow_resume_all' configuration option. diff --git a/imp/lib/Ui/Mimp.php b/imp/lib/Ui/Mimp.php index b5882ebe3..ed9388b13 100644 --- a/imp/lib/Ui/Mimp.php +++ b/imp/lib/Ui/Mimp.php @@ -53,4 +53,33 @@ class IMP_Ui_Mimp return $out . ''; } + /** + * [Un]Delete message(s). + * + * @param string $action Either 'delete' or 'undelete'. + * @param mixed $uids See IMP::parseIndicesList(). + * @param string $token Mailbox action token. + * + * @return boolean True if messages were removed from the mailbox. + */ + public function delete($action, $uids, $token) + { + switch ($action) { + case 'delete': + try { + Horde::checkRequestToken('imp.message-mimp', $token); + return (bool)$GLOBALS['injector']->getInstance('IMP_Message')->delete($uids); + } catch (Horde_Exception $e) { + $GLOBALS['notification']->push($e); + } + break; + + case 'undelete': + $imp_message->undelete($uids); + break; + } + + return false; + } + } diff --git a/imp/mailbox-mimp.php b/imp/mailbox-mimp.php index 323787567..092a6d707 100644 --- a/imp/mailbox-mimp.php +++ b/imp/mailbox-mimp.php @@ -37,6 +37,38 @@ $readonly = $imp_imap->isReadOnly($imp_mbox['mailbox']); /* Get the base URL for this page. */ $mailbox_url = IMP::generateIMPUrl('mailbox-mimp.php', $imp_mbox['mailbox']); +/* Perform message actions (via advanced UI). */ +switch ($vars->checkbox) { +// 'd' = delete message +// 'u' = undelete message +case 'd': +case 'u': + if ($readonly) { + break; + } + + $imp_message = $injector->getInstance('IMP_Message'); + + if ($vars->checkbox == 'd') { + try { + Horde::checkRequestToken('imp.message-mimp', $vars->mt); + $imp_message->delete($vars->indices); + } catch (Horde_Exception $e) { + $notification->push($e); + } + } else { + $imp_message->undelete($vars->indices); + } + break; + +// 'rs' = report spam +// 'ri' = report innocent +case 'rs': +case 'ri': + IMP_Spam::reportSpam($vars->indices, $vars->a == 'rs' ? 'spam' : 'innocent'); + break; +} + /* Run through the action handlers */ switch ($vars->a) { // 'm' = message missing @@ -131,7 +163,8 @@ while (list(,$ob) = each($mbox_info['overview'])) { /* Initialize the header fields. */ $msg = array( 'status' => '', - 'subject' => trim($imp_ui->getSubject($ob['envelope']['subject'])) + 'subject' => trim($imp_ui->getSubject($ob['envelope']['subject'])), + 'uid' => $ob['uid'] . IMP::IDX_SEP . $ob['mailbox'] ); /* Format the from header. */ @@ -163,7 +196,7 @@ while (list(,$ob) = each($mbox_info['overview'])) { /* Generate the target link. */ $msg['target'] = in_array('\\draft', $ob['flags']) ? IMP::composeLink(array(), array('a' => 'd', 'thismailbox' => $imp_mbox['mailbox'], 'uid' => $ob['uid'], 'bodypart' => 1)) - : IMP::generateIMPUrl('message-mimp.php', $imp_mbox['mailbox'], $ob['uid'], $ob['mailbox']); + : IMP::generateIMPUrl('message-mimp.php', $imp_mbox['mailbox'], $ob['uid'], $ob['mailbox']); $msgs[] = $msg; } @@ -228,6 +261,15 @@ if ($pageOb['page'] != $pageOb['pagecount']) { $t->set('menu', $imp_ui_mimp->getMenu('mailbox', $menu)); +/* Activate advanced checkbox UI? */ +try { + if (Horde::callHook('mimp_advanced', array('checkbox'), 'imp')) { + $t->set('checkbox', $mailbox_url->copy()->add('p', $pageOb['page'])); + $t->set('forminput', Horde_Util::formInput()); + $t->set('mt', Horde::getRequestToken('imp.message-mimp')); + } +} catch (Horde_Exception_HookNotSet $e) {} + require_once IMP_TEMPLATES . '/common-header.inc'; IMP::status(); echo $t->fetch(IMP_TEMPLATES . '/mailbox/mailbox-mimp.html'); diff --git a/imp/message-mimp.php b/imp/message-mimp.php index 211193ba8..20b568471 100644 --- a/imp/message-mimp.php +++ b/imp/message-mimp.php @@ -31,13 +31,12 @@ if (!$imp_mailbox->isValidIndex(false)) { exit; } -$imp_message = $injector->getInstance('IMP_Message'); +$readonly = $imp_imap->isReadOnly($imp_mbox['mailbox']); + +$imp_mimp = $injector->getInstance('IMP_Ui_Mimp'); $imp_hdr_ui = new IMP_Ui_Headers(); $imp_ui = new IMP_Ui_Message(); -/* Determine if mailbox is readonly. */ -$readonly = $imp_imap->isReadOnly($imp_mbox['mailbox']); - /* Run through action handlers */ $msg_delete = false; switch ($vars->a) { @@ -48,21 +47,19 @@ case 'u': if ($readonly) { break; } + $index_ob = $imp_mailbox->getIMAPIndex(); + $index_array = array($index_ob['mailbox'] => array($index_ob['uid'])); + $imp_message = $injector->getInstance('IMP_Message'); - /* Get mailbox/UID of message. */ - $index_array = $imp_mailbox->getIMAPIndex(); - $indices_array = array($index_array['mailbox'] => array($index_array['uid'])); - - if ($vars->a == 'u') { - $imp_message->undelete($indices_array); - } else { + if ($vars->a == 'd') { try { Horde::checkRequestToken('imp.message-mimp', $vars->mt); - $imp_message->delete($indices_array); - $msg_delete = false; + $msg_delete = (bool)$imp_message->delete($index_array); } catch (Horde_Exception $e) { $notification->push($e); } + } else { + $imp_message->undelete($index_array); } break; @@ -308,7 +305,7 @@ if ($conf['notspam']['reporting'] && $menu[] = array(_("Report as Innocent"), $self_link->copy()->add(array('a' => 'ri', 'mt' => Horde::getRequestToken('imp.message-mimp')))); } -$t->set('menu', $injector->getInstance('IMP_Ui_Mimp')->getMenu('message', $menu)); +$t->set('menu', $imp_mimp->getMenu('message', $menu)); $hdrs = array(); foreach ($display_headers as $head => $val) { diff --git a/imp/templates/mailbox/mailbox-mimp.html b/imp/templates/mailbox/mailbox-mimp.html index 776c4a0c1..0356fc83a 100644 --- a/imp/templates/mailbox/mailbox-mimp.html +++ b/imp/templates/mailbox/mailbox-mimp.html @@ -1,14 +1,25 @@

+ +
+ + + + + + + + + @@ -19,6 +30,20 @@
No messages.

+ +
+ + +
+ +
+
Menu
-- 2.11.0
[]