PageRenderTime 5ms CodeModel.GetById 46ms app.highlight 59ms RepoModel.GetById 1ms app.codeStats 1ms

/imp-h3-4.3.10/compose.php

#
PHP | 1258 lines | 1071 code | 114 blank | 73 comment | 267 complexity | a2aa81daf4ac381aa5c8847927e2a0c5 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2/**
   3 * $Horde: imp/compose.php,v 2.800.2.130 2009/12/16 21:56:13 jan Exp $
   4 *
   5 * Copyright 1999-2009 The Horde Project (http://www.horde.org/)
   6 *
   7 * See the enclosed file COPYING for license information (GPL). If you
   8 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
   9 *
  10 * @author Chuck Hagenbuch <chuck@horde.org>
  11 * @author Michael Slusarz <slusarz@horde.org>
  12 */
  13
  14function _mailboxReturnURL($encode, $url = null)
  15{
  16    if (empty($url)) {
  17        $url = Horde::applicationUrl('mailbox.php');
  18    }
  19
  20    foreach (array('start', 'page', 'mailbox', 'thismailbox') as $key) {
  21        if (($param = Util::getFormData($key))) {
  22            $url = Util::addParameter($url, $key, $param, $encode);
  23        }
  24    }
  25
  26    return $url;
  27}
  28
  29function _popupSuccess()
  30{
  31    require_once 'Horde/Menu.php';
  32    $menu = new Menu(HORDE_MENU_MASK_NONE);
  33    $menu->add(Horde::applicationUrl('compose.php'), _("New Message"), 'compose.png');
  34    $menu->add('', _("Close this window"), 'close.png', $GLOBALS['registry']->getImageDir('horde'), '', 'window.close();');
  35    require IMP_TEMPLATES . '/common-header.inc';
  36    $success_template = new IMP_Template();
  37    $success_template->set('menu', $menu->render());
  38    echo $success_template->fetch(IMP_TEMPLATES . '/compose/success.html');
  39    IMP::status();
  40    require $GLOBALS['registry']->get('templates', 'horde') . '/common-footer.inc';
  41}
  42
  43function &_getIMPContents($index, $mailbox)
  44{
  45    $res = false;
  46    if (empty($index)) {
  47        return $res;
  48    }
  49    require_once IMP_BASE . '/lib/MIME/Contents.php';
  50    $imp_contents = &IMP_Contents::singleton($index . IMP_IDX_SEP . $mailbox);
  51    if (is_a($imp_contents, 'PEAR_Error')) {
  52        $GLOBALS['notification']->push(_("Could not retrieve the message from the mail server."), 'horde.error');
  53        return $res;
  54    }
  55    return $imp_contents;
  56}
  57
  58
  59@define('IMP_BASE', dirname(__FILE__));
  60$session_control = 'netscape';
  61require_once IMP_BASE . '/lib/base.php';
  62require_once IMP_BASE . '/lib/Compose.php';
  63require_once IMP_BASE . '/lib/Template.php';
  64require_once 'Horde/Help.php';
  65require_once 'Horde/Identity.php';
  66require_once 'Horde/MIME/Part.php';
  67require_once 'Horde/Text/Filter.php';
  68
  69/* The message text. */
  70$msg = '';
  71
  72/* The headers of the message. */
  73$header = array(
  74    'in_reply_to' => Util::getFormData('in_reply_to'),
  75    'references' => Util::getFormData('references')
  76);
  77
  78$get_sig = true;
  79$pgp_passphrase_dialog = $pgp_symmetric_passphrase_dialog = $showmenu = $smime_passphrase_dialog = false;
  80$cursor_pos = $oldrtemode = $rtemode = $siglocation = null;
  81
  82/* Set the current identity. */
  83$identity = &Identity::singleton(array('imp', 'imp'));
  84if (!$prefs->isLocked('default_identity')) {
  85    $identity_id = Util::getFormData('identity');
  86    if (!is_null($identity_id)) {
  87        $identity->setDefault($identity_id);
  88    }
  89}
  90
  91/* Catch submits if javascript is not present. */
  92if (!($actionID = Util::getFormData('actionID'))) {
  93    foreach (array('send_message', 'save_draft', 'cancel_compose', 'add_attachment', 'compose_expand_addr') as $val) {
  94        if (Util::getFormData('btn_' . $val)) {
  95            $actionID = $val;
  96            break;
  97        }
  98    }
  99}
 100
 101if ($actionID) {
 102    switch ($actionID) {
 103    case 'mailto':
 104    case 'mailto_link':
 105    case 'draft':
 106    case 'reply':
 107    case 'reply_all':
 108    case 'reply_list':
 109    case 'forward_all':
 110    case 'forward_body':
 111    case 'forward_attachments':
 112    case 'redirect_compose':
 113    case 'fwd_digest':
 114    case 'recompose':
 115        // These are all safe actions that might be invoked without a token.
 116        break;
 117
 118    default:
 119        $result = IMP::checkRequestToken('imp.compose', Util::getFormData('compose_requestToken'));
 120        if (is_a($result, 'PEAR_Error')) {
 121            $notification->push($result);
 122            $actionID = null;
 123        }
 124    }
 125}
 126
 127$sent_mail_folder = $identity->getValue('sent_mail_folder');
 128$index = Util::getFormData('index');
 129$reply_index = Util::getFormData('reply_index');
 130$thismailbox = Util::getFormData('thismailbox');
 131
 132/* Check for duplicate submits. */
 133require_once 'Horde/Token.php';
 134if (isset($conf['token'])) {
 135    /* If there is a configured token system, set it up. */
 136    $tokenSource = Horde_Token::factory(
 137        $conf['token']['driver'],
 138        Horde::getDriverConfig('token', $conf['token']['driver']));
 139} else {
 140    /* Default to the file system if no config. */
 141    $tokenSource = Horde_Token::factory('file');
 142}
 143if ($token = Util::getFormData('compose_formToken')) {
 144    $verified = $tokenSource->verify($token);
 145    /* Notify and reset the actionID. */
 146    if (is_a($verified, 'PEAR_Error')) {
 147        $notification->push($verified);
 148        $actionID = null;
 149    } elseif (!$verified) {
 150        $notification->push(_("You have already submitted this page."), 'horde.error');
 151        $actionID = null;
 152    }
 153}
 154
 155/* Set the current time zone. */
 156NLS::setTimeZone();
 157
 158/* Initialize the IMP_Compose:: object. */
 159$imp_compose = &IMP_Compose::singleton(Util::getFormData('messageCache'));
 160$imp_compose->pgpAttachPubkey((bool) Util::getFormData('pgp_attach_pubkey'));
 161$imp_compose->userLinkAttachments((bool) Util::getFormData('link_attachments'));
 162$imp_compose->attachVCard((bool) Util::getFormData('vcard'), $identity->getValue('fullname'));
 163
 164/* Init IMP_UI_Compose:: object. */
 165require_once IMP_BASE . '/lib/UI/Compose.php';
 166$imp_ui = new IMP_UI_Compose();
 167
 168/* Set the default charset & encoding.
 169 * $charset - charset to use when sending messages
 170 * $encoding - best guessed charset offered to the user as the default value in
 171 *             the charset dropdown list. */
 172if ($prefs->isLocked('sending_charset')) {
 173    $charset = NLS::getEmailCharset();
 174} else {
 175    $charset = Util::getFormData('charset');
 176}
 177$encoding = empty($charset) ? NLS::getEmailCharset() : $charset;
 178
 179/* Is this a popup window? */
 180$has_js = $browser->hasFeature('javascript');
 181$isPopup = (($prefs->getValue('compose_popup') || Util::getFormData('popup')) && $has_js);
 182
 183/* Determine the composition type - text or HTML.
 184   $rtemode is null if browser does not support it. */
 185$rtemode = null;
 186if ($browser->hasFeature('rte')) {
 187    if ($prefs->isLocked('compose_html')) {
 188        $rtemode = $prefs->getValue('compose_html');
 189    } else {
 190        $rtemode = Util::getFormData('rtemode');
 191        if (is_null($rtemode)) {
 192            $rtemode = $prefs->getValue('compose_html');
 193        } else {
 194            $oldrtemode = Util::getFormData('oldrtemode');
 195            $get_sig = false;
 196        }
 197    }
 198}
 199
 200/* Load stationery. */
 201$stationery_list = array();
 202if (!$prefs->isLocked('stationery')) {
 203    $stationery = null;
 204    $all_stationery = @unserialize($prefs->getValue('stationery', false));
 205    if (is_array($all_stationery)) {
 206        $all_stationery = String::convertCharset($all_stationery, $prefs->getCharset());
 207        foreach ($all_stationery as $id => $choice) {
 208            if (($choice['t'] == 'plain') ||
 209                (($choice['t'] == 'html') && $rtemode)) {
 210                if ($rtemode && $choice['t'] == 'plain') {
 211                    $choice['c'] = $imp_compose->text2html($choice['c']);
 212                }
 213                $stationery_list[$id] = $choice;
 214            }
 215        }
 216    }
 217}
 218
 219/* Update the file attachment information. */
 220if ($_SESSION['imp']['file_upload']) {
 221    /* Only notify if we are reloading the compose screen. */
 222    $notify = ($actionID != 'send_message') && ($actionID != 'save_draft');
 223
 224    $deleteList = Util::getPost('delattachments', array());
 225
 226    /* Update the attachment information. */
 227    foreach (array_keys($imp_compose->getAttachments()) as $i) {
 228        if (!in_array($i, $deleteList)) {
 229            $disposition = Util::getFormData('file_disposition_' . $i);
 230            $description = Util::getFormData('file_description_' . $i);
 231            $imp_compose->updateAttachment($i, array('disposition' => $disposition, 'description' => $description));
 232        }
 233    }
 234
 235    /* Delete attachments. */
 236    if (!empty($deleteList)) {
 237        $filenames = $imp_compose->deleteAttachment($deleteList);
 238        if ($notify) {
 239            foreach ($filenames as $val) {
 240                $notification->push(sprintf(_("Deleted the attachment \"%s\"."), MIME::decode($val)), 'horde.success');
 241            }
 242        }
 243    }
 244
 245    /* Add new attachments. */
 246    if (!$imp_compose->addFilesFromUpload('upload_', 'upload_disposition_', $notify)) {
 247        $actionID = null;
 248    }
 249}
 250
 251/* Run through the action handlers. */
 252$reply_type = null;
 253$title = _("New Message");
 254switch ($actionID) {
 255case 'recompose':
 256    // Extract the stored form data.
 257    $formData = @unserialize($_SESSION['recompose_formData']);
 258    unset($_SESSION['recompose_formData']);
 259
 260    if (!empty($formData['post'])) {
 261        $_POST = $formData['post'];
 262    }
 263    if (!empty($formData['get'])) {
 264        $_GET = $formData['get'];
 265    }
 266
 267    $get_sig = false;
 268    break;
 269
 270case 'mailto':
 271    if (!($imp_contents = &_getIMPContents($index, $thismailbox))) {
 272        break;
 273    }
 274    $imp_headers = &$imp_contents->getHeaderOb();
 275    $header['to'] = '';
 276    if (Util::getFormData('mailto')) {
 277        $header['to'] = $imp_headers->getValue('to');
 278    }
 279    if (empty($header['to'])) {
 280        ($header['to'] = MIME::addrArray2String($imp_headers->getOb('from'))) ||
 281        ($header['to'] = MIME::addrArray2String($imp_headers->getOb('reply-to')));
 282    }
 283    break;
 284
 285case 'mailto_link':
 286    $args = IMP::getComposeArgs();
 287    if (isset($args['body'])) {
 288        $msg = $args['body'];
 289    }
 290    foreach (array('to', 'cc', 'bcc', 'subject') as $val) {
 291        if (isset($args[$val])) {
 292            $header[$val] = $args[$val];
 293        }
 294    }
 295    break;
 296
 297case 'draft':
 298    $result = $imp_compose->resumeDraft($index . IMP_IDX_SEP . $thismailbox);
 299    if (is_a($result, 'PEAR_Error')) {
 300        $notification->push($result->getMessage(), 'horde.error');
 301    } else {
 302        if (!is_null($rtemode)) {
 303            $rtemode = ($result['mode'] == 'html');
 304        }
 305        $msg = $result['msg'];
 306        $header = array_merge($header, $result['header']);
 307        if (!is_null($result['identity']) &&
 308            ($result['identity'] != $identity->getDefault()) &&
 309            !$prefs->isLocked('default_identity')) {
 310            $identity->setDefault($result['identity']);
 311            $sent_mail_folder = $identity->getValue('sent_mail_folder');
 312        }
 313        if (isset($result['header']['references'])) {
 314            $reply_type = 'reply';
 315        }
 316    }
 317    $get_sig = false;
 318    break;
 319
 320case 'compose_expand_addr':
 321case 'redirect_expand_addr':
 322    $header['to'] = $imp_ui->expandAddresses(Util::getFormData('to'), $imp_compose);
 323    if ($actionID == 'compose_expand_addr') {
 324        $header['cc'] = $imp_ui->expandAddresses(Util::getFormData('cc'), $imp_compose);
 325        $header['bcc'] = $imp_ui->expandAddresses(Util::getFormData('bcc'), $imp_compose);
 326    }
 327    $get_sig = false;
 328    break;
 329
 330case 'reply':
 331case 'reply_all':
 332case 'reply_list':
 333    if (!($imp_contents = &_getIMPContents($index, $thismailbox))) {
 334        break;
 335    }
 336
 337    $reply_msg = $imp_compose->replyMessage($actionID, $imp_contents, Util::getFormData('to'));
 338    $msg = $reply_msg['body'];
 339    $header = $reply_msg['headers'];
 340    $format = $reply_msg['format'];
 341
 342    if (!is_null($rtemode)) {
 343        $rtemode = $rtemode || $format == 'html';
 344    }
 345
 346    if ($actionID == 'reply') {
 347        $title = _("Reply:");
 348    } elseif ($actionID == 'reply_all') {
 349        $title = _("Reply to All:");
 350    } elseif ($actionID == 'reply_list') {
 351        $title = _("Reply to List:");
 352    }
 353    $title .= ' ' . $header['subject'];
 354
 355    $encoding = empty($charset) ? $header['encoding'] : $charset;
 356    $reply_index = $index;
 357    break;
 358
 359case 'forward_all':
 360case 'forward_body':
 361case 'forward_attachments':
 362    if (!($imp_contents = &_getIMPContents($index, $thismailbox))) {
 363        break;
 364    }
 365
 366    $fwd_msg = $imp_ui->getForwardData($imp_compose, $imp_contents, $actionID, $index . IMP_IDX_SEP . $thismailbox);
 367    if ($actionID == 'forward_all') {
 368        $msg = '';
 369    } else {
 370        $msg = $fwd_msg['body'];
 371    }
 372    $header = $fwd_msg['headers'];
 373    $format = $fwd_msg['format'];
 374    $rtemode = ($rtemode || (!is_null($rtemode) && ($format == 'html')));
 375    $title = $header['title'];
 376    $encoding = empty($charset) ? $header['encoding'] : $charset;
 377    break;
 378
 379case 'redirect_compose':
 380    $title = _("Redirect this message");
 381    break;
 382
 383case 'redirect_send':
 384    if (!($imp_contents = &_getIMPContents($index, $thismailbox))) {
 385        break;
 386    }
 387
 388    $f_to = Util::getFormData('to', $imp_ui->getAddressList(Util::getFormData('to'), Util::getFormData('to_list'), Util::getFormData('to_field'), Util::getFormData('to_new')));
 389
 390    $result = $imp_ui->redirectMessage($f_to, $imp_compose, $imp_contents, $encoding);
 391    if (!is_a($result, 'PEAR_Error')) {
 392        if ($isPopup) {
 393            if ($prefs->getValue('compose_confirm')) {
 394                $notification->push(_("Message redirected successfully."), 'horde.success');
 395                _popupSuccess();
 396            } else {
 397                Util::closeWindowJS();
 398            }
 399        } else {
 400            if ($prefs->getValue('compose_confirm')) {
 401                $notification->push(_("Message redirected successfully."), 'horde.success');
 402            }
 403            header('Location: ' . _mailboxReturnURL(false));
 404        }
 405        exit;
 406    }
 407    $notification->push($result, 'horde.error');
 408    $actionID = 'redirect_compose';
 409    $get_sig = false;
 410    break;
 411
 412case 'send_message':
 413    $from = $identity->getFromLine(null, Util::getFormData('from'));
 414    if (is_a($from, 'PEAR_Error')) {
 415        $get_sig = false;
 416        $notification->push($from);
 417        break;
 418    }
 419    $header['from'] = $from;
 420    $header['replyto'] = $identity->getValue('replyto_addr');
 421
 422    $header['to'] = $imp_ui->getAddressList(Util::getFormData('to'), Util::getFormData('to_list'), Util::getFormData('to_field'), Util::getFormData('to_new'));
 423    if ($prefs->getValue('compose_cc')) {
 424        $header['cc'] = $imp_ui->getAddressList(Util::getFormData('cc'), Util::getFormData('cc_list'), Util::getFormData('cc_field'), Util::getFormData('cc_new'));
 425    }
 426    if ($prefs->getValue('compose_bcc')) {
 427        $header['bcc'] = $imp_ui->getAddressList(Util::getFormData('bcc'), Util::getFormData('bcc_list'), Util::getFormData('bcc_field'), Util::getFormData('bcc_new'));
 428    }
 429
 430    $message = Util::getFormData('message');
 431    $header['subject'] = Util::getFormData('subject', '');
 432    if ($smf = Util::getFormData('sent_mail_folder')) {
 433        $sent_mail_folder = $smf;
 434    }
 435
 436    $options = array(
 437        'save_sent' => Util::getFormData('save_sent_mail'),
 438        'sent_folder' => $sent_mail_folder,
 439        'save_attachments' => Util::getFormData('save_attachments_select'),
 440        'reply_type' => Util::getFormData('reply_type'),
 441        'reply_index' => (empty($reply_index) ? null : $reply_index . IMP_IDX_SEP . $thismailbox),
 442        'encrypt' => $prefs->isLocked('default_encrypt') ? $prefs->getValue('default_encrypt') : Util::getFormData('encrypt_options'),
 443        'priority' => Util::getFormData('x_priority'),
 444        'readreceipt' => Util::getFormData('request_read_receipt')
 445    );
 446    $sent = $imp_compose->buildAndSendMessage($message, $header, $charset, $rtemode, $options);
 447
 448    if (is_a($sent, 'PEAR_Error')) {
 449        $get_sig = false;
 450        $code = $sent->getCode();
 451        $notification->push($sent, strpos($code, 'horde.') === 0 ? $code : 'horde.error');
 452        if ($sent->getUserInfo() == 'pgp_symmetric_passphrase_dialog') {
 453            $pgp_symmetric_passphrase_dialog = true;
 454        } elseif ($sent->getUserInfo() == 'pgp_passphrase_dialog') {
 455            $pgp_passphrase_dialog = true;
 456        } elseif ($sent->getUserInfo() == 'smime_passphrase_dialog') {
 457            $smime_passphrase_dialog = true;
 458        }
 459        break;
 460    }
 461
 462    if ($isPopup) {
 463        if ($prefs->getValue('compose_confirm') || !$sent) {
 464            if ($sent) {
 465                $notification->push(_("Message sent successfully."), 'horde.success');
 466            }
 467            _popupSuccess();
 468        } else {
 469            Util::closeWindowJS();
 470        }
 471    } else {
 472        if ($prefs->getValue('compose_confirm') && $sent) {
 473            $notification->push(_("Message sent successfully."), 'horde.success');
 474        }
 475        header('Location: ' . _mailboxReturnURL(false));
 476    }
 477    exit;
 478
 479case 'save_draft':
 480    /* Set up the From address based on the identity. */
 481    $header['from'] = $identity->getFromLine(null, Util::getFormData('from'));
 482    if (is_a($header['from'], 'PEAR_Error')) {
 483        $get_sig = false;
 484        $notification->push($header['from']);
 485        break;
 486    }
 487    foreach (array('to', 'cc', 'bcc', 'subject') as $val) {
 488        $header[$val] = Util::getFormData($val);
 489    }
 490    $message = Util::getFormData('message', '');
 491
 492    /* Save the draft. */
 493    $result = $imp_compose->saveDraft($header, $message, NLS::getCharset(), $rtemode);
 494    if (is_a($result, 'PEAR_Error')) {
 495        $notification->push($result->getMessage(), 'horde.error');
 496    } else {
 497        /* Closing draft if requested by preferences. */
 498        if ($isPopup) {
 499            if ($prefs->getValue('close_draft')) {
 500                Util::closeWindowJS();
 501            } else {
 502                $notification->push($result, 'horde.success');
 503                break;
 504            }
 505        } else {
 506            $notification->push($result);
 507            header('Location: ' . _mailboxReturnURL(false));
 508        }
 509        exit;
 510    }
 511
 512    $get_sig = false;
 513    break;
 514
 515case 'fwd_digest':
 516    $indices = Util::getFormData('fwddigest');
 517    if (!empty($indices)) {
 518        $msglist = unserialize(urldecode($indices));
 519        $imp_compose->attachIMAPMessage($msglist, $header);
 520    }
 521    break;
 522
 523case 'cancel_compose':
 524    $imp_compose->deleteAllAttachments();
 525    if ($isPopup) {
 526        Util::closeWindowJS();
 527    } else {
 528        header('Location: ' . _mailboxReturnURL(false));
 529    }
 530    exit;
 531
 532case 'selectlist_process':
 533    $select_id = Util::getFormData('selectlist_selectid');
 534    if (!empty($select_id)) {
 535        if ($registry->hasMethod('files/selectlistResults') &&
 536            $registry->hasMethod('files/returnFromSelectlist')) {
 537            $filelist = $registry->call('files/selectlistResults', array($select_id));
 538            if ($filelist && !is_a($filelist, 'PEAR_Error')) {
 539                $i = 0;
 540                foreach ($filelist as $val) {
 541                    $data = $registry->call('files/returnFromSelectlist', array($select_id, $i++));
 542                    if ($data && !is_a($data, 'PEAR_Error')) {
 543                        $part = new MIME_Part();
 544                        $part->setContents($data);
 545                        $part->setName(reset($val));
 546                        $res = $imp_compose->addMIMEPartAttachment($part);
 547                        if (is_a($res, 'PEAR_Error')) {
 548                            $notification->push($res, 'horde.error');
 549                        }
 550                    }
 551                }
 552            }
 553        }
 554    }
 555    break;
 556
 557case 'change_stationery':
 558    if (empty($stationery_list)) {
 559        break;
 560    }
 561    $stationery = Util::getFormData('stationery');
 562    if (strlen($stationery)) {
 563        $stationery = (int)$stationery;
 564        $stationery_content = $stationery_list[$stationery]['c'];
 565        $msg = Util::getFormData('message', '');
 566        if (strpos($stationery_content, '%s') !== false) {
 567            $sig = $identity->getSignature();
 568            if ($rtemode) {
 569                $sig = $imp_compose->text2html($sig);
 570                $stationery_content = $imp_compose->text2html($stationery_content);
 571            }
 572            $msg = str_replace(array("\r\n", $sig), array("\n", ''), $msg);
 573            $stationery_content = str_replace('%s', $sig, $stationery_content);
 574        }
 575        if (strpos($stationery_content, '%c') === false) {
 576            $msg .= $stationery_content;
 577        } else {
 578            $msg = str_replace('%c', $msg, $stationery_content);
 579        }
 580    }
 581    $get_sig = false;
 582    break;
 583
 584case 'add_attachment':
 585    $get_sig = false;
 586    break;
 587}
 588
 589/* Get the message cache ID. */
 590$messageCacheID = $imp_compose->getMessageCacheId();
 591
 592/* Has this page been reloaded? */
 593$reloaded = Util::getFormData('reloaded');
 594
 595/* Are we in redirect mode? */
 596$redirect = in_array($actionID, array('redirect_compose', 'redirect_expand_addr'));
 597
 598/* Attach autocompleters to the compose form elements. */
 599$spellcheck = false;
 600if ($has_js) {
 601    require_once IMP_BASE . '/lib/Imple.php';
 602    if ($redirect) {
 603        $imp_ui->attachAutoCompleter('Imple', array('to'));
 604    } else {
 605        $auto_complete = array('to');
 606        foreach (array('cc', 'bcc') as $val) {
 607            if ($prefs->getValue('compose_' . $val)) {
 608                $auto_complete[] = $val;
 609            }
 610        }
 611        $imp_ui->attachAutoCompleter('Imple', $auto_complete);
 612        if (!empty($conf['spell']['driver'])) {
 613            require_once IMP_BASE . '/lib/SpellChecker.php';
 614            if (IMP_SpellChecker::factory($conf['spell']['driver'], array()) !== false) {
 615                $spellcheck = true;
 616                $imp_ui->attachSpellChecker('imp', true);
 617            }
 618        }
 619        if ($browser->isBrowser('msie')) {
 620            Horde::addScriptFile('ieEscGuard.js', 'imp', true);
 621        }
 622    }
 623}
 624
 625$max_attach = $imp_compose->additionalAttachmentsAllowed();
 626$smf_check = !empty($conf['user']['select_sentmail_folder']) && !$prefs->isLocked('sent_mail_folder');
 627
 628/* Get the URL to use for the cancel action. */
 629$cancel_url = '';
 630if ($isPopup) {
 631    /* If the attachments cache is not empty, we must reload this page
 632     * and delete the attachments. */
 633    if ($imp_compose->numberOfAttachments()) {
 634        $cancel_url = Util::addParameter(Horde::selfUrl(), array('actionID' => 'cancel_compose', 'messageCache' => $messageCacheID, 'popup' => 1), null, false);
 635    }
 636} else {
 637    /* If the attachments cache is not empty, we must reload this page and
 638       delete the attachments. */
 639    if ($imp_compose->numberOfAttachments()) {
 640        $cancel_url = Util::addParameter(_mailboxReturnURL(true, Horde::selfUrl()), array('actionID' => 'cancel_compose', 'messageCache' => $messageCacheID), null, false);
 641    } else {
 642        $cancel_url = _mailboxReturnURL(true);
 643    }
 644    $showmenu = true;
 645}
 646
 647/* Grab any data that we were supplied with. */
 648if (empty($msg)) {
 649    $msg = Util::getFormData('message', Util::getFormData('body', ''));
 650    if ($browser->hasQuirk('double_linebreak_textarea')) {
 651        $msg = preg_replace('/(\r?\n){3}/', '$1', $msg);
 652    }
 653    $msg = "\n" . $msg;
 654}
 655
 656/* Get the current signature. */
 657$sig = $identity->getSignature();
 658
 659/* Convert from Text -> HTML or vice versa if RTE mode changed. */
 660if (!is_null($oldrtemode) && ($oldrtemode != $rtemode)) {
 661    if ($rtemode) {
 662        /* Try to find the signature, replace it with a placeholder,
 663         * HTML-ize the message, then replace the signature
 664         * placeholder with the HTML-ized signature, complete with
 665         * marker comment. */
 666        $msg = preg_replace('/' . preg_replace('/(?<!^)\s+/', '\\s+', preg_quote($sig, '/')) . '/', '##IMP_SIGNATURE##', $msg, 1);
 667        $msg = preg_replace('/\s+##IMP_SIGNATURE##/', '##IMP_SIGNATURE_WS####IMP_SIGNATURE##', $msg);
 668        $msg = $imp_compose->text2html($msg);
 669        $msg = str_replace(array('##IMP_SIGNATURE_WS##', '##IMP_SIGNATURE##'),
 670                           array('<p>&nbsp;</p>', '<p class="imp-signature"><!--begin_signature-->' . $imp_compose->text2html($sig) . '<!--end_signature--></p>'),
 671                           $msg);
 672    } else {
 673        $msg = Text_Filter::filter($msg, 'html2text');
 674    }
 675}
 676
 677/* If this is the first page load for this compose item, add auto BCC
 678 * addresses. */
 679if (!$reloaded && ($actionID != 'draft')) {
 680    $header['bcc'] = MIME::addrArray2String($identity->getBccAddresses());
 681}
 682
 683foreach (array('to', 'cc', 'bcc', 'subject') as $val) {
 684    if (!isset($header[$val])) {
 685        $header[$val] = Util::getFormData($val, $imp_ui->getAddressList(Util::getFormData($val), Util::getFormData($val . '_list'), Util::getFormData($val . '_field'), Util::getFormData($val . '_new')));
 686    }
 687}
 688
 689if ($get_sig && isset($msg) && !empty($sig)) {
 690    if ($rtemode) {
 691        $sig = '<p>&nbsp;</p><p class="imp-signature"><!--begin_signature-->' . $imp_compose->text2html(trim($sig)) . '<!--end_signature--></p>';
 692    }
 693
 694    if ($identity->getValue('sig_first')) {
 695        $siglocation = 0;
 696        $msg = "\n" . $sig . $msg;
 697    } else {
 698        $siglocation = String::length($msg);
 699        /* We always add a line break at the beginning, so if length is 1,
 700           ignore that line break (i.e. the message is empty). */
 701        if ($siglocation == 1) {
 702            $siglocation = 0;
 703        }
 704        $msg .= "\n" . $sig;
 705    }
 706}
 707
 708/* Open the passphrase window here. */
 709if ($pgp_passphrase_dialog || $pgp_symmetric_passphrase_dialog) {
 710    require_once IMP_BASE .'/lib/Crypt/PGP.php';
 711    $imp_pgp = new IMP_PGP();
 712    Horde::addScriptFile('popup.js', 'imp', true);
 713    $notification->push($imp_pgp->getJSOpenWinCode($pgp_symmetric_passphrase_dialog ? 'open_symmetric_passphrase_dialog' : 'open_passphrase_dialog', "opener.focus();opener.uniqSubmit('send_message');"), 'javascript');
 714} elseif ($smime_passphrase_dialog) {
 715    require_once IMP_BASE .'/lib/Crypt/SMIME.php';
 716    $imp_smime = new IMP_SMIME();
 717    Horde::addScriptFile('popup.js', 'imp', true);
 718    $notification->push($imp_smime->getJSOpenWinCode('open_passphrase_dialog', "opener.focus();opener.uniqSubmit('send_message');"), 'javascript');
 719}
 720
 721/* If PGP encryption is set by default, and we have a recipient list on first
 722 * load, make sure we have public keys for all recipients. */
 723$encrypt_options = $prefs->isLocked('default_encrypt')
 724      ? $prefs->getValue('default_encrypt')
 725      : Util::getFormData('encrypt_options');
 726if ($prefs->getValue('use_pgp') && !$prefs->isLocked('default_encrypt')) {
 727    $default_encrypt = $prefs->getValue('default_encrypt');
 728    if (!$reloaded &&
 729        in_array($default_encrypt, array(IMP_PGP_ENCRYPT, IMP_PGP_SIGNENC))) {
 730        $addrs = $imp_compose->recipientList($header);
 731        if (!is_a($addrs, 'PEAR_Error') && !empty($addrs['list'])) {
 732            require_once IMP_BASE .'/lib/Crypt/PGP.php';
 733            $imp_pgp = new IMP_PGP();
 734            foreach ($addrs['list'] as $val) {
 735                $res = $imp_pgp->getPublicKey($val);
 736                if (is_a($res, 'PEAR_Error')) {
 737                    $notification->push(_("PGP encryption cannot be used by default as public keys cannot be found for all recipients."), 'horde.warning');
 738                    $encrypt_options = ($default_encrypt == IMP_PGP_ENCRYPT) ? IMP_ENCRYPT_NONE : IMP_PGP_SIGN;
 739                    break;
 740                }
 741            }
 742        }
 743    }
 744}
 745
 746/* Determine the default cursor position in the compose text area. */
 747if (!$rtemode) {
 748    switch ($prefs->getValue('compose_cursor')) {
 749    case 'top':
 750    default:
 751        $cursor_pos = 0;
 752        break;
 753
 754    case 'bottom':
 755        $cursor_pos = String::length($msg);
 756        break;
 757
 758    case 'sig':
 759        if (!is_null($siglocation)) {
 760            $cursor_pos = $siglocation;
 761        } elseif (!empty($sig)) {
 762            $next_pos = $pos = 0;
 763            $sig_length = String::length($sig);
 764            do {
 765                $cursor_pos = $pos;
 766                $pos = strpos($msg, $sig, $next_pos);
 767                $next_pos = $pos + $sig_length;
 768            } while ($pos !== false);
 769        }
 770        break;
 771    };
 772}
 773
 774/* Define some variables used in the javascript code. */
 775$js_code = array(
 776    'var cancel_url = \'' . $cancel_url . '\'',
 777    'var compose_spellcheck = ' . intval($spellcheck && $prefs->getValue('compose_spellcheck')),
 778    'var cursor_pos = ' . (is_null($cursor_pos) ? 'null' : $cursor_pos),
 779    'var max_attachments = ' . (($max_attach === true) ? 'null' : $max_attach),
 780    'var compose_popup = ' . intval($isPopup),
 781    'var redirect = ' . intval($redirect),
 782    'var rtemode = ' . intval($rtemode),
 783    'var smf_check = ' . intval($smf_check),
 784    'var reloaded = ' . intval($reloaded),
 785);
 786
 787/* Create javascript identities array. */
 788if (!$redirect) {
 789    $js_ident = array();
 790    foreach ($identity->getAllSignatures() as $ident => $sig) {
 791        $smf = $identity->getValue('sent_mail_folder', $ident);
 792        $js_ident[] = array(
 793            ($rtemode) ? str_replace(' target="_blank"', '', Text_Filter::filter($sig, 'text2html', array('parselevel' => TEXT_HTML_MICRO_LINKURL, 'class' => null, 'callback' => null))) : $sig,
 794            $identity->getValue('sig_first', $ident),
 795            ($smf_check) ? $smf : IMP::displayFolder($smf),
 796            $identity->saveSentmail($ident),
 797            MIME::addrArray2String($identity->getBccAddresses($ident))
 798        );
 799    }
 800    require_once IMP_BASE . '/lib/JSON.php';
 801    $js_code[] = 'var identities = ' . IMP_Serialize_JSON::encode(String::convertCharset($js_ident, NLS::getCharset(), 'utf-8'));
 802}
 803
 804Horde::addScriptFile('prototype.js', 'imp', true);
 805Horde::addScriptFile('compose.js', 'imp', true);
 806require IMP_TEMPLATES . '/common-header.inc';
 807IMP::addInlineScript($js_code);
 808if ($showmenu) {
 809    IMP::menu();
 810}
 811
 812/* Set up the base template now. */
 813$t = new IMP_Template();
 814$t->setOption('gettext', true);
 815$t->set('post_action', Util::addParameter(Horde::applicationUrl('compose.php'), 'uniq', base_convert(microtime(), 10, 36)));
 816if ($has_js) {
 817    $t->set('loading_img', Horde::img('loading.gif', _("Loading...")));
 818}
 819
 820if ($redirect) {
 821    /* Prepare the redirect template. */
 822    $t->set('mailbox', htmlspecialchars($thismailbox));
 823    $t->set('index', htmlspecialchars($index));
 824    $t->set('status', IMP::status());
 825    $t->set('title', htmlspecialchars($title));
 826    $t->set('token', IMP::getRequestToken('imp.compose'));
 827
 828    if ($registry->hasMethod('contacts/search')) {
 829        $t->set('has_search', true);
 830        $t->set('abook', Horde::link('#', _("Address Book"), 'widget', null, 'window.open(\'' . Util::addParameter(Horde::applicationUrl('contacts.php'), array('formname' => 'redirect', 'to_only' => 1)) . '\', \'contacts\', \'toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes,width=550,height=300,left=100,top=100\'); return false;') . Horde::img('addressbook_browse.png') . '<br />' . _("Address Book") . '</a>');
 831        if (!$has_js) {
 832            $t->set('expand', Horde::link('#', _("Expand Names"), 'widget', null, "$('actionID').value='redirect_expand_addr';uniqSubmit();return false;") . Horde::img('expand.png') . '<br />' . _("Expand Names") . '</a>', true);
 833        }
 834    }
 835
 836    $t->set('to', Horde::label('to', _("To")));
 837
 838    $tabindex = -1;
 839    if (is_array($header['to'])) {
 840        $t->set('multiple_to', true);
 841        $first_to = true;
 842        $to_hdrs = array();
 843        foreach ($header['to'] as $to_item) {
 844            $entry = array();
 845            if (count($to_item) > 1) {
 846                $entry['multiple'] = true;
 847                $entry['select_tabindex'] = ++$tabindex;
 848                $entry['select_name'] = htmlspecialchars($to_item[0]);
 849                $entry['select_to'] = array();
 850                for ($i = 1; $i < count($to_item); $i++) {
 851                    $entry['select_to'][] = array('val' => htmlspecialchars($to_item[$i]));
 852                }
 853            } else {
 854                $entry['multiple'] = null;
 855                $entry['input_value'] = htmlspecialchars($to_item);
 856            }
 857            $entry['input_tabindex'] = ++$tabindex;
 858
 859            if ($first_to) {
 860                $first_to = false;
 861                $entry['help'] = Help::link('imp', 'compose-to');
 862            } else {
 863                $entry['help'] = null;
 864            }
 865            $to_hdrs[] = $entry;
 866        }
 867        $t->set('to_new_tabindex', ++$tabindex);
 868        $t->set('to_hdrs', $to_hdrs);
 869    } else {
 870        $t->set('input_tabindex', ++$tabindex);
 871        $t->set('input_value', htmlspecialchars($header['to']));
 872        $t->set('help', Help::link('imp', 'compose-to'));
 873    }
 874
 875    echo $t->fetch(IMP_TEMPLATES . '/compose/redirect.html');
 876} else {
 877    if (!($reply_type = Util::getFormData('reply_type', $reply_type))) {
 878        switch ($actionID) {
 879        case 'reply':
 880        case 'reply_all':
 881        case 'reply_list':
 882            $reply_type = 'reply';
 883            break;
 884
 885        case 'forward':
 886        case 'forward_all':
 887        case 'forward_body':
 888        case 'forward_attachments':
 889            $reply_type = 'forward';
 890            break;
 891        }
 892    }
 893
 894    /* Prepare the compose template. */
 895    $tabindex = 0;
 896
 897    $t->set('file_upload', $_SESSION['imp']['file_upload']);
 898    $t->set('forminput', Util::formInput());
 899
 900    $hidden = array();
 901    if ($_SESSION['imp']['file_upload']) {
 902        if ($browser->hasQuirk('broken_multipart_form')) {
 903            $hidden[] = array('n' => 'msie_formdata_is_broken', 'v' => '');
 904        }
 905        $hidden[] = array('n' => 'MAX_FILE_SIZE', 'v' => $_SESSION['imp']['file_upload']);
 906    }
 907    $hidden[] = array('n' => 'actionID', 'v' => '');
 908    $hidden[] = array('n' => 'compose_requestToken', 'v' => IMP::getRequestToken('imp.compose'));
 909    $hidden[] = array('n' => 'compose_formToken', 'v' => Horde_Token::generateId('compose'));
 910    $hidden[] = array('n' => 'messageCache', 'v' => $messageCacheID);
 911    $hidden[] = array('n' => 'mailbox', 'v' => htmlspecialchars($imp_mbox['mailbox']));
 912    $hidden[] = array('n' => 'thismailbox', 'v' => $thismailbox);
 913    foreach (array('page', 'start', 'popup') as $val) {
 914        $hidden[] = array('n' => $val, 'v' => htmlspecialchars(Util::getFormData($val)));
 915    }
 916    $hidden[] = array('n' => 'attachmentAction', 'v' => '');
 917    $hidden[] = array('n' => 'reloaded', 'v' => 1);
 918    $hidden[] = array('n' => 'oldrtemode', 'v' => $rtemode);
 919    $hidden[] = array('n' => 'rtemode', 'v' => $rtemode);
 920    $hidden[] = array('n' => 'index', 'v' => $index);
 921    if ($reply_type) {
 922        $hidden[] = array('n' => 'reply_type', 'v' => $reply_type);
 923        $hidden[] = array('n' => 'reply_index', 'v' => $reply_index);
 924        $hidden[] = array('n' => 'in_reply_to', 'v' => htmlspecialchars($header['in_reply_to']));
 925        if ($reply_type == 'reply') {
 926            $hidden[] = array('n' => 'references', 'v' => htmlspecialchars($header['references']));
 927        }
 928    }
 929    $t->set('hidden', $hidden);
 930
 931    $t->set('title', htmlspecialchars($title));
 932    $t->set('send_msg_ak', Horde::getAccessKeyAndTitle(_("_Send Message")));
 933    if ($conf['user']['allow_folders']) {
 934        $t->set('save_draft_ak', Horde::getAccessKeyAndTitle(_("Save _Draft")));
 935    }
 936    $t->set('help_buttons', Help::link('imp', 'compose-buttons'));
 937    $t->set('di_locked', $prefs->isLocked('default_identity'));
 938    if ($t->get('di_locked')) {
 939        $t->set('help_compose-from', Help::link('imp', 'compose-from'));
 940        $t->set('fromaddr_locked', $prefs->isLocked('from_addr'));
 941        $t->set('from', htmlspecialchars($identity->getFromLine(null, Util::getFormData('from'))));
 942        if (!$t->get('fromaddr_locked')) {
 943            $t->set('fromaddr_tabindex', ++$tabindex);
 944        }
 945    } else {
 946        $select_list = $identity->getSelectList();
 947        $t->set('identity_label', Horde::label('identity', _("_Identity")));
 948        $t->set('help_compose-from', Help::link('imp', 'compose-identity'));
 949        $t->set('last_identity', $identity->getDefault());
 950        $t->set('count_select_list', count($select_list) > 1);
 951        if (count($select_list) > 1) {
 952            $t->set('selectlist_tabindex', ++$tabindex);
 953            $t_select_list = array();
 954            foreach ($select_list as $key => $select) {
 955                $t_select_list[] = array('value' => $key, 'selected' => ($key == $identity->getDefault()), 'label' => htmlspecialchars($select));
 956            }
 957            $t->set('select_list', $t_select_list);
 958        } else {
 959            $t->set('identity_default', $identity->getDefault());
 960            $t->set('identity_text', htmlspecialchars($select_list[0]));
 961        }
 962    }
 963    $t->set('label_to', Horde::label('to', _("_To")));
 964
 965    $addr_array = array('to' => _("_To"));
 966    if ($prefs->getValue('compose_cc')) {
 967        $addr_array['cc'] = _("_Cc");
 968    }
 969    if ($prefs->getValue('compose_bcc')) {
 970        $addr_array['bcc'] = _("_Bcc");
 971    }
 972
 973    $address_array = array();
 974    foreach ($addr_array as $val => $label) {
 975        $addr = array(
 976            'id' => $val,
 977            'label' => Horde::label($val, $label),
 978        );
 979
 980        $first_addr = false;
 981        if (is_array($header[$val])) {
 982            $addr['multiple'] = true;
 983            $first_addr = true;
 984            $hdrs = array();
 985            foreach ($header[$val] as $item) {
 986                $entry = array();
 987                if (count($item) > 1) {
 988                    $entry['multiple'] = true;
 989                    $entry['select_tabindex'] = ++$tabindex;
 990                    $entry['select_name'] = htmlspecialchars($item[0]);
 991                    $entry['select_arr'] = array();
 992                    for ($i = 1; $i < count($item); $i++) {
 993                        $entry['select_arr'][] = array('val' => htmlspecialchars($item[$i]));
 994                    }
 995                    $entry['input_value'] = null;
 996                } else {
 997                    $entry['multiple'] = null;
 998                    $entry['input_value'] = htmlspecialchars($item);
 999                }
1000                $entry['input_tabindex'] = ++$tabindex;
1001
1002                if ($first_addr) {
1003                    $first_addr = false;
1004                    $entry['help'] = Help::link('imp', 'compose-' . $val);
1005                } else {
1006                    $entry['help'] = null;
1007                }
1008                $hdrs[] = $entry;
1009            }
1010            $addr['hdrs'] = $hdrs;
1011        } else {
1012            $addr['multiple'] = false;
1013            $addr['input_tabindex'] = ++$tabindex;
1014            $addr['input_value'] = htmlspecialchars($header[$val]);
1015            $addr['help_compose'] = Help::link('imp', 'compose-' . $val);
1016        }
1017        $address_array[] = $addr;
1018    }
1019    $t->set('addr', $address_array);
1020
1021    $t->set('subject_label', Horde::label('subject', _("S_ubject")));
1022    $t->set('subject_tabindex', ++$tabindex);
1023    $t->set('subject', htmlspecialchars($header['subject']));
1024    $t->set('help-subject', Help::link('imp', 'compose-subject'));
1025
1026    $t->set('set_priority', $prefs->getValue('set_priority'));
1027    $t->set('unlocked_charset', !$prefs->isLocked('sending_charset'));
1028    if ($t->get('unlocked_charset')) {
1029        $t->set('charset_label', Horde::label('charset', _("C_harset")));
1030        $t->set('charset_tabindex', ++$tabindex);
1031        $charset_array = array();
1032        foreach ($nls['encodings'] as $charset => $label) {
1033            $charset_array[] = array('value' => $charset, 'selected' => (strtolower($charset) == strtolower($encoding)), 'label' => $label);
1034        }
1035        $t->set('charset_array', $charset_array);
1036        $t->set('help_compose_charset', Help::link('imp', 'compose-charset'));
1037    }
1038    if ($t->get('set_priority')) {
1039        $t->set('priority_label', Horde::label('priority', _("_Priority")));
1040        $t->set('priority_tabindex', ++$tabindex);
1041
1042        $priority = Util::getFormData('x_priority', 3);
1043        $priorities = array(
1044            1 => '1 (' . _("Highest") . ')',
1045            2 => '2 (' . _("High") . ')',
1046            3 => '3 (' . _("Normal") . ')',
1047            4 => '4 (' . _("Low") . ')',
1048            5 => '5 (' . _("Lowest") . ')'
1049        );
1050        $priority_option = array();
1051        foreach ($priorities as $key => $val) {
1052            $priority_option[] = array('val' => $key, 'label' => $val, 'selected' => ($priority == $key));
1053        }
1054        $t->set('pri_opt', $priority_option);
1055        $t->set('help_priority', Help::link('imp', 'compose-priority'));
1056    }
1057
1058    $t->set('stationery', !empty($stationery_list));
1059    if ($t->get('stationery')) {
1060        $t->set('stationery_label', Horde::label('stationery', _("Stationery")));
1061        $stationeries = array();
1062        foreach ($stationery_list as $id => $choice) {
1063            $stationeries[] = array('val' => $id, 'label' => $choice['n'], 'selected' => ($stationery === $id));
1064        }
1065        $t->set('stationeries', $stationeries);
1066    }
1067
1068    $menu_view = $prefs->getValue('menu_view');
1069    $show_text = ($menu_view == 'text' || $menu_view == 'both');
1070    $compose_options = array();
1071    if ($registry->hasMethod('contacts/search')) {
1072        $compose_options[] = array(
1073            'url' => Horde::link('#', '', 'widget', null, 'window.open(\'' . Horde::applicationUrl('contacts.php') . '\', \'contacts\', \'toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes,width=550,height=300,left=100,top=100\'); return false;'),
1074            'img' => Horde::img('addressbook_browse.png'),
1075            'label' => $show_text ? _("Address Book") : '');
1076        if (!$has_js) {
1077            $compose_options[] = array(
1078                'url' => Horde::link(
1079                    '#', '', 'widget', null,
1080                    "uniqSubmit('compose_expand_addr'); return false;",
1081                    '', '', array('name' => 'btn_compose_expand_addr')),
1082                'img' => Horde::img('expand.png'),
1083                'label' => $show_text ? _("Expand Names") : '');
1084        }
1085    }
1086    if ($spellcheck) {
1087        $compose_options[] = array(
1088            'url' => Horde::link('#', '', 'widget', '', 'return false', '', '',
1089                                 array('id' => 'spellcheck')),
1090            'img' => '', 'label' => '');
1091    }
1092    if ($has_js && $conf['compose']['special_characters']) {
1093        $compose_options[] = array(
1094            'url' => Horde::link(
1095                '#', '', 'widget', null,
1096                'window.open(\''
1097                . Horde::url($registry->get('webroot', 'horde')
1098                             . '/services/keyboard.php')
1099                . '\', \'chars\', \'height=220,width=400\'); return false;'),
1100            'img' => Horde::img('keyboard.png', null, null,
1101                                $registry->getImageDir('horde')),
1102            'label' => $show_text ? _("Special Characters") : '');
1103    }
1104    if ($_SESSION['imp']['file_upload']) {
1105        $compose_options[] = array(
1106            'url' => Horde::link('#attachments', '', 'widget'),
1107            'img' => Horde::img('manage_attachments.png'),
1108            'label' => $show_text ? _("Attachments") : '');
1109    }
1110    $t->set('compose_options', $compose_options);
1111    $t->set('help_options', Help::link('imp', 'compose-options'));
1112
1113    $t->set('ssm', ($conf['user']['allow_folders'] && !$prefs->isLocked('save_sent_mail')));
1114    if ($t->get('ssm')) {
1115        $t->set('ssm_selected', ($reloaded) ? (Util::getFormData('save_sent_mail') == 'on') : $identity->saveSentmail());
1116        $t->set('ssm_label', Horde::label('ssm', _("Sa_ve a copy in ")));
1117        if ($smf = Util::getFormData('sent_mail_folder')) {
1118            $sent_mail_folder = $smf;
1119        }
1120        if (!empty($conf['user']['select_sentmail_folder']) &&
1121            !$prefs->isLocked('sent_mail_folder')) {
1122            /* Check to make sure the sent-mail folder is created - it needs
1123             * to exist to show up in drop-down list. */
1124            require_once IMP_BASE . '/lib/Folder.php';
1125            $imp_folder = &IMP_Folder::singleton();
1126            if (!$imp_folder->exists($sent_mail_folder)) {
1127                $imp_folder->create($sent_mail_folder, true);
1128            }
1129
1130            $t->set('ssm_tabindex', ++$tabindex);
1131            $t->set('ssm_folders', IMP::flistSelect('', false, array('INBOX'), $sent_mail_folder));
1132        } else {
1133            if (!empty($sent_mail_folder)) {
1134                $sent_mail_folder = '&quot;' . IMP::displayFolder($sent_mail_folder) . '&quot;';
1135            }
1136            $t->set('ssm_folder', $sent_mail_folder);
1137            $t->set('ssm_folders', false);
1138        }
1139    }
1140
1141    $d_read = $prefs->getValue('disposition_request_read');
1142    $t->set('rrr', $conf['compose']['allow_receipts'] && ($d_read != 'never'));
1143    if ($t->get('rrr')) {
1144       $t->set('rrr_selected', ($d_read != 'ask') || (Util::getFormData('request_read_receipt') == 'on'));
1145       $t->set('rrr_label', Horde::label('rrr', _("Request a _Read Receipt")));
1146    }
1147
1148    $t->set('compose_html', (!is_null($rtemode) && !$prefs->isLocked('compose_html')));
1149    if ($t->get('compose_html')) {
1150        $t->set('html_img', Horde::img('compose.png', _("Switch Composition Method")));
1151        $t->set('html_switch', Horde::link('#', _("Switch Composition Method"), '', '', "$('rtemode').value='" . ($rtemode ? 0 : 1) . "';uniqSubmit();return false;"));
1152        $t->set('rtemode', $rtemode);
1153    }
1154
1155    $t->set('message_label', Horde::label('message', _("Te_xt")));
1156    $t->set('message_tabindex', ++$tabindex);
1157    $t->set('message', htmlspecialchars($msg));
1158
1159    $t->set('use_encrypt', ($prefs->getValue('use_pgp') || $prefs->getValue('use_smime')));
1160    if ($t->get('use_encrypt')) {
1161        if ($prefs->isLocked('default_encrypt')) {
1162            $t->set('use_encrypt', false);
1163        } else {
1164            $t->set('encrypt_label', Horde::label('encrypt_options', _("Encr_yption Options")));
1165            $t->set('encrypt_options', IMP::encryptList($encrypt_options));
1166            $t->set('help-encrypt', Help::link('imp', 'compose-options-encrypt'));
1167        }
1168        $t->set('pgp_options', ($prefs->getValue('use_pgp') && $prefs->getValue('pgp_public_key')));
1169        if ($t->get('pgp_options')) {
1170            $t->set('pgp_attach_pubkey', Util::getFormData('pgp_attach_pubkey', $prefs->getValue('pgp_attach_pubkey')));
1171            $t->set('pap', Horde::label('pap', _("Attach a copy of your PGP public key to the message?")));
1172            $t->set('help-pubkey', Help::link('imp', 'pgp-compose-attach-pubkey'));
1173        }
1174    }
1175    if ($registry->hasMethod('contacts/ownVCard')) {
1176        $t->set('vcard', Horde::label('vcard', _("Attach your contact information to the message?")));
1177        $t->set('attach_vcard', Util::getFormData('vcard'));
1178    }
1179    if ($_SESSION['imp']['file_upload']) {
1180        if ($GLOBALS['registry']->hasMethod('files/selectlistLink')) {
1181            $res = $GLOBALS['registry']->call('files/selectlistLink', array(_("Attach Files"), 'widget', 'compose', true));
1182            $t->set('selectlistlink', (is_a($res, 'PEAR_Error')) ? null : $res);
1183        }
1184        $t->set('maxattachsize', !$imp_compose->maxAttachmentSize());
1185        if (!$t->get('maxattachsize')) {
1186            $t->set('maxattachmentnumber', !$max_attach);
1187            if (!$t->get('maxattachmentnumber')) {
1188                $t->set('file_tabindex', ++$tabindex);
1189            }
1190        }
1191        $t->set('attach_size', IMP::numberFormat($imp_compose->maxAttachmentSize(), 0));
1192        $t->set('help-attachments', Help::link('imp', 'compose-attachments'));
1193
1194        $save_attach = $prefs->getValue('save_attachments');
1195        $show_link_attach = ($conf['compose']['link_attachments'] && !$conf['compose']['link_all_attachments']);
1196        $show_save_attach = ($t->get('ssm') && (strpos($save_attach, 'prompt') === 0)
1197                             && (!$conf['compose']['link_attachments'] || !$conf['compose']['link_all_attachments']));
1198        $t->set('show_link_save_attach', ($show_link_attach || $show_save_attach));
1199        if ($t->get('show_link_save_attach')) {
1200            $attach_options = array();
1201            if ($show_save_attach) {
1202                $save_attach_val = Util::getFormData('save_attachments_select', ($save_attach == 'prompt_yes'));
1203                $attach_options[] = array('label' => _("Save Attachments with message in sent-mail folder?"), 'name' => 'save_attachments_select', 'select_yes' => ($save_attach_val == 1), 'select_no' => ($save_attach_val == 0), 'help' => Help::link('imp', 'compose-save-attachments'));
1204            }
1205            if ($show_link_attach) {
1206                $link_attach_val = Util::getFormData('link_attachments');
1207                $attach_options[] = array('label' => _("Link Attachments?"), 'name' => 'link_attachments', 'select_yes' => ($link_attach_val == 1), 'select_no' => ($link_attach_val == 0), 'help' => Help::link('imp', 'compose-link-attachments'));
1208            }
1209            $t->set('attach_options', $attach_options);
1210        }
1211
1212        $t->set('numberattach', $imp_compose->numberOfAttachments());
1213        if ($t->get('numberattach')) {
1214            require_once IMP_BASE . '/lib/MIME/Contents.php';
1215            $mime_contents = new MIME_Contents(new MIME_Part());
1216
1217            $atc = array();
1218            $disp_num = 0;
1219            foreach ($imp_compose->getAttachments() as $atc_num => $mime) {
1220                $entry = array();
1221                $disposition = $mime->getDisposition();
1222                $viewer = &$mime_contents->getMIMEViewer($mime);
1223                $linked = Util::getFormData (sprintf('file_linked_%d', $atc_num));
1224                $entry['name'] = $mime->getName(true, true);
1225                if ($mime->getType() != 'application/octet-stream') {
1226                    $preview_url = Util::addParameter(Horde::applicationUrl('view.php'), array('actionID' => 'compose_attach_preview', 'id' => $atc_num, 'messageCache' => $imp_compose->getMessageCacheId()));
1227                    $entry['name'] = Horde::link($preview_url, _("Preview") . ' ' . $entry['name'], 'link', 'compose_preview_window') . $entry['name'] . '</a>';
1228                }
1229                $entry['icon'] = $viewer->getIcon($mime->getType());
1230                $entry['disp_number'] = ++$disp_num;
1231                $entry['number'] = $atc_num;
1232                $entry['type'] = $mime->getType();
1233                $entry['size'] = $mime->getSize();
1234                $entry['disp_atc'] = ($disposition == 'attachment');
1235                $entry['disp_inline'] = ($disposition == 'inline');
1236                $entry['description'] = $mime->getDescriptio…

Large files files are truncated, but you can click here to view the full file