3.5. Hooks¶
Hooks are python callables that live in a module specified by hooksfile in the
config. Per default this points to ~/.config/alot/hooks.py
.
Pre/Post Command Hooks
For every COMMAND in mode MODE, the callables pre_MODE_COMMAND()
and post_MODE_COMMAND()
– if defined – will be called before and after the command is applied respectively. The signature for the
pre-send hook in envelope mode for example looks like this:
-
pre_envelope_send
(ui=None, dbm=None, cmd=None)¶ Parameters: - ui (
alot.ui.UI
) – the main user interface - dbm (
alot.db.manager.DBManager
) – a database manager - cmd (
alot.commands.Command
) – the Command instance that is being called
- ui (
Consider this pre-hook for the exit command, that logs a personalized goodbye message:
import logging
from alot.settings import settings
def pre_global_exit(**kwargs):
accounts = settings.get_accounts()
if accounts:
logging.info('goodbye, %s!' % accounts[0].realname)
else:
logging.info('goodbye!')
Other Hooks
Apart from command pre- and posthooks, the following hooks will be interpreted:
-
reply_prefix
(realname, address, timestamp[, ui= None, dbm=None])¶ Is used to reformat the first indented line in a reply message. This defaults to ‘Quoting %s (%s)n’ % (realname, timestamp)’ unless this hook is defined
Parameters: - realname (str) – name or the original sender
- address (str) – address of the sender
- timestamp (
datetime.datetime
) – value of the Date header of the replied message
Return type:
-
forward_prefix
(realname, address, timestamp[, ui= None, dbm=None])¶ Is used to reformat the first indented line in a inline forwarded message. This defaults to ‘Forwarded message from %s (%s)n’ % (realname, timestamp)’ if this hook is undefined
Parameters: - realname (str) – name or the original sender
- address (str) – address of the sender
- timestamp (
datetime.datetime
) – value of the Date header of the replied message
Return type:
-
pre_edit_translate
(bodytext[, ui= None, dbm=None])¶ used to manipulate a messages bodytext before the editor is called.
Parameters: bodytext (str) – text representation of mail body as displayed in the interface and as sent to the editor Return type: str
-
post_edit_translate
(bodytext[, ui= None, dbm=None])¶ used to manipulate a messages bodytext after the editor is called
Parameters: bodytext (str) – text representation of mail body as displayed in the interface and as sent to the editor Return type: str
-
text_quote
(message)¶ used to transform a message into a quoted one
Parameters: message (str) – message to be quoted Return type: str
-
timestamp_format
(timestamp)¶ represents given timestamp as string
Parameters: bodytext – timestamp to represent Return type: str
-
touch_external_cmdlist
(cmd, shell=shell, spawn=spawn, thread=thread)¶ used to change external commands according to given flags shortly before they are called.
Parameters: Returns: triple of amended command list, shell and thread flags
Return type: list of str, bool, bool
-
reply_subject
(subject)¶ used to reformat the subject header on reply
Parameters: subject (str) – subject to reformat Return type: str
-
forward_subject
(subject)¶ used to reformat the subject header on forward
Parameters: subject (str) – subject to reformat Return type: str
-
pre_buffer_open
(ui= None, dbm=None, buf=buf)¶ run before a new buffer is opened
Parameters: buf (alot.buffer.Buffer) – buffer to open
-
post_buffer_open
(ui=None, dbm=None, buf=buf)¶ run after a new buffer is opened
Parameters: buf (alot.buffer.Buffer) – buffer to open
-
pre_buffer_close
(ui=None, dbm=None, buf=buf)¶ run before a buffer is closed
Parameters: buf (alot.buffer.Buffer) – buffer to open
-
post_buffer_close
(ui=None, dbm=None, buf=buf, success=success)¶ run after a buffer is closed
Parameters: - buf (alot.buffer.Buffer) – buffer to open
- success (boolean) – true if successfully closed buffer
-
pre_buffer_focus
(ui=None, dbm=None, buf=buf)¶ run before a buffer is focused
Parameters: buf (alot.buffer.Buffer) – buffer to open
-
post_buffer_focus
(ui=None, dbm=None, buf=buf, success=success)¶ run after a buffer is focused
Parameters: - buf (alot.buffer.Buffer) – buffer to open
- success (boolean) – true if successfully focused buffer