Changeset 320 in subversion for trunk/roundcubemail/program/steps/mail/compose.inc
- Timestamp:
- Aug 18, 2006 8:48:33 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/roundcubemail/program/steps/mail/compose.inc
r297 r320 20 20 */ 21 21 22 23 22 require_once('Mail/mimeDecode.php'); 23 24 // define constants for message compose mode 25 define('RCUBE_COMPOSE_REPLY', 0x0106); 26 define('RCUBE_COMPOSE_FORWARD', 0x0107); 27 define('RCUBE_COMPOSE_DRAFT', 0x0108); 28 24 29 25 30 // remove an attachment … … 39 44 40 45 $MESSAGE_FORM = NULL; 41 $REPLY_MESSAGE = NULL; 42 $FORWARD_MESSAGE = NULL; 43 $DRAFT_MESSAGE = NULL; 46 $MESSAGE = NULL; 44 47 45 48 // nothing below is called during message composition, only at "new/forward/reply/draft" initialization … … 54 57 55 58 56 if ($_GET['_reply_uid'] || $_GET['_forward_uid'] || $_GET['_draft_uid']) 57 { 58 $msg_uid = ($_GET['_reply_uid'] ? $_GET['_reply_uid'] : ($_GET['_forward_uid'] ? $_GET['_forward_uid'] : $_GET['_draft_uid'])); 59 59 // get reference message and set compose mode 60 if ($msg_uid = get_input_value('_reply_uid', RCUBE_INPUT_GET)) 61 $compose_mode = RCUBE_COMPOSE_REPLY; 62 else if ($msg_uid = get_input_value('_forward_uid', RCUBE_INPUT_GET)) 63 $compose_mode = RCUBE_COMPOSE_FORWARD; 64 else if ($msg_uid = get_input_value('_draft_uid', RCUBE_INPUT_GET)) 65 $compose_mode = RCUBE_COMPOSE_DRAFT; 66 67 68 if (!empty($msg_uid)) 69 { 60 70 // similar as in program/steps/mail/show.inc 61 $MESSAGE = array(); 62 $MESSAGE['headers'] = $IMAP->get_headers($msg_uid); 63 64 $MESSAGE['source'] = rcmail_message_source($msg_uid); 65 66 $mmd = new Mail_mimeDecode($MESSAGE['source']); 67 $MESSAGE['structure'] = $mmd->decode(array('include_bodies' => TRUE, 68 'decode_headers' => TRUE, 69 'decode_bodies' => FALSE)); 70 71 $MESSAGE = array('UID' => $msg_uid); 72 $MESSAGE['headers'] = &$IMAP->get_headers($msg_uid); 73 $MESSAGE['structure'] = &$IMAP->get_structure($msg_uid); 71 74 $MESSAGE['subject'] = $IMAP->decode_header($MESSAGE['headers']->subject); 72 $MESSAGE['parts'] = $mmd->getMimeNumbers($MESSAGE['structure']); 73 74 if ($_GET['_reply_uid']) 75 { 76 $REPLY_MESSAGE = &$MESSAGE; 77 $_SESSION['compose']['reply_uid'] = $_GET['_reply_uid']; 78 $_SESSION['compose']['reply_msgid'] = $REPLY_MESSAGE['headers']->messageID; 79 $_SESSION['compose']['references'] = $REPLY_MESSAGE['headers']->reference; 80 $_SESSION['compose']['references'] .= !empty($REPLY_MESSAGE['headers']->reference) ? ' ' : ''; 81 $_SESSION['compose']['references'] .= $REPLY_MESSAGE['headers']->messageID; 82 83 if ($_GET['_all']) 84 $REPLY_MESSAGE['reply_all'] = 1; 85 86 } 87 else if ($_GET['_forward_uid']) 88 { 89 $FORWARD_MESSAGE = $MESSAGE; 90 $_SESSION['compose']['forward_uid'] = $_GET['_forward_uid']; 91 } 92 else 93 { 94 $DRAFT_MESSAGE = $MESSAGE; 95 $_SESSION['compose']['draft_uid'] = $_GET['_draft_uid']; 75 $MESSAGE['parts'] = $IMAP->get_mime_numbers($MESSAGE['structure']); 76 77 if ($compose_mode == RCUBE_COMPOSE_REPLY) 78 { 79 $_SESSION['compose']['reply_uid'] = $msg_uid; 80 $_SESSION['compose']['reply_msgid'] = $MESSAGE['headers']->messageID; 81 $_SESSION['compose']['references'] = $MESSAGE['headers']->reference; 82 $_SESSION['compose']['references'] .= !empty($MESSAGE['headers']->reference) ? ' ' : ''; 83 $_SESSION['compose']['references'] .= $MESSAGE['headers']->messageID; 84 85 if (!empty($_GET['_all'])) 86 $MESSAGE['reply_all'] = 1; 87 } 88 else if ($compose_mode == RCUBE_COMPOSE_FORWARD) 89 { 90 $_SESSION['compose']['forward_uid'] = $msg_uid; 91 } 92 else if ($compose_mode == RCUBE_COMPOSE_DRAFT) 93 { 94 $_SESSION['compose']['draft_uid'] = $msg_uid; 96 95 } 97 96 … … 103 102 function rcmail_compose_headers($attrib) 104 103 { 105 global $IMAP, $ REPLY_MESSAGE, $DRAFT_MESSAGE, $DB;104 global $IMAP, $MESSAGE, $DB, $compose_mode; 106 105 static $sa_recipients = array(); 107 106 … … 138 137 } 139 138 else if (!empty($_GET['_to'])) 140 $fvalue = $_GET['_to'];139 $fvalue = get_input_value('_to', RCUBE_INPUT_GET); 141 140 142 141 case 'cc': … … 165 164 if ($fname && !empty($_POST[$fname])) 166 165 $fvalue = get_input_value($fname, RCUBE_INPUT_POST, TRUE); 167 else if ($header && is_object($REPLY_MESSAGE['headers'])) 166 167 else if ($header && $compose_mode == RCUBE_COMPOSE_REPLY) 168 168 { 169 169 // get recipent address(es) out of the message headers 170 if ($header=='to' && $REPLY_MESSAGE['headers']->replyto)171 $fvalue = $IMAP->decode_header($ REPLY_MESSAGE['headers']->replyto);172 173 else if ($header=='to' && $REPLY_MESSAGE['headers']->from)174 $fvalue = $IMAP->decode_header($ REPLY_MESSAGE['headers']->from);170 if ($header=='to' && !empty($MESSAGE['headers']->replyto)) 171 $fvalue = $IMAP->decode_header($MESSAGE['headers']->replyto); 172 173 else if ($header=='to' && !empty($MESSAGE['headers']->from)) 174 $fvalue = $IMAP->decode_header($MESSAGE['headers']->from); 175 175 176 176 // add recipent of original message if reply to all 177 else if ($header=='cc' && $REPLY_MESSAGE['reply_all'])177 else if ($header=='cc' && !empty($MESSAGE['reply_all'])) 178 178 { 179 if ($IMAP->decode_header($REPLY_MESSAGE['headers']->to)) 180 $fvalue .= $IMAP->decode_header($REPLY_MESSAGE['headers']->to); 181 182 if ($IMAP->decode_header($REPLY_MESSAGE['headers']->cc)) 183 { 184 if($fvalue) 185 $fvalue .= ', '; 186 187 $fvalue .= $IMAP->decode_header($REPLY_MESSAGE['headers']->cc); 188 } 179 if ($v = $IMAP->decode_header($MESSAGE['headers']->to)) 180 $fvalue .= $v; 181 182 if ($v = $IMAP->decode_header($MESSAGE['headers']->cc)) 183 $fvalue .= (!empty($fvalue) ? ', ' : '') . $v; 189 184 } 190 185 … … 196 191 foreach ($to_addresses as $addr_part) 197 192 { 198 if (!in_array($addr_part['mailto'], $sa_recipients) && (!$ REPLY_MESSAGE['FROM'] || !in_array($addr_part['mailto'], $REPLY_MESSAGE['FROM'])))193 if (!in_array($addr_part['mailto'], $sa_recipients) && (!$MESSAGE['FROM'] || !in_array($addr_part['mailto'], $MESSAGE['FROM']))) 199 194 { 200 195 $fvalue .= (strlen($fvalue) ? ', ':'').$addr_part['string']; … … 204 199 } 205 200 } 206 else if ($header && is_object($DRAFT_MESSAGE['headers']))201 else if ($header && $compose_mode == RCUBE_COMPOSE_DRAFT) 207 202 { 208 203 // get drafted headers 209 if ($header=='to' && $DRAFT_MESSAGE['headers']->to)210 $fvalue = $IMAP->decode_header($ DRAFT_MESSAGE['headers']->to);211 212 if ($header=='cc' && $DRAFT_MESSAGE['headers']->cc)213 $fvalue = $IMAP->decode_header($ DRAFT_MESSAGE['headers']->cc);214 215 if ($header=='bcc' && $DRAFT_MESSAGE['headers']->bcc)216 $fvalue = $IMAP->decode_header($ DRAFT_MESSAGE['headers']->bcc);204 if ($header=='to' && !empty($MESSAGE['headers']->to)) 205 $fvalue = $IMAP->decode_header($MESSAGE['headers']->to); 206 207 if ($header=='cc' && !empty($MESSAGE['headers']->cc)) 208 $fvalue = $IMAP->decode_header($MESSAGE['headers']->cc); 209 210 if ($header=='bcc' && !empty($MESSAGE['headers']->bcc)) 211 $fvalue = $IMAP->decode_header($MESSAGE['headers']->bcc); 217 212 218 213 } … … 242 237 function rcmail_compose_header_from($attrib) 243 238 { 244 global $IMAP, $ REPLY_MESSAGE, $DRAFT_MESSAGE, $DB, $OUTPUT, $JS_OBJECT_NAME;239 global $IMAP, $MESSAGE, $DB, $OUTPUT, $JS_OBJECT_NAME, $compose_mode; 245 240 246 241 // pass the following attributes to the form class … … 252 247 // extract all recipients of the reply-message 253 248 $a_recipients = array(); 254 if ($ REPLY_MESSAGE && is_object($REPLY_MESSAGE['headers']))255 { 256 $ REPLY_MESSAGE['FROM'] = array();257 258 $a_to = $IMAP->decode_address_list($ REPLY_MESSAGE['headers']->to);249 if ($compose_mode == RCUBE_COMPOSE_REPLY && is_object($MESSAGE['headers'])) 250 { 251 $MESSAGE['FROM'] = array(); 252 253 $a_to = $IMAP->decode_address_list($MESSAGE['headers']->to); 259 254 foreach ($a_to as $addr) 260 255 { … … 263 258 } 264 259 265 if (!empty($ REPLY_MESSAGE['headers']->cc))260 if (!empty($MESSAGE['headers']->cc)) 266 261 { 267 $a_cc = $IMAP->decode_address_list($ REPLY_MESSAGE['headers']->cc);262 $a_cc = $IMAP->decode_address_list($MESSAGE['headers']->cc); 268 263 foreach ($a_cc as $addr) 269 264 { … … 302 297 $from_id = $sql_arr['identity_id']; 303 298 304 if ($ REPLY_MESSAGE && is_array($REPLY_MESSAGE['FROM']))305 $ REPLY_MESSAGE['FROM'][] = $sql_arr['email'];306 307 if ( strstr($DRAFT_MESSAGE['headers']->from,$sql_arr['email']))299 if ($compose_mode == RCUBE_COMPOSE_REPLY && is_array($MESSAGE['FROM'])) 300 $MESSAGE['FROM'][] = $sql_arr['email']; 301 302 if ($compose_mode == RCUBE_COMPOSE_DRAFT && strstr($MESSAGE['headers']->from, $sql_arr['email'])) 308 303 $from_id = $sql_arr['identity_id']; 309 304 … … 312 307 // overwrite identity selection with post parameter 313 308 if (isset($_POST['_from'])) 314 $from_id = $_POST['_from'];309 $from_id = get_input_value('_from', RCUBE_INPUT_POST); 315 310 316 311 $out = $select_from->show($from_id); … … 336 331 function rcmail_compose_body($attrib) 337 332 { 338 global $CONFIG, $OUTPUT, $ REPLY_MESSAGE, $FORWARD_MESSAGE, $DRAFT_MESSAGE, $JS_OBJECT_NAME;333 global $CONFIG, $OUTPUT, $MESSAGE, $JS_OBJECT_NAME, $compose_mode; 339 334 340 335 list($form_start, $form_end) = get_form_tags($attrib); … … 354 349 355 350 // compose reply-body 356 else if ( is_array($REPLY_MESSAGE['parts']))357 { 358 $body = rcmail_first_text_part($ REPLY_MESSAGE['parts']);351 else if ($compose_mode == RCUBE_COMPOSE_REPLY) 352 { 353 $body = rcmail_first_text_part($MESSAGE); 359 354 if (strlen($body)) 360 355 $body = rcmail_create_reply_body($body); … … 362 357 363 358 // forward message body inline 364 else if ( is_array($FORWARD_MESSAGE['parts']))365 { 366 $body = rcmail_first_text_part($ FORWARD_MESSAGE['parts']);359 else if ($compose_mode == RCUBE_COMPOSE_FORWARD) 360 { 361 $body = rcmail_first_text_part($MESSAGE); 367 362 if (strlen($body)) 368 363 $body = rcmail_create_forward_body($body); … … 370 365 371 366 // forward message body inline 372 else if ( is_array($DRAFT_MESSAGE['parts']))373 { 374 $body = rcmail_first_text_part($ DRAFT_MESSAGE['parts']);367 else if ($compose_mode == RCUBE_COMPOSE_DRAFT) 368 { 369 $body = rcmail_first_text_part($MESSAGE); 375 370 if (strlen($body)) 376 371 $body = rcmail_create_draft_body($body); … … 379 374 $out = $form_start ? "$form_start\n" : ''; 380 375 381 $saveid = new hiddenfield(array('name' => '_draft_saveid', 'value' => str_replace(array('<','>'),"",$ DRAFT_MESSAGE['headers']->messageID) ));376 $saveid = new hiddenfield(array('name' => '_draft_saveid', 'value' => str_replace(array('<','>'),"",$MESSAGE['headers']->messageID) )); 382 377 $out .= $saveid->show(); 383 378 … … 420 415 function rcmail_create_reply_body($body) 421 416 { 422 global $IMAP, $ REPLY_MESSAGE;417 global $IMAP, $MESSAGE; 423 418 424 419 // soft-wrap message first … … 441 436 // add title line 442 437 $pefix = sprintf("\n\n\nOn %s, %s wrote:\n", 443 $ REPLY_MESSAGE['headers']->date,444 $IMAP->decode_header($ REPLY_MESSAGE['headers']->from));438 $MESSAGE['headers']->date, 439 $IMAP->decode_header($MESSAGE['headers']->from)); 445 440 446 441 … … 458 453 function rcmail_create_forward_body($body) 459 454 { 460 global $IMAP, $ FORWARD_MESSAGE;455 global $IMAP, $MESSAGE; 461 456 462 457 // soft-wrap message first … … 464 459 465 460 $prefix = sprintf("\n\n\n-------- Original Message --------\nSubject: %s\nDate: %s\nFrom: %s\nTo: %s\n\n", 466 $ FORWARD_MESSAGE['subject'],467 $ FORWARD_MESSAGE['headers']->date,468 $IMAP->decode_header($ FORWARD_MESSAGE['headers']->from),469 $IMAP->decode_header($ FORWARD_MESSAGE['headers']->to));470 461 $MESSAGE['subject'], 462 $MESSAGE['headers']->date, 463 $IMAP->decode_header($MESSAGE['headers']->from), 464 $IMAP->decode_header($MESSAGE['headers']->to)); 465 471 466 // add attachments 472 if (!isset($_SESSION['compose']['forward_attachments']) && is_array($FORWARD_MESSAGE['parts']) && sizeof($FORWARD_MESSAGE['parts'])>1) 473 { 474 $temp_dir = rcmail_create_compose_tempdir(); 475 476 if (!is_array($_SESSION['compose']['attachments'])) 477 $_SESSION['compose']['attachments'] = array(); 478 479 foreach ($FORWARD_MESSAGE['parts'] as $part) 467 if (!isset($_SESSION['compose']['forward_attachments']) && 468 is_array($MESSAGE['parts']) && sizeof($MESSAGE['parts'])>1) 469 rcmail_write_compose_attachments($MESSAGE); 470 471 return $prefix.$body; 472 } 473 474 475 function rcmail_create_draft_body($body) 476 { 477 global $IMAP, $MESSAGE; 478 479 // add attachments 480 if (!isset($_SESSION['compose']['forward_attachments']) && 481 is_array($MESSAGE['parts']) && sizeof($MESSAGE['parts'])>1) 482 rcmail_write_compose_attachments($MESSAGE); 483 484 return $body; 485 } 486 487 488 function rcmail_write_compose_attachments(&$message) 489 { 490 global $IMAP; 491 492 $temp_dir = rcmail_create_compose_tempdir(); 493 494 if (!is_array($_SESSION['compose']['attachments'])) 495 $_SESSION['compose']['attachments'] = array(); 496 497 foreach ($message['parts'] as $pid => $part) 498 { 499 if ($part->ctype_primary != 'message' && $part->ctype_primary != 'text' && 500 ($part->disposition=='attachment' || $part->disposition=='inline' || $part->headers['content-id'] || 501 (empty($part->disposition) && ($part->d_parameters['filename'] || $part->ctype_parameters['name'])))) 480 502 { 481 if ($part->disposition=='attachment' || $part->disposition=='inline' || $part->headers['content-id'] ||482 (empty($part->disposition) && ($part->d_parameters['filename'] || $part->ctype_parameters['name'])))503 $tmp_path = tempnam($temp_dir, 'rcmAttmnt'); 504 if ($fp = fopen($tmp_path, 'w')) 483 505 { 484 $tmp_path = tempnam($temp_dir, 'rcmAttmnt'); 485 if ($fp = fopen($tmp_path, 'w')) 486 { 487 fwrite($fp, $IMAP->mime_decode($part->body, $part->headers['content-transfer-encoding'])); 488 fclose($fp); 489 490 if ($part->d_parameters['filename']) 491 $_SESSION['compose']['attachments'][] = array('name' => $part->d_parameters['filename'], 492 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary, 493 'path' => $tmp_path); 494 495 else if ($part->ctype_parameters['name']) 496 $_SESSION['compose']['attachments'][] = array('name' => $part->ctype_parameters['name'], 497 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary, 498 'path' => $tmp_path); 499 500 else if ($part->headers['content-description']) 501 $_SESSION['compose']['attachments'][] = array('name' => $part->headers['content-description'], 502 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary, 503 'path' => $tmp_path); 504 } 505 } 506 } 507 508 $_SESSION['compose']['forward_attachments'] = TRUE; 509 } 510 511 return $prefix.$body; 512 } 513 514 function rcmail_create_draft_body($body) 515 { 516 global $IMAP, $DRAFT_MESSAGE; 517 518 // add attachments 519 if (!isset($_SESSION['compose']['forward_attachments']) && is_array($DRAFT_MESSAGE['parts']) && sizeof($DRAFT_MESSAGE['parts'])>1) 520 { 521 $temp_dir = rcmail_create_compose_tempdir(); 522 523 if (!is_array($_SESSION['compose']['attachments'])) 524 $_SESSION['compose']['attachments'] = array(); 525 526 foreach ($DRAFT_MESSAGE['parts'] as $part) 527 { 528 if ($part->disposition=='attachment' || $part->disposition=='inline' || $part->headers['content-id'] || 529 (empty($part->disposition) && ($part->d_parameters['filename'] || $part->ctype_parameters['name']))) 530 { 531 $tmp_path = tempnam($temp_dir, 'rcmAttmnt'); 532 if ($fp = fopen($tmp_path, 'w')) 533 { 534 fwrite($fp, $IMAP->mime_decode($part->body, $part->headers['content-transfer-encoding'])); 535 fclose($fp); 536 537 if ($part->d_parameters['filename']) 538 $_SESSION['compose']['attachments'][] = array('name' => $part->d_parameters['filename'], 539 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary, 540 'path' => $tmp_path); 541 542 else if ($part->ctype_parameters['name']) 543 $_SESSION['compose']['attachments'][] = array('name' => $part->ctype_parameters['name'], 544 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary, 545 'path' => $tmp_path); 546 547 else if ($part->headers['content-description']) 548 $_SESSION['compose']['attachments'][] = array('name' => $part->headers['content-description'], 549 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary, 550 'path' => $tmp_path); 551 } 506 fwrite($fp, $IMAP->get_message_part($message['UID'], $pid, $part->encoding)); 507 fclose($fp); 508 509 $filename = !empty($part->d_parameters['filename']) ? $part->d_parameters['filename'] : 510 (!empty($part->ctype_parameters['name']) ? $part->ctype_parameters['name'] : 511 (!empty($part->headers['content-description']) ? $part->headers['content-description'] : 'file')); 512 513 $_SESSION['compose']['attachments'][] = array( 514 'name' => rcube_imap::decode_mime_string($filename), 515 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary, 516 'path' => $tmp_path 517 ); 552 518 } 553 519 } 554 555 $_SESSION['compose']['forward_attachments'] = TRUE; 556 } 557 558 return $body; 520 } 521 522 $_SESSION['compose']['forward_attachments'] = TRUE; 559 523 } 560 524 … … 562 526 function rcmail_compose_subject($attrib) 563 527 { 564 global $CONFIG, $ REPLY_MESSAGE, $FORWARD_MESSAGE, $DRAFT_MESSAGE;528 global $CONFIG, $MESSAGE, $compose_mode; 565 529 566 530 list($form_start, $form_end) = get_form_tags($attrib); … … 577 541 578 542 // create a reply-subject 579 else if ( isset($REPLY_MESSAGE['subject']))580 { 581 if (eregi('^re:', $ REPLY_MESSAGE['subject']))582 $subject = $ REPLY_MESSAGE['subject'];543 else if ($compose_mode == RCUBE_COMPOSE_REPLY) 544 { 545 if (eregi('^re:', $MESSAGE['subject'])) 546 $subject = $MESSAGE['subject']; 583 547 else 584 $subject = 'Re: '.$ REPLY_MESSAGE['subject'];548 $subject = 'Re: '.$MESSAGE['subject']; 585 549 } 586 550 587 551 // create a forward-subject 588 else if ( isset($FORWARD_MESSAGE['subject']))589 { 590 if (eregi('^fwd:', $ REPLY_MESSAGE['subject']))591 $subject = $ FORWARD_MESSAGE['subject'];552 else if ($compose_mode == RCUBE_COMPOSE_FORWARD) 553 { 554 if (eregi('^fwd:', $MESSAGE['subject'])) 555 $subject = $MESSAGE['subject']; 592 556 else 593 $subject = 'Fwd: '.$ FORWARD_MESSAGE['subject'];557 $subject = 'Fwd: '.$MESSAGE['subject']; 594 558 } 595 559 596 560 // creeate a draft-subject 597 else if ( isset($DRAFT_MESSAGE['subject']))598 $subject = $ DRAFT_MESSAGE['subject'];561 else if ($compose_mode == RCUBE_COMPOSE_DRAFT) 562 $subject = $MESSAGE['subject']; 599 563 600 564 $out = $form_start ? "$form_start\n" : '';
Note: See TracChangeset
for help on using the changeset viewer.
