Skip to content

Commit e88f183

Browse files
committed
sanitizing
1 parent c8f9113 commit e88f183

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lib/Service/MailService.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ private function verifyInfoAndPassword(string $content, array $toInfo): void {
186186
*/
187187
private function getMailFolder(string $userId, string $to, string $from): Folder {
188188
$node = OC::$server->getUserFolder($userId);
189+
$to = $this->parseMailAddress($to);
190+
$from = $this->parseMailAddress($from);
191+
189192
$folderPath = 'Mails sent to ' . $to . '/From ' . $from . '/';
190193

191194
if (!$node->nodeExists($folderPath)) {
@@ -384,5 +387,27 @@ private function saveMailAddresses(array $addresses): void {
384387
$this->configService->setAppValue(ConfigService::FROMMAIL_ADDRESSES, json_encode($addresses));
385388
}
386389

390+
391+
/**
392+
* @param string $address
393+
*
394+
* @return string
395+
*/
396+
private function parseMailAddress(string $address): string {
397+
$acceptedChars = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789@.-_+';
398+
399+
$fixed = '';
400+
for ($i = 0; $i < strlen($address); $i++) {
401+
$c = $address[$i];
402+
if (strpos($acceptedChars, $c) !== false) {
403+
$fixed .= $c;
404+
}
405+
}
406+
407+
$fixed = str_replace('..', '.', $fixed);
408+
409+
return $fixed;
410+
}
411+
387412
}
388413

0 commit comments

Comments
 (0)