Incoming messages

The doe-family.com/incoming.vsl script is run when the sender of the domain is not doe-family.com and that recipients domains are doe-family.com.

Thus, when this script is run, all recipients are guaranteed to have the doe-family.com domain. We can then deliver emails locally using the Mailbox protocol.

import "objects/family" as family;

#{
  delivery: [
    action "setup delivery" || {
      for rcpt in ctx::rcpt_list() {
        // Deliver locally using Mailbox if the recipient is from Doe's family.
        if rcpt in family::addresses { transport::mailbox(rcpt) }
      }
    }
  ],
}

doe-family.com/incoming.vsl

Jane wants a blind copy of her Jenny’s messages. Let’s create a Rhai function that does exactly that.

/etc/vsmtp
 ┣ vsmtp.vsl
 ┣ filter.vsl
 ┣ conf.d/
 ┃      ┣ config.vsl
 ┃      β”— *.vsl
 ┣ domain-available/
 ┃      β”— doe-family.com/
+┃         ┣ bcc.vsl
 ┃         ┣ incoming.vsl
 ┃         ┣ outgoing.vsl
 ┃         β”— internal.vsl
 ┣ domain-enabled/
 ┃     β”— example.com -> ...
 β”— objects/
       β”— family.vsl

adding a new script to the domain

import "objects/family" as family;

fn bcc_jenny() {
  // add Jane as a blind carbon copy if the current recipient is Jenny.
  if ctx::rcpt() == family::jenny {
    bcc(family::jane)
  }
}

doe-family.com/bcc.vsl

Now, let’s plug this function to our filtering rules by importing the bcc.vsl script.

+ import "domain-available/doe-family.com/bcc" as bcc;
  import "objects/family" as family;

  #{
+   rcpt: [
+     action "bcc jenny" || bcc::bcc_jenny(),
+   ],

    delivery: [
      action "setup delivery" || {
        for rcpt in ctx::rcpt_list() {
          // Deliver locally using Mailbox if the recipient is from Doe's family.
          if rcpt in family::family_addr { transport::mailbox(rcpt) }
        }
      }
    ],
  }

doe-family.com/incoming.vsl

With Rhai modules and functions, it becomes easy to reuse code across different rules.