| 1 | <?php |
| 2 | /** |
| 3 | ** compose.php |
| 4 | ** |
| 5 | ** Copyright (c) 1999-2000 The SquirrelMail development team |
| 6 | ** Licensed under the GNU GPL. For full terms see the file COPYING. |
| 7 | ** |
| 8 | ** This code sends a mail. |
| 9 | ** |
| 10 | ** There are 3 modes of operation: |
| 11 | ** - Start new mail |
| 12 | ** - Add an attachment |
| 13 | ** - Send mail |
| 14 | ** |
| 15 | ** $Id$ |
| 16 | **/ |
| 17 | |
| 18 | include('../src/validate.php'); |
| 19 | include("../functions/imap.php"); |
| 20 | include("../functions/date.php"); |
| 21 | include("../functions/mime.php"); |
| 22 | include("../functions/smtp.php"); |
| 23 | include("../functions/display_messages.php"); |
| 24 | include ("../functions/plugin.php"); |
| 25 | |
| 26 | if (!isset($attachments)) |
| 27 | { |
| 28 | $attachments = array(); |
| 29 | session_register('attachments'); |
| 30 | } |
| 31 | |
| 32 | |
| 33 | // This function is used when not sending or adding attachments |
| 34 | function newMail () { |
| 35 | global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body, |
| 36 | $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc, $editor_size; |
| 37 | |
| 38 | $send_to = decodeHeader($send_to); |
| 39 | $send_to_cc = decodeHeader($send_to_cc); |
| 40 | $send_to_bcc = decodeHeader($send_to_bcc); |
| 41 | |
| 42 | if ($forward_id) |
| 43 | $id = $forward_id; |
| 44 | elseif ($reply_id) |
| 45 | $id = $reply_id; |
| 46 | |
| 47 | |
| 48 | if (isset($id)) { |
| 49 | sqimap_mailbox_select($imapConnection, $mailbox); |
| 50 | $message = sqimap_get_message($imapConnection, $id, $mailbox); |
| 51 | $orig_header = $message->header; |
| 52 | if ($ent_num) |
| 53 | $message = getEntity($message, $ent_num); |
| 54 | |
| 55 | if ($message->header->type0 == "text" || $message->header->type1 == "message") { |
| 56 | if ($ent_num) |
| 57 | $body = decodeBody(mime_fetch_body($imapConnection, $id, $ent_num), $message->header->encoding); |
| 58 | else |
| 59 | $body = decodeBody(mime_fetch_body($imapConnection, $id, 1), $message->header->encoding); |
| 60 | } else { |
| 61 | $body = ""; |
| 62 | } |
| 63 | |
| 64 | if ($message->header->type1 == "html") |
| 65 | $body = strip_tags($body); |
| 66 | |
| 67 | sqUnWordWrap($body); |
| 68 | $body_ary = explode("\n", $body); |
| 69 | $i = count($body_ary) - 1; |
| 70 | while ($i >= 0 && ereg("^[>\\s]*$", $body_ary[$i])) { |
| 71 | unset($body_ary[$i]); |
| 72 | $i --; |
| 73 | } |
| 74 | $body = ""; |
| 75 | for ($i=0; isset($body_ary[$i]); $i++) { |
| 76 | if (! $forward_id) |
| 77 | { |
| 78 | if (ereg('^[ >]+', $body_ary[$i])) |
| 79 | { |
| 80 | $body_ary[$i] = '>' . $body_ary[$i]; |
| 81 | } |
| 82 | else |
| 83 | { |
| 84 | $body_ary[$i] = '> ' . $body_ary[$i]; |
| 85 | } |
| 86 | } |
| 87 | sqWordWrap($body_ary[$i], $editor_size - 1); |
| 88 | $body .= $body_ary[$i] . "\n"; |
| 89 | unset($body_ary[$i]); |
| 90 | } |
| 91 | if ($forward_id) |
| 92 | { |
| 93 | $bodyTop = "-------- " . _("Original Message") . " --------\n"; |
| 94 | $bodyTop .= _("Subject") . ": " . $orig_header->subject . "\n"; |
| 95 | $bodyTop .= _("From") . ": " . $orig_header->from . "\n"; |
| 96 | $bodyTop .= _("To") . ": " . $orig_header->to[0] . "\n"; |
| 97 | if (count($orig_header->to) > 1) { |
| 98 | for ($x=1; $x < count($orig_header->to); $x++) { |
| 99 | $bodyTop .= " " . $orig_header->to[$x] . "\n"; |
| 100 | } |
| 101 | } |
| 102 | $bodyTop .= "\n"; |
| 103 | $body = $bodyTop . $body; |
| 104 | } |
| 105 | |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | if (!$send_to) { |
| 110 | $send_to = sqimap_find_email($send_to); |
| 111 | } |
| 112 | |
| 113 | /** This formats a CC string if they hit "reply all" **/ |
| 114 | if ($send_to_cc != "") { |
| 115 | $send_to_cc = ereg_replace( '"[^"]*"', "", $send_to_cc); |
| 116 | $send_to_cc = ereg_replace(";", ",", $send_to_cc); |
| 117 | $sendcc = explode(",", $send_to_cc); |
| 118 | $send_to_cc = ""; |
| 119 | |
| 120 | for ($i = 0; $i < count($sendcc); $i++) { |
| 121 | $sendcc[$i] = trim($sendcc[$i]); |
| 122 | if ($sendcc[$i] == "") |
| 123 | continue; |
| 124 | |
| 125 | $sendcc[$i] = sqimap_find_email($sendcc[$i]); |
| 126 | $whofrom = sqimap_find_displayable_name($msg["HEADER"]["FROM"]); |
| 127 | $whoreplyto = sqimap_find_email($msg["HEADER"]["REPLYTO"]); |
| 128 | |
| 129 | if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) && |
| 130 | (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) && |
| 131 | (trim($sendcc[$i]) != "")) { |
| 132 | $send_to_cc .= trim($sendcc[$i]) . ", "; |
| 133 | } |
| 134 | } |
| 135 | $send_to_cc = trim($send_to_cc); |
| 136 | if (substr($send_to_cc, -1) == ",") { |
| 137 | $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1); |
| 138 | } |
| 139 | } |
| 140 | } // function newMail() |
| 141 | |
| 142 | function getAttachments($message) { |
| 143 | global $mailbox, $attachments, $attachment_dir, $imapConnection, |
| 144 | $ent_num, $forward_id; |
| 145 | |
| 146 | if (!$message) { |
| 147 | sqimap_mailbox_select($imapConnection, $mailbox); |
| 148 | $message = sqimap_get_message($imapConnection, $forward_id, |
| 149 | $mailbox); |
| 150 | } |
| 151 | |
| 152 | if (count($message->entities) == 0) { |
| 153 | if ($message->header->entity_id != $ent_num) { |
| 154 | $filename = decodeHeader($message->header->filename); |
| 155 | |
| 156 | if ($filename == "") |
| 157 | $filename = "untitled-".$message->header->entity_id; |
| 158 | |
| 159 | $localfilename = GenerateRandomString(32, '', 7); |
| 160 | while (file_exists($attachment_dir . $localfilename)) |
| 161 | $localfilename = GenerateRandomString(32, '', 7); |
| 162 | |
| 163 | $newAttachment = array(); |
| 164 | $newAttachment['localfilename'] = $localfilename; |
| 165 | $newAttachment['remotefilename'] = $filename; |
| 166 | $newAttachment['type'] = strtolower($message->header->type0 . |
| 167 | '/' . $message->header->type1); |
| 168 | |
| 169 | // Write Attachment to file |
| 170 | $fp = fopen ($attachment_dir.$localfilename, 'w'); |
| 171 | fputs ($fp, decodeBody(mime_fetch_body($imapConnection, |
| 172 | $forward_id, $message->header->entity_id), |
| 173 | $message->header->encoding)); |
| 174 | fclose ($fp); |
| 175 | |
| 176 | $attachments[] = $newAttachment; |
| 177 | } |
| 178 | } else { |
| 179 | for ($i = 0; $i < count($message->entities); $i++) { |
| 180 | getAttachments($message->entities[$i]); |
| 181 | } |
| 182 | } |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | function showInputForm () { |
| 187 | global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body, |
| 188 | $passed_body, $color, $use_signature, $signature, $prefix_sig, |
| 189 | $editor_size, $attachments, $subject, $newmail, |
| 190 | $use_javascript_addr_book, $send_to_bcc, $reply_id, $mailbox, |
| 191 | $from_htmladdr_search, $location_of_buttons, $attachment_dir, |
| 192 | $username, $data_dir, $identity; |
| 193 | |
| 194 | $subject = decodeHeader($subject); |
| 195 | $reply_subj = decodeHeader($reply_subj); |
| 196 | $forward_subj = decodeHeader($forward_subj); |
| 197 | |
| 198 | if ($use_javascript_addr_book) { |
| 199 | echo "\n<SCRIPT LANGUAGE=JavaScript><!--\n"; |
| 200 | echo "function open_abook() { \n"; |
| 201 | echo " var nwin = window.open(\"addrbook_popup.php\",\"abookpopup\","; |
| 202 | echo "\"width=670,height=300,resizable=yes,scrollbars=yes\");\n"; |
| 203 | echo " if((!nwin.opener) && (document.windows != null))\n"; |
| 204 | echo " nwin.opener = document.windows;\n"; |
| 205 | echo "}\n"; |
| 206 | echo "// --></SCRIPT>\n\n"; |
| 207 | } |
| 208 | |
| 209 | echo "\n<FORM name=compose action=\"compose.php\" METHOD=POST ENCTYPE=\"multipart/form-data\""; |
| 210 | do_hook("compose_form"); |
| 211 | echo ">\n"; |
| 212 | if ($reply_id) { |
| 213 | echo "<input type=hidden name=reply_id value=$reply_id>\n"; |
| 214 | } |
| 215 | printf("<INPUT TYPE=hidden NAME=mailbox VALUE=\"%s\">\n", htmlspecialchars($mailbox)); |
| 216 | echo "<TABLE WIDTH=\"100%\" ALIGN=center CELLSPACING=0 BORDER=0>\n"; |
| 217 | |
| 218 | if ($location_of_buttons == 'top') showComposeButtonRow(); |
| 219 | |
| 220 | $idents = getPref($data_dir, $username, 'identities'); |
| 221 | if ($idents != '' && $idents > 1) |
| 222 | { |
| 223 | echo " <TR>\n"; |
| 224 | echo " <TD BGCOLOR=\"$color[4]\" WIDTH=\"10%\" ALIGN=RIGHT>\n"; |
| 225 | echo _("From:"); |
| 226 | echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=\"90%\">\n"; |
| 227 | echo "<select name=identity>\n"; |
| 228 | echo "<option value=default>" . |
| 229 | htmlspecialchars(getPref($data_dir, $username, 'full_name')); |
| 230 | $em = getPref($data_dir, $username, 'email_address'); |
| 231 | if ($em != '') |
| 232 | echo htmlspecialchars(' <' . $em . '>') . "\n"; |
| 233 | for ($i = 1; $i < $idents; $i ++) { |
| 234 | echo '<option value="' . $i . '"'; |
| 235 | if (isset($identity) && $identity == $i) |
| 236 | echo ' SELECTED'; |
| 237 | echo '>'; |
| 238 | echo htmlspecialchars(getPref($data_dir, $username, 'full_name' . |
| 239 | $i)); |
| 240 | $em = getPref($data_dir, $username, 'email_address' . $i); |
| 241 | if ($em != '') |
| 242 | echo htmlspecialchars(' <' . $em . '>') . "\n"; |
| 243 | } |
| 244 | echo "</select>\n"; |
| 245 | echo " </TD>\n"; |
| 246 | echo " </TR>\n"; |
| 247 | } |
| 248 | echo " <TR>\n"; |
| 249 | echo " <TD BGCOLOR=\"$color[4]\" WIDTH=\"10%\" ALIGN=RIGHT>\n"; |
| 250 | echo _("To:"); |
| 251 | echo " </TD><TD BGCOLOR=\"$color[4]\" WIDTH=\"90%\">\n"; |
| 252 | printf(" <INPUT TYPE=text NAME=\"send_to\" VALUE=\"%s\" SIZE=60><BR>\n", |
| 253 | htmlspecialchars($send_to)); |
| 254 | echo " </TD>\n"; |
| 255 | echo " </TR>\n"; |
| 256 | echo " <TR>\n"; |
| 257 | echo " <TD BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n"; |
| 258 | echo _("CC:"); |
| 259 | echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n"; |
| 260 | printf(" <INPUT TYPE=text NAME=\"send_to_cc\" SIZE=60 VALUE=\"%s\"><BR>\n", |
| 261 | htmlspecialchars($send_to_cc)); |
| 262 | echo " </TD>\n"; |
| 263 | echo " </TR>\n"; |
| 264 | echo " <TR>\n"; |
| 265 | echo " <TD BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n"; |
| 266 | echo _("BCC:"); |
| 267 | echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n"; |
| 268 | printf(" <INPUT TYPE=text NAME=\"send_to_bcc\" VALUE=\"%s\" SIZE=60><BR>\n", |
| 269 | htmlspecialchars($send_to_bcc)); |
| 270 | echo "</TD></TR>\n"; |
| 271 | |
| 272 | echo " <TR>\n"; |
| 273 | echo " <TD BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n"; |
| 274 | echo _("Subject:"); |
| 275 | echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n"; |
| 276 | if ($reply_subj) { |
| 277 | $reply_subj = str_replace("\"", "'", $reply_subj); |
| 278 | $reply_subj = trim($reply_subj); |
| 279 | if (substr(strtolower($reply_subj), 0, 3) != "re:") |
| 280 | $reply_subj = "Re: $reply_subj"; |
| 281 | printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">", |
| 282 | htmlspecialchars($reply_subj)); |
| 283 | } else if ($forward_subj) { |
| 284 | $forward_subj = trim($forward_subj); |
| 285 | if ((substr(strtolower($forward_subj), 0, 4) != 'fwd:') && |
| 286 | (substr(strtolower($forward_subj), 0, 5) != '[fwd:') && |
| 287 | (substr(strtolower($forward_subj), 0, 6) != '[ fwd:')) |
| 288 | $forward_subj = "[Fwd: $forward_subj]"; |
| 289 | printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">", |
| 290 | htmlspecialchars($forward_subj)); |
| 291 | } else { |
| 292 | printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">", |
| 293 | htmlspecialchars($subject)); |
| 294 | } |
| 295 | echo "</td></tr>\n\n"; |
| 296 | |
| 297 | if ($location_of_buttons == 'between') showComposeButtonRow(); |
| 298 | |
| 299 | echo " <TR>\n"; |
| 300 | echo " <TD BGCOLOR=\"$color[4]\" COLSPAN=2>\n"; |
| 301 | echo " <TEXTAREA NAME=body ROWS=20 COLS=\"$editor_size\" WRAP=HARD>"; |
| 302 | echo htmlspecialchars($body); |
| 303 | if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) { |
| 304 | if ( $prefix_sig == true ) |
| 305 | echo "\n\n-- \n" . htmlspecialchars($signature); |
| 306 | else |
| 307 | echo "\n\n" . htmlspecialchars($signature); |
| 308 | } |
| 309 | echo "</TEXTAREA><BR>\n"; |
| 310 | echo " </TD>\n"; |
| 311 | echo " </TR>\n"; |
| 312 | |
| 313 | if ($location_of_buttons == 'bottom') |
| 314 | showComposeButtonRow(); |
| 315 | else { |
| 316 | echo " <TR><TD> </TD><TD ALIGN=LEFT><INPUT TYPE=SUBMIT NAME=send VALUE=\""._("Send")."\"></TD></TR>\n"; |
| 317 | } |
| 318 | |
| 319 | // This code is for attachments |
| 320 | echo " <tr>\n"; |
| 321 | echo " <TD BGCOLOR=\"$color[0]\" VALIGN=TOP ALIGN=RIGHT>\n"; |
| 322 | echo " <SMALL><BR></SMALL>"._("Attach:"); |
| 323 | echo " </td><td ALIGN=left BGCOLOR=\"$color[0]\">\n"; |
| 324 | echo " <INPUT NAME=\"attachfile\" SIZE=48 TYPE=\"file\">\n"; |
| 325 | echo " <input type=\"submit\" name=\"attach\""; |
| 326 | echo " value=\"" . _("Add") ."\">\n"; |
| 327 | echo " </td>\n"; |
| 328 | echo " </tr>\n"; |
| 329 | if (count($attachments)) |
| 330 | { |
| 331 | echo "<tr><td bgcolor=\"$color[0]\" align=right>\n"; |
| 332 | echo " "; |
| 333 | echo "</td><td align=left bgcolor=\"$color[0]\">"; |
| 334 | foreach ($attachments as $key => $info) { |
| 335 | echo "<input type=\"checkbox\" name=\"delete[]\" value=\"$key\">\n"; |
| 336 | echo $info['remotefilename'] . " - " . $info['type'] . " ("; |
| 337 | echo show_readable_size(filesize($attachment_dir . |
| 338 | $info['localfilename'])) . ")<br>\n"; |
| 339 | } |
| 340 | |
| 341 | echo "<input type=\"submit\" name=\"do_delete\" value=\""._("Delete selected attachments")."\">\n"; |
| 342 | echo "</td></tr>"; |
| 343 | } |
| 344 | // End of attachment code |
| 345 | |
| 346 | echo "</TABLE>\n"; |
| 347 | echo "</FORM>"; |
| 348 | do_hook("compose_bottom"); |
| 349 | } |
| 350 | |
| 351 | function showComposeButtonRow() { |
| 352 | global $use_javascript_addr_book; |
| 353 | |
| 354 | echo " <TR><td>\n </td><td>\n"; |
| 355 | if ($use_javascript_addr_book) { |
| 356 | echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\""; |
| 357 | echo " <input type=button value=\\\""._("Addresses")."\\\" onclick='javascript:open_abook();'>\");"; |
| 358 | echo " // --></SCRIPT><NOSCRIPT>\n"; |
| 359 | echo " <input type=submit name=\"html_addr_search\" value=\""._("Addresses")."\">"; |
| 360 | echo " </NOSCRIPT>\n"; |
| 361 | } else { |
| 362 | echo " <input type=submit name=\"html_addr_search\" value=\""._("Addresses")."\">"; |
| 363 | } |
| 364 | echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n"; |
| 365 | |
| 366 | do_hook("compose_button_row"); |
| 367 | |
| 368 | echo " </TD>\n"; |
| 369 | echo " </TR>\n\n"; |
| 370 | } |
| 371 | |
| 372 | function checkInput ($show) { |
| 373 | /** I implemented the $show variable because the error messages |
| 374 | were getting sent before the page header. So, I check once |
| 375 | using $show=false, and then when i'm ready to display the |
| 376 | error message, show=true **/ |
| 377 | global $body, $send_to, $subject, $color; |
| 378 | |
| 379 | if ($send_to == "") { |
| 380 | if ($show) |
| 381 | plain_error_message(_("You have not filled in the \"To:\" field."), $color); |
| 382 | return false; |
| 383 | } |
| 384 | return true; |
| 385 | } // function checkInput() |
| 386 | |
| 387 | |
| 388 | // True if FAILURE |
| 389 | function saveAttachedFiles() { |
| 390 | global $HTTP_POST_FILES, $attachment_dir, $attachments; |
| 391 | |
| 392 | $localfilename = GenerateRandomString(32, '', 7); |
| 393 | while (file_exists($attachment_dir . $localfilename)) |
| 394 | $localfilename = GenerateRandomString(32, '', 7); |
| 395 | |
| 396 | if (!@rename($HTTP_POST_FILES['attachfile']['tmp_name'], $attachment_dir.$localfilename)) { |
| 397 | if (!@copy($HTTP_POST_FILES['attachfile']['tmp_name'], $attachment_dir.$localfilename)) { |
| 398 | return true; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | $newAttachment['localfilename'] = $localfilename; |
| 403 | $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name']; |
| 404 | $newAttachment['type'] = |
| 405 | strtolower($HTTP_POST_FILES['attachfile']['type']); |
| 406 | |
| 407 | $attachments[] = $newAttachment; |
| 408 | } |
| 409 | |
| 410 | if (!isset($mailbox) || $mailbox == "" || ($mailbox == "None")) |
| 411 | $mailbox = "INBOX"; |
| 412 | |
| 413 | if (isset($send)) { |
| 414 | if (isset($HTTP_POST_FILES['attachfile']) && |
| 415 | $HTTP_POST_FILES['attachfile']['tmp_name'] && |
| 416 | $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') |
| 417 | $AttachFailure = saveAttachedFiles(); |
| 418 | if (checkInput(false) && !isset($AttachFailure)) { |
| 419 | $urlMailbox = urlencode (trim($mailbox)); |
| 420 | if (! isset($reply_id)) |
| 421 | $reply_id = 0; |
| 422 | // Set $default_charset to correspond with the user's selection |
| 423 | // of language interface. |
| 424 | set_my_charset(); |
| 425 | |
| 426 | // This is to change all newlines to \n |
| 427 | // We'll change them to \r\n later (in the sendMessage function) |
| 428 | $body = str_replace("\r\n", "\n", $body); |
| 429 | $body = str_replace("\r", "\n", $body); |
| 430 | |
| 431 | // Rewrap $body so that no line is bigger than $editor_size |
| 432 | // This should only really kick in the sqWordWrap function |
| 433 | // if the browser doesn't support "HARD" as the wrap type |
| 434 | $body = explode("\n", $body); |
| 435 | $newBody = ''; |
| 436 | foreach ($body as $line) { |
| 437 | $line = trim($line); |
| 438 | if (strlen($line) <= $editor_size) |
| 439 | $newBody .= $line . "\n"; |
| 440 | else { |
| 441 | sqWordWrap($line, $editor_size) . "\n"; |
| 442 | $newBody .= $line; |
| 443 | } |
| 444 | } |
| 445 | $body = $newBody; |
| 446 | |
| 447 | do_hook("compose_send"); |
| 448 | |
| 449 | if (! sendMessage($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id)) { |
| 450 | showInputForm(); |
| 451 | exit(); |
| 452 | } |
| 453 | Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort&startMessage=1"); |
| 454 | } else { |
| 455 | //$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
| 456 | displayPageHeader($color, $mailbox); |
| 457 | |
| 458 | if (isset($AttachFailure)) |
| 459 | plain_error_message(_("Could not move/copy file. File not attached"), $color); |
| 460 | |
| 461 | checkInput(true); |
| 462 | |
| 463 | showInputForm(); |
| 464 | //sqimap_logout($imapConnection); |
| 465 | } |
| 466 | } else if (isset($html_addr_search_done)) { |
| 467 | displayPageHeader($color, $mailbox); |
| 468 | |
| 469 | if (isset($send_to_search) && is_array($send_to_search)) { |
| 470 | foreach ($send_to_search as $k => $v) { |
| 471 | if (substr($k, 0, 1) == 'T') { |
| 472 | if ($send_to) |
| 473 | $send_to .= ', '; |
| 474 | $send_to .= $v; |
| 475 | } |
| 476 | elseif (substr($k, 0, 1) == 'C') { |
| 477 | if ($send_to_cc) |
| 478 | $send_to_cc .= ', '; |
| 479 | $send_to_cc .= $v; |
| 480 | } |
| 481 | elseif (substr($k, 0, 1) == 'B') { |
| 482 | if ($send_to_bcc) |
| 483 | $send_to_bcc .= ', '; |
| 484 | $send_to_bcc .= $v; |
| 485 | } |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | showInputForm(); |
| 490 | } else if (isset($html_addr_search)) { |
| 491 | if (isset($HTTP_POST_FILES['attachfile']) && |
| 492 | $HTTP_POST_FILES['attachfile']['tmp_name'] && |
| 493 | $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') |
| 494 | { |
| 495 | if (saveAttachedFiles()) |
| 496 | plain_error_message(_("Could not move/copy file. File not attached"), $color); |
| 497 | } |
| 498 | // I am using an include so as to elminiate an extra unnecessary click. If you |
| 499 | // can think of a better way, please implement it. |
| 500 | include ("./addrbook_search_html.php"); |
| 501 | } else if (isset($attach)) { |
| 502 | if (saveAttachedFiles()) |
| 503 | plain_error_message(_("Could not move/copy file. File not attached"), $color); |
| 504 | displayPageHeader($color, $mailbox); |
| 505 | showInputForm(); |
| 506 | } else if (isset($do_delete)) { |
| 507 | displayPageHeader($color, $mailbox); |
| 508 | |
| 509 | if (isset($delete) && is_array($delete)) |
| 510 | { |
| 511 | foreach($delete as $index) |
| 512 | { |
| 513 | unlink ($attachment_dir.$attachments[$index]['localfilename']); |
| 514 | unset ($attachments[$index]); |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | showInputForm(); |
| 519 | } else { |
| 520 | // This handles the default case as well as the error case |
| 521 | // (they had the same code) --> if (isset($smtpErrors)) |
| 522 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, |
| 523 | $imapPort, 0); |
| 524 | displayPageHeader($color, $mailbox); |
| 525 | |
| 526 | $newmail = true; |
| 527 | |
| 528 | ClearAttachments(); |
| 529 | |
| 530 | if (isset($forward_id) && $forward_id && isset($ent_num) && $ent_num) |
| 531 | getAttachments(0); |
| 532 | |
| 533 | newMail(); |
| 534 | showInputForm(); |
| 535 | sqimap_logout($imapConnection); |
| 536 | } |
| 537 | |
| 538 | |
| 539 | |
| 540 | |
| 541 | function ClearAttachments() { |
| 542 | global $attachments, $attachment_dir; |
| 543 | |
| 544 | foreach ($attachments as $info) { |
| 545 | if (file_exists($attachment_dir . $info['localfilename'])) { |
| 546 | unlink($attachment_dir . $info['localfilename']); |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | $attachments = array(); |
| 551 | } |
| 552 | |
| 553 | ?> |