Add msg:set_data()

This method allows replacing the message payload arbitrarily.
This is a building block for more advanced and convenient
modification operations.

refs: https://github.com/KumoCorp/kumomta/issues/117
refs: https://github.com/KumoCorp/kumomta/issues/120
This commit is contained in:
Wez Furlong
2024-03-31 06:57:59 -07:00
parent edc56226f7
commit 1fb712e2bf
3 changed files with 17 additions and 0 deletions
+4
View File
@@ -915,6 +915,10 @@ impl UserData for Message {
let data = this.get_data();
lua.create_string(&*data)
});
methods.add_method("set_data", move |_lua, this, data: mlua::String| {
this.assign_data(data.as_bytes().to_vec());
Ok(())
});
methods.add_method("id", move |_, this, _: ()| Ok(this.id().to_string()));
methods.add_method("sender", move |_, this, _: ()| {
Ok(this.sender().map_err(any_err)?)
+2
View File
@@ -2,3 +2,5 @@
Returns the message body/data as a string.
See also:
* [msg:set_data()](set_data.md)
+11
View File
@@ -0,0 +1,11 @@
# `message:set_data(payload)`
{{since('dev')}}
Replaces the message body/data completely.
It is your responsibility to ensure that the content is well-formed, has
canonical CRLF line endings, and uses appropriate transfer-encoding, otherwise
the system will misbehave when delivering the message.
See also:
* [msg:get_data()](get_data.md)