-
Notifications
You must be signed in to change notification settings - Fork 293
feat(PhishingDetection): Add support for the $Phishing IMAP flag
#12187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ChristophWurst
merged 1 commit into
nextcloud:main
from
DerDreschner:feature/support-phishing-flag
Dec 20, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Mail\Service\PhishingDetection; | ||
|
|
||
| use Horde_Imap_Client; | ||
| use OCA\Mail\PhishingDetectionResult; | ||
| use OCP\IL10N; | ||
|
|
||
| class ImapFlagCheck { | ||
| protected IL10N $l10n; | ||
|
|
||
| public function __construct(IL10N $l10n) { | ||
| $this->l10n = $l10n; | ||
| } | ||
|
|
||
| /** | ||
| * @param string[] $messageFlags | ||
| */ | ||
| public function run(array $messageFlags): PhishingDetectionResult { | ||
| $flaggedAsSpam = in_array(Horde_Imap_Client::FLAG_JUNK, $messageFlags, true) || in_array('junk', $messageFlags, true); | ||
| // TODO: Use Horde const once the flag is implemented there | ||
| // (https://github.com/bytestream/Imap_Client/blob/master/lib/Horde/Imap/Client.php#L153). | ||
| $flaggedAsPhishing = in_array('$phishing', $messageFlags, true); | ||
|
|
||
| if ($flaggedAsSpam && $flaggedAsPhishing) { | ||
| return new PhishingDetectionResult(PhishingDetectionResult::IMAP_FLAG_CHECK, true, $this->l10n->t('Mail server marked this message as phishing attempt')); | ||
| } | ||
|
|
||
| return new PhishingDetectionResult(PhishingDetectionResult::IMAP_FLAG_CHECK, false); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| import { createLocalVue, shallowMount } from '@vue/test-utils' | ||
| import PhishingWarning from '../../../components/PhishingWarning.vue' | ||
| import Nextcloud from '../../../mixins/Nextcloud.js' | ||
|
|
||
| const localVue = createLocalVue() | ||
| localVue.mixin(Nextcloud) | ||
|
|
||
| describe('PhishingWarning', () => { | ||
| it('Should only show messages from positive checks', async () => { | ||
| const view = shallowMount(PhishingWarning, { | ||
| propsData: { | ||
| phishingData: [ | ||
| { | ||
| isPhishing: false, | ||
| message: 'Lorem ipsum', | ||
| }, | ||
| { | ||
| isPhishing: true, | ||
| message: 'Ipsum lorem', | ||
| }, | ||
| ], | ||
| }, | ||
| localVue, | ||
| }) | ||
|
|
||
| expect(view.text()).not.toContain('Lorem ipsum') | ||
| expect(view.text()).toContain('Ipsum lorem') | ||
| }) | ||
|
|
||
| it('Should show the messages of multiple positive checks', async () => { | ||
| const view = shallowMount(PhishingWarning, { | ||
| propsData: { | ||
| phishingData: [{ | ||
| isPhishing: true, | ||
| message: 'Lorem ipsum', | ||
| }, | ||
| { | ||
| isPhishing: true, | ||
| message: 'Ipsum lorem', | ||
| }], | ||
| }, | ||
| localVue, | ||
| }) | ||
|
|
||
| expect(view.text()).toContain('Lorem ipsum') | ||
| expect(view.text()).toContain('Ipsum lorem') | ||
| }) | ||
|
|
||
| it('Should display the option to expand the list of suspicious links', async () => { | ||
| const view = shallowMount(PhishingWarning, { | ||
| propsData: { | ||
| phishingData: [{ | ||
| isPhishing: true, | ||
| message: 'Lorem ipsum', | ||
| type: 'Link', | ||
| additionalData: [ | ||
| { | ||
| href: 'http://lorem.ipsum/', | ||
| linkText: 'Stet clita kasd gubergren', | ||
| }, | ||
| { | ||
| href: 'http://lorem2.ipsum/', | ||
| linkText: 'At vero eos et', | ||
| }, | ||
| ], | ||
| }], | ||
| }, | ||
| localVue, | ||
| }) | ||
|
|
||
| expect(view.text()).toContain('Show suspicious links') | ||
| }) | ||
|
|
||
| it('Should hide the list of suspicious links by default', async () => { | ||
| const view = shallowMount(PhishingWarning, { | ||
| propsData: { | ||
| phishingData: [{ | ||
| isPhishing: true, | ||
| message: 'Lorem ipsum', | ||
| type: 'Link', | ||
| additionalData: [ | ||
| { | ||
| href: 'http://lorem.ipsum/', | ||
| linkText: 'Stet clita kasd gubergren', | ||
| }, | ||
| { | ||
| href: 'http://lorem2.ipsum/', | ||
| linkText: 'At vero eos et', | ||
| }, | ||
| ], | ||
| }], | ||
| }, | ||
| localVue, | ||
| }) | ||
|
|
||
| expect(view.text()).not.toContain('href: http://lorem.ipsum/') | ||
| expect(view.text()).not.toContain('link text: Stet clita kasd gubergren') | ||
| expect(view.text()).not.toContain('href: http://lorem2.ipsum/') | ||
| expect(view.text()).not.toContain('At vero eos et') | ||
| }) | ||
|
|
||
| it('Should show a list of suspicious links when requested', async () => { | ||
| const view = shallowMount(PhishingWarning, { | ||
| propsData: { | ||
| phishingData: [{ | ||
| isPhishing: true, | ||
| message: 'Lorem ipsum', | ||
| type: 'Link', | ||
| additionalData: [ | ||
| { | ||
| href: 'http://lorem.ipsum/', | ||
| linkText: 'Stet clita kasd gubergren', | ||
| }, | ||
| { | ||
| href: 'http://lorem2.ipsum/', | ||
| linkText: 'At vero eos et', | ||
| }, | ||
| ], | ||
| }], | ||
| }, | ||
| data() { | ||
| return { showMore: true } | ||
| }, | ||
| localVue, | ||
| }) | ||
|
|
||
| expect(view.text()).toContain('href: http://lorem.ipsum/') | ||
| expect(view.text()).toContain('link text: Stet clita kasd gubergren') | ||
| expect(view.text()).toContain('href: http://lorem2.ipsum/') | ||
| expect(view.text()).toContain('At vero eos et') | ||
| }) | ||
|
|
||
| it('Should display the option to collapse the list of suspicious links', async () => { | ||
| const view = shallowMount(PhishingWarning, { | ||
| propsData: { | ||
| phishingData: [{ | ||
| isPhishing: true, | ||
| message: 'Lorem ipsum', | ||
| type: 'Link', | ||
| additionalData: [ | ||
| { | ||
| href: 'http://lorem.ipsum/', | ||
| linkText: 'Stet clita kasd gubergren', | ||
| }, | ||
| { | ||
| href: 'http://lorem2.ipsum/', | ||
| linkText: 'At vero eos et', | ||
| }, | ||
| ], | ||
| }], | ||
| }, | ||
| data() { | ||
| return { showMore: true } | ||
| }, | ||
| localVue, | ||
| }) | ||
|
|
||
| expect(view.text()).toContain('Hide suspicious links') | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.