| | |
| | | | program/steps/mail/compose.inc | |
| | | | | |
| | | | This file is part of the Roundcube Webmail client | |
| | | | Copyright (C) 2005-2009, The Roundcube Dev Team | |
| | | | Copyright (C) 2005-2011, The Roundcube Dev Team | |
| | | | Licensed under the GNU GPL | |
| | | | | |
| | | | PURPOSE: | |
| | |
| | | $COMPOSE_ID = get_input_value('_id', RCUBE_INPUT_GET); |
| | | $_SESSION['compose'] = $_SESSION['compose_data_'.$COMPOSE_ID]; |
| | | |
| | | // give replicated session storage some time to synchronize |
| | | $retries = 0; |
| | | while ($COMPOSE_ID && !is_array($_SESSION['compose']) && $RCMAIL->db->is_replicated() && $retries++ < 5) { |
| | | usleep(500000); |
| | | $RCMAIL->session->reload(); |
| | | $_SESSION['compose'] = $_SESSION['compose_data_'.$COMPOSE_ID]; |
| | | } |
| | | |
| | | // Nothing below is called during message composition, only at "new/forward/reply/draft" initialization or |
| | | // if a compose-ID is given (i.e. when the compose step is opened in a new window/tab). |
| | | if (!is_array($_SESSION['compose'])) |
| | |
| | | 'param' => request2param(RCUBE_INPUT_GET), |
| | | 'mailbox' => $IMAP->get_mailbox_name(), |
| | | ); |
| | | |
| | | |
| | | // process values like "mailto:foo@bar.com?subject=new+message&cc=another" |
| | | if ($_SESSION['compose']['param']['to']) { |
| | | // #1486037: remove "mailto:" prefix |
| | |
| | | $_SESSION['compose']['param'][$f] = $val; |
| | | } |
| | | } |
| | | |
| | | |
| | | // select folder where to save the sent message |
| | | $_SESSION['compose']['param']['sent_mbox'] = $RCMAIL->config->get('sent_mbox'); |
| | | |
| | | |
| | | // pipe compose parameters thru plugins |
| | | $plugin = $RCMAIL->plugins->exec_hook('message_compose', $_SESSION['compose']); |
| | | $_SESSION['compose']['param'] = array_merge($_SESSION['compose']['param'], $plugin['param']); |
| | |
| | | 'path' => $attach, |
| | | ); |
| | | } |
| | | |
| | | |
| | | // save attachment if valid |
| | | if (($attachment['data'] && $attachment['name']) || ($attachment['path'] && file_exists($attachment['path']))) { |
| | | $attachment = rcmail::get_instance()->plugins->exec_hook('attachment_save', $attachment); |
| | | } |
| | | |
| | | |
| | | if ($attachment['status'] && !$attachment['abort']) { |
| | | unset($attachment['data'], $attachment['status'], $attachment['abort']); |
| | | $_SESSION['compose']['attachments'][$attachment['id']] = $attachment; |
| | |
| | | } |
| | | // set current mailbox in client environment |
| | | $OUTPUT->set_env('mailbox', $IMAP->get_mailbox_name()); |
| | | $OUTPUT->set_env('sig_above', $CONFIG['sig_above']); |
| | | $OUTPUT->set_env('top_posting', $CONFIG['top_posting']); |
| | | $OUTPUT->set_env('sig_above', $RCMAIL->config->get('sig_above', false)); |
| | | $OUTPUT->set_env('top_posting', $RCMAIL->config->get('top_posting', false)); |
| | | $OUTPUT->set_env('recipients_separator', trim($RCMAIL->config->get('recipients_separator', ','))); |
| | | |
| | | // get reference message and set compose mode |
| | | if ($msg_uid = $_SESSION['compose']['param']['draft_uid']) { |
| | |
| | | $MESSAGE->compose['from'] = $_SESSION['compose']['param']['from']; |
| | | } |
| | | else if (count($MESSAGE->identities)) { |
| | | // extract all recipients of the reply-message |
| | | $a_recipients = array(); |
| | | $a_names = array(); |
| | | |
| | | // extract all recipients of the reply-message |
| | | if (is_object($MESSAGE->headers) && in_array($compose_mode, array(RCUBE_COMPOSE_REPLY, RCUBE_COMPOSE_FORWARD))) |
| | | { |
| | | $a_to = $IMAP->decode_address_list($MESSAGE->headers->to); |
| | | foreach ($a_to as $addr) { |
| | | if (!empty($addr['mailto'])) |
| | | if (!empty($addr['mailto'])) { |
| | | $a_recipients[] = strtolower($addr['mailto']); |
| | | $a_names[] = $addr['name']; |
| | | } |
| | | } |
| | | |
| | | if (!empty($MESSAGE->headers->cc)) { |
| | | $a_cc = $IMAP->decode_address_list($MESSAGE->headers->cc); |
| | | foreach ($a_cc as $addr) { |
| | | if (!empty($addr['mailto'])) |
| | | if (!empty($addr['mailto'])) { |
| | | $a_recipients[] = strtolower($addr['mailto']); |
| | | $a_names[] = $addr['name']; |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | break; |
| | | } |
| | | // use replied message recipients |
| | | else if (in_array($ident['email_ascii'], $a_recipients)) { |
| | | $from_idx = $idx; |
| | | else if (($found = array_search($ident['email_ascii'], $a_recipients)) !== false) { |
| | | // match identity name, prefer default identity |
| | | if ($from_idx === null || ($a_names[$found] && $ident['name'] && $a_names[$found] == $ident['name'])) { |
| | | $from_idx = $idx; |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | // Set other headers |
| | | $a_recipients = array(); |
| | | $parts = array('to', 'cc', 'bcc', 'replyto', 'followupto'); |
| | | $separator = trim($RCMAIL->config->get('recipients_separator', ',')) . ' '; |
| | | |
| | | foreach ($parts as $header) { |
| | | $fvalue = ''; |
| | |
| | | $mailfollowup = $MESSAGE->headers->others['mail-followup-to']; |
| | | $mailreplyto = $MESSAGE->headers->others['mail-reply-to']; |
| | | |
| | | // Reply to mailing list... |
| | | if ($MESSAGE->reply_all == 'list' && $mailfollowup) |
| | | $fvalue = $mailfollowup; |
| | | else if ($MESSAGE->reply_all == 'list' |
| | | && preg_match('/<mailto:([^>]+)>/i', $MESSAGE->headers->others['list-post'], $m)) |
| | | $fvalue = $m[1]; |
| | | // Reply to... |
| | | else if ($MESSAGE->reply_all && $mailfollowup) |
| | | $fvalue = $mailfollowup; |
| | | else if ($mailreplyto) |
| | |
| | | $fvalue = $MESSAGE->headers->replyto; |
| | | else if (!empty($MESSAGE->headers->from)) |
| | | $fvalue = $MESSAGE->headers->from; |
| | | |
| | | // Reply to message sent by yourself (#1487074) |
| | | if (!empty($ident) && $fvalue == $ident['ident']) { |
| | | $fvalue = $MESSAGE->headers->to; |
| | | } |
| | | } |
| | | // add recipient of original message if reply to all |
| | | else if ($header == 'cc' && !empty($MESSAGE->reply_all) && $MESSAGE->reply_all != 'list') { |
| | | if ($v = $MESSAGE->headers->to) |
| | | $fvalue .= $v; |
| | | if ($v = $MESSAGE->headers->cc) |
| | | $fvalue .= (!empty($fvalue) ? ', ' : '') . $v; |
| | | $fvalue .= (!empty($fvalue) ? $separator : '') . $v; |
| | | } |
| | | } |
| | | else if (in_array($compose_mode, array(RCUBE_COMPOSE_DRAFT, RCUBE_COMPOSE_EDIT))) { |
| | |
| | | } |
| | | } |
| | | |
| | | $fvalue = implode(', ', $fvalue); |
| | | $fvalue = implode($separator, $fvalue); |
| | | } |
| | | |
| | | $MESSAGE->compose[$header] = $fvalue; |
| | |
| | | $attrib['name'] = '_store_target'; |
| | | $select = rcmail_mailbox_select(array_merge($attrib, array( |
| | | 'noselection' => '- '.rcube_label('dontsave').' -', |
| | | 'folder_filter' => 'mail' |
| | | 'folder_filter' => 'mail', |
| | | 'folder_rights' => 'w', |
| | | ))); |
| | | return $select->show($_SESSION['compose']['param']['sent_mbox'], $attrib); |
| | | } |