Source for file compose.php

Documentation is available at compose.php

  1. <?php
  2. /**
  3. * compose.php
  4. *
  5. * This code sends a mail.
  6. *
  7. * There are 4 modes of operation:
  8. * - Start new mail
  9. * - Add an attachment
  10. * - Send mail
  11. * - Save As Draft
  12. *
  13. * @copyright 1999-2020 The SquirrelMail Project Team
  14. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  15. * @version $Id: compose.php 14840 2020年01月07日 07:42:38Z pdontthink $
  16. * @package squirrelmail
  17. */
  18. /** This is the compose page */
  19. define ('PAGE_NAME', 'compose');
  20. /**
  21. * Path for SquirrelMail required files.
  22. * @ignore
  23. */
  24. define ('SM_PATH','../');
  25. /* SquirrelMail required files. */
  26. require_once(SM_PATH . 'include/validate.php');
  27. require_once(SM_PATH . 'functions/global.php');
  28. require_once(SM_PATH . 'functions/imap.php');
  29. require_once(SM_PATH . 'functions/date.php');
  30. require_once(SM_PATH . 'functions/mime.php');
  31. require_once(SM_PATH . 'functions/plugin.php');
  32. require_once(SM_PATH . 'functions/display_messages.php');
  33. require_once(SM_PATH . 'class/deliver/Deliver.class.php');
  34. require_once(SM_PATH . 'functions/addressbook.php');
  35. require_once(SM_PATH . 'functions/forms.php');
  36. require_once(SM_PATH . 'functions/identity.php');
  37. /* --------------------- Get globals ------------------------------------- */
  38. /** COOKIE VARS */
  39. sqgetGlobalVar ('key', $key, SQ_COOKIE );
  40. /** SESSION VARS */
  41. sqgetGlobalVar ('username', $username, SQ_SESSION );
  42. sqgetGlobalVar ('onetimepad',$onetimepad, SQ_SESSION );
  43. sqgetGlobalVar ('base_uri', $base_uri, SQ_SESSION );
  44. sqgetGlobalVar ('delimiter', $delimiter, SQ_SESSION );
  45. sqgetGlobalVar ('composesession', $composesession, SQ_SESSION );
  46. sqgetGlobalVar ('compose_messages', $compose_messages, SQ_SESSION );
  47. // compose_messages only useful in SESSION when a forward-as-attachment
  48. // has been preconstructed for us and passed in via that mechanism; once
  49. // we have it, we can clear it from the SESSION
  50. // -- No, this is useful in other scenarios, too -- removing:
  51. // sqsession_unregister('compose_messages');
  52. /** SESSION/POST/GET VARS */
  53. sqgetGlobalVar ('send', $send, SQ_POST );
  54. // Send can only be achieved by setting $_POST var. If Send = true then
  55. // retrieve other form fields from $_POST
  56. if (isset($send) && $send) {
  57. $SQ_GLOBAL = SQ_POST ;
  58. } else {
  59. $SQ_GLOBAL = SQ_FORM ;
  60. }
  61. sqgetGlobalVar ('smaction',$action, $SQ_GLOBAL);
  62. if (!sqgetGlobalVar ('smtoken',$submitted_token, $SQ_GLOBAL)) {
  63. $submitted_token = '';
  64. }
  65. sqgetGlobalVar ('session',$session, $SQ_GLOBAL);
  66. sqgetGlobalVar ('mailbox',$mailbox, $SQ_GLOBAL);
  67. sqgetGlobalVar ('identity',$orig_identity, $SQ_GLOBAL);
  68. if ( !sqgetGlobalVar ('identity',$identity, $SQ_GLOBAL) ) {
  69. $identity = 0;
  70. }
  71. sqgetGlobalVar ('send_to',$send_to, $SQ_GLOBAL);
  72. sqgetGlobalVar ('send_to_cc',$send_to_cc, $SQ_GLOBAL);
  73. sqgetGlobalVar ('send_to_bcc',$send_to_bcc, $SQ_GLOBAL);
  74. sqgetGlobalVar ('subject',$subject, $SQ_GLOBAL);
  75. sqgetGlobalVar ('body',$body, $SQ_GLOBAL);
  76. sqgetGlobalVar ('mailprio',$mailprio, $SQ_GLOBAL);
  77. sqgetGlobalVar ('request_mdn',$request_mdn, $SQ_GLOBAL);
  78. sqgetGlobalVar ('request_dr',$request_dr, $SQ_GLOBAL);
  79. sqgetGlobalVar ('html_addr_search',$html_addr_search, SQ_FORM );
  80. sqgetGlobalVar ('mail_sent',$mail_sent, SQ_FORM );
  81. sqgetGlobalVar ('passed_id',$passed_id, $SQ_GLOBAL);
  82. sqgetGlobalVar ('passed_ent_id',$passed_ent_id, $SQ_GLOBAL);
  83. sqgetGlobalVar ('attach',$attach, SQ_POST );
  84. sqgetGlobalVar ('draft',$draft, SQ_POST );
  85. sqgetGlobalVar ('draft_id',$draft_id, $SQ_GLOBAL);
  86. sqgetGlobalVar ('ent_num',$ent_num, $SQ_GLOBAL);
  87. sqgetGlobalVar ('saved_draft',$saved_draft, SQ_FORM );
  88. if ( sqgetGlobalVar ('delete_draft',$delete_draft) ) {
  89. $delete_draft = (int)$delete_draft;
  90. }
  91. if ( sqgetGlobalVar ('startMessage',$startMessage) ) {
  92. $startMessage = (int)$startMessage;
  93. } else {
  94. $startMessage = 1;
  95. }
  96. /** POST VARS */
  97. sqgetGlobalVar ('sigappend', $sigappend, SQ_POST );
  98. sqgetGlobalVar ('from_htmladdr_search', $from_htmladdr_search, SQ_POST );
  99. sqgetGlobalVar ('addr_search_done', $html_addr_search_done, SQ_POST );
  100. sqgetGlobalVar ('send_to_search', $send_to_search, SQ_POST );
  101. sqgetGlobalVar ('do_delete', $do_delete, SQ_POST );
  102. sqgetGlobalVar ('delete', $delete, SQ_POST );
  103. sqgetGlobalVar ('attachments', $attachments, SQ_POST );
  104. // Not used any more, but left for posterity
  105. //sqgetGlobalVar('restoremessages', $restoremessages, SQ_POST);
  106. if ( sqgetGlobalVar ('return', $temp, SQ_POST ) ) {
  107. $html_addr_search_done = 'Use Addresses';
  108. }
  109. /** GET VARS */
  110. // (none)
  111. /**
  112. * Here we decode the data passed in from mailto.php.
  113. */
  114. if ( sqgetGlobalVar ('mailtodata', $mailtodata, SQ_GET ) ) {
  115. $trtable = array('to' => 'send_to',
  116. 'cc' => 'send_to_cc',
  117. 'bcc' => 'send_to_bcc',
  118. 'body' => 'body',
  119. 'subject' => 'subject');
  120. $mtdata = unserialize ($mailtodata);
  121. foreach ($trtable as $f => $t) {
  122. if ( !empty($mtdata[$f]) ) {
  123. $$t = $mtdata[$f];
  124. }
  125. }
  126. unset($mailtodata,$mtdata, $trtable);
  127. }
  128. /* Location (For HTTP 1.1 Header("Location: ...") redirects) */
  129. $location = get_location ();
  130. /* Identities (fetch only once) */
  131. $idents = get_identities ();
  132. /* --------------------- Specific Functions ------------------------------ */
  133. function replyAllString ($header) {
  134. global $include_self_reply_all, $username, $data_dir ;
  135. $excl_ar = array();
  136. /**
  137. * 1) Remove the addresses we'll be sending the message 'to'
  138. */
  139. $url_replytoall_avoid_addrs = '';
  140. if (isset($header->reply_to) && is_array ($header->reply_to) && count ($header->reply_to)) {
  141. $excl_ar = $header->getAddr_a('reply_to');
  142. } else if (is_object ($header->reply_to)) { /* unneccesarry, just for failsafe purpose */
  143. $excl_ar = $header->getAddr_a('reply_to');
  144. } else {
  145. $excl_ar = $header->getAddr_a('from');
  146. }
  147. /**
  148. * 2) Remove our identities from the CC list (they still can be in the
  149. * TO list) only if $include_self_reply_all is turned off
  150. */
  151. if (!$include_self_reply_all) {
  152. global $idents;
  153. foreach($idents as $id) {
  154. $excl_ar[strtolower (trim ($id['email_address']))] = '';
  155. }
  156. }
  157. /**
  158. * 3) get the addresses.
  159. */
  160. $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
  161. /**
  162. * 4) generate the string.
  163. */
  164. $url_replytoallcc = '';
  165. foreach( $url_replytoall_ar as $email => $personal) {
  166. if ($personal) {
  167. // always quote personal name (can't just quote it if
  168. // it contains a comma separator, since it might still
  169. // be encoded)
  170. $url_replytoallcc .= ", \"$personal\" <$email>";
  171. } else {
  172. $url_replytoallcc .= ', '. $email;
  173. }
  174. }
  175. $url_replytoallcc = substr ($url_replytoallcc,2);
  176. return $url_replytoallcc;
  177. }
  178. function getReplyCitation ($orig_from, $orig_date) {
  179. global $reply_citation_style, $reply_citation_start, $reply_citation_end;
  180. // FIXME: why object is rewritten with string.
  181. if (!is_object ($orig_from)) {
  182. $orig_from = '';
  183. } else {
  184. $orig_from = decodeHeader ($orig_from->getAddress(false),false,false,true);
  185. }
  186. /* First, return an empty string when no citation style selected. */
  187. if (($reply_citation_style == '') || ($reply_citation_style == 'none')) {
  188. return '';
  189. }
  190. /* Make sure our final value isn't an empty string. */
  191. if ($orig_from == '') {
  192. return '';
  193. }
  194. /* Otherwise, try to select the desired citation style. */
  195. switch ($reply_citation_style) {
  196. case 'author_said':
  197. /**
  198. * To translators: %s is for author's name
  199. */
  200. $full_reply_citation = sprintf (_ ("%s wrote:"),$orig_from);
  201. break;
  202. case 'quote_who':
  203. $start = '<' . _ ("quote") . ' ' . _ ("who") . '="';
  204. $end = '">';
  205. $full_reply_citation = $start . $orig_from . $end;
  206. break;
  207. case 'date_time_author':
  208. /**
  209. * To translators:
  210. * first %s is for date string, second %s is for author's name. Date uses
  211. * formating from "D, F j, Y g:i a" and "D, F j, Y H:i" translations.
  212. * Example string:
  213. * "On Sat, December 24, 2004 23:59, Santa wrote:"
  214. * If you have to put author's name in front of date string, check comments about
  215. * argument swapping at http://www.php.net/sprintf
  216. */
  217. $full_reply_citation = sprintf (_ ("On %s, %s wrote:"), getLongDateString ($orig_date), $orig_from);
  218. break;
  219. case 'user-defined':
  220. $start = $reply_citation_start .
  221. ($reply_citation_start == '' ? '' : ' ');
  222. $end = $reply_citation_end;
  223. $full_reply_citation = $start . $orig_from . $end;
  224. break;
  225. default:
  226. return '';
  227. }
  228. /* Add line feed and return the citation string. */
  229. return ($full_reply_citation . "\n");
  230. }
  231. function getforwardHeader ($orig_header) {
  232. global $editor_size;
  233. $display = array( _ ("Subject") => strlen (_ ("Subject")),
  234. _ ("From") => strlen (_ ("From")),
  235. _ ("Date") => strlen (_ ("Date")),
  236. _ ("To") => strlen (_ ("To")),
  237. _ ("Cc") => strlen (_ ("Cc")) );
  238. $maxsize = max ($display);
  239. $indent = str_pad ('',$maxsize+2);
  240. foreach($display as $key => $val) {
  241. $display[$key] = $key .': '. str_pad ('', $maxsize - $val);
  242. }
  243. $from = decodeHeader ($orig_header->getAddr_s('from',"\n$indent"),false,false,true);
  244. $from = str_replace ('&nbsp;',' ',$from);
  245. $to = decodeHeader ($orig_header->getAddr_s('to',"\n$indent"),false,false,true);
  246. $to = str_replace ('&nbsp;',' ',$to);
  247. $subject = decodeHeader ($orig_header->subject,false,false,true);
  248. $subject = str_replace ('&nbsp;',' ',$subject);
  249. $bodyTop = str_pad (' '._ ("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH) .
  250. "\n". $display[_ ("Subject")] . $subject . "\n" .
  251. $display[_ ("From")] . $from . "\n" .
  252. $display[_ ("Date")] . getLongDateString ( $orig_header->date , $orig_header->date_unparsed ). "\n" .
  253. $display[_ ("To")] . $to . "\n";
  254. if ($orig_header->cc != array() && $orig_header->cc !='') {
  255. $cc = decodeHeader ($orig_header->getAddr_s('cc',"\n$indent"),false,false,true);
  256. $cc = str_replace ('&nbsp;',' ',$cc);
  257. $bodyTop .= $display[_ ("Cc")] .$cc . "\n";
  258. }
  259. $bodyTop .= str_pad ('', $editor_size -2 , '-') .
  260. "\n\n";
  261. return $bodyTop;
  262. }
  263. /* ----------------------------------------------------------------------- */
  264. /*
  265. * If the session is expired during a post this restores the compose session
  266. * vars.
  267. */
  268. $session_expired = false;
  269. if (sqsession_is_registered ('session_expired_post')) {
  270. sqgetGlobalVar ('session_expired_post', $session_expired_post, SQ_SESSION );
  271. /*
  272. * extra check for username so we don't display previous post data from
  273. * another user during this session.
  274. */
  275. if (!empty($session_expired_post['username'])
  276. && $session_expired_post['username'] == $username) {
  277. // these are the vars that we can set from the expired composed session
  278. $compo_var_list = array ('send_to', 'send_to_cc', 'body', 'mailbox',
  279. 'startMessage', 'passed_body', 'use_signature', 'signature',
  280. 'attachments', 'subject', 'newmail', 'send_to_bcc', 'passed_id',
  281. 'from_htmladdr_search', 'identity', 'draft_id', 'delete_draft',
  282. 'mailprio', 'edit_as_new', 'request_mdn', 'request_dr',
  283. 'composesession', /* Not used any more: 'compose_messsages', */);
  284. foreach ($compo_var_list as $var) {
  285. if ( isset($session_expired_post[$var]) && !isset($$var) ) {
  286. $$var = $session_expired_post[$var];
  287. }
  288. }
  289. if (!empty($attachments))
  290. $attachments = unserialize ($attachments);
  291. sqsession_register ($composesession,'composesession');
  292. if (isset($send)) {
  293. unset($send);
  294. }
  295. $session_expired = true;
  296. }
  297. unset($session_expired_post);
  298. sqsession_unregister ('session_expired_post');
  299. if (!isset($mailbox)) {
  300. $mailbox = '';
  301. }
  302. if ($compose_new_win == '1') {
  303. compose_Header ($color, $mailbox);
  304. } else {
  305. displayPageHeader ($color, $mailbox);
  306. }
  307. showInputForm ($session, false);
  308. exit();
  309. }
  310. if (!isset($composesession)) {
  311. $composesession = 0;
  312. sqsession_register (0,'composesession');
  313. } else {
  314. $composesession = (int)$composesession;
  315. }
  316. if (!isset($session) || (isset($newmessage) && $newmessage)) {
  317. sqsession_unregister ('composesession');
  318. $session = "$composesession" +1;
  319. $composesession = $session;
  320. sqsession_register ($composesession,'composesession');
  321. }
  322. if (!empty($compose_messages[$session])) {
  323. $composeMessage = $compose_messages[$session];
  324. } else {
  325. $composeMessage = new Message ();
  326. $rfc822_header = new Rfc822Header ();
  327. $composeMessage->rfc822_header = $rfc822_header;
  328. $composeMessage->reply_rfc822_header = '';
  329. }
  330. // re-add attachments that were already in this message
  331. // FIXME: note that technically this is very bad form -
  332. // should never directly manipulate an object like this
  333. if (!empty($attachments)) {
  334. $attachments = unserialize ($attachments);
  335. if (!empty($attachments) && is_array ($attachments)) {
  336. // sanitize the "att_local_name" since it is user-supplied and used to access the file system
  337. // it must be alpha-numeric and 32 characters long (see the use of GenerateRandomString() below)
  338. foreach ($attachments as $i => $attachment) {
  339. if (empty($attachment->att_local_name) || strlen ($attachment->att_local_name) !== 32) {
  340. unset($attachments[$i]);
  341. continue;
  342. }
  343. // probably marginal difference between (ctype_alnum + function_exists) and preg_match
  344. if (function_exists ('ctype_alnum')) {
  345. if (!ctype_alnum ($attachment->att_local_name))
  346. unset($attachments[$i]);
  347. }
  348. else if (preg_match ('/[^0-9a-zA-Z]/', $attachment->att_local_name))
  349. unset($attachments[$i]);
  350. }
  351. if (!empty($attachments))
  352. $composeMessage->entities = $attachments;
  353. }
  354. }
  355. if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None')) {
  356. $mailbox = 'INBOX';
  357. }
  358. if ($draft) {
  359. // validate security token
  360. //
  361. sm_validate_security_token ($submitted_token, -1, TRUE);
  362. /*
  363. * Set $default_charset to correspond with the user's selection
  364. * of language interface.
  365. */
  366. if (! deliverMessage ($composeMessage, true)) {
  367. showInputForm ($session);
  368. exit();
  369. } else {
  370. $draft_message = _ ("Draft Email Saved");
  371. /* If this is a resumed draft, then delete the original */
  372. if(isset($delete_draft)) {
  373. if ( !isset($pageheader_sent) || !$pageheader_sent ) {
  374. Header("Location: $location/delete_message.php?mailbox=" . urlencode ($draft_folder) .
  375. "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes&smtoken=" . sm_generate_security_token ());
  376. } else {
  377. echo ' <br><br><center><a href="' . $location
  378. . "/delete_message.php?mailbox=" . urlencode ($draft_folder)
  379. . "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes&smtoken=" . sm_generate_security_token () . "\">"
  380. . _ ("Return") . '</a></center>';
  381. }
  382. exit();
  383. }
  384. else {
  385. if ($compose_new_win == '1') {
  386. if ( !isset($pageheader_sent) || !$pageheader_sent ) {
  387. Header("Location: $location/compose.php?saved_draft=yes&session=$composesession");
  388. } else {
  389. echo ' <br><br><center><a href="' . $location
  390. . "/compose.php?saved_draft=yes&session=$composesession\">"
  391. . _ ("Return") . '</a></center>';
  392. }
  393. exit();
  394. }
  395. else {
  396. if ( !isset($pageheader_sent) || !$pageheader_sent ) {
  397. Header("Location: $location/right_main.php?mailbox=" . urlencode ($draft_folder) .
  398. "&sort=$sort&startMessage=1&note=".urlencode ($draft_message));
  399. } else {
  400. echo ' <br><br><center><a href="' . $location
  401. . "/right_main.php?mailbox=" . urlencode ($draft_folder)
  402. . "&sort=$sort&startMessage=1&note=".urlencode ($draft_message)
  403. . "\">" . _ ("Return") . '</a></center>';
  404. }
  405. exit();
  406. }
  407. }
  408. }
  409. }
  410. if ($send) {
  411. // validate security token
  412. //
  413. sm_validate_security_token ($submitted_token, -1, TRUE);
  414. if (isset($_FILES['attachfile']) &&
  415. $_FILES['attachfile']['tmp_name'] &&
  416. $_FILES['attachfile']['tmp_name'] != 'none') {
  417. $AttachFailure = saveAttachedFiles ($session);
  418. }
  419. if (checkInput (false) && !isset($AttachFailure)) {
  420. if ($mailbox == "All Folders") {
  421. /* We entered compose via the search results page */
  422. $mailbox = 'INBOX'; /* Send 'em to INBOX, that's safe enough */
  423. }
  424. $urlMailbox = urlencode ($mailbox);
  425. if (! isset($passed_id)) {
  426. $passed_id = 0;
  427. }
  428. /**
  429. * Set $default_charset to correspond with the user's selection
  430. * of language interface.
  431. */
  432. /**
  433. * This is to change all newlines to \n
  434. * We'll change them to \r\n later (in the sendMessage function)
  435. */
  436. $body = str_replace ("\r\n", "\n", $body);
  437. $body = str_replace ("\r", "\n", $body);
  438. /**
  439. * Rewrap $body so that no line is bigger than $editor_size
  440. * This should only really kick in the sqWordWrap function
  441. * if the browser doesn't support "VIRTUAL" as the wrap type.
  442. */
  443. $body = explode ("\n", $body);
  444. $newBody = '';
  445. foreach ($body as $line) {
  446. if( $line <> '-- ' ) {
  447. $line = rtrim ($line);
  448. }
  449. if (sq_strlen ($line, $default_charset) <= $editor_size + 1) {
  450. $newBody .= $line . "\n";
  451. } else {
  452. sqWordWrap ($line, $editor_size, $default_charset);
  453. $newBody .= $line . "\n";
  454. }
  455. }
  456. $body = $newBody;
  457. $Result = deliverMessage ($composeMessage);
  458. do_hook ('compose_send_after', $Result, $composeMessage);
  459. if (! $Result) {
  460. showInputForm ($session);
  461. exit();
  462. }
  463. /* if it is resumed draft, delete draft message */
  464. if ( isset($delete_draft)) {
  465. Header("Location: $location/delete_message.php?mailbox=" . urlencode ( $draft_folder ).
  466. "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes&smtoken=" . sm_generate_security_token ());
  467. exit();
  468. }
  469. if ($compose_new_win == '1') {
  470. Header("Location: $location/compose.php?mail_sent=yes");
  471. }
  472. else {
  473. global $return_to_message_after_reply;
  474. if (($action === 'reply' || $action === 'reply_all' || $action === 'forward' || $action === 'forward_as_attachment')
  475. && $return_to_message_after_reply)
  476. Header("Location: $location/read_body.php?passed_id=$passed_id&mailbox=$urlMailbox&sort=$sort".
  477. "&startMessage=$startMessage");
  478. else
  479. Header("Location: $location/right_main.php?mailbox=$urlMailbox&sort=$sort".
  480. "&startMessage=$startMessage");
  481. }
  482. } else {
  483. if ($compose_new_win == '1') {
  484. compose_Header ($color, $mailbox);
  485. }
  486. else {
  487. displayPageHeader ($color, $mailbox);
  488. }
  489. if (isset($AttachFailure)) {
  490. plain_error_message (_ ("Could not move/copy file. File not attached"),
  491. $color);
  492. }
  493. checkInput (true);
  494. showInputForm ($session);
  495. /* sqimap_logout($imapConnection); */
  496. }
  497. } elseif (isset($html_addr_search_done)) {
  498. // validate security token
  499. //
  500. sm_validate_security_token ($submitted_token, -1, TRUE);
  501. if ($compose_new_win == '1') {
  502. compose_Header ($color, $mailbox);
  503. }
  504. else {
  505. displayPageHeader ($color, $mailbox);
  506. }
  507. if (isset($send_to_search) && is_array ($send_to_search)) {
  508. foreach ($send_to_search as $k => $v) {
  509. if (substr ($k, 0, 1) == 'T') {
  510. if ($send_to) {
  511. $send_to .= ', ';
  512. }
  513. $send_to .= $v;
  514. }
  515. elseif (substr ($k, 0, 1) == 'C') {
  516. if ($send_to_cc) {
  517. $send_to_cc .= ', ';
  518. }
  519. $send_to_cc .= $v;
  520. }
  521. elseif (substr ($k, 0, 1) == 'B') {
  522. if ($send_to_bcc) {
  523. $send_to_bcc .= ', ';
  524. }
  525. $send_to_bcc .= $v;
  526. }
  527. }
  528. }
  529. showInputForm ($session);
  530. } elseif (isset($html_addr_search)) {
  531. if (isset($_FILES['attachfile']) &&
  532. $_FILES['attachfile']['tmp_name'] &&
  533. $_FILES['attachfile']['tmp_name'] != 'none') {
  534. if(saveAttachedFiles ($session)) {
  535. plain_error_message (_ ("Could not move/copy file. File not attached"), $color);
  536. }
  537. }
  538. /*
  539. * I am using an include so as to elminiate an extra unnecessary
  540. * click. If you can think of a better way, please implement it.
  541. */
  542. include_once('./addrbook_search_html.php');
  543. } elseif (isset($attach)) {
  544. // validate security token
  545. //
  546. sm_validate_security_token ($submitted_token, -1, TRUE);
  547. if (saveAttachedFiles ($session)) {
  548. plain_error_message (_ ("Could not move/copy file. File not attached"), $color);
  549. }
  550. if ($compose_new_win == '1') {
  551. compose_Header ($color, $mailbox);
  552. } else {
  553. displayPageHeader ($color, $mailbox);
  554. }
  555. showInputForm ($session);
  556. }
  557. elseif (isset($sigappend)) {
  558. // validate security token
  559. //
  560. sm_validate_security_token ($submitted_token, -1, TRUE);
  561. $signature = $idents[$identity]['signature'];
  562. $body .= "\n\n".($prefix_sig==true? "-- \n":'').$signature;
  563. if ($compose_new_win == '1') {
  564. compose_Header ($color, $mailbox);
  565. } else {
  566. displayPageHeader ($color, $mailbox);
  567. }
  568. showInputForm ($session);
  569. } elseif (isset($do_delete)) {
  570. // validate security token
  571. //
  572. sm_validate_security_token ($submitted_token, -1, TRUE);
  573. if ($compose_new_win == '1') {
  574. compose_Header ($color, $mailbox);
  575. } else {
  576. displayPageHeader ($color, $mailbox);
  577. }
  578. if (isset($delete) && is_array ($delete)) {
  579. foreach($delete as $index) {
  580. if (!empty($composeMessage->entities) && isset($composeMessage->entities[$index])) {
  581. $composeMessage->entities[$index]->purgeAttachments();
  582. // FIXME: one person reported that unset() didn't do anything at all here, so this is a work-around... but it triggers PHP notices if the unset() doesn't work, which should be fixed... but bigger question is if unset() doesn't work here, what about everywhere else? Anyway, uncomment this if you think you need it
  583. //$composeMessage->entities[$index] = NULL;
  584. unset ($composeMessage->entities[$index]);
  585. }
  586. }
  587. $new_entities = array();
  588. foreach ($composeMessage->entities as $entity) {
  589. $new_entities[] = $entity;
  590. }
  591. $composeMessage->entities = $new_entities;
  592. }
  593. showInputForm ($session);
  594. } else {
  595. /*
  596. * This handles the default case as well as the error case
  597. * (they had the same code) --> if (isset($smtpErrors))
  598. */
  599. if ($compose_new_win == '1') {
  600. compose_Header ($color, $mailbox);
  601. } else {
  602. displayPageHeader ($color, $mailbox);
  603. }
  604. $newmail = true;
  605. if (!isset($passed_ent_id)) {
  606. $passed_ent_id = '';
  607. }
  608. if (!isset($passed_id)) {
  609. $passed_id = '';
  610. }
  611. if (!isset($mailbox)) {
  612. $mailbox = '';
  613. }
  614. if (!isset($action)) {
  615. $action = '';
  616. }
  617. $values = newMail ($mailbox,$passed_id,$passed_ent_id, $action, $session);
  618. // forward as attachment - subject is in the message in session
  619. //
  620. if (sqgetGlobalVar ('forward_as_attachment_init', $forward_as_attachment_init, SQ_GET )
  621. && $forward_as_attachment_init)
  622. $subject = $composeMessage->rfc822_header->subject;
  623. /* in case the origin is not read_body.php */
  624. if (isset($send_to)) {
  625. $values['send_to'] = $send_to;
  626. }
  627. if (isset($send_to_cc)) {
  628. $values['send_to_cc'] = $send_to_cc;
  629. }
  630. if (isset($send_to_bcc)) {
  631. $values['send_to_bcc'] = $send_to_bcc;
  632. }
  633. if (isset($subject)) {
  634. $values['subject'] = $subject;
  635. }
  636. if (isset($mailprio)) {
  637. $values['mailprio'] = $mailprio;
  638. }
  639. if (isset($orig_identity)) {
  640. $values['identity'] = $orig_identity;
  641. }
  642. showInputForm ($session, $values);
  643. }
  644. exit();
  645. /**************** Only function definitions go below *************/
  646. /* This function is used when not sending or adding attachments */
  647. function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
  648. global $editor_size, $default_use_priority , $body, $idents,
  649. $use_signature, $composesession, $data_dir , $username,
  650. $username, $key, $imapServerAddress , $imapPort , $imap_stream_options,
  651. $composeMessage, $body_quote, $strip_sigs, $do_not_reply_to_self;
  652. global $languages , $squirrelmail_language, $default_charset , $compose_messages;
  653. /*
  654. * Set $default_charset to correspond with the user's selection
  655. * of language interface. $default_charset global is not correct,
  656. * if message is composed in new window.
  657. */
  658. $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
  659. $mailprio = 3;
  660. if ($passed_id) {
  661. $imapConnection = sqimap_login ($username, $key, $imapServerAddress,
  662. $imapPort, 0, $imap_stream_options);
  663. sqimap_mailbox_select ($imapConnection, $mailbox);
  664. $message = sqimap_get_message ($imapConnection, $passed_id, $mailbox);
  665. $body = '';
  666. if ($passed_ent_id) {
  667. /* redefine the messsage in case of message/rfc822 */
  668. $message = $message->getEntity ($passed_ent_id);
  669. /* message is an entity which contains the envelope and type0=message
  670. * and type1=rfc822. The actual entities are childs from
  671. * $message->entities[0]. That's where the encoding and is located
  672. */
  673. $entities = $message->entities[0]->findDisplayEntity
  674. (array(), $alt_order = array('text/plain'));
  675. if (!count ($entities)) {
  676. $entities = $message->entities[0]->findDisplayEntity
  677. (array(), $alt_order = array('text/plain','text/html'));
  678. }
  679. $orig_header = $message->rfc822_header; /* here is the envelope located */
  680. /* redefine the message for picking up the attachments */
  681. $message = $message->entities[0];
  682. } else {
  683. $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
  684. if (!count ($entities)) {
  685. $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','text/html'));
  686. }
  687. $orig_header = $message->rfc822_header;
  688. }
  689. $encoding = $message->header ->encoding;
  690. $type0 = $message->type0;
  691. $type1 = $message->type1;
  692. foreach ($entities as $ent) {
  693. $unencoded_bodypart = mime_fetch_body ($imapConnection, $passed_id, $ent);
  694. $body_part_entity = $message->getEntity ($ent);
  695. $bodypart = decodeBody ($unencoded_bodypart,
  696. $body_part_entity->header ->encoding);
  697. // type of the actual entity should be here;
  698. // fall back to parent only if not
  699. if (!empty($body_part_entity->type0))
  700. $type0 = $body_part_entity->type0;
  701. if (!empty($body_part_entity->type1))
  702. $type1 = $body_part_entity->type1;
  703. if ($type1 == 'html') {
  704. $bodypart = str_replace ("\n", ' ', $bodypart);
  705. $bodypart = preg_replace (array('/<\/?p>/i','/<div><\/div>/i','/<br\s*(\/)*>/i','/<\/?div>/i'), "\n", $bodypart);
  706. $bodypart = str_replace (array('&nbsp;','&gt;','&lt;'),array(' ','>','<'),$bodypart);
  707. $bodypart = strip_tags ($bodypart);
  708. }
  709. if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
  710. function_exists ($languages[$squirrelmail_language]['XTRA_CODE'])) {
  711. if (mb_detect_encoding ($bodypart) != 'ASCII') {
  712. $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart);
  713. }
  714. }
  715. // charset encoding in compose form stuff
  716. if (isset($body_part_entity->header ->parameters['charset'])) {
  717. $actual = $body_part_entity->header ->parameters['charset'];
  718. } else {
  719. $actual = 'us-ascii';
  720. }
  721. if ( $actual && is_conversion_safe ($actual) && $actual != $default_charset){
  722. $bodypart = charset_convert ($actual,$bodypart,$default_charset,false);
  723. }
  724. // end of charset encoding in compose
  725. $body .= $bodypart;
  726. }
  727. if ($default_use_priority) {
  728. $mailprio = substr ($orig_header->priority,0,1);
  729. if (!$mailprio) {
  730. $mailprio = 3;
  731. }
  732. } else {
  733. $mailprio = '';
  734. }
  735. $identity = '';
  736. $from_o = $orig_header->from;
  737. if (is_array ($from_o)) {
  738. if (isset($from_o[0])) {
  739. $from_o = $from_o[0];
  740. }
  741. }
  742. if (is_object ($from_o)) {
  743. $orig_from = $from_o->getAddress();
  744. } else {
  745. $orig_from = '';
  746. }
  747. $identities = array();
  748. if (count ($idents) > 1) {
  749. foreach($idents as $nr=>$data) {
  750. $enc_from_name = '"'.$data['full_name'].'" <'. $data['email_address'].'>';
  751. $identities[] = $enc_from_name;
  752. }
  753. $identity_match = $orig_header->findAddress($identities);
  754. if ($identity_match !== FALSE) {
  755. $identity = $identity_match;
  756. }
  757. }
  758. switch ($action) {
  759. case ('draft'):
  760. $use_signature = FALSE;
  761. $composeMessage->rfc822_header = $orig_header;
  762. $send_to = decodeHeader ($orig_header->getAddr_s('to'),false,false,true);
  763. $send_to_cc = decodeHeader ($orig_header->getAddr_s('cc'),false,false,true);
  764. $send_to_bcc = decodeHeader ($orig_header->getAddr_s('bcc'),false,false,true);
  765. $identity = 0;
  766. if (count ($idents) > 1) {
  767. $identity_match = $orig_header->findAddress($identities, TRUE);
  768. if ($identity_match !== FALSE) {
  769. $identity = $identity_match;
  770. }
  771. }
  772. $subject = decodeHeader ($orig_header->subject,false,false,true);
  773. /* remember the references and in-reply-to headers in case of an reply */
  774. $composeMessage->rfc822_header->more_headers['References'] = $orig_header->references;
  775. $composeMessage->rfc822_header->more_headers['In-Reply-To'] = $orig_header->in_reply_to;
  776. $body_ary = explode ("\n", $body);
  777. $cnt = count ($body_ary) ;
  778. $body = '';
  779. for ($i=0; $i < $cnt; $i++) {
  780. if (!preg_match ('/^[>\s]*$/', $body_ary[$i]) || !$body_ary[$i]) {
  781. sqWordWrap ($body_ary[$i], $editor_size, $default_charset );
  782. $body .= $body_ary[$i] . "\n";
  783. }
  784. unset($body_ary[$i]);
  785. }
  786. sqUnWordWrap ($body);
  787. $composeMessage = getAttachments ($message, $composeMessage, $passed_id, $entities, $imapConnection);
  788. if (!empty($orig_header->x_sm_flag_reply))
  789. $composeMessage->rfc822_header->more_headers['X-SM-Flag-Reply'] = $orig_header->x_sm_flag_reply;
  790. //TODO: completely unclear if should be using $compose_session instead of $session below
  791. $compose_messages[$session] = $composeMessage;
  792. sqsession_register ($compose_messages,'compose_messages');
  793. break;
  794. case ('edit_as_new'):
  795. $send_to = decodeHeader ($orig_header->getAddr_s('to'),false,false,true);
  796. $send_to_cc = decodeHeader ($orig_header->getAddr_s('cc'),false,false,true);
  797. $send_to_bcc = decodeHeader ($orig_header->getAddr_s('bcc'),false,false,true);
  798. $subject = decodeHeader ($orig_header->subject,false,false,true);
  799. $mailprio = $orig_header->priority;
  800. $orig_from = '';
  801. $composeMessage = getAttachments ($message, $composeMessage, $passed_id, $entities, $imapConnection);
  802. sqUnWordWrap ($body);
  803. break;
  804. case ('forward'):
  805. $send_to = '';
  806. $subject = decodeHeader ($orig_header->subject,false,false,true);
  807. if ((substr (strtolower ($subject), 0, 4) != 'fwd:') &&
  808. (substr (strtolower ($subject), 0, 5) != '[fwd:') &&
  809. (substr (strtolower ($subject), 0, 6) != '[ fwd:')) {
  810. $subject = '[Fwd: ' . $subject . ']';
  811. }
  812. $body = getforwardHeader ($orig_header) . $body;
  813. $composeMessage = getAttachments ($message, $composeMessage, $passed_id, $entities, $imapConnection);
  814. $body = "\n" . $body;
  815. break;
  816. case ('forward_as_attachment'):
  817. $subject = decodeHeader ($orig_header->subject,false,false,true);
  818. $subject = trim ($subject);
  819. if (substr (strtolower ($subject), 0, 4) != 'fwd:') {
  820. $subject = 'Fwd: ' . $subject;
  821. }
  822. $composeMessage = getMessage_RFC822_Attachment ($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
  823. $body = '';
  824. break;
  825. case ('reply_all'):
  826. if(isset($orig_header->mail_followup_to) && $orig_header->mail_followup_to) {
  827. $send_to = $orig_header->getAddr_s('mail_followup_to');
  828. } else {
  829. $send_to_cc = replyAllString ($orig_header);
  830. $send_to_cc = decodeHeader ($send_to_cc,false,false,true);
  831. $send_to_cc = str_replace ('""', '"', $send_to_cc);
  832. }
  833. case ('reply'):
  834. if (!$send_to) {
  835. $send_to = $orig_header->reply_to;
  836. if (is_array ($send_to) && count ($send_to)) {
  837. $send_to = $orig_header->getAddr_s('reply_to', ',', FALSE, TRUE);
  838. } else if (is_object ($send_to)) { /* unneccesarry, just for failsafe purpose */
  839. $send_to = $orig_header->getAddr_s('reply_to', ',', FALSE, TRUE);
  840. } else {
  841. $send_to = $orig_header->getAddr_s('from', ',', FALSE, TRUE);
  842. }
  843. }
  844. $send_to = decodeHeader ($send_to,false,false,true);
  845. $send_to = str_replace ('""', '"', $send_to);
  846. // If user doesn't want replies to her own messages
  847. // going back to herself (instead send again to the
  848. // original recipient of the message being replied to),
  849. // then iterate through identities, checking if the TO
  850. // field is one of them (if the reply is to ourselves)
  851. //
  852. // Note we don't bother if the original message doesn't
  853. // have anything in the TO field itself (because that's
  854. // what we use if we change the recipient to be that of
  855. // the previous message)
  856. //
  857. if ($do_not_reply_to_self && !empty($orig_header->to)) {
  858. $orig_to = '';
  859. foreach($idents as $id) {
  860. if (!empty($id['email_address'])
  861. && strpos ($send_to, $id['email_address']) !== FALSE) {
  862. // if this is a reply-all, the original recipient
  863. // is already in the CC field, so we can just blank
  864. // the recipient (TO field) (as long as the CC field
  865. // isn't empty that is)... but then move the CC into
  866. // the TO, so TO isn't empty
  867. //
  868. if ($action == 'reply_all' && !empty($send_to_cc)) {
  869. $orig_to = $send_to_cc;
  870. $send_to_cc = '';
  871. break;
  872. }
  873. $orig_to = $orig_header->to;
  874. if (is_array ($orig_to) && count ($orig_to)) {
  875. $orig_to = $orig_header->getAddr_s('to', ',', FALSE, TRUE);
  876. } else if (is_object ($orig_to)) { /* unneccesarry, just for failsafe purpose */
  877. $orig_to = $orig_header->getAddr_s('to', ',', FALSE, TRUE);
  878. } else {
  879. $orig_to = '';
  880. }
  881. $orig_to = decodeHeader ($orig_to,false,false,true);
  882. $orig_to = str_replace ('""', '"', $orig_to);
  883. break;
  884. }
  885. }
  886. // if the reply was addressed back to ourselves,
  887. // we will send it to the TO of the previous message
  888. //
  889. if (!empty($orig_to)) {
  890. $send_to = $orig_to;
  891. // in this case, we also want to reset the FROM
  892. // identity as well (it should match the original
  893. // *FROM* header instead of TO or CC)
  894. //
  895. if (count ($idents) > 1) {
  896. $identity = '';
  897. foreach($idents as $i => $id) {
  898. if (!empty($id['email_address'])
  899. && strpos ($orig_from, $id['email_address']) !== FALSE) {
  900. $identity = $i;
  901. break;
  902. }
  903. }
  904. }
  905. }
  906. }
  907. $subject = decodeHeader ($orig_header->subject,false,false,true);
  908. $subject = trim ($subject);
  909. if (substr (strtolower ($subject), 0, 3) != 're:') {
  910. $subject = 'Re: ' . $subject;
  911. }
  912. /* this corrects some wrapping/quoting problems on replies */
  913. $rewrap_body = explode ("\n", $body);
  914. $from = (is_array ($orig_header->from) && !empty($orig_header->from)) ? $orig_header->from[0] : $orig_header->from;
  915. sqUnWordWrap ($body);
  916. $body = '';
  917. $cnt = count ($rewrap_body);
  918. for ($i=0;$i<$cnt;$i++) {
  919. if ($strip_sigs && $rewrap_body[$i] == '-- ') {
  920. break;
  921. }
  922. sqWordWrap ($rewrap_body[$i], $editor_size, $default_charset);
  923. if (preg_match ("/^(>+)/", $rewrap_body[$i], $matches)) {
  924. $gt = $matches[1];
  925. $body .= $body_quote . str_replace ("\n", "\n" . $body_quote
  926. . "$gt ", rtrim ($rewrap_body[$i])) ."\n";
  927. } else {
  928. $body .= $body_quote . (!empty($body_quote) ? ' ' : '') . str_replace ("\n", "\n" . $body_quote . (!empty($body_quote) ? ' ' : ''), rtrim ($rewrap_body[$i])) . "\n";
  929. }
  930. unset($rewrap_body[$i]);
  931. }
  932. $body = getReplyCitation ($from , $orig_header->date ) . $body;
  933. $composeMessage->reply_rfc822_header = $orig_header;
  934. break;
  935. default:
  936. break;
  937. }
  938. sqimap_logout ($imapConnection);
  939. }
  940. $ret = array( 'send_to' => $send_to,
  941. 'send_to_cc' => $send_to_cc,
  942. 'send_to_bcc' => $send_to_bcc,
  943. 'subject' => $subject,
  944. 'mailprio' => $mailprio,
  945. 'body' => $body,
  946. 'identity' => $identity );
  947. return ($ret);
  948. } /* function newMail() */
  949. function getAttachments ($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
  950. global $attachment_dir , $username, $data_dir , $squirrelmail_language, $languages ;
  951. $hashed_attachment_dir = getHashedDir ($username, $attachment_dir);
  952. if (!count ($message->entities) ||
  953. ($message->type0 == 'message' && $message->type1 == 'rfc822')) {
  954. if ( !in_array ($message->entity_id, $entities) && $message->entity_id) {
  955. switch ($message->type0) {
  956. case 'message':
  957. if ($message->type1 == 'rfc822') {
  958. $filename = $message->rfc822_header->subject;
  959. if ($filename == "") {
  960. $filename = "untitled-".$message->entity_id;
  961. }
  962. $filename .= '.eml';
  963. } else {
  964. $filename = $message->getFilename();
  965. }
  966. break;
  967. default:
  968. if (!$message->mime_header) { /* temporary hack */
  969. $message->mime_header = $message->header ;
  970. }
  971. $filename = $message->getFilename();
  972. break;
  973. }
  974. $filename = decodeHeader ($filename, false, false, true);
  975. if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
  976. function_exists ($languages[$squirrelmail_language]['XTRA_CODE'])) {
  977. $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
  978. }
  979. $localfilename = GenerateRandomString (32, '', 7);
  980. $full_localfilename = "$hashed_attachment_dir/$localfilename";
  981. while (file_exists ($full_localfilename)) {
  982. $localfilename = GenerateRandomString (32, '', 7);
  983. $full_localfilename = "$hashed_attachment_dir/$localfilename";
  984. }
  985. $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
  986. $message->att_local_name = $localfilename;
  987. $composeMessage->initAttachment($message->type0.'/'.$message->type1,$filename,
  988. $localfilename);
  989. /* Write Attachment to file
  990. The function mime_print_body_lines writes directly to the
  991. provided resource $fp. That prohibits large memory consumption in
  992. case of forwarding mail with large attachments.
  993. */
  994. mime_print_body_lines ($imapConnection, $passed_id, $message->entity_id, $message->header ->encoding, $fp);
  995. fclose ($fp);
  996. }
  997. } else {
  998. for ($i=0, $entCount=count ($message->entities); $i<$entCount;$i++) {
  999. $composeMessage=getAttachments ($message->entities[$i], $composeMessage, $passed_id, $entities, $imapConnection);
  1000. }
  1001. }
  1002. return $composeMessage;
  1003. }
  1004. function getMessage_RFC822_Attachment ($message, $composeMessage, $passed_id,
  1005. $passed_ent_id='', $imapConnection) {
  1006. global $attachment_dir , $username, $data_dir , $uid_support ;
  1007. $hashed_attachment_dir = getHashedDir ($username, $attachment_dir);
  1008. if (!$passed_ent_id) {
  1009. $body_a = sqimap_run_command ($imapConnection,
  1010. 'FETCH '.$passed_id.' RFC822',
  1011. TRUE, $response, $readmessage,
  1012. $uid_support);
  1013. } else {
  1014. $body_a = sqimap_run_command ($imapConnection,
  1015. 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
  1016. TRUE, $response, $readmessage, $uid_support);
  1017. $message = $message->parent;
  1018. }
  1019. if ($response == 'OK') {
  1020. $subject = encodeHeader ($message->rfc822_header->subject);
  1021. array_shift ($body_a);
  1022. array_pop ($body_a);
  1023. $body = implode ('', $body_a) . "\r\n";
  1024. $localfilename = GenerateRandomString (32, 'FILE', 7);
  1025. $full_localfilename = "$hashed_attachment_dir/$localfilename";
  1026. $fp = fopen ($full_localfilename, 'w');
  1027. fwrite ($fp, $body);
  1028. fclose ($fp);
  1029. $composeMessage->initAttachment('message/rfc822',$subject.'.eml',
  1030. $localfilename);
  1031. }
  1032. return $composeMessage;
  1033. }
  1034. function showInputForm ($session, $values=false) {
  1035. global $send_to, $send_to_cc, $body, $startMessage, $attachments,
  1036. $session_expired,
  1037. $passed_body, $color, $use_signature, $signature, $prefix_sig,
  1038. $editor_size, $editor_height, $subject, $newmail,
  1039. $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
  1040. $from_htmladdr_search, $location_of_buttons, $attachment_dir ,
  1041. $username, $data_dir , $identity, $idents, $draft_id, $delete_draft,
  1042. $mailprio, $default_use_mdn , $mdn_user_support, $compose_new_win,
  1043. $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
  1044. $username, $composesession, $default_charset , $composeMessage,
  1045. $javascript_on, $compose_onsubmit;
  1046. if ($javascript_on)
  1047. $onfocus = ' onfocus="alreadyFocused=true;"';
  1048. else
  1049. $onfocus = '';
  1050. if ($values) {
  1051. $send_to = $values['send_to'];
  1052. $send_to_cc = $values['send_to_cc'];
  1053. $send_to_bcc = $values['send_to_bcc'];
  1054. $subject = $values['subject'];
  1055. $mailprio = $values['mailprio'];
  1056. $body = $values['body'];
  1057. $identity = (int) $values['identity'];
  1058. } else {
  1059. $send_to = decodeHeader ($send_to, true, false);
  1060. $send_to_cc = decodeHeader ($send_to_cc, true, false);
  1061. $send_to_bcc = decodeHeader ($send_to_bcc, true, false);
  1062. }
  1063. if ($use_javascript_addr_book) {
  1064. echo "\n". '<script language="JavaScript">'."\n<!--\n" .
  1065. 'function open_abook() { ' . "\n" .
  1066. ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
  1067. '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
  1068. ' if((!nwin.opener) && (document.windows != null))' . "\n" .
  1069. ' nwin.opener = document.windows;' . "\n" .
  1070. "}\n" .
  1071. "// -->\n</script>\n\n";
  1072. }
  1073. echo "\n" . '<form name="compose" action="compose.php" method="post" ' .
  1074. 'enctype="multipart/form-data"';
  1075. $compose_onsubmit = array();
  1076. do_hook ('compose_form');
  1077. // Plugins that use compose_form hook can add an array entry
  1078. // to the globally scoped $compose_onsubmit; we add them up
  1079. // here and format the form tag's full onsubmit handler.
  1080. // Each plugin should use "return false" if they need to
  1081. // stop form submission but otherwise should NOT use "return
  1082. // true" to give other plugins the chance to do what they need
  1083. // to do; SquirrelMail itself will add the final "return true".
  1084. // Onsubmit text is enclosed inside of double quotes, so plugins
  1085. // need to quote accordingly.
  1086. //
  1087. // Also, plugin authors should try to retain compatibility with
  1088. // the Compose Extras plugin by resetting its compose submit
  1089. // counter when preventing form submit. Use this code:
  1090. // if (your-code-here) { submit_count = 0; return false; }
  1091. //
  1092. if ($javascript_on) {
  1093. if (empty($compose_onsubmit))
  1094. $compose_onsubmit = array();
  1095. else if (!is_array ($compose_onsubmit))
  1096. $compose_onsubmit = array($compose_onsubmit);
  1097. $onsubmit_text = '';
  1098. foreach ($compose_onsubmit as $text) {
  1099. $text = trim ($text);
  1100. if (!empty($text)) {
  1101. if (substr ($text, -1) != ';' && substr ($text, -1) != '}')
  1102. $text .= '; ';
  1103. $onsubmit_text .= $text;
  1104. }
  1105. }
  1106. if (!empty($onsubmit_text))
  1107. echo ' onsubmit="' . $onsubmit_text . ' return true;"';
  1108. }
  1109. echo ">\n";
  1110. echo addHidden ('smtoken', sm_generate_security_token ());
  1111. echo addHidden ('startMessage', $startMessage);
  1112. if ($action == 'draft') {
  1113. echo addHidden ('delete_draft', $passed_id);
  1114. }
  1115. if (isset($delete_draft)) {
  1116. echo addHidden ('delete_draft', $delete_draft);
  1117. }
  1118. if (isset($session)) {
  1119. echo addHidden ('session', $session);
  1120. }
  1121. // NB: passed_id is set to empty string elsewhere, so this ALWAYS gets added, which is better anyway IMO
  1122. if (isset($passed_id)) {
  1123. echo addHidden ('passed_id', $passed_id);
  1124. }
  1125. if ($saved_draft == 'yes') {
  1126. echo '<br /><center><b>'. _ ("Your draft has been saved.").'</center></b>';
  1127. }
  1128. if ($mail_sent == 'yes') {
  1129. echo '<br /><center><b>'. _ ("Your mail has been sent.").'</center></b>';
  1130. }
  1131. if ($compose_new_win == '1') {
  1132. echo '<table align="center" bgcolor="'.$color[0].'" width="100%" border="0">'."\n" .
  1133. ' <tr><td></td>'.html_tag ( 'td', '', 'right' ).
  1134. '<input type="button" name="Close" onclick="return self.close()" value="'.
  1135. _ ("Close").'" /></td></tr>'."\n";
  1136. } else {
  1137. echo '<table align="center" cellspacing="0" border="0">' . "\n";
  1138. }
  1139. if ($location_of_buttons == 'top') {
  1140. }
  1141. /* display select list for identities */
  1142. if (count ($idents) > 1) {
  1143. echo ' <tr>' . "\n" .
  1144. html_tag ( 'td', '', 'right', $color[4], 'width="10%"' ) .
  1145. _ ("From:") . '</td>' . "\n" .
  1146. html_tag ( 'td', '', 'left', $color[4], 'width="90%"' ) .
  1147. ' <select name="identity">' . "\n";
  1148. foreach($idents as $nr => $data) {
  1149. echo '<option value="' . $nr . '"';
  1150. if (isset($identity) && $identity == $nr) {
  1151. echo ' selected="selected"';
  1152. }
  1153. $data['full_name'] . ' <' .
  1154. $data['email_address'] . '>') .
  1155. "</option>\n";
  1156. }
  1157. echo '</select>' . "\n" .
  1158. ' </td>' . "\n" .
  1159. ' </tr>' . "\n";
  1160. }
  1161. echo ' <tr>' . "\n" .
  1162. html_tag ( 'td', '', 'right', $color[4], 'width="10%"' ) .
  1163. _ ("To:") . '</td>' . "\n" .
  1164. html_tag ( 'td', '', 'left', $color[4], 'width="90%"' ) .
  1165. substr (addInput ('send_to', $send_to, 60), 0, -3). $onfocus . ' /><br />' . "\n" .
  1166. ' </td>' . "\n" .
  1167. ' </tr>' . "\n" .
  1168. ' <tr>' . "\n" .
  1169. html_tag ( 'td', '', 'right', $color[4] ) .
  1170. _ ("Cc:") . '</td>' . "\n" .
  1171. html_tag ( 'td', '', 'left', $color[4] ) .
  1172. substr (addInput ('send_to_cc', $send_to_cc, 60), 0, -3). $onfocus . ' /><br />' . "\n" .
  1173. ' </td>' . "\n" .
  1174. ' </tr>' . "\n" .
  1175. ' <tr>' . "\n" .
  1176. html_tag ( 'td', '', 'right', $color[4] ) .
  1177. _ ("Bcc:") . '</td>' . "\n" .
  1178. html_tag ( 'td', '', 'left', $color[4] ) .
  1179. substr (addInput ('send_to_bcc', $send_to_bcc, 60), 0, -3). $onfocus . ' /><br />' . "\n" .
  1180. ' </td>' . "\n" .
  1181. ' </tr>' . "\n" .
  1182. ' <tr>' . "\n" .
  1183. html_tag ( 'td', '', 'right', $color[4] ) .
  1184. _ ("Subject:") . '</td>' . "\n" .
  1185. html_tag ( 'td', '', 'left', $color[4] ) . "\n";
  1186. echo ' '.substr (addInput ('subject', $subject, 60), 0, -3). $onfocus .
  1187. ' /> </td>' . "\n" .
  1188. ' </tr>' . "\n\n";
  1189. if ($location_of_buttons == 'between') {
  1190. }
  1191. /* why this distinction? */
  1192. if ($compose_new_win == '1') {
  1193. echo ' <tr>' . "\n" .
  1194. ' <td bgcolor="' . $color[0] . '" colspan="2" align="center">' . "\n" .
  1195. ' <textarea name="body" id="body" rows="' . (int)$editor_height .
  1196. '" cols="' . (int)$editor_size . '" wrap="virtual"' . $onfocus . ">\n";
  1197. }
  1198. else {
  1199. echo ' <tr>' . "\n" .
  1200. ' <td bgcolor="' . $color[4] . '" colspan="2">' . "\n" .
  1201. ' &nbsp;&nbsp;<textarea name="body" id="body" rows="' . (int)$editor_height .
  1202. '" cols="' . (int)$editor_size . '" wrap="virtual"' . $onfocus . ">\n";
  1203. }
  1204. if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
  1205. $signature = $idents[$identity]['signature'];
  1206. if ($sig_first == '1') {
  1207. if ($default_charset == 'iso-2022-jp') {
  1208. echo "\n\n".($prefix_sig==true? "-- \n":'').mb_convert_encoding ($signature, 'EUC-JP');
  1209. } else {
  1210. echo "\n\n".($prefix_sig==true? "-- \n":'').decodeHeader ($signature,false,false,true);
  1211. }
  1212. echo "\n\n".sm_encode_html_special_chars (decodeHeader ($body,false,false,true));
  1213. }
  1214. else {
  1215. echo "\n\n".sm_encode_html_special_chars (decodeHeader ($body,false,false,true));
  1216. if ($default_charset == 'iso-2022-jp') {
  1217. echo "\n\n".($prefix_sig==true? "-- \n":'').mb_convert_encoding ($signature, 'EUC-JP');
  1218. }else{
  1219. echo "\n\n".($prefix_sig==true? "-- \n":'').decodeHeader ($signature,false,false,true);
  1220. }
  1221. }
  1222. } else {
  1223. echo sm_encode_html_special_chars (decodeHeader ($body,false,false,true));
  1224. }
  1225. echo '</textarea><br />' . "\n" .
  1226. ' </td>' . "\n" .
  1227. ' </tr>' . "\n";
  1228. if ($location_of_buttons == 'bottom') {
  1229. } else {
  1230. echo ' <tr>' . "\n" .
  1231. html_tag ( 'td', '', 'right', '', 'colspan="2"' ) . "\n" .
  1232. ' ' . addSubmit (_ ("Send"), 'send').
  1233. ' &nbsp;&nbsp;&nbsp;&nbsp;<br /><br />' . "\n" .
  1234. ' </td>' . "\n" .
  1235. ' </tr>' . "\n";
  1236. }
  1237. // composeMessage can be empty when coming from a restored session
  1238. if (is_object ($composeMessage) && $composeMessage->entities)
  1239. $attach_array = $composeMessage->entities;
  1240. if ($session_expired && !empty($attachments) && is_array ($attachments))
  1241. $attach_array = $attachments;
  1242. /* This code is for attachments */
  1243. if ((bool) ini_get ('file_uploads')) {
  1244. /* Calculate the max size for an uploaded file.
  1245. * This is advisory for the user because we can't actually prevent
  1246. * people to upload too large files. */
  1247. $sizes = array();
  1248. /* php.ini vars which influence the max for uploads */
  1249. $configvars = array('post_max_size', 'memory_limit', 'upload_max_filesize');
  1250. foreach($configvars as $var) {
  1251. /* skip 0 or empty values, and -1 which means 'unlimited' */
  1252. if( $size = getByteSize (ini_get ($var)) ) {
  1253. if ( $size != '-1' ) {
  1254. $sizes[] = $size;
  1255. }
  1256. }
  1257. }
  1258. if(count ($sizes) > 0) {
  1259. $maxsize_text = '(max.&nbsp;' . show_readable_size ( min ( $sizes ) ) . ')';
  1260. $maxsize_input = addHidden ('MAX_FILE_SIZE', min ( $sizes ));
  1261. } else {
  1262. $maxsize_text = $maxsize_input = '';
  1263. }
  1264. echo ' <tr>' . "\n" .
  1265. ' <td colspan="2">' . "\n" .
  1266. ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
  1267. ' border="0" bgcolor="'.$color[9].'">' . "\n" .
  1268. ' <tr>' . "\n" .
  1269. ' <td>' . "\n" .
  1270. ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
  1271. ' border="0">' . "\n" .
  1272. ' <tr>' . "\n" .
  1273. html_tag ( 'td', '', 'right', '', 'valign="middle"' ) .
  1274. _ ("Attach:") . '</td>' . "\n" .
  1275. html_tag ( 'td', '', 'left', '', 'valign="middle"' ) .
  1276. $maxsize_input .
  1277. ' <input name="attachfile" size="48" type="file" />' . "\n" .
  1278. ' &nbsp;&nbsp;<input type="submit" name="attach"' .
  1279. ' value="' . _ ("Add") .'" />' . "\n" .
  1280. $maxsize_text .
  1281. ' </td>' . "\n" .
  1282. ' </tr>' . "\n";
  1283. $s_a = array();
  1284. global $username, $attachment_dir ;
  1285. $hashed_attachment_dir = getHashedDir ($username, $attachment_dir);
  1286. if (!empty($attach_array)) {
  1287. $attachment_count = 0;
  1288. foreach ($attach_array as $key => $attachment) {
  1289. $attached_file = $attachment->att_local_name;
  1290. if ($attachment->att_local_name || $attachment->body_part) {
  1291. $attached_filename = decodeHeader ($attachment->mime_header->getParameter('name'));
  1292. $type = $attachment->mime_header->type0.'/'.
  1293. $attachment->mime_header->type1;
  1294. $s_a[] = '<table bgcolor="'.$color[0].
  1295. '" border="0"><tr><td>'.
  1296. addCheckBox ('delete[]', FALSE, $key, 'id="delete' . ++$attachment_count . '"').
  1297. "</td><td><label for='delete" . $attachment_count . "'>\n" . $attached_filename .
  1298. '</label></td><td><label for="delete' . $attachment_count . '">-</label></td><td><label for="delete' . $attachment_count . '"> ' . $type . '</label></td><td><label for="delete' . $attachment_count . '">('.
  1299. show_readable_size ( filesize ( $hashed_attachment_dir . '/' . $attached_file ) ) .
  1300. ')</label></td></tr></table>'."\n";
  1301. }
  1302. }
  1303. }
  1304. if (count ($s_a)) {
  1305. foreach ($s_a as $s) {
  1306. echo '<tr>' . html_tag ( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
  1307. }
  1308. echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
  1309. _ ("Delete selected attachments") . "\" />\n" .
  1310. '</td></tr>';
  1311. }
  1312. echo ' </table>' . "\n" .
  1313. ' </td>' . "\n" .
  1314. ' </tr>' . "\n" .
  1315. ' </table>' . "\n" .
  1316. ' </td>' . "\n" .
  1317. ' </tr>' . "\n";
  1318. } // End of file_uploads if-block
  1319. /* End of attachment code */
  1320. echo '</table>' . "\n" .
  1321. addHidden ('username', $username).
  1322. addHidden ('smaction', $action).
  1323. addHidden ('mailbox', $mailbox);
  1324. sqgetGlobalVar ('QUERY_STRING', $queryString, SQ_SERVER );
  1325. /*
  1326. store the complete ComposeMessages array in a hidden input value
  1327. so we can restore them in case of a session timeout.
  1328. */
  1329. echo addHidden ('composesession', $composesession).
  1330. addHidden ('querystring', $queryString).
  1331. (!empty($attach_array) ?
  1332. addHidden ('attachments', serialize ($attach_array)) : '').
  1333. "</form>\n";
  1334. if (!(bool) ini_get ('file_uploads')) {
  1335. /* File uploads are off, so we didn't show that part of the form.
  1336. To avoid bogus bug reports, tell the user why. */
  1337. echo '<p style="text-align:center">'
  1338. . _ ("Because PHP file uploads are turned off, you can not attach files to this message. Please see your system administrator for details.")
  1339. . "</p>\r\n";
  1340. }
  1341. do_hook ('compose_bottom');
  1342. echo '</body></html>' . "\n";
  1343. }
  1344. function showComposeButtonRow () {
  1345. global $use_javascript_addr_book, $save_as_draft,
  1346. $request_mdn, $request_dr,
  1347. $data_dir , $username;
  1348. echo ' <tr>' . "\n" .
  1349. ' <td></td>' . "\n" .
  1350. ' <td>' . "\n";
  1351. if ($default_use_priority) {
  1352. if(!isset($mailprio)) {
  1353. $mailprio = '3';
  1354. }
  1355. echo ' ' . _ ("Priority") .
  1356. addSelect ('mailprio', array(
  1357. '1' => _ ("High"),
  1358. '3' => _ ("Normal"),
  1359. '5' => _ ("Low") ), $mailprio, TRUE);
  1360. }
  1361. $mdn_user_support=getPref ($data_dir, $username, 'mdn_user_support',$default_use_mdn);
  1362. if ($default_use_mdn) {
  1363. if ($mdn_user_support) {
  1364. echo ' ' . _ ("Receipt") .': '.
  1365. addCheckBox ('request_mdn', $request_mdn == '1', '1', 'id="request_mdn"') . '<label for="request_mdn">' . _ ("On Read") . '</label>' .
  1366. addCheckBox ('request_dr', $request_dr == '1', '1', 'id="request_dr"') . '<label for="request_dr">' . _ ("On Delivery") . '</label>';
  1367. }
  1368. }
  1369. echo ' </td>' . "\n" .
  1370. ' </tr>' . "\n" .
  1371. ' <tr>' . "\n" .
  1372. ' <td></td>' . "\n" .
  1373. ' <td>' . "\n" .
  1374. ' <input type="submit" name="sigappend" value="' . _ ("Signature") . '" />' . "\n";
  1375. if ($use_javascript_addr_book) {
  1376. echo " <script language=\"JavaScript\"><!--\n document.write(\"".
  1377. " <input type=button value=\\\""._ ("Addresses").
  1378. "\\\" onclick=\\\"javascript:open_abook();\\\" />\");".
  1379. " // --></script><noscript>\n".
  1380. ' <input type="submit" name="html_addr_search" value="'.
  1381. _ ("Addresses").'" />'.
  1382. " </noscript>\n";
  1383. } else {
  1384. echo ' <input type="submit" name="html_addr_search" value="'.
  1385. _ ("Addresses").'" />' . "\n";
  1386. }
  1387. if ($save_as_draft) {
  1388. echo ' <input type="submit" name ="draft" value="' . _ ("Save Draft") . "\" />\n";
  1389. }
  1390. echo ' <input type="submit" name="send" value="'. _ ("Send") . '" />' . "\n";
  1391. do_hook ('compose_button_row');
  1392. echo ' </td>' . "\n" .
  1393. ' </tr>' . "\n\n";
  1394. }
  1395. function checkInput ($show) {
  1396. /*
  1397. * I implemented the $show variable because the error messages
  1398. * were getting sent before the page header. So, I check once
  1399. * using $show=false, and then when i'm ready to display the error
  1400. * message, show=true
  1401. */
  1402. global $body, $send_to, $send_to_cc, $send_to_bcc, $subject, $color;
  1403. $send_to = trim ($send_to);
  1404. $send_to_cc = trim ($send_to_cc);
  1405. $send_to_bcc = trim ($send_to_bcc);
  1406. if (empty($send_to) && empty($send_to_cc) && empty($send_to_bcc)) {
  1407. if ($show) {
  1408. plain_error_message (_ ("You have not filled in the \"To:\" field."), $color);
  1409. }
  1410. return false;
  1411. }
  1412. return true;
  1413. } /* function checkInput() */
  1414. /* True if FAILURE */
  1415. function saveAttachedFiles ($session) {
  1416. global $_FILES, $attachment_dir , $username,
  1417. $data_dir , $composeMessage;
  1418. /* get out of here if no file was attached at all */
  1419. if (! is_uploaded_file ($_FILES['attachfile']['tmp_name']) ) {
  1420. return true;
  1421. }
  1422. $hashed_attachment_dir = getHashedDir ($username, $attachment_dir);
  1423. $localfilename = GenerateRandomString (32, '', 7);
  1424. $full_localfilename = "$hashed_attachment_dir/$localfilename";
  1425. while (file_exists ($full_localfilename)) {
  1426. $localfilename = GenerateRandomString (32, '', 7);
  1427. $full_localfilename = "$hashed_attachment_dir/$localfilename";
  1428. }
  1429. // FIXME: we SHOULD prefer move_uploaded_file over rename because
  1430. // m_u_f works better with restricted PHP installs (safe_mode, open_basedir)
  1431. if (!@rename ($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
  1432. if (!@move_uploaded_file ($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
  1433. return true;
  1434. }
  1435. }
  1436. $type = strtolower ($_FILES['attachfile']['type']);
  1437. $name = $_FILES['attachfile']['name'];
  1438. $composeMessage->initAttachment($type, $name, $localfilename);
  1439. }
  1440. /* parse values like 8M and 2k into bytes */
  1441. function getByteSize ($ini_size) {
  1442. if(!$ini_size) {
  1443. return FALSE;
  1444. }
  1445. $ini_size = trim ($ini_size);
  1446. // if there's some kind of letter at the end of the string we need to multiply.
  1447. if(!is_numeric (substr ($ini_size, -1))) {
  1448. switch(strtoupper (substr ($ini_size, -1))) {
  1449. case 'G':
  1450. $bytesize = 1073741824;
  1451. break;
  1452. case 'M':
  1453. $bytesize = 1048576;
  1454. break;
  1455. case 'K':
  1456. $bytesize = 1024;
  1457. break;
  1458. }
  1459. return ($bytesize * (int)substr ($ini_size, 0, -1));
  1460. }
  1461. return $ini_size;
  1462. }
  1463. /**
  1464. * temporary function to make use of the deliver class.
  1465. * In the future the responsible backend should be automaticly loaded
  1466. * and conf.pl should show a list of available backends.
  1467. * The message also should be constructed by the message class.
  1468. *
  1469. * @param object $composeMessage The message being sent. Please note
  1470. * that it is passed by reference and
  1471. * will be returned modified, with additional
  1472. * headers, such as Message-ID, Date, In-Reply-To,
  1473. * References, and so forth.
  1474. *
  1475. * @return boolean FALSE if delivery failed, or some non-FALSE value
  1476. * upon success.
  1477. *
  1478. */
  1479. function deliverMessage (&$composeMessage, $draft=false) {
  1480. global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
  1481. $username, $popuser, $usernamedata, $identity, $idents, $data_dir ,
  1482. $request_mdn, $request_dr, $default_charset , $color, $useSendmail ,
  1483. $domain , $action, $default_move_to_sent, $move_to_sent, $session, $compose_messages;
  1484. global $imapServerAddress , $imapPort , $imap_stream_options, $sent_folder, $key;
  1485. $rfc822_header = $composeMessage->rfc822_header;
  1486. $abook = addressbook_init (false, true);
  1487. $rfc822_header->to = $rfc822_header->parseAddress ($send_to,true, array(), '', $domain, array(&$abook,'lookup'));
  1488. $rfc822_header->cc = $rfc822_header->parseAddress ($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup'));
  1489. $rfc822_header->bcc = $rfc822_header->parseAddress ($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'));
  1490. $rfc822_header->priority = $mailprio;
  1491. $rfc822_header->subject = $subject;
  1492. $special_encoding='';
  1493. if (strtolower ($default_charset) == 'iso-2022-jp') {
  1494. if (mb_detect_encoding ($body) == 'ASCII') {
  1495. $special_encoding = '8bit';
  1496. } else {
  1497. $body = mb_convert_encoding ($body, 'JIS');
  1498. $special_encoding = '7bit';
  1499. }
  1500. }
  1501. $composeMessage->setBody($body);
  1502. if (preg_match ('|^([^@%/]+)[@%/](.+)$|', $username, $usernamedata)) {
  1503. $popuser = $usernamedata[1];
  1504. $domain = $usernamedata[2];
  1505. unset($usernamedata);
  1506. } else {
  1507. $popuser = $username;
  1508. }
  1509. $reply_to = '';
  1510. $from_mail = $idents[$identity]['email_address'];
  1511. $full_name = $idents[$identity]['full_name'];
  1512. $reply_to = $idents[$identity]['reply_to'];
  1513. if (!$from_mail) {
  1514. $from_mail = "$popuser@$domain";
  1515. }
  1516. $rfc822_header->from = $rfc822_header->parseAddress ($from_mail,true);
  1517. if (!$rfc822_header->from[0]->host) $rfc822_header->from[0]->host = $domain;
  1518. if ($full_name) {
  1519. $from = $rfc822_header->from[0];
  1520. $full_name_encoded = encodeHeader ('"' . $full_name . '"');
  1521. if ($full_name_encoded != $full_name) {
  1522. $from_addr = $full_name_encoded .' <'.$from->mailbox.'@'.$from->host.'>';
  1523. } else {
  1524. $from_addr = '"'.$full_name .'" <'.$from->mailbox.'@'.$from->host.'>';
  1525. }
  1526. $rfc822_header->from = $rfc822_header->parseAddress ($from_addr,true);
  1527. }
  1528. if ($reply_to) {
  1529. $rfc822_header->reply_to = $rfc822_header->parseAddress ($reply_to,true);
  1530. if (!$rfc822_header->reply_to[0]->host) $rfc822_header->reply_to[0]->host = $domain;
  1531. }
  1532. /* Receipt: On Read */
  1533. if (isset($request_mdn) && $request_mdn) {
  1534. $rfc822_header->dnt = $rfc822_header->parseAddress ($from_mail,true);
  1535. }
  1536. /* Receipt: On Delivery */
  1537. if (isset($request_dr) && $request_dr) {
  1538. $rfc822_header->more_headers['Return-Receipt-To'] = $from_mail;
  1539. }
  1540. /* multipart messages */
  1541. if (count ($composeMessage->entities)) {
  1542. $message_body = new Message ();
  1543. $message_body->body_part = $composeMessage->body_part;
  1544. $composeMessage->body_part = '';
  1545. $mime_header = new MessageHeader ;
  1546. $mime_header->type0 = 'text';
  1547. $mime_header->type1 = 'plain';
  1548. if ($special_encoding) {
  1549. $mime_header->encoding = $special_encoding;
  1550. } else {
  1551. $mime_header->encoding = '8bit';
  1552. }
  1553. if ($default_charset) {
  1554. $mime_header->parameters['charset'] = $default_charset;
  1555. }
  1556. $message_body->mime_header = $mime_header;
  1557. array_unshift ($composeMessage->entities, $message_body);
  1558. $content_type = new ContentType ('multipart/mixed');
  1559. } else {
  1560. $content_type = new ContentType ('text/plain');
  1561. if ($special_encoding) {
  1562. $rfc822_header->encoding = $special_encoding;
  1563. } else {
  1564. $rfc822_header->encoding = '8bit';
  1565. }
  1566. if ($default_charset) {
  1567. $content_type->properties['charset']=$default_charset;
  1568. }
  1569. }
  1570. $rfc822_header->content_type = $content_type;
  1571. $composeMessage->rfc822_header = $rfc822_header;
  1572. if ($action == 'reply' || $action == 'reply_all') {
  1573. global $passed_id, $passed_ent_id;
  1574. $reply_id = $passed_id;
  1575. $reply_ent_id = $passed_ent_id;
  1576. } else {
  1577. $reply_id = '';
  1578. $reply_ent_id = '';
  1579. }
  1580. /* Here you can modify the message structure just before we hand
  1581. it over to deliver */
  1582. $hookReturn = do_hook ('compose_send', $composeMessage, $draft);
  1583. /* Get any changes made by plugins to $composeMessage. */
  1584. if ( is_object ($hookReturn[1]) ) {
  1585. $composeMessage = $hookReturn[1];
  1586. }
  1587. /* Get any changes made by plugins to $draft. */
  1588. if ( !empty($hookReturn[2]) || $hookReturn[2] === FALSE ) {
  1589. $draft = $hookReturn[2];
  1590. }
  1591. // remove special header if present and prepare to mark
  1592. // a message that a draft was composed in reply to
  1593. if (!empty($composeMessage->rfc822_header->x_sm_flag_reply) && !$draft) {
  1594. global $passed_id, $mailbox, $action;
  1595. // tricks the code below that marks the reply
  1596. list($action, $passed_id, $mailbox) = explode ('::', $rfc822_header->x_sm_flag_reply, 3);
  1597. unset($composeMessage->rfc822_header->x_sm_flag_reply);
  1598. unset($composeMessage->rfc822_header->more_headers['X-SM-Flag-Reply']);
  1599. }
  1600. if (!$useSendmail && !$draft) {
  1601. require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php');
  1602. $deliver = new Deliver_SMTP ();
  1603. global $smtpServerAddress , $smtpPort , $smtp_stream_options,
  1604. $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false;
  1605. $user = '';
  1606. $pass = '';
  1607. if (empty($pop_before_smtp_host))
  1608. $pop_before_smtp_host = $smtpServerAddress;
  1609. get_smtp_user ($user, $pass);
  1610. $stream = $deliver->initStream($composeMessage,$domain,0,
  1611. $smtpServerAddress, $smtpPort, $user, $pass, $authPop, $pop_before_smtp_host, $smtp_stream_options);
  1612. } elseif (!$draft) {
  1613. require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php');
  1614. // Check for outdated configuration
  1615. if (!isset($sendmail_args)) {
  1616. if ($sendmail_path=='/var/qmail/bin/qmail-inject') {
  1617. $sendmail_args = '';
  1618. } else {
  1619. $sendmail_args = '-i -t';
  1620. }
  1621. }
  1622. $deliver = new Deliver_SendMail (array('sendmail_args'=>$sendmail_args));
  1623. $stream = $deliver->initStream($composeMessage,$sendmail_path);
  1624. } elseif ($draft) {
  1625. global $draft_folder;
  1626. $imap_stream = sqimap_login ($username, $key, $imapServerAddress,
  1627. $imapPort, 0, $imap_stream_options);
  1628. if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
  1629. //TODO: this can leak private information about folders and message IDs if messages are accessed/sent from another client --- should this feature be optional?
  1630. // make note of the message to mark as having been replied to
  1631. global $passed_id, $mailbox, $action;
  1632. if ($action == 'reply' || $action == 'reply_all') {
  1633. $composeMessage->rfc822_header->more_headers['X-SM-Flag-Reply'] = $action . '::' . $passed_id . '::' . $mailbox;
  1634. }
  1635. require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
  1636. $imap_deliver = new Deliver_IMAP ();
  1637. $succes = $imap_deliver->mail ($composeMessage, $imap_stream, $reply_id, $reply_ent_id, $imap_stream, $draft_folder);
  1638. sqimap_logout ($imap_stream);
  1639. unset ($imap_deliver);
  1640. $composeMessage->purgeAttachments();
  1641. //TODO: completely unclear if should be using $compose_session instead of $session below
  1642. unset($compose_messages[$session]);
  1643. sqsession_register ($compose_messages,'compose_messages');
  1644. return $succes;
  1645. } else {
  1646. $msg = '<br />'.sprintf (_ ("Error: Draft folder %s does not exist."),
  1647. sm_encode_html_special_chars ($draft_folder));
  1648. plain_error_message ($msg, $color);
  1649. return false;
  1650. }
  1651. }
  1652. $succes = false;
  1653. if ($stream) {
  1654. $deliver->mail ($composeMessage, $stream, $reply_id, $reply_ent_id);
  1655. $succes = $deliver->finalizeStream($stream);
  1656. }
  1657. if (!$succes) {
  1658. $msg = _ ("Message not sent.") . ' ' . _ ("Server replied:")
  1659. . "\n<blockquote>\n"
  1660. . (isset($deliver->dlv_msg) ? $deliver->dlv_msg : '')
  1661. . '<br />'
  1662. . (isset($deliver->dlv_ret_nr) ? $deliver->dlv_ret_nr . ' ' : '')
  1663. . (isset($deliver->dlv_server_msg) ? $deliver->dlv_server_msg : '')
  1664. . "</blockquote>\n\n";
  1665. plain_error_message ($msg, $color);
  1666. } else {
  1667. unset ($deliver);
  1668. $imap_stream = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0, $imap_stream_options);
  1669. // mark original message as having been replied to if applicable
  1670. global $passed_id, $mailbox, $action;
  1671. if ($action == 'reply' || $action == 'reply_all') {
  1672. // select errors here could be due to a draft reply being sent
  1673. // after the original message's mailbox is moved or deleted
  1674. $result = sqimap_mailbox_select ($imap_stream, $mailbox, false);
  1675. // a non-empty return from above means we can proceed
  1676. if (!empty($result))
  1677. sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', false);
  1678. }
  1679. // copy message to sent folder
  1680. $move_to_sent = getPref ($data_dir,$username,'move_to_sent', $default_move_to_sent);
  1681. if (isset($default_move_to_sent) && ($default_move_to_sent != 0)) {
  1682. $svr_allow_sent = true;
  1683. } else {
  1684. $svr_allow_sent = false;
  1685. }
  1686. if (isset($sent_folder) && (($sent_folder != '') || ($sent_folder != 'none'))
  1687. && sqimap_mailbox_exists ( $imap_stream, $sent_folder)) {
  1688. $fld_sent = true;
  1689. } else {
  1690. $fld_sent = false;
  1691. }
  1692. if ((isset($move_to_sent) && ($move_to_sent != 0)) || (!isset($move_to_sent))) {
  1693. $lcl_allow_sent = true;
  1694. } else {
  1695. $lcl_allow_sent = false;
  1696. }
  1697. if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) || ($fld_sent && $lcl_allow_sent)) {
  1698. require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
  1699. $imap_deliver = new Deliver_IMAP ();
  1700. $imap_deliver->mail ($composeMessage, $imap_stream, $reply_id, $reply_ent_id, $imap_stream, $sent_folder);
  1701. unset ($imap_deliver);
  1702. }
  1703. $composeMessage->purgeAttachments();
  1704. //TODO: completely unclear if should be using $compose_session instead of $session below
  1705. unset($compose_messages[$session]);
  1706. sqsession_register ($compose_messages,'compose_messages');
  1707. sqimap_logout ($imap_stream);
  1708. }
  1709. return $succes;
  1710. }

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

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