adcac3e5f63084bae14a65e9d3b4a78dfe03dd3d
2 /** This code sends a mail.
4 ** There are 3 modes of operation:
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");
27 include("../src/load_prefs.php");
29 // This function is used when not sending or adding attachments
31 global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
32 $reply_id, $send_to, $send_to_cc, $mailbox;
34 $send_to = decodeHeader($send_to);
35 $send_to_cc = decodeHeader($send_to_cc);
38 sqimap_mailbox_select($imapConnection, $mailbox);
39 $msg = sqimap_get_message($imapConnection, $forward_id, $mailbox);
41 if (containsType($msg, "text", "html", $ent_num)) {
42 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"]);
43 } else if (containsType($msg, "text", "plain", $ent_num)) {
44 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"]);
46 // add other primary displaying msg types here
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"]);
54 $body = _("No Message");
58 $type1 = $msg["ENTITIES"][$ent_num]["TYPE1"];
60 $tmp = _("-------- Original Message ---------\n");
61 $body_ary = explode("\n", $body);
63 for ($i=0;$i < count($body_ary);$i++
) {
65 $tmp .= strip_tags($body_ary[$i]);
67 $tmp .= $body_ary[$i];
68 $body = "$body$tmp\n";
74 sqimap_mailbox_select($imapConnection, $mailbox);
75 $msg = sqimap_get_message($imapConnection, $reply_id, $mailbox);
77 if (containsType($msg, "text", "html", $ent_num)) {
78 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"], false);
79 } else if (containsType($msg, "text", "plain", $ent_num)) {
80 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"], false);
82 // add other primary displaying msg types here
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);
90 $body = _("No Message");
94 $type1 = $msg["ENTITIES"][$ent_num]["TYPE1"];
96 $body_ary = explode("\n", $body);
98 for ($i=0;$i < count($body_ary);$i++
) {
100 $tmp = strip_tags($body_ary[$i]);
102 $tmp = $body_ary[$i];
103 $body = "$body> $tmp\n";
107 $send_to = sqimap_find_email($send_to);
109 $send_to = ereg_replace("\"", "", $send_to);
110 $send_to = stripslashes($send_to);
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);
118 for ($i = 0; $i < count($sendcc); $i++
) {
119 $sendcc[$i] = trim($sendcc[$i]);
120 if ($sendcc[$i] == "")
123 $sendcc[$i] = sqimap_find_email($sendcc[$i]);
124 $whofrom = sqimap_find_displayable_name($msg["HEADER"]["FROM"]);
125 $whoreplyto = sqimap_find_email($msg["HEADER"]["REPLYTO"]);
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]) . ", ";
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);
138 } // function newMail()
140 function showInputForm () {
141 global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body,
142 $passed_body, $color, $use_signature, $signature, $editor_size,
143 $attachments, $subject, $newmail;
145 $subject = decodeHeader($subject);
146 $reply_subj = decodeHeader($reply_subj);
147 $forward_subj = decodeHeader($forward_subj);
149 echo "\n<FORM action=\"compose.php\" METHOD=POST\n";
150 echo "ENCTYPE=\"multipart/form-data\">\n";
151 echo "<TABLE COLS=2 WIDTH=50 ALIGN=center CELLSPACING=0 BORDER=0>\n";
153 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
155 echo " </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
157 echo " <INPUT TYPE=TEXT NAME=send_to VALUE=\"$send_to\" SIZE=60><BR>";
159 echo " <INPUT TYPE=TEXT NAME=send_to SIZE=60><BR>";
163 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
165 echo " </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
167 echo " <INPUT TYPE=TEXT NAME=send_to_cc SIZE=60 VALUE=\"$send_to_cc\"><BR>";
169 echo " <INPUT TYPE=TEXT NAME=send_to_cc SIZE=60><BR>";
173 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
175 echo " </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
177 echo " <INPUT TYPE=TEXT NAME=send_to_bcc VALUE=\"$send_to_bcc\" SIZE=60><BR>";
179 echo " <INPUT TYPE=TEXT NAME=send_to_bcc SIZE=60><BR>";
183 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
185 echo " </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
187 $reply_subj = str_replace("\"", "'", $reply_subj);
188 $reply_subj = stripslashes($reply_subj);
189 $reply_subj = trim($reply_subj);
190 if (substr(strtolower($reply_subj), 0, 3) != "re:")
191 $reply_subj = "Re: $reply_subj";
192 echo " <INPUT TYPE=TEXT NAME=subject SIZE=60 VALUE=\"$reply_subj\">";
193 } else if ($forward_subj) {
194 $forward_subj = str_replace("\"", "'", $forward_subj);
195 $forward_subj = stripslashes($forward_subj);
196 $forward_subj = trim($forward_subj);
197 if ((substr(strtolower($forward_subj), 0, 4) != "fwd:") &&
198 (substr(strtolower($forward_subj), 0, 5) != "[fwd:") &&
199 (substr(strtolower($forward_subj), 0, 6) != "[ fwd:"))
200 $forward_subj = "[Fwd: $forward_subj]";
201 echo " <INPUT TYPE=TEXT NAME=subject SIZE=50 VALUE=\"$forward_subj\">";
203 echo " <INPUT TYPE=TEXT NAME=subject VALUE=\"$subject\" SIZE=50>";
205 echo " <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">";
210 echo " <TD BGCOLOR=\"$color[4]\" COLSPAN=2>\n";
211 if ($use_signature == true && $newmail == true)
212 echo " <TEXTAREA NAME=body ROWS=20 COLS=\"$editor_size\" WRAP=HARD>". $body . "\n\n-- \n".$signature."</TEXTAREA><BR>";
214 echo " <TEXTAREA NAME=body ROWS=20 COLS=\"$editor_size\" WRAP=HARD>".$body."</TEXTAREA><BR>\n";
217 echo " <TR><TD COLSPAN=2 ALIGN=CENTER><INPUT TYPE=SUBMIT NAME=send VALUE=\"";
219 echo "\"></TD></TR>\n";
221 // This code is for attachments
223 echo " <TD WIDTH=50 BGCOLOR=\"$color[0]\" VALIGN=TOP ALIGN=RIGHT>\n";
224 echo " <SMALL><BR></SMALL>"._("Attach:");
225 echo " </td><td width=% ALIGN=left BGCOLOR=\"$color[0]\">\n";
226 // echo " <INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\"\n";
227 // echo " value=\"10000\">\n";
228 echo " <INPUT NAME=\"attachfile\" TYPE=\"file\">\n";
229 echo " <input type=\"submit\" name=\"attach\"\n";
230 echo " value=\"" . _("Add") ."\">\n";
234 if (isset($attachments) && count($attachments)>0) {
235 echo "</tr><tr><td width=50 bgcolor=\"$color[0]\" align=right>\n";
237 echo "</td><td width=% align=left bgcolor=\"$color[0]\">";
238 while (list($localname, $remotename) = each($attachments)) {
239 echo "<input type=\"checkbox\" name=\"delete[]\" value=\"$localname\">\n";
240 echo "$remotename <input type=\"hidden\" name=\"attachments[$localname]\" value=\"$remotename\"><br>\n";
243 echo "<input type=\"submit\" name=\"do_delete\" value=\""._("Delete selected attachments")."\">\n";
246 // End of attachment code
252 function showSentForm () {
253 echo "<BR><BR><BR><CENTER><B>Message Sent!</B><BR><BR>";
254 echo "You will be automatically forwarded.<BR>If not, <A HREF=\"right_main.php\">click here</A>";
258 function checkInput () {
259 global $body, $send_to, $subject;
262 plain_error_message(_("You have not entered a message body."), $color);
264 } else if ($send_to == "") {
265 displayPageHeader($color, "None");
266 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
268 } else if ($subject == "") {
269 plain_error_message(_("You have not entered a subject."), $color);
273 } // function checkInput()
277 sendMessage($send_to, $send_to_cc, $send_to_bcc, $subject, $body);
278 header ("Location: right_main.php");
280 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
281 $imapConnection = sqimap_login($username, $key, $imapServerAddress, 0);
282 displayPageHeader($color, "None");
286 } else if (isset($attach)) {
287 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
288 $imapConnection = sqimap_login($username, $key, $imapServerAddress, 0);
289 displayPageHeader($color, "None");
291 $localfilename = md5("$attachfile, $attachfile_name, $REMOTE_IP, $REMOTE_PORT, $UNIQUE_ID, and everything else that may add entropy");
292 $localfilename = $localfilename;
294 // Put the file in a better place
295 error_reporting(0); // Rename will produce error output if it fails
296 if (!rename($attachfile, $attachment_dir.$localfilename)) {
297 if (!copy($attachfile, $attachment_dir.$localfilename)) {
298 plain_error_message(_("Could not move/copy file. File not attached"));
302 // If it still exists, PHP will remove the original file
305 // Write information about the file
306 $fp = fopen ($attachment_dir.$localfilename.".info", "w");
307 fputs ($fp, "$attachfile_type\n$attachfile_name\n");
310 $attachments[$localfilename] = $attachfile_name;
314 } else if (isset($do_delete)) {
315 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
316 $imapConnection = sqimap_login($username, $key, $imapServerAddress, 0);
317 displayPageHeader($color, "None");
319 while (list($key, $localname) = each($delete)) {
320 array_splice ($attachments, $key, 1);
321 unlink ($attachment_dir.$localname);
322 unlink ($attachment_dir.$localname.".info");
327 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
328 $imapConnection = sqimap_login($username, $key, $imapServerAddress, 0);
329 displayPageHeader($color, "None");