Example #1
0
 /**
  * Return the next X messages from the mail store
  * FIXME: in CiviCRM 2.2 this always returns all the emails
  *
  * @param int $count  number of messages to fetch FIXME: ignored in CiviCRM 2.2 (assumed to be 0, i.e., fetch all)
  *
  * @return array      array of ezcMail objects
  */
 function fetchNext($count = 0)
 {
     $mails = array();
     $path = rtrim($this->_dir, DIRECTORY_SEPARATOR);
     if ($this->_debug) {
         print "fetching {$count} messages\n";
     }
     $directory = new DirectoryIterator($path);
     foreach ($directory as $entry) {
         if ($entry->isDot()) {
             continue;
         }
         if (count($mails) >= $count) {
             break;
         }
         $file = $path . DIRECTORY_SEPARATOR . $entry->getFilename();
         if ($this->_debug) {
             print "retrieving message {$file}\n";
         }
         $set = new ezcMailFileSet(array($file));
         $parser = new ezcMailParser();
         //set property text attachment as file CRM-5408
         $parser->options->parseTextAttachmentsAsFiles = TRUE;
         $mail = $parser->parseMail($set);
         if (!$mail) {
             return CRM_Core_Error::createAPIError(ts('%1 could not be parsed', array(1 => $file)));
         }
         $mails[$file] = $mail[0];
     }
     if ($this->_debug && count($mails) <= 0) {
         print "No messages found\n";
     }
     return $mails;
 }
 /**
  * Return the next X messages from the mail store
  *
  * @param int $count  number of messages to fetch FIXME: ignored in CiviCRM 2.2 (assumed to be 0, i.e., fetch all)
  *
  * @return array      array of ezcMail objects
  */
 function fetchNext($count = 0)
 {
     $mails = array();
     if ($this->_debug) {
         print "fetching {$count} messages\n";
     }
     $query = "SELECT * FROM mailgun_events WHERE processed = 0 AND ignored = 0";
     $query_params = array();
     if ($count > 0) {
         $query .= " LIMIT %1";
         $query_params[1] = array($count, 'Int');
     }
     $dao = CRM_Core_DAO::executeQuery($query, $query_params);
     while ($dao->fetch()) {
         $set = new ezcMailVariableSet($dao->email);
         $parser = new ezcMailParser();
         //set property text attachment as file CRM-5408
         $parser->options->parseTextAttachmentsAsFiles = TRUE;
         $mail = $parser->parseMail($set);
         if (!$mail) {
             return CRM_Core_Error::createAPIError(ts('Email ID %1 could not be parsed', array(1 => $dao->id)));
         }
         $mails[$dao->id] = $mail[0];
     }
     if ($this->_debug && count($mails) <= 0) {
         print "No messages found\n";
     }
     return $mails;
 }
 public function testFromProcMail()
 {
     $mail_msg = file_get_contents(dirname(__FILE__) . '/data/test-variable');
     $set = new ezcMailVariableSet($mail_msg);
     $parser = new ezcMailParser();
     $mail = $parser->parseMail($set);
     // check that we have no extra linebreaks
     $this->assertEquals("*****@*****.**", $mail[0]->from->email);
 }
Example #4
0
 /**
  * Return the next X messages from the mail store
  * FIXME: in CiviCRM 2.2 this always returns all the emails
  *
  * @param int $count  number of messages to fetch FIXME: ignored in CiviCRM 2.2 (assumed to be 0, i.e., fetch all)
  * @return array      array of ezcMail objects
  */
 function fetchNext($count = 0)
 {
     $mails = array();
     $parser = new ezcMailParser();
     foreach (array('cur', 'new') as $subdir) {
         $dir = $this->_dir . DIRECTORY_SEPARATOR . $subdir;
         foreach (scandir($dir) as $file) {
             if ($file == '.' or $file == '..') {
                 continue;
             }
             $path = $dir . DIRECTORY_SEPARATOR . $file;
             if ($this->_debug) {
                 print "retrieving message {$path}\n";
             }
             $set = new ezcMailFileSet(array($path));
             $single = $parser->parseMail($set);
             $mails[$path] = $single[0];
         }
     }
     return $mails;
 }
Example #5
0
 /**
  * Uses stdin, or the provided data in $mailMessage.
  *
  * @param string $mailMessage
  * @return ezcMvcRequest
  */
 public function createRequest($mailMessage = null)
 {
     if ($mailMessage === null) {
         $set = new ezcMailFileSet(array("php://stdin"));
     } else {
         $set = new ezcMailVariableSet($mailMessage);
     }
     $parser = new ezcMailParser();
     $mail = $parser->parseMail($set);
     if (count($mail) == 0) {
         throw new ezcMvcMailNoDataException();
     }
     $mail = $mail[0];
     $this->request = new ezcMvcRequest();
     $this->processStandardHeaders($mail);
     $this->processAcceptHeaders($mail);
     $this->processUserAgentHeaders($mail);
     $this->processFiles($mail);
     $this->request->raw = $mail;
     return $this->request;
 }
 /**
  * Basics parse
  *
  * @return array / boolean
  */
 public function parse()
 {
     // parse set to mailobject
     $set = new ezcMailVariableSet($this->MailboxItem->getRawMailMessageContent());
     try {
         $ezcMailObjectArray = $this->MailParser->parseMail($set);
     } catch (Exception $e) {
         CjwNewsletterLog::writeError('CjwNewsletterMailparser::parse', 'parseMail', 'ezcMailParser->parseMail-failed', array('error-code' => $e->getMessage()));
         return false;
     }
     if (count($ezcMailObjectArray) > 0) {
         $this->EzcMailObject = $ezcMailObjectArray[0];
         // return standard email headers
         $parsedMailInfosArray = $this->getHeaders();
         // return x-cwl- email headers
         $parsedCjwMailHeaderArray = $this->getCjwHeaders();
         // merge header arrays
         $parseArray = array_merge($parsedMailInfosArray, $parsedCjwMailHeaderArray);
         return $parseArray;
     } else {
         return false;
     }
 }
 public function testUidFetchByFlag()
 {
     $imap = new ezcMailImapTransport(self::$server, self::$port, array('uidReferencing' => true));
     $imap->authenticate(self::$user, self::$password);
     $imap->selectMailbox("inbox");
     $set = $imap->fetchByFlag("undeleted");
     $this->assertEquals(array(self::$ids[0], self::$ids[1], self::$ids[2], self::$ids[3]), $set->getMessageNumbers());
     $parser = new ezcMailParser();
     $mail = $parser->parseMail($set);
     $this->assertEquals(4, count($mail));
 }
Example #8
0
    public function testResolveCids()
    {
        $parser = new ezcMailParser();
        $set = new ezcMailFileSet(array(dirname(__FILE__) . '/parser/data/various/test-html-inline-images'));
        $mail = $parser->parseMail($set);
        $relatedParts = $mail[0]->body->getParts();
        $alternativeParts = $relatedParts[0]->getParts();
        $html = $alternativeParts[1]->getMainPart();
        $convertArray = array('consoletools-table.png@1421450' => 'foo', 'consoletools-table.png@1421452' => 'bar');
        $htmlBody = ezcMailTools::replaceContentIdRefs($html->text, $convertArray);
        $expected = <<<EOFE
<html>
Here is the HTML version of your mail
with an image: <img src='foo'/>
with an image: <img src='cid:consoletools-table.png@1421451'/>
</html>
EOFE;
        self::assertSame($expected, $htmlBody);
    }
Example #9
0
<?php

require_once '/home/dotxp/dev/PHP/zetacomponents/trunk/Base/src/ezc_bootstrap.php';
require_once 'blog_entry.php';
require_once 'blog_entry_creator.php';
$imapOptions = new ezcMailImapTransportOptions();
$imapOptions->ssl = true;
$imap = new ezcMailImapTransport('example.com', 993, $imapOptions);
$imap->authenticate('*****@*****.**', 'foo23bar');
$imap->selectMailbox('Inbox');
$messageSet = $imap->fetchAll();
$parser = new ezcMailParser();
$mails = $parser->parseMail($messageSet);
$blogEntryCreator = new qaBlogEntryCreator();
foreach ($mails as $mail) {
    $entry = $blogEntryCreator->createEntry($mail);
    $entry->save();
}
Example #10
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);
 }
 public function testServerSSL()
 {
     if (!ezcBaseFeatures::hasExtensionSupport('openssl')) {
         $this->markTestSkipped();
     }
     $pop3 = new ezcMailPop3Transport(self::$serverSSL, null, array('ssl' => true));
     $pop3->authenticate(self::$userSSL, self::$passwordSSL);
     $set = $pop3->fetchAll();
     $parser = new ezcMailParser();
     $mail = $parser->parseMail($set);
     $mail = $mail[0];
     $this->assertEquals(240, $mail->size);
 }
Example #12
0
 public function testFetchMailUnknownCharsets()
 {
     $mbox = new ezcMailMboxTransport(dirname(__FILE__) . "/data/unknown-charsets.mbox");
     $set = $mbox->fetchAll();
     $parser = new ezcMailParser();
     $mail = $parser->parseMail($set);
     $this->assertEquals("x-user-defined", $mail[0]->body->originalCharset);
     $this->assertEquals("utf-8", $mail[0]->body->charset);
     $this->assertEquals("Tämä on testiöö1", trim($mail[0]->body->text));
     $this->assertEquals("unknown-8bit", $mail[1]->body->originalCharset);
     $this->assertEquals("utf-8", $mail[1]->body->charset);
     $this->assertEquals("Tämä on testiöö2", trim($mail[1]->body->text));
 }
Example #13
0
 /**
  * Test for issue with extra space after "=" in header (some clients begin filename from new line and with \t prepended)
  */
 public function testSpaceBeforeFileName()
 {
     $parser = new ezcMailParser();
     $messages = array(array("Content-Disposition: attachment; filename=\r\n\t\"=?iso-8859-1?q?Lettre=20de=20motivation=20directeur=20de=20client=E8le.doc?=\"\r\n", "Lettre de motivation directeur de clientèle.doc"));
     foreach ($messages as $msg) {
         $set = new ezcMailVariableSet($msg[0]);
         $mail = $parser->parseMail($set);
         $mail = $mail[0];
         // check the body
         $this->assertEquals($msg[1], $mail->contentDisposition->displayFileName);
     }
 }
Example #14
0
 /**
  * Returns the temporary directory.
  *
  * Uses the PHP 5.2.1 function sys_get_temp_dir().
  *
  * Note that the directory name returned will have a "slash" at the end
  * ("/" for Linux and "\" for Windows).
  *
  * @return string
  */
 public static function getTmpDir()
 {
     if (self::$tmpDir === null) {
         self::$tmpDir = sys_get_temp_dir();
         if (substr(self::$tmpDir, strlen(self::$tmpDir) - 1) !== DIRECTORY_SEPARATOR) {
             self::$tmpDir = self::$tmpDir . DIRECTORY_SEPARATOR;
         }
     }
     return self::$tmpDir;
 }
Example #15
0
 /**
  * Return the next X messages from the mail store
  *
  * @param int $count  number of messages to fetch (0 to fetch all)
  * @return array      array of ezcMail objects
  */
 function fetchNext($count = 1)
 {
     if (isset($this->_transport->options->uidReferencing) and $this->_transport->options->uidReferencing) {
         $offset = array_shift($this->_transport->listUniqueIdentifiers());
     } else {
         $offset = 1;
     }
     try {
         $set = $this->_transport->fetchFromOffset($offset, $count);
         if ($this->_debug) {
             print "fetching {$count} messages\n";
         }
     } catch (ezcMailOffsetOutOfRangeException $e) {
         if ($this->_debug) {
             print "got to the end of the mailbox\n";
         }
         return array();
     }
     $mails = array();
     $parser = new ezcMailParser();
     //set property text attachment as file CRM-5408
     $parser->options->parseTextAttachmentsAsFiles = true;
     foreach ($set->getMessageNumbers() as $nr) {
         if ($this->_debug) {
             print "retrieving message {$nr}\n";
         }
         $single = $parser->parseMail($this->_transport->fetchByMessageNr($nr));
         $mails[$nr] = $single[0];
     }
     return $mails;
 }
Example #16
0
 /**
  * Test for issue 15456: Problems with parsing emails that have "charset = " instead of "charset="
  */
 public function testCharsetHeader()
 {
     $parser = new ezcMailParser();
     $set = new SingleFileSet('various/mail-with-broken-charset-header');
     $mail = $parser->parseMail($set);
     $mail = $mail[0];
     $parts = $mail->fetchParts();
     $this->assertEquals("wir können Ihnen mitteilen, dass einer Ihrer\n", $parts[0]->text);
 }
Example #17
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);
 }
Example #18
0
 public function testKmail1()
 {
     $parser = new ezcMailParser();
     $set = new SingleFileSetMP('kmail/mail_with_attachment.mail');
     $mail = $parser->parseMail($set);
 }
Example #19
0
 /**
  * Forward a mailing reply 
  *
  * @param int $queue_id     Queue event ID of the sender
  * @param string $mailing   The mailing object
  * @param string $bodyTxt   text part of the body (ignored if $fullEmail provided)
  * @param string $replyto   Reply-to of the incoming message
  * @param string $bodyHTML  HTML part of the body (ignored if $fullEmail provided)
  * @param string $fullEmail whole email to forward in one string
  * @return void
  * @access public
  * @static
  */
 public static function send($queue_id, &$mailing, &$bodyTxt, $replyto, &$bodyHTML = null, &$fullEmail = null)
 {
     if ($fullEmail) {
         // parse the email and set a new destination
         $parser = new ezcMailParser();
         $set = new ezcMailVariableSet($fullEmail);
         $parsed = array_shift($parser->parseMail($set));
         $parsed->to = array(new ezcMailAddress($mailing->replyto_email));
         // CRM-5567: we need to set Reply-To: so that any response
         // to the forward goes to the sender of the reply
         $parsed->setHeader('Reply-To', empty($replyto) ? $parsed->from->__toString() : $replyto);
         // $h must be an array, so we can't use generateHeaders()'s result,
         // but we have to regenerate the headers because we changed To
         $parsed->generateHeaders();
         $h = $parsed->headers->getCaseSensitiveArray();
         $b = $parsed->generateBody();
         // strip Return-Path of possible bounding brackets, CRM-4502
         $h['Return-Path'] = trim($h['Return-Path'], '<>');
         // FIXME: ugly hack - find the first MIME boundary in
         // the body and make the boundary in the header match it
         $ct =& $h['Content-Type'];
         if (substr_count($ct, 'boundary=')) {
             $matches = array();
             preg_match('/^--(.*)$/m', $b, $matches);
             $boundary = rtrim($matches[1]);
             $parts = explode('boundary=', $ct);
             $ct = "{$parts[0]} boundary=\"{$boundary}\"";
         }
     } else {
         $domain =& CRM_Core_BAO_Domain::getDomain();
         $emails = CRM_Core_BAO_Email::getTableName();
         $eq = CRM_Mailing_Event_BAO_Queue::getTableName();
         $contacts = CRM_Contact_BAO_Contact::getTableName();
         $dao =& new CRM_Core_DAO();
         $dao->query("SELECT     {$contacts}.display_name as display_name,\n                                    {$emails}.email as email\n                        FROM        {$eq}\n                        INNER JOIN  {$contacts}\n                                ON  {$eq}.contact_id = {$contacts}.id\n                        INNER JOIN  {$emails}\n                                ON  {$eq}.email_id = {$emails}.id\n                        WHERE       {$eq}.id = " . CRM_Utils_Type::escape($queue_id, 'Integer'));
         $dao->fetch();
         if (empty($dao->display_name)) {
             $from = $dao->email;
         } else {
             $from = "\"{$dao->display_name}\" <{$dao->email}>";
         }
         require_once 'CRM/Core/BAO/MailSettings.php';
         $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
         // we need to wrap Mail_mime because PEAR is apparently unable to fix
         // a six-year-old bug (PEAR bug #30) in Mail_mime::_encodeHeaders()
         // this fixes CRM-5466
         require_once 'CRM/Utils/Mail/FixedMailMIME.php';
         $message =& new CRM_Utils_Mail_FixedMailMIME("\n");
         $headers = array('Subject' => "Re: {$mailing->subject}", 'To' => $mailing->replyto_email, 'From' => $from, 'Reply-To' => empty($replyto) ? $dao->email : $replyto, 'Return-Path' => "do-not-reply@{$emailDomain}");
         $message->setTxtBody($bodyTxt);
         $message->setHTMLBody($bodyHTML);
         $b =& CRM_Utils_Mail::setMimeParams($message);
         $h =& $message->headers($headers);
     }
     $config =& CRM_Core_Config::singleton();
     $mailer =& $config->getMailer();
     PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Core_Error', 'nullHandler'));
     if (is_object($mailer)) {
         $mailer->send($mailing->replyto_email, $h, $b);
         CRM_Core_Error::setCallback();
     }
 }
Example #20
0
 /**
  * Test for issue #13539: Add new mail parser option fileClass.
  */
 public function testParserCustomFileClass()
 {
     $parser = new ezcMailParser();
     $parser->options->fileClass = 'myCustomFileClass';
     // to catch also the case with a custom mail class (it doesn't influence the test)
     $parser->options->mailClass = 'ExtendedMail';
     $set = new SingleFileSet('various/test-html-text-and-attachment');
     $mail = $parser->parseMail($set);
     $mail = $mail[0];
     $parts = $mail->fetchParts(null, false);
     $expected = array('ezcMailText', 'ezcMailText', 'myCustomFileClass', 'myCustomFileClass');
     $this->assertEquals(4, count($parts));
     for ($i = 0; $i < count($parts); $i++) {
         $this->assertEquals($expected[$i], get_class($parts[$i]));
     }
 }
Example #21
0
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */
require_once "../tutorial/tutorial_autoload.php";
$set = new ezcMailFileSet(array($argv[1]));
$parser = new ezcMailParser();
$mail = $parser->parseMail($set);
echo formatMail($mail[0]);
function formatMail($mail)
{
    $t = '';
    $t .= "From:      " . formatAddress($mail->from) . "\n";
    $t .= "To:        " . formatAddresses($mail->to) . "\n";
    $t .= "Cc:        " . formatAddresses($mail->cc) . "\n";
    $t .= "Bcc:       " . formatAddresses($mail->bcc) . "\n";
    $t .= 'Date:      ' . date(DATE_RFC822, $mail->timestamp) . "\n";
    $t .= 'Subject:   ' . $mail->subject . "\n";
    $t .= "MessageId: " . $mail->messageId . "\n";
    $t .= "\n";
    $t .= formatMailPart($mail->body);
    return $t;
Example #22
0
 /**
  * Get the password reset URL.
  *
  * @return string
  */
 public static function getPasswordResetURL()
 {
     $options = new \ezcMailImapTransportOptions();
     $options->ssl = true;
     $imap = new \ezcMailImapTransport('imap.gmail.com', null, $options);
     $imap->authenticate('*****@*****.**', Config::get('kinvey::testMail'));
     $imap->selectMailbox('Inbox');
     $set = $imap->searchMailbox('FROM "*****@*****.**"');
     $parser = new \ezcMailParser();
     $mail = $parser->parseMail($set);
     preg_match("#https.*#", $mail[0]->generateBody(), $matches);
     $url = html_entity_decode($matches[0]);
     $url = mb_substr($url, 0, -1);
     foreach ($set->getMessageNumbers() as $msgNum) {
         $imap->delete($msgNum);
     }
     $imap->expunge();
     return $url;
 }
Example #23
0
 /**
  * @param $file
  *
  * @return array
  * @throws Exception
  */
 public function &parse(&$file)
 {
     // check that the file exists and has some content
     if (!file_exists($file) || !trim(file_get_contents($file))) {
         return CRM_Core_Error::createAPIError(ts('%1 does not exists or is empty', array(1 => $file)));
     }
     require_once 'ezc/Base/src/ezc_bootstrap.php';
     require_once 'ezc/autoload/mail_autoload.php';
     // explode email to digestable format
     $set = new ezcMailFileSet(array($file));
     $parser = new ezcMailParser();
     $mail = $parser->parseMail($set);
     if (!$mail) {
         return CRM_Core_Error::createAPIError(ts('%1 could not be parsed', array(1 => $file)));
     }
     // since we only have one fileset
     $mail = $mail[0];
     $mailParams = self::parseMailingObject($mail);
     return $mailParams;
 }
Example #24
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]));
     }
 }
Example #25
0
 /**
  * Fetch the specified message to the local processed folder
  *
  * @param integer $nr  number of the message to fetch
  * @return void
  */
 function markProcessed($nr)
 {
     if ($this->_debug) {
         print "fetching message {$nr} and putting it in the processed mailbox\n";
     }
     $set = new ezcMailStorageSet($this->_transport->fetchByMessageNr($nr), $this->_processed);
     $parser = new ezcMailParser();
     $parser->parseMail($set);
     $this->_transport->delete($nr);
 }
Example #26
0
 /**
  * Forward a mailing reply.
  *
  * @param int $queue_id
  *   Queue event ID of the sender.
  * @param string $mailing
  *   The mailing object.
  * @param string $bodyTxt
  *   Text part of the body (ignored if $fullEmail provided).
  * @param string $replyto
  *   Reply-to of the incoming message.
  * @param string $bodyHTML
  *   HTML part of the body (ignored if $fullEmail provided).
  * @param string $fullEmail
  *   Whole email to forward in one string.
  *
  * @return void
  */
 public static function send($queue_id, &$mailing, &$bodyTxt, $replyto, &$bodyHTML = NULL, &$fullEmail = NULL)
 {
     $domain = CRM_Core_BAO_Domain::getDomain();
     $emails = CRM_Core_BAO_Email::getTableName();
     $queue = CRM_Mailing_Event_BAO_Queue::getTableName();
     $contacts = CRM_Contact_BAO_Contact::getTableName();
     $eq = new CRM_Core_DAO();
     $eq->query("SELECT     {$contacts}.display_name as display_name,\n                           {$emails}.email as email,\n                           {$queue}.job_id as job_id,\n                           {$queue}.hash as hash\n                   FROM        {$queue}\n                   INNER JOIN  {$contacts}\n                           ON  {$queue}.contact_id = {$contacts}.id\n                   INNER JOIN  {$emails}\n                           ON  {$queue}.email_id = {$emails}.id\n                   WHERE       {$queue}.id = " . CRM_Utils_Type::escape($queue_id, 'Integer'));
     $eq->fetch();
     if ($fullEmail) {
         // parse the email and set a new destination
         $parser = new ezcMailParser();
         $set = new ezcMailVariableSet($fullEmail);
         $parsed = array_shift($parser->parseMail($set));
         $parsed->to = array(new ezcMailAddress($mailing->replyto_email));
         // CRM-5567: we need to set Reply-To: so that any response
         // to the forward goes to the sender of the reply
         $parsed->setHeader('Reply-To', $replyto instanceof ezcMailAddress ? $replyto : $parsed->from->__toString());
         // $h must be an array, so we can't use generateHeaders()'s result,
         // but we have to regenerate the headers because we changed To
         $parsed->generateHeaders();
         $h = $parsed->headers->getCaseSensitiveArray();
         $b = $parsed->generateBody();
         // strip Return-Path of possible bounding brackets, CRM-4502
         if (!empty($h['Return-Path'])) {
             $h['Return-Path'] = trim($h['Return-Path'], '<>');
         }
         // FIXME: ugly hack - find the first MIME boundary in
         // the body and make the boundary in the header match it
         $ct = $h['Content-Type'];
         if (substr_count($ct, 'boundary=')) {
             $matches = array();
             preg_match('/^--(.*)$/m', $b, $matches);
             $boundary = rtrim($matches[1]);
             $parts = explode('boundary=', $ct);
             $ct = "{$parts[0]} boundary=\"{$boundary}\"";
         }
     } else {
         $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
         if (empty($eq->display_name)) {
             $from = $eq->email;
         } else {
             $from = "\"{$eq->display_name}\" <{$eq->email}>";
         }
         $message = new Mail_mime("\n");
         $headers = array('Subject' => "Re: {$mailing->subject}", 'To' => $mailing->replyto_email, 'From' => $from, 'Reply-To' => empty($replyto) ? $eq->email : $replyto, 'Return-Path' => "do-not-reply@{$emailDomain}");
         $message->setTxtBody($bodyTxt);
         $message->setHTMLBody($bodyHTML);
         $b = CRM_Utils_Mail::setMimeParams($message);
         $h = $message->headers($headers);
     }
     CRM_Mailing_BAO_Mailing::addMessageIdHeader($h, 'r', $eq->job_id, $queue_id, $eq->hash);
     $config = CRM_Core_Config::singleton();
     $mailer = $config->getMailer();
     if (is_object($mailer)) {
         $errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
         $mailer->send($mailing->replyto_email, $h, $b);
         unset($errorScope);
     }
 }
Example #27
0
 /**
  * Returns the filepointer of the opened file $fileName in a unique directory..
  *
  * This method will create a new unique folder in the temporary directory specified in ezcMailParser.
  * The fileName property of this class will be set to the location of the new file.
  *
  * @throws ezcBaseFileNotFoundException
  *         if the file could not be opened.
  * @param string $fileName
  * @return resource
  */
 private function openFile($fileName)
 {
     // The filename is now relative, we need to extend it with the absolute path.
     // To provide uniqueness we put the file in a directory based on processID and rand.
     $dirName = ezcMailParser::getTmpDir() . getmypid() . '-' . self::$counter++ . '/';
     if (!is_dir($dirName)) {
         mkdir($dirName, 0700);
     }
     // remove the directory and the file when PHP shuts down
     ezcMailParserShutdownHandler::registerForRemoval($dirName);
     $this->fileName = $dirName . $fileName;
     $fp = fopen($this->fileName, 'w');
     if ($this->fp === false) {
         throw new ezcBaseFileNotFoundException($this->fileName);
     }
     return $fp;
 }
Example #28
0
 /**
  * Test modified for issue #14776: ezcMailStorageSet generates bad file names.
  */
 public function testGetSourceFileNames()
 {
     $transport = new ezcMailImapTransport("mta1.ez.no");
     $transport->authenticate("*****@*****.**", "ezcomponents");
     $transport->selectMailbox("Inbox");
     $parser = new ezcMailParser();
     $set = new ezcMailStorageSet($transport->fetchAll(), $this->tempDir);
     $mail = $parser->parseMail($set);
     $files = $set->getSourceFiles();
     $expected = array(getmypid() . '-' . time() . '-' . 1, getmypid() . '-' . time() . '-' . 2, getmypid() . '-' . time() . '-' . 3, getmypid() . '-' . time() . '-' . 4);
     for ($i = 0; $i < count($files); $i++) {
         $this->assertEquals($expected[$i], basename($files[$i]));
     }
 }
 /**
  * @param string $msg
  *   Email header and body.
  * @return ezcMail
  */
 private function convertToEzc($msg)
 {
     $set = new ezcMailVariableSet($msg);
     $parser = new ezcMailParser();
     $mail = $parser->parseMail($set);
     $this->_ut->assertNotEmpty($mail, 'Cannot parse mail');
     return $mail[0];
 }
Example #30
0
 /**
  * Fetch the specified message to the local processed folder
  *
  * @param integer $nr  number of the message to fetch
  *
  * @return void
  */
 function markProcessed($nr)
 {
     if ($this->_debug) {
         print "copying message {$nr} to processed folder\n";
     }
     $set = new ezcMailStorageSet($this->_transport->fetchByMessageNr($nr), $this->_processed);
     $parser = new ezcMailParser();
     $parser->parseMail($set);
     $this->_leftToProcess--;
 }