4508b1b6 |
1 | <?php |
2 | |
3 | /** |
15e6162e |
4 | * newmail.php |
cc61478a |
5 | * |
15e6162e |
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. |
cc61478a |
9 | * |
15e6162e |
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. |
cc61478a |
15 | * |
15e6162e |
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). |
cc61478a |
21 | * |
15e6162e |
22 | * This was tested with IE5.0 - but I hear Netscape works well, |
23 | * too (with a plugin). |
cc61478a |
24 | * |
15e6162e |
25 | * $Id$ |
cc61478a |
26 | */ |
4508b1b6 |
27 | |
2d4c15d6 |
28 | function CheckNewMailboxSound($imapConnection, $mailbox, $real_box, $delimeter, $unseen, &$total_unseen) { |
29 | global $folder_prefix, $trash_folder, $sent_folder; |
6a745675 |
30 | global $color, $move_to_sent, $move_to_trash; |
2d4c15d6 |
31 | global $unseen_notify, $unseen_type, $newmail_allbox, $newmail_recent; |
32 | global $newmail_changetitle; |
4508b1b6 |
33 | |
2d4c15d6 |
34 | $mailboxURL = urlencode($real_box); |
35 | $unseen_found = 0; |
4508b1b6 |
36 | |
2d4c15d6 |
37 | // Skip folders for Sent and Trash |
4508b1b6 |
38 | |
6a745675 |
39 | if ($real_box == $sent_folder || |
2d4c15d6 |
40 | $real_box == $trash_folder) { |
6a745675 |
41 | return 0; |
2d4c15d6 |
42 | } |
4508b1b6 |
43 | |
2d4c15d6 |
44 | if (($unseen_notify == 2 && $real_box == 'INBOX') || |
45 | ($unseen_notify == 3 && ($newmail_allbox == 'on' || |
6a745675 |
46 | $real_box == 'INBOX'))) { |
2d4c15d6 |
47 | $unseen = sqimap_unseen_messages($imapConnection, $real_box); |
6a745675 |
48 | $total_unseen += $unseen; |
49 | |
50 | if($newmail_recent == 'on') { |
51 | $unseen = sqimap_mailbox_select( $imapConnection, $real_box, TRUE, TRUE); |
52 | } |
53 | |
2d4c15d6 |
54 | if ($unseen > 0) { |
55 | $unseen_found = 1; |
6a745675 |
56 | } |
2d4c15d6 |
57 | } |
58 | return( $unseen_found ); |
59 | } |
4508b1b6 |
60 | |
3d75ef16 |
61 | function squirrelmail_plugin_init_newmail() { |
62 | global $squirrelmail_plugin_hooks; |
6a745675 |
63 | |
3d75ef16 |
64 | $squirrelmail_plugin_hooks['left_main_before']['newmail'] = 'newmail_plugin'; |
cbe5423b |
65 | $squirrelmail_plugin_hooks['optpage_register_block']['newmail'] = 'newmail_optpage_register_block'; |
3d75ef16 |
66 | $squirrelmail_plugin_hooks['options_save']['newmail'] = 'newmail_sav'; |
67 | $squirrelmail_plugin_hooks['loading_prefs']['newmail'] = 'newmail_pref'; |
68 | } |
4508b1b6 |
69 | |
cbe5423b |
70 | function newmail_optpage_register_block() { |
3d75ef16 |
71 | // Gets added to the user's OPTIONS page. |
cbe5423b |
72 | global $optpage_blocks; |
4508b1b6 |
73 | |
3d75ef16 |
74 | if ( !soupNazi() ) { |
4508b1b6 |
75 | |
3d75ef16 |
76 | /* Register Squirrelspell with the $optionpages array. */ |
cbe5423b |
77 | $optpage_blocks[] = array( |
3d75ef16 |
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 | } |
4508b1b6 |
85 | |
e697b6cc |
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 | |
cc61478a |
93 | if ( isset($submit_newmail) ) { |
94 | |
e697b6cc |
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 | } |
4cf43843 |
129 | echo html_tag( 'p', _("New Mail Notification options saved"), 'center' ); |
e697b6cc |
130 | } |
131 | } |
4508b1b6 |
132 | |
2d4c15d6 |
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'); |
cc61478a |
141 | $newmail_media = getPref($data_dir, $username, 'newmail_media', '../plugins/newmail/sounds/Notify.wav'); |
2d4c15d6 |
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'); |
e697b6cc |
145 | |
2d4c15d6 |
146 | } |
147 | |
e697b6cc |
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 | } |
4508b1b6 |
191 | |
e697b6cc |
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"; |
975e3687 |
200 | if( $totalNew > 1 || $totalNew == 0 ) { |
e697b6cc |
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') { |
cc61478a |
218 | echo "<EMBED SRC=\"$newmail_media\" HIDDEN=TRUE AUTOSTART=TRUE>\n"; |
e697b6cc |
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 | } |
cbe5423b |
240 | ?> |