/** * Constructor. * * @param string $host * @param integer $port * @param array $config * @return void * @throws Zend_Mail_Protocol_Exception */ public function __construct($host = '127.0.0.1', $port = null, array $config = array()) { if (isset($config['ssl'])) { switch (strtolower($config['ssl'])) { case 'tls': $this->_secure = 'tls'; break; case 'ssl': $this->_transport = 'ssl'; $this->_secure = 'ssl'; if ($port == null) { $port = 465; } break; default: /** * @see Zend_Mail_Protocol_Exception */ require_once 'Zend/Mail/Protocol/Exception.php'; throw new Zend_Mail_Protocol_Exception($config['ssl'] . ' is unsupported SSL type'); break; } } // If no port has been specified then check the master PHP ini file. Defaults to 25 if the ini setting is null. if ($port == null) { if (($port = ini_get('smtp_port')) == '') { $port = 25; } } parent::__construct($host, $port); }
/** * test line end encoding of Zend_Mime_Part / Smtp Protocol */ public function testSendWithWrongLineEnd() { $config = TestServer::getInstance()->getConfig(); $mailDomain = $config->maildomain ? $config->maildomain : 'tine20.org'; // build message with wrong line end rfc822 part $mail = new Tinebase_Mail('utf-8'); $mail->setBodyText('testmail' . "\r\n" . "\r\n"); $mail->setFrom('unittest@' . $mailDomain, 'unittest'); $mail->setSubject('line end test'); $mail->addTo('unittest@' . $mailDomain); $mail->addHeader('X-Tine20TestMessage', 'lineend'); // replace EOLs $content = file_get_contents(dirname(dirname(__FILE__)) . '/files/text_plain.eml'); $content = preg_replace("/\\x0a/", "\r\n", $content); $stream = fopen("php://temp", 'r+'); fputs($stream, $content); rewind($stream); $attachment = new Zend_Mime_Part($stream); $attachment->type = Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822; $attachment->encoding = null; $attachment->charset = 'ISO-8859-1'; $attachment->filename = 'attach.eml'; $attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT; $mail->addAttachment($attachment); $smtpConfig = $this->_account->getSmtpConfig(); $transport = new Felamimail_Transport($smtpConfig['hostname'], $smtpConfig); Zend_Mail_Protocol_Abstract::$loggingEnabled = true; $mail->send($transport); Zend_Mail_Protocol_Abstract::$loggingEnabled = false; $smtpLog = $transport->getConnection()->getLog(); $badLineEndCount = preg_match_all("/\\x0d\\x0d\\x0a/", $smtpLog, $matches); $this->assertEquals(0, $badLineEndCount); $badLineEndCount = preg_match_all("/\\x0d/", $smtpLog, $matches); $this->assertTrue(preg_match_all("/\\x0d/", $smtpLog, $matches) > 70, 'unix line ends are missing'); }