zone-eu / zone-mta

📤 Modern outbound MTA cross platform and extendable server application
European Union Public License 1.2
583 stars 93 forks source link

Problem passing data through envelope in plugin hooks. #391

Closed detain closed 1 month ago

detain commented 1 month ago

According to the Plugins section: If you add your own properties to the envelope object or modify existing ones then these are persisted and available in other hooks and later also from the delivery object. Only use values that can be serialized into JSON for custom properties.

app.addHook('smtp:data', async (envelope, session) => {
    // Override existing source IP with something else.
    // This value ends up in the Received header
    envelope.origin = '1.2.3.4';
    // Add new custom property
    envelope.my_custom_value = 123;
});

app.addHook('sender:fetch', delivery => {
    console.log(envelope.my_custom_value); // 123;
});

However this does not seem to be the case. Testing with the queue:release I tried to access envelope but it gave a plugin error due to envelope not being set. In the example the sender:fetch does not pass envelope either but it appears (from the docs) as if its still available to it. I think the docs might be wrong and that its only available to hooks that pass envelope. I would like to be able to pass a simple string from the sender:headers hook to the queue:release hook using this method or another. Is this possible?

louis-lau commented 1 month ago

From the top of my head I think that envelope turns into delivery at some point, hence the "later also from the delivery object". So that example would indeed be incorrect, it would need to access delivery.my_custom_value instead I think.

Then again the queue:release hook gets neither envelope nor delivery. Not sure what's in the data argument though, you could check what's in there!

detain commented 1 month ago

It is as you said the envelope data became delivery so its available in many of the hooks but not the queue:release I wound up just using redis to store the data i want between hooks.