Пример #1
0
 /**
  * Test for issue #16154: Bcc headers are not stripped when using SMTP
  */
 public function testStripBccHeader()
 {
     $options = new ezcMailOptions();
     $options->stripBccHeader = true;
     $mail = new ezcMail($options);
     $mail->from = new ezcMailAddress("*****@*****.**", "No Spam 1");
     $mail->addTo(new ezcMailAddress("*****@*****.**", "No Spam 2"));
     $mail->addBcc(new ezcMailAddress("*****@*****.**", "No Spam 3"));
     $mail->subject = __FUNCTION__;
     $source = $mail->generate();
     // Assert that the mail source doesn't contain the Bcc header
     $this->assertEquals(false, strpos($source, "Bcc: "));
 }
Пример #2
0
 public function testMailHeaderFolding76Char()
 {
     $mail = new ezcMail();
     $mail->from = new ezcMailAddress('*****@*****.**', 'John Doe');
     $mail->addTo(new ezcMailAddress('*****@*****.**', 'John Doe'));
     $mail->body = new ezcMailText('Text');
     // test some subject sizes
     for ($i = 1; $i < 300; $i++) {
         $mail->subject = str_repeat('1', $i);
         $source = $mail->generate();
         preg_match('/Subject:\\s[0-9]+/', $source, $matches);
         $this->assertEquals(1, count($matches), "Subject is folded incorrectly for length {$i}.");
     }
 }
 /**
  * Sends the ezcMail $mail using the SMTP protocol.
  *
  * If you want to send several emails use keepConnection() to leave the
  * connection to the server open between each mail.
  *
  * @throws ezcMailTransportException
  *         if the mail could not be sent
  * @throws ezcBaseFeatureNotFoundException
  *         if trying to use SSL and the openssl extension is not installed
  * @param ezcMail $mail
  */
 public function send(ezcMail $mail)
 {
     // sanity check the e-mail
     // need at least one recepient
     if (count($mail->to) + count($mail->cc) + count($mail->bcc) < 1) {
         throw new ezcMailTransportException("Can not send e-mail with no 'to' recipients.");
     }
     try {
         // open connection unless we are connected already.
         if ($this->status != self::STATUS_AUTHENTICATED) {
             $this->connect();
         }
         if (isset($mail->returnPath)) {
             $this->cmdMail($mail->returnPath->email);
         } else {
             $this->cmdMail($mail->from->email);
         }
         // each recepient must be listed here.
         // this controls where the mail is actually sent as SMTP does not
         // read the headers itself
         foreach ($mail->to as $address) {
             $this->cmdRcpt($address->email);
         }
         foreach ($mail->cc as $address) {
             $this->cmdRcpt($address->email);
         }
         foreach ($mail->bcc as $address) {
             $this->cmdRcpt($address->email);
         }
         // done with the from and recipients, lets send the mail itself
         $this->cmdData();
         // A '.' on a line ends the mail. Make sure this does not happen in
         // the data we want to send.  also called transparancy in the RFC,
         // section 4.5.2
         $data = $mail->generate();
         $data = str_replace(self::CRLF . '.', self::CRLF . '..', $data);
         if ($data[0] == '.') {
             $data = '.' . $data;
         }
         $this->sendData($data);
         $this->sendData('.');
         if ($this->getReplyCode($error) !== '250') {
             throw new ezcMailTransportSmtpException("Error: {$error}");
         }
     } catch (ezcMailTransportSmtpException $e) {
         throw new ezcMailTransportException($e->getMessage());
         // TODO: reset connection here.pin
     }
     // close connection unless we should keep it
     if ($this->keepConnection === false) {
         try {
             $this->disconnect();
         } catch (Exception $e) {
             // Eat! We don't care anyway since we are aborting the connection
         }
     }
 }
Пример #4
0
 public function testMultipartReportFetchParts()
 {
     $mail = new ezcMail();
     $mail->from = new ezcMailAddress('*****@*****.**', 'Frederik Holljen');
     $mail->addTo(new ezcMailAddress('*****@*****.**', 'Frederik Holljen'));
     $mail->subject = "Report";
     $mail->subjectCharset = 'iso-8859-1';
     $delivery = new ezcMailDeliveryStatus();
     $delivery->message["Reporting-MTA"] = "dns; www.brssolutions.com";
     $lastRecipient = $delivery->createRecipient();
     $delivery->recipients[$lastRecipient]["Action"] = "failed";
     $mail->body = new ezcMailMultipartReport(new ezcMailText("Dette er body ßßæøååå", "iso-8859-1"), $delivery, new ezcMailText("The content initially sent"));
     $this->assertEquals("delivery-status", $mail->body->reportType);
     $msg = $mail->generate();
     $set = new ezcMailVariableSet($msg);
     $parser = new ezcMailParser();
     $mail = $parser->parseMail($set);
     $mail = $mail[0];
     $parts = $mail->fetchParts(null, true);
     $expected = array('ezcMailText', 'ezcMailDeliveryStatus', 'ezcMailText');
     $this->assertEquals(3, count($parts));
     for ($i = 0; $i < count($parts); $i++) {
         $this->assertEquals($expected[$i], get_class($parts[$i]));
     }
 }
Пример #5
0
 public function testTagInHeadersAndBody()
 {
     $imap = new ezcMailImapTransport(self::$server, self::$port);
     $imap->authenticate(self::$user, self::$password);
     $imap->createMailbox("Guybrush");
     $mail = new ezcMail();
     $mail->from = new ezcMailAddress('*****@*****.**', 'From');
     $mail->addTo(new ezcMailAddress('*****@*****.**', 'To'));
     $mail->subject = "A0000 A0001 A0002 A0003 A0004 A0005 A0006 A0007";
     $mail->body = new ezcMailText("A0000\nA0001\nA0002\nA0003\nA0004\nA0005\nA0006\nA0007");
     $data = $mail->generate();
     $imap->append("Guybrush", $data);
     $imap->append("Guybrush", $data, array('Answered'));
     $imap->selectMailbox("Guybrush");
     $set = $imap->fetchAll();
     $parser = new ezcMailParser();
     $mail = $parser->parseMail($set);
     $mail = $mail[0];
     $imap->selectMailbox("Inbox");
     $imap->deleteMailbox("Guybrush");
     $this->assertEquals('A0000 A0001 A0002 A0003 A0004 A0005 A0006 A0007', $mail->subject);
 }
Пример #6
0
 public function testContentDispositionLongHeader()
 {
     $mail = new ezcMail();
     $mail->from = new ezcMailAddress('*****@*****.**');
     $mail->subject = "яверасфăîţâşåæøåöä";
     $mail->addTo(new ezcMailAddress('*****@*****.**'));
     $file = new ezcMailFile(dirname(__FILE__) . "/parts/data/fly.jpg");
     $file->contentDisposition = new ezcMailContentDispositionHeader('attachment', 'яверасфăîţâşåæøåöäabcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz.jpg');
     $mail->body = new ezcMailMultipartMixed(new ezcMailText('xxx'), $file);
     $msg = $mail->generate();
     $set = new ezcMailVariableSet($msg);
     $parser = new ezcMailParser();
     $mail = $parser->parseMail($set);
     $parts = $mail[0]->fetchParts();
     // for issue #13038, displayFileName was added to contentDisposition
     $file->contentDisposition->displayFileName = 'яверасфăîţâşåæøåöäabcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz.jpg';
     $this->assertEquals($file->contentDisposition, $parts[1]->contentDisposition);
 }
Пример #7
0
$mailAddresses = array(new ezcMailAddress('*****@*****.**', 'Jøhn Doe', 'ISO-8859-1'), new ezcMailAddress('*****@*****.**', 'Jane Doe'));
$addresses = '=?ISO-8859-1?B?SsO4aG4gRG9l?= <*****@*****.**>, Jane Doe <*****@*****.**';
// Convert ezcMailAddress to string representation
var_dump(ezcMailTools::composeEmailAddress($mailAddresses[0]));
var_dump(ezcMailTools::composeEmailAddresses($mailAddresses));
// Convert string to ezcMailAddress
var_dump(ezcMailTools::parseEmailAddress($addresses));
var_dump(ezcMailTools::parseEmailAddresses($addresses));
// Validate an email address (with a regular expression, without checking for MX records)
$isValid = ezcMailTools::validateEmailAddress('*****@*****.**');
// Validate an email address with MX records check.
// MX record checking does not work on Windows due to the lack of getmxrr()
// and checkdnsrr() PHP functions. The ezcBaseFunctionalityNotSupportedException
// is thrown in this case.
// set this to your mail server, it is used in a
// 'HELO SMTP' command to validate against MX records
ezcMailTools::$mxValidateServer = 'your.mail.server';
// set this to a mail address such as '*****@*****.**', it is used in a
// 'MAIL FROM' SMTP command to validate against MX records
ezcMailTools::$mxValidateAddress = '*****@*****.**';
$isValid = ezcMailTools::validateEmailAddress('*****@*****.**', true);
// Create a new mail object
$mail = new ezcMail();
$mail->from = $mailAddresses[1];
$mail->addTo($mailAddresses[0]);
$mail->subject = "Top secret";
// Use the lineBreak() method
$mail->body = new ezcMailText("Confidential" . ezcMailTools::lineBreak() . "DO NOT READ");
$mail->generate();
// Create a reply message to the previous mail object
$reply = ezcMailTools::replyToMail($mail, new ezcMailAddress('*****@*****.**', 'Reply Guy'));