global::ctx

Inspect the transaction context.

fn client_address

fn client_address() -> String
details

Get the address of the client.

Effective smtp stage

All of them.

Return

  • string - the client’s address with the ip:port format.

Examples

#{
  connect: [
    action "log client address" || {
      log("info", `new client: ${ctx::client_address()}`);
    },
  ],
}

fn client_ip

fn client_ip() -> String
details

Get the ip address of the client.

Effective smtp stage

All of them.

Return

  • string - the client’s ip address.

Example

#{
  connect: [
    action "log client ip" || {
      log("info", `new client: ${ctx::client_ip()}`);
    },
  ],
}

fn client_port

fn client_port() -> int
details

Get the ip port of the client.

Effective smtp stage

All of them.

Return

  • int - the client’s port.

Example

#{
  connect: [
    action "log client address" || {
      log("info", `new client: ${ctx::client_ip()}:${ctx::client_port()}`);
    },
  ],
}

fn connection_timestamp

fn connection_timestamp() -> OffsetDateTime
details

Get a the timestamp of the client’s connection time.

Effective smtp stage

All of them.

Return

  • timestamp - the connexion timestamp of the client.

Example

#{
  connect: [
    action "log client" || {
      log("info", `new client connected at ${ctx::connection_timestamp()}`);
    },
  ],
}

fn helo

fn helo() -> String
details

Get the value of the HELO/EHLO command sent by the client.

Effective smtp stage

helo and onwards.

Return

  • string - the value of the HELO/EHLO command.

Examples

#{
    helo: [
       action "log info" || log("info", `helo/ehlo value: ${ctx::helo()}`),
    ]
}

fn is_secured

fn is_secured() -> bool
details

Has the connection been secured under the encryption protocol SSL/TLS.

Effective smtp stage

all of them.

Return

  • bool - true if the connection is secured, false otherwise.

Example

#{
  connect: [
    action "log ssl/tls" || {
      log("info", `The client is ${if ctx::is_secured() { "secured" } else { "unsecured!!!" }}`)
    }
  ],
}

fn mail_from

fn mail_from() -> SharedObject
details

Get the value of the MAIL FROM command sent by the client.

Effective smtp stage

mail and onwards.

Return

  • address - the sender address.

Examples

#{
    helo: [
       action "log info" || log("info", `received sender: ${ctx::mail_from()}`),
    ]
}

fn mail_timestamp

fn mail_timestamp() -> OffsetDateTime
details

Get the time of reception of the email.

Effective smtp stage

preq and onwards.

Return

  • string - the timestamp.

Examples

#{
    preq: [
       action "receiving the email" || log("info", `time of reception: ${ctx::mail_timestamp()}`),
    ]
}

fn message_id

fn message_id() -> String
details

Get the unique id of the received message.

Effective smtp stage

preq and onwards.

Return

  • string - the message id.

Examples

#{
    preq: [
       action "message received" || log("info", `message id: ${ctx::message_id()}`),
    ]
}

fn rcpt

fn rcpt() -> SharedObject
details

Get the value of the current RCPT TO command sent by the client.

Effective smtp stage

rcpt and onwards. Please note that ctx::rcpt() will always return the last recipient received in stages after the rcpt stage. Therefore, this functions is best used in the rcpt stage.

Return

  • address - the address of the received recipient.

Examples

#{
    rcpt: [
       action "log recipients" || log("info", `new recipient: ${ctx::rcpt()}`),
    ]
}

fn rcpt_list

fn rcpt_list() -> Array
details

Get the list of recipients received by the client.

Effective smtp stage

rcpt and onwards. Note that you will not have all recipients received all at once in the rcpt stage. It is better to use this function in the later stages.

Return

  • Array of addresses - the list containing all recipients.

Examples

#{
    preq: [
       action "log recipients" || log("info", `recipients: ${ctx::rcpt_list()}`),
    ]
}

fn server_address

fn server_address() -> String
details

Get the full server address.

Effective smtp stage

All of them.

Return

  • string - the server’s address with the ip:port format.

Example

#{
  connect: [
    action "log server address" || {
      log("info", `server: ${ctx::server_address()}`);
    },
  ],
}

fn server_ip

fn server_ip() -> IpAddr
details

Get the server’s ip.

Effective smtp stage

All of them.

Return

  • string - the server’s ip.

Example

#{
  connect: [
    action "log server ip" || {
      log("info", `server: ${ctx::server_ip()}`);
    },
  ],
}

fn server_name

fn server_name() -> String
details

Get the name of the server.

Effective smtp stage

All of them.

Return

  • string - the name of the server.

Example

#{
  connect: [
    action "log server" || {
      log("info", `server name: ${ctx::server_name()}`);
    },
  ],
}

fn server_port

fn server_port() -> int
details

Get the server’s port.

Effective smtp stage

All of them.

Return

  • string - the server’s port.

Example

#{
  connect: [
    action "log server address" || {
      log("info", `server: ${ctx::server_ip()}:${ctx::server_port()}`);
    },
  ],
}

fn to_string

fn to_string(context: Context) -> String
details

Produce a serialized JSON representation of the mail context.