setup.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. * @package plugins
  26. * @subpackage newmail
  27. */
  28. /**
  29. */
  30. include_once(SM_PATH . 'functions/display_messages.php');
  31. function CheckNewMailboxSound($imapConnection, $mailbox, $real_box, $delimeter, $unseen, &$total_new) {
  32. global $folder_prefix, $trash_folder, $sent_folder,
  33. $color, $move_to_sent, $move_to_trash,
  34. $unseen_notify, $unseen_type, $newmail_allbox,
  35. $newmail_recent, $newmail_changetitle;
  36. $mailboxURL = urlencode($real_box);
  37. $unseen = $recent = 0;
  38. // Skip folders for Sent and Trash
  39. if ($real_box == $sent_folder ||
  40. $real_box == $trash_folder) {
  41. return 0;
  42. }
  43. if (($unseen_notify == 2 && $real_box == 'INBOX') ||
  44. ($unseen_notify == 3 && ($newmail_allbox == 'on' ||
  45. $real_box == 'INBOX'))) {
  46. $status = sqimap_status_messages( $imapConnection, $real_box);
  47. if($newmail_recent == 'on') {
  48. $total_new += $status['RECENT'];
  49. } else {
  50. $total_new += $status['UNSEEN'];
  51. }
  52. if ($total_new) {
  53. return 1;
  54. }
  55. }
  56. return 0;
  57. }
  58. function squirrelmail_plugin_init_newmail() {
  59. global $squirrelmail_plugin_hooks;
  60. $squirrelmail_plugin_hooks['left_main_before']['newmail'] = 'newmail_plugin';
  61. $squirrelmail_plugin_hooks['optpage_register_block']['newmail'] = 'newmail_optpage_register_block';
  62. $squirrelmail_plugin_hooks['options_save']['newmail'] = 'newmail_sav';
  63. $squirrelmail_plugin_hooks['loading_prefs']['newmail'] = 'newmail_pref';
  64. }
  65. function newmail_optpage_register_block() {
  66. // Gets added to the user's OPTIONS page.
  67. global $optpage_blocks;
  68. if ( checkForJavascript() ) {
  69. /* Register Squirrelspell with the $optionpages array. */
  70. $optpage_blocks[] = array(
  71. 'name' => _("NewMail Options"),
  72. 'url' => SM_PATH . 'plugins/newmail/newmail_opt.php',
  73. 'desc' => _("This configures settings for playing sounds and/or showing popup windows when new mail arrives."),
  74. 'js' => TRUE
  75. );
  76. }
  77. }
  78. function newmail_sav() {
  79. global $data_dir, $username;
  80. if ( sqgetGlobalVar('submit_newmail', $submit, SQ_POST) ) {
  81. $media_enable = '';
  82. $media_popup = '';
  83. $media_allbox = '';
  84. $media_recent = '';
  85. $media_changetitle = '';
  86. $media_sel = '';
  87. sqgetGlobalVar('media_enable', $media_enable, SQ_POST);
  88. sqgetGlobalVar('media_popup', $media_popup, SQ_POST);
  89. sqgetGlobalVar('media_allbox', $media_allbox, SQ_POST);
  90. sqgetGlobalVar('media_recent', $media_recent, SQ_POST);
  91. sqgetGlobalVar('media_changetitle', $media_changetitle, SQ_POST);
  92. setPref($data_dir,$username,'newmail_enable',$media_enable);
  93. setPref($data_dir,$username,'newmail_popup', $media_popup);
  94. setPref($data_dir,$username,'newmail_allbox',$media_allbox);
  95. setPref($data_dir,$username,'newmail_recent',$media_recent);
  96. setPref($data_dir,$username,'newmail_changetitle',$media_changetitle);
  97. if( sqgetGlobalVar('media_sel', $media_sel, SQ_POST) &&
  98. ($media_sel == '(none)' || $media_sel == '(local media)') ) {
  99. removePref($data_dir,$username,'newmail_media');
  100. } else {
  101. setPref($data_dir,$username,'newmail_media',$media_sel);
  102. }
  103. echo html_tag( 'p', _("New Mail Notification options saved"), 'center' );
  104. }
  105. }
  106. function newmail_pref() {
  107. global $username,$data_dir;
  108. global $newmail_media,$newmail_enable,$newmail_popup,$newmail_allbox;
  109. global $newmail_recent, $newmail_changetitle;
  110. $newmail_recent = getPref($data_dir,$username,'newmail_recent');
  111. $newmail_enable = getPref($data_dir,$username,'newmail_enable');
  112. $newmail_media = getPref($data_dir, $username, 'newmail_media', '(none)');
  113. $newmail_popup = getPref($data_dir, $username, 'newmail_popup');
  114. $newmail_allbox = getPref($data_dir, $username, 'newmail_allbox');
  115. $newmail_changetitle = getPref($data_dir, $username, 'newmail_changetitle');
  116. }
  117. function newmail_plugin() {
  118. global $username, $key, $imapServerAddress, $imapPort,
  119. $newmail_media, $newmail_enable, $newmail_popup,
  120. $newmail_recent, $newmail_changetitle, $imapConnection, $PHP_SELF;
  121. if ($newmail_enable == 'on' ||
  122. $newmail_popup == 'on' ||
  123. $newmail_changetitle) {
  124. // open a connection on the imap port (143)
  125. $boxes = sqimap_mailbox_list($imapConnection);
  126. $delimeter = sqimap_get_delimiter($imapConnection);
  127. $status = 0;
  128. $totalNew = 0;
  129. for ($i = 0;$i < count($boxes); $i++) {
  130. $line = '';
  131. $mailbox = $boxes[$i]['formatted'];
  132. if (! isset($boxes[$i]['unseen'])) {
  133. $boxes[$i]['unseen'] = '';
  134. }
  135. if ($boxes[$i]['flags']) {
  136. $noselect = false;
  137. for ($h = 0; $h < count($boxes[$i]['flags']); $h++) {
  138. if (strtolower($boxes[$i]["flags"][$h]) == 'noselect') {
  139. $noselect = TRUE;
  140. }
  141. }
  142. if (! $noselect) {
  143. $status += CheckNewMailboxSound($imapConnection,
  144. $mailbox,
  145. $boxes[$i]['unformatted'],
  146. $delimeter,
  147. $boxes[$i]['unseen'],
  148. $totalNew);
  149. }
  150. } else {
  151. $status += CheckNewMailboxSound($imapConnection,
  152. $mailbox,
  153. $boxes[$i]['unformatted'],
  154. $delimeter,
  155. $boxes[$i]['unseen'],
  156. $totalNew);
  157. }
  158. }
  159. // sqimap_logout($imapConnection);
  160. // If we found unseen messages, then we
  161. // will play the sound as follows:
  162. if ($newmail_changetitle) {
  163. echo "<script language=\"javascript\">\n" .
  164. "function ChangeTitleLoad() {\n";
  165. if( $totalNew > 1 || $totalNew == 0 ) {
  166. echo 'window.parent.document.title = "' .
  167. sprintf(_("%s New Messages"), $totalNew ) .
  168. "\";\n";
  169. } else {
  170. echo 'window.parent.document.title = "' .
  171. sprintf(_("%s New Message"), $totalNew ) .
  172. "\";\n";
  173. }
  174. echo "if (BeforeChangeTitle != null)\n".
  175. "BeforeChangeTitle();\n".
  176. "}\n".
  177. "BeforeChangeTitle = window.onload;\n".
  178. "window.onload = ChangeTitleLoad;\n".
  179. "</script>\n";
  180. }
  181. if ($totalNew > 0 && $newmail_enable == 'on' && $newmail_media != '' ) {
  182. echo '<EMBED SRC="'.htmlspecialchars($newmail_media) .
  183. "\" HIDDEN=\"TRUE\" AUTOSTART=\"TRUE\">\n";
  184. }
  185. if ($totalNew > 0 && $newmail_popup == 'on') {
  186. echo "<SCRIPT LANGUAGE=\"JavaScript\">\n".
  187. "<!--\n".
  188. "function PopupScriptLoad() {\n".
  189. 'window.open("'.sqm_baseuri().'plugins/newmail/newmail.php?numnew='.$totalNew.
  190. '", "SMPopup",'.
  191. "\"width=200,height=130,scrollbars=no\");\n".
  192. "if (BeforePopupScript != null)\n".
  193. "BeforePopupScript();\n".
  194. "}\n".
  195. "BeforePopupScript = window.onload;\n".
  196. "window.onload = PopupScriptLoad;\n".
  197. // Idea by: Nic Wolfe (Nic@TimelapseProductions.com)
  198. // Web URL: http://fineline.xs.mw
  199. // More code from Tyler Akins
  200. "// End -->\n".
  201. "</script>\n";
  202. }
  203. }
  204. }
  205. ?>