| 1 | <? |
| 2 | /** This code sends a mail. |
| 3 | ** |
| 4 | ** There are 3 modes of operation: |
| 5 | ** - Start new mail |
| 6 | ** - Add an attachment |
| 7 | ** - Send mail |
| 8 | **/ |
| 9 | |
| 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"); |
| 18 | |
| 19 | include("../src/load_prefs.php"); |
| 20 | |
| 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"); |
| 24 | |
| 25 | // This function is used when not sending or adding attachments |
| 26 | function newMail () { |
| 27 | global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body, |
| 28 | $reply_id, $send_to, $send_to_cc, $mailbox; |
| 29 | |
| 30 | if ($forward_id) { |
| 31 | sqimap_mailbox_select($imapConnection, $mailbox); |
| 32 | $msg = sqimap_get_message($imapConnection, $forward_id, $mailbox); |
| 33 | |
| 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"]); |
| 38 | } |
| 39 | // add other primary displaying msg types here |
| 40 | else { |
| 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"]); |
| 46 | } else { |
| 47 | $body = _("No Message"); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | $type1 = $msg["ENTITIES"][$ent_num]["TYPE1"]; |
| 52 | |
| 53 | $tmp = _("-------- Original Message ---------\n"); |
| 54 | $body_ary = explode("\n", $body); |
| 55 | $body = ""; |
| 56 | for ($i=0;$i < count($body_ary);$i++) { |
| 57 | if ($type1 == "html") |
| 58 | $tmp .= strip_tags($body_ary[$i]); |
| 59 | else |
| 60 | $tmp .= $body_ary[$i]; |
| 61 | $body = "$body$tmp\n"; |
| 62 | $tmp = ""; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | if ($reply_id) { |
| 67 | sqimap_mailbox_select($imapConnection, $mailbox); |
| 68 | $msg = sqimap_get_message($imapConnection, $reply_id, $mailbox); |
| 69 | |
| 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); |
| 74 | } |
| 75 | // add other primary displaying msg types here |
| 76 | else { |
| 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); |
| 82 | } else { |
| 83 | $body = _("No Message"); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | $type1 = $msg["ENTITIES"][$ent_num]["TYPE1"]; |
| 88 | |
| 89 | $body_ary = explode("\n", $body); |
| 90 | $body = ""; |
| 91 | for ($i=0;$i < count($body_ary);$i++) { |
| 92 | if ($type1 == "html") |
| 93 | $tmp = strip_tags($body_ary[$i]); |
| 94 | else |
| 95 | $tmp = $body_ary[$i]; |
| 96 | $body = "$body> $tmp\n"; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | $send_to = sqimap_find_displayable_name($send_to); |
| 101 | |
| 102 | $send_to = strtolower($send_to); |
| 103 | $send_to = ereg_replace("\"", "", $send_to); |
| 104 | $send_to = stripslashes($send_to); |
| 105 | |
| 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); |
| 110 | $send_to_cc = ""; |
| 111 | |
| 112 | for ($i = 0; $i < count($sendcc); $i++) { |
| 113 | $sendcc[$i] = trim($sendcc[$i]); |
| 114 | if ($sendcc[$i] == "") |
| 115 | continue; |
| 116 | |
| 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"]); |
| 120 | |
| 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]) . ", "; |
| 125 | } |
| 126 | } |
| 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); |
| 130 | } |
| 131 | } |
| 132 | } // function newMail() |
| 133 | |
| 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; |
| 138 | |
| 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"; |
| 142 | echo " <TR>\n"; |
| 143 | echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n"; |
| 144 | echo " <FONT FACE=\"Arial,Helvetica\">"; |
| 145 | echo _("To:"); |
| 146 | echo " </FONT>\n"; |
| 147 | echo " </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n"; |
| 148 | if ($send_to) |
| 149 | echo " <INPUT TYPE=TEXT NAME=send_to VALUE=\"$send_to\" SIZE=60><BR>"; |
| 150 | else |
| 151 | echo " <INPUT TYPE=TEXT NAME=send_to SIZE=60><BR>"; |
| 152 | echo " </TD>\n"; |
| 153 | echo " </TR>\n"; |
| 154 | echo " <TR>\n"; |
| 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"; |
| 158 | if ($send_to_cc) |
| 159 | echo " <INPUT TYPE=TEXT NAME=send_to_cc SIZE=60 VALUE=\"$send_to_cc\"><BR>"; |
| 160 | else |
| 161 | echo " <INPUT TYPE=TEXT NAME=send_to_cc SIZE=60><BR>"; |
| 162 | echo " </TD>\n"; |
| 163 | echo " </TR>\n"; |
| 164 | echo " <TR>\n"; |
| 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"; |
| 168 | if ($send_to_bcc) |
| 169 | echo " <INPUT TYPE=TEXT NAME=send_to_bcc VALUE=\"$send_to_bcc\" SIZE=60><BR>"; |
| 170 | else |
| 171 | echo " <INPUT TYPE=TEXT NAME=send_to_bcc SIZE=60><BR>"; |
| 172 | echo " </TD>\n"; |
| 173 | echo " </TR>\n"; |
| 174 | echo " <TR>\n"; |
| 175 | echo " <TD WIDTH=50 BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n"; |
| 176 | echo " <FONT FACE=\"Arial,Helvetica\">"; |
| 177 | echo _("Subject:"); |
| 178 | echo " </FONT>\n"; |
| 179 | echo " </TD><TD WIDTH=% BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n"; |
| 180 | if ($reply_subj) { |
| 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\">"; |
| 196 | } else { |
| 197 | echo " <INPUT TYPE=TEXT NAME=subject VALUE=\"$subject\" SIZE=50>"; |
| 198 | } |
| 199 | echo " <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">"; |
| 200 | echo " </TD>\n"; |
| 201 | echo " </TR>\n"; |
| 202 | |
| 203 | echo " <TR>\n"; |
| 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>"; |
| 207 | else |
| 208 | echo " <TEXTAREA NAME=body ROWS=20 COLS=\"$editor_size\" WRAP=HARD>".$body."</TEXTAREA><BR>\n"; |
| 209 | echo " </TD>\n"; |
| 210 | echo " </TR>\n"; |
| 211 | echo " <TR><TD COLSPAN=2 ALIGN=CENTER><INPUT TYPE=SUBMIT NAME=send VALUE=\""; |
| 212 | echo _("Send"); |
| 213 | echo "\"></TD></TR>\n"; |
| 214 | |
| 215 | // This code is for attachments |
| 216 | echo " <tr>\n"; |
| 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"; |
| 226 | echo " </td>\n"; |
| 227 | echo " </font>\n"; |
| 228 | echo " </tr>\n"; |
| 229 | if (isset($attachments) && count($attachments)>0) { |
| 230 | echo "</tr><tr><td width=50 bgcolor=\"$color[0]\" align=right>\n"; |
| 231 | echo " "; |
| 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"; |
| 236 | } |
| 237 | |
| 238 | echo "<input type=\"submit\" name=\"do_delete\" value=\""._("Delete selected attachments")."\">\n"; |
| 239 | echo "</td></tr>"; |
| 240 | } |
| 241 | // End of attachment code |
| 242 | |
| 243 | echo "</TABLE>\n"; |
| 244 | echo "</FORM>"; |
| 245 | } |
| 246 | |
| 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>"; |
| 252 | } |
| 253 | |
| 254 | function checkInput () { |
| 255 | global $body, $send_to, $subject; |
| 256 | |
| 257 | if ($body == "") { |
| 258 | plain_error_message(_("You have not entered a message body."), $color); |
| 259 | return false; |
| 260 | } else if ($send_to == "") { |
| 261 | displayPageHeader($color, "None"); |
| 262 | plain_error_message(_("You have not filled in the \"To:\" field."), $color); |
| 263 | return false; |
| 264 | } else if ($subject == "") { |
| 265 | plain_error_message(_("You have not entered a subject."), $color); |
| 266 | return false; |
| 267 | } |
| 268 | return true; |
| 269 | } // function checkInput() |
| 270 | |
| 271 | if(isset($send)) { |
| 272 | if (checkInput()) { |
| 273 | sendMessage($send_to, $send_to_cc, $send_to_bcc, $subject, $body); |
| 274 | showSentForm(); |
| 275 | } else { |
| 276 | showInputForm(); |
| 277 | } |
| 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; |
| 281 | |
| 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")); |
| 287 | $failed = true; |
| 288 | } |
| 289 | } |
| 290 | // If it still exists, PHP will remove the original file |
| 291 | |
| 292 | if (!$failed) { |
| 293 | // Write information about the file |
| 294 | $fp = fopen ($attachment_dir.$localfilename.".info", "w"); |
| 295 | fputs ($fp, "$attachfile_type\n$attachfile_name\n"); |
| 296 | fclose ($fp); |
| 297 | |
| 298 | $attachments[$localfilename] = $attachfile_name; |
| 299 | } |
| 300 | |
| 301 | showInputForm(); |
| 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"); |
| 307 | } |
| 308 | |
| 309 | showInputForm(); |
| 310 | } else { |
| 311 | Newmail(); |
| 312 | showInputForm(); |
| 313 | } |
| 314 | ?> |