zone-eu / zone-mta

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

missleading message:queue documentation (not ran before) #316

Open dazoot opened 2 years ago

dazoot commented 2 years ago

In the plugins page the message:queue is advertised as running BEFORE the message is stored to the queue. By checking the code i think it runs AFTER hence the queue.removeMessage call in case of error.

Am i wrong ? @andris9

andris9 commented 2 years ago

It's actually in an in-between state. The email contents have been stored, but the required queue data info has not. After message:queue you would also get queue:route. You can detect when a message has been completely processed by using the log:entry hook with entry.action==='QUEUED' like here

dazoot commented 2 years ago

I still think the documentation is missleading.

We had a script to slow down users sending huge attachments, which proved not work as expected because the mail was already stored when the hook was reached :)

We were throttling AFTER the body (huge) was saved (the thing we were trying to avoid).

andris9 commented 2 years ago

Well, I'm not sure what would be the best solution for you. Once the SMTP clients issues that DATA command you must process the incoming email stream in full. Until the client has not issued that command, there could still be some routing-specific commands coming (RCPT TO).

I guess, you should probably use 'message:store' for this use case. It's issued immediately after DATA.

From the plugin docs:

andris9 commented 2 years ago
andris9 commented 2 years ago

I guess if you want to reject and not store a message, you could create a plugin for 'message:store' that redirects email content to /dev/null and once the message has been processed, returns a 4xx error for the client. ZoneMTA would still "receive" the full message, but the message would not be stored anywhere.

dazoot commented 2 years ago

Our hack was to send SIZE in RCPT_TO and rewrite envelope.to in the plugin.

But this issue is for updating the docs to not make people think that the plugin is ran before the message is stored to the queue (mongo). This mention that the plugin is ran before storing to queue confused us a lot since the size limitation we did was not working.

Maybe we can mention the details in the docs, that the message body is actually stored to the queue to make it clear.