source: subversion/trunk/roundcubemail/program/steps/mail/compose.inc @ 938

Last change on this file since 938 was 938, checked in by thomasb, 5 years ago

New class rcube_user + send message disposition notification

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