User Tools

Site Tools


reference:user_routing_script

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
reference:user_routing_script [2011/10/05 14:24] paulreference:user_routing_script [2023/03/27 10:32] (current) paul
Line 1: Line 1:
 ======User Routing Script====== ======User Routing Script======
  
-If there is a user_redirect.lua file in a user's directory this Lua script can override VPOP3's message routing options. You can edit this either on the disk directly, 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 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 file doesn't exist, but there is a user_redirect.lua file in the main VPOP3 directory, that Lua script will be used instead.+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: When the user_redirect.lua script is run there are several global variables set:
Line 34: Line 34:
   * Subject - the subject of the message   * Subject - the subject of the message
  
-An example script might be+ 
 +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. 
 +=====Examples===== 
 + 
 +====Don't forward messages from *@localdomain.com addresses====
  
 <code> <code>
 --Don't forward any messages from any *@localdomain.com addresses --Don't forward any messages from any *@localdomain.com addresses
-if (string.find(Sender, "@localdomain%.com$")) +if string.find(Sender, "@localdomain%.com$"then 
-  ShouldForward = false+  ShouldForward = false;
 end end
 </code> </code>
  
 +====If the sender is user@domain.com forward to person@mycompany.com====
 +
 +
 +<code>
 +--If  the sender is user@domain.com forward to person@mycompany.com
 +if string.lower(Sender) == "user@domain.com" then
 +  Forwards = "person@mycompany.com";
 +  UseForwards = true;
 +  ShouldForward = true;
 +end
 +</code>
 +
 +====If the time is currently in the morning, override the assistant to send to someone else====
 +
 +<code>
 +now = os.date("*t"); --https://www.lua.org/pil/22.1.html
 +if now.hour < 12 then
 +  Assistants = "otheraddress@example.com"
 +end
 +</code>
 +
 +====If the current time is between 10:00 on 2nd March 2023 and 17:00 on 5th March 2023, then forward====
 +
 +<code>
 +now = os.date("%Y-%m-%d %H:%M")
 +if (now >= "2023-03-02 10:00") and (now <= "2023-03-05 17:00") then
 +  Forwards = "person@mycompany.com";
 +  UseForwards = true;
 +  ShouldForward = true;
 +end
 +</code>
reference/user_routing_script.1317824651.txt.gz · Last modified: 2018/11/14 10:44 (external edit)