Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------+
  4. | program/steps/mail/show.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. | Display a mail message similar as a usual mail application does |
  15. | |
  16. +-----------------------------------------------------------------------+
  17. | Author: Thomas Bruederli <roundcube@gmail.com> |
  18. +-----------------------------------------------------------------------+
  19. */
  20. $PRINT_MODE = $RCMAIL->action == 'print';
  21. // Read browser capabilities and store them in session
  22. if ($caps = rcube_utils::get_input_value('_caps', rcube_utils::INPUT_GET)) {
  23. $browser_caps = array();
  24. foreach (explode(',', $caps) as $cap) {
  25. $cap = explode('=', $cap);
  26. $browser_caps[$cap[0]] = $cap[1];
  27. }
  28. $_SESSION['browser_caps'] = $browser_caps;
  29. }
  30. $uid = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_GET);
  31. $mbox_name = $RCMAIL->storage->get_folder();
  32. // similar code as in program/steps/mail/get.inc
  33. if ($uid) {
  34. // set message format (need to be done before rcube_message construction)
  35. if (!empty($_GET['_format'])) {
  36. $prefer_html = $_GET['_format'] == 'html';
  37. $RCMAIL->config->set('prefer_html', $prefer_html);
  38. $_SESSION['msg_formats'][$mbox_name.':'.$uid] = $prefer_html;
  39. }
  40. else if (isset($_SESSION['msg_formats'][$mbox_name.':'.$uid])) {
  41. $RCMAIL->config->set('prefer_html', $_SESSION['msg_formats'][$mbox_name.':'.$uid]);
  42. }
  43. $MESSAGE = new rcube_message($uid, $mbox_name, intval($_GET['_safe']));
  44. // if message not found (wrong UID)...
  45. if (empty($MESSAGE->headers)) {
  46. rcmail_message_error($uid);
  47. }
  48. // show images?
  49. rcmail_check_safe($MESSAGE);
  50. // set message charset as default
  51. if (!empty($MESSAGE->headers->charset)) {
  52. $RCMAIL->storage->set_charset($MESSAGE->headers->charset);
  53. }
  54. $OUTPUT->set_pagetitle(abbreviate_string($MESSAGE->subject, 128, '...', true));
  55. // set message environment
  56. $OUTPUT->set_env('uid', $MESSAGE->uid);
  57. $OUTPUT->set_env('safemode', $MESSAGE->is_safe);
  58. $OUTPUT->set_env('sender', $MESSAGE->sender['string']);
  59. $OUTPUT->set_env('mailbox', $mbox_name);
  60. $OUTPUT->set_env('username', $RCMAIL->get_user_name());
  61. $OUTPUT->set_env('permaurl', $RCMAIL->url(array('_action' => 'show', '_uid' => $MESSAGE->uid, '_mbox' => $mbox_name)));
  62. if ($MESSAGE->headers->get('list-post', false)) {
  63. $OUTPUT->set_env('list_post', true);
  64. }
  65. // set environment
  66. $OUTPUT->set_env('delimiter', $RCMAIL->storage->get_hierarchy_delimiter());
  67. // set configuration
  68. $RCMAIL->set_env_config(array('delete_junk', 'flag_for_deletion', 'read_when_deleted',
  69. 'skip_deleted', 'display_next', 'forward_attachment'));
  70. // set special folders
  71. foreach (array('drafts', 'trash', 'junk') as $mbox) {
  72. if ($folder = $RCMAIL->config->get($mbox . '_mbox')) {
  73. $OUTPUT->set_env($mbox . '_mailbox', $folder);
  74. }
  75. }
  76. // mimetypes supported by the browser (default settings)
  77. $mimetypes = (array)$RCMAIL->config->get('client_mimetypes');
  78. // Remove unsupported types, which makes that attachment which cannot be
  79. // displayed in a browser will be downloaded directly without displaying an overlay page
  80. if (empty($_SESSION['browser_caps']['pdf']) && ($key = array_search('application/pdf', $mimetypes)) !== false) {
  81. unset($mimetypes[$key]);
  82. }
  83. if (empty($_SESSION['browser_caps']['flash']) && ($key = array_search('application/x-shockwave-flash', $mimetypes)) !== false) {
  84. unset($mimetypes[$key]);
  85. }
  86. if (empty($_SESSION['browser_caps']['tif']) && ($key = array_search('image/tiff', $mimetypes)) !== false) {
  87. // we can convert tiff to jpeg
  88. if (!rcube_image::is_convertable('image/tiff')) {
  89. unset($mimetypes[$key]);
  90. }
  91. }
  92. $OUTPUT->set_env('mimetypes', array_values($mimetypes));
  93. if ($MESSAGE->has_html_part()) {
  94. $prefer_html = $RCMAIL->config->get('prefer_html');
  95. $OUTPUT->set_env('optional_format', $prefer_html ? 'text' : 'html');
  96. }
  97. if (!$OUTPUT->ajax_call) {
  98. $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash',
  99. 'movingmessage', 'deletingmessage', 'markingmessage', 'replyall', 'replylist');
  100. }
  101. // check for unset disposition notification
  102. if ($MESSAGE->headers->mdn_to
  103. && empty($MESSAGE->headers->flags['MDNSENT'])
  104. && empty($MESSAGE->headers->flags['SEEN'])
  105. && ($RCMAIL->storage->check_permflag('MDNSENT') || $RCMAIL->storage->check_permflag('*'))
  106. && $mbox_name != $RCMAIL->config->get('drafts_mbox')
  107. && $mbox_name != $RCMAIL->config->get('sent_mbox')
  108. ) {
  109. $mdn_cfg = intval($RCMAIL->config->get('mdn_requests'));
  110. if ($mdn_cfg == 1 || (($mdn_cfg == 3 || $mdn_cfg == 4) && rcmail_contact_exists($MESSAGE->sender['mailto']))) {
  111. // Send MDN
  112. if (rcmail_send_mdn($MESSAGE, $smtp_error))
  113. $OUTPUT->show_message('receiptsent', 'confirmation');
  114. else if ($smtp_error)
  115. $OUTPUT->show_message($smtp_error['label'], 'error', $smtp_error['vars']);
  116. else
  117. $OUTPUT->show_message('errorsendingreceipt', 'error');
  118. }
  119. else if ($mdn_cfg != 2 && $mdn_cfg != 4) {
  120. // Ask user
  121. $OUTPUT->add_label('mdnrequest');
  122. $OUTPUT->set_env('mdn_request', true);
  123. }
  124. }
  125. if (empty($MESSAGE->headers->flags['SEEN'])
  126. && ($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($RCMAIL->config->get('preview_pane_mark_read')) == 0))
  127. ) {
  128. $RCMAIL->output->command('set_unread_message', $MESSAGE->uid, $mbox_name);
  129. $RCMAIL->plugins->exec_hook('message_read', array(
  130. 'uid' => $MESSAGE->uid,
  131. 'mailbox' => $mbox_name,
  132. 'message' => $MESSAGE,
  133. ));
  134. $set_seen_flag = true;
  135. }
  136. }
  137. $OUTPUT->add_handlers(array(
  138. 'messageattachments' => 'rcmail_message_attachments',
  139. 'mailboxname' => 'rcmail_mailbox_name_display',
  140. 'messageobjects' => 'rcmail_message_objects',
  141. 'contactphoto' => 'rcmail_message_contactphoto',
  142. ));
  143. if ($RCMAIL->action == 'print' && $OUTPUT->template_exists('messageprint'))
  144. $OUTPUT->send('messageprint', false);
  145. else if ($RCMAIL->action == 'preview' && $OUTPUT->template_exists('messagepreview'))
  146. $OUTPUT->send('messagepreview', false);
  147. else
  148. $OUTPUT->send('message', false);
  149. // mark message as read
  150. if (!empty($set_seen_flag)) {
  151. if ($RCMAIL->storage->set_flag($MESSAGE->uid, 'SEEN', $mbox_name)) {
  152. if ($count = rcmail_get_unseen_count($mbox_name)) {
  153. rcmail_set_unseen_count($mbox_name, $count - 1);
  154. }
  155. }
  156. }
  157. // Save preview_pane preference, if not set yet (#1490362)
  158. if ($RCMAIL->action == 'preview' && !$RCMAIL->config->get('preview_pane')) {
  159. $RCMAIL->user->save_prefs(array('preview_pane' => true));
  160. }
  161. exit;
  162. function rcmail_message_attachments($attrib)
  163. {
  164. global $PRINT_MODE, $MESSAGE, $RCMAIL;
  165. $out = $ol = '';
  166. $attachments = array();
  167. if (sizeof($MESSAGE->attachments)) {
  168. foreach ($MESSAGE->attachments as $attach_prop) {
  169. $filename = rcmail_attachment_name($attach_prop, true);
  170. $filesize = $RCMAIL->message_part_size($attach_prop);
  171. if ($PRINT_MODE) {
  172. $ol .= html::tag('li', null, rcube::Q(sprintf("%s (%s)", $filename, $filesize)));
  173. }
  174. else {
  175. if ($attrib['maxlength'] && mb_strlen($filename) > $attrib['maxlength']) {
  176. $title = $filename;
  177. $filename = abbreviate_string($filename, $attrib['maxlength']);
  178. }
  179. else {
  180. $title = '';
  181. }
  182. $size = ' ' . html::span('attachment-size', '(' . rcube::Q($filesize) . ')');
  183. $mimetype = rcmail_fix_mimetype($attach_prop->mimetype);
  184. $class = rcube_utils::file2class($mimetype, $filename);
  185. $id = 'attach' . $attach_prop->mime_id;
  186. $link = html::a(array(
  187. 'href' => $MESSAGE->get_part_url($attach_prop->mime_id, false),
  188. 'onclick' => sprintf('return %s.command(\'load-attachment\',\'%s\',this)',
  189. rcmail_output::JS_OBJECT_NAME, $attach_prop->mime_id),
  190. 'onmouseover' => $title ? '' : 'rcube_webmail.long_subject_title_ex(this, 0)',
  191. 'title' => rcube::Q($title),
  192. ), rcube::Q($filename) . $size);
  193. $ol .= html::tag('li', array('class' => $class, 'id' => $id), $link);
  194. $attachments[$attach_prop->mime_id] = $mimetype;
  195. }
  196. }
  197. $out = html::tag('ul', $attrib, $ol, html::$common_attrib);
  198. $RCMAIL->output->set_env('attachments', $attachments);
  199. $RCMAIL->output->add_gui_object('attachments', $attrib['id']);
  200. }
  201. return $out;
  202. }
  203. function rcmail_remote_objects_msg()
  204. {
  205. global $MESSAGE, $RCMAIL;
  206. $attrib['id'] = 'remote-objects-message';
  207. $attrib['class'] = 'notice';
  208. $attrib['style'] = 'display: none';
  209. $msg = rcube::Q($RCMAIL->gettext('blockedimages')) . '&nbsp;';
  210. $msg .= html::a(array(
  211. 'href' => "#loadimages",
  212. 'onclick' => rcmail_output::JS_OBJECT_NAME.".command('load-images')"
  213. ),
  214. rcube::Q($RCMAIL->gettext('showimages')));
  215. // add link to save sender in addressbook and reload message
  216. if ($MESSAGE->sender['mailto'] && $RCMAIL->config->get('show_images') == 1) {
  217. $msg .= ' ' . html::a(array(
  218. 'href' => "#alwaysload",
  219. 'onclick' => rcmail_output::JS_OBJECT_NAME.".command('always-load')",
  220. 'style' => "white-space:nowrap"
  221. ),
  222. rcube::Q($RCMAIL->gettext(array('name' => 'alwaysshow', 'vars' => array('sender' => $MESSAGE->sender['mailto'])))));
  223. }
  224. $RCMAIL->output->add_gui_object('remoteobjectsmsg', $attrib['id']);
  225. return html::div($attrib, $msg);
  226. }
  227. function rcmail_message_buttons()
  228. {
  229. global $RCMAIL, $MESSAGE;
  230. $delim = $RCMAIL->storage->get_hierarchy_delimiter();
  231. $dbox = $RCMAIL->config->get('drafts_mbox');
  232. // the message is not a draft
  233. if ($MESSAGE->folder != $dbox && strpos($MESSAGE->folder, $dbox.$delim) !== 0) {
  234. return '';
  235. }
  236. $attrib['id'] = 'message-buttons';
  237. $attrib['class'] = 'notice';
  238. $msg = rcube::Q($RCMAIL->gettext('isdraft')) . '&nbsp;';
  239. $msg .= html::a(array(
  240. 'href' => "#edit",
  241. 'onclick' => rcmail_output::JS_OBJECT_NAME.".command('edit')"
  242. ),
  243. rcube::Q($RCMAIL->gettext('edit')));
  244. return html::div($attrib, $msg);
  245. }
  246. function rcmail_message_objects($attrib)
  247. {
  248. global $RCMAIL, $MESSAGE;
  249. if (!$attrib['id'])
  250. $attrib['id'] = 'message-objects';
  251. $content = array(
  252. rcmail_message_buttons(),
  253. rcmail_remote_objects_msg(),
  254. );
  255. $plugin = $RCMAIL->plugins->exec_hook('message_objects',
  256. array('content' => $content, 'message' => $MESSAGE));
  257. $content = implode("\n", $plugin['content']);
  258. return html::div($attrib, $content);
  259. }
  260. function rcmail_contact_exists($email)
  261. {
  262. global $RCMAIL;
  263. if ($email) {
  264. // @TODO: search in all address books?
  265. $CONTACTS = $RCMAIL->get_address_book(-1, true);
  266. if (is_object($CONTACTS)) {
  267. $existing = $CONTACTS->search('email', $email, 1, false);
  268. if ($existing->count) {
  269. return true;
  270. }
  271. }
  272. }
  273. return false;
  274. }
  275. function rcmail_message_contactphoto($attrib)
  276. {
  277. global $RCMAIL, $MESSAGE;
  278. $placeholder = $attrib['placeholder'] ? $RCMAIL->output->abs_url($attrib['placeholder'], true) : null;
  279. $placeholder = $RCMAIL->output->asset_url($placeholder ?: 'program/resources/blank.gif');
  280. if ($MESSAGE->sender) {
  281. $photo_img = $RCMAIL->url(array(
  282. '_task' => 'addressbook',
  283. '_action' => 'photo',
  284. '_email' => $MESSAGE->sender['mailto'],
  285. ));
  286. $attrib['onerror'] = "this.src = '$placeholder'";
  287. }
  288. else {
  289. $photo_img = $placeholder;
  290. }
  291. return html::img(array('src' => $photo_img, 'alt' => $RCMAIL->gettext('contactphoto')) + $attrib);
  292. }