コード例 #1
0
ファイル: send_encrypted.php プロジェクト: lorea/Hydra-dev
}
// Make sure the message field, send to field and title are not blank
if (!$body || !$subject) {
    register_error(elgg_echo("messages:blank"));
    forward("messages/compose");
}
// Otherwise, encrypt and 'send' the message
elgg_load_library('elggpg');
elgg_load_library('elggpg:send:override');
if (elgg_get_plugin_user_setting('encrypt_site_messages', elgg_get_logged_in_user_guid(), 'elggpg') == 'yes') {
    $body_from = elggpg_encrypt($body, elgg_get_logged_in_user_entity(), false);
}
if (!$body_from) {
    $body_from = $body;
}
if (elgg_get_plugin_user_setting('encrypt_site_messages', $user->guid, 'elggpg') == 'yes') {
    $body_to = elggpg_encrypt($body, $user, false);
}
if (!$body_to) {
    $body_to = $body;
}
// override of messages send to be able to save versions encrypted for both users
$result = messages_send_override($subject, $body_to, $body_from, $recipient_guid, 0, $reply);
// Save 'send' the message
if (!$result) {
    register_error(elgg_echo("messages:error"));
    forward("messages/compose");
}
elgg_clear_sticky_form('messages');
system_message(elgg_echo("messages:posted"));
forward('messages/inbox/' . elgg_get_logged_in_user_entity()->username);
コード例 #2
0
ファイル: start.php プロジェクト: lorea/Hydra-dev
/**
 * It hijacks the email sender to encrypt the messages if needed.
 * 
 * @param string $hook
 * @param string $type
 * @param bool $return
 * @param array $params Includes $from, $to, $subject, $body and $headers
 * 
 * @return bool
 */
function elggpg_send_email_handler($hook, $type, $return, $params)
{
    $from = $params['from'];
    $to = $params['to'];
    $subject = $params['subject'];
    $body = $params['body'];
    $headers = $params['headers'];
    $receiver = current(get_user_by_email($to));
    // Format message
    $body = html_entity_decode($body, ENT_COMPAT, 'UTF-8');
    // Decode any html entities
    $body = elgg_strip_tags($body);
    // Strip tags from message
    $body = preg_replace("/(\r\n|\r)/", "\n", $body);
    // Convert to unix line endings in body
    $body = preg_replace("/^From/", ">From", $body);
    // Change lines starting with From to >From
    $body = wordwrap($body);
    // Encrypting
    if (elgg_get_plugin_user_setting('encrypt_emails', $receiver->guid, 'elggpg') != 'no') {
        elgg_load_library('elggpg');
        $encrypted_body = elggpg_encrypt($body, $receiver, false);
        if ($encrypted_body) {
            $body = $encrypted_body;
        }
    }
    // The following code is the same that in elgg's
    $header_eol = "\r\n";
    if (elgg_get_config('broken_mta')) {
        // Allow non-RFC 2822 mail headers to support some broken MTAs
        $header_eol = "\n";
    }
    // Windows is somewhat broken, so we use just address for to and from
    if (strtolower(substr(PHP_OS, 0, 3)) == 'win') {
        // strip name from to and from
        if (strpos($to, '<')) {
            preg_match('/<(.*)>/', $to, $matches);
            $to = $matches[1];
        }
        if (strpos($from, '<')) {
            preg_match('/<(.*)>/', $from, $matches);
            $from = $matches[1];
        }
    }
    if (empty($headers)) {
        $headers = "From: {$from}{$header_eol}" . "Content-Type: text/plain; charset=UTF-8; format=flowed{$header_eol}" . "MIME-Version: 1.0{$header_eol}" . "Content-Transfer-Encoding: 8bit{$header_eol}";
    }
    // Sanitise subject by stripping line endings
    $subject = preg_replace("/(\r\n|\r|\n)/", " ", $subject);
    // this is because Elgg encodes everything and matches what is done with body
    $subject = html_entity_decode($subject, ENT_COMPAT, 'UTF-8');
    // Decode any html entities
    if (is_callable('mb_encode_mimeheader')) {
        $subject = mb_encode_mimeheader($subject, "UTF-8", "B");
    }
    return mail($to, $subject, $body, $headers);
}