-
Notifications
You must be signed in to change notification settings - Fork 22
/
Status.php
157 lines (138 loc) · 5.31 KB
/
Status.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
/**
* Copyright 2002-2017 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @category Horde
* @copyright 2002-2017 Horde LLC
* @license http://www.horde.org/licenses/gpl GPL
* @package IMP
*/
/**
* Renderer for multipart/report data referring to mail system administrative
* messages (RFC 3464).
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2002-2017 Horde LLC
* @license http://www.horde.org/licenses/gpl GPL
* @package IMP
*/
class IMP_Mime_Viewer_Status extends Horde_Mime_Viewer_Base
{
/**
* This driver's display capabilities.
*
* @var array
*/
protected $_capability = array(
'full' => false,
'info' => true,
'inline' => true,
'raw' => false
);
/**
* Metadata for the current viewer/data.
*
* @var array
*/
protected $_metadata = array(
'compressed' => false,
'embedded' => false,
'forceinline' => true
);
/**
* Return the rendered inline version of the Horde_Mime_Part object.
*
* @return array See parent::render().
*/
protected function _renderInline()
{
return $this->_renderInfo();
}
/**
* Return the rendered information about the Horde_Mime_Part object.
*
* @return array See parent::render().
*/
protected function _renderInfo()
{
$parts = array_keys($this->_mimepart->contentTypeMap());
/* RFC 3464 [2]: There are three parts to a delivery status
* multipart/report message:
* (1) Human readable message
* (2) Machine parsable body part (message/delivery-status)
* (3) Returned message (optional)
*
* Information on the message status is found in the 'Action' field
* located in part #2 (RFC 3464 [2.3.3]). It can be either 'failed',
* 'delayed', 'delivered', 'relayed', or 'expanded'. */
if (count($parts) < 2) {
return array();
}
reset($parts);
$part1_id = next($parts);
$part2_id = Horde_Mime::mimeIdArithmetic($part1_id, 'next');
$part3_id = Horde_Mime::mimeIdArithmetic($part2_id, 'next');
/* Get the action first - it appears in the second part. */
$action = null;
$part2 = $this->getConfigParam('imp_contents')->getMIMEPart($part2_id);
// This would be a broken msg, but don't cause an exception because of it
if (is_null($part2)) {
return array();
}
foreach (explode("\n", $part2->getContents()) as $line) {
if (stristr($line, 'Action:') !== false) {
$action = strtolower(trim(substr($line, strpos($line, ':') + 1)));
if (strpos($action, ' ') !== false) {
$action = substr($action, 0, strpos($action, ' '));
}
break;
}
}
if (is_null($action)) {
return array();
}
/* Get the correct text strings for the action type. */
switch ($action) {
case 'failed':
case 'delayed':
$status = new IMP_Mime_Status(array(
_("ERROR: Your message could not be delivered."),
sprintf(_("Technical error details can be viewed %s."), $this->getConfigParam('imp_contents')->linkViewJS($part2, 'view_attach', _("HERE"), array('jstext' => _("Technical details"), 'params' => array('ctype' => 'text/plain', 'mode' => IMP_Contents::RENDER_FULL))))
));
$status->action(IMP_Mime_Status::ERROR);
$msg_link = _("The text of the returned message can be viewed %s.");
$msg_link_status = _("The text of the returned message");
break;
case 'delivered':
case 'expanded':
case 'relayed':
$status = new IMP_Mime_Status(array(
_("Your message was successfully delivered."),
sprintf(_("Technical message details can be viewed %s."), $this->getConfigParam('imp_contents')->linkViewJS($part2, 'view_attach', _("HERE"), array('jstext' => _("Technical details"), 'params' => array('ctype' => 'text/x-simple', 'mode' => IMP_Contents::RENDER_FULL))))
));
$status->action(IMP_Mime_Status::SUCCESS);
$msg_link = _("The text of the message can be viewed %s.");
$msg_link_status = _("The text of the message");
break;
default:
return array();
}
/* Display a link to the returned message, if it exists. */
$part3 = $this->getConfigParam('imp_contents')->getMIMEPart($part3_id);
if ($part3) {
$status->addText(sprintf($msg_link, $this->getConfigParam('imp_contents')->linkViewJS($part3, 'view_attach', _("HERE"), array('jstext' => $msg_link_status, 'params' => array('ctype' => 'message/rfc822')))));
}
$ret = array_fill_keys(array_diff($parts, array($part1_id)), null);
$ret[$this->_mimepart->getMimeId()] = array(
'data' => '',
'status' => $status,
'type' => 'text/html; charset=' . $this->getConfigParam('charset'),
'wrap' => 'mimePartWrap'
);
return $ret;
}
}