[imp] Suggestion and how-to: adding

Matias Pelenur imp at matiaspelenur.com
Mon Jun 21 16:08:49 PDT 2004


Hi,
I noticed that GMail (Google mail) has a pretty useful "feature": the
page title is for example "Gmail (4)", where 4 is the number of unread
messages. This lets you see at a glance if you have new messages, even
without looking at the actual page (or tab on FireFox/Mozilla), since
the page refreshes every few minutes.

I modified my IMP 3.2.4 installation to provide the same functionality,
although it reports only the unseen message count in the page you are
looking at (as opposed to all unread messages on the mailbox). You also
have to have refresh enabled in the Preferences.

To do this, in imp/mailbox.php I added a variable $unseenCount, which
gets incremented for each message marked "unseen", and then is used to
modify the $title variable. I also added a line to common-footer.inc to
set the title even if the page is not in a frame.

This may certainly not be the best way to do it, but it was quick and
easy and maybe it can be implemented properly in future versions of IMP.

Here's a unified diff against mailbox.php v2.296.2.62

--------------start
--- mailbox.php 2004/06/21 22:15:55     2.296.2.62
+++ mailbox.php 2004/06/21 22:39:26    
@@ -645,6 +645,7 @@
 ksort($mailboxOverview);

 // Display message information.
+$unseenCount = 0;
 $curr_time = time();
 $curr_time -= ($curr_time % 60);
 foreach ($mailboxOverview as $key => $message) {
@@ -796,6 +797,7 @@
             $status .= $conf['mailbox']['unseen_flag'];
             $style[] = $conf['mailbox']['unseen_style'];
             $bg = 'unseen';
+            $unseenCount++;
         }
         if ($h->answered) {
             $flagbits |= IMP_ANSWERED;
@@ -861,6 +863,8 @@
     include IMP_TEMPLATES . '/mailbox/message_summaries.inc';
 }

+if ($unseenCount > 0) { $title .= " (" . $unseenCount . ")"; }
+
 if ($end == 0) {
     if ($imp['mailbox'] == '**search') {
         include IMP_TEMPLATES . '/mailbox/message_headers.inc';
--------------end

And then in common-footer.inc I added a line to set the document title
even if the page is not in the frame. It's easier than adding it to the
header since we don't have the count until after we use
common-header.inc. Here's the modified
common-footer.inc:

--------------start
<?php if (!empty($title)): ?>
<script language="JavaScript" type="text/javascript">
<!--
var title='<?php echo addslashes($registry->getParam('name') . ' :: ' .
$title) ?>'
if (parent.frames.horde_main) parent.document.title = title;
else document.title = title;
//-->
</script>
<?php endif; ?>
</body>
</html>
--------------end

Hope this helps those who like me keep switching compulsively to their
IMP page/tab to see every 5 minutes to see if they've gotten new mail.

--Matias
PS: please CC any replies to this address since I'm not subscribed to
the IMP list



More information about the imp mailing list