Included newmail for officialization 8)
authorphilippe_mingo <philippe_mingo@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 15 Nov 2001 15:57:11 +0000 (15:57 +0000)
committerphilippe_mingo <philippe_mingo@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 15 Nov 2001 15:57:11 +0000 (15:57 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@1761 7612ce4b-ef26-0410-bec9-ea0150e637f0

plugins/newmail/HISTORY [new file with mode: 0644]
plugins/newmail/README [new file with mode: 0644]
plugins/newmail/newmail.php [new file with mode: 0644]
plugins/newmail/newmail_opt.php [new file with mode: 0644]
plugins/newmail/setup.php [new file with mode: 0644]
plugins/newmail/sounds/FanFair.wav [new file with mode: 0644]
plugins/newmail/sounds/Friends.wav [new file with mode: 0644]
plugins/newmail/sounds/MontyPython.wav [new file with mode: 0644]
plugins/newmail/sounds/Notify.wav [new file with mode: 0644]
plugins/newmail/testsound.php [new file with mode: 0644]

diff --git a/plugins/newmail/HISTORY b/plugins/newmail/HISTORY
new file mode 100644 (file)
index 0000000..70c4bf0
--- /dev/null
@@ -0,0 +1,72 @@
+This is the history for the newmail plugin in SquirrelMail.  Currently
+works with the 1.1.2+ versions of SquirrelMail.
+
+2.1
+
+Fixes bug in when used with the 1.1.3 distro 
+
+
+
+2.0
+
+Adds a "try" sounds option to the Newmail plugins works with 1.1.2
+
+
+
+
+1.4
+
+Tyler Akins cleaned up the javascript and now it can change the title
+bar's text if you have new mail.  Additionally, this now correctly
+uses the new 1.1.1 validate.php format.  Uses the new
+sqimap_unseen_messages() format in 1.1.2.
+
+1.3a
+
+Hm. Apparently the Sent box is being used to indicate new mail when
+checking all folders.  Disabled this.  Ditto for the Trash folder
+as well.
+
+Changed the plugin name to "newmail", seeing that it really is more
+than just a sound plugin ;)
+
+
+1.3
+
+Now added the ability to only check for RECENT messages (those that
+have not had their information not yet looked at).  Once a message
+is "noticed", it will not show up again as recent.  Nice for
+people who want to limit the number of notifications.
+
+Also changed the popup from a javascript alert to a popup window.
+This way, it doesn't screw up the browser near as much.
+
+Finally, I added a new sub-directory called sounds.  Put in here
+any sounds you want users to choose from.  They now can choose
+from any file in that directory via a drop-down menu in the options 
+screen (or, they can still choose a local file).
+
+1.2
+
+Added the ability to show a popup window on new mail arrival (via a
+JavaScript function).
+
+Added the ability to check for ONLY the INBOX for unseen messages
+(the default).  Also fixed a bug in counting unseen messages. ;)
+
+1.1
+
+Now added the ability to turn off this feature for users who don't want
+it.  The default is NOT enabled, so you need to go to the options menu to
+turn it on.
+
+Also a nice way to reset the file back to the server default.
+
+1.0
+
+First release (with an option page)!
+
+0.9
+
+First pass-through of making a plugin.  Hack hack hack . . .
+
diff --git a/plugins/newmail/README b/plugins/newmail/README
new file mode 100644 (file)
index 0000000..ea6fb67
--- /dev/null
@@ -0,0 +1,42 @@
+Ok, this is my first attempt at a plugin, so excuse the mess you may find
+in here.
+
+This plugin is used to play sounds (currently a WAV file) through the
+browser whenever the user has unseen messages flagged in the left window
+pane.  There are options available (on the options page of course) to
+disable this feature for each user, and to select different media files
+from the users local computer.  The default is that this is NOT enabled,
+so you'll need to go to the options menu to turn it on first! There are
+also options to show a popup window via JavaScript.
+
+I tried to make this fairly simple to install.  To install the plugin:
+
+  1.  Change to the plugins directory.
+
+        $ cd plugins/
+
+  2.  Unarchive the plugin.
+
+        $ tar zxvf /your/path/to/newmail-x.x.tgz
+
+  2.  This should create a newmail/ directory under plugins.
+
+  4.  Go to the config directory and run conf.pl
+
+        $ cd ../../config/
+        $ ./conf.pl
+
+  5.  Choose option 8 and proceed to add the new plugin following
+      the instructions there.  Save and exit, and your plugin should
+      be in place.
+
+Any questions, you can let me know --
+
+Mike Huttinger
+huttinger@ipact.com
+
+-----------------------------------------
+
+Modifications by Tyler Akins to support changing the title bar and for the
+new 1.1.1 validate.php format.  Also uses the new sqimap_unseen_messages()
+function in 1.1.2
diff --git a/plugins/newmail/newmail.php b/plugins/newmail/newmail.php
new file mode 100644 (file)
index 0000000..4a9ab30
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+   chdir ('../');
+   require_once('../src/validate.php');
+   require_once('../src/load_prefs.php');
+?>
+<HTML>
+<TITLE>New Mail</TITLE>
+<BODY bgcolor=<?php echo $color[4] ?> topmargin=0 leftmargin=0
+rightmargin=0 marginwidth=0 marginheight=0>
+<CENTER>
+<table width=100% cellpadding=2 cellspacing=2 border=0>
+<tr>
+   <td bgcolor=<?php echo $color[0] ?>>
+      <b><center>SquirrelMail Notice:</center></b>
+   </td>
+</tr><tr>   
+   <td>
+      <center>
+      <br>
+      <big><font color=<?php echo $color[2] ?>>You have new
+mail!</font></big><br>
+      <form name=nm>
+         <input type=button name=bt value="Close Window"
+onClick="javascript:window.close();">
+      </form>
+      </center>
+   </td>
+</tr>
+</table>
+</CENTER>
+<script language=javascript>
+<!--
+   document.nm.bt.focus();
+-->
+</script>
+</BODY></HTML>
diff --git a/plugins/newmail/newmail_opt.php b/plugins/newmail/newmail_opt.php
new file mode 100644 (file)
index 0000000..0f942fc
--- /dev/null
@@ -0,0 +1,175 @@
+<?php
+   /**
+    **  newmails_opt.php
+    **
+    **  Displays all options relating to new mail sounds
+    **
+    **/
+
+   chdir('..');
+   require_once('../src/validate.php');
+   require_once('../functions/page_header.php');
+   require_once('../functions/display_messages.php');
+   require_once('../functions/imap.php');
+   require_once('../functions/array.php');
+   require_once('../src/load_prefs.php');
+
+   displayPageHeader($color, "None");
+
+   $media_enable = getPref($data_dir,$username,"newmail_enable");
+   if ($media_enable == '') {
+     $media_enable = 'FALSE';
+   }
+
+  $media_popup = getPref($data_dir, $username,"newmail_popup");
+  $media_allbox = getPref($data_dir,$username,"newmail_allbox");
+  $media_recent = getPref($data_dir,$username,"newmail_recent");
+  $media_changetitle = getPref($data_dir,$username,"newmail_changetitle");
+
+   $media = getPref($data_dir,$username,"newmail_media");
+   if ($media == "") {
+     $media = "../plugins/newmail/sounds/Notify.wav";
+   }
+
+?>
+   <br>
+   <table width=95% align=center border=0 cellpadding=2 cellspacing=0><tr><td bgcolor="<?php echo $color[0] ?>">
+      <center><b><?php echo _("Options") ?> - New Mail Notification v1.2</b></center>
+   </td></tr><tr><td>
+<p>
+Select <b>Enable Media Playing</b> to turn on playing a media file when
+unseen mail is in your folders. When enabled, you can specify the media file to play in the provided
+file box.<p>
+
+The <b>Check all boxes, not just INBOX</b> option will check ALL of your
+folders for unseen mail, not just the inbox for notification.<p>
+
+Selecting the <b>Show popup</b> option will enable the showing of a popup
+window when unseen mail is in your folders (requires JavaScript).<p>
+
+Use the <b>Check RECENT</b> to only check for messages that are recent.  
+Recent messages are those that have just recently showed up and have not
+been "viewed" or checked yet.  This can prevent being continuously annoyed
+by sounds or popups for unseen mail.<p>
+
+Selecting the <b>Change title</b> option will change the title in some
+browsers to let you know when you have new mail (requires JavaScript, and
+only works in IE but you won't see errors with other browsers).  
+This will always tell you if you have new mail, even if you have 
+<b>Check RECENT</b> enabled.<p>
+
+Select from the list of <b>server files</b> the media file to play when
+new mail arrives.  Selecting <b>local media</b> will play the file
+specified in the <b>local media file</b> box to play from the local
+computer.  If no file is specified, the system will use a default from the
+server.
+
+   <form action="../../src/options.php" method=post>
+      <table width=100% cellpadding=0 cellspacing=2 border=0>
+        <tr>
+            <td align=right nowrap>&nbsp
+            </td><td>
+               <input type=checkbox <?php
+                       if($media_enable == "on") {
+                         echo "checked";
+                       }?>
+               name=media_enable><b> Enable Media Playing</b> 
+            </td>
+         </tr>
+        <tr>
+            <td align=right nowrap>&nbsp
+            </td><td>
+               <input type=checkbox <?php
+                       if($media_allbox == "on") {
+                         echo "checked";
+                       }?>
+               name=media_allbox><b> Check all boxes, not just INBOX</b>
+            </td>
+         </tr>
+        <tr>
+            <td align=right nowrap>&nbsp
+            </td><td>
+               <input type=checkbox <?php
+                       if($media_recent == "on") {
+                         echo "checked";
+                       }?>
+               name=media_recent><b> Count only messages that are RECENT</b>
+            </td>
+         </tr>
+        <tr>
+            <td align=right nowrap>&nbsp
+            </td><td>
+               <input type=checkbox <?php
+                       if($media_changetitle == "on") {
+                         echo "checked";
+                       }?>
+               name=media_changetitle><b> Change title on supported browsers.</b>
+               &nbsp;(requires IE and JavaScript to work)
+            </td>
+         </tr>
+        <tr>
+            <td align=right nowrap>&nbsp
+            </td><td>
+               <input type=checkbox <?php
+                       if($media_popup == "on") {
+                         echo "checked";
+                       }?>
+               name=media_popup><b> Show popup window on new mail</b>
+               &nbsp;(requires JavaScript to work) 
+            </td>
+         </tr>
+        <tr>
+            <td align=right nowrap>Select server file:
+            </td><td>
+               <SELECT NAME=media_sel><?php
+
+               echo "<OPTION VALUE=\"(local media)\">(local media)";
+
+               // Iterate sound files for options
+
+               $d = dir("../plugins/newmail/sounds");
+               while($entry=$d->read()) {
+                  $fname = $d->path . "/" . $entry;
+                  if ($entry != ".." && $entry != ".") { 
+                       echo "<OPTION ";
+                       if ($fname == $media) {
+                           echo "SELECTED ";
+                       }                       
+                       echo "VALUE=\"" . $fname . "\">" . $entry . "\n";
+                  }
+               }
+               $d->close();
+
+               ?>
+              </SELECT> 
+               <input type="submit" value=" Try " name="test" onClick="
+                    window.open('testsound.php?sound='+media_sel.options[media_sel.selectedIndex].value, 'TestSound',
+                       'width=150,height=30,scrollbars=no');
+                    return false;
+               ">
+            </td>
+         </tr>
+         <tr>
+            <td align=right nowrap>Local Media File :
+            </td><td>
+               <input type=file size=40 name=media_file>
+            </td>
+         </tr>
+         <tr>
+            <td align=right nowrap>Current File:
+            </td><td>
+              <input type=hidden value=\"" <?php echo $media; ?>
+                       name=media_default>
+              <?php echo $media; ?> 
+            </td>
+         </tr>
+         <tr>
+            <td>&nbsp;
+            </td><td>
+               <input type="submit" value="Submit" name="submit_newmail">
+            </td>
+         </tr>
+      </table>   
+   </form>
+   </td></tr></table>
+</body></html>
diff --git a/plugins/newmail/setup.php b/plugins/newmail/setup.php
new file mode 100644 (file)
index 0000000..f5951f0
--- /dev/null
@@ -0,0 +1,239 @@
+<?php
+
+   /**
+    **  newmail.php
+    **  (c)2000 by Michael Huttinger
+    **
+    **  Quite a hack -- but my first attempt at a plugin.  We were
+    **  looking for a way to play a sound when there was unseen
+    **  messages to look at.  Nice for users who keep the squirrel
+    **  mail window up for long periods of time and want to know
+    **  when mail arrives.
+    **
+    **  Basically, I hacked much of left_main.php into a plugin that
+    **  goes through each mail folder and increments a flag if
+    **  there are unseen messages.  If the final count of unseen
+    **  folders is > 0, then we play a sound (using the HTML at the
+    **  far end of this script).
+    **
+    **  This was tested with IE5.0 - but I hear Netscape works well,
+    **  too (with a plugin).
+    **/
+
+   function CheckNewMailboxSound($imapConnection, $mailbox, $real_box, $delimeter, $unseen, &$total_unseen) {
+               global $folder_prefix, $trash_folder, $sent_folder;
+               global $color, $move_to_sent, $move_to_trash;
+      global $unseen_notify, $unseen_type, $newmail_allbox, $newmail_recent;
+      global $newmail_changetitle;
+
+      $mailboxURL = urlencode($real_box);
+      $unseen_found = 0;
+
+      // Skip folders for Sent and Trash
+
+      if ($real_box == $sent_folder || $real_box == $trash_folder)
+      {
+          return 0;
+      }
+
+      if (($unseen_notify == 2 && $real_box == "INBOX") ||
+          ($unseen_notify == 3 && ($newmail_allbox == "on" ||
+                                  $real_box == "INBOX"))) {
+         $unseen = sqimap_unseen_messages($imapConnection, $real_box);
+        $total_unseen += $unseen;
+        
+        if($newmail_recent == 'on')
+          $unseen = sqimap_mailbox_select($imapConnection,$real_box,true,true);
+        
+         if ($unseen > 0) {
+            $unseen_found = 1;
+         } 
+      }
+      return $unseen_found;
+   }
+
+function squirrelmail_plugin_init_newmail() {
+  global $squirrelmail_plugin_hooks;
+
+  $squirrelmail_plugin_hooks["left_main_before"]["newmail"] = "newmail_plugin";
+  $squirrelmail_plugin_hooks["options_link_and_description"]["newmail"] = "newmail_opt";
+  $squirrelmail_plugin_hooks["options_save"]["newmail"] = "newmail_sav";
+  $squirrelmail_plugin_hooks["loading_prefs"]["newmail"] = "newmail_pref";
+
+}
+
+function newmail_opt() {
+  global $color;
+  ?>
+  <table width=50% cellpadding=3 cellspacing=0 border=0 align=center>
+  <tr>
+     <td bgcolor="<?php echo $color[9] ?>">
+       <a href="../plugins/newmail/newmail_opt.php">New Mail Notification</a>
+     </td>
+  </tr>
+  <tr>
+     <td bgcolor="<?php echo $color[0] ?>">
+       This configures settings for playing sounds and/or showing
+       popup windows when new mail arrives.
+     </td>
+  </tr>
+  </table>
+  <?php
+}
+
+function newmail_sav() {
+
+  global $username,$data_dir;
+  global $submit_newmail,$media_file,$media_reset,$media_enable,$media_popup;
+  global $media_recent,$media_sel;
+  global $media_allbox, $media_changetitle;
+
+  if ($submit_newmail) {
+   if(isset($media_enable)) {
+     setPref($data_dir,$username,"newmail_enable",$media_enable);
+   } else {
+     setPref($data_dir,$username,"newmail_enable","");
+   }
+   if(isset($media_popup)) {
+     setPref($data_dir,$username,"newmail_popup",$media_popup);
+   } else {
+     setPref($data_dir,$username,"newmail_popup","");
+   }
+   if(isset($media_allbox)) {
+     setPref($data_dir,$username,"newmail_allbox",$media_allbox);
+   } else {
+     setPref($data_dir,$username,"newmail_allbox","");
+   }
+   if(isset($media_recent)) {
+     setPref($data_dir,$username,"newmail_recent",$media_recent);
+   } else {
+     setPref($data_dir,$username,"newmail_recent","");
+   }
+   if(isset($media_changetitle)) {
+     setPref($data_dir,$username,"newmail_changetitle",$media_changetitle);
+   } else {
+     setPref($data_dir,$username,"newmail_changetitle","");
+   }
+   if(isset($media_sel)) {
+     if($media_sel == "(local media)") { 
+         setPref($data_dir,$username,"newmail_media",StripSlashes($media_file));
+     } else {
+        setPref($data_dir,$username,"newmail_media",$media_sel);
+     }
+   } else {
+     setPref($data_dir,$username,"newmail_media","");
+   }
+   echo "<center> New Mail Notification options saved</center>";
+  }
+}
+
+function newmail_pref() {
+  
+  global $username,$data_dir;
+  global $newmail_media,$newmail_enable,$newmail_popup,$newmail_allbox;
+  global $newmail_recent, $newmail_changetitle;
+
+  $newmail_recent = getPref($data_dir,$username,"newmail_recent");
+  $newmail_enable = getPref($data_dir,$username,"newmail_enable");
+  $newmail_media = getPref($data_dir, $username, "newmail_media");
+  $newmail_popup = getPref($data_dir, $username, "newmail_popup");
+  $newmail_allbox = getPref($data_dir, $username, "newmail_allbox");
+  $newmail_changetitle = getPref($data_dir, $username, "newmail_changetitle");
+
+  if ($newmail_media == "")
+  {
+    $newmail_media = "../plugins/newmail/sounds/Notify.wav";
+  }
+
+}
+
+function newmail_plugin() {
+
+ global $username,$key,$imapServerAddress,$imapPort;
+ global $newmail_media,$newmail_enable,$newmail_popup,$newmail_recent;
+ global $newmail_changetitle;
+
+ if ($newmail_enable == "on" || $newmail_popup == "on" || $newmail_changetitle) {
+
+   // open a connection on the imap port (143)
+
+   $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
+
+   $boxes = sqimap_mailbox_list($imapConnection);
+   $delimeter = sqimap_get_delimiter($imapConnection);
+
+   $status = 0;
+   $totalNew = 0;
+
+   for ($i = 0;$i < count($boxes); $i++) {
+      $line = "";
+      $mailbox = $boxes[$i]["formatted"];
+
+      if (! isset($boxes[$i]['unseen']))
+         $boxes[$i]['unseen'] = '';
+      if ($boxes[$i]["flags"]) {
+         $noselect = false;
+         for ($h = 0; $h < count($boxes[$i]["flags"]); $h++) {
+            if (strtolower($boxes[$i]["flags"][$h]) == "noselect")
+               $noselect = true;
+         }
+         if (! $noselect) {
+            $status = $status + CheckNewMailboxSound($imapConnection, $mailbox,
+                       $boxes[$i]["unformatted"], $delimeter, $boxes[$i]["unseen"],
+                       $totalNew);
+         }
+      } else {
+         $status = $status + CheckNewMailboxSound($imapConnection, $mailbox, $boxes[$i]["unformatted"],
+                       $delimeter, $boxes[$i]["unseen"], $totalNew);
+      }
+   
+   }
+   sqimap_logout($imapConnection);
+
+   // If we found unseen messages, then we
+   // will play the sound as follows:
+
+   if ($newmail_changetitle) {
+?>
+<script language="javascript">
+function ChangeTitleLoad() {
+   changetitlenum = <?PHP echo $totalNew ?>;
+   if (changetitlenum == 1)
+      window.parent.document.title = changetitlenum + " New Message";
+   else
+      window.parent.document.title = changetitlenum + " New Messages";
+   if (BeforeChangeTitle != null)
+      BeforeChangeTitle();
+}
+BeforeChangeTitle = window.onload;
+window.onload = ChangeTitleLoad;
+</script>
+<?PHP
+   }
+   if ($status > 0 && $newmail_enable == "on") {
+      echo "<EMBED SRC=\"$newmail_media\" HIDDEN=TRUE AUTOSTART=TRUE>";
+   }
+   if ($status >0 && $newmail_popup == "on") {
+?>
+<SCRIPT LANGUAGE="JavaScript">
+<!--
+function PopupScriptLoad() {
+   window.open("../plugins/newmail/newmail.php", "SMPopup",
+      "width=200,height=130,scrollbars=no");
+   if (BeforePopupScript != null)
+      BeforePopupScript();
+}
+BeforePopupScript = window.onload;
+window.onload = PopupScriptLoad;
+
+// Idea by:  Nic Wolfe (Nic@TimelapseProductions.com)
+// Web URL:  http://fineline.xs.mw
+// More code from Tyler Akins
+// End -->
+</script>
+<?php
+
+   }
+ }
+}
+?>
diff --git a/plugins/newmail/sounds/FanFair.wav b/plugins/newmail/sounds/FanFair.wav
new file mode 100644 (file)
index 0000000..697371e
Binary files /dev/null and b/plugins/newmail/sounds/FanFair.wav differ
diff --git a/plugins/newmail/sounds/Friends.wav b/plugins/newmail/sounds/Friends.wav
new file mode 100644 (file)
index 0000000..b9397de
Binary files /dev/null and b/plugins/newmail/sounds/Friends.wav differ
diff --git a/plugins/newmail/sounds/MontyPython.wav b/plugins/newmail/sounds/MontyPython.wav
new file mode 100644 (file)
index 0000000..0dc3655
Binary files /dev/null and b/plugins/newmail/sounds/MontyPython.wav differ
diff --git a/plugins/newmail/sounds/Notify.wav b/plugins/newmail/sounds/Notify.wav
new file mode 100644 (file)
index 0000000..658bc7f
Binary files /dev/null and b/plugins/newmail/sounds/Notify.wav differ
diff --git a/plugins/newmail/testsound.php b/plugins/newmail/testsound.php
new file mode 100644 (file)
index 0000000..97b52db
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+   chdir ('../');
+   require_once ('../src/validate.php');
+   require_once ('../src/load_prefs.php');
+   if (!isset($sound)) {
+    $sound = 'Click.wav';
+   }
+   $sound = str_replace("../plugins/newmail/", "", $sound);
+   $sound = str_replace("../", "", $sound);
+   $sound = str_replace("..\\", "", $sound);
+?>
+<HTML>
+<TITLE>Test Sound</TITLE>
+<BODY bgcolor=<?php echo $color[4] ?> topmargin=0 leftmargin=0
+rightmargin=0 marginwidth=0 marginheight=0>
+<CENTER>
+<embed src="<?php echo $sound ?>" hidden=true autostart=true>
+<br>
+<font face="Veranda, Arial Helvetica, sans-serif" size="2" </font>
+<b>Loading the sound...</b><br><br>
+<form>
+<input type="button" name="close" value="  Close  " onClick="window.close()">
+</form>
+</CENTER>
+</BODY></HTML>