You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

compose.inc 67KB

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