Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Stripping attachments from mail in .maildir format
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
MasquedAvenger
Guru
Guru


Joined: 21 Aug 2003
Posts: 559
Location: Southern California

PostPosted: Sat Apr 24, 2004 6:41 pm    Post subject: Stripping attachments from mail in .maildir format Reply with quote

Hey everyone. I want to setup a procmail recipe to strip attachments from email and leave the messages themselves intact. Any ideas?

James
Back to top
View user's profile Send private message
devon
l33t
l33t


Joined: 23 Jun 2003
Posts: 943

PostPosted: Sat Apr 24, 2004 7:09 pm    Post subject: Reply with quote

What about MIMEDefang or AntiMIME?
Back to top
View user's profile Send private message
MasquedAvenger
Guru
Guru


Joined: 21 Aug 2003
Posts: 559
Location: Southern California

PostPosted: Sat Apr 24, 2004 8:37 pm    Post subject: Reply with quote

I'll have to look into those. They actually will delete the attachment rather than just rename the file, make it a different type of attachment, etc.?

By the way, sort of off topic, what I'm doing is using procmail to have ClamAV scan incoming mail, and if a virus is detected, rather than simply delete the entire email or move it to a quarantine folder, I will instead read the integer that ClamAV returns when it exits, and if it exits with the code that means there is a virus, I will strip the email of all attachments and append something to the subject of the email so that the message itself can still be read if the user so wishes.

James
Back to top
View user's profile Send private message
devon
l33t
l33t


Joined: 23 Jun 2003
Posts: 943

PostPosted: Sat Apr 24, 2004 10:42 pm    Post subject: Reply with quote

MasquedAvenger wrote:
They actually will delete the attachment rather than just rename the file, make it a different type of attachment, etc.?

I don't know. I have never personally used them, but I remembered them when I was curious about stripping attachments. :)
Back to top
View user's profile Send private message
MasquedAvenger
Guru
Guru


Joined: 21 Aug 2003
Posts: 559
Location: Southern California

PostPosted: Sun Apr 25, 2004 4:59 am    Post subject: Reply with quote

Oh ok. Well I guess I'll just have to look into it then :) Thanks for the references.

James
Back to top
View user's profile Send private message
rocketchef
n00b
n00b


Joined: 08 Feb 2004
Posts: 24

PostPosted: Sun May 02, 2004 11:04 am    Post subject: Reply with quote

Well, I did the following:

Code:

:0B
* ^Content-Type:.*name=.*\.exe
| /home/niels/skripte/deattach.pl


and this is my script:
Code:

#!/usr/bin/perl -w
use strict;

use Mail::Audit;
use Mail::Audit::Attach qw(Attach);

my $attachdir = '/home/niels/Mail/quarantine';
my $mail = Mail::Audit->new;

my $attachments = $mail->attachments || die "hier liegt der fehler\n";
                                                                               
foreach (@$attachments)
{
   if ($_->mime_type eq 'application/x-msdownload' || $_->filename =~ m/\.exe$/ )
   {
      $_->save($attachdir);
      $_->remove;
   }
}
$mail->pipe('/usr/bin/procmail') || die "no procmail";


This is for MS .exe files only, change MIME types at will
HTH,

Niels
Back to top
View user's profile Send private message
MasquedAvenger
Guru
Guru


Joined: 21 Aug 2003
Posts: 559
Location: Southern California

PostPosted: Sun May 02, 2004 4:32 pm    Post subject: Reply with quote

That is really awesome. Thank you so much :) One question though: I'm not quite sure how to make this activate only if ClamAV exits with the return code that signifies the presence of a virus.

James
Back to top
View user's profile Send private message
Little Nemo
l33t
l33t


Joined: 29 Mar 2004
Posts: 623
Location: Berlin, Germany

PostPosted: Sun May 02, 2004 7:03 pm    Post subject: Reply with quote

Yes, as always Perl is the (or at least an) answer. But as typically with Perl, "there's more than one way to do it". You could also call clamav from Perl to make sure the attachment you're dropping is the infected one. And of course ".exe" files are not the only bad attachments.
Back to top
View user's profile Send private message
ahadley
n00b
n00b


Joined: 08 Jan 2004
Posts: 45
Location: UK

PostPosted: Sun Feb 20, 2005 12:13 am    Post subject: Reply with quote

Sorry to drag up an old post like this but i am having problems with the perl script above, i get the following error:

Can't locate Mail/Audit.pm in @INC


Any help would be appreciated,
Thanks in advance,
Alex
_________________
Common sense is the collection of prejudices acquired by age eighteen.
Albert Einstein
Back to top
View user's profile Send private message
ahadley
n00b
n00b


Joined: 08 Jan 2004
Posts: 45
Location: UK

PostPosted: Sun Feb 20, 2005 12:36 am    Post subject: Reply with quote

Okay, sorry - am now installing the module with perl -MCPAN -e 'install Mail::Audit'... d'uh

Thanks,
and sorry for asking a stupid question
Alex
_________________
Common sense is the collection of prejudices acquired by age eighteen.
Albert Einstein
Back to top
View user's profile Send private message
ahadley
n00b
n00b


Joined: 08 Jan 2004
Posts: 45
Location: UK

PostPosted: Sun Feb 20, 2005 11:44 am    Post subject: Reply with quote

Well, I installed the perl module as required, and have procmail working, to a certain extent, but have 2 issues.

the first is with the above perl script, which freezes on the line:
Code:
my $mail = Mail::Audit->new;

I know it is this line as i added many printf's to the file to debug it...

It just freezes here untill i get (from the log file):
Code:
Timeout, terminating "/path/to/sortscript.pl"


Any help??

Thanks in advance,
Alex
_________________
Common sense is the collection of prejudices acquired by age eighteen.
Albert Einstein
Back to top
View user's profile Send private message
rocketchef
n00b
n00b


Joined: 08 Feb 2004
Posts: 24

PostPosted: Mon Jul 04, 2005 8:30 pm    Post subject: Reply with quote

Sorry this is really a late reply, you might already have found an answer, but anyway:

Code:

my $mail = Mail::Audit->new;


waits for a mail on stdin, so please use:
Code:

/path/to/my/script.pl < newmail.mail


where newmail.mail is a textfile in rfc format

hth,
Niels
Back to top
View user's profile Send private message
MasquedAvenger
Guru
Guru


Joined: 21 Aug 2003
Posts: 559
Location: Southern California

PostPosted: Thu Jul 07, 2005 5:51 pm    Post subject: Reply with quote

Thanks for the answer :) I actually went with amavisd-new for the virus scanning, but that's good information to know.

James
_________________
"There are no uninteresting things; only uninterested people." --G.K. Chesterton
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum