Add checkbox interface to mailbox page for advanced mobile browsers (MIMP)
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 16 Mar 2010 02:11:18 +0000 (20:11 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 16 Mar 2010 02:17:44 +0000 (20:17 -0600)
imp/config/hooks.php.dist
imp/docs/CHANGES
imp/lib/Ui/Mimp.php
imp/mailbox-mimp.php
imp/message-mimp.php
imp/templates/mailbox/mailbox-mimp.html

index 7b5b64c..b5de25f 100644 (file)
@@ -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:
+     * <pre>
+     * 'checkbox' - Adds a checkbox interface to selecting messages on the
+     *              mailbox listing page.
+     * </pre>
+     *
+     * @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;
+//     }
+
 }
index e096bcd..89483b0 100644 (file)
@@ -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.
index b5882eb..ed9388b 100644 (file)
@@ -53,4 +53,33 @@ class IMP_Ui_Mimp
         return $out . '</ol>';
     }
 
+    /**
+     * [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;
+    }
+
 }
index 3237875..092a6d7 100644 (file)
@@ -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');
index 211193b..20b5684 100644 (file)
@@ -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) {
index 776c4a0..0356fc8 100644 (file)
@@ -1,14 +1,25 @@
   <div><tag:title /></div>
   <hr />
+<if:checkbox>
+  <form action="<tag:checkbox />" method="post">
+  <input type="hidden" name="mt" value="<tag:mt />" />
+  <tag:forminput />
+</if:checkbox>
 <if:msgs>
   <table>
    <tr>
+<if:checkbox>
+    <th></th>
+</if:checkbox>
     <th><tag:hdr_arrival /></th>
     <th><tag:hdr_from /></th>
     <th><tag:hdr_subject /><if:hdr_subject_minor> <small>[<tag:hdr_subject_minor />]</small></if:hdr_subject_minor></th>
    </tr>
 <loop:msgs>
    <tr>
+<if:checkbox>
+    <td><input type="checkbox" name="indices[]" value="<tag:msgs.uid />" /></td>
+</if:checkbox>
     <td><tag:msgs.status /></td>
     <td><tag:msgs.from /></td>
     <td><tag:msgs.thread /> <a href="<tag:msgs.target />"><tag:msgs.subject /></a></td>
 <div><gettext>No messages.</gettext></div>
 </else:msgs></if:msgs>
   <hr />
+<if:checkbox>
+  <div>
+   <select name="checkbox">
+    <option value="" selected="selected"><gettext>Action:</gettext></option>
+    <option value="d">&nbsp;<gettext>Delete</gettext></option>
+    <option value="u">&nbsp;<gettext>Undelete</gettext></option>
+    <option value="s">&nbsp;<gettext>Report As Spam</gettext></option>
+    <option value="i">&nbsp;<gettext>Report As Innocent</gettext></option>
+   </select>
+   <input type="submit" value="<gettext>Do Action</gettext>" />
+  </div>
+  </form>
+  <hr />
+</if:checkbox>
   <div><gettext>Menu</gettext></div>
   <tag:menu />
  </body>