MailMessage struct represents an email message in Hoot and provides functionality to convert messages into Nostr gift-wrapped events for secure transmission over the Nostr protocol.
Struct fields
TheMailMessage struct contains the following fields:
Optional Nostr event ID for the message
Unix timestamp when the message was created
Public key of the message author
List of recipient public keys (To field)
List of CC recipient public keys
List of BCC recipient public keys
Optional list of parent event IDs for threading. Used to maintain conversation history.
Email subject line
Message body content
Optional NIP-05 identifier for the sender (e.g., “[email protected]”)
Methods
to_events()
Converts theMailMessage into a HashMap of gift-wrapped Nostr events, one for each recipient.
The sender’s Nostr keypair used to sign and encrypt the events
A HashMap mapping each recipient’s public key to their corresponding gift-wrapped event (kind 1059)
Behavior
This method performs the following operations:- Creates tags for all recipients in the
tofield (standard p tags) - Creates custom tags for CC recipients (p tags with “cc” marker)
- Adds event reference tags for threading (e tags for parent events)
- Adds NIP-05 tag if the sender has a NIP-05 identifier
- Adds the subject as a subject tag
- Creates a base event (kind 2024) with the message content
- Wraps the base event into gift-wrapped events (NIP-59) for each recipient
- Returns a HashMap where keys are recipient public keys and values are gift-wrapped events
Gift-wrapped events provide privacy by encrypting the message content and obscuring metadata. Each recipient receives their own individually encrypted copy.
Example usage
Constants
The custom Nostr event kind used for mail messages:
2024Threading behavior
Messages can be threaded by including parent event IDs in theparent_events field. When a message is a reply:
- Set
parent_eventsto include the ID(s) of the message(s) being replied to - The
to_events()method automatically adds e tags for each parent event - These tags allow the database to reconstruct conversation threads using recursive queries
Related
- RelayPool - For sending events to Nostr relays
- AccountManager - For managing keys and unwrapping received messages
- Database - For storing and retrieving messages