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");
28 if (!isset($auth_php))
29 include ("../functions/auth.php");
31 include("../src/load_prefs.php");
33 // This function is used when not sending or adding attachments
35 global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
36 $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc;
38 $send_to = decodeHeader($send_to);
39 $send_to_cc = decodeHeader($send_to_cc);
47 sqimap_mailbox_select($imapConnection, $mailbox);
48 $message = sqimap_get_message($imapConnection, $id, $mailbox);
49 $message = getEntity($message, $ent_num);
51 if ($message->header
->type0
== "text" ||
$message->header
->type1
== "message") {
52 $body = decodeBody(mime_fetch_body($imapConnection, $id, $message->header
->entity_id
), $message->header
->encoding
);
58 $tmp = _("-------- Original Message ---------\n");
59 if ($message->header
->type1
== "html")
60 $body = strip_tags($body);
62 $body_ary = explode("\n", $body);
64 for ($i=0; $i < count($body_ary); $i++
) {
68 $body = "$body$tmp\n";
70 $body = "$body> $tmp\n";
76 $send_to = sqimap_find_email($send_to);
79 // $send_to = ereg_replace("\"", "", $send_to);
80 $send_to = stripslashes($send_to);
82 /** This formats a CC string if they hit "reply all" **/
83 if ($send_to_cc != "") {
84 $send_to_cc = ereg_replace(";", ",", $send_to_cc);
85 $sendcc = explode(",", $send_to_cc);
88 for ($i = 0; $i < count($sendcc); $i++
) {
89 $sendcc[$i] = trim($sendcc[$i]);
90 if ($sendcc[$i] == "")
93 $sendcc[$i] = sqimap_find_email($sendcc[$i]);
94 $whofrom = sqimap_find_displayable_name($msg["HEADER"]["FROM"]);
95 $whoreplyto = sqimap_find_email($msg["HEADER"]["REPLYTO"]);
97 if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) &&
98 (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) &&
99 (trim($sendcc[$i]) != "")) {
100 $send_to_cc .= trim($sendcc[$i]) . ", ";
103 $send_to_cc = trim($send_to_cc);
104 if (substr($send_to_cc, -1) == ",") {
105 $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1);
108 } // function newMail()
110 function showInputForm () {
111 global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body,
112 $passed_body, $color, $use_signature, $signature, $editor_size,
113 $attachments, $subject, $newmail, $use_javascript_addr_book,
114 $send_to_bcc, $reply_id, $mailbox;
116 $subject = decodeHeader($subject);
117 $reply_subj = decodeHeader($reply_subj);
118 $forward_subj = decodeHeader($forward_subj);
120 if ($use_javascript_addr_book) {
121 echo "\n<SCRIPT LANGUAGE=JavaScript><!--\n";
122 echo "function open_abook() { \n";
123 echo " var nwin = window.open(\"addrbook_popup.php\",\"abookpopup\",";
124 echo "\"width=670,height=300,resizable=yes,scrollbars=yes\");\n";
125 echo " if((!nwin.opener) && (document.windows != null))\n";
126 echo " nwin.opener = document.windows;\n";
128 echo "// --></SCRIPT>\n\n";
131 echo "\n<FORM name=compose action=\"compose.php\" METHOD=POST ENCTYPE=\"multipart/form-data\">\n";
133 echo "<input type=hidden name=reply_id value=$reply_id>\n";
135 printf("<INPUT TYPE=hidden NAME=mailbox VALUE=\"%s\">\n", htmlspecialchars($mailbox));
136 echo "<TABLE WIDTH=50 ALIGN=center CELLSPACING=0 BORDER=0>\n";
138 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
140 echo " </TD><TD colspan=2 WIDTH=\"100%\" BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
141 printf(" <INPUT TYPE=text NAME=\"send_to\" VALUE=\"%s\" SIZE=60><BR>\n",
142 htmlspecialchars($send_to));
146 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
148 echo " </TD><TD colspan=2 BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
149 printf(" <INPUT TYPE=text NAME=\"send_to_cc\" SIZE=60 VALUE=\"%s\"><BR>\n",
150 htmlspecialchars($send_to_cc));
154 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
156 echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
157 printf(" <INPUT TYPE=text NAME=\"send_to_bcc\" VALUE=\"%s\" SIZE=60><BR>\n",
158 htmlspecialchars($send_to_bcc));
162 echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
164 echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
166 $reply_subj = str_replace("\"", "'", $reply_subj);
167 $reply_subj = stripslashes($reply_subj);
168 $reply_subj = trim($reply_subj);
169 if (substr(strtolower($reply_subj), 0, 3) != "re:")
170 $reply_subj = "Re: $reply_subj";
171 printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">",
172 htmlspecialchars($reply_subj));
173 } else if ($forward_subj) {
174 $forward_subj = str_replace("\"", "'", $forward_subj);
175 $forward_subj = stripslashes($forward_subj);
176 $forward_subj = trim($forward_subj);
177 if ((substr(strtolower($forward_subj), 0, 4) != "fwd:") &&
178 (substr(strtolower($forward_subj), 0, 5) != "[fwd:") &&
179 (substr(strtolower($forward_subj), 0, 6) != "[ fwd:"))
180 $forward_subj = "[Fwd: $forward_subj]";
181 printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">",
182 htmlspecialchars($forward_subj));
184 printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">",
185 htmlspecialchars($subject));
187 echo "</td></tr>\n\n";
189 echo " <TR><td>\n </td><td>\n";
190 if ($use_javascript_addr_book) {
191 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"";
192 echo " <input type=button value=\\\""._("Addresses")."\\\" onclick='javascript:open_abook();'>\");";
193 echo " // --></SCRIPT><NOSCRIPT>\n";
194 echo " <input type=submit name=\"html_addr_search\" value=\""._("Addresses")."\">";
195 echo " </NOSCRIPT>\n";
197 echo " <input type=submit name=\"html_addr_search\" value=\""._("Addresses")."\">";
199 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
205 echo " <TD BGCOLOR=\"$color[4]\" COLSPAN=3>\n";
206 echo " <TEXTAREA NAME=body ROWS=20 COLS=\"$editor_size\" WRAP=HARD>";
207 if ($use_signature == true && $newmail == true) {
208 echo htmlspecialchars($body) . "\n\n-- \n" . htmlspecialchars($signature);
210 echo htmlspecialchars($body);
212 echo "</TEXTAREA><BR>\n";
215 echo " <TR><TD COLSPAN=3 ALIGN=CENTER><INPUT TYPE=SUBMIT NAME=send VALUE=\"";
217 echo "\"></TD></TR>\n";
219 // This code is for attachments
221 echo " <TD WIDTH=50 BGCOLOR=\"$color[0]\" VALIGN=TOP ALIGN=RIGHT>\n";
222 echo " <SMALL><BR></SMALL>"._("Attach:");
223 echo " </td><td colspan=2 ALIGN=left BGCOLOR=\"$color[0]\">\n";
224 // echo " <INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\"\n";
225 // echo " value=\"10000\">\n";
226 echo " <INPUT NAME=\"attachfile\" TYPE=\"file\">\n";
227 echo " <input type=\"submit\" name=\"attach\"\n";
228 echo " value=\"" . _("Add") ."\">\n";
231 if (isset($attachments) && count($attachments)>0) {
232 echo "</tr><tr><td width=50 bgcolor=\"$color[0]\" align=right>\n";
234 echo "</td><td align=left colspan=2 bgcolor=\"$color[0]\">";
235 while (list($localname, $remotename) = each($attachments)) {
236 echo "<input type=\"checkbox\" name=\"delete[]\" value=\"$localname\">\n";
237 echo "$remotename <input type=\"hidden\" name=\"attachments[$localname]\" value=\"$remotename\"><br>\n";
240 echo "<input type=\"submit\" name=\"do_delete\" value=\""._("Delete selected attachments")."\">\n";
243 // End of attachment code
249 function showSentForm () {
250 echo "<BR><BR><BR><CENTER><B>Message Sent!</B><BR><BR>";
251 echo "You will be automatically forwarded.<BR>If not, <A HREF=\"right_main.php\">click here</A>";
255 function checkInput ($show) {
256 /** I implemented the $show variable because the error messages
257 were getting sent before the page header. So, I check once
258 using $show=false, and then when i'm ready to display the
259 error message, show=true **/
260 global $body, $send_to, $subject, $color;
262 if ($body == "" && $subject == "") {
264 plain_error_message(_("You have not entered a message body or a subject."), $color);
266 } else if ($send_to == "") {
268 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
272 } // function checkInput()
275 if (($mailbox == "") ||
($mailbox == "None"))
279 if (checkInput(false)) {
280 $urlMailbox = urlencode ($mailbox);
281 sendMessage($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id);
282 header ("Location: right_main.php?mailbox=$urlMailbox&sort=$sort&startMessage=1");
284 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
285 displayPageHeader($color, $mailbox);
290 } else if ($html_addr_search_done) {
292 displayPageHeader($color, $mailbox);
294 $body = stripslashes($body);
295 $send_to = stripslashes($send_to);
296 $send_to_cc = stripslashes($send_to_cc);
297 $send_to_bcc = stripslashes($send_to_bcc);
298 $subject = stripslashes($subject);
300 for ($i=0; $i < count($send_to_search); $i++
) {
303 $send_to .= $send_to_search[$i];
306 for ($i=0; $i < count($send_to_cc_search); $i++
) {
309 $send_to_cc .= $send_to_cc_search[$i];
313 } else if ($html_addr_search) {
314 // I am using an include so as to elminiate an extra unnecessary click. If you
315 // can think of a better way, please implement it.
316 include ("addrbook_search_html.php");
317 } else if (isset($attach)) {
319 displayPageHeader($color, $mailbox);
321 $localfilename = md5("$attachfile, $attachfile_name, $REMOTE_IP, $REMOTE_PORT, $UNIQUE_ID, and everything else that may add entropy");
322 $localfilename = $localfilename;
324 // Put the file in a better place
325 error_reporting(0); // Rename will produce error output if it fails
326 if (!rename($attachfile, $attachment_dir.$localfilename)) {
327 if (!copy($attachfile, $attachment_dir.$localfilename)) {
328 plain_error_message(_("Could not move/copy file. File not attached"));
332 // If it still exists, PHP will remove the original file
335 // Write information about the file
336 $fp = fopen ($attachment_dir.$localfilename.".info", "w");
337 fputs ($fp, "$attachfile_type\n$attachfile_name\n");
340 $attachments[$localfilename] = $attachfile_name;
344 } else if (isset($do_delete)) {
346 displayPageHeader($color, $mailbox);
348 while (list($key, $localname) = each($delete)) {
349 array_splice ($attachments, $key, 1);
350 unlink ($attachment_dir.$localname);
351 unlink ($attachment_dir.$localname.".info");
356 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
357 displayPageHeader($color, $mailbox);