Warith AL Maawali

0 %
Warith AL Maawali
Driving cybersecurity excellence
Innovator behind Linux Kodachi
  • Residence:
    127.0.0.1
  • Uptime Binary:
    101110
  • Mantra:
    Innovate, Secure, Repeat
ONS
EEDS
NSSG
Visual basic
Delphi
Gambas
Bash
PHP
  • Infrastructures
  • Digital Forensics
  • Cryptocurrency
  • Cloud & Server Management

How to process email attachments automatically on Linux

02/04/2014

Automating Email Attachment Processing with Linux Bash Scripting

I will share my experience of processing an attachment from my personal email using Linux bash scripting.

To start with, I purchased a daily proxy feed from Hidemy***, which I wanted to integrate into our proxy software, the E-Bouncer project. The downside is that Hidemy*** only sends the list as an attachment to your email address, which in my case, is my personal email. Extracting the list from a zip file and uploading it to the server on a daily basis was tedious.

So, I thought, why not automate the entire process? The plan was to create a filter on my Gmail account to forward any email with an attachment from Hidemy*** to a custom email address accessed by the E-Bouncer server, which is “hproxy@oman0.net.” When the email is received in my inbox and the condition is met, it will be forwarded to the custom email address.

I then wrote a small shell script that processes the “hproxy@oman0.net” email, extracts the attachment, and copies the new proxy list to the E-Bouncer directory. This ensures that users always retrieve the most recent proxy list automatically.

This approach streamlined the process and eliminated the need for manual intervention, making it efficient and reliable. If you encounter a similar situation, this method can help you automate and manage email attachments effectively.

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

Shelll Script:  

#!/bin/sh
# Shell script written by W. Al Maawali    
# (c) 2014 Founder of Eagle Eye Digital Solutions
# https://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

 

Download

Posted in Tech BlogTags:
© 2024 Warith AL Maawali. All Rights Reserved.
Stay Secure, Stay Assured.