Skip to content

[18.0][FIX] fetchmail_attach_from_folder: case-insensitive email matching#3610

Open
fsmw wants to merge 1 commit into
OCA:18.0from
fsmw:18.0-fix-email-case-insensitive
Open

[18.0][FIX] fetchmail_attach_from_folder: case-insensitive email matching#3610
fsmw wants to merge 1 commit into
OCA:18.0from
fsmw:18.0-fix-email-case-insensitive

Conversation

@fsmw
Copy link
Copy Markdown

@fsmw fsmw commented May 16, 2026

Bug

Closes #3402

Emails containing uppercase letters were not linked to partner records because the match algorithm lowercased the incoming email addresses but then searched with (case-sensitive exact match). If the partner stored the email as mixed-case (e.g. Name.SURNAME@Domain.com), the match failed.

Fix

Use Odoo's operator instead of . This matches Odoo's own approach in core ( line 965) and performs a case-insensitive exact match via PostgreSQL .

Changes

  • : default operator changed from to
  • : added covering uppercase email matching

Compatibility

  • Fully backward compatible: existing exact matches still work; now uppercase variants also match.

@OCA-git-bot
Copy link
Copy Markdown
Contributor

Hi @NL66278,
some modules you are maintaining are being modified, check this out!

@OCA-git-bot OCA-git-bot added series:18.0 mod:fetchmail_attach_from_folder Module fetchmail_attach_from_folder labels May 16, 2026
@NL66278
Copy link
Copy Markdown
Contributor

NL66278 commented May 17, 2026

@fsmw I think the bug is valid and the problem real. However replacing an equal comparison = with ilike might run into a lot of other problems. Suppose a mail is fetched for fernando@example.com, and there is a partner with email Fernando@example.com in the database. Your solution will find this, but will also find Alexando-Fernando@example.com. So maybe better to encourage people to search on email_normalized instead of on email (and reflect this in the tests and examples). What do you think?

Emails with uppercase letters were not matching partner records
because the search used "=" which is case-sensitive in PostgreSQL.

Changes:
- Use Odoo's email_normalize() on incoming addresses for consistent,
  normalized matching (strips display names, lowercases).
- Keep "=ilike" operator, but now search values are normalized so
  there are no wildcards — it functions as a case-insensitive "=".
- Added test coverage for partner stored as uppercase and display-name
  headers ("Name <email@domain>").

Fixes OCA#3402
@fsmw fsmw force-pushed the 18.0-fix-email-case-insensitive branch from 8507d1e to ee2f961 Compare May 17, 2026 14:39
@fsmw
Copy link
Copy Markdown
Author

fsmw commented May 17, 2026

Hi @NL66278, thanks for the review and the valid concern. Your suggestion has been incorporated:

  • _get_mailaddresses() now uses Odoo's email_normalize() to normalize incoming addresses (strips display names, lowercases, handles edge cases).
  • Since the search values are normalized and contain no % wildcards, =ilike functions exactly as a case-insensitive = — it won't match substrings.
  • Added test coverage for partner stored with uppercase email and for display-name headers ("Name email@domain").

Let me know if anything else is needed.

# Normalize using email_normalize for consistent matching.
# This strips display names, lowercases the address, and handles
# edge cases (e.g. "<user@domain.com>" or "User <user@domain.com>").
return [email_normalize(addr) or addr.lower() for addr in mailaddresses]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the or addr.lower() not superfluous here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:fetchmail_attach_from_folder Module fetchmail_attach_from_folder series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Email matching fails when addresses contain uppercase letters

3 participants