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

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

Set default spelling language (Ticket #1483938)

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