Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | require_once 'ezc/Base/src/ezc_bootstrap.php'; | |
37 | require_once 'ezc/autoload/mail_autoload.php'; | |
28518c90 EM |
38 | |
39 | /** | |
40 | * Class CRM_Mailing_MailStore_Localdir | |
41 | */ | |
6a488035 TO |
42 | class CRM_Mailing_MailStore_Localdir extends CRM_Mailing_MailStore { |
43 | ||
44 | /** | |
45 | * Connect to the supplied dir and make sure the two mail dirs exist | |
46 | * | |
dd244018 | 47 | * @param string $dir dir to operate upon |
6a488035 | 48 | * |
dd244018 | 49 | * @return \CRM_Mailing_MailStore_Localdir |
6a488035 TO |
50 | */ |
51 | function __construct($dir) { | |
52 | $this->_dir = $dir; | |
53 | ||
54 | $this->_ignored = $this->maildir(implode(DIRECTORY_SEPARATOR, array('CiviMail.ignored', date('Y'), date('m'), date('d')))); | |
55 | $this->_processed = $this->maildir(implode(DIRECTORY_SEPARATOR, array('CiviMail.processed', date('Y'), date('m'), date('d')))); | |
56 | } | |
57 | ||
58 | /** | |
59 | * Return the next X messages from the mail store | |
60 | * FIXME: in CiviCRM 2.2 this always returns all the emails | |
61 | * | |
62 | * @param int $count number of messages to fetch FIXME: ignored in CiviCRM 2.2 (assumed to be 0, i.e., fetch all) | |
63 | * | |
64 | * @return array array of ezcMail objects | |
65 | */ | |
66 | function fetchNext($count = 0) { | |
67 | $mails = array(); | |
68 | $path = rtrim($this->_dir, DIRECTORY_SEPARATOR); | |
69 | ||
70 | if ($this->_debug) { | |
71 | ||
72 | print "fetching $count messages\n"; | |
73 | ||
74 | } | |
75 | ||
76 | $directory = new DirectoryIterator($path); | |
77 | foreach ($directory as $entry) { | |
78 | if ($entry->isDot()) { | |
79 | continue; | |
80 | } | |
81 | if (count($mails) >= $count) | |
82 | break; | |
83 | ||
84 | $file = $path . DIRECTORY_SEPARATOR . $entry->getFilename(); | |
85 | if ($this->_debug) { | |
86 | print "retrieving message $file\n"; | |
87 | } | |
88 | ||
89 | $set = new ezcMailFileSet(array($file)); | |
90 | $parser = new ezcMailParser; | |
91 | //set property text attachment as file CRM-5408 | |
92 | $parser->options->parseTextAttachmentsAsFiles = TRUE; | |
93 | ||
94 | $mail = $parser->parseMail($set); | |
95 | ||
96 | if (!$mail) { | |
97 | return CRM_Core_Error::createAPIError(ts('%1 could not be parsed', | |
98 | array(1 => $file) | |
99 | )); | |
100 | } | |
101 | $mails[$file] = $mail[0]; | |
102 | } | |
103 | ||
104 | if ($this->_debug && (count($mails) <= 0)) { | |
105 | ||
106 | print "No messages found\n"; | |
107 | ||
108 | } | |
109 | ||
110 | return $mails; | |
111 | } | |
112 | ||
113 | /** | |
114 | * Fetch the specified message to the local ignore folder | |
115 | * | |
77b97be7 | 116 | * @param integer $file file location of the message to fetch |
6a488035 | 117 | * |
77b97be7 | 118 | * @throws Exception |
6a488035 TO |
119 | * @return void |
120 | */ | |
121 | function markIgnored($file) { | |
122 | if ($this->_debug) { | |
123 | print "moving $file to ignored folder\n"; | |
124 | } | |
125 | $target = $this->_ignored . DIRECTORY_SEPARATOR . basename($file); | |
126 | if (!rename($file, $target)) { | |
127 | throw new Exception("Could not rename $file to $target"); | |
128 | } | |
129 | } | |
130 | ||
131 | /** | |
132 | * Fetch the specified message to the local processed folder | |
133 | * | |
77b97be7 | 134 | * @param integer $file file location of the message to fetch |
6a488035 | 135 | * |
77b97be7 | 136 | * @throws Exception |
6a488035 TO |
137 | * @return void |
138 | */ | |
139 | function markProcessed($file) { | |
140 | if ($this->_debug) { | |
141 | print "moving $file to processed folder\n"; | |
142 | } | |
143 | $target = $this->_processed . DIRECTORY_SEPARATOR . basename($file); | |
144 | if (!rename($file, $target)) { | |
145 | throw new Exception("Could not rename $file to $target"); | |
146 | } | |
147 | } | |
148 | } | |
149 |