3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
36 require_once 'ezc/Base/src/ezc_bootstrap.php';
37 require_once 'ezc/autoload/mail_autoload.php';
38 class CRM_Mailing_MailStore_Maildir
extends CRM_Mailing_MailStore
{
41 * Connect to the supplied dir and make sure the two mail dirs exist
43 * @param string $dir dir to operate upon
47 function __construct($dir) {
50 $this->_ignored
= $this->maildir(implode(DIRECTORY_SEPARATOR
, array('CiviMail.ignored', date('Y'), date('m'), date('d'))));
51 $this->_processed
= $this->maildir(implode(DIRECTORY_SEPARATOR
, array('CiviMail.processed', date('Y'), date('m'), date('d'))));
55 * Return the next X messages from the mail store
56 * FIXME: in CiviCRM 2.2 this always returns all the emails
58 * @param int $count number of messages to fetch FIXME: ignored in CiviCRM 2.2 (assumed to be 0, i.e., fetch all)
60 * @return array array of ezcMail objects
62 function fetchNext($count = 0) {
64 $parser = new ezcMailParser
;
65 //set property text attachment as file CRM-5408
66 $parser->options
->parseTextAttachmentsAsFiles
= TRUE;
69 'cur', 'new') as $subdir) {
70 $dir = $this->_dir
. DIRECTORY_SEPARATOR
. $subdir;
71 foreach (scandir($dir) as $file) {
72 if ($file == '.' or $file == '..') {
75 $path = $dir . DIRECTORY_SEPARATOR
. $file;
79 print "retrieving message $path\n";
83 $set = new ezcMailFileSet(array($path));
84 $single = $parser->parseMail($set);
85 $mails[$path] = $single[0];
92 * Fetch the specified message to the local ignore folder
94 * @param integer $file file location of the message to fetch
98 function markIgnored($file) {
100 print "moving $file to ignored folder\n";
102 $target = $this->_ignored
. DIRECTORY_SEPARATOR
. basename($file);
103 if (!rename($file, $target)) {
104 throw new Exception("Could not rename $file to $target");
109 * Fetch the specified message to the local processed folder
111 * @param integer $file file location of the message to fetch
115 function markProcessed($file) {
117 print "moving $file to processed folder\n";
119 $target = $this->_processed
. DIRECTORY_SEPARATOR
. basename($file);
120 if (!rename($file, $target)) {
121 throw new Exception("Could not rename $file to $target");