您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

show.inc 12KB

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