1 | #! /usr/bin/python |
---|
2 | # |
---|
3 | # This script parses emails and generates entries suitable for inclusion here: |
---|
4 | # |
---|
5 | # <https://community.openvpn.net/openvpn/wiki/Patches> |
---|
6 | # |
---|
7 | # The email is passed to the script using pipes. You have least two deployment |
---|
8 | # options: |
---|
9 | # |
---|
10 | # 1) Use Mozilla Thunderbird and ImportExportTools plugin |
---|
11 | # |
---|
12 | # Save the email as an MBOX file and pass it to the script like this: |
---|
13 | # |
---|
14 | # $ cat file.mbox|./parseOvpn.py |
---|
15 | # |
---|
16 | # 2) Copy-and-paste the email source to a text editor and run parseOvpn.py as |
---|
17 | # an external command |
---|
18 | # |
---|
19 | # In gedit you'd first enable the "External Tools" plugin. Then you'd add a |
---|
20 | # new Tool that runs the following: |
---|
21 | # |
---|
22 | # #!/bin/sh |
---|
23 | # parseOvpn.py |
---|
24 | import email.header |
---|
25 | |
---|
26 | import email |
---|
27 | import email.utils |
---|
28 | import sys |
---|
29 | import time |
---|
30 | |
---|
31 | gmane='http://news.gmane.org/find-root.php?message_id=%s' |
---|
32 | |
---|
33 | lineformat='|| %(date)s ||[[%(url)s| %(title)s ]] || %(author)s || ||' |
---|
34 | |
---|
35 | def decode_header(h): |
---|
36 | t, e= email.header.decode_header(h)[0] |
---|
37 | print (t,e) |
---|
38 | if e: |
---|
39 | return t.decode(e) |
---|
40 | else: |
---|
41 | return t |
---|
42 | |
---|
43 | def main(): |
---|
44 | msg = email.message_from_file(sys.stdin) |
---|
45 | |
---|
46 | d= {} |
---|
47 | |
---|
48 | d['url'] = gmane % msg['Message-Id'] |
---|
49 | d['title'] = decode_header(msg['Subject']).replace( '\t',"").replace('\n',"") |
---|
50 | d['title'] = d['title'].replace('[Openvpn-devel] ',"") |
---|
51 | |
---|
52 | t = email.utils.parsedate(msg['Date']) |
---|
53 | d['date'] = time.strftime("%Y-%m-%d",t) |
---|
54 | d['author'] = decode_header(msg['From']) |
---|
55 | |
---|
56 | print lineformat % d |
---|
57 | |
---|
58 | if __name__=='__main__': |
---|
59 | main() |
---|