bounce.php
5.2 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/**
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
| |
| Copyright (C) The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Bounce/resend an email message |
+-----------------------------------------------------------------------+
| Author: Thomas Bruederli <roundcube@gmail.com> |
| Author: Aleksander Machniak <alec@alec.pl> |
+-----------------------------------------------------------------------+
*/
class rcmail_action_mail_bounce extends rcmail_action
{
protected static $MESSAGE;
/**
* Request handler.
*
* @param array $args Arguments from the previous step(s)
*/
public function run($args = [])
{
$rcmail = rcmail::get_instance();
$msg_uid = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_GP);
$msg_folder = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_GP, true);
$MESSAGE = new rcube_message($msg_uid, $msg_folder);
self::$MESSAGE = $MESSAGE;
if (!$MESSAGE->headers) {
$rcmail->output->show_message('messageopenerror', 'error');
$rcmail->output->send('iframe');
}
// Display Bounce form
if (empty($_POST)) {
if (!empty($MESSAGE->headers->charset)) {
$rcmail->storage->set_charset($MESSAGE->headers->charset);
}
// Initialize helper class to build the UI
$SENDMAIL = new rcmail_sendmail(
['mode' => rcmail_sendmail::MODE_FORWARD],
['message' => $MESSAGE]
);
$rcmail->output->set_env('mailbox', $msg_folder);
$rcmail->output->set_env('uid', $msg_uid);
$rcmail->output->add_handler('bounceobjects', [$this, 'bounce_objects']);
$rcmail->output->send('bounce');
}
// Initialize helper class to send the message
$SENDMAIL = new rcmail_sendmail(
['mode' => rcmail_sendmail::MODE_FORWARD],
[
'sendmail' => true,
'error_handler' => function() use ($rcmail) {
call_user_func_array([$rcmail->output, 'show_message'], func_get_args());
$rcmail->output->send('iframe');
}
]
);
// Handle the form input
$input_headers = $SENDMAIL->headers_input();
// Set Resent-* headers, these will be added on top of the bounced message
$headers = [];
foreach (['From', 'To', 'Cc', 'Bcc', 'Date', 'Message-ID'] as $name) {
if (!empty($input_headers[$name])) {
$headers['Resent-' . $name] = $input_headers[$name];
}
}
// Create the bounce message
$BOUNCE = new rcmail_resend_mail([
'bounce_message' => $MESSAGE,
'bounce_headers' => $headers,
]);
// Send the bounce message
$SENDMAIL->deliver_message($BOUNCE);
// Save in Sent (if requested)
$saved = $SENDMAIL->save_message($BOUNCE);
if (!$saved && strlen($SENDMAIL->options['store_target'])) {
self::display_server_error('errorsaving');
}
$rcmail->output->show_message('messagesent', 'confirmation', null, false);
$rcmail->output->send('iframe');
}
/**
* Handler for template object 'bounceObjects'
*
* @param array $attrib HTML attributes
*
* @return string HTML content
*/
public static function bounce_objects($attrib)
{
if (empty($attrib['id'])) {
$attrib['id'] = 'bounce-objects';
}
$rcmail = rcmail::get_instance();
$content = [];
// Always display a hint about the bounce feature behavior
$msg = html::span(null, rcube::Q($rcmail->gettext('bouncehint')));
$msg_attrib = ['id' => 'bounce-hint', 'class' => 'boxinformation'];
$content[] = html::div($msg_attrib, $msg);
// Add a warning about Bcc recipients
if (self::$MESSAGE->headers->get('bcc', false) || self::$MESSAGE->headers->get('resent-bcc', false)) {
$msg = html::span(null, rcube::Q($rcmail->gettext('bccemail')));
$msg_attrib = ['id' => 'bcc-warning', 'class' => 'boxwarning'];
$content[] = html::div($msg_attrib, $msg);
}
$plugin = $rcmail->plugins->exec_hook('bounce_objects',
['content' => $content, 'message' => self::$MESSAGE]);
$content = implode("\n", $plugin['content']);
return $content ? html::div($attrib, $content) : '';
}
}