6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This contains all the functions needed to send messages through
10 * an smtp server or sendmail.
15 require_once('../functions/addressbook.php');
16 require_once('../functions/plugin.php');
17 require_once('../functions/prefs.php');
19 global $username, $popuser, $domain;
21 /* This should most probably go to some initialization... */
22 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
23 $popuser = $usernamedata[1];
24 $domain = $usernamedata[2];
29 /* We need domain for smtp */
31 $domain = getenv('HOSTNAME');
34 /* Returns true only if this message is multipart */
35 function isMultipart ($session) {
38 foreach ($attachments as $info) {
39 if ($info['session'] == $session) {
46 /* looks up aliases in the addressbook and expands them to
49 * Adds @$domain if it wasn't in the address book and if it
50 * doesn't have an @ symbol in it
52 function expandAddrs ($array) {
55 /* don't show errors -- kinda critical that we don't see
56 * them here since the redirect won't work if we do show them
58 $abook = addressbook_init(false, true);
59 for ($i=0; $i < count($array); $i++
) {
60 $result = $abook->lookup($array[$i]);
62 if (isset($result['email'])) {
63 if (isset($result['name'])) {
64 $ret = '"'.$result['name'].'" ';
66 $ret .= '<'.$result['email'].'>';
71 if (strpos($array[$i], '@') === false) {
72 $array[$i] .= '@' . $domain;
74 $array[$i] = '<' . $array[$i] . '>';
81 /* looks up aliases in the addressbook and expands them to
82 * the RFC 821 valid RCPT address. ie <user@example.com>
83 * Adds @$domain if it wasn't in the address book and if it
84 * doesn't have an @ symbol in it
86 function expandRcptAddrs ($array) {
89 /* don't show errors -- kinda critical that we don't see
90 * them here since the redirect won't work if we do show them
92 $abook = addressbook_init(false, true);
93 for ($i=0; $i < count($array); $i++
) {
94 $result = $abook->lookup($array[$i]);
96 if (isset($result['email'])) {
97 $ret = '<'.$result['email'].'>';
101 if (strpos($array[$i], '@') === false) {
102 $array[$i] .= '@' . $domain;
104 $array[$i] = '<' . $array[$i] . '>';
111 /* Attach the files that are due to be attached
113 function attachFiles ($fp, $session, $rn="\r\n") {
114 global $attachments, $attachment_dir, $username;
118 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
119 if (isMultipart($session)) {
120 foreach ($attachments as $info) {
121 if ($info['session'] == $session) {
122 if (isset($info['type'])) {
123 $filetype = $info['type'];
126 $filetype = 'application/octet-stream';
129 $header = '--' . mimeBoundary() . "$rn";
130 if ( isset($info['remotefilename'])
131 && $info['remotefilename'] != '') {
132 $header .= "Content-Type: $filetype; name=\"" .
133 encodeHeader(charset_encode_japanese($info['remotefilename'])) . "\"$rn";
134 $header .= "Content-Disposition: attachment; filename=\""
135 . encodeHeader(charset_encode_japanese($info['remotefilename'])) . "\"$rn";
137 $header .= "Content-Type: $filetype$rn";
141 /* Use 'rb' for NT systems -- read binary
142 * Unix doesn't care -- everything's binary! :-)
145 $filename = $hashed_attachment_dir . '/'
146 . $info['localfilename'];
147 $file = fopen ($filename, 'rb');
148 if (substr($filetype, 0, 5) == 'text/' ||
149 substr($filetype, 0, 8) == 'message/' ) {
152 fputs ($fp, $header);
154 $length +
= strlen($header);
155 while ($tmp = fgets($file, 4096)) {
156 $tmp = str_replace("\r\n", "\n", $tmp);
157 $tmp = str_replace("\r", "\n", $tmp);
159 $tmp = str_replace("\n", "\r\n", $tmp);
164 $length +
= strlen($tmp);
166 if (substr($tmp, strlen($tmp) - strlen($rn), strlen($rn)) != $rn) {
172 $header .= "Content-Transfer-Encoding: base64"
174 if ($fp) fputs ($fp, $header);
175 $length +
= strlen($header);
176 while ($tmp = fread($file, 570)) {
177 $encoded = chunk_split(base64_encode($tmp));
178 $length +
= strlen($encoded);
179 if ($fp) fputs ($fp, $encoded);
189 /* Delete files that are uploaded for attaching
191 function deleteAttachments($session) {
192 global $username, $attachments, $attachment_dir, $data_dir;
193 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
195 $rem_attachments = array();
196 foreach ($attachments as $info) {
197 if ($info['session'] == $session) {
198 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
199 if (file_exists($attached_file)) {
200 unlink($attached_file);
203 $rem_attachments[] = $info;
206 $attachments = $rem_attachments;
207 setPref($data_dir, $username, 'attachments', serialize($attachments));
210 /* Return a nice MIME-boundary
212 function mimeBoundary () {
213 static $mimeBoundaryString;
215 if ( !isset( $mimeBoundaryString ) ||
216 $mimeBoundaryString == '') {
217 $mimeBoundaryString = '----=_' . date( 'YmdHis' ) . '_' .
218 mt_rand( 10000, 99999 );
221 return $mimeBoundaryString;
224 /* Time offset for correct timezone */
225 function timezone () {
228 $diff_second = date('Z');
230 $diff_second = - $diff_second;
232 if ($diff_second > 0) {
239 $diff_second = abs($diff_second);
241 $diff_hour = floor ($diff_second / 3600);
242 $diff_minute = floor (($diff_second-3600*$diff_hour) / 60);
244 $zonename = '('.strftime('%Z').')';
245 $result = sprintf ("%s%02d%02d %s", $sign, $diff_hour, $diff_minute,
250 /* Print all the needed RFC822 headers */
251 function write822Header ($fp, $t, $c, $b, $subject, $body, $more_headers, $session, $rn="\r\n") {
252 global $REMOTE_ADDR, $SERVER_NAME, $REMOTE_PORT;
253 global $data_dir, $username, $popuser, $domain, $version, $useSendmail;
254 global $default_charset, $HTTP_VIA, $HTTP_X_FORWARDED_FOR;
255 global $REMOTE_HOST, $identity;
257 /* Storing the header to make sure the header is the same
258 * everytime the header is printed.
260 static $header, $headerlength, $headerrn;
264 $to = expandAddrs(parseAddrs($t));
265 $cc = expandAddrs(parseAddrs($c));
266 $bcc = expandAddrs(parseAddrs($b));
267 if (isset($identity) && $identity != 'default') {
268 $reply_to = getPref($data_dir, $username, 'reply_to' . $identity);
269 $from = getPref($data_dir, $username, 'full_name' . $identity);
270 $from_addr = getFrom();
272 $reply_to = getPref($data_dir, $username, 'reply_to');
273 $from = getPref($data_dir, $username, 'full_name');
274 $from_addr = getFrom();
277 $to_list = getLineOfAddrs($to);
278 $cc_list = getLineOfAddrs($cc);
279 $bcc_list = getLineOfAddrs($bcc);
281 /* Encoding 8-bit characters and making from line */
282 $subject = encodeHeader($subject);
284 $from = "<$from_addr>";
287 $from = '"' . encodeHeader($from) . "\" <$from_addr>";
290 /* This creates an RFC 822 date */
291 $date = date("D, j M Y H:i:s ", mktime()) . timezone();
293 /* Create a message-id */
294 $message_id = '<' . $REMOTE_PORT . '.' . $REMOTE_ADDR . '.';
295 $message_id .= time() . '.squirrel@' . $SERVER_NAME .'>';
297 /* Make an RFC822 Received: line */
298 if (isset($REMOTE_HOST)) {
299 $received_from = "$REMOTE_HOST ([$REMOTE_ADDR])";
302 $received_from = $REMOTE_ADDR;
305 if (isset($HTTP_VIA) ||
isset ($HTTP_X_FORWARDED_FOR)) {
306 if ($HTTP_X_FORWARDED_FOR == '') {
307 $HTTP_X_FORWARDED_FOR = 'unknown';
309 $received_from .= " (proxying for $HTTP_X_FORWARDED_FOR)";
312 $header = "Received: from $received_from" . $rn;
313 $header .= " (SquirrelMail authenticated user $username)" . $rn;
314 $header .= " by $SERVER_NAME with HTTP;" . $rn;
315 $header .= " $date" . $rn;
317 /* Insert the rest of the header fields */
318 $header .= "Message-ID: $message_id" . $rn;
319 $header .= "Date: $date" . $rn;
320 $header .= "Subject: $subject" . $rn;
321 $header .= "From: $from" . $rn;
322 $header .= "To: $to_list" . $rn; // Who it's TO
324 if (isset($more_headers["Content-Type"])) {
325 $contentType = $more_headers["Content-Type"];
326 unset($more_headers["Content-Type"]);
329 if (isMultipart($session)) {
330 $contentType = "multipart/mixed;";
333 if ($default_charset != '') {
334 $contentType = 'text/plain; charset='.$default_charset;
337 $contentType = 'text/plain;';
342 /* Insert headers from the $more_headers array */
343 if(is_array($more_headers)) {
344 reset($more_headers);
345 while(list($h_name, $h_val) = each($more_headers)) {
346 if ($h_name == 'References') {
347 $h_val = str_replace(' ', "$rn ", $h_val);
349 $header .= sprintf("%s: %s%s", $h_name, $h_val, $rn);
354 $header .= "Cc: $cc_list" . $rn; // Who the CCs are
357 if ($reply_to != '') {
358 $header .= "Reply-To: $reply_to" . $rn;
363 // BCCs is removed from header by sendmail
364 $header .= "Bcc: $bcc_list" . $rn;
368 /* Identify SquirrelMail */
369 $header .= "X-Mailer: SquirrelMail (version $version)" . $rn;
371 /* Do the MIME-stuff */
372 $header .= "MIME-Version: 1.0" . $rn;
374 if (isMultipart($session)) {
375 $header .= 'Content-Type: '.$contentType.' boundary="';
376 $header .= mimeBoundary();
379 if (strtolower($default_charset) == 'iso-2022-jp') {
380 if (mb_detect_encoding($body) == 'ASCII') {
381 $header .= 'Content-Type: text/plain; US-ASCII' . $rn;
382 $header .= "Content-Transfer-Encoding: 8bit" . $rn;
384 $header .= 'Content-Type: '.$contentType . $rn;
385 $header .= "Content-Transfer-Encoding: 7bit" . $rn;
388 $header .= 'Content-Type: ' . $contentType . $rn;
389 $header .= "Content-Transfer-Encoding: 8bit" . $rn;
392 $header .= $rn; // One blank line to separate header and body
394 $headerlength = strlen($header);
397 if ($headerrn != $rn) {
398 $header = str_replace($headerrn, $rn, $header);
399 $headerlength = strlen($header);
403 /* Write the header */
404 if ($fp) fputs ($fp, $header);
406 return $headerlength;
411 function writeBody ($fp, $passedBody, $session, $rn="\r\n") {
412 global $default_charset;
414 $attachmentlength = 0;
416 if (isMultipart($session)) {
417 $body = '--'.mimeBoundary() . $rn;
419 if ($default_charset != "") {
420 $body .= "Content-Type: text/plain; charset=$default_charset".$rn;
423 $body .= "Content-Type: text/plain" . $rn;
426 if (strtolower($default_charset) == 'iso-2022-jp') {
427 if (mb_detect_encoding($passedBody) == 'ASCII') {
428 $body .= "Content-Transfer-Encoding: 8bit" . $rn . $rn .
429 $passedBody . $rn . $rn;
431 $body .= "Content-Transfer-Encoding: 7bit\r\n\r\n" .
432 mb_convert_encoding($passedBody, 'JIS') . "\r\n\r\n";
435 $body .= "Content-Transfer-Encoding: 8bit" . $rn . $rn .
436 $passedBody . $rn . $rn;
442 $attachmentlength = attachFiles($fp, $session, $rn);
444 if (!isset($postbody)) {
447 $postbody .= $rn . "--" . mimeBoundary() . "--" . $rn . $rn;
448 if ($fp) fputs ($fp, $postbody);
450 if (strtolower($default_charset) == 'iso-2022-jp') {
451 $body = mb_convert_encoding($passedBody, 'JIS') . $rn;
453 $body = $passedBody . $rn;
460 fputs ($fp, $postbody);
464 return (strlen($body) +
strlen($postbody) +
$attachmentlength);
467 /* Send mail using the sendmail command
469 function sendSendmail($t, $c, $b, $subject, $body, $more_headers, $session) {
470 global $sendmail_path, $popuser, $username, $domain;
472 /* Build envelope sender address. Make sure it doesn't contain
473 * spaces or other "weird" chars that would allow a user to
474 * exploit the shell/pipe it is used in.
476 $envelopefrom = getFrom();
477 $envelopefrom = ereg_replace("[[:blank:]]",'', $envelopefrom);
478 $envelopefrom = ereg_replace("[[:space:]]",'', $envelopefrom);
479 $envelopefrom = ereg_replace("[[:cntrl:]]",'', $envelopefrom);
482 * open pipe to sendmail or qmail-inject
483 * (qmail-inject doesn't accept -t param)
485 if (strstr($sendmail_path, "qmail-inject")) {
486 $fp = popen (escapeshellcmd("$sendmail_path -f$envelopefrom"), "w");
488 $fp = popen (escapeshellcmd("$sendmail_path -t -f$envelopefrom"), "w");
491 $headerlength = write822Header ($fp, $t, $c, $b, $subject, $body,
492 $more_headers, $session, "\n");
493 $bodylength = writeBody($fp, $body, $session, "\n");
497 return ($headerlength +
$bodylength);
500 function smtpReadData($smtpConnection) {
501 $read = fgets($smtpConnection, 1024);
505 $data[$counter] = $read;
506 $read = fgets($smtpConnection, 1024);
511 function sendSMTP($t, $c, $b, $subject, $body, $more_headers, $session) {
512 global $username, $popuser, $domain, $version, $smtpServerAddress,
513 $smtpPort, $data_dir, $color, $use_authenticated_smtp, $identity,
516 $to = expandRcptAddrs(parseAddrs($t));
517 $cc = expandRcptAddrs(parseAddrs($c));
518 $bcc = expandRcptAddrs(parseAddrs($b));
519 if (isset($identity) && $identity != 'default') {
520 $from_addr = getPref($data_dir, $username,
521 'email_address' . $identity);
524 $from_addr = getPref($data_dir, $username, 'email_address');
528 $from_addr = "$popuser@$domain";
531 /* POP3 BEFORE SMTP CODE HERE */
532 global $pop_before_smtp;
533 if (isset($pop_before_smtp) && $pop_before_smtp === true) {
534 if (!isset($pop_port)) {
537 if (!isset($pop_server)) {
538 $pop_server = $smtpServerAddress; /* usually the same host! */
540 $popConnection = fsockopen($pop_server, $pop_port, $err_no, $err_str);
541 if (!$popConnection) {
542 error_log("Error connecting to POP Server ($pop_server:$pop_port)"
543 . " $err_no : $err_str");
545 $tmp = fgets($popConnection, 1024); /* banner */
546 if (!eregi("^\+OK", $tmp, $regs)) {
549 fputs($popConnection, "USER $username\r\n");
550 $tmp = fgets($popConnection, 1024);
551 if (!eregi("^\+OK", $tmp, $regs)) {
554 fputs($popConnection, 'PASS ' . OneTimePadDecrypt($key, $onetimepad) . "\r\n");
555 $tmp = fgets($popConnection, 1024);
556 if (!eregi("^\+OK", $tmp, $regs)) {
559 fputs($popConnection, "QUIT\r\n"); /* log off */
560 fclose($popConnection);
564 $smtpConnection = fsockopen($smtpServerAddress, $smtpPort,
565 $errorNumber, $errorString);
566 if (!$smtpConnection) {
567 echo 'Error connecting to SMTP Server.<br>';
568 echo "$errorNumber : $errorString<br>";
571 $tmp = fgets($smtpConnection, 1024);
572 if (errorCheck($tmp, $smtpConnection)!=5) {
576 $to_list = getLineOfAddrs($to);
577 $cc_list = getLineOfAddrs($cc);
579 /* Lets introduce ourselves */
580 if (! isset ($use_authenticated_smtp)
581 ||
$use_authenticated_smtp == false) {
582 fputs($smtpConnection, "HELO $domain\r\n");
583 $tmp = fgets($smtpConnection, 1024);
584 if (errorCheck($tmp, $smtpConnection)!=5) return(0);
586 fputs($smtpConnection, "EHLO $domain\r\n");
587 $tmp = fgets($smtpConnection, 1024);
588 if (errorCheck($tmp, $smtpConnection)!=5) return(0);
590 fputs($smtpConnection, "AUTH LOGIN\r\n");
591 $tmp = fgets($smtpConnection, 1024);
592 if (errorCheck($tmp, $smtpConnection)!=5) {
596 fputs($smtpConnection, base64_encode ($username) . "\r\n");
597 $tmp = fgets($smtpConnection, 1024);
598 if (errorCheck($tmp, $smtpConnection)!=5) {
602 fputs($smtpConnection, base64_encode
603 (OneTimePadDecrypt($key, $onetimepad)) . "\r\n");
604 $tmp = fgets($smtpConnection, 1024);
605 if (errorCheck($tmp, $smtpConnection)!=5) {
610 /* Ok, who is sending the message? */
611 fputs($smtpConnection, "MAIL FROM: <$from_addr>\r\n");
612 $tmp = fgets($smtpConnection, 1024);
613 if (errorCheck($tmp, $smtpConnection)!=5) {
617 /* send who the recipients are */
618 for ($i = 0; $i < count($to); $i++
) {
619 fputs($smtpConnection, "RCPT TO: $to[$i]\r\n");
620 $tmp = fgets($smtpConnection, 1024);
621 if (errorCheck($tmp, $smtpConnection)!=5) {
625 for ($i = 0; $i < count($cc); $i++
) {
626 fputs($smtpConnection, "RCPT TO: $cc[$i]\r\n");
627 $tmp = fgets($smtpConnection, 1024);
628 if (errorCheck($tmp, $smtpConnection)!=5) {
632 for ($i = 0; $i < count($bcc); $i++
) {
633 fputs($smtpConnection, "RCPT TO: $bcc[$i]\r\n");
634 $tmp = fgets($smtpConnection, 1024);
635 if (errorCheck($tmp, $smtpConnection)!=5) {
640 /* Lets start sending the actual message */
641 fputs($smtpConnection, "DATA\r\n");
642 $tmp = fgets($smtpConnection, 1024);
643 if (errorCheck($tmp, $smtpConnection)!=5) {
647 /* Send the message */
648 $headerlength = write822Header ($smtpConnection, $t, $c, $b,
649 $subject, $body, $more_headers, $session);
650 $bodylength = writeBody($smtpConnection, $body, $session);
652 fputs($smtpConnection, ".\r\n"); /* end the DATA part */
653 $tmp = fgets($smtpConnection, 1024);
654 $num = errorCheck($tmp, $smtpConnection, true);
659 fputs($smtpConnection, "QUIT\r\n"); /* log off */
661 fclose($smtpConnection);
663 return ($headerlength +
$bodylength);
667 function errorCheck($line, $smtpConnection, $verbose = false) {
668 global $color, $compose_new_win;
670 /* Read new lines on a multiline response */
672 while(ereg("^[0-9]+-", $line)) {
673 $line = fgets($smtpConnection, 1024);
680 $err_num = substr($line, 0, strpos($line, " "));
682 case 500: $message = 'Syntax error; command not recognized';
685 case 501: $message = 'Syntax error in parameters or arguments';
688 case 502: $message = 'Command not implemented';
691 case 503: $message = 'Bad sequence of commands';
694 case 504: $message = 'Command parameter not implemented';
698 case 211: $message = 'System status, or system help reply';
701 case 214: $message = 'Help message';
705 case 220: $message = 'Service ready';
708 case 221: $message = 'Service closing transmission channel';
712 case 421: $message = 'Service not available, closing chanel';
718 case 250: $message = 'Requested mail action okay, completed';
721 case 251: $message = 'User not local; will forward';
724 case 334: return(5); break;
725 case 450: $message = 'Requested mail action not taken: mailbox unavailable';
728 case 550: $message = 'Requested action not taken: mailbox unavailable';
731 case 451: $message = 'Requested action aborted: error in processing';
734 case 551: $message = 'User not local; please try forwarding';
737 case 452: $message = 'Requested action not taken: insufficient system storage';
740 case 552: $message = 'Requested mail action aborted: exceeding storage allocation';
743 case 553: $message = 'Requested action not taken: mailbox name not allowed';
746 case 354: $message = 'Start mail input; end with .';
749 case 554: $message = 'Transaction failed';
752 default: $message = 'Unknown response: '. nl2br(htmlspecialchars($lines));
759 include_once('../functions/page_header.php');
760 if ($compose_new_win == '1') {
761 compose_Header($color, 'None');
764 displayPageHeader($color, 'None');
766 include_once('../functions/display_messages.php');
767 $lines = nl2br(htmlspecialchars($lines));
768 $msg = $message . "<br>\nServer replied: $lines";
769 plain_error_message($msg, $color);
771 if (! $verbose) return $status;
775 /* create new reference header per rfc2822 */
777 function calculate_references($refs, $inreplyto, $old_reply_to) {
780 for ($i=1;$i<count($refs[0]);$i++
) {
781 if (!empty($refs[0][$i])) {
782 if (preg_match("/^References:(.+)$/UA", $refs[0][$i], $regs)) {
783 $refer = trim($regs[1]);
786 $refer .= ' ' . trim($refs[0][$i]);
791 $refer_a = explode(' ', $refer);
793 foreach ($refer_a as $ref) {
795 if ($ref{0} == '<' && $ref{(strlen($ref)-1)} == '>') {
796 $refer .= $ref . ' ';
799 $refer = trim($refer);
800 if (strlen($refer) > 2) {
801 $refer .= ' ' . $inreplyto;
804 if (!empty($old_reply_to)) {
805 $refer .= $old_reply_to . ' ' . $inreplyto;
808 $refer .= $inreplyto;
815 function sendMessage($t, $c, $b, $subject, $body, $reply_id, $MDN,
816 $prio = 3, $session) {
817 global $useSendmail, $msg_id, $is_reply, $mailbox, $onetimepad,
818 $data_dir, $username, $domain, $key, $version, $sent_folder,
819 $imapServerAddress, $imapPort, $default_use_priority, $more_headers,
820 $request_mdn, $request_dr, $uid_support;
822 $more_headers = Array();
824 do_hook('smtp_send');
826 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
829 if (isset($reply_id) && $reply_id) {
830 sqimap_mailbox_select ($imap_stream, $mailbox);
831 sqimap_messages_flag ($imap_stream, $reply_id, $reply_id, 'Answered', false);
833 /* Insert In-Reply-To and References headers if the
834 * message-id of the message we reply to is set (longer than "<>")
835 * The References header should really be the old Referenced header
836 * with the message ID appended, and now it is (jmunro)
838 $sid = sqimap_session_id($uid_support);
839 $query = "$sid FETCH $reply_id (BODY.PEEK[HEADER.FIELDS (Message-Id In-Reply-To)])\r\n";
840 fputs ($imap_stream, $query);
841 $read = sqimap_read_data($imap_stream, $sid, true, $response, $message);
845 foreach ($read as $r) {
846 if (preg_match("/^message-id:(.*)/iA", $r, $regs)) {
847 $message_id = trim($regs[1]);
849 if (preg_match("/^in-reply-to:(.*)/iA", $r, $regs)) {
850 $in_reply_to = trim($regs[1]);
854 if(strlen($message_id) > 2) {
855 $refs = get_reference_header ($imap_stream, $reply_id);
856 $inreplyto = $message_id;
857 $old_reply_to = $in_reply_to;
858 $refer = calculate_references ($refs, $inreplyto, $old_reply_to);
859 $more_headers['In-Reply-To'] = $inreplyto;
860 $more_headers['References'] = $refer;
864 if ($default_use_priority) {
865 $more_headers = array_merge($more_headers, createPriorityHeaders($prio));
869 if (isset($request_dr)) {
872 if (isset($request_mdn)) {
875 if ( $requestRecipt > 0) {
876 $more_headers = array_merge($more_headers, createReceiptHeaders($requestRecipt));
879 /* In order to remove the problem of users not able to create
880 * messages with "." on a blank line, RFC821 has made provision
881 * in section 4.5.2 (Transparency).
883 $body = ereg_replace("\n\\.", "\n..", $body);
884 $body = ereg_replace("^\\.", "..", $body);
886 /* this is to catch all plain \n instances and
887 * replace them with \r\n. All newlines were converted
888 * into just \n inside the compose.php file.
889 * But only if delimiter is, in fact, \r\n.
893 $more_headers["Content-Type"] = "multipart/report; ".
894 "report-type=disposition-notification;";
898 $length = sendSendmail($t, $c, $b, $subject, $body, $more_headers,
900 $body = ereg_replace("\n", "\r\n", $body);
902 $body = ereg_replace("\n", "\r\n", $body);
903 $length = sendSMTP($t, $c, $b, $subject, $body, $more_headers,
906 if (sqimap_mailbox_exists ($imap_stream, $sent_folder)) {
907 $headerlength = write822Header (FALSE, $t, $c, $b, $subject, $more_headers, $session, "\r\n");
908 $bodylength = writeBody(FALSE, $body, $session, "\r\n");
909 $length = $headerlength +
$bodylength;
911 sqimap_append ($imap_stream, $sent_folder, $length);
912 write822Header ($imap_stream, $t, $c, $b, $subject, $body, $more_headers,
914 writeBody ($imap_stream, $body, $session);
915 sqimap_append_done ($imap_stream);
917 sqimap_logout($imap_stream);
918 /* Delete the files uploaded for attaching (if any).
919 * only if $length != 0 (if there was no error)
922 ClearAttachments($session);
928 function createPriorityHeaders($prio) {
929 $prio_headers = Array();
930 $prio_headers['X-Priority'] = $prio;
933 case 1: $prio_headers['Importance'] = 'High';
934 $prio_headers['X-MSMail-Priority'] = 'High';
937 case 3: $prio_headers['Importance'] = 'Normal';
938 $prio_headers['X-MSMail-Priority'] = 'Normal';
942 $prio_headers['Importance'] = 'Low';
943 $prio_headers['X-MSMail-Priority'] = 'Low';
946 return $prio_headers;
949 function createReceiptHeaders($receipt) {
951 GLOBAL $data_dir, $username, $identity, $popuser, $domain;
953 $receipt_headers = Array();
954 if (isset($identity) && $identity != 'default') {
955 $from = getPref($data_dir, $username, 'full_name' . $identity);
956 $from_addr = getPref($data_dir, $username, 'email_address' . $identity);
958 $from = getPref($data_dir, $username, 'full_name');
959 $from_addr = getPref($data_dir, $username, 'email_address');
961 if ($from_addr == '') {
962 $from_addr = $popuser.'@'.$domain;
966 $from = "<$from_addr>";
969 $from = '"' . encodeHeader($from) . "\" <$from_addr>";
975 $receipt_headers["Return-Receipt-To"] = $from;
981 $receipt_headers["X-Confirm-Reading-To"] = $from;
983 $receipt_headers["Disposition-Notification-To"] = $from;
985 return $receipt_headers;
988 /* Figure out what the 'From:' address is
992 global $username, $popuser, $domain, $data_dir, $identity;
993 if (isset($identity) && $identity != 'default') {
994 $from_addr = getPref($data_dir, $username,
995 'email_address' . $identity);
998 $from_addr = getPref($data_dir, $username, 'email_address');
1002 $from_addr = "$popuser@$domain";