~tualatrix/unity-mail/show-icon-in-notification

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Unity Mail, QuickList URL processor
# Author: Dmitry Shachnev <mitya57@gmail.com>
# License: GNU GPL 3 or higher; http://www.gnu.org/licenses/gpl.html

import os
import sys
import ConfigParser
import webbrowser
import subprocess

parser = ConfigParser.RawConfigParser()
parser.read(os.path.expanduser('~/.config/unity-mail.conf'))

default = \
{  'Home': 'https://mail.google.com/mail/', \
'Compose': 'https://mail.google.com/mail/#compose', \
  'Inbox': 'https://mail.google.com/mail/#inbox', \
   'Sent': 'https://mail.google.com/mail/#sent' }

def print_names():
	print('Possible URL names: "Home", "Compose", "Inbox", "Sent"')

if len(sys.argv) > 1:
	name = sys.argv[1]
	if parser.has_option('URLs', name):
		url = parser.get('URLs', name)
		if url.startswith('Exec:'):
			subprocess.Popen(url[5:].split(' '))
		else:
			webbrowser.open(url)
	else:
		try:
			webbrowser.open(default[name])
		except KeyError:
			print('Error: unknown URL name!')
			print_names()
else:
	print('Error: please specify URL name.')
	print_names()