newmail plugin strings
[squirrelmail.git] / plugins / newmail / setup.php
CommitLineData
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).
2d4c15d6 21 **
22 ** $Id$
23 **
4508b1b6 24 **/
25
2d4c15d6 26 function CheckNewMailboxSound($imapConnection, $mailbox, $real_box, $delimeter, $unseen, &$total_unseen) {
27 global $folder_prefix, $trash_folder, $sent_folder;
4508b1b6 28 global $color, $move_to_sent, $move_to_trash;
2d4c15d6 29 global $unseen_notify, $unseen_type, $newmail_allbox, $newmail_recent;
30 global $newmail_changetitle;
4508b1b6 31
2d4c15d6 32 $mailboxURL = urlencode($real_box);
33 $unseen_found = 0;
4508b1b6 34
2d4c15d6 35 // Skip folders for Sent and Trash
4508b1b6 36
2d4c15d6 37 if ($real_box == $sent_folder ||
38 $real_box == $trash_folder) {
39 return 0;
40 }
4508b1b6 41
2d4c15d6 42 if (($unseen_notify == 2 && $real_box == 'INBOX') ||
43 ($unseen_notify == 3 && ($newmail_allbox == 'on' ||
44 $real_box == 'INBOX'))) {
45 $unseen = sqimap_unseen_messages($imapConnection, $real_box);
46 $total_unseen += $unseen;
4508b1b6 47
2d4c15d6 48 if($newmail_recent == 'on') {
49 $unseen = sqimap_mailbox_select( $imapConnection, $real_box, TRUE, TRUE);
50 }
4508b1b6 51
2d4c15d6 52 if ($unseen > 0) {
53 $unseen_found = 1;
54 }
55 }
56 return( $unseen_found );
57 }
4508b1b6 58
59function squirrelmail_plugin_init_newmail() {
60 global $squirrelmail_plugin_hooks;
61
62 $squirrelmail_plugin_hooks["left_main_before"]["newmail"] = "newmail_plugin";
63 $squirrelmail_plugin_hooks["options_link_and_description"]["newmail"] = "newmail_opt";
64 $squirrelmail_plugin_hooks["options_save"]["newmail"] = "newmail_sav";
65 $squirrelmail_plugin_hooks["loading_prefs"]["newmail"] = "newmail_pref";
66
67}
68
69function newmail_opt() {
70 global $color;
71 ?>
72 <table width=50% cellpadding=3 cellspacing=0 border=0 align=center>
73 <tr>
74 <td bgcolor="<?php echo $color[9] ?>">
75 <a href="../plugins/newmail/newmail_opt.php">New Mail Notification</a>
76 </td>
77 </tr>
78 <tr>
79 <td bgcolor="<?php echo $color[0] ?>">
80 This configures settings for playing sounds and/or showing
81 popup windows when new mail arrives.
82 </td>
83 </tr>
84 </table>
85 <?php
86}
87
88function newmail_sav() {
89
90 global $username,$data_dir;
91 global $submit_newmail,$media_file,$media_reset,$media_enable,$media_popup;
92 global $media_recent,$media_sel;
93 global $media_allbox, $media_changetitle;
94
95 if ($submit_newmail) {
96 if(isset($media_enable)) {
97 setPref($data_dir,$username,"newmail_enable",$media_enable);
98 } else {
99 setPref($data_dir,$username,"newmail_enable","");
100 }
101 if(isset($media_popup)) {
102 setPref($data_dir,$username,"newmail_popup",$media_popup);
103 } else {
104 setPref($data_dir,$username,"newmail_popup","");
105 }
106 if(isset($media_allbox)) {
107 setPref($data_dir,$username,"newmail_allbox",$media_allbox);
108 } else {
109 setPref($data_dir,$username,"newmail_allbox","");
110 }
111 if(isset($media_recent)) {
112 setPref($data_dir,$username,"newmail_recent",$media_recent);
113 } else {
114 setPref($data_dir,$username,"newmail_recent","");
115 }
116 if(isset($media_changetitle)) {
117 setPref($data_dir,$username,"newmail_changetitle",$media_changetitle);
118 } else {
119 setPref($data_dir,$username,"newmail_changetitle","");
120 }
121 if(isset($media_sel)) {
122 if($media_sel == "(local media)") {
123 setPref($data_dir,$username,"newmail_media",StripSlashes($media_file));
124 } else {
125 setPref($data_dir,$username,"newmail_media",$media_sel);
126 }
127 } else {
128 setPref($data_dir,$username,"newmail_media","");
129 }
2d4c15d6 130 echo '<center> ' . _("New Mail Notification options saved") . '</center>';
4508b1b6 131 }
132}
133
2d4c15d6 134 function newmail_pref() {
135
136 global $username,$data_dir;
137 global $newmail_media,$newmail_enable,$newmail_popup,$newmail_allbox;
138 global $newmail_recent, $newmail_changetitle;
139
140 $newmail_recent = getPref($data_dir,$username,'newmail_recent');
141 $newmail_enable = getPref($data_dir,$username,'newmail_enable');
142 $newmail_media = getPref($data_dir, $username, 'newmail_media');
143 $newmail_popup = getPref($data_dir, $username, 'newmail_popup');
144 $newmail_allbox = getPref($data_dir, $username, 'newmail_allbox');
145 $newmail_changetitle = getPref($data_dir, $username, 'newmail_changetitle');
146
147 if ($newmail_media == '') {
148 $newmail_media = '../plugins/newmail/sounds/Notify.wav';
149 }
150
151 }
4508b1b6 152
153function newmail_plugin() {
154
155 global $username,$key,$imapServerAddress,$imapPort;
156 global $newmail_media,$newmail_enable,$newmail_popup,$newmail_recent;
157 global $newmail_changetitle;
2d4c15d6 158 global $imapConnection;
4508b1b6 159
2d4c15d6 160 if ($newmail_enable == 'on' || $newmail_popup == 'on' || $newmail_changetitle) {
4508b1b6 161
162 // open a connection on the imap port (143)
163
2d4c15d6 164 // $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
4508b1b6 165
166 $boxes = sqimap_mailbox_list($imapConnection);
167 $delimeter = sqimap_get_delimiter($imapConnection);
168
169 $status = 0;
170 $totalNew = 0;
171
172 for ($i = 0;$i < count($boxes); $i++) {
2d4c15d6 173
174 $line = '';
175 $mailbox = $boxes[$i]['formatted'];
4508b1b6 176
177 if (! isset($boxes[$i]['unseen']))
178 $boxes[$i]['unseen'] = '';
2d4c15d6 179 if ($boxes[$i]['flags']) {
4508b1b6 180 $noselect = false;
2d4c15d6 181 for ($h = 0; $h < count($boxes[$i]['flags']); $h++) {
182 if (strtolower($boxes[$i]["flags"][$h]) == 'noselect')
4508b1b6 183 $noselect = true;
184 }
185 if (! $noselect) {
186 $status = $status + CheckNewMailboxSound($imapConnection, $mailbox,
2d4c15d6 187 $boxes[$i]['unformatted'], $delimeter, $boxes[$i]['unseen'],
4508b1b6 188 $totalNew);
189 }
190 } else {
2d4c15d6 191 $status = $status + CheckNewMailboxSound($imapConnection, $mailbox, $boxes[$i]['unformatted'],
192 $delimeter, $boxes[$i]['unseen'], $totalNew);
4508b1b6 193 }
194
195 }
2d4c15d6 196
197 // sqimap_logout($imapConnection);
4508b1b6 198
199 // If we found unseen messages, then we
200 // will play the sound as follows:
201
2d4c15d6 202 if ($newmail_changetitle) {
203 echo "<script language=\"javascript\">\n" .
204 "function ChangeTitleLoad() {\n";
205 if( $totalNew > 1 ) {
206 echo 'window.parent.document.title = "' . sprintf(_("%s New Messages"), $totalNew ) . "\";\n";
207 }else {
208 echo 'window.parent.document.title = "' . sprintf(_("%s New Message"), $totalNew ) . "\";\n";
209 }
210 echo "if (BeforeChangeTitle != null)\n".
211 "BeforeChangeTitle();\n".
212 "}\n".
213 "BeforeChangeTitle = window.onload;\n".
214 "window.onload = ChangeTitleLoad;\n".
215 "</script>\n";
216 }
217
218 if ($status > 0 && $newmail_enable == 'on') {
219 echo "<EMBED SRC=\"$newmail_media\" HIDDEN=TRUE AUTOSTART=TRUE>";
220 }
221 if ($status >0 && $newmail_popup == 'on') {
4508b1b6 222?>
223<SCRIPT LANGUAGE="JavaScript">
224<!--
225function PopupScriptLoad() {
226 window.open("../plugins/newmail/newmail.php", "SMPopup",
227 "width=200,height=130,scrollbars=no");
228 if (BeforePopupScript != null)
229 BeforePopupScript();
230}
231BeforePopupScript = window.onload;
232window.onload = PopupScriptLoad;
233
234// Idea by: Nic Wolfe (Nic@TimelapseProductions.com)
235// Web URL: http://fineline.xs.mw
236// More code from Tyler Akins
237// End -->
238</script>
239<?php
240
241 }
242 }
243}
2d4c15d6 244?>