7. Contexts

There are multiple contexts (extensions) to the language, which provides context specific variables and functions. The smtpd process implements the CONNECT, AUTH, MAIL FROM, RCPT TO and DATA context. These contexts operates on an SMTP connection. The $messageid variable is set when connecting and may be regenerated upon the client sending a RSET command. There is also a $context variable which is bound to a connection and may be changed in any flow, this is useful for passing data between flows.

  .--------------------------------. <-- CONNECT context
  | ...                            |
> | AUTH LOGIN                     | <-- AUTH context
  | ...                            |
< | 250 OK                         |
> | MAIL FROM: <[email protected]>  | <-- MAIL FROM context
< | 250 OK                         |
> | RCPT TO: <[email protected]>    | <-- RCPT TO context
< | 250 OK                         |
> | DATA                           |
< | 354 Feed me                    |
> | Subject: Lunch                 |
> |                                |
> | Lunch on friday?               |
> | .                              | <-- DATA context
< | 250 Accepted                   |
  `--------------------------------´
               |
   ,-------> queue
   |           |                     <-- Pre-delivery context
   |   delivery attempt
   |           |                     <-- Post-delivery context
   \__________/ \______ done

The mailqueued process implements the Pre- and Post-delivery contexts. These contexts operates on a message in queue. A message in queue is not directly bound to an inbound SMTP connection, hence its delivery is not done inline.