1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Christoph Wurst <[email protected]> |
5
|
|
|
* @author Lukas Reschke <[email protected]> |
6
|
|
|
* @author Thomas Müller <[email protected]> |
7
|
|
|
* @author Timo Witte <[email protected]> |
8
|
|
|
* |
9
|
|
|
* ownCloud - Mail |
10
|
|
|
* |
11
|
|
|
* This code is free software: you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
13
|
|
|
* as published by the Free Software Foundation. |
14
|
|
|
* |
15
|
|
|
* This program is distributed in the hope that it will be useful, |
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
* GNU Affero General Public License for more details. |
19
|
|
|
* |
20
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
22
|
|
|
* |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace OCA\Mail\Controller; |
26
|
|
|
|
27
|
|
|
use OCA\Mail\Db\MailAccountMapper; |
28
|
|
|
use OCP\AppFramework\Controller; |
29
|
|
|
use OCP\AppFramework\Http\ContentSecurityPolicy; |
30
|
|
|
use OCP\AppFramework\Http\RedirectResponse; |
31
|
|
|
use OCP\AppFramework\Http\TemplateResponse; |
32
|
|
|
use OCP\IConfig; |
33
|
|
|
use OCP\IRequest; |
34
|
|
|
use OCP\IURLGenerator; |
35
|
|
|
|
36
|
|
|
class PageController extends Controller { |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var MailAccountMapper |
40
|
|
|
*/ |
41
|
|
|
private $mailAccountMapper; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var IURLGenerator |
45
|
|
|
*/ |
46
|
|
|
private $urlGenerator; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var IConfig |
50
|
|
|
*/ |
51
|
|
|
private $config; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var string |
55
|
|
|
*/ |
56
|
|
|
private $currentUserId; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string $appName |
60
|
|
|
* @param IRequest $request |
61
|
|
|
* @param $mailAccountMapper |
62
|
|
|
* @param IConfig $config |
63
|
|
|
* @param $UserId |
64
|
|
|
*/ |
65
|
6 |
|
public function __construct($appName, IRequest $request, MailAccountMapper $mailAccountMapper, IURLGenerator $urlGenerator, IConfig $config, $UserId) { |
66
|
6 |
|
parent::__construct($appName, $request); |
67
|
6 |
|
$this->mailAccountMapper = $mailAccountMapper; |
68
|
6 |
|
$this->urlGenerator = $urlGenerator; |
69
|
6 |
|
$this->config = $config; |
70
|
6 |
|
$this->currentUserId = $UserId; |
71
|
6 |
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @NoAdminRequired |
75
|
|
|
* @NoCSRFRequired |
76
|
|
|
* |
77
|
|
|
* @return TemplateResponse renders the index page |
78
|
|
|
*/ |
79
|
1 |
|
public function index() { |
80
|
1 |
|
$coreVersion = $this->config->getSystemValue('version'); |
81
|
|
|
$hasDavSupport = (int) version_compare($coreVersion, '9.0.0', '>='); |
82
|
|
|
// TODO: remove DEBUG constant check once minimum oc |
83
|
|
|
// core version >= 8.2, see https://github.com/owncloud/core/pull/18510 |
84
|
|
|
$response = new TemplateResponse($this->appName, 'index', [ |
85
|
|
|
'debug' => (defined('DEBUG') && DEBUG) || $this->config->getSystemValue('debug', false), |
86
|
|
|
'app-version' => $this->config->getAppValue('mail', 'installed_version'), |
87
|
|
|
'has-dav-support' => $hasDavSupport, |
88
|
|
|
]); |
89
|
|
|
|
90
|
|
|
// set csp rules for ownCloud 8.1 |
91
|
|
|
if (class_exists('OCP\AppFramework\Http\ContentSecurityPolicy')) { |
92
|
|
|
$csp = new ContentSecurityPolicy(); |
93
|
|
|
$csp->addAllowedFrameDomain('\'self\''); |
94
|
|
|
$response->setContentSecurityPolicy($csp); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $response; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @NoAdminRequired |
102
|
|
|
* @NoCSRFRequired |
103
|
|
|
* |
104
|
|
|
* @param string $uri |
105
|
|
|
* @return TemplateResponse renders the compose page |
106
|
|
|
*/ |
107
|
5 |
|
public function compose($uri) { |
108
|
5 |
|
$parts = parse_url($uri); |
109
|
5 |
|
$params = ['to' => $parts['path']]; |
110
|
5 |
|
if (isset($parts['query'])) { |
111
|
4 |
|
$parts = explode('&', $parts['query']); |
112
|
4 |
|
foreach ($parts as $part) { |
113
|
4 |
|
$pair = explode('=', $part, 2); |
114
|
4 |
|
$params[strtolower($pair[0])] = urldecode($pair[1]); |
115
|
4 |
|
} |
116
|
4 |
|
} |
117
|
|
|
|
118
|
5 |
|
array_walk($params, function (&$value, $key) { |
119
|
5 |
|
$value = "$key=" . urlencode($value); |
120
|
5 |
|
}); |
121
|
|
|
|
122
|
5 |
|
$hashParams = '#mailto?' . implode('&', $params); |
123
|
|
|
|
124
|
5 |
|
$baseUrl = $this->urlGenerator->linkToRoute("mail.page.index"); |
125
|
5 |
|
return new RedirectResponse($baseUrl . $hashParams); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
} |
129
|
|
|
|