Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

compose.inc 66KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------+
  4. | program/steps/mail/compose.inc |
  5. | |
  6. | This file is part of the Roundcube Webmail client |
  7. | Copyright (C) 2005-2016, The Roundcube Dev Team |
  8. | |
  9. | Licensed under the GNU General Public License version 3 or |
  10. | any later version with exceptions for skins & plugins. |
  11. | See the README file for a full license statement. |
  12. | |
  13. | PURPOSE: |
  14. | Compose a new mail message with all headers and attachments |
  15. | |
  16. +-----------------------------------------------------------------------+
  17. | Author: Thomas Bruederli <roundcube@gmail.com> |
  18. +-----------------------------------------------------------------------+
  19. */
  20. // define constants for message compose mode
  21. define('RCUBE_COMPOSE_REPLY', 'reply');
  22. define('RCUBE_COMPOSE_FORWARD', 'forward');
  23. define('RCUBE_COMPOSE_DRAFT', 'draft');
  24. define('RCUBE_COMPOSE_EDIT', 'edit');
  25. $MESSAGE_FORM = null;
  26. $COMPOSE_ID = rcube_utils::get_input_value('_id', rcube_utils::INPUT_GET);
  27. $COMPOSE = null;
  28. if ($COMPOSE_ID && $_SESSION['compose_data_'.$COMPOSE_ID])
  29. $COMPOSE =& $_SESSION['compose_data_'.$COMPOSE_ID];
  30. // give replicated session storage some time to synchronize
  31. $retries = 0;
  32. while ($COMPOSE_ID && !is_array($COMPOSE) && $RCMAIL->db->is_replicated() && $retries++ < 5) {
  33. usleep(500000);
  34. $RCMAIL->session->reload();
  35. if ($_SESSION['compose_data_'.$COMPOSE_ID]) {
  36. $COMPOSE =& $_SESSION['compose_data_'.$COMPOSE_ID];
  37. }
  38. }
  39. // Nothing below is called during message composition, only at "new/forward/reply/draft" initialization or
  40. // if a compose-ID is given (i.e. when the compose step is opened in a new window/tab).
  41. if (!is_array($COMPOSE)) {
  42. // Infinite redirect prevention in case of broken session (#1487028)
  43. if ($COMPOSE_ID) {
  44. // if we know the message with specified ID was already sent
  45. // we can ignore the error and compose a new message (#1490009)
  46. if ($COMPOSE_ID != $_SESSION['last_compose_session']) {
  47. rcube::raise_error(array('code' => 450), false, true);
  48. }
  49. }
  50. $COMPOSE_ID = uniqid(mt_rand());
  51. $params = rcube_utils::request2param(rcube_utils::INPUT_GET, 'task|action', true);
  52. $_SESSION['compose_data_'.$COMPOSE_ID] = array(
  53. 'id' => $COMPOSE_ID,
  54. 'param' => $params,
  55. 'mailbox' => $params['mbox'] ?: $RCMAIL->storage->get_folder(),
  56. );
  57. $COMPOSE =& $_SESSION['compose_data_'.$COMPOSE_ID];
  58. rcmail_process_compose_params($COMPOSE);
  59. // check if folder for saving sent messages exists and is subscribed (#1486802)
  60. if ($sent_folder = $COMPOSE['param']['sent_mbox']) {
  61. rcmail_check_sent_folder($sent_folder, true);
  62. }
  63. // redirect to a unique URL with all parameters stored in session
  64. $OUTPUT->redirect(array(
  65. '_action' => 'compose',
  66. '_id' => $COMPOSE['id'],
  67. '_search' => $_REQUEST['_search'],
  68. ));
  69. }
  70. // add some labels to client
  71. $OUTPUT->add_label('nosubject', 'nosenderwarning', 'norecipientwarning', 'nosubjectwarning', 'cancel',
  72. 'nobodywarning', 'notsentwarning', 'notuploadedwarning', 'savingmessage', 'sendingmessage',
  73. 'messagesaved', 'converting', 'editorwarning', 'searching', 'uploading', 'uploadingmany',
  74. 'fileuploaderror', 'sendmessage', 'newresponse', 'responsename', 'responsetext', 'save',
  75. 'savingresponse', 'restoresavedcomposedata', 'restoremessage', 'delete', 'restore', 'ignore',
  76. 'selectimportfile', 'messageissent', 'loadingdata', 'nopubkeyfor', 'nopubkeyforsender',
  77. 'encryptnoattachments','encryptedsendialog','searchpubkeyservers', 'importpubkeys',
  78. 'encryptpubkeysfound', 'search', 'close', 'import', 'keyid', 'keylength', 'keyexpired',
  79. 'keyrevoked', 'keyimportsuccess', 'keyservererror', 'attaching', 'namex', 'attachmentrename',
  80. 'disclosedrecipwarning', 'disclosedreciptitle', 'bccinstead', 'nosubjecttitle');
  81. $OUTPUT->set_pagetitle($RCMAIL->gettext('compose'));
  82. $OUTPUT->set_env('compose_id', $COMPOSE['id']);
  83. $OUTPUT->set_env('session_id', session_id());
  84. $OUTPUT->set_env('mailbox', $RCMAIL->storage->get_folder());
  85. $OUTPUT->set_env('top_posting', intval($RCMAIL->config->get('reply_mode')) > 0);
  86. $OUTPUT->set_env('sig_below', $RCMAIL->config->get('sig_below'));
  87. $OUTPUT->set_env('recipients_separator', trim($RCMAIL->config->get('recipients_separator', ',')));
  88. $OUTPUT->set_env('save_localstorage', (bool)$RCMAIL->config->get('compose_save_localstorage'));
  89. $OUTPUT->set_env('max_disclosed_recipients', (int) $RCMAIL->config->get('max_disclosed_recipients', 5));
  90. $OUTPUT->set_env('is_sent', false);
  91. $OUTPUT->set_env('mimetypes', rcmail_supported_mimetypes());
  92. $drafts_mbox = $RCMAIL->config->get('drafts_mbox');
  93. $config_show_sig = $RCMAIL->config->get('show_sig', 1);
  94. // add config parameters to client script
  95. if (strlen($drafts_mbox)) {
  96. $OUTPUT->set_env('drafts_mailbox', $drafts_mbox);
  97. $OUTPUT->set_env('draft_autosave', $RCMAIL->config->get('draft_autosave'));
  98. }
  99. // default font for HTML editor
  100. $font = rcmail::font_defs($RCMAIL->config->get('default_font'));
  101. if ($font && !is_array($font)) {
  102. $OUTPUT->set_env('default_font', $font);
  103. }
  104. // default font size for HTML editor
  105. if ($font_size = $RCMAIL->config->get('default_font_size')) {
  106. $OUTPUT->set_env('default_font_size', $font_size);
  107. }
  108. // get reference message and set compose mode
  109. if ($msg_uid = $COMPOSE['param']['draft_uid']) {
  110. $compose_mode = RCUBE_COMPOSE_DRAFT;
  111. $OUTPUT->set_env('draft_id', $msg_uid);
  112. $RCMAIL->storage->set_folder($drafts_mbox);
  113. }
  114. else if ($msg_uid = $COMPOSE['param']['reply_uid']) {
  115. $compose_mode = RCUBE_COMPOSE_REPLY;
  116. }
  117. else if ($msg_uid = $COMPOSE['param']['forward_uid']) {
  118. $compose_mode = RCUBE_COMPOSE_FORWARD;
  119. $COMPOSE['forward_uid'] = $msg_uid;
  120. $COMPOSE['as_attachment'] = !empty($COMPOSE['param']['attachment']);
  121. }
  122. else if ($msg_uid = $COMPOSE['param']['uid']) {
  123. $compose_mode = RCUBE_COMPOSE_EDIT;
  124. }
  125. if ($compose_mode) {
  126. $COMPOSE['mode'] = $compose_mode;
  127. $OUTPUT->set_env('compose_mode', $compose_mode);
  128. }
  129. if ($compose_mode == RCUBE_COMPOSE_EDIT || $compose_mode == RCUBE_COMPOSE_DRAFT) {
  130. // don't add signature in draft/edit mode, we'll also not remove the old-one
  131. // but only on page display, later we should be able to change identity/sig (#1489229)
  132. if ($config_show_sig == 1 || $config_show_sig == 2) {
  133. $OUTPUT->set_env('show_sig_later', true);
  134. }
  135. }
  136. else if ($config_show_sig == 1)
  137. $OUTPUT->set_env('show_sig', true);
  138. else if ($config_show_sig == 2 && empty($compose_mode))
  139. $OUTPUT->set_env('show_sig', true);
  140. else if ($config_show_sig == 3 && ($compose_mode == RCUBE_COMPOSE_REPLY || $compose_mode == RCUBE_COMPOSE_FORWARD))
  141. $OUTPUT->set_env('show_sig', true);
  142. // set line length for body wrapping
  143. $LINE_LENGTH = $RCMAIL->config->get('line_length', 72);
  144. if (!empty($msg_uid) && empty($COMPOSE['as_attachment'])) {
  145. $mbox_name = $RCMAIL->storage->get_folder();
  146. // set format before rcube_message construction
  147. // use the same format as for the message view
  148. if (isset($_SESSION['msg_formats'][$mbox_name.':'.$msg_uid])) {
  149. $RCMAIL->config->set('prefer_html', $_SESSION['msg_formats'][$mbox_name.':'.$msg_uid]);
  150. }
  151. else {
  152. $prefer_html = $RCMAIL->config->get('prefer_html') || $RCMAIL->config->get('htmleditor')
  153. || $compose_mode == RCUBE_COMPOSE_DRAFT || $compose_mode == RCUBE_COMPOSE_EDIT;
  154. $RCMAIL->config->set('prefer_html', $prefer_html);
  155. }
  156. $MESSAGE = new rcube_message($msg_uid);
  157. // make sure message is marked as read
  158. if ($MESSAGE->headers && $MESSAGE->context === null && empty($MESSAGE->headers->flags['SEEN'])) {
  159. $RCMAIL->storage->set_flag($msg_uid, 'SEEN');
  160. }
  161. if (!empty($MESSAGE->headers->charset)) {
  162. $RCMAIL->storage->set_charset($MESSAGE->headers->charset);
  163. }
  164. if (!$MESSAGE->headers) {
  165. // error
  166. }
  167. else if ($compose_mode == RCUBE_COMPOSE_FORWARD || $compose_mode == RCUBE_COMPOSE_REPLY) {
  168. if ($compose_mode == RCUBE_COMPOSE_REPLY) {
  169. $COMPOSE['reply_uid'] = $MESSAGE->context === null ? $msg_uid : null;
  170. if (!empty($COMPOSE['param']['all'])) {
  171. $MESSAGE->reply_all = $COMPOSE['param']['all'];
  172. }
  173. }
  174. else {
  175. $COMPOSE['forward_uid'] = $msg_uid;
  176. }
  177. $COMPOSE['reply_msgid'] = $MESSAGE->headers->messageID;
  178. $COMPOSE['references'] = trim($MESSAGE->headers->references . " " . $MESSAGE->headers->messageID);
  179. // Save the sent message in the same folder of the message being replied to
  180. if ($RCMAIL->config->get('reply_same_folder') && ($sent_folder = $COMPOSE['mailbox'])
  181. && rcmail_check_sent_folder($sent_folder, false)
  182. ) {
  183. $COMPOSE['param']['sent_mbox'] = $sent_folder;
  184. }
  185. }
  186. else if ($compose_mode == RCUBE_COMPOSE_DRAFT || $compose_mode == RCUBE_COMPOSE_EDIT) {
  187. if ($compose_mode == RCUBE_COMPOSE_DRAFT) {
  188. if ($draft_info = $MESSAGE->headers->get('x-draft-info')) {
  189. // get reply_uid/forward_uid to flag the original message when sending
  190. $info = rcmail_draftinfo_decode($draft_info);
  191. if ($info['type'] == 'reply')
  192. $COMPOSE['reply_uid'] = $info['uid'];
  193. else if ($info['type'] == 'forward')
  194. $COMPOSE['forward_uid'] = $info['uid'];
  195. $COMPOSE['mailbox'] = $info['folder'];
  196. // Save the sent message in the same folder of the message being replied to
  197. if ($RCMAIL->config->get('reply_same_folder') && ($sent_folder = $info['folder'])
  198. && rcmail_check_sent_folder($sent_folder, false)
  199. ) {
  200. $COMPOSE['param']['sent_mbox'] = $sent_folder;
  201. }
  202. }
  203. $COMPOSE['param']['message-id'] = $MESSAGE->headers->get('message-id');
  204. // use message UID as draft_id
  205. $OUTPUT->set_env('draft_id', $msg_uid);
  206. }
  207. if ($in_reply_to = $MESSAGE->headers->get('in-reply-to')) {
  208. $COMPOSE['reply_msgid'] = '<' . $in_reply_to . '>';
  209. }
  210. $COMPOSE['references'] = $MESSAGE->headers->references;
  211. }
  212. }
  213. else {
  214. $MESSAGE = new stdClass();
  215. // apply mailto: URL parameters
  216. if (!empty($COMPOSE['param']['in-reply-to'])) {
  217. $COMPOSE['reply_msgid'] = '<' . $COMPOSE['param']['in-reply-to'] . '>';
  218. }
  219. if (!empty($COMPOSE['param']['references'])) {
  220. $COMPOSE['references'] = $COMPOSE['param']['references'];
  221. }
  222. }
  223. if (!empty($COMPOSE['reply_msgid'])) {
  224. $OUTPUT->set_env('reply_msgid', $COMPOSE['reply_msgid']);
  225. }
  226. $MESSAGE->compose = array();
  227. // get user's identities
  228. $MESSAGE->identities = $RCMAIL->user->list_identities(null, true);
  229. // Set From field value
  230. if (!empty($_POST['_from'])) {
  231. $MESSAGE->compose['from'] = rcube_utils::get_input_value('_from', rcube_utils::INPUT_POST);
  232. }
  233. else if (!empty($COMPOSE['param']['from'])) {
  234. $MESSAGE->compose['from'] = $COMPOSE['param']['from'];
  235. }
  236. else if (count($MESSAGE->identities)) {
  237. $ident = rcmail_identity_select($MESSAGE, $MESSAGE->identities, $compose_mode);
  238. $MESSAGE->compose['from'] = $ident['identity_id'];
  239. $MESSAGE->compose['ident'] = $ident;
  240. }
  241. // process $MESSAGE body/attachments, set $MESSAGE_BODY/$HTML_MODE vars and some session data
  242. $MESSAGE_BODY = rcmail_prepare_message_body();
  243. $OUTPUT->include_script('publickey.js');
  244. // register UI objects
  245. $OUTPUT->add_handlers(array(
  246. 'composeheaders' => 'rcmail_compose_headers',
  247. 'composesubject' => 'rcmail_compose_subject',
  248. 'composebody' => 'rcmail_compose_body',
  249. 'composeattachmentlist' => 'rcmail_compose_attachment_list',
  250. 'composeattachmentform' => 'rcmail_compose_attachment_form',
  251. 'composeattachment' => 'rcmail_compose_attachment_field',
  252. 'filedroparea' => 'compose_file_drop_area',
  253. 'priorityselector' => 'rcmail_priority_selector',
  254. 'editorselector' => 'rcmail_editor_selector',
  255. 'receiptcheckbox' => 'rcmail_mdn_checkbox', // deprecated
  256. 'mdncheckbox' => 'rcmail_mdn_checkbox',
  257. 'dsncheckbox' => 'rcmail_dsn_checkbox',
  258. 'storetarget' => 'rcmail_store_target_selection',
  259. 'addressbooks' => 'rcmail_addressbook_list',
  260. 'addresslist' => 'rcmail_contacts_list',
  261. 'responseslist' => 'rcmail_compose_responses_list',
  262. ));
  263. $OUTPUT->send('compose');
  264. /****** compose mode functions ********/
  265. // process compose request parameters
  266. function rcmail_process_compose_params(&$COMPOSE)
  267. {
  268. if ($COMPOSE['param']['to']) {
  269. $mailto = explode('?', $COMPOSE['param']['to'], 2);
  270. // #1486037: remove "mailto:" prefix
  271. $COMPOSE['param']['to'] = preg_replace('/^mailto:/i', '', $mailto[0]);
  272. // #1490346: decode the recipient address
  273. // #1490510: use raw encoding for correct "+" character handling as specified in RFC6068
  274. $COMPOSE['param']['to'] = rawurldecode($COMPOSE['param']['to']);
  275. // Supported case-insensitive tokens in mailto URL
  276. $url_tokens = array('to', 'cc', 'bcc', 'reply-to', 'in-reply-to', 'references', 'subject', 'body');
  277. if (!empty($mailto[1])) {
  278. parse_str($mailto[1], $query);
  279. foreach ($query as $f => $val) {
  280. if (($key = array_search(strtolower($f), $url_tokens)) !== false) {
  281. $f = $url_tokens[$key];
  282. }
  283. // merge mailto: addresses with addresses from 'to' parameter
  284. if ($f == 'to' && !empty($COMPOSE['param']['to'])) {
  285. $to_addresses = rcube_mime::decode_address_list($COMPOSE['param']['to'], null, true, null, true);
  286. $add_addresses = rcube_mime::decode_address_list($val, null, true);
  287. foreach ($add_addresses as $addr) {
  288. if (!in_array($addr['mailto'], $to_addresses)) {
  289. $to_addresses[] = $addr['mailto'];
  290. $COMPOSE['param']['to'] = (!empty($to_addresses) ? ', ' : '') . $addr['string'];
  291. }
  292. }
  293. }
  294. else {
  295. $COMPOSE['param'][$f] = $val;
  296. }
  297. }
  298. }
  299. }
  300. // resolve _forward_uid=* to an absolute list of messages from a search result
  301. if ($COMPOSE['param']['forward_uid'] == '*' && is_object($_SESSION['search'][1])) {
  302. $COMPOSE['param']['forward_uid'] = $_SESSION['search'][1]->get();
  303. }
  304. // clean HTML message body which can be submitted by URL
  305. if (!empty($COMPOSE['param']['body'])) {
  306. if ($COMPOSE['param']['html'] = strpos($COMPOSE['param']['body'], '<') !== false) {
  307. $wash_params = array('safe' => false, 'inline_html' => true);
  308. $COMPOSE['param']['body'] = rcmail_wash_html($COMPOSE['param']['body'], $wash_params, array());
  309. $COMPOSE['param']['body'] = preg_replace('/<!--[^>\n]+>/', '', $COMPOSE['param']['body']);
  310. $COMPOSE['param']['body'] = preg_replace('/<\/?body>/', '', $COMPOSE['param']['body']);
  311. }
  312. }
  313. $RCMAIL = rcmail::get_instance();
  314. // select folder where to save the sent message
  315. $COMPOSE['param']['sent_mbox'] = $RCMAIL->config->get('sent_mbox');
  316. // pipe compose parameters thru plugins
  317. $plugin = $RCMAIL->plugins->exec_hook('message_compose', $COMPOSE);
  318. $COMPOSE['param'] = array_merge($COMPOSE['param'], $plugin['param']);
  319. // add attachments listed by message_compose hook
  320. if (is_array($plugin['attachments'])) {
  321. foreach ($plugin['attachments'] as $attach) {
  322. // we have structured data
  323. if (is_array($attach)) {
  324. $attachment = $attach + array('group' => $COMPOSE_ID);
  325. }
  326. // only a file path is given
  327. else {
  328. $filename = basename($attach);
  329. $attachment = array(
  330. 'group' => $COMPOSE_ID,
  331. 'name' => $filename,
  332. 'mimetype' => rcube_mime::file_content_type($attach, $filename),
  333. 'size' => filesize($attach),
  334. 'path' => $attach,
  335. );
  336. }
  337. // save attachment if valid
  338. if (($attachment['data'] && $attachment['name']) || ($attachment['path'] && file_exists($attachment['path']))) {
  339. $attachment = rcmail::get_instance()->plugins->exec_hook('attachment_save', $attachment);
  340. }
  341. if ($attachment['status'] && !$attachment['abort']) {
  342. unset($attachment['data'], $attachment['status'], $attachment['abort']);
  343. $COMPOSE['attachments'][$attachment['id']] = $attachment;
  344. }
  345. }
  346. }
  347. }
  348. function rcmail_compose_headers($attrib)
  349. {
  350. global $RCMAIL, $MESSAGE;
  351. list($form_start,) = get_form_tags($attrib);
  352. $out = '';
  353. $part = strtolower($attrib['part']);
  354. switch ($part) {
  355. case 'from':
  356. return $form_start . rcmail_compose_header_from($attrib);
  357. case 'to':
  358. case 'cc':
  359. case 'bcc':
  360. $fname = '_' . $part;
  361. $header = $param = $part;
  362. $allow_attrib = array('id', 'class', 'style', 'cols', 'rows', 'tabindex');
  363. $field_type = 'html_textarea';
  364. break;
  365. case 'replyto':
  366. case 'reply-to':
  367. $fname = '_replyto';
  368. $param = 'replyto';
  369. $header = 'reply-to';
  370. case 'followupto':
  371. case 'followup-to':
  372. if (!$fname) {
  373. $fname = '_followupto';
  374. $param = 'followupto';
  375. $header = 'mail-followup-to';
  376. }
  377. $allow_attrib = array('id', 'class', 'style', 'size', 'tabindex');
  378. $field_type = 'html_inputfield';
  379. break;
  380. }
  381. if ($fname && $field_type) {
  382. // pass the following attributes to the form class
  383. $field_attrib = array('name' => $fname, 'spellcheck' => 'false');
  384. foreach ($attrib as $attr => $value) {
  385. if (in_array($attr, $allow_attrib)) {
  386. $field_attrib[$attr] = $value;
  387. }
  388. }
  389. // create teaxtarea object
  390. $input = new $field_type($field_attrib);
  391. $out = $input->show(rcmail_compose_header_value($param));
  392. }
  393. if ($form_start) {
  394. $out = $form_start . $out;
  395. }
  396. // configure autocompletion
  397. $RCMAIL->autocomplete_init();
  398. return $out;
  399. }
  400. function rcmail_compose_header_from($attrib)
  401. {
  402. global $MESSAGE, $OUTPUT, $RCMAIL, $COMPOSE;
  403. // pass the following attributes to the form class
  404. $field_attrib = array('name' => '_from');
  405. foreach ($attrib as $attr => $value) {
  406. if (in_array($attr, array('id', 'class', 'style', 'size', 'tabindex'))) {
  407. $field_attrib[$attr] = $value;
  408. }
  409. }
  410. if (count($MESSAGE->identities)) {
  411. $a_signatures = array();
  412. $identities = array();
  413. $top_posting = intval($RCMAIL->config->get('reply_mode')) > 0
  414. && !$RCMAIL->config->get('sig_below')
  415. && ($COMPOSE['mode'] == RCUBE_COMPOSE_REPLY || $COMPOSE['mode'] == RCUBE_COMPOSE_FORWARD);
  416. $separator = $top_posting ? '---' : '-- ';
  417. $add_separator = (bool) $RCMAIL->config->get('sig_separator');
  418. $field_attrib['onchange'] = rcmail_output::JS_OBJECT_NAME.".change_identity(this)";
  419. $select_from = new html_select($field_attrib);
  420. // create SELECT element
  421. foreach ($MESSAGE->identities as $sql_arr) {
  422. $identity_id = $sql_arr['identity_id'];
  423. $select_from->add(format_email_recipient($sql_arr['email'], $sql_arr['name']), $identity_id);
  424. // add signature to array
  425. if (!empty($sql_arr['signature']) && empty($COMPOSE['param']['nosig'])) {
  426. $text = $html = $sql_arr['signature'];
  427. if ($sql_arr['html_signature']) {
  428. $text = $RCMAIL->html2text($html, array('links' => false));
  429. $text = trim($text, "\r\n");
  430. }
  431. else {
  432. $t2h = new rcube_text2html($text, false);
  433. $html = $t2h->get_html();
  434. }
  435. if ($add_separator && !preg_match('/^--[ -]\r?\n/m', $text)) {
  436. $text = $separator . "\n" . ltrim($text, "\r\n");
  437. $html = $separator . "<br>" . $html;
  438. }
  439. $a_signatures[$identity_id]['text'] = $text;
  440. $a_signatures[$identity_id]['html'] = $html;
  441. }
  442. // add bcc and reply-to
  443. if (!empty($sql_arr['reply-to'])) {
  444. $identities[$identity_id]['replyto'] = $sql_arr['reply-to'];
  445. }
  446. if (!empty($sql_arr['bcc'])) {
  447. $identities[$identity_id]['bcc'] = $sql_arr['bcc'];
  448. }
  449. $identities[$identity_id]['email'] = $sql_arr['email'];
  450. }
  451. $out = $select_from->show($MESSAGE->compose['from']);
  452. // add signatures to client
  453. $OUTPUT->set_env('signatures', $a_signatures);
  454. $OUTPUT->set_env('identities', $identities);
  455. }
  456. // no identities, display text input field
  457. else {
  458. $field_attrib['class'] = 'from_address';
  459. $input_from = new html_inputfield($field_attrib);
  460. $out = $input_from->show($MESSAGE->compose['from']);
  461. }
  462. return $out;
  463. }
  464. function rcmail_compose_header_value($header)
  465. {
  466. global $COMPOSE, $MESSAGE;
  467. $RCMAIL = rcube::get_instance();
  468. $fvalue = '';
  469. $decode_header = true;
  470. $charset = $MESSAGE->headers->charset;
  471. $separator = trim($RCMAIL->config->get('recipients_separator', ',')) . ' ';
  472. // we have a set of recipients stored is session
  473. if ($header == 'to' && ($mailto_id = $COMPOSE['param']['mailto'])
  474. && $_SESSION['mailto'][$mailto_id]
  475. ) {
  476. $fvalue = urldecode($_SESSION['mailto'][$mailto_id]);
  477. $decode_header = false;
  478. $charset = $RCMAIL->output->charset;
  479. // make session to not grow up too much
  480. unset($_SESSION['mailto'][$mailto_id]);
  481. $COMPOSE['param']['to'] = $fvalue;
  482. }
  483. else if (!empty($_POST['_' . $header])) {
  484. $fvalue = rcube_utils::get_input_value('_' . $header, rcube_utils::INPUT_POST, true);
  485. $charset = $RCMAIL->output->charset;
  486. }
  487. else if (!empty($COMPOSE['param'][$header])) {
  488. $fvalue = $COMPOSE['param'][$header];
  489. $charset = $RCMAIL->output->charset;
  490. }
  491. else if ($COMPOSE['mode'] == RCUBE_COMPOSE_REPLY) {
  492. // get recipent address(es) out of the message headers
  493. if ($header == 'to') {
  494. $mailfollowup = $MESSAGE->headers->others['mail-followup-to'];
  495. $mailreplyto = $MESSAGE->headers->others['mail-reply-to'];
  496. // Reply to mailing list...
  497. if ($MESSAGE->reply_all == 'list' && $mailfollowup) {
  498. $fvalue = $mailfollowup;
  499. }
  500. else if ($MESSAGE->reply_all == 'list'
  501. && preg_match('/<mailto:([^>]+)>/i', $MESSAGE->headers->others['list-post'], $m)
  502. ) {
  503. $fvalue = $m[1];
  504. }
  505. // Reply to...
  506. else if ($MESSAGE->reply_all && $mailfollowup) {
  507. $fvalue = $mailfollowup;
  508. }
  509. else if ($mailreplyto) {
  510. $fvalue = $mailreplyto;
  511. }
  512. else if (!empty($MESSAGE->headers->replyto)) {
  513. $fvalue = $MESSAGE->headers->replyto;
  514. $replyto = true;
  515. }
  516. else if (!empty($MESSAGE->headers->from)) {
  517. $fvalue = $MESSAGE->headers->from;
  518. }
  519. // Reply to message sent by yourself (#1487074, #1489230, #1490439)
  520. // Reply-To address need to be unset (#1490233)
  521. if (!empty($MESSAGE->compose['ident']) && empty($replyto)) {
  522. foreach (array($fvalue, $MESSAGE->headers->from) as $sender) {
  523. $senders = rcube_mime::decode_address_list($sender, null, false, $charset, true);
  524. if (in_array($MESSAGE->compose['ident']['email_ascii'], $senders)) {
  525. $fvalue = $MESSAGE->headers->to;
  526. break;
  527. }
  528. }
  529. }
  530. }
  531. // add recipient of original message if reply to all
  532. else if ($header == 'cc' && !empty($MESSAGE->reply_all) && $MESSAGE->reply_all != 'list') {
  533. if ($v = $MESSAGE->headers->to) {
  534. $fvalue .= $v;
  535. }
  536. if ($v = $MESSAGE->headers->cc) {
  537. $fvalue .= (!empty($fvalue) ? $separator : '') . $v;
  538. }
  539. // Use Sender header (#1489011)
  540. if ($v = $MESSAGE->headers->get('Sender', false)) {
  541. // Skip common mailing lists addresses: *-bounces@ and *-request@ (#1490452)
  542. if (empty($MESSAGE->headers->others['list-post']) || !preg_match('/-(bounces|request)@/', $v)) {
  543. $fvalue .= (!empty($fvalue) ? $separator : '') . $v;
  544. }
  545. }
  546. // When To: and Reply-To: are the same we add From: address to the list (#1489037)
  547. if ($v = $MESSAGE->headers->from) {
  548. $from = rcube_mime::decode_address_list($v, null, false, $charset, true);
  549. $to = rcube_mime::decode_address_list($MESSAGE->headers->to, null, false, $charset, true);
  550. $replyto = rcube_mime::decode_address_list($MESSAGE->headers->replyto, null, false, $charset, true);
  551. if (count($replyto) && !count(array_diff($to, $replyto)) && count(array_diff($from, $to))) {
  552. $fvalue .= (!empty($fvalue) ? $separator : '') . $v;
  553. }
  554. }
  555. }
  556. }
  557. else if (in_array($COMPOSE['mode'], array(RCUBE_COMPOSE_DRAFT, RCUBE_COMPOSE_EDIT))) {
  558. // get drafted headers
  559. if ($header == 'to' && !empty($MESSAGE->headers->to)) {
  560. $fvalue = $MESSAGE->get_header('to', true);
  561. }
  562. else if ($header == 'cc' && !empty($MESSAGE->headers->cc)) {
  563. $fvalue = $MESSAGE->get_header('cc', true);
  564. }
  565. else if ($header == 'bcc' && !empty($MESSAGE->headers->bcc)) {
  566. $fvalue = $MESSAGE->get_header('bcc', true);
  567. }
  568. else if ($header == 'replyto' && !empty($MESSAGE->headers->others['mail-reply-to'])) {
  569. $fvalue = $MESSAGE->get_header('mail-reply-to');
  570. }
  571. else if ($header == 'replyto' && !empty($MESSAGE->headers->replyto)) {
  572. $fvalue = $MESSAGE->get_header('reply-to');
  573. }
  574. else if ($header == 'followupto' && !empty($MESSAGE->headers->others['mail-followup-to'])) {
  575. $fvalue = $MESSAGE->get_header('mail-followup-to');
  576. }
  577. }
  578. // split recipients and put them back together in a unique way
  579. if (!empty($fvalue) && in_array($header, array('to', 'cc', 'bcc'))) {
  580. $from_email = @mb_strtolower($MESSAGE->compose['ident']['email']);
  581. $to_addresses = rcube_mime::decode_address_list($fvalue, null, $decode_header, $charset);
  582. $fvalue = array();
  583. foreach ($to_addresses as $addr_part) {
  584. if (empty($addr_part['mailto'])) {
  585. continue;
  586. }
  587. // According to RFC5321 local part of email address is case-sensitive
  588. // however, here it is better to compare addresses in case-insensitive manner
  589. $mailto = format_email(rcube_utils::idn_to_utf8($addr_part['mailto']));
  590. $mailto_lc = mb_strtolower($addr_part['mailto']);
  591. if (($header == 'to' || $COMPOSE['mode'] != RCUBE_COMPOSE_REPLY || $mailto_lc != $from_email)
  592. && !in_array($mailto_lc, (array) $MESSAGE->recipients)
  593. ) {
  594. if ($addr_part['name'] && $mailto != $addr_part['name']) {
  595. $mailto = format_email_recipient($mailto, $addr_part['name']);
  596. }
  597. $fvalue[] = $mailto;
  598. $MESSAGE->recipients[] = $mailto_lc;
  599. }
  600. }
  601. $fvalue = implode($separator, $fvalue);
  602. }
  603. return $fvalue;
  604. }
  605. function rcmail_compose_editor_mode()
  606. {
  607. global $RCMAIL, $COMPOSE;
  608. static $useHtml;
  609. if ($useHtml !== null) {
  610. return $useHtml;
  611. }
  612. $html_editor = intval($RCMAIL->config->get('htmleditor'));
  613. $compose_mode = $COMPOSE['mode'];
  614. if (is_bool($COMPOSE['param']['html'])) {
  615. $useHtml = $COMPOSE['param']['html'];
  616. }
  617. else if (isset($_POST['_is_html'])) {
  618. $useHtml = !empty($_POST['_is_html']);
  619. }
  620. else if ($compose_mode == RCUBE_COMPOSE_DRAFT || $compose_mode == RCUBE_COMPOSE_EDIT) {
  621. $useHtml = rcmail_message_is_html();
  622. }
  623. else if ($compose_mode == RCUBE_COMPOSE_REPLY) {
  624. $useHtml = $html_editor == 1 || ($html_editor >= 2 && rcmail_message_is_html());
  625. }
  626. else if ($compose_mode == RCUBE_COMPOSE_FORWARD) {
  627. $useHtml = $html_editor == 1 || $html_editor == 4
  628. || ($html_editor == 3 && rcmail_message_is_html());
  629. }
  630. else {
  631. $useHtml = $html_editor == 1 || $html_editor == 4;
  632. }
  633. return $useHtml;
  634. }
  635. function rcmail_message_is_html()
  636. {
  637. global $RCMAIL, $MESSAGE;
  638. return $RCMAIL->config->get('prefer_html') && ($MESSAGE instanceof rcube_message) && $MESSAGE->has_html_part(true);
  639. }
  640. function rcmail_prepare_message_body()
  641. {
  642. global $RCMAIL, $MESSAGE, $COMPOSE, $HTML_MODE;
  643. // use posted message body
  644. if (!empty($_POST['_message'])) {
  645. $body = rcube_utils::get_input_value('_message', rcube_utils::INPUT_POST, true);
  646. $isHtml = (bool) rcube_utils::get_input_value('_is_html', rcube_utils::INPUT_POST);
  647. }
  648. else if ($COMPOSE['param']['body']) {
  649. $body = $COMPOSE['param']['body'];
  650. $isHtml = (bool) $COMPOSE['param']['html'];
  651. }
  652. // forward as attachment
  653. else if ($COMPOSE['mode'] == RCUBE_COMPOSE_FORWARD && $COMPOSE['as_attachment']) {
  654. $isHtml = rcmail_compose_editor_mode();
  655. $body = '';
  656. rcmail_write_forward_attachments();
  657. }
  658. // reply/edit/draft/forward
  659. else if ($COMPOSE['mode'] && ($COMPOSE['mode'] != RCUBE_COMPOSE_REPLY || intval($RCMAIL->config->get('reply_mode')) != -1)) {
  660. $isHtml = rcmail_compose_editor_mode();
  661. $messages = array();
  662. if (!empty($MESSAGE->parts)) {
  663. // collect IDs of message/rfc822 parts
  664. foreach ($MESSAGE->mime_parts() as $part) {
  665. if ($part->mimetype == 'message/rfc822') {
  666. $messages[] = $part->mime_id;
  667. }
  668. }
  669. foreach ($MESSAGE->parts as $part) {
  670. if ($part->realtype == 'multipart/encrypted') {
  671. // find the encrypted message payload part
  672. if ($pgp_mime_part = $MESSAGE->get_multipart_encrypted_part()) {
  673. $RCMAIL->output->set_env('pgp_mime_message', array(
  674. '_mbox' => $RCMAIL->storage->get_folder(),
  675. '_uid' => $MESSAGE->uid,
  676. '_part' => $pgp_mime_part->mime_id,
  677. ));
  678. }
  679. continue;
  680. }
  681. // skip no-content and attachment parts (#1488557)
  682. if ($part->type != 'content' || !$part->size || $MESSAGE->is_attachment($part)) {
  683. continue;
  684. }
  685. // skip all content parts inside the message/rfc822 part
  686. foreach ($messages as $mimeid) {
  687. if (strpos($part->mime_id, $mimeid . '.') === 0) {
  688. continue 2;
  689. }
  690. }
  691. if ($part_body = rcmail_compose_part_body($part, $isHtml)) {
  692. $body .= ($body ? ($isHtml ? '<br/>' : "\n") : '') . $part_body;
  693. }
  694. }
  695. }
  696. else {
  697. $body = rcmail_compose_part_body($MESSAGE, $isHtml);
  698. }
  699. // compose reply-body
  700. if ($COMPOSE['mode'] == RCUBE_COMPOSE_REPLY) {
  701. $body = rcmail_create_reply_body($body, $isHtml);
  702. if ($MESSAGE->pgp_mime) {
  703. $RCMAIL->output->set_env('compose_reply_header', rcmail_get_reply_header($MESSAGE));
  704. }
  705. }
  706. // forward message body inline
  707. else if ($COMPOSE['mode'] == RCUBE_COMPOSE_FORWARD) {
  708. $body = rcmail_create_forward_body($body, $isHtml);
  709. }
  710. // load draft message body
  711. else if ($COMPOSE['mode'] == RCUBE_COMPOSE_DRAFT || $COMPOSE['mode'] == RCUBE_COMPOSE_EDIT) {
  712. $body = rcmail_create_draft_body($body, $isHtml);
  713. }
  714. }
  715. else { // new message
  716. $isHtml = rcmail_compose_editor_mode();
  717. }
  718. $plugin = $RCMAIL->plugins->exec_hook('message_compose_body',
  719. array('body' => $body, 'html' => $isHtml, 'mode' => $COMPOSE['mode']));
  720. $body = $plugin['body'];
  721. unset($plugin);
  722. // add blocked.gif attachment (#1486516)
  723. $regexp = '# src="program/resources/blocked\.gif"#';
  724. if ($isHtml && preg_match($regexp, $body)) {
  725. $content = $RCMAIL->get_resource_content('blocked.gif');
  726. if ($content && ($attachment = rcmail_save_image('blocked.gif', 'image/gif', $content))) {
  727. $COMPOSE['attachments'][$attachment['id']] = $attachment;
  728. $url = sprintf('%s&_id=%s&_action=display-attachment&_file=rcmfile%s',
  729. $RCMAIL->comm_path, $COMPOSE['id'], $attachment['id']);
  730. $body = preg_replace($regexp, ' src="' . $url . '"', $body);
  731. }
  732. }
  733. $HTML_MODE = $isHtml;
  734. return $body;
  735. }
  736. function rcmail_compose_part_body($part, $isHtml = false)
  737. {
  738. global $RCMAIL, $COMPOSE, $MESSAGE, $LINE_LENGTH;
  739. // Check if we have enough memory to handle the message in it
  740. // #1487424: we need up to 10x more memory than the body
  741. if (!rcube_utils::mem_check($part->size * 10)) {
  742. return '';
  743. }
  744. // fetch part if not available
  745. $body = $MESSAGE->get_part_body($part->mime_id, true);
  746. // message is cached but not exists (#1485443), or other error
  747. if ($body === false) {
  748. return '';
  749. }
  750. // register this part as pgp encrypted
  751. if (strpos($body, '-----BEGIN PGP MESSAGE-----') !== false) {
  752. $MESSAGE->pgp_mime = true;
  753. $RCMAIL->output->set_env('pgp_mime_message', array(
  754. '_mbox' => $RCMAIL->storage->get_folder(), '_uid' => $MESSAGE->uid, '_part' => $part->mime_id,
  755. ));
  756. }
  757. if ($isHtml) {
  758. if ($part->ctype_secondary == 'html') {
  759. }
  760. else if ($part->ctype_secondary == 'enriched') {
  761. $body = rcube_enriched::to_html($body);
  762. }
  763. else {
  764. // try to remove the signature
  765. if ($COMPOSE['mode'] != RCUBE_COMPOSE_DRAFT && $COMPOSE['mode'] != RCUBE_COMPOSE_EDIT) {
  766. if ($RCMAIL->config->get('strip_existing_sig', true)) {
  767. $body = rcmail_remove_signature($body);
  768. }
  769. }
  770. // add HTML formatting
  771. $body = rcmail_plain_body($body, $part->ctype_parameters['format'] == 'flowed', $part->ctype_parameters['delsp'] == 'yes');
  772. }
  773. }
  774. else {
  775. if ($part->ctype_secondary == 'enriched') {
  776. $body = rcube_enriched::to_html($body);
  777. $part->ctype_secondary = 'html';
  778. }
  779. if ($part->ctype_secondary == 'html') {
  780. // use html part if it has been used for message (pre)viewing
  781. // decrease line length for quoting
  782. $len = $COMPOSE['mode'] == RCUBE_COMPOSE_REPLY ? $LINE_LENGTH-2 : $LINE_LENGTH;
  783. $body = $RCMAIL->html2text($body, array('width' => $len));
  784. }
  785. else {
  786. if ($part->ctype_secondary == 'plain' && $part->ctype_parameters['format'] == 'flowed') {
  787. $body = rcube_mime::unfold_flowed($body, null, $part->ctype_parameters['delsp'] == 'yes');
  788. }
  789. // try to remove the signature
  790. if ($COMPOSE['mode'] != RCUBE_COMPOSE_DRAFT && $COMPOSE['mode'] != RCUBE_COMPOSE_EDIT) {
  791. if ($RCMAIL->config->get('strip_existing_sig', true)) {
  792. $body = rcmail_remove_signature($body);
  793. }
  794. }
  795. }
  796. }
  797. return $body;
  798. }
  799. function rcmail_compose_body($attrib)
  800. {
  801. global $RCMAIL, $OUTPUT, $HTML_MODE, $MESSAGE_BODY;
  802. list($form_start, $form_end) = get_form_tags($attrib);
  803. unset($attrib['form']);
  804. if (empty($attrib['id'])) {
  805. $attrib['id'] = 'rcmComposeBody';
  806. }
  807. // If desired, set this textarea to be editable by TinyMCE
  808. if ($HTML_MODE) {
  809. $attrib['class'] = 'mce_editor';
  810. }
  811. $attrib['name'] = '_message';
  812. $textarea = new html_textarea($attrib);
  813. $hidden = new html_hiddenfield();
  814. $hidden->add(array('name' => '_draft_saveid', 'value' => $RCMAIL->output->get_env('draft_id')));
  815. $hidden->add(array('name' => '_draft', 'value' => ''));
  816. $hidden->add(array('name' => '_is_html', 'value' => $HTML_MODE ? "1" : "0"));
  817. $hidden->add(array('name' => '_framed', 'value' => '1'));
  818. $OUTPUT->set_env('composebody', $attrib['id']);
  819. // include HTML editor
  820. $RCMAIL->html_editor();
  821. // Set language list
  822. if ($RCMAIL->config->get('enable_spellcheck')) {
  823. $engine = new rcube_spellchecker();
  824. $dictionary = (bool) $RCMAIL->config->get('spellcheck_dictionary');
  825. $spellcheck_langs = $engine->languages();
  826. $lang = $_SESSION['language'];
  827. // if not found in the list, try with two-letter code
  828. if (!$spellcheck_langs[$lang]) {
  829. $lang = strtolower(substr($lang, 0, 2));
  830. }
  831. if (!$spellcheck_langs[$lang]) {
  832. $lang = 'en';
  833. }
  834. $editor_lang_set = array();
  835. foreach ($spellcheck_langs as $key => $name) {
  836. $editor_lang_set[] = ($key == $lang ? '+' : '') . rcube::JQ($name).'='.rcube::JQ($key);
  837. }
  838. // include GoogieSpell
  839. $OUTPUT->include_script('googiespell.js');
  840. $OUTPUT->add_script(sprintf(
  841. "var googie = new GoogieSpell('%s/images/googiespell/','%s&lang=', %s);\n".
  842. "googie.lang_chck_spell = \"%s\";\n".
  843. "googie.lang_rsm_edt = \"%s\";\n".
  844. "googie.lang_close = \"%s\";\n".
  845. "googie.lang_revert = \"%s\";\n".
  846. "googie.lang_no_error_found = \"%s\";\n".
  847. "googie.lang_learn_word = \"%s\";\n".
  848. "googie.setLanguages(%s);\n".
  849. "googie.setCurrentLanguage('%s');\n".
  850. "googie.setDecoration(false);\n".
  851. "googie.decorateTextarea('%s');\n",
  852. $RCMAIL->output->asset_url($RCMAIL->output->get_skin_path()),
  853. $RCMAIL->url(array('_task' => 'utils', '_action' => 'spell', '_remote' => 1)),
  854. !empty($dictionary) ? 'true' : 'false',
  855. rcube::JQ(rcube::Q($RCMAIL->gettext('checkspelling'))),
  856. rcube::JQ(rcube::Q($RCMAIL->gettext('resumeediting'))),
  857. rcube::JQ(rcube::Q($RCMAIL->gettext('close'))),
  858. rcube::JQ(rcube::Q($RCMAIL->gettext('revertto'))),
  859. rcube::JQ(rcube::Q($RCMAIL->gettext('nospellerrors'))),
  860. rcube::JQ(rcube::Q($RCMAIL->gettext('addtodict'))),
  861. rcube_output::json_serialize($spellcheck_langs),
  862. $lang,
  863. $attrib['id']), 'foot');
  864. $OUTPUT->add_label('checking');
  865. $OUTPUT->set_env('spellcheck_langs', join(',', $editor_lang_set));
  866. $OUTPUT->set_env('spell_langs', $spellcheck_langs);
  867. $OUTPUT->set_env('spell_lang', $lang);
  868. }
  869. return ($form_start ? "$form_start\n" : '')
  870. . "\n" . $hidden->show() . "\n" . $textarea->show($MESSAGE_BODY)
  871. . ($form_end ? "\n$form_end\n" : '')
  872. . '<iframe name="savetarget" src="program/resources/blank.gif"'
  873. . ' style="width:0;height:0;border:none;visibility:hidden;" aria-hidden="true"></iframe>';
  874. }
  875. function rcmail_create_reply_body($body, $bodyIsHtml)
  876. {
  877. global $RCMAIL, $MESSAGE, $LINE_LENGTH;
  878. $prefix = rcmail_get_reply_header($MESSAGE);
  879. $reply_mode = intval($RCMAIL->config->get('reply_mode'));
  880. if (!$bodyIsHtml) {
  881. // soft-wrap and quote message text
  882. $body = rcmail_wrap_and_quote($body, $LINE_LENGTH);
  883. $prefix .= "\n";
  884. if ($reply_mode > 0) { // top-posting
  885. $prefix = "\n\n\n" . $prefix;
  886. $suffix = '';
  887. }
  888. else {
  889. $suffix = "\n";
  890. }
  891. }
  892. else {
  893. // save inline images to files
  894. $cid_map = rcmail_write_inline_attachments($MESSAGE);
  895. // set is_safe flag (we need this for html body washing)
  896. rcmail_check_safe($MESSAGE);
  897. // clean up html tags
  898. $body = rcmail_wash_html($body, array('safe' => $MESSAGE->is_safe), $cid_map);
  899. // build reply (quote content)
  900. $prefix = '<p>' . rcube::Q($prefix) . "</p>\n";
  901. $prefix .= '<blockquote>';
  902. if ($reply_mode > 0) { // top-posting
  903. $prefix = '<br>' . $prefix;
  904. $suffix = '</blockquote>';
  905. }
  906. else {
  907. $suffix = '</blockquote><p><br/></p>';
  908. }
  909. }
  910. return $prefix . $body . $suffix;
  911. }
  912. function rcmail_get_reply_header($message)
  913. {
  914. global $RCMAIL;
  915. $from = array_pop(rcube_mime::decode_address_list($message->get_header('from'), 1, false, $message->headers->charset));
  916. return $RCMAIL->gettext(array(
  917. 'name' => 'mailreplyintro',
  918. 'vars' => array(
  919. 'date' => $RCMAIL->format_date($message->headers->date, $RCMAIL->config->get('date_long')),
  920. 'sender' => $from['name'] ?: rcube_utils::idn_to_utf8($from['mailto']),
  921. )
  922. ));
  923. }
  924. function rcmail_create_forward_body($body, $bodyIsHtml)
  925. {
  926. global $RCMAIL, $MESSAGE, $COMPOSE;
  927. // add attachments
  928. if (!isset($COMPOSE['forward_attachments']) && is_array($MESSAGE->mime_parts)) {
  929. $cid_map = rcmail_write_compose_attachments($MESSAGE, $bodyIsHtml);
  930. }
  931. $date = $RCMAIL->format_date($MESSAGE->headers->date, $RCMAIL->config->get('date_long'));
  932. if (!$bodyIsHtml) {
  933. $prefix = "\n\n\n-------- " . $RCMAIL->gettext('originalmessage') . " --------\n";
  934. $prefix .= $RCMAIL->gettext('subject') . ': ' . $MESSAGE->subject . "\n";
  935. $prefix .= $RCMAIL->gettext('date') . ': ' . $date . "\n";
  936. $prefix .= $RCMAIL->gettext('from') . ': ' . $MESSAGE->get_header('from') . "\n";
  937. $prefix .= $RCMAIL->gettext('to') . ': ' . $MESSAGE->get_header('to') . "\n";
  938. if ($cc = $MESSAGE->headers->get('cc')) {
  939. $prefix .= $RCMAIL->gettext('cc') . ': ' . $cc . "\n";
  940. }
  941. if (($replyto = $MESSAGE->headers->get('reply-to')) && $replyto != $MESSAGE->get_header('from')) {
  942. $prefix .= $RCMAIL->gettext('replyto') . ': ' . $replyto . "\n";
  943. }
  944. $prefix .= "\n";
  945. $body = trim($body, "\r\n");
  946. }
  947. else {
  948. // set is_safe flag (we need this for html body washing)
  949. rcmail_check_safe($MESSAGE);
  950. // clean up html tags
  951. $body = rcmail_wash_html($body, array('safe' => $MESSAGE->is_safe), $cid_map);
  952. $prefix = sprintf(
  953. "<br /><p>-------- " . $RCMAIL->gettext('originalmessage') . " --------</p>" .
  954. "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tbody>" .
  955. "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>" .
  956. "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>" .
  957. "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>" .
  958. "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>",
  959. $RCMAIL->gettext('subject'), rcube::Q($MESSAGE->subject),
  960. $RCMAIL->gettext('date'), rcube::Q($date),
  961. $RCMAIL->gettext('from'), rcube::Q($MESSAGE->get_header('from'), 'replace'),
  962. $RCMAIL->gettext('to'), rcube::Q($MESSAGE->get_header('to'), 'replace'));
  963. if ($cc = $MESSAGE->headers->get('cc'))
  964. $prefix .= sprintf("<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>",
  965. $RCMAIL->gettext('cc'), rcube::Q($cc, 'replace'));
  966. if (($replyto = $MESSAGE->headers->get('reply-to')) && $replyto != $MESSAGE->get_header('from'))
  967. $prefix .= sprintf("<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>",
  968. $RCMAIL->gettext('replyto'), rcube::Q($replyto, 'replace'));
  969. $prefix .= "</tbody></table><br>";
  970. }
  971. return $prefix . $body;
  972. }
  973. function rcmail_create_draft_body($body, $bodyIsHtml)
  974. {
  975. global $MESSAGE, $COMPOSE;
  976. // add attachments
  977. // count($MESSAGE->mime_parts) can be 1 - e.g. attachment, but no text!
  978. if (empty($COMPOSE['forward_attachments'])
  979. && is_array($MESSAGE->mime_parts)
  980. && count($MESSAGE->mime_parts) > 0
  981. ) {
  982. $cid_map = rcmail_write_compose_attachments($MESSAGE, $bodyIsHtml);
  983. }
  984. // clean up HTML tags - XSS prevention (#1489251)
  985. if ($bodyIsHtml) {
  986. $body = rcmail_wash_html($body, array('safe' => 1), $cid_map);
  987. // cleanup
  988. $body = preg_replace(array(
  989. // remove comments (produced by washtml)
  990. '/<!--[^>]+-->/',
  991. // remove <body> tags
  992. '/<body([^>]*)>/i',
  993. '/<\/body>/i',
  994. // convert TinyMCE's empty-line sequence (#1490463)
  995. '/<p>\xC2\xA0<\/p>/',
  996. ),
  997. array(
  998. '',
  999. '',
  1000. '',
  1001. '<p><br /></p>',
  1002. ),
  1003. $body
  1004. );
  1005. // replace cid with href in inline images links
  1006. if (!empty($cid_map)) {
  1007. $body = str_replace(array_keys($cid_map), array_values($cid_map), $body);
  1008. }
  1009. }
  1010. return $body;
  1011. }
  1012. function rcmail_remove_signature($body)
  1013. {
  1014. global $RCMAIL;
  1015. $body = str_replace("\r\n", "\n", $body);
  1016. $len = strlen($body);
  1017. $sig_max_lines = $RCMAIL->config->get('sig_max_lines', 15);
  1018. while (($sp = strrpos($body, "-- \n", $sp ? -$len+$sp-1 : 0)) !== false) {
  1019. if ($sp == 0 || $body[$sp-1] == "\n") {
  1020. // do not touch blocks with more that X lines
  1021. if (substr_count($body, "\n", $sp) < $sig_max_lines) {
  1022. $body = substr($body, 0, max(0, $sp-1));
  1023. }
  1024. break;
  1025. }
  1026. }
  1027. return $body;
  1028. }
  1029. function rcmail_write_compose_attachments(&$message, $bodyIsHtml)
  1030. {
  1031. global $RCMAIL, $COMPOSE;
  1032. $loaded_attachments = array();
  1033. foreach ((array)$COMPOSE['attachments'] as $attachment) {
  1034. $loaded_attachments[$attachment['name'] . $attachment['mimetype']] = $attachment;
  1035. }
  1036. $cid_map = array();
  1037. $messages = array();
  1038. if ($message->pgp_mime) {
  1039. return $cid_map;
  1040. }
  1041. foreach ((array) $message->mime_parts() as $pid => $part) {
  1042. if ($part->mimetype == 'message/rfc822') {
  1043. $messages[] = $part->mime_id;
  1044. }
  1045. if ($part->disposition == 'attachment' || ($part->disposition == 'inline' && $bodyIsHtml) || $part->filename) {
  1046. // skip parts that aren't valid attachments
  1047. if ($part->ctype_primary == 'multipart' || $part->mimetype == 'application/ms-tnef') {
  1048. continue;
  1049. }
  1050. // skip message attachments in reply mode
  1051. if ($part->ctype_primary == 'message' && $COMPOSE['mode'] == RCUBE_COMPOSE_REPLY) {
  1052. continue;
  1053. }
  1054. // skip inline images when forwarding in text mode
  1055. if ($part->content_id && $part->disposition == 'inline' && !$bodyIsHtml && $COMPOSE['mode'] == RCUBE_COMPOSE_FORWARD) {
  1056. continue;
  1057. }
  1058. // skip version.txt parts of multipart/encrypted messages
  1059. if ($message->pgp_mime && $part->mimetype == 'application/pgp-encrypted' && $part->filename == 'version.txt') {
  1060. continue;
  1061. }
  1062. // skip attachments included in message/rfc822 attachment (#1486487, #1490607)
  1063. foreach ($messages as $mimeid) {
  1064. if (strpos($part->mime_id, $mimeid . '.') === 0) {
  1065. continue 2;
  1066. }
  1067. }
  1068. if (($attachment = $loaded_attachments[rcmail_attachment_name($part) . $part->mimetype])
  1069. || ($attachment = rcmail_save_attachment($message, $pid, $COMPOSE['id']))
  1070. ) {
  1071. if ($bodyIsHtml && ($part->content_id || $part->content_location)) {
  1072. $url = sprintf('%s&_id=%s&_action=display-attachment&_file=rcmfile%s',
  1073. $RCMAIL->comm_path, $COMPOSE['id'], $attachment['id']);
  1074. if ($part->content_id)
  1075. $cid_map['cid:'.$part->content_id] = $url;
  1076. else
  1077. $cid_map[$part->content_location] = $url;
  1078. }
  1079. }
  1080. }
  1081. }
  1082. $COMPOSE['forward_attachments'] = true;
  1083. return $cid_map;
  1084. }
  1085. function rcmail_write_inline_attachments(&$message)
  1086. {
  1087. global $RCMAIL, $COMPOSE;
  1088. $cid_map = array();
  1089. $messages = array();
  1090. if ($message->pgp_mime) {
  1091. return $cid_map;
  1092. }
  1093. foreach ((array) $message->mime_parts() as $pid => $part) {
  1094. if ($part->mimetype == 'message/rfc822') {
  1095. $messages[] = $part->mime_id;
  1096. }
  1097. if (($part->content_id || $part->content_location) && $part->filename) {
  1098. // skip attachments included in message/rfc822 attachment (#1486487, #1490607)
  1099. foreach ($messages as $mimeid) {
  1100. if (strpos($part->mime_id, $mimeid . '.') === 0) {
  1101. continue 2;
  1102. }
  1103. }
  1104. if ($attachment = rcmail_save_attachment($message, $pid, $COMPOSE['id'])) {
  1105. $url = sprintf('%s&_id=%s&_action=display-attachment&_file=rcmfile%s',
  1106. $RCMAIL->comm_path, $COMPOSE['id'], $attachment['id']);
  1107. if ($part->content_id)
  1108. $cid_map['cid:'.$part->content_id] = $url;
  1109. else
  1110. $cid_map[$part->content_location] = $url;
  1111. }
  1112. }
  1113. }
  1114. return $cid_map;
  1115. }
  1116. // Creates attachment(s) from the forwarded message(s)
  1117. function rcmail_write_forward_attachments()
  1118. {
  1119. global $RCMAIL, $COMPOSE, $MESSAGE;
  1120. $storage = $RCMAIL->get_storage();
  1121. $names = array();
  1122. $refs = array();
  1123. if ($MESSAGE->pgp_mime) {
  1124. return;
  1125. }
  1126. $loaded_attachments = array();
  1127. foreach ((array)$COMPOSE['attachments'] as $attachment) {
  1128. $loaded_attachments[$attachment['name'] . $attachment['mimetype']] = $attachment;
  1129. }
  1130. if ($COMPOSE['forward_uid'] == '*') {
  1131. $index = $storage->index(null, rcmail_sort_column(), rcmail_sort_order());
  1132. $COMPOSE['forward_uid'] = $index->get();
  1133. }
  1134. else if (!is_array($COMPOSE['forward_uid']) && strpos($COMPOSE['forward_uid'], ':')) {
  1135. $COMPOSE['forward_uid'] = rcube_imap_generic::uncompressMessageSet($COMPOSE['forward_uid']);
  1136. }
  1137. else if (is_string($COMPOSE['forward_uid'])) {
  1138. $COMPOSE['forward_uid'] = explode(',', $COMPOSE['forward_uid']);
  1139. }
  1140. foreach ((array)$COMPOSE['forward_uid'] as $uid) {
  1141. $message = new rcube_message($uid);
  1142. if (empty($message->headers)) {
  1143. continue;
  1144. }
  1145. if (!empty($message->headers->charset)) {
  1146. $storage->set_charset($message->headers->charset);
  1147. }
  1148. if (empty($MESSAGE->subject)) {
  1149. $MESSAGE->subject = $message->subject;
  1150. }
  1151. // generate (unique) attachment name
  1152. $name = strlen($message->subject) ? mb_substr($message->subject, 0, 64) : 'message_rfc822';
  1153. if (!empty($names[$name])) {
  1154. $names[$name]++;
  1155. $name .= '_' . $names[$name];
  1156. }
  1157. $names[$name] = 1;
  1158. $name .= '.eml';
  1159. if (!empty($loaded_attachments[$name . 'message/rfc822'])) {
  1160. continue;
  1161. }
  1162. rcmail_save_attachment($message, null, $COMPOSE['id'], array('filename' => $name));
  1163. if ($message->headers->messageID) {
  1164. $refs[] = $message->headers->messageID;
  1165. }
  1166. }
  1167. // set In-Reply-To and References headers
  1168. if (count($refs) == 1) {
  1169. $COMPOSE['reply_msgid'] = $refs[0];
  1170. }
  1171. if (!empty($refs)) {
  1172. $COMPOSE['references'] = implode(' ', $refs);
  1173. }
  1174. }
  1175. function rcmail_save_image($path, $mimetype = '', $data = null)
  1176. {
  1177. global $COMPOSE;
  1178. // handle attachments in memory
  1179. if (empty($data)) {
  1180. $data = file_get_contents($path);
  1181. $is_file = true;
  1182. }
  1183. $name = rcmail_basename($path);
  1184. if (empty($mimetype)) {
  1185. if ($is_file) {
  1186. $mimetype = rcube_mime::file_content_type($path, $name);
  1187. }
  1188. else {
  1189. $mimetype = rcube_mime::file_content_type($data, $name, 'application/octet-stream', true);
  1190. }
  1191. }
  1192. $attachment = array(
  1193. 'group' => $COMPOSE['id'],
  1194. 'name' => $name,
  1195. 'mimetype' => $mimetype,
  1196. 'data' => $data,
  1197. 'size' => strlen($data),
  1198. );
  1199. $attachment = rcmail::get_instance()->plugins->exec_hook('attachment_save', $attachment);
  1200. if ($attachment['status']) {
  1201. unset($attachment['data'], $attachment['status'], $attachment['content_id'], $attachment['abort']);
  1202. return $attachment;
  1203. }
  1204. return false;
  1205. }
  1206. function rcmail_basename($filename)
  1207. {
  1208. // basename() is not unicode safe and locale dependent
  1209. if (stristr(PHP_OS, 'win') || stristr(PHP_OS, 'netware')) {
  1210. return preg_replace('/^.*[\\\\\\/]/', '', $filename);
  1211. }
  1212. else {
  1213. return preg_replace('/^.*[\/]/', '', $filename);
  1214. }
  1215. }
  1216. /**
  1217. * Creates reply subject by removing common subject
  1218. * prefixes/suffixes from the original message subject
  1219. */
  1220. function rcmail_reply_subject($subject)
  1221. {
  1222. $subject = trim($subject);
  1223. // replace Re:, Re[x]:, Re-x (#1490497)
  1224. $prefix = '/^(re:|re\[\d\]:|re-\d:)\s*/i';
  1225. do {
  1226. $subject = preg_replace($prefix, '', $subject, -1, $count);
  1227. }
  1228. while ($count);
  1229. // replace (was: ...) (#1489375)
  1230. $subject = preg_replace('/\s*\([wW]as:[^\)]+\)\s*$/', '', $subject);
  1231. return 'Re: ' . $subject;
  1232. }
  1233. function rcmail_compose_subject($attrib)
  1234. {
  1235. global $MESSAGE, $COMPOSE;
  1236. list($form_start, $form_end) = get_form_tags($attrib);
  1237. unset($attrib['form']);
  1238. $attrib['name'] = '_subject';
  1239. $attrib['spellcheck'] = 'true';
  1240. $textfield = new html_inputfield($attrib);
  1241. $subject = '';
  1242. // use subject from post
  1243. if (isset($_POST['_subject'])) {
  1244. $subject = rcube_utils::get_input_value('_subject', rcube_utils::INPUT_POST, TRUE);
  1245. }
  1246. else if (!empty($COMPOSE['param']['subject'])) {
  1247. $subject = $COMPOSE['param']['subject'];
  1248. }
  1249. // create a reply-subject
  1250. else if ($COMPOSE['mode'] == RCUBE_COMPOSE_REPLY) {
  1251. $subject = rcmail_reply_subject($MESSAGE->subject);
  1252. }
  1253. // create a forward-subject
  1254. else if ($COMPOSE['mode'] == RCUBE_COMPOSE_FORWARD) {
  1255. if (preg_match('/^fwd:/i', $MESSAGE->subject))
  1256. $subject = $MESSAGE->subject;
  1257. else
  1258. $subject = 'Fwd: '.$MESSAGE->subject;
  1259. }
  1260. // creeate a draft-subject
  1261. else if ($COMPOSE['mode'] == RCUBE_COMPOSE_DRAFT || $COMPOSE['mode'] == RCUBE_COMPOSE_EDIT) {
  1262. $subject = $MESSAGE->subject;
  1263. }
  1264. $out = $form_start ? "$form_start\n" : '';
  1265. $out .= $textfield->show($subject);
  1266. $out .= $form_end ? "\n$form_end" : '';
  1267. return $out;
  1268. }
  1269. function rcmail_compose_attachment_list($attrib)
  1270. {
  1271. global $RCMAIL, $OUTPUT, $COMPOSE;
  1272. // add ID if not given
  1273. if (!$attrib['id'])
  1274. $attrib['id'] = 'rcmAttachmentList';
  1275. $out = "\n";
  1276. $jslist = array();
  1277. $button = '';
  1278. if ($attrib['icon_pos'] == 'left')
  1279. $COMPOSE['icon_pos'] = 'left';
  1280. if (is_array($COMPOSE['attachments'])) {
  1281. if ($attrib['deleteicon']) {
  1282. $button = html::img(array(
  1283. 'src' => $RCMAIL->output->abs_url($attrib['deleteicon'], true),
  1284. 'alt' => $RCMAIL->gettext('delete')
  1285. ));
  1286. }
  1287. else if (rcube_utils::get_boolean($attrib['textbuttons'])) {
  1288. $button = rcube::Q($RCMAIL->gettext('delete'));
  1289. }
  1290. foreach ($COMPOSE['attachments'] as $id => $a_prop) {
  1291. if (empty($a_prop)) {
  1292. continue;
  1293. }
  1294. $link_content = sprintf('%s <span class="attachment-size"> (%s)</span>',
  1295. rcube::Q($a_prop['name']), $RCMAIL->show_bytes($a_prop['size']));
  1296. $content_link = html::a(array(
  1297. 'href' => "#load",
  1298. 'class' => 'filename',
  1299. 'onclick' => sprintf("return %s.command('load-attachment','rcmfile%s', this, event)", rcmail_output::JS_OBJECT_NAME, $id),
  1300. ), $link_content);
  1301. $delete_link = html::a(array(
  1302. 'href' => "#delete",
  1303. 'title' => $RCMAIL->gettext('delete'),
  1304. 'onclick' => sprintf("return %s.command('remove-attachment','rcmfile%s', this, event)", rcmail_output::JS_OBJECT_NAME, $id),
  1305. 'class' => 'delete',
  1306. 'tabindex' => $attrib['tabindex'] ?: '0',
  1307. 'aria-label' => $RCMAIL->gettext('delete') . ' ' . $a_prop['name'],
  1308. ), $button);
  1309. $out .= html::tag('li', array(
  1310. 'id' => 'rcmfile'.$id,
  1311. 'class' => rcube_utils::file2class($a_prop['mimetype'], $a_prop['name']),
  1312. 'onmouseover' => "rcube_webmail.long_subject_title_ex(this, 0)",
  1313. ),
  1314. $COMPOSE['icon_pos'] == 'left' ? $delete_link.$content_link : $content_link.$delete_link
  1315. );
  1316. $jslist['rcmfile'.$id] = array(
  1317. 'name' => $a_prop['name'],
  1318. 'complete' => true,
  1319. 'mimetype' => $a_prop['mimetype']
  1320. );
  1321. }
  1322. }
  1323. if ($attrib['deleteicon'])
  1324. $COMPOSE['deleteicon'] = $RCMAIL->output->abs_url($attrib['deleteicon'], true);
  1325. else if (rcube_utils::get_boolean($attrib['textbuttons']))
  1326. $COMPOSE['textbuttons'] = true;
  1327. if ($attrib['cancelicon'])
  1328. $OUTPUT->set_env('cancelicon', $RCMAIL->output->abs_url($attrib['cancelicon'], true));
  1329. if ($attrib['loadingicon'])
  1330. $OUTPUT->set_env('loadingicon', $RCMAIL->output->abs_url($attrib['loadingicon'], true));
  1331. $OUTPUT->set_env('attachments', $jslist);
  1332. $OUTPUT->add_gui_object('attachmentlist', $attrib['id']);
  1333. // put tabindex value into data-tabindex attribute
  1334. if (isset($attrib['tabindex'])) {
  1335. $attrib['data-tabindex'] = $attrib['tabindex'];
  1336. unset($attrib['tabindex']);
  1337. }
  1338. return html::tag('ul', $attrib, $out, html::$common_attrib);
  1339. }
  1340. function rcmail_compose_attachment_form($attrib)
  1341. {
  1342. global $RCMAIL;
  1343. return $RCMAIL->upload_form($attrib, 'uploadform', 'send-attachment', array('multiple' => true));
  1344. }
  1345. function rcmail_priority_selector($attrib)
  1346. {
  1347. global $RCMAIL, $MESSAGE;
  1348. list($form_start, $form_end) = get_form_tags($attrib);
  1349. unset($attrib['form']);
  1350. $attrib['name'] = '_priority';
  1351. $prio_list = array(
  1352. $RCMAIL->gettext('lowest') => 5,
  1353. $RCMAIL->gettext('low') => 4,
  1354. $RCMAIL->gettext('normal') => 0,
  1355. $RCMAIL->gettext('high') => 2,
  1356. $RCMAIL->gettext('highest') => 1,
  1357. );
  1358. $selector = new html_select($attrib);
  1359. $selector->add(array_keys($prio_list), array_values($prio_list));
  1360. if (isset($_POST['_priority']))
  1361. $sel = $_POST['_priority'];
  1362. else if (isset($MESSAGE->headers->priority) && intval($MESSAGE->headers->priority) != 3)
  1363. $sel = $MESSAGE->headers->priority;
  1364. else
  1365. $sel = 0;
  1366. $out = $form_start ? "$form_start\n" : '';
  1367. $out .= $selector->show((int) $sel);
  1368. $out .= $form_end ? "\n$form_end" : '';
  1369. return $out;
  1370. }
  1371. function rcmail_mdn_checkbox($attrib)
  1372. {
  1373. global $RCMAIL, $MESSAGE;
  1374. list($form_start, $form_end) = get_form_tags($attrib);
  1375. unset($attrib['form']);
  1376. if (!isset($attrib['id']))
  1377. $attrib['id'] = 'receipt';
  1378. $attrib['name'] = '_mdn';
  1379. $attrib['value'] = '1';
  1380. $checkbox = new html_checkbox($attrib);
  1381. if (isset($_POST['_mdn']))
  1382. $mdn_default = $_POST['_mdn'];
  1383. else if (in_array($COMPOSE['mode'], array(RCUBE_COMPOSE_DRAFT, RCUBE_COMPOSE_EDIT)))
  1384. $mdn_default = (bool) $MESSAGE->headers->mdn_to;
  1385. else
  1386. $mdn_default = $RCMAIL->config->get('mdn_default');
  1387. $out = $form_start ? "$form_start\n" : '';
  1388. $out .= $checkbox->show($mdn_default);
  1389. $out .= $form_end ? "\n$form_end" : '';
  1390. return $out;
  1391. }
  1392. function rcmail_dsn_checkbox($attrib)
  1393. {
  1394. global $RCMAIL;
  1395. list($form_start, $form_end) = get_form_tags($attrib);
  1396. unset($attrib['form']);
  1397. if (!isset($attrib['id']))
  1398. $attrib['id'] = 'dsn';
  1399. $attrib['name'] = '_dsn';
  1400. $attrib['value'] = '1';
  1401. $checkbox = new html_checkbox($attrib);
  1402. if (isset($_POST['_dsn']))
  1403. $dsn_value = (int) $_POST['_dsn'];
  1404. else
  1405. $dsn_value = $RCMAIL->config->get('dsn_default');
  1406. $out = $form_start ? "$form_start\n" : '';
  1407. $out .= $checkbox->show($dsn_value);
  1408. $out .= $form_end ? "\n$form_end" : '';
  1409. return $out;
  1410. }
  1411. function rcmail_editor_selector($attrib)
  1412. {
  1413. global $RCMAIL;
  1414. // determine whether HTML or plain text should be checked
  1415. $useHtml = rcmail_compose_editor_mode();
  1416. if (empty($attrib['editorid']))
  1417. $attrib['editorid'] = 'rcmComposeBody';
  1418. if (empty($attrib['name']))
  1419. $attrib['name'] = 'editorSelect';
  1420. $attrib['onchange'] = "return rcmail.command('toggle-editor', {id: '".$attrib['editorid']."', html: this.value == 'html'}, '', event)";
  1421. $select = new html_select($attrib);
  1422. $select->add(rcube::Q($RCMAIL->gettext('htmltoggle')), 'html');
  1423. $select->add(rcube::Q($RCMAIL->gettext('plaintoggle')), 'plain');
  1424. return $select->show($useHtml ? 'html' : 'plain');
  1425. }
  1426. function rcmail_store_target_selection($attrib)
  1427. {
  1428. global $COMPOSE, $RCMAIL;
  1429. $attrib['name'] = '_store_target';
  1430. $select = $RCMAIL->folder_selector(array_merge($attrib, array(
  1431. 'noselection' => '- ' . $RCMAIL->gettext('dontsave') . ' -',
  1432. 'folder_filter' => 'mail',
  1433. 'folder_rights' => 'w',
  1434. )));
  1435. return $select->show(isset($_POST['_store_target']) ? $_POST['_store_target'] : $COMPOSE['param']['sent_mbox'], $attrib);
  1436. }
  1437. function rcmail_check_sent_folder($folder, $create=false)
  1438. {
  1439. global $RCMAIL;
  1440. // we'll not save the message, so it doesn't matter
  1441. if ($RCMAIL->config->get('no_save_sent_messages')) {
  1442. return true;
  1443. }
  1444. if ($RCMAIL->storage->folder_exists($folder, true)) {
  1445. return true;
  1446. }
  1447. // folder may exist but isn't subscribed (#1485241)
  1448. if ($create) {
  1449. if (!$RCMAIL->storage->folder_exists($folder))
  1450. return $RCMAIL->storage->create_folder($folder, true);
  1451. else
  1452. return $RCMAIL->storage->subscribe($folder);
  1453. }
  1454. return false;
  1455. }
  1456. function get_form_tags($attrib)
  1457. {
  1458. global $RCMAIL, $MESSAGE_FORM, $COMPOSE;
  1459. $form_start = '';
  1460. if (!$MESSAGE_FORM) {
  1461. $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $RCMAIL->task));
  1462. $hiddenfields->add(array('name' => '_action', 'value' => 'send'));
  1463. $hiddenfields->add(array('name' => '_id', 'value' => $COMPOSE['id']));
  1464. $hiddenfields->add(array('name' => '_attachments'));
  1465. $form_start = empty($attrib['form']) ? $RCMAIL->output->form_tag(array('name' => "form", 'method' => "post")) : '';
  1466. $form_start .= $hiddenfields->show();
  1467. }
  1468. $form_end = ($MESSAGE_FORM && !strlen($attrib['form'])) ? '</form>' : '';
  1469. $form_name = $attrib['form'] ?: 'form';
  1470. if (!$MESSAGE_FORM)
  1471. $RCMAIL->output->add_gui_object('messageform', $form_name);
  1472. $MESSAGE_FORM = $form_name;
  1473. return array($form_start, $form_end);
  1474. }
  1475. function rcmail_addressbook_list($attrib = array())
  1476. {
  1477. global $RCMAIL, $OUTPUT;
  1478. $attrib += array('id' => 'rcmdirectorylist');
  1479. $out = '';
  1480. $line_templ = html::tag('li', array(
  1481. 'id' => 'rcmli%s', 'class' => '%s'),
  1482. html::a(array('href' => '#list',
  1483. 'rel' => '%s',
  1484. 'onclick' => "return ".rcmail_output::JS_OBJECT_NAME.".command('list-addresses','%s',this)"), '%s'));
  1485. foreach ($RCMAIL->get_address_sources(false, true) as $j => $source) {
  1486. $id = strval(strlen($source['id']) ? $source['id'] : $j);
  1487. $js_id = rcube::JQ($id);
  1488. // set class name(s)
  1489. $class_name = 'addressbook';
  1490. if ($source['class_name'])
  1491. $class_name .= ' ' . $source['class_name'];
  1492. $out .= sprintf($line_templ,
  1493. rcube_utils::html_identifier($id,true),
  1494. $class_name,
  1495. $source['id'],
  1496. $js_id, ($source['name'] ?: $id));
  1497. }
  1498. $OUTPUT->add_gui_object('addressbookslist', $attrib['id']);
  1499. return html::tag('ul', $attrib, $out, html::$common_attrib);
  1500. }
  1501. // return the contacts list as HTML table
  1502. function rcmail_contacts_list($attrib = array())
  1503. {
  1504. global $RCMAIL, $OUTPUT;
  1505. $attrib += array('id' => 'rcmAddressList');
  1506. // set client env
  1507. $OUTPUT->add_gui_object('contactslist', $attrib['id']);
  1508. $OUTPUT->set_env('pagecount', 0);
  1509. $OUTPUT->set_env('current_page', 0);
  1510. $OUTPUT->include_script('list.js');
  1511. return $RCMAIL->table_output($attrib, array(), array('name'), 'ID');
  1512. }
  1513. /**
  1514. * Register a certain container as active area to drop files onto
  1515. */
  1516. function compose_file_drop_area($attrib)
  1517. {
  1518. global $OUTPUT;
  1519. if ($attrib['id']) {
  1520. $OUTPUT->add_gui_object('filedrop', $attrib['id']);
  1521. $OUTPUT->set_env('filedrop', array('action' => 'upload', 'fieldname' => '_attachments'));
  1522. }
  1523. }
  1524. /**
  1525. *
  1526. */
  1527. function rcmail_compose_responses_list($attrib)
  1528. {
  1529. global $RCMAIL, $OUTPUT;
  1530. $attrib += array('id' => 'rcmresponseslist', 'tagname' => 'ul', 'cols' => 1);
  1531. $jsenv = array();
  1532. $list = new html_table($attrib);
  1533. foreach ($RCMAIL->get_compose_responses(true) as $response) {
  1534. $key = $response['key'];
  1535. $item = html::a(array(
  1536. 'href' => '#'.urlencode($response['name']),
  1537. 'class' => rtrim('insertresponse ' . $attrib['itemclass']),
  1538. 'unselectable' => 'on',
  1539. 'tabindex' => '0',
  1540. 'rel' => $key,
  1541. ), rcube::Q($response['name']));
  1542. $jsenv[$key] = $response;
  1543. $list->add(array(), $item);
  1544. }
  1545. // set client env
  1546. $OUTPUT->set_env('textresponses', $jsenv);
  1547. $OUTPUT->add_gui_object('responseslist', $attrib['id']);
  1548. return $list->show();
  1549. }