Source for file compose.php
Documentation is available at compose.php
* This code sends a mail.
* There are 4 modes of operation:
* @copyright © 1999-2006 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: compose.php,v 1.450 2006/09/29 09:02:22 stekkel Exp $
* Include the SquirrelMail initialization file.
require
('../include/init.php');
/* SquirrelMail required files. */
require_once(SM_PATH .
'functions/imap_general.php');
require_once(SM_PATH .
'functions/imap_messages.php');
require_once(SM_PATH .
'functions/date.php');
require_once(SM_PATH .
'functions/mime.php');
require_once(SM_PATH .
'class/deliver/Deliver.class.php');
require_once(SM_PATH .
'functions/addressbook.php');
require_once(SM_PATH .
'functions/forms.php');
require_once(SM_PATH .
'functions/identity.php');
/* --------------------- Get globals ------------------------------------- */
// Turn on delayed error handling in case we wind up redirecting below
$oErrorHandler->setDelayedErrors(true);
/** SESSION/POST/GET VARS */
$startMessage = (int)
$startMessage;
$html_addr_search_done =
'Use Addresses';
if ( sqgetGlobalVar('smaction_reply_all',$tmp) ) $action =
'reply_all';
if ( sqgetGlobalVar('smaction_attache',$tmp) ) $action =
'forward_as_attachment';
if ( sqgetGlobalVar('smaction_edit_new',$tmp) ) $action =
'edit_as_new';
/* Location (For HTTP 1.1 Header("Location: ...") redirects) */
/* Identities (fetch only once) */
/* --------------------- Specific Functions ------------------------------ */
global $include_self_reply_all, $idents;
* 1) Remove the addresses we'll be sending the message 'to'
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) {
$url_replytoall_ar =
$header->getAddr_a(array('to','cc'), $excl_ar);
* 4) generate the string.
foreach( $url_replytoall_ar as $email =>
$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>";
$url_replytoallcc .=
', '.
$email;
$url_replytoallcc =
substr($url_replytoallcc,2);
return $url_replytoallcc;
* creates top line in reply citations
* Line style depends on user preferences.
* $orig_date argument is available only from 1.4.3 and 1.5.1 version.
* @param object $orig_from From: header object.
* @param integer $orig_date email's timestamp
* @return string reply citation
global $reply_citation_style, $reply_citation_start, $reply_citation_end;
$sOrig_from =
decodeHeader($orig_from->getAddress(false),false,false,true);
/* First, return an empty string when no citation style selected. */
if (($reply_citation_style ==
'') ||
($reply_citation_style ==
'none')) {
/* Make sure our final value isn't an empty string. */
/* Otherwise, try to select the desired citation style. */
switch ($reply_citation_style) {
* To translators: %s is for author's name
$full_reply_citation =
sprintf(_("%s wrote:"),$sOrig_from);
$full_reply_citation =
$start .
$sOrig_from .
$end;
* first %s is for date string, second %s is for author's name. Date uses
* formating from "D, F j, Y g:i a" and "D, F j, Y H:i" translations.
* "On Sat, December 24, 2004 23:59, Santa wrote:"
* If you have to put author's name in front of date string, check comments about
* argument swapping at http://www.php.net/sprintf
$start =
$reply_citation_start .
($reply_citation_start ==
'' ?
'' :
' ');
$end =
$reply_citation_end;
$full_reply_citation =
$start .
$sOrig_from .
$end;
/* Add line feed and return the citation string. */
return ($full_reply_citation .
"\n");
* Creates header fields in forwarded email body
* $default_charset global must be set correctly before you call this function.
* @param object $orig_header
// using own strlen function in order to detect correct string length
$display =
array( _("Subject") =>
sq_strlen(_("Subject"),$default_charset),
$maxsize =
max($display);
foreach($display as $key =>
$val) {
$display[$key] =
$key .
': '.
str_pad('', $maxsize -
$val);
$from =
decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false,true);
$to =
decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false,true);
$subject =
decodeHeader($orig_header->subject,false,false,true);
// using own str_pad function in order to create correct string pad
$bodyTop =
sq_str_pad(' '.
_("Original Message").
' ',$editor_size -
2,'-',STR_PAD_BOTH,$default_charset) .
"\n".
$display[_("Subject")] .
$subject .
"\n" .
$display[_("From")] .
$from .
"\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);
$bodyTop .=
$display[_("Cc")] .
$cc .
"\n";
$bodyTop .=
str_pad('', $editor_size -
2 , '-') .
/* ----------------------------------------------------------------------- */
* If the session is expired during a post this restores the compose 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);
// these are the vars that we can set from the expired composed session
$compo_var_list =
array ( 'send_to', 'send_to_cc','body','startMessage',
'passed_body','use_signature','signature','attachments','subject','newmail',
'send_to_bcc', 'passed_id', 'mailbox', 'from_htmladdr_search', 'identity',
'draft_id', 'delete_draft', 'mailprio', 'edit_as_new', 'compose_messsages',
'composesession', 'request_mdn', 'request_dr');
foreach ($compo_var_list as $var) {
if ( isset
($session_expired_post[$var]) &&
!isset
($
$var) ) {
$
$var =
$session_expired_post[$var];
unset
($session_expired_post);
if ($compose_new_win ==
'1') {
$sHeaderJs =
(isset
($sHeaderJs)) ?
$sHeaderJs :
'';
if (strpos($action, 'reply') !==
false &&
$reply_focus) {
$sBodyTagJs =
'onload="checkForm(\''.
$replyfocus.
'\');"';
$sBodyTagJs =
'onload="checkForm();"';
if (!isset
($composesession)) {
if (!isset
($session) ||
(isset
($newmessage) &&
$newmessage)) {
$session =
"$composesession" +
1;
$composesession =
$session;
if (!isset
($compose_messages)) {
$compose_messages =
array();
if (!isset
($compose_messages[$session]) ||
($compose_messages[$session] ==
NULL)) {
$composeMessage->rfc822_header =
$rfc822_header;
$composeMessage->reply_rfc822_header =
'';
$compose_messages[$session] =
$composeMessage;
$composeMessage=
$compose_messages[$session];
if (!isset
($mailbox) ||
$mailbox ==
'' ||
($mailbox ==
'None')) {
* Set $default_charset to correspond with the user's selection
$composeMessage=
$compose_messages[$session];
unset
($compose_messages[$session]);
$draft_message =
_("Draft Email Saved");
/* If this is a resumed draft, then delete the original */
if(isset
($delete_draft)) {
$imap_stream =
sqimap_login($username, false, $imapServerAddress, $imapPort, false);
// force bypass_trash=true because message should be saved when deliverMessage() returns true.
// in current implementation of sqimap_msgs_list_flag() single message id can
// be submitted as string. docs state that it should be array.
$oErrorHandler->saveDelayedErrors();
if ($compose_new_win ==
'1') {
if ( !isset
($pageheader_sent) ||
!$pageheader_sent ) {
Header("Location: $location/compose.php?saved_draft=yes&session=$composesession");
echo
' <br><br><div style="text-align: center;"><a href="' .
$location
.
'/compose.php?saved_sent=yes&session=' .
$composesession .
'">'
.
_("Return") .
'</a></div>';
if ( !isset
($pageheader_sent) ||
!$pageheader_sent ) {
Header("Location: $location/right_main.php?mailbox=" .
urlencode($draft_folder) .
"&startMessage=1¬e=".
urlencode($draft_message));
echo
' <br><br><div style="text-align: center;"><a href="' .
$location
.
'/right_main.php?mailbox=' .
urlencode($draft_folder)
.
'&startMessage=1&note=' .
urlencode($draft_message) .
'">'
.
_("Return") .
'</a></div>';
if (isset
($_FILES['attachfile']) &&
$_FILES['attachfile']['tmp_name'] &&
$_FILES['attachfile']['tmp_name'] !=
'none') {
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 */
if (! isset
($passed_id)) {
* Set $default_charset to correspond with the user's selection
* This is to change all newlines to \n
* We'll change them to \r\n later (in the sendMessage function)
* Rewrap $body so that no line is bigger than $editor_size
foreach ($body as $line) {
if (sq_strlen($line,$default_charset) <=
$editor_size +
1) {
$newBody .=
$line .
"\n";
$newBody .=
$line .
"\n";
$composeMessage=
$compose_messages[$session];
<