From: Michael Schmidt Date: Tue, 22 Sep 2009 17:18:12 +0000 (+0000) Subject: ADD: check mail and notify on new mail X-Git-Url: http://code.vuplus.com/gitweb/?p=vuplus_dvbapp-plugin;a=commitdiff_plain;h=a6c4dd9474c61396d6dc875882f07e50b15715e3 ADD: check mail and notify on new mail ADD: localisation --- diff --git a/emailclient/Makefile.am b/emailclient/Makefile.am index 308a09c..8078aa5 100755 --- a/emailclient/Makefile.am +++ b/emailclient/Makefile.am @@ -1 +1 @@ -SUBDIRS = src +SUBDIRS = src po diff --git a/emailclient/po/EmailClient.pot b/emailclient/po/EmailClient.pot new file mode 100644 index 0000000..8d9d564 --- /dev/null +++ b/emailclient/po/EmailClient.pot @@ -0,0 +1,164 @@ +# Enigma2 Plugin EmailClient Messages +# Copyright (C) 2009 THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2009-09-22 17:39+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "Attachments" +msgstr "" + +msgid "Bodys" +msgstr "" + +#, python-format +msgid "Box '%s' is empty" +msgstr "" + +msgid "Date" +msgstr "" + +msgid "Email Client" +msgstr "" + +msgid "From" +msgstr "" + +msgid "IMAP Port" +msgstr "" + +msgid "IMAP Server" +msgstr "" + +msgid "In" +msgstr "" + +msgid "" +"In order of missing standart python library files\n" +"i have copied the nessary files now.\n" +"But you have to restart your Box\n" +" to apply this!" +msgstr "" + +msgid "Mailbox" +msgstr "" + +msgid "" +"New mail arrived:\n" +"\n" +msgstr "" + +msgid "Password" +msgstr "" + +msgid "Subject" +msgstr "" + +msgid "Username" +msgstr "" + +msgid "cancel" +msgstr "" + +msgid "connected" +msgstr "" + +msgid "delete" +msgstr "" + +#, python-format +msgid "have %d messages " +msgstr "" + +msgid "headers loaded, now parsing ..." +msgstr "" + +msgid "interval to check for new mails" +msgstr "" + +msgid "leave unread" +msgstr "" + +#, python-format +msgid "loading headers %(from)d-%(to)d of Box '%(name)s'" +msgstr "" + +msgid "loading message" +msgstr "" + +msgid "logged in" +msgstr "" + +msgid "mail check process stopped" +msgstr "" + +msgid "max of Headers to load" +msgstr "" + +msgid "no" +msgstr "" + +msgid "no date" +msgstr "" + +msgid "no filename" +msgstr "" + +msgid "no from" +msgstr "" + +msgid "no sender" +msgstr "" + +msgid "no subject" +msgstr "" + +msgid "notify about new mails" +msgstr "" + +msgid "ok" +msgstr "" + +msgid "parsing message" +msgstr "" + +msgid "really delete Mail?" +msgstr "" + +msgid "really undelete Mail?" +msgstr "" + +msgid "select Attachment" +msgstr "" + +msgid "select Body" +msgstr "" + +msgid "show deleted entries" +msgstr "" + +msgid "timeout displaying new mails" +msgstr "" + +msgid "undelete" +msgstr "" + +msgid "unread messages in mailbox" +msgstr "" + +msgid "view Emails via IMAP4" +msgstr "" + +msgid "yes" +msgstr "" diff --git a/emailclient/po/Makefile.am b/emailclient/po/Makefile.am new file mode 100644 index 0000000..3dd22f2 --- /dev/null +++ b/emailclient/po/Makefile.am @@ -0,0 +1,57 @@ +# +# to use this for the localisation of other plugins, +# just change the DOMAIN to the name of the Plugin. +# It is assumed, that the domain ist the same as +# the directory name of the plugin. +# + +DOMAIN=EmailClient +installdir = /usr/lib/enigma2/python/Plugins/Extensions/$(DOMAIN) +#GETTEXT=./pygettext.py +GETTEXT=xgettext + +#MSGFMT = ./msgfmt.py +MSGFMT = msgfmt + +LANGS := de +LANGPO := $(foreach LANG, $(LANGS),$(LANG).po) +LANGMO := $(foreach LANG, $(LANGS),$(LANG).mo) + +default: $(DOMAIN).pot $(LANGPO) merge $(LANGMO) + for lang in $(LANGS); do \ + mkdir -p $$lang/LC_MESSAGES; \ + cp $$lang.mo $$lang/LC_MESSAGES/$(DOMAIN).mo; \ + done + +merge: + for lang in $(LANGS); do \ + msgmerge --no-location -s -N -U $$lang.po $(DOMAIN).pot; \ + done + + +# the TRANSLATORS: allows putting translation comments before the to-be-translated line. +$(DOMAIN).pot: + $(GETTEXT) --from-code=utf-8 -L python --add-comments="TRANSLATORS:" -d $(DOMAIN) -s -o $(DOMAIN).pot ../src/*.py + msguniq -o $(DOMAIN)uniq.pot $(DOMAIN).pot + $(RM) $(DOMAIN).pot + mv $(DOMAIN)uniq.pot $(DOMAIN).pot + +.PHONY: $(DOMAIN).pot + + +%.mo: %.po + $(MSGFMT) -o $@ $< + +%.po: + msginit -l $@ -o $@ -i $(DOMAIN).pot --no-translator + +CLEANFILES = $(foreach LANG, $(LANGS),$(LANG).mo) + +clean-local: + $(RM) -r $(LANGS) + +install-data-am: default + for lang in $(LANGS); do \ + mkdir -p $(DESTDIR)$(installdir)/locale/$$lang/LC_MESSAGES; \ + cp $$lang.mo $(DESTDIR)$(installdir)/locale/$$lang/LC_MESSAGES/$(DOMAIN).mo; \ + done diff --git a/emailclient/po/de.po b/emailclient/po/de.po new file mode 100644 index 0000000..67d41b6 --- /dev/null +++ b/emailclient/po/de.po @@ -0,0 +1,168 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Enigma2 EmailClient Plugin\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2009-09-22 19:08+0200\n" +"PO-Revision-Date: 2009-09-22 19:08+0200\n" +"Last-Translator: Michael Schmidt \n" +"Language-Team: de \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "Attachments" +msgstr "Anhänge" + +msgid "Bodys" +msgstr "" + +#, python-format +msgid "Box '%s' is empty" +msgstr "Mailbox %s ist leer" + +msgid "Date" +msgstr "Datum" + +msgid "Email Client" +msgstr "Email Client" + +msgid "From" +msgstr "Von" + +msgid "IMAP Port" +msgstr "IMAP Port" + +msgid "IMAP Server" +msgstr "IMAP Server" + +msgid "In" +msgstr "In" + +msgid "" +"In order of missing standart python library files\n" +"i have copied the nessary files now.\n" +"But you have to restart your Box\n" +" to apply this!" +msgstr "" +"Da Standard-Python-Library-Dateien fehlten,\n" +"wurden diese kopiert.\n" +"Ein Neustart könnte notwendig sein." + +msgid "Mailbox" +msgstr "Mailbox" + +msgid "" +"New mail arrived:\n" +"\n" +msgstr "" +"Neue Mail ist angekommen:\n" +"\n" + +msgid "Password" +msgstr "Passwort" + +msgid "Subject" +msgstr "Betreff" + +msgid "Username" +msgstr "Benutzername" + +msgid "cancel" +msgstr "Abbruch" + +msgid "connected" +msgstr "verbunden" + +msgid "delete" +msgstr "Löschen" + +#, python-format +msgid "have %d messages" +msgstr "habe %d Mails" + +msgid "headers loaded, now parsing ..." +msgstr "Header geladen, analysiere diese nun ..." + +msgid "interval to check for new mails" +msgstr "Intervall zur Prüfung auf neue Mails" + +msgid "leave unread" +msgstr "Ungelesen lassen" + +#, python-format +msgid "loading headers %(from)d-%(to)d of Box '%(name)s'" +msgstr "lade Header %(from)d-%(to)d von Mailbox '%(name)s'" + +msgid "loading message" +msgstr "lade Mail" + +msgid "logged in" +msgstr "angemeldet" + +msgid "mail check process stopped" +msgstr "Abfrage neuer Mails angehalten" + +msgid "max of Headers to load" +msgstr "Maximale Anzahl zu ladende Header" + +msgid "no" +msgstr "Nein" + +msgid "no date" +msgstr "kein Datum" + +msgid "no filename" +msgstr "kein Dateiname" + +msgid "no from" +msgstr "kein Absender" + +msgid "no sender" +msgstr "kein Sender" + +msgid "no subject" +msgstr "kein Betreff" + +msgid "notify about new mails" +msgstr "Benachrichtige bei neuen Mails" + +msgid "ok" +msgstr "OK" + +msgid "parsing message" +msgstr "Analysiere Mail" + +msgid "really delete Mail?" +msgstr "Mail wirklich löschen?" + +msgid "really undelete Mail?" +msgstr "Mail wiederherstellen?" + +msgid "select Attachment" +msgstr "wähle Anhang" + +msgid "select Body" +msgstr "wähle Textteil" + +msgid "show deleted entries" +msgstr "Anzeige gelöschter Mails" + +msgid "timeout displaying new mails" +msgstr "Timeout bei Anzeige neuer Mails" + +msgid "undelete" +msgstr "Löschen rückgängig" + +msgid "unread messages in mailbox" +msgstr "ungelesene Mails in Mailbox" + +msgid "view Emails via IMAP4" +msgstr "Lesen von Emails via IMAP4" + +msgid "yes" +msgstr "Ja" diff --git a/emailclient/src/EmailConfig.py b/emailclient/src/EmailConfig.py index 71beb34..c3c6881 100755 --- a/emailclient/src/EmailConfig.py +++ b/emailclient/src/EmailConfig.py @@ -4,6 +4,9 @@ from Components.ConfigList import ConfigListScreen from Components.Label import Label from Components.ActionMap import ActionMap +from . import _ +import plugin + from enigma import getDesktop DESKTOP_WIDTH = getDesktop(0).size().width() DESKTOP_HEIGHT = getDesktop(0).size().height() @@ -46,16 +49,8 @@ class EmailConfigScreen(ConfigListScreen,Screen): def __init__(self, session, args = 0): Screen.__init__(self, session) - l = [ - getConfigListEntry(_("Username"), config.plugins.emailimap.username), - getConfigListEntry(_("Password"), config.plugins.emailimap.password), - getConfigListEntry(_("IMAP Server"), config.plugins.emailimap.server), - getConfigListEntry(_("IMAP Port"), config.plugins.emailimap.port), - getConfigListEntry(_("max of Headers to load"), config.plugins.emailimap.maxheadertoload), - getConfigListEntry(_("show deleted entries"), config.plugins.emailimap.showDeleted) - ] - - ConfigListScreen.__init__(self, l) + self.list = [] + ConfigListScreen.__init__(self, self.list) self["buttonred"] = Label(_("cancel")) self["buttongreen"] = Label(_("ok")) self["info"] = Label('by 3c5x9') @@ -67,11 +62,41 @@ class EmailConfigScreen(ConfigListScreen,Screen): "cancel": self.cancel, "ok": self.save, }, -2) + self.createSetup() + + def createSetup(self): + self.list = [ + getConfigListEntry(_("Username"), config.plugins.emailimap.username), + getConfigListEntry(_("Password"), config.plugins.emailimap.password), + getConfigListEntry(_("IMAP Server"), config.plugins.emailimap.server), + getConfigListEntry(_("IMAP Port"), config.plugins.emailimap.port), + getConfigListEntry(_("max of Headers to load"), config.plugins.emailimap.maxheadertoload), + getConfigListEntry(_("show deleted entries"), config.plugins.emailimap.showDeleted), + getConfigListEntry(_("notify about new mails"), config.plugins.emailimap.checkForNewMails) + ] + if config.plugins.emailimap.checkForNewMails.value: + self.list.append(getConfigListEntry(_("interval to check for new mails"), config.plugins.emailimap.checkPeriod)) + self.list.append(getConfigListEntry(_("timeout displaying new mails"), config.plugins.emailimap.timeout)) + self["config"].list = self.list + self["config"].l.setList(self.list) + + def keyLeft(self): + ConfigListScreen.keyLeft(self) + self.createSetup() + + def keyRight(self): + ConfigListScreen.keyRight(self) + self.createSetup() def save(self): print "saving" for x in self["config"].list: x[1].save() + if plugin.mailChecker: + plugin.mailChecker.exit() + if config.plugins.emailimap.checkForNewMails.value: + plugin.mailChecker = plugin.CheckMail() + self.close(True) def cancel(self): diff --git a/emailclient/src/__init__.py b/emailclient/src/__init__.py index e69de29..74fa1a4 100755 --- a/emailclient/src/__init__.py +++ b/emailclient/src/__init__.py @@ -0,0 +1,15 @@ +from Tools.Directories import resolveFilename, SCOPE_LANGUAGE, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE +from Components.Language import language +import os, gettext + +lang = language.getLanguage() +os.environ["LANGUAGE"] = lang[:2] +gettext.bindtextdomain("enigma2", resolveFilename(SCOPE_LANGUAGE)) +gettext.textdomain("enigma2") +gettext.bindtextdomain("EmailClient", "%s%s" % (resolveFilename(SCOPE_PLUGINS), "Extensions/EmailClient/locale/")) + +def _(txt): + t = gettext.dgettext("EmailClient", txt) + if t == txt: + t = gettext.gettext(txt) + return t diff --git a/emailclient/src/plugin.py b/emailclient/src/plugin.py index 765cdf9..800eb82 100755 --- a/emailclient/src/plugin.py +++ b/emailclient/src/plugin.py @@ -1,10 +1,8 @@ from Components.ActionMap import ActionMap -from Components.GUIComponent import GUIComponent -from Components.HTMLComponent import HTMLComponent from Components.Label import Label from Screens.MessageBox import MessageBox from Components.MenuList import MenuList -from Components.MultiContent import MultiContentEntryText, MultiContentTemplateColor +from Components.MultiContent import MultiContentEntryText from Components.ScrollLabel import ScrollLabel from Components.Button import Button from Components.config import config, ConfigSubsection, ConfigInteger, ConfigText, ConfigEnableDisable @@ -12,22 +10,26 @@ from EmailConfig import EmailConfigScreen from Plugins.Plugin import PluginDescriptor from Screens.ChoiceBox import ChoiceBox from Screens.Screen import Screen -from enigma import eListboxPythonMultiContent, eListbox, gFont +from Tools import Notifications +from enigma import eListboxPythonMultiContent, gFont, eTimer from twisted.mail import imap4 from zope.interface import implements import email -import email.Parser from email.header import decode_header from TagStrip import strip_readable from protocol import createFactory +from . import _ + config.plugins.emailimap = ConfigSubsection() config.plugins.emailimap.username = ConfigText("user", fixed_size=False) config.plugins.emailimap.password = ConfigText("password", fixed_size=False) config.plugins.emailimap.server = ConfigText("please.config.first", fixed_size=False) -config.plugins.emailimap.port = ConfigInteger(143, limits = (1, 65536)) +config.plugins.emailimap.port = ConfigInteger(default=143, limits = (1, 65536)) config.plugins.emailimap.showDeleted = ConfigEnableDisable(default=False) - +config.plugins.emailimap.checkForNewMails = ConfigEnableDisable(default=True) +config.plugins.emailimap.checkPeriod = ConfigInteger(default=10000, limits=(10000, 1000000)) # in milliseconds, 600000 are 10 minutes (10*60*1000) +config.plugins.emailimap.timeout = ConfigInteger(default=0, limits=(0, 90)) # in seconds # 0= fetch all header , 10= fetch only the last 10 headers/messages of a mailbox config.plugins.emailimap.maxheadertoload = ConfigInteger(0, limits = (1, 100)) @@ -173,6 +175,7 @@ class EmailScreen(Screen, EmailHandler): ).addCallback(self.onExamine, c[0] , self.proto ).addErrback(self.onExamineFailed, self.proto ) + # self.proto.search(imap4.Query(unseen=1)).addCallback(self.cbOk).addErrback(self.cbNotOk) def onMessageSelected(self): c = self["messagelist"].getCurrent() @@ -205,7 +208,7 @@ class EmailScreen(Screen, EmailHandler): def loadMessage(self, message): print "loadMessage",message - self["infolabel"].setText("loading message") + self["infolabel"].setText(_("loading message")) self.proto.fetchMessage(message.uid ).addCallback(self.onMessageLoaded, message, self.proto @@ -213,7 +216,7 @@ class EmailScreen(Screen, EmailHandler): ) def onMessageLoaded(self, result, message, proto): - self["infolabel"].setText("parsing message") + self["infolabel"].setText(_("parsing message")) print "onMessageLoaded"#,result,message try: msgstr = result[message.uid]['RFC822'] @@ -257,7 +260,7 @@ class EmailScreen(Screen, EmailHandler): self.close() def onConnect(self, proto): - self["infolabel"].setText("connected") + self["infolabel"].setText(_("connected")) proto.getCapabilities( ).addCallback(self.cbCapabilities, proto ).addErrback(self.ebCapabilities, proto @@ -278,7 +281,7 @@ class EmailScreen(Screen, EmailHandler): def onAuthentication(self, result, proto): self.proto = proto - self["infolabel"].setText("logged in") + self["infolabel"].setText(_("logged in")) # better use LSUB here to get only the subscribed to mailboxes proto.lsub("", "*").addCallback(self.onMailboxList, proto) @@ -330,11 +333,11 @@ class EmailScreen(Screen, EmailHandler): def onExamine(self, result, mboxname, proto): print "onExamine", result, mboxname - self.setTitle("Mailbox: "+mboxname) + self.setTitle(_("Mailbox")+": "+mboxname) self.currentmailbox = mboxname numMessagesinFolder = int(result['EXISTS']) if numMessagesinFolder <= 0: - self["infolabel"].setText("Box '"+mboxname+"' is empty") + self["infolabel"].setText(_("Box '%s' is empty") %(mboxname)) self["messagelist"].l.setList([]) else: @@ -346,7 +349,7 @@ class EmailScreen(Screen, EmailHandler): rangeToFetch = [startmsg, numMessagesinFolder] else: rangeToFetch = [1, numMessagesinFolder] - self["infolabel"].setText("loading headers "+str(rangeToFetch[0])+"-"+str(rangeToFetch[1])+" of Box '"+mboxname+"'") + self["infolabel"].setText(_("loading headers %(from)d-%(to)d of Box '%(name)s'") % {'from': rangeToFetch[0], 'to': rangeToFetch[1], 'name': mboxname}) try: # proto.fetchEnvelope('%i:%i'%(rangeToFetch[0], rangeToFetch[1]) #'1:*' @@ -379,7 +382,7 @@ class EmailScreen(Screen, EmailHandler): def onHeaderList(self, result, proto): print "onHeaderList"#,result,proto - self["infolabel"].setText("headers loaded, now parsing ...") + self["infolabel"].setText(_("headers loaded, now parsing ...")) list = [] for m in result: state = IS_UNSEEN @@ -401,7 +404,7 @@ class EmailScreen(Screen, EmailHandler): print "onHeaderList error: %s with: %s" %(e,result[m]['RFC822.HEADER']) list.reverse() self["messagelist"].l.setList(list) - self["infolabel"].setText("have "+str(len(list))+" messages ") + self["infolabel"].setText(_("have %d messages") %(len(list))) def buildMessageListItem(self, message, state): if state == IS_UNSEEN: @@ -416,7 +419,7 @@ class EmailScreen(Screen, EmailHandler): return [ message, MultiContentEntryText(pos=(5, 0), size=(self.messagelistWidth, scaleV(20,18)+5), font=font, text=message.getSenderString(), color=color, color_sel=color), - MultiContentEntryText(pos=(5, scaleV(20,18)+1), size=(self.messagelistWidth, scaleV(20,18)+5), font=font, text=message.get('date', default='kein Datum'), color=color, color_sel=color), + MultiContentEntryText(pos=(5, scaleV(20,18)+1), size=(self.messagelistWidth, scaleV(20,18)+5), font=font, text=message.get('date', default=_('no date')), color=color, color_sel=color), MultiContentEntryText(pos=(5, 2*(scaleV(20,18)+1)), size=(self.messagelistWidth, scaleV(20,18)+5), font=font, text=message.getSubject(), color=color, color_sel=color) ] # @@ -474,12 +477,12 @@ class ScreenMailView(Screen): 4*buttonsGap+3*140, height-30-5, scaleV(18,16), ) Screen.__init__(self, session) - self["from"] = Label(decodeHeader(_("From") +": %s" %self.email.get('from', 'no-from'))) + self["from"] = Label(decodeHeader(_("From") +": %s" %self.email.get('from', _('no from')))) self["date"] = Label(_("Date") +": %s" %self.email.get('date', 'no-date')) - self["subject"] = Label(decodeHeader(_("Subject") +": %s" %self.email.get('subject', 'no-subject'))) + self["subject"] = Label(decodeHeader(_("Subject") +": %s" %self.email.get('subject', _('no subject')))) self["body"] = ScrollLabel(_(self.email.messagebodys[0].getData())) # TODO: show headers - self["buttonred"] = Button(_("")) + self["buttonred"] = Button("") self["buttongreen"] = Button("") self["buttonyellow"] = Button(_("leave unread")) if '\\Deleted' in flags: @@ -595,7 +598,7 @@ class MessageHeader(object): return self.message.get(key,failobj=default) def __str__(self): - return "" + return "" ############ class EmailBody: @@ -669,7 +672,7 @@ def main(session, **kwargs): shutil.copy('/usr/lib/enigma2/python/Plugins/Extensions/EmailClient/uu.py', '/usr/lib/python2.5/uu.py') global session2 session2 = session - session.openWithCallback(MessageCB, MessageBox, 'In order of missing standart python library files\ni have copied the nessary files now.\nBut you have to restart your Box\n to apply this!', type = MessageBox.TYPE_INFO) + session.openWithCallback(MessageCB, MessageBox, _('In order of missing standart python library files\ni have copied the nessary files now.\nBut you have to restart your Box\n to apply this!'), type = MessageBox.TYPE_INFO) else: session.open(EmailScreen) @@ -677,13 +680,132 @@ def MessageCB(*args): global session2 session2.open(EmailScreen) +class CheckMail: + implements(imap4.IMailboxListener) + + def __init__(self): + print('[CheckMail] __init__') + createFactory(self, config.plugins.emailimap.username.value, config.plugins.emailimap.server.value, config.plugins.emailimap.port.value) + self._timer = eTimer() + # self._timer.timeout.get().append(self._checkMail) + self._timer.callback.append(self._checkMail) + self._timer.start(config.plugins.emailimap.checkPeriod.value) + self._unseenList = None + self._proto = None + + def exit(self): + if self._proto: + self._proto.logout() + self._proto = None + self._timer.stop() + + def _checkMail(self): + print('[CheckMail] _checkMail ') + if self._proto: + self._proto.search(imap4.Query(unseen=1)).addCallback(self._cbNotify).addErrback(self._ebNotify, "search") + + def _cbNotify(self, newUnseenList): + def haveSeenBefore(messageNo): return messageNo not in self._unseenList + + print("[CheckMail] _cbNotify newUnseenList: %s" %repr(newUnseenList)) + if self._unseenList is None: + Notifications.AddNotification(MessageBox, str(len(newUnseenList)) + ' ' + _("unread messages in mailbox"), type=MessageBox.TYPE_INFO, timeout=config.plugins.emailimap.timeout.value) + else: + newMessages = filter(haveSeenBefore, newUnseenList) + if newMessages: + print("[CheckMail] _cbNotify newMessages: %s" %repr(newMessages)) + newMessageSet = imap4.MessageSet() + for messageNo in newMessages: + newMessageSet.add(messageNo) + self._proto.fetchHeaders(newMessageSet).addCallback(self._onHeaderList).addErrback(self._ebNotify, "fetchHeaders") + self._unseenList = newUnseenList + + def _onHeaderList(self, headers): + # print("[CheckMail] _onHeaderList headers: %s" %repr(headers)) + message = _("New mail arrived:\n\n") + for h in headers: + m = MessageHeader(h, headers[h]['RFC822.HEADER']) + message += m.getSenderString() + '\n' + m.getSubject() + '\n\n' + Notifications.AddNotification(MessageBox, message, type=MessageBox.TYPE_INFO, timeout=config.plugins.emailimap.timeout.value) + + def _ebNotify(self, result, where): + print("[CheckMail] _ebNotify result: %s" %(result.getErrorMessage())) + Notifications.AddNotification(MessageBox, _("In") + " " + where + ": " +result.getErrorMessage() + '\n' + _("mail check process stopped"), type=MessageBox.TYPE_ERROR, timeout=config.plugins.emailimap.timeout.value) + self.exit() + + def _cbOk(self, result): + print("[CheckMail] _cbOk result: %s" %repr(result)) + + def onConnect(self, proto=None): + print('[CheckMail] onConnect ') + if not proto: + proto = self._proto + else: + self._proto = proto + proto.getCapabilities().addCallback(self._cbCapabilities).addErrback(self._ebNotify) + + def onConnectFailed(self, reason): + print('[CheckMail] onConnectFailed: ' + reason.getErrorMessage()) + self._ebNotify(reason, "onConnectFailed") + + def _cbCapabilities(self,reason): + print "#"*30 + print "# If you have problems to log into your imap-server, please send me the output of the following line" + print "# cbCapabilities",reason + print "#"*30 + self._doLogin() + + def _doLogin(self): + useTLS = False #True + if useTLS: + #d = self._proto.startTLS().addCallback(self._proto.authenticate, config.plugins.emailimap.password.value) + d = self._proto.startTLS().addCallback(self._proto.authenticate) # don't know, why authenticate wants no param... + else: + d = self._proto.authenticate(config.plugins.emailimap.password.value) + d.addCallback(self._onAuthentication).addErrback(self._onAuthenticationFailed) + + def _onAuthentication(self, result): + print("[CheckMail] onAuthentication: logged in") + self._proto.examine('inbox').addCallback(self._cbOk).addErrback(self._ebNotify, "examine") + self._checkMail() + + def _onAuthenticationFailed(self, failure): + # If it failed because no SASL mechanisms match + print("[CheckMail] onAuthenticationFailed: " + failure.getErrorMessage() + ' ' + str(self._proto)) + try: + failure.trap(imap4.NoSupportedAuthentication) + self._doLoginInsecure() + except Exception,e: + print e,e.message + + def _doLoginInsecure(self): + print("[CheckMail] doLoginInsecure") + self._proto.login(config.plugins.emailimap.username.value, config.plugins.emailimap.password.value + ).addCallback(self._onAuthentication).addErrback(self._ebNotify, "login") + +mailChecker = None +def autostart(reason, **kwargs): + # ouch, this is a hack + #=========================================================================== + # if kwargs.has_key("session"): + # global my_global_session + # my_global_session = kwargs["session"] + # return + #=========================================================================== + print("[EmailClient] - Autostart") + global mailChecker + if config.plugins.emailimap.checkForNewMails.value and not mailChecker: + mailChecker = CheckMail() + + def Plugins(path, **kwargs): global plugin_path plugin_path = path return [ - PluginDescriptor(name="Email Client", description="view Emails via IMAP4", + PluginDescriptor(name=_("Email Client"), description=_("view Emails via IMAP4"), where = PluginDescriptor.WHERE_PLUGINMENU, fnc = main, icon="plugin.png" ), + PluginDescriptor(where=[PluginDescriptor.WHERE_SESSIONSTART, PluginDescriptor.WHERE_AUTOSTART], fnc=autostart) ]