1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-26 19:02:20 -05:00

[WO-87][WO-89] automated sync and notification on incoming email

This commit is contained in:
Felix Hammerl 2013-11-05 14:00:50 +01:00
parent 0cefc08fa3
commit c0203bb1f6
4 changed files with 54 additions and 2 deletions

View File

@ -28,7 +28,8 @@ define([], function() {
host: 'smtp.gmail.com'
}
},
checkOutboxInterval: 30000
checkOutboxInterval: 30000,
iconPath: '/img/icon.png'
};
/**

View File

@ -5,6 +5,8 @@ define(function(require) {
angular = require('angular'),
appController = require('js/app-controller'),
IScroll = require('iscroll'),
str = require('js/app-config').string,
cfg = require('js/app-config').config,
emailDao;
var MailListCtrl = function($scope) {
@ -14,6 +16,35 @@ define(function(require) {
emailDao = appController._emailDao;
emailDao.onIncomingMessage = function(email) {
if (email.subject.indexOf(str.subjectPrefix) === -1) {
return;
}
// sync
$scope.synchronize(function() {
// show notification
notificationForEmail(email);
});
};
function notificationClicked(uidString) {
var email, uid = parseInt(uidString, 10);
if (isNaN(uid)) {
return;
}
email = _.findWhere($scope.emails, {
uid: uid
});
if (email) {
$scope.select(email);
}
}
chrome.notifications.onClicked.addListener(notificationClicked);
//
// scope functions
//
@ -34,7 +65,7 @@ define(function(require) {
markAsRead(email);
};
$scope.$parent.synchronize = $scope.synchronize = function() {
$scope.$parent.synchronize = $scope.synchronize = function(callback) {
updateStatus('Syncing ...');
// sync from imap to local db
syncImapFolder({
@ -49,6 +80,9 @@ define(function(require) {
num: num
}, function() {
updateStatus('Last update: ', new Date());
if (callback) {
callback();
}
});
});
};
@ -75,6 +109,15 @@ define(function(require) {
// helper functions
//
function notificationForEmail(email) {
chrome.notifications.create('' + email.uid, {
type: 'basic',
title: email.from[0].address,
message: email.subject.split(str.subjectPrefix)[1],
iconUrl: chrome.runtime.getURL(cfg.iconPath)
}, function() {});
}
function initList() {
updateStatus('Read cache ...');

View File

@ -17,6 +17,13 @@ define(function(require) {
self._smtpClient = smtpClient;
self._crypto = crypto;
self._devicestorage = devicestorage;
// delegation-esque pattern to mitigate between node-style events and plain js
self._imapClient.onIncomingMessage = function(message) {
if (typeof self.onIncomingMessage === 'function') {
self.onIncomingMessage(message);
}
};
};
/**

View File

@ -10,6 +10,7 @@
"permissions": [{
"fileSystem": ["write"]
},
"notifications",
"https://keys.whiteout.io/",
"identity", {
"socket": [