Hold Tight...

0 %
Driving cybersecurity excellence
Innovator behind Kodachi OS
  • Residence:
    ::0
  • Uptime Binary:
    110001
  • Mantra:
    Innovate, Secure, Repeat
ONS
EEDS
NSSG
Cybersecurity
Programming & R&D
Cryptocurrency
AI & vibe coding
  • Bash
  • Gambas
  • Delphi
  • PHP
  • Visual Basic
  • Rust

How to process email attachments automatically on Linux

02/04/2014
2 min readDeep Tech3 code examplesUpdated October 2026

Key points

  • A Bash script that takes a proxy list sent as an email attachment, unpacks it with uudeview and copies the new list to the server every day.
  • A Gmail filter forwards the message, so the whole chain runs without me.
  • On current Debian, Ubuntu and Kodachi OS, uudeview is in the normal repositories.

How I Process Email Attachments Automatically with Bash

Updated October 2026: I wrote the script below to process email attachments for E-Bouncer, which is now an archived project, and its install step was written for CentOS 6, which reached end of life in November 2020. The idea still works; on current systems:

  • Debian, Ubuntu and Kodachi OS have uudeview in their standard repositories (Debian 13 has 0.5.20+20250228), so sudo apt install uudeview is all you need.
  • On Fedora, or on Rocky Linux and AlmaLinux 8 or 9 with EPEL, ripmime does the same job. I put both commands under the install block.
  • Gmail filters can still forward mail with attachments, but Gmail makes you confirm the forwarding address first.
  • The line ls -t | sed -e '1,1d' | xargs rm keeps only the newest file; it does not check age as its comment says. find . -type f -mtime +0 -delete removes files older than a day.

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

Why I automated the proxy list

To start with, I purchased a daily proxy feed from Hidemy***, which I wanted to integrate into my 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.

Installing uudeview

First, you will need to install uudeview (this is the 2014 CentOS 6 method):

ShellScript
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
ShellScript

On current distributions, install the tool from the normal repositories instead:

# Debian, Ubuntu and Kodachi OS: uudeview is in the standard repositories
sudo apt install uudeview

# Fedora, or Rocky Linux and AlmaLinux 8 or 9 (enable EPEL first: sudo dnf install epel-release):
# ripmime extracts the attachments of each mail file into a folder
sudo dnf install ripmime
for f in *; do ripmime -i "$f" -d ./attachments; done

Shell Script

ShellScript
#!/bin/sh
# Shell script written by Warith AL Maawali    
# (c) 2014 Warith AL Maawali
# 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 every mail except the newest one
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
ShellScript
Download

Posted in Deep TechTags: