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)  

left_main.php
Go to the documentation of this file.
1 <?php
2 
16 define('PAGE_NAME', 'left_main');
17 
22 define('SM_PATH','../');
23 
24 /* SquirrelMail required files. */
25 require_once(SM_PATH . 'include/validate.php');
26 require_once(SM_PATH . 'functions/imap.php');
27 require_once(SM_PATH . 'functions/plugin.php');
28 require_once(SM_PATH . 'functions/page_header.php');
29 require_once(SM_PATH . 'functions/html.php');
30 
31 /* These constants are used for folder stuff. */
32 define('SM_BOX_UNCOLLAPSED', 0);
33 define('SM_BOX_COLLAPSED', 1);
34 
35 /* --------------------- FUNCTIONS ------------------------- */
36 
37 function formatMailboxName($imapConnection, $box_array) {
38 
40  $color, $move_to_sent, $move_to_trash,
44  $real_box = $box_array['unformatted'];
45  $mailbox = str_replace('&nbsp;','',$box_array['formatted']);
46  $mailboxURL = urlencode($real_box);
47 
48  /* Strip down the mailbox name. */
49  if (preg_match('/^( *)([^ ]*)$/', $mailbox, $regs)) {
50  $mailbox = $regs[2];
51  }
52  $unseen = 0;
53  $status = array('','');
54  if (($unseen_notify == 2 && $real_box == 'INBOX') ||
55  $unseen_notify == 3) {
56  $tmp_status = create_unseen_string($real_box, $box_array, $imapConnection, $unseen_type );
57  if ($status !== false) {
58  $status = $tmp_status;
59  }
60  }
61  list($unseen_string, $unseen) = $status;
62  $special_color = ($use_special_folder_color && isSpecialMailbox($real_box));
63 
64  /* Start off with a blank line. */
65  $line = '';
66 
67  /* If there are unseen message, bold the line. */
68  if ($unseen > 0) { $line .= '<b>'; }
69 
70  /* Create the link for this folder. */
71  if ($status !== false) {
72  $line .= '<a href="right_main.php?PG_SHOWALL=0&amp;sort=0&amp;startMessage=1&amp;mailbox='.
73  $mailboxURL.'" target="right" style="text-decoration:none">';
74  }
75  if ($special_color) {
76  $line .= "<font color=\"$color[11]\">";
77  }
78  if ( $mailbox == 'INBOX' ) {
79  $line .= _("INBOX");
80  } else {
81  $line .= str_replace(array(' ','<','>'),array('&nbsp;','&lt;','&gt;'),$mailbox);
82  }
83  if ($special_color == TRUE)
84  $line .= '</font>';
85  if ($status !== false) {
86  $line .= '</a>';
87  }
88 
89  /* If there are unseen message, close bolding. */
90  if ($unseen > 0) { $line .= "</b>"; }
91 
92  /* Print unseen information. */
93  if ($unseen_string != '') {
94  $line .= "&nbsp;<small>$unseen_string</small>";
95  }
96 
97  /* If it's the trash folder, show a purge link when needed */
98  if (($move_to_trash) && ($real_box == $trash_folder)) {
99  if (! isset($numMessages)) {
100  $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
101  }
102 
103  if (($numMessages > 0) or ($box_array['parent'] == 1)) {
104  $urlMailbox = urlencode($real_box);
105  $line .= "\n<small>\n" .
106  '&nbsp;&nbsp;(<a href="empty_trash.php?smtoken=' . sm_generate_security_token() . '" style="text-decoration:none">'._("Purge").'</a>)' .
107  '</small>';
108  }
109  }
110 
111  $line .= concat_hook_function('left_main_after_each_folder',
112  array(isset($numMessages) ? $numMessages : '',
113  $real_box, $imapConnection));
114 
115  /* Return the final product. */
116  return ($line);
117 }
118 
124 function compute_folder_children(&$parbox, $boxcount) {
126  $nextbox = $parbox + 1;
127 
128  /* Retreive the name for the parent box. */
129  $parbox_name = $boxes[$parbox]['unformatted'];
130 
131  /* 'Initialize' this parent box to childless. */
132  $boxes[$parbox]['parent'] = FALSE;
133 
134  /* Compute the collapse status for this box. */
135  if( isset($collapse_folders) && $collapse_folders ) {
136  $collapse = getPref($data_dir, $username, 'collapse_folder_' . $parbox_name);
137  $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse);
138  } else {
139  $collapse = SM_BOX_UNCOLLAPSED;
140  }
141  $boxes[$parbox]['collapse'] = $collapse;
142 
143  /* Otherwise, get the name of the next box. */
144  if (isset($boxes[$nextbox]['unformatted'])) {
145  $nextbox_name = $boxes[$nextbox]['unformatted'];
146  } else {
147  $nextbox_name = '';
148  }
149 
150  /* Compute any children boxes for this box. */
151  while (($nextbox < $boxcount) &&
152  (is_parent_box($boxes[$nextbox]['unformatted'], $parbox_name))) {
153 
154  /* Note that this 'parent' box has at least one child. */
155  $boxes[$parbox]['parent'] = TRUE;
156 
157  /* Compute the visiblity of this box. */
158  $boxes[$nextbox]['visible'] = ($boxes[$parbox]['visible'] &&
159  ($boxes[$parbox]['collapse'] != SM_BOX_COLLAPSED));
160 
161  /* Compute the visibility of any child boxes. */
163  }
164 
165  /* Set the parent box to the current next box. */
166  $parbox = $nextbox;
167 }
168 
174 function create_collapse_link($boxnum) {
176  $mailbox = urlencode($boxes[$boxnum]['unformatted']);
177 
178  /* Create the link for this collapse link. */
179  $link = '<a target="left" style="text-decoration:none" ' .
180  'href="left_main.php?';
181  if ($boxes[$boxnum]['collapse'] == SM_BOX_COLLAPSED) {
182  $link .= "unfold=$mailbox\">+";
183  } else {
184  $link .= "fold=$mailbox\">-";
185  }
186  $link .= '</a>';
187 
188  /* Return the finished product. */
189  return ($link);
190 }
191 
204 function create_unseen_string($boxName, $boxArray, $imapConnection, $unseen_type) {
206 
207  /* Initialize the return value. */
208  $result = array(0,0);
209 
210  /* Initialize the counts for this folder. */
211  $boxUnseenCount = 0;
212  $boxMessageCount = 0;
213  $totalUnseenCount = 0;
214  $totalMessageCount = 0;
215 
216  /* Collect the counts for this box alone. */
217  $status = sqimap_status_messages($imapConnection, $boxName);
218  $boxUnseenCount = $status['UNSEEN'];
219  if ($boxUnseenCount === false) {
220  return false;
221  }
222  if ($unseen_type == 2) {
223  $boxMessageCount = $status['MESSAGES'];
224  }
225 
226  /* Initialize the total counts. */
227 
228  if ($boxArray['collapse'] == SM_BOX_COLLAPSED && $unseen_cum) {
229  /* Collect the counts for this boxes subfolders. */
230  $curBoxLength = strlen($boxName);
231  $boxCount = count($boxes);
232 
233  for ($i = 0; $i < $boxCount; ++$i) {
234  /* Initialize the counts for this subfolder. */
235  $subUnseenCount = 0;
236  $subMessageCount = 0;
237 
238  /* Collect the counts for this subfolder. */
239  if (($boxName != $boxes[$i]['unformatted'])
240  && (substr($boxes[$i]['unformatted'], 0, $curBoxLength) == $boxName)
241  && !in_array('noselect', $boxes[$i]['flags'])) {
242  $status = sqimap_status_messages($imapConnection, $boxes[$i]['unformatted']);
243  $subUnseenCount = $status['UNSEEN'];
244  if ($unseen_type == 2) {
245  $subMessageCount = $status['MESSAGES'];;
246  }
247  /* Add the counts for this subfolder to the total. */
248  $totalUnseenCount += $subUnseenCount;
249  $totalMessageCount += $subMessageCount;
250  }
251  }
252 
253  /* Add the counts for all subfolders to that of the box. */
254  $boxUnseenCount += $totalUnseenCount;
255  $boxMessageCount += $totalMessageCount;
256  }
257 
258  /* And create the magic unseen count string. */
259  /* Really a lot more then just the unseen count. */
260  if (($unseen_type == 1) && ($boxUnseenCount > 0)) {
261  $result[0] = "($boxUnseenCount)";
262  } else if ($unseen_type == 2) {
263  $result[0] = "($boxUnseenCount/$boxMessageCount)";
264  $result[0] = "<font color=\"$color[11]\">$result[0]</font>";
265  }
266 
267  /* Set the unseen count to return to the outside world. */
268  $result[1] = $boxUnseenCount;
269 
270  /* Return our happy result. */
271  return ($result);
272 }
273 
277 function is_parent_box($curbox_name, $parbox_name) {
278  global $delimiter;
279 
280  /* Extract the name of the parent of the current box. */
281  $curparts = explode($delimiter, $curbox_name);
282  $curname = array_pop($curparts);
283  $actual_parname = implode($delimiter, $curparts);
284  $actual_parname = substr($actual_parname,0,strlen($parbox_name));
285 
286  /* Compare the actual with the given parent name. */
287  return ($parbox_name == $actual_parname);
288 }
289 
290 
291 /* -------------------- MAIN ------------------------ */
292 
293 /* get globals */
294 sqgetGlobalVar('username', $username, SQ_SESSION);
295 sqgetGlobalVar('key', $key, SQ_COOKIE);
296 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
297 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
298 
299 sqgetGlobalVar('fold', $fold, SQ_GET);
300 sqgetGlobalVar('unfold', $unfold, SQ_GET);
301 sqgetGlobalVar('auto_create_done',$auto_create_done,SQ_SESSION);
302 
303 /* end globals */
304 
305 // Disable browser caching //
306 header('Cache-Control: no-cache, no-store, must-revalidate');
307 header('Pragma: no-cache');
308 header('Expires: Sat, 1 Jan 2000 00:00:00 GMT');
309 
310 // open a connection on the imap port (143)
311 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
312 
316 if (isset($left_refresh) && ($left_refresh != '') &&
317  !stristr($left_refresh, 'none')){
318  $xtra = "\n<meta http-equiv=\"REFRESH\" content=\"$left_refresh;URL=left_main.php\">\n";
319 } else {
320  $xtra = '';
321 }
322 
324 
325 /* If requested and not yet complete, attempt to autocreate folders. */
326 if ($auto_create_special && !$auto_create_done) {
327  $autocreate = array($sent_folder, $trash_folder, $draft_folder);
328  foreach( $autocreate as $folder ) {
329  if (($folder != '') && ($folder != 'none')) {
330  if ( !sqimap_mailbox_exists($imapConnection, $folder)) {
332  } else if (!sqimap_mailbox_is_subscribed($imapConnection, $folder)) {
334  }
335  }
336  }
337 
338  /* Let the world know that autocreation is complete! Hurrah! */
339  $auto_create_done = TRUE;
340  sqsession_register($auto_create_done, 'auto_create_done');
341  /* retrieve the mailboxlist. We do this at a later stage again but if
342  the right_frame loads faster then the second call retrieves a cached
343  version of the mailboxlist without the newly created folders.
344  The second parameter forces a non cached mailboxlist return.
345  */
347 }
348 
349 echo "\n<body bgcolor=\"$color[3]\" text=\"$color[6]\" link=\"$color[6]\" vlink=\"$color[6]\" alink=\"$color[6]\">\n";
350 
351 do_hook('left_main_before');
352 
353 echo "\n\n" . html_tag( 'table', '', 'left', '', 'border="0" cellspacing="0" cellpadding="0" width="99%"' ) .
354  html_tag( 'tr' ) .
355  html_tag( 'td', '', 'left' ) .
356  html_tag( 'table', '', '', '', 'border="0" cellspacing="0" cellpadding="0"' ) .
357  html_tag( 'tr' ) .
358  html_tag( 'td', '', 'center' ) .
359  '<font size="4"><b>'. _("Folders") . "</b><br /></font>\n\n";
360 
361 if ($date_format != 6) {
362  /* First, display the clock. */
363  if ($hour_format == 1) {
364  $hr = 'H:i';
365  if ($date_format == 4) {
366  $hr .= ':s';
367  }
368  } else {
369  if ($date_format == 4) {
370  $hr = 'g:i:s a';
371  } else {
372  $hr = 'g:i a';
373  }
374  }
375 
376  switch( $date_format ) {
377  case 0:
378  $clk = date('Y-m-d '.$hr. ' T', time());
379  break;
380  case 1:
381  $clk = date('m/d/y '.$hr, time());
382  break;
383  case 2:
384  $clk = date('d/m/y '.$hr, time());
385  break;
386  case 4:
387  case 5:
388  $clk = date($hr, time());
389  break;
390  default:
391  $clk = getDayAbrv( date( 'w', time() ) ) . date( ', ' . $hr, time() );
392  }
393  $clk = str_replace(' ','&nbsp;',$clk);
394 
395  echo '<small><span style="white-space: nowrap;">'
396  . str_replace(' ', '&nbsp;', _("Last Refresh"))
397  . ":</span><br /><span style=\"white-space: nowrap;\">$clk</span></small><br />";
398 }
399 
400 /* Next, display the refresh button. */
401 echo '<small style="white-space: nowrap;">(<a href="../src/left_main.php" target="left">'.
402  _("Check mail") . '</a>)</small></td></tr></table><br />';
403 
404 /* Lastly, display the folder list. */
405 if ( $collapse_folders ) {
406  /* If directed, collapse or uncollapse a folder. */
407  if (isset($fold)) {
408  setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED);
409  } else if (isset($unfold)) {
410  setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED);
411  }
412 }
413 
414 sqgetGlobalVar('force_refresh',$force_refresh,SQ_GET);
415 if (!isset($boxes)) { // auto_create_done
416  $boxes = sqimap_mailbox_list($imapConnection,$force_refresh);
417 }
418 /* Prepare do do out collapsedness and visibility computation. */
420 $boxcount = count($boxes);
421 
422 /* Compute the collapsedness and visibility of each box. */
423 
424 while ($curbox < $boxcount) {
425  $boxes[$curbox]['visible'] = TRUE;
427 }
428 
429 for ($i = 0; $i < count($boxes); $i++) {
430  if ( $boxes[$i]['visible'] ) {
431  $mailbox = $boxes[$i]['formatted'];
432  // remove folder_prefix using substr so folders aren't indented unnecessarily
433  $mblevel = substr_count(substr($boxes[$i]['unformatted'], strlen($folder_prefix)), $delimiter) + 1;
434 
435  /* Create the prefix for the folder name and link. */
436  $prefix = str_repeat(' ',$mblevel);
437  if (isset($collapse_folders) && $collapse_folders && $boxes[$i]['parent']) {
438  $prefix = str_replace(' ','&nbsp;',substr($prefix,0,strlen($prefix)-2)).
439  create_collapse_link($i) . '&nbsp;';
440  } else {
441  $prefix = str_replace(' ','&nbsp;',$prefix);
442  }
443  $line = "<span style=\"white-space: nowrap;\"><tt>$prefix</tt>";
444 
445  /* Add the folder name and link. */
446  if (! isset($color[15])) {
447  $color[15] = $color[6];
448  }
449 
450  if (in_array('noselect', $boxes[$i]['flags'])) {
451  if( isSpecialMailbox( $boxes[$i]['unformatted']) ) {
452  $line .= "<font color=\"$color[11]\">";
453  } else {
454  $line .= "<font color=\"$color[15]\">";
455  }
456  if (preg_match('/^( *)([^ ]*)/', $mailbox, $regs)) {
457  $mailbox = str_replace('&nbsp;','',$mailbox);
458  $line .= str_replace(' ', '&nbsp;', $mailbox);
459  }
460  $line .= '</font>';
461  } else {
463  }
464 
465  /* Put the final touches on our folder line. */
466  $line .= "</span><br />\n";
467 
468  /* Output the line for this folder. */
469  echo $line;
470  }
471 }
472 
473 do_hook('left_main_after');
475 
476 ?>
477 </td></tr></table>
478 </body></html>
create_unseen_string
create_unseen_string($boxName, $boxArray, $imapConnection, $unseen_type)
Definition: left_main.php:204
sqgetGlobalVar
sqgetGlobalVar($name, &$value, $search=SQ_INORDER)
Definition: global.php:344
formatMailboxName
formatMailboxName($imapConnection, $box_array)
Definition: left_main.php:37
$unseen_type
if($default_unseen_type=='') if($default_unseen_notify=='') $unseen_type
Definition: load_prefs.php:95
getPref
getPref($data_dir, $username, $string, $default='')
Definition: db_prefs.php:316
$imapConnection
$imapConnection
Definition: left_main.php:311
html_tag
html_tag( $tag, $val='', $align='', $bgcolor='', $xtra='')
Definition: html.php:27
is_parent_box
is_parent_box($curbox_name, $parbox_name)
Definition: left_main.php:277
$imapServerAddress
$imapServerAddress
Definition: config_default.php:202
sqimap_login
sqimap_login($username, $password, $imap_server_address, $imap_port, $hide)
Definition: imap_general.php:481
$draft_folder
$draft_folder
Definition: config_default.php:396
$unseen_notify
$unseen_notify
Definition: load_prefs.php:97
isSpecialMailbox
isSpecialMailbox($box, $include_subs=true)
Definition: imap_mailbox.php:118
$data_dir
$data_dir
Definition: config_default.php:499
SQ_SESSION
const SQ_SESSION
Definition: global.php:18
sqimap_mailbox_exists
sqimap_mailbox_exists($imap_stream, $mailbox)
Definition: imap_mailbox.php:226
$mailbox
$mailbox
Definition: options.php:28
setPref
setPref($data_dir, $username, $string, $set_to)
Definition: db_prefs.php:352
concat_hook_function
concat_hook_function($name, $parm=NULL)
Definition: plugin.php:96
SM_BOX_COLLAPSED
const SM_BOX_COLLAPSED
Definition: left_main.php:33
html
Definition: html.class.php:18
$trash_folder
$trash_folder
Definition: config_default.php:394
$username
global $username
Definition: validate.php:55
sqimap_mailbox_create
sqimap_mailbox_create($imap_stream, $mailbox, $type)
Definition: imap_mailbox.php:296
$auto_create_special
$auto_create_special
Definition: config_default.php:416
do_hook
do_hook($name)
Definition: plugin.php:42
getDayAbrv
getDayAbrv( $day_number)
Definition: date.php:147
$org_title
$org_title
Definition: config_default.php:61
$boxes
$boxes
Definition: empty_trash.php:49
$sent_folder
$sent_folder
Definition: config_default.php:395
sqimap_logout
sqimap_logout($imap_stream)
Definition: imap_general.php:639
$save_as_draft
$save_as_draft
Definition: load_prefs.php:86
$folder_prefix
$folder_prefix
Definition: load_prefs.php:103
sm_generate_security_token
sm_generate_security_token()
Definition: strings.php:1340
SQ_GET
const SQ_GET
Definition: global.php:16
create_collapse_link
create_collapse_link($boxnum)
Definition: left_main.php:174
$curbox
if(!isset($boxes)) $curbox
Definition: left_main.php:419
displayHtmlHeader
displayHtmlHeader( $title='SquirrelMail', $xtra='', $do_hook=TRUE)
Definition: page_header.php:21
sqimap_get_num_messages
sqimap_get_num_messages($imap_stream, $mailbox)
Definition: imap_general.php:729
sqimap_subscribe
sqimap_subscribe($imap_stream, $mailbox)
Definition: imap_mailbox.php:312
sqimap_status_messages
sqimap_status_messages($imap_stream, $mailbox)
Definition: imap_general.php:932
sqsession_register
sqsession_register($var, $name)
Definition: global.php:289
_
_($str)
Definition: gettext.php:160
SM_PATH
const SM_PATH
Definition: left_main.php:22
$unseen_cum
$unseen_cum
Definition: load_prefs.php:100
SM_BOX_UNCOLLAPSED
const SM_BOX_UNCOLLAPSED
Definition: left_main.php:32
sqimap_mailbox_is_subscribed
sqimap_mailbox_is_subscribed($imap_stream, $folder)
Definition: imap_mailbox.php:348
$imapPort
$imapPort
Definition: config_default.php:210
$collapse_folders
$collapse_folders
Definition: load_prefs.php:219
$boxcount
$boxcount
Definition: left_main.php:420
$xtra
for($i=1; $i< $count; $i++) $xtra
Definition: message_details_bottom.php:253
$color
$color
Definition: load_prefs.php:28
SQ_COOKIE
const SQ_COOKIE
Definition: global.php:19
$use_special_folder_color
$use_special_folder_color
Definition: config_default.php:407
$date_format
$date_format
Definition: load_prefs.php:247
compute_folder_children
compute_folder_children(&$parbox, $boxcount)
Definition: left_main.php:124
$left_refresh
$left_refresh
Definition: load_prefs.php:167
$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
$hour_format
$hour_format
Definition: load_prefs.php:248