| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * compose.php |
| 5 | * |
| 6 | * Copyright (c) 1999-2002 The SquirrelMail Project Team |
| 7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
| 8 | * |
| 9 | * This code sends a mail. |
| 10 | * |
| 11 | * There are 4 modes of operation: |
| 12 | * - Start new mail |
| 13 | * - Add an attachment |
| 14 | * - Send mail |
| 15 | * - Save As Draft |
| 16 | * |
| 17 | * $Id$ |
| 18 | */ |
| 19 | |
| 20 | require_once('../src/validate.php'); |
| 21 | require_once('../functions/imap.php'); |
| 22 | require_once('../functions/date.php'); |
| 23 | require_once('../functions/mime.php'); |
| 24 | require_once('../functions/smtp.php'); |
| 25 | require_once('../functions/display_messages.php'); |
| 26 | require_once('../functions/plugin.php'); |
| 27 | |
| 28 | if (!isset($attachments)) { |
| 29 | $attachments = array(); |
| 30 | session_register('attachments'); |
| 31 | } |
| 32 | |
| 33 | if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None')) { |
| 34 | $mailbox = 'INBOX'; |
| 35 | } |
| 36 | |
| 37 | if (isset($draft)) { |
| 38 | require_once ('../src/draft_actions.php'); |
| 39 | if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id)) { |
| 40 | showInputForm(); |
| 41 | exit(); |
| 42 | } else { |
| 43 | $draft_message = _("Draft Email Saved"); |
| 44 | /* If this is a resumed draft, then delete the original */ |
| 45 | if(isset($delete_draft)) { |
| 46 | Header("Location: delete_message.php?mailbox=$draft_folder". |
| 47 | "&message=$delete_draft&sort=$sort&startMessage=1"); |
| 48 | exit(); |
| 49 | } else { |
| 50 | Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort". |
| 51 | "&startMessage=1¬e=$draft_message"); |
| 52 | exit(); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | if (isset($send)) { |
| 58 | if (isset($HTTP_POST_FILES['attachfile']) && |
| 59 | $HTTP_POST_FILES['attachfile']['tmp_name'] && |
| 60 | $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') { |
| 61 | $AttachFailure = saveAttachedFiles(); |
| 62 | } |
| 63 | if (checkInput(false) && !isset($AttachFailure)) { |
| 64 | $urlMailbox = urlencode (trim($mailbox)); |
| 65 | if (! isset($reply_id)) { |
| 66 | $reply_id = 0; |
| 67 | } |
| 68 | /* |
| 69 | * Set $default_charset to correspond with the user's selection |
| 70 | * of language interface. |
| 71 | */ |
| 72 | set_my_charset(); |
| 73 | |
| 74 | /* |
| 75 | * This is to change all newlines to \n |
| 76 | * We'll change them to \r\n later (in the sendMessage function) |
| 77 | */ |
| 78 | $body = str_replace("\r\n", "\n", $body); |
| 79 | $body = str_replace("\r", "\n", $body); |
| 80 | |
| 81 | /* |
| 82 | * Rewrap $body so that no line is bigger than $editor_size |
| 83 | * This should only really kick in the sqWordWrap function |
| 84 | * if the browser doesn't support "HARD" as the wrap type |
| 85 | * Or, in Opera's case, something goes wrong. |
| 86 | */ |
| 87 | $body = explode("\n", $body); |
| 88 | $newBody = ''; |
| 89 | foreach ($body as $line) { |
| 90 | if( $line <> '-- ' ) { |
| 91 | $line = rtrim($line); |
| 92 | } |
| 93 | if (strlen($line) <= $editor_size + 1) { |
| 94 | $newBody .= $line . "\n"; |
| 95 | } else { |
| 96 | sqWordWrap($line, $editor_size) . "\n"; |
| 97 | $newBody .= $line; |
| 98 | } |
| 99 | } |
| 100 | $body = $newBody; |
| 101 | |
| 102 | do_hook("compose_send"); |
| 103 | |
| 104 | if (! isset($mailprio)) { |
| 105 | $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc, |
| 106 | $subject, $body, $reply_id); |
| 107 | } else { |
| 108 | $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc, |
| 109 | $subject, $body, $reply_id, $mailprio); |
| 110 | } |
| 111 | if (! $Result) { |
| 112 | showInputForm(); |
| 113 | exit(); |
| 114 | } |
| 115 | if ( isset($delete_draft)) { |
| 116 | Header("Location: delete_message.php?mailbox=$draft_folder". |
| 117 | "&message=$delete_draft&sort=$sort&startMessage=1"); |
| 118 | exit(); |
| 119 | } |
| 120 | |
| 121 | Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort". |
| 122 | "&startMessage=1"); |
| 123 | } else { |
| 124 | /* |
| 125 | *$imapConnection = sqimap_login($username, $key, $imapServerAddress, |
| 126 | * $imapPort, 0); |
| 127 | */ |
| 128 | displayPageHeader($color, $mailbox); |
| 129 | |
| 130 | if (isset($AttachFailure)) { |
| 131 | plain_error_message(_("Could not move/copy file. File not attached"), |
| 132 | $color); |
| 133 | } |
| 134 | |
| 135 | checkInput(true); |
| 136 | showInputForm(); |
| 137 | /* sqimap_logout($imapConnection); */ |
| 138 | } |
| 139 | } |
| 140 | elseif (isset($html_addr_search_done)) { |
| 141 | displayPageHeader($color, $mailbox); |
| 142 | |
| 143 | if (isset($send_to_search) && is_array($send_to_search)) { |
| 144 | foreach ($send_to_search as $k => $v) { |
| 145 | if (substr($k, 0, 1) == 'T') { |
| 146 | if ($send_to) { |
| 147 | $send_to .= ', '; |
| 148 | } |
| 149 | $send_to .= $v; |
| 150 | } |
| 151 | elseif (substr($k, 0, 1) == 'C') { |
| 152 | if ($send_to_cc) { |
| 153 | $send_to_cc .= ', '; |
| 154 | } |
| 155 | $send_to_cc .= $v; |
| 156 | } |
| 157 | elseif (substr($k, 0, 1) == 'B') { |
| 158 | if ($send_to_bcc) { |
| 159 | $send_to_bcc .= ', '; |
| 160 | } |
| 161 | $send_to_bcc .= $v; |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | showInputForm(); |
| 166 | } |
| 167 | elseif (isset($html_addr_search)) { |
| 168 | if (isset($HTTP_POST_FILES['attachfile']) && |
| 169 | $HTTP_POST_FILES['attachfile']['tmp_name'] && |
| 170 | $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') { |
| 171 | if (saveAttachedFiles()) { |
| 172 | plain_error_message(_("Could not move/copy file. File not attached"), $color); |
| 173 | } |
| 174 | } |
| 175 | /* |
| 176 | * I am using an include so as to elminiate an extra unnecessary |
| 177 | * click. If you can think of a better way, please implement it. |
| 178 | */ |
| 179 | include_once('./addrbook_search_html.php'); |
| 180 | } |
| 181 | elseif (isset($attach)) { |
| 182 | if (saveAttachedFiles()) { |
| 183 | plain_error_message(_("Could not move/copy file. File not attached"), $color); |
| 184 | } |
| 185 | displayPageHeader($color, $mailbox); |
| 186 | showInputForm(); |
| 187 | } |
| 188 | elseif (isset($do_delete)) { |
| 189 | displayPageHeader($color, $mailbox); |
| 190 | |
| 191 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
| 192 | if (isset($delete) && is_array($delete)) { |
| 193 | foreach($delete as $index) { |
| 194 | $attached_file = $hashed_attachment_dir . '/' |
| 195 | . $attachments[$index]['localfilename']; |
| 196 | unlink ($attached_file); |
| 197 | unset ($attachments[$index]); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | showInputForm(); |
| 202 | } else { |
| 203 | /* |
| 204 | * This handles the default case as well as the error case |
| 205 | * (they had the same code) --> if (isset($smtpErrors)) |
| 206 | */ |
| 207 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, |
| 208 | $imapPort, 0); |
| 209 | displayPageHeader($color, $mailbox); |
| 210 | |
| 211 | $newmail = true; |
| 212 | |
| 213 | ClearAttachments(); |
| 214 | |
| 215 | if (isset($forward_id) && $forward_id && isset($ent_num) && $ent_num) { |
| 216 | getAttachments(0); |
| 217 | } |
| 218 | |
| 219 | if (isset($draft_id) && $draft_id && isset($ent_num) && $ent_num) { |
| 220 | getAttachments(0); |
| 221 | } |
| 222 | |
| 223 | newMail(); |
| 224 | showInputForm(); |
| 225 | sqimap_logout($imapConnection); |
| 226 | } |
| 227 | |
| 228 | exit(); |
| 229 | |
| 230 | |
| 231 | /**************** Only function definitions go below *************/ |
| 232 | |
| 233 | |
| 234 | /* This function is used when not sending or adding attachments */ |
| 235 | function newMail () { |
| 236 | global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body, |
| 237 | $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc, $editor_size, |
| 238 | $draft_id, $use_signature; |
| 239 | |
| 240 | $send_to = decodeHeader($send_to); |
| 241 | $send_to_cc = decodeHeader($send_to_cc); |
| 242 | $send_to_bcc = decodeHeader($send_to_bcc); |
| 243 | |
| 244 | if ($forward_id) { |
| 245 | $id = $forward_id; |
| 246 | } elseif ($reply_id) { |
| 247 | $id = $reply_id; |
| 248 | } |
| 249 | |
| 250 | if ($draft_id){ |
| 251 | $id = $draft_id; |
| 252 | $use_signature = FALSE; |
| 253 | } |
| 254 | |
| 255 | if (isset($id)) { |
| 256 | sqimap_mailbox_select($imapConnection, $mailbox); |
| 257 | $message = sqimap_get_message($imapConnection, $id, $mailbox); |
| 258 | $orig_header = $message->header; |
| 259 | if ($ent_num) { |
| 260 | $message = getEntity($message, $ent_num); |
| 261 | } |
| 262 | if ($message->header->type0 == 'text' || |
| 263 | $message->header->type1 == 'message') { |
| 264 | if ($ent_num) { |
| 265 | $body = decodeBody( |
| 266 | mime_fetch_body($imapConnection, $id, $ent_num), |
| 267 | $message->header->encoding); |
| 268 | } else { |
| 269 | $body = decodeBody( |
| 270 | mime_fetch_body($imapConnection, $id, 1), |
| 271 | $message->header->encoding); |
| 272 | } |
| 273 | } else { |
| 274 | $body = ''; |
| 275 | } |
| 276 | |
| 277 | if ($message->header->type1 == 'html') { |
| 278 | $body = strip_tags($body); |
| 279 | } |
| 280 | |
| 281 | sqUnWordWrap($body); |
| 282 | $body_ary = explode("\n", $body); |
| 283 | $i = count($body_ary) - 1; |
| 284 | while ($i >= 0 && ereg("^[>\\s]*$", $body_ary[$i])) { |
| 285 | unset($body_ary[$i]); |
| 286 | $i --; |
| 287 | } |
| 288 | $body = ''; |
| 289 | for ($i=0; isset($body_ary[$i]); $i++) { |
| 290 | if ($reply_id) { |
| 291 | if (ereg('^[ >]+', $body_ary[$i])) { |
| 292 | $body_ary[$i] = '>' . $body_ary[$i]; |
| 293 | } else { |
| 294 | $body_ary[$i] = '> ' . $body_ary[$i]; |
| 295 | } |
| 296 | } |
| 297 | if (!$draft_id) { |
| 298 | sqWordWrap($body_ary[$i], $editor_size - 1); |
| 299 | } |
| 300 | $body .= $body_ary[$i] . "\n"; |
| 301 | unset($body_ary[$i]); |
| 302 | } |
| 303 | if ($forward_id) { |
| 304 | $bodyTop = '-------- ' . _("Original Message") . " --------\n" . |
| 305 | _("Subject") . ': ' . $orig_header->subject . "\n" . |
| 306 | _("From") . ': ' . $orig_header->from . "\n" . |
| 307 | _("Date") . ': ' . |
| 308 | getLongDateString( $orig_header->date ). "\n" . |
| 309 | _("To") . ': ' . $orig_header->to[0] . "\n"; |
| 310 | if (count($orig_header->to) > 1) { |
| 311 | for ($x=1; $x < count($orig_header->to); $x++) { |
| 312 | $bodyTop .= ' ' . $orig_header->to[$x] . "\n"; |
| 313 | } |
| 314 | } |
| 315 | $bodyTop .= "\n"; |
| 316 | $body = $bodyTop . $body; |
| 317 | } |
| 318 | elseif ($reply_id) { |
| 319 | $orig_from = decodeHeader($orig_header->from); |
| 320 | $body = getReplyCitation($orig_from) . $body; |
| 321 | } |
| 322 | |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | if (!$send_to) { |
| 327 | $send_to = sqimap_find_email($send_to); |
| 328 | } |
| 329 | |
| 330 | /* This formats a CC string if they hit "reply all" */ |
| 331 | if ($send_to_cc != '') { |
| 332 | $send_to_cc = ereg_replace('"[^"]*"', '', $send_to_cc); |
| 333 | $send_to_cc = ereg_replace(';', ',', $send_to_cc); |
| 334 | $sendcc = explode(',', $send_to_cc); |
| 335 | $send_to_cc = ''; |
| 336 | |
| 337 | for ($i = 0; $i < count($sendcc); $i++) { |
| 338 | $sendcc[$i] = trim($sendcc[$i]); |
| 339 | if ($sendcc[$i] == '') { |
| 340 | continue; |
| 341 | } |
| 342 | |
| 343 | $sendcc[$i] = sqimap_find_email($sendcc[$i]); |
| 344 | $whofrom = sqimap_find_displayable_name($msg['HEADER']['FROM']); |
| 345 | $whoreplyto = sqimap_find_email($msg['HEADER']['REPLYTO']); |
| 346 | |
| 347 | if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) && |
| 348 | (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) && |
| 349 | (trim($sendcc[$i]) != '')) { |
| 350 | $send_to_cc .= trim($sendcc[$i]) . ', '; |
| 351 | } |
| 352 | } |
| 353 | $send_to_cc = trim($send_to_cc); |
| 354 | if (substr($send_to_cc, -1) == ',') { |
| 355 | $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1); |
| 356 | } |
| 357 | } |
| 358 | } /* function newMail() */ |
| 359 | |
| 360 | |
| 361 | function getAttachments($message) { |
| 362 | global $mailbox, $attachments, $attachment_dir, $imapConnection, |
| 363 | $ent_num, $forward_id, $draft_id, $username; |
| 364 | |
| 365 | if (isset($draft_id)) { |
| 366 | $id = $draft_id; |
| 367 | } else { |
| 368 | $id = $forward_id; |
| 369 | } |
| 370 | |
| 371 | if (!$message) { |
| 372 | sqimap_mailbox_select($imapConnection, $mailbox); |
| 373 | $message = sqimap_get_message($imapConnection, $id, $mailbox); |
| 374 | } |
| 375 | |
| 376 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
| 377 | if (count($message->entities) == 0) { |
| 378 | if ($message->header->entity_id != $ent_num) { |
| 379 | $filename = decodeHeader($message->header->filename); |
| 380 | |
| 381 | if ($filename == "") { |
| 382 | $filename = "untitled-".$message->header->entity_id; |
| 383 | } |
| 384 | |
| 385 | $localfilename = GenerateRandomString(32, '', 7); |
| 386 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
| 387 | while (file_exists($full_localfilename)) { |
| 388 | $localfilename = GenerateRandomString(32, '', 7); |
| 389 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
| 390 | } |
| 391 | |
| 392 | $newAttachment = array(); |
| 393 | $newAttachment['localfilename'] = $localfilename; |
| 394 | $newAttachment['remotefilename'] = $filename; |
| 395 | $newAttachment['type'] = strtolower($message->header->type0 . |
| 396 | '/' . $message->header->type1); |
| 397 | |
| 398 | /* Write Attachment to file */ |
| 399 | $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w'); |
| 400 | fputs($fp, decodeBody(mime_fetch_body($imapConnection, |
| 401 | $id, $message->header->entity_id), |
| 402 | $message->header->encoding)); |
| 403 | fclose ($fp); |
| 404 | |
| 405 | $attachments[] = $newAttachment; |
| 406 | } |
| 407 | } else { |
| 408 | for ($i = 0; $i < count($message->entities); $i++) { |
| 409 | getAttachments($message->entities[$i]); |
| 410 | } |
| 411 | } |
| 412 | return; |
| 413 | } |
| 414 | |
| 415 | function showInputForm () { |
| 416 | global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body, |
| 417 | $passed_body, $color, $use_signature, $signature, $prefix_sig, |
| 418 | $editor_size, $attachments, $subject, $newmail, |
| 419 | $use_javascript_addr_book, $send_to_bcc, $reply_id, $mailbox, |
| 420 | $from_htmladdr_search, $location_of_buttons, $attachment_dir, |
| 421 | $username, $data_dir, $identity, $draft_id, $delete_draft, |
| 422 | $mailprio; |
| 423 | |
| 424 | $subject = decodeHeader($subject); |
| 425 | $reply_subj = decodeHeader($reply_subj); |
| 426 | $forward_subj = decodeHeader($forward_subj); |
| 427 | |
| 428 | if ($use_javascript_addr_book) { |
| 429 | echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" . |
| 430 | 'function open_abook() { ' . "\n" . |
| 431 | ' var nwin = window.open("addrbook_popup.php","abookpopup",' . |
| 432 | '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" . |
| 433 | ' if((!nwin.opener) && (document.windows != null))' . "\n" . |
| 434 | ' nwin.opener = document.windows;' . "\n" . |
| 435 | "}\n" . |
| 436 | '// --></SCRIPT>' . "\n\n"; |
| 437 | } |
| 438 | |
| 439 | echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' . |
| 440 | 'ENCTYPE="multipart/form-data"'; |
| 441 | do_hook("compose_form"); |
| 442 | echo ">\n"; |
| 443 | |
| 444 | if (isset($draft_id)) { |
| 445 | echo '<input type="hidden" name="delete_draft" value="' . $draft_id . "\">\n"; |
| 446 | } |
| 447 | if (isset($delete_draft)) { |
| 448 | echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n"; |
| 449 | } |
| 450 | |
| 451 | echo '<TABLE WIDTH="100%" ALIGN=center CELLSPACING=0 BORDER=0>' . "\n"; |
| 452 | |
| 453 | if ($location_of_buttons == 'top') { |
| 454 | showComposeButtonRow(); |
| 455 | } |
| 456 | |
| 457 | $idents = getPref($data_dir, $username, 'identities'); |
| 458 | if ($idents != '' && $idents > 1) { |
| 459 | echo ' <TR>' . "\n" . |
| 460 | ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . |
| 461 | "\n" . |
| 462 | _("From:") . |
| 463 | ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" . |
| 464 | '<select name=identity>' . "\n" . |
| 465 | '<option value=default>' . |
| 466 | htmlspecialchars(getPref($data_dir, $username, 'full_name')); |
| 467 | $em = getPref($data_dir, $username, 'email_address'); |
| 468 | if ($em != '') { |
| 469 | echo htmlspecialchars(' <' . $em . '>') . "\n"; |
| 470 | } |
| 471 | for ($i = 1; $i < $idents; $i ++) { |
| 472 | echo '<option value="' . $i . '"'; |
| 473 | if (isset($identity) && $identity == $i) { |
| 474 | echo ' SELECTED'; |
| 475 | } |
| 476 | echo '>' . htmlspecialchars(getPref($data_dir, $username, |
| 477 | 'full_name' . $i)); |
| 478 | $em = getPref($data_dir, $username, 'email_address' . $i); |
| 479 | if ($em != '') { |
| 480 | echo htmlspecialchars(' <' . $em . '>') . "\n"; |
| 481 | } |
| 482 | } |
| 483 | echo '</select>' . "\n" . |
| 484 | ' </TD>' . "\n" . |
| 485 | ' </TR>' . "\n"; |
| 486 | } |
| 487 | echo ' <TR>' . "\n" . |
| 488 | ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" . |
| 489 | _("To:") . |
| 490 | ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" . |
| 491 | ' <INPUT TYPE=text NAME="send_to" VALUE="' . |
| 492 | htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" . |
| 493 | ' </TD>' . "\n" . |
| 494 | ' </TR>' . "\n" . |
| 495 | ' <TR>' . "\n" . |
| 496 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" . |
| 497 | _("CC:") . |
| 498 | ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" . |
| 499 | ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' . |
| 500 | htmlspecialchars($send_to_cc) . '"><BR>' . "\n" . |
| 501 | ' </TD>' . "\n" . |
| 502 | ' </TR>' . "\n" . |
| 503 | ' <TR>' . "\n" . |
| 504 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" . |
| 505 | _("BCC:") . |
| 506 | ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" . |
| 507 | ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' . |
| 508 | htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" . |
| 509 | '</TD></TR>' . "\n" . |
| 510 | ' <TR>' . "\n" . |
| 511 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" . |
| 512 | _("Subject:") . |
| 513 | ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n"; |
| 514 | if ($reply_subj) { |
| 515 | $reply_subj = str_replace('"', "'", $reply_subj); |
| 516 | $reply_subj = trim($reply_subj); |
| 517 | if (substr(strtolower($reply_subj), 0, 3) != 're:') { |
| 518 | $reply_subj = 'Re: ' . $reply_subj; |
| 519 | } |
| 520 | echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' . |
| 521 | htmlspecialchars($reply_subj) . '">'; |
| 522 | } |
| 523 | elseif ($forward_subj) { |
| 524 | $forward_subj = trim($forward_subj); |
| 525 | if ((substr(strtolower($forward_subj), 0, 4) != 'fwd:') && |
| 526 | (substr(strtolower($forward_subj), 0, 5) != '[fwd:') && |
| 527 | (substr(strtolower($forward_subj), 0, 6) != '[ fwd:')) { |
| 528 | $forward_subj = '[Fwd: ' . $forward_subj . ']'; |
| 529 | } |
| 530 | echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' . |
| 531 | htmlspecialchars($forward_subj) . '">'; |
| 532 | } else { |
| 533 | echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' . |
| 534 | htmlspecialchars($subject) . '">'; |
| 535 | } |
| 536 | echo '</td></tr>' . "\n\n"; |
| 537 | |
| 538 | if ($location_of_buttons == 'between') { |
| 539 | showComposeButtonRow(); |
| 540 | } |
| 541 | |
| 542 | echo ' <TR>' . "\n" . |
| 543 | ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" . |
| 544 | ' <TEXTAREA NAME=body ROWS=20 COLS="' . |
| 545 | $editor_size . '" WRAP=HARD>' . htmlspecialchars($body); |
| 546 | if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) { |
| 547 | echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature); |
| 548 | } |
| 549 | echo '</TEXTAREA><BR>' . "\n" . |
| 550 | ' </TD>' . "\n" . |
| 551 | ' </TR>' . "\n"; |
| 552 | |
| 553 | if ($location_of_buttons == 'bottom') { |
| 554 | showComposeButtonRow(); |
| 555 | } else { |
| 556 | echo ' <TR><TD> </TD><TD ALIGN=LEFT><INPUT TYPE=SUBMIT ' . |
| 557 | 'NAME=send VALUE="' . _("Send") . '"></TD></TR>' . "\n"; |
| 558 | } |
| 559 | |
| 560 | /* This code is for attachments */ |
| 561 | echo ' <TR>' . "\n" . |
| 562 | ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" . |
| 563 | _("Attach:") . |
| 564 | ' </TD>' . "\n" . |
| 565 | ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" . |
| 566 | ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" . |
| 567 | ' <input type="submit" name="attach"' . |
| 568 | ' value="' . _("Add") .'">' . "\n" . |
| 569 | ' </TD>' . "\n" . |
| 570 | ' </TR>' . "\n"; |
| 571 | if (count($attachments)) { |
| 572 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
| 573 | echo '<tr><td bgcolor="' . $color[0] . '" align=right>' . "\n" . |
| 574 | ' ' . |
| 575 | '</td><td align=left bgcolor="' . $color[0] . '">'; |
| 576 | foreach ($attachments as $key => $info) { |
| 577 | $attached_file = "$hashed_attachment_dir/$info[localfilename]"; |
| 578 | echo '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" . |
| 579 | $info['remotefilename'] . ' - ' . $info['type'] . ' (' . |
| 580 | show_readable_size(filesize($attached_file)) . ")<br>\n"; |
| 581 | } |
| 582 | |
| 583 | echo '<input type="submit" name="do_delete" value="' . |
| 584 | _("Delete selected attachments") . "\">\n" . |
| 585 | '</td></tr>'; |
| 586 | } |
| 587 | /* End of attachment code */ |
| 588 | |
| 589 | echo '</TABLE>' . "\n"; |
| 590 | if ($reply_id) { |
| 591 | echo '<input type=hidden name=reply_id value=' . $reply_id . ">\n"; |
| 592 | } |
| 593 | echo '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) . |
| 594 | "\">\n" . |
| 595 | '</FORM>'; |
| 596 | do_hook("compose_bottom"); |
| 597 | echo '</BODY></HTML>' . "\n"; |
| 598 | } |
| 599 | |
| 600 | |
| 601 | function showComposeButtonRow() |
| 602 | { |
| 603 | global $use_javascript_addr_book, $save_as_draft, |
| 604 | $default_use_priority, $mailprio; |
| 605 | |
| 606 | echo " <TR><td>\n </td><td>\n"; |
| 607 | if ($use_javascript_addr_book) { |
| 608 | echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\""; |
| 609 | echo " <input type=button value=\\\""._("Addresses"). |
| 610 | "\\\" onclick='javascript:open_abook();'>\");"; |
| 611 | echo " // --></SCRIPT><NOSCRIPT>\n"; |
| 612 | echo " <input type=submit name=\"html_addr_search\" value=\"". |
| 613 | _("Addresses")."\">"; |
| 614 | echo " </NOSCRIPT>\n"; |
| 615 | } else { |
| 616 | echo " <input type=submit name=\"html_addr_search\" value=\"". |
| 617 | _("Addresses")."\">"; |
| 618 | } |
| 619 | echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n"; |
| 620 | |
| 621 | if ($save_as_draft) { |
| 622 | echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n"; |
| 623 | } |
| 624 | if ($default_use_priority) { |
| 625 | if(!isset($mailprio)) { |
| 626 | $mailprio = "3"; |
| 627 | } |
| 628 | echo "\n\t". _("Priority") .':<select name="mailprio">'. |
| 629 | "\n\t\t<option value=1".($mailprio=='1'?' selected':'').'>'. _("High") .'</option>'. |
| 630 | "\n\t\t<option value=3".($mailprio=='3'?' selected':'').'>'. _("Normal") .'</option>'. |
| 631 | "\n\t\t<option value=5".($mailprio=='5'?' selected':'').'>'. _("Low").'</option>'. |
| 632 | "\n\t</select>"; |
| 633 | } |
| 634 | |
| 635 | do_hook('compose_button_row'); |
| 636 | |
| 637 | echo " </TD>\n"; |
| 638 | echo " </TR>\n\n"; |
| 639 | } |
| 640 | |
| 641 | function checkInput ($show) |
| 642 | { |
| 643 | /* |
| 644 | * I implemented the $show variable because the error messages |
| 645 | * were getting sent before the page header. So, I check once |
| 646 | * using $show=false, and then when i'm ready to display the error |
| 647 | * message, show=true |
| 648 | */ |
| 649 | global $body, $send_to, $subject, $color; |
| 650 | |
| 651 | if ($send_to == "") { |
| 652 | if ($show) { |
| 653 | plain_error_message(_("You have not filled in the \"To:\" field."), $color); |
| 654 | } |
| 655 | return false; |
| 656 | } |
| 657 | return true; |
| 658 | } /* function checkInput() */ |
| 659 | |
| 660 | |
| 661 | /* True if FAILURE */ |
| 662 | function saveAttachedFiles() { |
| 663 | global $HTTP_POST_FILES, $attachment_dir, $attachments, $username; |
| 664 | |
| 665 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
| 666 | $localfilename = GenerateRandomString(32, '', 7); |
| 667 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
| 668 | while (file_exists($full_localfilename)) { |
| 669 | $localfilename = GenerateRandomString(32, '', 7); |
| 670 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
| 671 | } |
| 672 | |
| 673 | if (!@rename($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) { |
| 674 | if (!@copy($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) { |
| 675 | return true; |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | $newAttachment['localfilename'] = $localfilename; |
| 680 | $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name']; |
| 681 | $newAttachment['type'] = strtolower($HTTP_POST_FILES['attachfile']['type']); |
| 682 | |
| 683 | if ($newAttachment['type'] == "") { |
| 684 | $newAttachment['type'] = 'application/octet-stream'; |
| 685 | } |
| 686 | |
| 687 | $attachments[] = $newAttachment; |
| 688 | } |
| 689 | |
| 690 | |
| 691 | function ClearAttachments() |
| 692 | { |
| 693 | global $username, $attachments, $attachment_dir; |
| 694 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
| 695 | |
| 696 | foreach ($attachments as $info) { |
| 697 | $attached_file = "$hashed_attachment_dir/$info[localfilename]"; |
| 698 | if (file_exists($attached_file)) { |
| 699 | unlink($attached_file); |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | $attachments = array(); |
| 704 | } |
| 705 | |
| 706 | function getReplyCitation($orig_from) |
| 707 | { |
| 708 | global $reply_citation_style, $reply_citation_start, $reply_citation_end; |
| 709 | |
| 710 | /* First, return an empty string when no citation style selected. */ |
| 711 | if (($reply_citation_style == '') || ($reply_citation_style == 'none')) { |
| 712 | return ''; |
| 713 | } |
| 714 | |
| 715 | /* Decode the users name. */ |
| 716 | $parpos = strpos($orig_from, '('); |
| 717 | if ($parpos === false) { |
| 718 | $orig_from = trim(substr($orig_from, 0, strpos($orig_from, '<'))); |
| 719 | $orig_from = str_replace('"', '', $orig_from); |
| 720 | $orig_from = str_replace("'", '', $orig_from); |
| 721 | } else { |
| 722 | $end_parpos = strrpos($orig_from, ')'); |
| 723 | $end_parpos -= ($end_parpos === false ? $end_parpos : $parpos + 1); |
| 724 | $orig_from = trim(substr($orig_from, $parpos + 1, $end_parpos)); |
| 725 | } |
| 726 | |
| 727 | /* Make sure our final value isn't an empty string. */ |
| 728 | if ($orig_from == '') { |
| 729 | return ''; |
| 730 | } |
| 731 | |
| 732 | /* Otherwise, try to select the desired citation style. */ |
| 733 | switch ($reply_citation_style) { |
| 734 | case 'author_said': |
| 735 | $start = ''; |
| 736 | $end = ' ' . _("said") . ':'; |
| 737 | break; |
| 738 | case 'quote_who': |
| 739 | $start = '<' . _("quote") . ' ' . _("who") . '="'; |
| 740 | $end = '">'; |
| 741 | break; |
| 742 | case 'user-defined': |
| 743 | $start = $reply_citation_start; |
| 744 | $end = $reply_citation_end; |
| 745 | break; |
| 746 | default: |
| 747 | return ''; |
| 748 | } |
| 749 | |
| 750 | /* Build and return the citation string. */ |
| 751 | return ($start . $orig_from . $end . "\n"); |
| 752 | } |
| 753 | |
| 754 | ?> |