Skip to content

Commit

Permalink
sanitizing
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtificialOwl committed Mar 12, 2020
1 parent c8f9113 commit e88f183
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/Service/MailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ private function verifyInfoAndPassword(string $content, array $toInfo): void {
*/
private function getMailFolder(string $userId, string $to, string $from): Folder {
$node = OC::$server->getUserFolder($userId);
$to = $this->parseMailAddress($to);
$from = $this->parseMailAddress($from);

$folderPath = 'Mails sent to ' . $to . '/From ' . $from . '/';

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


/**
* @param string $address
*
* @return string
*/
private function parseMailAddress(string $address): string {
$acceptedChars = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789@.-_+';

$fixed = '';
for ($i = 0; $i < strlen($address); $i++) {
$c = $address[$i];
if (strpos($acceptedChars, $c) !== false) {
$fixed .= $c;
}
}

$fixed = str_replace('..', '.', $fixed);

return $fixed;
}

}

0 comments on commit e88f183

Please sign in to comment.