Patches: parseOvpn.5.py

File parseOvpn.5.py, 1.5 KB (added by plaisthos, 4 years ago)
Line 
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
24import email.header
25
26import email
27import email.utils
28import sys
29import time
30
31gmane='http://news.gmane.org/find-root.php?message_id=%s'
32
33lineformat='|| %(date)s ||[[%(url)s| %(title)s ]] || %(author)s || ||'
34
35def decode_header(h):
36    d = email.header.decode_header(h)
37    r =""
38    for t,e in d:
39        if r:
40            r+=" "
41        if e:
42            r += t.decode(e)
43        else:
44            r += t
45    return r
46       
47
48def main():
49    msg = email.message_from_file(sys.stdin)
50
51    d= {}
52
53    d['url'] = gmane % msg['Message-Id']
54    d['title'] = decode_header(msg['Subject']).replace( '\t',"").replace('\n',"")
55    d['title'] = d['title'].replace('[Openvpn-devel] ',"")
56
57    t = email.utils.parsedate(msg['Date'])
58    d['date'] = time.strftime("%Y-%m-%d",t)
59    d['author'] = decode_header(msg['From'])
60
61    print lineformat % d
62
63if __name__=='__main__':
64    main()