made sorting method persistant using session management
[squirrelmail.git] / src / read_body.php
1 <?php
2 session_start();
3
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");
16
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() {
22 global $currentArrayIndex, $msgs;
23 if ($currentArrayIndex < (count($msgs)-1))
24 return $msgs[$currentArrayIndex+1]["ID"];
25 return -1;
26 }
27
28 // returns the index of the previous message from the array
29 function findPreviousMessage() {
30 global $currentArrayIndex, $msgs;
31 if ($currentArrayIndex > 0)
32 return $msgs[$currentArrayIndex-1]["ID"];
33 return -1;
34 }
35
36 if (isset($msgs)) {
37 for ($i=0; $i < count($msgs); $i++) {
38 if ($msgs[$i]["ID"] == $passed_id) {
39 $currentArrayIndex = $i;
40 break;
41 }
42 }
43 } else {
44 $currentArrayIndex = -1;
45 }
46
47 include("../src/load_prefs.php");
48 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
49 sqimap_mailbox_select($imapConnection, $mailbox);
50
51 // $message contains all information about the message
52 // including header and body
53 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
54
55 echo "<HTML>";
56 echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
57 displayPageHeader($color, $mailbox);
58
59 /** translate the subject and mailbox into url-able text **/
60 $url_subj = urlencode(trim(stripslashes($message["HEADER"]["SUBJECT"])));
61 $urlMailbox = urlencode($mailbox);
62 $url_replyto = urlencode($message["HEADER"]["REPLYTO"]);
63
64 $url_replytoall = urlencode($message["HEADER"]["REPLYTO"]);
65 $url_replytoallcc = urlencode(getLineOfAddrs($message["HEADER"]["TO"]) . ", " . getLineOfAddrs($message["HEADER"]["CC"]));
66
67 $dateString = getLongDateString($message["HEADER"]["DATE"]);
68
69 /** TEXT STRINGS DEFINITIONS **/
70 $echo_more = _("more");
71 $echo_less = _("less");
72
73 /** FORMAT THE TO STRING **/
74 $i = 0;
75 $to_string = "";
76 $to_ary = $message["HEADER"]["TO"];
77 while ($i < count($to_ary)) {
78 $to_ary[$i] = htmlspecialchars($to_ary[$i]);
79 if ($to_string)
80 $to_string = "$to_string<BR>$to_ary[$i]";
81 else
82 $to_string = "$to_ary[$i]";
83
84 $i++;
85 if (count($to_ary) > 1) {
86 if ($show_more == false) {
87 if ($i == 1) {
88 $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>)";
89 $i = count($to_ary);
90 }
91 } else if ($i == 1) {
92 $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>)";
93 }
94 }
95 }
96
97 /** FORMAT THE CC STRING **/
98 $i = 0;
99 $cc_string = "";
100 $cc_ary = $message["HEADER"]["CC"];
101 while ($i < count($cc_ary)) {
102 $cc_ary[$i] = htmlspecialchars($cc_ary[$i]);
103 if ($cc_string)
104 $cc_string = "$cc_string<BR>$cc_ary[$i]";
105 else
106 $cc_string = "$cc_ary[$i]";
107
108 $i++;
109 if (count($cc_ary) > 1) {
110 if ($show_more_cc == false) {
111 if ($i == 1) {
112 $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>)";
113 $i = count($cc_ary);
114 }
115 } else if ($i == 1) {
116 $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>)";
117 }
118 }
119 }
120
121 /** make sure everything will display in HTML format **/
122 $from_name = decodeHeader(htmlspecialchars($message["HEADER"]["FROM"]));
123 $subject = decodeHeader(htmlspecialchars(stripslashes($message["HEADER"]["SUBJECT"])));
124
125 echo "<BR>";
126 echo "<TABLE COLS=1 CELLSPACING=0 WIDTH=98% BORDER=0 ALIGN=CENTER CELLPADDING=0>\n";
127 echo " <TR><TD BGCOLOR=\"$color[0]\" WIDTH=100%>";
128 echo " <TABLE WIDTH=100% CELLSPACING=0 BORDER=0 COLS=2 CELLPADDING=3>";
129 echo " <TR>";
130 echo " <TD ALIGN=LEFT WIDTH=33%>";
131 echo " <SMALL>";
132 echo " <A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">";
133 echo _("Message List");
134 echo "</A>&nbsp;|&nbsp;";
135 echo " <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=1\">";
136 echo _("Delete");
137 echo "</A>&nbsp;&nbsp;";
138 echo " </SMALL>";
139 echo " </TD><TD WIDTH=33% ALIGN=CENTER>";
140 echo " <SMALL>\n";
141 if ($currentArrayIndex == -1) {
142 echo "Previous&nbsp;|&nbspNext";
143 } else {
144 $prev = findPreviousMessage();
145 $next = findNextMessage();
146 if ($prev != -1)
147 echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$mailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A>&nbsp;|&nbsp;";
148 else
149 echo _("Previous") . "&nbsp;|&nbsp;";
150 if ($next != -1)
151 echo "<a href=\"read_body.php?passed_id=$next&mailbox=$mailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>";
152 else
153 echo _("Next");
154 }
155 echo " </SMALL>\n";
156 echo " </TD><TD WIDTH=33% ALIGN=RIGHT>";
157 echo " <SMALL>";
158 echo " <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox\">";
159 echo _("Forward");
160 echo "</A>&nbsp;|&nbsp;";
161 echo " <A HREF=\"compose.php?send_to=$url_replyto&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox\">";
162 echo _("Reply");
163 echo "</A>&nbsp;|&nbsp;";
164 echo " <A HREF=\"compose.php?send_to=$url_replytoall&send_to_cc=$url_replytoallcc&reply_subj=$url_subj&reply_id=$passed_id&mailbox=$urlMailbox\">";
165 echo _("Reply All");
166 echo "</A>&nbsp;&nbsp;";
167 echo " </SMALL>";
168 echo " </TD>";
169 echo " </TR>";
170 echo " </TABLE>";
171 echo " </TD></TR>";
172 echo " <TR><TD CELLSPACING=0 WIDTH=100%>";
173 echo " <TABLE COLS=2 WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=3>\n";
174 echo " <TR>\n";
175 /** subject **/
176 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT>\n";
177 echo _("Subject:");
178 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85%>\n";
179 echo " <B>$subject</B>\n";
180 echo " </TD>\n";
181 echo " </TR>\n";
182 /** from **/
183 echo " <TR>\n";
184 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT>\n";
185 echo _("From:");
186 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85%>\n";
187 echo " <B>$from_name</B>\n";
188 echo " </TD>\n";
189 echo " </TR>\n";
190 /** date **/
191 echo " <TR>\n";
192 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT>\n";
193 echo _("Date:");
194 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85%>\n";
195 echo " <B>$dateString</B>\n";
196 echo " </TD>\n";
197 echo " </TR>\n";
198 /** to **/
199 echo " <TR>\n";
200 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
201 echo _("To:");
202 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85% VALIGN=TOP>\n";
203 echo " <B>$to_string</B>\n";
204 echo " </TD>\n";
205 echo " </TR>\n";
206 /** cc **/
207 if ($message["HEADER"]["CC"][0]) {
208 echo " <TR>\n";
209 echo " <TD BGCOLOR=\"$color[4]\" WIDTH=15% ALIGN=RIGHT VALIGN=TOP>\n";
210 echo " Cc:\n";
211 echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=85% VALIGN=TOP>\n";
212 echo " <B>$cc_string</B>\n";
213 echo " </TD>\n";
214 echo " </TR>\n";
215 }
216 echo "</TABLE>";
217 echo " </TD></TR>";
218
219 echo " <TR><TD BGCOLOR=\"$color[4]\" WIDTH=100%>\n";
220 $body = formatBody($message, $color, $wrap_at);
221 echo "<BR>";
222
223 echo "$body";
224
225 echo " </TD></TR>\n";
226 echo " <TR><TD BGCOLOR=\"$color[9]\">&nbsp;</TD></TR>";
227 echo "</TABLE>\n";
228
229 ?>