Email
Research
Email engineering guide

Retrieving Gmail messages efficiently and correctly

Gmail message retrieval is a two-stage operation: list IDs for a bounded query, then fetch only the metadata, parsed payload, or raw MIME that the product needs.

Research surface only. This guide documents architecture and evaluation criteria; it does not describe a released DewEngine connector.
01
Search

Use list requests to discover candidate IDs

Filter by Gmail search query and label IDs, respect page tokens, and keep the result order separate from synchronization correctness. A list response is intentionally lightweight and does not include every message field.

  • Account and label scope
  • Search query
  • Page token
  • Result-size estimate, not a completion signal
02
Representation

Choose the smallest message format

Use metadata for headers, full for parsed MIME structure, raw when the original RFC message is required, and minimal for identifiers and labels. Cache only the representation the feature and retention policy justify.

03
MIME

Parse multipart messages defensively

Walk nested parts, distinguish text and HTML alternatives, decode transfer encodings, validate content type and filename, and fetch attachment data by attachment ID when it is not inline in the payload.

04
Synchronization

Do not use repeated search as change tracking

After a baseline, use Gmail history records and watches to discover updates. Retain message and thread IDs, apply label changes and deletes, and full-sync again when the history cursor is no longer valid.

  • History checkpoint
  • Label change handling
  • Deletion tombstone
  • 404 cursor recovery
Questions

Before you build.

Does messages.list return complete email bodies?+

No. It primarily returns message identifiers. Fetch each selected message with messages.get in the format the feature requires.

Are Gmail message IDs the same as RFC Message-ID headers?+

No. Gmail's resource ID is provider-specific. Preserve it alongside the Internet Message-ID header when both are needed.

Can I use DewEngine's email connectors today?+

Not yet. Gmail, Microsoft Graph, and IMAP/SMTP connectors are planned. This guide documents the intended architecture and the provider requirements a production release must satisfy.

Build with us

Does this match the workflow your users need?

DewEngine is in development. Real use cases decide what ships first.

Share your use case