| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | | | |
| 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 | +--------------------------------------------------------------------+ |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * |
| 14 | * @package CRM |
| 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
| 16 | */ |
| 17 | |
| 18 | /** |
| 19 | * Class CRM_Mailing_MailStore_Pop3 |
| 20 | */ |
| 21 | class CRM_Mailing_MailStore_Pop3 extends CRM_Mailing_MailStore { |
| 22 | |
| 23 | /** |
| 24 | * Connect to the supplied POP3 server and make sure the two mail dirs exist |
| 25 | * |
| 26 | * @param string $host |
| 27 | * Host to connect to. |
| 28 | * @param string $username |
| 29 | * Authentication username. |
| 30 | * @param string $password |
| 31 | * Authentication password. |
| 32 | * @param bool $ssl |
| 33 | * Whether to use POP3 or POP3S. |
| 34 | * |
| 35 | * @return \CRM_Mailing_MailStore_Pop3 |
| 36 | */ |
| 37 | public function __construct($host, $username, $password, $ssl = TRUE) { |
| 38 | if ($this->_debug) { |
| 39 | print "connecting to $host and authenticating as $username\n"; |
| 40 | } |
| 41 | |
| 42 | $options = ['ssl' => $ssl]; |
| 43 | $this->_transport = new ezcMailPop3Transport($host, NULL, $options); |
| 44 | $this->_transport->authenticate($username, $password); |
| 45 | |
| 46 | $this->_ignored = $this->maildir(implode(DIRECTORY_SEPARATOR, [ |
| 47 | 'CiviMail.ignored', |
| 48 | date('Y'), |
| 49 | date('m'), |
| 50 | date('d'), |
| 51 | ])); |
| 52 | $this->_processed = $this->maildir(implode(DIRECTORY_SEPARATOR, [ |
| 53 | 'CiviMail.processed', |
| 54 | date('Y'), |
| 55 | date('m'), |
| 56 | date('d'), |
| 57 | ])); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Fetch the specified message to the local ignore folder. |
| 62 | * |
| 63 | * @param int $nr |
| 64 | * Number of the message to fetch. |
| 65 | */ |
| 66 | public function markIgnored($nr) { |
| 67 | if ($this->_debug) { |
| 68 | print "fetching message $nr and putting it in the ignored mailbox\n"; |
| 69 | } |
| 70 | $set = new ezcMailStorageSet($this->_transport->fetchByMessageNr($nr), $this->_ignored); |
| 71 | $parser = new ezcMailParser(); |
| 72 | $parser->parseMail($set); |
| 73 | $this->_transport->delete($nr); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Fetch the specified message to the local processed folder. |
| 78 | * |
| 79 | * @param int $nr |
| 80 | * Number of the message to fetch. |
| 81 | */ |
| 82 | public function markProcessed($nr) { |
| 83 | if ($this->_debug) { |
| 84 | print "fetching message $nr and putting it in the processed mailbox\n"; |
| 85 | } |
| 86 | $set = new ezcMailStorageSet($this->_transport->fetchByMessageNr($nr), $this->_processed); |
| 87 | $parser = new ezcMailParser(); |
| 88 | $parser->parseMail($set); |
| 89 | $this->_transport->delete($nr); |
| 90 | } |
| 91 | |
| 92 | } |