Added the newmail_hook
When new mail arrives, this hook is triggered, allowing the user to play a sound, or launch a popup. Signed-off-by: Matthew Krafczyk <krafczyk.matthew@gmail.com>
This commit is contained in:
parent
ca1ce256ec
commit
48bb2f4113
@ -295,6 +295,19 @@ remoterepository = RemoteExample
|
|||||||
#postsynchook = notifysync.sh
|
#postsynchook = notifysync.sh
|
||||||
|
|
||||||
|
|
||||||
|
# This option stands in the [Account Test] section.
|
||||||
|
#
|
||||||
|
# You can specify a newmail hook to execute an external command upon receipt
|
||||||
|
# of new mail in the INBOX.
|
||||||
|
#
|
||||||
|
# This example plays a sound file of your chosing when new mail arrives.
|
||||||
|
#
|
||||||
|
# This feature is experimental.
|
||||||
|
#
|
||||||
|
#newmail_hook = lambda: os.sytem("cvlc --play-and-exit /path/to/sound/file.mp3" +
|
||||||
|
# " > /dev/null 2>&1")
|
||||||
|
|
||||||
|
|
||||||
# This option stands in the [Account Test] section.
|
# This option stands in the [Account Test] section.
|
||||||
#
|
#
|
||||||
# OfflineImap caches the state of the synchronisation to e.g. be able to
|
# OfflineImap caches the state of the synchronisation to e.g. be able to
|
||||||
|
@ -40,6 +40,11 @@ class BaseFolder(object):
|
|||||||
# Top level dir name is always ''
|
# Top level dir name is always ''
|
||||||
self.root = None
|
self.root = None
|
||||||
self.name = name if not name == self.getsep() else ''
|
self.name = name if not name == self.getsep() else ''
|
||||||
|
self.newmail_hook = None
|
||||||
|
# Only set the newmail_hook if the IMAP folder is named 'INBOX'
|
||||||
|
if self.name == 'INBOX':
|
||||||
|
self.newmail_hook = repository.newmail_hook
|
||||||
|
self.have_newmail = False
|
||||||
self.repository = repository
|
self.repository = repository
|
||||||
self.visiblename = repository.nametrans(name)
|
self.visiblename = repository.nametrans(name)
|
||||||
# In case the visiblename becomes '.' or '/' (top-level) we use
|
# In case the visiblename becomes '.' or '/' (top-level) we use
|
||||||
@ -781,6 +786,9 @@ class BaseFolder(object):
|
|||||||
# Got new UID, change the local uid.
|
# Got new UID, change the local uid.
|
||||||
# Save uploaded status in the statusfolder
|
# Save uploaded status in the statusfolder
|
||||||
statusfolder.savemessage(new_uid, message, flags, rtime)
|
statusfolder.savemessage(new_uid, message, flags, rtime)
|
||||||
|
# Check whether the mail has been seen
|
||||||
|
if 'S' not in flags:
|
||||||
|
self.have_newmail = True
|
||||||
elif new_uid == 0:
|
elif new_uid == 0:
|
||||||
# Message was stored to dstfolder, but we can't find it's UID
|
# Message was stored to dstfolder, but we can't find it's UID
|
||||||
# This means we can't link current message to the one created
|
# This means we can't link current message to the one created
|
||||||
@ -817,6 +825,9 @@ class BaseFolder(object):
|
|||||||
|
|
||||||
This function checks and protects us from action in dryrun mode."""
|
This function checks and protects us from action in dryrun mode."""
|
||||||
|
|
||||||
|
# We have no new mail yet
|
||||||
|
self.have_newmail = False
|
||||||
|
|
||||||
threads = []
|
threads = []
|
||||||
|
|
||||||
copylist = filter(lambda uid: not statusfolder.uidexists(uid),
|
copylist = filter(lambda uid: not statusfolder.uidexists(uid),
|
||||||
@ -854,6 +865,11 @@ class BaseFolder(object):
|
|||||||
for thread in threads:
|
for thread in threads:
|
||||||
thread.join()
|
thread.join()
|
||||||
|
|
||||||
|
# Execute new mail hook if we have new mail
|
||||||
|
if self.have_newmail:
|
||||||
|
if self.newmail_hook != None:
|
||||||
|
self.newmail_hook();
|
||||||
|
|
||||||
def __syncmessagesto_delete(self, dstfolder, statusfolder):
|
def __syncmessagesto_delete(self, dstfolder, statusfolder):
|
||||||
"""Pass 2: Remove locally deleted messages on dst.
|
"""Pass 2: Remove locally deleted messages on dst.
|
||||||
|
|
||||||
|
@ -48,6 +48,7 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
|
|||||||
self.folderfilter = lambda foldername: 1
|
self.folderfilter = lambda foldername: 1
|
||||||
self.folderincludes = []
|
self.folderincludes = []
|
||||||
self.foldersort = None
|
self.foldersort = None
|
||||||
|
self.newmail_hook = None
|
||||||
if self.config.has_option(self.getsection(), 'nametrans'):
|
if self.config.has_option(self.getsection(), 'nametrans'):
|
||||||
self.nametrans = self.localeval.eval(
|
self.nametrans = self.localeval.eval(
|
||||||
self.getconf('nametrans'), {'re': re})
|
self.getconf('nametrans'), {'re': re})
|
||||||
|
@ -36,6 +36,11 @@ class IMAPRepository(BaseRepository):
|
|||||||
self._host = None
|
self._host = None
|
||||||
self.imapserver = imapserver.IMAPServer(self)
|
self.imapserver = imapserver.IMAPServer(self)
|
||||||
self.folders = None
|
self.folders = None
|
||||||
|
# Only set the newmail_hook in an IMAP repository.
|
||||||
|
if self.config.has_option(self.getsection(), 'newmail_hook'):
|
||||||
|
self.newmail_hook = self.localeval.eval(
|
||||||
|
self.getconf('newmail_hook'))
|
||||||
|
|
||||||
if self.getconf('sep', None):
|
if self.getconf('sep', None):
|
||||||
self.ui.info("The 'sep' setting is being ignored for IMAP "
|
self.ui.info("The 'sep' setting is being ignored for IMAP "
|
||||||
"repository '%s' (it's autodetected)"% self)
|
"repository '%s' (it's autodetected)"% self)
|
||||||
|
Loading…
Reference in New Issue
Block a user