Skip to content

fix(email): delegate the inbound fetch to the framework - #3695

Open
chdecultot wants to merge 1 commit into
frappe:developfrom
chdecultot:fix/email-account-override-delegates
Open

fix(email): delegate the inbound fetch to the framework#3695
chdecultot wants to merge 1 commit into
frappe:developfrom
chdecultot:fix/email-account-override-delegates

Conversation

@chdecultot

Copy link
Copy Markdown

Problem

CustomEmailAccount.get_inbound_mails is a full copy of EmailAccount.get_inbound_mails. Only two things in it are actually helpdesk's:

  • skipping auto-generated mails (X-Auto-Generated)
  • threading through CustomInboundMail

Everything else — the IMAP folder loop, the sync rule, the connection handling, the error path — is duplicated framework code. Any change the framework makes to the fetch loop is silently dropped on every site where helpdesk is installed.

The copy also assumes the fetched messages are bytes:

_msg = message_from_string(message.decode("utf-8", errors="replace"))

When they are not, the except Exception around it swallows the AttributeError once per message and the account quietly yields zero mails. frappe's own test_email_account helpers build messages from str, which is how I ran into it.

Fix

Do both customisations on top of super().get_inbound_mails(). InboundMail already carries everything needed to re-wrap it: raw_message, uid, seen_status and append_to.

Net effect: -66 lines, and helpdesk inherits framework fixes to the fetch loop from now on.

Verification

On a bench with helpdesk installed, the frappe.email.doctype.email_account test module goes from 1 failure + 9 errors to a single unrelated SMTP error (test_sendmail).

One caveat in the interest of transparency: that bench runs Dodock, a Frappe fork, so the exact counts may differ against upstream frappe. The duplication and the bytes assumption are identical in both, and the 9 errors were all this override swallowing every message. Happy to re-run against upstream frappe if you'd like the numbers from there.

How I found it: on a multi-folder IMAP account, mail filed into a folder mapped to append_to produced no document unless it happened to be the newest message in that folder at poll time. The framework's per-folder UID cursor was handling this correctly; the override's copy of the loop predates it and never ran that code.

🤖 Generated with Claude Code

`CustomEmailAccount.get_inbound_mails` is a full copy of
`EmailAccount.get_inbound_mails`. Only two things in it are helpdesk's:
skipping auto-generated mails, and threading through `CustomInboundMail`.
Everything else -- the IMAP folder loop, the sync rule, the connection
handling -- is duplicated framework code, so any change the framework makes
to the fetch loop is silently dropped on every site where helpdesk is
installed.

The copy also assumes the fetched messages are bytes:

    _msg = message_from_string(message.decode("utf-8", errors="replace"))

When they are not, the `except Exception` around it swallows the
`AttributeError` per message and the account quietly yields zero mails.
frappe's own `test_email_account` helpers build `messages` from `str`, which
is how I ran into this.

Do both customisations on top of `super().get_inbound_mails()` instead.
`InboundMail` already carries everything needed to re-wrap it: `raw_message`,
`uid`, `seen_status` and `append_to`.

Verified on a bench with helpdesk installed: the
`frappe.email.doctype.email_account` test module goes from 1 failure and 9
errors to a single unrelated SMTP error. Note this bench runs Dodock, a
Frappe fork, so the exact counts may differ upstream -- but the duplication
and the bytes assumption are the same in both.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@mergify

mergify Bot commented Aug 13, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@greptile-apps

greptile-apps Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge with no actionable changed-code defect identified.

The delegated results retain the raw message, UID, seen status, and append target needed by the custom inbound-mail wrapper, while per-message filtering and error handling remain intact.

Fix All in Greploop

Reviews (1): Last reviewed commit: "fix(email): delegate the inbound fetch t..." | Re-trigger Greptile

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant