Added "List all" button to javascript address book.
[squirrelmail.git] / src / read_body.php
CommitLineData
59177427 1<?php
2a32fc83 2 session_start();
3
d068c0ec 4 if (!isset($config_php))
5 include("../config/config.php");
6 if (!isset($strings_php))
7 include("../functions/strings.php");
8 if (!isset($page_header_php))
9 include("../functions/page_header.php");
10 if (!isset($imap_php))
11 include("../functions/imap.php");
12 if (!isset($mime_php))
13 include("../functions/mime.php");
14 if (!isset($date_php))
15 include("../functions/date.php");
be69e508 16
90033b64 17 // given an IMAP message id number, this will look it up in the cached and sorted msgs array and
18 // return the index. used for finding the next and previous messages
19
20 // returns the index of the next valid message from the array
21 function findNextMessage() {
53524fa0 22 global $msort, $currentArrayIndex, $msgs;
23 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
24 if ($currentArrayIndex == $msgs[$key]["ID"]) {
25 next($msort);
26 $key = key($msort);
27 if (isset($key))
28 return $msgs[$key]["ID"];
29 }
30 }
90033b64 31 return -1;
32 }
33
34 // returns the index of the previous message from the array
35 function findPreviousMessage() {
53524fa0 36 global $msort, $currentArrayIndex, $msgs;
37 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
38 if ($currentArrayIndex == $msgs[$key]["ID"]) {
39 prev($msort);
40 $key = key($msort);
41 if (isset($key))
42 return $msgs[$key]["ID"];
43 }
44 }
90033b64 45 return -1;
46 }
47
48 if (isset($msgs)) {
53524fa0 49 $currentArrayIndex = $passed_id;
50 /*
90033b64 51 for ($i=0; $i < count($msgs); $i++) {
52 if ($msgs[$i]["ID"] == $passed_id) {
53 $currentArrayIndex = $i;
54 break;
55 }
56 }
53524fa0 57 */
90033b64 58 } else {
59 $currentArrayIndex = -1;
60 }
61
1108e8bb 62 for ($i = 0; $i < count($msgs); $i++) {
63 if ($msgs[$i]["ID"] == $passed_id)
64 $msgs[$i]["FLAG_SEEN"] = true;
65 }
66
d3cdb279 67 include("../src/load_prefs.php");
e1469126 68 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
813eba2f 69 sqimap_mailbox_select($imapConnection, $mailbox);
be69e508 70
f7fb20fe 71 // $message contains all information about the message
72 // including header and body
813eba2f 73 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
31f3d7c0 74
f8f9bed9 75 displayPageHeader($color, $mailbox);
d4467150 76
f7fb20fe 77 /** translate the subject and mailbox into url-able text **/
e39d73e5 78 $url_subj = urlencode(trim(stripslashes($message["HEADER"]["SUBJECT"])));
8467bf00 79 $urlMailbox = urlencode($mailbox);
5c55c295 80 $url_replyto = urlencode($message["HEADER"]["REPLYTO"]);
be69e508 81
4bfed9f3 82 $url_replytoall = urlencode($message["HEADER"]["REPLYTO"]);
83 $url_replytoallcc = urlencode(getLineOfAddrs($message["HEADER"]["TO"]) . ", " . getLineOfAddrs($message["HEADER"]["CC"]));
84
f7fb20fe 85 $dateString = getLongDateString($message["HEADER"]["DATE"]);
31f3d7c0 86
b581fa60 87 /** TEXT STRINGS DEFINITIONS **/
88 $echo_more = _("more");
89 $echo_less = _("less");
90
078a40a4 91 /** FORMAT THE TO STRING **/
2844086d 92 $i = 0;
93 $to_string = "";
f7fb20fe 94 $to_ary = $message["HEADER"]["TO"];
2844086d 95 while ($i < count($to_ary)) {
f7fb20fe 96 $to_ary[$i] = htmlspecialchars($to_ary[$i]);
be8e07f8 97
2844086d 98 if ($to_string)
99 $to_string = "$to_string<BR>$to_ary[$i]";
100 else
101 $to_string = "$to_ary[$i]";
102
103 $i++;
104 if (count($to_ary) > 1) {
105 if ($show_more == false) {
106 if ($i == 1) {
9f2215a1 107 $to_string = "$to_string&nbsp;(<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&sort=$sort&startMessage=$startMessage&show_more=1&show_more_cc=$show_more_cc\">$echo_more</A>)";
2844086d 108 $i = count($to_ary);
109 }
110 } else if ($i == 1) {
9f2215a1 111 $to_string = "$to_string&nbsp;(<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&sort=$sort&startMessage=$startMessage&show_more=0&show_more_cc=$show_more_cc\">$echo_less</A>)";
2844086d 112 }
113 }
114 }
115
078a40a4 116 /** FORMAT THE CC STRING **/
117 $i = 0;
118 $cc_string = "";
f7fb20fe 119 $cc_ary = $message["HEADER"]["CC"];
078a40a4 120 while ($i < count($cc_ary)) {
f7fb20fe 121 $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
078a40a4 122 if ($cc_string)
123 $cc_string = "$cc_string<BR>$cc_ary[$i]";
124 else
125 $cc_string = "$cc_ary[$i]";
126
127 $i++;
128 if (count($cc_ary) > 1) {
129 if ($show_more_cc == false) {
130 if ($i == 1) {
9f2215a1 131 $cc_string = "$cc_string&nbsp;(<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&sort=$sort&startMessage=$startMessage&show_more_cc=1&show_more=$show_more\">$echo_more</A>)";
078a40a4 132 $i = count($cc_ary);
133 }
134 } else if ($i == 1) {
9f2215a1 135 $cc_string = "$cc_string&nbsp;(<A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$passed_id&sort=$sort&startMessage=$startMessage&show_more_cc=0&show_more=$show_more\">$echo_less</A>)";
078a40a4 136 }
137 }
138 }
139
f7fb20fe 140 /** make sure everything will display in HTML format **/
9cccb418 141 $from_name = decodeHeader(htmlspecialchars($message["HEADER"]["FROM"]));
142 $subject = decodeHeader(htmlspecialchars(stripslashes($message["HEADER"]["SUBJECT"])));
078a40a4 143
8467bf00 144 echo "<BR>";
4809f489 145 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=98% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
f8f9bed9 146 echo " <TR><TD BGCOLOR=\"$color[0]\" WIDTH=100%>";
4809f489 147 echo " <TABLE WIDTH=100% CELLSPACING=0 BORDER=0 COLS=2 CELLPADDING=3>";
31f3d7c0 148 echo " <TR>";
90033b64 149 echo " <TD ALIGN=LEFT WIDTH=33%>";
aae41ae9 150 echo " <SMALL>";
90033b64 151 echo " <A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">";
b581fa60 152 echo _("Message List");
153 echo "</A>&nbsp;|&nbsp;";
9f2215a1 154 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=1\">";
b581fa60 155 echo _("Delete");
156 echo "</A>&nbsp;&nbsp;";
aae41ae9 157 echo " </SMALL>";
90033b64 158 echo " </TD><TD WIDTH=33% ALIGN=CENTER>";
159 echo " <SMALL>\n";
160 if ($currentArrayIndex == -1) {
9988d19e 161 echo "Previous&nbsp;|&nbsp;Next";
90033b64 162 } else {
163 $prev = findPreviousMessage();
164 $next = findNextMessage();
165 if ($prev != -1)
166 echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$mailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A>&nbsp;|&nbsp;";
167 else
168 echo _("Previous") . "&nbsp;|&nbsp;";
169 if ($next != -1)
170 echo "<a href=\"read_body.php?passed_id=$next&mailbox=$mailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>";
171 else
172 echo _("Next");
173 }
174 echo " </SMALL>\n";
175 echo " </TD><TD WIDTH=33% ALIGN=RIGHT>";
aae41ae9 176 echo " <SMALL>";
9f2215a1 177 echo " <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox\">";
b581fa60 178 echo _("Forward");
179 echo "</A>&nbsp;|&nbsp;";
9f2215a1 180 echo " <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox\">";
b581fa60 181 echo _("Reply");
182 echo "</A>&nbsp;|&nbsp;";
9f2215a1 183 echo " <A HREF=\"compose.php?send_to=$url_replytoall&send_to_cc=$url_replytoallcc&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox\">";
b581fa60 184 echo _("Reply All");
185 echo "</A>&nbsp;&nbsp;";
aae41ae9 186 echo " </SMALL>";
31f3d7c0 187 echo " </TD>";
188 echo " </TR>";
189 echo " </TABLE>";
8467bf00 190 echo " </TD></TR>";
4809f489 191 echo " <TR><TD CELLSPACING=0 WIDTH=100%>";
97afcee9 192 echo " <TABLE COLS=2 WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=3>\n";
be69e508 193 echo " <TR>\n";
194 /** subject **/
4809f489 195 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT>\n";
b581fa60 196 echo _("Subject:");
f8f9bed9 197 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85%>\n";
aae41ae9 198 echo " <B>$subject</B>\n";
be69e508 199 echo " </TD>\n";
200 echo " </TR>\n";
201 /** from **/
202 echo " <TR>\n";
4809f489 203 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT>\n";
b581fa60 204 echo _("From:");
f8f9bed9 205 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85%>\n";
aae41ae9 206 echo " <B>$from_name</B>\n";
be69e508 207 echo " </TD>\n";
208 echo " </TR>\n";
209 /** date **/
210 echo " <TR>\n";
4809f489 211 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT>\n";
32c7898c 212 echo _("Date:");
f8f9bed9 213 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85%>\n";
aae41ae9 214 echo " <B>$dateString</B>\n";
be69e508 215 echo " </TD>\n";
216 echo " </TR>\n";
2844086d 217 /** to **/
218 echo " <TR>\n";
4809f489 219 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
b581fa60 220 echo _("To:");
f8f9bed9 221 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85% VALIGN=TOP>\n";
aae41ae9 222 echo " <B>$to_string</B>\n";
2844086d 223 echo " </TD>\n";
224 echo " </TR>\n";
078a40a4 225 /** cc **/
f7fb20fe 226 if ($message["HEADER"]["CC"][0]) {
078a40a4 227 echo " <TR>\n";
4809f489 228 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
aae41ae9 229 echo " Cc:\n";
f8f9bed9 230 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85% VALIGN=TOP>\n";
aae41ae9 231 echo " <B>$cc_string</B>\n";
078a40a4 232 echo " </TD>\n";
233 echo " </TR>\n";
234 }
4809f489 235 echo "</TABLE>";
236 echo " </TD></TR>";
be69e508 237
f8f9bed9 238 echo " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n";
11307a4c 239 $body = formatBody($message, $color, $wrap_at);
4809f489 240 echo "<BR>";
5c55c295 241
7831268e 242 echo "$body";
d4467150 243
7831268e 244 echo " </TD></TR>\n";
245 echo " <TR><TD BGCOLOR=\"$color[9]\">&nbsp;</TD></TR>";
be69e508 246 echo "</TABLE>\n";
247
b581fa60 248?>