Patches: parseOvpn.2.py

File parseOvpn.2.py, 1.0 KB (added by samuli, 4 years ago)

parseOvpn.py version 2 (added documentation)

Line 
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
18import email
19import email.utils
20import sys
21import time
22
23gmane='http://news.gmane.org/find-root.php?message_id=%s'
24
25lineformat='|| %(date)s ||[[%(url)s| %(title)s ]] || %(author)s || || ||'
26
27def 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
42if __name__=='__main__':
43    main()