Patches: parseOvpn.3.py

File parseOvpn.3.py, 1.3 KB (added by Samuli Seppänen, 11 years ago)

Version 3 of parseOvpn.py: added more documentation

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
24
25import email
26import email.utils
27import sys
28import time
29
30gmane='http://news.gmane.org/find-root.php?message_id=%s'
31
32lineformat='|| %(date)s ||[[%(url)s| %(title)s ]] || %(author)s || || ||'
33
34def main():
35    msg = email.message_from_file(sys.stdin)
36
37    d= {}
38
39    d['url'] = gmane % msg['Message-Id']
40    d['title'] = msg['Subject'].replace( '\t',"").replace('\n',"")
41    d['title'] = d['title'].replace('[Openvpn-devel] ',"")
42
43    t = email.utils.parsedate(msg['Date'])
44    d['date'] = time.strftime("%Y-%m-%d",t)
45    d['author'] = msg['From']
46
47    print lineformat % d
48
49if __name__=='__main__':
50    main()