Merge remote-tracking branch 'upstream/4.6' into 4.6-master-2015-11-09-14-08-33
[civicrm-core.git] / CRM / Mailing / MailStore / Pop3.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
6a488035
TO
32 */
33
34require_once 'ezc/Base/src/ezc_bootstrap.php';
35require_once 'ezc/autoload/mail_autoload.php';
28518c90
EM
36
37/**
38 * Class CRM_Mailing_MailStore_Pop3
39 */
6a488035
TO
40class CRM_Mailing_MailStore_Pop3 extends CRM_Mailing_MailStore {
41
42 /**
43 * Connect to the supplied POP3 server and make sure the two mail dirs exist
44 *
90c8230e
TO
45 * @param string $host
46 * Host to connect to.
47 * @param string $username
48 * Authentication username.
49 * @param string $password
50 * Authentication password.
51 * @param bool $ssl
52 * Whether to use POP3 or POP3S.
6a488035 53 *
dd244018 54 * @return \CRM_Mailing_MailStore_Pop3
6a488035 55 */
00be9182 56 public function __construct($host, $username, $password, $ssl = TRUE) {
6a488035
TO
57 if ($this->_debug) {
58 print "connecting to $host and authenticating as $username\n";
59 }
60
61 $options = array('ssl' => $ssl);
62 $this->_transport = new ezcMailPop3Transport($host, NULL, $options);
63 $this->_transport->authenticate($username, $password);
64
353ffa53
TO
65 $this->_ignored = $this->maildir(implode(DIRECTORY_SEPARATOR, array(
66 'CiviMail.ignored',
67 date('Y'),
68 date('m'),
acb1052e 69 date('d'),
353ffa53
TO
70 )));
71 $this->_processed = $this->maildir(implode(DIRECTORY_SEPARATOR, array(
72 'CiviMail.processed',
73 date('Y'),
74 date('m'),
acb1052e 75 date('d'),
353ffa53 76 )));
6a488035
TO
77 }
78
79 /**
fe482240 80 * Fetch the specified message to the local ignore folder.
6a488035 81 *
90c8230e
TO
82 * @param int $nr
83 * Number of the message to fetch.
6a488035 84 */
00be9182 85 public function markIgnored($nr) {
6a488035
TO
86 if ($this->_debug) {
87 print "fetching message $nr and putting it in the ignored mailbox\n";
88 }
89 $set = new ezcMailStorageSet($this->_transport->fetchByMessageNr($nr), $this->_ignored);
acb1052e 90 $parser = new ezcMailParser();
6a488035
TO
91 $parser->parseMail($set);
92 $this->_transport->delete($nr);
93 }
94
95 /**
fe482240 96 * Fetch the specified message to the local processed folder.
6a488035 97 *
90c8230e
TO
98 * @param int $nr
99 * Number of the message to fetch.
6a488035 100 */
00be9182 101 public function markProcessed($nr) {
6a488035
TO
102 if ($this->_debug) {
103 print "fetching message $nr and putting it in the processed mailbox\n";
104 }
105 $set = new ezcMailStorageSet($this->_transport->fetchByMessageNr($nr), $this->_processed);
acb1052e 106 $parser = new ezcMailParser();
6a488035
TO
107 $parser->parseMail($set);
108 $this->_transport->delete($nr);
109 }
96025800 110
6a488035 111}