Thomas Bruederli
2015-09-10 f189d72943c490ae97323997aef8987bc58f3b5e
program/steps/mail/sendmail.inc
@@ -128,52 +128,25 @@
// if configured, the Received headers goes to top, for good measure
if ($RCMAIL->config->get('http_received_header')) {
    $nldlm   = "\r\n\t";
    $encrypt = $RCMAIL->config->get('http_received_header_encrypt');
    // FROM/VIA
    $nldlm       = "\r\n\t";
    $http_header = 'from ';
    // FROM/VIA
    if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $hosts    = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'], 2);
        $hostname = gethostbyaddr($hosts[0]);
        if ($encrypt) {
            $http_header .= rcmail_encrypt_header($hostname);
            if ($host != $hostname)
                $http_header .= ' ('. rcmail_encrypt_header($host) . ')';
        }
        else {
            $http_header .= (($host != $hostname) ? $hostname : '[' . $host . ']');
            if ($host != $hostname)
                $http_header .= ' (['. $host .'])';
        }
        $http_header .= $nldlm . ' via ';
        $hosts        = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'], 2);
        $http_header .= rcmail_received_host($hosts[0]) . $nldlm . ' via ';
    }
    $host     = $_SERVER['REMOTE_ADDR'];
    $hostname = gethostbyaddr($host);
    if ($encrypt) {
        $http_header .= rcmail_encrypt_header($hostname);
        if ($host != $hostname)
            $http_header .= ' ('. rcmail_encrypt_header($host) . ')';
    }
    else {
        $http_header .= (($host != $hostname) ? $hostname : '[' . $host . ']');
        if ($host != $hostname)
            $http_header .= ' (['. $host .'])';
    }
    $http_header .= rcmail_received_host($_SERVER['REMOTE_ADDR']);
    // BY
    $http_header .= $nldlm . 'by ' . $_SERVER['HTTP_HOST'];
    // WITH
    $http_header .= $nldlm . 'with HTTP (' . $_SERVER['SERVER_PROTOCOL'] .
      ' '.$_SERVER['REQUEST_METHOD'] . '); ' . date('r');
    $http_header = wordwrap($http_header, 69, $nldlm);
    $http_header .= $nldlm . 'with HTTP (' . $_SERVER['SERVER_PROTOCOL']
        . ' ' . $_SERVER['REQUEST_METHOD'] . '); ' . date('r');
    $headers['Received'] = $http_header;
    $headers['Received'] = wordwrap($http_header, 69, $nldlm);
}
$headers['Date'] = $RCMAIL->user_date();
@@ -272,6 +245,18 @@
// fetch message body
$message_body = rcube_utils::get_input_value('_message', rcube_utils::INPUT_POST, TRUE, $message_charset);
if (isset($_POST['_pgpmime'])) {
    $pgp_mime = rcube_utils::get_input_value('_pgpmime', rcube_utils::INPUT_POST);
    $message_body = 'This is an OpenPGP/MIME encrypted message (RFC 2440 and 3156)';
    $isHtml = false;
    // clear unencrypted attachments
    foreach ($COMPOSE['attachments'] as $attach) {
        $RCMAIL->plugins->exec_hook('attachment_delete', $attach);
    }
    $COMPOSE['attachments'] = array();
}
if ($isHtml) {
    $bstyle = array();
@@ -502,6 +487,43 @@
    $text_charset .= ";\r\n format=flowed";
}
// compose PGP/Mime message
if ($pgp_mime) {
    $MAIL_MIME->addAttachment(
        'Version: 1',
        'application/pgp-encrypted',
        'version.txt',  // required by Mail_mime::addAttachment()
        false,
        '8bit',
        '',    // $disposition
        '',    // $charset
        '',    // $language
        '',    // $location
        null,  // $n_encoding
        null,  // $f_encoding
        'PGP/MIME version identification'
    );
    // patch filename out of the version part
    foreach ($MAIL_MIME->_parts as $_i => $_part) {
        if ($_part['c_type'] == 'application/pgp-encrypted') {
            $MAIL_MIME->_parts[$_i]['name'] = '';
            break;
        }
    }
    $MAIL_MIME->addAttachment(
        $pgp_mime,
        'application/octet-stream',
        'encrypted.asc',
        false,
        '8bit',
        'inline'
    );
    $MAIL_MIME->setContentType('multipart/encrypted', array('protocol' => "application/pgp-encrypted"));
}
// encoding settings for mail composing
$MAIL_MIME->setParam('text_encoding', $transfer_encoding);
$MAIL_MIME->setParam('html_encoding', 'quoted-printable');
@@ -723,16 +745,33 @@
/****** message sending functions ********/
// encrypt parts of the header
function rcmail_encrypt_header($what)
function rcmail_received_host($host)
{
    $hostname = gethostbyaddr($host);
    $result = rcmail_encrypt_host($hostname);
    if ($host != $hostname) {
        $result .= ' (' . rcmail_encrypt_host($host) . ')';
    }
    return $result;
}
// encrypt host IP or hostname for Received header
function rcmail_encrypt_host($host)
{
    global $RCMAIL;
    if (!$RCMAIL->config->get('http_received_header_encrypt')) {
        return $what;
    if ($RCMAIL->config->get('http_received_header_encrypt')) {
        return $RCMAIL->encrypt($host);
    }
    return $RCMAIL->encrypt($what);
    if (!preg_match('/[^0-9:.]/', $host)) {
        return "[$host]";
    }
    return $host;
}
// get identity record