setup.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. /**
  3. * newmail.php
  4. *
  5. * Copyright (c) 1999-2002 The SquirrelMail Project Team
  6. * Copyright (c) 2000 by Michael Huttinger
  7. * Licensed under the GNU GPL. For full terms see the file COPYING.
  8. *
  9. * Quite a hack -- but my first attempt at a plugin. We were
  10. * looking for a way to play a sound when there was unseen
  11. * messages to look at. Nice for users who keep the squirrel
  12. * mail window up for long periods of time and want to know
  13. * when mail arrives.
  14. *
  15. * Basically, I hacked much of left_main.php into a plugin that
  16. * goes through each mail folder and increments a flag if
  17. * there are unseen messages. If the final count of unseen
  18. * folders is > 0, then we play a sound (using the HTML at the
  19. * far end of this script).
  20. *
  21. * This was tested with IE5.0 - but I hear Netscape works well,
  22. * too (with a plugin).
  23. *
  24. * $Id$
  25. */
  26. function CheckNewMailboxSound($imapConnection, $mailbox, $real_box, $delimeter, $unseen, &$total_unseen) {
  27. global $folder_prefix, $trash_folder, $sent_folder;
  28. global $color, $move_to_sent, $move_to_trash;
  29. global $unseen_notify, $unseen_type, $newmail_allbox, $newmail_recent;
  30. global $newmail_changetitle;
  31. $mailboxURL = urlencode($real_box);
  32. $unseen_found = 0;
  33. // Skip folders for Sent and Trash
  34. if ($real_box == $sent_folder ||
  35. $real_box == $trash_folder) {
  36. return 0;
  37. }
  38. if (($unseen_notify == 2 && $real_box == 'INBOX') ||
  39. ($unseen_notify == 3 && ($newmail_allbox == 'on' ||
  40. $real_box == 'INBOX'))) {
  41. $unseen = sqimap_unseen_messages($imapConnection, $real_box);
  42. $total_unseen += $unseen;
  43. if($newmail_recent == 'on') {
  44. $unseen = sqimap_mailbox_select( $imapConnection, $real_box, TRUE, TRUE);
  45. }
  46. if ($unseen > 0) {
  47. $unseen_found = 1;
  48. }
  49. }
  50. return( $unseen_found );
  51. }
  52. function squirrelmail_plugin_init_newmail() {
  53. global $squirrelmail_plugin_hooks;
  54. $squirrelmail_plugin_hooks['left_main_before']['newmail'] = 'newmail_plugin';
  55. $squirrelmail_plugin_hooks['optpage_register_block']['newmail'] = 'newmail_optpage_register_block';
  56. $squirrelmail_plugin_hooks['options_save']['newmail'] = 'newmail_sav';
  57. $squirrelmail_plugin_hooks['loading_prefs']['newmail'] = 'newmail_pref';
  58. }
  59. function newmail_optpage_register_block() {
  60. // Gets added to the user's OPTIONS page.
  61. global $optpage_blocks;
  62. if ( !soupNazi() ) {
  63. /* Register Squirrelspell with the $optionpages array. */
  64. $optpage_blocks[] = array(
  65. 'name' => _("NewMail Options"),
  66. 'url' => '../plugins/newmail/newmail_opt.php',
  67. 'desc' => _("This configures settings for playing sounds and/or showing popup windows when new mail arrives."),
  68. 'js' => TRUE
  69. );
  70. }
  71. }
  72. function newmail_sav() {
  73. global $username,$data_dir;
  74. global $submit_newmail,$media_file,$media_reset,$media_enable,$media_popup;
  75. global $media_recent,$media_sel;
  76. global $media_allbox, $media_changetitle;
  77. if ( isset($submit_newmail) ) {
  78. if(isset($media_enable)) {
  79. setPref($data_dir,$username,'newmail_enable',$media_enable);
  80. } else {
  81. setPref($data_dir,$username,'newmail_enable','');
  82. }
  83. if(isset($media_popup)) {
  84. setPref($data_dir,$username,'newmail_popup',$media_popup);
  85. } else {
  86. setPref($data_dir,$username,'newmail_popup','');
  87. }
  88. if(isset($media_allbox)) {
  89. setPref($data_dir,$username,'newmail_allbox',$media_allbox);
  90. } else {
  91. setPref($data_dir,$username,'newmail_allbox','');
  92. }
  93. if(isset($media_recent)) {
  94. setPref($data_dir,$username,'newmail_recent',$media_recent);
  95. } else {
  96. setPref($data_dir,$username,'newmail_recent','');
  97. }
  98. if(isset($media_changetitle)) {
  99. setPref($data_dir,$username,'newmail_changetitle',$media_changetitle);
  100. } else {
  101. setPref($data_dir,$username,'newmail_changetitle','');
  102. }
  103. if(isset($media_sel)) {
  104. if($media_sel == '(local media)') {
  105. setPref($data_dir,$username,'newmail_media',StripSlashes($media_file));
  106. } else {
  107. setPref($data_dir,$username,'newmail_media',$media_sel);
  108. }
  109. } else {
  110. setPref($data_dir,$username,'newmail_media','');
  111. }
  112. echo '<center> ' . _("New Mail Notification options saved") . '</center>';
  113. }
  114. }
  115. function newmail_pref() {
  116. global $username,$data_dir;
  117. global $newmail_media,$newmail_enable,$newmail_popup,$newmail_allbox;
  118. global $newmail_recent, $newmail_changetitle;
  119. $newmail_recent = getPref($data_dir,$username,'newmail_recent');
  120. $newmail_enable = getPref($data_dir,$username,'newmail_enable');
  121. $newmail_media = getPref($data_dir, $username, 'newmail_media', '../plugins/newmail/sounds/Notify.wav');
  122. $newmail_popup = getPref($data_dir, $username, 'newmail_popup');
  123. $newmail_allbox = getPref($data_dir, $username, 'newmail_allbox');
  124. $newmail_changetitle = getPref($data_dir, $username, 'newmail_changetitle');
  125. }
  126. function newmail_plugin() {
  127. global $username,$key,$imapServerAddress,$imapPort;
  128. global $newmail_media,$newmail_enable,$newmail_popup,$newmail_recent;
  129. global $newmail_changetitle;
  130. global $imapConnection;
  131. if ($newmail_enable == 'on' ||
  132. $newmail_popup == 'on' ||
  133. $newmail_changetitle) {
  134. // open a connection on the imap port (143)
  135. $boxes = sqimap_mailbox_list($imapConnection);
  136. $delimeter = sqimap_get_delimiter($imapConnection);
  137. $status = 0;
  138. $totalNew = 0;
  139. for ($i = 0;$i < count($boxes); $i++) {
  140. $line = '';
  141. $mailbox = $boxes[$i]['formatted'];
  142. if (! isset($boxes[$i]['unseen']))
  143. $boxes[$i]['unseen'] = '';
  144. if ($boxes[$i]['flags']) {
  145. $noselect = false;
  146. for ($h = 0; $h < count($boxes[$i]['flags']); $h++) {
  147. if (strtolower($boxes[$i]["flags"][$h]) == 'noselect')
  148. $noselect = TRUE;
  149. }
  150. if (! $noselect) {
  151. $status = $status + CheckNewMailboxSound($imapConnection, $mailbox,
  152. $boxes[$i]['unformatted'], $delimeter, $boxes[$i]['unseen'],
  153. $totalNew);
  154. }
  155. } else {
  156. $status = $status + CheckNewMailboxSound($imapConnection, $mailbox, $boxes[$i]['unformatted'],
  157. $delimeter, $boxes[$i]['unseen'], $totalNew);
  158. }
  159. }
  160. // sqimap_logout($imapConnection);
  161. // If we found unseen messages, then we
  162. // will play the sound as follows:
  163. if ($newmail_changetitle) {
  164. echo "<script language=\"javascript\">\n" .
  165. "function ChangeTitleLoad() {\n";
  166. if( $totalNew > 1 || $totalNew == 0 ) {
  167. echo 'window.parent.document.title = "' .
  168. sprintf(_("%s New Messages"), $totalNew ) .
  169. "\";\n";
  170. } else {
  171. echo 'window.parent.document.title = "' .
  172. sprintf(_("%s New Message"), $totalNew ) .
  173. "\";\n";
  174. }
  175. echo "if (BeforeChangeTitle != null)\n".
  176. "BeforeChangeTitle();\n".
  177. "}\n".
  178. "BeforeChangeTitle = window.onload;\n".
  179. "window.onload = ChangeTitleLoad;\n".
  180. "</script>\n";
  181. }
  182. if ($status > 0 && $newmail_enable == 'on') {
  183. echo "<EMBED SRC=\"$newmail_media\" HIDDEN=TRUE AUTOSTART=TRUE>\n";
  184. }
  185. if ($status >0 && $newmail_popup == 'on') {
  186. echo "<SCRIPT LANGUAGE=\"JavaScript\">\n".
  187. "<!--\n".
  188. "function PopupScriptLoad() {\n".
  189. 'window.open("../plugins/newmail/newmail.php", "SMPopup",'.
  190. "\"width=200,height=130,scrollbars=no\");\n".
  191. "if (BeforePopupScript != null)\n".
  192. "BeforePopupScript();\n".
  193. "}\n".
  194. "BeforePopupScript = window.onload;\n".
  195. "window.onload = PopupScriptLoad;\n".
  196. // Idea by: Nic Wolfe (Nic@TimelapseProductions.com)
  197. // Web URL: http://fineline.xs.mw
  198. // More code from Tyler Akins
  199. "// End -->\n".
  200. "</script>\n";
  201. }
  202. }
  203. }
  204. ?>