global::ctx

Inspect the transaction context.

fn to_string

fn to_string(context: Context) -> String
Produce a serialized JSON representation of the mail context.

fn client_address

fn client_address() -> String
Get the address of the client.

All of them.

  • string - the client’s address with the ip:port format.
#{
  connect: [
    action "log client address" || {
      log("info", `new client: ${ctx::client_address()}`);
    },
  ],
}

fn client_ip

fn client_ip() -> String
Get the ip address of the client.

All of them.

  • string - the client’s ip address.
#{
  connect: [
    action "log client ip" || {
      log("info", `new client: ${ctx::client_ip()}`);
    },
  ],
}

fn client_port

fn client_port() -> int
Get the ip port of the client.

All of them.

  • int - the client’s port.
#{
  connect: [
    action "log client address" || {
      log("info", `new client: ${ctx::client_ip()}:${ctx::client_port()}`);
    },
  ],
}

fn server_address

fn server_address() -> String
Get the full server address.

All of them.

  • string - the server’s address with the ip:port format.
#{
  connect: [
    action "log server address" || {
      log("info", `server: ${ctx::server_address()}`);
    },
  ],
}

fn server_ip

fn server_ip() -> String
Get the server's ip.

All of them.

  • string - the server’s ip.
#{
  connect: [
    action "log server ip" || {
      log("info", `server: ${ctx::server_ip()}`);
    },
  ],
}

fn server_port

fn server_port() -> int
Get the server's port.

All of them.

  • string - the server’s port.
#{
  connect: [
    action "log server address" || {
      log("info", `server: ${ctx::server_ip()}:${ctx::server_port()}`);
    },
  ],
}

fn connection_timestamp

fn connection_timestamp() -> OffsetDateTime
Get a the timestamp of the client's connection time.

All of them.

  • timestamp - the connection timestamp of the client.
#{
  connect: [
    action "log client" || {
      log("info", `new client connected at ${ctx::connection_timestamp()}`);
    },
  ],
}

fn server_name

fn server_name() -> String
Get the name of the server.

All of them.

  • string - the name of the server.
#{
  connect: [
    action "log server" || {
      log("info", `server name: ${ctx::server_name()}`);
    },
  ],
}

fn is_secured

fn is_secured() -> bool
Has the connection been secured under the encryption protocol SSL/TLS.

all of them.

  • bool - true if the connection is secured, false otherwise.
#{
  connect: [
    action "log ssl/tls" || {
      log("info", `The client is ${if ctx::is_secured() { "secured" } else { "unsecured!!!" }}`)
    }
  ],
}

fn helo

fn helo() -> String
Get the value of the `HELO/EHLO` command sent by the client.

helo and onwards.

  • string - the value of the HELO/EHLO command.
#{
    helo: [
       action "log info" || log("info", `helo/ehlo value: ${ctx::helo()}`),
    ]
}

fn mail_from

fn mail_from() -> SharedObject
Get the value of the `MAIL FROM` command sent by the client.

mail and onwards.

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

fn rcpt_list

fn rcpt_list() -> Array
Get the list of recipients received by the client.

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.

  • Array of addresses - the list containing all recipients.
#{
    preq: [
       action "log recipients" || log("info", `recipients: ${ctx::rcpt_list()}`),
    ]
}

fn rcpt

fn rcpt() -> SharedObject
Get the value of the current `RCPT TO` command sent by the client.

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.

  • address - the address of the received recipient.
#{
    rcpt: [
       action "log recipients" || log("info", `new recipient: ${ctx::rcpt()}`),
    ]
}

fn mail_timestamp

fn mail_timestamp() -> OffsetDateTime
Get the time of reception of the email.

preq and onwards.

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

fn message_id

fn message_id() -> String
Get the unique id of the received message.

preq and onwards.

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