Source for file left_main.php

Documentation is available at left_main.php

  1. <?php
  2. /**
  3. * left_main.php
  4. *
  5. * This is the code for the left bar. The left bar shows the folders
  6. * available, and has cookie information.
  7. *
  8. * @copyright 1999-2020 The SquirrelMail Project Team
  9. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10. * @version $Id: left_main.php 14840 2020年01月07日 07:42:38Z pdontthink $
  11. * @package squirrelmail
  12. */
  13. /** This is the left_main page */
  14. define ('PAGE_NAME', 'left_main');
  15. /**
  16. * Path for SquirrelMail required files.
  17. * @ignore
  18. */
  19. define ('SM_PATH','../');
  20. $script_libs = array();
  21. /* SquirrelMail required files. */
  22. require_once(SM_PATH . 'include/validate.php');
  23. require_once(SM_PATH . 'functions/imap.php');
  24. require_once(SM_PATH . 'functions/plugin.php');
  25. require_once(SM_PATH . 'functions/page_header.php');
  26. require_once(SM_PATH . 'functions/html.php');
  27. /* These constants are used for folder stuff. */
  28. define ('SM_BOX_UNCOLLAPSED', 0);
  29. define ('SM_BOX_COLLAPSED', 1);
  30. /* --------------------- FUNCTIONS ------------------------- */
  31. function formatMailboxName ($imapConnection, $box_array) {
  32. global $folder_prefix, $trash_folder, $sent_folder,
  33. $color, $move_to_sent, $move_to_trash,
  34. $unseen_notify, $unseen_type, $collapse_folders,
  35. $draft_folder, $save_as_draft,
  36. $real_box = $box_array['unformatted'];
  37. $mailbox = str_replace ('&nbsp;','',$box_array['formatted']);
  38. $mailboxURL = urlencode ($real_box);
  39. /* Strip down the mailbox name. */
  40. if (preg_match ('/^( *)([^ ]*)$/', $mailbox, $regs)) {
  41. $mailbox = $regs[2];
  42. }
  43. $unseen = 0;
  44. $status = array('','');
  45. if (($unseen_notify == 2 && $real_box == 'INBOX') ||
  46. $unseen_notify == 3) {
  47. $tmp_status = create_unseen_string ($real_box, $box_array, $imapConnection, $unseen_type );
  48. if ($status !== false) {
  49. $status = $tmp_status;
  50. }
  51. }
  52. list($unseen_string, $unseen) = $status;
  53. $special_color = ($use_special_folder_color && isSpecialMailbox ($real_box));
  54. /* Start off with a blank line. */
  55. $line = '';
  56. /* If there are unseen message, bold the line. */
  57. if ($unseen > 0) { $line .= '<b>'; }
  58. /* Create the link for this folder. */
  59. if ($status !== false) {
  60. $line .= '<a href="right_main.php?PG_SHOWALL=0&amp;sort=0&amp;startMessage=1&amp;mailbox='.
  61. $mailboxURL.'" target="right" title="' . ($mailbox == 'INBOX' ? _ ("INBOX") : $mailbox) . '" style="text-decoration:none">';
  62. }
  63. if ($special_color) {
  64. $line .= "<font color=\"$color[11]\">";
  65. }
  66. if ( $mailbox == 'INBOX' ) {
  67. $line .= _ ("INBOX");
  68. } else {
  69. $line .= str_replace (array(' ','<','>'),array('&nbsp;','&lt;','&gt;'),$mailbox);
  70. }
  71. if ($special_color == TRUE)
  72. $line .= '</font>';
  73. if ($status !== false) {
  74. $line .= '</a>';
  75. }
  76. /* If there are unseen message, close bolding. */
  77. if ($unseen > 0) { $line .= "</b>"; }
  78. /* Print unseen information. */
  79. if ($unseen_string != '') {
  80. $line .= "&nbsp;<small>$unseen_string</small>";
  81. }
  82. /* If it's the trash folder, show a purge link when needed */
  83. if (($move_to_trash) && ($real_box == $trash_folder)) {
  84. if (! isset($numMessages)) {
  85. $numMessages = sqimap_get_num_messages ($imapConnection, $real_box);
  86. }
  87. if (($numMessages > 0) or ($box_array['parent'] == 1)) {
  88. $urlMailbox = urlencode ($real_box);
  89. $line .= "\n<small>\n" .
  90. '&nbsp;&nbsp;(<a href="empty_trash.php?smtoken=' . sm_generate_security_token () . '" style="text-decoration:none">'._ ("Purge").'</a>)' .
  91. '</small>';
  92. }
  93. }
  94. $line .= concat_hook_function ('left_main_after_each_folder',
  95. array(isset($numMessages) ? $numMessages : '',
  96. $real_box, $imapConnection));
  97. /* Return the final product. */
  98. return ($line);
  99. }
  100. /**
  101. * Recursive function that computes the collapsed status and parent
  102. * (or not parent) status of this box, and the visiblity and collapsed
  103. * status and parent (or not parent) status for all children boxes.
  104. */
  105. function compute_folder_children (&$parbox, $boxcount) {
  106. global $boxes, $data_dir , $username, $collapse_folders;
  107. $nextbox = $parbox + 1;
  108. /* Retreive the name for the parent box. */
  109. $parbox_name = $boxes[$parbox]['unformatted'];
  110. /* 'Initialize' this parent box to childless. */
  111. $boxes[$parbox]['parent'] = FALSE;
  112. /* Compute the collapse status for this box. */
  113. if( isset($collapse_folders) && $collapse_folders ) {
  114. $collapse = getPref ($data_dir, $username, 'collapse_folder_' . $parbox_name);
  115. $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse);
  116. } else {
  117. $collapse = SM_BOX_UNCOLLAPSED ;
  118. }
  119. $boxes[$parbox]['collapse'] = $collapse;
  120. /* Otherwise, get the name of the next box. */
  121. if (isset($boxes[$nextbox]['unformatted'])) {
  122. $nextbox_name = $boxes[$nextbox]['unformatted'];
  123. } else {
  124. $nextbox_name = '';
  125. }
  126. /* Compute any children boxes for this box. */
  127. while (($nextbox < $boxcount) &&
  128. (is_parent_box ($boxes[$nextbox]['unformatted'], $parbox_name))) {
  129. /* Note that this 'parent' box has at least one child. */
  130. $boxes[$parbox]['parent'] = TRUE;
  131. /* Compute the visiblity of this box. */
  132. $boxes[$nextbox]['visible'] = ($boxes[$parbox]['visible'] &&
  133. ($boxes[$parbox]['collapse'] != SM_BOX_COLLAPSED ));
  134. /* Compute the visibility of any child boxes. */
  135. compute_folder_children ($nextbox, $boxcount);
  136. }
  137. /* Set the parent box to the current next box. */
  138. $parbox = $nextbox;
  139. }
  140. /**
  141. * Create the link for a parent folder that will allow that
  142. * parent folder to either be collapsed or expaned, as is
  143. * currently appropriate.
  144. */
  145. function create_collapse_link ($boxnum) {
  146. global $boxes, $imapConnection, $unseen_notify, $color;
  147. $mailbox = urlencode ($boxes[$boxnum]['unformatted']);
  148. /* Create the link for this collapse link. */
  149. $link = '<a target="left" style="text-decoration:none" ' .
  150. 'href="left_main.php?';
  151. if ($boxes[$boxnum]['collapse'] == SM_BOX_COLLAPSED ) {
  152. $link .= "unfold=$mailbox\">+";
  153. } else {
  154. $link .= "fold=$mailbox\">-";
  155. }
  156. $link .= '</a>';
  157. /* Return the finished product. */
  158. return ($link);
  159. }
  160. /**
  161. * create_unseen_string:
  162. *
  163. * Create unseen and total message count for both this folder and
  164. * it's subfolders.
  165. *
  166. * @param string $boxName name of the current mailbox
  167. * @param array $boxArray array for the current mailbox
  168. * @param $imapConnection current imap connection in use
  169. * @return array[0] unseen message string (for display)
  170. * @return array[1] unseen message count
  171. */
  172. function create_unseen_string ($boxName, $boxArray, $imapConnection, $unseen_type) {
  173. global $boxes, $unseen_type, $color, $unseen_cum;
  174. /* Initialize the return value. */
  175. $result = array(0,0);
  176. /* Initialize the counts for this folder. */
  177. $boxUnseenCount = 0;
  178. $boxMessageCount = 0;
  179. $totalUnseenCount = 0;
  180. $totalMessageCount = 0;
  181. /* Collect the counts for this box alone. */
  182. $status = sqimap_status_messages ($imapConnection, $boxName);
  183. $boxUnseenCount = $status['UNSEEN'];
  184. if ($boxUnseenCount === false) {
  185. return false;
  186. }
  187. if ($unseen_type == 2) {
  188. $boxMessageCount = $status['MESSAGES'];
  189. }
  190. /* Initialize the total counts. */
  191. if ($boxArray['collapse'] == SM_BOX_COLLAPSED && $unseen_cum) {
  192. /* Collect the counts for this boxes subfolders. */
  193. $curBoxLength = strlen ($boxName);
  194. $boxCount = count ($boxes);
  195. for ($i = 0; $i < $boxCount; ++$i) {
  196. /* Initialize the counts for this subfolder. */
  197. $subUnseenCount = 0;
  198. $subMessageCount = 0;
  199. /* Collect the counts for this subfolder. */
  200. if (($boxName != $boxes[$i]['unformatted'])
  201. && (substr ($boxes[$i]['unformatted'], 0, $curBoxLength) == $boxName)
  202. && !in_array ('noselect', $boxes[$i]['flags'])) {
  203. $status = sqimap_status_messages ($imapConnection, $boxes[$i]['unformatted']);
  204. $subUnseenCount = $status['UNSEEN'];
  205. if ($unseen_type == 2) {
  206. $subMessageCount = $status['MESSAGES'];;
  207. }
  208. /* Add the counts for this subfolder to the total. */
  209. $totalUnseenCount += $subUnseenCount;
  210. $totalMessageCount += $subMessageCount;
  211. }
  212. }
  213. /* Add the counts for all subfolders to that of the box. */
  214. $boxUnseenCount += $totalUnseenCount;
  215. $boxMessageCount += $totalMessageCount;
  216. }
  217. /* And create the magic unseen count string. */
  218. /* Really a lot more then just the unseen count. */
  219. if (($unseen_type == 1) && ($boxUnseenCount > 0)) {
  220. $result[0] = "($boxUnseenCount)";
  221. } else if ($unseen_type == 2) {
  222. $result[0] = "($boxUnseenCount/$boxMessageCount)";
  223. $result[0] = "<font color=\"$color[11]\">$result[0]</font>";
  224. }
  225. /* Set the unseen count to return to the outside world. */
  226. $result[1] = $boxUnseenCount;
  227. /* Return our happy result. */
  228. return ($result);
  229. }
  230. /**
  231. * This simple function checks if a box is another box's parent.
  232. */
  233. function is_parent_box ($curbox_name, $parbox_name) {
  234. global $delimiter;
  235. /* Extract the name of the parent of the current box. */
  236. $curparts = explode ($delimiter, $curbox_name);
  237. $curname = array_pop ($curparts);
  238. $actual_parname = implode ($delimiter, $curparts);
  239. $actual_parname = substr ($actual_parname,0,strlen ($parbox_name));
  240. /* Compare the actual with the given parent name. */
  241. return ($parbox_name == $actual_parname);
  242. }
  243. /* -------------------- MAIN ------------------------ */
  244. /* get globals */
  245. sqgetGlobalVar ('username', $username, SQ_SESSION );
  246. sqgetGlobalVar ('key', $key, SQ_COOKIE );
  247. sqgetGlobalVar ('delimiter', $delimiter, SQ_SESSION );
  248. sqgetGlobalVar ('onetimepad', $onetimepad, SQ_SESSION );
  249. sqgetGlobalVar ('fold', $fold, SQ_GET );
  250. sqgetGlobalVar ('unfold', $unfold, SQ_GET );
  251. sqgetGlobalVar ('auto_create_done',$auto_create_done,SQ_SESSION );
  252. /* end globals */
  253. // Disable browser caching //
  254. header ('Cache-Control: no-cache, no-store, must-revalidate');
  255. header ('Pragma: no-cache');
  256. header ('Expires: Sat, 1 Jan 2000 00:00:00 GMT');
  257. // open a connection to the IMAP server
  258. global $imap_stream_options; // in case not defined in config
  259. $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 10, $imap_stream_options); // the 10 is to hide the output
  260. /**
  261. * Using stristr since older preferences may contain "None" and "none".
  262. */
  263. $xtra = '';
  264. if (isset($left_refresh) && ($left_refresh != '') &&
  265. !stristr ($left_refresh, 'none')){
  266. if ($javascript_on
  267. && ($check_mail_mechanism === 'basic' || $check_mail_mechanism === 'advanced')) {
  268. $script_libs[] = SM_SCRIPT_LIB_REMOTE_REQUEST ;
  269. $script_libs[] = SM_SCRIPT_LIB_RELOAD_PAGE ;
  270. // NB: we could use $script_libs instead of $xtra - they both do the same thing for adding free-form extra script tags
  271. // FIXME: the "advanced" version of the JavaScript check mail feature could be triggered by browser detection (brief testing shows that at least IE 8 doesn't like the advanced version).... but for now, just let admin decide in system settings
  272. $xtra = "\n<script language=\"JavaScript\" type=\"text/javascript\">\n<!--\nvar base_uri = '" . $base_uri . "';\nvar reload_interval = " . $left_refresh . ";\nvar use_advanced_page_reload = " . ($check_mail_mechanism === 'advanced' ? "true;\n" : "false;\n") . "// -->\n</script>\n";
  273. } else {
  274. $xtra = "\n<meta http-equiv=\"REFRESH\" content=\"$left_refresh;URL=left_main.php\">\n";
  275. }
  276. }
  277. displayHtmlHeader ( $org_title, $xtra, TRUE, $script_libs );
  278. /* If requested and not yet complete, attempt to autocreate folders. */
  279. if ($auto_create_special && !$auto_create_done) {
  280. $autocreate = array($sent_folder, $trash_folder, $draft_folder);
  281. foreach( $autocreate as $folder ) {
  282. if (($folder != '') && ($folder != 'none')) {
  283. if ( !sqimap_mailbox_exists ($imapConnection, $folder)) {
  284. sqimap_mailbox_create ($imapConnection, $folder, '');
  285. } else if (!sqimap_mailbox_is_subscribed ($imapConnection, $folder)) {
  286. sqimap_subscribe ($imapConnection, $folder);
  287. }
  288. }
  289. }
  290. /* Let the world know that autocreation is complete! Hurrah! */
  291. $auto_create_done = TRUE;
  292. sqsession_register ($auto_create_done, 'auto_create_done');
  293. /* retrieve the mailboxlist. We do this at a later stage again but if
  294. the right_frame loads faster then the second call retrieves a cached
  295. version of the mailboxlist without the newly created folders.
  296. The second parameter forces a non cached mailboxlist return.
  297. */
  298. $boxes = sqimap_mailbox_list ($imapConnection,true);
  299. }
  300. echo "\n<body bgcolor=\"$color[3]\" text=\"$color[6]\" link=\"$color[6]\" vlink=\"$color[6]\" alink=\"$color[6]\">\n";
  301. do_hook ('left_main_before');
  302. echo "\n\n" . html_tag ( 'table', '', 'left', '', 'border="0" cellspacing="0" cellpadding="0" width="99%"' ) .
  303. html_tag ( 'tr' ) .
  304. html_tag ( 'td', '', 'left' ) .
  305. html_tag ( 'table', '', '', '', 'border="0" cellspacing="0" cellpadding="0"' ) .
  306. html_tag ( 'tr' ) .
  307. html_tag ( 'td', '', 'center' ) .
  308. '<font size="4"><b>'. _ ("Folders") . "</b><br /></font>\n\n";
  309. if ($date_format != 6) {
  310. /* First, display the clock. */
  311. if ($hour_format == 1) {
  312. $hr = 'H:i';
  313. if ($date_format == 4) {
  314. $hr .= ':s';
  315. }
  316. } else {
  317. if ($date_format == 4) {
  318. $hr = 'g:i:s a';
  319. } else {
  320. $hr = 'g:i a';
  321. }
  322. }
  323. switch( $date_format ) {
  324. case 0:
  325. $clk = date ('Y-m-d '.$hr. ' T', time ());
  326. break;
  327. case 1:
  328. $clk = date ('m/d/y '.$hr, time ());
  329. break;
  330. case 2:
  331. $clk = date ('d/m/y '.$hr, time ());
  332. break;
  333. case 4:
  334. case 5:
  335. $clk = date ($hr, time ());
  336. break;
  337. default:
  338. $clk = getDayAbrv ( date ( 'w', time () ) ) . date ( ', ' . $hr, time () );
  339. }
  340. $clk = str_replace (' ','&nbsp;',$clk);
  341. echo '<small><span style="white-space: nowrap;">'
  342. . str_replace (' ', '&nbsp;', _ ("Last Refresh"))
  343. . ":</span><br /><span style=\"white-space: nowrap;\">$clk</span></small><br />";
  344. }
  345. /* Next, display the refresh button. */
  346. echo '<small style="white-space: nowrap;">(<a href="../src/left_main.php" target="left">'.
  347. _ ("Check mail") . '</a>)</small></td></tr></table><br />';
  348. /* Lastly, display the folder list. */
  349. if ( $collapse_folders ) {
  350. /* If directed, collapse or uncollapse a folder. */
  351. if (isset($fold)) {
  352. setPref ($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED );
  353. } else if (isset($unfold)) {
  354. setPref ($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED );
  355. }
  356. }
  357. sqgetGlobalVar ('force_refresh',$force_refresh,SQ_GET );
  358. if (!isset($boxes)) { // auto_create_done
  359. $boxes = sqimap_mailbox_list ($imapConnection,$force_refresh);
  360. }
  361. /* Prepare do do out collapsedness and visibility computation. */
  362. $curbox = 0;
  363. $boxcount = count ($boxes);
  364. /* Compute the collapsedness and visibility of each box. */
  365. while ($curbox < $boxcount) {
  366. $boxes[$curbox]['visible'] = TRUE;
  367. compute_folder_children ($curbox, $boxcount);
  368. }
  369. for ($i = 0; $i < count ($boxes); $i++) {
  370. if ( $boxes[$i]['visible'] ) {
  371. $mailbox = $boxes[$i]['formatted'];
  372. // remove folder_prefix using substr so folders aren't indented unnecessarily
  373. $mblevel = substr_count (substr ($boxes[$i]['unformatted'], strlen ($folder_prefix)), $delimiter) + 1;
  374. /* Create the prefix for the folder name and link. */
  375. $prefix = str_repeat (' ',$mblevel);
  376. if (isset($collapse_folders) && $collapse_folders && $boxes[$i]['parent']) {
  377. $prefix = str_replace (' ','&nbsp;',substr ($prefix,0,strlen ($prefix)-2)).
  378. create_collapse_link ($i) . '&nbsp;';
  379. } else {
  380. $prefix = str_replace (' ','&nbsp;',$prefix);
  381. }
  382. $line = "<span style=\"white-space: nowrap;\"><tt>$prefix</tt>";
  383. /* Add the folder name and link. */
  384. if (! isset($color[15])) {
  385. $color[15] = $color[6];
  386. }
  387. if (in_array ('noselect', $boxes[$i]['flags'])) {
  388. if( isSpecialMailbox ( $boxes[$i]['unformatted']) ) {
  389. $line .= "<font color=\"$color[11]\">";
  390. } else {
  391. $line .= "<font color=\"$color[15]\">";
  392. }
  393. if (preg_match ('/^( *)([^ ]*)/', $mailbox, $regs)) {
  394. $mailbox = str_replace ('&nbsp;','',$mailbox);
  395. $line .= str_replace (' ', '&nbsp;', $mailbox);
  396. }
  397. $line .= '</font>';
  398. } else {
  399. $line .= formatMailboxName ($imapConnection, $boxes[$i]);
  400. }
  401. /* Put the final touches on our folder line. */
  402. $line .= "</span><br />\n";
  403. /* Output the line for this folder. */
  404. echo $line;
  405. }
  406. }
  407. do_hook ('left_main_after');
  408. sqimap_logout ($imapConnection);
  409. ?>
  410. </td></tr></table>
  411. </body></html>

Documentation generated on 2020年1月13日 04:24:52 +0100 by phpDocumentor 1.4.3

AltStyle によって変換されたページ (->オリジナル) /