2 /** This code sends a mail.
4 ** There are 3 modes of operation:
10 include("../config/config.php");
11 include("../functions/strings.php");
12 include("../functions/page_header.php");
13 include("../functions/imap.php");
14 include("../functions/date.php");
15 include("../functions/mime.php");
16 include("../functions/smtp.php");
17 include("../functions/display_messages.php");
19 include("../src/load_prefs.php");
21 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
22 $imapConnection = sqimap_login($username, $key, $imapServerAddress, 0);
23 displayPageHeader($color, "None");
25 // This function is used when not sending or adding attachments
27 global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
28 $reply_id, $send_to, $send_to_cc, $mailbox;
31 sqimap_mailbox_select($imapConnection, $mailbox);
32 $msg = sqimap_get_message($imapConnection, $forward_id, $mailbox);
34 if (containsType($msg, "text", "html", $ent_num)) {
35 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"]);
36 } else if (containsType($msg, "text", "plain", $ent_num)) {
37 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"]);
39 // add other primary displaying msg types here
41 // find any type that's displayable
42 if (containsType($msg, "text", "any_type", $ent_num)) {
43 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"]);
44 } else if (containsType($msg, "msg", "any_type", $ent_num)) {
45 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"]);
47 $body = _("No Message");
51 $type1 = $msg["ENTITIES"][$ent_num]["TYPE1"];
53 $tmp = _("-------- Original Message ---------\n");
54 $body_ary = explode("\n", $body);
56 for ($i=0;$i < count($body_ary);$i++
) {
58 $tmp .= strip_tags($body_ary[$i]);
60 $tmp .= $body_ary[$i];
61 $body = "$body$tmp\n";
67 sqimap_mailbox_select($imapConnection, $mailbox);
68 $msg = sqimap_get_message($imapConnection, $reply_id, $mailbox);
70 if (containsType($msg, "text", "html", $ent_num)) {
71 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"], false);
72 } else if (containsType($msg, "text", "plain", $ent_num)) {
73 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"], false);
75 // add other primary displaying msg types here
77 // find any type that's displayable
78 if (containsType($msg, "text", "any_type", $ent_num)) {
79 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"], false);
80 } else if (containsType($msg, "msg", "any_type", $ent_num)) {
81 $body = decodeBody($msg["ENTITIES"][$ent_num]["BODY"], $msg["ENTITIES"][$ent_num]["ENCODING"], false);
83 $body = _("No Message");
87 $type1 = $msg["ENTITIES"][$ent_num]["TYPE1"];
89 $body_ary = explode("\n", $body);
91 for ($i=0;$i < count($body_ary);$i++
) {
93 $tmp = strip_tags($body_ary[$i]);
96 $body = "$body> $tmp\n";
100 $send_to = sqimap_find_displayable_name($send_to);
102 $send_to = strtolower($send_to);
103 $send_to = ereg_replace("\"", "", $send_to);
104 $send_to = stripslashes($send_to);
106 /** This formats a CC string if they hit "reply all" **/
107 if ($send_to_cc != "") {
108 $send_to_cc = ereg_replace(";", ",", $send_to_cc);
109 $sendcc = explode(",", $send_to_cc);
112 for ($i = 0; $i < count($sendcc); $i++
) {
113 $sendcc[$i] = trim($sendcc[$i]);
114 if ($sendcc[$i] == "")
117 $sendcc[$i] = sqimap_find_displayable_name($sendcc[$i]);
118 $whofrom = sqimap_find_displayable_name($msg["HEADER"]["FROM"]);
119 $whoreplyto = sqimap_find_email($msg["HEADER"]["REPLYTO"]);
121 if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) &&
122 (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) &&
123 (trim($sendcc[$i]) != "")) {
124 $send_to_cc .= trim($sendcc[$i]) . ", ";
127 $send_to_cc = trim($send_to_cc);
128 if (substr($send_to_cc, -1) == ",") {
129 $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1);
132 } // function newMail()
134 function showInputForm () {
135 global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body,
136 $passed_body, $color, $use_signature, $signature, $editor_size,
137 $attachments, $subject;
139 echo "\n<FORM action=\"compose.php\" METHOD=POST\n";
140 echo "ENCTYPE=\"multipart/form-data\">\n";
141 echo "<TABLE COLS=2 WIDTH=50 ALIGN=center CELLSPACING=0 BORDER=0>\n";
143 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
144 echo " <FONT FACE=\"Arial,Helvetica\">";
147 echo " </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
149 echo " <INPUT TYPE=TEXT NAME=send_to VALUE=\"$send_to\" SIZE=60><BR>";
151 echo " <INPUT TYPE=TEXT NAME=send_to SIZE=60><BR>";
155 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
156 echo " <FONT FACE=\"Arial,Helvetica\">"._("CC").":</FONT>\n";
157 echo " </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
159 echo " <INPUT TYPE=TEXT NAME=send_to_cc SIZE=60 VALUE=\"$send_to_cc\"><BR>";
161 echo " <INPUT TYPE=TEXT NAME=send_to_cc SIZE=60><BR>";
165 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
166 echo " <FONT FACE=\"Arial,Helvetica\">BCC:</FONT>\n";
167 echo " </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
169 echo " <INPUT TYPE=TEXT NAME=send_to_bcc VALUE=\"$send_to_bcc\" SIZE=60><BR>";
171 echo " <INPUT TYPE=TEXT NAME=send_to_bcc SIZE=60><BR>";
175 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
176 echo " <FONT FACE=\"Arial,Helvetica\">";
179 echo " </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
181 $reply_subj = str_replace("\"", "'", $reply_subj);
182 $reply_subj = stripslashes($reply_subj);
183 $reply_subj = trim($reply_subj);
184 if (substr(strtolower($reply_subj), 0, 3) != "re:")
185 $reply_subj = "Re: $reply_subj";
186 echo " <INPUT TYPE=TEXT NAME=subject SIZE=60 VALUE=\"$reply_subj\">";
187 } else if ($forward_subj) {
188 $forward_subj = str_replace("\"", "'", $forward_subj);
189 $forward_subj = stripslashes($forward_subj);
190 $forward_subj = trim($forward_subj);
191 if ((substr(strtolower($forward_subj), 0, 4) != "fwd:") &&
192 (substr(strtolower($forward_subj), 0, 5) != "[fwd:") &&
193 (substr(strtolower($forward_subj), 0, 6) != "[ fwd:"))
194 $forward_subj = "[Fwd: $forward_subj]";
195 echo " <INPUT TYPE=TEXT NAME=subject SIZE=50 VALUE=\"$forward_subj\">";
197 echo " <INPUT TYPE=TEXT NAME=subject VALUE=\"$subject\" SIZE=50>";
199 echo " <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">";
204 echo " <TD BGCOLOR=\"$color[4]\" COLSPAN=2>\n";
205 if ($use_signature == true)
206 echo " <TEXTAREA NAME=body ROWS=20 COLS=\"$editor_size\" WRAP=HARD>". $body . "\n\n".$signature."</TEXTAREA><BR>";
208 echo " <TEXTAREA NAME=body ROWS=20 COLS=\"$editor_size\" WRAP=HARD>".$body."</TEXTAREA><BR>\n";
211 echo " <TR><TD COLSPAN=2 ALIGN=CENTER><INPUT TYPE=SUBMIT NAME=send VALUE=\"";
213 echo "\"></TD></TR>\n";
215 // This code is for attachments
217 echo " <TD WIDTH=50 BGCOLOR=\"$color[0]\" VALIGN=TOP ALIGN=RIGHT>\n";
218 echo " <FONT FACE=\"Arial,Helvetica\">";
219 echo " <SMALL><BR></SMALL>"._("Attach:")."</FONT>\n";
220 echo " </td><td width=% ALIGN=left BGCOLOR=\"$color[0]\">\n";
221 // echo " <INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\"\n";
222 // echo " value=\"10000\">\n";
223 echo " <INPUT NAME=\"attachfile\" TYPE=\"file\">\n";
224 echo " <input type=\"submit\" name=\"attach\"\n";
225 echo " value=\"" . _("Add") ."\">\n";
229 if (isset($attachments) && count($attachments)>0) {
230 echo "</tr><tr><td width=50 bgcolor=\"$color[0]\" align=right>\n";
232 echo "</td><td width=% align=left bgcolor=\"$color[0]\">";
233 while (list($localname, $remotename) = each($attachments)) {
234 echo "<input type=\"checkbox\" name=\"delete[]\" value=\"$localname\">\n";
235 echo "$remotename <input type=\"hidden\" name=\"attachments[$localname]\" value=\"$remotename\"><br>\n";
238 echo "<input type=\"submit\" name=\"do_delete\" value=\""._("Delete selected attachments")."\">\n";
241 // End of attachment code
247 function showSentForm () {
248 echo "<FONT FACE=\"Arial,Helvetica\">";
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>";
251 echo "</CENTER></FONT>";
254 function checkInput () {
255 global $body, $send_to, $subject;
258 plain_error_message(_("You have not entered a message body."), $color);
260 } else if ($send_to == "") {
261 displayPageHeader($color, "None");
262 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
264 } else if ($subject == "") {
265 plain_error_message(_("You have not entered a subject."), $color);
269 } // function checkInput()
273 sendMessage($send_to, $send_to_cc, $send_to_bcc, $subject, $body);
278 } else if (isset($attach)) {
279 $localfilename = md5("$attachfile, $attachfile_name, $REMOTE_IP, $REMOTE_PORT, $UNIQUE_ID, and everything else that may add entropy");
280 $localfilename = $localfilename;
282 // Put the file in a better place
283 error_reporting(0); // Rename will produce error output if it fails
284 if (!rename($attachfile, $attachment_dir.$localfilename)) {
285 if (!copy($attachfile, $attachment_dir.$localfilename)) {
286 plain_error_message(_("Could not move/copy file. File not attached"));
290 // If it still exists, PHP will remove the original file
293 // Write information about the file
294 $fp = fopen ($attachment_dir.$localfilename.".info", "w");
295 fputs ($fp, "$attachfile_type\n$attachfile_name\n");
298 $attachments[$localfilename] = $attachfile_name;
302 } else if (isset($do_delete)) {
303 while (list($key, $localname) = each($delete)) {
304 array_splice ($attachments, $localname, 1);
305 unlink ($attachment_dir.$localname);
306 unlink ($attachment_dir.$localname.".info");