From Qmailwiki
Jump to: navigation, search

The "onchange" patch for vpopmail was written by John Simpson. It provides a way for vpopmail to call an external script whenever anything relating to a mailbox changes. This includes mailboxes and domains being created and deleted, as well as passwords being changed. This allows for external systems which may rely on vpopmail's user base, such as John's validrcptto.cdb patch, to have their files updated at the same time that vpopmail itself changes.

To use this feature, specify the --enable-onchange-script option when running the ./configure command before compiling vpopmail.

In addition, if you are using other programs which use the vpopmail library (such as [qmailadmin]), you should also re-compile these after you have finished the make install portion of building vpopmail. This will add the onchange functionality to these other programs as well.

Once you have compiled vpopmail with this option, any time a mailbox or domain changes, the program will try to run a script called ~vpopmail/etc/onchange. If this script is not found, or if it's there but it's not marked as executable, the program will simply continue as if this function were not present (i.e. it will not throw an error message.)

You can put whatever you like into the script. However, you should take care to ensure that the script finishes running as soon as possible, because the original program which made the change (added the mailbox, changed the password, or whatever) will be waiting for your script to finish. If the script will be doing a long process (rebuilding a database, for example) it may make more sense to set up a background "pipe watcher" service which actually does the work, and set up your "onchange" script so that it signals this service to do it's job. John's qmail-updater service is an example of how to set up such a thing.

When vpopmail calls your script, it will pass information to the script on the command line, which tells the script what kind of change was made (or in the case of a "delete" operation, what kind of change is ABOUT to be made.) The exact information will depend on what change is being made. This is a list of the arguments sent for each operation:

Command Arg1 Arg2
add_user user@domain  
add_domain domain  
add_alias_domain  alias_domain  real_domain 
insert_alias alias@domain alias_line
del_all_alias domain  
Personal tools