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