Source for file folders_delete.php

Documentation is available at folders_delete.php

  1. <?php
  2. /**
  3. * folders_delete.php
  4. *
  5. * Deletes folders from the IMAP server.
  6. * Called from the folders.php
  7. *
  8. * @copyright 1999-2020 The SquirrelMail Project Team
  9. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10. * @version $Id: folders_delete.php 14840 2020年01月07日 07:42:38Z pdontthink $
  11. * @package squirrelmail
  12. */
  13. /** This is the folders_delete page */
  14. define ('PAGE_NAME', 'folders_delete');
  15. /**
  16. * Path for SquirrelMail required files.
  17. * @ignore
  18. */
  19. define ('SM_PATH','../');
  20. /* SquirrelMail required files. */
  21. require_once(SM_PATH . 'include/validate.php');
  22. require_once(SM_PATH . 'functions/global.php');
  23. require_once(SM_PATH . 'functions/imap.php');
  24. require_once(SM_PATH . 'functions/tree.php');
  25. require_once(SM_PATH . 'functions/display_messages.php');
  26. require_once(SM_PATH . 'functions/html.php');
  27. require_once(SM_PATH . 'functions/forms.php');
  28. /*
  29. * Incoming values:
  30. * $mailbox - selected mailbox from the form
  31. */
  32. /* globals */
  33. sqgetGlobalVar ('key', $key, SQ_COOKIE );
  34. sqgetGlobalVar ('username', $username, SQ_SESSION );
  35. sqgetGlobalVar ('onetimepad',$onetimepad, SQ_SESSION );
  36. sqgetGlobalVar ('delimiter', $delimiter, SQ_SESSION );
  37. sqgetGlobalVar ('mailbox', $mailbox, SQ_POST );
  38. if (!sqgetGlobalVar ('smtoken',$submitted_token, SQ_POST )) {
  39. $submitted_token = '';
  40. }
  41. /* end globals */
  42. if ($mailbox == '') {
  43. displayPageHeader ($color, 'None');
  44. plain_error_message (_ ("You have not selected a folder to delete. Please do so.").
  45. '<br /><a href="../src/folders.php">'._ ("Click here to go back").'</a>.', $color);
  46. exit;
  47. }
  48. if ( sqgetGlobalVar ('backingout', $tmp, SQ_POST ) ) {
  49. $location = get_location ();
  50. header ("Location: $location/folders.php");
  51. exit;
  52. }
  53. if( !sqgetGlobalVar ('confirmed', $tmp, SQ_POST ) ) {
  54. displayPageHeader ($color, 'None');
  55. // get displayable mailbox format
  56. global $folder_prefix;
  57. if (substr ($mailbox,0,strlen ($folder_prefix))==$folder_prefix) {
  58. $mailbox_unformatted_disp = substr ($mailbox, strlen ($folder_prefix));
  59. } else {
  60. $mailbox_unformatted_disp = $mailbox;
  61. }
  62. echo '<br />' .
  63. html_tag ( 'table', '', 'center', '', 'width="95%" border="0"' ) .
  64. html_tag ( 'tr',
  65. html_tag ( 'td', '<b>' . _ ("Delete Folder") . '</b>', 'center', $color[0] )
  66. ) .
  67. html_tag ( 'tr' ) .
  68. html_tag ( 'td', '', 'center', $color[4] ) .
  69. sprintf (_ ("Are you sure you want to delete %s?"), str_replace (array(' ','<','>'),array('&nbsp;','&lt;','&gt;'),imap_utf7_decode_local ($mailbox_unformatted_disp))).
  70. addForm ('folders_delete.php', 'post', '', '', '', '', TRUE)."<p>\n".
  71. addHidden ('mailbox', $mailbox).
  72. addSubmit (_ ("Yes"), 'confirmed').
  73. addSubmit (_ ("No"), 'backingout').
  74. '</p></form><br /></td></tr></table>';
  75. exit;
  76. }
  77. // first, validate security token
  78. sm_validate_security_token ($submitted_token, -1, TRUE);
  79. global $imap_stream_options; // in case not defined in config
  80. $imap_stream = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0, $imap_stream_options);
  81. $boxes = sqimap_mailbox_list ($imap_stream);
  82. $numboxes = count ($boxes);
  83. global $delete_folder;
  84. if (substr ($mailbox, -1) == $delimiter)
  85. $mailbox_no_dm = substr ($mailbox, 0, strlen ($mailbox) - 1);
  86. else
  87. $mailbox_no_dm = $mailbox;
  88. /** lets see if we CAN move folders to the trash.. otherwise,
  89. ** just delete them **/
  90. if ((isset($delete_folder) && $delete_folder) ||
  91. preg_match ('/^' . preg_quote ($trash_folder, '/') . '.+/i', $mailbox) ) {
  92. $can_move_to_trash = FALSE;
  93. }
  94. /* Otherwise, check if trash folder exits and support sub-folders */
  95. else {
  96. for ($i = 0; $i < $numboxes; $i++) {
  97. if ($boxes[$i]['unformatted'] == $trash_folder) {
  98. $can_move_to_trash = !in_array ('noinferiors', $boxes[$i]['flags']);
  99. }
  100. }
  101. }
  102. /** First create the top node in the tree **/
  103. for ($i = 0; $i < $numboxes; $i++) {
  104. if (($boxes[$i]['unformatted-dm'] == $mailbox) && (strlen ($boxes[$i]['unformatted-dm']) == strlen ($mailbox))) {
  105. $foldersTree[0]['value'] = $mailbox;
  106. $foldersTree[0]['doIHaveChildren'] = false;
  107. continue;
  108. }
  109. }
  110. /* Now create the nodes for subfolders of the parent folder
  111. You can tell that it is a subfolder by tacking the mailbox delimiter
  112. on the end of the $mailbox string, and compare to that. */
  113. for ($i = 0; $i < $numboxes; $i++) {
  114. if (substr ($boxes[$i]['unformatted'], 0, strlen ($mailbox_no_dm . $delimiter)) == ($mailbox_no_dm . $delimiter)) {
  115. addChildNodeToTree ($boxes[$i]["unformatted"], $boxes[$i]['unformatted-dm'], $foldersTree);
  116. }
  117. }
  118. /** Lets start removing the folders and messages **/
  119. if (($move_to_trash == true) && ($can_move_to_trash == true)) { /** if they wish to move messages to the trash **/
  120. walkTreeInPostOrderCreatingFoldersUnderTrash (0, $imap_stream, $foldersTree, $mailbox);
  121. walkTreeInPreOrderDeleteFolders (0, $imap_stream, $foldersTree);
  122. } else { /** if they do NOT wish to move messages to the trash (or cannot)**/
  123. walkTreeInPreOrderDeleteFolders (0, $imap_stream, $foldersTree);
  124. }
  125. /** Log out this session **/
  126. sqimap_logout ($imap_stream);
  127. $location = get_location ();
  128. header ("Location: $location/folders.php?success=delete");

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

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