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 $info['remotefilename'] . "\"$rn";
134 $header .= "Content-Disposition: attachment; filename=\""
135 . $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/' ) {
151 if ($fp) fputs ($fp, $header);
152 $length +
= strlen($header);
153 while ($tmp = fgets($file, 4096)) {
154 $tmp = str_replace("\r\n", "\n", $tmp);
155 $tmp = str_replace("\r", "\n", $tmp);
157 $tmp = str_replace("\n", "\r\n", $tmp);
160 * Check if the last line has newline ($rn) in it
161 * and append if it doesn't.
163 if (feof($fp) && !strstr($tmp, "$rn")){
166 if ($fp) fputs($fp, $tmp);
167 $length +
= strlen($tmp);
170 $header .= "Content-Transfer-Encoding: base64"
172 if ($fp) fputs ($fp, $header);
173 $length +
= strlen($header);
174 while ($tmp = fread($file, 570)) {
175 $encoded = chunk_split(base64_encode($tmp));
176 $length +
= strlen($encoded);
177 if ($fp) fputs ($fp, $encoded);
187 /* Delete files that are uploaded for attaching
189 function deleteAttachments($session) {
190 global $username, $attachments, $attachment_dir;
191 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
193 $rem_attachments = array();
194 foreach ($attachments as $info) {
195 if ($info['session'] == $session) {
196 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
197 if (file_exists($attached_file)) {
198 unlink($attached_file);
201 $rem_attachments[] = $info;
204 $attachments = $rem_attachments;
207 /* Return a nice MIME-boundary
209 function mimeBoundary () {
210 static $mimeBoundaryString;
212 if ( !isset( $mimeBoundaryString ) ||
213 $mimeBoundaryString == '') {
214 $mimeBoundaryString = '----=_' . date( 'YmdHis' ) . '_' .
215 mt_rand( 10000, 99999 );
218 return $mimeBoundaryString;
221 /* Time offset for correct timezone */
222 function timezone () {
225 $diff_second = date('Z');
227 $diff_second = - $diff_second;
229 if ($diff_second > 0) {
236 $diff_second = abs($diff_second);
238 $diff_hour = floor ($diff_second / 3600);
239 $diff_minute = floor (($diff_second-3600*$diff_hour) / 60);
241 $zonename = '('.strftime('%Z').')';
242 $result = sprintf ("%s%02d%02d %s", $sign, $diff_hour, $diff_minute,
247 /* Print all the needed RFC822 headers */
248 function write822Header ($fp, $t, $c, $b, $subject, $more_headers, $session, $rn="\r\n") {
249 global $REMOTE_ADDR, $SERVER_NAME, $REMOTE_PORT;
250 global $data_dir, $username, $popuser, $domain, $version, $useSendmail;
251 global $default_charset, $HTTP_VIA, $HTTP_X_FORWARDED_FOR;
252 global $REMOTE_HOST, $identity;
254 /* Storing the header to make sure the header is the same
255 * everytime the header is printed.
257 static $header, $headerlength, $headerrn;
261 $to = expandAddrs(parseAddrs($t));
262 $cc = expandAddrs(parseAddrs($c));
263 $bcc = expandAddrs(parseAddrs($b));
264 if (isset($identity) && $identity != 'default') {
265 $reply_to = getPref($data_dir, $username, 'reply_to' . $identity);
266 $from = getPref($data_dir, $username, 'full_name' . $identity);
267 $from_addr = getFrom();
269 $reply_to = getPref($data_dir, $username, 'reply_to');
270 $from = getPref($data_dir, $username, 'full_name');
271 $from_addr = getFrom();
274 $to_list = getLineOfAddrs($to);
275 $cc_list = getLineOfAddrs($cc);
276 $bcc_list = getLineOfAddrs($bcc);
278 /* Encoding 8-bit characters and making from line */
279 $subject = encodeHeader($subject);
281 $from = "<$from_addr>";
284 $from = '"' . encodeHeader($from) . "\" <$from_addr>";
287 /* This creates an RFC 822 date */
288 $date = date("D, j M Y H:i:s ", mktime()) . timezone();
290 /* Create a message-id */
291 $message_id = '<' . $REMOTE_PORT . '.' . $REMOTE_ADDR . '.';
292 $message_id .= time() . '.squirrel@' . $SERVER_NAME .'>';
294 /* Make an RFC822 Received: line */
295 if (isset($REMOTE_HOST)) {
296 $received_from = "$REMOTE_HOST ([$REMOTE_ADDR])";
299 $received_from = $REMOTE_ADDR;
302 if (isset($HTTP_VIA) ||
isset ($HTTP_X_FORWARDED_FOR)) {
303 if ($HTTP_X_FORWARDED_FOR == '') {
304 $HTTP_X_FORWARDED_FOR = 'unknown';
306 $received_from .= " (proxying for $HTTP_X_FORWARDED_FOR)";
309 $header = "Received: from $received_from" . $rn;
310 $header .= " (SquirrelMail authenticated user $username)" . $rn;
311 $header .= " by $SERVER_NAME with HTTP;" . $rn;
312 $header .= " $date" . $rn;
314 /* Insert the rest of the header fields */
315 $header .= "Message-ID: $message_id" . $rn;
316 $header .= "Date: $date" . $rn;
317 $header .= "Subject: $subject" . $rn;
318 $header .= "From: $from" . $rn;
319 $header .= "To: $to_list" . $rn; // Who it's TO
321 if (isset($more_headers["Content-Type"])) {
322 $contentType = $more_headers["Content-Type"];
323 unset($more_headers["Content-Type"]);
326 if (isMultipart($session)) {
327 $contentType = "multipart/mixed;";
330 if ($default_charset != '') {
331 $contentType = 'text/plain; charset='.$default_charset;
334 $contentType = 'text/plain;';
339 /* Insert headers from the $more_headers array */
340 if(is_array($more_headers)) {
341 reset($more_headers);
342 while(list($h_name, $h_val) = each($more_headers)) {
343 if ($h_name == 'References') {
344 $h_val = str_replace(' ', "$rn ", $h_val);
346 $header .= sprintf("%s: %s%s", $h_name, $h_val, $rn);
351 $header .= "Cc: $cc_list" . $rn; // Who the CCs are
354 if ($reply_to != '') {
355 $header .= "Reply-To: $reply_to" . $rn;
360 // BCCs is removed from header by sendmail
361 $header .= "Bcc: $bcc_list" . $rn;
365 /* Identify SquirrelMail */
366 $header .= "X-Mailer: SquirrelMail (version $version)" . $rn;
368 /* Do the MIME-stuff */
369 $header .= "MIME-Version: 1.0" . $rn;
371 if (isMultipart($session)) {
372 $header .= 'Content-Type: '.$contentType.' boundary="';
373 $header .= mimeBoundary();
376 $header .= 'Content-Type: ' . $contentType . $rn;
377 $header .= "Content-Transfer-Encoding: 8bit" . $rn;
379 $header .= $rn; // One blank line to separate header and body
381 $headerlength = strlen($header);
384 if ($headerrn != $rn) {
385 $header = str_replace($headerrn, $rn, $header);
386 $headerlength = strlen($header);
390 /* Write the header */
391 if ($fp) fputs ($fp, $header);
393 return $headerlength;
398 function writeBody ($fp, $passedBody, $session, $rn="\r\n") {
399 global $default_charset;
401 $attachmentlength = 0;
403 if (isMultipart($session)) {
404 $body = '--'.mimeBoundary() . $rn;
406 if ($default_charset != "") {
407 $body .= "Content-Type: text/plain; charset=$default_charset".$rn;
410 $body .= "Content-Type: text/plain" . $rn;
413 $body .= "Content-Transfer-Encoding: 8bit" . $rn . $rn;
414 $body .= $passedBody . $rn . $rn;
415 if ($fp) fputs ($fp, $body);
417 $attachmentlength = attachFiles($fp, $session, $rn);
419 if (!isset($postbody)) {
422 $postbody .= $rn . "--" . mimeBoundary() . "--" . $rn . $rn;
423 if ($fp) fputs ($fp, $postbody);
425 $body = $passedBody . $rn;
426 if ($fp) fputs ($fp, $body);
428 if ($fp) fputs ($fp, $postbody);
431 return (strlen($body) +
strlen($postbody) +
$attachmentlength);
434 /* Send mail using the sendmail command
436 function sendSendmail($t, $c, $b, $subject, $body, $more_headers, $session) {
437 global $sendmail_path, $popuser, $username, $domain;
439 /* Build envelope sender address. Make sure it doesn't contain
440 * spaces or other "weird" chars that would allow a user to
441 * exploit the shell/pipe it is used in.
443 $envelopefrom = getFrom();
444 $envelopefrom = ereg_replace("[[:blank:]]",'', $envelopefrom);
445 $envelopefrom = ereg_replace("[[:space:]]",'', $envelopefrom);
446 $envelopefrom = ereg_replace("[[:cntrl:]]",'', $envelopefrom);
449 * open pipe to sendmail or qmail-inject
450 * (qmail-inject doesn't accept -t param)
452 if (strstr($sendmail_path, "qmail-inject")) {
453 $fp = popen (escapeshellcmd("$sendmail_path -f$envelopefrom"), "w");
455 $fp = popen (escapeshellcmd("$sendmail_path -t -f$envelopefrom"), "w");
458 $headerlength = write822Header ($fp, $t, $c, $b, $subject,
459 $more_headers, $session, "\n");
460 $bodylength = writeBody($fp, $body, $session, "\n");
464 return ($headerlength +
$bodylength);
467 function smtpReadData($smtpConnection) {
468 $read = fgets($smtpConnection, 1024);
472 $data[$counter] = $read;
473 $read = fgets($smtpConnection, 1024);
478 function sendSMTP($t, $c, $b, $subject, $body, $more_headers, $session) {
479 global $username, $popuser, $domain, $version, $smtpServerAddress,
480 $smtpPort, $data_dir, $color, $use_authenticated_smtp, $identity,
483 $to = expandRcptAddrs(parseAddrs($t));
484 $cc = expandRcptAddrs(parseAddrs($c));
485 $bcc = expandRcptAddrs(parseAddrs($b));
486 if (isset($identity) && $identity != 'default') {
487 $from_addr = getPref($data_dir, $username,
488 'email_address' . $identity);
491 $from_addr = getPref($data_dir, $username, 'email_address');
495 $from_addr = "$popuser@$domain";
498 /* POP3 BEFORE SMTP CODE HERE */
499 global $pop_before_smtp;
500 if (isset($pop_before_smtp) && $pop_before_smtp === true) {
501 if (!isset($pop_port)) {
504 if (!isset($pop_server)) {
505 $pop_server = $smtpServerAddress; /* usually the same host! */
507 $popConnection = fsockopen($pop_server, $pop_port, $err_no, $err_str);
508 if (!$popConnection) {
509 error_log("Error connecting to POP Server ($pop_server:$pop_port)"
510 . " $err_no : $err_str");
512 $tmp = fgets($popConnection, 1024); /* banner */
513 if (!eregi("^\+OK", $tmp, $regs)) {
516 fputs($popConnection, "USER $username\r\n");
517 $tmp = fgets($popConnection, 1024);
518 if (!eregi("^\+OK", $tmp, $regs)) {
521 fputs($popConnection, 'PASS ' . OneTimePadDecrypt($key, $onetimepad) . "\r\n");
522 $tmp = fgets($popConnection, 1024);
523 if (!eregi("^\+OK", $tmp, $regs)) {
526 fputs($popConnection, "QUIT\r\n"); /* log off */
527 fclose($popConnection);
531 $smtpConnection = fsockopen($smtpServerAddress, $smtpPort,
532 $errorNumber, $errorString);
533 if (!$smtpConnection) {
534 echo 'Error connecting to SMTP Server.<br>';
535 echo "$errorNumber : $errorString<br>";
538 $tmp = fgets($smtpConnection, 1024);
539 if (errorCheck($tmp, $smtpConnection)!=5) {
543 $to_list = getLineOfAddrs($to);
544 $cc_list = getLineOfAddrs($cc);
546 /* Lets introduce ourselves */
547 if (! isset ($use_authenticated_smtp)
548 ||
$use_authenticated_smtp == false) {
549 fputs($smtpConnection, "HELO $domain\r\n");
550 $tmp = fgets($smtpConnection, 1024);
551 if (errorCheck($tmp, $smtpConnection)!=5) return(0);
553 fputs($smtpConnection, "EHLO $domain\r\n");
554 $tmp = fgets($smtpConnection, 1024);
555 if (errorCheck($tmp, $smtpConnection)!=5) return(0);
557 fputs($smtpConnection, "AUTH LOGIN\r\n");
558 $tmp = fgets($smtpConnection, 1024);
559 if (errorCheck($tmp, $smtpConnection)!=5) {
563 fputs($smtpConnection, base64_encode ($username) . "\r\n");
564 $tmp = fgets($smtpConnection, 1024);
565 if (errorCheck($tmp, $smtpConnection)!=5) {
569 fputs($smtpConnection, base64_encode
570 (OneTimePadDecrypt($key, $onetimepad)) . "\r\n");
571 $tmp = fgets($smtpConnection, 1024);
572 if (errorCheck($tmp, $smtpConnection)!=5) {
577 /* Ok, who is sending the message? */
578 fputs($smtpConnection, "MAIL FROM: <$from_addr>\r\n");
579 $tmp = fgets($smtpConnection, 1024);
580 if (errorCheck($tmp, $smtpConnection)!=5) {
584 /* send who the recipients are */
585 for ($i = 0; $i < count($to); $i++
) {
586 fputs($smtpConnection, "RCPT TO: $to[$i]\r\n");
587 $tmp = fgets($smtpConnection, 1024);
588 if (errorCheck($tmp, $smtpConnection)!=5) {
592 for ($i = 0; $i < count($cc); $i++
) {
593 fputs($smtpConnection, "RCPT TO: $cc[$i]\r\n");
594 $tmp = fgets($smtpConnection, 1024);
595 if (errorCheck($tmp, $smtpConnection)!=5) {
599 for ($i = 0; $i < count($bcc); $i++
) {
600 fputs($smtpConnection, "RCPT TO: $bcc[$i]\r\n");
601 $tmp = fgets($smtpConnection, 1024);
602 if (errorCheck($tmp, $smtpConnection)!=5) {
607 /* Lets start sending the actual message */
608 fputs($smtpConnection, "DATA\r\n");
609 $tmp = fgets($smtpConnection, 1024);
610 if (errorCheck($tmp, $smtpConnection)!=5) {
614 /* Send the message */
615 $headerlength = write822Header ($smtpConnection, $t, $c, $b,
616 $subject, $more_headers, $session);
617 $bodylength = writeBody($smtpConnection, $body, $session);
619 fputs($smtpConnection, ".\r\n"); /* end the DATA part */
620 $tmp = fgets($smtpConnection, 1024);
621 $num = errorCheck($tmp, $smtpConnection, true);
626 fputs($smtpConnection, "QUIT\r\n"); /* log off */
628 fclose($smtpConnection);
630 return ($headerlength +
$bodylength);
634 function errorCheck($line, $smtpConnection, $verbose = false) {
635 global $color, $compose_new_win;
637 /* Read new lines on a multiline response */
639 while(ereg("^[0-9]+-", $line)) {
640 $line = fgets($smtpConnection, 1024);
647 $err_num = substr($line, 0, strpos($line, " "));
649 case 500: $message = 'Syntax error; command not recognized';
652 case 501: $message = 'Syntax error in parameters or arguments';
655 case 502: $message = 'Command not implemented';
658 case 503: $message = 'Bad sequence of commands';
661 case 504: $message = 'Command parameter not implemented';
665 case 211: $message = 'System status, or system help reply';
668 case 214: $message = 'Help message';
672 case 220: $message = 'Service ready';
675 case 221: $message = 'Service closing transmission channel';
679 case 421: $message = 'Service not available, closing chanel';
685 case 250: $message = 'Requested mail action okay, completed';
688 case 251: $message = 'User not local; will forward';
691 case 334: return(5); break;
692 case 450: $message = 'Requested mail action not taken: mailbox unavailable';
695 case 550: $message = 'Requested action not taken: mailbox unavailable';
698 case 451: $message = 'Requested action aborted: error in processing';
701 case 551: $message = 'User not local; please try forwarding';
704 case 452: $message = 'Requested action not taken: insufficient system storage';
707 case 552: $message = 'Requested mail action aborted: exceeding storage allocation';
710 case 553: $message = 'Requested action not taken: mailbox name not allowed';
713 case 354: $message = 'Start mail input; end with .';
716 case 554: $message = 'Transaction failed';
719 default: $message = 'Unknown response: '. nl2br(htmlspecialchars($lines));
726 include_once('../functions/page_header.php');
727 if ($compose_new_win == '1') {
728 compose_Header($color, 'None');
731 displayPageHeader($color, 'None');
733 include_once('../functions/display_messages.php');
734 $lines = nl2br(htmlspecialchars($lines));
735 $msg = $message . "<br>\nServer replied: $lines";
736 plain_error_message($msg, $color);
738 if (! $verbose) return $status;
742 /* create new reference header per rfc2822 */
744 function calculate_references($refs, $inreplyto, $old_reply_to) {
747 for ($i=1;$i<count($refs[0]);$i++
) {
748 if (!empty($refs[0][$i])) {
749 if (preg_match("/^References:(.+)$/", $refs[0][$i], $regs)) {
750 $refer = trim($regs[1]);
753 $refer .= ' ' . trim($refs[0][$i]);
757 $refer = trim($refer);
758 if (strlen($refer) > 2) {
759 $refer .= ' ' . $inreplyto;
762 if (!empty($old_reply_to)) {
763 $refer .= $old_reply_to . ' ' . $inreplyto;
766 $refer .= $inreplyto;
773 function sendMessage($t, $c, $b, $subject, $body, $reply_id, $MDN,
774 $prio = 3, $session) {
775 global $useSendmail, $msg_id, $is_reply, $mailbox, $onetimepad,
776 $data_dir, $username, $domain, $key, $version, $sent_folder,
777 $imapServerAddress, $imapPort, $default_use_priority, $more_headers,
778 $request_mdn, $request_dr;
780 $more_headers = Array();
782 do_hook('smtp_send');
784 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
787 if (isset($reply_id) && $reply_id) {
788 sqimap_mailbox_select ($imap_stream, $mailbox);
789 sqimap_messages_flag ($imap_stream, $reply_id, $reply_id, 'Answered');
791 /* Insert In-Reply-To and References headers if the
792 * message-id of the message we reply to is set (longer than "<>")
793 * The References header should really be the old Referenced header
794 * with the message ID appended, and now it is (jmunro)
796 $sid = sqimap_session_id();
797 $query = "$sid FETCH $reply_id (BODY.PEEK[HEADER.FIELDS (Message-Id In-Reply-To)])\r\n";
798 fputs ($imap_stream, $query);
799 $read = sqimap_read_data($imap_stream, $sid, true, $response, $message);
803 foreach ($read as $r) {
804 if (preg_match("/^message-id:(.*)/iA", $r, $regs)) {
805 $message_id = trim($regs[1]);
807 if (preg_match("/^in-reply-to:(.*)/iA", $r, $regs)) {
808 $in_reply_to = trim($regs[1]);
812 if(strlen($message_id) > 2) {
813 $refs = get_reference_header ($imap_stream, $reply_id);
814 $inreplyto = $message_id;
815 $old_reply_to = $in_reply_to;
816 $refer = calculate_references ($refs, $inreplyto, $old_reply_to);
817 $more_headers['In-Reply-To'] = $inreplyto;
818 $more_headers['References'] = $refer;
822 if ($default_use_priority) {
823 $more_headers = array_merge($more_headers, createPriorityHeaders($prio));
827 if (isset($request_dr)) {
830 if (isset($request_mdn)) {
833 if ( $requestRecipt > 0) {
834 $more_headers = array_merge($more_headers, createReceiptHeaders($requestRecipt));
837 /* In order to remove the problem of users not able to create
838 * messages with "." on a blank line, RFC821 has made provision
839 * in section 4.5.2 (Transparency).
841 $body = ereg_replace("\n\\.", "\n..", $body);
842 $body = ereg_replace("^\\.", "..", $body);
844 /* this is to catch all plain \n instances and
845 * replace them with \r\n. All newlines were converted
846 * into just \n inside the compose.php file.
847 * But only if delimiter is, in fact, \r\n.
851 $more_headers["Content-Type"] = "multipart/report; ".
852 "report-type=disposition-notification;";
856 $length = sendSendmail($t, $c, $b, $subject, $body, $more_headers,
858 $body = ereg_replace("\n", "\r\n", $body);
860 $body = ereg_replace("\n", "\r\n", $body);
861 $length = sendSMTP($t, $c, $b, $subject, $body, $more_headers,
864 if (sqimap_mailbox_exists ($imap_stream, $sent_folder)) {
865 $headerlength = write822Header (FALSE, $t, $c, $b, $subject, $more_headers, $session, "\r\n");
866 $bodylength = writeBody(FALSE, $body, $session, "\r\n");
867 $length = $headerlength +
$bodylength;
869 sqimap_append ($imap_stream, $sent_folder, $length);
870 write822Header ($imap_stream, $t, $c, $b, $subject, $more_headers,
872 writeBody ($imap_stream, $body, $session);
873 sqimap_append_done ($imap_stream);
875 sqimap_logout($imap_stream);
876 /* Delete the files uploaded for attaching (if any).
877 * only if $length != 0 (if there was no error)
880 ClearAttachments($session);
886 function createPriorityHeaders($prio) {
887 $prio_headers = Array();
888 $prio_headers['X-Priority'] = $prio;
891 case 1: $prio_headers['Importance'] = 'High';
892 $prio_headers['X-MSMail-Priority'] = 'High';
895 case 3: $prio_headers['Importance'] = 'Normal';
896 $prio_headers['X-MSMail-Priority'] = 'Normal';
900 $prio_headers['Importance'] = 'Low';
901 $prio_headers['X-MSMail-Priority'] = 'Low';
904 return $prio_headers;
907 function createReceiptHeaders($receipt) {
909 GLOBAL $data_dir, $username, $identity, $popuser, $domain;
911 $receipt_headers = Array();
912 if (isset($identity) && $identity != 'default') {
913 $from = getPref($data_dir, $username, 'full_name' . $identity);
914 $from_addr = getPref($data_dir, $username, 'email_address' . $identity);
916 $from = getPref($data_dir, $username, 'full_name');
917 $from_addr = getPref($data_dir, $username, 'email_address');
919 if ($from_addr == '') {
920 $from_addr = $popuser.'@'.$domain;
924 $from = "<$from_addr>";
927 $from = '"' . encodeHeader($from) . "\" <$from_addr>";
933 $receipt_headers["Return-Receipt-To"] = $from;
939 $receipt_headers["X-Confirm-Reading-To"] = $from;
941 $receipt_headers["Disposition-Notification-To"] = $from;
943 return $receipt_headers;
946 /* Figure out what the 'From:' address is
950 global $username, $popuser, $domain, $data_dir, $identity;
951 if (isset($identity) && $identity != 'default') {
952 $from_addr = getPref($data_dir, $username,
953 'email_address' . $identity);
956 $from_addr = getPref($data_dir, $username, 'email_address');
960 $from_addr = "$popuser@$domain";