From 54e3c1d8bb43166fe4093ee9a55e346c88655a59 Mon Sep 17 00:00:00 2001 From: lkehresman Date: Mon, 29 Nov 1999 16:30:24 +0000 Subject: [PATCH] Deleting and creating folders works great! git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@39 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/imap.php | 20 ++++++++++++++++ src/folders.php | 39 +++++++------------------------ src/folders_create.php | 7 +----- src/folders_delete.php | 52 ++++++++++++++++++++++++++---------------- 4 files changed, 61 insertions(+), 57 deletions(-) diff --git a/functions/imap.php b/functions/imap.php index 30ef23b0..090f078e 100644 --- a/functions/imap.php +++ b/functions/imap.php @@ -62,4 +62,24 @@ function removeFolder($imapConnection, $folder) { fputs($imapConnection, "1 delete \"$folder\"\n"); } + + /** Sends back two arrays, boxesFormatted and boxesUnformatted **/ + function getFolderList($imapConnection, &$boxesFormatted, &$boxesUnformatted) { + fputs($imapConnection, "1 list \"\" *\n"); + $str = imapReadData($imapConnection); + + for ($i = 0;$i < count($str); $i++) { + $mailbox = chop($str[$i]); + $mailbox = findMailboxName($mailbox); + $periodCount = countCharInString($mailbox, "."); + + // indent the correct number of spaces. + for ($j = 0;$j < $periodCount;$j++) + $boxesFormatted[$i] = "$boxesFormatted[$i]  "; + + $boxesFormatted[$i] = $boxesFormatted[$i] . readShortMailboxName($mailbox, "."); + $boxesUnformatted[$i] = $mailbox; + } + } + ?> diff --git a/src/folders.php b/src/folders.php index 7b7ec043..99150b54 100644 --- a/src/folders.php +++ b/src/folders.php @@ -15,39 +15,19 @@ echo "\n"; $imapConnection = loginToImapServer($username, $key, $imapServerAddress); - - fputs($imapConnection, "1 list \"\" *\n"); - $str = imapReadData($imapConnection); - - for ($i = 0;$i < count($str); $i++) { - $mailbox = Chop($str[$i]); - // find the quote at the begining of the mailbox name. - // i subtract 1 from the strlen so it doesn't find the quote at the end of the mailbox name. - $mailbox = findMailboxName($mailbox); - $periodCount = countCharInString($mailbox, "."); - - // indent the correct number of spaces. - for ($j = 0;$j < $periodCount;$j++) - $boxes[$i] = "$boxes[$i]   "; - - $boxes[$i] = $boxes[$i] . readShortMailboxName($mailbox, "."); - $long_name_boxes[$i] = $mailbox; - } + getFolderList($imapConnection, $boxesFormatted, $boxesUnformatted); /** DELETING FOLDERS **/ - echo "
\n"; echo "\n"; echo "\n"; @@ -58,11 +38,8 @@ echo "\n"; echo "  as a subfolder of  "; echo "\n"; echo "\n"; @@ -71,14 +48,14 @@ /** RENAMING FOLDERS **/ echo "\n"; echo "\n"; echo "\n"; diff --git a/src/folders_create.php b/src/folders_create.php index 79b0224c..bf64b8a8 100644 --- a/src/folders_create.php +++ b/src/folders_create.php @@ -5,12 +5,7 @@ include("../functions/imap.php"); $imapConnection = loginToImapServer($username, $key, $imapServerAddress); - - if ($subfolder == "INBOX") - fputs($imapConnection, "1 create \"user.$username.$folder_name\"\n"); - else - fputs($imapConnection, "1 create \"user.$username.$subfolder.$folder_name\"\n"); - + fputs($imapConnection, "1 create \"$subfolder.$folder_name\"\n"); fputs($imapConnection, "1 logout\n"); echo "

Return"; diff --git a/src/folders_delete.php b/src/folders_delete.php index 8bc2ff5a..acddaf55 100644 --- a/src/folders_delete.php +++ b/src/folders_delete.php @@ -6,29 +6,41 @@ include("../functions/mailbox.php"); $imapConnection = loginToImapServer($username, $key, $imapServerAddress); - - // switch to the mailbox, and get the number of messages in it. selectMailbox($imapConnection, $mailbox, $numMessages); - - $folder = getFolderNameMinusINBOX($mailbox); - $trash = getFolderNameMinusINBOX($trash_folder); - - /** check if they would like to move it to the trash folder or not */ - if ($move_to_trash == true) { - createFolder($imapConnection, "user.$username.$trash.$folder"); - echo "CREATING FOLDER: user.$username.$trash.$folder
"; - if ($numMessages > 0) - $success = copyMessages($imapConnection, 1, $numMessages, $trash_folder); - else - $success = true; - - if ($success == true) - removeFolder($imapConnection, "user.$username.$folder"); - } else { - removeFolder($imapConnection, "user.$username.$folder"); + getFolderList($imapConnection, $boxesFormatted, $boxesUnformatted); + + /** Lets start removing the folders and messages **/ + if ($move_to_trash == true) { /** if they wish to move messages to the trash **/ + /** Creates the subfolders under $trash_folder **/ + for ($i = 0; $i < count($boxesUnformatted); $i++) { + if (substr($boxesUnformatted[$i], 0, strlen($mailbox)) == $mailbox) { + $folderWithoutINBOX = getFolderNameMinusINBOX($boxesUnformatted[$i]); + createFolder($imapConnection, "$trash_folder.$folderWithoutINBOX"); + } + } + for ($i = 0; $i < count($boxesUnformatted); $i++) { + if (substr($boxesUnformatted[$i], 0, strlen($mailbox)) == $mailbox) { + selectMailbox($imapConnection, $boxesUnformatted[$i], $numMessages); + $folder = getFolderNameMinusINBOX($boxesUnformatted[$i]); + + if ($numMessages > 0) + $success = copyMessages($imapConnection, 1, $numMessages, "$trash_folder.$folder"); + else + $success = true; + + if ($success == true) + removeFolder($imapConnection, "$boxesUnformatted[$i]"); + } + } + } else { /** if they do NOT wish to move messages to the trash **/ + for ($i = 0; $i < count($boxesUnformatted); $i++) { + if (substr($boxesUnformatted[$i], 0, strlen($mailbox)) == $mailbox) { + removeFolder($imapConnection, "$boxesUnformatted[$i]"); + } + } } - // Log out this session + /** Log out this session **/ fputs($imapConnection, "1 logout"); echo "

Return"; -- 2.25.1