3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
36 require_once 'ezc/Base/src/ezc_bootstrap.php';
37 require_once 'ezc/autoload/mail_autoload.php';
40 * Class CRM_Mailing_MailStore_Localdir
42 class CRM_Mailing_MailStore_Localdir
extends CRM_Mailing_MailStore
{
45 * Connect to the supplied dir and make sure the two mail dirs exist.
48 * Dir to operate upon.
50 * @return \CRM_Mailing_MailStore_Localdir
52 public function __construct($dir) {
55 $this->_ignored
= $this->maildir(implode(DIRECTORY_SEPARATOR
, array(
61 $this->_processed
= $this->maildir(implode(DIRECTORY_SEPARATOR
, array(
70 * Return the next X messages from the mail store.
71 * FIXME: in CiviCRM 2.2 this always returns all the emails
74 * Number of messages to fetch FIXME: ignored in CiviCRM 2.2 (assumed to be 0, i.e., fetch all).
77 * array of ezcMail objects
79 public function fetchNext($count = 0) {
81 $path = rtrim($this->_dir
, DIRECTORY_SEPARATOR
);
85 print "fetching $count messages\n";
89 $directory = new DirectoryIterator($path);
90 foreach ($directory as $entry) {
91 if ($entry->isDot()) {
94 if (count($mails) >= $count) {
98 $file = $path . DIRECTORY_SEPARATOR
. $entry->getFilename();
100 print "retrieving message $file\n";
103 $set = new ezcMailFileSet(array($file));
104 $parser = new ezcMailParser();
105 //set property text attachment as file CRM-5408
106 $parser->options
->parseTextAttachmentsAsFiles
= TRUE;
108 $mail = $parser->parseMail($set);
111 return CRM_Core_Error
::createAPIError(ts('%1 could not be parsed',
115 $mails[$file] = $mail[0];
118 if ($this->_debug
&& (count($mails) <= 0)) {
120 print "No messages found\n";
128 * Fetch the specified message to the local ignore folder.
131 * File location of the message to fetch.
136 public function markIgnored($file) {
138 print "moving $file to ignored folder\n";
140 $target = $this->_ignored
. DIRECTORY_SEPARATOR
. basename($file);
141 if (!rename($file, $target)) {
142 throw new Exception("Could not rename $file to $target");
147 * Fetch the specified message to the local processed folder.
150 * File location of the message to fetch.
155 public function markProcessed($file) {
157 print "moving $file to processed folder\n";
159 $target = $this->_processed
. DIRECTORY_SEPARATOR
. basename($file);
160 if (!rename($file, $target)) {
161 throw new Exception("Could not rename $file to $target");