hermes - ✅(Solved) Fix [Bug]: [Email] IMAP fetch error: 'int' object has no attribute 'decode' [1 pull requests, 3 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#18106Fetched 2026-05-01 05:53:47
View on GitHub
Comments
3
Participants
2
Timeline
8
Reactions
0
Author
Participants
Timeline (top)
labeled ×4commented ×3cross-referenced ×1

Error Message

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'

Root Cause

Root Cause Analysis (optional)

Fix Action

Fixed

PR fix notes

PR #18146: fix(email): guard IMAP FETCH response against non-bytes payloads

Description (problem / solution / changelog)

Problem

Fixes #12498 Fixes #18106

Some IMAP servers return malformed FETCH responses where the body slot is an int, plain bytes, or None instead of the expected (header, body) tuple. Accessing msg_data[0][1] then either raises IndexError/TypeError, or returns an int (indexing bytes yields an int in Python 3), which only surfaces later as:

ERROR gateway.platforms.email: [Email] IMAP fetch error: 'int' object has no attribute 'decode'

The exception kills the inner loop iteration and is caught by the outer try/except at the bottom of _fetch_new_messages, so the entire polling pass returns empty — no messages are dispatched for that tick.

Observed on iCloud (OVH IMAP) and reported independently in two issues.

Fix

Add a two-stage guard around the fetch response, inside the per-UID loop in _fetch_new_messages:

  1. try/except (IndexError, TypeError) around msg_data[0][1] access
  2. isinstance(raw_email, (bytes, bytearray)) check before message_from_bytes

In both branches, log a warning with the offending UID and continue to the next message rather than bailing on the entire poll pass.

Before vs After

ScenarioBeforeAfter
msg_data[0] is bytes (indexing yields int)'int' object has no attribute 'decode', entire poll failsWarning logged, message skipped, rest of inbox processed
msg_data[0] is NoneTypeError, entire poll failsWarning logged, message skipped, rest of inbox processed
Normal (header, body) tupleParses OKUnchanged

Tests

  • tests/gateway/test_email.py — added TestFetchMalformedResponse with 2 tests:
    • test_fetch_skips_int_payload: msg_data = [b"abcdef"]msg_data[0][1] is int → guard skips
    • test_fetch_skips_none_payload: msg_data = [None]TypeError → guard skips

Changed files

  • gateway/platforms/email.py (modified, +18/-1)
  • tests/gateway/test_email.py (modified, +45/-0)

Code Example

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'

---

Impacted lines included above as these pastes included private information.

---
RAW_BUFFERClick to expand / collapse

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

extent analysis

TL;DR

The issue is likely due to an incorrect data type being passed to a function that expects a bytes-like object, causing the 'int' object has no attribute 'decode' error, and a potential SSL handshake timeout.

Guidance

  • Verify the IMAP connection settings and ensure that the credentials and server details are correct.
  • Check the code that handles the IMAP fetch operation to ensure that the correct data type is being passed to the decode function.
  • Investigate the SSL handshake timeout error and consider increasing the timeout value or checking the server's SSL configuration.
  • Review the email adapter initialization and connection test logs to ensure that the adapter is properly configured and connected.

Example

No code snippet can be provided without more context, but the issue seems to be related to the gateway.platforms.email module.

Notes

The issue may be specific to the iCloud email server or the Hermes version being used. Further investigation is needed to determine the root cause.

Recommendation

Apply workaround: Increase the SSL handshake timeout value and verify the IMAP connection settings to mitigate the issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - ✅(Solved) Fix [Bug]: [Email] IMAP fetch error: 'int' object has no attribute 'decode' [1 pull requests, 3 comments, 2 participants]