2 /** This code sends a mail.
4 ** There are 3 modes of operation:
12 if (!isset($config_php))
13 include("../config/config.php");
14 if (!isset($strings_php))
15 include("../functions/strings.php");
16 if (!isset($page_header_php))
17 include("../functions/page_header.php");
18 if (!isset($imap_php))
19 include("../functions/imap.php");
20 if (!isset($date_php))
21 include("../functions/date.php");
22 if (!isset($mime_php))
23 include("../functions/mime.php");
24 if (!isset($smtp_php))
25 include("../functions/smtp.php");
26 if (!isset($display_messages_php))
27 include("../functions/display_messages.php");
29 include("../src/load_prefs.php");
31 // This function is used when not sending or adding attachments
33 global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
34 $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc;
36 $send_to = decodeHeader($send_to);
37 $send_to_cc = decodeHeader($send_to_cc);
45 sqimap_mailbox_select($imapConnection, $mailbox);
46 $message = sqimap_get_message($imapConnection, $id, $mailbox);
47 $message = getEntity($message, $ent_num);
49 if ($message->header
->type0
== "text" ||
$message->header
->type1
== "message") {
50 $body = decodeBody(mime_fetch_body($imapConnection, $id, $message->header
->entity_id
), $message->header
->encoding
);
56 $tmp = _("-------- Original Message ---------\n");
57 if ($message->header
->type1
== "html")
58 $body = strip_tags($body);
60 $body_ary = explode("\n", $body);
62 for ($i=0; $i < count($body_ary); $i++
) {
66 $body = "$body$tmp\n";
68 $body = "$body> $tmp\n";
74 $send_to = sqimap_find_email($send_to);
77 $send_to = ereg_replace("\"", "", $send_to);
78 $send_to = stripslashes($send_to);
80 /** This formats a CC string if they hit "reply all" **/
81 if ($send_to_cc != "") {
82 $send_to_cc = ereg_replace(";", ",", $send_to_cc);
83 $sendcc = explode(",", $send_to_cc);
86 for ($i = 0; $i < count($sendcc); $i++
) {
87 $sendcc[$i] = trim($sendcc[$i]);
88 if ($sendcc[$i] == "")
91 $sendcc[$i] = sqimap_find_email($sendcc[$i]);
92 $whofrom = sqimap_find_displayable_name($msg["HEADER"]["FROM"]);
93 $whoreplyto = sqimap_find_email($msg["HEADER"]["REPLYTO"]);
95 if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) &&
96 (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) &&
97 (trim($sendcc[$i]) != "")) {
98 $send_to_cc .= trim($sendcc[$i]) . ", ";
101 $send_to_cc = trim($send_to_cc);
102 if (substr($send_to_cc, -1) == ",") {
103 $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1);
106 } // function newMail()
108 function showInputForm () {
109 global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body,
110 $passed_body, $color, $use_signature, $signature, $editor_size,
111 $attachments, $subject, $newmail, $use_javascript_addr_book,
112 $send_to_bcc, $reply_id, $mailbox;
114 $subject = decodeHeader($subject);
115 $reply_subj = decodeHeader($reply_subj);
116 $forward_subj = decodeHeader($forward_subj);
118 if ($use_javascript_addr_book) {
119 echo "\n<SCRIPT LANGUAGE=JavaScript><!--\n";
120 echo "function open_abook() { \n";
121 echo " var nwin = window.open(\"addrbook_popup.php\",\"abookpopup\",";
122 echo "\"width=670,height=300,resizable=yes,scrollbars=yes\");\n";
123 echo " if((!nwin.opener) && (document.windows != null))\n";
124 echo " nwin.opener = document.windows;\n";
126 echo "// --></SCRIPT>\n\n";
129 echo "\n<FORM name=compose action=\"compose.php\" METHOD=POST ENCTYPE=\"multipart/form-data\">\n";
131 echo "<input type=hidden name=reply_id value=$reply_id>\n";
133 echo "<input type=hidden name=mailbox value=$mailbox>\n";
134 echo "<TABLE WIDTH=50 ALIGN=center CELLSPACING=0 BORDER=0>\n";
136 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
138 echo " </TD><TD colspan=2 WIDTH=\"100%\" BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
140 echo " <INPUT TYPE=TEXT NAME=\"send_to\" VALUE=\"$send_to\" SIZE=60><BR>\n";
142 echo " <INPUT TYPE=TEXT NAME=\"send_to\" SIZE=60><BR>\n";
146 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
148 echo " </TD><TD colspan=2 BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
150 echo " <INPUT TYPE=TEXT NAME=\"send_to_cc\" SIZE=60 VALUE=\"$send_to_cc\"><BR>\n";
152 echo " <INPUT TYPE=TEXT NAME=\"send_to_cc\" SIZE=60><BR>\n";
156 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
158 echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
160 echo " <INPUT TYPE=TEXT NAME=\"send_to_bcc\" VALUE=\"$send_to_bcc\" SIZE=60><BR>\n";
162 echo " <INPUT TYPE=TEXT NAME=\"send_to_bcc\" SIZE=60><BR>";
167 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
169 echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
171 $reply_subj = str_replace("\"", "'", $reply_subj);
172 $reply_subj = stripslashes($reply_subj);
173 $reply_subj = trim($reply_subj);
174 if (substr(strtolower($reply_subj), 0, 3) != "re:")
175 $reply_subj = "Re: $reply_subj";
176 echo " <INPUT TYPE=TEXT NAME=subject SIZE=60 VALUE=\"$reply_subj\">";
177 } else if ($forward_subj) {
178 $forward_subj = str_replace("\"", "'", $forward_subj);
179 $forward_subj = stripslashes($forward_subj);
180 $forward_subj = trim($forward_subj);
181 if ((substr(strtolower($forward_subj), 0, 4) != "fwd:") &&
182 (substr(strtolower($forward_subj), 0, 5) != "[fwd:") &&
183 (substr(strtolower($forward_subj), 0, 6) != "[ fwd:"))
184 $forward_subj = "[Fwd: $forward_subj]";
185 echo " <INPUT TYPE=TEXT NAME=subject SIZE=60 VALUE=\"$forward_subj\">";
187 echo " <INPUT TYPE=TEXT NAME=subject VALUE=\"$subject\" SIZE=60>";
189 echo "</td></tr>\n\n";
191 echo " <TR><td>\n </td><td>\n";
192 if ($use_javascript_addr_book) {
193 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"";
194 echo " <input type=button value=\\\""._("Addresses")."\\\" onclick='javascript:open_abook();'>\");";
195 echo " // --></SCRIPT><NOSCRIPT>\n";
196 echo " <input type=submit name=\"html_addr_search\" value=\""._("Addresses")."\">";
197 echo " </NOSCRIPT>\n";
199 echo " <input type=submit name=\"html_addr_search\" value=\""._("Addresses")."\">";
201 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
207 echo " <TD BGCOLOR=\"$color[4]\" COLSPAN=3>\n";
208 if ($use_signature == true && $newmail == true)
209 echo " <TEXTAREA NAME=body ROWS=20 COLS=\"$editor_size\" WRAP=HARD>". $body . "\n\n-- \n".$signature."</TEXTAREA><BR>";
211 echo " <TEXTAREA NAME=body ROWS=20 COLS=\"$editor_size\" WRAP=HARD>".$body."</TEXTAREA><BR>\n";
214 echo " <TR><TD COLSPAN=3 ALIGN=CENTER><INPUT TYPE=SUBMIT NAME=send VALUE=\"";
216 echo "\"></TD></TR>\n";
218 // This code is for attachments
220 echo " <TD WIDTH=50 BGCOLOR=\"$color[0]\" VALIGN=TOP ALIGN=RIGHT>\n";
221 echo " <SMALL><BR></SMALL>"._("Attach:");
222 echo " </td><td colspan=2 ALIGN=left BGCOLOR=\"$color[0]\">\n";
223 // echo " <INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\"\n";
224 // echo " value=\"10000\">\n";
225 echo " <INPUT NAME=\"attachfile\" TYPE=\"file\">\n";
226 echo " <input type=\"submit\" name=\"attach\"\n";
227 echo " value=\"" . _("Add") ."\">\n";
230 if (isset($attachments) && count($attachments)>0) {
231 echo "</tr><tr><td width=50 bgcolor=\"$color[0]\" align=right>\n";
233 echo "</td><td align=left colspan=2 bgcolor=\"$color[0]\">";
234 while (list($localname, $remotename) = each($attachments)) {
235 echo "<input type=\"checkbox\" name=\"delete[]\" value=\"$localname\">\n";
236 echo "$remotename <input type=\"hidden\" name=\"attachments[$localname]\" value=\"$remotename\"><br>\n";
239 echo "<input type=\"submit\" name=\"do_delete\" value=\""._("Delete selected attachments")."\">\n";
242 // End of attachment code
248 function showSentForm () {
249 echo "<BR><BR><BR><CENTER><B>Message Sent!</B><BR><BR>";
250 echo "You will be automatically forwarded.<BR>If not, <A HREF=\"right_main.php\">click here</A>";
254 function checkInput ($show) {
255 /** I implemented the $show variable because the error messages
256 were getting sent before the page header. So, I check once
257 using $show=false, and then when i'm ready to display the
258 error message, show=true **/
259 global $body, $send_to, $subject, $color;
261 if ($body == "" && $subject == "") {
263 plain_error_message(_("You have not entered a message body or a subject."), $color);
265 } else if ($send_to == "") {
267 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
271 } // function checkInput()
274 if (($mailbox == "") ||
($mailbox == "None"))
278 if (checkInput(false)) {
279 $urlMailbox = urlencode ($mailbox);
280 sendMessage($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id);
281 header ("Location: right_main.php?mailbox=$urlMailbox&sort=$sort&startMessage=1");
283 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
284 displayPageHeader($color, $mailbox);
289 } else if ($html_addr_search_done) {
290 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
291 displayPageHeader($color, $mailbox);
293 $body = stripslashes($body);
294 $send_to = stripslashes($send_to);
295 $send_to_cc = stripslashes($send_to_cc);
296 $send_to_bcc = stripslashes($send_to_bcc);
297 $subject = stripslashes($subject);
299 for ($i=0; $i < count($send_to_search); $i++
) {
302 $send_to .= $send_to_search[$i];
305 for ($i=0; $i < count($send_to_cc_search); $i++
) {
308 $send_to_cc .= $send_to_cc_search[$i];
312 } else if ($html_addr_search) {
313 //* I am using an include so as to elminiate an extra unnecessary click. If you
314 //* can think of a better way, please implement it.
315 include ("addrbook_search_html.php");
316 } else if (isset($attach)) {
317 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
318 displayPageHeader($color, $mailbox);
320 $localfilename = md5("$attachfile, $attachfile_name, $REMOTE_IP, $REMOTE_PORT, $UNIQUE_ID, and everything else that may add entropy");
321 $localfilename = $localfilename;
323 // Put the file in a better place
324 error_reporting(0); // Rename will produce error output if it fails
325 if (!rename($attachfile, $attachment_dir.$localfilename)) {
326 if (!copy($attachfile, $attachment_dir.$localfilename)) {
327 plain_error_message(_("Could not move/copy file. File not attached"));
331 // If it still exists, PHP will remove the original file
334 // Write information about the file
335 $fp = fopen ($attachment_dir.$localfilename.".info", "w");
336 fputs ($fp, "$attachfile_type\n$attachfile_name\n");
339 $attachments[$localfilename] = $attachfile_name;
343 } else if (isset($do_delete)) {
344 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
345 displayPageHeader($color, $mailbox);
347 while (list($key, $localname) = each($delete)) {
348 array_splice ($attachments, $key, 1);
349 unlink ($attachment_dir.$localname);
350 unlink ($attachment_dir.$localname.".info");
355 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
356 displayPageHeader($color, $mailbox);