Changeset 38 for trunk/lib


Ignore:
Timestamp:
Dec 15, 2005 1:28:09 AM (19 years ago)
Author:
scdev
Message:

added extra headers option to Email:: and fixed confusion over \r\n

Location:
trunk/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/App.inc.php

    r37 r38  
    10031003        }
    10041004       
    1005         if ('on' != getenv('HTTPS') && $this->getParam('ssl_enabled') && preg_match('/mod_ssl/i', getenv('SERVER_SOFTWARE'))) {
     1005        if (function_exists('apache_get_modules')) {
     1006            $modules = apache_get_modules();
     1007        } else {
     1008            // It's safe to assume we have mod_ssl if we can't determine otherwise.
     1009            $modules = array('mod_ssl');
     1010        }
     1011       
     1012        if ('on' != getenv('HTTPS') && $this->getParam('ssl_enabled') && in_array('mod_ssl', $modules)) {
    10061013            $this->raiseMsg(sprintf(_("Secure SSL connection made to %s"), $this->getParam('ssl_domain')), MSG_NOTICE, __FILE__, __LINE__);
    10071014            // Always append session because some browsers do not send cookie when crossing to SSL URL.
  • trunk/lib/Email.inc.php

    r37 r38  
    3636        'from' => null,
    3737        'subject' => null,
     38        'headers' => null,
    3839        'regex' => null
    3940    );
     
    207208     * @since   28 Nov 2005 12:56:09
    208209     */
    209     function send($to=null, $from=null, $subject=null)
     210    function send($to=null, $from=null, $subject=null, $headers=null)
    210211    {
    211212        // Use arguments if provided.
     
    219220             $this->setParam(array('subject' => $subject));
    220221        }
     222        if (isset($headers)) {
     223             $this->setParam(array('headers' => $headers));
     224        }
    221225
    222226        // Ensure required values exist.
     
    248252       
    249253        // From headers are custom headers.
    250         $headers = sprintf("From: %s\r\n\r\n", $this->_params['from']);
     254        $headers = array('From' => $this->_params['from']);
     255
     256        // Additional headers.
     257        if (isset($this->_params['headers']) && is_array($this->_params['headers'])) {
     258            $headers = array_merge($this->_params['headers'], $headers);
     259        }
     260       
     261        // Process headers.
     262        $final_headers = array();
     263        foreach ($headers as $key => $val) {
     264            $final_headers[] = sprintf('%s: %s', $key, $val);
     265        }
     266        $final_headers = join("\r\n", $final_headers);
    251267       
    252268        // This is the address where delivery problems are sent to. We must strip off everything except the local@domain part.
     
    254270       
    255271        // Check for mail header injection attacks.
    256         $full_mail_content = join("\n", array($final_to, $this->_params['subject'], $final_body, $headers, $envelope_sender_header));
     272        $full_mail_content = join("\n", array($final_to, $this->_params['subject'], $final_body, $final_headers, $envelope_sender_header));
    257273        if (preg_match("/(Content-Type:|MIME-Version:|Content-Transfer-Encoding:|[\n\r]Bcc:|[\n\r]Cc:)/i", $full_mail_content)) {
    258274            App::logMsg(sprintf('Mail header injection attack in content: %s', $full_mail_content), LOG_WARNING, __FILE__, __LINE__);
     
    262278
    263279        // Ensure message was successfully accepted for delivery.
    264         if (!mail($final_to, $this->_params['subject'], $final_body, $headers, $envelope_sender_header)) {
    265             App::logMsg(sprintf('Email failure with parameters: %s, %s, %s, %s', $this->_params['to'], $this->_params['subject'], str_replace("\r\n", '', $headers), $envelope_sender_header), LOG_NOTICE, __FILE__, __LINE__);
     280        if (!mail($final_to, $this->_params['subject'], $final_body, $final_headers, $envelope_sender_header)) {
     281            App::logMsg(sprintf('Email failure with parameters: %s, %s, %s, %s', $this->_params['to'], $this->_params['subject'], str_replace("\r\n", '', $final_headers), $envelope_sender_header), LOG_NOTICE, __FILE__, __LINE__);
    266282            return false;
    267283        }
  • trunk/lib/MCVE.inc.php

    r37 r38  
    2626            trigger_error('MCVE class instantiation failed: MCVE extension not available.', E_USER_WARNING);
    2727            die;
     28        }
     29        if ('' == $username || '' == $password) {
     30            App::logMsg(sprintf('Empty username or password provided.', null), LOG_ERR, __FILE__, __LINE__);
    2831        }
    2932        $this->username = $username;
Note: See TracChangeset for help on using the changeset viewer.