‪TYPO3CMS  ‪main
EmailLinkHandler.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
24 {
28  public function ‪asString(array $parameters): string
29  {
30  $queryParameters = [];
31  foreach (['subject', 'cc', 'bcc', 'body'] as $additionalInfo) {
32  if (isset($parameters[$additionalInfo])) {
33  $queryParameters[$additionalInfo] = rawurldecode(trim($parameters[$additionalInfo]));
34  }
35  }
36  $result = 'mailto:' . trim($parameters['email']);
37  if ($queryParameters !== []) {
38  // We need to percent-encode additional parameters (RFC 3986)
39  $result .= '?' . http_build_query($queryParameters, '', '&', PHP_QUERY_RFC3986);
40  }
41  return $result;
42  }
43 
48  public function ‪resolveHandlerData(array $data): array
49  {
50  $linkParts = parse_url($data['email'] ?? '');
51  $data['email'] = trim($linkParts['path'] ?? '');
52  if (isset($linkParts['query'])) {
53  $result = [];
54  parse_str($linkParts['query'], $result);
55  foreach (['subject', 'cc', 'bcc', 'body'] as $additionalInfo) {
56  if (isset($result[$additionalInfo])) {
57  $data[$additionalInfo] = trim($result[$additionalInfo]);
58  }
59  }
60  }
61  return $data;
62  }
63 }