|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* This file is part of Aura for PHP. |
|
5
|
|
|
* |
|
6
|
|
|
* @license http://opensource.org/licenses/bsd-license.php BSD |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace Aura\Auth\Adapter; |
|
10
|
|
|
|
|
11
|
|
|
use Aura\Auth\Exception; |
|
12
|
|
|
use Aura\Auth\Phpfunc; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* |
|
16
|
|
|
* Authenticate against an IMAP, POP3, or NNTP server. |
|
17
|
|
|
* |
|
18
|
|
|
* @package Aura.Auth |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
class ImapAdapter extends AbstractAdapter |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* |
|
25
|
|
|
* An imap_open() mailbox string; e.g., "{mail.example.com:143/imap/secure}" |
|
26
|
|
|
* or "{mail.example.com:110/pop3/secure}". |
|
27
|
|
|
* |
|
28
|
|
|
* @var string |
|
29
|
|
|
* |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $mailbox; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* |
|
35
|
|
|
* Options for the imap_open() call. |
|
36
|
|
|
* |
|
37
|
|
|
* @var int |
|
38
|
|
|
* |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $options = 0; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* |
|
44
|
|
|
* Try to connect this many times. |
|
45
|
|
|
* |
|
46
|
|
|
* @var int |
|
47
|
|
|
* |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $retries = 1; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* |
|
53
|
|
|
* Params for the imap_open() call. |
|
54
|
|
|
* |
|
55
|
|
|
* @var array|null |
|
56
|
|
|
* |
|
57
|
|
|
*/ |
|
58
|
|
|
protected $params; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* |
|
62
|
|
|
* An object to intercept PHP calls. |
|
63
|
|
|
* |
|
64
|
|
|
* @var Phpfunc |
|
65
|
|
|
* |
|
66
|
|
|
*/ |
|
67
|
|
|
protected $phpfunc; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* |
|
71
|
|
|
* Constructor. |
|
72
|
|
|
* |
|
73
|
|
|
* @param Phpfunc $phpfunc An object to intercept PHP calls. |
|
74
|
|
|
* |
|
75
|
|
|
* @param string $mailbox The imap_open() mailbox string. |
|
76
|
|
|
* |
|
77
|
|
|
* @param int $options Options for the imap_open() call. |
|
78
|
|
|
* |
|
79
|
|
|
* @param int $retries Try connecting this many times. |
|
80
|
|
|
* |
|
81
|
|
|
* @param array $params Params for the imap_open() call. |
|
82
|
|
|
* |
|
83
|
|
|
*/ |
|
84
|
5 |
|
public function __construct( |
|
85
|
|
|
Phpfunc $phpfunc, |
|
86
|
|
|
$mailbox, |
|
87
|
|
|
$options = 0, |
|
88
|
|
|
$retries = 1, |
|
89
|
|
|
array $params = null |
|
90
|
|
|
) { |
|
91
|
5 |
|
$this->phpfunc = $phpfunc; |
|
92
|
5 |
|
$this->mailbox = $mailbox; |
|
93
|
5 |
|
$this->options = $options; |
|
94
|
5 |
|
$this->retries = $retries; |
|
95
|
5 |
|
$this->params = $params; |
|
96
|
5 |
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* |
|
100
|
|
|
* Verifies a set of credentials. |
|
101
|
|
|
* |
|
102
|
|
|
* @param array $input An array of credential data, including any data to |
|
103
|
|
|
* bind to the query. |
|
104
|
|
|
* |
|
105
|
|
|
* @return array An array of login data. |
|
106
|
|
|
* |
|
107
|
|
|
* @throws Exception\ConnectionFailed when the IMAP connection fails. |
|
108
|
|
|
* |
|
109
|
|
|
*/ |
|
110
|
2 |
|
public function login(array $input) |
|
111
|
|
|
{ |
|
112
|
2 |
|
$this->checkInput($input); |
|
113
|
2 |
|
$username = $input['username']; |
|
114
|
2 |
|
$password = $input['password']; |
|
115
|
|
|
|
|
116
|
2 |
|
$conn = $this->phpfunc->imap_open( |
|
|
|
|
|
|
117
|
2 |
|
$this->mailbox, |
|
118
|
2 |
|
$username, |
|
119
|
2 |
|
$password, |
|
120
|
2 |
|
$this->options, |
|
121
|
2 |
|
$this->retries, |
|
122
|
2 |
|
$this->params |
|
123
|
2 |
|
); |
|
124
|
|
|
|
|
125
|
2 |
|
if (! $conn) { |
|
126
|
1 |
|
throw new Exception\ConnectionFailed($this->mailbox); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
1 |
|
$this->phpfunc->imap_close($conn); |
|
|
|
|
|
|
130
|
1 |
|
return array($username, array()); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: