f5951f0a26d7bf95f02bd35b2513247ccce528eb
5 ** (c)2000 by Michael Huttinger
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
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).
19 ** This was tested with IE5.0 - but I hear Netscape works well,
20 ** too (with a plugin).
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;
29 $mailboxURL = urlencode($real_box);
32 // Skip folders for Sent and Trash
34 if ($real_box == $sent_folder ||
$real_box == $trash_folder)
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;
45 if($newmail_recent == 'on')
46 $unseen = sqimap_mailbox_select($imapConnection,$real_box,true,true);
55 function squirrelmail_plugin_init_newmail() {
56 global $squirrelmail_plugin_hooks;
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";
65 function newmail_opt() {
68 <table width
=50% cellpadding
=3 cellspacing
=0 border
=0 align
=center
>
70 <td bgcolor
="<?php echo $color[9] ?>">
71 <a href
="../plugins/newmail/newmail_opt.php">New Mail Notification
</a
>
75 <td bgcolor
="<?php echo $color[0] ?>">
76 This configures settings
for playing sounds
and/or showing
77 popup windows when
new mail arrives
.
84 function newmail_sav() {
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;
91 if ($submit_newmail) {
92 if(isset($media_enable)) {
93 setPref($data_dir,$username,"newmail_enable",$media_enable);
95 setPref($data_dir,$username,"newmail_enable","");
97 if(isset($media_popup)) {
98 setPref($data_dir,$username,"newmail_popup",$media_popup);
100 setPref($data_dir,$username,"newmail_popup","");
102 if(isset($media_allbox)) {
103 setPref($data_dir,$username,"newmail_allbox",$media_allbox);
105 setPref($data_dir,$username,"newmail_allbox","");
107 if(isset($media_recent)) {
108 setPref($data_dir,$username,"newmail_recent",$media_recent);
110 setPref($data_dir,$username,"newmail_recent","");
112 if(isset($media_changetitle)) {
113 setPref($data_dir,$username,"newmail_changetitle",$media_changetitle);
115 setPref($data_dir,$username,"newmail_changetitle","");
117 if(isset($media_sel)) {
118 if($media_sel == "(local media)") {
119 setPref($data_dir,$username,"newmail_media",StripSlashes($media_file));
121 setPref($data_dir,$username,"newmail_media",$media_sel);
124 setPref($data_dir,$username,"newmail_media","");
126 echo "<center> New Mail Notification options saved</center>";
130 function newmail_pref() {
132 global $username,$data_dir;
133 global $newmail_media,$newmail_enable,$newmail_popup,$newmail_allbox;
134 global $newmail_recent, $newmail_changetitle;
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");
143 if ($newmail_media == "")
145 $newmail_media = "../plugins/newmail/sounds/Notify.wav";
150 function newmail_plugin() {
152 global $username,$key,$imapServerAddress,$imapPort;
153 global $newmail_media,$newmail_enable,$newmail_popup,$newmail_recent;
154 global $newmail_changetitle;
156 if ($newmail_enable == "on" ||
$newmail_popup == "on" ||
$newmail_changetitle) {
158 // open a connection on the imap port (143)
160 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
162 $boxes = sqimap_mailbox_list($imapConnection);
163 $delimeter = sqimap_get_delimiter($imapConnection);
168 for ($i = 0;$i < count($boxes); $i++
) {
170 $mailbox = $boxes[$i]["formatted"];
172 if (! isset($boxes[$i]['unseen']))
173 $boxes[$i]['unseen'] = '';
174 if ($boxes[$i]["flags"]) {
176 for ($h = 0; $h < count($boxes[$i]["flags"]); $h++
) {
177 if (strtolower($boxes[$i]["flags"][$h]) == "noselect")
181 $status = $status +
CheckNewMailboxSound($imapConnection, $mailbox,
182 $boxes[$i]["unformatted"], $delimeter, $boxes[$i]["unseen"],
186 $status = $status +
CheckNewMailboxSound($imapConnection, $mailbox, $boxes[$i]["unformatted"],
187 $delimeter, $boxes[$i]["unseen"], $totalNew);
191 sqimap_logout($imapConnection);
193 // If we found unseen messages, then we
194 // will play the sound as follows:
196 if ($newmail_changetitle) {
198 <script language
="javascript">
199 function ChangeTitleLoad() {
200 changetitlenum
= <?PHP
echo $totalNew ?
>;
201 if (changetitlenum
== 1)
202 window
.parent
.document
.title
= changetitlenum +
" New Message";
204 window
.parent
.document
.title
= changetitlenum +
" New Messages";
205 if (BeforeChangeTitle
!= null)
208 BeforeChangeTitle
= window
.onload
;
209 window
.onload
= ChangeTitleLoad
;
213 if ($status > 0 && $newmail_enable == "on") {
214 echo "<EMBED SRC=\"$newmail_media\" HIDDEN=TRUE AUTOSTART=TRUE>";
216 if ($status >0 && $newmail_popup == "on") {
218 <SCRIPT LANGUAGE
="JavaScript">
220 function PopupScriptLoad() {
221 window
.open("../plugins/newmail/newmail.php", "SMPopup",
222 "width=200,height=130,scrollbars=no");
223 if (BeforePopupScript
!= null)
226 BeforePopupScript
= window
.onload
;
227 window
.onload
= PopupScriptLoad
;
229 // Idea by: Nic Wolfe (Nic@TimelapseProductions.com)
230 // Web URL: http://fineline.xs.mw
231 // More code from Tyler Akins