/**
  * Return address information from mime headers.
  * @param boolean $full return full address (true) or only personal if it exists, otherwise email (false)
  * @param boolean $encoded (since 1.4.0) return rfc2047 encoded address (true) or plain text (false).
  * @param boolean $unconditionally_quote (since 1.4.21/1.5.2) when TRUE, always quote the personal part, whether or not it is encoded, otherwise quoting is only added if the personal part is not encoded
  *
  * @return string
  */
 function getAddress($full = true, $encoded = false, $unconditionally_quote = FALSE)
 {
     $result = '';
     if (is_object($this)) {
         $email = $this->host ? $this->mailbox . '@' . $this->host : $this->mailbox;
         $personal = trim($this->personal);
         $is_encoded = false;
         if (preg_match('/(=\\?([^?]*)\\?(Q|B)\\?([^?]*)\\?=)(.*)/i', $personal, $reg)) {
             $is_encoded = true;
         }
         if ($personal) {
             if ($encoded && !$is_encoded) {
                 $personal_encoded = encodeHeader('"' . $personal . '"');
                 if ($personal !== $personal_encoded) {
                     $personal = $personal_encoded;
                 } else {
                     //FIXME: this probably adds quotes around an encoded string which itself is already quoted
                     $personal = '"' . $this->personal . '"';
                 }
             } else {
                 if (!$is_encoded || $unconditionally_quote) {
                     $personal = '"' . $this->personal . '"';
                 }
             }
             $addr = $email ? $personal . ' <' . $email . '>' : $this->personal;
             $best_dpl = $this->personal;
         } else {
             $addr = $email;
             $best_dpl = $email;
         }
         $result = $full ? $addr : $best_dpl;
     }
     return $result;
 }
示例#2
0
文件: spamcop.php 项目: jprice/EHCP
function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id = '', $imapConnection)
{
    global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
    $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
    if (!$passed_ent_id) {
        $body_a = sqimap_run_command($imapConnection, 'FETCH ' . $passed_id . ' RFC822', TRUE, $response, $readmessage, $uid_support);
    } else {
        $body_a = sqimap_run_command($imapConnection, 'FETCH ' . $passed_id . ' BODY[' . $passed_ent_id . ']', TRUE, $response, $readmessage, $uid_support);
        $message = $message->parent;
    }
    if ($response == 'OK') {
        $subject = encodeHeader($message->rfc822_header->subject);
        array_shift($body_a);
        $body = implode('', $body_a) . "\r\n";
        $localfilename = GenerateRandomString(32, 'FILE', 7);
        $full_localfilename = "{$hashed_attachment_dir}/{$localfilename}";
        $fp = fopen($full_localfilename, 'w');
        fwrite($fp, $body);
        fclose($fp);
        /* dirty relative dir fix */
        if (substr($attachment_dir, 0, 3) == '../') {
            $attachment_dir = substr($attachment_dir, 3);
            $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
        }
        $full_localfilename = "{$hashed_attachment_dir}/{$localfilename}";
        $composeMessage->initAttachment('message/rfc822', 'email.txt', $full_localfilename);
    }
    return $composeMessage;
}
 function getAddress($full = true, $encoded = false)
 {
     $result = '';
     if (is_object($this)) {
         $email = $this->host ? $this->mailbox . '@' . $this->host : $this->mailbox;
         $personal = trim($this->personal);
         $is_encoded = false;
         if (preg_match('/(=\\?([^?]*)\\?(Q|B)\\?([^?]*)\\?=)(.*)/Ui', $personal, $reg)) {
             $is_encoded = true;
         }
         if ($personal) {
             if ($encoded && !$is_encoded) {
                 $personal_encoded = encodeHeader($personal);
                 if ($personal !== $personal_encoded) {
                     $personal = $personal_encoded;
                 } else {
                     $personal = '"' . $this->personal . '"';
                 }
             } else {
                 if (!$is_encoded) {
                     $personal = '"' . $this->personal . '"';
                 }
             }
             $addr = $email ? $personal . ' <' . $email . '>' : $this->personal;
             $best_dpl = $this->personal;
         } else {
             $addr = $email;
             $best_dpl = $email;
         }
         $result = $full ? $addr : $best_dpl;
     }
     return $result;
 }
 function prepareRFC822_Header($rfc822_header, $reply_rfc822_header, &$raw_length)
 {
     global $domain, $version, $username;
     /* if server var SERVER_NAME not available, use $domain */
     if (!sqGetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER)) {
         $SERVER_NAME = $domain;
     }
     sqGetGlobalVar('REMOTE_ADDR', $REMOTE_ADDR, SQ_SERVER);
     sqGetGlobalVar('REMOTE_PORT', $REMOTE_PORT, SQ_SERVER);
     sqGetGlobalVar('REMOTE_HOST', $REMOTE_HOST, SQ_SERVER);
     sqGetGlobalVar('HTTP_VIA', $HTTP_VIA, SQ_SERVER);
     sqGetGlobalVar('HTTP_X_FORWARDED_FOR', $HTTP_X_FORWARDED_FOR, SQ_SERVER);
     $rn = "\r\n";
     /* This creates an RFC 822 date */
     $date = date('D, j M Y H:i:s ', mktime()) . $this->timezone();
     /* Create a message-id */
     $message_id = '<' . $REMOTE_PORT . '.' . $REMOTE_ADDR . '.';
     $message_id .= time() . '.squirrel@' . $SERVER_NAME . '>';
     /* Make an RFC822 Received: line */
     if (isset($REMOTE_HOST)) {
         $received_from = "{$REMOTE_HOST} ([{$REMOTE_ADDR}])";
     } else {
         $received_from = $REMOTE_ADDR;
     }
     if (isset($HTTP_VIA) || isset($HTTP_X_FORWARDED_FOR)) {
         if (!isset($HTTP_X_FORWARDED_FOR) || $HTTP_X_FORWARDED_FOR == '') {
             $HTTP_X_FORWARDED_FOR = 'unknown';
         }
         $received_from .= " (proxying for {$HTTP_X_FORWARDED_FOR})";
     }
     $header = array();
     $header[] = "Received: from {$received_from}" . $rn;
     $header[] = "        (SquirrelMail authenticated user {$username})" . $rn;
     $header[] = "        by {$SERVER_NAME} with HTTP;" . $rn;
     $header[] = "        {$date}" . $rn;
     /* Insert the rest of the header fields */
     $header[] = 'Message-ID: ' . $message_id . $rn;
     if ($reply_rfc822_header->message_id) {
         $rep_message_id = $reply_rfc822_header->message_id;
         //	    $this->strip_crlf($message_id);
         $header[] = 'In-Reply-To: ' . $rep_message_id . $rn;
         $references = $this->calculate_references($reply_rfc822_header);
         $header[] = 'References: ' . $references . $rn;
     }
     $header[] = "Date: {$date}" . $rn;
     $header[] = 'Subject: ' . encodeHeader($rfc822_header->subject) . $rn;
     $header[] = 'From: ' . $rfc822_header->getAddr_s('from', ',', true) . $rn;
     /* RFC2822 if from contains more then 1 address */
     if (count($rfc822_header->from) > 1) {
         $header[] = 'Sender: ' . $rfc822_header->getAddr_s('sender', ',', true) . $rn;
     }
     if (count($rfc822_header->to)) {
         $header[] = 'To: ' . $rfc822_header->getAddr_s('to', ',', true) . $rn;
     }
     if (count($rfc822_header->cc)) {
         $header[] = 'Cc: ' . $rfc822_header->getAddr_s('cc', ',', true) . $rn;
     }
     if (count($rfc822_header->reply_to)) {
         $header[] = 'Reply-To: ' . $rfc822_header->getAddr_s('reply_to', ',', true) . $rn;
     }
     /* Sendmail should return true. Default = false */
     $bcc = $this->getBcc();
     if (count($rfc822_header->bcc)) {
         $s = 'Bcc: ' . $rfc822_header->getAddr_s('bcc', ',', true) . $rn;
         if (!$bcc) {
             $s = $this->foldLine($s, 78, str_pad('', 4));
             $raw_length += strlen($s);
         } else {
             $header[] = $s;
         }
     }
     /* Identify SquirrelMail */
     $header[] = 'User-Agent: SquirrelMail/' . $version . $rn;
     /* Do the MIME-stuff */
     $header[] = 'MIME-Version: 1.0' . $rn;
     $contenttype = 'Content-Type: ' . $rfc822_header->content_type->type0 . '/' . $rfc822_header->content_type->type1;
     if (count($rfc822_header->content_type->properties)) {
         foreach ($rfc822_header->content_type->properties as $k => $v) {
             if ($k && $v) {
                 $contenttype .= ';' . $k . '=' . $v;
             }
         }
     }
     $header[] = $contenttype . $rn;
     if ($rfc822_header->dnt) {
         $dnt = $rfc822_header->getAddr_s('dnt');
         /* Pegasus Mail */
         $header[] = 'X-Confirm-Reading-To: ' . $dnt . $rn;
         /* RFC 2298 */
         $header[] = 'Disposition-Notification-To: ' . $dnt . $rn;
     }
     if ($rfc822_header->priority) {
         $prio = $rfc822_header->priority;
         $header[] = 'X-Priority: ' . $prio . $rn;
         switch ($prio) {
             case 1:
                 $header[] = 'Importance: High' . $rn;
                 break;
             case 3:
                 $header[] = 'Importance: Normal' . $rn;
                 break;
             case 5:
                 $header[] = 'Importance: Low' . $rn;
                 break;
             default:
                 break;
         }
     }
     /* Insert headers from the $more_headers array */
     if (count($rfc822_header->more_headers)) {
         reset($rfc822_header->more_headers);
         foreach ($rfc822_header->more_headers as $k => $v) {
             $header[] = $k . ': ' . $v . $rn;
         }
     }
     $cnt = count($header);
     $hdr_s = '';
     for ($i = 0; $i < $cnt; $i++) {
         $hdr_s .= $this->foldLine($header[$i], 78, str_pad('', 4));
     }
     //	$debug = "Debug: <123456789012345678901234567890123456789012345678901234567890123456789>\r\n";
     //	$this->foldLine($debug, 78, str_pad('',4));
     $header = $hdr_s;
     $header .= $rn;
     /* One blank line to separate header and body */
     $raw_length += strlen($header);
     return $header;
 }
 function build_mail()
 {
     $ret = false;
     $this->importance();
     $this->headers();
     if ($this->importance != '' && strlen($this->from) > 0) {
         // headers
         $this->body .= $this->headers;
         // priorité
         $this->body .= $this->importance . "\n";
         $this->body .= "Date: " . date('r', time()) . "\n";
         $this->body .= "From: " . $this->from . "\n";
         // on ajoute les To, Cc, Cci:
         if (strlen($this->to) > 0) {
             $this->body .= "To: " . $this->to . "\n";
         }
         if (strlen($this->cc) > 0) {
             $this->body .= "Cc: " . $this->cc . "\n";
         }
         if (strlen($this->cci) > 0) {
             $this->body .= "Bcc: " . $this->cci . "\n";
         }
         if (strlen($this->reply_to) != 0) {
             $this->body .= "Reply-To: " . $this->reply_to . "\n";
         }
         if (strlen($this->subject) > 0) {
             $this->body .= 'Subject: ' . encodeHeader($this->subject) . "\n";
         } else {
             $this->body .= "";
         }
         // qu a t on en fait a envoyer ?
         $this->formatTexte = false;
         $this->formatHTML = false;
         if (isset($this->text)) {
             // que du texte
             $this->formatTexte = true;
             $this->text .= "\n\n";
         } else {
             // on avait une partie html : on genere la partie texte : dans ce cas, on a deux parties
             $this->text = str_replace("</p>", "\n", $this->html);
             $this->text = strip_tags(br2nl($this->text));
             $this->text = html_entity_decode($this->text, ENT_QUOTES, 'UTF-8');
             $this->formatHTML = true;
         }
         if (isset($this->html)) {
             $this->formatHTML = $this->formatTexte = true;
         }
         $this->body .= "MIME-Version: 1.0\n";
         // on genere un boundary general
         $boundary_general = $this->boundary();
         $is_mail_complete = false;
         if (!$this->formatHTML && !isset($this->attachments)) {
             // que du texte : aucun multipart
             $this->body .= "Content-Type: text/plain; charset=\"utf-8\"\n";
             $this->body .= "Content-Transfer-Encoding: base64\n";
             $this->body .= "\n";
             $this->body .= chunk_split(base64_encode($this->text));
             $is_mail_complete = true;
         } elseif (!$this->formatHTML && isset($this->attachments) && $this->attachments) {
             // texte + attachement : mixed
             $this->body .= "Content-Type: multipart/mixed;\n";
         } elseif ($this->formatHTML && !isset($this->attachments)) {
             // texte + html : alternative
             $this->body .= "Content-Type: multipart/alternative;\n";
         } elseif ($this->formatHTML && isset($this->attachments) && $this->attachments) {
             // texte + html + attachement : mixed
             $this->body .= "Content-Type: multipart/mixed;\n";
         }
         if (!$is_mail_complete) {
             // on blute la fin de l'entete générale
             $this->body .= " boundary=\"" . $boundary_general . "\"\n";
             $this->body .= "\n";
             $this->body .= "This is a multi-part message in MIME format.\n\n";
             $this->body .= "--" . $boundary_general . "\n";
             // Si on a des pj, on annonce la partie texte et la partie html avec un multipart/alternative
             if (isset($this->attachments) && $this->attachments) {
                 // on blute une partie alternative
                 $boundary_alternative = $this->boundary();
                 $this->body .= "Content-Type: multipart/alternative;\n";
                 $this->body .= " boundary=\"" . $boundary_alternative . "\"\n";
                 $this->body .= "\n";
                 $this->body .= "\n";
                 $this->body .= "--" . $boundary_alternative . "\n";
             }
             // on blute la partie texte
             $this->body .= "Content-Type: text/plain; charset=\"utf-8\"\n";
             $this->body .= "Content-Transfer-Encoding: base64\n";
             $this->body .= "\n";
             $this->body .= chunk_split(base64_encode($this->text));
             $this->body .= "\n";
             if (isset($boundary_alternative)) {
                 $this->body .= "--" . $boundary_alternative . "\n";
             } else {
                 $this->body .= "--" . $boundary_general . "\n";
             }
             // Si on a du inline, on blute du related
             if (isset($this->inline) && $this->inline) {
                 // on se genere un boundary
                 $boundary_related = $this->boundary();
                 $this->body .= "Content-Type: multipart/related;\n";
                 $this->body .= " boundary=\"" . $boundary_related . "\"\n";
                 $this->body .= "\n";
                 $this->body .= "--" . $boundary_related . "\n";
             }
             // on blute la partie html
             $this->body .= "Content-Type: text/html; charset=\"utf-8\"\n";
             $this->body .= "Content-Transfer-Encoding: base64\n";
             $this->body .= "\n";
             $this->body .= chunk_split(base64_encode($this->html)) . "\n";
             // Si on a du inline, on blute les images inline
             if (isset($this->inline) && $this->inline) {
                 for ($a = 0; $a < count($this->files); $a++) {
                     if ($this->files[$a]->cid != '') {
                         $this->body .= "--" . $boundary_related . "\n";
                         $this->body .= "Content-Type: " . $this->files[$a]->type . "\n";
                         $this->body .= ' name="' . $this->files[$a]->nom . '"' . "\n";
                         $this->body .= "Content-Transfer-Encoding: base64\n";
                         $this->body .= "Content-ID: <" . $this->files[$a]->cid . ">\n";
                         $this->body .= "Content-Disposition: inline;\n";
                         $this->body .= ' filename="' . $this->files[$a]->nom . '"' . "\n";
                         $this->body .= "\n";
                         $this->body .= chunk_split(base64_encode($this->files[$a]->file));
                         $this->body .= "\n";
                     }
                 }
                 // On cloture la partie INLINE
                 $this->body .= "--" . $boundary_related . "--\n\n";
             }
             if (isset($boundary_alternative)) {
                 $this->body .= "--" . $boundary_alternative . "--\n";
             } elseif (!isset($this->attachments)) {
                 $this->body .= "--" . $boundary_general . "--\n\n";
             }
             // pieces jointes
             if (isset($this->attachments) && $this->attachments) {
                 for ($a = 0; $a < count($this->files); $a++) {
                     if ($this->files[$a]->cid == '') {
                         $this->body .= "--" . $boundary_general . "\n";
                         $this->body .= "Content-Type: " . $this->files[$a]->type . "\n";
                         $this->body .= ' name="' . $this->files[$a]->nom . '"' . "\n";
                         $this->body .= "Content-Transfer-Encoding: base64\n";
                         $this->body .= "Content-Disposition: attachment;\n";
                         $this->body .= ' filename="' . $this->files[$a]->nom . '"' . "\n";
                         $this->body .= "\n";
                         $this->body .= chunk_split(base64_encode($this->files[$a]->file));
                         $this->body .= "\n";
                     }
                 }
                 // On cloture le mail
                 $this->body .= "--" . $boundary_general . "--\n\n";
             }
         }
         // on efface tous les \r que le mec a pu balancer dans son mail
         $this->body = str_replace("\r", "", $this->body);
         // on calcule le nombre de \n
         $nb_backslash_n = substr_count($this->body, "\n");
         // on calcule la taille du mail en octets
         $this->size = strlen($this->body);
         $this->rfcsize = $this->size + $nb_backslash_n;
         $ret = true;
     }
     return $ret;
 }
示例#6
0
/**
 * Do after address parsing handling. This is used by compose.php and should
 * be moved to compose.php.
 * The AddressStructure objetc is now obsolete and dependent parts of that will
 * be adapted so that it can make use of this function
 * After that we can remove the parseAddress method from the Rfc822Header class completely
 * so we achieved 1 single instance of parseAddress instead of two like we have now.
 *
 * @param array $aAddressList list with email address arrays
 * @param array  $aProps  associative array with properties
 * @return string
 * @public
 * @see parseRFC822Address
 * @see Rfc822Header
 * @author Marc Groot Koerkamp
 *
 **/
function processAddressArray($aAddresses, $aProps)
{
    $aPropsDefault = array('domain' => '', 'limit' => 0, 'abooklookup' => false);
    $aProps = is_array($aProps) ? array_merge($aPropsDefault, $aProps) : $aPropsDefault;
    $aProcessedAddress = array();
    foreach ($aAddresses as $aEntry) {
        /*
         * if the emailaddress does not contain the domainpart it can concern
         * an alias or local (in the same domain as the user is) email
         * address. In that case we try to look it up in the addressbook or add
         * the local domain part
         */
        if (!$aEntry[SQM_ADDR_HOST]) {
            if ($cbLookup) {
                $aAddr = call_user_func_array($cbLookup, array($aEntry[SQM_ADDR_MAILBOX]));
                if (isset($aAddr['email'])) {
                    /*
                     * if the returned email address concerns multiple email
                     * addresses we have to process those as well
                     */
                    if (strpos($aAddr['email'], ',')) {
                        /* multiple addresses */
                        /* add the parsed addresses to the processed address array */
                        $aProcessedAddress = array_merge($aProcessedAddress, parseAddress($aAddr['email']));
                        /* skip to next address, all processing is done */
                        continue;
                    } else {
                        /* single address */
                        $iPosAt = strpos($aAddr['email'], '@');
                        $aEntry[SQM_ADDR_MAILBOX] = substr($aAddr['email'], 0, $iPosAt);
                        $aEntry[SQM_ADDR_HOST] = substr($aAddr['email'], $iPosAt + 1);
                        if (isset($aAddr['name'])) {
                            $aEntry[SQM_ADDR_PERSONAL] = $aAddr['name'];
                        } else {
                            $aEntry[SQM_ADDR_PERSONAL] = encodeHeader($sPersonal);
                        }
                    }
                }
            }
            /*
             * append the domain
             *
             */
            if (!$aEntry[SQM_ADDR_MAILBOX]) {
                $aEntry[SQM_ADDR_MAILBOX] = trim($sEmail);
            }
            if ($sDomain && !$aEntry[SQM_ADDR_HOST]) {
                $aEntry[SQM_ADDR_HOST] = $sDomain;
            }
        }
        if ($aEntry[SQM_ADDR_MAILBOX]) {
            $aProcessedAddress[] = $aEntry;
        }
    }
    return $aProcessedAddress;
}
示例#7
0
function deliverMessage($composeMessage, $draft = false)
{
    global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body, $username, $popuser, $usernamedata, $identity, $idents, $data_dir, $request_mdn, $request_dr, $default_charset, $color, $useSendmail, $domain, $action, $default_move_to_sent, $move_to_sent;
    global $imapServerAddress, $imapPort, $sent_folder, $key;
    $rfc822_header = $composeMessage->rfc822_header;
    $abook = addressbook_init(false, true);
    $rfc822_header->to = $rfc822_header->parseAddress($send_to, true, array(), '', $domain, array(&$abook, 'lookup'));
    $rfc822_header->cc = $rfc822_header->parseAddress($send_to_cc, true, array(), '', $domain, array(&$abook, 'lookup'));
    $rfc822_header->bcc = $rfc822_header->parseAddress($send_to_bcc, true, array(), '', $domain, array(&$abook, 'lookup'));
    $rfc822_header->priority = $mailprio;
    $rfc822_header->subject = $subject;
    $special_encoding = '';
    if (strtolower($default_charset) == 'iso-2022-jp') {
        if (mb_detect_encoding($body) == 'ASCII') {
            $special_encoding = '8bit';
        } else {
            $body = mb_convert_encoding($body, 'JIS');
            $special_encoding = '7bit';
        }
    }
    $composeMessage->setBody($body);
    if (ereg("^([^@%/]+)[@%/](.+)\$", $username, $usernamedata)) {
        $popuser = $usernamedata[1];
        $domain = $usernamedata[2];
        unset($usernamedata);
    } else {
        $popuser = $username;
    }
    $reply_to = '';
    $from_mail = $idents[$identity]['email_address'];
    $full_name = $idents[$identity]['full_name'];
    $reply_to = $idents[$identity]['reply_to'];
    if (!$from_mail) {
        $from_mail = "{$popuser}@{$domain}";
    }
    $rfc822_header->from = $rfc822_header->parseAddress($from_mail, true);
    if ($full_name) {
        $from = $rfc822_header->from[0];
        if (!$from->host) {
            $from->host = $domain;
        }
        $full_name_encoded = encodeHeader($full_name);
        if ($full_name_encoded != $full_name) {
            $from_addr = $full_name_encoded . ' <' . $from->mailbox . '@' . $from->host . '>';
        } else {
            $from_addr = '"' . $full_name . '" <' . $from->mailbox . '@' . $from->host . '>';
        }
        $rfc822_header->from = $rfc822_header->parseAddress($from_addr, true);
    }
    if ($reply_to) {
        $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to, true);
    }
    /* Receipt: On Read */
    if (isset($request_mdn) && $request_mdn) {
        $rfc822_header->dnt = $rfc822_header->parseAddress($from_mail, true);
    }
    /* Receipt: On Delivery */
    if (isset($request_dr) && $request_dr) {
        $rfc822_header->more_headers['Return-Receipt-To'] = $from_mail;
    }
    /* multipart messages */
    if (count($composeMessage->entities)) {
        $message_body = new Message();
        $message_body->body_part = $composeMessage->body_part;
        $composeMessage->body_part = '';
        $mime_header = new MessageHeader();
        $mime_header->type0 = 'text';
        $mime_header->type1 = 'plain';
        if ($special_encoding) {
            $mime_header->encoding = $special_encoding;
        } else {
            $mime_header->encoding = '8bit';
        }
        if ($default_charset) {
            $mime_header->parameters['charset'] = $default_charset;
        }
        $message_body->mime_header = $mime_header;
        array_unshift($composeMessage->entities, $message_body);
        $content_type = new ContentType('multipart/mixed');
    } else {
        $content_type = new ContentType('text/plain');
        if ($special_encoding) {
            $rfc822_header->encoding = $special_encoding;
        } else {
            $rfc822_header->encoding = '8bit';
        }
        if ($default_charset) {
            $content_type->properties['charset'] = $default_charset;
        }
    }
    $rfc822_header->content_type = $content_type;
    $composeMessage->rfc822_header = $rfc822_header;
    /* Here you can modify the message structure just before we hand
       it over to deliver */
    $hookReturn = do_hook('compose_send', $composeMessage);
    /* Get any changes made by plugins to $composeMessage. */
    if (is_object($hookReturn[1])) {
        $composeMessage = $hookReturn[1];
    }
    if (!$useSendmail && !$draft) {
        require_once SM_PATH . 'class/deliver/Deliver_SMTP.class.php';
        $deliver = new Deliver_SMTP();
        global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech;
        $authPop = isset($pop_before_smtp) && $pop_before_smtp ? true : false;
        get_smtp_user($user, $pass);
        $stream = $deliver->initStream($composeMessage, $domain, 0, $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
    } elseif (!$draft) {
        require_once SM_PATH . 'class/deliver/Deliver_SendMail.class.php';
        global $sendmail_path;
        $deliver = new Deliver_SendMail();
        $stream = $deliver->initStream($composeMessage, $sendmail_path);
    } elseif ($draft) {
        global $draft_folder;
        require_once SM_PATH . 'class/deliver/Deliver_IMAP.class.php';
        $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
        if (sqimap_mailbox_exists($imap_stream, $draft_folder)) {
            require_once SM_PATH . 'class/deliver/Deliver_IMAP.class.php';
            $imap_deliver = new Deliver_IMAP();
            $length = $imap_deliver->mail($composeMessage);
            sqimap_append($imap_stream, $draft_folder, $length);
            $imap_deliver->mail($composeMessage, $imap_stream);
            sqimap_append_done($imap_stream, $draft_folder);
            sqimap_logout($imap_stream);
            unset($imap_deliver);
            return $length;
        } else {
            $msg = '<br />' . sprintf(_("Error: Draft folder %s does not exist."), $draft_folder);
            plain_error_message($msg, $color);
            return false;
        }
    }
    $succes = false;
    if ($stream) {
        $length = $deliver->mail($composeMessage, $stream);
        $succes = $deliver->finalizeStream($stream);
    }
    if (!$succes) {
        $msg = $deliver->dlv_msg . '<br />' . _("Server replied: ") . $deliver->dlv_ret_nr . ' ' . $deliver->dlv_server_msg;
        plain_error_message($msg, $color);
    } else {
        unset($deliver);
        $move_to_sent = getPref($data_dir, $username, 'move_to_sent');
        $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
        /* Move to sent code */
        if (isset($default_move_to_sent) && $default_move_to_sent != 0) {
            $svr_allow_sent = true;
        } else {
            $svr_allow_sent = false;
        }
        if (isset($sent_folder) && ($sent_folder != '' || $sent_folder != 'none') && sqimap_mailbox_exists($imap_stream, $sent_folder)) {
            $fld_sent = true;
        } else {
            $fld_sent = false;
        }
        if (isset($move_to_sent) && $move_to_sent != 0 || !isset($move_to_sent)) {
            $lcl_allow_sent = true;
        } else {
            $lcl_allow_sent = false;
        }
        if ($fld_sent && $svr_allow_sent && !$lcl_allow_sent || $fld_sent && $lcl_allow_sent) {
            global $passed_id, $mailbox, $action;
            if ($action == 'reply' || $action == 'reply_all') {
                $save_reply_with_orig = getPref($data_dir, $username, 'save_reply_with_orig');
                if ($save_reply_with_orig) {
                    $sent_folder = $mailbox;
                }
            }
            sqimap_append($imap_stream, $sent_folder, $length);
            require_once SM_PATH . 'class/deliver/Deliver_IMAP.class.php';
            $imap_deliver = new Deliver_IMAP();
            $imap_deliver->mail($composeMessage, $imap_stream);
            sqimap_append_done($imap_stream, $sent_folder);
            unset($imap_deliver);
        }
        global $passed_id, $mailbox, $action;
        ClearAttachments($composeMessage);
        if ($action == 'reply' || $action == 'reply_all') {
            sqimap_mailbox_select($imap_stream, $mailbox);
            sqimap_messages_flag($imap_stream, $passed_id, $passed_id, 'Answered', false);
        }
        sqimap_logout($imap_stream);
    }
    return $succes;
}
示例#8
0
 /**
  * recursive function for parsing address strings and storing them in an address stucture object.
  *  personal name: encoded: =?charset?Q|B?string?=
  *                 quoted:  "string"
  *                 normal:  string
  *  email        : <mailbox@host>
  *               : mailbox@host
  *  This function is also used for validating addresses returned from compose
  *  That's also the reason that the function became a little bit huge
  * @param string $address
  * @param boolean $ar return array instead of only the first element
  * @param array $addr_ar (obsolete) array with parsed addresses
  * @param string $group (obsolete)
  * @param string $host default domainname in case of addresses without a domainname
  * @param string $lookup (since) callback function for lookup of address strings which are probably nicks (without @)
  * @return mixed array with AddressStructure objects or only one address_structure object.
  */
 function parseAddress($address, $ar = false, $aAddress = array(), $sGroup = '', $sHost = '', $lookup = false)
 {
     $aTokens = $this->getAddressTokens($address);
     $sPersonal = $sEmail = $sComment = $sGroup = '';
     $aStack = $aComment = array();
     foreach ($aTokens as $sToken) {
         $cChar = $sToken[0];
         switch ($cChar) {
             case '=':
             case '"':
             case ' ':
                 $aStack[] = $sToken;
                 break;
             case '(':
                 $aComment[] = substr($sToken, 1, -1);
                 break;
             case ';':
                 if ($sGroup) {
                     $aAddress[] = $this->createAddressObject($aStack, $aComment, $sEmail, $sGroup);
                     $oAddr = end($aAddress);
                     if (!$oAddr || isset($oAddr) && !strlen($oAddr->mailbox) && !$oAddr->personal) {
                         $sEmail = $sGroup . ':;';
                     }
                     $aAddress[] = $this->createAddressObject($aStack, $aComment, $sEmail, $sGroup);
                     $sGroup = '';
                     $aStack = $aComment = array();
                     break;
                 }
             case ',':
                 $aAddress[] = $this->createAddressObject($aStack, $aComment, $sEmail, $sGroup);
                 break;
             case ':':
                 $sGroup = trim(implode(' ', $aStack));
                 $sGroup = preg_replace('/\\s+/', ' ', $sGroup);
                 $aStack = array();
                 break;
             case '<':
                 $sEmail = trim(substr($sToken, 1, -1));
                 break;
             case '>':
                 /* skip */
                 break;
             default:
                 $aStack[] = $sToken;
                 break;
         }
     }
     /* now do the action again for the last address */
     $aAddress[] = $this->createAddressObject($aStack, $aComment, $sEmail);
     /* try to lookup the addresses in case of invalid email addresses */
     $aProcessedAddress = array();
     foreach ($aAddress as $oAddr) {
         $aAddrBookAddress = array();
         if (!$oAddr->host) {
             $grouplookup = false;
             if ($lookup) {
                 $aAddr = call_user_func_array($lookup, array($oAddr->mailbox));
                 if (isset($aAddr['email'])) {
                     if (strpos($aAddr['email'], ',')) {
                         $grouplookup = true;
                         $aAddrBookAddress = $this->parseAddress($aAddr['email'], true);
                     } else {
                         $iPosAt = strpos($aAddr['email'], '@');
                         if ($iPosAt === FALSE) {
                             $oAddr->mailbox = $aAddr['email'];
                             $oAddr->host = FALSE;
                         } else {
                             $oAddr->mailbox = substr($aAddr['email'], 0, $iPosAt);
                             $oAddr->host = substr($aAddr['email'], $iPosAt + 1);
                         }
                         if (isset($aAddr['name'])) {
                             $oAddr->personal = $aAddr['name'];
                         } else {
                             $oAddr->personal = encodeHeader($sPersonal);
                         }
                     }
                 }
             }
             if (!$grouplookup && !strlen($oAddr->mailbox)) {
                 $oAddr->mailbox = trim($sEmail);
                 if ($sHost && strlen($oAddr->mailbox)) {
                     $oAddr->host = $sHost;
                 }
             } else {
                 if (!$grouplookup && !$oAddr->host) {
                     if ($sHost && strlen($oAddr->mailbox)) {
                         $oAddr->host = $sHost;
                     }
                 }
             }
         }
         if (!$aAddrBookAddress && strlen($oAddr->mailbox)) {
             $aProcessedAddress[] = $oAddr;
         } else {
             $aProcessedAddress = array_merge($aProcessedAddress, $aAddrBookAddress);
         }
     }
     if ($ar) {
         return $aProcessedAddress;
     } else {
         if (isset($aProcessedAddress[0])) {
             return $aProcessedAddress[0];
         } else {
             return '';
         }
     }
 }
示例#9
0
/**
 * Construct our "From:" header based on
 * a supplied identity number.
 * Will fall back when no sensible email address has been defined.
 *
 * @param   int $identity   identity# to use
 * @since 1.5.2
 */
function build_from_header($identity = 0)
{
    global $domain;
    $idents = get_identities();
    if (!isset($idents[$identity])) {
        $identity = 0;
    }
    if (!empty($idents[$identity]['full_name'])) {
        $from_name = $idents[$identity]['full_name'];
    }
    $from_mail = $idents[$identity]['email_address'];
    if (strpos($from_mail, '@') === FALSE) {
        $from_mail .= '@' . $domain;
    }
    if (isset($from_name)) {
        $from_name_encoded = encodeHeader('"' . $from_name . '"');
        if ($from_name_encoded != $from_name) {
            return $from_name_encoded . ' <' . $from_mail . '>';
        }
        return '"' . $from_name . '" <' . $from_mail . '>';
    }
    return $from_mail;
}
示例#10
0
function SendMDN($mailbox, $passed_id, $sender, $message, $imapConnection)
{
    global $username, $attachment_dir, $color, $version, $attachments, $squirrelmail_language, $default_charset, $languages, $useSendmail, $domain, $sent_folder, $popuser, $data_dir, $username;
    sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER);
    $header = $message->rfc822_header;
    $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
    $rfc822_header = new Rfc822Header();
    $content_type = new ContentType('multipart/report');
    $content_type->properties['report-type'] = 'disposition-notification';
    set_my_charset();
    if ($default_charset) {
        $content_type->properties['charset'] = $default_charset;
    }
    $rfc822_header->content_type = $content_type;
    $rfc822_header->to[] = $header->dnt;
    $rfc822_header->subject = _("Read:") . ' ' . encodeHeader($header->subject);
    // FIX ME, use identity.php from SM 1.5. Change this also in compose.php
    $reply_to = '';
    if (isset($identity) && $identity != 'default') {
        $from_mail = getPref($data_dir, $username, 'email_address' . $identity);
        $full_name = getPref($data_dir, $username, 'full_name' . $identity);
        $from_addr = '"' . $full_name . '" <' . $from_mail . '>';
        $reply_to = getPref($data_dir, $username, 'reply_to' . $identity);
    } else {
        $from_mail = getPref($data_dir, $username, 'email_address');
        $full_name = getPref($data_dir, $username, 'full_name');
        $from_addr = '"' . $full_name . '" <' . $from_mail . '>';
        $reply_to = getPref($data_dir, $username, 'reply_to');
    }
    // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md)
    // This merely comes from compose.php and only happens when there is no
    // email_addr specified in user's identity (which is the startup config)
    if (ereg("^([^@%/]+)[@%/](.+)\$", $username, $usernamedata)) {
        $popuser = $usernamedata[1];
        $domain = $usernamedata[2];
        unset($usernamedata);
    } else {
        $popuser = $username;
    }
    if (!$from_mail) {
        $from_mail = "{$popuser}@{$domain}";
        $from_addr = $from_mail;
    }
    $rfc822_header->from = $rfc822_header->parseAddress($from_addr, true);
    if ($reply_to) {
        $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to, true);
    }
    // part 1 (RFC2298)
    $senton = getLongDateString($header->date, $header->date_unparsed);
    $to_array = $header->to;
    $to = '';
    foreach ($to_array as $line) {
        $to .= ' ' . $line->getAddress();
    }
    $now = getLongDateString(time());
    set_my_charset();
    $body = _("Your message") . "\r\n\r\n" . "\t" . _("To") . ': ' . decodeHeader($to, false, false, true) . "\r\n" . "\t" . _("Subject") . ': ' . decodeHeader($header->subject, false, false, true) . "\r\n" . "\t" . _("Sent") . ': ' . $senton . "\r\n" . "\r\n" . sprintf(_("Was displayed on %s"), $now);
    $special_encoding = '';
    if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
        $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
        if (strtolower($default_charset) == 'iso-2022-jp') {
            if (mb_detect_encoding($body) == 'ASCII') {
                $special_encoding = '8bit';
            } else {
                $body = mb_convert_encoding($body, 'JIS');
                $special_encoding = '7bit';
            }
        }
    } elseif (sq_is8bit($body)) {
        // detect 8bit symbols added by translations
        $special_encoding = '8bit';
    }
    $part1 = new Message();
    $part1->setBody($body);
    $mime_header = new MessageHeader();
    $mime_header->type0 = 'text';
    $mime_header->type1 = 'plain';
    if ($special_encoding) {
        $mime_header->encoding = $special_encoding;
    } else {
        $mime_header->encoding = 'us-ascii';
    }
    if ($default_charset) {
        $mime_header->parameters['charset'] = $default_charset;
    }
    $part1->mime_header = $mime_header;
    // part2  (RFC2298)
    $original_recipient = $to;
    $original_message_id = $header->message_id;
    $report = "Reporting-UA : {$SERVER_NAME} ; SquirrelMail (version {$version}) \r\n";
    if ($original_recipient != '') {
        $report .= "Original-Recipient : {$original_recipient}\r\n";
    }
    $final_recipient = $sender;
    $report .= "Final-Recipient: rfc822; {$final_recipient}\r\n" . "Original-Message-ID : {$original_message_id}\r\n" . "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
    $part2 = new Message();
    $part2->setBody($report);
    $mime_header = new MessageHeader();
    $mime_header->type0 = 'message';
    $mime_header->type1 = 'disposition-notification';
    $mime_header->encoding = 'us-ascii';
    $part2->mime_header = $mime_header;
    $composeMessage = new Message();
    $composeMessage->rfc822_header = $rfc822_header;
    $composeMessage->addEntity($part1);
    $composeMessage->addEntity($part2);
    if ($useSendmail) {
        require_once SM_PATH . 'class/deliver/Deliver_SendMail.class.php';
        global $sendmail_path, $sendmail_args;
        // Check for outdated configuration
        if (!isset($sendmail_args)) {
            if ($sendmail_path == '/var/qmail/bin/qmail-inject') {
                $sendmail_args = '';
            } else {
                $sendmail_args = '-i -t';
            }
        }
        $deliver = new Deliver_SendMail(array('sendmail_args' => $sendmail_args));
        $stream = $deliver->initStream($composeMessage, $sendmail_path);
    } else {
        require_once SM_PATH . 'class/deliver/Deliver_SMTP.class.php';
        $deliver = new Deliver_SMTP();
        global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp;
        if ($smtp_auth_mech == 'none') {
            $user = '';
            $pass = '';
        } else {
            global $key, $onetimepad;
            $user = $username;
            $pass = OneTimePadDecrypt($key, $onetimepad);
        }
        $authPop = isset($pop_before_smtp) && $pop_before_smtp ? true : false;
        $stream = $deliver->initStream($composeMessage, $domain, 0, $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
    }
    $success = false;
    if ($stream) {
        $length = $deliver->mail($composeMessage, $stream);
        $success = $deliver->finalizeStream($stream);
    }
    if (!$success) {
        $msg = _("Message not sent.") . ' ' . _("Server replied:") . "\n<blockquote>\n" . $deliver->dlv_msg . '<br />' . $deliver->dlv_ret_nr . ' ' . $deliver->dlv_server_msg . "</blockquote>\n\n";
        require_once SM_PATH . 'functions/display_messages.php';
        plain_error_message($msg, $color);
    } else {
        unset($deliver);
        if (sqimap_mailbox_exists($imapConnection, $sent_folder)) {
            sqimap_append($imapConnection, $sent_folder, $length);
            require_once SM_PATH . 'class/deliver/Deliver_IMAP.class.php';
            $imap_deliver = new Deliver_IMAP();
            $imap_deliver->mail($composeMessage, $imapConnection);
            sqimap_append_done($imapConnection);
            unset($imap_deliver);
        }
    }
    return $success;
}
示例#11
0
function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id = '', $imapConnection)
{
    if (!$passed_ent_id) {
        $body_a = sqimap_run_command($imapConnection, 'FETCH ' . $passed_id . ' RFC822', TRUE, $response, $readmessage, TRUE);
    } else {
        $body_a = sqimap_run_command($imapConnection, 'FETCH ' . $passed_id . ' BODY[' . $passed_ent_id . ']', TRUE, $response, $readmessage, TRUE);
        $message = $message->parent;
    }
    if ($response == 'OK') {
        $subject = encodeHeader($message->rfc822_header->subject);
        array_shift($body_a);
        array_pop($body_a);
        $body = implode('', $body_a) . "\r\n";
        global $username, $attachment_dir;
        $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
        $localfilename = sq_get_attach_tempfile();
        $fp = fopen($hashed_attachment_dir . '/' . $localfilename, 'wb');
        fwrite($fp, $body);
        fclose($fp);
        $composeMessage->initAttachment('message/rfc822', $subject . '.eml', $localfilename);
    }
    return $composeMessage;
}
示例#12
0
 /**
  * function prepareRFC822_Header - prepares the RFC822 header string from Rfc822Header object(s)
  *
  * This function takes the Rfc822Header object(s) and formats them
  * into the RFC822Header string to send to the SMTP server as part
  * of the SMTP message.
  *
  * @param Rfc822Header  $rfc822_header
  * @param Rfc822Header  $reply_rfc822_header
  * @param integer      &$raw_length length of the message
  *
  * @return string $header
  */
 function prepareRFC822_Header(&$rfc822_header, $reply_rfc822_header, &$raw_length)
 {
     global $domain, $version, $username, $encode_header_key, $edit_identity, $hide_auth_header;
     if (!isset($hide_auth_header)) {
         $hide_auth_header = false;
     }
     /* if server var SERVER_NAME not available, use $domain */
     if (!sqGetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER)) {
         $SERVER_NAME = $domain;
     }
     sqGetGlobalVar('REMOTE_ADDR', $REMOTE_ADDR, SQ_SERVER);
     sqGetGlobalVar('REMOTE_PORT', $REMOTE_PORT, SQ_SERVER);
     sqGetGlobalVar('REMOTE_HOST', $REMOTE_HOST, SQ_SERVER);
     sqGetGlobalVar('HTTP_VIA', $HTTP_VIA, SQ_SERVER);
     sqGetGlobalVar('HTTP_X_FORWARDED_FOR', $HTTP_X_FORWARDED_FOR, SQ_SERVER);
     $rn = "\r\n";
     /* This creates an RFC 822 date */
     $date = date('D, j M Y H:i:s ', time()) . $this->timezone();
     /* Create a message-id */
     $message_id = 'MESSAGE ID GENERATION ERROR! PLEASE CONTACT SQUIRRELMAIL DEVELOPERS';
     if (empty($rfc822_header->message_id)) {
         $message_id = '<';
         /* user-specifc data to decrease collision chance */
         $seed_data = $username . '.';
         $seed_data .= !empty($REMOTE_PORT) ? $REMOTE_PORT . '.' : '';
         $seed_data .= !empty($REMOTE_ADDR) ? $REMOTE_ADDR . '.' : '';
         /* add the current time in milliseconds and randomness */
         $seed_data .= uniqid(mt_rand(), true);
         /* put it through one-way hash and add it to the ID */
         $message_id .= md5($seed_data) . '.squirrel@' . $SERVER_NAME . '>';
     }
     /* Make an RFC822 Received: line */
     if (isset($REMOTE_HOST)) {
         $received_from = "{$REMOTE_HOST} ([{$REMOTE_ADDR}])";
     } else {
         $received_from = $REMOTE_ADDR;
     }
     if (isset($HTTP_VIA) || isset($HTTP_X_FORWARDED_FOR)) {
         if (!isset($HTTP_X_FORWARDED_FOR) || $HTTP_X_FORWARDED_FOR == '') {
             $HTTP_X_FORWARDED_FOR = 'unknown';
         }
         $received_from .= " (proxying for {$HTTP_X_FORWARDED_FOR})";
     }
     $header = array();
     /**
      * SquirrelMail header
      *
      * This Received: header provides information that allows to track
      * user and machine that was used to send email. Don't remove it
      * unless you understand all possible forging issues or your
      * webmail installation does not prevent changes in user's email address.
      * See SquirrelMail bug tracker #847107 for more details about it.
      */
     // FIXME: The following headers may generate slightly differently between the message sent to the destination and that stored in the Sent folder because this code will be called before both actions.  This is not necessarily a big problem, but other headers such as Message-ID and Date are preserved between both actions
     if (isset($encode_header_key) && trim($encode_header_key) != '') {
         // use encoded headers, if encryption key is set and not empty
         $header[] = 'X-Squirrel-UserHash: ' . OneTimePadEncrypt($username, base64_encode($encode_header_key)) . $rn;
         $header[] = 'X-Squirrel-FromHash: ' . OneTimePadEncrypt($this->ip2hex($REMOTE_ADDR), base64_encode($encode_header_key)) . $rn;
         if (isset($HTTP_X_FORWARDED_FOR)) {
             $header[] = 'X-Squirrel-ProxyHash:' . OneTimePadEncrypt($this->ip2hex($HTTP_X_FORWARDED_FOR), base64_encode($encode_header_key)) . $rn;
         }
     } else {
         // use default received headers
         $header[] = "Received: from {$received_from}" . $rn;
         if ($edit_identity || !isset($hide_auth_header) || !$hide_auth_header) {
             $header[] = "        (SquirrelMail authenticated user {$username})" . $rn;
         }
         $header[] = "        by {$SERVER_NAME} with HTTP;" . $rn;
         $header[] = "        {$date}" . $rn;
     }
     /* Insert the rest of the header fields */
     if (!empty($rfc822_header->message_id)) {
         $header[] = 'Message-ID: ' . $rfc822_header->message_id . $rn;
     } else {
         $header[] = 'Message-ID: ' . $message_id . $rn;
         $rfc822_header->message_id = $message_id;
     }
     if (is_object($reply_rfc822_header) && isset($reply_rfc822_header->message_id) && $reply_rfc822_header->message_id) {
         //if ($reply_rfc822_header->message_id) {
         $rep_message_id = $reply_rfc822_header->message_id;
         $header[] = 'In-Reply-To: ' . $rep_message_id . $rn;
         $rfc822_header->in_reply_to = $rep_message_id;
         $references = $this->calculate_references($reply_rfc822_header);
         $header[] = 'References: ' . $references . $rn;
         $rfc822_header->references = $references;
     }
     if (!empty($rfc822_header->date) && $rfc822_header->date != -1) {
         $header[] = 'Date: ' . $rfc822_header->date . $rn;
     } else {
         $header[] = "Date: {$date}" . $rn;
         $rfc822_header->date = $date;
     }
     $header[] = 'Subject: ' . encodeHeader($rfc822_header->subject) . $rn;
     // folding address list [From|To|Cc|Bcc] happens by using ",$rn<space>"
     // as delimiter
     // Do not use foldLine for that.
     $header[] = 'From: ' . $rfc822_header->getAddr_s('from', ",{$rn} ", true) . $rn;
     // RFC2822 if from contains more then 1 address
     if (count($rfc822_header->from) > 1) {
         $header[] = 'Sender: ' . $rfc822_header->getAddr_s('sender', ',', true) . $rn;
     }
     if (count($rfc822_header->to)) {
         $header[] = 'To: ' . $rfc822_header->getAddr_s('to', ",{$rn} ", true) . $rn;
     }
     if (count($rfc822_header->cc)) {
         $header[] = 'Cc: ' . $rfc822_header->getAddr_s('cc', ",{$rn} ", true) . $rn;
     }
     if (count($rfc822_header->reply_to)) {
         $header[] = 'Reply-To: ' . $rfc822_header->getAddr_s('reply_to', ',', true) . $rn;
     }
     /* Sendmail should return true. Default = false */
     $bcc = $this->getBcc();
     if (count($rfc822_header->bcc)) {
         $s = 'Bcc: ' . $rfc822_header->getAddr_s('bcc', ",{$rn} ", true) . $rn;
         if (!$bcc) {
             $raw_length += strlen($s);
         } else {
             $header[] = $s;
         }
     }
     /* Identify SquirrelMail */
     $header[] = 'User-Agent: SquirrelMail/' . $version . $rn;
     /* Do the MIME-stuff */
     $header[] = 'MIME-Version: 1.0' . $rn;
     $contenttype = 'Content-Type: ' . $rfc822_header->content_type->type0 . '/' . $rfc822_header->content_type->type1;
     if (count($rfc822_header->content_type->properties)) {
         foreach ($rfc822_header->content_type->properties as $k => $v) {
             if ($k && $v) {
                 $contenttype .= ';' . $k . '=' . $v;
             }
         }
     }
     $header[] = $contenttype . $rn;
     if ($encoding = $rfc822_header->encoding) {
         $header[] = 'Content-Transfer-Encoding: ' . $encoding . $rn;
     }
     if ($rfc822_header->dnt) {
         $dnt = $rfc822_header->getAddr_s('dnt');
         /* Pegasus Mail */
         $header[] = 'X-Confirm-Reading-To: ' . $dnt . $rn;
         /* RFC 2298 */
         $header[] = 'Disposition-Notification-To: ' . $dnt . $rn;
     }
     if ($rfc822_header->priority) {
         switch ($rfc822_header->priority) {
             case 1:
                 $header[] = 'X-Priority: 1 (Highest)' . $rn;
                 $header[] = 'Importance: High' . $rn;
                 break;
             case 3:
                 $header[] = 'X-Priority: 3 (Normal)' . $rn;
                 $header[] = 'Importance: Normal' . $rn;
                 break;
             case 5:
                 $header[] = 'X-Priority: 5 (Lowest)' . $rn;
                 $header[] = 'Importance: Low' . $rn;
                 break;
             default:
                 break;
         }
     }
     /* Insert headers from the $more_headers array */
     if (count($rfc822_header->more_headers)) {
         reset($rfc822_header->more_headers);
         foreach ($rfc822_header->more_headers as $k => $v) {
             $header[] = $k . ': ' . $v . $rn;
         }
     }
     $cnt = count($header);
     $hdr_s = '';
     for ($i = 0; $i < $cnt; $i++) {
         $sKey = substr($header[$i], 0, strpos($header[$i], ':'));
         switch ($sKey) {
             case 'Message-ID':
             case 'In-Reply_To':
                 $hdr_s .= $header[$i];
                 break;
             case 'References':
                 $sRefs = substr($header[$i], 12);
                 $aRefs = explode(' ', $sRefs);
                 $sLine = 'References:';
                 foreach ($aRefs as $sReference) {
                     if (trim($sReference) == '') {
                         /* Don't add spaces. */
                     } elseif (strlen($sLine) + strlen($sReference) > 76) {
                         $hdr_s .= $sLine;
                         $sLine = $rn . '    ' . $sReference;
                     } else {
                         $sLine .= ' ' . $sReference;
                     }
                 }
                 $hdr_s .= $sLine;
                 break;
             case 'To':
             case 'Cc':
             case 'Bcc':
             case 'From':
                 $hdr_s .= $header[$i];
                 break;
             default:
                 $hdr_s .= $this->foldLine($header[$i], 78);
                 break;
         }
     }
     $header = $hdr_s;
     $header .= $rn;
     /* One blank line to separate header and body */
     $raw_length += strlen($header);
     return $header;
 }