User Tools

Site Tools


User Routing Script

If there is a <username>/user_redirect.lua script, this Lua script can override VPOP3's message routing options. You can edit this either in the Settings → Scripts page in the settings, or via the 'Routing' tab in the user's settings in the VPOP3 administration console. This script affects how VPOP3 will handle how messages to this user are handled. (Messages from this user are not affected by the script at all).

If that script doesn't exist, but there is a user_redirect.lua script, that Lua script will be used instead.

When the user_redirect.lua script is run there are several global variables set:

  • Assistants - the value of the 'Assistants' setting for this user (string)
  • RedirectToAssistant - the value of the 'Redirect to Assistant' setting for this user (boolean)
  • Forwards - the value of the 'Forward To' setting for this user (string)
  • UseForwards - the value of the 'UseForwarding' setting for this user (boolean)
  • SendToNormalRecipient - if this is true the message will be sent to the normal recipient (unless a Forward or Assistant overrides this) (boolean)
  • ShouldForward - if this is false then VPOP3 will ignore the Assistants and any forwarding settings (boolean)
  • BigRedirect - the settings for the 'If message > xxx kb' setting for this user
  • SmallRedirect - the settings for the 'If message < xxx kb' setting for this user

The BigRedirect and SmallRedirect variables are tables with 4 entries:

  • Target - the target address(es) for this redirector (string)
  • Threshold - the threshold at which this redirector is actioned (in kB) (number)
  • Copy - whether this redirector will copy or redirect the message (boolean)
  • Bigger - true if the redirector checks for messages > Threshold, false if it checks for messages < Threshold (boolean)

All the above settings can be changed by the script to alter the routing (the changes will only apply for this message, not future messages)

There are also some global variables which should be treated as read-only - any changes to them will be ignored outside the Lua script

  • MessageSize - the size of the message in bytes (may be zero if size is unknown)
  • SpamScore - the spam score for the message
  • SpamScoreValid - true if the SpamScore setting is value (it will be false if spam processing is disabled, for instance)
  • Sender - the email address of the message sender
  • User - the username of the user being processed
  • Subject - the subject of the message

Please note - the only help we will give with Lua with our free support is to clarify the Lua interface (eg function signatures etc), we will not give help with Lua in general or help you to write or debug your own Lua scripts. We can help with that, but it will be on a chargeable basis depending on the complexity of the issue. Contact us for more information.


Don't forward messages from * addresses

--Don't forward any messages from any * addresses
if string.find(Sender, "$") then
  ShouldForward = false;

If the sender is forward to

--If  the sender is forward to
if string.lower(Sender) == "" then
  Forwards = "";
  UseForwards = true;
  ShouldForward = true;

If the time is currently in the morning, override the assistant to send to someone else

now ="*t"); --
if now.hour < 12 then
  Assistants = ""

If the current time is between 10:00 on 2nd March 2023 and 17:00 on 5th March 2023, then forward

now ="%Y-%m-%d %H:%M")
if (now >= "2023-03-02 10:00") and (now <= "2023-03-05 17:00") then
  Forwards = "";
  UseForwards = true;
  ShouldForward = true;
reference/user_routing_script.txt · Last modified: 2023/03/27 11:32 by paul