blah mail
Par jd le jeudi, septembre 18 2008, 11:49 - Free Software - Lien permanent
Following my first idea of a blah script for irssi, I've wrote the same thing in Python for filtering some mail. IMHO, it's better than killfile.
1 #!/usr/bin/python
2
3 import email, sys, re
4
5 def blaahw(match):
6 w = match.group(0)
7 l = len(w)
8 if l == 1:
9 return "o"
10 elif l == 2:
11 return "he"
12 elif l == 3:
13 return "lol"
14 a = "a" * (l - 3)
15 return re.sub("\w+", "bl%sh" % a, w)
16
17 def blaah(text):
18 rc = re.compile('\w+')
19 return rc.sub(blaahw, text)
20
21 mail = email.message_from_file(sys.stdin)
22
23 mail.replace_header("Subject", blaah(mail["Subject"]))
24
25 def blaah_payload(pl):
26 if type(pl) == list:
27 for i in range(len(pl)):
28 if pl[i].get_content_type() == "text/plain":
29 pl[i].set_payload(blaah(pl[i].get_payload()))
30 return pl
31 elif type(pl) == str:
32 return blaah(pl)
33
34 mail.set_payload(blaah_payload(mail.get_payload()))
35 print(mail)
Then can use a procmail rule like:
:0 fw * ^From: asshole <asshole@asshole.com> | $HOME/bin/blahmail.py
EDIT: I've updated it to a more robust version which support multipart messages.
Commentaires
fed my spam folder to this script to see what is it (dont read python here).
2 points:
"multi-part message in MIME format" crashes the script.
It's useless for 8-bit non-latin encodings (cyrillic f.e.). Eats up latin sub-string (URLS et al.) successfully in such thou.
Cheers!
I have updated it, now it's a bit more robust with multi part.