2019-02-27 10:33:49 +01:00
|
|
|
|
|
|
|
# Mail format
|
|
|
|
The mail format in the api hooks
|
|
|
|
|
|
|
|
```lua
|
|
|
|
mail = {
|
|
|
|
src = "source name",
|
|
|
|
dst = "destination name",
|
|
|
|
subject = "subject line",
|
|
|
|
body = "mail body",
|
|
|
|
-- 8 attachments max
|
|
|
|
attachments = {"default:stone 99", "default:gold_ingot 99"}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2019-03-03 19:20:52 +01:00
|
|
|
## Sending mail
|
2019-03-03 19:26:10 +01:00
|
|
|
Old variant (pre-1.1)
|
2019-03-03 19:25:13 +01:00
|
|
|
```lua
|
|
|
|
mail.send("source name", "destination name", "subject line", "mail body")
|
|
|
|
```
|
|
|
|
|
2019-03-03 19:26:10 +01:00
|
|
|
New variant (1.1+)
|
2019-03-03 19:20:52 +01:00
|
|
|
```lua
|
|
|
|
mail.send({
|
|
|
|
src = "source name",
|
|
|
|
dst = "destination name",
|
|
|
|
subject = "subject line",
|
|
|
|
body = "mail body"
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
2019-02-27 10:33:49 +01:00
|
|
|
# Hooks
|
|
|
|
On-receive mail hook:
|
|
|
|
|
|
|
|
```lua
|
|
|
|
mail.register_on_receive(function(m)
|
|
|
|
-- "m" is an object in the form: "Mail format"
|
|
|
|
end)
|
|
|
|
```
|
|
|
|
|
|
|
|
# internal mail format (on-disk)
|
|
|
|
The mail format on-disk
|
|
|
|
|
|
|
|
> (worldfolder)/mails/(playername).json
|
|
|
|
|
|
|
|
```json
|
|
|
|
[{
|
|
|
|
"unread": true,
|
|
|
|
"sender": "sender name",
|
|
|
|
"subject": "subject name",
|
|
|
|
"body": "main\nmultiline\nbody",
|
|
|
|
"time": 1551258349,
|
|
|
|
"attachments": [
|
|
|
|
"default:stone 99",
|
|
|
|
"default:gold_ingot 99"
|
|
|
|
]
|
|
|
|
}]
|
|
|
|
|
2019-03-03 19:20:52 +01:00
|
|
|
```
|