Ftp – mail2ftp Interface with Postfix/Cyrus – How to automaticly share mail attachments via FTP

cyrusemailftpimappostfix

I'm trying to build a solution to transfer attachments from Mail to an FTP folder. Are there any suggestions to solve this task?

My first idea was to write a shell script which fetches the mail from the Cyrus /var/imap folder and searches for the mail attachment finally writing it into a pdf file. As this does not seem to be the intended way of solving this issue, there might be a better one.

Best Answer

With ripmime and cronjob you can solve this problem. Ripmime is a tools to fetch MIME parts of a Mail. You can fetch text and attachments and extract it to an folder. With cronjob you can start a shellscript that looks into Maildir and starts ripmime for each Mail.

Install ripmime from http://www.pldaniels.com/ripmime/

After that I use this shellscript for fetch the attachments:

for file in /var/spool/cyrus/mail/x/user/username/*. ; do
    echo "$file"
    ripmime -i $file -d /home/username
    rm $file
done

With crontab -e you can add this Task:

*/1 * * * *     sh /home/ftp-scripts.sh >> /var/log/ripmime_ftp.log

After you get a Mail in /var/spool/... this Script call ripmime and extract the Attachment to ftp dir.