setup.php 9.5 KB

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