annotate program/lib/Roundcube/rcube_message.php @ 24:e53add5ddac5

More cleaning up php8 Warnings/deprecations
author Charlie Root
date Fri, 17 Oct 2025 17:31:22 -0400
parents 303b85d5b561
children bea5a38be938
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1 <?php
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4 +-----------------------------------------------------------------------+
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5 | This file is part of the Roundcube Webmail client |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6 | Copyright (C) 2008-2014, The Roundcube Dev Team |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7 | |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8 | Licensed under the GNU General Public License version 3 or |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9 | any later version with exceptions for skins & plugins. |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
10 | See the README file for a full license statement. |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
11 | |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
12 | PURPOSE: |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
13 | Logical representation of a mail message with all its data |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
14 | and related functions |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
15 +-----------------------------------------------------------------------+
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
16 | Author: Thomas Bruederli <roundcube@gmail.com> |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
17 +-----------------------------------------------------------------------+
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
18 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
19
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
20 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
21 * Logical representation of a mail message with all its data
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
22 * and related functions
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
23 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
24 * @package Framework
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
25 * @subpackage Storage
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
26 * @author Thomas Bruederli <roundcube@gmail.com>
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
27 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
28 class rcube_message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
29 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
30 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
31 * Instance of framework class.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
32 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
33 * @var rcube
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
34 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
35 private $app;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
36
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
37 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
38 * Instance of storage class
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
39 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
40 * @var rcube_storage
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
41 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
42 private $storage;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
43
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
44 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
45 * Instance of mime class
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
46 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
47 * @var rcube_mime
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
48 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
49 private $mime;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
50 private $opt = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
51 private $parse_alternative = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
52
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
53 public $uid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
54 public $folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
55 public $headers;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
56 public $sender;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
57 public $context;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
58 public $parts = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
59 public $mime_parts = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
60 public $inline_parts = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
61 public $attachments = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
62 public $subject = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
63 public $is_safe = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
64
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
65 const BODY_MAX_SIZE = 1048576; // 1MB
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
66
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
67
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
68 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
69 * __construct
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
70 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
71 * Provide a uid, and parse message structure.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
72 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
73 * @param string $uid The message UID.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
74 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
75 * @param bool $is_safe Security flag
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
76 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
77 * @see self::$app, self::$storage, self::$opt, self::$parts
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
78 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
79 function __construct($uid, $folder = null, $is_safe = false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
80 {
22
303b85d5b561 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 19
diff changeset
81 $context = null;
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
82 // decode combined UID-folder identifier
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
83 if (preg_match('/^[0-9.]+-.+/', $uid)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
84 list($uid, $folder) = explode('-', $uid, 2);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
85 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
86
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
87 if (preg_match('/^([0-9]+)\.([0-9.]+)$/', $uid, $matches)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
88 $uid = $matches[1];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
89 $context = $matches[2];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
90 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
91
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
92 $this->uid = $uid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
93 $this->context = $context;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
94 $this->app = rcube::get_instance();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
95 $this->storage = $this->app->get_storage();
24
e53add5ddac5 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 22
diff changeset
96 $this->folder = (!empty($folder)) ? $folder : $this->storage->get_folder();
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
97
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
98 // Set current folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
99 $this->storage->set_folder($this->folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
100 $this->storage->set_options(array('all_headers' => true));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
101
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
102 $this->headers = $this->storage->get_message($uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
103
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
104 if (!$this->headers) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
105 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
106 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
107
22
303b85d5b561 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 19
diff changeset
108 $this->set_safe($is_safe || ($_SESSION['safe_messages'][$this->folder.':'.$uid]??null));
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
109 $this->opt = array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
110 'safe' => $this->is_safe,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
111 'prefer_html' => $this->app->config->get('prefer_html'),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
112 'get_url' => $this->app->url(array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
113 'action' => 'get',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
114 'mbox' => $this->folder,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
115 'uid' => $uid),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
116 false, false, true)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
117 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
118
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
119 if (!empty($this->headers->structure)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
120 $this->get_mime_numbers($this->headers->structure);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
121 $this->parse_structure($this->headers->structure);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
122 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
123 else if ($this->context === null) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
124 $this->body = $this->storage->get_body($uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
125 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
126
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
127 $this->mime = new rcube_mime($this->headers->charset);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
128 $this->subject = $this->headers->get('subject');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
129 $from = $this->mime->decode_address_list($this->headers->from, 1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
130 $this->sender = current($from);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
131
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
132 // notify plugins and let them analyze this structured message object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
133 $this->app->plugins->exec_hook('message_load', array('object' => $this));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
134 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
135
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
136 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
137 * Return a (decoded) message header
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
138 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
139 * @param string $name Header name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
140 * @param bool $row Don't mime-decode the value
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
141 * @return string Header value
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
142 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
143 public function get_header($name, $raw = false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
144 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
145 if (empty($this->headers)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
146 return null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
147 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
148
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
149 return $this->headers->get($name, !$raw);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
150 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
151
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
152 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
153 * Set is_safe var and session data
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
154 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
155 * @param bool $safe enable/disable
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
156 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
157 public function set_safe($safe = true)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
158 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
159 $_SESSION['safe_messages'][$this->folder.':'.$this->uid] = $this->is_safe = $safe;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
160 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
161
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
162 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
163 * Compose a valid URL for getting a message part
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
164 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
165 * @param string $mime_id Part MIME-ID
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
166 * @param mixed $embed Mimetype class for parts to be embedded
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
167 * @return string URL or false if part does not exist
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
168 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
169 public function get_part_url($mime_id, $embed = false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
170 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
171 if ($this->mime_parts[$mime_id])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
172 return $this->opt['get_url'] . '&_part=' . $mime_id . ($embed ? '&_embed=1&_mimeclass=' . $embed : '');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
173 else
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
174 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
175 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
176
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
177 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
178 * Get content of a specific part of this message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
179 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
180 * @param string $mime_id Part MIME-ID
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
181 * @param resource $fp File pointer to save the message part
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
182 * @param boolean $skip_charset_conv Disables charset conversion
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
183 * @param int $max_bytes Only read this number of bytes
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
184 * @param boolean $formatted Enables formatting of text/* parts bodies
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
185 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
186 * @return string Part content
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
187 * @deprecated
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
188 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
189 public function get_part_content($mime_id, $fp = null, $skip_charset_conv = false, $max_bytes = 0, $formatted = true)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
190 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
191 if ($part = $this->mime_parts[$mime_id]) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
192 // stored in message structure (winmail/inline-uuencode)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
193 if (!empty($part->body) || $part->encoding == 'stream') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
194 if ($fp) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
195 fwrite($fp, $part->body);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
196 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
197 return $fp ? true : $part->body;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
198 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
199
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
200 // get from IMAP
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
201 $this->storage->set_folder($this->folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
202
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
203 return $this->storage->get_message_part($this->uid, $mime_id, $part,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
204 NULL, $fp, $skip_charset_conv, $max_bytes, $formatted);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
205 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
206 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
207
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
208 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
209 * Get content of a specific part of this message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
210 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
211 * @param string $mime_id Part ID
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
212 * @param boolean $formatted Enables formatting of text/* parts bodies
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
213 * @param int $max_bytes Only return/read this number of bytes
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
214 * @param mixed $mode NULL to return a string, -1 to print body
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
215 * or file pointer to save the body into
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
216 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
217 * @return string|bool Part content or operation status
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
218 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
219 public function get_part_body($mime_id, $formatted = false, $max_bytes = 0, $mode = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
220 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
221 if (!($part = $this->mime_parts[$mime_id])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
222 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
223 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
224
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
225 // allow plugins to modify part body
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
226 $plugin = $this->app->plugins->exec_hook('message_part_body',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
227 array('object' => $this, 'part' => $part));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
228
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
229 // only text parts can be formatted
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
230 $formatted = $formatted && $part->ctype_primary == 'text';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
231
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
232 // part body not fetched yet... save in memory if it's small enough
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
233 if ($part->body === null && is_numeric($mime_id) && $part->size < self::BODY_MAX_SIZE) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
234 $this->storage->set_folder($this->folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
235 // Warning: body here should be always unformatted
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
236 $part->body = $this->storage->get_message_part($this->uid, $mime_id, $part,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
237 null, null, true, 0, false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
238 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
239
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
240 // body stored in message structure (winmail/inline-uuencode)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
241 if ($part->body !== null || $part->encoding == 'stream') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
242 $body = $part->body;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
243
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
244 if ($formatted && $body) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
245 $body = self::format_part_body($body, $part, $this->headers->charset);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
246 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
247
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
248 if ($max_bytes && strlen($body) > $max_bytes) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
249 $body = substr($body, 0, $max_bytes);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
250 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
251
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
252 if (is_resource($mode)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
253 if ($body !== false) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
254 fwrite($mode, $body);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
255 rewind($mode);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
256 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
257
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
258 return $body !== false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
259 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
260
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
261 if ($mode === -1) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
262 if ($body !== false) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
263 print($body);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
264 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
265
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
266 return $body !== false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
267 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
268
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
269 return $body;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
270 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
271
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
272 // get the body from IMAP
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
273 $this->storage->set_folder($this->folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
274
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
275 $body = $this->storage->get_message_part($this->uid, $mime_id, $part,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
276 $mode === -1, is_resource($mode) ? $mode : null,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
277 !($mode && $formatted), $max_bytes, $mode && $formatted);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
278
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
279 if (is_resource($mode)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
280 rewind($mode);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
281 return $body !== false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
282 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
283
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
284 if (!$mode && $body && $formatted) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
285 $body = self::format_part_body($body, $part, $this->headers->charset);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
286 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
287
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
288 return $body;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
289 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
290
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
291 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
292 * Format text message part for display
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
293 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
294 * @param string $body Part body
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
295 * @param rcube_message_part $part Part object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
296 * @param string $default_charset Fallback charset if part charset is not specified
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
297 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
298 * @return string Formatted body
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
299 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
300 public static function format_part_body($body, $part, $default_charset = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
301 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
302 // remove useless characters
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
303 $body = preg_replace('/[\t\r\0\x0B]+\n/', "\n", $body);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
304
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
305 // remove NULL characters if any (#1486189)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
306 if (strpos($body, "\x00") !== false) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
307 $body = str_replace("\x00", '', $body);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
308 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
309
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
310 // detect charset...
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
311 if (!$part->charset || strtoupper($part->charset) == 'US-ASCII') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
312 // try to extract charset information from HTML meta tag (#1488125)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
313 if ($part->ctype_secondary == 'html' && preg_match('/<meta[^>]+charset=([a-z0-9-_]+)/i', $body, $m)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
314 $part->charset = strtoupper($m[1]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
315 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
316 else if ($default_charset) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
317 $part->charset = $default_charset;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
318 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
319 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
320 $rcube = rcube::get_instance();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
321 $part->charset = $rcube->config->get('default_charset', RCUBE_CHARSET);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
322 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
323 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
324
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
325 // ..convert charset encoding
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
326 $body = rcube_charset::convert($body, $part->charset);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
327
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
328 return $body;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
329 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
330
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
331 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
332 * Determine if the message contains a HTML part. This must to be
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
333 * a real part not an attachment (or its part)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
334 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
335 * @param bool $enriched Enables checking for text/enriched parts too
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
336 * @param rcube_message_part &$part Reference to the part if found
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
337 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
338 * @return bool True if a HTML is available, False if not
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
339 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
340 public function has_html_part($enriched = false, &$part = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
341 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
342 // check all message parts
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
343 foreach ($this->mime_parts as $part) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
344 if ($part->mimetype == 'text/html' || ($enriched && $part->mimetype == 'text/enriched')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
345 // Skip if part is an attachment, don't use is_attachment() here
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
346 if ($part->filename) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
347 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
348 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
349
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
350 if (!$part->size) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
351 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
352 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
353
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
354 if (!$this->check_context($part)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
355 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
356 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
357
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
358 $level = explode('.', $part->mime_id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
359 $depth = count($level);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
360 $last = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
361
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
362 // Check if the part belongs to higher-level's multipart part
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
363 // this can be alternative/related/signed/encrypted or mixed
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
364 while (array_pop($level) !== null) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
365 $parent_depth = count($level);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
366 if (!$parent_depth) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
367 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
368 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
369
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
370 $parent = $this->mime_parts[join('.', $level)];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
371
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
372 if (!$this->check_context($parent)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
373 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
374 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
375
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
376 $max_delta = $depth - (1 + ($last == 'multipart/alternative' ? 1 : 0));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
377 $last = $parent->real_mimetype ?: $parent->mimetype;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
378
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
379 if (!preg_match('/^multipart\/(alternative|related|signed|encrypted|mixed)$/', $last)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
380 || ($last == 'multipart/mixed' && $parent_depth < $max_delta)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
381 continue 2;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
382 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
383 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
384
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
385 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
386 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
387 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
388
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
389 $part = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
390
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
391 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
392 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
393
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
394 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
395 * Determine if the message contains a text/plain part. This must to be
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
396 * a real part not an attachment (or its part)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
397 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
398 * @param rcube_message_part &$part Reference to the part if found
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
399 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
400 * @return bool True if a plain text part is available, False if not
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
401 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
402 public function has_text_part(&$part = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
403 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
404 // check all message parts
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
405 foreach ($this->mime_parts as $part) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
406 if ($part->mimetype == 'text/plain') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
407 // Skip if part is an attachment, don't use is_attachment() here
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
408 if ($part->filename) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
409 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
410 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
411
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
412 if (!$part->size) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
413 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
414 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
415
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
416 if (!$this->check_context($part)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
417 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
418 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
419
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
420 $level = explode('.', $part->mime_id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
421
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
422 // Check if the part belongs to higher-level's alternative/related
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
423 while (array_pop($level) !== null) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
424 if (!count($level)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
425 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
426 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
427
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
428 $parent = $this->mime_parts[join('.', $level)];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
429
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
430 if (!$this->check_context($parent)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
431 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
432 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
433
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
434 if ($parent->mimetype != 'multipart/alternative' && $parent->mimetype != 'multipart/related') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
435 continue 2;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
436 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
437 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
438
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
439 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
440 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
441 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
442
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
443 $part = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
444
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
445 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
446 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
447
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
448 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
449 * Return the first HTML part of this message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
450 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
451 * @param rcube_message_part &$part Reference to the part if found
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
452 * @param bool $enriched Enables checking for text/enriched parts too
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
453 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
454 * @return string HTML message part content
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
455 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
456 public function first_html_part(&$part = null, $enriched = false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
457 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
458 if ($this->has_html_part($enriched, $part)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
459 $body = $this->get_part_body($part->mime_id, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
460
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
461 if ($part->mimetype == 'text/enriched') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
462 $body = rcube_enriched::to_html($body);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
463 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
464
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
465 return $body;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
466 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
467 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
468
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
469 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
470 * Return the first text part of this message.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
471 * If there's no text/plain part but $strict=true and text/html part
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
472 * exists, it will be returned in text/plain format.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
473 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
474 * @param rcube_message_part &$part Reference to the part if found
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
475 * @param bool $strict Check only text/plain parts
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
476 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
477 * @return string Plain text message/part content
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
478 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
479 public function first_text_part(&$part = null, $strict = false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
480 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
481 // no message structure, return complete body
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
482 if (empty($this->parts)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
483 return $this->body;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
484 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
485
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
486 if ($this->has_text_part($part)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
487 return $this->get_part_body($part->mime_id, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
488 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
489
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
490 if (!$strict && ($body = $this->first_html_part($part, true))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
491 // create instance of html2text class
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
492 $h2t = new rcube_html2text($body);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
493 return $h2t->get_text();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
494 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
495 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
496
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
497 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
498 * Return message parts in current context
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
499 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
500 public function mime_parts()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
501 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
502 if ($this->context === null) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
503 return $this->mime_parts;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
504 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
505
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
506 $parts = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
507
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
508 foreach ($this->mime_parts as $part_id => $part) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
509 if ($this->check_context($part)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
510 $parts[$part_id] = $part;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
511 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
512 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
513
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
514 return $parts;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
515 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
516
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
517 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
518 * Checks if part of the message is an attachment (or part of it)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
519 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
520 * @param rcube_message_part $part Message part
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
521 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
522 * @return bool True if the part is an attachment part
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
523 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
524 public function is_attachment($part)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
525 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
526 foreach ($this->attachments as $att_part) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
527 if ($att_part->mime_id == $part->mime_id) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
528 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
529 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
530
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
531 // check if the part is a subpart of another attachment part (message/rfc822)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
532 if ($att_part->mimetype == 'message/rfc822') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
533 if (in_array($part, (array)$att_part->parts)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
534 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
535 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
536 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
537 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
538
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
539 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
540 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
541
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
542 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
543 * In a multipart/encrypted encrypted message,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
544 * find the encrypted message payload part.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
545 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
546 * @return rcube_message_part
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
547 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
548 public function get_multipart_encrypted_part()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
549 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
550 foreach ($this->mime_parts as $mime_id => $mpart) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
551 if ($mpart->mimetype == 'multipart/encrypted') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
552 $this->pgp_mime = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
553 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
554 if ($this->pgp_mime && ($mpart->mimetype == 'application/octet-stream' ||
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
555 (!empty($mpart->filename) && $mpart->filename != 'version.txt'))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
556 $this->encrypted_part = $mime_id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
557 return $mpart;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
558 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
559 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
560
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
561 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
562 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
563
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
564 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
565 * Read the message structure returend by the IMAP server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
566 * and build flat lists of content parts and attachments
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
567 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
568 * @param rcube_message_part $structure Message structure node
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
569 * @param bool $recursive True when called recursively
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
570 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
571 private function parse_structure($structure, $recursive = false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
572 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
573 // real content-type of message/rfc822 part
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
574 if ($structure->mimetype == 'message/rfc822' && $structure->real_mimetype) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
575 $mimetype = $structure->real_mimetype;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
576
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
577 // parse headers from message/rfc822 part
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
578 if (!isset($structure->headers['subject']) && !isset($structure->headers['from'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
579 list($headers, ) = explode("\r\n\r\n", $this->get_part_body($structure->mime_id, false, 32768));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
580 $structure->headers = rcube_mime::parse_headers($headers);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
581
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
582 if ($this->context == $structure->mime_id) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
583 $this->headers = rcube_message_header::from_array($structure->headers);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
584 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
585 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
586 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
587 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
588 $mimetype = $structure->mimetype;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
589 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
590
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
591 // show message headers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
592 if ($recursive && is_array($structure->headers) &&
24
e53add5ddac5 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 22
diff changeset
593 (isset($structure->headers['subject']) || ($structure->headers['from']??false) || ($structure->headers['to']??false))
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
594 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
595 $c = new stdClass;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
596 $c->type = 'headers';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
597 $c->headers = $structure->headers;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
598 $this->add_part($c);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
599 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
600
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
601 // Allow plugins to handle message parts
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
602 $plugin = $this->app->plugins->exec_hook('message_part_structure',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
603 array('object' => $this, 'structure' => $structure,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
604 'mimetype' => $mimetype, 'recursive' => $recursive));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
605
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
606 if ($plugin['abort']) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
607 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
608 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
609
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
610 $structure = $plugin['structure'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
611 $mimetype = $plugin['mimetype'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
612 $recursive = $plugin['recursive'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
613
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
614 list($message_ctype_primary, $message_ctype_secondary) = explode('/', $mimetype);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
615
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
616 // print body if message doesn't have multiple parts
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
617 if ($message_ctype_primary == 'text' && !$recursive) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
618 // parts with unsupported type add to attachments list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
619 if (!in_array($message_ctype_secondary, array('plain', 'html', 'enriched'))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
620 $this->add_part($structure, 'attachment');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
621 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
622 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
623
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
624 $structure->type = 'content';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
625 $this->add_part($structure);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
626
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
627 // Parse simple (plain text) message body
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
628 if ($message_ctype_secondary == 'plain') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
629 foreach ((array)$this->uu_decode($structure) as $uupart) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
630 $this->mime_parts[$uupart->mime_id] = $uupart;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
631 $this->add_part($uupart, 'attachment');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
632 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
633 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
634 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
635 // the same for pgp signed messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
636 else if ($mimetype == 'application/pgp' && !$recursive) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
637 $structure->type = 'content';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
638 $this->add_part($structure);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
639 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
640 // message contains (more than one!) alternative parts
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
641 else if ($mimetype == 'multipart/alternative'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
642 && is_array($structure->parts) && count($structure->parts) > 1
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
643 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
644 // get html/plaintext parts, other add to attachments list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
645 foreach ($structure->parts as $p => $sub_part) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
646 $sub_mimetype = $sub_part->mimetype;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
647 $is_multipart = preg_match('/^multipart\/(related|relative|mixed|alternative)/', $sub_mimetype);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
648
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
649 // skip empty text parts
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
650 if (!$sub_part->size && !$is_multipart) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
651 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
652 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
653
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
654 // We've encountered (malformed) messages with more than
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
655 // one text/plain or text/html part here. There's no way to choose
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
656 // which one is better, so we'll display first of them and add
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
657 // others as attachments (#1489358)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
658
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
659 // check if sub part is
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
660 if ($is_multipart)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
661 $related_part = $p;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
662 else if ($sub_mimetype == 'text/plain' && !$plain_part)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
663 $plain_part = $p;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
664 else if ($sub_mimetype == 'text/html' && !$html_part) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
665 $html_part = $p;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
666 $this->got_html_part = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
667 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
668 else if ($sub_mimetype == 'text/enriched' && !$enriched_part)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
669 $enriched_part = $p;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
670 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
671 // add unsupported/unrecognized parts to attachments list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
672 $this->add_part($sub_part, 'attachment');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
673 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
674 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
675
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
676 // parse related part (alternative part could be in here)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
677 if ($related_part !== null && !$this->parse_alternative) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
678 $this->parse_alternative = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
679 $this->parse_structure($structure->parts[$related_part], true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
680 $this->parse_alternative = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
681
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
682 // if plain part was found, we should unset it if html is preferred
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
683 if ($this->opt['prefer_html'] && count($this->parts)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
684 $plain_part = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
685 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
686 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
687
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
688 // choose html/plain part to print
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
689 if ($html_part !== null && $this->opt['prefer_html']) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
690 $print_part = $structure->parts[$html_part];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
691 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
692 else if ($enriched_part !== null) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
693 $print_part = $structure->parts[$enriched_part];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
694 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
695 else if ($plain_part !== null) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
696 $print_part = $structure->parts[$plain_part];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
697 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
698
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
699 // add the right message body
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
700 if (is_object($print_part)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
701 $print_part->type = 'content';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
702
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
703 // Allow plugins to handle also this part
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
704 $plugin = $this->app->plugins->exec_hook('message_part_structure',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
705 array('object' => $this, 'structure' => $print_part,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
706 'mimetype' => $print_part->mimetype, 'recursive' => true));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
707
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
708 if (!$plugin['abort']) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
709 $this->add_part($print_part);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
710 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
711 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
712 // show plaintext warning
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
713 else if ($html_part !== null && empty($this->parts)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
714 $c = new stdClass;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
715 $c->type = 'content';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
716 $c->ctype_primary = 'text';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
717 $c->ctype_secondary = 'plain';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
718 $c->mimetype = 'text/plain';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
719 $c->realtype = 'text/html';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
720
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
721 $this->add_part($c);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
722 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
723 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
724 // this is an ecrypted message -> create a plaintext body with the according message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
725 else if ($mimetype == 'multipart/encrypted') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
726 $p = new stdClass;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
727 $p->type = 'content';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
728 $p->ctype_primary = 'text';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
729 $p->ctype_secondary = 'plain';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
730 $p->mimetype = 'text/plain';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
731 $p->realtype = 'multipart/encrypted';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
732 $p->mime_id = $structure->mime_id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
733
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
734 $this->add_part($p);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
735
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
736 // add encrypted payload part as attachment
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
737 if (is_array($structure->parts)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
738 for ($i=0; $i < count($structure->parts); $i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
739 $subpart = $structure->parts[$i];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
740 if ($subpart->mimetype == 'application/octet-stream' || !empty($subpart->filename)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
741 $this->add_part($subpart, 'attachment');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
742 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
743 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
744 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
745 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
746 // this is an S/MIME ecrypted message -> create a plaintext body with the according message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
747 else if ($mimetype == 'application/pkcs7-mime') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
748 $p = new stdClass;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
749 $p->type = 'content';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
750 $p->ctype_primary = 'text';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
751 $p->ctype_secondary = 'plain';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
752 $p->mimetype = 'text/plain';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
753 $p->realtype = 'application/pkcs7-mime';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
754 $p->mime_id = $structure->mime_id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
755
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
756 $this->add_part($p);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
757
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
758 if (!empty($structure->filename)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
759 $this->add_part($structure, 'attachment');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
760 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
761 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
762 // message contains multiple parts
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
763 else if (is_array($structure->parts) && !empty($structure->parts)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
764 // iterate over parts
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
765 for ($i=0; $i < count($structure->parts); $i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
766 $mail_part = &$structure->parts[$i];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
767 $primary_type = $mail_part->ctype_primary;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
768 $secondary_type = $mail_part->ctype_secondary;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
769 $part_mimetype = $mail_part->mimetype;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
770
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
771 // multipart/alternative or message/rfc822
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
772 if ($primary_type == 'multipart' || $part_mimetype == 'message/rfc822') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
773 $this->parse_structure($mail_part, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
774
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
775 // list message/rfc822 as attachment as well (mostly .eml)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
776 if ($primary_type == 'message' && !empty($mail_part->filename)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
777 $this->add_part($mail_part, 'attachment');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
778 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
779 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
780 // part text/[plain|html] or delivery status
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
781 else if ((($part_mimetype == 'text/plain' || $part_mimetype == 'text/html') && $mail_part->disposition != 'attachment') ||
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
782 in_array($part_mimetype, array('message/delivery-status', 'text/rfc822-headers', 'message/disposition-notification'))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
783 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
784 // Allow plugins to handle also this part
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
785 $plugin = $this->app->plugins->exec_hook('message_part_structure',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
786 array('object' => $this, 'structure' => $mail_part,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
787 'mimetype' => $part_mimetype, 'recursive' => true));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
788
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
789 if ($plugin['abort']) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
790 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
791 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
792
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
793 if ($part_mimetype == 'text/html' && $mail_part->size) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
794 $this->got_html_part = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
795 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
796
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
797 $mail_part = $plugin['structure'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
798 list($primary_type, $secondary_type) = explode('/', $plugin['mimetype']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
799
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
800 // add text part if it matches the prefs
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
801 if (!$this->parse_alternative ||
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
802 ($secondary_type == 'html' && $this->opt['prefer_html']) ||
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
803 ($secondary_type == 'plain' && !$this->opt['prefer_html'])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
804 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
805 $mail_part->type = 'content';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
806 $this->add_part($mail_part);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
807 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
808
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
809 // list as attachment as well
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
810 if (!empty($mail_part->filename)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
811 $this->add_part($mail_part, 'attachment');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
812 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
813 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
814 // ignore "virtual" protocol parts
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
815 else if ($primary_type == 'protocol') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
816 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
817 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
818 // part is Microsoft Outlook TNEF (winmail.dat)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
819 else if ($part_mimetype == 'application/ms-tnef') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
820 $tnef_parts = (array) $this->tnef_decode($mail_part);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
821 foreach ($tnef_parts as $tpart) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
822 $this->mime_parts[$tpart->mime_id] = $tpart;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
823 $this->add_part($tpart, 'attachment');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
824 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
825
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
826 // add winmail.dat to the list if it's content is unknown
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
827 if (empty($tnef_parts) && !empty($mail_part->filename)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
828 $this->mime_parts[$mail_part->mime_id] = $mail_part;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
829 $this->add_part($mail_part, 'attachment');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
830 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
831 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
832 // part is a file/attachment
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
833 else if (preg_match('/^(inline|attach)/', $mail_part->disposition) ||
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
834 $mail_part->headers['content-id'] ||
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
835 ($mail_part->filename &&
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
836 (empty($mail_part->disposition) || preg_match('/^[a-z0-9!#$&.+^_-]+$/i', $mail_part->disposition)))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
837 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
838 // skip apple resource forks
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
839 if ($message_ctype_secondary == 'appledouble' && $secondary_type == 'applefile')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
840 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
841
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
842 // part belongs to a related message and is linked
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
843 if (preg_match('/^multipart\/(related|relative)/', $mimetype)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
844 && ($mail_part->headers['content-id'] || $mail_part->headers['content-location'])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
845 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
846 if ($mail_part->headers['content-id'])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
847 $mail_part->content_id = preg_replace(array('/^</', '/>$/'), '', $mail_part->headers['content-id']);
24
e53add5ddac5 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 22
diff changeset
848 if (!isempty($mail_part->headers['content-location']))
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
849 $mail_part->content_location = $mail_part->headers['content-base'] . $mail_part->headers['content-location'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
850
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
851 $this->add_part($mail_part, 'inline');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
852 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
853 // regular attachment with valid content type
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
854 // (content-type name regexp according to RFC4288.4.2)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
855 else if (preg_match('/^[a-z0-9!#$&.+^_-]+\/[a-z0-9!#$&.+^_-]+$/i', $part_mimetype)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
856 $this->add_part($mail_part, 'attachment');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
857 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
858 // attachment with invalid content type
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
859 // replace malformed content type with application/octet-stream (#1487767)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
860 else if ($mail_part->filename) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
861 $mail_part->ctype_primary = 'application';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
862 $mail_part->ctype_secondary = 'octet-stream';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
863 $mail_part->mimetype = 'application/octet-stream';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
864
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
865 $this->add_part($mail_part, 'attachment');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
866 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
867 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
868 // calendar part not marked as attachment (#1490325)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
869 else if ($part_mimetype == 'text/calendar') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
870 if (!$mail_part->filename) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
871 $mail_part->filename = 'calendar.ics';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
872 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
873
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
874 $this->add_part($mail_part, 'attachment');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
875 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
876 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
877
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
878 // if this was a related part try to resolve references
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
879 if (preg_match('/^multipart\/(related|relative)/', $mimetype) && count($this->inline_parts)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
880 $a_replaces = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
881 $img_regexp = '/^image\/(gif|jpe?g|png|tiff|bmp|svg)/';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
882
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
883 foreach ($this->inline_parts as $inline_object) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
884 $part_url = $this->get_part_url($inline_object->mime_id, $inline_object->ctype_primary);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
885 if (isset($inline_object->content_id))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
886 $a_replaces['cid:'.$inline_object->content_id] = $part_url;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
887 if ($inline_object->content_location) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
888 $a_replaces[$inline_object->content_location] = $part_url;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
889 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
890
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
891 if (!empty($inline_object->filename)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
892 // MS Outlook sends sometimes non-related attachments as related
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
893 // In this case multipart/related message has only one text part
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
894 // We'll add all such attachments to the attachments list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
895 if (!isset($this->got_html_part)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
896 $this->add_part($inline_object, 'attachment');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
897 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
898 // MS Outlook sometimes also adds non-image attachments as related
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
899 // We'll add all such attachments to the attachments list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
900 // Warning: some browsers support pdf in <img/>
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
901 else if (!preg_match($img_regexp, $inline_object->mimetype)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
902 $this->add_part($inline_object, 'attachment');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
903 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
904 // @TODO: we should fetch HTML body and find attachment's content-id
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
905 // to handle also image attachments without reference in the body
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
906 // @TODO: should we list all image attachments in text mode?
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
907 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
908 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
909
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
910 // add replace array to each content part
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
911 // (will be applied later when part body is available)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
912 foreach ($this->parts as $i => $part) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
913 if ($part->type == 'content')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
914 $this->parts[$i]->replaces = $a_replaces;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
915 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
916 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
917 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
918 // message is a single part non-text
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
919 else if ($structure->filename || preg_match('/^application\//i', $mimetype)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
920 $this->add_part($structure, 'attachment');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
921 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
922 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
923
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
924 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
925 * Fill a flat array with references to all parts, indexed by part numbers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
926 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
927 * @param rcube_message_part $part Message body structure
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
928 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
929 private function get_mime_numbers(&$part)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
930 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
931 if (strlen($part->mime_id))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
932 $this->mime_parts[$part->mime_id] = &$part;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
933
19
b6a96bdd6b29 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 0
diff changeset
934 if (is_array($part->parts??null))
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
935 for ($i=0; $i<count($part->parts); $i++)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
936 $this->get_mime_numbers($part->parts[$i]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
937 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
938
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
939 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
940 * Add a part to object parts array(s) (with context check)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
941 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
942 private function add_part($part, $type = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
943 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
944 if ($this->check_context($part)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
945 switch ($type) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
946 case 'inline': $this->inline_parts[] = $part; break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
947 case 'attachment': $this->attachments[] = $part; break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
948 default: $this->parts[] = $part; break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
949 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
950 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
951 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
952
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
953 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
954 * Check if specified part belongs to the current context
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
955 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
956 private function check_context($part)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
957 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
958 return $this->context === null || strpos($part->mime_id, $this->context . '.') === 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
959 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
960
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
961 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
962 * Decode a Microsoft Outlook TNEF part (winmail.dat)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
963 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
964 * @param rcube_message_part $part Message part to decode
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
965 * @return array
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
966 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
967 function tnef_decode(&$part)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
968 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
969 // @TODO: attachment may be huge, handle body via file
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
970 $body = $this->get_part_body($part->mime_id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
971 $tnef = new rcube_tnef_decoder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
972 $tnef_arr = $tnef->decompress($body);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
973 $parts = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
974
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
975 unset($body);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
976
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
977 foreach ($tnef_arr as $pid => $winatt) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
978 $tpart = new rcube_message_part;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
979
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
980 $tpart->filename = $this->fix_attachment_name(trim($winatt['name']), $part);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
981 $tpart->encoding = 'stream';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
982 $tpart->ctype_primary = trim(strtolower($winatt['type']));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
983 $tpart->ctype_secondary = trim(strtolower($winatt['subtype']));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
984 $tpart->mimetype = $tpart->ctype_primary . '/' . $tpart->ctype_secondary;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
985 $tpart->mime_id = 'winmail.' . $part->mime_id . '.' . $pid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
986 $tpart->size = $winatt['size'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
987 $tpart->body = $winatt['stream'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
988
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
989 $parts[] = $tpart;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
990 unset($tnef_arr[$pid]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
991 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
992
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
993 return $parts;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
994 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
995
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
996 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
997 * Parse message body for UUencoded attachments bodies
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
998 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
999 * @param rcube_message_part $part Message part to decode
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1000 * @return array
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1001 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1002 function uu_decode(&$part)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1003 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1004 // @TODO: messages may be huge, handle body via file
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1005 $part->body = $this->get_part_body($part->mime_id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1006 $parts = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1007 $pid = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1008
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1009 // FIXME: line length is max.65?
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1010 $uu_regexp_begin = '/begin [0-7]{3,4} ([^\r\n]+)\r?\n/s';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1011 $uu_regexp_end = '/`\r?\nend((\r?\n)|($))/s';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1012
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1013 while (preg_match($uu_regexp_begin, $part->body, $matches, PREG_OFFSET_CAPTURE)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1014 $startpos = $matches[0][1];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1015
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1016 if (!preg_match($uu_regexp_end, $part->body, $m, PREG_OFFSET_CAPTURE, $startpos)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1017 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1018 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1019
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1020 $endpos = $m[0][1];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1021 $begin_len = strlen($matches[0][0]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1022 $end_len = strlen($m[0][0]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1023
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1024 // extract attachment body
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1025 $filebody = substr($part->body, $startpos + $begin_len, $endpos - $startpos - $begin_len - 1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1026 $filebody = str_replace("\r\n", "\n", $filebody);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1027
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1028 // remove attachment body from the message body
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1029 $part->body = substr_replace($part->body, '', $startpos, $endpos + $end_len - $startpos);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1030 // mark body as modified so it will not be cached by rcube_imap_cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1031 $part->body_modified = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1032
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1033 // add attachments to the structure
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1034 $uupart = new rcube_message_part;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1035 $uupart->filename = trim($matches[1][0]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1036 $uupart->encoding = 'stream';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1037 $uupart->body = convert_uudecode($filebody);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1038 $uupart->size = strlen($uupart->body);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1039 $uupart->mime_id = 'uu.' . $part->mime_id . '.' . $pid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1040
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1041 $ctype = rcube_mime::file_content_type($uupart->body, $uupart->filename, 'application/octet-stream', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1042 $uupart->mimetype = $ctype;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1043 list($uupart->ctype_primary, $uupart->ctype_secondary) = explode('/', $ctype);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1044
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1045 $parts[] = $uupart;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1046 $pid++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1047 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1048
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1049 return $parts;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1050 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1051
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1052 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1053 * Fix attachment name encoding if needed/possible
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1054 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1055 protected function fix_attachment_name($name, $part)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1056 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1057 if ($name == rcube_charset::clean($name)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1058 return $name;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1059 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1060
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1061 // find charset from part or its parent(s)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1062 if ($part->charset) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1063 $charsets[] = $part->charset;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1064 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1065 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1066 // check first part (common case)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1067 $n = strpos($part->mime_id, '.') ? preg_replace('/\.[0-9]+$/', '', $part->mime_id) . '.1' : 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1068 if (($_part = $this->mime_parts[$n]) && $_part->charset) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1069 $charsets[] = $_part->charset;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1070 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1071
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1072 // check parents' charset
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1073 $items = explode('.', $part->mime_id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1074 for ($i = count($items)-1; $i > 0; $i--) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1075 $last = array_pop($items);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1076 $parent = $this->mime_parts[join('.', $items)];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1077
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1078 if ($parent && $parent->charset) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1079 $charsets[] = $parent->charset;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1080 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1081 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1082 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1083
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1084 if ($this->headers->charset) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1085 $charsets[] = $this->headers->charset;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1086 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1087
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1088 if (empty($charsets)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1089 $rcube = rcube::get_instance();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1090 $charsets[] = rcube_charset::detect($name, $rcube->config->get('default_charset', RCUBE_CHARSET));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1091 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1092
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1093 foreach (array_unique($charsets) as $charset) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1094 $_name = rcube_charset::convert($name, $charset);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1095
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1096 if ($_name == rcube_charset::clean($_name)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1097 if (!$part->charset) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1098 $part->charset = $charset;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1099 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1100
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1101 return $_name;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1102 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1103 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1104
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1105 return $name;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1106 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1107
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1108 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1109 * Deprecated methods (to be removed)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1110 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1111
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1112 public static function unfold_flowed($text)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1113 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1114 return rcube_mime::unfold_flowed($text);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1115 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1116
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1117 public static function format_flowed($text, $length = 72)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1118 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1119 return rcube_mime::format_flowed($text, $length);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1120 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1121 }