# Postfix(Text)Resp

Once your `Handle()` method finished the **pps** [Handler](https://pps-docs.pebcak.de/api/handler) interfaces expects it to return a response code, so it can tell Postfix what to do with the mail in question. The [PostfixResp](https://pps-docs.pebcak.de/api/postfixresp) and the [PostifxTextResp](https://pps-docs.pebcak.de/api/postfixresp) types define all responses that Postfix accepts and the **pps** package supports.

Please check the [Postfix documentation](http://www.postfix.org/access.5.html) on the details of the various responses.

### PostfixResp

The `PostfixResp` type defines all possible respones to Postfix that do not require any type additional text appended to it. Any of these can be directly used as return value in your Handle() method.

{% tabs %}
{% tab title="Signature" %}

```go
type PostfixResp string

const (
	RespOk            PostfixResp = "OK"
	RespReject        PostfixResp = "REJECT"
	RespDefer         PostfixResp = "DEFER"
	RespDeferIfReject PostfixResp = "DEFER_IF_REJECT"
	RespDeferIfPermit PostfixResp = "DEFER_IF_PERMIT"
	RespDiscard       PostfixResp = "DISCARD"
	RespDunno         PostfixResp = "DUNNO"
	RespHold          PostfixResp = "HOLD"
	RespInfo          PostfixResp = "INFO"
	RespWarn          PostfixResp = "WARN"
)
```

{% endtab %}

{% tab title="Example" %}

```go
func Handle(ps *pps.PolicySet) pps.PostfixResp {
    fmt.Println("Postfix received a mail for:", ps.Recipient)
    return pps.RespDunno    
}
```

{% endtab %}
{% endtabs %}

### PostfixTextResp

The `PostfixTextResp` type defines those kind of responses that require to have additional information appended to it. These types cannot be directly used as return value in your `Handle()` function but need to be converted to a `PostfixResp` type first using the [Custom responses](#custom-responses) functions.

{% tabs %}
{% tab title="Siganture" %}

```go
type PostfixTextResp string

const (
	TextRespFilter   PostfixTextResp = "FILTER"
	TextRespPrepend  PostfixTextResp = "PREPEND"
	TextRespRedirect PostfixTextResp = "REDIRECT"
)
```

{% endtab %}
{% endtabs %}

## Custom responses

As already mentioned, the `PostfixResp` type responses do not require any additional information appended to, but most of those reponses allow it. For the `PostfixTextResp` types the additional information is non-optional. **pps** provides methods to create custom responses with both of these types.

### TextResponseOpt

The `TextResponseOpt()` method allows you to append custom text to your `PostfixResp` type responses. It will return a valid `PostfixResp` type that can be used as return value in your `Handle()` method.

{% tabs %}
{% tab title="Signature" %}

```go
func TextResponseOpt(PostfixResp, string) PostfixResp
```

{% endtab %}

{% tab title="Example" %}

```go
custResp := pps.TextResponseOpt(pps.RespDunno, "custom text")
```

{% endtab %}
{% endtabs %}

### TextResponseNonOpt

With the `TextResponseNonOpt()` method you can make use of the `PostfixTextResp` type responses and create a valid `PostfixResp` type with it, that can be used as return value for your `Handle()` method.

{% tabs %}
{% tab title="Signature" %}

```go
func TextResponseNonOpt(PostfixTextResp, string) PostfixResp
```

{% endtab %}

{% tab title="Example" %}

```go
custResp := pps.TextResponseNonOpt(pps.TextRespFilter, "custom:filter")
```

{% endtab %}
{% endtabs %}
