Source for file read_body.php

Documentation is available at read_body.php

  1. <?php
  2. /**
  3. * read_body.php
  4. *
  5. * This file is used for reading the msgs array and displaying
  6. * the resulting emails in the right frame.
  7. *
  8. * @copyright 1999-2020 The SquirrelMail Project Team
  9. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10. * @version $Id: read_body.php 14840 2020年01月07日 07:42:38Z pdontthink $
  11. * @package squirrelmail
  12. */
  13. /** This is the read_body page */
  14. define ('PAGE_NAME', 'read_body');
  15. /**
  16. * Path for SquirrelMail required files.
  17. * @ignore
  18. */
  19. define ('SM_PATH','../');
  20. /* SquirrelMail required files. */
  21. require_once(SM_PATH . 'include/validate.php');
  22. require_once(SM_PATH . 'functions/imap.php');
  23. require_once(SM_PATH . 'functions/mime.php');
  24. require_once(SM_PATH . 'functions/date.php');
  25. require_once(SM_PATH . 'functions/url_parser.php');
  26. require_once(SM_PATH . 'functions/html.php');
  27. /**
  28. * Given an IMAP message id number, this will look it up in the cached
  29. * and sorted msgs array and return the index. Used for finding the next
  30. * and previous messages.
  31. *
  32. * @return the index of the next valid message from the array
  33. */
  34. function findNextMessage ($passed_id) {
  35. global $msort, $msgs, $sort,
  36. $thread_sort_messages, $allow_server_sort ,
  37. $server_sort_array;
  38. if (!is_array ($server_sort_array)) {
  39. $thread_sort_messages = 0;
  40. $allow_server_sort = FALSE;
  41. }
  42. $result = -1;
  43. if ($thread_sort_messages || $allow_server_sort) {
  44. $count = count ($server_sort_array) - 1;
  45. foreach($server_sort_array as $key=>$value) {
  46. if ($passed_id == $value) {
  47. if ($key == $count) {
  48. break;
  49. }
  50. $result = $server_sort_array[$key + 1];
  51. break;
  52. }
  53. }
  54. } else {
  55. if (is_array ($msort)) {
  56. for (reset ($msort); ($key = key ($msort)), (isset($key)); next ($msort)) {
  57. if ($passed_id == $msgs[$key]['ID']) {
  58. next ($msort);
  59. $key = key ($msort);
  60. if (isset($key)){
  61. $result = $msgs[$key]['ID'];
  62. break;
  63. }
  64. }
  65. }
  66. }
  67. }
  68. return $result;
  69. }
  70. /** returns the index of the previous message from the array. */
  71. function findPreviousMessage ($numMessages, $passed_id) {
  72. global $msort, $sort, $msgs,
  73. $thread_sort_messages,
  74. $allow_server_sort , $server_sort_array;
  75. $result = -1;
  76. if (!is_array ($server_sort_array)) {
  77. $thread_sort_messages = 0;
  78. $allow_server_sort = FALSE;
  79. }
  80. if ($thread_sort_messages || $allow_server_sort ) {
  81. foreach($server_sort_array as $key=>$value) {
  82. if ($passed_id == $value) {
  83. if ($key == 0) {
  84. break;
  85. }
  86. $result = $server_sort_array[$key - 1];
  87. break;
  88. }
  89. }
  90. } else {
  91. if (is_array ($msort)) {
  92. for (reset ($msort); ($key = key ($msort)), (isset($key)); next ($msort)) {
  93. if ($passed_id == $msgs[$key]['ID']) {
  94. prev ($msort);
  95. $key = key ($msort);
  96. if (isset($key)) {
  97. $result = $msgs[$key]['ID'];
  98. break;
  99. }
  100. }
  101. }
  102. }
  103. }
  104. return $result;
  105. }
  106. /**
  107. * Displays a link to a page where the message is displayed more
  108. * "printer friendly".
  109. */
  110. function printer_friendly_link ($mailbox, $passed_id, $passed_ent_id, $color) {
  111. global $javascript_on;
  112. /* hackydiehack */
  113. // Pull "view_unsafe_images" from the URL to find out if the unsafe images
  114. // should be displayed. The default is not to display unsafe images.
  115. if( !sqgetGlobalVar ('view_unsafe_images', $view_unsafe_images, SQ_GET ) ) {
  116. // If "view_unsafe_images" isn't part of the URL, default to not
  117. // displaying unsafe images.
  118. $view_unsafe_images = false;
  119. } else {
  120. // If "view_unsafe_images" is part of the URL, display unsafe images
  121. // regardless of the value of the URL variable.
  122. // FIXME: Do we really want to display the unsafe images regardless of the value in URL variable?
  123. $view_unsafe_images = true;
  124. }
  125. $params = '?passed_ent_id=' . urlencode ($passed_ent_id) .
  126. '&mailbox=' . urlencode ($mailbox) .
  127. '&passed_id=' . urlencode ($passed_id).
  128. '&view_unsafe_images='. (bool) $view_unsafe_images;
  129. $print_text = _ ("View Printable Version");
  130. $result = '';
  131. /* Output the link. */
  132. if ($javascript_on) {
  133. $result = '<script language="javascript" type="text/javascript">' . "\n" .
  134. '<!--' . "\n" .
  135. " function printFormat() {\n" .
  136. ' window.open("../src/printer_friendly_main.php' .
  137. $params . '","Print","width=800,height=600");' . "\n".
  138. " }\n" .
  139. "// -->\n" .
  140. '</script>' .
  141. "<a href=\"javascript:printFormat();\" style=\"white-space: nowrap;\">$print_text</a>";
  142. } else {
  143. $result = '<a target="_blank" href="../src/printer_friendly_bottom.php' .
  144. "$params\" style=\"white-space: nowrap;\">$print_text</a>";
  145. }
  146. return $result;
  147. }
  148. function ServerMDNSupport ($read) {
  149. /* escaping $ doesn't work -> \x36 */
  150. $ret = preg_match ('/(\x36MDNSent|\\\\\*)/i', $read);
  151. return $ret;
  152. }
  153. function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
  154. global $username, $attachment_dir , $color, $default_move_to_sent,
  155. $version, $attachments, $squirrelmail_language, $default_charset ,
  156. $languages , $useSendmail , $domain , $sent_folder,
  157. $popuser, $data_dir ;
  158. sqgetGlobalVar ('SERVER_NAME', $SERVER_NAME, SQ_SERVER );
  159. $header = $message->rfc822_header;
  160. $hashed_attachment_dir = getHashedDir ($username, $attachment_dir);
  161. $rfc822_header = new Rfc822Header ();
  162. $content_type = new ContentType ('multipart/report');
  163. $content_type->properties['report-type']='disposition-notification';
  164. if ($default_charset) {
  165. $content_type->properties['charset']=$default_charset;
  166. }
  167. $rfc822_header->content_type = $content_type;
  168. $rfc822_header->to[] = $header->dnt;
  169. $rfc822_header->subject = _ ("Read:") . ' ' . decodeHeader ($header->subject, true, false);
  170. // FIXME: use identity.php from SM 1.5. Change this also in compose.php
  171. $reply_to = '';
  172. if (isset($identity) && $identity != 'default') {
  173. $from_mail = getPref ($data_dir, $username,
  174. 'email_address' . $identity);
  175. $full_name = getPref ($data_dir, $username,
  176. 'full_name' . $identity);
  177. $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
  178. $reply_to = getPref ($data_dir, $username,
  179. 'reply_to' . $identity);
  180. } else {
  181. $from_mail = getPref ($data_dir, $username, 'email_address');
  182. $full_name = getPref ($data_dir, $username, 'full_name');
  183. $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
  184. $reply_to = getPref ($data_dir, $username,'reply_to');
  185. }
  186. // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md)
  187. // This merely comes from compose.php and only happens when there is no
  188. // email_addr specified in user's identity (which is the startup config)
  189. if (preg_match ('|^([^@%/]+)[@%/](.+)$|', $username, $usernamedata)) {
  190. $popuser = $usernamedata[1];
  191. $domain = $usernamedata[2];
  192. unset($usernamedata);
  193. } else {
  194. $popuser = $username;
  195. }
  196. if (!$from_mail) {
  197. $from_mail = "$popuser@$domain";
  198. $from_addr = $from_mail;
  199. }
  200. $rfc822_header->from = $rfc822_header->parseAddress ($from_addr,true);
  201. if ($reply_to) {
  202. $rfc822_header->reply_to = $rfc822_header->parseAddress ($reply_to,true);
  203. }
  204. // part 1 (RFC2298)
  205. $senton = getLongDateString ( $header->date , $header->date_unparsed );
  206. $to_array = $header->to;
  207. $to = '';
  208. foreach ($to_array as $line) {
  209. $to .= ' '.$line->getAddress();
  210. }
  211. $now = getLongDateString ( time () );
  212. $body = _ ("Your message") . "\r\n\r\n" .
  213. "\t" . _ ("To") . ': ' . decodeHeader ($to,false,false,true) . "\r\n" .
  214. "\t" . _ ("Subject") . ': ' . decodeHeader ($header->subject,false,false,true) . "\r\n" .
  215. "\t" . _ ("Sent") . ': ' . $senton . "\r\n" .
  216. "\r\n" .
  217. sprintf ( _ ("Was displayed on %s"), $now );
  218. $special_encoding = '';
  219. if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
  220. function_exists ($languages[$squirrelmail_language]['XTRA_CODE'])) {
  221. $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
  222. if (strtolower ($default_charset) == 'iso-2022-jp') {
  223. if (mb_detect_encoding ($body) == 'ASCII') {
  224. $special_encoding = '8bit';
  225. } else {
  226. $body = mb_convert_encoding ($body, 'JIS');
  227. $special_encoding = '7bit';
  228. }
  229. }
  230. } elseif (sq_is8bit ($body)) {
  231. // detect 8bit symbols added by translations
  232. $special_encoding = '8bit';
  233. }
  234. $part1 = new Message ();
  235. $part1->setBody($body);
  236. $mime_header = new MessageHeader ;
  237. $mime_header->type0 = 'text';
  238. $mime_header->type1 = 'plain';
  239. if ($special_encoding) {
  240. $mime_header->encoding = $special_encoding;
  241. } else {
  242. $mime_header->encoding = '7bit';
  243. }
  244. if ($default_charset) {
  245. $mime_header->parameters['charset'] = $default_charset;
  246. }
  247. $part1->mime_header = $mime_header;
  248. // part2 (RFC2298)
  249. $original_recipient = $to;
  250. $original_message_id = $header->message_id;
  251. $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
  252. if ($original_recipient != '') {
  253. $report .= "Original-Recipient : $original_recipient\r\n";
  254. }
  255. $final_recipient = $sender;
  256. $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
  257. "Original-Message-ID : $original_message_id\r\n" .
  258. "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
  259. $part2 = new Message ();
  260. $part2->setBody($report);
  261. $mime_header = new MessageHeader ;
  262. $mime_header->type0 = 'message';
  263. $mime_header->type1 = 'disposition-notification';
  264. $mime_header->encoding = '7bit';
  265. $part2->mime_header = $mime_header;
  266. $composeMessage = new Message ();
  267. $composeMessage->rfc822_header = $rfc822_header;
  268. $composeMessage->addEntity($part1);
  269. $composeMessage->addEntity($part2);
  270. if ($useSendmail) {
  271. require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php');
  272. // Check for outdated configuration
  273. if (!isset($sendmail_args)) {
  274. if ($sendmail_path=='/var/qmail/bin/qmail-inject') {
  275. $sendmail_args = '';
  276. } else {
  277. $sendmail_args = '-i -t';
  278. }
  279. }
  280. $deliver = new Deliver_SendMail (array('sendmail_args'=>$sendmail_args));
  281. $stream = $deliver->initStream($composeMessage,$sendmail_path);
  282. } else {
  283. require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php');
  284. $deliver = new Deliver_SMTP ();
  285. $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false;
  286. $user = '';
  287. $pass = '';
  288. if (empty($pop_before_smtp_host))
  289. $pop_before_smtp_host = $smtpServerAddress;
  290. get_smtp_user ($user, $pass);
  291. $stream = $deliver->initStream($composeMessage,$domain,0,
  292. $smtpServerAddress, $smtpPort, $user, $pass, $authPop, $pop_before_smtp_host);
  293. }
  294. $success = false;
  295. if ($stream) {
  296. $deliver->mail ($composeMessage, $stream);
  297. $success = $deliver->finalizeStream($stream);
  298. }
  299. if (!$success) {
  300. $msg = _ ("Message not sent.") .' '. _ ("Server replied:") .
  301. "\n<blockquote>\n" . $deliver->dlv_msg . '<br />' .
  302. $deliver->dlv_ret_nr . ' ' .
  303. $deliver->dlv_server_msg . "</blockquote>\n\n";
  304. require_once(SM_PATH . 'functions/display_messages.php');
  305. plain_error_message ($msg, $color);
  306. } else {
  307. unset ($deliver);
  308. // copy message to sent folder
  309. $move_to_sent = getPref ($data_dir,$username,'move_to_sent', $default_move_to_sent);
  310. if (isset($default_move_to_sent) && ($default_move_to_sent != 0)) {
  311. $svr_allow_sent = true;
  312. } else {
  313. $svr_allow_sent = false;
  314. }
  315. if (isset($sent_folder) && (($sent_folder != '') || ($sent_folder != 'none'))
  316. && sqimap_mailbox_exists ( $imapConnection, $sent_folder)) {
  317. $fld_sent = true;
  318. } else {
  319. $fld_sent = false;
  320. }
  321. if ((isset($move_to_sent) && ($move_to_sent != 0)) || (!isset($move_to_sent))) {
  322. $lcl_allow_sent = true;
  323. } else {
  324. $lcl_allow_sent = false;
  325. }
  326. if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) || ($fld_sent && $lcl_allow_sent)) {
  327. require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
  328. $imap_deliver = new Deliver_IMAP ();
  329. $imap_deliver->mail ($composeMessage, $imapConnection, 0, 0, $imapConnection, $sent_folder);
  330. unset ($imap_deliver);
  331. }
  332. }
  333. return $success;
  334. }
  335. function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id, $uid_support) {
  336. $sg = $set?'+':'-';
  337. $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
  338. $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
  339. $readmessage, $uid_support);
  340. }
  341. function formatRecipientString ($recipients, $item ) {
  342. global $show_more_cc, $show_more, $show_more_bcc,
  343. $PHP_SELF;
  344. $string = '';
  345. if ((is_array ($recipients)) && (isset($recipients[0]))) {
  346. $show = false;
  347. if ($item == 'to') {
  348. if ($show_more) {
  349. $show = true;
  350. $url = set_url_var ($PHP_SELF, 'show_more',0);
  351. } else {
  352. $url = set_url_var ($PHP_SELF, 'show_more',1);
  353. }
  354. } else if ($item == 'cc') {
  355. if ($show_more_cc) {
  356. $show = true;
  357. $url = set_url_var ($PHP_SELF, 'show_more_cc',0);
  358. } else {
  359. $url = set_url_var ($PHP_SELF, 'show_more_cc',1);
  360. }
  361. } else if ($item == 'bcc') {
  362. if ($show_more_bcc) {
  363. $show = true;
  364. $url = set_url_var ($PHP_SELF, 'show_more_bcc',0);
  365. } else {
  366. $url = set_url_var ($PHP_SELF, 'show_more_bcc',1);
  367. }
  368. }
  369. $cnt = count ($recipients);
  370. foreach($recipients as $r) {
  371. $add = decodeHeader ($r->getAddress(true));
  372. if ($string) {
  373. $string .= '<br />' . $add;
  374. } else {
  375. $string = $add;
  376. if ($cnt > 1) {
  377. $string .= '&nbsp;(<a href="'.$url;
  378. if ($show) {
  379. $string .= '">'._ ("less").'</a>)';
  380. } else {
  381. $string .= '">'._ ("more").'</a>)';
  382. break;
  383. }
  384. }
  385. }
  386. }
  387. }
  388. return $string;
  389. }
  390. function formatEnvheader ($mailbox, $passed_id, $passed_ent_id, $message,
  391. $color, $FirstTimeSee) {
  392. $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
  393. $squirrelmail_language;
  394. $header = $message->rfc822_header;
  395. $env = array();
  396. $env[_ ("Subject")] = decodeHeader ($header->subject);
  397. $from_name = $header->getAddr_s('from');
  398. if (!$from_name) {
  399. $from_name = $header->getAddr_s('sender');
  400. if (!$from_name) {
  401. $from_name = _ ("Unknown sender");
  402. }
  403. }
  404. $env[_ ("From")] = decodeHeader ($from_name);
  405. $env[_ ("Date")] = getLongDateString ($header->date , $header->date_unparsed);
  406. $env[_ ("To")] = formatRecipientString ($header->to, "to");
  407. $env[_ ("Cc")] = formatRecipientString ($header->cc, "cc");
  408. $env[_ ("Bcc")] = formatRecipientString ($header->bcc, "bcc");
  409. if ($default_use_priority) {
  410. $env[_ ("Priority")] = sm_encode_html_special_chars (getPriorityStr ($header->priority));
  411. }
  412. if ($show_xmailer_default) {
  413. $env[_ ("Mailer")] = decodeHeader ($header->xmailer);
  414. }
  415. if ($default_use_mdn) {
  416. if ($mdn_user_support) {
  417. if ($header->dnt) {
  418. if ($message->is_mdnsent) {
  419. $env[_ ("Read receipt")] = _ ("sent");
  420. } else {
  421. $env[_ ("Read receipt")] = _ ("requested");
  422. if (!(handleAsSent ($mailbox) ||
  423. $message->is_deleted ||
  424. $passed_ent_id)) {
  425. $mdn_url = $PHP_SELF;
  426. $mdn_url = set_url_var ($mdn_url, 'mailbox', urlencode ($mailbox));
  427. $mdn_url = set_url_var ($mdn_url, 'passed_id', $passed_id);
  428. $mdn_url = set_url_var ($mdn_url, 'passed_ent_id', $passed_ent_id);
  429. $mdn_url = set_url_var ($mdn_url, 'sendreceipt', 1);
  430. if ($FirstTimeSee && $javascript_on) {
  431. $script = '<script language="JavaScript" type="text/javascript">' . "\n";
  432. $script .= '<!--'. "\n";
  433. $script .= 'if(window.confirm("' .
  434. _ ("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
  435. '")) { '."\n" .
  436. ' sendMDN()'.
  437. '}' . "\n";
  438. $script .= '// -->'. "\n";
  439. $script .= '</script>'. "\n";
  440. echo $script;
  441. }
  442. $env[_ ("Read receipt")] .= '&nbsp;<a href="' . $mdn_url . '">[' .
  443. _ ("Send read receipt now") . ']</a>';
  444. }
  445. }
  446. }
  447. }
  448. }
  449. $s = '<table width="100%" cellpadding="0" cellspacing="2" border="0"';
  450. $s .= ' align="center" bgcolor="'.$color[0].'">';
  451. foreach ($env as $key => $val) {
  452. if ($val) {
  453. $s .= '<tr>';
  454. $s .= html_tag ('td', '<b>' . $key . ':&nbsp;&nbsp;</b>', 'right', '', 'valign="top" width="20%"') . "\n";
  455. $s .= html_tag ('td', $val, 'left', '', 'valign="top" width="80%"') . "\n";
  456. $s .= '</tr>';
  457. }
  458. }
  459. echo '<table bgcolor="'.$color[9].'" width="100%" cellpadding="1"'.
  460. ' cellspacing="0" border="0" align="center">'."\n";
  461. echo '<tr><td height="5" colspan="2" bgcolor="'.
  462. $color[4].'"></td></tr><tr><td align="center">'."\n";
  463. echo $s;
  464. do_hook ('read_body_header');
  465. formatToolbar ($mailbox, $passed_id, $passed_ent_id, $message, $color);
  466. echo '</table>';
  467. echo '</td></tr><tr><td height="5" colspan="2" bgcolor="'.$color[4].'"></td></tr>'."\n";
  468. echo '</table>';
  469. }
  470. function formatMenuBar ($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response) {
  471. global $base_uri, $draft_folder, $where, $what, $color, $sort,
  472. $startMessage, $PHP_SELF, $save_as_draft,
  473. $enable_forward_as_attachment;
  474. // wrapping is ok: $topbar_delimiter = '&nbsp;|&nbsp;';
  475. $topbar_delimiter = '&nbsp;| ';
  476. $urlMailbox = urlencode ($mailbox);
  477. $s = '<table width="100%" cellpadding="3" cellspacing="0" align="center"'.
  478. ' border="0" bgcolor="'.$color[9].'"><tr>' .
  479. html_tag ( 'td', '', 'left', '', 'width="49%"' ) . '<small>';
  480. $msgs_url = $base_uri . 'src/';
  481. if (isset($where) && isset($what)) {
  482. $msgs_url .= 'search.php?smtoken=' . sm_generate_security_token () . '&amp;where=' . urlencode ($where) .
  483. '&amp;what=' . urlencode ($what) . '&amp;mailbox=' . $urlMailbox;
  484. $msgs_str = _ ("Search Results");
  485. } else {
  486. $msgs_url .= 'right_main.php?sort=' . $sort . '&amp;startMessage=' .
  487. $startMessage . '&amp;mailbox=' . $urlMailbox;
  488. $msgs_str = _ ("Message List");
  489. }
  490. $s .= '<a href="' . $msgs_url . '" style="white-space: nowrap;">' . $msgs_str . '</a>';
  491. $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox .
  492. '&amp;message=' . $passed_id . '&amp;smtoken=' . sm_generate_security_token () . '&amp;';
  493. $unread_url = $base_uri . 'src/';
  494. if (!(isset($passed_ent_id) && $passed_ent_id)) {
  495. if ($where && $what) {
  496. $unread_url .= 'search.php?unread_passed_id=' . $passed_id . '&amp;smtoken=' . sm_generate_security_token () . '&amp;where=' . urlencode ($where) . '&amp;what=' . urlencode ($what) . '&amp;mailbox=' . $urlMailbox;
  497. } else {
  498. $unread_url .= 'right_main.php?unread_passed_id=' . $passed_id . '&amp;sort=' . $sort . '&amp;startMessage=' . $startMessage . '&amp;mailbox=' . $urlMailbox;
  499. }
  500. $s .= $topbar_delimiter;
  501. $s .= '<a href="' . $unread_url . '">' . _ ("Unread") . '</a>';
  502. if ($where && $what) {
  503. $delete_url .= 'where=' . urlencode ($where) . '&amp;what=' . urlencode ($what);
  504. } else {
  505. $delete_url .= 'sort=' . $sort . '&amp;startMessage=' . $startMessage;
  506. }
  507. $s .= $topbar_delimiter;
  508. $s .= '<a href="' . $delete_url . '">' . _ ("Delete") . '</a>';
  509. }
  510. $comp_uri = 'src/compose.php' .
  511. '?passed_id=' . $passed_id .
  512. '&amp;mailbox=' . $urlMailbox .
  513. '&amp;startMessage=' . $startMessage .
  514. (isset($passed_ent_id)?'&amp;passed_ent_id='.urlencode ($passed_ent_id):'');
  515. if (($mailbox == $draft_folder) && ($save_as_draft)) {
  516. $comp_alt_uri = $comp_uri . '&amp;smaction=draft';
  517. $comp_alt_string = _ ("Resume Draft");
  518. } else if (handleAsSent ($mailbox)) {
  519. $comp_alt_uri = $comp_uri . '&amp;smaction=edit_as_new';
  520. $comp_alt_string = _ ("Edit Message as New");
  521. }
  522. if (isset($comp_alt_uri)) {
  523. $s .= $topbar_delimiter;
  524. $s .= makeComposeLink ($comp_alt_uri, '<span style="white-space: nowrap;">' . $comp_alt_string . '</span>');
  525. }
  526. $s .= '</small></td><td align="center" width="2%" style="white-space: nowrap"><small>'
  527. . (strpos ($topbar_delimiter, '&nbsp;') === 0 ? substr ($topbar_delimiter, 6) : ltrim ($topbar_delimiter));
  528. if (!(isset($where) && isset($what)) && !$passed_ent_id) {
  529. $prev = findPreviousMessage ($mbx_response['EXISTS'], $passed_id);
  530. $next = findNextMessage ($passed_id);
  531. if ($prev != -1) {
  532. $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
  533. '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
  534. '&amp;startMessage='.$startMessage;
  535. $s .= '<a href="'.$uri.'">'._ ("Previous").'</a>';
  536. } else {
  537. $s .= _ ("Previous");
  538. }
  539. $s .= $topbar_delimiter;
  540. if ($next != -1) {
  541. $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
  542. '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
  543. '&amp;startMessage='.$startMessage;
  544. $s .= '<a href="'.$uri.'">'._ ("Next").'</a>';
  545. } else {
  546. $s .= _ ("Next");
  547. }
  548. } else if (isset($passed_ent_id) && $passed_ent_id) {
  549. /* code for navigating through attached message/rfc822 messages */
  550. $url = set_url_var ($PHP_SELF, 'passed_ent_id',0);
  551. $s .= '<a href="'.$url.'">'._ ("View Message").'</a>';
  552. $entities = array();
  553. $entity_count = array();
  554. $c = 0;
  555. foreach($message->parent->entities as $ent) {
  556. if ($ent->type0 == 'message' && $ent->type1 == 'rfc822') {
  557. $c++;
  558. $entity_count[$c] = $ent->entity_id;
  559. $entities[$ent->entity_id] = $c;
  560. }
  561. }
  562. $prev_link = _ ("Previous");
  563. if (!empty($entities[$passed_ent_id]) && ($entities[$passed_ent_id] > 1)) {
  564. $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
  565. $prev_link = '<a href="'
  566. . set_url_var ($PHP_SELF, 'passed_ent_id', $prev_ent_id)
  567. . '">' . $prev_link . '</a>';
  568. }
  569. $next_link = _ ("Next");
  570. if (!empty($entities[$passed_ent_id]) && ($entities[$passed_ent_id] < $c)) {
  571. $next_ent_id = $entity_count[$entities[$passed_ent_id] + 1];
  572. $next_link = '<a href="'
  573. . set_url_var ($PHP_SELF, 'passed_ent_id', $next_ent_id)
  574. . '">' . $next_link . '</a>';
  575. }
  576. $s .= $topbar_delimiter . $prev_link;
  577. $par_ent_id = $message->parent->entity_id;
  578. if ($par_ent_id) {
  579. $par_ent_id = substr ($par_ent_id,0,-2);
  580. $s .= $topbar_delimiter;
  581. $url = set_url_var ($PHP_SELF, 'passed_ent_id',$par_ent_id);
  582. $s .= '<a href="'.$url.'">'._ ("Up").'</a>';
  583. }
  584. $s .= $topbar_delimiter . $next_link;
  585. }
  586. $s .= (strrpos ($topbar_delimiter, '&nbsp;') === strlen ($topbar_delimiter) - 6 ? substr ($topbar_delimiter, 0, -6) : rtrim ($topbar_delimiter))
  587. . '</small></td>' . "\n" .
  588. html_tag ( 'td', '', 'right', '', 'width="49%" ' ) . '<small>';
  589. $comp_action_uri = $comp_uri . '&amp;smaction=forward';
  590. $s .= makeComposeLink ($comp_action_uri, _ ("Forward"));
  591. if ($enable_forward_as_attachment) {
  592. $comp_action_uri = $comp_uri . '&amp;smaction=forward_as_attachment';
  593. $s .= $topbar_delimiter;
  594. $s .= makeComposeLink ($comp_action_uri, '<span style="white-space: nowrap;">' . _ ("Forward as Attachment") . '</span>');
  595. }
  596. $comp_action_uri = $comp_uri . '&amp;smaction=reply';
  597. $s .= $topbar_delimiter;
  598. $s .= makeComposeLink ($comp_action_uri, _ ("Reply"));
  599. $comp_action_uri = $comp_uri . '&amp;smaction=reply_all';
  600. $s .= $topbar_delimiter;
  601. $s .= makeComposeLink ($comp_action_uri, '<span style="white-space: nowrap;">' . _ ("Reply All") . '</span>');
  602. $s .= '</small></td></tr></table>';
  603. $ret = do_hook_function ('read_body_menu_top', $s);
  604. if(!is_null ($ret)) {
  605. $s = $ret;
  606. }
  607. echo $s;
  608. do_hook ('read_body_menu_bottom');
  609. }
  610. function formatToolbar ($mailbox, $passed_id, $passed_ent_id, $message, $color) {
  611. global $base_uri, $where, $what, $download_and_unsafe_link;
  612. $urlMailbox = urlencode ($mailbox);
  613. $urlPassed_id = urlencode ($passed_id);
  614. $urlPassed_ent_id = urlencode ($passed_ent_id);
  615. $query_string = 'mailbox=' . $urlMailbox . '&amp;passed_id=' . $urlPassed_id . '&amp;passed_ent_id=' . $urlPassed_ent_id;
  616. if (!empty($where)) {
  617. $query_string .= '&amp;where=' . urlencode ($where);
  618. }
  619. if (!empty($what)) {
  620. $query_string .= '&amp;what=' . urlencode ($what);
  621. }
  622. $url = $base_uri.'src/view_header.php?'.$query_string;
  623. $s = "<tr>\n" .
  624. html_tag ( 'td', '', 'right', '', 'valign="middle" width="20%"' ) . '<b>' . _ ("Options") . ":&nbsp;&nbsp;</b></td>\n" .
  625. html_tag ( 'td', '', 'left', '', 'valign="middle" width="80%"' ) . '<small>' .
  626. '<a href="'.$url.'" style="white-space: nowrap;">'._ ("View Full Header").'</a>';
  627. /* Output the printer friendly link if we are in subtle mode. */
  628. $s .= '&nbsp;| ' .
  629. printer_friendly_link ($mailbox, $passed_id, $passed_ent_id, $color);
  630. echo $s;
  631. /* Output the download and/or unsafe images link/-s, if any. */
  632. if ($download_and_unsafe_link) {
  633. echo $download_and_unsafe_link;
  634. }
  635. do_hook ("read_body_header_right");
  636. $s = "</small></td>\n" .
  637. "</tr>\n";
  638. echo $s;
  639. }
  640. /***************************/
  641. /* Main of read_body.php */
  642. /***************************/
  643. /* get the globals we may need */
  644. sqgetGlobalVar ('key', $key, SQ_COOKIE );
  645. sqgetGlobalVar ('username', $username, SQ_SESSION );
  646. sqgetGlobalVar ('onetimepad',$onetimepad, SQ_SESSION );
  647. sqgetGlobalVar ('delimiter', $delimiter, SQ_SESSION );
  648. sqgetGlobalVar ('base_uri', $base_uri, SQ_SESSION );
  649. sqgetGlobalVar ('msgs', $msgs, SQ_SESSION );
  650. sqgetGlobalVar ('msort', $msort, SQ_SESSION );
  651. sqgetGlobalVar ('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION );
  652. sqgetGlobalVar ('server_sort_array', $server_sort_array, SQ_SESSION );
  653. if (!sqgetGlobalVar ('messages', $messages, SQ_SESSION ) ) {
  654. $messages = array();
  655. }
  656. /** GET VARS */
  657. sqgetGlobalVar ('sendreceipt', $sendreceipt, SQ_GET );
  658. sqgetGlobalVar ('where', $where, SQ_GET );
  659. sqgetGlobalVar ('what', $what, SQ_GET );
  660. if ( sqgetGlobalVar ('show_more', $temp, SQ_GET ) ) {
  661. $show_more = (int) $temp;
  662. }
  663. if ( sqgetGlobalVar ('show_more_cc', $temp, SQ_GET ) ) {
  664. $show_more_cc = (int) $temp;
  665. }
  666. if ( sqgetGlobalVar ('show_more_bcc', $temp, SQ_GET ) ) {
  667. $show_more_bcc = (int) $temp;
  668. }
  669. if ( sqgetGlobalVar ('view_hdr', $temp, SQ_GET ) ) {
  670. $view_hdr = (int) $temp;
  671. }
  672. /** POST VARS */
  673. sqgetGlobalVar ('move_id', $move_id, SQ_POST );
  674. /** GET/POST VARS */
  675. sqgetGlobalVar ('passed_ent_id', $passed_ent_id);
  676. sqgetGlobalVar ('mailbox', $mailbox);
  677. if ( sqgetGlobalVar ('passed_id', $temp) ) {
  678. $passed_id = (int) $temp;
  679. }
  680. if ( sqgetGlobalVar ('sort', $temp) ) {
  681. $sort = (int) $temp;
  682. }
  683. if ( sqgetGlobalVar ('startMessage', $temp) ) {
  684. $startMessage = (int) $temp;
  685. }
  686. /* end of get globals */
  687. global $uid_support, $sqimap_capabilities;
  688. global $imap_stream_options; // in case not defined in config
  689. $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0, $imap_stream_options);
  690. $mbx_response = sqimap_mailbox_select ($imapConnection, $mailbox, false, false, true);
  691. /**
  692. * $message contains all information about the message
  693. * including header and body
  694. */
  695. $uidvalidity = $mbx_response['UIDVALIDITY'];
  696. if (!isset($messages[$uidvalidity])) {
  697. $messages[$uidvalidity] = array();
  698. }
  699. if (!isset($messages[$uidvalidity][$passed_id]) || !$uid_support) {
  700. $message = sqimap_get_message ($imapConnection, $passed_id, $mailbox);
  701. $FirstTimeSee = !$message->is_seen;
  702. $message->is_seen = true;
  703. $messages[$uidvalidity][$passed_id] = $message;
  704. } else {
  705. // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
  706. $message = $messages[$uidvalidity][$passed_id];
  707. $FirstTimeSee = !$message->is_seen;
  708. }
  709. if (isset($passed_ent_id) && $passed_ent_id) {
  710. $message = $message->getEntity ($passed_ent_id);
  711. if ($message->type0 != 'message' && $message->type1 != 'rfc822') {
  712. $message = $message->parent;
  713. }
  714. $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support);
  715. $rfc822_header = new Rfc822Header ();
  716. $rfc822_header->parseHeader($read);
  717. $message->rfc822_header = $rfc822_header;
  718. } else {
  719. $passed_ent_id = 0;
  720. }
  721. $header = $message->header ;
  722. // gmail does not mark messages as read when retrieving the message body
  723. // even though RFC 3501, section 6.4.5 (FETCH Command) says:
  724. // "The \Seen flag is implicitly set; if this causes the flags to change,
  725. // they SHOULD be included as part of the FETCH responses."
  726. //
  727. if ($imap_server_type == 'gmail') {
  728. sqimap_toggle_flag ($imapConnection, $passed_id, '\\Seen', true, true);
  729. }
  730. do_hook ('html_top');
  731. /****************************************/
  732. /* Block for handling incoming url vars */
  733. /****************************************/
  734. if (isset($sendreceipt)) {
  735. if ( !$message->is_mdnsent ) {
  736. if (isset($identity) ) {
  737. $final_recipient = getPref ($data_dir, $username, 'email_address0', '' );
  738. } else {
  739. $final_recipient = getPref ($data_dir, $username, 'email_address', '' );
  740. }
  741. $final_recipient = trim ($final_recipient);
  742. if ($final_recipient == '' ) {
  743. $final_recipient = getPref ($data_dir, $username, 'email_address', '' );
  744. }
  745. $supportMDN = ServerMDNSupport ($mbx_response["PERMANENTFLAGS"]);
  746. if ( SendMDN ( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
  747. ToggleMDNflag ( true, $imapConnection, $mailbox, $passed_id, $uid_support);
  748. $message->is_mdnsent = true;
  749. $messages[$uidvalidity][$passed_id]=$message;
  750. }
  751. }
  752. }
  753. /***********************************************/
  754. /* End of block for handling incoming url vars */
  755. /***********************************************/
  756. $msgs[$passed_id]['FLAG_SEEN'] = true;
  757. $messagebody = '';
  758. do_hook ('read_body_top');
  759. if ($show_html_default == 1) {
  760. $ent_ar = $message->findDisplayEntity(array());
  761. } else {
  762. $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
  763. }
  764. $cnt = count ($ent_ar);
  765. for ($i = 0; $i < $cnt; $i++) {
  766. $messagebody .= formatBody ($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
  767. if ($i != $cnt-1) {
  768. $messagebody .= '<hr noshade size=1>';
  769. }
  770. }
  771. displayPageHeader ($color, $mailbox);
  772. formatMenuBar ($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
  773. formatEnvheader ($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
  774. echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
  775. echo ' <tr><td>';
  776. echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
  777. echo ' <tr><td>';
  778. echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
  779. echo ' <tr bgcolor="'.$color[4].'"><td>';
  780. // echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">';
  781. echo html_tag ( 'table' ,'' , 'left', '', 'cellpadding="1" cellspacing="5" border="0"' );
  782. echo ' <tr>' . html_tag ( 'td', '<br />'. $messagebody."\n", 'left')
  783. . '</tr>';
  784. echo ' </table>';
  785. echo ' </td></tr>';
  786. echo ' </table></td></tr>';
  787. echo ' </table>';
  788. echo ' </td></tr>';
  789. echo '<tr><td height="5" colspan="2" bgcolor="'.
  790. $color[4].'"></td></tr>'."\n";
  791. $attachmentsdisplay = formatAttachments ($message,$ent_ar,$mailbox, $passed_id);
  792. if ($attachmentsdisplay) {
  793. echo ' <tr><td>';
  794. echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
  795. echo ' <tr><td>';
  796. echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
  797. echo ' <tr>' . html_tag ( 'td', '', 'left', $color[9] );
  798. echo ' <b>' . _ ("Attachments") . ':</b>';
  799. $hook_args = array($message, $mailbox, $passed_id, $passed_ent_id);
  800. echo concat_hook_function ('attachments_top', $hook_args);
  801. echo ' </td></tr>';
  802. echo ' <tr><td>';
  803. echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'">';
  804. echo $attachmentsdisplay;
  805. echo ' </table>';
  806. echo ' </td></tr></table>';
  807. echo ' </td></tr></table>';
  808. echo ' </td></tr>';
  809. echo '<tr><td height="5" colspan="2" bgcolor="'.
  810. $color[4].'"></td></tr>';
  811. }
  812. echo '</table>';
  813. /* show attached images inline -- if pref'fed so */
  814. if (($attachment_common_show_images) &&
  815. is_array ($attachment_common_show_images_list)) {
  816. foreach ($attachment_common_show_images_list as $img) {
  817. $imgurl = SM_PATH . 'src/download.php' .
  818. '?' .
  819. 'passed_id=' . urlencode ($img['passed_id']) .
  820. '&amp;mailbox=' . urlencode ($mailbox) .
  821. '&amp;ent_id=' . urlencode ($img['ent_id']) .
  822. '&amp;absolute_dl=true';
  823. echo html_tag ( 'table', "\n" .
  824. html_tag ( 'tr', "\n" .
  825. html_tag ( 'td', '<img src="' . $imgurl . '" />' ."\n", 'left'
  826. )
  827. ) ,
  828. 'center', '', 'cellspacing="0" border="0" cellpadding="2"');
  829. }
  830. }
  831. //FIXME: one of these hooks should be removed if we can verify disuse (html_bottom?)
  832. do_hook ('read_body_bottom');
  833. do_hook ('html_bottom');
  834. sqimap_logout ($imapConnection);
  835. /* sessions are written at the end of the script. it's better to register
  836. them at the end so we avoid double session_register calls */
  837. sqsession_register ($messages,'messages');
  838. ?>
  839. </body></html>

Documentation generated on 2020年1月13日 04:25:12 +0100 by phpDocumentor 1.4.3

AltStyle によって変換されたページ (->オリジナル) /