- The below is written to accomidate multiple websites within one mail system for user configuration. All config tag names and groups are NOT case sensitive.
- Below will scan “Parent” folders for matching eMail and file it. All filed eMail will be contained within configured parent folders like “Clients”.
- This is designed to be initially transparent and still support tweaking from the website. The client can make a folder off a parent in eMail or off the site and it will sync up transparently.
- This will use 2 scripts. The one run from the site or the one run from cron/command prompt. They can be the same script controlled with arguments but two scripts might be better so the refresh script can be placed in a more central location.
- To make a file run the CreateMailBoxCmd then chmod it then add it to the SubscriptionFile
- Ignore eMails that are flagged or unread.
- MailRootFolder = /var/virtualmail
- InboxDir = /cur
- SentDir = /.Sent Items
- AdminEMail = Merlin@DesktopMasters.com
- CreateMailBoxCmd = sudo -u vmail /usr/bin/maildirmake -f ‘$FolderName’ $MailDir
- chmod=chmod -R g+X $MailDir
- SubscriptonFile=courierimapsubscribed
- Retention=7 (Days to go back before moving data to the file folders) This is a global setting but can be over ridden by user. on an account level or parent folder.
- MailExcludeFolders=Delimited (by pipe) list of folders that are not allowed to be parent folders and will not slow up in the websites add new parent dialog.
- ScanSentDir=1/True/Yes (This is the global setting for the default when creating/adding accounts)
- [*WebSites] – This group is where we store the websites to process. Feel free to use some other char other then astrisk if it makes your coding easier. Maybe two asterisks or ?. Below each site is listed by name you can just enumerate the group. The site name on the left of the = is just for me and for notifications in the event there is a problem.
- DesktopMasters.com = path to site config folder to import user configurations. Allowing for infinate sites each one is processed the same. In this case assume it is set to /home/merlin/Web/DesktopMasters.com/www/wp-content/plugins/automailfiler/usersettings
- I have reasons for not using the database as a medium.
- If you want to shorten the above path and have a variable for the WebRoot folder feel free.
- Config files are named after the eMail address they apply to so merlin@desktopmasters.com.cfg
- All paths (should be) accessible via total lower case.
- Modified = 0 (also support Yes and True not case sensitive) This setting is set to 1/True/yes when a modification is made so the script knows what direction to send the settings. If both config files have “Modified” turned on then send a conflict eMail notification to the AdminEMail.
- ScanAllMail = 1 (Date and time of last scan is retained in mailbox settings. This allows yout o shorten the mail scanned. Setting this to 1 will allow you to scan the full inbox) Has 3 settings blank (leave the mail setting the way it is, 1 and 0)
- AvailableFolders=Pipe Separated flat list of folders in the mailbox that they can use to create/use as a parent. This is a list of all folders excluding the exclude list. If I add a folder to the exlude list later you should be able to detect that. So generate the list fresh then double check it against the config file.
- Retention = This is a global user setting or the default. If the user has not set it then leave blank and show the user the default setting in the main config. This is global to all parent folders unless they have the setting overridden.
- ScanSentDir= to include sent dir when scanning and moving. This overrides the global for the users and sets the default for added parents if not specified. Hard code this to the default when the account is first created.
- Parent folders are prefixed with an astrisk not shown to user [*Clients] or [*Clients/Medical](This is where we configure the parent folder options. Slashes are used to make it more user friendly when editing script files by hand. The actual folders will have a dot. So replace the “/” with “.” and do not allow dots in names they will mess everything up as the eMail folders are flat and use the dot as the delimiter.
- New = If the website just created this new is 1 so you know to try and make the folder in the users inbox.
- Modified = 1 if modified by site.
- Retention = (Days for inbox to retain mail. Anything to be moved outside this setting will be moved that is not flagged or unread) So if 7 you would move anything 8 days or older. This will over ride all previous Retention settings and should be set to nothing if defaulted.
- ScanSentDir= to include sent dir when scanning and moving. This overrides the global for the users. Leave blank and follow the inherited default until the user specifies otherwise.
- [John Doe] = Child folder listed as a group with settings for that child folder inside.
- New = If the website just created this new is 1 so you know to try and make the folder in the users inbox.
- “Clients”, “Clients/Medical”, “Clients/
- Parent=Clients/Medical (This is the *Parent folder it belongs to)
- Search=john@somewhere.com (By default all search fields are blank and search for the display name. However we can override that and make it search for specific text like the eMail address by adding it to the web interface. This and retention are the only real reasons for the web interface.
- Open the main config file and grab the virtual mail folder and store it in $MailRootFolder use that to create/appendto the $MailDir variable below.
- Process one site at a time starting with Site1.
- Open the first users .cfg file.
- Figure out the folder based on their eMail address and store the full path in $MailDir and varify it exists. Note the actual inbox mail is stored in “cur”.
- all settings will be stored in the “automailfiler” file in the root of the mailbox. Check each mailbox in the domain as well as in the website folder and if the file exists server side create the config file in the website. If a folder is gone from the server side delete the file on the website side.
- When checking the folders if it is missing in the mail side and neither config shows it then delete it from the settings side. DO NOT delete folders. If the folder does not exist and you see it is flagged as new on the settings side then create it.
- Look for the Modified tag and if a settings group has been modified copy the settings over to the other side. If they are both modified then do nothing and notify the admin.
- Use global retention unless someone has set it from the website then hard code the days. If it is default then leave it blank.
- If scan all mail on user side is 0 set this to zero here. If it is one set it to 1. If it is blank leave it the way it is. In the mail folder settings this will ether be 0 or 1. You will change it back to 0 after scanning all mail.
- this is a script or function the website will call through sudo that will run as root and will compare settings and scan the mail folders. The site (I think) will run this when the site first loads the page to make sure its information is correct. This will kick off the above sync for the ONE email address only that is specified on the command line. It should be able to run very quickly. This will also be run when the user on the website presses the submit button to make sure any changes they made website side are applied to the servers mail folders at that time.
- Since these scripts calls will be run through sudo they will be run as root. If you were for example to call “sudo /root/bin/AutoMailFiler.php refresh desktopmasters.com:merlin@desktopmasters.com” you would be able to look up in the main config the domain name to find the folder to work with and sync with for the specified eMail address. Run it without the eMail address it updates the domain. Run it with only refresh it updates everything.
- The only other command the web server will be able to execute is a command to ask the server to run the mail filer script on their inbox at that time. so “sudo /root/bin/AutoMailFiler.php file desktopmasters.com:merlin@desktopmasters.com” Same as above. Depending on how much additional information given it will control how deep (level) it runs as in the previous bullet.
- After doing the above action on a user you find yourself here on the same user. Scanning for new mail…
- Scan one day past the last time and day of last scan (Just to be safe). Unless the scan all mail has been set. If it has then scan all mail and then change the setting back to 0.
- Move mail by doing a case insensitive search on the folder name or search setting if set by user.
- When done set the last scan date and time so you would know where to stop the next time.
- Note: At some point if a user asks for it I may have you add the ability to log and email a report of what was moved to where weekly or daily. But we will not bother with it now.
- Scan for sent mail if specified. Create the sent mail folder if it does not exist. Name it after the default folder name as a subfolder of the child folder.