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

Last change on this file since 419 was 419, checked in by thomasb, 6 years ago

New (strict) quoting for all kind of strings

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