85aba1815a9625b7b03d20f75de13e9de900e863
5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
8 ** This code sends a mail.
10 ** There are 3 modes of operation:
12 ** - Add an attachment
18 if (!isset($config_php))
19 include("../config/config.php");
20 if (!isset($strings_php))
21 include("../functions/strings.php");
22 if (!isset($page_header_php))
23 include("../functions/page_header.php");
24 if (!isset($imap_php))
25 include("../functions/imap.php");
26 if (!isset($date_php))
27 include("../functions/date.php");
28 if (!isset($mime_php))
29 include("../functions/mime.php");
30 if (!isset($smtp_php))
31 include("../functions/smtp.php");
32 if (!isset($display_messages_php))
33 include("../functions/display_messages.php");
34 if (!isset($auth_php))
35 include ("../functions/auth.php");
36 if (!isset($plugin_php))
37 include ("../functions/plugin.php");
39 include("../src/load_prefs.php");
41 // This function is used when not sending or adding attachments
43 global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
44 $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc;
46 $send_to = stripslashes(decodeHeader($send_to));
47 $send_to_cc = stripslashes(decodeHeader($send_to_cc));
56 sqimap_mailbox_select($imapConnection, $mailbox);
57 $message = sqimap_get_message($imapConnection, $id, $mailbox);
58 $orig_header = $message->header
;
60 $message = getEntity($message, $ent_num);
62 if ($message->header
->type0
== "text" ||
$message->header
->type1
== "message") {
64 $body = decodeBody(mime_fetch_body($imapConnection, $id, $ent_num), $message->header
->encoding
);
66 $body = decodeBody(mime_fetch_body($imapConnection, $id, 1), $message->header
->encoding
);
71 if ($message->header
->type1
== "html")
72 $body = strip_tags($body);
74 $body_ary = explode("\n", $body);
76 for ($i=0; $i < count($body_ary); $i++
) {
77 if ($i==0 && $forward_id) {
78 $tmp = "-------- " . _("Original Message") . " --------";
79 $tmp .= _("Subject") . ": " . $orig_header->subject
. "\n";
80 $tmp .= " " . _("From") . ": " . $orig_header->from
. "\n";
81 $tmp .= " " . _("To") . ": " . $orig_header->to
[0] . "\n";
82 if (count($orig_header->to
) > 1) {
83 for ($x=1; $x < count($orig_header->to
); $x++
) {
84 $tmp .= " " . $orig_header->to
[$x] . "\n";
87 $tmp .= "\n" . $body_ary[$i];
92 $body = "$body$tmp\n";
94 $body = "$body> $tmp\n";
99 $send_to = stripslashes($send_to);
102 $send_to = sqimap_find_email($send_to);
105 /** This formats a CC string if they hit "reply all" **/
106 if ($send_to_cc != "") {
107 $send_to_cc = ereg_replace(";", ",", $send_to_cc);
108 $sendcc = explode(",", $send_to_cc);
111 for ($i = 0; $i < count($sendcc); $i++
) {
112 $sendcc[$i] = trim($sendcc[$i]);
113 if ($sendcc[$i] == "")
116 $sendcc[$i] = sqimap_find_email($sendcc[$i]);
117 $whofrom = sqimap_find_displayable_name($msg["HEADER"]["FROM"]);
118 $whoreplyto = sqimap_find_email($msg["HEADER"]["REPLYTO"]);
120 if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) &&
121 (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) &&
122 (trim($sendcc[$i]) != "")) {
123 $send_to_cc .= trim($sendcc[$i]) . ", ";
126 $send_to_cc = trim($send_to_cc);
127 if (substr($send_to_cc, -1) == ",") {
128 $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1);
131 } // function newMail()
133 function showInputForm () {
134 global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body,
135 $passed_body, $color, $use_signature, $signature, $editor_size,
136 $attachments, $subject, $newmail, $use_javascript_addr_book,
137 $send_to_bcc, $reply_id, $mailbox;
139 $subject = decodeHeader($subject);
140 $reply_subj = decodeHeader($reply_subj);
141 $forward_subj = decodeHeader($forward_subj);
143 if ($use_javascript_addr_book) {
144 echo "\n<SCRIPT LANGUAGE=JavaScript><!--\n";
145 echo "function open_abook() { \n";
146 echo " var nwin = window.open(\"addrbook_popup.php\",\"abookpopup\",";
147 echo "\"width=670,height=300,resizable=yes,scrollbars=yes\");\n";
148 echo " if((!nwin.opener) && (document.windows != null))\n";
149 echo " nwin.opener = document.windows;\n";
151 echo "// --></SCRIPT>\n\n";
154 echo "\n<FORM name=compose action=\"compose.php\" METHOD=POST>\n";
156 echo "<input type=hidden name=reply_id value=$reply_id>\n";
158 printf("<INPUT TYPE=hidden NAME=mailbox VALUE=\"%s\">\n", htmlspecialchars($mailbox));
159 echo "<TABLE WIDTH=50 ALIGN=center CELLSPACING=0 BORDER=0>\n";
161 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
163 echo " </TD><TD colspan=2 WIDTH=\"100%\" BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
164 printf(" <INPUT TYPE=text NAME=\"send_to\" VALUE=\"%s\" SIZE=60><BR>\n",
165 htmlspecialchars($send_to));
169 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
171 echo " </TD><TD colspan=2 BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
172 printf(" <INPUT TYPE=text NAME=\"send_to_cc\" SIZE=60 VALUE=\"%s\"><BR>\n",
173 htmlspecialchars($send_to_cc));
177 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
179 echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
180 printf(" <INPUT TYPE=text NAME=\"send_to_bcc\" VALUE=\"%s\" SIZE=60><BR>\n",
181 htmlspecialchars($send_to_bcc));
185 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
187 echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
189 $reply_subj = str_replace("\"", "'", $reply_subj);
190 $reply_subj = stripslashes($reply_subj);
191 $reply_subj = trim($reply_subj);
192 if (substr(strtolower($reply_subj), 0, 3) != "re:")
193 $reply_subj = "Re: $reply_subj";
194 printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">",
195 htmlspecialchars($reply_subj));
196 } else if ($forward_subj) {
197 $forward_subj = str_replace("\"", "'", $forward_subj);
198 $forward_subj = stripslashes($forward_subj);
199 $forward_subj = trim($forward_subj);
200 if ((substr(strtolower($forward_subj), 0, 4) != "fwd:") &&
201 (substr(strtolower($forward_subj), 0, 5) != "[fwd:") &&
202 (substr(strtolower($forward_subj), 0, 6) != "[ fwd:"))
203 $forward_subj = "[Fwd: $forward_subj]";
204 printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">",
205 htmlspecialchars($forward_subj));
207 printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">",
208 htmlspecialchars($subject));
210 echo "</td></tr>\n\n";
212 echo " <TR><td>\n </td><td>\n";
213 if ($use_javascript_addr_book) {
214 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"";
215 echo " <input type=button value=\\\""._("Addresses")."\\\" onclick='javascript:open_abook();'>\");";
216 echo " // --></SCRIPT><NOSCRIPT>\n";
217 echo " <input type=submit name=\"html_addr_search\" value=\""._("Addresses")."\">";
218 echo " </NOSCRIPT>\n";
220 echo " <input type=submit name=\"html_addr_search\" value=\""._("Addresses")."\">";
222 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
224 do_hook("compose_button_row");
231 echo " <TD BGCOLOR=\"$color[4]\" COLSPAN=3>\n";
232 echo " <TEXTAREA NAME=body ROWS=20 COLS=\"$editor_size\" WRAP=HARD>";
233 if ($use_signature == true && $newmail == true) {
234 echo htmlspecialchars($body) . "\n\n-- \n" . htmlspecialchars($signature);
236 echo htmlspecialchars($body);
238 echo "</TEXTAREA><BR>\n";
241 echo " <TR><TD COLSPAN=3 ALIGN=CENTER><INPUT TYPE=SUBMIT NAME=send VALUE=\"";
243 echo "\"></TD></TR>\n";
245 // This code is for attachments
247 echo " <TD WIDTH=50 BGCOLOR=\"$color[0]\" VALIGN=TOP ALIGN=RIGHT>\n";
248 echo " <SMALL><BR></SMALL>"._("Attach:");
249 echo " </td><td colspan=2 ALIGN=left BGCOLOR=\"$color[0]\">\n";
250 // echo " <INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\"\n";
251 // echo " value=\"10000\">\n";
252 echo " <INPUT NAME=\"attachfile\" TYPE=\"file\">\n";
253 echo " <input type=\"submit\" name=\"attach\"";
254 echo " value=\"" . _("Add") ."\">\n";
257 if (isset($attachments) && count($attachments)>0) {
258 echo "</tr><tr><td width=50 bgcolor=\"$color[0]\" align=right>\n";
260 echo "</td><td align=left colspan=2 bgcolor=\"$color[0]\">";
261 while (list($localname, $remotename) = each($attachments)) {
262 echo "<input type=\"checkbox\" name=\"delete[]\" value=\"$localname\">\n";
263 echo "$remotename <input type=\"hidden\" name=\"attachments[$localname]\" value=\"$remotename\"><br>\n";
266 echo "<input type=\"submit\" name=\"do_delete\" value=\""._("Delete selected attachments")."\">\n";
269 // End of attachment code
275 function showSentForm () {
276 echo "<BR><BR><BR><CENTER><B>Message Sent!</B><BR><BR>";
277 echo "You will be automatically forwarded.<BR>If not, <A HREF=\"right_main.php\">click here</A>";
281 function checkInput ($show) {
282 /** I implemented the $show variable because the error messages
283 were getting sent before the page header. So, I check once
284 using $show=false, and then when i'm ready to display the
285 error message, show=true **/
286 global $body, $send_to, $subject, $color;
288 if ($body == "" && $subject == "") {
290 plain_error_message(_("You have not entered a message body or a subject."), $color);
292 } else if ($send_to == "") {
294 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
298 } // function checkInput()
301 if (($mailbox == "") ||
($mailbox == "None"))
305 if (checkInput(false)) {
306 $urlMailbox = urlencode ($mailbox);
307 sendMessage($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id);
308 header ("Location: right_main.php?mailbox=$urlMailbox&sort=$sort&startMessage=1");
310 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
311 displayPageHeader($color, $mailbox);
315 sqimap_logout($imapConnection);
317 } else if ($html_addr_search_done) {
319 displayPageHeader($color, $mailbox);
321 $body = stripslashes($body);
322 $send_to = stripslashes($send_to);
323 $send_to_cc = stripslashes($send_to_cc);
324 $send_to_bcc = stripslashes($send_to_bcc);
325 $subject = stripslashes($subject);
327 for ($i=0; $i < count($send_to_search); $i++
) {
330 $send_to .= $send_to_search[$i];
333 for ($i=0; $i < count($send_to_cc_search); $i++
) {
336 $send_to_cc .= $send_to_cc_search[$i];
340 } else if ($html_addr_search) {
341 // I am using an include so as to elminiate an extra unnecessary click. If you
342 // can think of a better way, please implement it.
343 include ("addrbook_search_html.php");
344 } else if (isset($attach)) {
346 displayPageHeader($color, $mailbox);
348 $localfilename = md5("$attachfile, $attachfile_name, $REMOTE_IP, $REMOTE_PORT, $UNIQUE_ID, and everything else that may add entropy");
349 $localfilename = $localfilename;
351 // Put the file in a better place
352 error_reporting(0); // Rename will produce error output if it fails
353 if (!rename($attachfile, $attachment_dir.$localfilename)) {
354 if (!copy($attachfile, $attachment_dir.$localfilename)) {
355 plain_error_message(_("Could not move/copy file. File not attached"));
359 // If it still exists, PHP will remove the original file
362 // Write information about the file
363 $fp = fopen ($attachment_dir.$localfilename.".info", "w");
364 fputs ($fp, "$attachfile_type\n$attachfile_name\n");
367 $attachments[$localfilename] = $attachfile_name;
371 } else if (isset($do_delete)) {
373 displayPageHeader($color, $mailbox);
375 while (list($key, $localname) = each($delete)) {
376 array_splice ($attachments, $key, 1);
377 unlink ($attachment_dir.$localname);
378 unlink ($attachment_dir.$localname.".info");
383 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
384 displayPageHeader($color, $mailbox);
389 sqimap_logout($imapConnection);