Skip to content

fix: correct TLS type and add missing 'text' search property#327

Merged
andris9 merged 1 commit intopostalsys:masterfrom
Receiptor-AI:fix/typescript-definitions
Jan 8, 2026
Merged

fix: correct TLS type and add missing 'text' search property#327
andris9 merged 1 commit intopostalsys:masterfrom
Receiptor-AI:fix/typescript-definitions

Conversation

@mryraghi
Copy link
Contributor

@mryraghi mryraghi commented Jan 8, 2026

Summary

This PR fixes two TypeScript definition issues:

  1. Wrong TLS type: ImapFlow was importing TlsOptions (server-side) instead of ConnectionOptions (client-side), preventing use of client-specific options like checkServerIdentity
  2. Missing text search: The text search parameter is documented but missing from SearchObject TypeScript definitions

Problem 1: Wrong TLS Type

ImapFlow is a client that connects to IMAP servers, but it was using TlsOptions which is the server-side interface from Node's tls module.

Current (incorrect):

import { TlsOptions } from 'tls';

export interface ImapFlowOptions {
    tls?: TlsOptions;  // ❌ Server-side, missing client options
}

Impact: Users cannot use essential client TLS options without type errors:

  • checkServerIdentity - Custom hostname validation
  • servername - SNI (Server Name Indication)
  • session - Session resumption
  • minDHSize - Minimum DH parameter size

Current workaround needed:

new ImapFlow({
  tls: {
    checkServerIdentity: () => undefined
  } as any  // ❌ Type assertion required
});

Problem 2: Missing text Search

The text search parameter is documented in the ImapFlow search guide but missing from SearchObject:

text - "Any text (searches headers and body)"

Current workaround needed:

await client.search({ text: "query" } as any, { uid: true });

Solution

  1. Changed TlsOptionsConnectionOptions for correct client-side TLS typing
  2. Added text?: string to SearchObject interface with proper JSDoc

After This PR

Users can use proper typing without workarounds:

// TLS options work correctly
new ImapFlow({
  tls: {
    checkServerIdentity: () => undefined,  // ✅ No type error
    servername: 'mail.example.com'         // ✅ Works correctly
  }
});

// Text search works correctly
await client.search({ text: "query" }, { uid: true });  // ✅ No type error

Testing

  • ✅ Both features already work at runtime (this just fixes the types)
  • ✅ TypeScript compiles without errors
  • ✅ No breaking changes (purely additive/corrective)
  • ✅ Verified against Node.js tls module type definitions

References

The 'text' search parameter is documented in the official ImapFlow
documentation (https://imapflow.com/docs/guides/searching) but was
missing from the TypeScript type definitions.

This allows users to search across both headers and body content
without requiring type assertions.

Fixes type safety when using:
await client.search({ text: 'query' }, { uid: true });
Copy link
Collaborator

@andris9 andris9 left a comment

Choose a reason for hiding this comment

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

The package-lock changes are unneeded, and these will get overwritten anyway so the changes are irrelevant. Otherwise LGTM

@andris9 andris9 merged commit 0d1e43d into postalsys:master Jan 8, 2026
4 checks passed
@mryraghi mryraghi deleted the fix/typescript-definitions branch January 8, 2026 11:17
@mryraghi
Copy link
Contributor Author

mryraghi commented Jan 8, 2026

You're right, sorry about that, it slipped into my commit! Anyway, thanks for your prompt merge. Switching from node-imap, which is unstable.

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.

2 participants