Skip to content

[Bug]: [Email] IMAP fetch error: 'int' object has no attribute 'decode' #18106

Open

Description

@mwhuss

Bug Description

2026-04-30 21:29:36,163 ERROR gateway.platforms.email: [Email] IMAP fetch error: 'int' object has no attribute 'decode'

2026-04-30 21:24:42,963 INFO gateway.platforms.email: [Email] Adapter initialized for <email>@icloud.com
2026-04-30 21:24:42,964 INFO gateway.run: Connecting to email...
2026-04-30 21:24:44,094 INFO gateway.platforms.email: [Email] IMAP connection test passed. 3 existing messages skipped.
2026-04-30 21:24:45,351 INFO gateway.platforms.email: [Email] SMTP connection test passed.

... later ...

2026-04-30 20:42:39,102 ERROR gateway.platforms.email: [Email] IMAP fetch error: 'int' object has no attribute 'decode'
2026-04-30 20:46:02,329 ERROR gateway.platforms.email: [Email] IMAP fetch error: _ssl.c:1012: The handshake operation timed out
2026-04-30 20:47:22,904 ERROR gateway.platforms.email: [Email] IMAP fetch error: 'int' object has no attribute 'decode'

Steps to Reproduce

  • Setup an IMAP and SMTP server. In this case it's for an iCloud email address.
  • Restart the gateway
  • Wait for it to fail

Expected Behavior

Email Messaging works as outlined in the documentation: https://hermes-agent.nousresearch.com/docs/user-guide/messaging/email

Actual Behavior

Email messaging does not work due to the error.

Affected Component

Gateway (Telegram/Discord/Slack/WhatsApp)

Messaging Platform (if gateway-related)

N/A (CLI only)

Debug Report

Impacted lines included above as these pastes included private information.

Operating System

Ubuntu 22.04.5 LTS

Python Version

Python 3.14.4

Hermes Version

0.11.0

Additional Logs / Traceback (optional)

Root Cause Analysis (optional)

No response

Proposed Fix (optional)

No response

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

Activity

  1. added
    type/bugSomething isn't working
    comp/gatewayGateway runner, session dispatch, delivery
    P2Medium — degraded but workaround exists
    on Apr 30, 2026
  2. alt-glitch commented on Apr 30, 2026

    @alt-glitch

    Likely duplicate of #12498 — same root cause: IMAP FETCH response contains non-bytes payloads (int/None) from iCloud, needs type guard before .decode().

  3. alt-glitch commented on Apr 30, 2026

    @alt-glitch

    Likely duplicate of #12498

  4. mwhuss commented on Apr 30, 2026

    @mwhuss
    Author

    I believe you're right. The fix recommended in #12498 touches the same code Gemini just patched locally to try to resolve the issue.

  5. mknightz commented on May 10, 2026

    @mknightz

    Confirming this is iCloud-specific and tracing the actual mechanism in case it
    helps maintainers pick between the existing PRs.

    Reproduction

    Hit the same 'int' object has no attribute 'decode' error fetching from
    imap.mail.me.com with iCloud+ Custom Domain. Persistent 100% loss on every
    UNSEEN message; never observed against Gmail's IMAP for the same code path.

    Mechanism

    Three things compound to make this a permanent loss rather than a retryable
    error:

    1. iCloud responds to (RFC822) with a single bare-bytes element like
      [b'<UID> (UID <uid>)'] — no body data items at all. msg_data[0] is
      bytes not the expected (envelope, body) tuple, so msg_data[0][1]
      evaluates to an int (the ord of that byte). email.message_from_bytes(int)
      raises the 'int' object has no attribute 'decode' we see.

    2. The except block at the bottom of _fetch_new_messages swallows the
      error with logger.error(...) and moves on.

    3. Crucially, the UID was already added to _seen_uids before the fetch
      (in-memory dedupe), AND the iCloud server set the \Seen flag as a side
      effect of the (RFC822) request itself. So subsequent UNSEEN searches
      won't find it AND the in-memory dedupe will skip it after restart — the
      message is gone for good.

    Gmail returns the standard (envelope, body) tuple shape for (RFC822),
    which is why this is iCloud-specific.

    Local fix

    We run a fix that's equivalent to combining #14939 / #21987 (BODY.PEEK[] swap)
    with #12498 / #18146 (defensive non-bytes guard) — the protocol switch addresses
    factors 1 and 3, and the type guard catches any remaining shape variation as
    defense in depth. Verified end-to-end against iCloud across multiple UIDs over
    a one-week soak. Diff for reference:
    main...mknightz:hermes-agent:fix/icloud-rfc822-empty-body

    Not opening a PR — the existing queue covers it. Happy to comment on the
    BODY.PEEK[] PRs with the iCloud-specific reproduction if that would help.

  6. added
    comp/pluginsPlugin system and bundled plugins
    P3Low — cosmetic, nice to have
    sweeper:risk-message-deliverySweeper risk: may drop, duplicate, misroute, or suppress messages
    and removed
    comp/gatewayGateway runner, session dispatch, delivery
    P2Medium — degraded but workaround exists
    on Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low — cosmetic, nice to havecomp/pluginsPlugin system and bundled pluginsplatform/emailEmail (IMAP/SMTP) adaptersweeper:risk-message-deliverySweeper risk: may drop, duplicate, misroute, or suppress messagestype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions