30ef23b0862ce05eece85b4d9477ed92bf3b53f4
5 ** Functions for the IMAP connection
9 /** Read from the connection until we get either an OK or BAD message. **/
10 function imapReadData($connection) {
11 $read = fgets($connection, 1024);
13 while ((substr($read, strpos($read, " ") +
1, 2) != "OK") && (substr($read, strpos($read, " ") +
1, 3) != "BAD")) {
14 $data[$counter] = $read;
15 $read = fgets($connection, 1024);
21 /** Parse the incoming mailbox name and return a string that is the FOLDER.MAILBOX **/
22 function findMailboxName($mailbox) {
23 // start at -2 so that we skip the initial quote at the end of the mailbox name
25 $char = substr($mailbox, $i, 1);
26 while ($char != "\"") {
29 $char = substr($mailbox, $i, 1);
34 // handles logging onto an imap server.
35 function loginToImapServer($username, $key, $imapServerAddress) {
36 $imapConnection = fsockopen($imapServerAddress, 143, &$errorNumber, &$errorString);
37 if (!$imapConnection) {
38 echo "Error connecting to IMAP Server.<br>";
39 echo "$errorNumber : $errorString<br>";
42 $serverInfo = fgets($imapConnection, 256);
45 fputs($imapConnection, "1 login $username $key\n");
46 $read = fgets($imapConnection, 1024);
48 if (strpos($read, "NO")) {
49 error_username_password_incorrect();
53 return $imapConnection;
56 /** must be sent in the form: user.<USER>.<FOLDER> **/
57 function createFolder($imapConnection, $folder) {
58 fputs($imapConnection, "1 create \"$folder\"\n");
61 /** must be sent in the form: user.<USER>.<FOLDER> **/
62 function removeFolder($imapConnection, $folder) {
63 fputs($imapConnection, "1 delete \"$folder\"\n");