Script to write email Attachment to Filesystem (m2fs)
$30-250 USD
In Progress
Posted over 14 years ago
$30-250 USD
Paid on delivery
PHP script that runs on any linux system that does the following.
- Checks a certain email address (pop and/or imap ok, but it must work with gmail accounts, see google help pages on ports and ssl connections)
- Gets the email, strips the attachments out of it, and saves them to
a directory on the server
- File extensions that are allowed as an attachment can be configured in the script. Other extensions are ignored.
- In the script, a root directory, and a directory in that root directory for attachments to be saved is specified in a configuration file, and the sub-directory will be specified in the subject of the mail.
Example, if the attachments directory is configured as "/home/me/m2fs/attachments" and someone sends a mail to the specified email address with an attachment, and the Subject of the mail is "mystuff-docs", then the attachment would be stripped and placed in the /home/me/attachments/mystuff/docs/ directory.
- If the directory that is specified in the Subject of the mail doesnt exist, it should be created, with any other directories in the path specified in the Subject (the whole path should be created if it doesnt exist.
- The body of the mail should be stored in another fixed (configured) directory, with the timestamp of the mail.
- If the mail subject has spaces or any special characters other than - or _ in it, then those characters should be replaced with "_".
- A log of any errors should be stored in another directory under the root dir that is also configured in the config file.
Additional specifications:
- zip files should be extracted (not left as zip files) and the contents of the zip file should be saved with their original file names in the directory that is specified in the subject of the email. There is no need to create another directory for the zip file content, just treat those contents as if they were attached to the email unzipped.
- If a file of the same name exists already in the same directory that is specified, then a "_n" (where n is a number starting at one) should be added to the new file before the extension. Eg: if [login to view URL] exists, and [login to view URL] is sent by email to the same directory, then it should be renamed [login to view URL] and saved. If it is sent yet again after that, it should become [login to view URL] and so on.
- Each saved email (body file, text without attachments) will be saved.
- The file body (text file) however should be saved in another directory, with the timestamp as the file name e.g. [login to view URL] (timestamp until second). The full text should remain in the body file, but not the attachment content. The attachment names however should remain in the content, as this will facilitate searching who sent which attachment later on.
Preferable, this solution should be standalone (not need any other files other than standard PHP libs or perl libs, but if that is impossible, procmail and fetchmail may be used for mail fetching and processing.
Best is a php script that can be run from php-cli by cron. Otherwise a perl script that can be run by cron is ok. Anyone who proposes php will be chosen over people who chose perl.
Dear Project Owner, I can create this script, all in php+shell scripting.
on further communication if you like, i will send you a development plan about steps and time required.
Thank you