squirrelmail-webmail  1.4.22
About: SquirrelMail is a standards-based webmail package with strong MIME support, address books, and folder manipulation (written in PHP4).
  Fossies Dox: squirrelmail-webmail-1.4.22.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

setup.php
Go to the documentation of this file.
1 <?php
2 
41 function CheckNewMailboxSound($imapConnection, $mailbox, $real_box, $delimeter, $unseen, &$total_new) {
43  $color, $move_to_sent, $move_to_trash,
44  $unseen_notify, $unseen_type, $newmail_allbox,
45  $newmail_recent, $newmail_changetitle;
46 
47  $mailboxURL = urlencode($real_box);
48  $unseen = $recent = 0;
49 
50  // Skip folders for Sent and Trash
51 
52  if ($real_box == $sent_folder ||
53  $real_box == $trash_folder) {
54  return 0;
55  }
56 
57  if (($unseen_notify == 2 && $real_box == 'INBOX') ||
58  ($unseen_notify == 3 && ($newmail_allbox == 'on' ||
59  $real_box == 'INBOX'))) {
60  $status = sqimap_status_messages( $imapConnection, $real_box);
61  if($newmail_recent == 'on') {
62  $total_new += $status['RECENT'];
63  } else {
64  $total_new += $status['UNSEEN'];
65  }
66  if ($total_new) {
67  return 1;
68  }
69  }
70  return 0;
71 }
72 
75 
76  $squirrelmail_plugin_hooks['left_main_before']['newmail'] = 'newmail_plugin';
77  $squirrelmail_plugin_hooks['optpage_register_block']['newmail'] = 'newmail_optpage_register_block';
78  $squirrelmail_plugin_hooks['options_save']['newmail'] = 'newmail_sav';
79  $squirrelmail_plugin_hooks['loading_prefs']['newmail'] = 'newmail_pref';
80  $squirrelmail_plugin_hooks['optpage_set_loadinfo']['newmail'] = 'newmail_set_loadinfo';
81 }
82 
84  // Gets added to the user's OPTIONS page.
85  global $optpage_blocks;
86 
87  if ( !soupNazi() ) {
88 
89  /* Register Squirrelspell with the $optionpages array. */
90  $optpage_blocks[] = array(
91  'name' => _("NewMail Options"),
92  'url' => SM_PATH . 'plugins/newmail/newmail_opt.php',
93  'desc' => _("This configures settings for playing sounds and/or showing popup windows when new mail arrives."),
94  'js' => TRUE
95  );
96  }
97 }
98 
99 function newmail_sav() {
100  global $data_dir, $username;
101 
102  if ( sqgetGlobalVar('submit_newmail', $submit, SQ_POST) ) {
103  $media_enable = '';
104  $media_popup = '';
105  $media_allbox = '';
106  $media_recent = '';
107  $media_changetitle = '';
108  $media_sel = '';
109 
110  sqgetGlobalVar('media_enable', $media_enable, SQ_POST);
111  sqgetGlobalVar('media_popup', $media_popup, SQ_POST);
112  sqgetGlobalVar('media_allbox', $media_allbox, SQ_POST);
113  sqgetGlobalVar('media_recent', $media_recent, SQ_POST);
114  sqgetGlobalVar('media_changetitle', $media_changetitle, SQ_POST);
115  sqgetGlobalVar('popup_height', $newmail_popup_height, SQ_POST);
116  sqgetGlobalVar('popup_width', $newmail_popup_width, SQ_POST);
117 
118  setPref($data_dir,$username,'newmail_enable',$media_enable);
119  setPref($data_dir,$username,'newmail_popup', $media_popup);
120  setPref($data_dir,$username,'newmail_allbox',$media_allbox);
121  setPref($data_dir,$username,'newmail_recent',$media_recent);
122  setPref($data_dir,$username,'newmail_popup_height',$newmail_popup_height);
123  setPref($data_dir,$username,'newmail_popup_width',$newmail_popup_width);
124  setPref($data_dir,$username,'newmail_changetitle',$media_changetitle);
125 
126  if( sqgetGlobalVar('media_sel', $media_sel, SQ_POST) &&
127  ($media_sel == '(none)' || $media_sel == '(local media)') ) {
128  removePref($data_dir,$username,'newmail_media');
129  } else {
130  setPref($data_dir,$username,'newmail_media',$media_sel);
131  }
132  }
133 }
134 
135 function newmail_pref() {
136  global $username, $data_dir, $newmail_media, $newmail_enable, $newmail_popup,
137  $newmail_allbox, $newmail_recent, $newmail_changetitle, $newmail_popup_height,
139 
140 
141  $newmail_recent = getPref($data_dir,$username,'newmail_recent');
142  $newmail_enable = getPref($data_dir,$username,'newmail_enable');
143  $newmail_media = getPref($data_dir, $username, 'newmail_media', '(none)');
144  $newmail_popup = getPref($data_dir, $username, 'newmail_popup');
145  $newmail_allbox = getPref($data_dir, $username, 'newmail_allbox');
146  $newmail_popup_height = getPref($data_dir, $username, 'newmail_popup_height',130);
147  $newmail_popup_width = getPref($data_dir, $username, 'newmail_popup_width',200);
148  $newmail_changetitle = getPref($data_dir, $username, 'newmail_changetitle');
149 
150 }
151 
158  global $optpage, $optpage_name;
159  if ($optpage=='newmail') {
160  $optpage_name=_("NewMail Options");
161  }
162 }
163 
164 function newmail_plugin() {
165  global $username, $key, $imapServerAddress, $imapPort,
166  $newmail_media, $newmail_enable, $newmail_popup,
167  $newmail_popup_height, $newmail_popup_width, $newmail_recent,
168  $newmail_changetitle, $imapConnection;
169 
170  include_once(SM_PATH . 'functions/display_messages.php');
171 
172  if ($newmail_enable == 'on' ||
173  $newmail_popup == 'on' ||
174  $newmail_changetitle) {
175 
176  // open a connection on the imap port (143)
179 
180  $status = 0;
181  $totalNew = 0;
182 
183  for ($i = 0;$i < count($boxes); $i++) {
184 
185  $line = '';
186  $mailbox = $boxes[$i]['formatted'];
187 
188  if (! isset($boxes[$i]['unseen'])) {
189  $boxes[$i]['unseen'] = '';
190  }
191  if ($boxes[$i]['flags']) {
192  $noselect = false;
193  for ($h = 0; $h < count($boxes[$i]['flags']); $h++) {
194  if (strtolower($boxes[$i]["flags"][$h]) == 'noselect') {
195  $noselect = TRUE;
196  }
197  }
198  if (! $noselect) {
200  $mailbox,
201  $boxes[$i]['unformatted'],
202  $delimeter,
203  $boxes[$i]['unseen'],
204  $totalNew);
205  }
206  } else {
208  $mailbox,
209  $boxes[$i]['unformatted'],
210  $delimeter,
211  $boxes[$i]['unseen'],
212  $totalNew);
213  }
214 
215  }
216 
217  // sqimap_logout($imapConnection);
218 
219  // If we found unseen messages, then we
220  // will play the sound as follows:
221 
222  if ($newmail_changetitle) {
223  global $org_title;
224  echo "<script language=\"javascript\" type=\"text/javascript\">\n" .
225  "function ChangeTitleLoad() {\n";
226  if( $totalNew > 1 || $totalNew == 0 ) {
227  echo 'window.parent.document.title = "' . $org_title . ' [' .
228  sprintf(_("%s New Messages"), $totalNew ) .
229  "]\";\n";
230  } else {
231  echo 'window.parent.document.title = "' . $org_title . ' [' .
232  sprintf(_("%s New Message"), $totalNew ) .
233  "]\";\n";
234  }
235  echo "if (BeforeChangeTitle != null)\n".
236  "BeforeChangeTitle();\n".
237  "}\n".
238  "BeforeChangeTitle = window.onload;\n".
239  "window.onload = ChangeTitleLoad;\n".
240  "</script>\n";
241  }
242 
243  if ($totalNew > 0 && $newmail_enable == 'on' && $newmail_media != '' && $newmail_media != '(none)') {
244  $newmail_media=sqm_baseuri().'plugins/newmail/sounds/'.basename($newmail_media);
245  echo '<embed src="'.htmlspecialchars($newmail_media)
246  ."\" hidden=\"true\" autostart=\"true\" width=\"2\" height=\"2\">\n";
247  }
248  if ($totalNew > 0 && $newmail_popup == 'on') {
249  echo "<script language=\"JavaScript\">\n".
250  "<!--\n".
251  "function PopupScriptLoad() {\n".
252  'window.open("'.sqm_baseuri().'plugins/newmail/newmail.php?numnew='.$totalNew.
253  '", "SMPopup",'.
254  "\"width=" . (int)$newmail_popup_width . ",height=" . (int)$newmail_popup_height . ",scrollbars=no\");\n".
255  "if (BeforePopupScript != null)\n".
256  "BeforePopupScript();\n".
257  "}\n".
258  "BeforePopupScript = window.onload;\n".
259  "window.onload = PopupScriptLoad;\n".
260  // Idea by: Nic Wolfe (Nic@TimelapseProductions.com)
261  // Web URL: http://fineline.xs.mw
262  // More code from Tyler Akins
263  "// End -->\n".
264  "</script>\n";
265  }
266  }
267 }
sqgetGlobalVar
sqgetGlobalVar($name, &$value, $search=SQ_INORDER)
Definition: global.php:344
$unseen_type
if($default_unseen_type=='') if($default_unseen_notify=='') $unseen_type
Definition: load_prefs.php:95
$media_enable
$media_enable
Definition: newmail_opt.php:28
$imapConnection
$imapConnection
Definition: message_details_bottom.php:74
$media_popup
$media_popup
Definition: newmail_opt.php:29
getPref
getPref($data_dir, $username, $string, $default='')
Definition: db_prefs.php:316
newmail_set_loadinfo
newmail_set_loadinfo()
Definition: setup.php:157
$imapServerAddress
$imapServerAddress
Definition: config_default.php:202
$unseen_notify
$unseen_notify
Definition: load_prefs.php:97
$data_dir
$data_dir
Definition: config_default.php:499
$optpage_name
if(!isset($optmode)) $optpage_name
Definition: options.php:168
$newmail_popup_width
$newmail_popup_width
Definition: newmail_opt.php:34
$media_allbox
$media_allbox
Definition: newmail_opt.php:30
$mailbox
$mailbox
Definition: options.php:28
setPref
setPref($data_dir, $username, $string, $set_to)
Definition: db_prefs.php:352
newmail_plugin
newmail_plugin()
Definition: setup.php:164
sprintf
powered by Systran sprintf(_("Number of supported language pairs: %s"), '36').' '
Definition: options.php:107
sqm_baseuri
sqm_baseuri()
Definition: strings.php:315
$trash_folder
$trash_folder
Definition: config_default.php:394
$newmail_popup_height
$newmail_popup_height
Definition: newmail_opt.php:33
$username
global $username
Definition: validate.php:55
$org_title
$org_title
Definition: config_default.php:61
$boxes
$boxes
Definition: empty_trash.php:49
newmail_pref
newmail_pref()
Definition: setup.php:135
$sent_folder
$sent_folder
Definition: config_default.php:395
$squirrelmail_plugin_hooks
global $squirrelmail_plugin_hooks
Definition: plugin.php:17
newmail_optpage_register_block
newmail_optpage_register_block()
Definition: setup.php:83
removePref
removePref($data_dir, $username, $string)
Definition: db_prefs.php:331
$folder_prefix
$folder_prefix
Definition: load_prefs.php:103
$media_recent
$media_recent
Definition: newmail_opt.php:31
squirrelmail_plugin_init_newmail
squirrelmail_plugin_init_newmail()
Definition: setup.php:73
SQ_POST
const SQ_POST
Definition: global.php:17
CheckNewMailboxSound
CheckNewMailboxSound($imapConnection, $mailbox, $real_box, $delimeter, $unseen, &$total_new)
Definition: setup.php:41
SM_PATH
const SM_PATH
Definition: decrypt_headers.php:16
newmail_sav
newmail_sav()
Definition: setup.php:99
sqimap_status_messages
sqimap_status_messages($imap_stream, $mailbox)
Definition: imap_general.php:932
_
_($str)
Definition: gettext.php:160
$media_changetitle
$media_changetitle
Definition: newmail_opt.php:32
$imapPort
$imapPort
Definition: config_default.php:210
$color
$color
Definition: load_prefs.php:28
sqimap_get_delimiter
sqimap_get_delimiter($imap_stream=false)
Definition: imap_general.php:681
$move_to_trash
$move_to_trash
Definition: load_prefs.php:84
sqimap_mailbox_list
sqimap_mailbox_list($imap_stream, $force=false)
Definition: imap_mailbox.php:597
soupNazi
soupNazi()
Definition: plugin.php:176