commit | author | age
|
4e17e6
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| program/steps/mail/func.inc | |
|
6 |
| | |
|
7 |
| This file is part of the RoundCube Webmail client | |
cbbef3
|
8 |
| Copyright (C) 2005-2009, RoundCube Dev. - Switzerland | |
30233b
|
9 |
| Licensed under the GNU GPL | |
4e17e6
|
10 |
| | |
T |
11 |
| PURPOSE: | |
|
12 |
| Provide webmail functionality and GUI objects | |
|
13 |
| | |
|
14 |
+-----------------------------------------------------------------------+ |
|
15 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
16 |
+-----------------------------------------------------------------------+ |
|
17 |
|
|
18 |
$Id$ |
|
19 |
|
|
20 |
*/ |
|
21 |
|
7c60ff
|
22 |
$EMAIL_ADDRESS_PATTERN = '([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9][a-z0-9\-\.]*\\.[a-z]{2,5})'; |
39cd51
|
23 |
|
A |
24 |
// actions that do not require imap connection |
133bb0
|
25 |
$NOIMAP_ACTIONS = array('spell', 'addcontact', 'autocomplete', 'upload', 'display-attachment', 'remove-attachment'); |
39cd51
|
26 |
|
A |
27 |
|
|
28 |
// log in to imap server |
|
29 |
if (!in_array($RCMAIL->action, $NOIMAP_ACTIONS) && !$RCMAIL->imap_connect()) { |
|
30 |
$RCMAIL->kill_session(); |
|
31 |
|
|
32 |
if ($OUTPUT->ajax_call) |
|
33 |
$OUTPUT->redirect(array(), 2000); |
|
34 |
|
|
35 |
$OUTPUT->set_env('task', 'login'); |
|
36 |
$OUTPUT->send('login'); |
|
37 |
} |
|
38 |
|
4e17e6
|
39 |
|
T |
40 |
// set imap properties and session vars |
b3ce79
|
41 |
if ($mbox = get_input_value('_mbox', RCUBE_INPUT_GPC)) |
c57996
|
42 |
$IMAP->set_mailbox(($_SESSION['mbox'] = $mbox)); |
4e5b11
|
43 |
else |
A |
44 |
$_SESSION['mbox'] = $IMAP->get_mailbox_name(); |
4e17e6
|
45 |
|
b3ce79
|
46 |
if (!empty($_GET['_page'])) |
c57996
|
47 |
$IMAP->set_page(($_SESSION['page'] = intval($_GET['_page']))); |
4e17e6
|
48 |
|
6a35c8
|
49 |
// set default sort col/order to session |
T |
50 |
if (!isset($_SESSION['sort_col'])) |
|
51 |
$_SESSION['sort_col'] = $CONFIG['message_sort_col']; |
|
52 |
if (!isset($_SESSION['sort_order'])) |
|
53 |
$_SESSION['sort_order'] = $CONFIG['message_sort_order']; |
2bca6e
|
54 |
|
T |
55 |
// set message set for search result |
8d0758
|
56 |
if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']])) |
1f020b
|
57 |
{ |
8d0758
|
58 |
$IMAP->set_search_set($_SESSION['search'][$_REQUEST['_search']]); |
1f020b
|
59 |
$OUTPUT->set_env('search_request', $_REQUEST['_search']); |
S |
60 |
$OUTPUT->set_env('search_text', $_SESSION['last_text_search']); |
|
61 |
} |
4e17e6
|
62 |
|
528514
|
63 |
// set main env variables, labels and page title |
197601
|
64 |
if (empty($RCMAIL->action) || $RCMAIL->action == 'list') |
528514
|
65 |
{ |
8abda5
|
66 |
$mbox_name = $IMAP->get_mailbox_name(); |
A |
67 |
|
|
68 |
if (empty($RCMAIL->action)) |
|
69 |
{ |
|
70 |
// initialize searching result if search_filter is used |
|
71 |
if ($_SESSION['search_filter'] && $_SESSION['search_filter'] != 'ALL') |
|
72 |
{ |
|
73 |
$search_request = md5($mbox_name.$_SESSION['search_filter']); |
|
74 |
|
|
75 |
$IMAP->search($mbox_name, $_SESSION['search_filter'], RCMAIL_CHARSET, $_SESSION['sort_col']); |
|
76 |
$_SESSION['search'][$search_request] = $IMAP->get_search_set(); |
|
77 |
$OUTPUT->set_env('search_request', $search_request); |
|
78 |
} |
39cd51
|
79 |
|
30b152
|
80 |
$OUTPUT->set_env('search_mods', $_SESSION['search_mods'] ? $_SESSION['search_mods'] : array('subject'=>'subject')); |
39cd51
|
81 |
// make sure the message count is refreshed (for default view) |
A |
82 |
$IMAP->messagecount($mbox_name, 'ALL', true); |
8abda5
|
83 |
} |
A |
84 |
|
528514
|
85 |
// set current mailbox in client environment |
8abda5
|
86 |
$OUTPUT->set_env('mailbox', $mbox_name); |
528514
|
87 |
$OUTPUT->set_env('quota', $IMAP->get_capability('quota')); |
A |
88 |
$OUTPUT->set_env('delimiter', $IMAP->get_hierarchy_delimiter()); |
|
89 |
|
0b2ce9
|
90 |
if ($CONFIG['flag_for_deletion']) |
A |
91 |
$OUTPUT->set_env('flag_for_deletion', true); |
|
92 |
if ($CONFIG['read_when_deleted']) |
|
93 |
$OUTPUT->set_env('read_when_deleted', true); |
|
94 |
if ($CONFIG['skip_deleted']) |
|
95 |
$OUTPUT->set_env('skip_deleted', true); |
e54bb7
|
96 |
if ($CONFIG['display_next']) |
A |
97 |
$OUTPUT->set_env('display_next', true); |
0b2ce9
|
98 |
|
528514
|
99 |
if ($CONFIG['trash_mbox']) |
A |
100 |
$OUTPUT->set_env('trash_mailbox', $CONFIG['trash_mbox']); |
|
101 |
if ($CONFIG['drafts_mbox']) |
|
102 |
$OUTPUT->set_env('drafts_mailbox', $CONFIG['drafts_mbox']); |
|
103 |
if ($CONFIG['junk_mbox']) |
|
104 |
$OUTPUT->set_env('junk_mailbox', $CONFIG['junk_mbox']); |
|
105 |
|
|
106 |
if (!$OUTPUT->ajax_call) |
112c91
|
107 |
$OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash', 'movingmessage'); |
528514
|
108 |
|
4e5b11
|
109 |
$OUTPUT->set_pagetitle(rcmail_localize_foldername($mbox_name)); |
a86204
|
110 |
} |
5eee00
|
111 |
|
4e17e6
|
112 |
|
45f56c
|
113 |
/** |
T |
114 |
* return the message list as HTML table |
|
115 |
*/ |
4e17e6
|
116 |
function rcmail_message_list($attrib) |
T |
117 |
{ |
f11541
|
118 |
global $IMAP, $CONFIG, $COMM_PATH, $OUTPUT; |
b076a4
|
119 |
|
4e17e6
|
120 |
$skin_path = $CONFIG['skin_path']; |
e189a6
|
121 |
$image_tag = '<img src="%s%s" alt="%s" />'; |
b076a4
|
122 |
|
f3b659
|
123 |
// check to see if we have some settings for sorting |
6a35c8
|
124 |
$sort_col = $_SESSION['sort_col']; |
T |
125 |
$sort_order = $_SESSION['sort_order']; |
24053e
|
126 |
|
T |
127 |
// add some labels to client |
112c91
|
128 |
$OUTPUT->add_label('from', 'to'); |
f3b659
|
129 |
|
4e17e6
|
130 |
// get message headers |
f3b659
|
131 |
$a_headers = $IMAP->list_headers('', '', $sort_col, $sort_order); |
4e17e6
|
132 |
|
T |
133 |
// add id to message list table if not specified |
|
134 |
if (!strlen($attrib['id'])) |
|
135 |
$attrib['id'] = 'rcubemessagelist'; |
|
136 |
|
|
137 |
// allow the following attributes to be added to the <table> tag |
|
138 |
$attrib_str = create_attrib_string($attrib, array('style', 'class', 'id', 'cellpadding', 'cellspacing', 'border', 'summary')); |
|
139 |
|
|
140 |
$out = '<table' . $attrib_str . ">\n"; |
e0ddd4
|
141 |
|
d59aaa
|
142 |
// define list of cols to be displayed based on parameter or config |
A |
143 |
if (empty($attrib['columns'])) |
|
144 |
$a_show_cols = is_array($CONFIG['list_cols']) ? $CONFIG['list_cols'] : array('subject'); |
|
145 |
else |
58687d
|
146 |
$a_show_cols = preg_split('/[\s,;]+/', strip_quotes($attrib['columns'])); |
d59aaa
|
147 |
|
A |
148 |
// store column list in a session-variable |
|
149 |
$_SESSION['list_columns'] = $a_show_cols; |
|
150 |
|
|
151 |
// define sortable columns |
c8c1e0
|
152 |
$a_sort_cols = array('subject', 'date', 'from', 'to', 'size'); |
41bece
|
153 |
|
T |
154 |
$mbox = $IMAP->get_mailbox_name(); |
4e17e6
|
155 |
|
T |
156 |
// show 'to' instead of from in sent messages |
41bece
|
157 |
if (($mbox==$CONFIG['sent_mbox'] || $mbox==$CONFIG['drafts_mbox']) && ($f = array_search('from', $a_show_cols)) |
8c2e58
|
158 |
&& !array_search('to', $a_show_cols)) |
4e17e6
|
159 |
$a_show_cols[$f] = 'to'; |
8c2e58
|
160 |
|
e0ddd4
|
161 |
// add col definition |
T |
162 |
$out .= '<colgroup>'; |
01c86f
|
163 |
$out .= '<col class="icon" />'; |
e0ddd4
|
164 |
|
T |
165 |
foreach ($a_show_cols as $col) |
d59aaa
|
166 |
$out .= ($col!='attachment') ? sprintf('<col class="%s" />', $col) : '<col class="icon" />'; |
e0ddd4
|
167 |
|
T |
168 |
$out .= "</colgroup>\n"; |
4e17e6
|
169 |
|
T |
170 |
// add table title |
|
171 |
$out .= "<thead><tr>\n<td class=\"icon\"> </td>\n"; |
b076a4
|
172 |
|
f3b659
|
173 |
$javascript = ''; |
4e17e6
|
174 |
foreach ($a_show_cols as $col) |
f3b659
|
175 |
{ |
T |
176 |
// get column name |
d59aaa
|
177 |
switch ($col) |
A |
178 |
{ |
|
179 |
case 'flag': |
|
180 |
$col_name = sprintf($image_tag, $skin_path, $attrib['unflaggedicon'], ''); |
|
181 |
break; |
|
182 |
case 'attachment': |
|
183 |
$col_name = sprintf($image_tag, $skin_path, $attrib['attachmenticon'], ''); |
|
184 |
break; |
|
185 |
default: |
|
186 |
$col_name = Q(rcube_label($col)); |
|
187 |
} |
f3b659
|
188 |
|
T |
189 |
// make sort links |
|
190 |
$sort = ''; |
2a9cb3
|
191 |
if (in_array($col, $a_sort_cols)) |
f3b659
|
192 |
{ |
1cded8
|
193 |
// have buttons configured |
T |
194 |
if (!empty($attrib['sortdescbutton']) || !empty($attrib['sortascbutton'])) |
|
195 |
{ |
|
196 |
$sort = ' '; |
b076a4
|
197 |
|
1cded8
|
198 |
// asc link |
T |
199 |
if (!empty($attrib['sortascbutton'])) |
|
200 |
{ |
f11541
|
201 |
$sort .= $OUTPUT->button(array( |
T |
202 |
'command' => 'sort', |
|
203 |
'prop' => $col.'_ASC', |
|
204 |
'image' => $attrib['sortascbutton'], |
|
205 |
'align' => 'absmiddle', |
|
206 |
'title' => 'sortasc')); |
1cded8
|
207 |
} |
b076a4
|
208 |
|
1cded8
|
209 |
// desc link |
T |
210 |
if (!empty($attrib['sortdescbutton'])) |
|
211 |
{ |
f11541
|
212 |
$sort .= $OUTPUT->button(array( |
T |
213 |
'command' => 'sort', |
|
214 |
'prop' => $col.'_DESC', |
|
215 |
'image' => $attrib['sortdescbutton'], |
|
216 |
'align' => 'absmiddle', |
|
217 |
'title' => 'sortdesc')); |
1cded8
|
218 |
} |
T |
219 |
} |
|
220 |
// just add a link tag to the header |
|
221 |
else |
b076a4
|
222 |
{ |
41bece
|
223 |
$col_name = sprintf( |
T |
224 |
'<a href="./#sort" onclick="return %s.command(\'sort\',\'%s\',this)" title="%s">%s</a>', |
|
225 |
JS_OBJECT_NAME, |
|
226 |
$col, |
|
227 |
rcube_label('sortby'), |
|
228 |
$col_name); |
b076a4
|
229 |
} |
f3b659
|
230 |
} |
b076a4
|
231 |
|
T |
232 |
$sort_class = $col==$sort_col ? " sorted$sort_order" : ''; |
f3b659
|
233 |
|
T |
234 |
// put it all together |
d59aaa
|
235 |
if ($col!='attachment') |
A |
236 |
$out .= '<td class="'.$col.$sort_class.'" id="rcm'.$col.'">' . "$col_name$sort</td>\n"; |
|
237 |
else |
|
238 |
$out .= '<td class="icon" id="rcm'.$col.'">' . "$col_name$sort</td>\n"; |
f3b659
|
239 |
} |
4e17e6
|
240 |
|
T |
241 |
$out .= "</tr></thead>\n<tbody>\n"; |
|
242 |
|
|
243 |
// no messages in this mailbox |
|
244 |
if (!sizeof($a_headers)) |
5eee00
|
245 |
$OUTPUT->show_message('nomessagesfound', 'notice'); |
4e17e6
|
246 |
|
T |
247 |
$a_js_message_arr = array(); |
|
248 |
|
|
249 |
// create row for each message |
|
250 |
foreach ($a_headers as $i => $header) //while (list($i, $header) = each($a_headers)) |
|
251 |
{ |
e189a6
|
252 |
$message_icon = $attach_icon = $flagged_icon = ''; |
4e17e6
|
253 |
$js_row_arr = array(); |
a164a2
|
254 |
$zebra_class = $i%2 ? ' even' : ' odd'; |
4e17e6
|
255 |
|
T |
256 |
// set messag attributes to javascript array |
6ec0a8
|
257 |
if ($header->deleted) |
S |
258 |
$js_row_arr['deleted'] = true; |
4e17e6
|
259 |
if (!$header->seen) |
T |
260 |
$js_row_arr['unread'] = true; |
|
261 |
if ($header->answered) |
|
262 |
$js_row_arr['replied'] = true; |
d73404
|
263 |
if ($header->forwarded) |
A |
264 |
$js_row_arr['forwarded'] = true; |
e189a6
|
265 |
if ($header->flagged) |
A |
266 |
$js_row_arr['flagged'] = true; |
|
267 |
|
6ec0a8
|
268 |
// set message icon |
S |
269 |
if ($attrib['deletedicon'] && $header->deleted) |
|
270 |
$message_icon = $attrib['deletedicon']; |
d73404
|
271 |
else if ($attrib['repliedicon'] && $header->answered) |
A |
272 |
{ |
|
273 |
if ($attrib['forwardedrepliedicon'] && $header->forwarded) |
|
274 |
$message_icon = $attrib['forwardedrepliedicon']; |
|
275 |
else |
|
276 |
$message_icon = $attrib['repliedicon']; |
|
277 |
} |
|
278 |
else if ($attrib['forwardedicon'] && $header->forwarded) |
|
279 |
$message_icon = $attrib['forwardedicon']; |
6ec0a8
|
280 |
else if ($attrib['unreadicon'] && !$header->seen) |
4e17e6
|
281 |
$message_icon = $attrib['unreadicon']; |
T |
282 |
else if ($attrib['messageicon']) |
|
283 |
$message_icon = $attrib['messageicon']; |
e189a6
|
284 |
|
A |
285 |
if ($attrib['flaggedicon'] && $header->flagged) |
|
286 |
$flagged_icon = $attrib['flaggedicon']; |
|
287 |
else if ($attrib['unflaggedicon'] && !$header->flagged) |
|
288 |
$flagged_icon = $attrib['unflaggedicon']; |
4e17e6
|
289 |
|
f11541
|
290 |
// set attachment icon |
7a2d79
|
291 |
if ($attrib['attachmenticon'] && preg_match("/multipart\/m/i", $header->ctype)) |
4e17e6
|
292 |
$attach_icon = $attrib['attachmenticon']; |
T |
293 |
|
a164a2
|
294 |
$out .= sprintf('<tr id="rcmrow%d" class="message%s%s%s%s">'."\n", |
15a9d1
|
295 |
$header->uid, |
T |
296 |
$header->seen ? '' : ' unread', |
|
297 |
$header->deleted ? ' deleted' : '', |
e189a6
|
298 |
$header->flagged ? ' flagged' : '', |
a164a2
|
299 |
$zebra_class); |
15a9d1
|
300 |
|
4e17e6
|
301 |
$out .= sprintf("<td class=\"icon\">%s</td>\n", $message_icon ? sprintf($image_tag, $skin_path, $message_icon, '') : ''); |
e189a6
|
302 |
|
5faac0
|
303 |
$IMAP->set_charset(!empty($header->charset) ? $header->charset : $CONFIG['default_charset']); |
583850
|
304 |
|
4e17e6
|
305 |
// format each col |
T |
306 |
foreach ($a_show_cols as $col) |
|
307 |
{ |
|
308 |
if ($col=='from' || $col=='to') |
8e44f4
|
309 |
$cont = Q(rcmail_address_string($header->$col, 3, false, $attrib['addicon']), 'show'); |
4e17e6
|
310 |
else if ($col=='subject') |
b4b081
|
311 |
{ |
41bece
|
312 |
$action = $mbox==$CONFIG['drafts_mbox'] ? 'compose' : 'show'; |
2b962c
|
313 |
$uid_param = $mbox==$CONFIG['drafts_mbox'] ? '_draft_uid' : '_uid'; |
44385f
|
314 |
$cont = abbreviate_string(trim($IMAP->decode_header($header->$col)), 160); |
T |
315 |
if (empty($cont)) $cont = rcube_label('nosubject'); |
2f2bb4
|
316 |
$cont = $OUTPUT->browser->ie ? Q($cont) : sprintf('<a href="%s" onclick="return rcube_event.cancel(event)">%s</a>', Q(rcmail_url($action, array($uid_param=>$header->uid, '_mbox'=>$mbox))), Q($cont)); |
b4b081
|
317 |
} |
e189a6
|
318 |
else if ($col=='flag') |
A |
319 |
$cont = $flagged_icon ? sprintf($image_tag, $skin_path, $flagged_icon, '') : ''; |
4e17e6
|
320 |
else if ($col=='size') |
T |
321 |
$cont = show_bytes($header->$col); |
|
322 |
else if ($col=='date') |
f11541
|
323 |
$cont = format_date($header->date); |
4e17e6
|
324 |
else |
2bca6e
|
325 |
$cont = Q($header->$col); |
4e17e6
|
326 |
|
d59aaa
|
327 |
if ($col!='attachment') |
A |
328 |
$out .= '<td class="'.$col.'">' . $cont . "</td>\n"; |
|
329 |
else |
de2e0b
|
330 |
$out .= sprintf("<td class=\"icon\">%s</td>\n", $attach_icon ? sprintf($image_tag, $skin_path, $attach_icon, '') : ' '); |
4e17e6
|
331 |
} |
T |
332 |
|
|
333 |
$out .= "</tr>\n"; |
|
334 |
|
|
335 |
if (sizeof($js_row_arr)) |
|
336 |
$a_js_message_arr[$header->uid] = $js_row_arr; |
|
337 |
} |
|
338 |
|
|
339 |
// complete message table |
|
340 |
$out .= "</tbody></table>\n"; |
|
341 |
|
|
342 |
$message_count = $IMAP->messagecount(); |
|
343 |
|
|
344 |
// set client env |
f11541
|
345 |
$OUTPUT->add_gui_object('mailcontframe', 'mailcontframe'); |
T |
346 |
$OUTPUT->add_gui_object('messagelist', $attrib['id']); |
|
347 |
$OUTPUT->set_env('messagecount', $message_count); |
|
348 |
$OUTPUT->set_env('current_page', $IMAP->list_page); |
|
349 |
$OUTPUT->set_env('pagecount', ceil($message_count/$IMAP->page_size)); |
|
350 |
$OUTPUT->set_env('sort_col', $sort_col); |
|
351 |
$OUTPUT->set_env('sort_order', $sort_order); |
4e17e6
|
352 |
|
T |
353 |
if ($attrib['messageicon']) |
f11541
|
354 |
$OUTPUT->set_env('messageicon', $skin_path . $attrib['messageicon']); |
6ec0a8
|
355 |
if ($attrib['deletedicon']) |
f11541
|
356 |
$OUTPUT->set_env('deletedicon', $skin_path . $attrib['deletedicon']); |
4e17e6
|
357 |
if ($attrib['unreadicon']) |
f11541
|
358 |
$OUTPUT->set_env('unreadicon', $skin_path . $attrib['unreadicon']); |
4e17e6
|
359 |
if ($attrib['repliedicon']) |
f11541
|
360 |
$OUTPUT->set_env('repliedicon', $skin_path . $attrib['repliedicon']); |
d73404
|
361 |
if ($attrib['forwardedicon']) |
A |
362 |
$OUTPUT->set_env('forwardedicon', $skin_path . $attrib['forwardedicon']); |
|
363 |
if ($attrib['forwardedrepliedicon']) |
|
364 |
$OUTPUT->set_env('forwardedrepliedicon', $skin_path . $attrib['forwardedrepliedicon']); |
4e17e6
|
365 |
if ($attrib['attachmenticon']) |
f11541
|
366 |
$OUTPUT->set_env('attachmenticon', $skin_path . $attrib['attachmenticon']); |
e189a6
|
367 |
if ($attrib['flaggedicon']) |
A |
368 |
$OUTPUT->set_env('flaggedicon', $skin_path . $attrib['flaggedicon']); |
|
369 |
if ($attrib['unflaggedicon']) |
|
370 |
$OUTPUT->set_env('unflaggedicon', $skin_path . $attrib['unflaggedicon']); |
4e17e6
|
371 |
|
ae895a
|
372 |
$OUTPUT->set_env('messages', $a_js_message_arr); |
d24d20
|
373 |
$OUTPUT->set_env('coltypes', $a_show_cols); |
f11541
|
374 |
|
6b47de
|
375 |
$OUTPUT->include_script('list.js'); |
4e17e6
|
376 |
|
T |
377 |
return $out; |
|
378 |
} |
|
379 |
|
|
380 |
|
45f56c
|
381 |
/** |
T |
382 |
* return javascript commands to add rows to the message list |
7a7235
|
383 |
* or to replace the whole list (IE only) |
45f56c
|
384 |
*/ |
7a7235
|
385 |
function rcmail_js_message_list($a_headers, $insert_top=FALSE, $replace=TRUE) |
4e17e6
|
386 |
{ |
f11541
|
387 |
global $CONFIG, $IMAP, $OUTPUT; |
4e17e6
|
388 |
|
d59aaa
|
389 |
if (empty($_SESSION['list_columns'])) |
A |
390 |
$a_show_cols = is_array($CONFIG['list_cols']) ? $CONFIG['list_cols'] : array('subject'); |
|
391 |
else |
|
392 |
$a_show_cols = $_SESSION['list_columns']; |
|
393 |
|
41bece
|
394 |
$mbox = $IMAP->get_mailbox_name(); |
4e17e6
|
395 |
|
T |
396 |
// show 'to' instead of from in sent messages |
41bece
|
397 |
if (($mbox == $CONFIG['sent_mbox'] || $mbox == $CONFIG['drafts_mbox']) |
f11541
|
398 |
&& (($f = array_search('from', $a_show_cols)) !== false) && array_search('to', $a_show_cols) === false) |
4e17e6
|
399 |
$a_show_cols[$f] = 'to'; |
T |
400 |
|
c4b819
|
401 |
$browser = new rcube_browser; |
A |
402 |
|
f11541
|
403 |
$OUTPUT->command('set_message_coltypes', $a_show_cols); |
7a7235
|
404 |
if ($browser->ie && $replace) |
c4b819
|
405 |
$OUTPUT->command('offline_message_list', true); |
25d8ba
|
406 |
|
4e17e6
|
407 |
// loop through message headers |
ecd2e7
|
408 |
foreach ($a_headers as $n => $header) |
4e17e6
|
409 |
{ |
T |
410 |
$a_msg_cols = array(); |
|
411 |
$a_msg_flags = array(); |
ecd2e7
|
412 |
|
T |
413 |
if (empty($header)) |
|
414 |
continue; |
f11541
|
415 |
|
5faac0
|
416 |
$IMAP->set_charset(!empty($header->charset) ? $header->charset : $CONFIG['default_charset']); |
583850
|
417 |
|
d59aaa
|
418 |
// remove 'attachment' and 'flag' columns, we don't need them here |
A |
419 |
if(($key = array_search('attachment', $a_show_cols)) !== FALSE) |
|
420 |
unset($a_show_cols[$key]); |
|
421 |
if(($key = array_search('flag', $a_show_cols)) !== FALSE) |
|
422 |
unset($a_show_cols[$key]); |
|
423 |
|
4e17e6
|
424 |
// format each col; similar as in rcmail_message_list() |
T |
425 |
foreach ($a_show_cols as $col) |
|
426 |
{ |
|
427 |
if ($col=='from' || $col=='to') |
583850
|
428 |
$cont = Q(rcmail_address_string($header->$col, 3), 'show'); |
4e17e6
|
429 |
else if ($col=='subject') |
7bbd5f
|
430 |
{ |
41bece
|
431 |
$action = $mbox==$CONFIG['drafts_mbox'] ? 'compose' : 'show'; |
2b962c
|
432 |
$uid_param = $mbox==$CONFIG['drafts_mbox'] ? '_draft_uid' : '_uid'; |
daa3f7
|
433 |
$cont = abbreviate_string(trim($IMAP->decode_header($header->$col)), 160); |
44385f
|
434 |
if (!$cont) $cont = rcube_label('nosubject'); |
5302a9
|
435 |
$cont = $browser->ie ? Q($cont) : sprintf('<a href="%s" onclick="return rcube_event.cancel(event)">%s</a>', Q(rcmail_url($action, array($uid_param=>$header->uid, '_mbox'=>$mbox))), Q($cont)); |
7bbd5f
|
436 |
} |
4e17e6
|
437 |
else if ($col=='size') |
T |
438 |
$cont = show_bytes($header->$col); |
|
439 |
else if ($col=='date') |
f11541
|
440 |
$cont = format_date($header->date); |
4e17e6
|
441 |
else |
2bca6e
|
442 |
$cont = Q($header->$col); |
4e17e6
|
443 |
|
T |
444 |
$a_msg_cols[$col] = $cont; |
|
445 |
} |
|
446 |
|
c4b819
|
447 |
if ($header->deleted) |
A |
448 |
$a_msg_flags['deleted'] = 1; |
|
449 |
if (!$header->seen) |
|
450 |
$a_msg_flags['unread'] = 1; |
|
451 |
if ($header->answered) |
|
452 |
$a_msg_flags['replied'] = 1; |
|
453 |
if ($header->forwarded) |
|
454 |
$a_msg_flags['forwarded'] = 1; |
|
455 |
if ($header->flagged) |
|
456 |
$a_msg_flags['flagged'] = 1; |
2f2bb4
|
457 |
|
f11541
|
458 |
$OUTPUT->command('add_message_row', |
T |
459 |
$header->uid, |
|
460 |
$a_msg_cols, |
|
461 |
$a_msg_flags, |
|
462 |
preg_match("/multipart\/m/i", $header->ctype), |
|
463 |
$insert_top); |
4e17e6
|
464 |
} |
c4b819
|
465 |
|
7a7235
|
466 |
if ($browser->ie && $replace) |
c4b819
|
467 |
$OUTPUT->command('offline_message_list', false); |
4e17e6
|
468 |
} |
T |
469 |
|
|
470 |
|
45f56c
|
471 |
/** |
T |
472 |
* return an HTML iframe for loading mail content |
|
473 |
*/ |
b19097
|
474 |
function rcmail_messagecontent_frame($attrib) |
T |
475 |
{ |
f11541
|
476 |
global $OUTPUT; |
b19097
|
477 |
|
T |
478 |
if (empty($attrib['id'])) |
|
479 |
$attrib['id'] = 'rcmailcontentwindow'; |
|
480 |
|
e2c610
|
481 |
$attrib['name'] = $attrib['id']; |
b19097
|
482 |
|
e2c610
|
483 |
$OUTPUT->set_env('contentframe', $attrib['id']); |
f11541
|
484 |
$OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif'); |
b19097
|
485 |
|
95fcc3
|
486 |
return html::iframe($attrib); |
b19097
|
487 |
} |
T |
488 |
|
4e17e6
|
489 |
|
45f56c
|
490 |
/** |
T |
491 |
* |
|
492 |
*/ |
4e17e6
|
493 |
function rcmail_messagecount_display($attrib) |
T |
494 |
{ |
f11541
|
495 |
global $IMAP, $OUTPUT; |
4e17e6
|
496 |
|
T |
497 |
if (!$attrib['id']) |
|
498 |
$attrib['id'] = 'rcmcountdisplay'; |
|
499 |
|
f11541
|
500 |
$OUTPUT->add_gui_object('countdisplay', $attrib['id']); |
4e17e6
|
501 |
|
e2c610
|
502 |
return html::span($attrib, rcmail_get_messagecount_text()); |
4e17e6
|
503 |
} |
T |
504 |
|
|
505 |
|
45f56c
|
506 |
/** |
T |
507 |
* |
|
508 |
*/ |
58e360
|
509 |
function rcmail_quota_display($attrib) |
T |
510 |
{ |
f11541
|
511 |
global $OUTPUT, $COMM_PATH; |
58e360
|
512 |
|
T |
513 |
if (!$attrib['id']) |
|
514 |
$attrib['id'] = 'rcmquotadisplay'; |
|
515 |
|
6d2714
|
516 |
if(isset($attrib['display'])) |
A |
517 |
$_SESSION['quota_display'] = $attrib['display']; |
|
518 |
|
f11541
|
519 |
$OUTPUT->add_gui_object('quotadisplay', $attrib['id']); |
58e360
|
520 |
|
6d20d0
|
521 |
return html::span($attrib, rcmail_quota_content(NULL, $attrib)); |
23796e
|
522 |
} |
S |
523 |
|
|
524 |
|
45f56c
|
525 |
/** |
T |
526 |
* |
|
527 |
*/ |
6cd009
|
528 |
function rcmail_quota_content($quota=NULL, $attrib=NULL) |
23796e
|
529 |
{ |
876b15
|
530 |
global $IMAP, $COMM_PATH, $RCMAIL; |
3ea0e3
|
531 |
|
6d2714
|
532 |
$display = isset($_SESSION['quota_display']) ? $_SESSION['quota_display'] : ''; |
A |
533 |
|
|
534 |
if (is_array($quota) && !empty($quota['used']) && !empty($quota['total'])) |
3ea0e3
|
535 |
{ |
6d2714
|
536 |
if (!isset($quota['percent'])) |
A |
537 |
$quota['percent'] = $quota['used'] / $quota['total']; |
|
538 |
} |
|
539 |
elseif (!$IMAP->get_capability('QUOTA')) |
|
540 |
return rcube_label('unknown'); |
|
541 |
else |
|
542 |
$quota = $IMAP->get_quota(); |
|
543 |
|
876b15
|
544 |
if ($quota && !($quota['total']==0 && $RCMAIL->config->get('quota_zero_as_unlimited'))) |
6d2714
|
545 |
{ |
A |
546 |
$quota_text = sprintf('%s / %s (%.0f%%)', |
|
547 |
show_bytes($quota['used'] * 1024), |
|
548 |
show_bytes($quota['total'] * 1024), |
|
549 |
$quota['percent']); |
3ea0e3
|
550 |
|
T |
551 |
// show quota as image (by Brett Patterson) |
23796e
|
552 |
if ($display == 'image' && function_exists('imagegif')) |
3ea0e3
|
553 |
{ |
6cd009
|
554 |
if (!$attrib['width']) |
A |
555 |
$attrib['width'] = isset($_SESSION['quota_width']) ? $_SESSION['quota_width'] : 100; |
|
556 |
else |
|
557 |
$_SESSION['quota_width'] = $attrib['width']; |
|
558 |
|
|
559 |
if (!$attrib['height']) |
|
560 |
$attrib['height'] = isset($_SESSION['quota_height']) ? $_SESSION['quota_height'] : 14; |
|
561 |
else |
|
562 |
$_SESSION['quota_height'] = $attrib['height']; |
|
563 |
|
f11541
|
564 |
$quota_text = sprintf('<img src="./bin/quotaimg.php?u=%s&q=%d&w=%d&h=%d" width="%d" height="%d" alt="%s" title="%s / %s" />', |
3ea0e3
|
565 |
$quota['used'], $quota['total'], |
fda695
|
566 |
$attrib['width'], $attrib['height'], |
T |
567 |
$attrib['width'], $attrib['height'], |
|
568 |
$quota_text, |
6cd009
|
569 |
show_bytes($quota['used'] * 1024), |
A |
570 |
show_bytes($quota['total'] * 1024)); |
3ea0e3
|
571 |
} |
T |
572 |
} |
|
573 |
else |
4647e1
|
574 |
$quota_text = rcube_label('unlimited'); |
58e360
|
575 |
|
23796e
|
576 |
return $quota_text; |
58e360
|
577 |
} |
T |
578 |
|
4e17e6
|
579 |
|
45f56c
|
580 |
/** |
T |
581 |
* |
|
582 |
*/ |
4647e1
|
583 |
function rcmail_get_messagecount_text($count=NULL, $page=NULL) |
4e17e6
|
584 |
{ |
T |
585 |
global $IMAP, $MESSAGE; |
|
586 |
|
8fa58e
|
587 |
if (isset($MESSAGE->index)) |
4e17e6
|
588 |
{ |
T |
589 |
return rcube_label(array('name' => 'messagenrof', |
8fa58e
|
590 |
'vars' => array('nr' => $MESSAGE->index+1, |
4647e1
|
591 |
'count' => $count!==NULL ? $count : $IMAP->messagecount()))); |
4e17e6
|
592 |
} |
31b2ce
|
593 |
|
4647e1
|
594 |
if ($page===NULL) |
T |
595 |
$page = $IMAP->list_page; |
|
596 |
|
|
597 |
$start_msg = ($page-1) * $IMAP->page_size + 1; |
|
598 |
$max = $count!==NULL ? $count : $IMAP->messagecount(); |
4e17e6
|
599 |
|
T |
600 |
if ($max==0) |
|
601 |
$out = rcube_label('mailboxempty'); |
|
602 |
else |
|
603 |
$out = rcube_label(array('name' => 'messagesfromto', |
|
604 |
'vars' => array('from' => $start_msg, |
|
605 |
'to' => min($max, $start_msg + $IMAP->page_size - 1), |
|
606 |
'count' => $max))); |
|
607 |
|
2bca6e
|
608 |
return Q($out); |
4e17e6
|
609 |
} |
T |
610 |
|
ac5d15
|
611 |
/** |
T |
612 |
* |
|
613 |
*/ |
|
614 |
function rcmail_mailbox_name_display($attrib) |
|
615 |
{ |
|
616 |
global $RCMAIL; |
|
617 |
|
|
618 |
if (!$attrib['id']) |
|
619 |
$attrib['id'] = 'rcmmailboxname'; |
|
620 |
|
|
621 |
$RCMAIL->output->add_gui_object('mailboxname', $attrib['id']); |
|
622 |
|
|
623 |
return html::span($attrib, rcmail_get_mailbox_name_text()); |
|
624 |
} |
|
625 |
|
|
626 |
function rcmail_get_mailbox_name_text() |
|
627 |
{ |
|
628 |
global $RCMAIL; |
|
629 |
return rcmail_localize_foldername($RCMAIL->imap->get_mailbox_name()); |
|
630 |
} |
|
631 |
|
ec603f
|
632 |
/** |
A |
633 |
* Sets message is_safe flag according to 'show_images' option value |
|
634 |
* |
|
635 |
* @param object rcube_message Message |
|
636 |
*/ |
|
637 |
function rcmail_check_safe(&$message) |
|
638 |
{ |
|
639 |
global $RCMAIL; |
|
640 |
|
|
641 |
$show_images = $RCMAIL->config->get('show_images'); |
|
642 |
if (!$message->is_safe |
|
643 |
&& !empty($show_images) |
|
644 |
&& $message->has_html_part()) |
|
645 |
{ |
|
646 |
switch($show_images) { |
|
647 |
case '1': // known senders only |
8a78a1
|
648 |
$CONTACTS = new rcube_contacts($RCMAIL->db, $_SESSION['user_id']); |
ec603f
|
649 |
if ($CONTACTS->search('email', $message->sender['mailto'], true, false)->count) { |
A |
650 |
$message->set_safe(true); |
|
651 |
} |
|
652 |
break; |
|
653 |
case '2': // always |
|
654 |
$message->set_safe(true); |
|
655 |
break; |
|
656 |
} |
|
657 |
} |
|
658 |
} |
|
659 |
|
|
660 |
/** |
|
661 |
* Cleans up the given message HTML Body (for displaying) |
|
662 |
* |
|
663 |
* @param string HTML |
|
664 |
* @param array Display parameters |
|
665 |
* @param array CID map replaces (inline images) |
|
666 |
* @return string Clean HTML |
|
667 |
*/ |
|
668 |
function rcmail_wash_html($html, $p = array(), $cid_replaces) |
|
669 |
{ |
|
670 |
global $REMOTE_OBJECTS; |
|
671 |
|
|
672 |
$p += array('safe' => false, 'inline_html' => true); |
2337a8
|
673 |
|
ec603f
|
674 |
// special replacements (not properly handled by washtml class) |
A |
675 |
$html_search = array( |
|
676 |
'/(<\/nobr>)(\s+)(<nobr>)/i', // space(s) between <NOBR> |
|
677 |
'/<title>.*<\/title>/i', // PHP bug #32547 workaround: remove title tag |
3bde30
|
678 |
'/^(\0\0\xFE\xFF|\xFF\xFE\0\0|\xFE\xFF|\xFF\xFE|\xEF\xBB\xBF)/', // byte-order mark (only outlook?) |
4f7aa8
|
679 |
'/<html\s[^>]+>/i', // washtml/DOMDocument cannot handle xml namespaces |
ec603f
|
680 |
); |
A |
681 |
$html_replace = array( |
|
682 |
'\\1'.' '.'\\3', |
|
683 |
'', |
|
684 |
'', |
6c2d7e
|
685 |
'<html>', |
ec603f
|
686 |
); |
A |
687 |
$html = preg_replace($html_search, $html_replace, $html); |
2337a8
|
688 |
|
A |
689 |
// fix (unknown/malformed) HTML tags before "wash" |
|
690 |
$html = preg_replace_callback('/(<[\/!]*)([^ >]+)/', 'rcmail_html_tag_callback', $html); |
ec603f
|
691 |
|
a80b7d
|
692 |
// charset was converted to UTF-8 in rcube_imap::get_message_part(), |
269fb8
|
693 |
// -> change charset specification in HTML accordingly |
f4bf20
|
694 |
$charset_pattern = '(<meta\s+[^>]*)(content=[\'"]?\w+\/\w+;\s*charset)=([a-z0-9-_]+)'; |
A |
695 |
if (preg_match("/$charset_pattern/Ui", $html)) { |
|
696 |
$html = preg_replace("/$charset_pattern/i", '\\1\\2='.RCMAIL_CHARSET, $html); |
ec603f
|
697 |
} |
269fb8
|
698 |
else { |
A |
699 |
// add meta content-type to malformed messages, washtml cannot work without that |
|
700 |
if (!preg_match('/<head[^>]*>(.*)<\/head>/Uims', $html)) |
|
701 |
$html = '<head></head>'. $html; |
|
702 |
$html = substr_replace($html, '<meta http-equiv="Content-Type" content="text/html; charset='.RCMAIL_CHARSET.'" />', intval(stripos($html, '<head>')+6), 0); |
|
703 |
} |
10d0e3
|
704 |
|
ec603f
|
705 |
// turn relative into absolute urls |
A |
706 |
$html = rcmail_resolve_base($html); |
|
707 |
|
|
708 |
// clean HTML with washhtml by Frederic Motte |
|
709 |
$wash_opts = array( |
|
710 |
'show_washed' => false, |
|
711 |
'allow_remote' => $p['safe'], |
|
712 |
'blocked_src' => "./program/blocked.gif", |
|
713 |
'charset' => RCMAIL_CHARSET, |
|
714 |
'cid_map' => $cid_replaces, |
|
715 |
'html_elements' => array('body'), |
|
716 |
); |
|
717 |
|
|
718 |
if (!$p['inline_html']) { |
|
719 |
$wash_opts['html_elements'] = array('html','head','title','body'); |
|
720 |
} |
|
721 |
if ($p['safe']) { |
|
722 |
$wash_opts['html_elements'][] = 'link'; |
|
723 |
$wash_opts['html_attribs'] = array('rel','type'); |
|
724 |
} |
|
725 |
|
|
726 |
$washer = new washtml($wash_opts); |
|
727 |
$washer->add_callback('form', 'rcmail_washtml_callback'); |
|
728 |
|
2337a8
|
729 |
// allow CSS styles, will be sanitized by rcmail_washtml_callback() |
A |
730 |
$washer->add_callback('style', 'rcmail_washtml_callback'); |
ec603f
|
731 |
|
A |
732 |
$html = $washer->wash($html); |
|
733 |
$REMOTE_OBJECTS = $washer->extlinks; |
|
734 |
|
|
735 |
return $html; |
|
736 |
} |
|
737 |
|
4e17e6
|
738 |
|
45f56c
|
739 |
/** |
65cc1c
|
740 |
* Convert the given message part to proper HTML |
T |
741 |
* which can be displayed the message view |
45f56c
|
742 |
* |
65cc1c
|
743 |
* @param object rcube_message_part Message part |
ec603f
|
744 |
* @param array Display parameters array |
65cc1c
|
745 |
* @return string Formatted HTML string |
45f56c
|
746 |
*/ |
21e724
|
747 |
function rcmail_print_body($part, $p = array()) |
45f56c
|
748 |
{ |
cc97ea
|
749 |
global $RCMAIL; |
T |
750 |
|
|
751 |
// trigger plugin hook |
|
752 |
$data = $RCMAIL->plugins->exec_hook('message_part_before', |
|
753 |
array('type' => $part->ctype_secondary, 'body' => $part->body) + $p + array('safe' => false, 'plain' => false, 'inline_html' => true)); |
ec603f
|
754 |
|
5cc4b1
|
755 |
// convert html to text/plain |
cc97ea
|
756 |
if ($data['type'] == 'html' && $data['plain']) { |
T |
757 |
$txt = new html2text($data['body'], false, true); |
5cc4b1
|
758 |
$body = $txt->get_text(); |
T |
759 |
$part->ctype_secondary = 'plain'; |
45f56c
|
760 |
} |
4e17e6
|
761 |
// text/html |
cc97ea
|
762 |
else if ($data['type'] == 'html') { |
T |
763 |
$body = rcmail_wash_html($data['body'], $data, $part->replaces); |
|
764 |
$part->ctype_secondary = $data['type']; |
45f56c
|
765 |
} |
4e17e6
|
766 |
// text/enriched |
cc97ea
|
767 |
else if ($data['type'] == 'enriched') { |
cfe4a6
|
768 |
$part->ctype_secondary = 'html'; |
ec603f
|
769 |
require_once('lib/enriched.inc'); |
cc97ea
|
770 |
$body = Q(enriched_to_html($data['body']), 'show'); |
45f56c
|
771 |
} |
cc97ea
|
772 |
else { |
T |
773 |
// assert plaintext |
45f56c
|
774 |
$body = $part->body; |
cc97ea
|
775 |
$part->ctype_secondary = $data['type'] = 'plain'; |
45f56c
|
776 |
} |
cc97ea
|
777 |
|
T |
778 |
// free some memory (hopefully) |
|
779 |
unset($data['body']); |
45f56c
|
780 |
|
cc97ea
|
781 |
// plaintext postprocessing |
T |
782 |
if ($part->ctype_secondary == 'plain') { |
|
783 |
// make links and email-addresses clickable |
|
784 |
$replacements = new rcube_string_replacer; |
|
785 |
|
|
786 |
// search for patterns like links and e-mail addresses |
88ed23
|
787 |
$body = preg_replace_callback($replacements->link_pattern, array($replacements, 'link_callback'), $body); |
A |
788 |
$body = preg_replace_callback($replacements->mailto_pattern, array($replacements, 'mailto_callback'), $body); |
cc97ea
|
789 |
|
T |
790 |
// split body into single lines |
|
791 |
$a_lines = preg_split('/\r?\n/', $body); |
88ed23
|
792 |
$q_lines = array(); |
cc97ea
|
793 |
$quote_level = 0; |
T |
794 |
|
88ed23
|
795 |
// find/mark quoted lines... |
A |
796 |
for ($n=0, $cnt=count($a_lines); $n < $cnt; $n++) { |
cc97ea
|
797 |
$q = 0; |
T |
798 |
|
88ed23
|
799 |
if ($a_lines[$n][0] == '>' && preg_match('/^(>+\s*)+/', $a_lines[$n], $regs)) { |
A |
800 |
$q = strlen(preg_replace('/\s/', '', $regs[0])); |
|
801 |
$a_lines[$n] = substr($a_lines[$n], strlen($regs[0])); |
cc97ea
|
802 |
|
T |
803 |
if ($q > $quote_level) |
88ed23
|
804 |
$q_lines[$n]['quote'] = $q - $quote_level; |
cc97ea
|
805 |
else if ($q < $quote_level) |
6ca827
|
806 |
$q_lines[$n]['endquote'] = $quote_level - $q; |
cc97ea
|
807 |
} |
T |
808 |
else if ($quote_level > 0) |
88ed23
|
809 |
$q_lines[$n]['endquote'] = $quote_level; |
cc97ea
|
810 |
|
T |
811 |
$quote_level = $q; |
|
812 |
} |
88ed23
|
813 |
|
A |
814 |
// quote plain text |
|
815 |
$body = Q(join("\n", $a_lines), 'replace', false); |
|
816 |
|
a54242
|
817 |
// colorize signature |
A |
818 |
if (($sp = strrpos($body, '-- ')) !== false) |
|
819 |
if (($sp == 0 || $body[$sp-1] == "\n") && $body[$sp+3] == "\n") { |
|
820 |
$body = substr($body, 0, max(0, $sp)) |
|
821 |
.'<span class="sig">'.substr($body, $sp).'</span>'; |
|
822 |
} |
|
823 |
|
|
824 |
// colorize quoted lines |
88ed23
|
825 |
$a_lines = preg_split('/\n/', $body); |
A |
826 |
foreach ($q_lines as $i => $q) |
|
827 |
if ($q['quote']) |
|
828 |
$a_lines[$i] = str_repeat('<blockquote>', $q['quote']) . $a_lines[$i]; |
|
829 |
else if ($q['endquote']) |
|
830 |
$a_lines[$i] = str_repeat('</blockquote>', $q['endquote']) . $a_lines[$i]; |
cc97ea
|
831 |
|
T |
832 |
// insert the links for urls and mailtos |
|
833 |
$body = $replacements->resolve(join("\n", $a_lines)); |
|
834 |
} |
88ed23
|
835 |
|
cc97ea
|
836 |
// allow post-processing of the message body |
T |
837 |
$data = $RCMAIL->plugins->exec_hook('message_part_after', array('type' => $part->ctype_secondary, 'body' => $body) + $data); |
|
838 |
|
|
839 |
return $data['type'] == 'html' ? $data['body'] : html::tag('pre', array(), $data['body']); |
21e724
|
840 |
} |
4e17e6
|
841 |
|
ec603f
|
842 |
|
45f56c
|
843 |
/** |
T |
844 |
* add a string to the replacement array and return a replacement string |
|
845 |
*/ |
4e17e6
|
846 |
function rcmail_str_replacement($str, &$rep) |
21e724
|
847 |
{ |
4e17e6
|
848 |
static $count = 0; |
T |
849 |
$rep[$count] = stripslashes($str); |
|
850 |
return "##string_replacement{".($count++)."}##"; |
21e724
|
851 |
} |
4e17e6
|
852 |
|
21e724
|
853 |
|
T |
854 |
/** |
|
855 |
* Callback function for washtml cleaning class |
|
856 |
*/ |
|
857 |
function rcmail_washtml_callback($tagname, $attrib, $content) |
|
858 |
{ |
|
859 |
switch ($tagname) { |
|
860 |
case 'form': |
|
861 |
$out = html::div('form', $content); |
f54a3a
|
862 |
break; |
T |
863 |
|
1c499a
|
864 |
case 'style': |
T |
865 |
// decode all escaped entities and reduce to ascii strings |
c5ee03
|
866 |
$stripped = preg_replace('/[^a-zA-Z\(:]/', '', rcmail_xss_entity_decode($content)); |
1c499a
|
867 |
|
36c236
|
868 |
// now check for evil strings like expression, behavior or url() |
T |
869 |
if (!preg_match('/expression|behavior|url\(|import/', $stripped)) { |
1c499a
|
870 |
$out = html::tag('style', array('type' => 'text/css'), $content); |
T |
871 |
break; |
|
872 |
} |
|
873 |
|
21e724
|
874 |
default: |
T |
875 |
$out = ''; |
|
876 |
} |
|
877 |
|
|
878 |
return $out; |
|
879 |
} |
4e17e6
|
880 |
|
T |
881 |
|
45f56c
|
882 |
/** |
2337a8
|
883 |
* Callback function for HTML tags fixing |
A |
884 |
*/ |
|
885 |
function rcmail_html_tag_callback($matches) |
|
886 |
{ |
|
887 |
$tagname = $matches[2]; |
|
888 |
|
|
889 |
$tagname = preg_replace(array( |
|
890 |
'/:.*$/', // Microsoft's Smart Tags <st1:xxxx> |
|
891 |
'/[^a-z0-9_-]/i', // forbidden characters |
|
892 |
), '', $tagname); |
|
893 |
|
|
894 |
return $matches[1].$tagname; |
|
895 |
} |
|
896 |
|
|
897 |
|
|
898 |
/** |
45f56c
|
899 |
* return table with message headers |
T |
900 |
*/ |
4e17e6
|
901 |
function rcmail_message_headers($attrib, $headers=NULL) |
T |
902 |
{ |
cc97ea
|
903 |
global $IMAP, $OUTPUT, $MESSAGE, $PRINT_MODE, $RCMAIL; |
4e17e6
|
904 |
static $sa_attrib; |
T |
905 |
|
|
906 |
// keep header table attrib |
|
907 |
if (is_array($attrib) && !$sa_attrib) |
|
908 |
$sa_attrib = $attrib; |
|
909 |
else if (!is_array($attrib) && is_array($sa_attrib)) |
|
910 |
$attrib = $sa_attrib; |
|
911 |
|
|
912 |
if (!isset($MESSAGE)) |
|
913 |
return FALSE; |
|
914 |
|
|
915 |
// get associative array of headers object |
|
916 |
if (!$headers) |
8fa58e
|
917 |
$headers = is_object($MESSAGE->headers) ? get_object_vars($MESSAGE->headers) : $MESSAGE->headers; |
7c60ff
|
918 |
|
4e17e6
|
919 |
// show these headers |
591381
|
920 |
$standard_headers = array('subject', 'from', 'to', 'cc', 'bcc', 'replyto', 'date'); |
cc97ea
|
921 |
$output_headers = array(); |
e5686f
|
922 |
|
cc97ea
|
923 |
foreach ($standard_headers as $hkey) { |
4e17e6
|
924 |
if (!$headers[$hkey]) |
T |
925 |
continue; |
|
926 |
|
cc97ea
|
927 |
if ($hkey == 'date') { |
5b1de5
|
928 |
if ($PRINT_MODE) |
cc97ea
|
929 |
$header_value = format_date($headers[$hkey], $RCMAIL->config->get('date_long', 'x')); |
5b1de5
|
930 |
else |
A |
931 |
$header_value = format_date($headers[$hkey]); |
cc97ea
|
932 |
} |
T |
933 |
else if ($hkey == 'replyto') { |
700320
|
934 |
if ($headers['replyto'] != $headers['from']) |
cc97ea
|
935 |
$header_value = rcmail_address_string($headers['replyto'], null, true, $attrib['addicon']); |
700320
|
936 |
else |
A |
937 |
continue; |
4e17e6
|
938 |
} |
cc97ea
|
939 |
else if (in_array($hkey, array('from', 'to', 'cc', 'bcc'))) |
T |
940 |
$header_value = rcmail_address_string($headers[$hkey], null, true, $attrib['addicon']); |
|
941 |
else if ($hkey == 'subject' && empty($headers[$hkey])) |
|
942 |
$header_value = rcube_label('nosubject'); |
|
943 |
else |
|
944 |
$header_value = trim($IMAP->decode_header($headers[$hkey])); |
|
945 |
|
|
946 |
$output_headers[$hkey] = array('title' => rcube_label($hkey), 'value' => $header_value, 'raw' => $headers[$hkey]); |
|
947 |
} |
|
948 |
|
|
949 |
$plugin = $RCMAIL->plugins->exec_hook('message_headers_output', array('output' => $output_headers, 'headers' => $MESSAGE->headers)); |
|
950 |
|
|
951 |
// compose html table |
|
952 |
$table = new html_table(array('cols' => 2)); |
|
953 |
|
|
954 |
foreach ($plugin['output'] as $hkey => $row) { |
|
955 |
$table->add(array('class' => 'header-title'), Q($row['title'])); |
|
956 |
$table->add(array('class' => $hkey, 'width' => "90%"), Q($row['value'], ($hkey == 'subject' ? 'strict' : 'show'))); |
|
957 |
} |
4e17e6
|
958 |
|
e5686f
|
959 |
// all headers division |
cc97ea
|
960 |
$table->add(array('colspan' => 2, 'class' => "more-headers show-headers", 'onclick' => "return ".JS_OBJECT_NAME.".command('load-headers','',this)"), ''); |
T |
961 |
$table->add_row(array('id' => "all-headers")); |
|
962 |
$table->add(array('colspan' => 2, 'class' => "all"), html::div(array('id' => 'headers-source'), '')); |
|
963 |
|
e5686f
|
964 |
$OUTPUT->add_gui_object('all_headers_row', 'all-headers'); |
A |
965 |
$OUTPUT->add_gui_object('all_headers_box', 'headers-source'); |
|
966 |
|
cc97ea
|
967 |
return $table->show($attrib); |
4e17e6
|
968 |
} |
T |
969 |
|
|
970 |
|
45f56c
|
971 |
/** |
21605c
|
972 |
* Handler for the 'messagebody' GUI object |
45f56c
|
973 |
* |
21605c
|
974 |
* @param array Named parameters |
T |
975 |
* @return string HTML content showing the message body |
45f56c
|
976 |
*/ |
4e17e6
|
977 |
function rcmail_message_body($attrib) |
T |
978 |
{ |
8fa58e
|
979 |
global $CONFIG, $OUTPUT, $MESSAGE, $IMAP, $REMOTE_OBJECTS; |
5f8686
|
980 |
|
8fa58e
|
981 |
if (!is_array($MESSAGE->parts) && empty($MESSAGE->body)) |
4e17e6
|
982 |
return ''; |
T |
983 |
|
|
984 |
if (!$attrib['id']) |
|
985 |
$attrib['id'] = 'rcmailMsgBody'; |
|
986 |
|
8fa58e
|
987 |
$safe_mode = $MESSAGE->is_safe || intval($_GET['_safe']); |
21605c
|
988 |
$out = ''; |
4e17e6
|
989 |
|
T |
990 |
$header_attrib = array(); |
|
991 |
foreach ($attrib as $attr => $value) |
|
992 |
if (preg_match('/^headertable([a-z]+)$/i', $attr, $regs)) |
|
993 |
$header_attrib[$regs[1]] = $value; |
|
994 |
|
8fa58e
|
995 |
if (!empty($MESSAGE->parts)) |
4e17e6
|
996 |
{ |
8fa58e
|
997 |
foreach ($MESSAGE->parts as $i => $part) |
4e17e6
|
998 |
{ |
8fa58e
|
999 |
if ($part->type == 'headers') |
8d4bcd
|
1000 |
$out .= rcmail_message_headers(sizeof($header_attrib) ? $header_attrib : NULL, $part->headers); |
3b7e00
|
1001 |
else if ($part->type == 'content' && $part->size) |
4e17e6
|
1002 |
{ |
8d4bcd
|
1003 |
if (empty($part->ctype_parameters) || empty($part->ctype_parameters['charset'])) |
8fa58e
|
1004 |
$part->ctype_parameters['charset'] = $MESSAGE->headers->charset; |
a0109c
|
1005 |
|
8d4bcd
|
1006 |
// fetch part if not available |
T |
1007 |
if (!isset($part->body)) |
8fa58e
|
1008 |
$part->body = $MESSAGE->get_part_content($part->mime_id); |
a0109c
|
1009 |
|
21e724
|
1010 |
$body = rcmail_print_body($part, array('safe' => $safe_mode, 'plain' => !$CONFIG['prefer_html'])); |
5f8686
|
1011 |
|
cfe4a6
|
1012 |
if ($part->ctype_secondary == 'html') |
21605c
|
1013 |
$out .= html::div('message-htmlpart', rcmail_html4inline($body, $attrib['id'])); |
a2f2c5
|
1014 |
else |
21605c
|
1015 |
$out .= html::div('message-part', $body); |
4e17e6
|
1016 |
} |
T |
1017 |
} |
|
1018 |
} |
|
1019 |
else |
278064
|
1020 |
$out .= html::div('message-part', html::tag('pre', array(), Q($MESSAGE->body))); |
4e17e6
|
1021 |
|
8fa58e
|
1022 |
$ctype_primary = strtolower($MESSAGE->structure->ctype_primary); |
T |
1023 |
$ctype_secondary = strtolower($MESSAGE->structure->ctype_secondary); |
166b61
|
1024 |
|
4e17e6
|
1025 |
// list images after mail body |
be5f03
|
1026 |
if ($CONFIG['inline_images'] |
2da368
|
1027 |
&& $ctype_primary == 'multipart' |
T |
1028 |
&& !empty($MESSAGE->attachments) |
|
1029 |
&& !strstr($message_body, '<html')) |
166b61
|
1030 |
{ |
8fa58e
|
1031 |
foreach ($MESSAGE->attachments as $attach_prop) { |
T |
1032 |
if (strpos($attach_prop->mimetype, 'image/') === 0) { |
|
1033 |
$out .= html::tag('hr') . html::p(array('align' => "center"), |
|
1034 |
html::img(array( |
|
1035 |
'src' => $MESSAGE->get_part_url($attach_prop->mime_id), |
|
1036 |
'title' => $attach_prop->filename, |
|
1037 |
'alt' => $attach_prop->filename, |
|
1038 |
))); |
|
1039 |
} |
4e17e6
|
1040 |
} |
8fa58e
|
1041 |
} |
4e17e6
|
1042 |
|
T |
1043 |
// tell client that there are blocked remote objects |
|
1044 |
if ($REMOTE_OBJECTS && !$safe_mode) |
f11541
|
1045 |
$OUTPUT->set_env('blockedobjects', true); |
4e17e6
|
1046 |
|
21605c
|
1047 |
return html::div($attrib, $out); |
4e17e6
|
1048 |
} |
T |
1049 |
|
|
1050 |
|
aa055c
|
1051 |
/** |
T |
1052 |
* Convert all relative URLs according to a <base> in HTML |
|
1053 |
*/ |
|
1054 |
function rcmail_resolve_base($body) |
|
1055 |
{ |
|
1056 |
// check for <base href=...> |
|
1057 |
if (preg_match('!(<base.*href=["\']?)([hftps]{3,5}://[a-z0-9/.%-]+)!i', $body, $regs)) { |
|
1058 |
$replacer = new rcube_base_replacer($regs[2]); |
|
1059 |
|
|
1060 |
// replace all relative paths |
|
1061 |
$body = preg_replace_callback('/(src|background|href)=(["\']?)([\.\/]+[^"\'\s]+)(\2|\s|>)/Ui', array($replacer, 'callback'), $body); |
|
1062 |
$body = preg_replace_callback('/(url\s*\()(["\']?)([\.\/]+[^"\'\)\s]+)(\2)\)/Ui', array($replacer, 'callback'), $body); |
|
1063 |
} |
|
1064 |
|
|
1065 |
return $body; |
|
1066 |
} |
4e17e6
|
1067 |
|
45f56c
|
1068 |
/** |
T |
1069 |
* modify a HTML message that it can be displayed inside a HTML page |
|
1070 |
*/ |
|
1071 |
function rcmail_html4inline($body, $container_id) |
4e17e6
|
1072 |
{ |
T |
1073 |
$last_style_pos = 0; |
|
1074 |
$body_lc = strtolower($body); |
|
1075 |
|
|
1076 |
// find STYLE tags |
|
1077 |
while (($pos = strpos($body_lc, '<style', $last_style_pos)) && ($pos2 = strpos($body_lc, '</style>', $pos))) |
|
1078 |
{ |
ea206d
|
1079 |
$pos = strpos($body_lc, '>', $pos)+1; |
T |
1080 |
|
4e17e6
|
1081 |
// replace all css definitions with #container [def] |
aa055c
|
1082 |
$styles = rcmail_mod_css_styles(substr($body, $pos, $pos2-$pos), $container_id); |
ea206d
|
1083 |
|
3b12ae
|
1084 |
$body = substr($body, 0, $pos) . $styles . substr($body, $pos2); |
S |
1085 |
$body_lc = strtolower($body); |
4e17e6
|
1086 |
$last_style_pos = $pos2; |
5e98e1
|
1087 |
} |
4e17e6
|
1088 |
|
fe79b1
|
1089 |
// modify HTML links to open a new window if clicked |
115263
|
1090 |
$GLOBALS['rcmail_html_container_id'] = $container_id; |
T |
1091 |
$body = preg_replace_callback('/<(a|link)\s+([^>]+)>/Ui', 'rcmail_alter_html_link', $body); |
|
1092 |
unset($GLOBALS['rcmail_html_container_id']); |
4e17e6
|
1093 |
|
T |
1094 |
// add comments arround html and other tags |
06895c
|
1095 |
$out = preg_replace(array( |
d7a411
|
1096 |
'/(<!DOCTYPE[^>]*>)/i', |
A |
1097 |
'/(<\?xml[^>]*>)/i', |
06895c
|
1098 |
'/(<\/?html[^>]*>)/i', |
T |
1099 |
'/(<\/?head[^>]*>)/i', |
|
1100 |
'/(<title[^>]*>.*<\/title>)/Ui', |
|
1101 |
'/(<\/?meta[^>]*>)/i'), |
|
1102 |
'<!--\\1-->', |
|
1103 |
$body); |
a0109c
|
1104 |
|
97bd2c
|
1105 |
$out = preg_replace( |
45f56c
|
1106 |
array('/<body([^>]*)>/i', '/<\/body>/i'), |
T |
1107 |
array('<div class="rcmBody"\\1>', '</div>'), |
97bd2c
|
1108 |
$out); |
a0109c
|
1109 |
|
86958f
|
1110 |
// quote <? of php and xml files that are specified as text/html |
T |
1111 |
$out = preg_replace(array('/<\?/', '/\?>/'), array('<?', '?>'), $out); |
|
1112 |
|
4e17e6
|
1113 |
return $out; |
T |
1114 |
} |
|
1115 |
|
|
1116 |
|
45f56c
|
1117 |
/** |
T |
1118 |
* parse link attributes and set correct target |
|
1119 |
*/ |
115263
|
1120 |
function rcmail_alter_html_link($matches) |
e5af2f
|
1121 |
{ |
115263
|
1122 |
global $EMAIL_ADDRESS_PATTERN; |
T |
1123 |
|
|
1124 |
$tag = $matches[1]; |
|
1125 |
$attrib = parse_attrib_string($matches[2]); |
e5af2f
|
1126 |
$end = '>'; |
84f5b7
|
1127 |
|
e5af2f
|
1128 |
if ($tag == 'link' && preg_match('/^https?:\/\//i', $attrib['href'])) { |
115263
|
1129 |
$attrib['href'] = "./bin/modcss.php?u=" . urlencode($attrib['href']) . "&c=" . urlencode($GLOBALS['rcmail_html_container_id']); |
e5af2f
|
1130 |
$end = ' />'; |
T |
1131 |
} |
115263
|
1132 |
else if (preg_match("/^mailto:$EMAIL_ADDRESS_PATTERN/i", $attrib['href'], $mailto)) { |
T |
1133 |
$attrib['href'] = $mailto[0]; |
97bd2c
|
1134 |
$attrib['onclick'] = sprintf( |
T |
1135 |
"return %s.command('compose','%s',this)", |
|
1136 |
JS_OBJECT_NAME, |
115263
|
1137 |
JQ($mailto[1])); |
4e17e6
|
1138 |
} |
e5af2f
|
1139 |
else if (!empty($attrib['href']) && $attrib['href'][0] != '#') { |
T |
1140 |
$attrib['target'] = '_blank'; |
|
1141 |
} |
|
1142 |
|
|
1143 |
return "<$tag" . html::attrib_string($attrib, array('href','name','target','onclick','id','class','style','title','rel','type','media')) . $end; |
|
1144 |
} |
4e17e6
|
1145 |
|
T |
1146 |
|
45f56c
|
1147 |
/** |
T |
1148 |
* decode address string and re-format it as HTML links |
|
1149 |
*/ |
8e44f4
|
1150 |
function rcmail_address_string($input, $max=null, $linked=false, $addicon=null) |
T |
1151 |
{ |
f11541
|
1152 |
global $IMAP, $PRINT_MODE, $CONFIG, $OUTPUT, $EMAIL_ADDRESS_PATTERN; |
1088d6
|
1153 |
|
4e17e6
|
1154 |
$a_parts = $IMAP->decode_address_list($input); |
T |
1155 |
|
|
1156 |
if (!sizeof($a_parts)) |
|
1157 |
return $input; |
|
1158 |
|
|
1159 |
$c = count($a_parts); |
|
1160 |
$j = 0; |
|
1161 |
$out = ''; |
|
1162 |
|
8e44f4
|
1163 |
foreach ($a_parts as $part) { |
4e17e6
|
1164 |
$j++; |
8e44f4
|
1165 |
if ($PRINT_MODE) { |
90cd45
|
1166 |
$out .= sprintf('%s <%s>', Q($part['name']), $part['mailto']); |
8e44f4
|
1167 |
} |
115263
|
1168 |
else if (preg_match("/$EMAIL_ADDRESS_PATTERN/i", $part['mailto'])) { |
8e44f4
|
1169 |
if ($linked) { |
T |
1170 |
$out .= html::a(array( |
|
1171 |
'href' => 'mailto:'.$part['mailto'], |
|
1172 |
'onclick' => sprintf("return %s.command('compose','%s',this)", JS_OBJECT_NAME, JQ($part['mailto'])), |
|
1173 |
'title' => $part['mailto'], |
|
1174 |
'class' => "rcmContactAddress", |
|
1175 |
), |
|
1176 |
Q($part['name'])); |
4e17e6
|
1177 |
} |
8e44f4
|
1178 |
else { |
T |
1179 |
$out .= html::span(array('title' => $part['mailto'], 'class' => "rcmContactAddress"), Q($part['name'])); |
|
1180 |
} |
|
1181 |
|
|
1182 |
if ($addicon) { |
|
1183 |
$out .= ' ' . html::a(array( |
|
1184 |
'href' => "#add", |
|
1185 |
'onclick' => sprintf("return %s.command('add-contact','%s',this)", JS_OBJECT_NAME, urlencode($part['string'])), |
|
1186 |
'title' => rcube_label('addtoaddressbook'), |
|
1187 |
), |
|
1188 |
html::img(array( |
|
1189 |
'src' => $CONFIG['skin_path'] . $addicon, |
|
1190 |
'alt' => "Add contact", |
|
1191 |
))); |
|
1192 |
} |
|
1193 |
} |
|
1194 |
else { |
4e17e6
|
1195 |
if ($part['name']) |
2bca6e
|
1196 |
$out .= Q($part['name']); |
4e17e6
|
1197 |
if ($part['mailto']) |
28bfe4
|
1198 |
$out .= (strlen($out) ? ' ' : '') . sprintf('<%s>', Q($part['mailto'])); |
8e44f4
|
1199 |
} |
4e17e6
|
1200 |
|
T |
1201 |
if ($c>$j) |
|
1202 |
$out .= ','.($max ? ' ' : ' '); |
|
1203 |
|
8e44f4
|
1204 |
if ($max && $j==$max && $c>$j) { |
4e17e6
|
1205 |
$out .= '...'; |
T |
1206 |
break; |
|
1207 |
} |
8e44f4
|
1208 |
} |
4e17e6
|
1209 |
|
T |
1210 |
return $out; |
8e44f4
|
1211 |
} |
4e17e6
|
1212 |
|
T |
1213 |
|
ccd63c
|
1214 |
/** |
T |
1215 |
* Wrap text to a given number of characters per line |
|
1216 |
* but respect the mail quotation of replies messages (>) |
|
1217 |
* |
|
1218 |
* @param string Text to wrap |
|
1219 |
* @param int The line width |
|
1220 |
* @return string The wrapped text |
|
1221 |
*/ |
|
1222 |
function rcmail_wrap_quoted($text, $max = 76) |
|
1223 |
{ |
|
1224 |
// Rebuild the message body with a maximum of $max chars, while keeping quoted message. |
|
1225 |
$lines = preg_split('/\r?\n/', trim($text)); |
|
1226 |
$out = ''; |
|
1227 |
|
|
1228 |
foreach ($lines as $line) { |
|
1229 |
if (strlen($line) > $max) { |
|
1230 |
if (preg_match('/^([>\s]+)/', $line, $regs)) { |
|
1231 |
$length = strlen($regs[0]); |
|
1232 |
$prefix = substr($line, 0, $length); |
|
1233 |
|
|
1234 |
// Remove '> ' from the line, then wordwrap() the line |
7145e0
|
1235 |
$line = rc_wordwrap(substr($line, $length), $max - $length); |
ccd63c
|
1236 |
|
T |
1237 |
// Rebuild the line with '> ' at the beginning of each 'subline' |
|
1238 |
$newline = ''; |
|
1239 |
foreach (explode("\n", $line) as $l) { |
|
1240 |
$newline .= $prefix . $l . "\n"; |
|
1241 |
} |
|
1242 |
|
|
1243 |
// Remove the righest newline char |
|
1244 |
$line = rtrim($newline); |
|
1245 |
} |
|
1246 |
else { |
7145e0
|
1247 |
$line = rc_wordwrap($line, $max); |
ccd63c
|
1248 |
} |
T |
1249 |
} |
|
1250 |
|
|
1251 |
// Append the line |
|
1252 |
$out .= $line . "\n"; |
|
1253 |
} |
|
1254 |
|
|
1255 |
return $out; |
|
1256 |
} |
|
1257 |
|
|
1258 |
|
4e17e6
|
1259 |
function rcmail_message_part_controls() |
T |
1260 |
{ |
8fa58e
|
1261 |
global $MESSAGE; |
4e17e6
|
1262 |
|
d5342a
|
1263 |
$part = asciiwords(get_input_value('_part', RCUBE_INPUT_GPC)); |
8fa58e
|
1264 |
if (!is_object($MESSAGE) || !is_array($MESSAGE->parts) || !($_GET['_uid'] && $_GET['_part']) || !$MESSAGE->mime_parts[$part]) |
4e17e6
|
1265 |
return ''; |
T |
1266 |
|
8fa58e
|
1267 |
$part = $MESSAGE->mime_parts[$part]; |
T |
1268 |
$table = new html_table(array('cols' => 3)); |
4e17e6
|
1269 |
|
8fa58e
|
1270 |
if (!empty($part->filename)) { |
T |
1271 |
$table->add('title', Q(rcube_label('filename'))); |
|
1272 |
$table->add(null, Q($part->filename)); |
8dc048
|
1273 |
$table->add(null, '[' . html::a('?'.str_replace('_frame=', '_download=', $_SERVER['QUERY_STRING']), Q(rcube_label('download'))) . ']'); |
8fa58e
|
1274 |
} |
4e17e6
|
1275 |
|
8fa58e
|
1276 |
if (!empty($part->size)) { |
T |
1277 |
$table->add('title', Q(rcube_label('filesize'))); |
|
1278 |
$table->add(null, Q(show_bytes($part->size))); |
|
1279 |
} |
4e17e6
|
1280 |
|
8fa58e
|
1281 |
return $table->show($attrib); |
4e17e6
|
1282 |
} |
T |
1283 |
|
|
1284 |
|
|
1285 |
|
|
1286 |
function rcmail_message_part_frame($attrib) |
|
1287 |
{ |
|
1288 |
global $MESSAGE; |
|
1289 |
|
8fa58e
|
1290 |
$part = $MESSAGE->mime_parts[asciiwords(get_input_value('_part', RCUBE_INPUT_GPC))]; |
4e17e6
|
1291 |
$ctype_primary = strtolower($part->ctype_primary); |
T |
1292 |
|
95fcc3
|
1293 |
$attrib['src'] = './?' . str_replace('_frame=', ($ctype_primary=='text' ? '_show=' : '_preload='), $_SERVER['QUERY_STRING']); |
4e17e6
|
1294 |
|
95fcc3
|
1295 |
return html::iframe($attrib); |
4e17e6
|
1296 |
} |
T |
1297 |
|
|
1298 |
|
45f56c
|
1299 |
/** |
T |
1300 |
* clear message composing settings |
|
1301 |
*/ |
4e17e6
|
1302 |
function rcmail_compose_cleanup() |
T |
1303 |
{ |
|
1304 |
if (!isset($_SESSION['compose'])) |
|
1305 |
return; |
70d4b9
|
1306 |
|
cc97ea
|
1307 |
rcmail::get_instance()->plugins->exec_hook('cleanup_attachments',array()); |
4e17e6
|
1308 |
|
617b4f
|
1309 |
rcube_sess_unset('compose'); |
4e17e6
|
1310 |
} |
fba1f5
|
1311 |
|
T |
1312 |
|
|
1313 |
/** |
|
1314 |
* Send the given message compose object using the configured method |
|
1315 |
*/ |
2818f8
|
1316 |
function rcmail_deliver_message(&$message, $from, $mailto, &$smtp_error) |
fba1f5
|
1317 |
{ |
a22cb6
|
1318 |
global $CONFIG, $RCMAIL; |
fba1f5
|
1319 |
|
T |
1320 |
$msg_body = $message->get(); |
8fa58e
|
1321 |
$headers = $message->headers(); |
79aeb3
|
1322 |
|
fba1f5
|
1323 |
// send thru SMTP server using custom SMTP library |
e54f6c
|
1324 |
if ($CONFIG['smtp_server']) { |
fba1f5
|
1325 |
// generate list of recipients |
T |
1326 |
$a_recipients = array($mailto); |
|
1327 |
|
|
1328 |
if (strlen($headers['Cc'])) |
|
1329 |
$a_recipients[] = $headers['Cc']; |
|
1330 |
if (strlen($headers['Bcc'])) |
|
1331 |
$a_recipients[] = $headers['Bcc']; |
|
1332 |
|
|
1333 |
// clean Bcc from header for recipients |
|
1334 |
$send_headers = $headers; |
|
1335 |
unset($send_headers['Bcc']); |
7ec922
|
1336 |
// here too, it because txtHeaders() below use $message->_headers not only $send_headers |
A |
1337 |
unset($message->_headers['Bcc']); |
fba1f5
|
1338 |
|
T |
1339 |
// send message |
2c3d81
|
1340 |
if (!is_object($RCMAIL->smtp)) |
A |
1341 |
$RCMAIL->smtp_init(true); |
|
1342 |
|
|
1343 |
$sent = $RCMAIL->smtp->send_mail($from, $a_recipients, ($foo = $message->txtHeaders($send_headers, true)), $msg_body); |
|
1344 |
$smtp_response = $RCMAIL->smtp->get_response(); |
|
1345 |
$smtp_error = $RCMAIL->smtp->get_error(); |
fba1f5
|
1346 |
|
T |
1347 |
// log error |
|
1348 |
if (!$sent) |
|
1349 |
raise_error(array('code' => 800, 'type' => 'smtp', 'line' => __LINE__, 'file' => __FILE__, |
|
1350 |
'message' => "SMTP error: ".join("\n", $smtp_response)), TRUE, FALSE); |
e54f6c
|
1351 |
} |
fba1f5
|
1352 |
// send mail using PHP's mail() function |
e54f6c
|
1353 |
else { |
fba1f5
|
1354 |
// unset some headers because they will be added by the mail() function |
T |
1355 |
$headers_enc = $message->headers($headers); |
|
1356 |
$headers_php = $message->_headers; |
|
1357 |
unset($headers_php['To'], $headers_php['Subject']); |
|
1358 |
|
|
1359 |
// reset stored headers and overwrite |
|
1360 |
$message->_headers = array(); |
|
1361 |
$header_str = $message->txtHeaders($headers_php); |
5d1101
|
1362 |
|
A |
1363 |
// #1485779 |
|
1364 |
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
|
1365 |
if (preg_match_all('/<([^@]+@[^>]+)>/', $headers_enc['To'], $m)) { |
|
1366 |
$headers_enc['To'] = implode(', ', $m[1]); |
|
1367 |
} |
|
1368 |
} |
|
1369 |
|
fba1f5
|
1370 |
if (ini_get('safe_mode')) |
T |
1371 |
$sent = mail($headers_enc['To'], $headers_enc['Subject'], $msg_body, $header_str); |
|
1372 |
else |
|
1373 |
$sent = mail($headers_enc['To'], $headers_enc['Subject'], $msg_body, $header_str, "-f$from"); |
e54f6c
|
1374 |
} |
fba1f5
|
1375 |
|
e54f6c
|
1376 |
if ($sent) { |
T |
1377 |
$RCMAIL->plugins->exec_hook('message_sent', array('headers' => $headers, 'body' => $msg_body)); |
|
1378 |
|
79aeb3
|
1379 |
// remove MDN headers after sending |
ae8f19
|
1380 |
unset($headers['Return-Receipt-To'], $headers['Disposition-Notification-To']); |
79aeb3
|
1381 |
|
e54f6c
|
1382 |
if ($CONFIG['smtp_log']) { |
146977
|
1383 |
write_log('sendmail', sprintf("User %s [%s]; Message for %s; %s", |
e54f6c
|
1384 |
$RCMAIL->user->get_username(), |
T |
1385 |
$_SERVER['REMOTE_ADDR'], |
|
1386 |
$mailto, |
|
1387 |
!empty($smtp_response) ? join('; ', $smtp_response) : '')); |
|
1388 |
} |
79aeb3
|
1389 |
} |
fba1f5
|
1390 |
|
T |
1391 |
$message->_headers = array(); |
|
1392 |
$message->headers($headers); |
|
1393 |
|
|
1394 |
return $sent; |
|
1395 |
} |
f11541
|
1396 |
|
T |
1397 |
|
2818f8
|
1398 |
function rcmail_send_mdn($uid, &$smtp_error) |
0ea884
|
1399 |
{ |
83a763
|
1400 |
global $RCMAIL, $IMAP; |
8fa58e
|
1401 |
|
T |
1402 |
$message = new rcube_message($uid); |
0ea884
|
1403 |
|
5c771c
|
1404 |
if ($message->headers->mdn_to && !$message->headers->mdn_sent && |
A |
1405 |
($IMAP->check_permflag('MDNSENT') || $IMAP->check_permflag('*'))) |
0ea884
|
1406 |
{ |
83a763
|
1407 |
$identity = $RCMAIL->user->get_identity(); |
0ea884
|
1408 |
$sender = format_email_recipient($identity['email'], $identity['name']); |
8fa58e
|
1409 |
$recipient = array_shift($IMAP->decode_address_list($message->headers->mdn_to)); |
0ea884
|
1410 |
$mailto = $recipient['mailto']; |
T |
1411 |
|
83a763
|
1412 |
$compose = new rcube_mail_mime($RCMAIL->config->header_delimiter()); |
0ea884
|
1413 |
$compose->setParam(array( |
T |
1414 |
'text_encoding' => 'quoted-printable', |
|
1415 |
'html_encoding' => 'quoted-printable', |
|
1416 |
'head_encoding' => 'quoted-printable', |
|
1417 |
'head_charset' => RCMAIL_CHARSET, |
|
1418 |
'html_charset' => RCMAIL_CHARSET, |
|
1419 |
'text_charset' => RCMAIL_CHARSET, |
|
1420 |
)); |
|
1421 |
|
|
1422 |
// compose headers array |
|
1423 |
$headers = array( |
|
1424 |
'Date' => date('r'), |
|
1425 |
'From' => $sender, |
8fa58e
|
1426 |
'To' => $message->headers->mdn_to, |
T |
1427 |
'Subject' => rcube_label('receiptread') . ': ' . $message->subject, |
b48d9b
|
1428 |
'Message-ID' => sprintf('<%s@%s>', md5(uniqid('rcmail'.mt_rand(),true)), $RCMAIL->config->mail_domain($_SESSION['imap_host'])), |
0ea884
|
1429 |
'X-Sender' => $identity['email'], |
T |
1430 |
'Content-Type' => 'multipart/report; report-type=disposition-notification', |
|
1431 |
); |
|
1432 |
|
83a763
|
1433 |
if ($agent = $RCMAIL->config->get('useragent')) |
T |
1434 |
$headers['User-Agent'] = $agent; |
0ea884
|
1435 |
|
T |
1436 |
$body = rcube_label("yourmessage") . "\r\n\r\n" . |
8fa58e
|
1437 |
"\t" . rcube_label("to") . ': ' . rcube_imap::decode_mime_string($message->headers->to, $message->headers->charset) . "\r\n" . |
T |
1438 |
"\t" . rcube_label("subject") . ': ' . $message->subject . "\r\n" . |
83a763
|
1439 |
"\t" . rcube_label("sent") . ': ' . format_date($message->headers->date, $RCMAIL->config->get('date_long')) . "\r\n" . |
0ea884
|
1440 |
"\r\n" . rcube_label("receiptnote") . "\r\n"; |
T |
1441 |
|
83a763
|
1442 |
$ua = $RCMAIL->config->get('useragent', "RoundCube Webmail (Version ".RCMAIL_VERSION.")"); |
0ea884
|
1443 |
$report = "Reporting-UA: $ua\r\n"; |
T |
1444 |
|
8fa58e
|
1445 |
if ($message->headers->to) |
T |
1446 |
$report .= "Original-Recipient: {$message->headers->to}\r\n"; |
0ea884
|
1447 |
|
T |
1448 |
$report .= "Final-Recipient: rfc822; {$identity['email']}\r\n" . |
8fa58e
|
1449 |
"Original-Message-ID: {$message->headers->messageID}\r\n" . |
0ea884
|
1450 |
"Disposition: manual-action/MDN-sent-manually; displayed\r\n"; |
T |
1451 |
|
8fa58e
|
1452 |
$compose->headers($headers); |
7145e0
|
1453 |
$compose->setTXTBody(rc_wordwrap($body, 75, "\r\n")); |
0ea884
|
1454 |
$compose->addAttachment($report, 'message/disposition-notification', 'MDNPart2.txt', false, '7bit', 'inline'); |
T |
1455 |
|
2818f8
|
1456 |
$sent = rcmail_deliver_message($compose, $identity['email'], $mailto, $smtp_error); |
0ea884
|
1457 |
|
T |
1458 |
if ($sent) |
|
1459 |
{ |
8fa58e
|
1460 |
$IMAP->set_flag($message->uid, 'MDNSENT'); |
0ea884
|
1461 |
return true; |
T |
1462 |
} |
|
1463 |
} |
|
1464 |
|
|
1465 |
return false; |
|
1466 |
} |
|
1467 |
|
|
1468 |
|
e538b3
|
1469 |
function rcmail_search_filter($attrib) |
A |
1470 |
{ |
119cd1
|
1471 |
global $OUTPUT, $CONFIG; |
e538b3
|
1472 |
|
A |
1473 |
if (!strlen($attrib['id'])) |
|
1474 |
$attrib['id'] = 'rcmlistfilter'; |
|
1475 |
|
|
1476 |
$attrib['onchange'] = JS_OBJECT_NAME.'.filter_mailbox(this.value)'; |
|
1477 |
|
|
1478 |
/* |
|
1479 |
RFC3501 (6.4.4): 'ALL', 'RECENT', |
|
1480 |
'ANSWERED', 'DELETED', 'FLAGGED', 'SEEN', |
|
1481 |
'UNANSWERED', 'UNDELETED', 'UNFLAGGED', 'UNSEEN', |
|
1482 |
'NEW', // = (RECENT UNSEEN) |
|
1483 |
'OLD' // = NOT RECENT |
|
1484 |
*/ |
|
1485 |
|
|
1486 |
$select_filter = new html_select($attrib); |
|
1487 |
$select_filter->add(rcube_label('all'), 'ALL'); |
|
1488 |
$select_filter->add(rcube_label('unread'), 'UNSEEN'); |
|
1489 |
$select_filter->add(rcube_label('flagged'), 'FLAGGED'); |
|
1490 |
$select_filter->add(rcube_label('unanswered'), 'UNANSWERED'); |
119cd1
|
1491 |
if (!$CONFIG['skip_deleted']) |
A |
1492 |
$select_filter->add(rcube_label('deleted'), 'DELETED'); |
e538b3
|
1493 |
|
A |
1494 |
$out = $select_filter->show($_SESSION['search_filter']); |
|
1495 |
|
|
1496 |
$OUTPUT->add_gui_object('search_filter', $attrib['id']); |
|
1497 |
|
|
1498 |
return $out; |
|
1499 |
} |
|
1500 |
|
f11541
|
1501 |
// register UI objects |
T |
1502 |
$OUTPUT->add_handlers(array( |
|
1503 |
'mailboxlist' => 'rcmail_mailbox_list', |
|
1504 |
'messages' => 'rcmail_message_list', |
|
1505 |
'messagecountdisplay' => 'rcmail_messagecount_display', |
|
1506 |
'quotadisplay' => 'rcmail_quota_display', |
ac5d15
|
1507 |
'mailboxname' => 'rcmail_mailbox_name_display', |
f11541
|
1508 |
'messageheaders' => 'rcmail_message_headers', |
T |
1509 |
'messagebody' => 'rcmail_message_body', |
|
1510 |
'messagecontentframe' => 'rcmail_messagecontent_frame', |
|
1511 |
'messagepartframe' => 'rcmail_message_part_frame', |
|
1512 |
'messagepartcontrols' => 'rcmail_message_part_controls', |
e538b3
|
1513 |
'searchfilter' => 'rcmail_search_filter', |
47124c
|
1514 |
'searchform' => array($OUTPUT, 'search_form'), |
f11541
|
1515 |
)); |
T |
1516 |
|
93be5b
|
1517 |
?> |