]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/sendmail.inc
Imported Upstream version 0.3.1
[roundcube.git] / program / steps / mail / sendmail.inc
1 <?php
2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/mail/sendmail.inc                                       |
6  |                                                                       |
7  | This file is part of the RoundCube Webmail client                     |
8  | Copyright (C) 2005-2009, RoundCube Dev. - Switzerland                 |
9  | Licensed under the GNU GPL                                            |
10  |                                                                       |
11  | PURPOSE:                                                              |
12  |   Compose a new mail message with all headers and attachments         |
13  |   and send it using the PEAR::Net_SMTP class or with PHP mail()       |
14  |                                                                       |
15  +-----------------------------------------------------------------------+
16  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
17  +-----------------------------------------------------------------------+
18
19  $Id: sendmail.inc 3042 2009-10-14 10:52:27Z alec $
20
21 */
22
23
24 // remove all scripts and act as called in frame
25 $OUTPUT->reset();
26 $OUTPUT->framed = TRUE;
27
28 $savedraft = !empty($_POST['_draft']) ? TRUE : FALSE;
29
30 /****** checks ********/
31
32 if (!isset($_SESSION['compose']['id'])) {
33   raise_error(array('code' => 500, 'type' => 'smtp', 'file' => __FILE__, 'message' => "Invalid compose ID"), true, false);
34   console("Sendmail error", $_SESSION['compose']);
35   $OUTPUT->show_message("An internal error occured. Please try again.", 'error');
36   $OUTPUT->send('iframe');
37 }
38
39 if (!$savedraft) {
40   if (empty($_POST['_to']) && empty($_POST['_cc']) && empty($_POST['_bcc'])
41     && empty($_POST['_subject']) && $_POST['_message']) {
42     $OUTPUT->show_message('sendingfailed', 'error');
43     $OUTPUT->send('iframe');
44   }
45
46   if(!empty($CONFIG['sendmail_delay'])) {
47     $wait_sec = time() - intval($CONFIG['sendmail_delay']) - intval($CONFIG['last_message_time']);
48     if($wait_sec < 0) {
49       $OUTPUT->show_message('senttooquickly', 'error', array('sec' => $wait_sec * -1));
50       $OUTPUT->send('iframe');
51     }
52   }
53 }
54
55
56 /****** message sending functions ********/
57
58 // encrypt parts of the header
59 function rcmail_encrypt_header($what)
60 {
61   global $CONFIG, $RCMAIL;
62   if (!$CONFIG['http_received_header_encrypt'])
63   {
64     return $what;
65   }
66   return $RCMAIL->encrypt($what);
67 }
68
69 // get identity record
70 function rcmail_get_identity($id)
71   {
72   global $USER, $OUTPUT;
73   
74   if ($sql_arr = $USER->get_identity($id))
75     {
76     $out = $sql_arr;
77     $out['mailto'] = $sql_arr['email'];
78     
79     // Special chars as defined by RFC 822 need to in quoted string (or escaped).
80     if (preg_match('/[\(\)\<\>\\\.\[\]@,;:"]/', $sql_arr['name']))
81       $name = '"' . addcslashes($sql_arr['name'], '"') . '"';
82     else
83       $name = $sql_arr['name'];
84
85     $out['string'] = rcube_charset_convert($name, RCMAIL_CHARSET, $OUTPUT->get_charset());
86     if ($sql_arr['email'])
87       $out['string'] .= ' <' . $sql_arr['email'] . '>';
88
89     return $out;
90     }
91
92   return FALSE;  
93   }
94
95 /**
96  * go from this:
97  * <img src=".../tiny_mce/plugins/emotions/images/smiley-cool.gif" border="0" alt="Cool" title="Cool" />
98  *
99  * to this:
100  *
101  * <IMG src="cid:smiley-cool.gif"/>
102  * ...
103  * ------part...
104  * Content-Type: image/gif
105  * Content-Transfer-Encoding: base64
106  * Content-ID: <smiley-cool.gif>
107  */
108 function rcmail_attach_emoticons(&$mime_message)
109 {
110   global $CONFIG;
111
112   $body = $mime_message->getHtmlBody();
113
114   // remove any null-byte characters before parsing
115   $body = preg_replace('/\x00/', '', $body);
116   
117   $searchstr = 'program/js/tiny_mce/plugins/emotions/img/';
118   $offset = 0;
119
120   // keep track of added images, so they're only added once
121   $included_images = array();
122
123   if (preg_match_all('# src=[\'"]([^\'"]+)#', $body, $matches, PREG_OFFSET_CAPTURE)) {
124     foreach ($matches[1] as $m) {
125       // find emoticon image tags
126       if (preg_match('#'.$searchstr.'(.*)$#', $m[0], $imatches)) {
127         $image_name = $imatches[1];
128
129         // sanitize image name so resulting attachment doesn't leave images dir
130         $image_name = preg_replace('/[^a-zA-Z0-9_\.\-]/i', '', $image_name);
131         $img_file = INSTALL_PATH . '/' . $searchstr . $image_name;
132
133         if (! in_array($image_name, $included_images)) {
134           // add the image to the MIME message
135           if(! $mime_message->addHTMLImage($img_file, 'image/gif', '', true, $image_name))
136             $OUTPUT->show_message("emoticonerror", 'error');
137           array_push($included_images, $image_name);
138         }
139
140         $body = substr_replace($body, $img_file, $m[1] + $offset, strlen($m[0]));
141         $offset += strlen($img_file) - strlen($m[0]);
142       }
143     }
144   }
145
146   $mime_message->setHTMLBody($body);
147
148   return $body;
149 }
150
151 // parse email address input
152 function rcmail_email_input_format($mailto)
153 {
154   global $EMAIL_FORMAT_ERROR;
155
156   $regexp = array('/[,;]\s*[\r\n]+/', '/[\r\n]+/', '/[,;]\s*$/m', '/;/', '/(\S{1})(<\S+@\S+>)/U');
157   $replace = array(', ', ', ', '', ',', '\\1 \\2');
158
159   // replace new lines and strip ending ', ', make address input more valid
160   $mailto = trim(preg_replace($regexp, $replace, $mailto));
161
162   $result = array();
163   $items = rcube_explode_quoted_string(',', $mailto);
164
165   foreach($items as $item) {
166     $item = trim($item);
167     // address in brackets without name (do nothing)
168     if (preg_match('/^<\S+@\S+>$/', $item)) {
169       $result[] = $item;
170     // address without brackets and without name (add brackets)
171     } else if (preg_match('/^\S+@\S+$/', $item)) {
172       $result[] = '<'.$item.'>';
173     // address with name (handle name)
174     } else if (preg_match('/\S+@\S+>*$/', $item, $matches)) {
175       $address = $matches[0];
176       $name = str_replace($address, '', $item);
177       $name = trim($name);
178       if ($name && ($name[0] != '"' || $name[strlen($name)-1] != '"')
179           && preg_match('/[\(\)\<\>\\\.\[\]@,;:"]/', $name)) {
180           $name = '"'.addcslashes($name, '"').'"';
181       }
182       if (!preg_match('/^<\S+@\S+>$/', $address))
183         $address = '<'.$address.'>';
184
185       $result[] = $name.' '.$address;
186       $item = $address;
187     } else if (trim($item)) {
188       continue;
189     }
190
191     // check address format
192     $item = trim($item, '<>');
193     if ($item && !check_email($item)) {
194       $EMAIL_FORMAT_ERROR = $item;
195       return;
196     }
197   }
198
199   return implode(', ', $result);
200 }
201
202 /****** compose message ********/
203
204 if (strlen($_POST['_draft_saveid']) > 3)
205   $olddraftmessageid = get_input_value('_draft_saveid', RCUBE_INPUT_POST);
206
207 $message_id = sprintf('<%s@%s>', md5(uniqid('rcmail'.mt_rand(),true)), $RCMAIL->config->mail_domain($_SESSION['imap_host']));
208
209 // set default charset
210 $input_charset = $OUTPUT->get_charset();
211 $message_charset = isset($_POST['_charset']) ? $_POST['_charset'] : $input_charset;
212
213 $EMAIL_FORMAT_ERROR = NULL;
214
215 $mailto = rcmail_email_input_format(get_input_value('_to', RCUBE_INPUT_POST, TRUE, $message_charset));
216 $mailcc = rcmail_email_input_format(get_input_value('_cc', RCUBE_INPUT_POST, TRUE, $message_charset));
217 $mailbcc = rcmail_email_input_format(get_input_value('_bcc', RCUBE_INPUT_POST, TRUE, $message_charset));
218
219 if ($EMAIL_FORMAT_ERROR) {
220   $OUTPUT->show_message('emailformaterror', 'error', array('email' => $EMAIL_FORMAT_ERROR)); 
221   $OUTPUT->send('iframe');
222 }
223
224 if (empty($mailto) && !empty($mailcc)) {
225   $mailto = $mailcc;
226   $mailcc = null;
227 }
228 else if (empty($mailto))
229   $mailto = 'undisclosed-recipients:;';
230
231 // get sender name and address
232 $from = get_input_value('_from', RCUBE_INPUT_POST, true, $message_charset);
233 $identity_arr = rcmail_get_identity($from);
234
235 if (!$identity_arr && ($from = rcmail_email_input_format($from))) {
236   if (preg_match('/(\S+@\S+)/', $from, $m))
237     $identity_arr['mailto'] = $m[1];
238 } else
239   $from = $identity_arr['mailto'];
240
241 if (empty($identity_arr['string']))
242   $identity_arr['string'] = $from;
243
244 // compose headers array
245 $headers = array();
246
247 // if configured, the Received headers goes to top, for good measure
248 if ($CONFIG['http_received_header'])
249 {
250   $nldlm = $RCMAIL->config->header_delimiter() . "\t";
251   // FROM/VIA
252   $http_header = 'from ';
253   if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
254     $host = $_SERVER['HTTP_X_FORWARDED_FOR'];
255     $hostname = gethostbyaddr($host);
256     if ($CONFIG['http_received_header_encrypt']) {
257       $http_header .= rcmail_encrypt_header($hostname);
258       if ($host != $hostname)
259         $http_header .= ' ('. rcmail_encrypt_header($host) . ')';
260     } else {
261       $http_header .= (($host != $hostname) ? $hostname : '[' . $host . ']');
262       $http_header .= ' ('. ($host == $hostname ? '' : $hostname . ' ') .
263         '[' . $host .'])';
264     }
265     $http_header .= $nldlm . ' via ';
266   }
267   $host = $_SERVER['REMOTE_ADDR'];
268   $hostname = gethostbyaddr($host);
269   if ($CONFIG['http_received_header_encrypt']) {
270     $http_header .= rcmail_encrypt_header($hostname);
271     if ($host != $hostname)
272       $http_header .= ' ('. rcmail_encrypt_header($host) . ')';
273   } else {
274     $http_header .= (($host != $hostname) ? $hostname : '[' . $host . ']');
275     $http_header .= ' ('. ($host == $hostname ? '' : $hostname . ' ') .
276       '[' . $host .'])';
277   }
278   // BY
279   $http_header .= $nldlm . 'by ' . $_SERVER['HTTP_HOST'];
280   // WITH
281   $http_header .= $nldlm . 'with ' . $_SERVER['SERVER_PROTOCOL'] .
282       ' ('.$_SERVER['REQUEST_METHOD'] . '); ' . date('r');
283   $http_header = wordwrap($http_header, 69, $nldlm);
284
285   $headers['Received'] = $http_header;
286 }
287
288 $headers['Date'] = date('r');
289 $headers['From'] = rcube_charset_convert($identity_arr['string'], RCMAIL_CHARSET, $message_charset);
290 $headers['To'] = $mailto;
291
292 // additional recipients
293 if (!empty($mailcc))
294   $headers['Cc'] = $mailcc;
295
296 if (!empty($mailbcc))
297   $headers['Bcc'] = $mailbcc;
298   
299 if (!empty($identity_arr['bcc']))
300   $headers['Bcc'] = ($headers['Bcc'] ? $headers['Bcc'].', ' : '') . $identity_arr['bcc'];
301
302 // add subject
303 $headers['Subject'] = trim(get_input_value('_subject', RCUBE_INPUT_POST, TRUE, $message_charset));
304
305 if (!empty($identity_arr['organization']))
306   $headers['Organization'] = $identity_arr['organization'];
307
308 if (!empty($_POST['_replyto']))
309   $headers['Reply-To'] = rcmail_email_input_format(get_input_value('_replyto', RCUBE_INPUT_POST, TRUE, $message_charset));
310 else if (!empty($identity_arr['reply-to']))
311   $headers['Reply-To'] = $identity_arr['reply-to'];
312
313 if (!empty($_SESSION['compose']['reply_msgid']))
314   $headers['In-Reply-To'] = $_SESSION['compose']['reply_msgid'];
315
316 if (!empty($_SESSION['compose']['references']))
317   $headers['References'] = $_SESSION['compose']['references'];
318
319 if (!empty($_POST['_priority']))
320   {
321   $priority = intval($_POST['_priority']);
322   $a_priorities = array(1=>'highest', 2=>'high', 4=>'low', 5=>'lowest');
323   if ($str_priority = $a_priorities[$priority])
324     $headers['X-Priority'] = sprintf("%d (%s)", $priority, ucfirst($str_priority));
325   }
326
327 if (!empty($_POST['_receipt']))
328   {
329   $headers['Return-Receipt-To'] = $identity_arr['string'];
330   $headers['Disposition-Notification-To'] = $identity_arr['string'];
331   }
332
333 // additional headers
334 $headers['Message-ID'] = $message_id;
335 $headers['X-Sender'] = $from;
336
337 if (!empty($CONFIG['useragent']))
338   $headers['User-Agent'] = $CONFIG['useragent'];
339
340 $isHtmlVal = strtolower(get_input_value('_is_html', RCUBE_INPUT_POST));
341 $isHtml = ($isHtmlVal == "1");
342
343 // fetch message body
344 $message_body = get_input_value('_message', RCUBE_INPUT_POST, TRUE, $message_charset);
345
346 if (!$savedraft) {
347   // remove signature's div ID
348   if ($isHtml)
349     $message_body = preg_replace('/\s*id="_rc_sig"/', '', $message_body);
350
351   // generic footer for all messages
352   if (!empty($CONFIG['generic_message_footer'])) {
353     $footer = file_get_contents(realpath($CONFIG['generic_message_footer']));
354     $footer = rcube_charset_convert($footer, RCMAIL_CHARSET, $message_charset);
355   }
356 }
357
358 // create extended PEAR::Mail_mime instance
359 $MAIL_MIME = new rcube_mail_mime($RCMAIL->config->header_delimiter());
360
361 // For HTML-formatted messages, construct the MIME message with both
362 // the HTML part and the plain-text part
363
364 if ($isHtml) {
365   $plugin = $RCMAIL->plugins->exec_hook('outgoing_message_body', array('body' => $message_body, 'type' => 'html', 'message' => $MAIL_MIME));
366   $MAIL_MIME->setHTMLBody($plugin['body'] . ($footer ? "\r\n<pre>".$footer.'</pre>' : ''));
367
368   // add a plain text version of the e-mail as an alternative part.
369   $h2t = new html2text($plugin['body'], false, true, 0);
370   $plainTextPart = rc_wordwrap($h2t->get_text(), 75, "\r\n") . ($footer ? "\r\n".$footer : '');
371   $plainTextPart = wordwrap($plainTextPart, 998, "\r\n", true);
372   if (!strlen($plainTextPart)) {
373     // empty message body breaks attachment handling in drafts 
374     $plainTextPart = "\r\n"; 
375   }
376   $plugin = $RCMAIL->plugins->exec_hook('outgoing_message_body', array('body' => $plainTextPart, 'type' => 'alternative', 'message' => $MAIL_MIME));
377   $MAIL_MIME->setTXTBody($plugin['body']);
378
379   // look for "emoticon" images from TinyMCE and copy into message as attachments
380   $message_body = rcmail_attach_emoticons($MAIL_MIME);
381 }
382 else
383   {
384   $message_body = rc_wordwrap($message_body, 75, "\r\n");
385   if ($footer)
386     $message_body .= "\r\n" . $footer;
387   $message_body = wordwrap($message_body, 998, "\r\n", true);
388   if (!strlen($message_body)) { 
389     // empty message body breaks attachment handling in drafts 
390     $message_body = "\r\n"; 
391   }
392   $plugin = $RCMAIL->plugins->exec_hook('outgoing_message_body', array('body' => $message_body, 'type' => 'plain', 'message' => $MAIL_MIME));
393   $MAIL_MIME->setTXTBody($plugin['body'], false, true);
394 }
395
396 // chose transfer encoding
397 $charset_7bit = array('ASCII', 'ISO-2022-JP', 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-15');
398 $transfer_encoding = in_array(strtoupper($message_charset), $charset_7bit) ? '7bit' : '8bit';
399
400 // add stored attachments, if any
401 if (is_array($_SESSION['compose']['attachments'])) {
402   foreach ($_SESSION['compose']['attachments'] as $id => $attachment) {
403     // This hook retrieves the attachment contents from the file storage backend
404     $attachment = $RCMAIL->plugins->exec_hook('get_attachment', $attachment);
405
406     $dispurl = '/\ssrc\s*=\s*[\'"]*\S+display-attachment\S+file=rcmfile' . preg_quote($attachment['id']) . '[\s\'"]\s*/';
407     $message_body = $MAIL_MIME->getHTMLBody();
408     if ($isHtml && (preg_match($dispurl, $message_body) > 0)) {
409       $message_body = preg_replace($dispurl, ' src="'.$attachment['name'].'" ', $message_body);
410       $MAIL_MIME->setHTMLBody($message_body);
411       
412       if ($attachment['data'])
413         $MAIL_MIME->addHTMLImage($attachment['data'], $attachment['mimetype'], $attachment['name'], false);
414       else
415         $MAIL_MIME->addHTMLImage($attachment['path'], $attachment['mimetype'], $attachment['name'], true);
416     }
417     else {
418       $ctype = str_replace('image/pjpeg', 'image/jpeg', $attachment['mimetype']); // #1484914
419       $file = $attachment['data'] ? $attachment['data'] : $attachment['path'];
420
421       // .eml attachments send inline
422       $MAIL_MIME->addAttachment($file,
423         $ctype, 
424         $attachment['name'],
425         ($attachment['data'] ? false : true),
426         ($ctype == 'message/rfc822' ? $transfer_encoding : 'base64'),
427         ($ctype == 'message/rfc822' ? 'inline' : 'attachment'),
428         $message_charset, '', '', 
429         $CONFIG['mime_param_folding'] ? 'quoted-printable' : NULL,
430         $CONFIG['mime_param_folding'] == 2 ? 'quoted-printable' : NULL
431       );
432     }
433   }
434 }
435
436 // add submitted attachments
437 if (is_array($_FILES['_attachments']['tmp_name'])) {
438   foreach ($_FILES['_attachments']['tmp_name'] as $i => $filepath) {
439     $ctype = $files['type'][$i];
440     $ctype = str_replace('image/pjpeg', 'image/jpeg', $ctype); // #1484914
441     
442     $MAIL_MIME->addAttachment($filepath, $ctype, $files['name'][$i], true,
443       $ctype == 'message/rfc822' ? $transfer_encoding : 'base64',
444       'attachment', $message_charset, '', '', 
445       $CONFIG['mime_param_folding'] ? 'quoted-printable' : NULL,
446       $CONFIG['mime_param_folding'] == 2 ? 'quoted-printable' : NULL
447     );
448   }
449 }
450
451 // encoding settings for mail composing
452 $MAIL_MIME->setParam(array(
453   'text_encoding' => $transfer_encoding,
454   'html_encoding' => 'quoted-printable',
455   'head_encoding' => 'quoted-printable',
456   'head_charset'  => $message_charset,
457   'html_charset'  => $message_charset,
458   'text_charset'  => $message_charset,
459 ));
460
461 $data = $RCMAIL->plugins->exec_hook('outgoing_message_headers', array('headers' => $headers));
462 $headers = $data['headers'];
463
464 // encoding subject header with mb_encode provides better results with asian characters
465 if (function_exists("mb_encode_mimeheader"))
466 {
467   mb_internal_encoding($message_charset);
468   $headers['Subject'] = mb_encode_mimeheader($headers['Subject'], $message_charset, 'Q');
469   mb_internal_encoding(RCMAIL_CHARSET);
470 }
471
472 // pass headers to message object
473 $MAIL_MIME->headers($headers);
474
475 // Begin SMTP Delivery Block 
476 if (!$savedraft)
477 {
478   // check for 'From' address (identity may be incomplete)
479   if ($identity_arr && !$identity_arr['mailto']) {
480     $OUTPUT->show_message('nofromaddress', 'error');
481     $OUTPUT->send('iframe'); 
482   }
483
484   $sent = rcmail_deliver_message($MAIL_MIME, $from, $mailto, $smtp_error);
485   
486   // return to compose page if sending failed
487   if (!$sent)
488     {
489     if ($smtp_error)
490       $OUTPUT->show_message($smtp_error['label'], 'error', $smtp_error['vars']); 
491     else
492       $OUTPUT->show_message('sendingfailed', 'error'); 
493     $OUTPUT->send('iframe');
494     }
495
496   // save message sent time
497   if (!empty($CONFIG['sendmail_delay']))
498     $RCMAIL->user->save_prefs(array('last_message_time' => time()));
499   
500   // set replied/forwarded flag
501   if ($_SESSION['compose']['reply_uid'])
502     $IMAP->set_flag($_SESSION['compose']['reply_uid'], 'ANSWERED', $_SESSION['compose']['mailbox']);
503   else if ($_SESSION['compose']['forward_uid'])
504     $IMAP->set_flag($_SESSION['compose']['forward_uid'], 'FORWARDED', $_SESSION['compose']['mailbox']);
505
506 } // End of SMTP Delivery Block
507
508
509
510 // Determine which folder to save message
511 if ($savedraft)
512   $store_target = $CONFIG['drafts_mbox'];
513 else    
514   $store_target = isset($_POST['_store_target']) ? get_input_value('_store_target', RCUBE_INPUT_POST) : $CONFIG['sent_mbox'];
515
516 if ($store_target)
517   {
518   // check if mailbox exists
519   if (!in_array_nocase($store_target, $IMAP->list_mailboxes()))
520     {
521       // folder may be existing but not subscribed (#1485241)
522       if (!in_array_nocase($store_target, $IMAP->list_unsubscribed()))
523         $store_folder = $IMAP->create_mailbox($store_target, TRUE);
524       else if ($IMAP->subscribe($store_target))
525         $store_folder = TRUE;
526     }
527   else
528     $store_folder = TRUE;
529   
530   // append message to sent box
531   if ($store_folder)
532     $saved = $IMAP->save_message($store_target, $MAIL_MIME->getMessage());
533
534   // raise error if saving failed
535   if (!$saved)
536     {
537     raise_error(array('code' => 800, 'type' => 'imap', 'file' => __FILE__,
538                       'message' => "Could not save message in $store_target"), TRUE, FALSE);
539     
540     if ($savedraft) {
541       $OUTPUT->show_message('errorsaving', 'error');
542       $OUTPUT->send('iframe');
543       }
544     }
545
546   if ($olddraftmessageid)
547     {
548     // delete previous saved draft
549     $a_deleteid = $IMAP->search($CONFIG['drafts_mbox'], 'HEADER Message-ID '.$olddraftmessageid);
550
551     $deleted = $IMAP->delete_message($IMAP->get_uid($a_deleteid[0], $CONFIG['drafts_mbox']), $CONFIG['drafts_mbox']);
552
553     // raise error if deletion of old draft failed
554     if (!$deleted)
555       raise_error(array('code' => 800, 'type' => 'imap', 'file' => __FILE__,
556                         'message' => "Could not delete message from ".$CONFIG['drafts_mbox']), TRUE, FALSE);
557     }
558   }
559
560 if ($savedraft)
561   {
562   $msgid = strtr($message_id, array('>' => '', '<' => ''));
563   
564   // remember new draft-uid
565   $draftids = $IMAP->search($CONFIG['drafts_mbox'], 'HEADER Message-ID '.$msgid);
566   $_SESSION['compose']['param']['_draft_uid'] = $IMAP->get_uid($draftids[0], $CONFIG['drafts_mbox']);
567
568   // display success
569   $OUTPUT->show_message('messagesaved', 'confirmation');
570
571   // update "_draft_saveid" and the "cmp_hash" to prevent "Unsaved changes" warning
572   $OUTPUT->command('set_draft_id', $msgid);
573   $OUTPUT->command('compose_field_hash', true);
574
575   // start the auto-save timer again
576   $OUTPUT->command('auto_save_start');
577
578   $OUTPUT->send('iframe');
579   }
580 else
581   {
582   rcmail_compose_cleanup();
583
584   if ($store_folder && !$saved)
585     $OUTPUT->command('sent_successfully', 'error', rcube_label('errorsavingsent'));
586   else
587     $OUTPUT->command('sent_successfully', 'confirmation', rcube_label('messagesent'));
588   $OUTPUT->send('iframe');
589   }
590
591 ?>