commit | author | age
|
4e17e6
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| program/steps/mail/compose.inc | |
|
6 |
| | |
|
7 |
| This file is part of the RoundCube Webmail client | |
|
8 |
| Copyright (C) 2005, RoundCube Dev. - Switzerland | |
30233b
|
9 |
| Licensed under the GNU GPL | |
4e17e6
|
10 |
| | |
T |
11 |
| PURPOSE: | |
|
12 |
| Compose a new mail message with all headers and attachments | |
|
13 |
| | |
|
14 |
+-----------------------------------------------------------------------+ |
|
15 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
16 |
+-----------------------------------------------------------------------+ |
|
17 |
|
|
18 |
$Id$ |
|
19 |
|
|
20 |
*/ |
|
21 |
|
|
22 |
|
|
23 |
require_once('Mail/mimeDecode.php'); |
|
24 |
|
a894ba
|
25 |
// remove an attachment |
aade7b
|
26 |
if ($_action=='remove-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_GET['_file'], $regs)) |
a894ba
|
27 |
{ |
aade7b
|
28 |
$id = $regs[1]; |
T |
29 |
if (is_array($_SESSION['compose']['attachments'][$id])) |
|
30 |
{ |
|
31 |
@unlink($_SESSION['compose']['attachments'][$id]['path']); |
|
32 |
$_SESSION['compose']['attachments'][$id] = NULL; |
|
33 |
$commands = sprintf("parent.%s.remove_from_attachment_list('rcmfile%d');\n", $JS_OBJECT_NAME, $id); |
|
34 |
rcube_remote_response($commands); |
|
35 |
exit; |
|
36 |
} |
a894ba
|
37 |
} |
aade7b
|
38 |
|
f0f98f
|
39 |
|
S |
40 |
$MESSAGE_FORM = NULL; |
|
41 |
$REPLY_MESSAGE = NULL; |
|
42 |
$FORWARD_MESSAGE = NULL; |
|
43 |
$DRAFT_MESSAGE = NULL; |
|
44 |
|
|
45 |
// nothing below is called during message composition, only at "new/forward/reply/draft" initialization |
|
46 |
// since there are many ways to leave the compose page improperly, it seems necessary to clean-up an old |
|
47 |
// compose when a "new/forward/reply/draft" is called - otherwise the old session attachments will appear |
|
48 |
|
|
49 |
rcmail_compose_cleanup(); |
|
50 |
$_SESSION['compose'] = array('id' => uniqid(rand())); |
4e17e6
|
51 |
|
10a699
|
52 |
// add some labels to client |
41fa0b
|
53 |
rcube_add_label('nosubject', 'norecipientwarning', 'nosubjectwarning', 'nobodywarning', 'notsentwarning', 'savingmessage', 'sendingmessage', 'messagesaved'); |
10a699
|
54 |
|
T |
55 |
|
1966c5
|
56 |
if ($_GET['_reply_uid'] || $_GET['_forward_uid'] || $_GET['_draft_uid']) |
4e17e6
|
57 |
{ |
1966c5
|
58 |
$msg_uid = ($_GET['_reply_uid'] ? $_GET['_reply_uid'] : ($_GET['_forward_uid'] ? $_GET['_forward_uid'] : $_GET['_draft_uid'])); |
4e17e6
|
59 |
|
T |
60 |
// similar as in program/steps/mail/show.inc |
|
61 |
$MESSAGE = array(); |
|
62 |
$MESSAGE['headers'] = $IMAP->get_headers($msg_uid); |
|
63 |
|
|
64 |
$MESSAGE['source'] = rcmail_message_source($msg_uid); |
|
65 |
|
|
66 |
$mmd = new Mail_mimeDecode($MESSAGE['source']); |
|
67 |
$MESSAGE['structure'] = $mmd->decode(array('include_bodies' => TRUE, |
|
68 |
'decode_headers' => TRUE, |
|
69 |
'decode_bodies' => FALSE)); |
583f1c
|
70 |
|
4e17e6
|
71 |
$MESSAGE['subject'] = $IMAP->decode_header($MESSAGE['headers']->subject); |
T |
72 |
$MESSAGE['parts'] = $mmd->getMimeNumbers($MESSAGE['structure']); |
1966c5
|
73 |
|
4e17e6
|
74 |
if ($_GET['_reply_uid']) |
T |
75 |
{ |
583f1c
|
76 |
$REPLY_MESSAGE = &$MESSAGE; |
4e17e6
|
77 |
$_SESSION['compose']['reply_uid'] = $_GET['_reply_uid']; |
T |
78 |
$_SESSION['compose']['reply_msgid'] = $REPLY_MESSAGE['headers']->messageID; |
479399
|
79 |
$_SESSION['compose']['references'] = $REPLY_MESSAGE['headers']->reference; |
f88d41
|
80 |
$_SESSION['compose']['references'] .= !empty($REPLY_MESSAGE['headers']->reference) ? ' ' : ''; |
T |
81 |
$_SESSION['compose']['references'] .= $REPLY_MESSAGE['headers']->messageID; |
583f1c
|
82 |
|
T |
83 |
if ($_GET['_all']) |
|
84 |
$REPLY_MESSAGE['reply_all'] = 1; |
1966c5
|
85 |
|
4e17e6
|
86 |
} |
1966c5
|
87 |
else if ($_GET['_forward_uid']) |
4e17e6
|
88 |
{ |
T |
89 |
$FORWARD_MESSAGE = $MESSAGE; |
|
90 |
$_SESSION['compose']['forward_uid'] = $_GET['_forward_uid']; |
|
91 |
} |
1966c5
|
92 |
else |
S |
93 |
{ |
|
94 |
$DRAFT_MESSAGE = $MESSAGE; |
|
95 |
$_SESSION['compose']['draft_uid'] = $_GET['_draft_uid']; |
|
96 |
} |
|
97 |
|
4e17e6
|
98 |
} |
T |
99 |
|
|
100 |
/****** compose mode functions ********/ |
|
101 |
|
|
102 |
|
|
103 |
function rcmail_compose_headers($attrib) |
|
104 |
{ |
1966c5
|
105 |
global $IMAP, $REPLY_MESSAGE, $DRAFT_MESSAGE, $DB; |
583f1c
|
106 |
static $sa_recipients = array(); |
4e17e6
|
107 |
|
T |
108 |
list($form_start, $form_end) = get_form_tags($attrib); |
|
109 |
|
|
110 |
$out = ''; |
|
111 |
$part = strtolower($attrib['part']); |
|
112 |
|
|
113 |
switch ($part) |
|
114 |
{ |
|
115 |
case 'from': |
1cded8
|
116 |
return rcmail_compose_header_from($attrib); |
4e17e6
|
117 |
|
T |
118 |
case 'to': |
|
119 |
$fname = '_to'; |
|
120 |
$header = 'to'; |
1cded8
|
121 |
|
4e17e6
|
122 |
// we have contact id's as get parameters |
4fd971
|
123 |
if (!empty($_GET['_to']) && preg_match('/^[0-9]+(,[0-9]+)*$/', $_GET['_to'])) |
4e17e6
|
124 |
{ |
T |
125 |
$a_recipients = array(); |
d7cb77
|
126 |
$sql_result = $DB->query("SELECT name, email |
1cded8
|
127 |
FROM ".get_table_name('contacts')." |
T |
128 |
WHERE user_id=? |
|
129 |
AND del<>1 |
d7cb77
|
130 |
AND contact_id IN (".$_GET['_to'].")", |
S |
131 |
$_SESSION['user_id']); |
4e17e6
|
132 |
|
T |
133 |
while ($sql_arr = $DB->fetch_assoc($sql_result)) |
|
134 |
$a_recipients[] = format_email_recipient($sql_arr['email'], $sql_arr['name']); |
|
135 |
|
|
136 |
if (sizeof($a_recipients)) |
|
137 |
$fvalue = join(', ', $a_recipients); |
|
138 |
} |
597170
|
139 |
else if (!empty($_GET['_to'])) |
4e17e6
|
140 |
$fvalue = $_GET['_to']; |
T |
141 |
|
|
142 |
case 'cc': |
|
143 |
if (!$fname) |
|
144 |
{ |
|
145 |
$fname = '_cc'; |
583f1c
|
146 |
$header = 'cc'; |
4e17e6
|
147 |
} |
T |
148 |
case 'bcc': |
|
149 |
if (!$fname) |
|
150 |
$fname = '_bcc'; |
|
151 |
|
317219
|
152 |
$allow_attrib = array('id', 'class', 'style', 'cols', 'rows', 'wrap', 'tabindex'); |
4e17e6
|
153 |
$field_type = 'textarea'; |
T |
154 |
break; |
|
155 |
|
|
156 |
case 'replyto': |
|
157 |
case 'reply-to': |
|
158 |
$fname = '_replyto'; |
317219
|
159 |
$allow_attrib = array('id', 'class', 'style', 'size', 'tabindex'); |
4e17e6
|
160 |
$field_type = 'textfield'; |
T |
161 |
break; |
|
162 |
|
|
163 |
} |
1966c5
|
164 |
|
597170
|
165 |
if ($fname && !empty($_POST[$fname])) |
01c86f
|
166 |
$fvalue = get_input_value($fname, RCUBE_INPUT_POST, TRUE); |
4e17e6
|
167 |
else if ($header && is_object($REPLY_MESSAGE['headers'])) |
T |
168 |
{ |
|
169 |
// get recipent address(es) out of the message headers |
|
170 |
if ($header=='to' && $REPLY_MESSAGE['headers']->replyto) |
|
171 |
$fvalue = $IMAP->decode_header($REPLY_MESSAGE['headers']->replyto); |
58e360
|
172 |
|
4e17e6
|
173 |
else if ($header=='to' && $REPLY_MESSAGE['headers']->from) |
T |
174 |
$fvalue = $IMAP->decode_header($REPLY_MESSAGE['headers']->from); |
58e360
|
175 |
|
583f1c
|
176 |
// add recipent of original message if reply to all |
T |
177 |
else if ($header=='cc' && $REPLY_MESSAGE['reply_all']) |
|
178 |
{ |
|
179 |
if ($IMAP->decode_header($REPLY_MESSAGE['headers']->to)) |
|
180 |
$fvalue .= $IMAP->decode_header($REPLY_MESSAGE['headers']->to); |
|
181 |
|
|
182 |
if ($IMAP->decode_header($REPLY_MESSAGE['headers']->cc)) |
|
183 |
{ |
|
184 |
if($fvalue) |
|
185 |
$fvalue .= ', '; |
|
186 |
|
|
187 |
$fvalue .= $IMAP->decode_header($REPLY_MESSAGE['headers']->cc); |
|
188 |
} |
|
189 |
} |
|
190 |
|
4e17e6
|
191 |
// split recipients and put them back together in a unique way |
583f1c
|
192 |
if (!empty($fvalue)) |
T |
193 |
{ |
|
194 |
$to_addresses = $IMAP->decode_address_list($fvalue); |
|
195 |
$fvalue = ''; |
|
196 |
foreach ($to_addresses as $addr_part) |
|
197 |
{ |
58e360
|
198 |
if (!in_array($addr_part['mailto'], $sa_recipients) && (!$REPLY_MESSAGE['FROM'] || !in_array($addr_part['mailto'], $REPLY_MESSAGE['FROM']))) |
583f1c
|
199 |
{ |
T |
200 |
$fvalue .= (strlen($fvalue) ? ', ':'').$addr_part['string']; |
|
201 |
$sa_recipients[] = $addr_part['mailto']; |
|
202 |
} |
|
203 |
} |
|
204 |
} |
4e17e6
|
205 |
} |
1966c5
|
206 |
else if ($header && is_object($DRAFT_MESSAGE['headers'])) |
S |
207 |
{ |
|
208 |
// get drafted headers |
|
209 |
if ($header=='to' && $DRAFT_MESSAGE['headers']->to) |
|
210 |
$fvalue = $IMAP->decode_header($DRAFT_MESSAGE['headers']->to); |
|
211 |
|
|
212 |
if ($header=='cc' && $DRAFT_MESSAGE['headers']->cc) |
|
213 |
$fvalue = $IMAP->decode_header($DRAFT_MESSAGE['headers']->cc); |
|
214 |
|
|
215 |
if ($header=='bcc' && $DRAFT_MESSAGE['headers']->bcc) |
|
216 |
$fvalue = $IMAP->decode_header($DRAFT_MESSAGE['headers']->bcc); |
|
217 |
|
|
218 |
} |
583f1c
|
219 |
|
4e17e6
|
220 |
|
T |
221 |
if ($fname && $field_type) |
|
222 |
{ |
|
223 |
// pass the following attributes to the form class |
|
224 |
$field_attrib = array('name' => $fname); |
|
225 |
foreach ($attrib as $attr => $value) |
|
226 |
if (in_array($attr, $allow_attrib)) |
|
227 |
$field_attrib[$attr] = $value; |
|
228 |
|
|
229 |
// create teaxtarea object |
|
230 |
$input = new $field_type($field_attrib); |
|
231 |
$out = $input->show($fvalue); |
|
232 |
} |
|
233 |
|
|
234 |
if ($form_start) |
|
235 |
$out = $form_start.$out; |
1966c5
|
236 |
|
4e17e6
|
237 |
return $out; |
T |
238 |
} |
|
239 |
|
|
240 |
|
1cded8
|
241 |
|
T |
242 |
function rcmail_compose_header_from($attrib) |
4e17e6
|
243 |
{ |
1966c5
|
244 |
global $IMAP, $REPLY_MESSAGE, $DRAFT_MESSAGE, $DB, $OUTPUT, $JS_OBJECT_NAME; |
1cded8
|
245 |
|
T |
246 |
// pass the following attributes to the form class |
|
247 |
$field_attrib = array('name' => '_from'); |
|
248 |
foreach ($attrib as $attr => $value) |
|
249 |
if (in_array($attr, array('id', 'class', 'style', 'size', 'tabindex'))) |
|
250 |
$field_attrib[$attr] = $value; |
4e17e6
|
251 |
|
1cded8
|
252 |
// extract all recipients of the reply-message |
T |
253 |
$a_recipients = array(); |
|
254 |
if ($REPLY_MESSAGE && is_object($REPLY_MESSAGE['headers'])) |
|
255 |
{ |
58e360
|
256 |
$REPLY_MESSAGE['FROM'] = array(); |
T |
257 |
|
1cded8
|
258 |
$a_to = $IMAP->decode_address_list($REPLY_MESSAGE['headers']->to); |
T |
259 |
foreach ($a_to as $addr) |
|
260 |
{ |
|
261 |
if (!empty($addr['mailto'])) |
|
262 |
$a_recipients[] = $addr['mailto']; |
|
263 |
} |
4e17e6
|
264 |
|
1cded8
|
265 |
if (!empty($REPLY_MESSAGE['headers']->cc)) |
T |
266 |
{ |
|
267 |
$a_cc = $IMAP->decode_address_list($REPLY_MESSAGE['headers']->cc); |
|
268 |
foreach ($a_cc as $addr) |
|
269 |
{ |
|
270 |
if (!empty($addr['mailto'])) |
|
271 |
$a_recipients[] = $addr['mailto']; |
|
272 |
} |
|
273 |
} |
|
274 |
} |
4e17e6
|
275 |
|
1cded8
|
276 |
// get this user's identities |
T |
277 |
$sql_result = $DB->query("SELECT identity_id, name, email, signature |
|
278 |
FROM ".get_table_name('identities')." |
|
279 |
WHERE user_id=? |
|
280 |
AND del<>1 |
|
281 |
ORDER BY ".$DB->quoteIdentifier('standard')." DESC, name ASC", |
|
282 |
$_SESSION['user_id']); |
|
283 |
|
|
284 |
if ($DB->num_rows($sql_result)) |
|
285 |
{ |
|
286 |
$from_id = 0; |
|
287 |
$a_signatures = array(); |
|
288 |
|
|
289 |
$field_attrib['onchange'] = "$JS_OBJECT_NAME.change_identity(this)"; |
|
290 |
$select_from = new select($field_attrib); |
|
291 |
|
|
292 |
while ($sql_arr = $DB->fetch_assoc($sql_result)) |
|
293 |
{ |
|
294 |
$select_from->add(format_email_recipient($sql_arr['email'], $sql_arr['name']), $sql_arr['identity_id']); |
4e17e6
|
295 |
|
1cded8
|
296 |
// add signature to array |
T |
297 |
if (!empty($sql_arr['signature'])) |
|
298 |
$a_signatures[$sql_arr['identity_id']] = $sql_arr['signature']; |
|
299 |
|
|
300 |
// set identity if it's one of the reply-message recipients |
|
301 |
if (in_array($sql_arr['email'], $a_recipients)) |
|
302 |
$from_id = $sql_arr['identity_id']; |
58e360
|
303 |
|
T |
304 |
if ($REPLY_MESSAGE && is_array($REPLY_MESSAGE['FROM'])) |
|
305 |
$REPLY_MESSAGE['FROM'][] = $sql_arr['email']; |
1966c5
|
306 |
|
S |
307 |
if (strstr($DRAFT_MESSAGE['headers']->from,$sql_arr['email'])) |
|
308 |
$from_id = $sql_arr['identity_id']; |
|
309 |
|
1cded8
|
310 |
} |
4e17e6
|
311 |
|
1cded8
|
312 |
// overwrite identity selection with post parameter |
T |
313 |
if (isset($_POST['_from'])) |
|
314 |
$from_id = $_POST['_from']; |
4e17e6
|
315 |
|
1cded8
|
316 |
$out = $select_from->show($from_id); |
T |
317 |
|
4e17e6
|
318 |
|
1cded8
|
319 |
// add signatures to client |
T |
320 |
$OUTPUT->add_script(sprintf("%s.set_env('signatures', %s);", $JS_OBJECT_NAME, array2js($a_signatures))); |
|
321 |
} |
|
322 |
else |
|
323 |
{ |
|
324 |
$input_from = new textfield($field_attrib); |
|
325 |
$out = $input_from->show($_POST['_from']); |
|
326 |
} |
1966c5
|
327 |
|
1cded8
|
328 |
if ($form_start) |
T |
329 |
$out = $form_start.$out; |
4e17e6
|
330 |
|
1cded8
|
331 |
return $out; |
4e17e6
|
332 |
} |
T |
333 |
|
1cded8
|
334 |
|
4e17e6
|
335 |
|
T |
336 |
function rcmail_compose_body($attrib) |
|
337 |
{ |
1966c5
|
338 |
global $CONFIG, $OUTPUT, $REPLY_MESSAGE, $FORWARD_MESSAGE, $DRAFT_MESSAGE, $JS_OBJECT_NAME; |
4e17e6
|
339 |
|
T |
340 |
list($form_start, $form_end) = get_form_tags($attrib); |
|
341 |
unset($attrib['form']); |
dd53e2
|
342 |
|
T |
343 |
if (empty($attrib['id'])) |
|
344 |
$attrib['id'] = 'rcmComposeMessage'; |
4e17e6
|
345 |
|
T |
346 |
$attrib['name'] = '_message'; |
|
347 |
$textarea = new textarea($attrib); |
|
348 |
|
|
349 |
$body = ''; |
|
350 |
|
|
351 |
// use posted message body |
597170
|
352 |
if (!empty($_POST['_message'])) |
ea7c46
|
353 |
$body = get_input_value('_message', RCUBE_INPUT_POST, TRUE); |
4e17e6
|
354 |
|
T |
355 |
// compose reply-body |
|
356 |
else if (is_array($REPLY_MESSAGE['parts'])) |
|
357 |
{ |
|
358 |
$body = rcmail_first_text_part($REPLY_MESSAGE['parts']); |
|
359 |
if (strlen($body)) |
|
360 |
$body = rcmail_create_reply_body($body); |
|
361 |
} |
|
362 |
|
|
363 |
// forward message body inline |
|
364 |
else if (is_array($FORWARD_MESSAGE['parts'])) |
|
365 |
{ |
|
366 |
$body = rcmail_first_text_part($FORWARD_MESSAGE['parts']); |
|
367 |
if (strlen($body)) |
|
368 |
$body = rcmail_create_forward_body($body); |
|
369 |
} |
1966c5
|
370 |
|
S |
371 |
// forward message body inline |
|
372 |
else if (is_array($DRAFT_MESSAGE['parts'])) |
|
373 |
{ |
|
374 |
$body = rcmail_first_text_part($DRAFT_MESSAGE['parts']); |
|
375 |
if (strlen($body)) |
|
376 |
$body = rcmail_create_draft_body($body); |
|
377 |
} |
4e17e6
|
378 |
|
T |
379 |
$out = $form_start ? "$form_start\n" : ''; |
1966c5
|
380 |
|
f0f98f
|
381 |
$saveid = new hiddenfield(array('name' => '_draft_saveid', 'value' => str_replace(array('<','>'),"",$DRAFT_MESSAGE['headers']->messageID) )); |
S |
382 |
$out .= $saveid->show(); |
1966c5
|
383 |
|
S |
384 |
$drafttoggle = new hiddenfield(array('name' => '_draft', 'value' => 'yes')); |
|
385 |
$out .= $drafttoggle->show(); |
|
386 |
|
4e17e6
|
387 |
$out .= $textarea->show($body); |
T |
388 |
$out .= $form_end ? "\n$form_end" : ''; |
dd53e2
|
389 |
|
T |
390 |
// include GoogieSpell |
ed5d29
|
391 |
if (!empty($CONFIG['enable_spellcheck'])) |
T |
392 |
{ |
|
393 |
$OUTPUT->include_script('googiespell.js'); |
|
394 |
$OUTPUT->add_script(sprintf("var googie = new GoogieSpell('\$__skin_path/images/googiespell/','%s&_action=spell&lang=');\n". |
|
395 |
"googie.lang_chck_spell = \"%s\";\n". |
|
396 |
"googie.lang_rsm_edt = \"%s\";\n". |
|
397 |
"googie.lang_close = \"%s\";\n". |
|
398 |
"googie.lang_revert = \"%s\";\n". |
|
399 |
"googie.lang_no_error_found = \"%s\";\n". |
|
400 |
"googie.decorateTextarea('%s');\n". |
|
401 |
"%s.set_env('spellcheck', googie);", |
|
402 |
$GLOBALS['COMM_PATH'], |
|
403 |
rep_specialchars_output(rcube_label('checkspelling')), |
|
404 |
rep_specialchars_output(rcube_label('resumeediting')), |
|
405 |
rep_specialchars_output(rcube_label('close')), |
|
406 |
rep_specialchars_output(rcube_label('revertto')), |
|
407 |
rep_specialchars_output(rcube_label('nospellerrors')), |
|
408 |
$attrib['id'], |
|
409 |
$JS_OBJECT_NAME), 'foot'); |
|
410 |
|
|
411 |
rcube_add_label('checking'); |
|
412 |
} |
f0f98f
|
413 |
|
41fa0b
|
414 |
$out .= "\n".'<iframe name="savetarget" src="program/blank.gif" style="width:0;height:0;visibility:hidden;"></iframe>'; |
T |
415 |
|
4e17e6
|
416 |
return $out; |
T |
417 |
} |
|
418 |
|
|
419 |
|
|
420 |
function rcmail_create_reply_body($body) |
|
421 |
{ |
|
422 |
global $IMAP, $REPLY_MESSAGE; |
|
423 |
|
|
424 |
// soft-wrap message first |
|
425 |
$body = wordwrap($body, 75); |
|
426 |
|
|
427 |
// split body into single lines |
|
428 |
$a_lines = preg_split('/\r?\n/', $body); |
|
429 |
|
|
430 |
// add > to each line |
|
431 |
for($n=0; $n<sizeof($a_lines); $n++) |
|
432 |
{ |
|
433 |
if (strpos($a_lines[$n], '>')===0) |
|
434 |
$a_lines[$n] = '>'.$a_lines[$n]; |
|
435 |
else |
|
436 |
$a_lines[$n] = '> '.$a_lines[$n]; |
|
437 |
} |
|
438 |
|
|
439 |
$body = join("\n", $a_lines); |
|
440 |
|
|
441 |
// add title line |
|
442 |
$pefix = sprintf("\n\n\nOn %s, %s wrote:\n", |
|
443 |
$REPLY_MESSAGE['headers']->date, |
|
444 |
$IMAP->decode_header($REPLY_MESSAGE['headers']->from)); |
1cded8
|
445 |
|
T |
446 |
|
|
447 |
// try to remove the signature |
749b07
|
448 |
if ($sp = strrpos($body, '-- ')) |
1cded8
|
449 |
{ |
T |
450 |
if ($body{$sp+3}==' ' || $body{$sp+3}=="\n" || $body{$sp+3}=="\r") |
|
451 |
$body = substr($body, 0, $sp-1); |
|
452 |
} |
4e17e6
|
453 |
|
T |
454 |
return $pefix.$body; |
|
455 |
} |
|
456 |
|
|
457 |
|
|
458 |
function rcmail_create_forward_body($body) |
|
459 |
{ |
|
460 |
global $IMAP, $FORWARD_MESSAGE; |
|
461 |
|
|
462 |
// soft-wrap message first |
|
463 |
$body = wordwrap($body, 80); |
|
464 |
|
|
465 |
$prefix = sprintf("\n\n\n-------- Original Message --------\nSubject: %s\nDate: %s\nFrom: %s\nTo: %s\n\n", |
|
466 |
$FORWARD_MESSAGE['subject'], |
|
467 |
$FORWARD_MESSAGE['headers']->date, |
|
468 |
$IMAP->decode_header($FORWARD_MESSAGE['headers']->from), |
|
469 |
$IMAP->decode_header($FORWARD_MESSAGE['headers']->to)); |
|
470 |
|
597170
|
471 |
// add attachments |
T |
472 |
if (!isset($_SESSION['compose']['forward_attachments']) && is_array($FORWARD_MESSAGE['parts']) && sizeof($FORWARD_MESSAGE['parts'])>1) |
|
473 |
{ |
|
474 |
$temp_dir = rcmail_create_compose_tempdir(); |
|
475 |
|
|
476 |
if (!is_array($_SESSION['compose']['attachments'])) |
|
477 |
$_SESSION['compose']['attachments'] = array(); |
|
478 |
|
|
479 |
foreach ($FORWARD_MESSAGE['parts'] as $part) |
|
480 |
{ |
a43e0c
|
481 |
if ($part->disposition=='attachment' || $part->disposition=='inline' || $part->headers['content-id'] || |
S |
482 |
(empty($part->disposition) && ($part->d_parameters['filename'] || $part->ctype_parameters['name']))) |
aade7b
|
483 |
{ |
a43e0c
|
484 |
$tmp_path = tempnam($temp_dir, 'rcmAttmnt'); |
S |
485 |
if ($fp = fopen($tmp_path, 'w')) |
|
486 |
{ |
|
487 |
fwrite($fp, $IMAP->mime_decode($part->body, $part->headers['content-transfer-encoding'])); |
|
488 |
fclose($fp); |
597170
|
489 |
|
a43e0c
|
490 |
if ($part->d_parameters['filename']) |
S |
491 |
$_SESSION['compose']['attachments'][] = array('name' => $part->d_parameters['filename'], |
|
492 |
'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary, |
|
493 |
'path' => $tmp_path); |
|
494 |
|
|
495 |
else if ($part->ctype_parameters['name']) |
|
496 |
$_SESSION['compose']['attachments'][] = array('name' => $part->ctype_parameters['name'], |
|
497 |
'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary, |
|
498 |
'path' => $tmp_path); |
f8d0a5
|
499 |
|
S |
500 |
else if ($part->headers['content-description']) |
|
501 |
$_SESSION['compose']['attachments'][] = array('name' => $part->headers['content-description'], |
|
502 |
'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary, |
|
503 |
'path' => $tmp_path); |
a43e0c
|
504 |
} |
S |
505 |
} |
597170
|
506 |
} |
T |
507 |
|
|
508 |
$_SESSION['compose']['forward_attachments'] = TRUE; |
|
509 |
} |
|
510 |
|
4e17e6
|
511 |
return $prefix.$body; |
T |
512 |
} |
|
513 |
|
1966c5
|
514 |
function rcmail_create_draft_body($body) |
S |
515 |
{ |
|
516 |
global $IMAP, $DRAFT_MESSAGE; |
|
517 |
|
|
518 |
// add attachments |
|
519 |
if (!isset($_SESSION['compose']['forward_attachments']) && is_array($DRAFT_MESSAGE['parts']) && sizeof($DRAFT_MESSAGE['parts'])>1) |
|
520 |
{ |
|
521 |
$temp_dir = rcmail_create_compose_tempdir(); |
|
522 |
|
|
523 |
if (!is_array($_SESSION['compose']['attachments'])) |
|
524 |
$_SESSION['compose']['attachments'] = array(); |
|
525 |
|
|
526 |
foreach ($DRAFT_MESSAGE['parts'] as $part) |
|
527 |
{ |
|
528 |
if ($part->disposition=='attachment' || $part->disposition=='inline' || $part->headers['content-id'] || |
|
529 |
(empty($part->disposition) && ($part->d_parameters['filename'] || $part->ctype_parameters['name']))) |
|
530 |
{ |
|
531 |
$tmp_path = tempnam($temp_dir, 'rcmAttmnt'); |
|
532 |
if ($fp = fopen($tmp_path, 'w')) |
|
533 |
{ |
|
534 |
fwrite($fp, $IMAP->mime_decode($part->body, $part->headers['content-transfer-encoding'])); |
|
535 |
fclose($fp); |
|
536 |
|
|
537 |
if ($part->d_parameters['filename']) |
|
538 |
$_SESSION['compose']['attachments'][] = array('name' => $part->d_parameters['filename'], |
|
539 |
'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary, |
|
540 |
'path' => $tmp_path); |
|
541 |
|
|
542 |
else if ($part->ctype_parameters['name']) |
|
543 |
$_SESSION['compose']['attachments'][] = array('name' => $part->ctype_parameters['name'], |
|
544 |
'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary, |
|
545 |
'path' => $tmp_path); |
|
546 |
|
|
547 |
else if ($part->headers['content-description']) |
|
548 |
$_SESSION['compose']['attachments'][] = array('name' => $part->headers['content-description'], |
|
549 |
'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary, |
|
550 |
'path' => $tmp_path); |
|
551 |
} |
|
552 |
} |
|
553 |
} |
|
554 |
|
|
555 |
$_SESSION['compose']['forward_attachments'] = TRUE; |
|
556 |
} |
|
557 |
|
|
558 |
return $body; |
|
559 |
} |
4e17e6
|
560 |
|
T |
561 |
|
|
562 |
function rcmail_compose_subject($attrib) |
|
563 |
{ |
1966c5
|
564 |
global $CONFIG, $REPLY_MESSAGE, $FORWARD_MESSAGE, $DRAFT_MESSAGE; |
4e17e6
|
565 |
|
T |
566 |
list($form_start, $form_end) = get_form_tags($attrib); |
|
567 |
unset($attrib['form']); |
|
568 |
|
|
569 |
$attrib['name'] = '_subject'; |
|
570 |
$textfield = new textfield($attrib); |
|
571 |
|
|
572 |
$subject = ''; |
|
573 |
|
|
574 |
// use subject from post |
597170
|
575 |
if (isset($_POST['_subject'])) |
01c86f
|
576 |
$subject = get_input_value('_subject', RCUBE_INPUT_POST, TRUE); |
4e17e6
|
577 |
|
T |
578 |
// create a reply-subject |
|
579 |
else if (isset($REPLY_MESSAGE['subject'])) |
520c36
|
580 |
{ |
09941e
|
581 |
if (eregi('^re:', $REPLY_MESSAGE['subject'])) |
520c36
|
582 |
$subject = $REPLY_MESSAGE['subject']; |
T |
583 |
else |
|
584 |
$subject = 'Re: '.$REPLY_MESSAGE['subject']; |
|
585 |
} |
4e17e6
|
586 |
|
T |
587 |
// create a forward-subject |
|
588 |
else if (isset($FORWARD_MESSAGE['subject'])) |
09941e
|
589 |
{ |
T |
590 |
if (eregi('^fwd:', $REPLY_MESSAGE['subject'])) |
|
591 |
$subject = $FORWARD_MESSAGE['subject']; |
|
592 |
else |
|
593 |
$subject = 'Fwd: '.$FORWARD_MESSAGE['subject']; |
|
594 |
} |
4e17e6
|
595 |
|
1966c5
|
596 |
// creeate a draft-subject |
S |
597 |
else if (isset($DRAFT_MESSAGE['subject'])) |
|
598 |
$subject = $DRAFT_MESSAGE['subject']; |
4e17e6
|
599 |
|
T |
600 |
$out = $form_start ? "$form_start\n" : ''; |
|
601 |
$out .= $textfield->show($subject); |
|
602 |
$out .= $form_end ? "\n$form_end" : ''; |
|
603 |
|
|
604 |
return $out; |
|
605 |
} |
|
606 |
|
|
607 |
|
|
608 |
function rcmail_compose_attachment_list($attrib) |
|
609 |
{ |
|
610 |
global $OUTPUT, $JS_OBJECT_NAME; |
|
611 |
|
|
612 |
// add ID if not given |
|
613 |
if (!$attrib['id']) |
|
614 |
$attrib['id'] = 'rcmAttachmentList'; |
|
615 |
|
|
616 |
// allow the following attributes to be added to the <ul> tag |
|
617 |
$attrib_str = create_attrib_string($attrib, array('id', 'class', 'style')); |
|
618 |
|
|
619 |
$out = '<ul'. $attrib_str . ">\n"; |
|
620 |
|
|
621 |
if (is_array($_SESSION['compose']['attachments'])) |
|
622 |
{ |
a894ba
|
623 |
if ($attrib['deleteicon']) |
aade7b
|
624 |
$button = sprintf('<img src="%s%s" alt="%s" border="0" style="padding-right:2px;vertical-align:middle" />', |
508442
|
625 |
$CONFIG['skin_path'], |
T |
626 |
$attrib['deleteicon'], |
|
627 |
rcube_label('delete')); |
a894ba
|
628 |
else |
S |
629 |
$button = rcube_label('delete'); |
|
630 |
|
aade7b
|
631 |
foreach ($_SESSION['compose']['attachments'] as $id => $a_prop) |
T |
632 |
$out .= sprintf('<li id="rcmfile%d"><a href="#delete" onclick="return %s.command(\'remove-attachment\',\'rcmfile%d\', this)" title="%s">%s</a>%s</li>', |
|
633 |
$id, |
508442
|
634 |
$JS_OBJECT_NAME, |
aade7b
|
635 |
$id, |
508442
|
636 |
rcube_label('delete'), |
aade7b
|
637 |
$button, |
T |
638 |
rep_specialchars_output($a_prop['name'])); |
4e17e6
|
639 |
} |
T |
640 |
|
|
641 |
$OUTPUT->add_script(sprintf("%s.gui_object('attachmentlist', '%s');", $JS_OBJECT_NAME, $attrib['id'])); |
|
642 |
|
|
643 |
$out .= '</ul>'; |
|
644 |
return $out; |
|
645 |
} |
|
646 |
|
|
647 |
|
|
648 |
|
|
649 |
function rcmail_compose_attachment_form($attrib) |
|
650 |
{ |
|
651 |
global $OUTPUT, $JS_OBJECT_NAME, $SESS_HIDDEN_FIELD; |
|
652 |
|
|
653 |
// add ID if not given |
|
654 |
if (!$attrib['id']) |
|
655 |
$attrib['id'] = 'rcmUploadbox'; |
|
656 |
|
|
657 |
// allow the following attributes to be added to the <div> tag |
|
658 |
$attrib_str = create_attrib_string($attrib, array('id', 'class', 'style')); |
|
659 |
$input_field = rcmail_compose_attachment_field(array()); |
|
660 |
$label_send = rcube_label('upload'); |
|
661 |
$label_close = rcube_label('close'); |
|
662 |
|
|
663 |
$out = <<<EOF |
|
664 |
<div$attrib_str> |
|
665 |
<form action="./" method="post" enctype="multipart/form-data"> |
|
666 |
$SESS_HIDDEN_FIELD |
|
667 |
$input_field<br /> |
|
668 |
<input type="button" value="$label_close" class="button" onclick="document.getElementById('$attrib[id]').style.visibility='hidden'" /> |
|
669 |
<input type="button" value="$label_send" class="button" onclick="$JS_OBJECT_NAME.command('send-attachment', this.form)" /> |
|
670 |
</form> |
|
671 |
</div> |
|
672 |
EOF; |
|
673 |
|
|
674 |
|
|
675 |
$OUTPUT->add_script(sprintf("%s.gui_object('uploadbox', '%s');", $JS_OBJECT_NAME, $attrib['id'])); |
|
676 |
return $out; |
|
677 |
} |
|
678 |
|
|
679 |
|
|
680 |
function rcmail_compose_attachment_field($attrib) |
|
681 |
{ |
|
682 |
// allow the following attributes to be added to the <input> tag |
|
683 |
$attrib_str = create_attrib_string($attrib, array('id', 'class', 'style', 'size')); |
|
684 |
|
|
685 |
$out = '<input type="file" name="_attachments[]"'. $attrib_str . " />"; |
|
686 |
return $out; |
|
687 |
} |
|
688 |
|
66e2bf
|
689 |
|
4e17e6
|
690 |
function rcmail_priority_selector($attrib) |
T |
691 |
{ |
|
692 |
list($form_start, $form_end) = get_form_tags($attrib); |
|
693 |
unset($attrib['form']); |
|
694 |
|
|
695 |
$attrib['name'] = '_priority'; |
|
696 |
$selector = new select($attrib); |
|
697 |
|
|
698 |
$selector->add(array(rcube_label('lowest'), |
|
699 |
rcube_label('low'), |
|
700 |
rcube_label('normal'), |
|
701 |
rcube_label('high'), |
|
702 |
rcube_label('highest')), |
7902df
|
703 |
array(5, 4, 0, 2, 1)); |
4e17e6
|
704 |
|
597170
|
705 |
$sel = isset($_POST['_priority']) ? $_POST['_priority'] : 0; |
4e17e6
|
706 |
|
T |
707 |
$out = $form_start ? "$form_start\n" : ''; |
|
708 |
$out .= $selector->show($sel); |
|
709 |
$out .= $form_end ? "\n$form_end" : ''; |
|
710 |
|
|
711 |
return $out; |
|
712 |
} |
|
713 |
|
|
714 |
|
620439
|
715 |
function rcmail_receipt_checkbox($attrib) |
T |
716 |
{ |
|
717 |
list($form_start, $form_end) = get_form_tags($attrib); |
|
718 |
unset($attrib['form']); |
66e2bf
|
719 |
|
T |
720 |
if (!isset($attrib['id'])) |
|
721 |
$attrib['id'] = 'receipt'; |
620439
|
722 |
|
T |
723 |
$attrib['name'] = '_receipt'; |
66e2bf
|
724 |
$attrib['value'] = '1'; |
T |
725 |
$checkbox = new checkbox($attrib); |
620439
|
726 |
|
T |
727 |
$out = $form_start ? "$form_start\n" : ''; |
|
728 |
$out .= $checkbox->show(0); |
|
729 |
$out .= $form_end ? "\n$form_end" : ''; |
|
730 |
|
|
731 |
return $out; |
|
732 |
} |
|
733 |
|
|
734 |
|
4e17e6
|
735 |
function get_form_tags($attrib) |
T |
736 |
{ |
|
737 |
global $CONFIG, $OUTPUT, $JS_OBJECT_NAME, $MESSAGE_FORM, $SESS_HIDDEN_FIELD; |
|
738 |
|
|
739 |
$form_start = ''; |
|
740 |
if (!strlen($MESSAGE_FORM)) |
|
741 |
{ |
|
742 |
$hiddenfields = new hiddenfield(array('name' => '_task', 'value' => $GLOBALS['_task'])); |
|
743 |
$hiddenfields->add(array('name' => '_action', 'value' => 'send')); |
1966c5
|
744 |
|
597170
|
745 |
$form_start = empty($attrib['form']) ? '<form name="form" action="./" method="post">' : ''; |
4e17e6
|
746 |
$form_start .= "\n$SESS_HIDDEN_FIELD\n"; |
T |
747 |
$form_start .= $hiddenfields->show(); |
|
748 |
} |
|
749 |
|
|
750 |
$form_end = (strlen($MESSAGE_FORM) && !strlen($attrib['form'])) ? '</form>' : ''; |
597170
|
751 |
$form_name = !empty($attrib['form']) ? $attrib['form'] : 'form'; |
4e17e6
|
752 |
|
T |
753 |
if (!strlen($MESSAGE_FORM)) |
|
754 |
$OUTPUT->add_script("$JS_OBJECT_NAME.gui_object('messageform', '$form_name');"); |
|
755 |
|
|
756 |
$MESSAGE_FORM = $form_name; |
|
757 |
|
|
758 |
return array($form_start, $form_end); |
|
759 |
} |
|
760 |
|
|
761 |
|
|
762 |
function format_email_recipient($email, $name='') |
|
763 |
{ |
|
764 |
if ($name && $name != $email) |
|
765 |
return sprintf('%s <%s>', strpos($name, ",") ? '"'.$name.'"' : $name, $email); |
|
766 |
else |
|
767 |
return $email; |
|
768 |
} |
|
769 |
|
|
770 |
|
fd8c50
|
771 |
function rcmail_charset_pulldown($selected='ISO-8859-1') |
T |
772 |
{ |
|
773 |
$select = new select(); |
|
774 |
|
|
775 |
|
|
776 |
return $select->show($selected); |
|
777 |
} |
|
778 |
|
|
779 |
|
4e17e6
|
780 |
/****** get contacts for this user and add them to client scripts ********/ |
T |
781 |
|
d7cb77
|
782 |
$sql_result = $DB->query("SELECT name, email |
S |
783 |
FROM ".get_table_name('contacts')." WHERE user_id=? |
1cded8
|
784 |
AND del<>1",$_SESSION['user_id']); |
4e17e6
|
785 |
|
T |
786 |
if ($DB->num_rows($sql_result)) |
|
787 |
{ |
|
788 |
$a_contacts = array(); |
|
789 |
while ($sql_arr = $DB->fetch_assoc($sql_result)) |
|
790 |
if ($sql_arr['email']) |
|
791 |
$a_contacts[] = format_email_recipient($sql_arr['email'], rep_specialchars_output($sql_arr['name'], 'js')); |
|
792 |
|
|
793 |
$OUTPUT->add_script(sprintf("$JS_OBJECT_NAME.set_env('contacts', %s);", array2js($a_contacts))); |
|
794 |
} |
|
795 |
|
|
796 |
|
|
797 |
parse_template('compose'); |
1966c5
|
798 |
?> |