source: github/program/steps/mail/compose.inc @ f115416

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since f115416 was f115416, checked in by thomascube <thomas@…>, 6 years ago

Merged branch devel-addressbook from r443 back to trunk

  • Property mode set to 100644
File size: 26.6 KB
Line 
1<?php
2
3/*
4 +-----------------------------------------------------------------------+
5 | program/steps/mail/compose.inc                                        |
6 |                                                                       |
7 | This file is part of the RoundCube Webmail client                     |
8 | Copyright (C) 2005, RoundCube Dev. - Switzerland                      |
9 | Licensed under the GNU GPL                                            |
10 |                                                                       |
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
22require_once('Mail/mimeDecode.php');
23require_once('lib/html2text.inc');
24
25// define constants for message compose mode
26define('RCUBE_COMPOSE_REPLY', 0x0106);
27define('RCUBE_COMPOSE_FORWARD', 0x0107);
28define('RCUBE_COMPOSE_DRAFT', 0x0108);
29
30
31// remove an attachment
32if ($_action=='remove-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_GET['_file'], $regs))
33  {
34  $id = $regs[1];
35  if (is_array($_SESSION['compose']['attachments'][$id]))
36    {
37    @unlink($_SESSION['compose']['attachments'][$id]['path']);
38    $_SESSION['compose']['attachments'][$id] = NULL;
39    $OUTPUT->command('remove_from_attachment_list', "rcmfile$id");
40    $OUTPUT->send();
41    exit;
42    }
43  }
44
45
46$MESSAGE_FORM = NULL;
47$MESSAGE = NULL;
48
49// Nothing below is called during message composition, only at "new/forward/reply/draft" initialization or
50// if a compose-ID is given (i.e. when the compose step is opened in a new window/tab).
51// Since there are many ways to leave the compose page improperly, it seems necessary to clean-up an old
52// compose when a "new/forward/reply/draft" is called - otherwise the old session attachments will appear
53
54if (!is_array($_SESSION['compose']) || $_SESSION['compose']['id'] != get_input_value('_id', RCUBE_INPUT_GET))
55  {
56  rcmail_compose_cleanup();
57  $_SESSION['compose'] = array('id' => uniqid(rand()));
58  }
59
60// add some labels to client
61rcube_add_label('nosubject', 'norecipientwarning', 'nosubjectwarning', 'nobodywarning', 'notsentwarning', 'savingmessage', 'sendingmessage', 'messagesaved', 'converting');
62
63// add config parameter to client script
64$OUTPUT->set_env('draft_autosave', !empty($CONFIG['drafts_mbox']) ? $CONFIG['draft_autosave'] : 0);
65
66
67// get reference message and set compose mode
68if ($msg_uid = get_input_value('_reply_uid', RCUBE_INPUT_GET))
69  $compose_mode = RCUBE_COMPOSE_REPLY;
70else if ($msg_uid = get_input_value('_forward_uid', RCUBE_INPUT_GET))
71  $compose_mode = RCUBE_COMPOSE_FORWARD;
72else if ($msg_uid = get_input_value('_draft_uid', RCUBE_INPUT_GET))
73  $compose_mode = RCUBE_COMPOSE_DRAFT;
74
75
76if (!empty($msg_uid))
77  {
78  // similar as in program/steps/mail/show.inc
79  $MESSAGE = array('UID' => $msg_uid);
80  $MESSAGE['headers'] = &$IMAP->get_headers($msg_uid);
81  $MESSAGE['structure'] = &$IMAP->get_structure($msg_uid); 
82  $MESSAGE['subject'] = $IMAP->decode_header($MESSAGE['headers']->subject);
83  $MESSAGE['parts'] = $IMAP->get_mime_numbers($MESSAGE['structure']);
84 
85  if ($compose_mode == RCUBE_COMPOSE_REPLY)
86    {
87    $_SESSION['compose']['reply_uid'] = $msg_uid;
88    $_SESSION['compose']['reply_msgid'] = $MESSAGE['headers']->messageID;
89    $_SESSION['compose']['references']  = $MESSAGE['headers']->reference;
90    $_SESSION['compose']['references'] .= !empty($MESSAGE['headers']->reference) ? ' ' : '';
91    $_SESSION['compose']['references'] .= $MESSAGE['headers']->messageID;
92
93    if (!empty($_GET['_all']))
94      $MESSAGE['reply_all'] = 1;
95    }
96  else if ($compose_mode == RCUBE_COMPOSE_FORWARD)
97    {
98    $_SESSION['compose']['forward_uid'] = $msg_uid;
99    }
100  else if ($compose_mode == RCUBE_COMPOSE_DRAFT)
101    {
102    $_SESSION['compose']['draft_uid'] = $msg_uid;
103    }
104
105  }
106
107/****** compose mode functions ********/
108
109
110function rcmail_compose_headers($attrib)
111  {
112  global $IMAP, $MESSAGE, $DB, $compose_mode;
113  static $sa_recipients = array();
114
115  list($form_start, $form_end) = get_form_tags($attrib);
116 
117  $out = '';
118  $part = strtolower($attrib['part']);
119 
120  switch ($part)
121    {
122    case 'from':
123      return rcmail_compose_header_from($attrib);
124
125    case 'to':
126      $fname = '_to';
127      $header = 'to';
128     
129      // we have a set of recipients stored is session
130      if (($mailto_id = get_input_value('_mailto', RCUBE_INPUT_GET)) && $_SESSION['mailto'][$mailto_id])
131        $fvalue = $_SESSION['mailto'][$mailto_id];
132      else if (!empty($_GET['_to']))
133        $fvalue = get_input_value('_to', RCUBE_INPUT_GET);
134       
135    case 'cc':
136      if (!$fname)
137        {
138        $fname = '_cc';
139        $header = 'cc';
140        }
141    case 'bcc':
142      if (!$fname)
143        {
144        $fname = '_bcc';
145        $header = 'bcc';
146        }
147       
148      $allow_attrib = array('id', 'class', 'style', 'cols', 'rows', 'wrap', 'tabindex');
149      $field_type = 'textarea';           
150      break;
151
152    case 'replyto':
153    case 'reply-to':
154      $fname = '_replyto';
155      $allow_attrib = array('id', 'class', 'style', 'size', 'tabindex');
156      $field_type = 'textfield';
157      break;
158   
159    }
160 
161  if ($fname && !empty($_POST[$fname]))
162    $fvalue = get_input_value($fname, RCUBE_INPUT_POST, TRUE);
163
164  else if ($header && $compose_mode == RCUBE_COMPOSE_REPLY)
165    {
166    // get recipent address(es) out of the message headers
167    if ($header=='to' && !empty($MESSAGE['headers']->replyto))
168      $fvalue = $MESSAGE['headers']->replyto;
169
170    else if ($header=='to' && !empty($MESSAGE['headers']->from))
171      $fvalue = $MESSAGE['headers']->from;
172
173    // add recipent of original message if reply to all
174    else if ($header=='cc' && !empty($MESSAGE['reply_all']))
175      {
176      if ($v = $MESSAGE['headers']->to)
177        $fvalue .= $v;
178
179      if ($v = $MESSAGE['headers']->cc)
180        $fvalue .= (!empty($fvalue) ? ', ' : '') . $v;
181      }
182
183    // split recipients and put them back together in a unique way
184    if (!empty($fvalue))
185      {
186      $to_addresses = $IMAP->decode_address_list($fvalue);
187      $fvalue = '';
188      foreach ($to_addresses as $addr_part)
189        {
190        if (!empty($addr_part['mailto']) && !in_array($addr_part['mailto'], $sa_recipients) && (!$MESSAGE['FROM'] || !in_array($addr_part['mailto'], $MESSAGE['FROM'])))
191          {
192          $fvalue .= (strlen($fvalue) ? ', ':'').$addr_part['string'];
193          $sa_recipients[] = $addr_part['mailto'];
194          }
195        }
196      }
197    }
198  else if ($header && $compose_mode == RCUBE_COMPOSE_DRAFT)
199    {
200    // get drafted headers
201    if ($header=='to' && !empty($MESSAGE['headers']->to))
202      $fvalue = $IMAP->decode_header($MESSAGE['headers']->to);
203
204    if ($header=='cc' && !empty($MESSAGE['headers']->cc))
205      $fvalue = $IMAP->decode_header($MESSAGE['headers']->cc);
206
207    if ($header=='bcc' && !empty($MESSAGE['headers']->bcc))
208      $fvalue = $IMAP->decode_header($MESSAGE['headers']->bcc);
209    }
210
211       
212  if ($fname && $field_type)
213    {
214    // pass the following attributes to the form class
215    $field_attrib = array('name' => $fname);
216    foreach ($attrib as $attr => $value)
217      if (in_array($attr, $allow_attrib))
218        $field_attrib[$attr] = $value;
219
220    // create teaxtarea object
221    $input = new $field_type($field_attrib);
222    $out = $input->show($fvalue);   
223    }
224 
225  if ($form_start)
226    $out = $form_start.$out;
227
228  return $out; 
229  }
230
231
232
233function rcmail_compose_header_from($attrib)
234  {
235  global $IMAP, $MESSAGE, $DB, $OUTPUT, $compose_mode;
236   
237  // pass the following attributes to the form class
238  $field_attrib = array('name' => '_from');
239  foreach ($attrib as $attr => $value)
240    if (in_array($attr, array('id', 'class', 'style', 'size', 'tabindex')))
241      $field_attrib[$attr] = $value;
242
243  // extract all recipients of the reply-message
244  $a_recipients = array();
245  if ($compose_mode == RCUBE_COMPOSE_REPLY && is_object($MESSAGE['headers']))
246    {
247    $MESSAGE['FROM'] = array();
248
249    $a_to = $IMAP->decode_address_list($MESSAGE['headers']->to);
250    foreach ($a_to as $addr)
251      {
252      if (!empty($addr['mailto']))
253        $a_recipients[] = $addr['mailto'];
254      }
255
256    if (!empty($MESSAGE['headers']->cc))
257      {
258      $a_cc = $IMAP->decode_address_list($MESSAGE['headers']->cc);
259      foreach ($a_cc as $addr)
260        {
261        if (!empty($addr['mailto']))
262          $a_recipients[] = $addr['mailto'];
263        }
264      }
265    }
266
267  // get this user's identities
268  $sql_result = $DB->query("SELECT identity_id, name, email, signature, html_signature
269                            FROM   ".get_table_name('identities')."
270                            WHERE user_id=?
271                            AND    del<>1
272                            ORDER BY ".$DB->quoteIdentifier('standard')." DESC, name ASC",
273                           $_SESSION['user_id']);
274
275  if ($DB->num_rows($sql_result))
276    {
277    $from_id = 0;
278    $a_signatures = array();
279
280    $field_attrib['onchange'] = JS_OBJECT_NAME.".change_identity(this)";
281    $select_from = new select($field_attrib);
282
283    while ($sql_arr = $DB->fetch_assoc($sql_result))
284      {
285      $identity_id = $sql_arr['identity_id'];
286      $select_from->add(format_email_recipient($sql_arr['email'], $sql_arr['name']), $identity_id);
287
288      // add signature to array
289      if (!empty($sql_arr['signature']))
290        {
291        $a_signatures[$identity_id]['text'] = $sql_arr['signature'];
292        $a_signatures[$identity_id]['is_html'] = ($sql_arr['html_signature'] == 1) ? true : false;
293        if ($a_signatures[$identity_id]['is_html'])
294          {
295            $h2t = new html2text($a_signatures[$identity_id]['text'], false, false);
296            $plainTextPart = $h2t->get_text();
297            $a_signatures[$identity_id]['plain_text'] = trim($plainTextPart);
298          }
299        }
300
301      // set identity if it's one of the reply-message recipients
302      if (in_array($sql_arr['email'], $a_recipients))
303        $from_id = $sql_arr['identity_id'];
304
305      if ($compose_mode == RCUBE_COMPOSE_REPLY && is_array($MESSAGE['FROM']))
306        $MESSAGE['FROM'][] = $sql_arr['email'];
307
308      if ($compose_mode == RCUBE_COMPOSE_DRAFT && strstr($MESSAGE['headers']->from, $sql_arr['email']))
309        $from_id = $sql_arr['identity_id'];
310      }
311
312    // overwrite identity selection with post parameter
313    if (isset($_POST['_from']))
314      $from_id = get_input_value('_from', RCUBE_INPUT_POST);
315
316    $out = $select_from->show($from_id);
317
318    // add signatures to client
319    $OUTPUT->set_env('signatures', $a_signatures);
320    }
321  else
322    {
323    $input_from = new textfield($field_attrib);
324    $out = $input_from->show($_POST['_from']);
325    }
326 
327  if ($form_start)
328    $out = $form_start.$out;
329
330  return $out;
331  }
332
333 
334
335function rcmail_compose_body($attrib)
336  {
337  global $CONFIG, $OUTPUT, $MESSAGE, $compose_mode;
338 
339  list($form_start, $form_end) = get_form_tags($attrib);
340  unset($attrib['form']);
341 
342  if (empty($attrib['id']))
343    $attrib['id'] = 'rcmComposeMessage';
344
345  $attrib['name'] = '_message';
346
347  if ($CONFIG['htmleditor'])
348    $isHtml = true;
349  else
350    $isHtml = false;
351
352  $body = '';
353
354  // use posted message body
355  if (!empty($_POST['_message']))
356    {
357    $body = get_input_value('_message', RCUBE_INPUT_POST, TRUE);
358    }
359  // compose reply-body
360  else if ($compose_mode == RCUBE_COMPOSE_REPLY)
361    {
362    $hasHtml = rcmail_has_html_part($MESSAGE['parts']);
363    if ($hasHtml && $CONFIG['htmleditor'])
364      {
365      $body = rcmail_first_html_part($MESSAGE);
366      $isHtml = true;
367      }
368    else
369      {
370      $body = rcmail_first_text_part($MESSAGE);
371      $isHtml = false;
372      }
373
374    $body = rcmail_create_reply_body($body, $isHtml);
375    }
376  // forward message body inline
377  else if ($compose_mode == RCUBE_COMPOSE_FORWARD)
378    {
379    $hasHtml = rcmail_has_html_part($MESSAGE['parts']);
380    if ($hasHtml && $CONFIG['htmleditor'])
381      {
382      $body = rcmail_first_html_part($MESSAGE);
383      $isHtml = true;
384      }
385    else
386      {
387      $body = rcmail_first_text_part($MESSAGE);
388      $isHtml = false;
389      }
390
391    $body = rcmail_create_forward_body($body, $isHtml);
392    }
393  else if ($compose_mode == RCUBE_COMPOSE_DRAFT)
394    {
395    $hasHtml = rcmail_has_html_part($MESSAGE['parts']);
396    if ($hasHtml && $CONFIG['htmleditor'])
397      {
398      $body = rcmail_first_html_part($MESSAGE);
399      $isHtml = true;
400      }
401    else
402      {
403      $body = rcmail_first_text_part($MESSAGE);
404      $isHtml = false;
405      }
406
407    $body = rcmail_create_draft_body($body, $isHtml);
408    }
409
410  $OUTPUT->include_script('tiny_mce/tiny_mce.js');
411  $OUTPUT->include_script("editor.js");
412  $OUTPUT->add_script('rcmail_editor_init("$__skin_path");');
413
414  $out = $form_start ? "$form_start\n" : '';
415
416  $saveid = new hiddenfield(array('name' => '_draft_saveid', 'value' => $compose_mode==RCUBE_COMPOSE_DRAFT ? str_replace(array('<','>'), "", $MESSAGE['headers']->messageID) : ''));
417  $out .= $saveid->show();
418
419  $drafttoggle = new hiddenfield(array('name' => '_draft', 'value' => 'yes'));
420  $out .= $drafttoggle->show();
421
422  $msgtype = new hiddenfield(array('name' => '_is_html', 'value' => ($isHtml?"1":"0")));
423  $out .= $msgtype->show();
424
425  // If desired, set this text area to be editable by TinyMCE
426  if ($isHtml)
427    $attrib['mce_editable'] = "true";
428  $textarea = new textarea($attrib);
429  $out .= $textarea->show($body);
430  $out .= $form_end ? "\n$form_end" : '';
431
432  // include GoogieSpell
433  if (!empty($CONFIG['enable_spellcheck']) && !$isHtml)
434    {
435    $lang_set = '';
436    if (!empty($CONFIG['spellcheck_languages']) && is_array($CONFIG['spellcheck_languages']))
437      $lang_set = "googie.setLanguages(".array2js($CONFIG['spellcheck_languages']).");\n";
438   
439    $OUTPUT->include_script('googiespell.js');
440    $OUTPUT->add_script(sprintf(
441      "var googie = new GoogieSpell('\$__skin_path/images/googiespell/','%s&_action=spell&lang=');\n".
442      "googie.lang_chck_spell = \"%s\";\n".
443      "googie.lang_rsm_edt = \"%s\";\n".
444      "googie.lang_close = \"%s\";\n".
445      "googie.lang_revert = \"%s\";\n".
446      "googie.lang_no_error_found = \"%s\";\n%s".
447      "googie.setCurrentLanguage('%s');\n".
448      "googie.decorateTextarea('%s');\n".
449      "%s.set_env('spellcheck', googie);",
450      $GLOBALS['COMM_PATH'],
451      JQ(Q(rcube_label('checkspelling'))),
452      JQ(Q(rcube_label('resumeediting'))),
453      JQ(Q(rcube_label('close'))),
454      JQ(Q(rcube_label('revertto'))),
455      JQ(Q(rcube_label('nospellerrors'))),
456      $lang_set,
457      substr($_SESSION['user_lang'], 0, 2),
458      $attrib['id'],
459      JS_OBJECT_NAME), 'foot');
460
461    rcube_add_label('checking');
462    }
463 
464  $out .= "\n".'<iframe name="savetarget" src="program/blank.gif" style="width:0;height:0;visibility:hidden;"></iframe>';
465
466  return $out;
467  }
468
469
470function rcmail_create_reply_body($body, $bodyIsHtml)
471  {
472  global $IMAP, $MESSAGE;
473
474  if (! $bodyIsHtml)
475  {
476    // soft-wrap message first
477    $body = wordwrap($body, 75);
478 
479    // split body into single lines
480    $a_lines = preg_split('/\r?\n/', $body);
481 
482    // add > to each line
483    for($n=0; $n<sizeof($a_lines); $n++)
484      {
485      if (strpos($a_lines[$n], '>')===0)
486        $a_lines[$n] = '>'.$a_lines[$n];
487      else
488        $a_lines[$n] = '> '.$a_lines[$n];
489      }
490 
491    $body = join("\n", $a_lines);
492
493    // add title line
494    $prefix = sprintf("\n\n\nOn %s, %s wrote:\n",
495             $MESSAGE['headers']->date,
496             $IMAP->decode_header($MESSAGE['headers']->from));
497
498    // try to remove the signature
499    if ($sp = strrstr($body, '-- '))
500      {
501      if ($body{$sp+3}==' ' || $body{$sp+3}=="\n" || $body{$sp+3}=="\r")
502        $body = substr($body, 0, $sp-1);
503      }
504    $suffix = '';
505  }
506  else
507  {
508     $prefix = sprintf("<br><br>On %s, %s wrote:<br><blockquote type=\"cite\" " .
509                       "style=\"padding-left: 5px; border-left: #1010ff 2px solid; " .
510                       "margin-left: 5px; width: 100%%\">",
511                       $MESSAGE['headers']->date,
512                       $IMAP->decode_header($MESSAGE['headers']->from));
513
514     $suffix = "</blockquote>";
515  }
516
517  return $prefix.$body.$suffix;
518  }
519
520
521function rcmail_create_forward_body($body, $bodyIsHtml)
522  {
523  global $IMAP, $MESSAGE;
524
525  if (! $bodyIsHtml)
526  {
527    // soft-wrap message first
528    $body = wordwrap($body, 80);
529 
530    $prefix = sprintf("\n\n\n-------- Original Message --------\nSubject: %s\nDate: %s\nFrom: %s\nTo: %s\n\n",
531                     $MESSAGE['subject'],
532                     $MESSAGE['headers']->date,
533                     $IMAP->decode_header($MESSAGE['headers']->from),
534                     $IMAP->decode_header($MESSAGE['headers']->to));
535  }
536  else
537  {
538      $prefix = sprintf(
539        "<br><br>-------- Original Message --------" .
540        "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tbody>" .
541        "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">Subject: </th><td>%s</td></tr>" .
542        "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">Date: </th><td>%s</td></tr>" .
543        "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">From: </th><td>%s</td></tr>" .
544        "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">To: </th><td>%s</td></tr>" .
545        "</tbody></table><br>",
546                     Q($MESSAGE['subject']),
547                     Q($MESSAGE['headers']->date),
548                     Q($IMAP->decode_header($MESSAGE['headers']->from)),
549                     Q($IMAP->decode_header($MESSAGE['headers']->to)));
550  }
551
552  // add attachments
553  if (!isset($_SESSION['compose']['forward_attachments']) && is_array($MESSAGE['parts']))
554    rcmail_write_compose_attachments($MESSAGE);
555   
556  return $prefix.$body;
557  }
558
559
560function rcmail_create_draft_body($body, $bodyIsHtml)
561  {
562  global $IMAP, $MESSAGE;
563   
564  // add attachments
565  if (!isset($_SESSION['compose']['forward_attachments']) &&
566      is_array($MESSAGE['parts']) && sizeof($MESSAGE['parts'])>1)
567    rcmail_write_compose_attachments($MESSAGE);
568
569  return $body;
570  }
571 
572 
573function rcmail_write_compose_attachments(&$message)
574  {
575  global $IMAP, $CONFIG;
576
577  $temp_dir = unslashify($CONFIG['temp_dir']);
578
579  if (!is_array($_SESSION['compose']['attachments']))
580    $_SESSION['compose']['attachments'] = array();
581 
582  foreach ($message['parts'] as $pid => $part)
583    {
584    if ($part->ctype_primary != 'message' && $part->ctype_primary != 'text' &&
585        ($part->disposition=='attachment' || $part->disposition=='inline' || $part->headers['content-id'] ||
586         (empty($part->disposition) && $part->filename)))
587      {
588      $tmp_path = tempnam($temp_dir, 'rcmAttmnt');
589      if ($fp = fopen($tmp_path, 'w'))
590        {
591        fwrite($fp, $IMAP->get_message_part($message['UID'], $pid, $part->encoding));
592        fclose($fp);
593       
594        $_SESSION['compose']['attachments'][] = array(
595          'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
596          'name' => $part->filename,
597          'path' => $tmp_path
598          );
599        }
600      }
601    }
602       
603  $_SESSION['compose']['forward_attachments'] = TRUE;
604  }
605
606
607function rcmail_compose_subject($attrib)
608  {
609  global $CONFIG, $MESSAGE, $compose_mode;
610 
611  list($form_start, $form_end) = get_form_tags($attrib);
612  unset($attrib['form']);
613 
614  $attrib['name'] = '_subject';
615  $textfield = new textfield($attrib);
616
617  $subject = '';
618
619  // use subject from post
620  if (isset($_POST['_subject']))
621    $subject = get_input_value('_subject', RCUBE_INPUT_POST, TRUE);
622   
623  // create a reply-subject
624  else if ($compose_mode == RCUBE_COMPOSE_REPLY)
625    {
626    if (eregi('^re:', $MESSAGE['subject']))
627      $subject = $MESSAGE['subject'];
628    else
629      $subject = 'Re: '.$MESSAGE['subject'];
630    }
631
632  // create a forward-subject
633  else if ($compose_mode == RCUBE_COMPOSE_FORWARD)
634    {
635    if (eregi('^fwd:', $MESSAGE['subject']))
636      $subject = $MESSAGE['subject'];
637    else
638      $subject = 'Fwd: '.$MESSAGE['subject'];
639    }
640
641  // creeate a draft-subject
642  else if ($compose_mode == RCUBE_COMPOSE_DRAFT)
643    $subject = $MESSAGE['subject'];
644 
645  $out = $form_start ? "$form_start\n" : '';
646  $out .= $textfield->show($subject);
647  $out .= $form_end ? "\n$form_end" : '';
648         
649  return $out;
650  }
651
652
653function rcmail_compose_attachment_list($attrib)
654  {
655  global $OUTPUT, $CONFIG;
656 
657  // add ID if not given
658  if (!$attrib['id'])
659    $attrib['id'] = 'rcmAttachmentList';
660 
661  // allow the following attributes to be added to the <ul> tag
662  $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style'));
663 
664  $out = '<ul'. $attrib_str . ">\n";
665 
666  if (is_array($_SESSION['compose']['attachments']))
667    {
668    if ($attrib['deleteicon'])
669      $button = sprintf('<img src="%s%s" alt="%s" border="0" style="padding-right:2px;vertical-align:middle" />',
670                        $CONFIG['skin_path'],
671                        $attrib['deleteicon'],
672                        rcube_label('delete'));
673    else
674      $button = rcube_label('delete');
675
676    foreach ($_SESSION['compose']['attachments'] as $id => $a_prop)
677      $out .= sprintf('<li id="rcmfile%d"><a href="#delete" onclick="return %s.command(\'remove-attachment\',\'rcmfile%d\', this)" title="%s">%s</a>%s</li>',
678                      $id,
679                      JS_OBJECT_NAME,
680                      $id,
681                      Q(rcube_label('delete')),
682                      $button,
683                      Q($a_prop['name']));
684    }
685
686  $OUTPUT->add_gui_object('attachmentlist', $attrib['id']);
687   
688  $out .= '</ul>';
689  return $out;
690  }
691
692
693
694function rcmail_compose_attachment_form($attrib)
695  {
696  global $OUTPUT, $SESS_HIDDEN_FIELD;
697
698  // add ID if not given
699  if (!$attrib['id'])
700    $attrib['id'] = 'rcmUploadbox';
701 
702  // allow the following attributes to be added to the <div> tag
703  $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style'));
704  $input_field = rcmail_compose_attachment_field(array());
705  $label_send = rcube_label('upload');
706  $label_close = rcube_label('close');
707  $js_instance = JS_OBJECT_NAME;
708 
709  $out = <<<EOF
710<div$attrib_str>
711<form action="./" method="post" enctype="multipart/form-data">
712$SESS_HIDDEN_FIELD
713$input_field<br />
714<input type="button" value="$label_close" class="button" onclick="document.getElementById('$attrib[id]').style.visibility='hidden'" />
715<input type="button" value="$label_send" class="button" onclick="$js_instance.command('send-attachment', this.form)" />
716</form>
717</div>
718EOF;
719
720 
721  $OUTPUT->add_gui_object('uploadbox', $attrib['id']);
722  return $out;
723  }
724
725
726function rcmail_compose_attachment_field($attrib)
727  {
728  // allow the following attributes to be added to the <input> tag
729  $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style', 'size'));
730 
731  $out = '<input type="file" name="_attachments[]"'. $attrib_str . " />";
732  return $out;
733  }
734
735
736function rcmail_priority_selector($attrib)
737  {
738  list($form_start, $form_end) = get_form_tags($attrib);
739  unset($attrib['form']);
740 
741  $attrib['name'] = '_priority';
742  $selector = new select($attrib);
743
744  $selector->add(array(rcube_label('lowest'),
745                       rcube_label('low'),
746                       rcube_label('normal'),
747                       rcube_label('high'),
748                       rcube_label('highest')),
749                 array(5, 4, 0, 2, 1));
750                 
751  $sel = isset($_POST['_priority']) ? $_POST['_priority'] : 0;
752
753  $out = $form_start ? "$form_start\n" : '';
754  $out .= $selector->show($sel);
755  $out .= $form_end ? "\n$form_end" : '';
756         
757  return $out;
758  }
759
760
761function rcmail_receipt_checkbox($attrib)
762  {
763  list($form_start, $form_end) = get_form_tags($attrib);
764  unset($attrib['form']);
765 
766  if (!isset($attrib['id']))
767    $attrib['id'] = 'receipt'; 
768
769  $attrib['name'] = '_receipt';
770  $attrib['value'] = '1';
771  $checkbox = new checkbox($attrib);
772
773  $out = $form_start ? "$form_start\n" : '';
774  $out .= $checkbox->show(0);
775  $out .= $form_end ? "\n$form_end" : '';
776
777  return $out;
778  }
779
780
781function rcmail_editor_selector($attrib)
782{
783  global $CONFIG, $MESSAGE, $compose_mode;
784
785  $choices = array(
786    'html'  => 'htmltoggle',
787    'plain' => 'plaintoggle'
788  );
789
790  // determine whether HTML or plain text should be checked
791  if ($CONFIG['htmleditor'])
792    $useHtml = true;
793  else
794    $useHtml = false;
795
796  if ($compose_mode == RCUBE_COMPOSE_REPLY ||
797      $compose_mode == RCUBE_COMPOSE_FORWARD ||
798      $compose_mode == RCUBE_COMPOSE_DRAFT)
799    {
800    $hasHtml = rcmail_has_html_part($MESSAGE['parts']);
801    $useHtml = ($hasHtml && $CONFIG['htmleditor']);
802    }
803
804  $selector = '';
805 
806  $attrib['name'] = '_editorSelect';
807  $attrib['onchange'] = 'return rcmail_toggle_editor(this)';
808  foreach ($choices as $value => $text)
809    {
810    $checked = '';
811    if ((($value == 'html') && $useHtml) ||
812        (($value != 'html') && !$useHtml))
813      $attrib['checked'] = 'true';
814    else
815      unset($attrib['checked']);
816
817    $attrib['id'] = '_' . $value;
818    $rb = new radiobutton($attrib);
819    $selector .= sprintf("%s<label for=\"%s\">%s</label>",
820                         $rb->show($value),
821                         $attrib['id'],
822                         rcube_label($text));
823    }
824
825  return $selector;
826}
827
828
829function get_form_tags($attrib)
830  {
831  global $CONFIG, $OUTPUT, $MESSAGE_FORM, $SESS_HIDDEN_FIELD; 
832
833  $form_start = '';
834  if (!strlen($MESSAGE_FORM))
835    {
836    $hiddenfields = new hiddenfield(array('name' => '_task', 'value' => $GLOBALS['_task']));
837    $hiddenfields->add(array('name' => '_action', 'value' => 'send'));
838
839    $form_start = empty($attrib['form']) ? '<form name="form" action="./" method="post">' : '';
840    $form_start .= "\n$SESS_HIDDEN_FIELD\n";
841    $form_start .= $hiddenfields->show();
842    }
843   
844  $form_end = (strlen($MESSAGE_FORM) && !strlen($attrib['form'])) ? '</form>' : '';
845  $form_name = !empty($attrib['form']) ? $attrib['form'] : 'form';
846 
847  if (!strlen($MESSAGE_FORM))
848    $OUTPUT->add_gui_object('messageform', $form_name);
849 
850  $MESSAGE_FORM = $form_name;
851
852  return array($form_start, $form_end); 
853  }
854
855
856// register UI objects
857$OUTPUT->add_handlers(array(
858  'composeheaders' => 'rcmail_compose_headers',
859  'composesubject' => 'rcmail_compose_subject',
860  'composebody' => 'rcmail_compose_body',
861  'composeattachmentlist' => 'rcmail_compose_attachment_list',
862  'composeattachmentform' => 'rcmail_compose_attachment_form',
863  'composeattachment' => 'rcmail_compose_attachment_field',
864  'priorityselector' => 'rcmail_priority_selector',
865  'editorselector' => 'rcmail_editor_selector',
866  'receiptcheckbox' => 'rcmail_receipt_checkbox',
867));
868
869
870/****** get contacts for this user and add them to client scripts ********/
871
872require_once('include/rcube_contacts.inc');
873
874$CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']);
875$CONTACTS->set_pagesize(1000);
876                                   
877if ($result = $CONTACTS->list_records())
878  {       
879  $a_contacts = array();
880  while ($sql_arr = $result->iterate())
881    if ($sql_arr['email'])
882      $a_contacts[] = format_email_recipient($sql_arr['email'], JQ($sql_arr['name']));
883 
884  $OUTPUT->set_env('contacts', $a_contacts);
885  }
886
887
888parse_template('compose');
889?>
Note: See TracBrowser for help on using the repository browser.