Skip to content

Commit 7659ee1

Browse files
fixup! fix: normalize email addresses before using them
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
1 parent 60ca2a4 commit 7659ee1

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\Mail\BackgroundJob;
11+
12+
use OCP\AppFramework\Utility\ITimeFactory;
13+
use OCP\BackgroundJob\IJobList;
14+
use OCP\BackgroundJob\TimedJob;
15+
use OCP\DB\QueryBuilder\IQueryBuilder;
16+
use OCP\IDBConnection;
17+
18+
class RepairRecipients extends TimedJob {
19+
20+
public function __construct(
21+
protected ITimeFactory $time,
22+
private IDBConnection $db,
23+
private IJobList $jobService
24+
) {
25+
parent::__construct($time);
26+
$this->setInterval(300);
27+
}
28+
29+
protected function run($argument): void {
30+
// fetch all quoted emails
31+
$select = $this->db->getQueryBuilder();
32+
$select->select('id', 'email')
33+
->from('mail_recipients')
34+
->where(
35+
$select->expr()->like('email', $select->createNamedParameter('\'%\'', IQueryBuilder::PARAM_STR))
36+
)
37+
->setMaxResults(1000);
38+
$recipients = $select->executeQuery()->fetchAll();
39+
// update emails
40+
$update = $this->db->getQueryBuilder();
41+
$update->update('mail_recipients')
42+
->set('email', $update->createParameter('email'), IQueryBuilder::PARAM_STR)
43+
->where($update->expr()->in('id', $update->createParameter('id'), IQueryBuilder::PARAM_STR));
44+
foreach ($recipients as $recipient) {
45+
$id = $recipient['id'];
46+
$email = $recipient['email'];
47+
$email = str_replace('\'', '', $email);
48+
$update->setParameter('id', $id, IQueryBuilder::PARAM_STR);
49+
$update->setParameter('email', $email, IQueryBuilder::PARAM_STR);
50+
$update->executeStatement();
51+
}
52+
// remove job depending on the result
53+
if (count($recipient) === 0) {
54+
$this->jobService->remove(RepairRecipients::class);
55+
}
56+
}
57+
58+
}

lib/IMAP/ImapMessageFetcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public function fetchMessage(?Horde_Imap_Client_Data_Fetch $fetch = null): IMAPM
252252
$fetch->getFlags(),
253253
AddressList::fromHorde($envelope->from, true),
254254
AddressList::fromHorde($envelope->to, true),
255-
AddressList::fromHorde($envelope->ccv, true),
255+
AddressList::fromHorde($envelope->cc, true),
256256
AddressList::fromHorde($envelope->bcc, true),
257257
AddressList::fromHorde($envelope->reply_to, true),
258258
$this->decodeSubject($envelope),
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\Mail\Migration;
11+
12+
use Closure;
13+
use OCP\BackgroundJob\IJobList;
14+
use OCP\Migration\IOutput;
15+
use OCP\Migration\SimpleMigrationStep;
16+
17+
class Version5000Date20250507000000 extends SimpleMigrationStep {
18+
19+
public function __construct(
20+
private IJobList $jobService
21+
) {
22+
parent::__construct();
23+
}
24+
25+
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
26+
$this->jobService->add(\OCA\Mail\BackgroundJob\RepairRecipients::class);
27+
}
28+
29+
}

0 commit comments

Comments
 (0)