From d92b6f319c3ca67ff701db9da869b42c298ef9a4 Mon Sep 17 00:00:00 2001 From: lkehresman Date: Thu, 16 Dec 1999 21:18:54 +0000 Subject: [PATCH] I believe everything is compatable with all IMAP servers now git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@83 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- COPYING | 280 +++++++++++++++++++++++++++++++++ ChangeLog | 9 ++ functions/imap.php | 161 ++++++++++++++++--- functions/mailbox.php | 17 +- functions/mailbox_display.php | 6 +- functions/page_header.php | 2 +- functions/strings.php | 14 +- index.html | 7 +- src/delete_message.php | 2 +- src/empty_trash.php | 50 ++---- src/folders.php | 16 +- src/folders_create.php | 10 +- src/folders_delete.php | 52 ++++-- src/folders_rename_do.php | 21 ++- src/folders_rename_getname.php | 25 ++- src/left_main.php | 129 ++++++++++++--- src/login.php | 5 - src/move_messages.php | 6 +- src/right_main.php | 1 - 19 files changed, 657 insertions(+), 156 deletions(-) create mode 100644 COPYING create mode 100644 ChangeLog diff --git a/COPYING b/COPYING new file mode 100644 index 00000000..c7aea189 --- /dev/null +++ b/COPYING @@ -0,0 +1,280 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 675 Mass Ave, Cambridge, MA 02139, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 00000000..fe5c2d4a --- /dev/null +++ b/ChangeLog @@ -0,0 +1,9 @@ +Version 0.1 -- December 14, 1999 +-------------------------------- +- Message composing (with to, cc, bcc) +- Message viewing, including HTML messages +- Basic MIME support, no attachments...yet +- Message sorting by Date, Name, or subject +- Folder manipulation (deleting, creating, moving, and renaming) +- IMAP email (currently only Cyrus IMAP server has been tested) +- Many other features that are basic email functionality diff --git a/functions/imap.php b/functions/imap.php index 4f11ed90..62bfe30b 100644 --- a/functions/imap.php +++ b/functions/imap.php @@ -7,33 +7,90 @@ **/ /** Read from the connection until we get either an OK or BAD message. **/ - function imapReadData($connection) { + function imapReadData($connection, $pre, $handle_errors, &$response, &$message) { + require ("../config/config.php"); + $read = fgets($connection, 1024); $counter = 0; - while ((substr($read, strpos($read, " ") + 1, 2) != "OK") && (substr($read, strpos($read, " ") + 1, 3) != "BAD")) { + while ((substr($read, 0, strlen("$pre OK")) != "$pre OK") && + (substr($read, 0, strlen("$pre BAD")) != "$pre BAD") && + (substr($read, 0, strlen("$pre NO")) != "$pre NO")) { $data[$counter] = $read; $read = fgets($connection, 1024); $counter++; } + if (substr($read, 0, strlen("$pre OK")) == "$pre OK") { + $response = "OK"; + $message = trim(substr($read, strlen("$pre OK"), strlen($read))); + } else if (substr($read, 0, strlen("$pre BAD")) == "$pre BAD") { + $response = "BAD"; + $message = trim(substr($read, strlen("$pre BAD"), strlen($read))); + } else { + $response = "NO"; + $message = trim(substr($read, strlen("$pre NO"), strlen($read))); + } + + if ($handle_errors == true) { + if ($response == "NO") { + echo "ERROR: Could not complete request.
  Reason given: $message

"; + exit; + } else if ($response == "BAD") { + echo "ERROR: Bad or malformed request.
  Server responded: $message

"; + exit; + } + } + return $data; } /** Parse the incoming mailbox name and return a string that is the FOLDER.MAILBOX **/ function findMailboxName($mailbox) { - // start at -2 so that we skip the initial quote at the end of the mailbox name - $i = -2; - $char = substr($mailbox, $i, 1); - while ($char != "\"") { - $i--; - $temp .= $char; - $char = substr($mailbox, $i, 1); + $mailbox = trim($mailbox); + if (substr($mailbox, strlen($mailbox)-1, strlen($mailbox)) == "\"") { + $mailbox = substr($mailbox, 0, strlen($mailbox) - 1); + $pos = strrpos($mailbox, "\"") + 1; + $box = substr($mailbox, $pos, strlen($mailbox)); + } else { + $box = substr($mailbox, strrpos($mailbox, " ")+1, strlen($mailbox)); } - echo $tmp; - return strrev($temp); + return $box; + } + + /** Finds the delimeter between mailboxes **/ + function findMailboxDelimeter($imapConnection) { + fputs($imapConnection, ". list \"\" \"\"\n"); + $read = fgets($imapConnection, 1024); + + $pos = strrpos($read, "\""); + $read = substr($read, 0, $pos); + + $pos = strrpos($read, "\""); + $read = substr($read, 0, $pos); + + $pos = strrpos($read, "\""); + $read = substr($read, 0, $pos); + + $pos = strrpos($read, "\""); + $read = substr($read, $pos+1, strlen($read)); + + $tmp = fgets($imapConnection, 1024); + return $read; + } + + function getMailboxFlags($mailbox) { + $mailbox = trim($mailbox); + $mailbox = substr($mailbox, strpos($mailbox, "(")+1, strlen($mailbox)); + $mailbox = substr($mailbox, 0, strpos($mailbox, ")")); + $mailbox = str_replace("\\", "", $mailbox); + $mailbox = strtolower($mailbox); + $mailbox = explode(" ", $mailbox); + return $mailbox; } // handles logging onto an imap server. - function loginToImapServer($username, $key, $imapServerAddress) { + function loginToImapServer($username, $key, $imapServerAddress, $hide) { + require("../config/config.php"); + $imapConnection = fsockopen($imapServerAddress, 143, &$errorNumber, &$errorString); if (!$imapConnection) { echo "Error connecting to IMAP Server.
"; @@ -43,42 +100,98 @@ $serverInfo = fgets($imapConnection, 256); // login - fputs($imapConnection, "1 login $username $key\n"); + fputs($imapConnection, "a001 LOGIN $username $key\n"); $read = fgets($imapConnection, 1024); - - if (strpos($read, "NO")) { - error_username_password_incorrect(); - exit; + if ($debug_login == true) { + echo "SERVER SAYS: $read
"; } - + + if (substr($read, 0, 7) != "a001 OK") { + if (!$hide) { + if (substr($read, 0, 8) == "a001 BAD") { + echo "Bad request: $read
"; + exit; + } + else if (substr($read, 0, 7) == "a001 NO") { + echo "
"; + echo ""; + echo " "; + echo " "; + echo "
"; + echo "
ERROR
"; + echo "
"; + echo "

Unknown user or password incorrect.
Click here to try again.
"; + echo "
"; + echo ""; + exit; + } + else { + echo "Unknown error: $read
"; + exit; + } + } else { + exit; + } + } + return $imapConnection; } /** must be sent in the form: user.. **/ - function createFolder($imapConnection, $folder) { + function createFolder($imapConnection, $folder, $type) { + require ("../config/config.php"); + + if (strtolower($type) == "noselect") { + $dm = findMailboxDelimeter($imapConnection); + $folder = "$folder$dm"; + } else { + $folder = "$folder"; + } fputs($imapConnection, "1 create \"$folder\"\n"); + $data = imapReadData($imapConnection, "1", false, $response, $message); + + if ($response == "NO") { + echo "ERROR: Could not complete request.
  Reason given: $message

"; + echo "Possible solutions:
  • You may need to specify that the folder is a subfolder of INBOX
  • "; + exit; + } else if ($response == "BAD") { + echo "ERROR: Bad or malformed request.
      Server responded: $message

    "; + exit; + } } - /** must be sent in the form: user.. **/ function removeFolder($imapConnection, $folder) { fputs($imapConnection, "1 delete \"$folder\"\n"); + $data = imapReadData($imapConnection, "1", false, $response, $message); + if ($response == "NO") { + echo "ERROR: Could not delete the folder $folder."; + echo "Probable causes:
    "; + echo "
  • This folder may contain subfolders. Delete all subfolders first
  • "; + exit; + } else if ($response == "BAD") { + echo "ERROR: Bad or malformed request.
      Server responded: $message

    "; + exit; + } } /** Sends back two arrays, boxesFormatted and boxesUnformatted **/ - function getFolderList($imapConnection, &$boxesFormatted, &$boxesUnformatted) { + function getFolderList($imapConnection, &$boxesFormatted, &$boxesUnformatted, &$boxesRaw) { fputs($imapConnection, "1 list \"\" *\n"); - $str = imapReadData($imapConnection); + $str = imapReadData($imapConnection, "1", true, $response, $message); + $dm = findMailboxDelimeter($imapConnection); for ($i = 0;$i < count($str); $i++) { $mailbox = chop($str[$i]); + $boxesRaw[$i] = $mailbox; + $mailbox = findMailboxName($mailbox); - $periodCount = countCharInString($mailbox, "."); + $periodCount = countCharInString($mailbox, $dm); // indent the correct number of spaces. for ($j = 0;$j < $periodCount;$j++) $boxesFormatted[$i] = "$boxesFormatted[$i]  "; - $boxesFormatted[$i] = $boxesFormatted[$i] . readShortMailboxName($mailbox, "."); + $boxesFormatted[$i] = $boxesFormatted[$i] . readShortMailboxName($mailbox, $dm); $boxesUnformatted[$i] = $mailbox; } } diff --git a/functions/mailbox.php b/functions/mailbox.php index 383da2df..8babee25 100644 --- a/functions/mailbox.php +++ b/functions/mailbox.php @@ -10,14 +10,12 @@ function selectMailbox($imapConnection, $mailbox, &$numberOfMessages) { // select mailbox fputs($imapConnection, "mailboxSelect SELECT \"$mailbox\"\n"); - $read = fgets($imapConnection, 1024); - $unseen = false; - while ((substr($read, 0, 16) != "mailboxSelect OK") && (substr($read, 0, 17) != "mailboxSelect BAD")) { - if (substr(Chop($read), -6) == "EXISTS") { - $array = explode(" ", $read); + $data = imapReadData($imapConnection, "mailboxSelect"); + for ($i = 0; $i < count($data); $i++) { + if (substr(Chop($data[$i]), -6) == "EXISTS") { + $array = explode(" ", $data[$i]); $numberOfMessages = $array[1]; } - $read = fgets($imapConnection, 1024); } } @@ -226,9 +224,10 @@ fputs($imapConnection, "1 EXPUNGE\n"); } - function getFolderNameMinusINBOX($mailbox) { - if (substr($mailbox, 0, 6) == "INBOX.") - $box = substr($mailbox, 6, strlen($mailbox)); + function getFolderNameMinusINBOX($mailbox, $del) { + $inbox = "INBOX" . $del; + if (substr($mailbox, 0, strlen($inbox)) == $inbox) + $box = substr($mailbox, strlen($inbox), strlen($mailbox)); else $box = $mailbox; diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index 66c7fde5..98007b04 100644 --- a/functions/mailbox_display.php +++ b/functions/mailbox_display.php @@ -9,6 +9,8 @@ **/ function printMessageInfo($imapConnection, $t, $i, $from, $subject, $dateString, $answered, $seen, $mailbox, $sort, $startMessage) { + require ("../config/config.php"); + $senderName = getSenderName($from); $urlMailbox = urlencode($mailbox); $subject = trim(stripslashes($subject)); @@ -31,7 +33,7 @@ ** This function loops through a group of messages in the mailbox and shows them **/ function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort) { - include("../config/config.php"); + require ("../config/config.php"); if (1 <= $numMessages) { getMessageHeaders($imapConnection, 1, $numMessages, $from, $subject, $date); @@ -194,7 +196,7 @@ echo " \n"; echo " \n"; echo "
    \n"; echo "  as a subfolder of
    "; echo "
    \n"; echo "\n"; echo "

    \n"; /** RENAMING FOLDERS **/ - echo "Rename or Move Folder"; + echo "Rename a Folder"; echo ""; echo "
    \n"; echo "\n"; - echo "\n"; + echo "\n"; echo "

    \n"; ?> diff --git a/src/folders_create.php b/src/folders_create.php index e259dc03..171fbad9 100644 --- a/src/folders_create.php +++ b/src/folders_create.php @@ -1,5 +1,4 @@ - \n"; $imapConnection = loginToImapServer($username, $key, $imapServerAddress); - fputs($imapConnection, "1 create \"$subfolder.$folder_name\"\n"); + $dm = findMailboxDelimeter($imapConnection); + if (trim($subfolder) == "[ None ]") { + createFolder($imapConnection, "$folder_name"); + } else { + createFolder($imapConnection, "$subfolder$dm$folder_name"); + } fputs($imapConnection, "1 logout\n"); - echo "


    You will be automatically forwarded.
    If not, click here
    "; + echo "

    Return"; ?> diff --git a/src/folders_delete.php b/src/folders_delete.php index 430bb00b..6e214ecd 100644 --- a/src/folders_delete.php +++ b/src/folders_delete.php @@ -5,26 +5,46 @@ include("../functions/imap.php"); include("../functions/mailbox.php"); + echo "\n"; $imapConnection = loginToImapServer($username, $key, $imapServerAddress); - selectMailbox($imapConnection, $mailbox, $numMessages); - getFolderList($imapConnection, $boxesFormatted, $boxesUnformatted); + getFolderList($imapConnection, $boxesFormatted, $boxesUnformatted, $boxesRaw); + + $dm = findMailboxDelimeter($imapConnection); + /** lets see if we CAN move folders to the trash.. otherwise, just delete them **/ + for ($i = 0; $i < count($boxesUnformatted); $i++) { + if ($boxesUnformatted[$i] == $trash_folder) + $tmp_trash_folder = $boxesRaw[$i]; + } + + $tmpflags = getMailboxFlags($tmp_trash_folder); + $can_move_to_trash = true; + for ($i = 0; $i < count($tmpflags); $i++) { + if (strtolower($tmpflags[$i]) == "noinferiors") + $can_move_to_trash = false; + } /** Lets start removing the folders and messages **/ - if ($move_to_trash == true) { /** if they wish to move messages to the trash **/ + if (($move_to_trash == true) && ($can_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"); + if (($boxesUnformatted[$i] == $mailbox) || + (substr($boxesUnformatted[$i], 0, strlen($mailbox . $dm)) == $mailbox . $dm)) { + $folderWithoutINBOX = getFolderNameMinusINBOX($boxesUnformatted[$i], $dm); + $flags = getMailboxFlags($boxesRaw[$i]); + for ($b = 0; $b < count($flags); $b++) { + $type = $flags[$b]; + } + createFolder($imapConnection, "$trash_folder" . $dm . "$folderWithoutINBOX", $type); } } for ($i = 0; $i < count($boxesUnformatted); $i++) { - if (substr($boxesUnformatted[$i], 0, strlen($mailbox)) == $mailbox) { + if (($boxesUnformatted[$i] == $mailbox) || + (substr($boxesUnformatted[$i], 0, strlen($mailbox . $dm)) == $mailbox . $dm)) { selectMailbox($imapConnection, $boxesUnformatted[$i], $numMessages); $folder = getFolderNameMinusINBOX($boxesUnformatted[$i]); if ($numMessages > 0) - $success = copyMessages($imapConnection, 1, $numMessages, "$trash_folder.$folder"); + $success = copyMessages($imapConnection, 1, $numMessages, "$trash_folder" . $dm . "$folder"); else $success = true; @@ -32,18 +52,24 @@ 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]"); + } else { /** if they do NOT wish to move messages to the trash (or cannot)**/ + fputs($imapConnection, "1 LIST \"$mailbox\" *\n"); + $data = imapReadData($imapConnection , "1", false, $response, $message); + while (substr($data[0], strpos($data[0], " ")+1, 4) == "LIST") { + for ($i = 0; $i < count($boxesUnformatted); $i++) { + if (($boxesUnformatted[$i] == $mailbox) || + (substr($boxesUnformatted[$i], 0, strlen($mailbox . $dm)) == $mailbox . $dm)) { + removeFolder($imapConnection, "$boxesUnformatted[$i]"); + } } + fputs($imapConnection, "1 LIST \"$mailbox\" *\n"); + $data = imapReadData($imapConnection , "1", false, $response, $message); } } /** Log out this session **/ fputs($imapConnection, "1 logout"); - echo "\n"; echo "

    Return"; echo ""; ?> diff --git a/src/folders_rename_do.php b/src/folders_rename_do.php index 5c7e9aba..b13ff6bd 100644 --- a/src/folders_rename_do.php +++ b/src/folders_rename_do.php @@ -6,8 +6,25 @@ include("../functions/mailbox.php"); $imapConnection = loginToImapServer($username, $key, $imapServerAddress); + $dm = findMailboxDelimeter($imapConnection); + + if (strpos($orig, $dm)) + $old_dir = substr($orig, 0, strrpos($orig, $dm)); + else + $old_dir = ""; + + if ($old_dir != "") + $newone = "$old_dir$dm$new_name"; + else + $newone = "$new_name"; + + fputs ($imapConnection, ". RENAME \"$orig\" \"$newone\"\n"); + $data = imapReadData($imapConnection, ".", true, $a, $b); + +/* fputs ($imapConnection, ". RENAME \"$old_name\" \"$mailbox\"\n"; + selectMailbox($imapConnection, $orig, $numMessages); - getFolderList($imapConnection, $boxesFormatted, $boxesUnformatted); + getFolderList($imapConnection, $boxesFormatted, $boxesUnformatted, $boxesRaw); $mailbox = "$subfolder.$new_name"; $old_name = substr($orig, strrpos($orig, ".")+1, strlen($orig)); @@ -39,7 +56,7 @@ } } } - +*/ /** Log out this session **/ fputs($imapConnection, "1 logout"); diff --git a/src/folders_rename_getname.php b/src/folders_rename_getname.php index 6f9fba1f..5a8dec1c 100644 --- a/src/folders_rename_getname.php +++ b/src/folders_rename_getname.php @@ -7,28 +7,25 @@ $imapConnection = loginToImapServer($username, $key, $imapServerAddress); selectMailbox($imapConnection, $old, $numMessages); - getFolderList($imapConnection, $boxesFormatted, $boxesUnformatted); + getFolderList($imapConnection, $boxesFormatted, $boxesUnformatted, $boxesRaw); - $old_name = substr($old, strrpos($old, ".")+1, strlen($old)); - $old_parent = substr($old, 0, strrpos($old, ".")); + $dm = findMailboxDelimeter($imapConnection); + if (strpos($old, $dm)) { + $old_name = substr($old, strrpos($old, $dm)+1, strlen($old)); + $old_parent = substr($old, 0, strrpos($old, $dm)); + } else { + $old_name = $old; + $old_parent = ""; + } echo "\n"; displayPageHeader($color, "None"); echo ""; - echo ""; + echo ""; echo ""; echo "
    Rename or Move a folder
    Rename a folder
    "; echo "
    \n"; - echo "Original Name:   
    \n"; - echo "As a subfolder of:   "; + echo "New name:   
    \n"; echo ""; - echo "
    \n"; echo "\n"; echo "

    "; diff --git a/src/left_main.php b/src/left_main.php index e3725eb8..b224497b 100644 --- a/src/left_main.php +++ b/src/left_main.php @@ -15,52 +15,129 @@ "; + + $line .= ""; + $line .= readShortMailboxName($mailbox, $delimeter); + if (($move_to_trash == true) && (trim($mailbox) == $trash_folder)) { + $urlMailbox = urlencode($mailbox); + $line .= "    (empty)"; + } + $line .= "\n"; + if ($numUnseen > 0) { + $line .= " 
    ($numUnseen)"; + } + return $line; + } + echo ""; echo ""; - // open a connection on the imap port (143) - $imapConnection = loginToImapServer($username, $key, $imapServerAddress); + $imapConnection = loginToImapServer($username, $key, $imapServerAddress, 10); // the 10 is to hide the output fputs($imapConnection, "1 list \"\" *\n"); - $str = imapReadData($imapConnection); + $str = imapReadData($imapConnection, "1", true, $response, $message); - echo "
    "; + echo "
    "; echo "Folders
    "; - echo "(refresh folder list)

    "; + echo "(refresh folder list)

    "; echo "\n"; + $delimeter = findMailboxDelimeter($imapConnection); for ($i = 0;$i < count($str); $i++) { $mailbox = Chop($str[$i]); + $boxFlags = getMailboxFlags($mailbox); $mailbox = findMailboxName($mailbox); - // 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. - $periodCount = countCharInString($mailbox, "."); - + $boxCount = countCharInString($mailbox, $delimeter); + + $line = ""; // indent the correct number of spaces. - for ($j = 0;$j < $periodCount;$j++) - echo "  "; - - $mailboxURL = urlencode($mailbox); - selectMailbox($imapConnection, $mailbox, $numNessages); - $unseen = unseenMessages($imapConnection, $numUnseen); - if ($unseen) - echo ""; - echo ""; - echo readShortMailboxName($mailbox, "."); - if (($move_to_trash == true) && ($mailbox == $trash_folder)) { - $urlMailbox = urlencode($mailbox); - echo "    (empty)"; + for ($j = 0;$j < $boxCount;$j++) + $line .= "  "; + + if (trim($boxFlags[0]) != "") { + for ($h = 0; $h < count($boxFlags); $h++) { + if (strtolower($boxFlags[$h]) == "noselect") { + $line .= ""; + $line .= readShortMailboxName($mailbox, $delimeter); + $line .= ""; + } else { + $line .= formatMailboxName($imapConnection, $mailbox, $delimeter); + } + } + } else { + $line .= formatMailboxName($imapConnection, $mailbox, $delimeter); } - echo "\n"; - if ($numUnseen > 0) { - echo " ($numUnseen)"; + $folder_list[$i]["FORMATTED"] = trim($line); + $folder_list[$i]["PLAIN"] = trim($mailbox); + $folder_list[$i]["ID"] = $i; + } + + /** Alphebetize the folders */ + $original = $folder_list; + + for ($i = 0; $i < count($original); $i++) { + $folder_list[$i]["PLAIN"] = strtolower($folder_list[$i]["PLAIN"]); + } + + $folder_list = ary_sort($folder_list, "PLAIN", 1); + + for ($i = 0; $i < count($original); $i++) { + for ($j = 0; $j < count($original); $j++) { + if ($folder_list[$i]["ID"] == $original[$j]["ID"]) { + $folder_list[$i]["PLAIN"] = $original[$j]["PLAIN"]; + $folder_list[$i]["FORMATTED"] = $original[$j]["FORMATTED"]; + } } - echo "
    \n"; } + + /** If it is the inbox, list it first **/ + for ($i = 0; $i < count($folder_list); $i++) { + if ($folder_list[$i]["PLAIN"] == $special_folders[0]) { + echo ""; + echo trim($folder_list[$i]["FORMATTED"]); + echo "
    "; + $folder_list[$i]["USED"] = true; + } + } + /** Now the other special folders **/ + if ($list_special_folders_first == true) { + for ($i = 0; $i < count($folder_list); $i++) { + for ($j = 1; $j < count($special_folders); $j++) { + if (substr($folder_list[$i]["PLAIN"], 0, strlen($special_folders[$j])) == $special_folders[$j]) { + echo ""; + echo trim($folder_list[$i]["FORMATTED"]); + echo "
    "; + $folder_list[$i]["USED"] = true; + } + } + } + } + /** Then list all the other ones (not equal to INBOX) **/ + /** NOTE: .mailboxlist is a netscape thing.. just ignore it **/ + for ($i = 0; $i < count($folder_list); $i++) { + if (($folder_list[$i]["PLAIN"] != $special_folders[0]) && + ($folder_list[$i]["PLAIN"] != ".mailboxlist") && + ($folder_list[$i]["USED"] == false)) { + echo ""; + echo trim($folder_list[$i]["FORMATTED"]); + echo "
    "; + } + } + echo "
    "; fclose($imapConnection); diff --git a/src/login.php b/src/login.php index 4e1197a2..b8a46bc6 100644 --- a/src/login.php +++ b/src/login.php @@ -48,11 +48,6 @@ echo "\n"; echo "\n"; ?> - - - diff --git a/src/move_messages.php b/src/move_messages.php index 93c48ec2..280a2399 100644 --- a/src/move_messages.php +++ b/src/move_messages.php @@ -53,7 +53,7 @@ } $i++; } - messages_deleted_message($mailbox, $sort, $startMessage); + messages_deleted_message($mailbox, $sort, $startMessage, $color); } else { echo "

    No messages selected.
    "; } @@ -79,9 +79,9 @@ if ($auto_expunge == true) expungeBox($imapConnection, $mailbox, $numMessages); - messages_moved_message($mailbox, $sort, $startMessage); + messages_moved_message($mailbox, $sort, $startMessage, $color); } else { - error_message("No messages were selected.", $mailbox, $sort, $startMessage); + error_message("No messages were selected.", $mailbox, $sort, $startMessage, $color); } } diff --git a/src/right_main.php b/src/right_main.php index ed51ab20..1def94ed 100644 --- a/src/right_main.php +++ b/src/right_main.php @@ -46,7 +46,6 @@ // ///////////////////////////////////////////////////////////////////////////////// - // open a connection on the imap port (143) $imapConnection = loginToImapServer($username, $key, $imapServerAddress); -- 2.25.1