+ global $default_charset;
+
+ // Storing the header to make sure the header is the same
+ // everytime the header is printed.
+ static $header, $headerlength;
+
+ if ($header == "") {
+ $to = parseAddrs($t);
+ $cc = parseAddrs($c);
+ $bcc = parseAddrs($b);
+ $reply_to = getPref($data_dir, $username, "reply_to");
+ $from = getPref($data_dir, $username, "full_name");
+ $from_addr = getPref($data_dir, $username, "email_address");
+
+ if ($from_addr == "")
+ $from_addr = "$username@$domain";
+
+ $to_list = getLineOfAddrs($to);
+ $cc_list = getLineOfAddrs($cc);
+ $bcc_list = getLineOfAddrs($bcc);
+
+ if ($from == "")
+ $from = "<$from_addr>";
+ else
+ $from = $from . " <$from_addr>";
+
+ /* Encoding 8-bit characters */
+ $subject = encodeHeader($subject);
+ $from = encodeHeader($from);
+
+ /* This creates an RFC 822 date */
+ $date = date("D, j M Y H:i:s ", mktime()) . timezone();
+
+ /* Create a message-id */
+ $message_id = "<" . $REMOTE_PORT . "." . $REMOTE_ADDR . ".";
+ $message_id .= time() . "@" . $SERVER_NAME .">";
+
+ /* Make an RFC822 Received: line */
+ $header = "Received: from $REMOTE_ADDR by $SERVER_NAME with HTTP; ";
+ $header .= "$date\r\n";
+
+ /* Insert the rest of the header fields */
+ $header .= "Message-ID: $message_id\r\n";
+ $header .= "Date: $date\r\n";
+ $header .= "Subject: $subject\r\n";
+ $header .= "From: $from\r\n";
+ $header .= "To: $to_list \r\n"; // Who it's TO
+
+ if ($cc_list) {
+ $header .= "Cc: $cc_list\r\n"; // Who the CCs are
+ }
+
+ if ($reply_to != "")
+ $header .= "Reply-To: $reply_to\r\n";
+
+ if ($useSendmail) {
+ if ($bcc_list) {
+ // BCCs is removed from header by sendmail
+ $header .= "Bcc: $bcc_list\r\n";
+ }
+ }
+
+ $header .= "X-Mailer: SquirrelMail (version $version)\r\n"; // Identify SquirrelMail
+
+ // Do the MIME-stuff
+ $header .= "MIME-Version: 1.0\r\n";
+
+ if (isMultipart()) {
+ $header .= "Content-Type: multipart/mixed; boundary=\"";
+ $header .= mimeBoundary();
+ $header .= "\"\r\n";
+ } else {
+ if ($default_charset != "")
+ $header .= "Content-Type: text/plain; charset=$default_charset\r\n";
+ else
+ $header .= "Content-Type: text/plain;\r\n";
+ $header .= "Content-Transfer-Encoding: 8bit\r\n";
+ }
+ $header .= "\r\n"; // One blank line to separate header and body