How to process email attachments on linux
I will share my experience that I had get through while trying to find a way to process an attachment from my personal email using Linux bash scripting.
To start with the story I purchased a daily proxy feed from Hidemy*** which I wanted to feed to our proxy software E-bouncer. The down side is that Hidemy*** will only send you the list as an attachment on your purchased email address which is my personal email. I had to extract the list from a zip file and upload it to the server on daily basis you can imagine how boring was that.
So I thought why don’t I automate the entire process and the plan was to create a filter on my gmail service to forward any email with attachment that comes from Hidemy*** to a custom email that is accessed within the server which is “hproxy a@t oman0.net”. If the email is received on my inbox and the condition is met it will straight forward it to the custom email address.
Therefore I had to write a tiny shell script that would process the “hproxy a@t oman0.net” email address and extract the attachment then copy the new arrived proxy list to E-Bouncer directory so when users retrieves proxy list they get the most recent one automatically.
Here is the script that does the job in case you run into similar situation:
First you will need to install uudeview
wget http://springdale.math.ias.edu/data/puias/6/x86_64/os/Addons/uudeview-0.5.20-19.puias6.x86_64.rpm rpm -Uvh uudeview-0.5.20-19.puias6.x86_64.rpm yum install uudeview
#!/bin/sh # Shell script written by W. Al Maawali # (c) 2014 Founder of Eagle Eye Digital Solutions # http://www.digi77.com # http://www.om77.net # script starts here: # Go to the custom mail directory cd /home/oman0/mail/.hproxy@oman0_net/new # Delete files older than 1 day ls -t | sed -e '1,1d' |xargs rm # Extract attachment files from any available mail on the current directory uudeview -c -i * # Decompress it as you only receive it as zip file unzip *.zip # Move to sub directory cd full_list # Rename the proxy list file to a custom name cp _full_list.txt elite.pp FILE='/home/oman0/mail/.hproxy@oman0_net/new/full_list/elite.pp' # We only proceed if the proxy list is found by checking file existence if [ -f $FILE ]; then # remove the old proxy list rm -f /home/digi77/www/software/xxx/data/proxy-feed/elite.pp # Copy the new proxy list cp elite.pp /home/digi77/www/software/xxx/data/proxy-feed/elite.pp # Clean mail box and wait for next day update cd /home/oman0/mail/.hproxy@oman0_net/new rm -f -r /home/oman0/mail/.hproxy@oman0_net/new/* rm -f -r /home/oman0/mail/.hproxy@oman0_net/new/*.* rm -f -r /home/oman0/mail/.hproxy@oman0_net/cur/* rm -f -r /home/oman0/mail/.hproxy@oman0_net/cur/*.* # Count number of proxies cat /home/digi77/www/software/xxx/data/proxy-feed/elite.pp|wc -l > /home/digi77/www/software/xxx/data/servercount.pp # Print the date date +'%Y-%m-%d' > /home/digi77/www/software/xxx/data/proxyvalidatedate.pp else echo "File $FILE does not exists" fi
Latest posts by Warith Al Maawali (see all)
- Apple iOS Mail Client leaking highly sensitive information - December 27, 2019
- Validating VPN nodes - November 3, 2019
- Migrating from php 5.6 to 7.3 - November 1, 2019
- Linux Kodachi 7.6 The Secure OS - October 20, 2013
- Migrating from Vbulletin to Burning board - March 27, 2016