3

For a project I am currently working on, we received a requirement for a 'dynamic' mail attachment size limit. For postfix (which we currently use) this would be easily implemented using the message_size_limit configuration option. This however prevents the user from sending an email with an attachment. Our use case requires for two different limits. In some situations a lower limit is applied, but this should be transparent to the users. They should still be able to send an email with an attachment which is smaller in size than the maximum limit.

So we would like to prevent a 'message-too-large' rejection mail, but instead queue the message to re-attempt delivery at a later time. So when the size limit for attachments is increased again, the mail will still get delivered to the recipient.

Background

We need this ability for vessels which can sometimes be connected to a slow satellite uplink, and other times be connected to a high-speed uplink. For the high-speed uplink large attachments (<20MB) aren't that much of a problem, but for a very-low bandwidth satellite connection this becomes a problem, so we want to limit the attachment size. This however shouldn't be visible to the user, since he has no knowledge about the current uplink type.

masegaloeh
  • 17,978
  • 9
  • 56
  • 104
  • How would you programmatically define uplink bandwidth status? If you have that answer, you can cron a periodic test from the client/sender side, if uplink bandwidth has changed significantly, you alter message_size_limit and reload/restart postfix. This may get problematic if you have many vessels. – JayMcTee Sep 02 '15 at 10:09

1 Answers1

4

Here I assume you have a mechanism monitoring uplink status of your server. You need to run a script described below when the uplink changes.

Postfix only check message size before queue the message it self. The action was either 200 accept or 5XX reject. There are no custom action like, "Hey postfix please hold this big message until we are connected to high speed uplink".

So, we need companion here. You can use postfwd to do message size checking for you. When your message exceed the limit from postfwd, you can define custom action, like HOLD action. According from man 5 access, when HOLD action applied to a message then

HOLD optional text...

Place the message on the hold queue, where it will sit until someone either deletes it or releases it for delivery. Log the optional text if specified, otherwise log a generic message.

So here the idea:

  • When you are connected to slow uplink, put the lower limit in postfwd. When a user send message exceeded the lower limit, postfix will HOLD it. It stays in queue and postfix won't bother to delivery it.
  • When you are connected to high speed uplink, the script will put the higher limit in postfwd. Then the script must issued postsuper command as root to release the email from HOLD queue.

    postsuper -H ALL
    

    Note, in this case the postfwd limit must be greater than message_size_limit in postfix. Otherwise, postfix won't reject big message but hold it.

  • When you are connected to slow uplink again, put the lower limit in postfwd.

The example rule of postfwd is

# replace 192.168.1.0/24 with your local network and 12345 with limit size
id=RULE001
    client_address=192.168.1.0/24
    size=12345
    action=HOLD exceed slow link limit

Please consult postfwd docs about installation and its rules. This answer won't covered it.

masegaloeh
  • 17,978
  • 9
  • 56
  • 104