X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Fcompose.php;h=d4b3d7c18cbd9f5703c51f02378cc4cfb4820691;hb=fe868193d60150226a596984dac9eaa337b1e6ff;hp=22935f9554cc715f87bce7fda6f304399d05dc52;hpb=0904405501f3ab2be2098c2bc387bc07be6d0592;p=squirrelmail.git diff --git a/src/compose.php b/src/compose.php index 22935f95..7f1d6809 100644 --- a/src/compose.php +++ b/src/compose.php @@ -3,7 +3,7 @@ /** * compose.php * - * Copyright (c) 1999-2002 The SquirrelMail Project Team + * Copyright (c) 1999-2004 The SquirrelMail Project Team * Licensed under the GNU GPL. For full terms see the file COPYING. * * This code sends a mail. @@ -15,169 +15,349 @@ * - Save As Draft * * $Id$ + * @package squirrelmail */ -require_once('../src/validate.php'); -require_once('../functions/imap.php'); -require_once('../functions/date.php'); -require_once('../functions/mime.php'); -require_once('../functions/smtp.php'); -require_once('../functions/display_messages.php'); -require_once('../functions/plugin.php'); +/** Path for SquirrelMail required files. */ +define('SM_PATH','../'); + +/* SquirrelMail required files. */ +require_once(SM_PATH . 'include/validate.php'); +require_once(SM_PATH . 'functions/global.php'); +require_once(SM_PATH . 'functions/imap.php'); +require_once(SM_PATH . 'functions/date.php'); +require_once(SM_PATH . 'functions/mime.php'); +require_once(SM_PATH . 'functions/plugin.php'); +require_once(SM_PATH . 'functions/display_messages.php'); +require_once(SM_PATH . 'class/deliver/Deliver.class.php'); +require_once(SM_PATH . 'functions/addressbook.php'); +require_once(SM_PATH . 'functions/identity.php'); +require_once(SM_PATH . 'functions/forms.php'); + +/* --------------------- Get globals ------------------------------------- */ +/** COOKIE VARS */ +sqgetGlobalVar('key', $key, SQ_COOKIE); + +/** SESSION VARS */ +sqgetGlobalVar('username', $username, SQ_SESSION); +sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION); +sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION); +sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); + +sqgetGlobalVar('composesession', $composesession, SQ_SESSION); +sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION); + +/** SESSION/POST/GET VARS */ +sqgetGlobalVar('session',$session); +sqgetGlobalVar('mailbox',$mailbox); +if(!sqgetGlobalVar('identity',$identity)) { + $identity=0; +} +sqgetGlobalVar('send_to',$send_to); +sqgetGlobalVar('send_to_cc',$send_to_cc); +sqgetGlobalVar('send_to_bcc',$send_to_bcc); +sqgetGlobalVar('subject',$subject); +sqgetGlobalVar('body',$body); +sqgetGlobalVar('mailprio',$mailprio); +sqgetGlobalVar('request_mdn',$request_mdn); +sqgetGlobalVar('request_dr',$request_dr); +sqgetGlobalVar('html_addr_search',$html_addr_search); +sqgetGlobalVar('mail_sent',$mail_sent); +sqgetGlobalVar('passed_id',$passed_id); +sqgetGlobalVar('passed_ent_id',$passed_ent_id); +sqgetGlobalVar('send',$send); + +sqgetGlobalVar('attach',$attach); + +sqgetGlobalVar('draft',$draft); +sqgetGlobalVar('draft_id',$draft_id); +sqgetGlobalVar('ent_num',$ent_num); +sqgetGlobalVar('saved_draft',$saved_draft); +sqgetGlobalVar('delete_draft',$delete_draft); +sqgetGlobalVar('startMessage',$startMessage); + +/** POST VARS */ +sqgetGlobalVar('sigappend', $sigappend, SQ_POST); +sqgetGlobalVar('from_htmladdr_search', $from_htmladdr_search, SQ_POST); +sqgetGlobalVar('addr_search_done', $html_addr_search_done, SQ_POST); +sqgetGlobalVar('send_to_search', $send_to_search, SQ_POST); +sqgetGlobalVar('do_delete', $do_delete, SQ_POST); +sqgetGlobalVar('delete', $delete, SQ_POST); +sqgetGlobalVar('restoremessages', $restoremessages, SQ_POST); +if ( sqgetGlobalVar('return', $temp, SQ_POST) ) { + $html_addr_search_done = 'Use Addresses'; +} + +/** GET VARS */ +sqgetGlobalVar('attachedmessages', $attachedmessages, SQ_GET); + +/** get smaction */ +if ( !sqgetGlobalVar('smaction',$action) ) +{ + if ( sqgetGlobalVar('smaction_reply',$tmp) ) $action = 'reply'; + if ( sqgetGlobalVar('smaction_reply_all',$tmp) ) $action = 'reply_all'; + if ( sqgetGlobalVar('smaction_forward',$tmp) ) $action = 'forward'; + if ( sqgetGlobalVar('smaction_attache',$tmp) ) $action = 'forward_as_attachment'; + if ( sqgetGlobalVar('smaction_draft',$tmp) ) $action = 'draft'; + if ( sqgetGlobalVar('smaction_edit_new',$tmp) ) $action = 'edit_as_new'; +} + +/* Location (For HTTP 1.1 Header("Location: ...") redirects) */ +$location = get_location(); +/* Identities (fetch only once) */ +$idents = get_identities(); /* --------------------- Specific Functions ------------------------------ */ -/** - * Wraps text at $wrap characters - * - * Has a problem with special HTML characters, so call this before - * you do character translation. - * - * Specifically, ' comes up as 5 characters instead of 1. - * This should not add newlines to the end of lines. - */ -function sqWordWrap(&$line, $wrap) { - ereg("^([\t >]*)([^\t >].*)?$", $line, $regs); - $beginning_spaces = $regs[1]; - if (isset($regs[2])) { - $words = explode(' ', $regs[2]); - } else { - $words = ''; - } - - $i = 0; - $line = $beginning_spaces; - - while ($i < count($words)) { - /* Force one word to be on a line (minimum) */ - $line .= $words[$i]; - $line_len = strlen($beginning_spaces) + strlen($words[$i]) + 2; - if (isset($words[$i + 1])) - $line_len += strlen($words[$i + 1]); - $i ++; - - /* Add more words (as long as they fit) */ - while ($line_len < $wrap && $i < count($words)) { - $line .= ' ' . $words[$i]; - $i++; - if (isset($words[$i])) - $line_len += strlen($words[$i]) + 1; - else - $line_len += 1; - } - - /* Skip spaces if they are the first thing on a continued line */ - while (!isset($words[$i]) && $i < count($words)) { - $i ++; - } - - /* Go to the next line if we have more to process */ - if ($i < count($words)) { - $line .= "\n" . $beginning_spaces; +function replyAllString($header) { + global $include_self_reply_all, $idents; + $excl_ar = array(); + /** + * 1) Remove the addresses we'll be sending the message 'to' + */ + $url_replytoall_avoid_addrs = ''; + if (isset($header->replyto)) { + $excl_ar = $header->getAddr_a('replyto'); + } + /** + * 2) Remove our identities from the CC list (they still can be in the + * TO list) only if $include_self_reply_all is turned off + */ + if (!$include_self_reply_all) { + foreach($idents as $id) { + $excl_ar[strtolower(trim($id['email_address']))] = ''; } - } + } + + /** + * 3) get the addresses. + */ + $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar); + + /** + * 4) generate the string. + */ + $url_replytoallcc = ''; + foreach( $url_replytoall_ar as $email => $personal) { + if ($personal) { + // if personal name contains address separator then surround + // the personal name with double quotes. + if (strpos($personal,',') !== false) { + $personal = '"'.$personal.'"'; + } + $url_replytoallcc .= ", $personal <$email>"; + } else { + $url_replytoallcc .= ', '. $email; + } + } + $url_replytoallcc = substr($url_replytoallcc,2); + + return $url_replytoallcc; } -/** - * Does the opposite of sqWordWrap() - */ -function sqUnWordWrap(&$body) { - $lines = explode("\n", $body); - $body = ''; - $PreviousSpaces = ''; - for ($i = 0; $i < count($lines); $i ++) { - ereg("^([\t >]*)([^\t >].*)?$", $lines[$i], $regs); - $CurrentSpaces = $regs[1]; - if (isset($regs[2])) { - $CurrentRest = $regs[2]; - } - - if ($i == 0) { - $PreviousSpaces = $CurrentSpaces; - $body = $lines[$i]; - } else if (($PreviousSpaces == $CurrentSpaces) /* Do the beginnings match */ - && (strlen($lines[$i - 1]) > 65) /* Over 65 characters long */ - && strlen($CurrentRest)) { /* and there's a line to continue with */ - $body .= ' ' . $CurrentRest; - } else { - $body .= "\n" . $lines[$i]; - $PreviousSpaces = $CurrentSpaces; - } +function getReplyCitation($orig_from, $orig_date) { + global $reply_citation_style, $reply_citation_start, $reply_citation_end; + $orig_from = decodeHeader($orig_from->getAddress(false),false,false,true); +// $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false); + /* First, return an empty string when no citation style selected. */ + if (($reply_citation_style == '') || ($reply_citation_style == 'none')) { + return ''; + } + + /* Make sure our final value isn't an empty string. */ + if ($orig_from == '') { + return ''; + } + + /* Otherwise, try to select the desired citation style. */ + switch ($reply_citation_style) { + case 'author_said': + $start = ''; + $end = ' ' . _("said") . ':'; + break; + case 'quote_who': + $start = '<' . _("quote") . ' ' . _("who") . '="'; + $end = '">'; + break; + case 'date_time_author': + $start = 'On ' . getLongDateString($orig_date) . ', '; + $end = ' ' . _("said") . ':'; + break; + case 'user-defined': + $start = $reply_citation_start . + ($reply_citation_start == '' ? '' : ' '); + $end = $reply_citation_end; + break; + default: + return ''; } - $body .= "\n"; + + /* Build and return the citation string. */ + return ($start . $orig_from . $end . "\n"); } +function getforwardHeader($orig_header) { + global $editor_size; + + $display = array( _("Subject") => strlen(_("Subject")), + _("From") => strlen(_("From")), + _("Date") => strlen(_("Date")), + _("To") => strlen(_("To")), + _("Cc") => strlen(_("Cc")) ); + $maxsize = max($display); + $indent = str_pad('',$maxsize+2); + foreach($display as $key => $val) { + $display[$key] = $key .': '. str_pad('', $maxsize - $val); + } + $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false,true); + $from = str_replace(' ',' ',$from); + $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false,true); + $to = str_replace(' ',' ',$to); + $subject = decodeHeader($orig_header->subject,false,false,true); + $subject = str_replace(' ',' ',$subject); + $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH) . + "\n". $display[_("Subject")] . $subject . "\n" . + $display[_("From")] . $from . "\n" . + $display[_("Date")] . getLongDateString( $orig_header->date ). "\n" . + $display[_("To")] . $to . "\n"; + if ($orig_header->cc != array() && $orig_header->cc !='') { + $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false,true); + $cc = str_replace(' ',' ',$cc); + $bodyTop .= $display[_("Cc")] .$cc . "\n"; + } + $bodyTop .= str_pad('', $editor_size -2 , '-') . + "\n\n"; + return $bodyTop; +} /* ----------------------------------------------------------------------- */ -if (!isset($attachments)) { - $attachments = array(); - session_register('attachments'); +/* + * If the session is expired during a post this restores the compose session + * vars. + */ +if (sqsession_is_registered('session_expired_post')) { + sqgetGlobalVar('session_expired_post', $session_expired_post, SQ_SESSION); + /* + * extra check for username so we don't display previous post data from + * another user during this session. + */ + if ($session_expired_post['username'] != $username) { + unset($session_expired_post); + sqsession_unregister('session_expired_post'); + session_write_close(); + } else { + foreach ($session_expired_post as $postvar => $val) { + if (isset($val)) { + $$postvar = $val; + } else { + $$postvar = ''; + } + } + $compose_messages = unserialize(urldecode($restoremessages)); + sqsession_register($compose_messages,'compose_messages'); + sqsession_register($composesession,'composesession'); + if (isset($send)) { + unset($send); + } + $session_expired = true; + } + unset($session_expired_post); + sqsession_unregister('session_expired_post'); + session_write_close(); + if (!isset($mailbox)) { + $mailbox = ''; + } + if ($compose_new_win == '1') { + compose_Header($color, $mailbox); + } else { + displayPageHeader($color, $mailbox); + } + showInputForm($session, false); + exit(); } - if (!isset($composesession)) { $composesession = 0; - session_register('composesession'); + sqsession_register(0,'composesession'); } -if (!isset($session)) { - $session = "$composesession" +1; - $composesession = $session; -} +if (!isset($session) || (isset($newmessage) && $newmessage)) { + sqsession_unregister('composesession'); + $session = "$composesession" +1; + $composesession = $session; + sqsession_register($composesession,'composesession'); +} +if (!isset($compose_messages)) { + $compose_messages = array(); +} +if (!isset($compose_messages[$session]) || ($compose_messages[$session] == NULL)) { +/* if (!array_key_exists($session, $compose_messages)) { /* We can only do this in PHP >= 4.1 */ + $composeMessage = new Message(); + $rfc822_header = new Rfc822Header(); + $composeMessage->rfc822_header = $rfc822_header; + $composeMessage->reply_rfc822_header = ''; + $compose_messages[$session] = $composeMessage; + sqsession_register($compose_messages,'compose_messages'); +} else { + $composeMessage=$compose_messages[$session]; +} if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None')) { $mailbox = 'INBOX'; } -if (isset($draft)) { - include_once ('../src/draft_actions.php'); - if (! isset($reply_id)) { - $reply_id = 0; - } - if (! isset($MDN)) { - $MDN = 'False'; - } - if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id, $MDN, $session)) { +if ($draft) { + /* + * Set $default_charset to correspond with the user's selection + * of language interface. + */ + set_my_charset(); + $composeMessage=$compose_messages[$session]; + if (! deliverMessage($composeMessage, true)) { showInputForm($session); exit(); } else { + unset($compose_messages[$session]); $draft_message = _("Draft Email Saved"); /* If this is a resumed draft, then delete the original */ if(isset($delete_draft)) { - Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) . + Header("Location: $location/delete_message.php?mailbox=" . urlencode($draft_folder) . "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes"); exit(); } else { if ($compose_new_win == '1') { - Header("Location: compose.php?saved_draft=yes&session=$composesession"); - exit(); + Header("Location: $location/compose.php?saved_draft=yes&session=$composesession"); + exit(); } else { - Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort". - "&startMessage=1¬e=$draft_message"); - exit(); + Header("Location: $location/right_main.php?mailbox=$draft_folder&sort=$sort". + "&startMessage=1¬e=".urlencode($draft_message)); + exit(); } } } } -if (isset($send)) { - if (isset($HTTP_POST_FILES['attachfile']) && - $HTTP_POST_FILES['attachfile']['tmp_name'] && - $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') { +if ($send) { + if (isset($_FILES['attachfile']) && + $_FILES['attachfile']['tmp_name'] && + $_FILES['attachfile']['tmp_name'] != 'none') { $AttachFailure = saveAttachedFiles($session); } if (checkInput(false) && !isset($AttachFailure)) { + if ($mailbox == "All Folders") { + /* We entered compose via the search results page */ + $mailbox="INBOX"; /* Send 'em to INBOX, that's safe enough */ + } $urlMailbox = urlencode (trim($mailbox)); - if (! isset($reply_id)) { - $reply_id = 0; + if (! isset($passed_id)) { + $passed_id = 0; } /* * Set $default_charset to correspond with the user's selection * of language interface. */ set_my_charset(); - /* * This is to change all newlines to \n * We'll change them to \r\n later (in the sendMessage function) @@ -188,8 +368,7 @@ if (isset($send)) { /* * Rewrap $body so that no line is bigger than $editor_size * This should only really kick in the sqWordWrap function - * if the browser doesn't support "HARD" as the wrap type - * Or, in Opera's case, something goes wrong. + * if the browser doesn't support "VIRTUAL" as the wrap type. */ $body = explode("\n", $body); $newBody = ''; @@ -200,43 +379,36 @@ if (isset($send)) { if (strlen($line) <= $editor_size + 1) { $newBody .= $line . "\n"; } else { - sqWordWrap($line, $editor_size) . "\n"; - $newBody .= $line; + sqWordWrap($line, $editor_size); + $newBody .= $line . "\n"; + } + } $body = $newBody; - do_hook('compose_send'); + $composeMessage=$compose_messages[$session]; - $MDN = False; // we are not sending a mdn response - if (! isset($mailprio)) { - $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc, - $subject, $body, $reply_id, $MDN, '', $session); - } else { - $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc, - $subject, $body, $reply_id, $MDN, $mailprio, $session); - } + $Result = deliverMessage($composeMessage); if (! $Result) { showInputForm($session); exit(); } + unset($compose_messages[$session]); if ( isset($delete_draft)) { - Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ). + Header("Location: $location/delete_message.php?mailbox=" . urlencode( $draft_folder ). "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes"); exit(); } if ($compose_new_win == '1') { - Header("Location: compose.php?mail_sent=yes&session=$composesession"); + + Header("Location: $location/compose.php?mail_sent=yes"); } else { - Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort". - "&startMessage=1"); + Header("Location: $location/right_main.php?mailbox=$urlMailbox&sort=$sort". + "&startMessage=$startMessage&mail_sent=yes"); } } else { - /* - *$imapConnection = sqimap_login($username, $key, $imapServerAddress, - * $imapPort, 0); - */ if ($compose_new_win == '1') { compose_Header($color, $mailbox); } @@ -247,7 +419,6 @@ if (isset($send)) { plain_error_message(_("Could not move/copy file. File not attached"), $color); } - checkInput(true); showInputForm($session); /* sqimap_logout($imapConnection); */ @@ -284,10 +455,10 @@ if (isset($send)) { } showInputForm($session); } elseif (isset($html_addr_search)) { - if (isset($HTTP_POST_FILES['attachfile']) && - $HTTP_POST_FILES['attachfile']['tmp_name'] && - $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') { - if (saveAttachedFiles($session)) { + if (isset($_FILES['attachfile']) && + $_FILES['attachfile']['tmp_name'] && + $_FILES['attachfile']['tmp_name'] != 'none') { + if(saveAttachedFiles($session)) { plain_error_message(_("Could not move/copy file. File not attached"), $color); } } @@ -309,15 +480,8 @@ if (isset($send)) { showInputForm($session); } elseif (isset($sigappend)) { - $idents = getPref($data_dir, $username, 'identities', 0); - if ($idents > 1) { - if ($identity == 'default') { - $no = 'g'; - } else { - $no = $identity; - } - $signature = getSig($data_dir, $username, $no); - } + $signature = $idents[$identity]['signature']; + $body .= "\n\n".($prefix_sig==true? "-- \n":'').$signature; if ($compose_new_win == '1') { compose_Header($color, $mailbox); @@ -333,475 +497,694 @@ elseif (isset($sigappend)) { displayPageHeader($color, $mailbox); } - $hashed_attachment_dir = getHashedDir($username, $attachment_dir); if (isset($delete) && is_array($delete)) { + $composeMessage = $compose_messages[$session]; foreach($delete as $index) { - $attached_file = $hashed_attachment_dir . '/' - . $attachments[$index]['localfilename']; - unlink ($attached_file); - unset ($attachments[$index]); + $attached_file = $composeMessage->entities[$index]->att_local_name; + unlink ($attached_file); + unset ($composeMessage->entities[$index]); } - } - - showInputForm($session); - -} elseif (isset($attachedmessages)) { - - /* - * This handles the case if we attache message - */ - $imapConnection = sqimap_login($username, $key, $imapServerAddress, - $imapPort, 0); - if ($compose_new_win == '1') { - compose_Header($color, $mailbox); + $new_entities = array(); + foreach ($composeMessage->entities as $entity) { + $new_entities[] = $entity; } - else { - displayPageHeader($color, $mailbox); - } - - $newmail = true; - - newMail(); + $composeMessage->entities = $new_entities; + $compose_messages[$session] = $composeMessage; + sqsession_register($compose_messages, 'compose_messages'); + } showInputForm($session); - sqimap_logout($imapConnection); - } else { /* * This handles the default case as well as the error case - * (they had the same code) --> if (isset($smtpErrors)) + * (they had the same code) --> if (isset($smtpErrors)) */ - $imapConnection = sqimap_login($username, $key, $imapServerAddress, - $imapPort, 0); - if ($compose_new_win == '1') { - compose_Header($color, $mailbox); - } - else { - displayPageHeader($color, $mailbox); - } - $newmail = true; + if ($compose_new_win == '1') { + compose_Header($color, $mailbox); + } else { + displayPageHeader($color, $mailbox); + } - ClearAttachments($session); + $newmail = true; - if (isset($forward_id) && $forward_id && isset($ent_num) && $ent_num) { - getAttachments(0, $session); + if (!isset($passed_ent_id)) { + $passed_ent_id = ''; } - - if (isset($draft_id) && $draft_id && isset($ent_num) && $ent_num) { - getAttachments(0, $session); + if (!isset($passed_id)) { + $passed_id = ''; + } + if (!isset($mailbox)) { + $mailbox = ''; + } + if (!isset($action)) { + $action = ''; } - newMail($session); - showInputForm($session); - sqimap_logout($imapConnection); + $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session); + + /* in case the origin is not read_body.php */ + if (isset($send_to)) { + $values['send_to'] = $send_to; + } + if (isset($send_to_cc)) { + $values['send_to_cc'] = $send_to_cc; + } + if (isset($send_to_bcc)) { + $values['send_to_bcc'] = $send_to_bcc; + } + if (isset($subject)) { + $values['subject'] = $subject; + } + showInputForm($session, $values); } exit(); - /**************** Only function definitions go below *************/ +function getforwardSubject($subject) +{ + if ((substr(strtolower($subject), 0, 4) != 'fwd:') && + (substr(strtolower($subject), 0, 5) != '[fwd:') && + (substr(strtolower($subject), 0, 6) != '[ fwd:')) { + $subject = '[Fwd: ' . $subject . ']'; + } + return $subject; +} /* This function is used when not sending or adding attachments */ -function newMail () { - global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body, - $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc, $editor_size, - $draft_id, $use_signature, $composesession, $forward_cc; - - $send_to = decodeHeader($send_to, false); - $send_to_cc = decodeHeader($send_to_cc, false); - $send_to_bcc = decodeHeader($send_to_bcc, false); +function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') { + global $editor_size, $default_use_priority, $body, $idents, + $use_signature, $composesession, $data_dir, $username, + $username, $key, $imapServerAddress, $imapPort, $compose_messages, + $composeMessage; + global $languages, $squirrelmail_language, $default_charset; - if ($forward_id) { - $id = $forward_id; - } elseif ($reply_id) { - $id = $reply_id; - } + $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = ''; + $mailprio = 3; - if ($draft_id){ - $id = $draft_id; - $use_signature = FALSE; - } + if ($passed_id) { + $imapConnection = sqimap_login($username, $key, $imapServerAddress, + $imapPort, 0); - if (isset($id)) { sqimap_mailbox_select($imapConnection, $mailbox); - $message = sqimap_get_message($imapConnection, $id, $mailbox); - $orig_header = $message->header; - if ($ent_num) { - $message = getEntity($message, $ent_num); - } - if ($message->header->type0 == 'text' || - $message->header->type1 == 'message') { - if ($ent_num) { - $body = decodeBody( - mime_fetch_body($imapConnection, $id, $ent_num), - $message->header->encoding); - } else { - $body = decodeBody( - mime_fetch_body($imapConnection, $id, 1), - $message->header->encoding); + $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); + + $body = ''; + if ($passed_ent_id) { + /* redefine the messsage in case of message/rfc822 */ + $message = $message->getEntity($passed_ent_id); + /* message is an entity which contains the envelope and type0=message + * and type1=rfc822. The actual entities are childs from + * $message->entities[0]. That's where the encoding and is located + */ + + $entities = $message->entities[0]->findDisplayEntity + (array(), $alt_order = array('text/plain')); + if (!count($entities)) { + $entities = $message->entities[0]->findDisplayEntity + (array(), $alt_order = array('text/plain','html/plain')); } + $orig_header = $message->rfc822_header; /* here is the envelope located */ + /* redefine the message for picking up the attachments */ + $message = $message->entities[0]; + } else { - $body = ''; + $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain')); + if (!count($entities)) { + $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain')); + } + $orig_header = $message->rfc822_header; } - if ($message->header->type1 == 'html') { - $body = strip_tags($body); - } + $encoding = $message->header->encoding; + $type0 = $message->type0; + $type1 = $message->type1; + foreach ($entities as $ent) { + $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent); + $body_part_entity = $message->getEntity($ent); + $bodypart = decodeBody($unencoded_bodypart, + $body_part_entity->header->encoding); + if ($type1 == 'html') { + $bodypart = str_replace("\n", ' ', $bodypart); + $bodypart = preg_replace(array('/
/i','/
/i'), "\n", $bodypart);
+ $bodypart = str_replace(array(' ','>','<'),array(' ','>','<'),$bodypart);
+ $bodypart = strip_tags($bodypart);
- sqUnWordWrap($body);
- $body_ary = explode("\n", $body);
- $i = count($body_ary) - 1;
- while ($i >= 0 && ereg("^[>\\s]*$", $body_ary[$i])) {
- unset($body_ary[$i]);
- $i --;
- }
- $body = '';
- for ($i=0; isset($body_ary[$i]); $i++) {
- if ($reply_id) {
- if (ereg('^[ >]+', $body_ary[$i])) {
- $body_ary[$i] = '>' . $body_ary[$i];
- } else {
- $body_ary[$i] = '> ' . $body_ary[$i];
- }
}
- if (!$draft_id) {
- sqWordWrap($body_ary[$i], $editor_size - 1);
- }
- $body .= $body_ary[$i] . "\n";
- unset($body_ary[$i]);
- }
- if ($forward_id) {
- $bodyTop = '-------- ' . _("Original Message") . " --------\n" .
- _("Subject") . ': ' . $orig_header->subject . "\n" .
- _("From") . ': ' . $orig_header->from . "\n" .
- _("Date") . ': ' .
- getLongDateString( $orig_header->date ). "\n" .
- _("To") . ': ' . $orig_header->to[0] . "\n";
- if (count($orig_header->to) > 1) {
- for ($x=1; $x < count($orig_header->to); $x++) {
- $bodyTop .= ' ' . $orig_header->to[$x] . "\n";
+ if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
+ function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
+ if (mb_detect_encoding($bodypart) != 'ASCII') {
+ $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart);
}
}
- if (isset($forward_cc) && $forward_cc) {
- $bodyTop .= _("Cc") . ': ' . $orig_header->cc[0] . "\n";
- if (count($orig_header->cc) > 1) {
- for ($x = 1; $x < count($orig_header->cc); $x++) {
- $bodyTop .= ' ' . $orig_header->cc[$x] . "\n";
- }
- }
- }
- $bodyTop .= "\n";
- $body = $bodyTop . $body;
- }
- elseif ($reply_id) {
- $orig_from = decodeHeader($orig_header->from, false);
- $body = getReplyCitation($orig_from) . $body;
- }
- return;
- }
+ if (isset($body_part_entity->header->parameters['charset'])) {
+ $actual = $body_part_entity->header->parameters['charset'];
+ } else {
+ $actual = 'us-ascii';
+ }
- if (!$send_to) {
- $send_to = sqimap_find_email($send_to);
- }
+ if ( $actual && is_conversion_safe($actual) && $actual != $default_charset){
+ $bodypart = charset_decode($actual,$bodypart);
+ }
- /* This formats a CC string if they hit "reply all" */
- if ($send_to_cc != '') {
- $send_to_cc = ereg_replace('"[^"]*"', '', $send_to_cc);
- $send_to_cc = str_replace(';', ',', $send_to_cc);
- $sendcc = explode(',', $send_to_cc);
- $send_to_cc = '';
+ $body .= $bodypart;
+ }
+ if ($default_use_priority) {
+ $mailprio = substr($orig_header->priority,0,1);
+ if (!$mailprio) {
+ $mailprio = 3;
+ }
+ } else {
+ $mailprio = '';
+ }
+ //ClearAttachments($session);
- for ($i = 0; $i < count($sendcc); $i++) {
- $sendcc[$i] = trim($sendcc[$i]);
- if ($sendcc[$i] == '') {
- continue;
+ $identity = '';
+ $from_o = $orig_header->from;
+ if (is_array($from_o)) {
+ if (isset($from_o[0])) {
+ $from_o = $from_o[0];
}
+ }
+ if (is_object($from_o)) {
+ $orig_from = $from_o->getAddress();
+ } else {
+ $orig_from = '';
+ }
- $sendcc[$i] = sqimap_find_email($sendcc[$i]);
- $whofrom = sqimap_find_displayable_name($msg['HEADER']['FROM']);
- $whoreplyto = sqimap_find_email($msg['HEADER']['REPLYTO']);
+ $identities = array();
+ if (count($idents) > 1) {
+ foreach($idents as $nr=>$data) {
+ $enc_from_name = '"'.$data['full_name'].'" <'. $data['email_address'].'>';
+ if($enc_from_name == $orig_from) {
+ $identity = $nr;
+ break;
+ }
+ $identities[] = $enc_from_name;
+ }
- if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) &&
- (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) &&
- (trim($sendcc[$i]) != '')) {
- $send_to_cc .= trim($sendcc[$i]) . ', ';
+ $identity_match = $orig_header->findAddress($identities);
+ if ($identity_match) {
+ $identity = $identity_match;
}
}
- $send_to_cc = trim($send_to_cc);
- if (substr($send_to_cc, -1) == ',') {
- $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1);
+
+ switch ($action) {
+ case ('draft'):
+ $use_signature = FALSE;
+ $composeMessage->rfc822_header = $orig_header;
+ $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true);
+ $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true);
+ $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true);
+ $send_from = $orig_header->getAddr_s('from');
+ $send_from_parts = new AddressStructure();
+ $send_from_parts = $orig_header->parseAddress($send_from);
+ $send_from_add = $send_from_parts->mailbox . '@' . $send_from_parts->host;
+ $identities = get_identities();
+ if (count($identities) > 0) {
+ foreach($identities as $iddata) {
+ if ($send_from_add == $iddata['email_address']) {
+ $identity = $iddata['index'];
+ break;
+ }
+ }
+ }
+ $subject = decodeHeader($orig_header->subject,false,false,true);
+// /* remember the references and in-reply-to headers in case of an reply */
+ $composeMessage->rfc822_header->more_headers['References'] = $orig_header->references;
+ $composeMessage->rfc822_header->more_headers['In-Reply-To'] = $orig_header->in_reply_to;
+ $body_ary = explode("\n", $body);
+ $cnt = count($body_ary) ;
+ $body = '';
+ for ($i=0; $i < $cnt; $i++) {
+ if (!ereg("^[>\\s]*$", $body_ary[$i]) || !$body_ary[$i]) {
+ sqWordWrap($body_ary[$i], $editor_size );
+ $body .= $body_ary[$i] . "\n";
+ }
+ unset($body_ary[$i]);
+ }
+ sqUnWordWrap($body);
+ $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
+ break;
+ case ('edit_as_new'):
+ $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true);
+ $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true);
+ $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true);
+ $subject = decodeHeader($orig_header->subject,false,false,true);
+ $mailprio = $orig_header->priority;
+ $orig_from = '';
+ $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
+ sqUnWordWrap($body);
+ break;
+ case ('forward'):
+ $send_to = '';
+ $subject = getforwardSubject(decodeHeader($orig_header->subject,false,false,true));
+ $body = getforwardHeader($orig_header) . $body;
+ sqUnWordWrap($body);
+ $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
+ $body = "\n" . $body;
+ break;
+ case ('forward_as_attachment'):
+ $subject = getforwardSubject(decodeHeader($orig_header->subject,false,false,true));
+ $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
+ $body = '';
+ break;
+ case ('reply_all'):
+ if(isset($orig_header->mail_followup_to) && $orig_header->mail_followup_to) {
+ $send_to = $orig_header->getAddr_s('mail_followup_to');
+ } else {
+ $send_to_cc = replyAllString($orig_header);
+ $send_to_cc = decodeHeader($send_to_cc,false,false,true);
+ }
+ case ('reply'):
+ // skip this if send_to was already set right above here
+ if(!$send_to) {
+ $send_to = $orig_header->reply_to;
+ if (is_array($send_to) && count($send_to)) {
+ $send_to = $orig_header->getAddr_s('reply_to');
+ } else if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */
+ $send_to = $orig_header->getAddr_s('reply_to');
+ } else {
+ $send_to = $orig_header->getAddr_s('from');
+ }
+ }
+ $send_to = decodeHeader($send_to,false,false,true);
+ $subject = decodeHeader($orig_header->subject,false,false,true);
+ $subject = str_replace('"', "'", $subject);
+ $subject = trim($subject);
+ if (substr(strtolower($subject), 0, 3) != 're:') {
+ $subject = 'Re: ' . $subject;
+ }
+ /* this corrects some wrapping/quoting problems on replies */
+ $rewrap_body = explode("\n", $body);
+ $from = (is_array($orig_header->from)) ? $orig_header->from[0] : $orig_header->from;
+ sqUnWordWrap($body); // unwrap and then reset it?!
+ $body = '';
+ $strip_sigs = getPref($data_dir, $username, 'strip_sigs');
+ foreach ($rewrap_body as $line) {
+ if ($strip_sigs && substr($line,0,3) == '-- ') {
+ break;
+ }
+ sqWordWrap($line, ($editor_size));
+ if (preg_match("/^(>+)/", $line, $matches)) {
+ $gt = $matches[1];
+ $body .= '>' . str_replace("\n", "\n>$gt ", rtrim($line)) ."\n";
+ } else {
+ $body .= '> ' . str_replace("\n", "\n> ", rtrim($line)) . "\n";
+ }
+ }
+ $body = getReplyCitation($from , $orig_header->date) . $body;
+ $composeMessage->reply_rfc822_header = $orig_header;
+
+ break;
+ default:
+ break;
}
+ $compose_messages[$session] = $composeMessage;
+ sqsession_register($compose_messages, 'compose_messages');
+ session_write_close();
+ sqimap_logout($imapConnection);
}
+ $ret = array( 'send_to' => $send_to,
+ 'send_to_cc' => $send_to_cc,
+ 'send_to_bcc' => $send_to_bcc,
+ 'subject' => $subject,
+ 'mailprio' => $mailprio,
+ 'body' => $body,
+ 'identity' => $identity );
+
+ return ($ret);
} /* function newMail() */
-
-function getAttachments($message, $session) {
- global $mailbox, $attachments, $attachment_dir, $imapConnection,
- $ent_num, $forward_id, $draft_id, $username;
-
- if (isset($draft_id)) {
- $id = $draft_id;
+function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
+ global $attachment_dir, $username, $data_dir, $squirrelmail_language;
+ $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
+ if (!count($message->entities) ||
+ ($message->type0 == 'message' && $message->type1 == 'rfc822')) {
+ if ( !in_array($message->entity_id, $entities) && $message->entity_id) {
+ switch ($message->type0) {
+ case 'message':
+ if ($message->type1 == 'rfc822') {
+ $filename = $message->rfc822_header->subject;
+ if ($filename == "") {
+ $filename = "untitled-".$message->entity_id;
+ }
+ $filename .= '.msg';
+ } else {
+ $filename = $message->getFilename();
+ }
+ break;
+ default:
+ if (!$message->mime_header) { /* temporary hack */
+ $message->mime_header = $message->header;
+ }
+ $filename = $message->getFilename();
+ break;
+ }
+ $filename = str_replace(' ', ' ', decodeHeader($filename));
+ if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
+ function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
+ $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
+ }
+ $localfilename = GenerateRandomString(32, '', 7);
+ $full_localfilename = "$hashed_attachment_dir/$localfilename";
+ while (file_exists($full_localfilename)) {
+ $localfilename = GenerateRandomString(32, '', 7);
+ $full_localfilename = "$hashed_attachment_dir/$localfilename";
+ }
+ $message->att_local_name = $full_localfilename;
+
+ $composeMessage->initAttachment($message->type0.'/'.$message->type1,$filename,
+ $full_localfilename);
+
+ /* Write Attachment to file */
+ $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
+ fputs($fp, decodeBody(mime_fetch_body($imapConnection,
+ $passed_id, $message->entity_id),
+ $message->header->encoding));
+ fclose ($fp);
+ }
} else {
- $id = $forward_id;
- }
-
- if (!$message) {
- sqimap_mailbox_select($imapConnection, $mailbox);
- $message = sqimap_get_message($imapConnection, $id, $mailbox);
+ for ($i=0, $entCount=count($message->entities); $i<$entCount;$i++) {
+ $composeMessage=getAttachments($message->entities[$i], $composeMessage, $passed_id, $entities, $imapConnection);
+ }
}
+ return $composeMessage;
+}
+function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
+ $passed_ent_id='', $imapConnection) {
+ global $attachments, $attachment_dir, $username, $data_dir;
$hashed_attachment_dir = getHashedDir($username, $attachment_dir);
- if (count($message->entities) == 0) {
- if ($message->header->entity_id != $ent_num) {
- $filename = decodeHeader($message->header->filename);
-
- if ($filename == "") {
- $filename = "untitled-".$message->header->entity_id;
- }
-
- $localfilename = GenerateRandomString(32, '', 7);
- $full_localfilename = "$hashed_attachment_dir/$localfilename";
- while (file_exists($full_localfilename)) {
- $localfilename = GenerateRandomString(32, '', 7);
- $full_localfilename = "$hashed_attachment_dir/$localfilename";
- }
-
- $newAttachment = array();
- $newAttachment['localfilename'] = $localfilename;
- $newAttachment['remotefilename'] = $filename;
- $newAttachment['type'] = strtolower($message->header->type0 .
- '/' . $message->header->type1);
- $newAttachment['id'] = strtolower($message->header->id);
- $newAttachment['session'] = $session;
+ if (!$passed_ent_id) {
+ $body_a = sqimap_run_command($imapConnection,
+ 'FETCH '.$passed_id.' RFC822',
+ TRUE, $response, $readmessage,
+ TRUE);
+ } else {
+ $body_a = sqimap_run_command($imapConnection,
+ 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
+ TRUE, $response, $readmessage, TRUE);
+ $message = $message->parent;
+ }
+ if ($response == 'OK') {
+ $subject = encodeHeader($message->rfc822_header->subject);
+ array_shift($body_a);
+ array_pop($body_a);
+ $body = implode('', $body_a) . "\r\n";
- /* Write Attachment to file */
- $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w');
- fputs($fp, decodeBody(mime_fetch_body($imapConnection,
- $id, $message->header->entity_id),
- $message->header->encoding));
- fclose ($fp);
+ $localfilename = GenerateRandomString(32, 'FILE', 7);
+ $full_localfilename = "$hashed_attachment_dir/$localfilename";
- $attachments[] = $newAttachment;
- }
- } else {
- for ($i = 0; $i < count($message->entities); $i++) {
- getAttachments($message->entities[$i], $session);
- }
+ $fp = fopen($full_localfilename, 'w');
+ fwrite ($fp, $body);
+ fclose($fp);
+ $composeMessage->initAttachment('message/rfc822',$subject.'.msg',
+ $full_localfilename);
}
- return;
+ return $composeMessage;
}
-function showInputForm ($session) {
- global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body,
+function showInputForm ($session, $values=false) {
+ global $send_to, $send_to_cc, $body, $startMessage,
$passed_body, $color, $use_signature, $signature, $prefix_sig,
- $editor_size, $attachments, $subject, $newmail,
- $use_javascript_addr_book, $send_to_bcc, $reply_id, $mailbox,
+ $editor_size, $editor_height, $attachments, $subject, $newmail,
+ $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
$from_htmladdr_search, $location_of_buttons, $attachment_dir,
- $username, $data_dir, $identity, $draft_id, $delete_draft,
+ $username, $data_dir, $identity, $idents, $draft_id, $delete_draft,
$mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
- $saved_draft, $mail_sent, $sig_first;
-
- $subject = decodeHeader($subject, false);
- $reply_subj = decodeHeader($reply_subj, false);
- $forward_subj = decodeHeader($forward_subj, false);
+ $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
+ $username, $compose_messages, $composesession, $default_charset;
+
+ $composeMessage = $compose_messages[$session];
+ if ($values) {
+ $send_to = $values['send_to'];
+ $send_to_cc = $values['send_to_cc'];
+ $send_to_bcc = $values['send_to_bcc'];
+ $subject = $values['subject'];
+ $mailprio = $values['mailprio'];
+ $body = $values['body'];
+ $identity = (int) $values['identity'];
+ } else {
+ $send_to = decodeHeader($send_to, true, false);
+ $send_to_cc = decodeHeader($send_to_cc, true, false);
+ $send_to_bcc = decodeHeader($send_to_bcc, true, false);
+ }
if ($use_javascript_addr_book) {
- echo "\n". '' . "\n\n";
+ "// -->\n\n\n";
}
- echo "\n" . '