Class EmailChannel
- All Implemented Interfaces:
ChannelAdapter
Inbound: polls a configured IMAP folder on a fixed schedule, converts
each UNSEEN message that passes the senderAllowlist into a
UnifiedMessage, and delivers it via ChannelContext.onMessage(com.tnsai.channels.api.UnifiedMessage).
Read messages are marked SEEN so the next poll cycle skips them.
Outbound: each UnifiedResponse becomes an SMTP send addressed
to the original sender of the thread. Thread continuity is preserved by
setting In-Reply-To to the last seen Message-ID and a
subject derived from the inbound subject (prefixed with Re: if not
already there). Recipient + Message-ID state is held per-conversationId
in a ConcurrentHashMap for the channel's lifetime — restart loses
this state, which is acceptable for an async channel where threads may
span days.
Configuration comes from EmailChannelConfig; in production
a consumer reads it from its configuration and passes it through the factory.
When started without explicit config the channel attempts
EmailChannelConfig.fromEnvironment() and reports a fatal
ChannelError if required vars are missing.
Thread safety: send(com.tnsai.channels.api.UnifiedResponse) can be invoked from any agent thread;
the IMAP poll runs on a single-threaded ScheduledExecutorService.
SMTP Transports are short-lived per-send; IMAP Stores are
opened per poll. Neither is held across the whole channel lifetime, so
there's no shared mutable JavaMail state to guard.
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor — usesEmailChannelConfig.fromEnvironment()when started.EmailChannel(EmailChannelConfig config) Programmatic constructor — used by the factory when explicit config is supplied. -
Method Summary
Modifier and TypeMethodDescriptionDeclares what this channel supports.Human-readable display name.id()Unique identifier for this channel (e.g.booleanWhether the adapter is currently connected and operational.voidsend(UnifiedResponse response) Send a response back through this channel.voidstart(ChannelContext context) Start listening for inbound messages.voidstop()Stop listening and release resources.
-
Constructor Details
-
EmailChannel
public EmailChannel()Default constructor — usesEmailChannelConfig.fromEnvironment()when started. -
EmailChannel
Programmatic constructor — used by the factory when explicit config is supplied.
-
-
Method Details
-
id
Description copied from interface:ChannelAdapterUnique identifier for this channel (e.g. "telegram", "discord", "slack").- Specified by:
idin interfaceChannelAdapter
-
displayName
Description copied from interface:ChannelAdapterHuman-readable display name.- Specified by:
displayNamein interfaceChannelAdapter
-
capabilities
Description copied from interface:ChannelAdapterDeclares what this channel supports.- Specified by:
capabilitiesin interfaceChannelAdapter
-
start
Description copied from interface:ChannelAdapterStart listening for inbound messages. The adapter should callChannelContext.onMessage(com.tnsai.channels.api.UnifiedMessage)when a message arrives.- Specified by:
startin interfaceChannelAdapter- Parameters:
context- callback interface for delivering events to the gateway
-
stop
public void stop()Description copied from interface:ChannelAdapterStop listening and release resources.- Specified by:
stopin interfaceChannelAdapter
-
isRunning
public boolean isRunning()Description copied from interface:ChannelAdapterWhether the adapter is currently connected and operational.- Specified by:
isRunningin interfaceChannelAdapter
-
send
Description copied from interface:ChannelAdapterSend a response back through this channel.- Specified by:
sendin interfaceChannelAdapter- Parameters:
response- the unified response to deliver
-