Other plugins can extend Mailbox with these hooks (add them in your plugin's index.php). Mailbox never calls an AI service itself: the button hooks are the place to add AI features like "Summarise" or "Draft a reply".
| Filter | Where the button shows | Context | Button types |
| mailbox_conversation_actions | Toolbar of an open conversation | thread_id, account_id, folder_id | modal, link |
| mailbox_message_actions | Next to Reply on each email | message_id, thread_id, account_id | modal, link |
| mailbox_compose_actions | Footer of the compose window | account_id, mode, source_id, draft_id | insert |
A button is an array: title (required), url (required, made with get_uri(); only "link" buttons may use another https URL), icon (a Feather icon, default "zap") and type. modal opens your URL in a RISE modal and posts the context, link opens it in a new tab with the context in the query string, insert posts the whole compose form.
app_hooks()->add_filter("mailbox_conversation_actions", function ($buttons, $context) {
$buttons[] = array(
"title" => "Summarise",
"icon" => "cpu",
"type" => "modal",
"url" => get_uri("my_ai/summarise_modal") //receives thread_id, account_id, folder_id
);
return $buttons;
}, 10, 2);
Always check access in your own controller, because the ids come from the browser:
$access = new \Mailbox\Module\Libraries\Mailbox_access($this->login_user);
if (!$access->can_access_mailbox($account_id)) {
app_redirect("forbidden");
}
An insert button gets the compose form (account_id, to, cc, bcc, subject, body, mode, source_id, draft_id) and answers with JSON:
echo json_encode(array(
"success" => true,
"html" => "Thanks for your email...
",
"mode" => "insert", //"insert" = above the current text, "replace" = the whole body
"message" => "" //optional success message
));
| Hook | Type | When / value |
| mailbox_message_received | Action | A new email was saved by the sync. Data: message_id, thread_id, account_id, folder_id, folder_role, direction. |
| mailbox_message_sent | Action | An email was sent from RISE. Data: message_id, thread_id, account_id, user_id. |
| mailbox_incoming_connectors | Filter | type => class implementing Mailbox\Module\Libraries\Mail\Contracts\Incoming_connector. Also implement Contracts\Backfill_connector (fetch_older()) so the first import takes the newest emails first. |
| mailbox_outgoing_connectors | Filter | type => class implementing Mailbox\Module\Libraries\Mail\Contracts\Outgoing_connector. |
| mailbox_oauth_providers | Filter | type => class extending Mailbox\Module\Libraries\Mail\Oauth\Oauth_provider (type: lower case letters, numbers and _). |
The actions run inside the sync and the send request: keep them fast. Errors in your code are logged and don't stop the sync. Classes that don't exist or don't follow the contract are ignored. Mailbox also adds the notification event mailbox_new_email with the recipient term mailbox_members; on RISE versions without register_notification_event, Mailbox works without notifications.