Removed font tags
[squirrelmail.git] / src / compose.php
1 <?
2 /** This code sends a mail.
3 **
4 ** There are 3 modes of operation:
5 ** - Start new mail
6 ** - Add an attachment
7 ** - Send mail
8 **/
9
10 if (!isset($config_php))
11 include("../config/config.php");
12 if (!isset($strings_php))
13 include("../functions/strings.php");
14 if (!isset($page_header_php))
15 include("../functions/page_header.php");
16 if (!isset($imap_php))
17 include("../functions/imap.php");
18 if (!isset($date_php))
19 include("../functions/date.php");
20 if (!isset($mime_php))
21 include("../functions/mime.php");
22 if (!isset($smtp_php))
23 include("../functions/smtp.php");
24 if (!isset($display_messages_php))
25 include("../functions/display_messages.php");
26
27 include("../src/load_prefs.php");
28
29 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
30 $imapConnection = sqimap_login($username, $key, $imapServerAddress, 0);
31 displayPageHeader($color, "None");
32
33 // This function is used when not sending or adding attachments
34 function newMail () {
35 global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
36 $reply_id, $send_to, $send_to_cc, $mailbox;
37
38 $send_to = decodeHeader($send_to);
39 $send_to_cc = decodeHeader($send_to_cc);
40
41 if ($forward_id) {
42 sqimap_mailbox_select($imapConnection, $mailbox);
43 $msg = sqimap_get_message($imapConnection, $forward_id, $mailbox);
44
45 if (containsType($msg, "text", "html", $ent_num)) {
46 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"]);
47 } else if (containsType($msg, "text", "plain", $ent_num)) {
48 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"]);
49 }
50 // add other primary displaying msg types here
51 else {
52 // find any type that's displayable
53 if (containsType($msg, "text", "any_type", $ent_num)) {
54 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"]);
55 } else if (containsType($msg, "msg", "any_type", $ent_num)) {
56 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"]);
57 } else {
58 $body = _("No Message");
59 }
60 }
61
62 $type1 = $msg["ENTITIES"][$ent_num]["TYPE1"];
63
64 $tmp = _("-------- Original Message ---------\n");
65 $body_ary = explode("\n", $body);
66 $body = "";
67 for ($i=0;$i < count($body_ary);$i++) {
68 if ($type1 == "html")
69 $tmp .= strip_tags($body_ary[$i]);
70 else
71 $tmp .= $body_ary[$i];
72 $body = "$body$tmp\n";
73 $tmp = "";
74 }
75 }
76
77 if ($reply_id) {
78 sqimap_mailbox_select($imapConnection, $mailbox);
79 $msg = sqimap_get_message($imapConnection, $reply_id, $mailbox);
80
81 if (containsType($msg, "text", "html", $ent_num)) {
82 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"], false);
83 } else if (containsType($msg, "text", "plain", $ent_num)) {
84 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"], false);
85 }
86 // add other primary displaying msg types here
87 else {
88 // find any type that's displayable
89 if (containsType($msg, "text", "any_type", $ent_num)) {
90 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"], false);
91 } else if (containsType($msg, "msg", "any_type", $ent_num)) {
92 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"], false);
93 } else {
94 $body = _("No Message");
95 }
96 }
97
98 $type1 = $msg["ENTITIES"][$ent_num]["TYPE1"];
99
100 $body_ary = explode("\n", $body);
101 $body = "";
102 for ($i=0;$i < count($body_ary);$i++) {
103 if ($type1 == "html")
104 $tmp = strip_tags($body_ary[$i]);
105 else
106 $tmp = $body_ary[$i];
107 $body = "$body> $tmp\n";
108 }
109 }
110
111 $send_to = sqimap_find_email($send_to);
112
113 $send_to = ereg_replace("\"", "", $send_to);
114 $send_to = stripslashes($send_to);
115
116 /** This formats a CC string if they hit "reply all" **/
117 if ($send_to_cc != "") {
118 $send_to_cc = ereg_replace(";", ",", $send_to_cc);
119 $sendcc = explode(",", $send_to_cc);
120 $send_to_cc = "";
121
122 for ($i = 0; $i < count($sendcc); $i++) {
123 $sendcc[$i] = trim($sendcc[$i]);
124 if ($sendcc[$i] == "")
125 continue;
126
127 $sendcc[$i] = sqimap_find_email($sendcc[$i]);
128 $whofrom = sqimap_find_displayable_name($msg["HEADER"]["FROM"]);
129 $whoreplyto = sqimap_find_email($msg["HEADER"]["REPLYTO"]);
130
131 if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) &&
132 (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) &&
133 (trim($sendcc[$i]) != "")) {
134 $send_to_cc .= trim($sendcc[$i]) . ", ";
135 }
136 }
137 $send_to_cc = trim($send_to_cc);
138 if (substr($send_to_cc, -1) == ",") {
139 $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1);
140 }
141 }
142 } // function newMail()
143
144 function showInputForm () {
145 global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body,
146 $passed_body, $color, $use_signature, $signature, $editor_size,
147 $attachments, $subject, $newmail;
148
149 $subject = decodeHeader($subject);
150 $reply_subj = decodeHeader($reply_subj);
151 $forward_subj = decodeHeader($forward_subj);
152
153 echo "\n<FORM action=\"compose.php\" METHOD=POST\n";
154 echo "ENCTYPE=\"multipart/form-data\">\n";
155 echo "<TABLE COLS=2 WIDTH=50 ALIGN=center CELLSPACING=0 BORDER=0>\n";
156 echo " <TR>\n";
157 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
158 echo _("To:");
159 echo " </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
160 if ($send_to)
161 echo " <INPUT TYPE=TEXT NAME=send_to VALUE=\"$send_to\" SIZE=60><BR>";
162 else
163 echo " <INPUT TYPE=TEXT NAME=send_to SIZE=60><BR>";
164 echo " </TD>\n";
165 echo " </TR>\n";
166 echo " <TR>\n";
167 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
168 echo _("CC:");
169 echo " </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
170 if ($send_to_cc)
171 echo " <INPUT TYPE=TEXT NAME=send_to_cc SIZE=60 VALUE=\"$send_to_cc\"><BR>";
172 else
173 echo " <INPUT TYPE=TEXT NAME=send_to_cc SIZE=60><BR>";
174 echo " </TD>\n";
175 echo " </TR>\n";
176 echo " <TR>\n";
177 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
178 echo _("BCC:");
179 echo " </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
180 if ($send_to_bcc)
181 echo " <INPUT TYPE=TEXT NAME=send_to_bcc VALUE=\"$send_to_bcc\" SIZE=60><BR>";
182 else
183 echo " <INPUT TYPE=TEXT NAME=send_to_bcc SIZE=60><BR>";
184 echo " </TD>\n";
185 echo " </TR>\n";
186 echo " <TR>\n";
187 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
188 echo _("Subject:");
189 echo " </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
190 if ($reply_subj) {
191 $reply_subj = str_replace("\"", "'", $reply_subj);
192 $reply_subj = stripslashes($reply_subj);
193 $reply_subj = trim($reply_subj);
194 if (substr(strtolower($reply_subj), 0, 3) != "re:")
195 $reply_subj = "Re: $reply_subj";
196 echo " <INPUT TYPE=TEXT NAME=subject SIZE=60 VALUE=\"$reply_subj\">";
197 } else if ($forward_subj) {
198 $forward_subj = str_replace("\"", "'", $forward_subj);
199 $forward_subj = stripslashes($forward_subj);
200 $forward_subj = trim($forward_subj);
201 if ((substr(strtolower($forward_subj), 0, 4) != "fwd:") &&
202 (substr(strtolower($forward_subj), 0, 5) != "[fwd:") &&
203 (substr(strtolower($forward_subj), 0, 6) != "[ fwd:"))
204 $forward_subj = "[Fwd: $forward_subj]";
205 echo " <INPUT TYPE=TEXT NAME=subject SIZE=50 VALUE=\"$forward_subj\">";
206 } else {
207 echo " <INPUT TYPE=TEXT NAME=subject VALUE=\"$subject\" SIZE=50>";
208 }
209 echo "&nbsp;&nbsp;<INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">";
210 echo " </TD>\n";
211 echo " </TR>\n";
212
213 echo " <TR>\n";
214 echo " <TD BGCOLOR=\"$color[4]\" COLSPAN=2>\n";
215 if ($use_signature == true && $newmail == true)
216 echo " &nbsp;&nbsp;<TEXTAREA NAME=body ROWS=20 COLS=\"$editor_size\" WRAP=HARD>". $body . "\n\n-- \n".$signature."</TEXTAREA><BR>";
217 else
218 echo " &nbsp;&nbsp;<TEXTAREA NAME=body ROWS=20 COLS=\"$editor_size\" WRAP=HARD>".$body."</TEXTAREA><BR>\n";
219 echo " </TD>\n";
220 echo " </TR>\n";
221 echo " <TR><TD COLSPAN=2 ALIGN=CENTER><INPUT TYPE=SUBMIT NAME=send VALUE=\"";
222 echo _("Send");
223 echo "\"></TD></TR>\n";
224
225 // This code is for attachments
226 echo " <tr>\n";
227 echo " <TD WIDTH=50 BGCOLOR=\"$color[0]\" VALIGN=TOP ALIGN=RIGHT>\n";
228 echo " <SMALL><BR></SMALL>"._("Attach:");
229 echo " </td><td width=% ALIGN=left BGCOLOR=\"$color[0]\">\n";
230 // echo " <INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\"\n";
231 // echo " value=\"10000\">\n";
232 echo " <INPUT NAME=\"attachfile\" TYPE=\"file\">\n";
233 echo " &nbsp;&nbsp;<input type=\"submit\" name=\"attach\"\n";
234 echo " value=\"" . _("Add") ."\">\n";
235 echo " </td>\n";
236 echo " </font>\n";
237 echo " </tr>\n";
238 if (isset($attachments) && count($attachments)>0) {
239 echo "</tr><tr><td width=50 bgcolor=\"$color[0]\" align=right>\n";
240 echo "&nbsp;";
241 echo "</td><td width=% align=left bgcolor=\"$color[0]\">";
242 while (list($localname, $remotename) = each($attachments)) {
243 echo "<input type=\"checkbox\" name=\"delete[]\" value=\"$localname\">\n";
244 echo "$remotename <input type=\"hidden\" name=\"attachments[$localname]\" value=\"$remotename\"><br>\n";
245 }
246
247 echo "<input type=\"submit\" name=\"do_delete\" value=\""._("Delete selected attachments")."\">\n";
248 echo "</td></tr>";
249 }
250 // End of attachment code
251
252 echo "</TABLE>\n";
253 echo "</FORM>";
254 }
255
256 function showSentForm () {
257 echo "<BR><BR><BR><CENTER><B>Message Sent!</B><BR><BR>";
258 echo "You will be automatically forwarded.<BR>If not, <A HREF=\"right_main.php\">click here</A>";
259 echo "</CENTER>";
260 }
261
262 function checkInput () {
263 global $body, $send_to, $subject;
264
265 if ($body == "") {
266 plain_error_message(_("You have not entered a message body."), $color);
267 return false;
268 } else if ($send_to == "") {
269 displayPageHeader($color, "None");
270 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
271 return false;
272 } else if ($subject == "") {
273 plain_error_message(_("You have not entered a subject."), $color);
274 return false;
275 }
276 return true;
277 } // function checkInput()
278
279 if(isset($send)) {
280 if (checkInput()) {
281 sendMessage($send_to, $send_to_cc, $send_to_bcc, $subject, $body);
282 showSentForm();
283 } else {
284 showInputForm();
285 }
286 } else if (isset($attach)) {
287 $localfilename = md5("$attachfile, $attachfile_name, $REMOTE_IP, $REMOTE_PORT, $UNIQUE_ID, and everything else that may add entropy");
288 $localfilename = $localfilename;
289
290 // Put the file in a better place
291 error_reporting(0); // Rename will produce error output if it fails
292 if (!rename($attachfile, $attachment_dir.$localfilename)) {
293 if (!copy($attachfile, $attachment_dir.$localfilename)) {
294 plain_error_message(_("Could not move/copy file. File not attached"));
295 $failed = true;
296 }
297 }
298 // If it still exists, PHP will remove the original file
299
300 if (!$failed) {
301 // Write information about the file
302 $fp = fopen ($attachment_dir.$localfilename.".info", "w");
303 fputs ($fp, "$attachfile_type\n$attachfile_name\n");
304 fclose ($fp);
305
306 $attachments[$localfilename] = $attachfile_name;
307 }
308
309 showInputForm();
310 } else if (isset($do_delete)) {
311 while (list($key, $localname) = each($delete)) {
312 array_splice ($attachments, $key, 1);
313 unlink ($attachment_dir.$localname);
314 unlink ($attachment_dir.$localname.".info");
315 }
316
317 showInputForm();
318 } else {
319 $newmail = true;
320 newMail();
321 showInputForm();
322 }
323 ?>