X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=functions%2Fimap.php;h=44c63bdae089d7aabb7b09edc59e79245224451b;hp=f2b192ef59d226e8d58abf28f1028aace78e5a7e;hb=d29aac0e3969fcd88d2dc76698ea802718c200e6;hpb=36c5a7ec4209dfb7e7cc9c6ee5358094feb4562e
diff --git a/functions/imap.php b/functions/imap.php
index f2b192ef..44c63bda 100644
--- a/functions/imap.php
+++ b/functions/imap.php
@@ -1,348 +1,10 @@
- /**
- ** imap.php
- **
- ** Functions for the IMAP connection
- **
+ /** This just includes the different sections of the imap functions.
+ ** They have been organized into these sections for simplicity sake.
**/
-
- /** Read from the connection until we get either an OK or BAD message. **/
- function imapReadData($connection, $pre, $handle_errors, &$response, &$message) {
- require ("../config/config.php");
-
- $read = fgets($connection, 1024);
- $counter = 0;
- 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) {
- $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));
- }
- return $box;
- }
-
- /**
- Finds the delimeter between mailboxes. This should now be more compliant across
- different server types that vary in their RFC2060 compliance.
- **/
- function findMailboxDelimeter($imapConnection) {
- fputs($imapConnection, ". list \"\" *\n");
- $read = imapReadData($imapConnection, ".", true, $a, $b);
- $quotePosition = strpos($read[0], "\"");
- $delim = substr($read[0], $quotePosition+1, 1);
-
- return $delim;
- }
-
- function getMailboxFlags($imapConnection, $mailbox) {
- $name = findMailboxName($mailbox);
- fputs ($imapConnection, "1 LIST \"$name\" *\n");
- $data = imapReadData($imapConnection, "1", true, $response, $message);
- $mailbox = $data[0];
- $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, $hide) {
- require("../config/config.php");
-
- $imapConnection = fsockopen($imapServerAddress, 143, &$errorNumber, &$errorString);
- if (!$imapConnection) {
- echo "Error connecting to IMAP Server.
";
- echo "$errorNumber : $errorString
";
- exit;
- }
- $serverInfo = fgets($imapConnection, 256);
-
- // login
- fputs($imapConnection, "a001 LOGIN \"$username\" \"$key\"\n");
- $read = fgets($imapConnection, 1024);
- if ($debug_login == true) {
- echo "SERVER SAYS: $read
";
- }
-
- /** If the login attempt was UNsuccessful, lets see why **/
- 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 " Unknown user or password incorrect. Click here to try again. |