-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathEmailAccount.js
103 lines (96 loc) · 3.12 KB
/
EmailAccount.js
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
/*
* Copyright (c) 2012-2017 Gnome Email Notifications contributors
*
* Gnome Email Notifications Extension 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.
*
* Gnome Email Notifications Extension 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 Gnome Documents; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
"use strict";
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Console = Me.imports.console.Console;
const Gettext = imports.gettext.domain('gmail_notify');
const _ = Gettext.gettext;
const InboxScanner = Me.imports.InboxScanner.InboxScanner;
const Notifier = Me.imports.Notifier.Notifier;
/**
* Controls a single Gnome Online Account
*/
var EmailAccount = class {
/**
* Creates a new EmailAccount with a Gnome Online Account
* @param {Conf} config
* @param account - the Gnome Online Account
*/
constructor(config, account) {
this.config = config;
this.mailbox = account.get_account().presentation_identity;
if (this.mailbox === undefined) this.mailbox = '';
this._scanner = new InboxScanner(account, this.config);
this._notifier = new Notifier(this);
this._console = new Console();
}
/**
* Creates a notification for an error and logs it to the console
* @param {Error} error - the error to display
*/
_showError(error) {
this._console.error(error);
this._notifier.showError(error);
}
/**
* Scans the current account for emails
*/
scanInbox() {
try {
this._notifier.removeErrors();
this._scanner.scanInbox(this._processData.bind(this));
} catch (err) {
this._showError(err);
}
}
/**
* Displays error or emails to message tray.
* @param {Error} err - the error to display
* @param folders - a list of folders which contain unread emails
* @private
*/
_processData(err, folders) {
if (err) {
this._showError(err);
} else {
try {
const content = folders[0].list;
this.updateContent(content);
} catch (err) {
this._showError(err);
}
}
}
/**
* Displays notifications for unread emails
* @param content - a list of unread emails
*/
updateContent(content) {
if (content !== undefined) {
content.reverse();
this._notifier.displayUnreadMessages(content);
}
}
/**
* Destroys all sources for the email account
*/
destroySources() {
this._notifier.destroySources();
}
};