aboutsummaryrefslogtreecommitdiff
path: root/data/usr/bin/ayatana-webmail-url
blob: bb8fbae7a9710b64fa3750fd50a7a32d6e83d7c9 (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Ayatana Webmail, QuickList URL processor
# Authors: Dmitry Shachnev <mitya57@gmail.com>
#          Robert Tari <robert@tari.in>
# License: GNU GPL 3 or higher; http://www.gnu.org/licenses/gpl.html

import sys
import dbus
from gi.repository import GLib
from dbus.mainloop.glib import DBusGMainLoop
from ayatanawebmail.common import isRunning

if __name__ == '__main__':

    if len(sys.argv) == 2 and sys.argv[1] in ['Home', 'Compose', 'Inbox', 'Sent']:

        if isRunning():

            bInit = False

            DBusGMainLoop(set_as_default=True)
            oSessionBus = dbus.SessionBus()

            try:

                oSession = oSessionBus.get_object('org.ayatana.webmail', '/org/ayatana/webmail')
                oInterface = dbus.Interface(oSession, 'org.ayatana.webmail')
                oLoop = GLib.MainLoop()

                def replyHandler(b):

                    global bInit
                    bInit = b
                    oLoop.quit()

                oInterface.isinit(reply_handler=replyHandler, error_handler=lambda o: oLoop.quit())
                oLoop.run()

                if not bInit:
                    oInterface.settings(reply_handler=lambda: oLoop.quit(), error_handler=lambda o: oLoop.quit())
                else:
                    oInterface.openurl(sys.argv[1], reply_handler=lambda: oLoop.quit(), error_handler=lambda o: oLoop.quit())

                oLoop = GLib.MainLoop()
                oLoop.run()
                sys.exit(0)

            except dbus.DBusException as oDBusException:

                print(oDBusException)

        else:

            print("Cannot start ayatana-webmail-url - Ayatana Webmail is not running.")

    else:

        print('ayatana-webmail-url must be called with one of these arguments: Home, Compose, Inbox or Sent')

    sys.exit(1)