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

How to programmatically remove a delivery from a plugin? #306

Closed matteomattei closed 2 years ago

matteomattei commented 2 years ago

Hello, I am setting deliveryZone to null for all deliveries based on some criteria:

app.addHook('queue:route', (envelope, routing, next) => {
        if (someCondition) {
            routing.deliveryZone = null;
        }
        return next();
});

I want to drop all these deliveries instead of keeping them in mongo but turn back to the client the message ID as the message have been correctly processed. I want it behaves more or less in the same way of an account in the suppression list: the message is never delivered but the caller receives a message-id in answer.

I see I would call something like releaseDelivery() to cleanup the database, but I don't see any hook to attach and call it.

I know I can connect to mongo from an external process and remove all records with deliveryZone = null in zone-queue collection and related records in mail.chunks and mail.files but I would like to avoid a cronjob like this....

Any idea?

dazoot commented 2 years ago

I guess you can silent bounce it by using delivery.skipBounce in your plugin.

Ex:

let err = new Error('Reject message here');
err.responseCode = 554;
delivery.skipBounce = err.message;
return next(err);
dazoot commented 2 years ago

@matteomattei @andris9 close if ok.