From 2aa12d5e029f04fa8c778ec1d3487418d0c3b62d Mon Sep 17 00:00:00 2001 From: nehresma Date: Mon, 29 Nov 1999 01:31:19 +0000 Subject: [PATCH] pulled out all the login stuff and error checking from each individual php file and put it in functions/imap.php git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@33 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/imap.php | 22 ++++++++++++++++++++++ src/empty_trash.php | 20 +++----------------- src/folders.php | 13 ++----------- src/folders_create.php | 12 +----------- src/folders_delete.php | 17 +---------------- src/left_main.php | 11 +---------- src/move_messages.php | 21 +++------------------ src/right_main.php | 16 +--------------- 8 files changed, 34 insertions(+), 98 deletions(-) diff --git a/functions/imap.php b/functions/imap.php index 979128fa..1dea2a4f 100644 --- a/functions/imap.php +++ b/functions/imap.php @@ -31,6 +31,28 @@ return strrev($temp); } + // handles logging onto an imap server. + function loginToImapServer($username, $key, $imapServerAddress) { + $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, "1 login $username $key\n"); + $read = fgets($imapConnection, 1024); + + if (strpos($read, "NO")) { + error_username_password_incorrect(); + exit; + } + + return $imapConnection; + } + /** must be sent in the form: user.. **/ function createFolder($imapConnection, $folder) { fputs($imapConnection, "1 create \"$folder\"\n"); diff --git a/src/empty_trash.php b/src/empty_trash.php index ee460ba4..f6baf0db 100644 --- a/src/empty_trash.php +++ b/src/empty_trash.php @@ -4,23 +4,9 @@ include("../functions/strings.php"); include("../functions/page_header.php"); include("../functions/display_messages.php"); + include("../functions/imap.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, "1 login $username $key\n"); - $read = fgets($imapConnection, 1024); - - if (strpos($read, "NO")) { - error_username_password_incorrect(); - exit; - } + $imapConnection = loginToImapServer($username, $key, $imapServerAddress); // switch to the mailbox, and get the number of messages in it. selectMailbox($imapConnection, $mailbox, $numMessages); @@ -41,4 +27,4 @@ displayPageHeader($mailbox); messages_deleted_message($mailbox, $sort, $startMessage); -?> \ No newline at end of file +?> diff --git a/src/folders.php b/src/folders.php index 5ce49644..0942ddbf 100644 --- a/src/folders.php +++ b/src/folders.php @@ -13,16 +13,7 @@ echo " \n"; echo "\n"; - $imapConnection = fsockopen($imapServerAddress, 143, &$errorNumber, &$errorString); - if (!$imapConnection) { - echo "Error connecting to IMAP Server.
"; - echo "$errorNumber : $errorString
"; - exit; - } - $serverInfo = fgets($imapConnection, 256); - - fputs($imapConnection, "1 login $username $key\n"); - $read = fgets($imapConnection, 1024); + $imapConnection = loginToImapServer($username, $key, $imapServerAddress); fputs($imapConnection, "1 list \"\" *\n"); $str = imapReadData($imapConnection); @@ -91,4 +82,4 @@ echo "
\n"; ?> - \ No newline at end of file + diff --git a/src/folders_create.php b/src/folders_create.php index 57be1754..79b0224c 100644 --- a/src/folders_create.php +++ b/src/folders_create.php @@ -4,17 +4,7 @@ include("../functions/page_header.php"); include("../functions/imap.php"); - $imapConnection = fsockopen($imapServerAddress, 143, &$errorNumber, &$errorString); - if (!$imapConnection) { - echo "Error connecting to IMAP Server.
"; - echo "$errorNumber : $errorString
"; - exit; - } - $serverInfo = fgets($imapConnection, 256); - - fputs($imapConnection, "1 login $username $key\n"); - $read = fgets($imapConnection, 1024); - echo $read; + $imapConnection = loginToImapServer($username, $key, $imapServerAddress); if ($subfolder == "INBOX") fputs($imapConnection, "1 create \"user.$username.$folder_name\"\n"); diff --git a/src/folders_delete.php b/src/folders_delete.php index 3af351a8..f211a4bf 100644 --- a/src/folders_delete.php +++ b/src/folders_delete.php @@ -4,22 +4,7 @@ include("../functions/page_header.php"); include("../functions/imap.php"); - $imapConnection = fsockopen($imapServerAddress, 143, &$errorNumber, &$errorString); - if (!$imapConnection) { - echo "Error connecting to IMAP Server.
"; - echo "$errorNumber : $errorString
"; - exit; - } - $serverInfo = fgets($imapConnection, 256); - - fputs($imapConnection, "1 login $username $key\n"); - $read = fgets($imapConnection, 1024); - echo $read; - - if (strpos($read, "NO")) { - error_username_password_incorrect(); - exit; - } + $imapConnection = loginToImapServer($username, $key, $imapServerAddress); // switch to the mailbox, and get the number of messages in it. selectMailbox($imapConnection, $mailbox, $numMessages); diff --git a/src/left_main.php b/src/left_main.php index 3bf51e59..086ec082 100644 --- a/src/left_main.php +++ b/src/left_main.php @@ -39,16 +39,7 @@ include("../functions/imap.php"); // open a connection on the imap port (143) - $imapConnection = fsockopen($imapServerAddress, 143, &$errorNumber, &$errorString); - if (!$imapConnection) { - echo "Error connecting to IMAP Server.
"; - echo "$errorNumber : $errorString
"; - exit; - } - $serverInfo = fgets($imapConnection, 256); - - fputs($imapConnection, "1 login $username $key\n"); - $read = fgets($imapConnection, 1024); + $imapConnection = loginToImapServer($username, $key, $imapServerAddress); fputs($imapConnection, "1 list \"\" *\n"); $str = imapReadData($imapConnection); diff --git a/src/move_messages.php b/src/move_messages.php index ff9031be..0dc83b96 100644 --- a/src/move_messages.php +++ b/src/move_messages.php @@ -5,25 +5,10 @@ include("../functions/page_header.php"); include("../functions/display_messages.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, "1 login $username $key\n"); - $read = fgets($imapConnection, 1024); - - if (strpos($read, "NO")) { - error_username_password_incorrect(); - exit; - } + $imapConnection = loginToImapServer($username, $key); // switch to the mailbox, and get the number of messages in it. - selectMailbox($imapConnection, $mailbox, $numMessages); + selectMailbox($imapConnection, $mailbox, $numMessages, $imapServerAddress); // Marks the selected messages ad 'Deleted' $j = 0; @@ -54,4 +39,4 @@ displayPageHeader($mailbox); messages_deleted_message($mailbox, $sort, $startMessage); -?> \ No newline at end of file +?> diff --git a/src/right_main.php b/src/right_main.php index 5c86e144..3071e422 100644 --- a/src/right_main.php +++ b/src/right_main.php @@ -47,21 +47,7 @@ // open a connection on the imap port (143) - $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, "1 login $username $key\n"); - $read = fgets($imapConnection, 1024); - if (strpos($read, "NO")) { - error_username_password_incorrect(); - exit; - } + $imapConnection = loginToImapServer($username, $key, $imapServerAddress); // If the page has been loaded without a specific mailbox, // just show a page of general info. -- 2.25.1