<?php
- /**
- * compose.php
- *
- * Copyright (c) 1999-2000 The SquirrelMail development team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
- *
- * This code sends a mail.
- *
- * There are 4 modes of operation:
- * - Start new mail
- * - Add an attachment
- * - Send mail
- * - Save As Draft
- *
- * $Id$
- **/
-
- 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');
-
- if (!isset($attachments))
- {
+
+/**
+ * compose.php
+ *
+ * Copyright (c) 1999-2002 The SquirrelMail Project Team
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
+ *
+ * This code sends a mail.
+ *
+ * There are 4 modes of operation:
+ * - Start new mail
+ * - Add an attachment
+ * - Send mail
+ * - Save As Draft
+ *
+ * $Id$
+ */
+
+/*****************************************************************/
+/*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
+/*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
+/*** + Base level indent should begin at left margin, as ***/
+/*** the require_once below looks. ***/
+/*** + All identation should consist of four space blocks ***/
+/*** + Tab characters are evil. ***/
+/*** + all comments should use "slash-star ... star-slash" ***/
+/*** style -- no pound characters, no slash-slash style ***/
+/*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
+/*** ALWAYS USE { AND } CHARACTERS!!! ***/
+/*** + Please use ' instead of ", when possible. Note " ***/
+/*** should always be used in _( ) function calls. ***/
+/*** Thank you for your help making the SM code more readable. ***/
+/*****************************************************************/
+
+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');
+
+ if (!isset($attachments)) {
$attachments = array();
session_register('attachments');
}
-
// This function is used when not sending or adding attachments
function newMail () {
global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
$body = $bodyTop . $body;
} else if ($reply_id) {
$orig_from = decodeHeader($orig_header->from);
- $orig_from = trim(substr($orig_from,0,strpos($orig_from,'<')));
- $orig_from = str_replace('"','',$orig_from);
- $orig_from = str_replace("'",'',$orig_from);
$body = getReplyCitation($orig_from) . $body;
}
function getAttachments($message) {
global $mailbox, $attachments, $attachment_dir, $imapConnection,
- $ent_num, $forward_id, $draft_id;
+ $ent_num, $forward_id, $draft_id, $username;
if (isset($draft_id))
$id = $draft_id;
$mailbox);
}
+ $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
if (count($message->entities) == 0) {
if ($message->header->entity_id != $ent_num) {
$filename = decodeHeader($message->header->filename);
$filename = "untitled-".$message->header->entity_id;
$localfilename = GenerateRandomString(32, '', 7);
- while (file_exists($attachment_dir . $localfilename))
+ $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;
'/' . $message->header->type1);
// Write Attachment to file
- $fp = fopen ($attachment_dir.$localfilename, 'w');
+ $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w');
fputs ($fp, decodeBody(mime_fetch_body($imapConnection,
$id, $message->header->entity_id),
$message->header->encoding));
}
// This code is for attachments
- echo " <tr>\n";
- echo " <TD BGCOLOR=\"$color[0]\" VALIGN=TOP ALIGN=RIGHT>\n";
- echo " <SMALL><BR></SMALL>"._("Attach:");
- echo " </td><td ALIGN=left BGCOLOR=\"$color[0]\">\n";
+ echo " <TR>\n";
+ echo " <TD VALIGN=MIDDLE ALIGN=RIGHT>\n";
+ echo _("Attach:");
+ echo " </TD>\n";
+ echo " <TD VALIGN=MIDDLE ALIGN=LEFT>\n";
echo " <INPUT NAME=\"attachfile\" SIZE=48 TYPE=\"file\">\n";
echo " <input type=\"submit\" name=\"attach\"";
echo " value=\"" . _("Add") ."\">\n";
- echo " </td>\n";
- echo " </tr>\n";
- if (count($attachments))
- {
+ echo " </TD>\n";
+ echo " </TR>\n";
+ if (count($attachments)) {
+ $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
echo "<tr><td bgcolor=\"$color[0]\" align=right>\n";
echo " ";
echo "</td><td align=left bgcolor=\"$color[0]\">";
foreach ($attachments as $key => $info) {
+ $attached_file = "$hashed_attachment_dir/$info[localfilename]";
echo "<input type=\"checkbox\" name=\"delete[]\" value=\"$key\">\n";
echo $info['remotefilename'] . " - " . $info['type'] . " (";
- echo show_readable_size(filesize($attachment_dir .
- $info['localfilename'])) . ")<br>\n";
+ echo show_readable_size(filesize($attached_file)) . ")<br>\n";
}
echo "<input type=\"submit\" name=\"do_delete\" value=\""._("Delete selected attachments")."\">\n";
echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
if ($save_as_draft) {
- echo "<input type=\"submit\" name =\"draft\" value=\"Save Draft\">\n";
+ echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
}
if ($default_use_priority) {
if(!isset($mailprio)) {
// True if FAILURE
function saveAttachedFiles() {
- global $HTTP_POST_FILES, $attachment_dir, $attachments;
+ global $HTTP_POST_FILES, $attachment_dir, $attachments, $username;
+ $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
$localfilename = GenerateRandomString(32, '', 7);
- while (file_exists($attachment_dir . $localfilename))
+ $full_localfilename = "$hashed_attachment_dir/$localfilename";
+ while (file_exists($full_localfilename)) {
$localfilename = GenerateRandomString(32, '', 7);
+ $full_localfilename = "$hashed_attachment_dir/$localfilename";
+ }
- if (!@rename($HTTP_POST_FILES['attachfile']['tmp_name'], $attachment_dir.$localfilename)) {
- if (!@copy($HTTP_POST_FILES['attachfile']['tmp_name'], $attachment_dir.$localfilename)) {
+ if (!@rename($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
+ if (!@copy($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
return true;
}
}
$attachments[] = $newAttachment;
}
- if (!isset($mailbox) || $mailbox == "" || ($mailbox == "None"))
+ if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None'))
$mailbox = "INBOX";
if (isset($draft)) {
do_hook("compose_send");
- if (!sendMessage($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id, $mailprio)) {
+ if (! isset($mailprio))
+ $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
+ $subject, $body, $reply_id);
+ else
+ $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
+ $subject, $body, $reply_id, $mailprio);
+ if (! $Result) {
showInputForm();
exit();
}
} else if (isset($do_delete)) {
displayPageHeader($color, $mailbox);
- if (isset($delete) && is_array($delete))
- {
- foreach($delete as $index)
- {
- unlink ($attachment_dir.$attachments[$index]['localfilename']);
+ $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
+ if (isset($delete) && is_array($delete)) {
+ foreach($delete as $index) {
+ $attached_file = $hashed_attachment_dir . '/'
+ . $attachments[$index]['localfilename'];
+ unlink ($attached_file);
unset ($attachments[$index]);
}
}
}
function ClearAttachments() {
- global $attachments, $attachment_dir;
+ global $username, $attachments, $attachment_dir;
+ $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
foreach ($attachments as $info) {
- if (file_exists($attachment_dir . $info['localfilename'])) {
- unlink($attachment_dir . $info['localfilename']);
+ $attached_file = "$hashed_attachment_dir/$info[localfilename]";
+ if (file_exists($attached_file)) {
+ unlink($attached_file);
}
}
return ('');
}
+ /* Decode the users name. */
+ $parpos = strpos($orig_from, '(');
+ if ($parpos === false) {
+ $orig_from = trim(substr($orig_from, 0, strpos($orig_from, '<')));
+ $orig_from = str_replace('"', '', $orig_from);
+ $orig_from = str_replace("'", '', $orig_from);
+ } else {
+ $end_parpos = strrpos($orig_from, ')');
+ $end_parpos -= ($end_parpos === false ? $end_parpos : $parpos + 1);
+ $orig_from = trim(substr($orig_from, $parpos + 1, $end_parpos));
+ }
+
+ /* 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':