X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Fread_body.php;h=6950bcb4e2f1d2263c5c7a8f6517e6d4e9f89fd8;hb=38c944cca3a80b0d62def6b1974d1abec143ff54;hp=0aa2c9ef5b46366ec484ab9e161a3f671532bef6;hpb=54817114a34450766c7d5967fbc409b4136de8a6;p=squirrelmail.git
diff --git a/src/read_body.php b/src/read_body.php
index 0aa2c9ef..6950bcb4 100644
--- a/src/read_body.php
+++ b/src/read_body.php
@@ -18,37 +18,70 @@ require_once('../functions/mime.php');
require_once('../functions/date.php');
require_once('../functions/url_parser.php');
require_once('../functions/smtp.php');
+require_once('../functions/html.php');
+require_once('../src/view_header.php');
+
/**
-* Given an IMAP message id number, this will look it up in the cached
-* and sorted msgs array and return the index. Used for finding the next
-* and previous messages.
-*
-* returns the index of the next valid message from the array
-*/
+ * Given an IMAP message id number, this will look it up in the cached
+ * and sorted msgs array and return the index. Used for finding the next
+ * and previous messages.
+ *
+ * @return the index of the next valid message from the array
+ */
function findNextMessage() {
- global $msort, $currentArrayIndex, $msgs, $sort;
+ global $msort, $currentArrayIndex, $msgs, $sort,
+ $thread_sort_messages, $allow_server_sort,
+ $server_sort_array;
+ if (!is_array($server_sort_array)) {
+ $thread_sort_messages = 0;
+ $allow_server_sort = FALSE;
+ }
$result = -1;
-
- if ($sort == 6) {
+ if ($thread_sort_messages == 1 || $allow_server_sort == TRUE) {
+ reset($server_sort_array);
+ while(list($key, $value) = each ($server_sort_array)) {
+ if ($currentArrayIndex == $value) {
+ if ($key == (count($server_sort_array) - 1)) {
+ $result = -1;
+ break;
+ }
+ $result = $server_sort_array[$key + 1];
+ break;
+ }
+ }
+ }
+ elseif ($sort == 6 && $allow_server_sort != TRUE &&
+ $thread_sort_messages != 1) {
if ($currentArrayIndex != 1) {
$result = $currentArrayIndex - 1;
}
- } else {
+ }
+ elseif ($allow_server_sort != TRUE && $thread_sort_messages != 1 ) {
+ if (!is_array($msort)) {
+ return -1;
+ }
for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
if ($currentArrayIndex == $msgs[$key]['ID']) {
next($msort);
$key = key($msort);
- if (isset($key))
+ if (isset($key)){
$result = $msgs[$key]['ID'];
break;
+ }
}
}
}
return ($result);
}
-/** Removes just one address from the list of addresses. */
+/**
+ * Removes just one address from the list of addresses.
+ *
+ * @param &$addr_list a by-ref array of addresses
+ * @param $addr an address to remove
+ * @return void, since it operates on a by-ref param
+ */
function RemoveAddress(&$addr_list, $addr) {
if ($addr != '') {
foreach (array_keys($addr_list, $addr) as $key_to_delete) {
@@ -60,16 +93,37 @@ function RemoveAddress(&$addr_list, $addr) {
/** returns the index of the previous message from the array. */
function findPreviousMessage() {
global $msort, $currentArrayIndex, $sort, $msgs, $imapConnection,
- $mailbox, $data_dir, $username;
-
+ $mailbox, $data_dir, $username, $thread_sort_messages,
+ $allow_server_sort, $server_sort_array;
$result = -1;
-
- if ($sort == 6) {
+ if (!is_array($server_sort_array)) {
+ $thread_sort_messages = 0;
+ $allow_server_sort = FALSE;
+ }
+ if ($thread_sort_messages == 1 || $allow_server_sort == TRUE) {
+ reset($server_sort_array);
+ while(list($key, $value) = each ($server_sort_array)) {
+ if ($currentArrayIndex == $value) {
+ if ($key == 0) {
+ $result = -1;
+ break;
+ }
+ $result = $server_sort_array[$key -1];
+ break;
+ }
+ }
+ }
+ elseif ($sort == 6 && $allow_server_sort != TRUE &&
+ $thread_sort_messages != 1) {
$numMessages = sqimap_get_num_messages($imapConnection, $mailbox);
if ($currentArrayIndex != $numMessages) {
$result = $currentArrayIndex + 1;
}
- } else {
+ }
+ elseif ($thread_sort_messages != 1 && $allow_server_sort != TRUE) {
+ if (!is_array($msort)) {
+ return -1;
+ }
for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
if ($currentArrayIndex == $msgs[$key]['ID']) {
prev($msort);
@@ -85,9 +139,9 @@ function findPreviousMessage() {
}
/**
-* Displays a link to a page where the message is displayed more
-* "printer friendly".
-*/
+ * Displays a link to a page where the message is displayed more
+ * "printer friendly".
+ */
function printer_friendly_link() {
global $passed_id, $mailbox, $ent_num, $color,
$pf_subtle_link,
@@ -98,25 +152,24 @@ function printer_friendly_link() {
}
$params = '?passed_ent_id=' . $ent_num .
- '&mailbox=' . urlencode($mailbox) .
- '&passed_id=' . $passed_id;
+ '&mailbox=' . urlencode($mailbox) .
+ '&passed_id=' . $passed_id;
$print_text = _("View Printable Version");
if (!$pf_subtle_link) {
/* The link is large, on the bottom of the header panel. */
- $result = '
' .
- '' .
- ' ' .
- ' | '."\n";
+ $result = html_tag( 'tr', '', '', $color[0] ) .
+ html_tag( 'td', ' ', 'right', '', 'class="medText" valign="top"' ) .
+ html_tag( 'td', '', 'left', '', 'class="medText" valign="top" colspan="2"' ) . "\n";
} else {
/* The link is subtle, below "view full header". */
- $result = " \n";
+ $result = " \n";
}
/* Output the link. */
if ($javascript_on) {
- $result .= '\n" .
- "$print_text\n";
+ "$print_text\n";
} else {
- $result .= '$print_text\n";
+ $result .= '$print_text\n";
}
if (!$pf_subtle_link) {
@@ -139,22 +192,8 @@ function printer_friendly_link() {
}
function ServerMDNSupport( $read ) {
-
- $num = 0;
- $resp = '';
- while ($num < count($read) ) {
- $resp .= $read[$num];
- $num++;
- }
- $read[] = split(' * ', $resp);
- $num = 0;
- $ret = FALSE;
- while ( !$ret && $num < count($read) ) {
- if ( ereg('PERMANENTFLAGS', $read[$num] ) ) {
- $ret = ( ereg('mdnsent',strtolower($read[$num]) ) || ereg("\\\*", $read[$num] ) );
- }
- $num++;
- }
+ /* escaping $ doesn't work -> \x36 */
+ $ret = preg_match( '/(\x36MDNSent|\\\*)/i', $read );
return ( $ret );
}
@@ -162,9 +201,7 @@ function SendMDN ( $recipient , $sender) {
global $imapConnection, $mailbox, $username, $attachment_dir, $SERVER_NAME,
$version, $attachments, $identity, $data_dir, $passed_id;
- $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
- $header = $message->header;
-
+ $header = sqimap_get_message_header($imapConnection, $passed_id, $mailbox);
$hashed_attachment_dir = getHashedDir($username, $attachment_dir);
// part 1 (RFC2298)
@@ -179,18 +216,15 @@ function SendMDN ( $recipient , $sender) {
$subject = $header->subject;
$now = getLongDateString( time() );
+ set_my_charset();
+
$body = _("Your message") . "\r\n\r\n" .
"\t" . _("To:") . ' ' . $to . "\r\n" .
"\t" . _("Subject:") . ' ' . $subject . "\r\n" .
"\t" . _("Sent:") . ' ' . $senton . "\r\n" .
"\r\n" .
sprintf( _("Was displayed on %s"), $now );
-/*
- $body = sprintf( _("This message sent on %s to %s with subject \"%s\" has been displayed on %s."),
- $senton, $to, $subject, $now ) .
- "\r\n" .
- _("This is no guarantee that the message has been read or understood.") . "\r\n";
-*/
+
// part2 (RFC2298)
$original_recipient = $to;
@@ -216,30 +250,23 @@ function SendMDN ( $recipient , $sender) {
$newAttachment = array();
$newAttachment['localfilename'] = $localfilename;
$newAttachment['type'] = "message/disposition-notification";
-
+ $newAttachment['session']=-1;
$attachments[] = $newAttachment;
$MDN_to = trim($recipient);
$reply_id = 0;
- return (SendMessage($MDN_to,'','', _("Read:") . ' ' . $subject, $body,$reply_id, True, 3) );
+ return (SendMessage($MDN_to, '', '', _("Read:") . ' ' . $subject,
+ $body, $reply_id, True, 3, -1) );
}
function ToggleMDNflag ( $set ) {
-
- global $imapConnection, $passed_id, $mailbox;
-
- if ( $set ) {
- $sg = '+';
-
- } else {
- $sg = '-';
- }
-
- $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
+ global $imapConnection, $passed_id, $mailbox, $uid;
sqimap_mailbox_select($imapConnection, $mailbox);
- $read = sqimap_run_command ($imapConnection, $cmd, true, $response, $readmessage);
-
+ $sg = $set?'+':'-';
+ $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
+ $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
+ $readmessage, $uid);
}
function ClearAttachments() {
@@ -247,17 +274,90 @@ function ClearAttachments() {
$hashed_attachment_dir = getHashedDir($username, $attachment_dir);
+ $rem_attachments = array();
foreach ($attachments as $info) {
- $attached_file = "$hashed_attachment_dir/$info[localfilename]";
- if (file_exists($attached_file)) {
- unlink($attached_file);
- }
- }
+ if ($info['session'] == -1) {
+ $attached_file = "$hashed_attachment_dir/$info[localfilename]";
+ if (file_exists($attached_file)) {
+ unlink($attached_file);
+ }
+ } else {
+ $rem_attachments[] = $info;
+ }
+ }
+ $attachments = $rem_attachments;
+}
- $attachments = array();
+function formatRecipientString($recipients, $item ) {
+ global $base_uri, $passed_id, $urlMailbox, $startMessage, $show_more_cc,
+ $echo_more, $echo_less, $show_more, $show_more_bcc, $sort, $passed_ent_id,
+ $PHP_SELF;
+
+ $i = 0;
+ $url_string = '';
+ if ((is_array($recipients)) && (isset($recipients[0]))) {
+ $string = '';
+ $ary = $recipients;
+ $show = false;
+
+ if ($item == 'to') {
+ if ($show_more) {
+ $show = true;
+ $url = set_url_var($PHP_SELF, 'show_more',0);
+ } else {
+ $url = set_url_var($PHP_SELF, 'show_more',1);
+ }
+ } else if ($item == 'cc') {
+ if ($show_more_cc) {
+ $url = set_url_var($PHP_SELF, 'show_more_cc',0);
+ $show = true;
+ } else {
+ $url = set_url_var($PHP_SELF, 'show_more_cc',1);
+ }
+ } else if ($item == 'bcc') {
+ if ($show_more_bcc) {
+ $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
+ $show = true;
+ } else {
+ $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
+ }
+ }
+
+ $cnt = count($ary);
+ while ($i < $cnt) {
+ $addr_o = $ary[$i];
+ $ary[$i] = $addr_o->getAddress();
+ $ary[$i] = decodeHeader(htmlspecialchars($ary[$i]));
+ $url_string .= $ary[$i];
+ if ($string) {
+ $string .= ' '.$ary[$i];
+ } else {
+ $string = $ary[$i];
+ if ($cnt>1) {
+ $string .= ' ('.$echo_less.')';
+ } else {
+ $string .= '">'.$echo_more.')';
+ break;
+ }
+ }
+ }
+ $i++;
+ }
+ }
+ else {
+ $string = '';
+ }
+ $url_string = urlencode($url_string);
+ $result = array();
+ $result['str'] = $string;
+ $result['url_str'] = $url_string;
+ return $result;
}
+
/*
* Main of read_boby.php --------------------------------------------------
*/
@@ -268,83 +368,67 @@ function ClearAttachments() {
$passed_id
*/
-$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
-$read = sqimap_mailbox_select($imapConnection, $mailbox);
+global $uid_support, $sqimap_capabilities;
+
+if (isset($mailbox)){
+ $mailbox = urldecode( $mailbox );
+}
+
+$imapConnection = sqimap_login($username, $key, $imapServerAddress,
+ $imapPort, 0);
+
+$mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
+
+if (!isset($messages)) {
+ $messages = array();
+ session_register('messages');
+ echo "SET messages";
+}
+
+/**
+ * $message contains all information about the message
+ * including header and body
+ */
+if (!isset($messages[$passed_id])) {
+ $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
+ $messages["$passed_id"] = $message;
+ $header = $message->header;
+
+ echo "NOT SET $passed_id";
+} else {
+ $message = $messages[$passed_id];
+ $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
+ if (isset($passed_ent_id)) {
+ $message = $message->getEntity($passed_ent_id);
+ $message->id = $passed_id;
+ $message->mailbox = $mailbox;
+ }
+ $header = $message->header;
+}
do_hook('html_top');
/*
* The following code sets necesarry stuff for the MDN thing
*/
-if( $default_use_mdn &&
- ( $mdn_user_support = getPref($data_dir, $username, 'mdn_user_support', $default_use_mdn) ) ) {
-
- $supportMDN = ServerMDNSupport($read);
- $flags = sqimap_get_flags ($imapConnection, $passed_id);
- $FirstTimeSee = !(in_array( 'Seen', $flags ));
+if($default_use_mdn &&
+ ($mdn_user_support = getPref($data_dir, $username, 'mdn_user_support',
+ $default_use_mdn))) {
+ $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
+ $FirstTimeSee = !$message->is_seen;
}
displayPageHeader($color, $mailbox);
-
/*
* The following code shows the header of the message and then exit
*/
if (isset($view_hdr)) {
- $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[HEADER]", true, $a, $b);
-
- echo ' ' .
- '\n" .
- "\n" .
- '';
-
- $cnum = 0;
- for ($i=1; $i < count($read); $i++) {
- $line = htmlspecialchars($read[$i]);
- if (eregi("^>", $line)) {
- $second[$i] = $line;
- $first[$i] = ' ';
- $cnum++;
- } else if (eregi("^[ |\t]", $line)) {
- $second[$i] = $line;
- $first[$i] = '';
- } else if (eregi("^([^:]+):(.+)", $line, $regs)) {
- $first[$i] = $regs[1] . ':';
- $second[$i] = $regs[2];
- $cnum++;
- } else {
- $second[$i] = trim($line);
- $first[$i] = '';
- }
- }
- for ($i=0; $i < count($second); $i = $j) {
- if (isset($first[$i])) {
- $f = $first[$i];
- }
- if (isset($second[$i])) {
- $s = nl2br($second[$i]);
- }
- $j = $i + 1;
- while (($first[$j] == '') && ($j < count($first))) {
- $s .= ' ' . nl2br($second[$j]);
- $j++;
- }
- parseEmail($s);
- if (isset($f)) echo "$f$s";
- }
- echo " | \n" .
- ' |