3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Class CRM_Mailing_MailStore_Localdir
21 class CRM_Mailing_MailStore_Localdir
extends CRM_Mailing_MailStore
{
24 * Connect to the supplied dir and make sure the two mail dirs exist.
27 * Dir to operate upon.
29 * @return \CRM_Mailing_MailStore_Localdir
31 public function __construct($dir) {
34 $this->_ignored
= $this->maildir(implode(DIRECTORY_SEPARATOR
, [
40 $this->_processed
= $this->maildir(implode(DIRECTORY_SEPARATOR
, [
49 * Return the next X messages from the mail store.
50 * FIXME: in CiviCRM 2.2 this always returns all the emails
53 * Number of messages to fetch FIXME: ignored in CiviCRM 2.2 (assumed to be 0, i.e., fetch all).
56 * array of ezcMail objects
58 public function fetchNext($count = 0) {
60 $path = rtrim($this->_dir
, DIRECTORY_SEPARATOR
);
64 print "fetching $count messages\n";
68 $directory = new DirectoryIterator($path);
69 foreach ($directory as $entry) {
70 if ($entry->isDot()) {
73 if (count($mails) >= $count) {
77 $file = $path . DIRECTORY_SEPARATOR
. $entry->getFilename();
79 print "retrieving message $file\n";
82 $set = new ezcMailFileSet([$file]);
83 $parser = new ezcMailParser();
84 // set property text attachment as file CRM-5408
85 $parser->options
->parseTextAttachmentsAsFiles
= TRUE;
87 $mail = $parser->parseMail($set);
90 return CRM_Core_Error
::createAPIError(ts('%1 could not be parsed',
94 $mails[$file] = $mail[0];
97 if ($this->_debug
&& (count($mails) <= 0)) {
99 print "No messages found\n";
107 * Fetch the specified message to the local ignore folder.
110 * File location of the message to fetch.
114 public function markIgnored($file) {
116 print "moving $file to ignored folder\n";
118 $target = $this->_ignored
. DIRECTORY_SEPARATOR
. basename($file);
119 if (!rename($file, $target)) {
120 throw new Exception("Could not rename $file to $target");
125 * Fetch the specified message to the local processed folder.
128 * File location of the message to fetch.
132 public function markProcessed($file) {
134 print "moving $file to processed folder\n";
136 $target = $this->_processed
. DIRECTORY_SEPARATOR
. basename($file);
137 if (!rename($file, $target)) {
138 throw new Exception("Could not rename $file to $target");