Sat, 09 Sep 2006

Restricting Mail Delivery Times with Exim

Denisa decided she doesn't want to feel compelled to check her email all day long, and asked me if there was a way to restrict the hours during which she could receive email. Since I use the magical MTA that is Exim, I was sure this must be possible. While I couldn't find explicit support for such a feature, I was able to hack something out. Here's my new local_delivery transport:

local_delivery:
  driver = appendfile
  envelope_to_add
  file = /var/spool/mail/${local_part}
  group = mail
  mode = 0660
  no_mode_fail_narrower
  return_path_add
  # hack to queue messages during certain hours
  message_size_limit = ${if ! and {\
    {match_local_part{$local_part}{+time_restricted_users}} \
    {or {{<{${substr_11_2:$tod_log}}{21}}{>={${substr_11_2:$tod_log}}{22}}}} \
  }{0}fail}

The trick I used was to force expansion failure of the message_size_limit when delivering a message to her address and when the current time matches our constraints, in this case before 9pm or after 10pm. The expansion failure causes the message to be queued. To ensure that she actually gets her queued messages during that one hour window, I added a new retry rule for our domain that retries every 15 minutes for four days, rather than the default rule which increases the interval between delivery attempts as the time on the queue increases. In case I ever want to configure other accounts similarly, I set up a localpartlist named time_restricted_users.

tech » mail | Permanent Link

The state is that great fiction by which everyone tries to live at the expense of everyone else. - Frederic Bastiat