1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050
|
<?php
/*
File: compose.php3
$Author: bjn $
$Revision: 2.35.2.84 $
$Date: 2001/05/22 03:44:48 $
IMP: Copyright 1999, 2000 Charles J. Hagenbuch <chuck@horde.org>
You should have received a copy of the GNU Public
License along with this package; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/* check for non-standard address formats, such as seperating with
spaces or semicolons. */
function format_addresses ($address_string) {
// if there are angle brackets (<>) assume the user knew what they were doing
if (!is_string(strstr($address_string, '>'))) { // check return value explicitly because it might be 0
$address_string = trim(strtr($address_string, ';,', ' '));
$address_string = preg_replace('|\s+|', ', ', $address_string);
}
return $address_string;
}
/* format a from: address correctly based on all relevant factors... */
function get_from () {
global $default, $from, $imp;
if ($default->user_change_fullname || $default->use_db)
$name = imp_get_fullname($imp->user, $imp->server);
if (empty($name)) $name = '';
if (!isset($from) || !$from || !$default->user_change_from) {
$from = '';
if ($name) {
$from = $name;
$from .= ' <';
}
$from .= get_barefrom();
if ($name) {
$from .= '>';
}
}
return $from;
}
/*
* Return the value of upload_tmp_dir, or default to '/tmp'
*/
function tmpdir()
{
$tmp = get_cfg_var('upload_tmp_dir');
if (empty($tmp)) {
$tmp = getenv('TMPDIR');
}
return (empty($tmp) ? '/tmp' : $tmp);
}
/*
* Make sure a path is inside of the upload directory.
*/
function safe_file($file) {
return tmpdir() . '/' . basename($file);
}
/* Obtain the date offset. Thanks to Javier Kohen <jkohen@tough.com>
* for fixing this for wrap-around
*/
function gm_offset () {
$date = date('H');
$gmdate = gmdate('H');
/* Adjust for wrap-around, the difference can't be more than 12 hours.
* AFAIK, -1200 is invalid, the correct one is +1200 (ie: at New Zealand).
*
* CHANGED Oct 18 2000 (Submitted by <demian@coretech.co.nz>) to handle
* New Zealand daylight savings time.
*/
if ($gmdate + 13 < $date) {
$gmdate += 24;
} else if ($date + 11 <= $gmdate) {
$date += 24;
}
$offset = $date - $gmdate;
if ($offset >= 0) {
return sprintf("+%02d", $offset) . "00";
} else {
return sprintf("-%02d", -$offset) . "00";
}
}
// if $id=2.1, returns $structure->parts[1]->parts[0]
function partFromId ($structure, $id) {
$res = $structure;
if (isset($res->parts[0])) {
$piece = explode('.', $id);
$num = count($piece);
$ind = 0;
$j = 0;
while ($j < $num) {
$ind = $piece[$j]-1;
$res = $res->parts[$ind];
$j++;
}
}
return $res;
}
function find_text_part (&$attachments) {
reset($attachments);
while (list(,$mime) = each($attachments)) {
mimeParse($mime);
if ($mime->type == TYPETEXT) {
return MimeFetchDecodedContent($mime);
}
}
return '';
}
/* add the attachments to the message in the case of a forward with attachments */
function attach_files ($part, $ref) {
global $msg, $bodypart, $mailbox, $index, $attachments_name, $attachments_size, $attachments_file, $attachments_type, $total_size;
$num_parts = count($part->parts);
for ($j=1; $j<$num_parts; $j++) {
if (strlen($ref) == 0)
$aref = '' . ($j+1);
else
$aref = $ref . '.' . ($j+1);
if (isset($part->parts[$j])) {
$p = $part->parts[$j];
if (isset($p->parts[0]))
$msg = attach_files($p, $aref, $msg);
}
else {
$p = $part;
}
$mime = new mime_part_data;
$mime->set_imap_data($index, $aref);
$mime->parse($p);
$file_upload_name = $mime->name;
$file_upload_size = $mime->size;
$file_upload_type = $mime->type_text . '/' . $mime->subtype;
$file_upload = $aref;
if (isset($attachments_name) && !is_array($attachments_name)) { $attachments_name = array($attachments_name); }
if (isset($attachments_size) && !is_array($attachments_size)) { $attachments_size = array($attachments_size); }
if (isset($attachments_file) && !is_array($attachments_file)) { $attachments_file = array($attachments_file); }
if (isset($attachments_type) && !is_array($attachments_type)) { $attachments = array($attachments_type); }
$attachments_name[] = $file_upload_name;
$attachments_size[] = $file_upload_size;
$attachments_file[] = $index . "-" . $file_upload . ".mime";
$attachments_type[] = $file_upload_type;
$total_size = 0;
for ($i=0; $i<count($attachments_size); $i++) {
$total_size += $attachments_size[$i];
}
}
}
$need_horde_db = 1;
require '../lib/horde.lib';
require './lib/imp.lib'; /* IMPlib is the IMP function library */
require '../config/horde.php3';
require './config/defaults.php3'; /* Defaults configuration file */
require './config/lang.php3';
require './lib/version.php';
/* Html styles configuration */
require '../config/html.php3';
require './config/html.php3';
/* include mime and language configuration */
require './config/mime.php3';
require '../lib/mime.lib'; /* Mime lib for composing mime messages */
require './lib/mimetypes.lib';
$language = select_lang();
require './lib/postconf.php3';
require "./locale/$language/compose.lang";
require "./locale/local/compose.lang";
$help_file = 'compose.help';
require "./locale/defines/$help_file";
require './config/lang.php3';
/* Setup the this_client object */
$this_client = new WebClient;
error_reporting($default->error_level);
/* Adjust the form element sizes for the appropriate screen size */
if ($_html['screen_size'] == 'small') {
$_html['smresize'] = 0.7;
$_html['bgresize'] = 0.5;
$_html['compose_headers_size'] = $_html['compose_headers_size'] * $_html['smresize'];
$_html['compose_attach_size'] = $_html['compose_attach_size'] * $_html['smresize'];
$_html['compose_body_cols'] = $_html['compose_body_cols'] * $_html['smresize'];
$_html['compose_body_rows'] = $_html['compose_body_rows'] * $_html['bgresize'];
} else if ($_html['screen_size'] == 'large') {
$_html['smresize'] = 1;
$_html['bgresize'] = 1;
}
if ($this_client->ns) {
page_open(array('sess' => 'HordeSessionCached'));
} else {
page_open(array('sess' => 'HordeSession'));
}
page_close();
if (!isset($imp) || !is_object($imp)) { echo '<script language="JavaScript">window.close()</script>'; exit; }
$imp->unpickle();
$imp->authenticate(); /* login */
$get_sig = true;
/* array to translate string actions into the appropriate integer ID */
$actions[$lang->button_send] = SEND_MESSAGE;
$actions[htmlentities($lang->button_send)] = SEND_MESSAGE;
$actions[$lang->button_attach] = ADD_ATTACHMENT;
$actions[htmlentities($lang->button_attach)] = ADD_ATTACHMENT;
$actions[$lang->button_bounce] = BOUNCE_MESSAGE;
$actions[htmlentities($lang->button_bounce)] = BOUNCE_MESSAGE;
$actions[$lang->button_cancel] = CANCEL;
$actions[htmlentities($lang->button_cancel)] = CANCEL;
$actions[$lang->button_delete_attach] = DELETE_ATTACHMENT;
$actions[htmlentities($lang->button_delete_attach)] = DELETE_ATTACHMENT;
$actions[$lang->button_postpone] = POSTPONE_DRAFT;
$actions[htmlentities($lang->button_postpone)] = POSTPONE_DRAFT;
if (isset($index)) {
$index = intval($index); // prevent abuse
}
/* doctype */
require "$default->include_dir/doctype.inc";
/* Run through action handlers */
if (isset($actionID)) {
/* translate non-int values into the correct int */
if (strcspn($actionID, '0123456789')) {
$actionID = isset($actions[$actionID]) ? $actions[$actionID] : $actions[htmlentities($actionID)];
}
switch ($actionID) {
case NO_ACTION:
/* don't want it to hit the IMAP server here - nuke the refresh */
unset($default->refresh_delay);
status($lang->status_composition);
$ACTION_TEXT = $lang->status_composition;
break;
case COMPOSE:
if (isset($to)) {
$to = chop(decode_mime_string($to));
}
if (isset($subject)) {
$subject = chop(decode_mime_string($subject));
}
$ACTION_TEXT = $lang->action_compose;
break;
case MAILTO:
if ($imp->mailbox && $index) {
$h = @imap_header($imp->stream, imap_msgno($imp->stream, $index));
if (isset($mailto) && isset($h->$mailto)) {
$to = chop(decode_mime_string($h->$mailto));
} else if (!empty($h->reply_toaddress)) {
$to = chop(decode_mime_string($h->reply_toaddress));
} else if (!empty($h->fromaddress)) {
$to = chop(decode_mime_string($h->fromaddress));
} else {
$to = '';
}
$ACTION_TEXT = $lang->action_compose;
}
break;
case DRAFT:
if ($mailbox && $index && $bodypart) {
$h = imap_header($imp->stream, imap_msgno($imp->stream, $index));
if ($h) {
if (isset($h->fromaddress)) $from = chop(decode_mime_string($h->fromaddress));
if (isset($h->toaddress)) $to = chop(decode_mime_string($h->toaddress));
if (isset($h->ccaddress)) $cc = chop(decode_mime_string($h->ccaddress));
if (isset($h->bccaddress)) $bcc = chop(decode_mime_string($h->bccaddress));
if (isset($h->reply_toaddress)) $reply_to = chop(decode_mime_string($h->reply_toaddress));
if (isset($h->subject)) $subject = chop(decode_mime_string($h->subject));
}
$quote_str = "\n" . $default->quote_prefix;
$msg = imap_fetchbody($imp->stream, $index, $bodypart, FT_UID);
$ACTION_TEXT = $lang->action_compose;
$structure = @imap_fetchstructure($imp->stream, $index, FT_UID);
if (@count($structure->parts) > 1) {
attach_files($structure, '');
}
$get_sig = false;
}
break;
case REPLY:
if ($imp->mailbox && $index && $bodypart) {
$h = imap_header($imp->stream, imap_msgno($imp->stream, $index));
/* Set the message_id and references headers */
if (isset($h->message_id)) {
$in_reply_to = chop($h->message_id);
if (isset($h->references)) {
$references = chop($h->references) . ' ' . $in_reply_to;
} else {
$references = $in_reply_to;
}
} else {
$in_reply_to = '';
$references = '';
}
if (isset($h->reply_toaddress))
$to = chop(decode_mime_string($h->reply_toaddress));
else if (isset($h->fromaddress))
$to = chop(decode_mime_string($h->fromaddress));
else
$to = '';
if (isset($h->fromaddress))
$qfrom = chop(decode_mime_string($h->fromaddress));
else $qfrom = '<>';
$quote_str = "\n" . $default->quote_prefix;
$structure = imap_fetchstructure($imp->stream, $index, FT_UID);
$foo = false;
$attachments = MimeParseStructure($structure, '', $foo);
$msg = find_text_part($attachments);
$msg = wrap_message($msg, $_html['compose_body_cols'] - 8, $quote_str);
$msg = $lang->quoting_string . ' ' . $qfrom . ":\n$quote_str$msg";
$msg .= "\n";
if (isset($h->subject) && (strtolower(substr(trim(decode_mime_string($h->subject)), 0, 3)) != 're:'))
$subject = 'Re: ' . chop(decode_mime_string($h->subject));
else if (isset($h->subject))
$subject = chop(decode_mime_string($h->subject));
else
$subject = 'Re: ';
$ACTION_TEXT = $lang->action_reply . ' ' . $subject;
}
break;
case REPLY_ALL:
if ($imp->mailbox && $index && $bodypart) {
$h = imap_header($imp->stream, imap_msgno($imp->stream, $index));
/* Set the message_id and references headers */
if (isset($h->message_id)) {
$in_reply_to = chop($h->message_id);
if (isset($h->references)) {
$references = chop($h->references) . ' ' . $in_reply_to;
} else {
$references = $in_reply_to;
}
} else {
$in_reply_to = '';
$references = '';
}
if (!empty($h->reply_toaddress)) {
$reply = chop(decode_mime_string($h->reply_toaddress));
} else if (!empty($h->fromaddress)) {
$reply = chop(decode_mime_string($h->fromaddress));
} else {
$reply = '';
}
/* make a few checks unnecessary by initializing these */
if (empty($h->fromaddress)) $h->fromaddress = '';
if (empty($h->toaddress)) $h->toaddress = '';
/* build up the reply to all addresses */
if ($reply != chop(decode_mime_string($h->fromaddress))) {
$to = $reply . ',' . chop(decode_mime_string($h->fromaddress));
} else {
$to = $reply;
}
if ($reply != chop(decode_mime_string($h->toaddress))) {
$cc = chop(decode_mime_string($h->toaddress));
if (!empty($h->ccaddress)) {
$cc .= ',' . chop(decode_mime_string($h->ccaddress));
}
} else if (!empty($h->ccaddress)) {
$cc = chop(decode_mime_string($h->ccaddress));
}
if (!empty($h->bccaddress)) {
$bcc = ',' . chop(decode_mime_string($h->bccaddress));
}
$quote_str = "\n" . $default->quote_prefix;
$structure = imap_fetchstructure($imp->stream, $index, FT_UID);
$foo = false;
$attachments = MimeParseStructure($structure, '', $foo);
$msg = find_text_part($attachments);
$msg = wrap_message($msg, $_html['compose_body_cols'] - 8, $quote_str);
$msg = $lang->quoting_string . ' ' . chop(decode_mime_string($h->fromaddress)) . ":\n$quote_str$msg";
$msg .= "\n";
if (isset($h->subject) && strtolower(substr(trim(decode_mime_string($h->subject)), 0, 3)) != 're:') $subject = 'Re: ' . chop(decode_mime_string($h->subject));
else if (isset($h->subject)) $subject = chop(decode_mime_string($h->subject));
else $subject = '';
$ACTION_TEXT = $lang->action_reply_all . ' ' . $subject;
}
break;
case FORWARD:
if ($imp->mailbox && $index && $bodypart) {
$h = imap_header($imp->stream, imap_msgno($imp->stream, $index));
if (isset($h->fromaddress))
$message_source = chop(decode_mime_string($h->fromaddress));
else
$message_source = '';
$from = get_from();
$msg = "\n" . $lang->forwarded_from($message_source) . "\n";
if (isset($h->date) && $h->date) { $msg .= 'Date: ' . chop(decode_mime_string($h->date)) . "\n"; }
if (isset($h->fromaddress) && $h->fromaddress) { $msg .= 'From: ' . chop(decode_mime_string($h->fromaddress)) . "\n"; }
if (isset($h->reply_toaddress) && $h->reply_toaddress) { $msg .= 'Reply-To: ' . chop(decode_mime_string($h->reply_toaddress)) . "\n"; }
if (isset($h->subject) && $h->subject) { $msg .= 'Subject: ' . chop(decode_mime_string($h->subject)) . "\n"; }
if (isset($h->toaddress) && $h->toaddress) { $msg .= 'To: ' . chop(decode_mime_string($h->toaddress)) . "\n"; }
$msg .= "\n";
$msg .= wrap_message(imap_fetchbody($imp->stream, $index, $bodypart, FT_UID));
$msg .= "\n----- " . $lang->forward_end_string . " -----\n";
if ($qprint_msg = imap_qprint($msg)) {
$msg = $qprint_msg;
}
if (isset($h->subject)) {
$subject = $lang->fwd_string . ' ' . chop(decode_mime_string($h->subject));
$ACTION_TEXT = $lang->action_forward . ' ' . chop(decode_mime_string($h->subject));
} else {
$subject = $lang->fwd_string;
$ACTION_TEXT = $lang->action_forward;
}
$structure = @imap_fetchstructure($imp->stream, $index, FT_UID);
if (@count($structure->parts) > 1) {
attach_files($structure, '');
}
}
break;
case BOUNCE_MESSAGE:
if ($imp->mailbox && $index && $to) {
$recipients = $to;
$headers = imap_fetchheader($imp->stream, $index, FT_UID);
$headers = str_replace("\r", '', $headers);
$header_arr = explode("\n", $headers);
for ($i=0; $i<count($header_arr); $i++) {
if (!empty($header_arr[$i]) && $header_arr[$i] != '' && $header_arr[$i] != "\n") {
if (preg_match("|^([-\\w]*): (.*)|", $header_arr[$i], $pieces)) {
$envelope[$pieces[1]] = $pieces[2];
$last = $pieces[1];
} else {
if (isset($last) && $envelope[$last]) {
$envelope[$last] .= "\n" . $header_arr[$i];
}
}
}
}
$envelope['Resent-Date'] = date('D, d M Y H:i:s ') . gm_offset() . ' (' . strftime('%Z') . ')';
$envelope['Resent-From'] = get_barefrom();
$envelope['Resent-To'] = $to;
$envelope['Resent-Message-ID'] = '<' . uniqid(time() . '.') . '@' . $SERVER_NAME . '>';
$msg = imap_body($imp->stream, $index, FT_UID);
if (mailfrom($recipients, $envelope, $msg)) {
status($lang->status_bounce_success);
$status_result = $lang->status_bounce_success;
if ($default->minimum_popups || $this_client->rather_not_popup) {
include "$default->include_dir/generic-header.inc";
include "$default->include_dir/compose/results.inc";
include "$default->include_dir/generic-footer.inc";
exit;
}
if (!$this_client->lynx) {
echo '<script language="JavaScript">self.close();</script></body></html>';
} else {
include('./mailbox.php3');
}
exit;
}
unset($to);
unset($msg);
}
break;
case SEND_MESSAGE:
if (isset($is_reply) && isset($index) && isset($imp->mailbox) && $is_reply) {
imap_setflag_full($imp->stream, $index, '\\ANSWERED', SE_UID);
}
if (isset($attachments_name) && !is_array($attachments_name)) { $attachments = array($attachments_name); }
if (isset($attachments_size) && !is_array($attachments_size)) { $attachments = array($attachments_size); }
if (isset($attachments_file) && !is_array($attachments_file)) { $attachments = array($attachments_file); }
if (isset($attachments_type) && !is_array($attachments_type)) { $attachments = array($attachments_type); }
if ($to && isset($message)) {
$message = str_replace("\r\n", "\n", $message);
$mime = new MimeMessage($message);
$text_part = new mime_part;
$text_part->type = 'text';
$text_part->subtype = 'plain';
$text_part->contents = $message;
if ($default->append_trailer) {
/* add footer to text_part */
$config_trailer = "\n" . implode(@file('./config/trailer.txt'), '');
$config_trailer = set_env_in_string($config_trailer);
$text_part->contents .= $config_trailer;
}
$mime->add_begin_part($text_part);
if (isset($attachments_name) && is_array($attachments_name) && count($attachments_name) > 0) {
for ($i = 0; $i < count($attachments_name)-1; $i++) {
/* read it from the filesystem if its a normal attachment */
if (!preg_match("|.mime$|", $attachments_file[$i])) {
$fd = fopen (safe_file($attachments_file[$i]), 'r');
$contents = fread($fd, $attachments_size[$i]);
fclose($fd);
unlink(safe_file($attachments_file[$i]));
} else {
/* fetch it from the mail message if its a forwarded attachment */
preg_match("|(.*)-(.*).mime|", $attachments_file[$i], $regs);
$message_index = $regs[1];
$message_part = $regs[2];
$forwarded_mime = new mime_part_data;
$mime_structure = imap_fetchstructure($imp->stream, $message_index, FT_UID);
$part_structure = partFromId($mime_structure, $message_part);
$forwarded_mime->parse($part_structure);
$contents = imap_fetchbody($imp->stream, $message_index, $message_part, FT_UID);
if ($forwarded_mime->encoding == 3)
$contents = imap_base64($contents);
else if ($forwarded_mime->encoding == 4 && ($qprint_msg = imap_qprint($contents)))
$contents = $qprint_msg;
}
$file_part = new mime_part;
/* some browsers do not send mime type */
if (strcmp($attachments_type[$i], '')) {
$file_part->parse_full_type($attachments_type[$i]);
} else {
$file_part->parse_full_type('application/octet-stream');
}
$file_part->name = $attachments_name[$i];
/* if the type is text, we shouldn't base64 it */
if ($file_part->type == 'text') {
$file_part->contents = $contents;
} else {
$file_part->transfer_encoding = 'base64';
$file_part->contents = chunk_split(base64_encode($contents), 73, "\n") . "\n";
}
$mime->add_middle_part($file_part);
}
$i = count($attachments_name)-1;
/* read it from the filesystem if its a normal attachment */
if (!preg_match("|.mime$|", $attachments_file[$i])) {
$fd = fopen (safe_file($attachments_file[$i]), 'r');
$contents = fread($fd, $attachments_size[$i]);
fclose($fd);
unlink(safe_file($attachments_file[$i]));
} else {
/* fetch it from the mail message if its a forwarded attachment */
preg_match("|(.*)-(.*).mime|", $attachments_file[$i], $regs);
$message_index = $regs[1];
$message_part = $regs[2];
$forwarded_mime = new mime_part_data;
$mime_structure = imap_fetchstructure($imp->stream, $message_index, FT_UID);
$part_structure = partFromId($mime_structure, $message_part);
$forwarded_mime->parse($part_structure);
$contents = imap_fetchbody($imp->stream, $message_index, $message_part, FT_UID);
if ($forwarded_mime->encoding == 3)
$contents = imap_base64($contents);
else if ($forwarded_mime->encoding == 4 && ($qprint_msg = imap_qprint($contents)))
$contents = $qprint_msg;
}
$file_part = new mime_part;
/* some browsers do not send mime type */
if (strcmp($attachments_type[$i], '')) {
$file_part->parse_full_type($attachments_type[$i]);
} else {
$file_part->parse_full_type('application/octet-stream');
}
$file_part->name = $attachments_name[$i];
/* if the type is text, we shouldn't base64 it */
if ($file_part->type == 'text') {
$file_part->contents = $contents;
} else {
$file_part->transfer_encoding = "base64";
$file_part->contents = chunk_split(base64_encode($contents)) . "\n";
}
$mime->add_end_part($file_part);
}
$msg = $mime->generate();
$recipients = '';
$from = get_from();
$envelope['Message-ID'] = '<' . uniqid(time() . '.') . '@' . $SERVER_NAME . '>';
$envelope['Date'] = date("D, d M Y H:i:s ") . gm_offset() . ' (' . strftime('%Z') . ')';
$to = format_addresses($to);
$envelope['To'] = $to;
$envelope['From'] = $from;
$recipients = $to;
if (!empty($cc)) {
$cc = format_addresses($cc);
$envelope['Cc'] = $cc;
$recipients .= ', ' . $cc;
}
if (!empty($bcc)) {
$bcc = format_addresses($bcc);
$envelope['Bcc'] = $bcc;
$recipients .= ', ' . $bcc;
}
if (isset($subject) && $subject)
$envelope['Subject'] = $subject;
if (isset($references))
$envelope['References'] = $references;
if (isset($in_reply_to))
$envelope['In-Reply-To'] = $in_reply_to;
$envelope = $mime->header($envelope);
$envelope['User-Agent'] = 'IMP/PHP IMAP webmail program ' . IMP_VERSION;
if (mailfrom($recipients, $envelope, $msg)) {
status($lang->status_send_success);
$status_result = $lang->status_send_success;
if ($default->user_use_folders && $default->save_sent_mail) {
// Loop through the envelope and add headers.
reset($envelope);
$fcc = '';
while (list($key, $val) = each($envelope)) {
if ($key != 'recipients')
$fcc .= $key . ': ' . $val . "\n";
}
$fcc .= "\n";
$fcc .= $msg;
$preamble = $imp->folders . $default->personal_folders;
$sent_folder = imap_utf7_encode($preamble . $default->sent_mail);
if (!imap_listmailbox($imp->stream, '{' . $imp->server . ':' . $imp->port . '}', $sent_folder)) {
@imap_createmailbox($imp->stream, '{' . $imp->server . ':' . $imp->port . '}' . $sent_folder);
if ($default->use_imap_subscribe) {
@imap_subscribe($imp->stream, '{' . $imp->server . ':' . $imp->port . '}' . $sent_folder);
}
imp_reload_frame('impfolder', $sess->url('select.php3?uniq=' . uniqid(rand())));
}
$fcc = str_replace("\n", "\r\n", $fcc);
if (!(@imap_append($imp->stream, '{' . $imp->server . ':' . $imp->port . '}' . $sent_folder, $fcc, '\\Seen'))) {
status($lang->status_send_save_error . ' ' . $preamble . $default->sent_mail);
$status_result = $lang->status_send_save_error . ' ' . $default->sent_mail;
}
}
if ($default->minimum_popups || $this_client->rather_not_popup) {
include "$default->include_dir/generic-header.inc";
include "$default->include_dir/compose/results.inc";
include "$default->include_dir/generic-footer.inc";
exit;
}
if (!$this_client->lynx) {
echo '<script language="JavaScript">self.close();</script></body></html>';
} else {
include './mailbox.php3';
}
exit;
}
}
$total_size = 0;
if (isset($attachments_size) && is_array($attachments_size)) {
for ($i = 0; $i < count($attachments_size); $i++) {
$total_size += $attachments_size[$i];
}
}
$get_sig = false;
$ACTION_TEXT = $lang->status_send_error;
break;
case POSTPONE_DRAFT:
$append_flags = '\\Draft';
case POSTPONE_MESSAGE:
$preamble = $imp->folders . $default->personal_folders;
$copyto = imap_utf7_encode($preamble . $default->postponed);
if (!empty($copyto)) {
$total_size = 0;
if (isset($attachments_size) && is_array($attachments_size)) {
for ($i = 0; $i < count($attachments_size); $i++) {
$total_size += $attachments_size[$i];
}
}
if (isset($message)) {
$msg = $message; // save for later.
$message = str_replace("\r\n", "\n", $message);
$mime = new MimeMessage($message);
$text_part = new mime_part;
$text_part->type = 'text';
$text_part->subtype = 'plain';
$text_part->contents = $message;
$mime->add_begin_part($text_part);
if (isset($attachments_name) && is_array($attachments_name) && count($attachments_name) > 0) {
for ($i = 0; $i < count($attachments_name)-1; $i++) {
/* read it from the filesystem if its a normal attachment */
if (!preg_match("|\.mime$|", $attachments_file[$i])) {
$fd = fopen (safe_file($attachments_file[$i]), 'r');
$contents = fread($fd, $attachments_size[$i]);
fclose($fd);
unlink(safe_file($attachments_file[$i]));
} else {
/* fetch it from the mail message if its a forwarded attachment */
preg_match("|(.*)-(.*).mime|", $attachments_file[$i], $regs);
$message_index = $regs[1];
$message_part = $regs[2];
$forwarded_mime = new mime_part_data;
$mime_structure = imap_fetchstructure($imp->stream, $message_index, FT_UID);
$part_structure = partFromId($mime_structure, $message_part);
$forwarded_mime->parse($part_structure);
$contents = imap_fetchbody($imp->stream, $message_index, $message_part, FT_UID);
if ($forwarded_mime->encoding == 3)
$contents = imap_base64($contents);
else if ($forwarded_mime->encoding == 4 && ($qprint_msg = imap_qprint($contents)))
$contents = $qprint_msg;
}
$file_part = new mime_part;
/* some browsers do not send mime type */
if (strcmp($attachments_type[$i], '')) {
$file_part->parse_full_type($attachments_type[$i]);
} else {
$file_part->parse_full_type('application/octet-stream');
}
$file_part->name = $attachments_name[$i];
/* if the type is text, we shouldn't base64 it */
if ($file_part->type == 'text') {
$file_part->contents = $contents;
} else {
$file_part->transfer_encoding = 'base64';
$file_part->contents = chunk_split(base64_encode($contents), 73, "\n") . "\n";
}
$mime->add_middle_part($file_part);
}
$i = count($attachments_name)-1;
/* read it from the filesystem if its a normal attachment */
if (!preg_match("|.mime$|", $attachments_file[$i])) {
$fd = fopen(safe_file($attachments_file[$i]), 'r');
$contents = fread($fd, $attachments_size[$i]);
fclose($fd);
unlink(safe_file($attachments_file[$i]));
} else {
/* fetch it from the mail message if its a forwarded attachment */
preg_match("|(.*)-(.*).mime|", $attachments_file[$i], $regs);
$message_index = $regs[1];
$message_part = $regs[2];
$forwarded_mime = new mime_part_data;
$mime_structure = imap_fetchstructure($imp->stream, $message_index, FT_UID);
$part_structure = partFromId($mime_structure, $message_part);
$forwarded_mime->parse($part_structure);
$contents = imap_fetchbody($imp->stream, $message_index, $message_part, FT_UID);
if ($forwarded_mime->encoding == 3)
$contents = imap_base64($contents);
else if ($forwarded_mime->encoding == 4 && ($qprint_msg = imap_qprint($contents)))
$contents = $qprint_msg;
}
$file_part = new mime_part;
/* some browsers do not send mime type */
if (strcmp($attachments_type[$i], '')) {
$file_part->parse_full_type($attachments_type[$i]);
} else {
$file_part->parse_full_type('application/octet-stream');
}
$file_part->name = $attachments_name[$i];
/* if the type is text, we shouldn't base64 it */
if ($file_part->type == 'text') {
$file_part->contents = $contents;
} else {
$file_part->transfer_encoding = "base64";
$file_part->contents = chunk_split(base64_encode($contents)) . "\n";
}
$mime->add_end_part($file_part);
}
$body = $mime->generate();
} else {
$body = '';
}
$from = get_from();
$hdrs = '';
if ($from != '') {
$hdrs .= "From: $from\n";
}
if ($to != '') {
$hdrs .= "To: $to\n";
}
if ($cc != '') {
$hdrs .= "Cc: $cc\n";
}
if ($bcc != '') {
$hdrs .= "Bcc: $bcc\n";
}
if ($subject != '') {
$hdrs .= "Subject: $subject\n";
}
// FIXME
// The absence of Mime-Version here should really be taken care of
// in horde/lib/mime.lib, but I'm not sure how, and this at least
// makes it *work*. Blame <rich@alcor.concordia.ca>.
$hdrs .= "Mime-Version: 1.0\n";
if (isset($mime)) {
$hdrs .= $mime->textHeader();
}
$body = $hdrs . "\n" . $body;
$body = str_replace("\n", "\r\n", $body);
if (isset($append_flags)) {
$append_flags .= ' \\Seen';
} else {
$append_flags = '\\Seen';
}
if (!imap_listmailbox($imp->stream, '{' . $imp->server . ':' . $imp->port . '}', $copyto)) {
@imap_createmailbox($imp->stream, '{' . $imp->server . ':' . $imp->port . '}' . $copyto);
if ($default->use_imap_subscribe) {
@imap_subscribe($imp->stream, '{' . $imp->server . ':' . $imp->port . '}' . $copyto);
imp_reload_frame('impfolder', $sess->url('select.php3?uniq=' . uniqid(rand())));
}
}
if (!(@imap_append($imp->stream, '{' . $imp->server . ':' . $imp->port . "}$copyto", $body, $append_flags))) {
echo '<script language="JavaScript">alert("save message failed:\n' . addslashes(imap_last_error()) . '");</script>';
} else {
if ($default->minimum_popups || $this_client->rather_not_popup) {
$status_result = $lang->status_message_postponed;
include "$default->include_dir/generic-header.inc";
include "$default->include_dir/compose/results.inc";
include "$default->include_dir/generic-footer.inc";
exit;
}
if (!$this_client->lynx) {
echo '<script language="JavaScript">self.close();</script></body></html>';
} else {
include './mailbox.php3';
}
exit;
}
}
$get_sig = false;
$ACTION_TEXT = $lang->status_message_postponed;
break;
case ADD_ATTACHMENT:
if (isset($attachments_name) && !is_array($attachments_name)) { $attachments_name = array($attachments_name); }
if (isset($attachments_size) && !is_array($attachments_size)) { $attachments_size = array($attachments_size); }
if (isset($attachments_file) && !is_array($attachments_file)) { $attachments_file = array($attachments_file); }
if (isset($attachments_type) && !is_array($attachments_type)) { $attachments = array($attachments_type); }
/*
* NOTE that PHP tempnam() doesn't use mkstemp() until PHP 4.0.3!
* If using PHP 3.0.x, patch your PHP to use mkstemp(), to avoid
* the possibility of a /tmp race.
*/
if ($file_upload_size > 0) {
if (!is_uploaded_file(safe_file($file_upload))) {
break; /* ignore attempt to spoof us; back to composing */
}
$attachments_name[] = $file_upload_name;
$attachments_size[] = $file_upload_size;
$tmpfile_name = tempnam(dirname(safe_file($file_upload)), 'att.');
$attachments_file[] = $tmpfile_name;
if (isset ($file_upload_type)) {
$attachments_type[] = $file_upload_type;
} else {
$attachments_type[] = '';
}
copy (safe_file($file_upload), $tmpfile_name);
$msg = $message;
}
$total_size = 0;
for ($i = 0; $i < count($attachments_size); $i++) {
$total_size += $attachments_size[$i];
}
$ACTION_TEXT = $lang->action_add_attach;
$get_sig = false;
break;
case DELETE_ATTACHMENT:
if (isset($attachments_name) && !is_array($attachments_name)) { $attachments = array($attachments_name); }
if (isset($attachments_size) && !is_array($attachments_size)) { $attachments = array($attachments_size); }
if (isset($attachments_file) && !is_array($attachments_file)) { $attachments = array($attachments_file); }
if (isset($attachments_type) && !is_array($attachments_type)) { $attachments = array($attachments_type); }
if (isset($delattachments) && !is_array($delattachments)) { $indices = array($delattachments); }
if (isset($delattachments) && is_array($delattachments)) {
for ($i=0; $i<count($delattachments); $i++) {
for ($j=0; $j<count($attachments_file); $j++) {
if (strcmp($delattachments[$i], $attachments_file[$j]) == 0) {
if (!preg_match("|.mime$|", $attachments_file[$j])) {
unlink (safe_file($attachments_file[$j]));
}
$attachments_name[$j] = "";
$attachments_size[$j] = "";
$attachments_file[$j] = "";
$attachments_type[$i] = "";
}
}
}
}
$new_name = array ();
$new_file = array ();
$new_size = array ();
$new_type = array ();
for ($i=0; $i<count($attachments_file); $i++) {
if (strcmp($attachments_file[$i], "")) {
$new_name[] = $attachments_name[$i];
$new_file[] = $attachments_file[$i];
$new_size[] = $attachments_size[$i];
$new_type[] = $attachments_type[$i];
}
}
$attachments_name = array ();
$attachments_file = array ();
$attachments_size = array ();
$attachments_type = array ();
$total_size = 0;
for ($i=0; $i<count($new_name); $i++) {
$attachments_name[] = $new_name[$i];
$attachments_file[] = $new_file[$i];
$attachments_size[] = $new_size[$i];
$attachments_type[] = $new_type[$i];
$total_size += $attachments_size[$i];
}
$msg = $message;
$ACTION_TEXT = $lang->action_del_attach;
$get_sig = false;
break;
case BOUNCE_COMPOSE:
$ACTION_TEXT = $lang->action_bounce;
break;
case CANCEL:
$status_result = $lang->status_cancel;
include "$default->include_dir/generic-header.inc";
include "$default->include_dir/compose/results.inc";
include "$default->include_dir/generic-footer.inc";
exit;
default:
$ACTION_TEXT = $lang->action_compose;
break;
}
}
if (!isset($ACTION_TEXT)) $ACTION_TEXT = $lang->action_compose;
if (!isset($status_sent)) status($lang->status_composition);
$title = $lang->status_composition;
$sidebar = false;
require ("$default->include_dir/generic-header.inc");
if (!$this_client->lynx) {
$addresses = imp_get_addresses($imp->user, $imp->server);
include "$default->include_dir/compose/javascript.inc";
include "./lib/js/open_contacts.js";
}
$from = get_from();
if (!isset($msg)) { $msg = ''; }
if (!isset($to)) { $to = ''; }
if (!isset($cc)) { $cc = ''; }
if (!isset($bcc)) { $bcc = ''; }
if (!isset($subject)) { $subject = ''; }
if ($get_sig && $sig = imp_get_signature($imp->user, $imp->server)) $msg .= "\n\n\n" . $sig;
if (isset($actionID) && ($actionID == BOUNCE_COMPOSE)) {
if (!$this_client->lynx) {
include "$default->include_dir/compose/bounce.inc";
} else {
include "$default->include_dir/compose/lynx_bounce.inc";
}
} else {
if (!$this_client->lynx) {
include "$default->include_dir/compose/compose.inc";
} else {
include "$default->include_dir/compose/lynx_compose.inc";
}
}
require "$default->include_dir/generic-footer.inc";
?>
|