Update
This commit is contained in:
parent
5865aa445f
commit
ef3379f1d9
3 changed files with 33 additions and 3 deletions
|
@ -13,6 +13,7 @@ class Mailer {
|
|||
];
|
||||
static final List<String> whiteListEmail = ['louis@holyenergy.fr'];
|
||||
static MailClient? _mailClient;
|
||||
static Timer? _timer;
|
||||
|
||||
/// High level mail API example
|
||||
static Future<bool> connect({
|
||||
|
@ -45,7 +46,8 @@ class Mailer {
|
|||
_mailClient!.eventBus.on<ImapEvent>().listen((ImapEvent event) async {
|
||||
await _onMessage(event, streamController, email, whitelist);
|
||||
});
|
||||
await _mailClient!.startPolling();
|
||||
await _mailClient!.startPolling(const Duration(seconds: 1));
|
||||
_startDebugProfiler(streamController);
|
||||
return true;
|
||||
} on MailException catch (e) {
|
||||
streamController.add(StreamElement(StreamElementType.log, e.toString()));
|
||||
|
@ -59,6 +61,7 @@ class Mailer {
|
|||
}) async {
|
||||
if (_mailClient == null) return;
|
||||
Logger.log(LoggerType.info, Mailer, 'Disconnecting from mail');
|
||||
_stopDebugProfiler();
|
||||
await _mailClient!.stopPolling();
|
||||
await _mailClient!.disconnect();
|
||||
Logger.log(LoggerType.info, Mailer, 'Disconnected from mail');
|
||||
|
@ -103,4 +106,19 @@ class Mailer {
|
|||
await Requests.sendAlert(message, type: AlertType.host);
|
||||
streamController.add(StreamElement(StreamElementType.alert, message));
|
||||
}
|
||||
|
||||
static void _startDebugProfiler(StreamController streamController) {
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), (timer) async {
|
||||
if (!_mailClient!.isPolling()) {
|
||||
streamController.add(StreamElement(StreamElementType.warning,
|
||||
'Mail client is not polling | Restart it'));
|
||||
await _mailClient!.startPolling();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static void _stopDebugProfiler() {
|
||||
_timer?.cancel();
|
||||
_timer = null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue