PageRenderTime 55ms CodeModel.GetById 15ms RepoModel.GetById 0ms 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
Possible License(s): AGPL-1.0

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

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