X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fimap.php;h=190df98f4999fca0473ed3f5944ec7d63dd7d59c;hb=eb5073496da0bcc9b07109f1c31f837ed90cf199;hp=62bfe30b96ffdd112a4c92e5fddecfa23363fdbb;hpb=d92b6f319c3ca67ff701db9da869b42c298ef9a4;p=squirrelmail.git diff --git a/functions/imap.php b/functions/imap.php index 62bfe30b..190df98f 100644 --- a/functions/imap.php +++ b/functions/imap.php @@ -32,10 +32,10 @@ if ($handle_errors == true) { if ($response == "NO") { - echo "ERROR: Could not complete request.
  Reason given: $message

"; + echo "
ERROR: Could not complete request.
  Reason given: $message

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

"; + echo "
ERROR: Bad or malformed request.
  Server responded: $message

"; exit; } } @@ -61,12 +61,17 @@ fputs($imapConnection, ". list \"\" \"\"\n"); $read = fgets($imapConnection, 1024); - $pos = strrpos($read, "\""); - $read = substr($read, 0, $pos); - - $pos = strrpos($read, "\""); - $read = substr($read, 0, $pos); + if (strrpos($read, "\"") == strlen($read)) { + $pos = strrpos($read, "\""); + $read = substr($read, 0, $pos); + $pos = strrpos($read, "\""); + $read = substr($read, 0, $pos); + } else { + $pos = strrpos($read, " "); + $read = substr($read, 0, $pos); + } + $pos = strrpos($read, "\""); $read = substr($read, 0, $pos); @@ -100,12 +105,13 @@ $serverInfo = fgets($imapConnection, 256); // login - fputs($imapConnection, "a001 LOGIN $username $key\n"); + 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") { @@ -113,11 +119,11 @@ exit; } else if (substr($read, 0, 7) == "a001 NO") { - echo "
"; - echo ""; + echo "
"; + echo "
"; echo " "; - echo " "; @@ -151,13 +157,16 @@ $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
  • "; + 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
  • "; + echo "
  • Try renaming the folder to something different.
  • "; exit; } else if ($response == "BAD") { - echo "ERROR: Bad or malformed request.
      Server responded: $message

    "; + echo "ERROR: Bad or malformed request.
      Server responded: $message

    "; exit; } + fputs($imapConnection, "1 SUBSCRIBE \"$folder\"\n"); + $data = imapReadData($imapConnection, "1", true, $response, $message); } function removeFolder($imapConnection, $folder) { @@ -175,25 +184,108 @@ } /** Sends back two arrays, boxesFormatted and boxesUnformatted **/ - function getFolderList($imapConnection, &$boxesFormatted, &$boxesUnformatted, &$boxesRaw) { - fputs($imapConnection, "1 list \"\" *\n"); + function getFolderList($imapConnection, &$boxes) { + require ("../config/config.php"); + + /** First we get the inbox **/ + fputs($imapConnection, "1 LIST \"\" INBOX\n"); $str = imapReadData($imapConnection, "1", true, $response, $message); + $dm = findMailboxDelimeter($imapConnection); + $g = 0; + for ($i = 0;$i < count($str); $i++) { + $mailbox = chop($str[$i]); + if (substr(findMailboxName($mailbox), 0, 1) != ".") { + $boxes[$g]["RAW"] = $mailbox; + + $mailbox = findMailboxName($mailbox); + $periodCount = countCharInString($mailbox, $dm); + + // indent the correct number of spaces. + for ($j = 0;$j < $periodCount;$j++) + $boxes[$g]["FORMATTED"] = $boxes[$g]["FORMATTED"] . "  "; + $boxes[$g]["FORMATTED"] = $boxes[$g]["FORMATTED"] . readShortMailboxName($mailbox, $dm); + $boxes[$g]["UNFORMATTED"] = $mailbox; + $boxes[$g]["ID"] = $g; + $g++; + } + } + + /** Next, we get all subscribed folders **/ + fputs($imapConnection, "1 LSUB \"\" *\n"); + $str = imapReadData($imapConnection, "1", true, $response, $message); $dm = findMailboxDelimeter($imapConnection); for ($i = 0;$i < count($str); $i++) { $mailbox = chop($str[$i]); - $boxesRaw[$i] = $mailbox; + if (substr(findMailboxName($mailbox), 0, 1) != ".") { + $boxes[$g]["RAW"] = $mailbox; - $mailbox = findMailboxName($mailbox); - $periodCount = countCharInString($mailbox, $dm); + $mailbox = findMailboxName($mailbox); + $periodCount = countCharInString($mailbox, $dm); - // indent the correct number of spaces. - for ($j = 0;$j < $periodCount;$j++) - $boxesFormatted[$i] = "$boxesFormatted[$i]  "; + // indent the correct number of spaces. + for ($j = 0;$j < $periodCount;$j++) + $boxes[$g]["FORMATTED"] = $boxes[$g]["FORMATTED"] . "  "; - $boxesFormatted[$i] = $boxesFormatted[$i] . readShortMailboxName($mailbox, $dm); - $boxesUnformatted[$i] = $mailbox; + $boxes[$g]["FORMATTED"] = $boxes[$g]["FORMATTED"] . readShortMailboxName($mailbox, $dm); + $boxes[$g]["UNFORMATTED"] = $mailbox; + $boxes[$g]["ID"] = $g; + $g++; + } + } + + $original = $boxes; + + for ($i = 0; $i < count($original); $i++) { + $boxes[$i]["UNFORMATTED"] = strtolower($boxes[$i]["UNFORMATTED"]); + } + + $boxes = ary_sort($boxes, "UNFORMATTED", 1); + + for ($i = 0; $i < count($original); $i++) { + for ($j = 0; $j < count($original); $j++) { + if ($boxes[$i]["ID"] == $original[$j]["ID"]) { + $boxes[$i]["UNFORMATTED"] = $original[$j]["UNFORMATTED"]; + $boxes[$i]["FORMATTED"] = $original[$j]["FORMATTED"]; + $boxes[$i]["RAW"] = $original[$j]["RAW"]; + } + } } + + for ($i = 0; $i < count($boxes); $i++) { + if ($boxes[$i]["UNFORMATTED"] == $special_folders[0]) { + $boxesnew[0]["FORMATTED"] = $boxes[$i]["FORMATTED"]; + $boxesnew[0]["UNFORMATTED"] = trim($boxes[$i]["UNFORMATTED"]); + $boxesnew[0]["RAW"] = trim($boxes[$i]["RAW"]); + $boxes[$i]["USED"] = true; + } + } + if ($list_special_folders_first == true) { + for ($i = 0; $i < count($boxes); $i++) { + for ($j = 1; $j < count($special_folders); $j++) { + if (substr($boxes[$i]["UNFORMATTED"], 0, strlen($special_folders[$j])) == $special_folders[$j]) { + $pos = count($boxesnew); + $boxesnew[$pos]["FORMATTED"] = $boxes[$i]["FORMATTED"]; + $boxesnew[$pos]["RAW"] = trim($boxes[$i]["RAW"]); + $boxesnew[$pos]["UNFORMATTED"] = trim($boxes[$i]["UNFORMATTED"]); + $boxes[$i]["USED"] = true; + } + } + } + } + for ($i = 0; $i < count($boxes); $i++) { + if (($boxes[$i]["UNFORMATTED"] != $special_folders[0]) && + ($boxes[$i]["UNFORMATTED"] != ".mailboxlist") && + ($boxes[$i]["USED"] == false)) { + $pos = count($boxesnew); + $boxesnew[$pos]["FORMATTED"] = $boxes[$i]["FORMATTED"]; + $boxesnew[$pos]["RAW"] = trim($boxes[$i]["RAW"]); + $boxesnew[$pos]["UNFORMATTED"] = trim($boxes[$i]["UNFORMATTED"]); + $boxes[$i]["USED"] = true; + } + } + + $boxes = $boxesnew; } function deleteMessages($imapConnection, $a, $b, $numMessages, $trash_folder, $move_to_trash, $auto_expunge, $mailbox) { @@ -205,7 +297,10 @@ } else { setMessageFlag($imapConnection, $a, $b, "Deleted"); } + if ($auto_expunge == true) + expungeBox($imapConnection, $mailbox); } + function stripComments($line) { if (strpos($line, ";")) { $line = substr($line, 0, strpos($line, ";"));
    "; - echo "
    ERROR
    "; + echo "
    "; + echo "
    ERROR
    "; echo "
    "; echo "

    Unknown user or password incorrect.
    Click here to try again.
    "; echo "