** to allow proper session number handling.
******************************************************************************/
+function sqimap_run_command_list ($imap_stream, $query, $handle_errors, &$response, &$message) {
+ fputs ($imap_stream, sqimap_session_id() . ' ' . $query . "\r\n");
+ $read = sqimap_read_data_list ($imap_stream, sqimap_session_id(), $handle_errors, $response, $message);
+ return $read;
+}
+
function sqimap_run_command ($imap_stream, $query, $handle_errors, &$response, &$message) {
- fputs ($imap_stream, sqimap_session_id() . $query . "\r\n");
+ fputs ($imap_stream, sqimap_session_id() . ' ' . $query . "\r\n");
$read = sqimap_read_data ($imap_stream, sqimap_session_id(), $handle_errors, $response, $message);
return $read;
}
exit;
}
- fputs ($imap_stream, sqimap_session_id() . ' LOGIN "' . quoteIMAP($username) .
- '" "' . quoteIMAP($password) . "\"\r\n");
- $read = sqimap_read_data ($imap_stream, sqimap_session_id(), false, $response, $message);
+ $query = 'LOGIN "' . quoteIMAP($username) . '" "' . quoteIMAP($password) . '"';
+ $read = sqimap_run_command ($imap_stream, $query, false, $response, $message);
/** If the connection was not successful, lets see why **/
if ($response != 'OK') {
}
exit;
} else {
- // If the user does not log in with the correct
- // username and password it is not possible to get the
- // correct locale from the user's preferences.
- // Therefore, apply the same hack as on the login
- // screen.
+ /* If the user does not log in with the correct
+ * username and password it is not possible to get the
+ * correct locale from the user's preferences.
+ * Therefore, apply the same hack as on the login
+ * screen.
+ */
- // $squirrelmail_language is set by a cookie when
- // the user selects language and logs out
+ /* $squirrelmail_language is set by a cookie when
+ * the user selects language and logs out
+ */
set_up_language($squirrelmail_language, true);
* Simply logs out the imap session
*/
function sqimap_logout ($imap_stream) {
- fputs ($imap_stream, sqimap_session_id() . " LOGOUT\r\n");
+ /* Logout is not valid until the server returns 'BYE' */
+ sqimap_run_command($imap_stream, 'LOGOUT', false, $response, $message);
}
function sqimap_capability($imap_stream, $capability) {
global $sqimap_capabilities;
if (!is_array($sqimap_capabilities)) {
- fputs ($imap_stream, sqimap_session_id() . " CAPABILITY\r\n");
- $read = sqimap_read_data($imap_stream, sqimap_session_id(), true, $a, $b);
-
+ $read = sqimap_run_command($imap_stream, 'CAPABILITY', true, $a, $b);
+
$c = explode(' ', $read[0]);
for ($i=2; $i < count($c); $i++) {
$cap_list = explode('=', $c[$i]);
OS: * NAMESPACE (PERSONAL NAMESPACES) (OTHER_USERS NAMESPACE) (SHARED NAMESPACES)
OS: We want to lookup all personal NAMESPACES...
*/
- fputs ($imap_stream, sqimap_session_id() . " NAMESPACE\r\n");
- $read = sqimap_read_data($imap_stream, sqimap_session_id(), true, $a, $b);
+ $read = sqimap_run_command($imap_stream, 'NAMESPACE', true, $a, $b);
if (eregi('\\* NAMESPACE +(\\( *\\(.+\\) *\\)|NIL) +(\\( *\\(.+\\) *\\)|NIL) +(\\( *\\(.+\\) *\\)|NIL)', $read[0], $data)) {
if (eregi('^\\( *\\((.*)\\) *\\)', $data[1], $data2)) {
$pn = $data2[1];
*/
function sqimap_get_num_messages ($imap_stream, $mailbox) {
- fputs ($imap_stream, sqimap_session_id() . " EXAMINE \"$mailbox\"\r\n");
- $read_ary = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $result, $message);
+ $read_ary = sqimap_run_command ($imap_stream, " EXAMINE \"$mailbox\"", true, $result, $message);
for ($i = 0; $i < count($read_ary); $i++) {
if (ereg("[^ ]+ +([^ ]+) +EXISTS", $read_ary[$i], $regs)) {
return $regs[1];
*/
function sqimap_unseen_messages ($imap_stream, $mailbox) {
//fputs ($imap_stream, sqimap_session_id() . " SEARCH UNSEEN NOT DELETED\r\n");
- fputs ($imap_stream, sqimap_session_id() . " STATUS \"$mailbox\" (UNSEEN)\r\n");
- $read_ary = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $result, $message);
+ $read_ary = sqimap_run_command ($imap_stream, " STATUS \"$mailbox\" (UNSEEN)", true, $result, $message);
ereg("UNSEEN ([0-9]+)", $read_ary[0], $regs);
return $regs[1];
}
*/
function sqimap_append ($imap_stream, $sent_folder, $length) {
fputs ($imap_stream, sqimap_session_id() . " APPEND \"$sent_folder\" (\\Seen) \{$length}\r\n");
- $tmp = fgets ($imap_stream, 1024);
+ $tmp = fgets ($imap_stream, 1024);
}
function sqimap_append_done ($imap_stream) {
*************************/
function sqimap_mailbox_expunge ($imap_stream, $mailbox,$handle_errors = true)
{
- fputs ($imap_stream, sqimap_session_id() . " EXPUNGE\r\n");
- $read = sqimap_read_data($imap_stream, sqimap_session_id(),
- $handle_errors, $response, $message);
+ $read = sqimap_run_command($imap_stream, 'EXPUNGE',
+ $handle_errors, $response, $message);
}
if (! isset($mailbox)) {
return false;
}
- fputs ($imap_stream, sqimap_session_id() . " LIST \"\" \"$mailbox\"\r\n");
- $mbx = sqimap_read_data($imap_stream, sqimap_session_id(),
- true, $response, $message);
+ $mbx = sqimap_run_command($imap_stream, "LIST \"\" \"$mailbox\"",
+ true, $response, $message);
return isset($mbx[0]);
}
return;
}
- fputs ($imap_stream, sqimap_session_id() . " SELECT \"$mailbox\"\r\n");
- $read = sqimap_read_data($imap_stream, sqimap_session_id(),
- true, $response, $message);
+ $read = sqimap_run_command($imap_stream, "SELECT \"$mailbox\"",
+ true, $response, $message);
if ($recent) {
for ($i=0; $i<count($read); $i++) {
if (strpos(strtolower($read[$i]), 'recent')) {
return $r[1];
}
if ($auto_expunge) {
- fputs ($imap_stream, sqimap_session_id() . " EXPUNGE\r\n");
- $tmp = sqimap_read_data($imap_stream, sqimap_session_id(),
- false, $a, $b);
+ $tmp = sqimap_run_command($imap_stream, "EXPUNGE",
+ false, $a, $b);
}
}
if (strtolower($type) == 'noselect') {
$mailbox = $mailbox.$delimiter;
}
- fputs ($imap_stream, sqimap_session_id() . " CREATE \"$mailbox\"\r\n");
- $read_ary = sqimap_read_data($imap_stream, sqimap_session_id(),
- true, $response, $message);
+ $read_ary = sqimap_run_command($imap_stream, "CREATE \"$mailbox\"",
+ true, $response, $message);
sqimap_subscribe ($imap_stream, $mailbox);
}
******************************************************************************/
function sqimap_subscribe ($imap_stream, $mailbox)
{
- fputs ($imap_stream, sqimap_session_id() . " SUBSCRIBE \"$mailbox\"\r\n");
- $read_ary = sqimap_read_data($imap_stream, sqimap_session_id(),
+ $read_ary = sqimap_run_command($imap_stream, " SUBSCRIBE \"$mailbox\"",
true, $response, $message);
}
{
global $imap_server_type;
- fputs ($imap_stream, sqimap_session_id() . " UNSUBSCRIBE \"$mailbox\"\r\n");
- $read_ary = sqimap_read_data($imap_stream, sqimap_session_id(),
+ $read_ary = sqimap_run_command($imap_stream, " UNSUBSCRIBE \"$mailbox\"",
true, $response, $message);
}
******************************************************************************/
function sqimap_mailbox_delete ($imap_stream, $mailbox)
{
- fputs ($imap_stream, sqimap_session_id() . " DELETE \"$mailbox\"\r\n");
- $read_ary = sqimap_read_data($imap_stream, sqimap_session_id(),
+ $read_ary = sqimap_run_command($imap_stream, "DELETE \"$mailbox\"",
true, $response, $message);
sqimap_unsubscribe ($imap_stream, $mailbox);
}
$boxes = FALSE;
}
- $cmd = sqimap_session_id() . " RENAME \"" . quoteIMAP($old_name) . "\" \"" .
- quoteIMAP($new_name) . "\"\r\n";
- fputs($imap_stream, $cmd);
- $data = sqimap_read_data($imap_stream, sqimap_session_id(),
+ $cmd = 'RENAME "' . quoteIMAP($old_name) . '" "' . quoteIMAP($new_name) . '"';
+ $data = sqimap_run_command($imap_stream, $cmd,
TRUE, $response, $message);
sqimap_unsubscribe($imap_stream, $old_name.$postfix);
sqimap_subscribe($imap_stream, $new_name.$postfix);
require_once('../functions/array.php');
/** LSUB array **/
- fputs ($imap_stream, sqimap_session_id() .
- " LSUB \"$folder_prefix\" \"*\"\r\n");
- $lsub_ary = sqimap_read_data ($imap_stream, sqimap_session_id(),
+ $lsub_ary = sqimap_run_command ($imap_stream, "LSUB \"$folder_prefix\" \"*\"",
true, $response, $message);
/* Section about removing the last element was removed */
$mbx = $sorted_lsub_ary[$i];
}
- fputs ($imap_stream, sqimap_session_id() . " LIST \"\" \"$mbx\"\r\n");
- $read = sqimap_read_data ($imap_stream, sqimap_session_id(),
+ $read = sqimap_run_command ($imap_stream, "LIST \"\" \"$mbx\"",
true, $response, $message);
/* Another workaround for EIMS */
if (isset($read[1]) &&
* we'll get it for them anyway
*/
if ($inbox_subscribed == false || $inbox_in_list == false) {
- fputs ($imap_stream, sqimap_session_id() . " LIST \"\" \"INBOX\"\r\n");
- $inbox_ary = sqimap_read_data ($imap_stream, sqimap_session_id(),
+ $inbox_ary = sqimap_run_command ($imap_stream, "LIST \"\" \"INBOX\"",
true, $response, $message);
/* Another workaround for EIMS */
if (isset($inbox_ary[1]) &&
$boxes[$g]["id"] = $g;
/** Now lets get the flags for this mailbox **/
- fputs ($imap_stream, sqimap_session_id() . " LIST \"\" \"$mailbox\"\r\n");
- $read_mlbx = sqimap_read_data ($imap_stream, sqimap_session_id(),
+ $read_mlbx = sqimap_run_command ($imap_stream, "LIST \"\" \"$mailbox\"",
true, $response, $message);
/* Another workaround for EIMS */
** Copies specified messages to specified folder
****************************************************************************/
function sqimap_messages_copy ($imap_stream, $start, $end, $mailbox) {
- fputs ($imap_stream, sqimap_session_id() . " COPY $start:$end \"$mailbox\"\r\n");
- $read = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $response, $message);
+ $read = sqimap_run_command ($imap_stream, "COPY $start:$end \"$mailbox\"", true, $response, $message);
}
/****************************************************************************
** Sets the specified messages with specified flag
****************************************************************************/
function sqimap_messages_flag ($imap_stream, $start, $end, $flag) {
- fputs ($imap_stream, sqimap_session_id() . " STORE $start:$end +FLAGS (\\$flag)\r\n");
- $read = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $response, $message);
+ $read = sqimap_run_command ($imap_stream, "STORE $start:$end +FLAGS (\\$flag)", true, $response, $message);
}
** Remove specified flag from specified messages
****************************************************************************/
function sqimap_messages_remove_flag ($imap_stream, $start, $end, $flag) {
- fputs ($imap_stream, sqimap_session_id() . " STORE $start:$end -FLAGS (\\$flag)\r\n");
- $read = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $response, $message);
+ $read = sqimap_run_command ($imap_stream, "STORE $start:$end -FLAGS (\\$flag)", true, $response, $message);
}
** Returns the flags for the specified messages
****************************************************************************/
function sqimap_get_flags ($imap_stream, $i) {
- fputs ($imap_stream, sqimap_session_id() . " FETCH $i:$i FLAGS\r\n");
- $read = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $response, $message);
+ $read = sqimap_run_command ($imap_stream, "FETCH $i:$i FLAGS", true, $response, $message);
if (ereg("FLAGS(.*)", $read[0], $regs)) {
return explode(" ", trim(ereg_replace('[\\(\\)\\\\]', '', $regs[1])));
}
for ($i = 0; $i < sizeof($msg_list); $i++) {
$id2index[$msg_list[$i]] = $i;
}
- fputs ($imap_stream, sqimap_session_id() . " FETCH $msgs_str FLAGS\r\n");
- $result_list = sqimap_read_data_list ($imap_stream, sqimap_session_id(), true, $response, $message);
+ $result_list = sqimap_run_command_list ($imap_stream, "FETCH $msgs_str FLAGS", true, $response, $message);
$result_flags = array();
for ($i = 0; $i < sizeof($result_list); $i++) {
** Wrapper function that reformats the header information.
****************************************************************************/
function sqimap_get_message_header ($imap_stream, $id, $mailbox) {
- fputs ($imap_stream, sqimap_session_id() . " FETCH $id:$id BODY[HEADER]\r\n");
- $read = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $response, $message);
+ $read = sqimap_run_command ($imap_stream, "FETCH $id:$id BODY[HEADER]", true, $response, $message);
$header = sqimap_get_header($imap_stream, $read);
$header->id = $id;
$pos = $search_position;
$urlMailbox = urlencode($mailbox);
- $isid = sqimap_session_id();
/* Construct the Search QuERY */
- $ss = $isid;
if (isset($languages[$squirrelmail_language]['CHARSET']) &&
$languages[$squirrelmail_language]['CHARSET']) {
- $ss .= " SEARCH CHARSET ".$languages[$squirrelmail_language]['CHARSET']." ALL $search_where \"$search_what\"\r\n";
+ $ss = "SEARCH CHARSET ".$languages[$squirrelmail_language]['CHARSET']." ALL $search_where \"$search_what\"";
} else {
- $ss .= " SEARCH ALL $search_where \"$search_what\"\r\n";
+ $ss .= "SEARCH ALL $search_where \"$search_what\"";
}
- fputs($imapConnection,$ss);
/* Read Data Back From IMAP */
- $readin = sqimap_read_data ($imapConnection, $isid, false, $result, $message);
+ $readin = sqimap_run_command ($imapConnection, $ss, true, $result, $message);
if (isset($languages[$squirrelmail_language]['CHARSET']) && strtolower($result) == 'no') {
- $ss = $isid . " SEARCH CHARSET \"US-ASCII\" ALL $search_where \"$search_what\"\r\n";
- fputs ($imapConnection, $ss);
- $readin = sqimap_read_data ($imapConnection, $isid, true, $result, $message);
+ $ss = "SEARCH CHARSET \"US-ASCII\" ALL $search_where \"$search_what\"";
+ $readin = sqimap_run_command ($imapConnection, $ss, true, $result, $message);
}
unset($messagelist); $msgs=""; $c = 0;
}
}
-?>
\ No newline at end of file
+?>
// that it is the first one. That is usually the case anyway.
if (!$ent_id)
$ent_id = 1;
- $sid = sqimap_session_id();
- fputs ($imap_stream, "$sid FETCH $id BODY[$ent_id]\r\n");
- $data = sqimap_read_data ($imap_stream, $sid, true, $response, $message);
+ $data = sqimap_run_command ($imap_stream, " FETCH $id BODY[$ent_id]", true, $response, $message);
$topline = array_shift($data);
while (! ereg('\\* [0-9]+ FETCH ', $topline) && $data)
$topline = array_shift($data);
in order to parse html messages. Let's get them here.
*/
if ( $ret{0} == '<' ) {
- fputs ($imap_stream, "$sid FETCH $id BODY[$ent_id.MIME]\r\n");
- $data = sqimap_read_data ($imap_stream, $sid, true, $response, $message);
+ $data = sqimap_run_command ($imap_stream, "FETCH $id BODY[$ent_id.MIME]", true, $response, $message);
$base = '';
$k = 10;
foreach( $data as $d ) {
_("Message:") . " $message<BR>" .
_("FETCH line:") . " $topline<BR></tt></font></b>";
- fputs ($imap_stream, "$sid FETCH $passed_id BODY[]\r\n");
- $data = sqimap_read_data ($imap_stream, $sid, true, $response, $message);
+ $data = sqimap_run_command ($imap_stream, "FETCH $passed_id BODY[]", true, $response, $message);
array_shift($data);
$wholemessage = implode('', $data);
return( $ret );
}
-?>
\ No newline at end of file
+?>