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