Source for file folders_delete.php

Documentation is available at folders_delete.php

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

Documentation generated on Sun, 19 May 2013 04:22:02 +0200 by phpDocumentor 1.4.3