Added _() to some strings missing from translation.
[squirrelmail.git] / src / compose.php
CommitLineData
8467bf00 1<?
df15de21 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
d068c0ec 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");
f7fb20fe 26
d3cdb279 27 include("../src/load_prefs.php");
8467bf00 28
4ba45d11 29 // This function is used when not sending or adding attachments
df15de21 30 function newMail () {
31 global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
32 $reply_id, $send_to, $send_to_cc, $mailbox;
e39d73e5 33
2e434774 34 $send_to = decodeHeader($send_to);
35 $send_to_cc = decodeHeader($send_to_cc);
a53e5469 36
df15de21 37 if ($forward_id) {
813eba2f 38 sqimap_mailbox_select($imapConnection, $mailbox);
39 $msg = sqimap_get_message($imapConnection, $forward_id, $mailbox);
df15de21 40
41 if (containsType($msg, "text", "html", $ent_num)) {
78509c54 42 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"]);
df15de21 43 } else if (containsType($msg, "text", "plain", $ent_num)) {
78509c54 44 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"]);
df15de21 45 }
46 // add other primary displaying msg types here
47 else {
48 // find any type that's displayable
49 if (containsType($msg, "text", "any_type", $ent_num)) {
50 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"]);
51 } else if (containsType($msg, "msg", "any_type", $ent_num)) {
52 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"]);
53 } else {
54 $body = _("No Message");
55 }
56 }
57
58 $type1 = $msg["ENTITIES"][$ent_num]["TYPE1"];
59
60 $tmp = _("-------- Original Message ---------\n");
61 $body_ary = explode("\n", $body);
62 $body = "";
63 for ($i=0;$i < count($body_ary);$i++) {
64 if ($type1 == "html")
65 $tmp .= strip_tags($body_ary[$i]);
66 else
67 $tmp .= $body_ary[$i];
68 $body = "$body$tmp\n";
69 $tmp = "";
78509c54 70 }
71 }
df15de21 72
73 if ($reply_id) {
813eba2f 74 sqimap_mailbox_select($imapConnection, $mailbox);
75 $msg = sqimap_get_message($imapConnection, $reply_id, $mailbox);
df15de21 76
77 if (containsType($msg, "text", "html", $ent_num)) {
78509c54 78 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"], false);
df15de21 79 } else if (containsType($msg, "text", "plain", $ent_num)) {
78509c54 80 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"], false);
df15de21 81 }
82 // add other primary displaying msg types here
83 else {
84 // find any type that's displayable
85 if (containsType($msg, "text", "any_type", $ent_num)) {
86 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"], false);
87 } else if (containsType($msg, "msg", "any_type", $ent_num)) {
88 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"], false);
89 } else {
90 $body = _("No Message");
91 }
92 }
93
94 $type1 = $msg["ENTITIES"][$ent_num]["TYPE1"];
95
96 $body_ary = explode("\n", $body);
97 $body = "";
98 for ($i=0;$i < count($body_ary);$i++) {
99 if ($type1 == "html")
100 $tmp = strip_tags($body_ary[$i]);
101 else
102 $tmp = $body_ary[$i];
103 $body = "$body> $tmp\n";
78509c54 104 }
105 }
df15de21 106
a53e5469 107 $send_to = sqimap_find_email($send_to);
df15de21 108
df15de21 109 $send_to = ereg_replace("\"", "", $send_to);
110 $send_to = stripslashes($send_to);
111
112 /** This formats a CC string if they hit "reply all" **/
113 if ($send_to_cc != "") {
114 $send_to_cc = ereg_replace(";", ",", $send_to_cc);
115 $sendcc = explode(",", $send_to_cc);
116 $send_to_cc = "";
117
118 for ($i = 0; $i < count($sendcc); $i++) {
119 $sendcc[$i] = trim($sendcc[$i]);
120 if ($sendcc[$i] == "")
121 continue;
122
a53e5469 123 $sendcc[$i] = sqimap_find_email($sendcc[$i]);
813eba2f 124 $whofrom = sqimap_find_displayable_name($msg["HEADER"]["FROM"]);
125 $whoreplyto = sqimap_find_email($msg["HEADER"]["REPLYTO"]);
df15de21 126
127 if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) &&
128 (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) &&
129 (trim($sendcc[$i]) != "")) {
130 $send_to_cc .= trim($sendcc[$i]) . ", ";
131 }
132 }
133 $send_to_cc = trim($send_to_cc);
134 if (substr($send_to_cc, -1) == ",") {
135 $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1);
136 }
137 }
138 } // function newMail()
78509c54 139
df15de21 140 function showInputForm () {
141 global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body,
4ba45d11 142 $passed_body, $color, $use_signature, $signature, $editor_size,
b57c4e63 143 $attachments, $subject, $newmail;
78509c54 144
2e434774 145 $subject = decodeHeader($subject);
146 $reply_subj = decodeHeader($reply_subj);
147 $forward_subj = decodeHeader($forward_subj);
a53e5469 148
5100704d 149 echo "\n<SCRIPT LANGUAGE=JavaScript><!--\n";
150 echo "function open_abook() { \n";
151 echo " var nwin = window.open(\"addrbook_popup.php\",\"abookpopup\",";
152 echo "\"width=670,height=300,resizable=yes,scrollbars=yes\");\n";
153 echo " if((!nwin.opener) && (document.windows != null))\n";
154 echo " nwin.opener = document.windows;\n";
155 echo "}\n";
156 echo "// --></SCRIPT>\n\n";
157
158 echo "\n<FORM name=compose action=\"compose.php\" METHOD=POST\n";
4ba45d11 159 echo "ENCTYPE=\"multipart/form-data\">\n";
57101712 160 echo "<TABLE COLS=2 WIDTH=50 ALIGN=center CELLSPACING=0 BORDER=0>\n";
df15de21 161 echo " <TR>\n";
162 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
df15de21 163 echo _("To:");
df15de21 164 echo " </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
165 if ($send_to)
166 echo " <INPUT TYPE=TEXT NAME=send_to VALUE=\"$send_to\" SIZE=60><BR>";
167 else
168 echo " <INPUT TYPE=TEXT NAME=send_to SIZE=60><BR>";
169 echo " </TD>\n";
170 echo " </TR>\n";
171 echo " <TR>\n";
172 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
aae41ae9 173 echo _("CC:");
df15de21 174 echo " </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
175 if ($send_to_cc)
176 echo " <INPUT TYPE=TEXT NAME=send_to_cc SIZE=60 VALUE=\"$send_to_cc\"><BR>";
177 else
178 echo " <INPUT TYPE=TEXT NAME=send_to_cc SIZE=60><BR>";
179 echo " </TD>\n";
180 echo " </TR>\n";
181 echo " <TR>\n";
182 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
aae41ae9 183 echo _("BCC:");
df15de21 184 echo " </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
185 if ($send_to_bcc)
186 echo " <INPUT TYPE=TEXT NAME=send_to_bcc VALUE=\"$send_to_bcc\" SIZE=60><BR>";
187 else
188 echo " <INPUT TYPE=TEXT NAME=send_to_bcc SIZE=60><BR>";
189 echo " </TD>\n";
190 echo " </TR>\n";
5100704d 191
192 echo "<SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"";
193 echo "<TR><TD BGCOLOR=\\\"$color[4]\\\">&nbsp;</TD>";
194 echo "</TD><TD BGCOLOR=\\\"$color[4]\\\" ALIGN=LEFT>";
195 printf("<A HREF=\\\"javascript:open_abook();\\\">%s</A>",
138f26f6 196 _("Lookup recipients in addressbook.")."<BR>");
5100704d 197 echo "</TD></TR>\");\n";
198 echo "// --></SCRIPT>\n";
199
df15de21 200 echo " <TR>\n";
201 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
df15de21 202 echo _("Subject:");
df15de21 203 echo " </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
204 if ($reply_subj) {
205 $reply_subj = str_replace("\"", "'", $reply_subj);
206 $reply_subj = stripslashes($reply_subj);
207 $reply_subj = trim($reply_subj);
208 if (substr(strtolower($reply_subj), 0, 3) != "re:")
209 $reply_subj = "Re: $reply_subj";
210 echo " <INPUT TYPE=TEXT NAME=subject SIZE=60 VALUE=\"$reply_subj\">";
211 } else if ($forward_subj) {
212 $forward_subj = str_replace("\"", "'", $forward_subj);
213 $forward_subj = stripslashes($forward_subj);
214 $forward_subj = trim($forward_subj);
215 if ((substr(strtolower($forward_subj), 0, 4) != "fwd:") &&
216 (substr(strtolower($forward_subj), 0, 5) != "[fwd:") &&
217 (substr(strtolower($forward_subj), 0, 6) != "[ fwd:"))
218 $forward_subj = "[Fwd: $forward_subj]";
57101712 219 echo " <INPUT TYPE=TEXT NAME=subject SIZE=50 VALUE=\"$forward_subj\">";
df15de21 220 } else {
57101712 221 echo " <INPUT TYPE=TEXT NAME=subject VALUE=\"$subject\" SIZE=50>";
31f3d7c0 222 }
57101712 223 echo "&nbsp;&nbsp;<INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">";
df15de21 224 echo " </TD>\n";
225 echo " </TR>\n";
4ba45d11 226
e5b23ff2 227 echo " <TR>\n";
228 echo " <TD BGCOLOR=\"$color[4]\" COLSPAN=2>\n";
b57c4e63 229 if ($use_signature == true && $newmail == true)
230 echo " &nbsp;&nbsp;<TEXTAREA NAME=body ROWS=20 COLS=\"$editor_size\" WRAP=HARD>". $body . "\n\n-- \n".$signature."</TEXTAREA><BR>";
e5b23ff2 231 else
232 echo " &nbsp;&nbsp;<TEXTAREA NAME=body ROWS=20 COLS=\"$editor_size\" WRAP=HARD>".$body."</TEXTAREA><BR>\n";
233 echo " </TD>\n";
234 echo " </TR>\n";
235 echo " <TR><TD COLSPAN=2 ALIGN=CENTER><INPUT TYPE=SUBMIT NAME=send VALUE=\"";
236 echo _("Send");
237 echo "\"></TD></TR>\n";
238
4ba45d11 239 // This code is for attachments
240 echo " <tr>\n";
e5b23ff2 241 echo " <TD WIDTH=50 BGCOLOR=\"$color[0]\" VALIGN=TOP ALIGN=RIGHT>\n";
aae41ae9 242 echo " <SMALL><BR></SMALL>"._("Attach:");
e5b23ff2 243 echo " </td><td width=% ALIGN=left BGCOLOR=\"$color[0]\">\n";
4ba45d11 244 // echo " <INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\"\n";
245 // echo " value=\"10000\">\n";
246 echo " <INPUT NAME=\"attachfile\" TYPE=\"file\">\n";
469eb37b 247 echo " &nbsp;&nbsp;<input type=\"submit\" name=\"attach\"\n";
4ba45d11 248 echo " value=\"" . _("Add") ."\">\n";
469eb37b 249 echo " </td>\n";
250 echo " </font>\n";
251 echo " </tr>\n";
4ba45d11 252 if (isset($attachments) && count($attachments)>0) {
e5b23ff2 253 echo "</tr><tr><td width=50 bgcolor=\"$color[0]\" align=right>\n";
254 echo "&nbsp;";
255 echo "</td><td width=% align=left bgcolor=\"$color[0]\">";
4ba45d11 256 while (list($localname, $remotename) = each($attachments)) {
257 echo "<input type=\"checkbox\" name=\"delete[]\" value=\"$localname\">\n";
258 echo "$remotename <input type=\"hidden\" name=\"attachments[$localname]\" value=\"$remotename\"><br>\n";
259 }
260
261 echo "<input type=\"submit\" name=\"do_delete\" value=\""._("Delete selected attachments")."\">\n";
469eb37b 262 echo "</td></tr>";
4ba45d11 263 }
4ba45d11 264 // End of attachment code
265
ffc2ccbc 266 echo "</TABLE>\n";
df15de21 267 echo "</FORM>";
31f3d7c0 268 }
8467bf00 269
df15de21 270 function showSentForm () {
df15de21 271 echo "<BR><BR><BR><CENTER><B>Message Sent!</B><BR><BR>";
272 echo "You will be automatically forwarded.<BR>If not, <A HREF=\"right_main.php\">click here</A>";
aae41ae9 273 echo "</CENTER>";
df15de21 274 }
b278172f 275
0ad7dbda 276 function checkInput ($show) {
277 /** I implemented the $show variable because the error messages
278 were getting sent before the page header. So, I check once
279 using $show=false, and then when i'm ready to display the
280 error message, show=true **/
281 global $body, $send_to, $subject, $color;
b278172f 282
df15de21 283 if ($body == "") {
0ad7dbda 284 if ($show)
285 plain_error_message(_("You have not entered a message body."), $color);
df15de21 286 return false;
287 } else if ($send_to == "") {
0ad7dbda 288 if ($show)
289 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
df15de21 290 return false;
291 } else if ($subject == "") {
0ad7dbda 292 if ($show)
293 plain_error_message(_("You have not entered a subject."), $color);
df15de21 294 return false;
b278172f 295 }
df15de21 296 return true;
297 } // function checkInput()
298
4ba45d11 299 if(isset($send)) {
0ad7dbda 300 if (checkInput(false)) {
df15de21 301 sendMessage($send_to, $send_to_cc, $send_to_bcc, $subject, $body);
fc3348ac 302 header ("Location: right_main.php");
df15de21 303 } else {
fc3348ac 304 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
e1469126 305 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
fc3348ac 306 displayPageHeader($color, "None");
0ad7dbda 307 checkInput(true);
308
df15de21 309 showInputForm();
7c6cb7ca 310 }
4ba45d11 311 } else if (isset($attach)) {
fc3348ac 312 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
e1469126 313 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
fc3348ac 314 displayPageHeader($color, "None");
315
4ba45d11 316 $localfilename = md5("$attachfile, $attachfile_name, $REMOTE_IP, $REMOTE_PORT, $UNIQUE_ID, and everything else that may add entropy");
c3c37167 317 $localfilename = $localfilename;
4ba45d11 318
319 // Put the file in a better place
320 error_reporting(0); // Rename will produce error output if it fails
c3c37167 321 if (!rename($attachfile, $attachment_dir.$localfilename)) {
322 if (!copy($attachfile, $attachment_dir.$localfilename)) {
4ba45d11 323 plain_error_message(_("Could not move/copy file. File not attached"));
c3c37167 324 $failed = true;
4ba45d11 325 }
326 }
327 // If it still exists, PHP will remove the original file
328
c3c37167 329 if (!$failed) {
330 // Write information about the file
331 $fp = fopen ($attachment_dir.$localfilename.".info", "w");
332 fputs ($fp, "$attachfile_type\n$attachfile_name\n");
333 fclose ($fp);
4ba45d11 334
c3c37167 335 $attachments[$localfilename] = $attachfile_name;
336 }
4ba45d11 337
338 showInputForm();
339 } else if (isset($do_delete)) {
fc3348ac 340 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
e1469126 341 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
fc3348ac 342 displayPageHeader($color, "None");
343
4ba45d11 344 while (list($key, $localname) = each($delete)) {
a53e5469 345 array_splice ($attachments, $key, 1);
c3c37167 346 unlink ($attachment_dir.$localname);
347 unlink ($attachment_dir.$localname.".info");
4ba45d11 348 }
4bfed9f3 349
4ba45d11 350 showInputForm();
351 } else {
fc3348ac 352 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
e1469126 353 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
fc3348ac 354 displayPageHeader($color, "None");
355
b57c4e63 356 $newmail = true;
1220e677 357 newMail();
4ba45d11 358 showInputForm();
359 }
da79853a 360?>