aboutsummaryrefslogtreecommitdiff
path: root/data/usr/bin/ayatana-webmail-clear
blob: 500195fc0c1275d620d9d952c2161aff8d79d7b2 (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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Ayatana Webmail, Mark all messages as read
# Authors: 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

oLoop = None

if __name__ == '__main__':

    if isRunning():

        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')

            oInterface.clear(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-clear - Ayatana Webmail is not running.")

    sys.exit(1)