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

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

Made automatic draft saving configurable

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