1 | #! /usr/bin/python |
---|
2 | # |
---|
3 | # This script parses MBOX files and generates entries suitable for inclusion |
---|
4 | # here: |
---|
5 | # |
---|
6 | # <https://community.openvpn.net/openvpn/wiki/Patches> |
---|
7 | # |
---|
8 | # If you're using Mozilla Thunderbird you need ImportExportTools plugin to |
---|
9 | # export your emails as MBOX. |
---|
10 | # |
---|
11 | # You can parse an MBOX file like this: |
---|
12 | # |
---|
13 | # cat file.mbox|./parseOvpn.py |
---|
14 | # |
---|
15 | # This will produce Trac-compatible output, which you simply copy and paste to |
---|
16 | # the above page. |
---|
17 | |
---|
18 | import email |
---|
19 | import email.utils |
---|
20 | import sys |
---|
21 | import time |
---|
22 | |
---|
23 | gmane='http://news.gmane.org/find-root.php?message_id=%s' |
---|
24 | |
---|
25 | lineformat='|| %(date)s ||[[%(url)s| %(title)s ]] || %(author)s || || ||' |
---|
26 | |
---|
27 | def main(): |
---|
28 | msg = email.message_from_file(sys.stdin) |
---|
29 | |
---|
30 | d= {} |
---|
31 | |
---|
32 | d['url'] = gmane % msg['Message-Id'] |
---|
33 | d['title'] = msg['Subject'].replace( '\t',"").replace('\n',"") |
---|
34 | d['title'] = d['title'].replace('[Openvpn-devel] ',"") |
---|
35 | |
---|
36 | t = email.utils.parsedate(msg['Date']) |
---|
37 | d['date'] = time.strftime("%Y-%m-%d",t) |
---|
38 | d['author'] = msg['From'] |
---|
39 | |
---|
40 | print lineformat % d |
---|
41 | |
---|
42 | if __name__=='__main__': |
---|
43 | main() |
---|