X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fimap_messages.php;h=0e140e5ad9a8e0c1d60f9e9378c76ab5e4a78f60;hb=b51a15da60e50d2446136428d383984a33766c46;hp=4dfa79d584190e6695c747b47c6af7881531d89e;hpb=c2e295583478b9c0c7a680e9d832d07f2f04c013;p=squirrelmail.git
diff --git a/functions/imap_messages.php b/functions/imap_messages.php
index 4dfa79d5..0e140e5a 100755
--- a/functions/imap_messages.php
+++ b/functions/imap_messages.php
@@ -1,110 +1,101 @@
' .
- _("ERROR : Could not complete request.") .
- '
' .
- _("Unknown response from IMAP server: ") . ' 1.' .
- htmlspecialchars($read) . "
\n";
- break;
+ $msg['ERROR'] = $read; // htmlspecialchars should be done just before display. this is backend code
+ break;
}
$i = strpos($read,'(',$i_space+5);
$read = substr($read,$i+1);
@@ -670,6 +679,12 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $show_num=false,
break 3;
}
+ break;
+ case 'ENVELOPE':
+ break; // to be implemented, moving imap code out of the nessages class
+ sqimap_parse_address($read,$i,$msg);
+ break; // to be implemented, moving imap code out of the nessages class
+ case 'BODYSTRUCTURE':
break;
case 'INTERNALDATE':
$msg['INTERNALDATE'] = str_replace(' ', ' ',parseString($read,$i));
@@ -684,6 +699,7 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $show_num=false,
/* Now we can make a new header array with */
/* each element representing a headerline */
$hdr = explode("\n" , $hdr);
+ $aReceived = array();
foreach ($hdr as $line) {
$pos = strpos($line, ':');
if ($pos > 0) {
@@ -706,16 +722,25 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $show_num=false,
$type = substr($type, 0, $pos);
}
$type = explode("/", $type);
- if(!is_array($type)) {
+ if(!is_array($type) || count($type) < 2) {
$msg['TYPE0'] = 'text';
$msg['TYPE1'] = 'plain';
+ } else {
+ $msg['TYPE0'] = strtolower($type[0]);
+ $msg['TYPE1'] = strtolower($type[1]);
}
break;
+ case 'received':
+ $aReceived[] = $value;
+ break;
default: break;
}
}
}
}
+ if (count($aReceived)) {
+ $msg['RECEIVED'] = $aReceived;
+ }
break;
default:
++$i;
@@ -723,19 +748,140 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $show_num=false,
}
}
$msgi ="$unique_id";
- $msg['ID'] = $unique_id;
+ $msg['UID'] = $unique_id;
- $messages[$msgi] = $msg;
+ $aMessageList[$msgi] = $msg;
++$msgi;
}
- array_reverse($messages);
- return $messages;
+ return $aMessageList;
}
/**
-* Returns a message array with all the information about a message.
-* See the documentation folder for more information about this array.
-*/
+ * Work in process
+ * @private
+ * @author Marc Groot Koerkamp
+ */
+function sqimap_parse_envelope($read, &$i, &$msg) {
+ $arg_no = 0;
+ $arg_a = array();
+ ++$i;
+ for ($cnt = strlen($read); ($i < $cnt) && ($read{$i} != ')'); ++$i) {
+ $char = strtoupper($read{$i});
+ switch ($char) {
+ case '{':
+ case '"':
+ $arg_a[] = parseString($read,$i);
+ ++$arg_no;
+ break;
+ case 'N':
+ /* probably NIL argument */
+ if (strtoupper(substr($read, $i, 3)) == 'NIL') {
+ $arg_a[] = '';
+ ++$arg_no;
+ $i += 2;
+ }
+ break;
+ case '(':
+ /* Address structure (with group support)
+ * Note: Group support is useless on SMTP connections
+ * because the protocol doesn't support it
+ */
+ $addr_a = array();
+ $group = '';
+ $a=0;
+ for (; $i < $cnt && $read{$i} != ')'; ++$i) {
+ if ($read{$i} == '(') {
+ $addr = sqimap_parse_address($read, $i);
+ if (($addr[3] == '') && ($addr[2] != '')) {
+ /* start of group */
+ $group = $addr[2];
+ $group_addr = $addr;
+ $j = $a;
+ } else if ($group && ($addr[3] == '') && ($addr[2] == '')) {
+ /* end group */
+ if ($a == ($j+1)) { /* no group members */
+ $group_addr[4] = $group;
+ $group_addr[2] = '';
+ $group_addr[0] = "$group: Undisclosed recipients;";
+ $addr_a[] = $group_addr;
+ $group ='';
+ }
+ } else {
+ $addr[4] = $group;
+ $addr_a[] = $addr;
+ }
+ ++$a;
+ }
+ }
+ $arg_a[] = $addr_a;
+ break;
+ default: break;
+ }
+ }
+
+ if (count($arg_a) > 9) {
+ $d = strtr($arg_a[0], array(' ' => ' '));
+ $d = explode(' ', $d);
+ if (!$arg_a[1]) $arg_1[1] = '';
+ $msg['DATE'] = $d; /* argument 1: date */
+ $msg['SUBJECT'] = $arg_a[1]; /* argument 2: subject */
+ $msg['FROM'] = is_array($arg_a[2]) ? $arg_a[2][0] : ''; /* argument 3: from */
+ $msg['SENDER'] = is_array($arg_a[3]) ? $arg_a[3][0] : ''; /* argument 4: sender */
+ $msg['REPLY-TO'] = is_array($arg_a[4]) ? $arg_a[4][0] : ''; /* argument 5: reply-to */
+ $msg['TO'] = $arg_a[5]; /* argument 6: to */
+ $msg['CC'] = $arg_a[6]; /* argument 7: cc */
+ $msg['BCC'] = $arg_a[7]; /* argument 8: bcc */
+ $msg['IN-REPLY-TO'] = $arg_a[8]; /* argument 9: in-reply-to */
+ $msg['MESSAGE-ID'] = $arg_a[9]; /* argument 10: message-id */
+ }
+}
+
+/**
+ * Work in process
+ * @private
+ * @author Marc Groot Koerkamp
+ */
+function sqimap_parse_address($read, &$i) {
+ $arg_a = array();
+ for (; $read{$i} != ')'; ++$i) {
+ $char = strtoupper($read{$i});
+ switch ($char) {
+ case '{':
+ case '"': $arg_a[] = parseString($read,$i); break;
+ case 'n':
+ case 'N':
+ if (strtoupper(substr($read, $i, 3)) == 'NIL') {
+ $arg_a[] = '';
+ $i += 2;
+ }
+ break;
+ default: break;
+ }
+ }
+
+ if (count($arg_a) == 4) {
+ return $arg_a;
+
+// $adr = new AddressStructure();
+// $adr->personal = $arg_a[0];
+// $adr->adl = $arg_a[1];
+// $adr->mailbox = $arg_a[2];
+// $adr->host = $arg_a[3];
+ } else {
+ $adr = '';
+ }
+ return $adr;
+}
+
+/**
+ * Returns a message array with all the information about a message.
+ * See the documentation folder for more information about this array.
+ *
+ * @param resource $imap_stream imap connection
+ * @param integer $id uid of the message
+ * @param string $mailbox used for error handling, can be removed because we should return an error code and generate the message elsewhere
+ * @return Message Message object
+ */
function sqimap_get_message ($imap_stream, $id, $mailbox) {
// typecast to int to prohibit 1:* msgs sets
$id = (int) $id;
@@ -766,4 +912,39 @@ function sqimap_get_message ($imap_stream, $id, $mailbox) {
return $msg;
}
+/**
+* Depricated !!!!!!! DO NOT USE THIS, use sqimap_msgs_list_copy instead
+*/
+function sqimap_messages_copy ($imap_stream, $start, $end, $mailbox) {
+ $read = sqimap_run_command ($imap_stream, "COPY $start:$end " . sqimap_encode_mailbox_name($mailbox), true, $response, $message, TRUE);
+}
+
+/**
+* Depricated !!!!!!! DO NOT USE THIS, use sqimap_msgs_list_delete instead
+*/
+function sqimap_messages_delete ($imap_stream, $start, $end, $mailbox, $bypass_trash=false) {
+ global $move_to_trash, $trash_folder, $auto_expunge;
+
+ if (($move_to_trash == true) && ($bypass_trash != true) &&
+ (sqimap_mailbox_exists($imap_stream, $trash_folder) && ($mailbox != $trash_folder))) {
+ sqimap_messages_copy ($imap_stream, $start, $end, $trash_folder);
+ }
+ sqimap_messages_flag ($imap_stream, $start, $end, "Deleted", true);
+}
+
+/**
+* Depricated !!!!!!! DO NOT USE THIS, use sqimap_toggle_flag instead
+* Set a flag on the provided uid list
+* @param resource imap connection
+*/
+function sqimap_messages_flag ($imap_stream, $start, $end, $flag, $handle_errors) {
+ $read = sqimap_run_command ($imap_stream, "STORE $start:$end +FLAGS (\\$flag)", $handle_errors, $response, $message, TRUE);
+}
+
+/** @deprecated */
+function sqimap_get_small_header ($imap_stream, $id, $sent) {
+ $res = sqimap_get_small_header_list($imap_stream, $id, $sent);
+ return $res[0];
+}
+
?>