ConnectorTypeIMAP
class connector_types.connector_type_imap.ConnectorTypeIMAP
Access an IMAP mailbox.
Supported commands
capabilities
Query server capabilities Returns a list of IMAP4 capabilities as responded by the server.list_folders
List available folders. Returns a list of dictionaries describing the folders on the IMAP server.folder_info
Fetch information about a folder Returns a dictionary containing the folder informationsearch
Search for messages in a folder. The folder can be specified in thefolder
input. Search criteria can be specified in thecriteria
input. Returns a list of message IDs.fetch
Fetch messages. Text payloads will be inlcuded in the outputs. Other payloads will be stored as Cloudomation files if thestore_attachments
input is set to True The folder can be specified in thefolder
input. The message IDs to fetch can be specified in themessage_set
input. Returns a dictionary describing the fetched messages.add_flags
Add flags to messages. The folder can be specified in thefolder
input. The message IDs to fetch can be specified in themessage_set
input. The flags to add can be specified in theflags
input. Returns a dictionary describing the flags of the messages.get_flags
Get flags of messages. The folder can be specified in thefolder
input. The message IDs to fetch can be specified in themessage_set
input. Returns a dictionary describing the flags of the messages.remove_flags
Remove flags from messages. The folder can be specified in thefolder
input. The message IDs to fetch can be specified in themessage_set
input. The flags to remove can be specified in theflags
input. Returns a dictionary describing the flags of the messages.set_flags
Set flags of messages. The folder can be specified in thefolder
input. The message IDs to fetch can be specified in themessage_set
input. The flags to set can be specified in theflags
input. Returns a dictionary describing the flags of the messages.move
Move messages to a folder The source folder can be specified in thefolder
input. The target folder can be specified in thetarget_folder
input. The message IDs to fetch can be specified in themessage_set
input. Requires the MOVE capability of the IMAP server. See RFC 6851.delete
Delete messages. The message IDs to delete can be specified in themessage_set
input. Returns a dictionary describing the flags of the deleted messages.
Inputs
Name | Type | Default | Description |
---|---|---|---|
command | String | list_folders | The IMAP command to use. Please refer to the Supported commands. |
criteria | List( String ) | None | Specify search criteria. If not specified "ALL" will be used. Please see https://tools.ietf.org/html/rfc3501#section-6.4.4 for possible criteria. Example: criteria=[ 'SUBJECT', 'test', 'SINCE', '11-Oct-2020', 'UNSEEN', ] |
flags | List( String ) | None | Flags to add, set or remove. |
folder | String | None | The folder to use. If not specified "INBOX" will be used. |
host | String | ||
login | String | None | |
message_set | String | None | The message_set option is a string specifying one or more messages to be acted upon. It may be a simple message number ('1'), a range of message numbers ('2:4'), or a group of non-contiguous ranges separated by commas ('1:3,6:9'). A range can contain an asterisk to indicate an infinite upper bound ('3:*'). |
password | String | None | |
port | Number | None | If not specified the default port is used (143 without SSL, or 993 with SSL) |
store_attachments | Boolean | False | Set to True to store non-text email payloads in the Cloudomation files resource |
target_folder | String | None | The target folder. Only used with the move command. |
use_ssl | Boolean | True | Whether or not to connect using IMAP4-over-SSL |
Outputs
Name | Type | Default | Description |
---|---|---|---|
execution_id | int | The ID of the connection execution | |
log | list | ||
message | str | The ended message for the connection. If the connection ended with an error, the message will contain information about what went wrong | |
result | Object | ||
status | str | The ended status for the connection. Either "success" or "error". |
Constants
input_list = ['command', 'criteria', 'flags', 'folder', 'host', 'login', 'message_set', 'password', 'port', 'store_attachments', 'target_folder', 'use_ssl'] output_list = ['log', 'result'] ssl_context_inputs = ['check_hostname', 'client_cert', 'client_key', 'server_ca'] version = 1Methods
execute ()
handle_add_flags ()
handle_capabilities ()
handle_delete ()
handle_fetch ()
handle_fetch_get_payloads (message_id, message)
handle_folder_info ()
handle_get_flags ()
handle_list_folders ()
handle_move ()
handle_remove_flags ()
handle_search ()
handle_set_flags ()
log (message)
one_of_inputs (options)
run ()
select_folder ()
Example
List all available folders of a mailbox:
import flow_api
def handler(system: flow_api.System, this: flow_api.Execution):
folders = this.connect(
connector_type='IMAP',
host='imap.gmail.com',
port=993,
use_ssl=True,
login='example@gmail.com',
password='***',
command='list_folders',
).get('output_value')['result']
this.log(folders=folders)
return this.success('all done')
List all unread (unseen) messages in a folder:
import flow_api
def handler(system: flow_api.System, this: flow_api.Execution):
message_ids = this.connect(
connector_type='IMAP',
host='imap.gmail.com',
port=993,
use_ssl=True,
login='example@gmail.com',
password='***',
command='search',
folder='INBOX',
criteria=[
'UNSEEN',
],
).get('output_value')['result']
this.log(message_ids=message_ids)
return this.success('all done')
Fetch a message:
import flow_api
def handler(system: flow_api.System, this: flow_api.Execution):
messages = this.connect(
connector_type='IMAP',
host='imap.gmail.com',
port=993,
use_ssl=True,
login='example@gmail.com',
password='***',
command='fetch',
message_set=[
'1,8:15',
],
).get('output_value')['result']
this.log(messages=messages)
return this.success('all done')
Mark a message as unseen:
The flag which is used to track seen/unseen status might differ between IMAP implementations.
import flow_api
def handler(system: flow_api.System, this: flow_api.Execution):
folders = this.connect(
connector_type='IMAP',
host='imap.gmail.com',
port=993,
use_ssl=True,
login='example@gmail.com',
password='***',
command='remove_flags',
message_set=[
'15',
],
flags=[
'\Seen',
],
).get('output_value')['result']
this.log(folders=folders)
return this.success('all done')