summaryrefslogtreecommitdiff
path: root/program/steps
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2011-05-13 16:29:19 +0000
committeralecpl <alec@alec.pl>2011-05-13 16:29:19 +0000
commita208a4fa68d3c26c34ca3dae250267fec761675c (patch)
tree2daca4f626ae711226f157722c7235282d86269b /program/steps
parent79275b4df5a60d4ffa70ab0e63479a41a962c6e1 (diff)
- Add forward-as-attachment feature
Diffstat (limited to 'program/steps')
-rw-r--r--program/steps/mail/compose.inc66
1 files changed, 64 insertions, 2 deletions
diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 4fe924409..943c800b5 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -214,6 +214,9 @@ if (!empty($msg_uid))
{
$_SESSION['compose']['forward_uid'] = $msg_uid;
$OUTPUT->set_env('compose_mode', 'forward');
+
+ if (!empty($_SESSION['compose']['param']['attachment']))
+ $MESSAGE->forward_attachment = true;
}
}
@@ -560,6 +563,13 @@ function rcmail_prepare_message_body()
$body = $_SESSION['compose']['param']['body'];
$isHtml = false;
}
+ // forward as attachment
+ else if ($compose_mode == RCUBE_COMPOSE_FORWARD && $MESSAGE->forward_attachment) {
+ $isHtml = rcmail_compose_editor_mode();
+ $body = '';
+ if (empty($_SESSION['compose']['attachments']))
+ rcmail_write_forward_attachment($MESSAGE);
+ }
// reply/edit/draft/forward
else if ($compose_mode) {
$has_html_part = $MESSAGE->has_html_part();
@@ -960,8 +970,61 @@ function rcmail_write_inline_attachments(&$message)
return $cid_map;
}
+// Creates an attachment from the forwarded message
+function rcmail_write_forward_attachment(&$message)
+{
+ global $RCMAIL;
+
+ if (strlen($message->subject)) {
+ $name = mb_substr($message->subject, 0, 64) . '.eml';
+ }
+ else {
+ $name = 'message_rfc822.eml';
+ }
+
+ $mem_limit = parse_bytes(ini_get('memory_limit'));
+ $curr_mem = function_exists('memory_get_usage') ? memory_get_usage() : 16*1024*1024; // safe value: 16MB
+ $data = $path = null;
+
+ // don't load too big attachments into memory
+ if ($mem_limit > 0 && $message->size > $mem_limit - $curr_mem) {
+ $temp_dir = unslashify($RCMAIL->config->get('temp_dir'));
+ $path = tempnam($temp_dir, 'rcmAttmnt');
+ if ($fp = fopen($path, 'w')) {
+ $RCMAIL->imap->get_raw_body($message->uid, $fp);
+ fclose($fp);
+ } else
+ return false;
+ } else {
+ $data = $RCMAIL->imap->get_raw_body($message->uid);
+ }
+
+ $attachment = array(
+ 'group' => $_SESSION['compose']['id'],
+ 'name' => $name,
+ 'mimetype' => 'message/rfc822',
+ 'data' => $data,
+ 'path' => $path,
+ 'size' => $path ? filesize($path) : strlen($data),
+ );
+
+ $attachment = $RCMAIL->plugins->exec_hook('attachment_save', $attachment);
+
+ if ($attachment['status']) {
+ unset($attachment['data'], $attachment['status'], $attachment['content_id'], $attachment['abort']);
+ $_SESSION['compose']['attachments'][$attachment['id']] = $attachment;
+ return true;
+ } else if ($path) {
+ @unlink($path);
+ }
+
+ return false;
+}
+
+
function rcmail_save_attachment(&$message, $pid)
{
+ $rcmail = rcmail::get_instance();
$part = $message->mime_parts[$pid];
$mem_limit = parse_bytes(ini_get('memory_limit'));
$curr_mem = function_exists('memory_get_usage') ? memory_get_usage() : 16*1024*1024; // safe value: 16MB
@@ -969,7 +1032,6 @@ function rcmail_save_attachment(&$message, $pid)
// don't load too big attachments into memory
if ($mem_limit > 0 && $part->size > $mem_limit - $curr_mem) {
- $rcmail = rcmail::get_instance();
$temp_dir = unslashify($rcmail->config->get('temp_dir'));
$path = tempnam($temp_dir, 'rcmAttmnt');
if ($fp = fopen($path, 'w')) {
@@ -991,7 +1053,7 @@ function rcmail_save_attachment(&$message, $pid)
'size' => $path ? filesize($path) : strlen($data),
);
- $attachment = rcmail::get_instance()->plugins->exec_hook('attachment_save', $attachment);
+ $attachment = $rcmail->plugins->exec_hook('attachment_save', $attachment);
if ($attachment['status']) {
unset($attachment['data'], $attachment['status'], $attachment['content_id'], $attachment['abort']);