<a id="module-disconnect"></a>

<a id="disconnect"></a>

# Disconnect

This script is executed when the client has disconnected.

<a id="variables"></a>

## Variables

These are the pre-defined variables available for each command. Depending on when the disconnect script is executed, the different objects may contain different information.

| Variable                                                   | Type   | Read-only   | Description                                  |
|------------------------------------------------------------|--------|-------------|----------------------------------------------|
| [$arguments](#v-xc9)  | array  | yes         | Context/hook arguments                       |
| [$connection](#v-c9) | array  | yes         | Connection/session bound                     |
| $transaction                                               | array  | yes         | Transaction bound (empty)                    |
| $context                                                   | any    | no          | Connection bound user-defined (default none) |

<a id="v-xc9"></a>

<a id="arguments"></a>

### Arguments

| Array item                                           | Type   | Example                                  | Description                                          |
|------------------------------------------------------|--------|------------------------------------------|------------------------------------------------------|
| close                                                | string | `"local"`                                | Who initialized the disconnect (`local` or `remote`) |
| [reply](#ac9r) | array  | `["code" => 250, "enhanced" => [1, ...]` | A SMTP protocol response (if available)              |
| [error](#ac9e) | array  | `["reason" => "....`                     | If an error occurred (if available)                  |

<a id="ac9e"></a>

<a id="error"></a>

#### Error

| Array item   | Type   | Example                      | Description                                                                          |
|--------------|--------|------------------------------|--------------------------------------------------------------------------------------|
| reason       | string | `"Connection reset by peer"` | The error message                                                                    |
| type         | string | `"socket"`                   | The type of error (if avilable, `socket` or `tls`)                                   |
| code         | number | `54`                         | The error code (for `socket` it’s an errno and for `tls` it’s an OpenSSL error code) |

<a id="ac9r"></a>

<a id="reply"></a>

#### Reply

| Array item                                               | Type   | Example     | Description                                                           |
|----------------------------------------------------------|--------|-------------|-----------------------------------------------------------------------|
| code                                                     | number | `221`       | A SMTP status code                                                    |
| enhanced                                                 | array  | `[2, 5, 0]` | A SMTP enhanced status code                                           |
| reason                                                   | array  | `["Bye"]`   | A SMTP response text                                                  |
| [state](postdelivery.html.md#as1) | string | `"QUIT"`    | An enum to indicate which issued SMTP command triggerd the disconnect |

<a id="v-c9"></a>

<a id="connection"></a>

### Connection

| Array item                                          | Type   | Example                     | Description                                              |
|-----------------------------------------------------|--------|-----------------------------|----------------------------------------------------------|
| id                                                  | string | `"18c190a3-93f-47d7-bd..."` | ID of the connection                                     |
| priority                                            | number | `1`                         | The connection priority                                  |
| remoteip                                            | string | `"192.168.1.11"`            | IP address of the connected client                       |
| remoteport                                          | number | `41666`                     | TCP port of connected client                             |
| remoteptr                                           | string | `"mail.example.org"`        | Reverse DNS (FCrDNS) for remoteip (not always available) |
| remoteuid                                           | number | `106`                       | UNIX socket remote user id (not always available)        |
| localip                                             | string | `"10.0.0.1"`                | IP address of the server                                 |
| localport                                           | number | `25`                        | TCP port of the server                                   |
| serverid                                            | string | `"inbound"`                 | ID of the server                                         |
| [helo](#he9) | array  |                             | HELO information (not always available)                  |
| [tls](#tls9)  | array  |                             | TLS information (if TLS was started)                     |
| [auth](#au9) | array  |                             | AUTH information (not always available)                  |

<a id="he9"></a>

<a id="helo"></a>

#### HELO

| Array item   | Type   | Example              | Description          |
|--------------|--------|----------------------|----------------------|
| verb         | string | `"EHLO"`             | HELO or EHLO command |
| host         | string | `"mail.example.com"` | HELO hostname        |

<a id="tls9"></a>

<a id="tls"></a>

#### TLS

| Array item                                              | Type   | Example                     | Description                                      |
|---------------------------------------------------------|--------|-----------------------------|--------------------------------------------------|
| protocol                                                | string | `"TLSv1.3"`                 | The protocol                                     |
| cipher                                                  | string | `"ECDHE-RSA-AES256-SHA384"` | The cipher                                       |
| keysize                                                 | number | `256`                       | The keysize                                      |
| sni                                                     | string | `"example.com"`             | The SNI hostname (not always available)          |
| [peercert](#p9) | array  |                             | The peer certificate (if provided by the client) |

<a id="p9"></a>

<a id="peercert"></a>

##### Peercert

| Array item   | Type         | Example   | Description                                                                                          |
|--------------|--------------|-----------|------------------------------------------------------------------------------------------------------|
| x509         | X509Resource |           | An X509Resource to be used with the [`X509`](functions.html.md#X509) class |
| chain        | array        |           | An array of X509Resource (the chain)                                                                 |
| error        | number       | `18`      | The peer certificate validation error (see OpenSSLs SSL_get_verify_result(3))                        |

<a id="au9"></a>

<a id="auth"></a>

#### AUTH

| Array item   | Type   | Example      | Description                          |
|--------------|--------|--------------|--------------------------------------|
| mechanism    | string | `"PLAIN"`    | SASL mechanism (always in uppercase) |
| username     | string | `"mailuser"` | SASL username (not always available) |

<a id="functions"></a>

## Functions

<a id="Pass"></a>

<a id="disconnect.Pass"></a>

### Pass()

Terminate the disconnect script.

* **Returns:**
  doesn’t return, script is terminated

<a id="on-script-error"></a>

## On script error

On script error [`Pass()`](#disconnect.Pass) is called.

<a id="on-implicit-termination"></a>

## On implicit termination

If not explicitly terminated then [`Pass()`](#disconnect.Pass) is called.
