Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have configured Redmine email integration and while it's awesome, a major annoyance is that people have signatures that include a company logo, which then gets posted to every ticket they update via email. I know this is not a perfect solution but I would like to pipe to a script that deletes attachments named "image001.png" from the message so I can then pipe it along to the handler. Are there tools available to help with this, or do I have to start from scratch?

Before: alias > mailhandler.rb

After: alias > parser.script > mailhandler.rb

share|improve this question
up vote 1 down vote accepted

I'd personally go for the MIMEDefang option suggested by Andrzej A. Filip but I wondered how I'd write this in a python script and came up with the following solution. In case MIMEDefang is not an option for your environment you might want to try it. No guarantees, only tested with a few sample messages

import email
import sys

def remove_attachment(rootmsg,attachment_name):
    """return message source without the first occurence of the attachment named <attachment_name> or None if the attachment was not found"""
    for msgrep in rootmsg.walk():
        if msgrep.is_multipart():
            for attachment in payload:
                att_name = attachment.get_filename(None)
                if att_name==attachment_name:
                    del payload[indexcounter]
                    return rootmsg.as_string()

if __name__=='__main__':
        sys.stderr.write("Message could not be parsed")

    if src!=None:
share|improve this answer

You may use MIMEDefang milter as an addon to postfix (or sendmail).

MIMEDefang can inspect and modify e-mail messages as they pass through your mail relay. MIMEDefang is written in Perl, and its filter actions are expressed in Perl, so it's highly flexible. Here are some things that you can do very easily with MIMEDefang:
* Delete or alter attachments based on file name, contents, results of a virus scan, attachment size, etc.
* Replace large attachments with links to a centrally-stored copy to ease the burden on POP3 users with slow modem links.

MIMEDefang is free software: It's released under the terms of the GNU General Public License. It runs under Linux, FreeBSD, Solaris and most other UNIX or UNIX-like systems.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.