\n\n";
}
function checkInput ($show) {
/** I implemented the $show variable because the error messages
were getting sent before the page header. So, I check once
using $show=false, and then when i'm ready to display the
error message, show=true **/
global $body, $send_to, $subject, $color;
if ($send_to == "") {
if ($show)
plain_error_message(_("You have not filled in the \"To:\" field."), $color);
return false;
}
return true;
} // function checkInput()
// True if FAILURE
function saveAttachedFiles() {
global $HTTP_POST_FILES, $attachment_dir, $attachments;
$localfilename = GenerateRandomString(32, '', 7);
while (file_exists($attachment_dir . $localfilename))
$localfilename = GenerateRandomString(32, '', 7);
if (!@rename($HTTP_POST_FILES['attachfile']['tmp_name'], $attachment_dir.$localfilename)) {
if (!@copy($HTTP_POST_FILES['attachfile']['tmp_name'], $attachment_dir.$localfilename)) {
return true;
}
}
$newAttachment['localfilename'] = $localfilename;
$newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name'];
$newAttachment['type'] =
strtolower($HTTP_POST_FILES['attachfile']['type']);
if ($newAttachment['type'] == "")
$newAttachment['type'] = 'application/octet-stream';
$attachments[] = $newAttachment;
}
if (!isset($mailbox) || $mailbox == "" || ($mailbox == "None"))
$mailbox = "INBOX";
if (isset($send)) {
if (isset($HTTP_POST_FILES['attachfile']) &&
$HTTP_POST_FILES['attachfile']['tmp_name'] &&
$HTTP_POST_FILES['attachfile']['tmp_name'] != 'none')
$AttachFailure = saveAttachedFiles();
if (checkInput(false) && !isset($AttachFailure)) {
$urlMailbox = urlencode (trim($mailbox));
if (! isset($reply_id))
$reply_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)
$body = str_replace("\r\n", "\n", $body);
$body = str_replace("\r", "\n", $body);
// 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.
$body = explode("\n", $body);
$newBody = '';
foreach ($body as $line) {
if( $line <> '-- ' )
$line = rtrim($line);
if (strlen($line) <= $editor_size + 1)
$newBody .= $line . "\n";
else {
sqWordWrap($line, $editor_size) . "\n";
$newBody .= $line;
}
}
$body = $newBody;
do_hook("compose_send");
if (! sendMessage($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id)) {
showInputForm();
exit();
}
Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort&startMessage=1");
} else {
//$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
displayPageHeader($color, $mailbox);
if (isset($AttachFailure))
plain_error_message(_("Could not move/copy file. File not attached"), $color);
checkInput(true);
showInputForm();
//sqimap_logout($imapConnection);
}
} else if (isset($html_addr_search_done)) {
displayPageHeader($color, $mailbox);
if (isset($send_to_search) && is_array($send_to_search)) {
foreach ($send_to_search as $k => $v) {
if (substr($k, 0, 1) == 'T') {
if ($send_to)
$send_to .= ', ';
$send_to .= $v;
}
elseif (substr($k, 0, 1) == 'C') {
if ($send_to_cc)
$send_to_cc .= ', ';
$send_to_cc .= $v;
}
elseif (substr($k, 0, 1) == 'B') {
if ($send_to_bcc)
$send_to_bcc .= ', ';
$send_to_bcc .= $v;
}
}
}
showInputForm();
} else if (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())
plain_error_message(_("Could not move/copy file. File not attached"), $color);
}
// I am using an include so as to elminiate an extra unnecessary click. If you
// can think of a better way, please implement it.
include_once('./addrbook_search_html.php');
} else if (isset($attach)) {
if (saveAttachedFiles())
plain_error_message(_("Could not move/copy file. File not attached"), $color);
displayPageHeader($color, $mailbox);
showInputForm();
} else if (isset($do_delete)) {
displayPageHeader($color, $mailbox);
if (isset($delete) && is_array($delete))
{
foreach($delete as $index)
{
unlink ($attachment_dir.$attachments[$index]['localfilename']);
unset ($attachments[$index]);
}
}
showInputForm();
} else {
// This handles the default case as well as the error case
// (they had the same code) --> if (isset($smtpErrors))
$imapConnection = sqimap_login($username, $key, $imapServerAddress,
$imapPort, 0);
displayPageHeader($color, $mailbox);
$newmail = true;
ClearAttachments();
if (isset($forward_id) && $forward_id && isset($ent_num) && $ent_num)
getAttachments(0);
newMail();
showInputForm();
sqimap_logout($imapConnection);
}
function ClearAttachments() {
global $attachments, $attachment_dir;
foreach ($attachments as $info) {
if (file_exists($attachment_dir . $info['localfilename'])) {
unlink($attachment_dir . $info['localfilename']);
}
}
$attachments = array();
}
function getReplyCitation($orig_from) {
global $reply_citation_style, $reply_citation_start, $reply_citation_end;
/* First, return an empty string when no citation style selected. */
if (($reply_citation_style == '') || ($reply_citation_style == 'none')) {
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 'user-defined':
$start = $reply_citation_start;
$end = $reply_citation_end;
break;
default: return ('');
}
/* Build and return the citation string. */
return ($start . $orig_from . $end . "\n");
}
?>