X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fimap_general.php;h=17671284c7173093e7adb175b4a1ad648cd398b8;hb=6c540963c77709619a0670cc733249c8a4162c30;hp=c97bf43ddec03795610d3dba28727ec589569d03;hpb=d17b1a714665bb8817373d5941ca53935944ca8c;p=squirrelmail.git
diff --git a/functions/imap_general.php b/functions/imap_general.php
index c97bf43d..17671284 100755
--- a/functions/imap_general.php
+++ b/functions/imap_general.php
@@ -1,275 +1,1066 @@
-
- /**
- ** imap.php
- **
- ** This implements all functions that do general imap functions.
- **/
-
- /******************************************************************************
- ** Reads the output from the IMAP stream. If handle_errors is set to true,
- ** this will also handle all errors that are received. If it is not set,
- ** the errors will be sent back through $response and $message
- ******************************************************************************/
- function sqimap_read_data ($imap_stream, $pre, $handle_errors, $response, $message) {
- global $color;
-
- $read = fgets ($imap_stream, 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 ($imap_stream, 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)));
- }
+";
- echo _("ERROR : Could not complete request.");
- echo "
";
- echo _("Reason Given: ");
- echo "$message
";
- exit;
- } else if ($response == "BAD") {
- echo "
";
- echo _("ERROR : Bad or malformed request.");
- echo "
";
- echo _("Server responded: ");
- echo "$message
";
- exit;
- }
- }
-
- return $data;
- }
-
+/**
+ * imap_general.php
+ *
+ * Copyright (c) 1999-2003 The SquirrelMail Project Team
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
+ *
+ * This implements all functions that do general imap functions.
+ *
+ * $Id$
+ */
+
+require_once(SM_PATH . 'functions/page_header.php');
+require_once(SM_PATH . 'functions/auth.php');
+
+
+global $sqimap_session_id;
+$sqimap_session_id = 1;
+
+/* Sets an unique session id in order to avoid simultanous sessions crash. */
+function sqimap_session_id($unique_id = false) {
+ global $data_dir, $username, $sqimap_session_id;
+ if (!$unique_id) {
+ return( sprintf("A%03d", $sqimap_session_id++) );
+ } else {
+ return( sprintf("A%03d", $sqimap_session_id++) . ' UID' );
+ }
+}
+/*
+ * Both send a command and accept the result from the command.
+ * This is to allow proper session number handling.
+ */
+function sqimap_run_command_list ($imap_stream, $query, $handle_errors, &$response, &$message, $unique_id = false) {
+ if ($imap_stream) {
+ $sid = sqimap_session_id($unique_id);
+ fputs ($imap_stream, $sid . ' ' . $query . "\r\n");
+ $tag_uid_a = explode(' ',trim($sid));
+ $tag = $tag_uid_a[0];
+ $read = sqimap_retrieve_imap_response ($imap_stream, $tag, $handle_errors, $response, $message, $query );
+ /* get the response and the message */
+ $message = $message[$tag];
+ $response = $response[$tag];
+ return $read[$tag];
+ } else {
+ global $squirrelmail_language, $color;
+ set_up_language($squirrelmail_language);
+ require_once(SM_PATH . 'functions/display_messages.php');
+ $string = "\n" .
+ _("ERROR : No available imapstream.") .
+ "\n";
+ error_box($string,$color);
+ return false;
+ }
+}
+function sqimap_run_command ($imap_stream, $query, $handle_errors, &$response,
+ &$message, $unique_id = false,$filter=false,
+ $outputstream=false,$no_return=false) {
+ if ($imap_stream) {
+ $sid = sqimap_session_id($unique_id);
+ fputs ($imap_stream, $sid . ' ' . $query . "\r\n");
+ $tag_uid_a = explode(' ',trim($sid));
+ $tag = $tag_uid_a[0];
- /******************************************************************************
- ** Logs the user into the imap server. If $hide is set, no error messages
- ** will be displayed. This function returns the imap connection handle.
- ******************************************************************************/
- function sqimap_login ($username, $password, $imap_server_address, $hide) {
- global $color;
- $imap_stream = fsockopen ($imap_server_address, 143, &$error_number, &$error_string);
- $server_info = fgets ($imap_stream, 1024);
-
- /** Do some error correction **/
- if (!$imap_stream) {
- if (!$hide) {
- echo "Error connecting to IMAP server: $imap_server_address.
\r\n";
- echo "$error_number : $error_string
\r\n";
- }
- exit;
- }
+ $read = sqimap_read_data ($imap_stream, $tag, $handle_errors, $response,
+ $message, $query,$filter,$outputstream,$no_return);
+ /* retrieve the response and the message */
+ $response = $response[$tag];
+ $message = $message[$tag];
+
+ if (!empty($read[$tag])) {
+ return $read[$tag][0];
+ } else {
+ return $read[$tag];
+ }
+ } else {
+ global $squirrelmail_language, $color;
+ set_up_language($squirrelmail_language);
+ require_once(SM_PATH . 'functions/display_messages.php');
+ $string = "\n" .
+ _("ERROR : No available imapstream.") .
+ "\n";
+ error_box($string,$color);
+ return false;
+ }
+}
+function sqimap_prepare_pipelined_query($new_query,&$tag,&$aQuery,$unique_id) {
+ $sid = sqimap_session_id($unique_id);
+ $tag_uid_a = explode(' ',trim($sid));
+ $tag = $tag_uid_a[0];
+ $query = $sid . ' '.$new_query."\r\n";
+ $aQuery[$tag] = $query;
+}
- fputs ($imap_stream, "a001 LOGIN \"$username\" \"$password\"\r\n");
- $read = fgets ($imap_stream, 1024);
-
- /** If the connection was not successful, lets see why **/
- if (substr($read, 0, 7) != "a001 OK") {
- if (!$hide) {
- if (substr($read, 0, 8) == "a001 BAD") {
- echo "Bad request: $read
\r\n";
- exit;
- } else if (substr($read, 0, 7) == "a001 NO") {
- ?>
-
-
-
- |
-
- - echo _("Click here to try again") ?> - |
-