-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathforwardattachment.php
executable file
·101 lines (87 loc) · 2.67 KB
/
forwardattachment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* ForwardAttachment
*
* Plugin to allow forwarding multiple mails as attachments
*
* @version @package_version@
* @author Roland Liebl
* @modified by Philip Weir
*/
class forwardattachment extends rcube_plugin
{
public $task = 'mail';
function init()
{
$this->register_action('plugin.forwardatt', array($this, 'attach_message'));
if (rcube::get_instance()->action == '')
$this->include_script('forwardattachment.js');
}
function attach_message()
{
$rcmail = rcube::get_instance();
$storage = $rcmail->storage;
$temp_dir = $rcmail->config->get('temp_dir');
$COMPOSE_ID = uniqid(mt_rand());
$_SESSION['compose_data_' . $COMPOSE_ID] = array(
'id' => $COMPOSE_ID,
'mailbox' => $storage->get_folder(),
);
$COMPOSE =& $_SESSION['compose_data_' . $COMPOSE_ID];
if ($uids = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_GPC)) {
$uids = explode(",", $uids);
foreach ($uids as $key => $uid) {
$message = new rcube_message($uid);
$this->_rcmail_write_forward_attachment($message, $COMPOSE);
}
}
$COMPOSE['param']['sent_mbox'] = $rcmail->config->get('sent_mbox');
$rcmail->output->redirect(array('_action' => 'compose', '_id' => $COMPOSE['id']));
exit;
}
// Creates an attachment from the forwarded message
// Copied from program/steps/mail/compose.inc
private function _rcmail_write_forward_attachment(&$message, &$COMPOSE)
{
$rcmail = rcube::get_instance();
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->storage->get_raw_body($message->uid, $fp);
fclose($fp);
}
else {
return;
}
}
else {
$data = $rcmail->storage->get_raw_body($message->uid);
}
$attachment = array(
'group' => $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']);
$COMPOSE['attachments'][$attachment['id']] = $attachment;
}
elseif ($path) {
@unlink($path);
}
}
}
?>