<?php
/**
 * @package Am_Mail
 * @todo put into a separate file for lazy-loading
 */
class Am_Mail_Transport_Smtp extends Zend_Mail_Transport_Smtp implements Am_Mail_Transport_Iface
{
    public function _sendMail()
    {
        $_ = parent::_sendMail(); // TODO: Change the autogenerated stub
        $this->getConnection()->resetLog(); // workaround for memory overusage
        return $_;
    }

    function sendFromSaved($from, $recipients, $body, array $headers, $subject, $EOL)
    {
        if ($EOL !== $this->EOL)
        {
            $my_eol = $EOL;
            $t_eol = $this->EOL;
            $body = str_replace($my_eol, $t_eol, $body);
            $headers = array_map(
                function ($_) use ($my_eol, $t_eol) {
                    return str_replace($my_eol, $t_eol, $_);
                },
                $headers
            );
        }

        $this->_mail = new Am_Mail_Saved;
        $this->_mail->from = $from;
        $this->_mail->subject = $subject;
        $this->_mail->recipients = explode(',', $recipients);
        $this->recipients = $recipients;
        $this->body = $body;
        $this->_prepareHeaders($headers);
        $this->_sendMail();
    }
}