0
|
1 <?php
|
|
2
|
|
3 /**
|
|
4 +-----------------------------------------------------------------------+
|
|
5 | program/steps/mail/compose.inc |
|
|
6 | |
|
|
7 | This file is part of the Roundcube Webmail client |
|
|
8 | Copyright (C) 2005-2016, The Roundcube Dev Team |
|
|
9 | |
|
|
10 | Licensed under the GNU General Public License version 3 or |
|
|
11 | any later version with exceptions for skins & plugins. |
|
|
12 | See the README file for a full license statement. |
|
|
13 | |
|
|
14 | PURPOSE: |
|
|
15 | Compose a new mail message with all headers and attachments |
|
|
16 | |
|
|
17 +-----------------------------------------------------------------------+
|
|
18 | Author: Thomas Bruederli <roundcube@gmail.com> |
|
|
19 +-----------------------------------------------------------------------+
|
|
20 */
|
|
21
|
|
22 // define constants for message compose mode
|
|
23 define('RCUBE_COMPOSE_REPLY', 'reply');
|
|
24 define('RCUBE_COMPOSE_FORWARD', 'forward');
|
|
25 define('RCUBE_COMPOSE_DRAFT', 'draft');
|
|
26 define('RCUBE_COMPOSE_EDIT', 'edit');
|
|
27
|
|
28 $MESSAGE_FORM = null;
|
|
29 $COMPOSE_ID = rcube_utils::get_input_value('_id', rcube_utils::INPUT_GET);
|
|
30 $COMPOSE = null;
|
|
31
|
|
32 if ($COMPOSE_ID && $_SESSION['compose_data_'.$COMPOSE_ID])
|
|
33 $COMPOSE =& $_SESSION['compose_data_'.$COMPOSE_ID];
|
|
34
|
|
35 // give replicated session storage some time to synchronize
|
|
36 $retries = 0;
|
|
37 while ($COMPOSE_ID && !is_array($COMPOSE) && $RCMAIL->db->is_replicated() && $retries++ < 5) {
|
|
38 usleep(500000);
|
|
39 $RCMAIL->session->reload();
|
|
40 if ($_SESSION['compose_data_'.$COMPOSE_ID]) {
|
|
41 $COMPOSE =& $_SESSION['compose_data_'.$COMPOSE_ID];
|
|
42 }
|
|
43 }
|
|
44
|
|
45 // Nothing below is called during message composition, only at "new/forward/reply/draft" initialization or
|
|
46 // if a compose-ID is given (i.e. when the compose step is opened in a new window/tab).
|
|
47 if (!is_array($COMPOSE)) {
|
|
48 // Infinite redirect prevention in case of broken session (#1487028)
|
|
49 if ($COMPOSE_ID) {
|
|
50 // if we know the message with specified ID was already sent
|
|
51 // we can ignore the error and compose a new message (#1490009)
|
|
52 if ($COMPOSE_ID != $_SESSION['last_compose_session']) {
|
|
53 rcube::raise_error(array('code' => 450), false, true);
|
|
54 }
|
|
55 }
|
|
56
|
|
57 $COMPOSE_ID = uniqid(mt_rand());
|
|
58 $params = rcube_utils::request2param(rcube_utils::INPUT_GET, 'task|action', true);
|
|
59
|
|
60 $_SESSION['compose_data_'.$COMPOSE_ID] = array(
|
|
61 'id' => $COMPOSE_ID,
|
|
62 'param' => $params,
|
|
63 'mailbox' => $params['mbox'] ?: $RCMAIL->storage->get_folder(),
|
|
64 );
|
|
65 $COMPOSE =& $_SESSION['compose_data_'.$COMPOSE_ID];
|
|
66 rcmail_process_compose_params($COMPOSE);
|
|
67
|
|
68 // check if folder for saving sent messages exists and is subscribed (#1486802)
|
|
69 if ($sent_folder = $COMPOSE['param']['sent_mbox']) {
|
|
70 rcmail_check_sent_folder($sent_folder, true);
|
|
71 }
|
|
72
|
|
73 // redirect to a unique URL with all parameters stored in session
|
|
74 $OUTPUT->redirect(array(
|
|
75 '_action' => 'compose',
|
|
76 '_id' => $COMPOSE['id'],
|
|
77 '_search' => $_REQUEST['_search'],
|
|
78 ));
|
|
79 }
|
|
80
|
|
81
|
|
82 // add some labels to client
|
|
83 $OUTPUT->add_label('nosubject', 'nosenderwarning', 'norecipientwarning', 'nosubjectwarning', 'cancel',
|
|
84 'nobodywarning', 'notsentwarning', 'notuploadedwarning', 'savingmessage', 'sendingmessage',
|
|
85 'messagesaved', 'converting', 'editorwarning', 'searching', 'uploading', 'uploadingmany',
|
|
86 'fileuploaderror', 'sendmessage', 'newresponse', 'responsename', 'responsetext', 'save',
|
|
87 'savingresponse', 'restoresavedcomposedata', 'restoremessage', 'delete', 'restore', 'ignore',
|
|
88 'selectimportfile', 'messageissent', 'loadingdata', 'nopubkeyfor', 'nopubkeyforsender',
|
|
89 'encryptnoattachments','encryptedsendialog','searchpubkeyservers', 'importpubkeys',
|
|
90 'encryptpubkeysfound', 'search', 'close', 'import', 'keyid', 'keylength', 'keyexpired',
|
|
91 'keyrevoked', 'keyimportsuccess', 'keyservererror', 'attaching', 'namex', 'attachmentrename',
|
|
92 'disclosedrecipwarning', 'disclosedreciptitle', 'bccinstead', 'nosubjecttitle');
|
|
93
|
|
94 $OUTPUT->set_pagetitle($RCMAIL->gettext('compose'));
|
|
95
|
|
96 $OUTPUT->set_env('compose_id', $COMPOSE['id']);
|
|
97 $OUTPUT->set_env('session_id', session_id());
|
|
98 $OUTPUT->set_env('mailbox', $RCMAIL->storage->get_folder());
|
|
99 $OUTPUT->set_env('top_posting', intval($RCMAIL->config->get('reply_mode')) > 0);
|
|
100 $OUTPUT->set_env('sig_below', $RCMAIL->config->get('sig_below'));
|
|
101 $OUTPUT->set_env('recipients_separator', trim($RCMAIL->config->get('recipients_separator', ',')));
|
|
102 $OUTPUT->set_env('save_localstorage', (bool)$RCMAIL->config->get('compose_save_localstorage'));
|
|
103 $OUTPUT->set_env('max_disclosed_recipients', (int) $RCMAIL->config->get('max_disclosed_recipients', 5));
|
|
104 $OUTPUT->set_env('is_sent', false);
|
|
105 $OUTPUT->set_env('mimetypes', rcmail_supported_mimetypes());
|
|
106
|
|
107 $drafts_mbox = $RCMAIL->config->get('drafts_mbox');
|
|
108 $config_show_sig = $RCMAIL->config->get('show_sig', 1);
|
|
109
|
|
110 // add config parameters to client script
|
|
111 if (strlen($drafts_mbox)) {
|
|
112 $OUTPUT->set_env('drafts_mailbox', $drafts_mbox);
|
|
113 $OUTPUT->set_env('draft_autosave', $RCMAIL->config->get('draft_autosave'));
|
|
114 }
|
|
115
|
|
116 // default font for HTML editor
|
|
117 $font = rcmail::font_defs($RCMAIL->config->get('default_font'));
|
|
118 if ($font && !is_array($font)) {
|
|
119 $OUTPUT->set_env('default_font', $font);
|
|
120 }
|
|
121
|
|
122 // default font size for HTML editor
|
|
123 if ($font_size = $RCMAIL->config->get('default_font_size')) {
|
|
124 $OUTPUT->set_env('default_font_size', $font_size);
|
|
125 }
|
|
126
|
|
127 // get reference message and set compose mode
|
|
128 if ($msg_uid = $COMPOSE['param']['draft_uid']) {
|
|
129 $compose_mode = RCUBE_COMPOSE_DRAFT;
|
|
130 $OUTPUT->set_env('draft_id', $msg_uid);
|
|
131 $RCMAIL->storage->set_folder($drafts_mbox);
|
|
132 }
|
|
133 else if ($msg_uid = $COMPOSE['param']['reply_uid']) {
|
|
134 $compose_mode = RCUBE_COMPOSE_REPLY;
|
|
135 }
|
|
136 else if ($msg_uid = $COMPOSE['param']['forward_uid']) {
|
|
137 $compose_mode = RCUBE_COMPOSE_FORWARD;
|
|
138 $COMPOSE['forward_uid'] = $msg_uid;
|
|
139 $COMPOSE['as_attachment'] = !empty($COMPOSE['param']['attachment']);
|
|
140 }
|
|
141 else if ($msg_uid = $COMPOSE['param']['uid']) {
|
|
142 $compose_mode = RCUBE_COMPOSE_EDIT;
|
|
143 }
|
|
144
|
|
145 if ($compose_mode) {
|
|
146 $COMPOSE['mode'] = $compose_mode;
|
|
147 $OUTPUT->set_env('compose_mode', $compose_mode);
|
|
148 }
|
|
149
|
|
150 if ($compose_mode == RCUBE_COMPOSE_EDIT || $compose_mode == RCUBE_COMPOSE_DRAFT) {
|
|
151 // don't add signature in draft/edit mode, we'll also not remove the old-one
|
|
152 // but only on page display, later we should be able to change identity/sig (#1489229)
|
|
153 if ($config_show_sig == 1 || $config_show_sig == 2) {
|
|
154 $OUTPUT->set_env('show_sig_later', true);
|
|
155 }
|
|
156 }
|
|
157 else if ($config_show_sig == 1)
|
|
158 $OUTPUT->set_env('show_sig', true);
|
|
159 else if ($config_show_sig == 2 && empty($compose_mode))
|
|
160 $OUTPUT->set_env('show_sig', true);
|
|
161 else if ($config_show_sig == 3 && ($compose_mode == RCUBE_COMPOSE_REPLY || $compose_mode == RCUBE_COMPOSE_FORWARD))
|
|
162 $OUTPUT->set_env('show_sig', true);
|
|
163
|
|
164 // set line length for body wrapping
|
|
165 $LINE_LENGTH = $RCMAIL->config->get('line_length', 72);
|
|
166
|
|
167 if (!empty($msg_uid) && empty($COMPOSE['as_attachment'])) {
|
|
168 $mbox_name = $RCMAIL->storage->get_folder();
|
|
169
|
|
170 // set format before rcube_message construction
|
|
171 // use the same format as for the message view
|
|
172 if (isset($_SESSION['msg_formats'][$mbox_name.':'.$msg_uid])) {
|
|
173 $RCMAIL->config->set('prefer_html', $_SESSION['msg_formats'][$mbox_name.':'.$msg_uid]);
|
|
174 }
|
|
175 else {
|
|
176 $prefer_html = $RCMAIL->config->get('prefer_html') || $RCMAIL->config->get('htmleditor')
|
|
177 || $compose_mode == RCUBE_COMPOSE_DRAFT || $compose_mode == RCUBE_COMPOSE_EDIT;
|
|
178
|
|
179 $RCMAIL->config->set('prefer_html', $prefer_html);
|
|
180 }
|
|
181
|
|
182 $MESSAGE = new rcube_message($msg_uid);
|
|
183
|
|
184 // make sure message is marked as read
|
|
185 if ($MESSAGE->headers && $MESSAGE->context === null && empty($MESSAGE->headers->flags['SEEN'])) {
|
|
186 $RCMAIL->storage->set_flag($msg_uid, 'SEEN');
|
|
187 }
|
|
188
|
|
189 if (!empty($MESSAGE->headers->charset)) {
|
|
190 $RCMAIL->storage->set_charset($MESSAGE->headers->charset);
|
|
191 }
|
|
192
|
|
193 if (!$MESSAGE->headers) {
|
|
194 // error
|
|
195 }
|
|
196 else if ($compose_mode == RCUBE_COMPOSE_FORWARD || $compose_mode == RCUBE_COMPOSE_REPLY) {
|
|
197 if ($compose_mode == RCUBE_COMPOSE_REPLY) {
|
|
198 $COMPOSE['reply_uid'] = $MESSAGE->context === null ? $msg_uid : null;
|
|
199
|
|
200 if (!empty($COMPOSE['param']['all'])) {
|
|
201 $MESSAGE->reply_all = $COMPOSE['param']['all'];
|
|
202 }
|
|
203 }
|
|
204 else {
|
|
205 $COMPOSE['forward_uid'] = $msg_uid;
|
|
206 }
|
|
207
|
|
208 $COMPOSE['reply_msgid'] = $MESSAGE->headers->messageID;
|
|
209 $COMPOSE['references'] = trim($MESSAGE->headers->references . " " . $MESSAGE->headers->messageID);
|
|
210
|
|
211 // Save the sent message in the same folder of the message being replied to
|
|
212 if ($RCMAIL->config->get('reply_same_folder') && ($sent_folder = $COMPOSE['mailbox'])
|
|
213 && rcmail_check_sent_folder($sent_folder, false)
|
|
214 ) {
|
|
215 $COMPOSE['param']['sent_mbox'] = $sent_folder;
|
|
216 }
|
|
217 }
|
|
218 else if ($compose_mode == RCUBE_COMPOSE_DRAFT || $compose_mode == RCUBE_COMPOSE_EDIT) {
|
|
219 if ($compose_mode == RCUBE_COMPOSE_DRAFT) {
|
|
220 if ($draft_info = $MESSAGE->headers->get('x-draft-info')) {
|
|
221 // get reply_uid/forward_uid to flag the original message when sending
|
|
222 $info = rcmail_draftinfo_decode($draft_info);
|
|
223
|
|
224 if ($info['type'] == 'reply')
|
|
225 $COMPOSE['reply_uid'] = $info['uid'];
|
|
226 else if ($info['type'] == 'forward')
|
|
227 $COMPOSE['forward_uid'] = $info['uid'];
|
|
228
|
|
229 $COMPOSE['mailbox'] = $info['folder'];
|
|
230
|
|
231 // Save the sent message in the same folder of the message being replied to
|
|
232 if ($RCMAIL->config->get('reply_same_folder') && ($sent_folder = $info['folder'])
|
|
233 && rcmail_check_sent_folder($sent_folder, false)
|
|
234 ) {
|
|
235 $COMPOSE['param']['sent_mbox'] = $sent_folder;
|
|
236 }
|
|
237 }
|
|
238
|
|
239 $COMPOSE['param']['message-id'] = $MESSAGE->headers->get('message-id');
|
|
240
|
|
241 // use message UID as draft_id
|
|
242 $OUTPUT->set_env('draft_id', $msg_uid);
|
|
243 }
|
|
244
|
|
245 if ($in_reply_to = $MESSAGE->headers->get('in-reply-to')) {
|
|
246 $COMPOSE['reply_msgid'] = '<' . $in_reply_to . '>';
|
|
247 }
|
|
248
|
|
249 $COMPOSE['references'] = $MESSAGE->headers->references;
|
|
250 }
|
|
251 }
|
|
252 else {
|
|
253 $MESSAGE = new stdClass();
|
|
254
|
|
255 // apply mailto: URL parameters
|
|
256 if (!empty($COMPOSE['param']['in-reply-to'])) {
|
|
257 $COMPOSE['reply_msgid'] = '<' . $COMPOSE['param']['in-reply-to'] . '>';
|
|
258 }
|
|
259
|
|
260 if (!empty($COMPOSE['param']['references'])) {
|
|
261 $COMPOSE['references'] = $COMPOSE['param']['references'];
|
|
262 }
|
|
263 }
|
|
264
|
|
265 if (!empty($COMPOSE['reply_msgid'])) {
|
|
266 $OUTPUT->set_env('reply_msgid', $COMPOSE['reply_msgid']);
|
|
267 }
|
|
268
|
|
269 $MESSAGE->compose = array();
|
|
270
|
|
271 // get user's identities
|
|
272 $MESSAGE->identities = $RCMAIL->user->list_identities(null, true);
|
|
273
|
|
274 // Set From field value
|
|
275 if (!empty($_POST['_from'])) {
|
|
276 $MESSAGE->compose['from'] = rcube_utils::get_input_value('_from', rcube_utils::INPUT_POST);
|
|
277 }
|
|
278 else if (!empty($COMPOSE['param']['from'])) {
|
|
279 $MESSAGE->compose['from'] = $COMPOSE['param']['from'];
|
|
280 }
|
|
281 else if (count($MESSAGE->identities)) {
|
|
282 $ident = rcmail_identity_select($MESSAGE, $MESSAGE->identities, $compose_mode);
|
|
283
|
|
284 $MESSAGE->compose['from'] = $ident['identity_id'];
|
|
285 $MESSAGE->compose['ident'] = $ident;
|
|
286 }
|
|
287
|
|
288 // process $MESSAGE body/attachments, set $MESSAGE_BODY/$HTML_MODE vars and some session data
|
|
289 $MESSAGE_BODY = rcmail_prepare_message_body();
|
|
290
|
|
291 $OUTPUT->include_script('publickey.js');
|
|
292
|
|
293 // register UI objects
|
|
294 $OUTPUT->add_handlers(array(
|
|
295 'composeheaders' => 'rcmail_compose_headers',
|
|
296 'composesubject' => 'rcmail_compose_subject',
|
|
297 'composebody' => 'rcmail_compose_body',
|
|
298 'composeattachmentlist' => 'rcmail_compose_attachment_list',
|
|
299 'composeattachmentform' => 'rcmail_compose_attachment_form',
|
|
300 'composeattachment' => 'rcmail_compose_attachment_field',
|
|
301 'filedroparea' => 'compose_file_drop_area',
|
|
302 'priorityselector' => 'rcmail_priority_selector',
|
|
303 'editorselector' => 'rcmail_editor_selector',
|
|
304 'receiptcheckbox' => 'rcmail_mdn_checkbox', // deprecated
|
|
305 'mdncheckbox' => 'rcmail_mdn_checkbox',
|
|
306 'dsncheckbox' => 'rcmail_dsn_checkbox',
|
|
307 'storetarget' => 'rcmail_store_target_selection',
|
|
308 'addressbooks' => 'rcmail_addressbook_list',
|
|
309 'addresslist' => 'rcmail_contacts_list',
|
|
310 'responseslist' => 'rcmail_compose_responses_list',
|
|
311 ));
|
|
312
|
|
313 $OUTPUT->send('compose');
|
|
314
|
|
315
|
|
316 /****** compose mode functions ********/
|
|
317
|
|
318 // process compose request parameters
|
|
319 function rcmail_process_compose_params(&$COMPOSE)
|
|
320 {
|
|
321 if ($COMPOSE['param']['to']) {
|
|
322 $mailto = explode('?', $COMPOSE['param']['to'], 2);
|
|
323
|
|
324 // #1486037: remove "mailto:" prefix
|
|
325 $COMPOSE['param']['to'] = preg_replace('/^mailto:/i', '', $mailto[0]);
|
|
326 // #1490346: decode the recipient address
|
|
327 // #1490510: use raw encoding for correct "+" character handling as specified in RFC6068
|
|
328 $COMPOSE['param']['to'] = rawurldecode($COMPOSE['param']['to']);
|
|
329
|
|
330 // Supported case-insensitive tokens in mailto URL
|
|
331 $url_tokens = array('to', 'cc', 'bcc', 'reply-to', 'in-reply-to', 'references', 'subject', 'body');
|
|
332
|
|
333 if (!empty($mailto[1])) {
|
|
334 parse_str($mailto[1], $query);
|
|
335 foreach ($query as $f => $val) {
|
|
336 if (($key = array_search(strtolower($f), $url_tokens)) !== false) {
|
|
337 $f = $url_tokens[$key];
|
|
338 }
|
|
339
|
|
340 // merge mailto: addresses with addresses from 'to' parameter
|
|
341 if ($f == 'to' && !empty($COMPOSE['param']['to'])) {
|
|
342 $to_addresses = rcube_mime::decode_address_list($COMPOSE['param']['to'], null, true, null, true);
|
|
343 $add_addresses = rcube_mime::decode_address_list($val, null, true);
|
|
344
|
|
345 foreach ($add_addresses as $addr) {
|
|
346 if (!in_array($addr['mailto'], $to_addresses)) {
|
|
347 $to_addresses[] = $addr['mailto'];
|
|
348 $COMPOSE['param']['to'] = (!empty($to_addresses) ? ', ' : '') . $addr['string'];
|
|
349 }
|
|
350 }
|
|
351 }
|
|
352 else {
|
|
353 $COMPOSE['param'][$f] = $val;
|
|
354 }
|
|
355 }
|
|
356 }
|
|
357 }
|
|
358
|
|
359 // resolve _forward_uid=* to an absolute list of messages from a search result
|
|
360 if ($COMPOSE['param']['forward_uid'] == '*' && is_object($_SESSION['search'][1])) {
|
|
361 $COMPOSE['param']['forward_uid'] = $_SESSION['search'][1]->get();
|
|
362 }
|
|
363
|
|
364 // clean HTML message body which can be submitted by URL
|
|
365 if (!empty($COMPOSE['param']['body'])) {
|
|
366 if ($COMPOSE['param']['html'] = strpos($COMPOSE['param']['body'], '<') !== false) {
|
|
367 $wash_params = array('safe' => false, 'inline_html' => true);
|
|
368 $COMPOSE['param']['body'] = rcmail_wash_html($COMPOSE['param']['body'], $wash_params, array());
|
|
369 $COMPOSE['param']['body'] = preg_replace('/<!--[^>\n]+>/', '', $COMPOSE['param']['body']);
|
|
370 $COMPOSE['param']['body'] = preg_replace('/<\/?body>/', '', $COMPOSE['param']['body']);
|
|
371 }
|
|
372 }
|
|
373
|
|
374 $RCMAIL = rcmail::get_instance();
|
|
375
|
|
376 // select folder where to save the sent message
|
|
377 $COMPOSE['param']['sent_mbox'] = $RCMAIL->config->get('sent_mbox');
|
|
378
|
|
379 // pipe compose parameters thru plugins
|
|
380 $plugin = $RCMAIL->plugins->exec_hook('message_compose', $COMPOSE);
|
|
381 $COMPOSE['param'] = array_merge($COMPOSE['param'], $plugin['param']);
|
|
382
|
|
383 // add attachments listed by message_compose hook
|
|
384 if (is_array($plugin['attachments'])) {
|
|
385 foreach ($plugin['attachments'] as $attach) {
|
|
386 // we have structured data
|
|
387 if (is_array($attach)) {
|
|
388 $attachment = $attach + array('group' => $COMPOSE_ID);
|
|
389 }
|
|
390 // only a file path is given
|
|
391 else {
|
|
392 $filename = basename($attach);
|
|
393 $attachment = array(
|
|
394 'group' => $COMPOSE_ID,
|
|
395 'name' => $filename,
|
|
396 'mimetype' => rcube_mime::file_content_type($attach, $filename),
|
|
397 'size' => filesize($attach),
|
|
398 'path' => $attach,
|
|
399 );
|
|
400 }
|
|
401
|
|
402 // save attachment if valid
|
|
403 if (($attachment['data'] && $attachment['name']) || ($attachment['path'] && file_exists($attachment['path']))) {
|
|
404 $attachment = rcmail::get_instance()->plugins->exec_hook('attachment_save', $attachment);
|
|
405 }
|
|
406
|
|
407 if ($attachment['status'] && !$attachment['abort']) {
|
|
408 unset($attachment['data'], $attachment['status'], $attachment['abort']);
|
|
409 $COMPOSE['attachments'][$attachment['id']] = $attachment;
|
|
410 }
|
|
411 }
|
|
412 }
|
|
413 }
|
|
414
|
|
415 function rcmail_compose_headers($attrib)
|
|
416 {
|
|
417 global $RCMAIL, $MESSAGE;
|
|
418
|
|
419 list($form_start,) = get_form_tags($attrib);
|
|
420
|
|
421 $out = '';
|
|
422 $part = strtolower($attrib['part']);
|
|
423
|
|
424 switch ($part) {
|
|
425 case 'from':
|
|
426 return $form_start . rcmail_compose_header_from($attrib);
|
|
427
|
|
428 case 'to':
|
|
429 case 'cc':
|
|
430 case 'bcc':
|
|
431 $fname = '_' . $part;
|
|
432 $header = $param = $part;
|
|
433
|
|
434 $allow_attrib = array('id', 'class', 'style', 'cols', 'rows', 'tabindex');
|
|
435 $field_type = 'html_textarea';
|
|
436 break;
|
|
437
|
|
438 case 'replyto':
|
|
439 case 'reply-to':
|
|
440 $fname = '_replyto';
|
|
441 $param = 'replyto';
|
|
442 $header = 'reply-to';
|
|
443
|
|
444 case 'followupto':
|
|
445 case 'followup-to':
|
|
446 if (!$fname) {
|
|
447 $fname = '_followupto';
|
|
448 $param = 'followupto';
|
|
449 $header = 'mail-followup-to';
|
|
450 }
|
|
451
|
|
452 $allow_attrib = array('id', 'class', 'style', 'size', 'tabindex');
|
|
453 $field_type = 'html_inputfield';
|
|
454 break;
|
|
455 }
|
|
456
|
|
457 if ($fname && $field_type) {
|
|
458 // pass the following attributes to the form class
|
|
459 $field_attrib = array('name' => $fname, 'spellcheck' => 'false');
|
|
460 foreach ($attrib as $attr => $value) {
|
|
461 if (in_array($attr, $allow_attrib)) {
|
|
462 $field_attrib[$attr] = $value;
|
|
463 }
|
|
464 }
|
|
465
|
|
466 // create teaxtarea object
|
|
467 $input = new $field_type($field_attrib);
|
|
468 $out = $input->show(rcmail_compose_header_value($param));
|
|
469 }
|
|
470
|
|
471 if ($form_start) {
|
|
472 $out = $form_start . $out;
|
|
473 }
|
|
474
|
|
475 // configure autocompletion
|
|
476 $RCMAIL->autocomplete_init();
|
|
477
|
|
478 return $out;
|
|
479 }
|
|
480
|
|
481
|
|
482 function rcmail_compose_header_from($attrib)
|
|
483 {
|
|
484 global $MESSAGE, $OUTPUT, $RCMAIL, $COMPOSE;
|
|
485
|
|
486 // pass the following attributes to the form class
|
|
487 $field_attrib = array('name' => '_from');
|
|
488 foreach ($attrib as $attr => $value) {
|
|
489 if (in_array($attr, array('id', 'class', 'style', 'size', 'tabindex'))) {
|
|
490 $field_attrib[$attr] = $value;
|
|
491 }
|
|
492 }
|
|
493
|
|
494 if (count($MESSAGE->identities)) {
|
|
495 $a_signatures = array();
|
|
496 $identities = array();
|
|
497 $top_posting = intval($RCMAIL->config->get('reply_mode')) > 0
|
|
498 && !$RCMAIL->config->get('sig_below')
|
|
499 && ($COMPOSE['mode'] == RCUBE_COMPOSE_REPLY || $COMPOSE['mode'] == RCUBE_COMPOSE_FORWARD);
|
|
500
|
|
501 $separator = $top_posting ? '---' : '-- ';
|
|
502 $add_separator = (bool) $RCMAIL->config->get('sig_separator');
|
|
503
|
|
504 $field_attrib['onchange'] = rcmail_output::JS_OBJECT_NAME.".change_identity(this)";
|
|
505 $select_from = new html_select($field_attrib);
|
|
506
|
|
507 // create SELECT element
|
|
508 foreach ($MESSAGE->identities as $sql_arr) {
|
|
509 $identity_id = $sql_arr['identity_id'];
|
|
510 $select_from->add(format_email_recipient($sql_arr['email'], $sql_arr['name']), $identity_id);
|
|
511
|
|
512 // add signature to array
|
|
513 if (!empty($sql_arr['signature']) && empty($COMPOSE['param']['nosig'])) {
|
|
514 $text = $html = $sql_arr['signature'];
|
|
515
|
|
516 if ($sql_arr['html_signature']) {
|
|
517 $text = $RCMAIL->html2text($html, array('links' => false));
|
|
518 $text = trim($text, "\r\n");
|
|
519 }
|
|
520 else {
|
|
521 $t2h = new rcube_text2html($text, false);
|
|
522 $html = $t2h->get_html();
|
|
523 }
|
|
524
|
|
525 if ($add_separator && !preg_match('/^--[ -]\r?\n/m', $text)) {
|
|
526 $text = $separator . "\n" . ltrim($text, "\r\n");
|
|
527 $html = $separator . "<br>" . $html;
|
|
528 }
|
|
529
|
|
530 $a_signatures[$identity_id]['text'] = $text;
|
|
531 $a_signatures[$identity_id]['html'] = $html;
|
|
532 }
|
|
533
|
|
534 // add bcc and reply-to
|
|
535 if (!empty($sql_arr['reply-to'])) {
|
|
536 $identities[$identity_id]['replyto'] = $sql_arr['reply-to'];
|
|
537 }
|
|
538 if (!empty($sql_arr['bcc'])) {
|
|
539 $identities[$identity_id]['bcc'] = $sql_arr['bcc'];
|
|
540 }
|
|
541
|
|
542 $identities[$identity_id]['email'] = $sql_arr['email'];
|
|
543 }
|
|
544
|
|
545 $out = $select_from->show($MESSAGE->compose['from']);
|
|
546
|
|
547 // add signatures to client
|
|
548 $OUTPUT->set_env('signatures', $a_signatures);
|
|
549 $OUTPUT->set_env('identities', $identities);
|
|
550 }
|
|
551 // no identities, display text input field
|
|
552 else {
|
|
553 $field_attrib['class'] = 'from_address';
|
|
554 $input_from = new html_inputfield($field_attrib);
|
|
555 $out = $input_from->show($MESSAGE->compose['from']);
|
|
556 }
|
|
557
|
|
558 return $out;
|
|
559 }
|
|
560
|
|
561 function rcmail_compose_header_value($header)
|
|
562 {
|
|
563 global $COMPOSE, $MESSAGE;
|
|
564
|
|
565 $RCMAIL = rcube::get_instance();
|
|
566 $fvalue = '';
|
|
567 $decode_header = true;
|
|
568 $charset = $MESSAGE->headers->charset;
|
|
569 $separator = trim($RCMAIL->config->get('recipients_separator', ',')) . ' ';
|
|
570
|
|
571 // we have a set of recipients stored is session
|
|
572 if ($header == 'to' && ($mailto_id = $COMPOSE['param']['mailto'])
|
|
573 && $_SESSION['mailto'][$mailto_id]
|
|
574 ) {
|
|
575 $fvalue = urldecode($_SESSION['mailto'][$mailto_id]);
|
|
576 $decode_header = false;
|
|
577 $charset = $RCMAIL->output->charset;
|
|
578
|
|
579 // make session to not grow up too much
|
|
580 unset($_SESSION['mailto'][$mailto_id]);
|
|
581 $COMPOSE['param']['to'] = $fvalue;
|
|
582 }
|
|
583 else if (!empty($_POST['_' . $header])) {
|
|
584 $fvalue = rcube_utils::get_input_value('_' . $header, rcube_utils::INPUT_POST, true);
|
|
585 $charset = $RCMAIL->output->charset;
|
|
586 }
|
|
587 else if (!empty($COMPOSE['param'][$header])) {
|
|
588 $fvalue = $COMPOSE['param'][$header];
|
|
589 $charset = $RCMAIL->output->charset;
|
|
590 }
|
|
591 else if ($COMPOSE['mode'] == RCUBE_COMPOSE_REPLY) {
|
|
592 // get recipent address(es) out of the message headers
|
|
593 if ($header == 'to') {
|
|
594 $mailfollowup = $MESSAGE->headers->others['mail-followup-to'];
|
|
595 $mailreplyto = $MESSAGE->headers->others['mail-reply-to'];
|
|
596
|
|
597 // Reply to mailing list...
|
|
598 if ($MESSAGE->reply_all == 'list' && $mailfollowup) {
|
|
599 $fvalue = $mailfollowup;
|
|
600 }
|
|
601 else if ($MESSAGE->reply_all == 'list'
|
|
602 && preg_match('/<mailto:([^>]+)>/i', $MESSAGE->headers->others['list-post'], $m)
|
|
603 ) {
|
|
604 $fvalue = $m[1];
|
|
605 }
|
|
606 // Reply to...
|
|
607 else if ($MESSAGE->reply_all && $mailfollowup) {
|
|
608 $fvalue = $mailfollowup;
|
|
609 }
|
|
610 else if ($mailreplyto) {
|
|
611 $fvalue = $mailreplyto;
|
|
612 }
|
|
613 else if (!empty($MESSAGE->headers->replyto)) {
|
|
614 $fvalue = $MESSAGE->headers->replyto;
|
|
615 $replyto = true;
|
|
616 }
|
|
617 else if (!empty($MESSAGE->headers->from)) {
|
|
618 $fvalue = $MESSAGE->headers->from;
|
|
619 }
|
|
620
|
|
621 // Reply to message sent by yourself (#1487074, #1489230, #1490439)
|
|
622 // Reply-To address need to be unset (#1490233)
|
|
623 if (!empty($MESSAGE->compose['ident']) && empty($replyto)) {
|
|
624 foreach (array($fvalue, $MESSAGE->headers->from) as $sender) {
|
|
625 $senders = rcube_mime::decode_address_list($sender, null, false, $charset, true);
|
|
626
|
|
627 if (in_array($MESSAGE->compose['ident']['email_ascii'], $senders)) {
|
|
628 $fvalue = $MESSAGE->headers->to;
|
|
629 break;
|
|
630 }
|
|
631 }
|
|
632 }
|
|
633 }
|
|
634 // add recipient of original message if reply to all
|
|
635 else if ($header == 'cc' && !empty($MESSAGE->reply_all) && $MESSAGE->reply_all != 'list') {
|
|
636 if ($v = $MESSAGE->headers->to) {
|
|
637 $fvalue .= $v;
|
|
638 }
|
|
639 if ($v = $MESSAGE->headers->cc) {
|
|
640 $fvalue .= (!empty($fvalue) ? $separator : '') . $v;
|
|
641 }
|
|
642 // Use Sender header (#1489011)
|
|
643 if ($v = $MESSAGE->headers->get('Sender', false)) {
|
|
644 // Skip common mailing lists addresses: *-bounces@ and *-request@ (#1490452)
|
|
645 if (empty($MESSAGE->headers->others['list-post']) || !preg_match('/-(bounces|request)@/', $v)) {
|
|
646 $fvalue .= (!empty($fvalue) ? $separator : '') . $v;
|
|
647 }
|
|
648 }
|
|
649
|
|
650 // When To: and Reply-To: are the same we add From: address to the list (#1489037)
|
|
651 if ($v = $MESSAGE->headers->from) {
|
|
652 $from = rcube_mime::decode_address_list($v, null, false, $charset, true);
|
|
653 $to = rcube_mime::decode_address_list($MESSAGE->headers->to, null, false, $charset, true);
|
|
654 $replyto = rcube_mime::decode_address_list($MESSAGE->headers->replyto, null, false, $charset, true);
|
|
655
|
|
656 if (count($replyto) && !count(array_diff($to, $replyto)) && count(array_diff($from, $to))) {
|
|
657 $fvalue .= (!empty($fvalue) ? $separator : '') . $v;
|
|
658 }
|
|
659 }
|
|
660 }
|
|
661 }
|
|
662 else if (in_array($COMPOSE['mode'], array(RCUBE_COMPOSE_DRAFT, RCUBE_COMPOSE_EDIT))) {
|
|
663 // get drafted headers
|
|
664 if ($header == 'to' && !empty($MESSAGE->headers->to)) {
|
|
665 $fvalue = $MESSAGE->get_header('to', true);
|
|
666 }
|
|
667 else if ($header == 'cc' && !empty($MESSAGE->headers->cc)) {
|
|
668 $fvalue = $MESSAGE->get_header('cc', true);
|
|
669 }
|
|
670 else if ($header == 'bcc' && !empty($MESSAGE->headers->bcc)) {
|
|
671 $fvalue = $MESSAGE->get_header('bcc', true);
|
|
672 }
|
|
673 else if ($header == 'replyto' && !empty($MESSAGE->headers->others['mail-reply-to'])) {
|
|
674 $fvalue = $MESSAGE->get_header('mail-reply-to');
|
|
675 }
|
|
676 else if ($header == 'replyto' && !empty($MESSAGE->headers->replyto)) {
|
|
677 $fvalue = $MESSAGE->get_header('reply-to');
|
|
678 }
|
|
679 else if ($header == 'followupto' && !empty($MESSAGE->headers->others['mail-followup-to'])) {
|
|
680 $fvalue = $MESSAGE->get_header('mail-followup-to');
|
|
681 }
|
|
682 }
|
|
683
|
|
684 // split recipients and put them back together in a unique way
|
|
685 if (!empty($fvalue) && in_array($header, array('to', 'cc', 'bcc'))) {
|
|
686 $from_email = @mb_strtolower($MESSAGE->compose['ident']['email']);
|
|
687 $to_addresses = rcube_mime::decode_address_list($fvalue, null, $decode_header, $charset);
|
|
688 $fvalue = array();
|
|
689
|
|
690 foreach ($to_addresses as $addr_part) {
|
|
691 if (empty($addr_part['mailto'])) {
|
|
692 continue;
|
|
693 }
|
|
694
|
|
695 // According to RFC5321 local part of email address is case-sensitive
|
|
696 // however, here it is better to compare addresses in case-insensitive manner
|
|
697 $mailto = format_email(rcube_utils::idn_to_utf8($addr_part['mailto']));
|
|
698 $mailto_lc = mb_strtolower($addr_part['mailto']);
|
|
699
|
|
700 if (($header == 'to' || $COMPOSE['mode'] != RCUBE_COMPOSE_REPLY || $mailto_lc != $from_email)
|
|
701 && !in_array($mailto_lc, (array) $MESSAGE->recipients)
|
|
702 ) {
|
|
703 if ($addr_part['name'] && $mailto != $addr_part['name']) {
|
|
704 $mailto = format_email_recipient($mailto, $addr_part['name']);
|
|
705 }
|
|
706
|
|
707 $fvalue[] = $mailto;
|
|
708 $MESSAGE->recipients[] = $mailto_lc;
|
|
709 }
|
|
710 }
|
|
711
|
|
712 $fvalue = implode($separator, $fvalue);
|
|
713 }
|
|
714
|
|
715 return $fvalue;
|
|
716 }
|
|
717
|
|
718 function rcmail_compose_editor_mode()
|
|
719 {
|
|
720 global $RCMAIL, $COMPOSE;
|
|
721 static $useHtml;
|
|
722
|
|
723 if ($useHtml !== null) {
|
|
724 return $useHtml;
|
|
725 }
|
|
726
|
|
727 $html_editor = intval($RCMAIL->config->get('htmleditor'));
|
|
728 $compose_mode = $COMPOSE['mode'];
|
|
729
|
|
730 if (is_bool($COMPOSE['param']['html'])) {
|
|
731 $useHtml = $COMPOSE['param']['html'];
|
|
732 }
|
|
733 else if (isset($_POST['_is_html'])) {
|
|
734 $useHtml = !empty($_POST['_is_html']);
|
|
735 }
|
|
736 else if ($compose_mode == RCUBE_COMPOSE_DRAFT || $compose_mode == RCUBE_COMPOSE_EDIT) {
|
|
737 $useHtml = rcmail_message_is_html();
|
|
738 }
|
|
739 else if ($compose_mode == RCUBE_COMPOSE_REPLY) {
|
|
740 $useHtml = $html_editor == 1 || ($html_editor >= 2 && rcmail_message_is_html());
|
|
741 }
|
|
742 else if ($compose_mode == RCUBE_COMPOSE_FORWARD) {
|
|
743 $useHtml = $html_editor == 1 || $html_editor == 4
|
|
744 || ($html_editor == 3 && rcmail_message_is_html());
|
|
745 }
|
|
746 else {
|
|
747 $useHtml = $html_editor == 1 || $html_editor == 4;
|
|
748 }
|
|
749
|
|
750 return $useHtml;
|
|
751 }
|
|
752
|
|
753 function rcmail_message_is_html()
|
|
754 {
|
|
755 global $RCMAIL, $MESSAGE;
|
|
756
|
|
757 return $RCMAIL->config->get('prefer_html') && ($MESSAGE instanceof rcube_message) && $MESSAGE->has_html_part(true);
|
|
758 }
|
|
759
|
|
760 function rcmail_prepare_message_body()
|
|
761 {
|
|
762 global $RCMAIL, $MESSAGE, $COMPOSE, $HTML_MODE;
|
|
763
|
|
764 // use posted message body
|
|
765 if (!empty($_POST['_message'])) {
|
|
766 $body = rcube_utils::get_input_value('_message', rcube_utils::INPUT_POST, true);
|
|
767 $isHtml = (bool) rcube_utils::get_input_value('_is_html', rcube_utils::INPUT_POST);
|
|
768 }
|
|
769 else if ($COMPOSE['param']['body']) {
|
|
770 $body = $COMPOSE['param']['body'];
|
|
771 $isHtml = (bool) $COMPOSE['param']['html'];
|
|
772 }
|
|
773 // forward as attachment
|
|
774 else if ($COMPOSE['mode'] == RCUBE_COMPOSE_FORWARD && $COMPOSE['as_attachment']) {
|
|
775 $isHtml = rcmail_compose_editor_mode();
|
|
776 $body = '';
|
|
777
|
|
778 rcmail_write_forward_attachments();
|
|
779 }
|
|
780 // reply/edit/draft/forward
|
|
781 else if ($COMPOSE['mode'] && ($COMPOSE['mode'] != RCUBE_COMPOSE_REPLY || intval($RCMAIL->config->get('reply_mode')) != -1)) {
|
|
782 $isHtml = rcmail_compose_editor_mode();
|
|
783 $messages = array();
|
|
784
|
|
785 if (!empty($MESSAGE->parts)) {
|
|
786 // collect IDs of message/rfc822 parts
|
|
787 foreach ($MESSAGE->mime_parts() as $part) {
|
|
788 if ($part->mimetype == 'message/rfc822') {
|
|
789 $messages[] = $part->mime_id;
|
|
790 }
|
|
791 }
|
|
792
|
|
793 foreach ($MESSAGE->parts as $part) {
|
|
794 if ($part->realtype == 'multipart/encrypted') {
|
|
795 // find the encrypted message payload part
|
|
796 if ($pgp_mime_part = $MESSAGE->get_multipart_encrypted_part()) {
|
|
797 $RCMAIL->output->set_env('pgp_mime_message', array(
|
|
798 '_mbox' => $RCMAIL->storage->get_folder(),
|
|
799 '_uid' => $MESSAGE->uid,
|
|
800 '_part' => $pgp_mime_part->mime_id,
|
|
801 ));
|
|
802 }
|
|
803 continue;
|
|
804 }
|
|
805
|
|
806 // skip no-content and attachment parts (#1488557)
|
|
807 if ($part->type != 'content' || !$part->size || $MESSAGE->is_attachment($part)) {
|
|
808 continue;
|
|
809 }
|
|
810
|
|
811 // skip all content parts inside the message/rfc822 part
|
|
812 foreach ($messages as $mimeid) {
|
|
813 if (strpos($part->mime_id, $mimeid . '.') === 0) {
|
|
814 continue 2;
|
|
815 }
|
|
816 }
|
|
817
|
|
818 if ($part_body = rcmail_compose_part_body($part, $isHtml)) {
|
|
819 $body .= ($body ? ($isHtml ? '<br/>' : "\n") : '') . $part_body;
|
|
820 }
|
|
821 }
|
|
822 }
|
|
823 else {
|
|
824 $body = rcmail_compose_part_body($MESSAGE, $isHtml);
|
|
825 }
|
|
826
|
|
827 // compose reply-body
|
|
828 if ($COMPOSE['mode'] == RCUBE_COMPOSE_REPLY) {
|
|
829 $body = rcmail_create_reply_body($body, $isHtml);
|
|
830
|
|
831 if ($MESSAGE->pgp_mime) {
|
|
832 $RCMAIL->output->set_env('compose_reply_header', rcmail_get_reply_header($MESSAGE));
|
|
833 }
|
|
834 }
|
|
835 // forward message body inline
|
|
836 else if ($COMPOSE['mode'] == RCUBE_COMPOSE_FORWARD) {
|
|
837 $body = rcmail_create_forward_body($body, $isHtml);
|
|
838 }
|
|
839 // load draft message body
|
|
840 else if ($COMPOSE['mode'] == RCUBE_COMPOSE_DRAFT || $COMPOSE['mode'] == RCUBE_COMPOSE_EDIT) {
|
|
841 $body = rcmail_create_draft_body($body, $isHtml);
|
|
842 }
|
|
843 }
|
|
844 else { // new message
|
|
845 $isHtml = rcmail_compose_editor_mode();
|
|
846 }
|
|
847
|
|
848 $plugin = $RCMAIL->plugins->exec_hook('message_compose_body',
|
|
849 array('body' => $body, 'html' => $isHtml, 'mode' => $COMPOSE['mode']));
|
|
850
|
|
851 $body = $plugin['body'];
|
|
852 unset($plugin);
|
|
853
|
|
854 // add blocked.gif attachment (#1486516)
|
|
855 $regexp = '# src="program/resources/blocked\.gif"#';
|
|
856 if ($isHtml && preg_match($regexp, $body)) {
|
|
857 $content = $RCMAIL->get_resource_content('blocked.gif');
|
|
858
|
|
859 if ($content && ($attachment = rcmail_save_image('blocked.gif', 'image/gif', $content))) {
|
|
860 $COMPOSE['attachments'][$attachment['id']] = $attachment;
|
|
861 $url = sprintf('%s&_id=%s&_action=display-attachment&_file=rcmfile%s',
|
|
862 $RCMAIL->comm_path, $COMPOSE['id'], $attachment['id']);
|
|
863 $body = preg_replace($regexp, ' src="' . $url . '"', $body);
|
|
864 }
|
|
865 }
|
|
866
|
|
867 $HTML_MODE = $isHtml;
|
|
868
|
|
869 return $body;
|
|
870 }
|
|
871
|
|
872 function rcmail_compose_part_body($part, $isHtml = false)
|
|
873 {
|
|
874 global $RCMAIL, $COMPOSE, $MESSAGE, $LINE_LENGTH;
|
|
875
|
|
876 // Check if we have enough memory to handle the message in it
|
|
877 // #1487424: we need up to 10x more memory than the body
|
|
878 if (!rcube_utils::mem_check($part->size * 10)) {
|
|
879 return '';
|
|
880 }
|
|
881
|
|
882 // fetch part if not available
|
|
883 $body = $MESSAGE->get_part_body($part->mime_id, true);
|
|
884
|
|
885 // message is cached but not exists (#1485443), or other error
|
|
886 if ($body === false) {
|
|
887 return '';
|
|
888 }
|
|
889
|
|
890 // register this part as pgp encrypted
|
|
891 if (strpos($body, '-----BEGIN PGP MESSAGE-----') !== false) {
|
|
892 $MESSAGE->pgp_mime = true;
|
|
893 $RCMAIL->output->set_env('pgp_mime_message', array(
|
|
894 '_mbox' => $RCMAIL->storage->get_folder(), '_uid' => $MESSAGE->uid, '_part' => $part->mime_id,
|
|
895 ));
|
|
896 }
|
|
897
|
|
898 if ($isHtml) {
|
|
899 if ($part->ctype_secondary == 'html') {
|
|
900 }
|
|
901 else if ($part->ctype_secondary == 'enriched') {
|
|
902 $body = rcube_enriched::to_html($body);
|
|
903 }
|
|
904 else {
|
|
905 // try to remove the signature
|
|
906 if ($COMPOSE['mode'] != RCUBE_COMPOSE_DRAFT && $COMPOSE['mode'] != RCUBE_COMPOSE_EDIT) {
|
|
907 if ($RCMAIL->config->get('strip_existing_sig', true)) {
|
|
908 $body = rcmail_remove_signature($body);
|
|
909 }
|
|
910 }
|
|
911
|
|
912 // add HTML formatting
|
|
913 $body = rcmail_plain_body($body, $part->ctype_parameters['format'] == 'flowed', $part->ctype_parameters['delsp'] == 'yes');
|
|
914 }
|
|
915 }
|
|
916 else {
|
|
917 if ($part->ctype_secondary == 'enriched') {
|
|
918 $body = rcube_enriched::to_html($body);
|
|
919 $part->ctype_secondary = 'html';
|
|
920 }
|
|
921
|
|
922 if ($part->ctype_secondary == 'html') {
|
|
923 // use html part if it has been used for message (pre)viewing
|
|
924 // decrease line length for quoting
|
|
925 $len = $COMPOSE['mode'] == RCUBE_COMPOSE_REPLY ? $LINE_LENGTH-2 : $LINE_LENGTH;
|
|
926 $body = $RCMAIL->html2text($body, array('width' => $len));
|
|
927 }
|
|
928 else {
|
|
929 if ($part->ctype_secondary == 'plain' && $part->ctype_parameters['format'] == 'flowed') {
|
|
930 $body = rcube_mime::unfold_flowed($body, null, $part->ctype_parameters['delsp'] == 'yes');
|
|
931 }
|
|
932
|
|
933 // try to remove the signature
|
|
934 if ($COMPOSE['mode'] != RCUBE_COMPOSE_DRAFT && $COMPOSE['mode'] != RCUBE_COMPOSE_EDIT) {
|
|
935 if ($RCMAIL->config->get('strip_existing_sig', true)) {
|
|
936 $body = rcmail_remove_signature($body);
|
|
937 }
|
|
938 }
|
|
939 }
|
|
940 }
|
|
941
|
|
942 return $body;
|
|
943 }
|
|
944
|
|
945 function rcmail_compose_body($attrib)
|
|
946 {
|
|
947 global $RCMAIL, $OUTPUT, $HTML_MODE, $MESSAGE_BODY;
|
|
948
|
|
949 list($form_start, $form_end) = get_form_tags($attrib);
|
|
950 unset($attrib['form']);
|
|
951
|
|
952 if (empty($attrib['id'])) {
|
|
953 $attrib['id'] = 'rcmComposeBody';
|
|
954 }
|
|
955
|
|
956 // If desired, set this textarea to be editable by TinyMCE
|
|
957 if ($HTML_MODE) {
|
|
958 $attrib['class'] = 'mce_editor';
|
|
959 }
|
|
960
|
|
961 $attrib['name'] = '_message';
|
|
962
|
|
963 $textarea = new html_textarea($attrib);
|
|
964 $hidden = new html_hiddenfield();
|
|
965
|
|
966 $hidden->add(array('name' => '_draft_saveid', 'value' => $RCMAIL->output->get_env('draft_id')));
|
|
967 $hidden->add(array('name' => '_draft', 'value' => ''));
|
|
968 $hidden->add(array('name' => '_is_html', 'value' => $HTML_MODE ? "1" : "0"));
|
|
969 $hidden->add(array('name' => '_framed', 'value' => '1'));
|
|
970
|
|
971 $OUTPUT->set_env('composebody', $attrib['id']);
|
|
972
|
|
973 // include HTML editor
|
|
974 $RCMAIL->html_editor();
|
|
975
|
|
976 // Set language list
|
|
977 if ($RCMAIL->config->get('enable_spellcheck')) {
|
|
978 $engine = new rcube_spellchecker();
|
|
979 $dictionary = (bool) $RCMAIL->config->get('spellcheck_dictionary');
|
|
980 $spellcheck_langs = $engine->languages();
|
|
981 $lang = $_SESSION['language'];
|
|
982
|
|
983 // if not found in the list, try with two-letter code
|
|
984 if (!$spellcheck_langs[$lang]) {
|
|
985 $lang = strtolower(substr($lang, 0, 2));
|
|
986 }
|
|
987
|
|
988 if (!$spellcheck_langs[$lang]) {
|
|
989 $lang = 'en';
|
|
990 }
|
|
991
|
|
992 $editor_lang_set = array();
|
|
993 foreach ($spellcheck_langs as $key => $name) {
|
|
994 $editor_lang_set[] = ($key == $lang ? '+' : '') . rcube::JQ($name).'='.rcube::JQ($key);
|
|
995 }
|
|
996
|
|
997 // include GoogieSpell
|
|
998 $OUTPUT->include_script('googiespell.js');
|
|
999 $OUTPUT->add_script(sprintf(
|
|
1000 "var googie = new GoogieSpell('%s/images/googiespell/','%s&lang=', %s);\n".
|
|
1001 "googie.lang_chck_spell = \"%s\";\n".
|
|
1002 "googie.lang_rsm_edt = \"%s\";\n".
|
|
1003 "googie.lang_close = \"%s\";\n".
|
|
1004 "googie.lang_revert = \"%s\";\n".
|
|
1005 "googie.lang_no_error_found = \"%s\";\n".
|
|
1006 "googie.lang_learn_word = \"%s\";\n".
|
|
1007 "googie.setLanguages(%s);\n".
|
|
1008 "googie.setCurrentLanguage('%s');\n".
|
|
1009 "googie.setDecoration(false);\n".
|
|
1010 "googie.decorateTextarea('%s');\n",
|
|
1011 $RCMAIL->output->asset_url($RCMAIL->output->get_skin_path()),
|
|
1012 $RCMAIL->url(array('_task' => 'utils', '_action' => 'spell', '_remote' => 1)),
|
|
1013 !empty($dictionary) ? 'true' : 'false',
|
|
1014 rcube::JQ(rcube::Q($RCMAIL->gettext('checkspelling'))),
|
|
1015 rcube::JQ(rcube::Q($RCMAIL->gettext('resumeediting'))),
|
|
1016 rcube::JQ(rcube::Q($RCMAIL->gettext('close'))),
|
|
1017 rcube::JQ(rcube::Q($RCMAIL->gettext('revertto'))),
|
|
1018 rcube::JQ(rcube::Q($RCMAIL->gettext('nospellerrors'))),
|
|
1019 rcube::JQ(rcube::Q($RCMAIL->gettext('addtodict'))),
|
|
1020 rcube_output::json_serialize($spellcheck_langs),
|
|
1021 $lang,
|
|
1022 $attrib['id']), 'foot');
|
|
1023
|
|
1024 $OUTPUT->add_label('checking');
|
|
1025 $OUTPUT->set_env('spellcheck_langs', join(',', $editor_lang_set));
|
|
1026 $OUTPUT->set_env('spell_langs', $spellcheck_langs);
|
|
1027 $OUTPUT->set_env('spell_lang', $lang);
|
|
1028 }
|
|
1029
|
|
1030 return ($form_start ? "$form_start\n" : '')
|
|
1031 . "\n" . $hidden->show() . "\n" . $textarea->show($MESSAGE_BODY)
|
|
1032 . ($form_end ? "\n$form_end\n" : '')
|
|
1033 . '<iframe name="savetarget" src="program/resources/blank.gif"'
|
|
1034 . ' style="width:0;height:0;border:none;visibility:hidden;" aria-hidden="true"></iframe>';
|
|
1035 }
|
|
1036
|
|
1037
|
|
1038 function rcmail_create_reply_body($body, $bodyIsHtml)
|
|
1039 {
|
|
1040 global $RCMAIL, $MESSAGE, $LINE_LENGTH;
|
|
1041
|
|
1042 $prefix = rcmail_get_reply_header($MESSAGE);
|
|
1043 $reply_mode = intval($RCMAIL->config->get('reply_mode'));
|
|
1044
|
|
1045 if (!$bodyIsHtml) {
|
|
1046 // soft-wrap and quote message text
|
|
1047 $body = rcmail_wrap_and_quote($body, $LINE_LENGTH);
|
|
1048
|
|
1049 $prefix .= "\n";
|
|
1050
|
|
1051 if ($reply_mode > 0) { // top-posting
|
|
1052 $prefix = "\n\n\n" . $prefix;
|
|
1053 $suffix = '';
|
|
1054 }
|
|
1055 else {
|
|
1056 $suffix = "\n";
|
|
1057 }
|
|
1058 }
|
|
1059 else {
|
|
1060 // save inline images to files
|
|
1061 $cid_map = rcmail_write_inline_attachments($MESSAGE);
|
|
1062 // set is_safe flag (we need this for html body washing)
|
|
1063 rcmail_check_safe($MESSAGE);
|
|
1064 // clean up html tags
|
|
1065 $body = rcmail_wash_html($body, array('safe' => $MESSAGE->is_safe), $cid_map);
|
|
1066
|
|
1067 // build reply (quote content)
|
|
1068 $prefix = '<p>' . rcube::Q($prefix) . "</p>\n";
|
|
1069 $prefix .= '<blockquote>';
|
|
1070
|
|
1071 if ($reply_mode > 0) { // top-posting
|
|
1072 $prefix = '<br>' . $prefix;
|
|
1073 $suffix = '</blockquote>';
|
|
1074 }
|
|
1075 else {
|
|
1076 $suffix = '</blockquote><p><br/></p>';
|
|
1077 }
|
|
1078 }
|
|
1079
|
|
1080 return $prefix . $body . $suffix;
|
|
1081 }
|
|
1082
|
|
1083 function rcmail_get_reply_header($message)
|
|
1084 {
|
|
1085 global $RCMAIL;
|
|
1086
|
|
1087 $from = array_pop(rcube_mime::decode_address_list($message->get_header('from'), 1, false, $message->headers->charset));
|
|
1088 return $RCMAIL->gettext(array(
|
|
1089 'name' => 'mailreplyintro',
|
|
1090 'vars' => array(
|
|
1091 'date' => $RCMAIL->format_date($message->headers->date, $RCMAIL->config->get('date_long')),
|
|
1092 'sender' => $from['name'] ?: rcube_utils::idn_to_utf8($from['mailto']),
|
|
1093 )
|
|
1094 ));
|
|
1095 }
|
|
1096
|
|
1097 function rcmail_create_forward_body($body, $bodyIsHtml)
|
|
1098 {
|
|
1099 global $RCMAIL, $MESSAGE, $COMPOSE;
|
|
1100
|
|
1101 // add attachments
|
|
1102 if (!isset($COMPOSE['forward_attachments']) && is_array($MESSAGE->mime_parts)) {
|
|
1103 $cid_map = rcmail_write_compose_attachments($MESSAGE, $bodyIsHtml);
|
|
1104 }
|
|
1105
|
|
1106 $date = $RCMAIL->format_date($MESSAGE->headers->date, $RCMAIL->config->get('date_long'));
|
|
1107
|
|
1108 if (!$bodyIsHtml) {
|
|
1109 $prefix = "\n\n\n-------- " . $RCMAIL->gettext('originalmessage') . " --------\n";
|
|
1110 $prefix .= $RCMAIL->gettext('subject') . ': ' . $MESSAGE->subject . "\n";
|
|
1111 $prefix .= $RCMAIL->gettext('date') . ': ' . $date . "\n";
|
|
1112 $prefix .= $RCMAIL->gettext('from') . ': ' . $MESSAGE->get_header('from') . "\n";
|
|
1113 $prefix .= $RCMAIL->gettext('to') . ': ' . $MESSAGE->get_header('to') . "\n";
|
|
1114
|
|
1115 if ($cc = $MESSAGE->headers->get('cc')) {
|
|
1116 $prefix .= $RCMAIL->gettext('cc') . ': ' . $cc . "\n";
|
|
1117 }
|
|
1118 if (($replyto = $MESSAGE->headers->get('reply-to')) && $replyto != $MESSAGE->get_header('from')) {
|
|
1119 $prefix .= $RCMAIL->gettext('replyto') . ': ' . $replyto . "\n";
|
|
1120 }
|
|
1121
|
|
1122 $prefix .= "\n";
|
|
1123 $body = trim($body, "\r\n");
|
|
1124 }
|
|
1125 else {
|
|
1126 // set is_safe flag (we need this for html body washing)
|
|
1127 rcmail_check_safe($MESSAGE);
|
|
1128
|
|
1129 // clean up html tags
|
|
1130 $body = rcmail_wash_html($body, array('safe' => $MESSAGE->is_safe), $cid_map);
|
|
1131
|
|
1132 $prefix = sprintf(
|
|
1133 "<br /><p>-------- " . $RCMAIL->gettext('originalmessage') . " --------</p>" .
|
|
1134 "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tbody>" .
|
|
1135 "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>" .
|
|
1136 "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>" .
|
|
1137 "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>" .
|
|
1138 "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>",
|
|
1139 $RCMAIL->gettext('subject'), rcube::Q($MESSAGE->subject),
|
|
1140 $RCMAIL->gettext('date'), rcube::Q($date),
|
|
1141 $RCMAIL->gettext('from'), rcube::Q($MESSAGE->get_header('from'), 'replace'),
|
|
1142 $RCMAIL->gettext('to'), rcube::Q($MESSAGE->get_header('to'), 'replace'));
|
|
1143
|
|
1144 if ($cc = $MESSAGE->headers->get('cc'))
|
|
1145 $prefix .= sprintf("<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>",
|
|
1146 $RCMAIL->gettext('cc'), rcube::Q($cc, 'replace'));
|
|
1147
|
|
1148 if (($replyto = $MESSAGE->headers->get('reply-to')) && $replyto != $MESSAGE->get_header('from'))
|
|
1149 $prefix .= sprintf("<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>",
|
|
1150 $RCMAIL->gettext('replyto'), rcube::Q($replyto, 'replace'));
|
|
1151
|
|
1152 $prefix .= "</tbody></table><br>";
|
|
1153 }
|
|
1154
|
|
1155 return $prefix . $body;
|
|
1156 }
|
|
1157
|
|
1158
|
|
1159 function rcmail_create_draft_body($body, $bodyIsHtml)
|
|
1160 {
|
|
1161 global $MESSAGE, $COMPOSE;
|
|
1162
|
|
1163 // add attachments
|
|
1164 // count($MESSAGE->mime_parts) can be 1 - e.g. attachment, but no text!
|
|
1165 if (empty($COMPOSE['forward_attachments'])
|
|
1166 && is_array($MESSAGE->mime_parts)
|
|
1167 && count($MESSAGE->mime_parts) > 0
|
|
1168 ) {
|
|
1169 $cid_map = rcmail_write_compose_attachments($MESSAGE, $bodyIsHtml);
|
|
1170 }
|
|
1171
|
|
1172 // clean up HTML tags - XSS prevention (#1489251)
|
|
1173 if ($bodyIsHtml) {
|
|
1174 $body = rcmail_wash_html($body, array('safe' => 1), $cid_map);
|
|
1175
|
|
1176 // cleanup
|
|
1177 $body = preg_replace(array(
|
|
1178 // remove comments (produced by washtml)
|
|
1179 '/<!--[^>]+-->/',
|
|
1180 // remove <body> tags
|
|
1181 '/<body([^>]*)>/i',
|
|
1182 '/<\/body>/i',
|
|
1183 // convert TinyMCE's empty-line sequence (#1490463)
|
|
1184 '/<p>\xC2\xA0<\/p>/',
|
|
1185 ),
|
|
1186 array(
|
|
1187 '',
|
|
1188 '',
|
|
1189 '',
|
|
1190 '<p><br /></p>',
|
|
1191 ),
|
|
1192 $body
|
|
1193 );
|
|
1194
|
|
1195 // replace cid with href in inline images links
|
|
1196 if (!empty($cid_map)) {
|
|
1197 $body = str_replace(array_keys($cid_map), array_values($cid_map), $body);
|
|
1198 }
|
|
1199 }
|
|
1200
|
|
1201 return $body;
|
|
1202 }
|
|
1203
|
|
1204
|
|
1205 function rcmail_remove_signature($body)
|
|
1206 {
|
|
1207 global $RCMAIL;
|
|
1208
|
|
1209 $body = str_replace("\r\n", "\n", $body);
|
|
1210 $len = strlen($body);
|
|
1211 $sig_max_lines = $RCMAIL->config->get('sig_max_lines', 15);
|
|
1212
|
|
1213 while (($sp = strrpos($body, "-- \n", $sp ? -$len+$sp-1 : 0)) !== false) {
|
|
1214 if ($sp == 0 || $body[$sp-1] == "\n") {
|
|
1215 // do not touch blocks with more that X lines
|
|
1216 if (substr_count($body, "\n", $sp) < $sig_max_lines) {
|
|
1217 $body = substr($body, 0, max(0, $sp-1));
|
|
1218 }
|
|
1219 break;
|
|
1220 }
|
|
1221 }
|
|
1222
|
|
1223 return $body;
|
|
1224 }
|
|
1225
|
|
1226
|
|
1227 function rcmail_write_compose_attachments(&$message, $bodyIsHtml)
|
|
1228 {
|
|
1229 global $RCMAIL, $COMPOSE;
|
|
1230
|
|
1231 $loaded_attachments = array();
|
|
1232 foreach ((array)$COMPOSE['attachments'] as $attachment) {
|
|
1233 $loaded_attachments[$attachment['name'] . $attachment['mimetype']] = $attachment;
|
|
1234 }
|
|
1235
|
|
1236 $cid_map = array();
|
|
1237 $messages = array();
|
|
1238
|
|
1239 if ($message->pgp_mime) {
|
|
1240 return $cid_map;
|
|
1241 }
|
|
1242
|
|
1243 foreach ((array) $message->mime_parts() as $pid => $part) {
|
|
1244 if ($part->mimetype == 'message/rfc822') {
|
|
1245 $messages[] = $part->mime_id;
|
|
1246 }
|
|
1247
|
|
1248 if ($part->disposition == 'attachment' || ($part->disposition == 'inline' && $bodyIsHtml) || $part->filename) {
|
|
1249 // skip parts that aren't valid attachments
|
|
1250 if ($part->ctype_primary == 'multipart' || $part->mimetype == 'application/ms-tnef') {
|
|
1251 continue;
|
|
1252 }
|
|
1253
|
|
1254 // skip message attachments in reply mode
|
|
1255 if ($part->ctype_primary == 'message' && $COMPOSE['mode'] == RCUBE_COMPOSE_REPLY) {
|
|
1256 continue;
|
|
1257 }
|
|
1258
|
|
1259 // skip inline images when forwarding in text mode
|
|
1260 if ($part->content_id && $part->disposition == 'inline' && !$bodyIsHtml && $COMPOSE['mode'] == RCUBE_COMPOSE_FORWARD) {
|
|
1261 continue;
|
|
1262 }
|
|
1263
|
|
1264 // skip version.txt parts of multipart/encrypted messages
|
|
1265 if ($message->pgp_mime && $part->mimetype == 'application/pgp-encrypted' && $part->filename == 'version.txt') {
|
|
1266 continue;
|
|
1267 }
|
|
1268
|
|
1269 // skip attachments included in message/rfc822 attachment (#1486487, #1490607)
|
|
1270 foreach ($messages as $mimeid) {
|
|
1271 if (strpos($part->mime_id, $mimeid . '.') === 0) {
|
|
1272 continue 2;
|
|
1273 }
|
|
1274 }
|
|
1275
|
|
1276 if (($attachment = $loaded_attachments[rcmail_attachment_name($part) . $part->mimetype])
|
|
1277 || ($attachment = rcmail_save_attachment($message, $pid, $COMPOSE['id']))
|
|
1278 ) {
|
|
1279 if ($bodyIsHtml && ($part->content_id || $part->content_location)) {
|
|
1280 $url = sprintf('%s&_id=%s&_action=display-attachment&_file=rcmfile%s',
|
|
1281 $RCMAIL->comm_path, $COMPOSE['id'], $attachment['id']);
|
|
1282
|
|
1283 if ($part->content_id)
|
|
1284 $cid_map['cid:'.$part->content_id] = $url;
|
|
1285 else
|
|
1286 $cid_map[$part->content_location] = $url;
|
|
1287 }
|
|
1288 }
|
|
1289 }
|
|
1290 }
|
|
1291
|
|
1292 $COMPOSE['forward_attachments'] = true;
|
|
1293
|
|
1294 return $cid_map;
|
|
1295 }
|
|
1296
|
|
1297
|
|
1298 function rcmail_write_inline_attachments(&$message)
|
|
1299 {
|
|
1300 global $RCMAIL, $COMPOSE;
|
|
1301
|
|
1302 $cid_map = array();
|
|
1303 $messages = array();
|
|
1304
|
|
1305 if ($message->pgp_mime) {
|
|
1306 return $cid_map;
|
|
1307 }
|
|
1308
|
|
1309 foreach ((array) $message->mime_parts() as $pid => $part) {
|
|
1310 if ($part->mimetype == 'message/rfc822') {
|
|
1311 $messages[] = $part->mime_id;
|
|
1312 }
|
|
1313
|
|
1314 if (($part->content_id || $part->content_location) && $part->filename) {
|
|
1315 // skip attachments included in message/rfc822 attachment (#1486487, #1490607)
|
|
1316 foreach ($messages as $mimeid) {
|
|
1317 if (strpos($part->mime_id, $mimeid . '.') === 0) {
|
|
1318 continue 2;
|
|
1319 }
|
|
1320 }
|
|
1321
|
|
1322 if ($attachment = rcmail_save_attachment($message, $pid, $COMPOSE['id'])) {
|
|
1323 $url = sprintf('%s&_id=%s&_action=display-attachment&_file=rcmfile%s',
|
|
1324 $RCMAIL->comm_path, $COMPOSE['id'], $attachment['id']);
|
|
1325
|
|
1326 if ($part->content_id)
|
|
1327 $cid_map['cid:'.$part->content_id] = $url;
|
|
1328 else
|
|
1329 $cid_map[$part->content_location] = $url;
|
|
1330 }
|
|
1331 }
|
|
1332 }
|
|
1333
|
|
1334 return $cid_map;
|
|
1335 }
|
|
1336
|
|
1337 // Creates attachment(s) from the forwarded message(s)
|
|
1338 function rcmail_write_forward_attachments()
|
|
1339 {
|
|
1340 global $RCMAIL, $COMPOSE, $MESSAGE;
|
|
1341
|
|
1342 $storage = $RCMAIL->get_storage();
|
|
1343 $names = array();
|
|
1344 $refs = array();
|
|
1345
|
|
1346 if ($MESSAGE->pgp_mime) {
|
|
1347 return;
|
|
1348 }
|
|
1349
|
|
1350 $loaded_attachments = array();
|
|
1351 foreach ((array)$COMPOSE['attachments'] as $attachment) {
|
|
1352 $loaded_attachments[$attachment['name'] . $attachment['mimetype']] = $attachment;
|
|
1353 }
|
|
1354
|
|
1355 if ($COMPOSE['forward_uid'] == '*') {
|
|
1356 $index = $storage->index(null, rcmail_sort_column(), rcmail_sort_order());
|
|
1357 $COMPOSE['forward_uid'] = $index->get();
|
|
1358 }
|
|
1359 else if (!is_array($COMPOSE['forward_uid']) && strpos($COMPOSE['forward_uid'], ':')) {
|
|
1360 $COMPOSE['forward_uid'] = rcube_imap_generic::uncompressMessageSet($COMPOSE['forward_uid']);
|
|
1361 }
|
|
1362 else if (is_string($COMPOSE['forward_uid'])) {
|
|
1363 $COMPOSE['forward_uid'] = explode(',', $COMPOSE['forward_uid']);
|
|
1364 }
|
|
1365
|
|
1366 foreach ((array)$COMPOSE['forward_uid'] as $uid) {
|
|
1367 $message = new rcube_message($uid);
|
|
1368
|
|
1369 if (empty($message->headers)) {
|
|
1370 continue;
|
|
1371 }
|
|
1372
|
|
1373 if (!empty($message->headers->charset)) {
|
|
1374 $storage->set_charset($message->headers->charset);
|
|
1375 }
|
|
1376
|
|
1377 if (empty($MESSAGE->subject)) {
|
|
1378 $MESSAGE->subject = $message->subject;
|
|
1379 }
|
|
1380
|
|
1381 // generate (unique) attachment name
|
|
1382 $name = strlen($message->subject) ? mb_substr($message->subject, 0, 64) : 'message_rfc822';
|
|
1383 if (!empty($names[$name])) {
|
|
1384 $names[$name]++;
|
|
1385 $name .= '_' . $names[$name];
|
|
1386 }
|
|
1387 $names[$name] = 1;
|
|
1388 $name .= '.eml';
|
|
1389
|
|
1390 if (!empty($loaded_attachments[$name . 'message/rfc822'])) {
|
|
1391 continue;
|
|
1392 }
|
|
1393
|
|
1394 rcmail_save_attachment($message, null, $COMPOSE['id'], array('filename' => $name));
|
|
1395
|
|
1396 if ($message->headers->messageID) {
|
|
1397 $refs[] = $message->headers->messageID;
|
|
1398 }
|
|
1399 }
|
|
1400
|
|
1401 // set In-Reply-To and References headers
|
|
1402 if (count($refs) == 1) {
|
|
1403 $COMPOSE['reply_msgid'] = $refs[0];
|
|
1404 }
|
|
1405 if (!empty($refs)) {
|
|
1406 $COMPOSE['references'] = implode(' ', $refs);
|
|
1407 }
|
|
1408 }
|
|
1409
|
|
1410 function rcmail_save_image($path, $mimetype = '', $data = null)
|
|
1411 {
|
|
1412 global $COMPOSE;
|
|
1413
|
|
1414 // handle attachments in memory
|
|
1415 if (empty($data)) {
|
|
1416 $data = file_get_contents($path);
|
|
1417 $is_file = true;
|
|
1418 }
|
|
1419
|
|
1420 $name = rcmail_basename($path);
|
|
1421
|
|
1422 if (empty($mimetype)) {
|
|
1423 if ($is_file) {
|
|
1424 $mimetype = rcube_mime::file_content_type($path, $name);
|
|
1425 }
|
|
1426 else {
|
|
1427 $mimetype = rcube_mime::file_content_type($data, $name, 'application/octet-stream', true);
|
|
1428 }
|
|
1429 }
|
|
1430
|
|
1431 $attachment = array(
|
|
1432 'group' => $COMPOSE['id'],
|
|
1433 'name' => $name,
|
|
1434 'mimetype' => $mimetype,
|
|
1435 'data' => $data,
|
|
1436 'size' => strlen($data),
|
|
1437 );
|
|
1438
|
|
1439 $attachment = rcmail::get_instance()->plugins->exec_hook('attachment_save', $attachment);
|
|
1440
|
|
1441 if ($attachment['status']) {
|
|
1442 unset($attachment['data'], $attachment['status'], $attachment['content_id'], $attachment['abort']);
|
|
1443 return $attachment;
|
|
1444 }
|
|
1445
|
|
1446 return false;
|
|
1447 }
|
|
1448
|
|
1449 function rcmail_basename($filename)
|
|
1450 {
|
|
1451 // basename() is not unicode safe and locale dependent
|
|
1452 if (stristr(PHP_OS, 'win') || stristr(PHP_OS, 'netware')) {
|
|
1453 return preg_replace('/^.*[\\\\\\/]/', '', $filename);
|
|
1454 }
|
|
1455 else {
|
|
1456 return preg_replace('/^.*[\/]/', '', $filename);
|
|
1457 }
|
|
1458 }
|
|
1459
|
|
1460 /**
|
|
1461 * Creates reply subject by removing common subject
|
|
1462 * prefixes/suffixes from the original message subject
|
|
1463 */
|
|
1464 function rcmail_reply_subject($subject)
|
|
1465 {
|
|
1466 $subject = trim($subject);
|
|
1467
|
|
1468 // replace Re:, Re[x]:, Re-x (#1490497)
|
|
1469 $prefix = '/^(re:|re\[\d\]:|re-\d:)\s*/i';
|
|
1470 do {
|
|
1471 $subject = preg_replace($prefix, '', $subject, -1, $count);
|
|
1472 }
|
|
1473 while ($count);
|
|
1474
|
|
1475 // replace (was: ...) (#1489375)
|
|
1476 $subject = preg_replace('/\s*\([wW]as:[^\)]+\)\s*$/', '', $subject);
|
|
1477
|
|
1478 return 'Re: ' . $subject;
|
|
1479 }
|
|
1480
|
|
1481 function rcmail_compose_subject($attrib)
|
|
1482 {
|
|
1483 global $MESSAGE, $COMPOSE;
|
|
1484
|
|
1485 list($form_start, $form_end) = get_form_tags($attrib);
|
|
1486 unset($attrib['form']);
|
|
1487
|
|
1488 $attrib['name'] = '_subject';
|
|
1489 $attrib['spellcheck'] = 'true';
|
|
1490
|
|
1491 $textfield = new html_inputfield($attrib);
|
|
1492 $subject = '';
|
|
1493
|
|
1494 // use subject from post
|
|
1495 if (isset($_POST['_subject'])) {
|
|
1496 $subject = rcube_utils::get_input_value('_subject', rcube_utils::INPUT_POST, TRUE);
|
|
1497 }
|
|
1498 else if (!empty($COMPOSE['param']['subject'])) {
|
|
1499 $subject = $COMPOSE['param']['subject'];
|
|
1500 }
|
|
1501 // create a reply-subject
|
|
1502 else if ($COMPOSE['mode'] == RCUBE_COMPOSE_REPLY) {
|
|
1503 $subject = rcmail_reply_subject($MESSAGE->subject);
|
|
1504 }
|
|
1505 // create a forward-subject
|
|
1506 else if ($COMPOSE['mode'] == RCUBE_COMPOSE_FORWARD) {
|
|
1507 if (preg_match('/^fwd:/i', $MESSAGE->subject))
|
|
1508 $subject = $MESSAGE->subject;
|
|
1509 else
|
|
1510 $subject = 'Fwd: '.$MESSAGE->subject;
|
|
1511 }
|
|
1512 // creeate a draft-subject
|
|
1513 else if ($COMPOSE['mode'] == RCUBE_COMPOSE_DRAFT || $COMPOSE['mode'] == RCUBE_COMPOSE_EDIT) {
|
|
1514 $subject = $MESSAGE->subject;
|
|
1515 }
|
|
1516
|
|
1517 $out = $form_start ? "$form_start\n" : '';
|
|
1518 $out .= $textfield->show($subject);
|
|
1519 $out .= $form_end ? "\n$form_end" : '';
|
|
1520
|
|
1521 return $out;
|
|
1522 }
|
|
1523
|
|
1524 function rcmail_compose_attachment_list($attrib)
|
|
1525 {
|
|
1526 global $RCMAIL, $OUTPUT, $COMPOSE;
|
|
1527
|
|
1528 // add ID if not given
|
|
1529 if (!$attrib['id'])
|
|
1530 $attrib['id'] = 'rcmAttachmentList';
|
|
1531
|
|
1532 $out = "\n";
|
|
1533 $jslist = array();
|
|
1534 $button = '';
|
|
1535
|
|
1536 if ($attrib['icon_pos'] == 'left')
|
|
1537 $COMPOSE['icon_pos'] = 'left';
|
|
1538
|
|
1539 if (is_array($COMPOSE['attachments'])) {
|
|
1540 if ($attrib['deleteicon']) {
|
|
1541 $button = html::img(array(
|
|
1542 'src' => $RCMAIL->output->abs_url($attrib['deleteicon'], true),
|
|
1543 'alt' => $RCMAIL->gettext('delete')
|
|
1544 ));
|
|
1545 }
|
|
1546 else if (rcube_utils::get_boolean($attrib['textbuttons'])) {
|
|
1547 $button = rcube::Q($RCMAIL->gettext('delete'));
|
|
1548 }
|
|
1549
|
|
1550 foreach ($COMPOSE['attachments'] as $id => $a_prop) {
|
|
1551 if (empty($a_prop)) {
|
|
1552 continue;
|
|
1553 }
|
|
1554
|
|
1555 $link_content = sprintf('%s <span class="attachment-size"> (%s)</span>',
|
|
1556 rcube::Q($a_prop['name']), $RCMAIL->show_bytes($a_prop['size']));
|
|
1557
|
|
1558 $content_link = html::a(array(
|
|
1559 'href' => "#load",
|
|
1560 'class' => 'filename',
|
|
1561 'onclick' => sprintf("return %s.command('load-attachment','rcmfile%s', this, event)", rcmail_output::JS_OBJECT_NAME, $id),
|
|
1562 ), $link_content);
|
|
1563
|
|
1564 $delete_link = html::a(array(
|
|
1565 'href' => "#delete",
|
|
1566 'title' => $RCMAIL->gettext('delete'),
|
|
1567 'onclick' => sprintf("return %s.command('remove-attachment','rcmfile%s', this, event)", rcmail_output::JS_OBJECT_NAME, $id),
|
|
1568 'class' => 'delete',
|
|
1569 'tabindex' => $attrib['tabindex'] ?: '0',
|
|
1570 'aria-label' => $RCMAIL->gettext('delete') . ' ' . $a_prop['name'],
|
|
1571 ), $button);
|
|
1572
|
|
1573 $out .= html::tag('li', array(
|
|
1574 'id' => 'rcmfile'.$id,
|
|
1575 'class' => rcube_utils::file2class($a_prop['mimetype'], $a_prop['name']),
|
|
1576 'onmouseover' => "rcube_webmail.long_subject_title_ex(this, 0)",
|
|
1577 ),
|
|
1578 $COMPOSE['icon_pos'] == 'left' ? $delete_link.$content_link : $content_link.$delete_link
|
|
1579 );
|
|
1580
|
|
1581 $jslist['rcmfile'.$id] = array(
|
|
1582 'name' => $a_prop['name'],
|
|
1583 'complete' => true,
|
|
1584 'mimetype' => $a_prop['mimetype']
|
|
1585 );
|
|
1586 }
|
|
1587 }
|
|
1588
|
|
1589 if ($attrib['deleteicon'])
|
|
1590 $COMPOSE['deleteicon'] = $RCMAIL->output->abs_url($attrib['deleteicon'], true);
|
|
1591 else if (rcube_utils::get_boolean($attrib['textbuttons']))
|
|
1592 $COMPOSE['textbuttons'] = true;
|
|
1593 if ($attrib['cancelicon'])
|
|
1594 $OUTPUT->set_env('cancelicon', $RCMAIL->output->abs_url($attrib['cancelicon'], true));
|
|
1595 if ($attrib['loadingicon'])
|
|
1596 $OUTPUT->set_env('loadingicon', $RCMAIL->output->abs_url($attrib['loadingicon'], true));
|
|
1597
|
|
1598 $OUTPUT->set_env('attachments', $jslist);
|
|
1599 $OUTPUT->add_gui_object('attachmentlist', $attrib['id']);
|
|
1600
|
|
1601 // put tabindex value into data-tabindex attribute
|
|
1602 if (isset($attrib['tabindex'])) {
|
|
1603 $attrib['data-tabindex'] = $attrib['tabindex'];
|
|
1604 unset($attrib['tabindex']);
|
|
1605 }
|
|
1606
|
|
1607 return html::tag('ul', $attrib, $out, html::$common_attrib);
|
|
1608 }
|
|
1609
|
|
1610
|
|
1611 function rcmail_compose_attachment_form($attrib)
|
|
1612 {
|
|
1613 global $RCMAIL;
|
|
1614
|
|
1615 return $RCMAIL->upload_form($attrib, 'uploadform', 'send-attachment', array('multiple' => true));
|
|
1616 }
|
|
1617
|
|
1618 function rcmail_priority_selector($attrib)
|
|
1619 {
|
|
1620 global $RCMAIL, $MESSAGE;
|
|
1621
|
|
1622 list($form_start, $form_end) = get_form_tags($attrib);
|
|
1623 unset($attrib['form']);
|
|
1624
|
|
1625 $attrib['name'] = '_priority';
|
|
1626 $prio_list = array(
|
|
1627 $RCMAIL->gettext('lowest') => 5,
|
|
1628 $RCMAIL->gettext('low') => 4,
|
|
1629 $RCMAIL->gettext('normal') => 0,
|
|
1630 $RCMAIL->gettext('high') => 2,
|
|
1631 $RCMAIL->gettext('highest') => 1,
|
|
1632 );
|
|
1633
|
|
1634 $selector = new html_select($attrib);
|
|
1635 $selector->add(array_keys($prio_list), array_values($prio_list));
|
|
1636
|
|
1637 if (isset($_POST['_priority']))
|
|
1638 $sel = $_POST['_priority'];
|
|
1639 else if (isset($MESSAGE->headers->priority) && intval($MESSAGE->headers->priority) != 3)
|
|
1640 $sel = $MESSAGE->headers->priority;
|
|
1641 else
|
|
1642 $sel = 0;
|
|
1643
|
|
1644 $out = $form_start ? "$form_start\n" : '';
|
|
1645 $out .= $selector->show((int) $sel);
|
|
1646 $out .= $form_end ? "\n$form_end" : '';
|
|
1647
|
|
1648 return $out;
|
|
1649 }
|
|
1650
|
|
1651
|
|
1652 function rcmail_mdn_checkbox($attrib)
|
|
1653 {
|
|
1654 global $RCMAIL, $MESSAGE;
|
|
1655
|
|
1656 list($form_start, $form_end) = get_form_tags($attrib);
|
|
1657 unset($attrib['form']);
|
|
1658
|
|
1659 if (!isset($attrib['id']))
|
|
1660 $attrib['id'] = 'receipt';
|
|
1661
|
|
1662 $attrib['name'] = '_mdn';
|
|
1663 $attrib['value'] = '1';
|
|
1664
|
|
1665 $checkbox = new html_checkbox($attrib);
|
|
1666
|
|
1667 if (isset($_POST['_mdn']))
|
|
1668 $mdn_default = $_POST['_mdn'];
|
|
1669 else if (in_array($COMPOSE['mode'], array(RCUBE_COMPOSE_DRAFT, RCUBE_COMPOSE_EDIT)))
|
|
1670 $mdn_default = (bool) $MESSAGE->headers->mdn_to;
|
|
1671 else
|
|
1672 $mdn_default = $RCMAIL->config->get('mdn_default');
|
|
1673
|
|
1674 $out = $form_start ? "$form_start\n" : '';
|
|
1675 $out .= $checkbox->show($mdn_default);
|
|
1676 $out .= $form_end ? "\n$form_end" : '';
|
|
1677
|
|
1678 return $out;
|
|
1679 }
|
|
1680
|
|
1681
|
|
1682 function rcmail_dsn_checkbox($attrib)
|
|
1683 {
|
|
1684 global $RCMAIL;
|
|
1685
|
|
1686 list($form_start, $form_end) = get_form_tags($attrib);
|
|
1687 unset($attrib['form']);
|
|
1688
|
|
1689 if (!isset($attrib['id']))
|
|
1690 $attrib['id'] = 'dsn';
|
|
1691
|
|
1692 $attrib['name'] = '_dsn';
|
|
1693 $attrib['value'] = '1';
|
|
1694
|
|
1695 $checkbox = new html_checkbox($attrib);
|
|
1696
|
|
1697 if (isset($_POST['_dsn']))
|
|
1698 $dsn_value = (int) $_POST['_dsn'];
|
|
1699 else
|
|
1700 $dsn_value = $RCMAIL->config->get('dsn_default');
|
|
1701
|
|
1702 $out = $form_start ? "$form_start\n" : '';
|
|
1703 $out .= $checkbox->show($dsn_value);
|
|
1704 $out .= $form_end ? "\n$form_end" : '';
|
|
1705
|
|
1706 return $out;
|
|
1707 }
|
|
1708
|
|
1709
|
|
1710 function rcmail_editor_selector($attrib)
|
|
1711 {
|
|
1712 global $RCMAIL;
|
|
1713
|
|
1714 // determine whether HTML or plain text should be checked
|
|
1715 $useHtml = rcmail_compose_editor_mode();
|
|
1716
|
|
1717 if (empty($attrib['editorid']))
|
|
1718 $attrib['editorid'] = 'rcmComposeBody';
|
|
1719
|
|
1720 if (empty($attrib['name']))
|
|
1721 $attrib['name'] = 'editorSelect';
|
|
1722
|
|
1723 $attrib['onchange'] = "return rcmail.command('toggle-editor', {id: '".$attrib['editorid']."', html: this.value == 'html'}, '', event)";
|
|
1724
|
|
1725 $select = new html_select($attrib);
|
|
1726
|
|
1727 $select->add(rcube::Q($RCMAIL->gettext('htmltoggle')), 'html');
|
|
1728 $select->add(rcube::Q($RCMAIL->gettext('plaintoggle')), 'plain');
|
|
1729
|
|
1730 return $select->show($useHtml ? 'html' : 'plain');
|
|
1731 }
|
|
1732
|
|
1733
|
|
1734 function rcmail_store_target_selection($attrib)
|
|
1735 {
|
|
1736 global $COMPOSE, $RCMAIL;
|
|
1737
|
|
1738 $attrib['name'] = '_store_target';
|
|
1739 $select = $RCMAIL->folder_selector(array_merge($attrib, array(
|
|
1740 'noselection' => '- ' . $RCMAIL->gettext('dontsave') . ' -',
|
|
1741 'folder_filter' => 'mail',
|
|
1742 'folder_rights' => 'w',
|
|
1743 )));
|
|
1744
|
|
1745 return $select->show(isset($_POST['_store_target']) ? $_POST['_store_target'] : $COMPOSE['param']['sent_mbox'], $attrib);
|
|
1746 }
|
|
1747
|
|
1748
|
|
1749 function rcmail_check_sent_folder($folder, $create=false)
|
|
1750 {
|
|
1751 global $RCMAIL;
|
|
1752
|
|
1753 // we'll not save the message, so it doesn't matter
|
|
1754 if ($RCMAIL->config->get('no_save_sent_messages')) {
|
|
1755 return true;
|
|
1756 }
|
|
1757
|
|
1758 if ($RCMAIL->storage->folder_exists($folder, true)) {
|
|
1759 return true;
|
|
1760 }
|
|
1761
|
|
1762 // folder may exist but isn't subscribed (#1485241)
|
|
1763 if ($create) {
|
|
1764 if (!$RCMAIL->storage->folder_exists($folder))
|
|
1765 return $RCMAIL->storage->create_folder($folder, true);
|
|
1766 else
|
|
1767 return $RCMAIL->storage->subscribe($folder);
|
|
1768 }
|
|
1769
|
|
1770 return false;
|
|
1771 }
|
|
1772
|
|
1773
|
|
1774 function get_form_tags($attrib)
|
|
1775 {
|
|
1776 global $RCMAIL, $MESSAGE_FORM, $COMPOSE;
|
|
1777
|
|
1778 $form_start = '';
|
|
1779 if (!$MESSAGE_FORM) {
|
|
1780 $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $RCMAIL->task));
|
|
1781 $hiddenfields->add(array('name' => '_action', 'value' => 'send'));
|
|
1782 $hiddenfields->add(array('name' => '_id', 'value' => $COMPOSE['id']));
|
|
1783 $hiddenfields->add(array('name' => '_attachments'));
|
|
1784
|
|
1785 $form_start = empty($attrib['form']) ? $RCMAIL->output->form_tag(array('name' => "form", 'method' => "post")) : '';
|
|
1786 $form_start .= $hiddenfields->show();
|
|
1787 }
|
|
1788
|
|
1789 $form_end = ($MESSAGE_FORM && !strlen($attrib['form'])) ? '</form>' : '';
|
|
1790 $form_name = $attrib['form'] ?: 'form';
|
|
1791
|
|
1792 if (!$MESSAGE_FORM)
|
|
1793 $RCMAIL->output->add_gui_object('messageform', $form_name);
|
|
1794
|
|
1795 $MESSAGE_FORM = $form_name;
|
|
1796
|
|
1797 return array($form_start, $form_end);
|
|
1798 }
|
|
1799
|
|
1800
|
|
1801 function rcmail_addressbook_list($attrib = array())
|
|
1802 {
|
|
1803 global $RCMAIL, $OUTPUT;
|
|
1804
|
|
1805 $attrib += array('id' => 'rcmdirectorylist');
|
|
1806
|
|
1807 $out = '';
|
|
1808 $line_templ = html::tag('li', array(
|
|
1809 'id' => 'rcmli%s', 'class' => '%s'),
|
|
1810 html::a(array('href' => '#list',
|
|
1811 'rel' => '%s',
|
|
1812 'onclick' => "return ".rcmail_output::JS_OBJECT_NAME.".command('list-addresses','%s',this)"), '%s'));
|
|
1813
|
|
1814 foreach ($RCMAIL->get_address_sources(false, true) as $j => $source) {
|
|
1815 $id = strval(strlen($source['id']) ? $source['id'] : $j);
|
|
1816 $js_id = rcube::JQ($id);
|
|
1817
|
|
1818 // set class name(s)
|
|
1819 $class_name = 'addressbook';
|
|
1820 if ($source['class_name'])
|
|
1821 $class_name .= ' ' . $source['class_name'];
|
|
1822
|
|
1823 $out .= sprintf($line_templ,
|
|
1824 rcube_utils::html_identifier($id,true),
|
|
1825 $class_name,
|
|
1826 $source['id'],
|
|
1827 $js_id, ($source['name'] ?: $id));
|
|
1828 }
|
|
1829
|
|
1830 $OUTPUT->add_gui_object('addressbookslist', $attrib['id']);
|
|
1831
|
|
1832 return html::tag('ul', $attrib, $out, html::$common_attrib);
|
|
1833 }
|
|
1834
|
|
1835 // return the contacts list as HTML table
|
|
1836 function rcmail_contacts_list($attrib = array())
|
|
1837 {
|
|
1838 global $RCMAIL, $OUTPUT;
|
|
1839
|
|
1840 $attrib += array('id' => 'rcmAddressList');
|
|
1841
|
|
1842 // set client env
|
|
1843 $OUTPUT->add_gui_object('contactslist', $attrib['id']);
|
|
1844 $OUTPUT->set_env('pagecount', 0);
|
|
1845 $OUTPUT->set_env('current_page', 0);
|
|
1846 $OUTPUT->include_script('list.js');
|
|
1847
|
|
1848 return $RCMAIL->table_output($attrib, array(), array('name'), 'ID');
|
|
1849 }
|
|
1850
|
|
1851
|
|
1852 /**
|
|
1853 * Register a certain container as active area to drop files onto
|
|
1854 */
|
|
1855 function compose_file_drop_area($attrib)
|
|
1856 {
|
|
1857 global $OUTPUT;
|
|
1858
|
|
1859 if ($attrib['id']) {
|
|
1860 $OUTPUT->add_gui_object('filedrop', $attrib['id']);
|
|
1861 $OUTPUT->set_env('filedrop', array('action' => 'upload', 'fieldname' => '_attachments'));
|
|
1862 }
|
|
1863 }
|
|
1864
|
|
1865
|
|
1866 /**
|
|
1867 *
|
|
1868 */
|
|
1869 function rcmail_compose_responses_list($attrib)
|
|
1870 {
|
|
1871 global $RCMAIL, $OUTPUT;
|
|
1872
|
|
1873 $attrib += array('id' => 'rcmresponseslist', 'tagname' => 'ul', 'cols' => 1);
|
|
1874
|
|
1875 $jsenv = array();
|
|
1876 $list = new html_table($attrib);
|
|
1877 foreach ($RCMAIL->get_compose_responses(true) as $response) {
|
|
1878 $key = $response['key'];
|
|
1879 $item = html::a(array(
|
|
1880 'href' => '#'.urlencode($response['name']),
|
|
1881 'class' => rtrim('insertresponse ' . $attrib['itemclass']),
|
|
1882 'unselectable' => 'on',
|
|
1883 'tabindex' => '0',
|
|
1884 'rel' => $key,
|
|
1885 ), rcube::Q($response['name']));
|
|
1886
|
|
1887 $jsenv[$key] = $response;
|
|
1888 $list->add(array(), $item);
|
|
1889 }
|
|
1890
|
|
1891 // set client env
|
|
1892 $OUTPUT->set_env('textresponses', $jsenv);
|
|
1893 $OUTPUT->add_gui_object('responseslist', $attrib['id']);
|
|
1894
|
|
1895 return $list->show();
|
|
1896 }
|