<?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 3 modes of operation:
- ** - Start new mail
- ** - Add an attachment
- ** - Send mail
- **
- ** $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-2001 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$
+ */
+
+/*****************************************************************/
+/*** 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,
- $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc, $editor_size;
+ $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc, $editor_size,
+ $draft_id, $use_signature;
$send_to = decodeHeader($send_to);
$send_to_cc = decodeHeader($send_to_cc);
elseif ($reply_id)
$id = $reply_id;
+ if ($draft_id){
+ $id = $draft_id;
+ $use_signature = FALSE;
+ }
if (isset($id)) {
sqimap_mailbox_select($imapConnection, $mailbox);
}
$body = "";
for ($i=0; isset($body_ary[$i]); $i++) {
- if (! $forward_id)
+ if ($reply_id)
{
if (ereg('^[ >]+', $body_ary[$i]))
{
$body_ary[$i] = '> ' . $body_ary[$i];
}
}
- sqWordWrap($body_ary[$i], $editor_size - 1);
+ if (!$draft_id) {
+ sqWordWrap($body_ary[$i], $editor_size - 1);
+ }
$body .= $body_ary[$i] . "\n";
unset($body_ary[$i]);
}
function getAttachments($message) {
global $mailbox, $attachments, $attachment_dir, $imapConnection,
- $ent_num, $forward_id;
+ $ent_num, $forward_id, $draft_id, $username;
+
+ if (isset($draft_id))
+ $id = $draft_id;
+ else
+ $id = $forward_id;
if (!$message) {
sqimap_mailbox_select($imapConnection, $mailbox);
- $message = sqimap_get_message($imapConnection, $forward_id,
+ $message = sqimap_get_message($imapConnection, $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,
- $forward_id, $message->header->entity_id),
+ $id, $message->header->entity_id),
$message->header->encoding));
fclose ($fp);
$editor_size, $attachments, $subject, $newmail,
$use_javascript_addr_book, $send_to_bcc, $reply_id, $mailbox,
$from_htmladdr_search, $location_of_buttons, $attachment_dir,
- $username, $data_dir, $identity;
+ $username, $data_dir, $identity, $draft_id, $delete_draft,
+ $mailprio;
$subject = decodeHeader($subject);
$reply_subj = decodeHeader($reply_subj);
do_hook("compose_form");
echo ">\n";
+ if (isset($draft_id)) {
+ echo "<input type=\"hidden\" name=\"delete_draft\" value=\"$draft_id\">\n";
+ }
+ if (isset($delete_draft)) {
+ echo "<input type=\"hidden\" name=\"delete_draft\" value=\"$delete_draft\">\n";
+ }
+
echo "<TABLE WIDTH=\"100%\" ALIGN=center CELLSPACING=0 BORDER=0>\n";
if ($location_of_buttons == 'top') showComposeButtonRow();
// 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 BGCOLOR=\"$color[0]\" VALIGN=MIDDLE ALIGN=RIGHT>\n";
+ echo _("Attach:");
echo " </td><td ALIGN=left BGCOLOR=\"$color[0]\">\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))
- {
+ 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";
printf("<INPUT TYPE=hidden NAME=mailbox VALUE=\"%s\">\n", htmlspecialchars($mailbox));
echo "</FORM>";
do_hook("compose_bottom");
+ echo "</BODY></HTML>\n";
}
function showComposeButtonRow() {
- global $use_javascript_addr_book;
+ global $use_javascript_addr_book, $save_as_draft,
+ $default_use_priority, $mailprio;
echo " <TR><td>\n </td><td>\n";
if ($use_javascript_addr_book) {
}
echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
+ if ($save_as_draft) {
+ echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
+ }
+ if ($default_use_priority) {
+ if(!isset($mailprio)) {
+ $mailprio = "3";
+ }
+ echo "\n\t". _("Priority") .":<select name=\"mailprio\">".
+ "\n\t\t<option value=1".($mailprio=="1"?" selected":"").">". _("High") ."</option>".
+ "\n\t\t<option value=3".($mailprio=="3"?" selected":"").">". _("Normal") ."</option>".
+ "\n\t\t<option value=5".($mailprio=="5"?" selected":"").">". _("Low")."</option>".
+ "\n\t</select>";
+ }
+
do_hook("compose_button_row");
echo " </TD>\n";
// 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)) {
+ require_once ('../src/draft_actions.php');
+ if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id)) {
+ showInputForm();
+ exit();
+ } else {
+ $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=$draft_folder&message=$delete_draft&sort=$sort&startMessage=1");
+ exit();
+ } else {
+ Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort&startMessage=1¬e=$draft_message");
+ exit();
+ }
+ }
+ }
+
if (isset($send)) {
if (isset($HTTP_POST_FILES['attachfile']) &&
$HTTP_POST_FILES['attachfile']['tmp_name'] &&
do_hook("compose_send");
- if (! sendMessage($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id)) {
+ 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();
}
+ if ( isset($delete_draft)) {
+ Header("Location: delete_message.php?mailbox=$draft_folder&message=$delete_draft&sort=$sort&startMessage=1");
+ exit();
+ }
+
Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort&startMessage=1");
} else {
//$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
} 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]);
}
}
if (isset($forward_id) && $forward_id && isset($ent_num) && $ent_num)
getAttachments(0);
+ if (isset($draft_id) && $draft_id && isset($ent_num) && $ent_num)
+ getAttachments(0);
+
newMail();
showInputForm();
sqimap_logout($imapConnection);
}
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);
}
}
/* Build and return the citation string. */
return ($start . $orig_from . $end . "\n");
}
-?>
\ No newline at end of file
+?>