-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgoaplugin.py
114 lines (83 loc) · 3.37 KB
/
goaplugin.py
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Copyright 2014 - 2020 Patrick Ulbrich <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
import gi
gi.require_version('Goa', '1.0')
from gi.repository import Goa
from Mailnag.common.plugins import Plugin, HookTypes
from Mailnag.common.accounts import Account
from Mailnag.common.i18n import _
plugin_defaults = {}
class GOAPlugin(Plugin):
def __init__(self):
self._accounts_loaded_hook = None
def enable(self):
def accounts_loaded_hook(accounts):
client = Goa.Client.new_sync(None)
goa_accounts = client.get_accounts()
for a in goa_accounts:
mail = a.get_mail() # get the mail interface
if (mail != None) and (not a.get_account().props.mail_disabled):
if mail.props.imap_supported:
passwd = ''
auth_string = ''
pwd_based = a.get_password_based()
if pwd_based != None:
passwd = pwd_based.call_get_password_sync('imap-password', None)
else:
oauth2_based = a.get_oauth2_based()
if oauth2_based != None:
token = oauth2_based.call_get_access_token_sync(None)
# TODO: this authstring is probably GMail specific
# (Check a.get_account().props.provider_name == 'Google' ?)
# See : http://google-mail-oauth2-tools.googlecode.com/svn/trunk/python/oauth2.py
auth_string = 'user=%s\1auth=Bearer %s\1\1' % (mail.props.imap_user_name, token[0])
# Append GOA account to Mailnag accounts (if any)
if (passwd != '') or (auth_string != ''):
acc = Account(enabled = True, name = mail.props.email_address, \
user = mail.props.imap_user_name, password = passwd, \
oauth2string = auth_string, server = mail.props.imap_host, port = '', \
ssl = mail.props.imap_use_ssl, imap = True, idle = True, folders = [])
# acc.fetch_imap_folders()
accounts.append(acc)
self._accounts_loaded_hook = accounts_loaded_hook
controller = self.get_mailnag_controller()
hooks = controller.get_hooks()
hooks.register_hook_func(HookTypes.ACCOUNTS_LOADED,
self._accounts_loaded_hook)
def disable(self):
controller = self.get_mailnag_controller()
hooks = controller.get_hooks()
if self._accounts_loaded_hook != None:
hooks.unregister_hook_func(HookTypes.ACCOUNTS_LOADED,
self._accounts_loaded_hook)
self._accounts_loaded_hook = None
def get_manifest(self):
return (_("GNOME Online Accounts"),
_("GNOME Online Accounts Integration."),
"2.0",
"Patrick Ulbrich <[email protected]>")
def get_default_config(self):
return plugin_defaults
def has_config_ui(self):
return False
def get_config_ui(self):
return None
def load_ui_from_config(self, config_ui):
pass
def save_ui_to_config(self, config_ui):
pass