|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @author Christoph Wurst <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* Mail |
|
7
|
|
|
* |
|
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
10
|
|
|
* as published by the Free Software Foundation. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
namespace OCA\Mail\Service\AutoConfig; |
|
22
|
|
|
|
|
23
|
|
|
use OCP\Security\ICrypto; |
|
24
|
|
|
use OCA\Mail\Account; |
|
25
|
|
|
use OCA\Mail\Db\MailAccount; |
|
26
|
|
|
use OCA\Mail\Service\Logger; |
|
27
|
|
|
|
|
28
|
|
|
class ImapConnector { |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var Crypto |
|
32
|
|
|
*/ |
|
33
|
|
|
private $crypto; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var Logger |
|
37
|
|
|
*/ |
|
38
|
|
|
private $logger; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var string |
|
42
|
|
|
*/ |
|
43
|
|
|
private $userId; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param ICrypto $crypto |
|
47
|
|
|
* @param Logger $logger |
|
48
|
|
|
* @param type $UserId |
|
49
|
|
|
*/ |
|
50
|
|
|
public function __construct(ICrypto $crypto, Logger $logger, $UserId) { |
|
51
|
|
|
$this->crypto = $crypto; |
|
|
|
|
|
|
52
|
|
|
$this->logger = $logger; |
|
53
|
|
|
$this->userId = $UserId; |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param $email |
|
58
|
|
|
* @param $password |
|
59
|
|
|
* @param $name |
|
60
|
|
|
* @param $host |
|
61
|
|
|
* @param $port |
|
62
|
|
|
* @param string|null $encryptionProtocol |
|
63
|
|
|
* @param $user |
|
64
|
|
|
* @return MailAccount |
|
65
|
|
|
*/ |
|
66
|
|
|
public function connect($email, $password, $name, $host, $port, |
|
67
|
|
|
$encryptionProtocol, $user) { |
|
68
|
|
|
|
|
69
|
|
|
$account = new MailAccount(); |
|
70
|
|
|
$account->setUserId($this->userId); |
|
71
|
|
|
$account->setName($name); |
|
72
|
|
|
$account->setEmail($email); |
|
73
|
|
|
$account->setInboundHost($host); |
|
74
|
|
|
$account->setInboundPort($port); |
|
75
|
|
|
$account->setInboundSslMode($encryptionProtocol); |
|
76
|
|
|
$account->setInboundUser($user); |
|
77
|
|
|
$password = $this->crypto->encrypt($password); |
|
78
|
|
|
$account->setInboundPassword($password); |
|
79
|
|
|
|
|
80
|
|
|
$a = new Account($account); |
|
81
|
|
|
$a->getImapConnection(); |
|
82
|
|
|
$this->logger->info("Test-Account-Successful: $this->userId, $host, $port, $user, $encryptionProtocol"); |
|
83
|
|
|
return $account; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..