<a id="changing-message-states"></a>

# Changing message states

Messages are automatically moved between the
active and defer queue in accordance with the normal behavior of an MTA (try-defer-retry-defer, etc).
Messages can also be forcibly moved between queues.
Messages can be updated using
the [Protocol Buffer](https://docs.halon.io/protobuf-schemas/6.12-stable/) API’s `QueueUpdate` function, [command line interface](cli.html.md),
[web administration](web.html.md),
as well as from the pre- and [post-delivery script](https://docs.halon.io/hsl/archive/6.12-stable/postdelivery.html).
This changes both the information on disk and in memory (the queue process’s data structures).
When a message is moved, it is re-injected via the “update” actor described
in the [activity diagram](queue.html.md#activity-diagram-label).

To put queued messages for example.com on hold:

```console
$ halonctl queue update --recipientdomain example.com --state DEFER --state ACTIVE --hold
10 messages affected
```

Messages that are in a “working” (for example, being delivered) will be unaffected.
To immediately retry a certain deferred message by ID:

```console
$ halonctl queue update --id 44815e44-05d3-11ea-b388-06f091ceb4dc:1 --state DEFER --active
1 messages affected
```

<a id="messages-on-hold"></a>

## Messages on hold

Messages, or copies of messages, can be put in a frozen *HOLD* state.
This usually done from the end-of-data [script](https://docs.halon.io/hsl/archive/6.12-stable/) to implement for example short-term
quarantines. In order to enforce a retention policy for those messages, you can run
[halonctl](cli.html.md) from *cron*:

```console
# crontab -l
*/5 * * * * halonctl queue update --delete --state HOLD --age '>86400' --metadata qid=1day
*/5 * * * * halonctl queue update --delete --state HOLD --age '>604800' --metadata qid=7days
```
