Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
28518c90 EM |
18 | /** |
19 | * Class CRM_Mailing_MailStore_Mbox | |
20 | */ | |
6a488035 TO |
21 | class CRM_Mailing_MailStore_Mbox extends CRM_Mailing_MailStore { |
22 | ||
23 | /** | |
fe482240 | 24 | * Connect to and lock the supplied file and make sure the two mail dirs exist. |
6a488035 | 25 | * |
90c8230e TO |
26 | * @param string $file |
27 | * Mbox to operate upon. | |
6a488035 | 28 | * |
dd244018 | 29 | * @return \CRM_Mailing_MailStore_Mbox |
6a488035 | 30 | */ |
00be9182 | 31 | public function __construct($file) { |
6a488035 TO |
32 | $this->_transport = new ezcMailMboxTransport($file); |
33 | flock($this->_transport->fh, LOCK_EX); | |
34 | ||
35 | $this->_leftToProcess = count($this->_transport->listMessages()); | |
36 | ||
be2fb01f | 37 | $this->_ignored = $this->maildir(implode(DIRECTORY_SEPARATOR, [ |
7e8c8317 SL |
38 | 'CiviMail.ignored', |
39 | date('Y'), | |
40 | date('m'), | |
41 | date('d'), | |
42 | ])); | |
be2fb01f | 43 | $this->_processed = $this->maildir(implode(DIRECTORY_SEPARATOR, [ |
7e8c8317 SL |
44 | 'CiviMail.processed', |
45 | date('Y'), | |
46 | date('m'), | |
47 | date('d'), | |
48 | ])); | |
6a488035 TO |
49 | } |
50 | ||
51 | /** | |
25606795 | 52 | * Empty the mail source (if it was processed fully) and unlock the file. |
6a488035 | 53 | */ |
00be9182 | 54 | public function __destruct() { |
6a488035 TO |
55 | if ($this->_leftToProcess === 0) { |
56 | // FIXME: the ftruncate() call does not work for some reason | |
57 | if ($this->_debug) { | |
58 | print "trying to delete the mailbox\n"; | |
59 | } | |
60 | ftruncate($this->_transport->fh, 0); | |
61 | } | |
62 | flock($this->_transport->fh, LOCK_UN); | |
63 | } | |
64 | ||
65 | /** | |
fe482240 | 66 | * Fetch the specified message to the local ignore folder. |
6a488035 | 67 | * |
90c8230e TO |
68 | * @param int $nr |
69 | * Number of the message to fetch. | |
6a488035 | 70 | */ |
00be9182 | 71 | public function markIgnored($nr) { |
6a488035 TO |
72 | if ($this->_debug) { |
73 | print "copying message $nr to ignored folder\n"; | |
74 | } | |
75 | $set = new ezcMailStorageSet($this->_transport->fetchByMessageNr($nr), $this->_ignored); | |
acb1052e | 76 | $parser = new ezcMailParser(); |
6a488035 TO |
77 | $parser->parseMail($set); |
78 | $this->_leftToProcess--; | |
79 | } | |
80 | ||
81 | /** | |
fe482240 | 82 | * Fetch the specified message to the local processed folder. |
6a488035 | 83 | * |
90c8230e TO |
84 | * @param int $nr |
85 | * Number of the message to fetch. | |
6a488035 | 86 | */ |
00be9182 | 87 | public function markProcessed($nr) { |
6a488035 TO |
88 | if ($this->_debug) { |
89 | print "copying message $nr to processed folder\n"; | |
90 | } | |
91 | $set = new ezcMailStorageSet($this->_transport->fetchByMessageNr($nr), $this->_processed); | |
acb1052e | 92 | $parser = new ezcMailParser(); |
6a488035 TO |
93 | $parser->parseMail($set); |
94 | $this->_leftToProcess--; | |
95 | } | |
96025800 | 96 | |
6a488035 | 97 | } |