Major rewrite: multiple accounts, notification about new mails
authorMichael Schmidt <drmichael@users.schwerkraft.elitedvb.net>
Sat, 31 Oct 2009 15:14:31 +0000 (15:14 +0000)
committerMichael Schmidt <drmichael@users.schwerkraft.elitedvb.net>
Sat, 31 Oct 2009 15:14:31 +0000 (15:14 +0000)
12 files changed:
emailclient/CONTROL/control
emailclient/po/EmailClient.pot
emailclient/po/Makefile.am
emailclient/po/de.po
emailclient/po/es.po [new file with mode: 0644]
emailclient/po/it.po
emailclient/po/sr.po
emailclient/src/EmailConfig.py
emailclient/src/Makefile.am
emailclient/src/__init__.py
emailclient/src/plugin.py
emailclient/src/protocol.py

index a24a1a8..5826c12 100755 (executable)
@@ -6,5 +6,5 @@ Section: extra
 Priority: optional
 Maintainer: 3c5x9 <3c5x9@gmx.net>
 Homepage: n/a
-Depends: enigma2, twisted-web, twisted-mail, python-email, python-pyopenssl, python-shell
+Depends: enigma2, twisted-web, twisted-mail, python-email, python-pyopenssl, python-shell, python-textutils
 Source: http://schwerkraft.elitedvb.net/scm/?group_id=11
index bf94ac2..d21f146 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2009-10-03 17:26+0200\n"
+"POT-Creation-Date: 2009-10-31 11:19+0100\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -16,14 +16,17 @@ msgstr ""
 "Content-Type: text/plain; charset=CHARSET\n"
 "Content-Transfer-Encoding: 8bit\n"
 
-msgid "Attachments"
+#, python-format
+msgid "%(name)s (%(user)s@%(server)s)"
 msgstr ""
 
-msgid "Bodys"
+msgid "Accounts list"
 msgstr ""
 
-#, python-format
-msgid "Box '%s' is empty"
+msgid "Attachments"
+msgstr ""
+
+msgid "Bodys"
 msgstr ""
 
 msgid "Date"
@@ -35,6 +38,16 @@ msgstr ""
 msgid "Email Client"
 msgstr ""
 
+msgid "Email setup"
+msgstr ""
+
+#, python-format
+msgid ""
+"EmailClient for %(account)s:\n"
+"\n"
+"%(error)s"
+msgstr ""
+
 msgid "From"
 msgstr ""
 
@@ -44,41 +57,46 @@ msgstr ""
 msgid "IMAP Server"
 msgstr ""
 
+#, python-format
 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!"
+"New mail arrived for account %s:\n"
+"\n"
 msgstr ""
 
-msgid "Mailbox"
+#, python-format
+msgid "Really delete account %s?"
 msgstr ""
 
-msgid ""
-"New mail arrived:\n"
-"\n"
+msgid "Subject"
 msgstr ""
 
-msgid "Password"
+#, python-format
+msgid ""
+"[EmailAccount] %(name)s: _cbCapabilities:\n"
+"####################################################################################################\n"
+"# If you have problems to log into your imap-server, please send me the "
+"output of the following line\n"
+"# cbCapabilities: %(capa)s\n"
+"####################################################################################################\n"
 msgstr ""
 
-msgid "Subject"
+#, python-format
+msgid "account %s is not connected"
 msgstr ""
 
-msgid "Username"
+msgid "account name"
 msgstr ""
 
-msgid "cancel"
+msgid "account not connected"
 msgstr ""
 
-msgid "cannot access inbox"
+msgid "add"
 msgstr ""
 
-#, python-format
-msgid "cannot access mailbox '%(mboxname)s'"
+msgid "cancel"
 msgstr ""
 
-msgid "cannot get capabilities of mailserver"
+msgid "cannot access inbox"
 msgstr ""
 
 msgid "cannot get headers of new messages"
@@ -87,32 +105,31 @@ msgstr ""
 msgid "cannot get list of new messages"
 msgstr ""
 
-msgid "check interval (minutes)"
+msgid "connection failed - retrying"
 msgstr ""
 
-msgid "connected"
+msgid "delete"
 msgstr ""
 
-#, python-format
-msgid "connection to %(server)s:%(port)d failed"
+msgid "display timeout (seconds)"
 msgstr ""
 
-#, python-format
-msgid ""
-"connection to %(server)s:%(port)d failed:\n"
-"%(reason)s"
+msgid "edit"
 msgstr ""
 
-msgid "delete"
+msgid "empty values - retry"
 msgstr ""
 
-msgid "display timeout (seconds)"
+#, python-format
+msgid ""
+"error logging %(who)s in:\n"
+"%(failure)s"
 msgstr ""
 
-msgid "encrypted login failed, trying without encryption"
+msgid "failed to load message"
 msgstr ""
 
-msgid "failed to load message"
+msgid "getting message ..."
 msgstr ""
 
 #, python-format
@@ -125,26 +142,26 @@ msgstr ""
 msgid "headers loaded, now parsing ..."
 msgstr ""
 
-msgid "leave unread"
+#, python-format
+msgid "importing configurations from %s"
 msgstr ""
 
-#, python-format
-msgid "loading headers %(from)d-%(to)d of Box '%(name)s'"
+msgid "leave unread"
 msgstr ""
 
-msgid "loading message"
+msgid "loading headers ..."
 msgstr ""
 
-msgid "logged in"
+msgid "mail check interval (minutes)"
 msgstr ""
 
-msgid "login failed"
+msgid "maximum mail size to fetch"
 msgstr ""
 
-msgid "max of Headers to load"
+msgid "message too large"
 msgstr ""
 
-msgid "no"
+msgid "no account selected"
 msgstr ""
 
 msgid "no date"
@@ -156,6 +173,9 @@ msgstr ""
 msgid "no from"
 msgstr ""
 
+msgid "no mailbox?!?!"
+msgstr ""
+
 msgid "no sender"
 msgstr ""
 
@@ -168,13 +188,19 @@ msgstr ""
 msgid "ok"
 msgstr ""
 
-msgid "parsing message"
+msgid "parsing message ..."
 msgstr ""
 
-msgid "really delete Mail?"
+msgid "password"
 msgstr ""
 
-msgid "really undelete Mail?"
+msgid "really delete mail?"
+msgstr ""
+
+msgid "really undelete mail?"
+msgstr ""
+
+msgid "remove"
 msgstr ""
 
 msgid "select Attachment"
@@ -189,11 +215,8 @@ msgstr ""
 msgid "undelete"
 msgstr ""
 
-msgid "unread messages in mailbox"
+msgid "user name"
 msgstr ""
 
 msgid "view Emails via IMAP4"
 msgstr ""
-
-msgid "yes"
-msgstr ""
index d492d54..f323b8e 100644 (file)
@@ -13,7 +13,7 @@ GETTEXT=xgettext
 #MSGFMT = ./msgfmt.py
 MSGFMT = msgfmt
 
-LANGS := de it sr sv
+LANGS := de it sr sv es
 LANGPO := $(foreach LANG, $(LANGS),$(LANG).po)
 LANGMO := $(foreach LANG, $(LANGS),$(LANG).mo)
 
index 0d7577e..8444d4b 100644 (file)
@@ -7,24 +7,27 @@ msgid ""
 msgstr ""
 "Project-Id-Version: Enigma2 EmailClient Plugin\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2009-10-03 17:26+0200\n"
-"PO-Revision-Date: 2009-10-03 17:27+0200\n"
+"POT-Creation-Date: 2009-10-31 11:19+0100\n"
+"PO-Revision-Date: 2009-10-23 19:16+0200\n"
 "Last-Translator: Michael Schmidt <michael@schmidt-schmitten.com>\n"
 "Language-Team: de <de@li.org>\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=utf-8\n"
 "Content-Transfer-Encoding: 8bit\n"
 
+#, python-format
+msgid "%(name)s (%(user)s@%(server)s)"
+msgstr "%(name)s (%(user)s@%(server)s)"
+
+msgid "Accounts list"
+msgstr "Kontenliste"
+
 msgid "Attachments"
 msgstr "Anhänge"
 
 msgid "Bodys"
 msgstr "Textkörper"
 
-#, python-format
-msgid "Box '%s' is empty"
-msgstr "Mailbox %s ist leer"
-
 msgid "Date"
 msgstr "Datum"
 
@@ -34,6 +37,19 @@ msgstr "Debug"
 msgid "Email Client"
 msgstr "Email Client"
 
+msgid "Email setup"
+msgstr "Email Einstellungen"
+
+#, python-format
+msgid ""
+"EmailClient for %(account)s:\n"
+"\n"
+"%(error)s"
+msgstr ""
+"EmailClient für %(account)s:\n"
+"\n"
+"%(error)s"
+
 msgid "From"
 msgstr "Von"
 
@@ -43,34 +59,49 @@ msgstr "IMAP Port"
 msgid "IMAP Server"
 msgstr "IMAP Server"
 
+#, python-format
 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"
+"New mail arrived for account %s:\n"
 "\n"
 msgstr ""
-"Neue Nachricht ist angekommen:\n"
+"Neue Nachricht für %s ist angekommen:\n"
 "\n"
 
-msgid "Password"
-msgstr "Passwort"
+#, python-format
+msgid "Really delete account %s?"
+msgstr "Konto '%s' wirklich löschen?"
 
 msgid "Subject"
 msgstr "Betreff"
 
-msgid "Username"
-msgstr "Benutzername"
+#, python-format
+msgid ""
+"[EmailAccount] %(name)s: _cbCapabilities:\n"
+"####################################################################################################\n"
+"# If you have problems to log into your imap-server, please send me the "
+"output of the following line\n"
+"# cbCapabilities: %(capa)s\n"
+"####################################################################################################\n"
+msgstr ""
+"[EmailAccount] %(name)s: _cbCapabilities:\n"
+"####################################################################################################\n"
+"# Bei Problemen sich am IMAP-Server anzumelden, bitte folgende Zeilen "
+"schicken:\n"
+"# cbCapabilities: %(capa)s\n"
+"####################################################################################################\n"
+
+#, python-format
+msgid "account %s is not connected"
+msgstr "Konto %s ist nicht verbunden"
+
+msgid "account name"
+msgstr "Kontoname"
+
+msgid "account not connected"
+msgstr "Konto nicht verbunden"
+
+msgid "add"
+msgstr "Hinzufügen"
 
 msgid "cancel"
 msgstr "Abbruch"
@@ -78,36 +109,14 @@ msgstr "Abbruch"
 msgid "cannot access inbox"
 msgstr "Kein Zugriff auf INBOX"
 
-#, python-format
-msgid "cannot access mailbox '%(mboxname)s'"
-msgstr "Kein Zugriff auf Mailbox '%(mboxname)s'"
-
-msgid "cannot get capabilities of mailserver"
-msgstr "Kann Eigenschaften des Mailservers nicht auslesen"
-
 msgid "cannot get headers of new messages"
 msgstr "Kann Header der neuen Nachrichten nicht lesen"
 
 msgid "cannot get list of new messages"
 msgstr "Kann Liste neuer Nachrichten nicht bekommen"
 
-msgid "check interval (minutes)"
-msgstr "Check-Intervall (in Minuten)"
-
-msgid "connected"
-msgstr "Verbunden"
-
-#, python-format
-msgid "connection to %(server)s:%(port)d failed"
-msgstr "Verbindung zu  %(server)s:%(port)d fehlgeschlagen"
-
-#, python-format
-msgid ""
-"connection to %(server)s:%(port)d failed:\n"
-"%(reason)s"
-msgstr ""
-"Verbindung zu  %(server)s:%(port)d fehlgeschlagen\n"
-"%(reason)s"
+msgid "connection failed - retrying"
+msgstr "Verbindung fehlgeschlage - neuer Versuch"
 
 msgid "delete"
 msgstr "Löschen"
@@ -115,12 +124,26 @@ msgstr "Löschen"
 msgid "display timeout (seconds)"
 msgstr "Anzeige-Timeout (in Sekunden)"
 
-msgid "encrypted login failed, trying without encryption"
-msgstr "Verschlüsselte Anmeldung fehlgeschlagen, versuche es unverschlüsselt"
+msgid "edit"
+msgstr "Bearbeiten"
+
+msgid "empty values - retry"
+msgstr "Leere Felder, neuer Versuch"
+
+#, python-format
+msgid ""
+"error logging %(who)s in:\n"
+"%(failure)s"
+msgstr ""
+"Fehler bei Anmeldung von %(who)s:\n"
+"%(failure)s"
 
 msgid "failed to load message"
 msgstr "Konnte Nachricht nicht laden"
 
+msgid "getting message ..."
+msgstr "Hole Nachricht ..."
+
 #, python-format
 msgid "have %d messages"
 msgstr "%d Nachrichten"
@@ -131,27 +154,27 @@ msgstr "Keine Nachrichten"
 msgid "headers loaded, now parsing ..."
 msgstr "Header geladen, analysiere diese nun ..."
 
+#, python-format
+msgid "importing configurations from %s"
+msgstr "Importiere Konfigurationen von %s"
+
 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 Nachricht"
+msgid "loading headers ..."
+msgstr "Lade Header ..."
 
-msgid "logged in"
-msgstr "Angemeldet"
+msgid "mail check interval (minutes)"
+msgstr "Mailcheck-Intervall"
 
-msgid "login failed"
-msgstr "Anmeldung fehlgeschlagen"
+msgid "maximum mail size to fetch"
+msgstr "Hole nur Nachrichten bis zur Größe"
 
-msgid "max of Headers to load"
-msgstr "Maximale Anzahl zu ladende Header"
+msgid "message too large"
+msgstr "Nachricht zu groß"
 
-msgid "no"
-msgstr "Nein"
+msgid "no account selected"
+msgstr "Kein Konto ausgewählt"
 
 msgid "no date"
 msgstr "kein Datum"
@@ -162,6 +185,9 @@ msgstr "kein Dateiname"
 msgid "no from"
 msgstr "kein Absender"
 
+msgid "no mailbox?!?!"
+msgstr ""
+
 msgid "no sender"
 msgstr "kein Sender"
 
@@ -174,14 +200,20 @@ msgstr "Benachrichtige bei neuen Nachrichten"
 msgid "ok"
 msgstr "OK"
 
-msgid "parsing message"
-msgstr "Analysiere Mail"
+msgid "parsing message ..."
+msgstr "Analysiere Nachricht ..."
+
+msgid "password"
+msgstr "Passwort"
 
-msgid "really delete Mail?"
-msgstr "Mail wirklich löschen?"
+msgid "really delete mail?"
+msgstr "Nachricht wirklich löschen?"
 
-msgid "really undelete Mail?"
-msgstr "Mail wiederherstellen?"
+msgid "really undelete mail?"
+msgstr "Nachricht wiederherstellen?"
+
+msgid "remove"
+msgstr "Löschen"
 
 msgid "select Attachment"
 msgstr "Wähle Anhang"
@@ -195,11 +227,8 @@ msgstr "Anzeige gelöschter Mails"
 msgid "undelete"
 msgstr "Löschen rückgängig"
 
-msgid "unread messages in mailbox"
-msgstr "ungelesene Mails in Mailbox"
+msgid "user name"
+msgstr "Benutzername"
 
 msgid "view Emails via IMAP4"
 msgstr "Lesen von Emails via IMAP4"
-
-msgid "yes"
-msgstr "Ja"
diff --git a/emailclient/po/es.po b/emailclient/po/es.po
new file mode 100644 (file)
index 0000000..426f822
--- /dev/null
@@ -0,0 +1,292 @@
+# Spanish translations for enigma2-plugins package.
+# Copyright (C) 2009 THE enigma2-plugins'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the enigma2-plugins package.
+# Automatically generated, 2009.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: enigma2-plugins 1.0\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2009-10-31 11:19+0100\n"
+"PO-Revision-Date: 2009-10-28 08:44+0100\n"
+"Last-Translator: José Juan Zapater <josej@zapater.fdns.net>\n"
+"Language-Team: none\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+#, python-format
+msgid "%(name)s (%(user)s@%(server)s)"
+msgstr "%(name)s (%(user)s@%(server)s)"
+
+msgid "Accounts list"
+msgstr "Lista de cuentas"
+
+msgid "Attachments"
+msgstr "Adjuntos"
+
+msgid "Bodys"
+msgstr "Cuerpos"
+
+msgid "Date"
+msgstr "Fecha"
+
+msgid "Debug"
+msgstr "Debug"
+
+msgid "Email Client"
+msgstr "Cliente correo"
+
+msgid "Email setup"
+msgstr "Configuración correo"
+
+#, python-format
+msgid ""
+"EmailClient for %(account)s:\n"
+"\n"
+"%(error)s"
+msgstr ""
+"EmailClient para %(account)s:\n"
+"\n"
+"%(error)s"
+
+msgid "From"
+msgstr "De"
+
+msgid "IMAP Port"
+msgstr "Puerto IMAP"
+
+msgid "IMAP Server"
+msgstr "Servidor IMAP"
+
+#, python-format
+msgid ""
+"New mail arrived for account %s:\n"
+"\n"
+msgstr ""
+"Nuevo correo para la cuenta %s:\n"
+"\n"
+
+#, python-format
+msgid "Really delete account %s?"
+msgstr "¿Seguro que quiere borrar la cuenta %s?"
+
+msgid "Subject"
+msgstr "Asunto"
+
+#, python-format
+msgid ""
+"[EmailAccount] %(name)s: _cbCapabilities:\n"
+"####################################################################################################\n"
+"# If you have problems to log into your imap-server, please send me the "
+"output of the following line\n"
+"# cbCapabilities: %(capa)s\n"
+"####################################################################################################\n"
+msgstr ""
+"[CuentaEmail] %(name)s: _cbCapacidades:\n"
+"####################################################################################################\n"
+"# Si tiene problemas al entrar en el servidor imap, envíeme la salida de la "
+"siguiente línea\n"
+"# cbCapabilities: %(capa)s\n"
+"####################################################################################################\n"
+
+#, python-format
+msgid "account %s is not connected"
+msgstr "la cuenta %s no está conectada"
+
+msgid "account name"
+msgstr "nombre de la cuenta"
+
+msgid "account not connected"
+msgstr "cuenta no conectada"
+
+msgid "add"
+msgstr "añadir"
+
+msgid "cancel"
+msgstr "cancelar"
+
+msgid "cannot access inbox"
+msgstr "no puedo acceder a la bandeja de entrada"
+
+msgid "cannot get headers of new messages"
+msgstr "no puede obtener las cabeceras de los nuevos mensajes"
+
+msgid "cannot get list of new messages"
+msgstr "no puedo obtener la lista de mensajes nuevos"
+
+msgid "connection failed - retrying"
+msgstr "falló la conexión - reintentando"
+
+msgid "delete"
+msgstr "borrar"
+
+msgid "display timeout (seconds)"
+msgstr "visualizar timeout (segundos)"
+
+msgid "edit"
+msgstr "editar"
+
+msgid "empty values - retry"
+msgstr "valores vacíos - reintentando"
+
+#, python-format
+msgid ""
+"error logging %(who)s in:\n"
+"%(failure)s"
+msgstr ""
+"error logueando %(who)s en:\n"
+"%(failure)s"
+
+msgid "failed to load message"
+msgstr "falló la carga del mensaje"
+
+msgid "getting message ..."
+msgstr "cargando mensaje"
+
+#, python-format
+msgid "have %d messages"
+msgstr "tiene %d mensajes"
+
+msgid "have no messages"
+msgstr "no hay mensajes"
+
+msgid "headers loaded, now parsing ..."
+msgstr "cabeceras cargadas, analizando ..."
+
+#, python-format
+msgid "importing configurations from %s"
+msgstr "importando configuraciones desde %s"
+
+msgid "leave unread"
+msgstr "dejarlo sin leer"
+
+msgid "loading headers ..."
+msgstr "cargando cabeceras..."
+
+msgid "mail check interval (minutes)"
+msgstr "intérvalo de chequeo (minutos)"
+
+msgid "maximum mail size to fetch"
+msgstr "máximo tamaño del mensaje a traer"
+
+msgid "message too large"
+msgstr "mensaje demasiado grande"
+
+msgid "no account selected"
+msgstr "no ha seleccionado ninguna cuenta"
+
+msgid "no date"
+msgstr "sin fecha"
+
+msgid "no filename"
+msgstr "sin nombre de fichero"
+
+msgid "no from"
+msgstr "sin de"
+
+msgid "no mailbox?!?!"
+msgstr ""
+
+msgid "no sender"
+msgstr "sin origen"
+
+msgid "no subject"
+msgstr "sin asunto"
+
+msgid "notify about new mails"
+msgstr "notifíqueme sobre nuevos correos"
+
+msgid "ok"
+msgstr "ok"
+
+msgid "parsing message ..."
+msgstr "analizando mensaje..."
+
+msgid "password"
+msgstr "contraseña"
+
+msgid "really delete mail?"
+msgstr "¿Seguro que quiere borrar el correo?"
+
+msgid "really undelete mail?"
+msgstr "¿Seguro que quiere desborrar el correo?"
+
+msgid "remove"
+msgstr "borrar"
+
+msgid "select Attachment"
+msgstr "seleccionar Adjunto"
+
+msgid "select Body"
+msgstr "seleccionar Cuerpo"
+
+msgid "show deleted entries"
+msgstr "mostrar entradas borradas"
+
+msgid "undelete"
+msgstr "desborrar"
+
+msgid "user name"
+msgstr "nombre de usuario"
+
+msgid "view Emails via IMAP4"
+msgstr "ver Correos via IMAP4"
+
+#~ msgid "Box '%s' is empty"
+#~ msgstr "Buzón '%s' está vacío"
+
+#~ 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 ""
+#~ "Faltaban ficheros de librería python\n"
+#~ "he copiado los ficheros necesarios.\n"
+#~ "Deberá reiniciar el equipo\n"
+#~ "para aplicar esto!"
+
+#~ msgid "Mailbox"
+#~ msgstr "Buzón"
+
+#~ msgid "cannot access mailbox '%(mboxname)s'"
+#~ msgstr "no puedo acceder al buzón '%(mboxname)s'"
+
+#~ msgid "cannot get capabilities of mailserver"
+#~ msgstr "no puedo obtener las capacidades del servidor"
+
+#~ msgid "connection to %(server)s:%(port)d failed"
+#~ msgstr "falló la conexión a %(server)s:%(port)d"
+
+#~ msgid ""
+#~ "connection to %(server)s:%(port)d failed:\n"
+#~ "%(reason)s"
+#~ msgstr ""
+#~ "falló la conexión a %(server)s:%(port)d:\n"
+#~ "%(reason)s"
+
+#~ msgid "encrypted login failed, trying without encryption"
+#~ msgstr "falló el login encriptado, intente sin encriptar"
+
+#~ msgid "loading headers %(from)d-%(to)d of Box '%(name)s'"
+#~ msgstr "cargando cabeceras %(from)d-%(to)d del Buzón '%(name)s'"
+
+#~ msgid "logged in"
+#~ msgstr "logueado"
+
+#~ msgid "login failed"
+#~ msgstr "falló el logueo"
+
+#~ msgid "max of Headers to load"
+#~ msgstr "máx de Caberas a cargar"
+
+#~ msgid "no"
+#~ msgstr "no"
+
+#~ msgid "unread messages in mailbox"
+#~ msgstr "mensajes no leídos en el buzón"
+
+#~ msgid "yes"
+#~ msgstr "si"
index 26fa55e..d5f047f 100644 (file)
@@ -2,8 +2,8 @@ msgid ""
 msgstr ""
 "Project-Id-Version: enigma2 - emailclient\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2009-10-03 17:26+0200\n"
-"PO-Revision-Date: 2009-09-23 15:35+0100\n"
+"POT-Creation-Date: 2009-10-31 11:19+0100\n"
+"PO-Revision-Date: 2009-10-25 22:14+0100\n"
 "Last-Translator: Spaeleus <spaeleus@croci.org>\n"
 "Language-Team: www.linsat.net <spaeleus@croci.org>\n"
 "MIME-Version: 1.0\n"
@@ -16,25 +16,41 @@ msgstr ""
 "X-Poedit-Basepath: /home/dario/Plugins/emailclient\n"
 "X-Poedit-SearchPath-0: /home/dario/Plugins/emailclient\n"
 
+#, python-format
+msgid "%(name)s (%(user)s@%(server)s)"
+msgstr "%(name)s (%(user)s@%(server)s)"
+
+msgid "Accounts list"
+msgstr "Elenco account"
+
 msgid "Attachments"
 msgstr "Allegati"
 
 msgid "Bodys"
 msgstr "Corpi"
 
-#, python-format
-msgid "Box '%s' is empty"
-msgstr "Il box \"%s\" è vuoto"
-
 msgid "Date"
 msgstr "Data"
 
 msgid "Debug"
-msgstr ""
+msgstr "Debug"
 
 msgid "Email Client"
 msgstr "Client email"
 
+msgid "Email setup"
+msgstr "Configurazione email"
+
+#, python-format
+msgid ""
+"EmailClient for %(account)s:\n"
+"\n"
+"%(error)s"
+msgstr ""
+"EmailClient per %(account)s:\n"
+"\n"
+"%(error)s"
+
 msgid "From"
 msgstr "Da"
 
@@ -44,116 +60,122 @@ msgstr "Porta IMAP"
 msgid "IMAP Server"
 msgstr "Server IMAP"
 
+#, python-format
 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 ""
-"A causa della mancanza di librerie python indispensabili\n"
-"i file necessari sono stati copiati.\n"
-"Ora si rende necessario io riavvio del Dreambox\n"
-"per la loro attivazione!"
-
-msgid "Mailbox"
-msgstr "Mailbox"
-
-msgid ""
-"New mail arrived:\n"
+"New mail arrived for account %s:\n"
 "\n"
 msgstr ""
-"Nuovo messaggio ricevuto:\n"
+"Nuovo messaggio ricevuto per l'account %s:\n"
 "\n"
 
-msgid "Password"
-msgstr "Password"
+#, python-format
+msgid "Really delete account %s?"
+msgstr "Cancellare l'account %s?"
 
 msgid "Subject"
 msgstr "Soggetto"
 
-msgid "Username"
-msgstr "Nome User"
-
-msgid "cancel"
-msgstr "Annull."
-
-msgid "cannot access inbox"
+#, python-format
+msgid ""
+"[EmailAccount] %(name)s: _cbCapabilities:\n"
+"####################################################################################################\n"
+"# If you have problems to log into your imap-server, please send me the "
+"output of the following line\n"
+"# cbCapabilities: %(capa)s\n"
+"####################################################################################################\n"
 msgstr ""
+"[EmailAccount] %(name)s: _cbCapabilities:\n"
+"####################################################################################################\n"
+"# In caso di difficoltà ad effettuare il login al proprio server imap, "
+"inviarmi il contenuto della riga seguente.\n"
+"# cbCapabilities: %(capa)s\n"
+"####################################################################################################\n"
 
 #, python-format
-msgid "cannot access mailbox '%(mboxname)s'"
-msgstr ""
+msgid "account %s is not connected"
+msgstr "L'account %s non è connesso"
 
-msgid "cannot get capabilities of mailserver"
-msgstr ""
+msgid "account name"
+msgstr "Nome account"
 
-msgid "cannot get headers of new messages"
-msgstr ""
+msgid "account not connected"
+msgstr "Account non connesso"
 
-msgid "cannot get list of new messages"
-msgstr ""
+msgid "add"
+msgstr "Agg."
 
-#, fuzzy
-msgid "check interval (minutes)"
-msgstr "Intervallo verifica nuovi messaggi (minuti)"
+msgid "cancel"
+msgstr "Annull."
 
-msgid "connected"
-msgstr "Connesso"
+msgid "cannot access inbox"
+msgstr "Impossibile accedere alla inbox"
 
-#, python-format
-msgid "connection to %(server)s:%(port)d failed"
-msgstr ""
+msgid "cannot get headers of new messages"
+msgstr "Impossibile ottenere l'elenco intestazioni nuovi messaggi"
 
-#, python-format
-msgid ""
-"connection to %(server)s:%(port)d failed:\n"
-"%(reason)s"
-msgstr ""
+msgid "cannot get list of new messages"
+msgstr "Impossibile ottenere l'elenco dei nuovi messaggi"
+
+msgid "connection failed - retrying"
+msgstr "Connessione fallita. Nuovo tentativo in corso"
 
 msgid "delete"
 msgstr "Cancellare"
 
-#, fuzzy
 msgid "display timeout (seconds)"
-msgstr "Marcare come letto dopo (secondi)"
+msgstr "Timeout visualizzazione (secondi)"
+
+msgid "edit"
+msgstr "Mod."
+
+msgid "empty values - retry"
+msgstr "Valori nulli - riprovare"
 
-msgid "encrypted login failed, trying without encryption"
+#, python-format
+msgid ""
+"error logging %(who)s in:\n"
+"%(failure)s"
 msgstr ""
+"Errore log %(who)s in:\n"
+"%(failure)s"
 
 msgid "failed to load message"
-msgstr ""
+msgstr "Caricamento messaggio fallito"
+
+msgid "getting message ..."
+msgstr "Caricamento messaggio..."
 
 #, python-format
 msgid "have %d messages"
 msgstr "Ricevuti %d messaggi"
 
 msgid "have no messages"
-msgstr ""
+msgstr "Nessun messaggio"
 
 msgid "headers loaded, now parsing ..."
 msgstr "Intestazioni caricate, analisi in corso"
 
+#, python-format
+msgid "importing configurations from %s"
+msgstr "Importazione configurazione da %s in corso"
+
 msgid "leave unread"
 msgstr "Lasciare non letto"
 
-#, python-format
-msgid "loading headers %(from)d-%(to)d of Box '%(name)s'"
-msgstr "Caricamento intestazioni %(from)d-%(to)d dal Box \"%(name)s\""
-
-msgid "loading message"
-msgstr "Caricamento messaggio"
+msgid "loading headers ..."
+msgstr "Caricamento intestazioni..."
 
-msgid "logged in"
-msgstr "Registrato"
+msgid "mail check interval (minutes)"
+msgstr "Intervallo verifica mail (minuti)"
 
-msgid "login failed"
-msgstr ""
+msgid "maximum mail size to fetch"
+msgstr "Dimensione massima messaggi"
 
-msgid "max of Headers to load"
-msgstr "Num. max. intestazioni da caricare"
+msgid "message too large"
+msgstr "Messaggio troppo grande"
 
-msgid "no"
-msgstr "No"
+msgid "no account selected"
+msgstr "Nessun account selezionato"
 
 msgid "no date"
 msgstr "Nessuna data"
@@ -164,6 +186,9 @@ msgstr "Nessun nome file"
 msgid "no from"
 msgstr "Nessuna origine"
 
+msgid "no mailbox?!?!"
+msgstr ""
+
 msgid "no sender"
 msgstr "Nessun mittente"
 
@@ -176,14 +201,20 @@ msgstr "Avvisare dell'arrivo di nuovi messaggi"
 msgid "ok"
 msgstr "Ok"
 
-msgid "parsing message"
-msgstr "nalisi messaggio"
+msgid "parsing message ..."
+msgstr "Analisi messaggio..."
 
-msgid "really delete Mail?"
+msgid "password"
+msgstr "Password"
+
+msgid "really delete mail?"
 msgstr "Cancellare il messaggio?"
 
-msgid "really undelete Mail?"
-msgstr "Ripristinare il messaggio"
+msgid "really undelete mail?"
+msgstr "Ripristinare il messaggio?"
+
+msgid "remove"
+msgstr "Canc."
 
 msgid "select Attachment"
 msgstr "Sel. allegato"
@@ -197,21 +228,8 @@ msgstr "Mostrare le voci cancellate"
 msgid "undelete"
 msgstr "Ripristinare"
 
-msgid "unread messages in mailbox"
-msgstr "Messaggi non letti"
+msgid "user name"
+msgstr "Nome User"
 
 msgid "view Emails via IMAP4"
 msgstr "Leggere email (prot. IMAP4)"
-
-msgid "yes"
-msgstr "Sì"
-
-#~ msgid "In"
-#~ msgstr "In"
-
-#, fuzzy
-#~ msgid "connection failed"
-#~ msgstr "Connesso"
-
-#~ msgid "mail check process stopped"
-#~ msgstr "Processo di verifica mail interrotto"
index a37aa9b..36975ec 100755 (executable)
@@ -7,7 +7,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: Enigma2 - Plugin EmailClient\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2009-10-03 17:26+0200\n"
+"POT-Creation-Date: 2009-10-31 11:19+0100\n"
 "PO-Revision-Date: 2009-09-27 17:49+0100\n"
 "Last-Translator: maja <jovanovic@gmx.ch>\n"
 "Language-Team: veselin & majevica CRNABERZA <jovanovic@gmx.ch>\n"
@@ -18,16 +18,19 @@ msgstr ""
 "X-Poedit-Country: SERBIA\n"
 "X-Poedit-SourceCharset: utf-8\n"
 
+#, python-format
+msgid "%(name)s (%(user)s@%(server)s)"
+msgstr ""
+
+msgid "Accounts list"
+msgstr ""
+
 msgid "Attachments"
 msgstr "Dodatci"
 
 msgid "Bodys"
 msgstr "Oblici"
 
-#, python-format
-msgid "Box '%s' is empty"
-msgstr "Sanduče %s je prazno"
-
 msgid "Date"
 msgstr "Datum"
 
@@ -37,6 +40,17 @@ msgstr ""
 msgid "Email Client"
 msgstr "Imejl klijent"
 
+#, fuzzy
+msgid "Email setup"
+msgstr "Imejl klijent"
+
+#, python-format
+msgid ""
+"EmailClient for %(account)s:\n"
+"\n"
+"%(error)s"
+msgstr ""
+
 msgid "From"
 msgstr "Od"
 
@@ -46,47 +60,49 @@ msgstr "IMAP Port"
 msgid "IMAP Server"
 msgstr "IMAP Server"
 
+#, fuzzy, python-format
 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 ""
-"Zbog nedostatka stand. python lib. datoteka\n"
-"sada sam kopirao potrebne datoteke.\n"
-"Ali vi treba da restartujete vaš boks\n"
-"da ovo primenite!"
-
-msgid "Mailbox"
-msgstr "Pošt. sand."
-
-msgid ""
-"New mail arrived:\n"
+"New mail arrived for account %s:\n"
 "\n"
 msgstr ""
 "Nova poruka stigla:\n"
 "\n"
 
-msgid "Password"
-msgstr "Lozinka"
+#, fuzzy, python-format
+msgid "Really delete account %s?"
+msgstr "stvarno obrisati poruku?"
 
 msgid "Subject"
 msgstr "Subjekt"
 
-msgid "Username"
-msgstr "Korisn. ime"
+#, python-format
+msgid ""
+"[EmailAccount] %(name)s: _cbCapabilities:\n"
+"####################################################################################################\n"
+"# If you have problems to log into your imap-server, please send me the "
+"output of the following line\n"
+"# cbCapabilities: %(capa)s\n"
+"####################################################################################################\n"
+msgstr ""
 
-msgid "cancel"
-msgstr "otkaži"
+#, fuzzy, python-format
+msgid "account %s is not connected"
+msgstr "spojen"
 
-msgid "cannot access inbox"
+msgid "account name"
 msgstr ""
 
-#, python-format
-msgid "cannot access mailbox '%(mboxname)s'"
+#, fuzzy
+msgid "account not connected"
+msgstr "spojen"
+
+msgid "add"
 msgstr ""
 
-msgid "cannot get capabilities of mailserver"
+msgid "cancel"
+msgstr "otkaži"
+
+msgid "cannot access inbox"
 msgstr ""
 
 msgid "cannot get headers of new messages"
@@ -95,21 +111,7 @@ msgstr ""
 msgid "cannot get list of new messages"
 msgstr ""
 
-#, fuzzy
-msgid "check interval (minutes)"
-msgstr "Interval za proveru novih poruka (u minutima)"
-
-msgid "connected"
-msgstr "spojen"
-
-#, python-format
-msgid "connection to %(server)s:%(port)d failed"
-msgstr ""
-
-#, python-format
-msgid ""
-"connection to %(server)s:%(port)d failed:\n"
-"%(reason)s"
+msgid "connection failed - retrying"
 msgstr ""
 
 msgid "delete"
@@ -119,13 +121,26 @@ msgstr "obriši"
 msgid "display timeout (seconds)"
 msgstr "vreme prikazivanja nove poruke (sekunde)"
 
-msgid "encrypted login failed, trying without encryption"
+msgid "edit"
+msgstr ""
+
+msgid "empty values - retry"
+msgstr ""
+
+#, python-format
+msgid ""
+"error logging %(who)s in:\n"
+"%(failure)s"
 msgstr ""
 
 #, fuzzy
 msgid "failed to load message"
 msgstr "učitavam poruku"
 
+#, fuzzy
+msgid "getting message ..."
+msgstr "analiziram poruku"
+
 #, python-format
 msgid "have %d messages"
 msgstr "ima %d poruka"
@@ -137,27 +152,30 @@ msgstr "ima %d poruka"
 msgid "headers loaded, now parsing ..."
 msgstr "Zaglavlja učitana, sad raščlanjujem ..."
 
+#, python-format
+msgid "importing configurations from %s"
+msgstr ""
+
 msgid "leave unread"
 msgstr "ostavi nepročitano"
 
-#, python-format
-msgid "loading headers %(from)d-%(to)d of Box '%(name)s'"
-msgstr "učitavam zaglavlja %(from)d-%(to)d iz sand.'%(name)s'"
-
-msgid "loading message"
+#, fuzzy
+msgid "loading headers ..."
 msgstr "učitavam poruku"
 
-msgid "logged in"
-msgstr "regstrovan"
+#, fuzzy
+msgid "mail check interval (minutes)"
+msgstr "Interval za proveru novih poruka (u minutima)"
 
-msgid "login failed"
+msgid "maximum mail size to fetch"
 msgstr ""
 
-msgid "max of Headers to load"
-msgstr "maksimum zaglavlja za učitavanje"
+msgid "message too large"
+msgstr ""
 
-msgid "no"
-msgstr "ne"
+#, fuzzy
+msgid "no account selected"
+msgstr "spojen"
 
 msgid "no date"
 msgstr "bez datuma"
@@ -168,6 +186,9 @@ msgstr "bez imena datoteke"
 msgid "no from"
 msgstr "bez odakle"
 
+msgid "no mailbox?!?!"
+msgstr ""
+
 msgid "no sender"
 msgstr "bez pošiljaoca"
 
@@ -180,15 +201,25 @@ msgstr "obavesti o novim porukama"
 msgid "ok"
 msgstr "ok"
 
-msgid "parsing message"
+#, fuzzy
+msgid "parsing message ..."
 msgstr "analiziram poruku"
 
-msgid "really delete Mail?"
+#, fuzzy
+msgid "password"
+msgstr "Lozinka"
+
+#, fuzzy
+msgid "really delete mail?"
 msgstr "stvarno obrisati poruku?"
 
-msgid "really undelete Mail?"
+#, fuzzy
+msgid "really undelete mail?"
 msgstr "stvarno restaurirati poruku?"
 
+msgid "remove"
+msgstr ""
+
 msgid "select Attachment"
 msgstr "izaberi dodatak"
 
@@ -201,17 +232,55 @@ msgstr "pokaži obrisane unose"
 msgid "undelete"
 msgstr "restauriraj"
 
-msgid "unread messages in mailbox"
-msgstr "nepročitane poruke u sandučetu"
+#, fuzzy
+msgid "user name"
+msgstr "Korisn. ime"
 
 msgid "view Emails via IMAP4"
 msgstr "vidi imejlove preko IMAP4"
 
-msgid "yes"
-msgstr "da"
+#~ msgid "Box '%s' is empty"
+#~ msgstr "Sanduče %s je prazno"
 
 #~ msgid "In"
 #~ msgstr "U"
 
+#~ 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 ""
+#~ "Zbog nedostatka stand. python lib. datoteka\n"
+#~ "sada sam kopirao potrebne datoteke.\n"
+#~ "Ali vi treba da restartujete vaš boks\n"
+#~ "da ovo primenite!"
+
+#~ msgid "Mailbox"
+#~ msgstr "Pošt. sand."
+
+#, fuzzy
+#~ msgid "Yes"
+#~ msgstr "da"
+
+#~ msgid "loading headers %(from)d-%(to)d of Box '%(name)s'"
+#~ msgstr "učitavam zaglavlja %(from)d-%(to)d iz sand.'%(name)s'"
+
+#~ msgid "logged in"
+#~ msgstr "regstrovan"
+
 #~ msgid "mail check process stopped"
 #~ msgstr "proces provere poruka zaustavljen"
+
+#~ msgid "max of Headers to load"
+#~ msgstr "maksimum zaglavlja za učitavanje"
+
+#~ msgid "no"
+#~ msgstr "ne"
+
+#, fuzzy
+#~ msgid "unread messages in mailbox %s"
+#~ msgstr "nepročitane poruke u sandučetu"
+
+#~ msgid "yes"
+#~ msgstr "da"
index 22de288..f8cad3f 100755 (executable)
@@ -1,34 +1,18 @@
 from Screens.Screen import Screen
-from Components.config import config, getConfigListEntry
+from Screens.MessageBox import MessageBox
+from Components.config import config, getConfigListEntry, ConfigText, ConfigPassword, ConfigSelection
 from Components.ConfigList import ConfigListScreen
 from Components.Label import Label
 from Components.ActionMap import ActionMap
 
-from . import _, initLog
-import plugin
+from . import _, initLog, debug, scaleH, scaleV, DESKTOP_WIDTH, DESKTOP_HEIGHT #@UnresolvedImport
+from plugin import mailAccounts
 
-from enigma import getDesktop
-DESKTOP_WIDTH = getDesktop(0).size().width()
-DESKTOP_HEIGHT = getDesktop(0).size().height()
-def scaleH(y2, y1):
-       if y2 == -1:
-               y2 = y1*1280/720
-       elif y1 == -1:
-               y1 = y2*720/1280
-       return scale(y2, y1, 1280, 720, DESKTOP_WIDTH)
-def scaleV(y2, y1):
-       if y2 == -1:
-               y2 = y1*720/576
-       elif y1 == -1:
-               y1 = y2*576/720
-       return scale(y2, y1, 720, 576, DESKTOP_HEIGHT)
-def scale(y2, y1, x2, x1, x):
-       return (y2 - y1) * (x - x1) / (x2 - x1) + y1
-
-class EmailConfigScreen(ConfigListScreen,Screen):
-       width = max(2*140+100, 550)
+class EmailConfigOptions(ConfigListScreen,Screen):
+       noButtons = 2
+       width = max(noButtons*140+100, 550)
        height = 5*30+50
-       buttonsGap = (width-2*140)/3
+       buttonsGap = (width-noButtons*140)/(noButtons+1)
        skin = """
                <screen position="%d,%d" size="%d,%d" title="Email Setup" >
                <widget name="config" position="0,0" size="%d,%d" scrollbarMode="showOnDemand" />
@@ -36,7 +20,6 @@ class EmailConfigScreen(ConfigListScreen,Screen):
                <ePixmap position="%d,%d" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
                <widget name="buttonred" position="%d,%d" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;%d" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
                <widget name="buttongreen" position="%d,%d" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;%d" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
-               <widget name="info" position="%d,%d" size="100,40" halign="right" zPosition="2"  foregroundColor="white" font="Regular;%d"/> 
                </screen>""" %(
                                        (DESKTOP_WIDTH-width)/2, (DESKTOP_HEIGHT-height)/2, width, height,
                                        width, height-50,  # config
@@ -44,16 +27,15 @@ class EmailConfigScreen(ConfigListScreen,Screen):
                                        2*buttonsGap+140, height-45,
                                        buttonsGap, height-45, scaleV(22,18),
                                        2*buttonsGap+140, height-45, scaleV(22,18),
-                                       3*buttonsGap+2*140, height-45, scaleV(22,18)
                                        )
 
-       def __init__(self, session, args = 0):
+       def __init__(self, session, versionString):
+               self.versionString = versionString
                Screen.__init__(self, session)
                self.list = []
-               ConfigListScreen.__init__(self, self.list)
+               ConfigListScreen.__init__(self, self.list, session=session)
                self["buttonred"] = Label(_("cancel"))
                self["buttongreen"] = Label(_("ok"))
-               self["info"] = Label('by 3c5x9')
                self["setupActions"] = ActionMap(["SetupActions"],
                {
                        "green": self.save,
@@ -62,47 +44,107 @@ 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(_("check interval (minutes)"), config.plugins.emailimap.checkPeriod))
-                       self.list.append(getConfigListEntry(_("display timeout (seconds)"), config.plugins.emailimap.timeout))
-               self.list.append(getConfigListEntry(_("Debug"), config.plugins.emailimap.debug))
+                       getConfigListEntry(_("notify about new mails"), config.plugins.emailimap.checkForNewMails),
+                       getConfigListEntry(_("display timeout (seconds)"), config.plugins.emailimap.timeout),
+                       getConfigListEntry(_("Debug"), config.plugins.emailimap.debug),
+                       ]       
                self["config"].list = self.list
                self["config"].l.setList(self.list)
+               self.onLayoutFinish.append(self._layoutFinish)
 
-       def keyLeft(self):
-               ConfigListScreen.keyLeft(self)
-               self.createSetup()
-
-       def keyRight(self):
-               ConfigListScreen.keyRight(self)
-               self.createSetup()
+       def _layoutFinish(self):
+               self.setTitle(_("Email setup") + " (" + self.versionString + ")")
 
        def save(self):
-               print "saving"
+               debug("[EmailConfigOptions] 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()
+               for acc in mailAccounts:
+                       acc.stopChecker()
+                       if config.plugins.emailimap.checkForNewMails.value:
+                               acc.startChecker()
                initLog()
-                       
                self.close(True)
 
        def cancel(self):
-               print "cancel"
+               debug("[EmailConfigOptions] cancel")
                for x in self["config"].list:
                        x[1].cancel()
                self.close(False)
+
+class EmailConfigAccount(ConfigListScreen,Screen):
+       width = max(2*140+100, 550)
+       height = 5*30+50
+       buttonsGap = (width-2*140)/3
+       skin = """
+               <screen position="%d,%d" size="%d,%d" title="Account Setup" >
+               <widget name="config" position="0,0" size="%d,%d" scrollbarMode="showOnDemand" />
+               <ePixmap position="%d,%d" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
+               <ePixmap position="%d,%d" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
+               <widget name="buttonred" position="%d,%d" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;%d" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+               <widget name="buttongreen" position="%d,%d" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;%d" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+               </screen>""" %(
+                                       (DESKTOP_WIDTH-width)/2, (DESKTOP_HEIGHT-height)/2, width, height,
+                                       width, height-50,  # config
+                                       buttonsGap, height-45,
+                                       2*buttonsGap+140, height-45,
+                                       buttonsGap, height-45, scaleV(22,18),
+                                       2*buttonsGap+140, height-45, scaleV(22,18)
+                                       )
+
+       def __init__(self, session, params=None):
+               debug("[EmailConfigAccount] __init__")
+               self._session = session
+               Screen.__init__(self, session)
+               self.list = []
+               ConfigListScreen.__init__(self, self.list, session=session)
+               self["buttonred"] = Label(_("cancel"))
+               self["buttongreen"] = Label(_("ok"))
+               self["setupActions"] = ActionMap(["SetupActions"],
+               {
+                       "green": self.save,
+                       "red": self.cancel,
+                       "save": self.save,
+                       "cancel": self.cancel,
+                       "ok": self.save,
+               }, -2)
+               
+               if params:
+                       (self._name, self._server, self._port, self._user, self._password, self._interval, self._maxmail) = params
+               else:
+                       (self._name, self._server, self._port, self._user, self._password, self._interval, self._maxmail) = ("","","993","","","60","50")
+               self._cName = ConfigText(self._name, fixed_size=False)
+               self._cServer = ConfigText(self._server, fixed_size=False)
+               self._cPort = ConfigSelection(choices=[("143", "143"),("993", "993 (SSL)")])
+               self._cUser = ConfigText(self._user, fixed_size=False)
+               self._cPassword = ConfigPassword(self._password, fixed_size=False)
+               self._cInterval = ConfigText(self._interval, fixed_size=False)
+               self._cInterval.setUseableChars('0123456789,')
+               self._cMaxmail = ConfigText(self._maxmail, fixed_size=False)
+               self._cMaxmail.setUseableChars('0123456789,')
+               
+               self.list = [
+                                       getConfigListEntry(_("account name"), self._cName),
+                                       getConfigListEntry(_("IMAP Server"), self._cServer),
+                                       getConfigListEntry(_("IMAP Port"), self._cPort),
+                                       getConfigListEntry(_("user name"), self._cUser),
+                                       getConfigListEntry(_("password"), self._cPassword),
+                                       getConfigListEntry(_("mail check interval (minutes)"), self._cInterval),
+                                       getConfigListEntry(_("maximum mail size to fetch"), self._cMaxmail)
+                                       ]
+               self["config"].list = self.list
+               self["config"].l.setList(self.list)
+
+       def save(self):
+               debug("[EmailConfigAccount] saving")
+               # do some sanity checks
+               if not self._cName.value or not self._cServer.value or not self._cUser.value or not self._cPassword.value or not self._cInterval.value or not self._cMaxmail.value:
+                       self._session.open(MessageBox, _("empty values - retry"), type=MessageBox.TYPE_ERROR, timeout=config.plugins.emailimap.timeout.value)
+               else:
+                       self.close((self._cName.value, self._cServer.value, self._cPort.value, self._cUser.value, self._cPassword.value, self._cInterval.value, self._cMaxmail.value))
+
+       def cancel(self):
+               debug("[EmailConfigAccount] cancel")
+               self.close(None)
index fbc9f2f..778ee9f 100755 (executable)
@@ -1,5 +1,5 @@
 installdir = /usr/lib/enigma2/python/Plugins/Extensions/EmailClient
 
-install_PYTHON = __init__.py plugin.py EmailConfig.py protocol.py TagStrip.py uu.py
+install_PYTHON = *.py
 install_DATA = plugin.png LICENSE
 
index 7177386..a74b46f 100755 (executable)
@@ -1,7 +1,7 @@
 from Tools.Directories import resolveFilename, SCOPE_LANGUAGE, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
 from Components.Language import language
 from Components.config import config
-import os, gettext
+import os, gettext, time
 
 lang = language.getLanguage()
 os.environ["LANGUAGE"] = lang[:2]
@@ -25,7 +25,25 @@ def debug(message):
        if config.plugins.emailimap.debug.value:
                try:
                        deb = open("/tmp/EmailClient.log", "aw")
-                       deb.write(message + "\n")
+                       deb.write(time.ctime() + ': ' + message + "\n")
                        deb.close()
                except:
                        debug(repr(message) + " (retried debug)")
+
+from enigma import getDesktop
+DESKTOP_WIDTH = getDesktop(0).size().width()
+DESKTOP_HEIGHT = getDesktop(0).size().height()
+def scaleH(y2, y1):
+       if y2 == -1:
+               y2 = y1*1280/720
+       elif y1 == -1:
+               y1 = y2*720/1280
+       return scale(y2, y1, 1280, 720, DESKTOP_WIDTH)
+def scaleV(y2, y1):
+       if y2 == -1:
+               y2 = y1*720/576
+       elif y1 == -1:
+               y1 = y2*576/720
+       return scale(y2, y1, 720, 576, DESKTOP_HEIGHT)
+def scale(y2, y1, x2, x1, x):
+       return (y2 - y1) * (x - x1) / (x2 - x1) + y1
index b61ccb8..de21110 100755 (executable)
@@ -1,3 +1,10 @@
+# -*- coding: utf-8 -*-
+#===============================================================================
+# $Author$
+# $Revision$
+# $Date$
+# $Id$
+#==============================
 from Components.ActionMap import ActionMap
 from Components.Label import Label
 from Screens.MessageBox import MessageBox
@@ -5,66 +12,34 @@ from Components.MenuList import MenuList
 from Components.MultiContent import MultiContentEntryText
 from Components.ScrollLabel import ScrollLabel
 from Components.Button import Button
-from Components.config import config, ConfigSubsection, ConfigInteger, ConfigText, ConfigEnableDisable
-from EmailConfig import EmailConfigScreen
+from Components.config import config, ConfigSubsection, ConfigInteger, ConfigEnableDisable
 from Plugins.Plugin import PluginDescriptor
 from Screens.ChoiceBox import ChoiceBox
 from Screens.Screen import Screen
 from Tools import Notifications
-from enigma import eListboxPythonMultiContent, gFont, eTimer
+from enigma import eListboxPythonMultiContent, gFont, eTimer #@UnresolvedImport
 from twisted.mail import imap4
 from zope.interface import implements
-import email, time
+import email, re, os
 from email.header import decode_header
 from TagStrip import strip_readable
 from protocol import createFactory
 
-from . import _, initLog, debug
+from . import _, initLog, debug, scaleH, scaleV, DESKTOP_WIDTH, DESKTOP_HEIGHT #@UnresolvedImport
+mailAccounts = [] # contains all EmailAccount objects
+from EmailConfig import EmailConfigOptions, EmailConfigAccount
 
 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(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=60, limits=(0, 900)) #  in minutes
 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))
 config.plugins.emailimap.debug = ConfigEnableDisable(default=False)
 
-from enigma import getDesktop
-DESKTOP_WIDTH = getDesktop(0).size().width()
-DESKTOP_HEIGHT = getDesktop(0).size().height()
-#
-# this is pure magic.
-# It returns the first value, if HD (1280x720),
-# the second if SD (720x576),
-# else something scaled accordingly
-# if one of the parameters is -1, scale proportionally
-#
-def scaleH(y2, y1):
-       if y2 == -1:
-               y2 = y1*1280/720
-       elif y1 == -1:
-               y1 = y2*720/1280
-       return scale(y2, y1, 1280, 720, DESKTOP_WIDTH)
-def scaleV(y2, y1):
-       if y2 == -1:
-               y2 = y1*720/576
-       elif y1 == -1:
-               y1 = y2*576/720
-       return scale(y2, y1, 720, 576, DESKTOP_HEIGHT)
-def scale(y2, y1, x2, x1, x):
-       return (y2 - y1) * (x - x1) / (x2 - x1) + y1
-
 def decodeHeader(text, default=''):
        if text is None:
                return _(default)
        text = text.replace('\r',' ').replace('\n',' ').replace('\t',' ')
-       while text.find('  ') != -1:
-               text = text.replace('  ',' ')
+       text = re.sub('\s\s+', ' ', text)
        textNew = ""
        for part in decode_header(text):
                (content, charset) = part
@@ -82,14 +57,14 @@ IS_UNSEEN = 0
 IS_SEEN = 1
 IS_DELETED = 2 
 
-class EmailHandler:
-       def __init__(self):
-               pass
-       def onConnect(self, proto):
-               pass
-
-class EmailScreen(Screen, EmailHandler):
-       implements(imap4.IMailboxListener)
+class EmailScreen(Screen):
+       '''
+       This is the main screen for interacting with the user.
+       It contains the list of mailboxes (boxlist) on the left and
+       the list of messages (messagelist) on the right.
+       At the bottom we have a line for info messages.
+       It is specific for one account.
+       '''
 
        width = scaleH(-1,530)
        height = scaleV(-1,430)
@@ -108,123 +83,170 @@ class EmailScreen(Screen, EmailHandler):
                                           0, height-infolabelHeight, width, infolabelHeight, scaleV(20,18)
                                           )
 
-       currentmailbox = None
-       proto = None
-
-       def __init__(self, session, args = 0):
-               EmailHandler.__init__(self)
-               self.session = session
-
+       def __init__(self, session, account):
+               '''
+               This is the main screen for interacting with the user.
+               It contains the list of mailboxes (boxlist) on the left and
+               the list of messages (messagelist) on the right.
+               At the bottom we have a line for info messages.
+               It is specific for one account.
+       
+               @param session: session in which this screen is running
+               @param account: account for which mailboxes are shown 
+               '''
+               self._session = session
+               self._account = account
                self.skin = EmailScreen.skin
                Screen.__init__(self, session)
-               self.factory = createFactory(self, config.plugins.emailimap.username.value, config.plugins.emailimap.server.value, config.plugins.emailimap.port.value)
 
                self["actions"] = ActionMap(["InfobarChannelSelection", "WizardActions", "DirectionActions", "MenuActions", "ShortcutActions", "GlobalActions", "HelpActions", "NumberActions", "ChannelSelectBaseActions"],
                        {
-                        "ok": self.action_ok,
-                        "back": self.action_exit,
-                        "historyNext": self.selectMessagelist,
-                        "historyBack": self.selectBoxlist,
-                        "nextBouquet": self.selectMessagelist,
-                        "prevBouquet": self.selectBoxlist,
-                        "down":                self.down,
-                        "up":            self.up,
-                        "left":                self.left,
-                        "right":          self.right,
-                        "menu":                self.action_menu,
+                        "ok": self._ok,
+                        "back": self._exit,
+                        "historyNext": self._selectMessagelist,
+                        "historyBack": self._selectBoxlist,
+                        "nextBouquet": self._selectMessagelist,
+                        "prevBouquet": self._selectBoxlist,
+                        "down":                self._down,
+                        "up":            self._up,
+                        "left":                self._left,
+                        "right":          self._right,
                         }, -1)
-               self["boxlist"] = MenuList([])
-               self["messagelist"] = MailList([])
-               self["infolabel"] = Label("")
-               self.onLayoutFinish.append(self.selectBoxlist)
+               self["messagelist"] = MenuList([], content=eListboxPythonMultiContent)
+               self["messagelist"].l.setItemHeight(scaleV(70,60))
+               self["messagelist"].l.setFont(0, gFont("Regular", scaleV(20,18))) # new
+               self["messagelist"].l.setFont(1, gFont("Regular", scaleV(18,16))) # deleted
+               self["messagelist"].l.setFont(2, gFont("Regular", scaleV(18,16))) # seen
+
+               if self._account.isConnected():
+                       self["infolabel"] = Label("")
+                       self["boxlist"] = MenuList(self._account.mailboxList)
+                       self.onLayoutFinish.append(self._finishBoxlist)
+               else:
+                       self["infolabel"] = Label(_("account not connected"))
+                       self["boxlist"] = MenuList([])
 
-       def action_menu(self):
-               self.session.open(EmailConfigScreen).onHide.append(self.onBoxSelected)
+       def _exit(self):
+               self.close()
 
-       def selectBoxlist(self):
+       def _finishBoxlist(self):
+               self.setTitle(_("%(name)s (%(user)s@%(server)s)")
+                               %{
+                               'name':self._account._name,
+                               'user':self._account._user,
+                               'server':self._account._server
+                               })
+               self["boxlist"].moveToIndex(self._account.inboxPos-1)
+               self._selectBoxlist()
+               self._onBoxSelected()
+       
+       def _selectBoxlist(self):
                self.currList = "boxlist"
-               self["boxlist"].selectionEnabled(1)
                self["messagelist"].selectionEnabled(0)
+               self["boxlist"].selectionEnabled(1)
 
-       def selectMessagelist(self):
+       def _selectMessagelist(self):
                self.currList = "messagelist"
                self["boxlist"].selectionEnabled(0)
                self["messagelist"].selectionEnabled(1)
 
-       def up(self):
+       def _up(self):
                self[self.currList].up()
 
-       def down(self):
+       def _down(self):
                self[self.currList].down()
 
-       def left(self):
+       def _left(self):
                self[self.currList].pageUp()
 
-       def right(self):
+       def _right(self):
                self[self.currList].pageDown()
 
-       def action_ok(self):
+       def _ok(self):
                if self.currList == "boxlist":
-                       self.onBoxSelected()
+                       self._onBoxSelected()
+               else:
+                       self._onMessageSelected()
+
+       def _ebNotify(self, where, what):
+               '''
+               Error notification via calling back
+               @param where: location, where the error occurred
+               @param what: message, what happened
+               '''
+               debug("[EmailScreen] _ebNotify error in %s: %s" %(where, what))
+               self.session.open(MessageBox, _("EmailClient for %(account)s:\n\n%(error)s") %{'account': self._account._name, 'error':what}, type=MessageBox.TYPE_ERROR, timeout=config.plugins.emailimap.timeout.value)
+
+       def _onBoxSelected(self):
+               self["messagelist"].l.setList([])
+               self._onBoxSelectedNoClear()
+
+       def _onBoxSelectedNoClear(self):
+               self["infolabel"].setText(_("loading headers ..."))
+               if self["boxlist"].getCurrent():
+                       if self._account.getMessageList(self._onHeaderList, self["boxlist"].getCurrent()):
+                               self._selectMessagelist()
+                       else:
+                               self["infolabel"].setText(_("account not connected"))
                else:
-                       self.onMessageSelected()
+                       self["infolabel"].setText(_("no mailbox?!?!"))
+                       
 
-       def onBoxSelected(self):
-               c = self["boxlist"].getCurrent()
-               if c is not None:
-                       self.proto.select(UTF7toUTF8(c[1][2]) # select instead of examine to get write access
-                                                          ).addCallback(self.onExamine, c[0] , self.proto
-                                                         ).addErrback(self.onExamineFailed, c[0], self.proto
-                                                         )
-               # self.proto.search(imap4.Query(unseen=1)).addCallback(self.cbOk).addErrback(self.cbNotOk)
+       def _onHeaderList(self, result, flagsList):
+               '''
+               
+               @param result: list of message
+               @param flagsList: list of corresponding flags
+               '''
+               debug("[EmailScreen] onHeaderList")
+               self["infolabel"].setText(_("headers loaded, now parsing ..."))
+               self._flagsList = flagsList
+               list = []
+               for m in result:
+                       state = IS_UNSEEN
+                       # debug("onHeaderList :" + repr(flagsList[m]['FLAGS']))
+                       if '\\Seen' in flagsList[m]['FLAGS']:
+                               state = IS_SEEN
+                       if '\\Deleted' in flagsList[m]['FLAGS']:
+                               if not config.plugins.emailimap.showDeleted.value:
+                                       continue
+                               else:
+                                       state = IS_DELETED
+                       try:
+                               list.append(self._buildMessageListItem(MessageHeader(m, result[m]['RFC822.HEADER']), state))
+                       except Exception,e:
+                               try:
+                                       list.append(self._buildMessageListItem(MessageHeader(m, result[m]['RFC822.HEADER'].decode('iso8859-1', 'replace'), state)))
+                               except:
+                                       # this appear to be errors in the formatting of the mail itself...
+                                       debug("[EmailScreen] onHeaderList error: %s (%s)" %(result[m]['RFC822.HEADER'], str(e)))
+               if list:
+                       list.reverse()
+                       self["messagelist"].l.setList(list)
+                       self["infolabel"].setText(_("have %d messages") %(len(list)))
+               else:
+                       self["messagelist"].l.setList([])
+                       self["infolabel"].setText(_("have no messages"))
+                       # self.onBoxSelected() # brings us into endless loop, when still deleted messages are in there...
+                       self._selectBoxlist()
 
-       def onMessageSelected(self):
+       def _onMessageSelected(self):
+               self["infolabel"].setText(_("getting message ..."))
                c = self["messagelist"].getCurrent()
                if c is not None:
-                       self.fetchMessageSize(c[0])
+                       if not self._account.getMessage(c[0], self._onMessageLoaded, self._ebNotify):
+                               self["infolabel"] = Label(_("account not connected"))
 
-       def fetchMessageSize(self, message):
-               debug("[EmailScreen] fetchMessageSize: " + str(message))
-               self.proto.fetchSize(message.uid
-                       ).addCallback(self.onMessageSizeLoaded, message, self.proto
-                       ).addErrback(self.onMessageLoadFailed, message, self.proto
-                       )
-
-       def onMessageSizeLoaded(self, result, message, proto):
-               debug("[EmailScreen] onMessageSizeLoaded: " + str(result) + ' ' + str(message))
-               size = int(result[message.uid]['RFC822.SIZE'])
-               self.MAX_MESSAGE_SIZE_TO_OPEN = 4000000
-               if size >= self.MAX_MESSAGE_SIZE_TO_OPEN:
-                       #ask here to open message
-                       debug("message to large to open (size=%d" %size)
-               else:
-                       self.loadMessage(message)
-
-#      def fetchBodyStructure(self, message):
-#              print "fetchBodyStructure",message
-#              self.proto.fetchBodyStructure(message.uid
-#                      ).addCallback(self.onBodystructureLoaded, message, self.proto
-#                      ).addErrback(self.onMessageLoadFailed, message, self.proto
-#                      )
-
-       def loadMessage(self, message):
-               debug("[EmailScreen] loadMessage: " + str(message))
-               self["infolabel"].setText(_("loading message"))
-
-               self.proto.fetchMessage(message.uid
-                       ).addCallback(self.onMessageLoaded, message, self.proto
-                       ).addErrback(self.onMessageLoadFailed, message, self.proto
-                       )
-
-       def onMessageLoaded(self, result, message, proto):
-               self["infolabel"].setText(_("parsing message"))
+       def _onMessageLoaded(self, result, message):
+               self["infolabel"].setText(_("parsing message ..."))
                debug("[EmailScreen] onMessageLoaded") #,result,message
                try:
                        msgstr = result[message.uid]['RFC822']
                except KeyError:
-                       self.loadMessage(message)
+                       self._account.getMessage(message, self._onMessageLoaded, self._ebNotify)
+                       # self.loadMessage(message)
                        return
-               msg = email.Parser.Parser().parsestr(msgstr)
+               msg = email.Parser.Parser().parsestr(msgstr) #@UndefinedVariable
                msg.messagebodys = []
                msg.attachments = []
 
@@ -238,190 +260,22 @@ class EmailScreen(Screen, EmailHandler):
                                        elif part.get_content_subtype() == "plain":
                                                msg.messagebodys.append(EmailBody(part))
                                        else:
-                                               debug("[EmailScreen] unkown content type= " + part.get_content_maintype() + "/", part.get_content_subtype())
+                                               debug("[EmailScreen] onMessageLoaded: unknown content type=%s/%s" %(str(part.get_content_maintype()), str(part.get_content_subtype())))
                                else:
-                                       debug("[EmailScreen] found Attachment with  " + part.get_content_type() + " and name " + part.get_filename())
+                                       debug("[EmailScreen] onMessageLoaded: found Attachment with  %s and name %s" %(str(part.get_content_type()), str(part.get_filename())))
                                        msg.attachments.append(EmailAttachment(part.get_filename(), part.get_content_type(), part.get_payload()))
                else:
                        msg.messagebodys.append(EmailBody(msg))
-               self.session.open(ScreenMailView, msg, message.uid, proto, self.flagsList[message.uid]['FLAGS']).onHide.append(self.onBoxSelected)
-
-       def onMessageLoadFailed(self, failure, message, proto):
-               debug("[EmailScreen] onMessageLoadFailed: " + str(failure) + ' ' + str(message))
-               self["infolabel"].setText(_("failed to load message") + ': ' + failure.getErrorMessage())
-
-       def action_exit(self):
-               global mailChecker
-               if not mailChecker and self.proto is not None:
-                       self.proto.logout().addCallback(self.onLogedOut, self.proto).addErrback(self.onLogedOut, self.proto)
-               else:
-                       self.factory.stopFactory()
-                       self.close()
-
-       def onLogedOut(self, result, proto):
-               debug("[EmailScreen] onLogedOut: " + str(result))
-               self.factory.stopFactory()()
-               self.close()
-
-       def onConnect(self, proto):
-               self["infolabel"].setText(_("connected"))
-               proto.getCapabilities(
-                                               ).addCallback(self.cbCapabilities, proto
-                                               ).addErrback(self.ebCapabilities, proto
-                                               )
-               self.factory.resetDelay()
-
-       def cbCapabilities(self,reason,proto):
-               debug("[EmailScreen] \n\
-####################################################################################################\n\
-# If you have problems to log into your imap-server, please send me the output of the following line\n\
-# cbCapabilities: " + str(reason) +"\n\
-####################################################################################################\n")
-               self.doLogin(proto)
-
-       def ebCapabilities(self,reason,proto):
-               debug("[EmailScreen] ebCapabilities: " + str(reason))
-
-       def onConnectFailed(self, reason):
-               debug("[EmailScreen] onConnectFailed: " + reason.getErrorMessage())
-               if self.has_key('infolabel'):
-                       self["infolabel"].setText(_("connection to %(server)s:%(port)d failed") %{'server':config.plugins.emailimap.server.value,'port':config.plugins.emailimap.port.value}) # + ': ' + reason.getErrorMessage()) # the messages provided by twisted are crap here
-               self.action_exit()
-
-       def onAuthentication(self, result, proto):
-               self.proto = proto
-               self["infolabel"].setText(_("logged in"))
-               # better use LSUB here to get only the subscribed to mailboxes
-               proto.lsub("", "*").addCallback(self.onMailboxList, proto)
-
-       def doLogin(self, proto):
-               debug("[EmailScreen] login secure")
-               useTLS = False #True
-               if useTLS:
-                       context = proto.context.getContext()
-                       d = proto.startTLS(context)
-                       d = d.addCallback(proto.authenticate, config.plugins.emailimap.password.value)
-               else:
-                       d = proto.authenticate(config.plugins.emailimap.password.value)
-               d.addCallback(self.onAuthentication, proto)
-               d.addErrback(self.onAuthenticationFailed, proto)
-               return d
-
-       def onAuthenticationFailed(self, failure, proto):
-               # If it failed because no SASL mechanisms match
-               debug("[EmailScreen] onAuthenticationFailed: " + failure.getErrorMessage())
-               self["infolabel"].setText(_("encrypted login failed, trying without encryption"))
-               try:
-                       failure.trap(imap4.NoSupportedAuthentication)
-                       self.doLoginInsecure(proto)
-               except Exception,e:
-                       print e,e.message
-
-       def doLoginInsecure(self, proto):
-               debug("[EmailScreen] login INSECURE")
-               proto.login(config.plugins.emailimap.username.value, config.plugins.emailimap.password.value
-                               ).addCallback(self.onAuthentication, proto
-                               ).addErrback(self.onInsecureAuthenticationFailed, proto
-                               )
-
-       def onInsecureAuthenticationFailed(self, failure, proto):
-               debug("[EmailScreen] onInsecureAuthenticationFailed: " + failure.getErrorMessage())
-               self["infolabel"].setText(_("login failed") + ': ' + failure.getErrorMessage())
-
-       def onMailboxList(self, result, proto):
-               debug("[EmailScreen] onMailboxList: " + str(result) + ' ' + str(proto))
-               list = []
-               inboxPos = 0
-               for i in result:
-                       flags, hierarchy_delimiter, name = i #@UnusedVariable
-                       list.append((UTF7toUTF8(name).encode('utf-8'), i))
-                       if name.lower() == 'inbox':
-                               inboxPos = len(list)
-               self["boxlist"].setList(list)
-               self["boxlist"].moveToIndex(inboxPos-1)
-
-       def onExamine(self, result, mboxname, proto):
-               debug("[EmailScreen] onExamine: " + str(result) + ' ' + mboxname)
-               self.setTitle(_("Mailbox")+": "+mboxname)
-               self.currentmailbox = mboxname
-               numMessagesinFolder = int(result['EXISTS'])
-               if numMessagesinFolder <= 0:
-                       self["infolabel"].setText(_("Box '%s' is empty") %(mboxname))
-                       self["messagelist"].l.setList([])
-
-               else:
-                       if config.plugins.emailimap.maxheadertoload.value > 0:
-                               maxMessagesToFetch = config.plugins.emailimap.maxheadertoload.value
-                               startmsg = numMessagesinFolder-maxMessagesToFetch+1
-                               if startmsg <= 0:
-                                       startmsg = 1
-                               rangeToFetch = [startmsg, numMessagesinFolder]
-                       else:
-                               rangeToFetch = [1, numMessagesinFolder]
-                       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:*'
-#                                                 ).addCallback(self.onnvelopeList, proto
-#                                                 )
-                               self.proto = proto
-                               self.rangeToFetch = rangeToFetch
-                               proto.fetchFlags('%i:%i'%(rangeToFetch[0], rangeToFetch[1])     #'1:*'
-                                                  ).addCallback(self.onFlagsList)
-
-                       except imap4.IllegalServerResponse, e:
-                               debug("[EmailScreen] onExamine exception: " + str(e))
-                       self.selectMessagelist()
-
-       def onFlagsList(self, result):
-               self.flagsList = result
-               self.proto.fetchHeaders('%i:%i'%(self.rangeToFetch[0], self.rangeToFetch[1])    #'1:*'
-                                  ).addCallback(self.onHeaderList, self.proto
-                                  )
-
-       def onExamineFailed(self, failure, mboxname, proto):
-               debug("[EmailScreen] onExamineFailed: " + mboxname + ' ' + str(failure) + ' ' + str(proto))
-               self["infolabel"].setText(_("cannot access mailbox '%(mboxname)s'") % {'mboxname':mboxname})
-
-       def cbOk(self, result):
-               debug("[EmailScreen] cbOk result: %s" %repr(result))
-
-       def cbNotOk(self, result):
-               debug("[EmailScreen] cbNotOk result: %s" %(str(result)))
-
-       def onHeaderList(self, result, proto):
-               debug("[EmailScreen] onHeaderList") #,result,proto
-               self["infolabel"].setText(_("headers loaded, now parsing ..."))
-               list = []
-               for m in result:
-                       state = IS_UNSEEN
-                       # debug("onHeaderList :" + repr(self.flagsList[m]['FLAGS']))
-                       if '\\Seen' in self.flagsList[m]['FLAGS']:
-                               state = IS_SEEN
-                       if '\\Deleted' in self.flagsList[m]['FLAGS']:
-                               if not config.plugins.emailimap.showDeleted.value:
-                                       continue
-                               else:
-                                       state = IS_DELETED
-                       try:
-                               list.append(self.buildMessageListItem(MessageHeader(m, result[m]['RFC822.HEADER']), state))
-                       except Exception,e:
-                               try:
-                                       list.append(self.buildMessageListItem(MessageHeader(m, result[m]['RFC822.HEADER'].decode('iso8859-1', 'replace'), state)))
-                               except:
-                                       # this appear to be errors in the formatting of the mail itself...
-                                       debug("[EmailScreen] onHeaderList error: %s (%s)" %(result[m]['RFC822.HEADER'], str(e)))
-               if list:
-                       list.reverse()
-                       self["messagelist"].l.setList(list)
-                       self["infolabel"].setText(_("have %d messages") %(len(list)))
-               else:
-                       self["messagelist"].l.setList([])
-                       self["infolabel"].setText(_("have no messages"))
-                       # self.onBoxSelected() # brings us into endless loop, when still deleted messages are in there...
-                       self.selectBoxlist()
-
-       def buildMessageListItem(self, message, state):
+               debug("[EmailScreen] onMessageLoaded:" + str(message.uid) +';'+ repr(self._flagsList[message.uid]['FLAGS']))
+               self.session.open(ScreenMailView, self._account, msg, message.uid, self._flagsList[message.uid]['FLAGS']).onHide.append(self._onBoxSelectedNoClear)
+               self["infolabel"].setText("")
+
+       def _buildMessageListItem(self, message, state):
+               '''
+               Construct a MultiContentEntryText from parameters
+               @param message: message
+               @param state: IS_UNSEEN (grey), IS_DELETED (red) are especially colored
+               '''
                if state == IS_UNSEEN:
                        font = 0
                        color = 0x00FFFFFF # white
@@ -437,23 +291,21 @@ class EmailScreen(Screen, EmailHandler):
                        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)
                ]
-       #
-       # IMailboxListener methods
-       #
-       def modeChanged(self, writeable):
-               debug("[EmailScreen] modeChanged: " + str(writeable))
-
-       def flagsChanged(self, newFlags):
-               debug("[EmailScreen] flagsChanged: " + str(newFlags))
-
-       def newMessages(self, exists, recent):
-               debug("[EmailScreen] newMessages: " + str(exists) + ' ' +  str(recent))
 
 class ScreenMailView(Screen):
        skin=""
-       def __init__(self, session, email, uid, proto, flags):
-               self.session = session
-               self.email = email
+       def __init__(self, session, account, email, uid, flags):
+               '''
+               Principal screen to show one mail message.
+               @param session:
+               @param account: mail acoount, this message is coming from 
+               @param email: the message itself
+               @param uid: uid of the message, needed to (un)delete and unmark
+               @param flags: the flags of the message, needed to check, whether IS_DELETED
+               '''
+               self._session = session
+               self._email = email
+               self._account = account
                # debug('ScreenMailView ' + repr(email) + ' dir: ' + repr(dir(email)))
                width = max(4*140,scaleH(-1,550))
                height = scaleV(-1,476)
@@ -492,11 +344,10 @@ 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["date"] = Label(_("Date") +": %s" %self.email.get('date', 'no-date'))
-               self["subject"] = Label(decodeHeader(_("Subject") +": %s" %self.email.get('subject', _('no subject'))))
-               self["body"] = ScrollLabel(_(self.email.messagebodys[0].getData()))
-               # TODO: show headers
+               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["body"] = ScrollLabel(_(self._email.messagebodys[0].getData()))
                self["buttonred"] = Button("")
                self["buttongreen"] = Button("")
                self["buttonyellow"] = Button(_("leave unread"))
@@ -512,108 +363,78 @@ class ScreenMailView(Screen):
                         # TODO: perhaps better use left/right for previous/next message
                         "left": self["body"].pageUp,
                         "right": self["body"].pageDown,
-                        "red": self.selectBody,
-                        "green": self.selectAttachment,
-                        "yellow": self.markUnread,
-                        "blue": self.delete,
+                        "red": self._selectBody,
+                        "green": self._selectAttachment,
+                        "yellow": self._markUnread,
+                        "blue": self._delete,
 
                         }, -1)
-               self.flags = flags
-               self.proto = proto
-               self.uid = uid
-               proto.fetchFlags(self.uid).addCallback(self.cbOk).addErrback(self.cbNotOk)
-               self.onLayoutFinish.append(self.updateButtons)
+               self._uid = uid
+               self._flags = flags
+               self.onLayoutFinish.append(self._updateButtons)
 
-       def cbOk(self, result):
-               debug("[ScreenMailView] cbOk result: %s" %repr(result))
-
-       def cbNotOk(self, result):
-               debug("[ScreenMailView] cbNotOk result: %s" %(str(result)))
-
-       def delete(self):
-               if '\\Deleted' in self.flags:
-                       self.session.openWithCallback(self.deleteCB, ChoiceBox, title=_("really undelete Mail?"), list=[(_("yes"), True),(_("no"), False)])
+       def _delete(self):
+               if '\\Deleted' in self._flags:
+                       self.session.openWithCallback(self._deleteCB, MessageBox, _("really undelete mail?"), type=MessageBox.TYPE_YESNO, timeout=config.plugins.emailimap.timeout.value)
                else:
-                       self.session.openWithCallback(self.deleteCB, ChoiceBox, title=_("really delete Mail?"), list=[(_("yes"), True),(_("no"), False)])
+                       self.session.openWithCallback(self._deleteCB, MessageBox, _("really delete mail?"), type=MessageBox.TYPE_YESNO, timeout=config.plugins.emailimap.timeout.value)
 
-       def deleteCB(self, returnValue):
-               if returnValue and returnValue[1] is True:
-                       if '\\Deleted' in self.flags:
-                               self.proto.removeFlags(self.uid, ["\\Deleted"]).addCallback(self.cbOk).addErrback(self.cbNotOk)
+       def _deleteCB(self, returnValue):
+               if returnValue:
+                       if '\\Deleted' in self._flags:
+                               if not self._account.undelete(self._uid):
+                                       self.session.open(MessageBox, _("account not connected"), type=MessageBox.TYPE_INFO, timeout=config.plugins.emailimap.timeout.value)
                        else:
-                               self.proto.addFlags(self.uid, ["\\Deleted"]).addCallback(self.cbOk).addErrback(self.cbNotOk)
-                       debug("[ScreenMailView] deleteCB: %s"  %repr(self.email))
+                               if not self._account.delete(self._uid):
+                                       self.session.open(MessageBox, _("account not connected"), type=MessageBox.TYPE_INFO, timeout=config.plugins.emailimap.timeout.value)
+                       debug("[ScreenMailView] deleteCB: %s"  %repr(self._email))
                        self.close()
 
-       def markUnread(self):
-               self.proto.removeFlags(self.uid, ["\\Seen"]).addCallback(self.cbOk).addErrback(self.cbNotOk)
+       def _markUnread(self):
+               if not self._account.unread(self._uid):
+                       self.session.open(MessageBox, _("account not connected"), type=MessageBox.TYPE_INFO, timeout=config.plugins.emailimap.timeout.value)
                self.close()
 
-       def openMessagesHeaders(self):
-               pass #self.session.open(ScreenMailViewHeader,self.profil,self.email)
-
-       def updateButtons(self):
-               self["buttonred"].setText(_("Bodys"))
-               if len(self.email.attachments):
+       def _updateButtons(self):
+               if len(self._email.messagebodys):
+                       self["buttonred"].setText(_("Bodys"))
+               else:
+                       self["buttonred"].setText("")
+               if len(self._email.attachments):
                        self["buttongreen"].setText(_("Attachments"))
                else:
                        self["buttongreen"].setText("")
 
-       def selectBody(self):
-               if len(self.email.messagebodys):
+       def _selectBody(self):
+               if len(self._email.messagebodys):
                        list = []
-                       for a in self.email.messagebodys:
+                       for a in self._email.messagebodys:
                                list.append((a.getContenttype(), a))
-                       self.session.openWithCallback(self.selectBodyCB, ChoiceBox, _("select Body"), list)
+                       self.session.openWithCallback(self._selectBodyCB, ChoiceBox, _("select Body"), list)
 
-       def selectBodyCB(self, choice):
+       def _selectBodyCB(self, choice):
                if choice is not None:
                        self["body"].setText(choice[1].getData())
 
-       def selectAttachment(self):
-               if len(self.email.attachments):
+       def _selectAttachment(self):
+               if len(self._email.attachments):
                        list = []
-                       for a in self.email.attachments:
+                       for a in self._email.attachments:
                                name = a.getFilename()
                                if name:
                                        list.append((a.getFilename(), a))
                                else:
                                        list.append((_("no filename"), a))
                        debug("[ScreenMailView] selectAttachment : " + repr(list))
-                       self.session.openWithCallback(self.selectAttachmentCB, ChoiceBox, _("select Attachment"), list)
-
-       def selectAttachmentCB(self, choice):
-               if choice is not None:
-                       debug("[ScreenMailView] Attachment selected: " + choice[1].getFilename())
-                       #showMessageBox(self.session)
-
-class MailList(MenuList):
-       def __init__(self, list, enableWrapAround = False):
-               MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
-               self.l.setFont(0, gFont("Regular", scaleV(20,18))) # new
-               self.l.setFont(1, gFont("Regular", scaleV(18,16))) # deleted
-               self.l.setFont(2, gFont("Regular", scaleV(18,16))) # seen
-
-       def postWidgetCreate(self, instance):
-               MenuList.postWidgetCreate(self, instance)
-               instance.setItemHeight(scaleV(70,60))
-
-class MessageHeader(object):
-       def __init__(self, uid, message):
-               self.uid = uid #must be int
-               self.message = email.Parser.Parser().parsestr(message)
-
-       def getSenderString(self):
-               return decodeHeader(self.get("from"), _("no sender"))
-
-       def getSubject(self):
-               return decodeHeader(self.get("subject"), _("no subject"))
+                       self.session.openWithCallback(self._selectAttachmentCB, ChoiceBox, _("select Attachment"), list)
 
-       def get(self, key, default=None):
-               return self.message.get(key,failobj=default)
-
-       def __str__(self):
-               return "<MessageHeader uid="+str(self.uid)+", subject="+self.get("subject",_("no subject"))+">"
+       def _selectAttachmentCB(self, choice):
+               if choice:
+                       if choice[1].getFilename():
+                               debug("[ScreenMailView] Attachment selected: " + choice[1].getFilename())
+                       else:
+                               debug("[ScreenMailView] Attachment with no filename selected")
+                       # nothing happens here. What shall we do now with the attachment?
 
 ############
 class EmailBody:
@@ -681,138 +502,601 @@ def UTF7toUTF8(str):
 def UTF8toUTF7(str):
        return imap4.encoder(str.decode('utf-8'))[0]
 
-def main(session, **kwargs):
-       import os,shutil
-       if os.path.isfile('/usr/lib/python2.5/uu.py') is not True:
-               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)
-       else:
-               session.open(EmailScreen)
-
-def MessageCB(*args):
-       global session2
-       session2.open(EmailScreen)
 
 class CheckMail:
-       implements(imap4.IMailboxListener)
-       _timer = None
-
-       def __init__(self):
-               debug('[CheckMail] __init__ on %s' %time.ctime())
-               self.factory = createFactory(self, config.plugins.emailimap.username.value, config.plugins.emailimap.server.value, config.plugins.emailimap.port.value)
-               if not self._timer:
-                       debug('[CheckMail] __init__ creatings timer: %s' %time.ctime())
-                       self._timer = eTimer()
-                       # self._timer.timeout.get().append(self._checkMail)
-                       self._timer.callback.append(self._checkMail)
-                       self._timer.start(config.plugins.emailimap.checkPeriod.value*60*1000) # it is minutes
+       def __init__(self, acc):
+               '''
+               Mail checker object for one account
+               @param acc: the account to be checked periodically, each account has
+                                       at most one checker
+               @type acc: EmailAccount
+               '''
+               import random
+               self._name = acc._name
+               self._account = acc
+               self._timer = eTimer()
+               self._timer.callback.append(self._checkMail)
+               # I guess, users tend to use identical intervals, so make them a bit different :-)
+               # constant stolen from ReconnectingFactory
+               self._interval = int(self._account._interval)*60*1000
+               self._interval = int(random.normalvariate(self._interval, self._interval * 0.11962656472))
+               debug("[CheckMail] %(name)s: __init__: checking all %(interval)s seconds"
+                       %{'name':self._name, 'interval':self._interval/1000})
+               self._timer.start(self._interval) # it is minutes
                self._unseenList = None
-               self._proto = None
+               self._checkMail()
 
        def exit(self):
-               if self._proto:
-                       self._proto.logout()
-                       self._proto = None
+               debug("[CheckMail] %s: exit" %(self._name))
                self._timer.stop()
-               self.factory.stopFactory()
 
-       def _checkMail(self):
-               debug('[CheckMail] _checkMail on %s' %time.ctime())
-               if self._proto:
-                       self._proto.search(imap4.Query(unseen=1)).addCallback(self._cbNotify).addErrback(self._ebNotify, _("cannot get list of new messages"))
-               else:
-                       self.factory.retry()
+       def stopChecking(self):
+               '''
+               Just stop the timer, don't empty the unseenList.
+               '''
+               debug("[CheckMail] %s: stopChecking" %(self._name))
+               self._timer.stop()
 
-       def _cbNotify(self, newUnseenList):
-               def haveNotSeenBefore(messageNo): return messageNo not in self._unseenList
+       def reStartChecking(self):
+               '''
+               Start the timer again and immediately do a check.
+               '''
+               debug("[CheckMail] %s: reStartChecking" %(self._name))
+               self._timer.start(self._interval)
+               self._checkMail()
 
-               debug("[CheckMail] _cbNotify newUnseenList: %s" %repr(newUnseenList))
+       def _checkMail(self):
+               # debug("[CheckMail] _checkMail for %s" %self._name)
+               self._account.getUnseenHeaders(self._filterNewUnseen)
+
+       def _filterNewUnseen(self, newUnseenList):
+               '''
+               Main method in this class: get the list of unseen messages
+               and check them against the last list. New unseen messages
+               are then displayed via _onHeaderList
+               @param newUnseenList: new list of unseen messages
+               '''
+               debug('[CheckMail] %s: _filterNewUnseen: %s' %(self._name, 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)
+                       debug('[CheckMail] %s: _filterNewUnseen: init' %(self._name))
+                       # Notifications.AddNotification(MessageBox, str(len(newUnseenList)) + ' ' + _("unread messages in mailbox %s") %self._name, type=MessageBox.TYPE_INFO, timeout=config.plugins.emailimap.timeout.value)
                else:
-                       newMessages = filter(haveNotSeenBefore, newUnseenList)
+                       newMessages = filter(lambda x: x not in self._unseenList, newUnseenList)
                        if newMessages:
-                               debug("[CheckMail] _cbNotify newMessages: %s" %repr(newMessages))
+                               debug("[CheckMail] %s: _filterNewUnseen: new message(s): %s" %(self._name, repr(newMessages)))
+                               # construct MessageSet from list of message numbers
+                               # newMessageSet = reduce(lambda x,y: y.add(x), newMessages, imap4.MessageSet())
                                newMessageSet = imap4.MessageSet()
-                               for messageNo in newMessages:
-                                       newMessageSet.add(messageNo)
-                               self._proto.fetchHeaders(newMessageSet).addCallback(self._onHeaderList).addErrback(self._ebNotify, _("cannot get headers of new messages"))
+                               for i in newMessages:
+                                       newMessageSet.add(i)
+                               if not self._account.getHeaders(self._onHeaderList, newMessageSet):
+                                       debug("[CheckMail] %s: _filterNewUnseen: could not get Headers" %(self._name))
+
                self._unseenList = newUnseenList
 
        def _onHeaderList(self, headers):
-               # debug("_onHeaderList headers: %s" %repr(headers))
-               message = _("New mail arrived:\n\n")
+               '''
+               Notify about the list of headers.
+               @param headers: list of headers
+               '''
+               # debug("[CheckMail] _onHeaderList headers: %s" %repr(headers))
+               message = _("New mail arrived for account %s:\n\n") %self._name
                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)
 
+class MessageHeader(object):
+       def __init__(self, uid, message):
+               self.uid = uid #must be int
+               self.message = email.Parser.Parser().parsestr(message) #@UndefinedVariable
+
+       def getSenderString(self):
+               return decodeHeader(self.get("from"), _("no sender"))
+
+       def getSubject(self):
+               return decodeHeader(self.get("subject"), _("no subject"))
+
+       def get(self, key, default=None):
+               return self.message.get(key,failobj=default)
+
+       def __str__(self):
+               return "<MessageHeader uid="+str(self.uid)+", subject="+self.getSubject()+">"
+
+class EmailAccount():
+       '''
+       Principal class to hold an account.
+       '''
+       implements(imap4.IMailboxListener)
+
+       def __init__(self, params, afterInit=None):
+               '''
+               Principal class to hold an account.
+               @param params: (name, server, port, user, password, interval, maxmail)
+               @param afterInit: to be called, when init is done. Needed to writeAccounts AFTER this one is added
+               '''
+               (self._name, self._server, self._port, self._user, self._password, self._interval, self._maxmail) = params
+               # debug("[EmailAccount] %s: __init__: %s" %(self._name, repr(params)))
+               self._factory = createFactory(self, self._user, self._server, int(self._port))
+               self._proto = None
+               self._mailChecker = None
+               self.inboxPos = 0
+               self.mailboxList = None
+               self._failureReason = ""
+               self._connectCallback = None 
+               mailAccounts.append(self)
+               if afterInit:
+                       afterInit()
+
+       def exit(self):
+               mailAccounts.remove(self)
+               # stop checker and get rid of it
+               self.stopChecker()
+               self._mailChecker = None
+               # stop factory and get rid of it
+               if self._factory:
+                       self._factory.stopTrying()
+               self._factory = None # I am not sure to stop the factory, though...
+               # if we still have a proto, logout and dump it
+               if self._proto:
+                       self._proto.logout()
+               self._proto = None
+
+       def isConnected(self):
+               return self._proto is not None and self.mailboxList is not None
+
+       def forceRetry(self, connectCallback):
+               '''
+               reset delays and retry
+               @param connectCallback: call this function on successful connect, used by EmailAccountList
+               '''
+               self._connectCallback = connectCallback 
+               self._factory.resetDelay()
+               self._factory.retry()
+
+       def removeCallback(self):
+               self._connectCallback = None 
+
+       def getConfig(self):
+               return (self._name, self._server, self._port, self._user, self._password, self._interval, self._maxmail)
+
        def _ebNotify(self, result, where, what):
-               debug("[CheckMail] _ebNotify error in %s: %s: %s" %(where, what, result.getErrorMessage()))
-               Notifications.AddNotification(MessageBox, "EmailClient:\n\n" + what, type=MessageBox.TYPE_ERROR, timeout=config.plugins.emailimap.timeout.value)
-               # self.exit()
+               debug("[EmailAccount] %s: _ebNotify error in %s: %s: %s" %(self._name, where, what, result.getErrorMessage()))
+               Notifications.AddNotification(MessageBox, "EmailClient for %(account)s:\n\n%(error)s" %{'account': self._name, 'error':what}, type=MessageBox.TYPE_ERROR, timeout=config.plugins.emailimap.timeout.value)
+
+       def startChecker(self):
+               # debug("[EmailAccount] %s: startChecker?" %self._name)
+               if config.plugins.emailimap.checkForNewMails.value:
+                       # interval == 0 means: no checking for this account
+                       if int(self._interval) != 0:
+                               if self._mailChecker:
+                                       # so, we already have seen an unseenList
+                                       # debug("[EmailAccount] %s: startChecker again" %self._name)
+                                       self._mailChecker.reStartChecking()
+                               else:
+                                       # debug("[EmailAccount] %s: startChecker new" %self._name)
+                                       self._mailChecker = CheckMail(self)
+
+       def stopChecker(self):
+               if self._mailChecker:
+                       self._mailChecker.stopChecking()
+
+       def undelete(self, uid):
+               '''
+               undelete a message
+               @param uid: uid of message
+               '''
+               if self._proto:
+                       self._proto.removeFlags(uid, ["\\Deleted"])
+                       return True
+               else:
+                       return False
+
+       def delete(self, uid):
+               '''
+               mark message as deleted 
+               @param uid: uid of message
+               '''
+               if self._proto:
+                       self._proto.addFlags(uid, ["\\Deleted"])
+                       return True
+               else:
+                       return False
+
+       def unread(self, uid):
+               '''
+               mark message as unread, remove \\Seen
+               @param uid: uis of message
+               '''
+               if self._proto:
+                       self._proto.removeFlags(uid, ["\\Seen"])
+                       return True
+               else:
+                       return False
+
+       def getUnseenHeaders(self, callback):
+               # debug('[EmailAccount] %s: getUnseenHeaders' %self._name)
+               if self._proto:
+                       self._proto.examine('inbox').addCallback(self._doSearchUnseen, callback).addErrback(self._ebNotify, "getUnseenHeaders", _("cannot access inbox"))
+                       return True
+               else:
+                       return False
+
+       def _doSearchUnseen(self, result, callback): #@UnusedVariable
+               # debug('[EmailAccount] %s: _doSearchUnseen' %(self._name))
+               self._proto.search(imap4.Query(unseen=1)).addCallback(callback).addErrback(self._ebNotify, '_doSearchUnseen', _("cannot get list of new messages"))
+
+       def getMessageList(self, callback, mbox):
+               if self._proto:
+                       self._proto.select(mbox.decode('utf-8')).addCallback(self._onSelect, callback, mbox).addErrback(self._onSelectFailed, callback, mbox)
+                       return True
+               else:
+                       return False
+
+       def _onSelect(self, result, callback, mboxname):
+               # debug("[EmailAccount] _onExamine: " + str(result) + ' ' + mboxname)
+               numMessagesinFolder = int(result['EXISTS'])
+               if numMessagesinFolder <= 0:
+                       callback([], [])
+               else:
+                       if int(self._maxmail) > 0:
+                               maxMessagesToFetch = int(self._maxmail)
+                               startmsg = numMessagesinFolder-maxMessagesToFetch+1
+                               if startmsg <= 0:
+                                       startmsg = 1
+                               rangeToFetch = [startmsg, numMessagesinFolder]
+                       else:
+                               rangeToFetch = [1, numMessagesinFolder]
+                       try:
+                               self._rangeToFetch = rangeToFetch
+                               self._proto.fetchFlags('%i:%i'%(rangeToFetch[0], rangeToFetch[1])       #'1:*'
+                                                  ).addCallback(self._onFlagsList, callback)
+
+                       except imap4.IllegalServerResponse, e:
+                               debug("[EmailAccount] _onExamine exception: " + str(e))
+                               callback([], [])
+
+       def _onSelectFailed(self, failure, callback, mboxname):
+               debug("[EmailAccount] %s: _onSelectFailed: %s %s" %(self._name, mboxname, str(failure)))
+               callback([], [])
+
+       def _onFlagsList(self, flagsList, callback):
+               self._proto.fetchHeaders('%i:%i'%(self._rangeToFetch[0], self._rangeToFetch[1]) #'1:*'
+                                  ).addCallback(callback, flagsList)
+
+       def getMessage(self, message, callback, errCallback):
+               debug("[EmailAccount] %s: getMessage: %s" %(self._name, str(message)))
+               if self._proto:
+                       self._proto.fetchSize(message.uid
+                               ).addCallback(self._onMessageSizeLoaded, message, callback, errCallback 
+                               ).addErrback(self._onMessageLoadFailed, message, callback, errCallback
+                               )
+                       return True
+               else:
+                       return False
 
-       def _cbOk(self, result):
-               debug("[CheckMail] _cbOk result: %s" %repr(result))
+       def _onMessageSizeLoaded(self, result, message, callback, errCallback):
+               debug("[EmailAccount] %s: _onMessageSizeLoaded: %s %s" %(self._name, str(result), str(message)))
+               size = int(result[message.uid]['RFC822.SIZE'])
+               self.MAX_MESSAGE_SIZE_TO_OPEN = 4000000
+               if size >= self.MAX_MESSAGE_SIZE_TO_OPEN:
+                       #ask here to open message
+                       debug("[EmailAccount] _onMessageSizeLoaded: message to large to open (size=%d)" %size)
+                       errCallback('', _("message too large"))
+               else:
+                       self._proto.fetchMessage(message.uid
+                               ).addCallback(callback, message,
+                               ).addErrback(self._onMessageLoadFailed, message, callback, errCallback
+                               )
+
+       def _onMessageLoadFailed(self, failure, message, callback, errCallback):
+               debug("[EmailAccount] %s: onMessageLoadFailed: %s %s" %(self._name, str(failure), str(message)))
+               errCallback('', _("failed to load message") + ': ' + failure.getErrorMessage())
+
+       def getHeaders(self, callback, messageSet):
+               debug('[EmailAccount] %s: getHeaders' %self._name)
+               if self._proto:
+                       self._proto.fetchHeaders(messageSet).addCallback(callback).addErrback(self._ebNotify, 'getHeaders', _("cannot get headers of new messages"))
+                       return True
+               else:
+                       return False
 
        def onConnect(self, proto):
-               debug('[CheckMail] onConnect ' + str(proto))
+               debug("[EmailAccount] %s: %s@%s:%s: onConnect" %(self._name, self._user, self._server, self._port))
+               self._factory.resetDelay()
                self._proto = proto
-               proto.getCapabilities().addCallback(self._cbCapabilities).addErrback(self._ebNotify, "getCapabilities", _("cannot get capabilities of mailserver"))
+               self._failureReason = ""
+               try:
+                       self._connectCallback()
+               except:
+                       pass # for the unlikely case, the screen does not exist anymore
+               self._connectCallback = None
+               proto.getCapabilities().addCallback(self._cbCapabilities).addErrback(self._ebCapabilities)
+
+       def onConnectionFailed(self, reason):
+               debug("[EmailAccount] %s@%s:%s: onConnectFailed: %s" %(self._user, self._server, self._port, reason.getErrorMessage()))
+               reasonString = reason.getErrorMessage()
+               if reasonString != self._failureReason:
+                       self._ebNotify(reason, 'onConnectionFailed', _("connection failed - retrying")+'\n'+reason.getErrorMessage())
+                       self._failureReason = reasonString
+               self._proto = None
+               # self.stopChecker() not necessary, because we don't have an active connection...
 
-       def onConnectFailed(self, reason):
-               debug('[CheckMail] onConnectFailed: ' + reason.getErrorMessage())
-               self._ebNotify(reason, "onConnectFailed", _("connection to %(server)s:%(port)d failed:\n%(reason)s") %{'server':config.plugins.emailimap.server.value,'port':config.plugins.emailimap.port.value,'reason':reason.getErrorMessage()})
+       def onConnectionLost(self, reason):
+               debug("[EmailAccount] %s@%s:%s: onConnectFailed: %s" %(self._user, self._server, self._port, reason.getErrorMessage()))
+               # too noisy... self._ebNotify(reason, 'onConnectionLost', _("connection lost - retrying"))
                self._proto = None
+               self.stopChecker()
 
        def _cbCapabilities(self,reason):
-               debug("[CheckMail] _cbCapabilities\n\
+               debug(_("[EmailAccount] %(name)s: _cbCapabilities:\n\
 ####################################################################################################\n\
 # If you have problems to log into your imap-server, please send me the output of the following line\n\
-# cbCapabilities: " + str(reason) +"\n\
+# cbCapabilities: %(capa)s\n\
 ####################################################################################################\n")
+                       %{'name':self._name, 'capa':str(reason)})
                self._doLogin()
-               
+
+       def _ebCapabilities(self,reason):
+               debug("[EmailAccount] %s: _ebCapabilities: %s" %(self._name, str(reason)))
+
        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)
-               
+               debug("[EmailAccount] %s: _doLogin secure" %(self._name))
+               d = self._proto.authenticate(self._password)
+               d.addCallback(self._onAuthentication)
+               d.addErrback(self._onAuthenticationFailed)
+               return d
+
        def _onAuthentication(self, result):
-               debug("[CheckMail] onAuthentication: logged in")
-               self._proto.examine('inbox').addCallback(self._cbOk).addErrback(self._ebNotify, "examine", _("cannot access inbox"))
-               self._checkMail()
+               # better use LSUB here to get only the subscribed to mailboxes
+               debug("[EmailAccount] %s: _onAuthentication: %s" %(self._name, str(result)))
+               self.startChecker()
+               self._proto.lsub("", "*").addCallback(self._onMailboxList)
 
        def _onAuthenticationFailed(self, failure):
                # If it failed because no SASL mechanisms match
-               debug("[CheckMail] onAuthenticationFailed: " + failure.getErrorMessage())
+               debug("[EmailAccount] %s: onAuthenticationFailed: %s" %(self._name, failure.getErrorMessage()))
                try:
                        failure.trap(imap4.NoSupportedAuthentication)
                        self._doLoginInsecure()
                except Exception,e:
-                       debug("[CheckMail] onAuthenticationFailed: %s" %str(e))
+                       debug("[EmailAccount] %s: _onAuthenticationFailed: %s" %(self._name, e.message))
+                       print e,e.message
 
        def _doLoginInsecure(self):
-               debug("[CheckMail] doLoginInsecure")
-               self._proto.login(config.plugins.emailimap.username.value, config.plugins.emailimap.password.value
-                               ).addCallback(self._onAuthentication).addErrback(self._ebNotify, "login", _("login failed"))
+               debug("[EmailAccount] %s: _doLoginInsecure" %(self._name))
+               self._proto.login(self._user, self._password).addCallback(self._onAuthentication).addErrback(self._onInsecureAuthenticationFailed)
+
+       def _onInsecureAuthenticationFailed(self, failure):
+               debug("[EmailAccount] %s: _onInsecureAuthenticationFailed: %s" %(self._name, failure.getErrorMessage()))
+               self._proto = None
+               Notifications.AddNotification(
+                       MessageBox,
+                       _("error logging %(who)s in:\n%(failure)s")
+                               %{
+                               'who':"%s@%s" %(self._user, self._server),
+                               'failure':failure.getErrorMessage()
+                               }, type=MessageBox.TYPE_ERROR, timeout=config.plugins.emailimap.timeout.value)
+
+       def _onMailboxList(self, result):
+               list = [UTF7toUTF8(mb[2]).encode('utf-8') for mb in result if '\\Noselect' not in mb[0]]
+               debug("[EmailAccount] %s: onMailboxList: %s selectable mailboxes" %(self._name, len(list)))
+               list.sort()
+               try:
+                       self.inboxPos = map(lambda x: x.lower(), list).index('inbox')+1
+               except:
+                       debug("[EmailAccount] onMailboxList: no inbox?!?!")
+                       list = ['INBOX']
+                       self.inboxPos = 1
+               self.mailboxList = list
+
+class EmailAccountList(Screen):
+
+       def __init__(self, session):
+               '''
+               Entry screen holding the list of accounts.
+               Offering to add, edit or remove one. Also configuration through <menu> 
+               '''
+               debug("[EmailAccountList] __init__")
+               noButtons = 3
+               width = max(noButtons*140+35+100, DESKTOP_WIDTH/3)
+               self.width = width
+               height = max(5*30+50, DESKTOP_HEIGHT/3)
+               buttonsGap = (width-(noButtons)*140-35)/(noButtons+2)
+               self.skin = """
+                       <screen position="%d,%d" size="%d,%d" title="Accounts list" >
+                       <widget name="accounts" position="0,0" size="%d,%d" scrollbarMode="showOnDemand" />
+                       <ePixmap position="%d,%d" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
+                       <ePixmap position="%d,%d" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
+                       <ePixmap position="%d,%d" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
+                       <ePixmap position="%d,%d"       size="35,25" pixmap="skin_default/buttons/key_menu.png"         alphatest="on" />
+                       <widget name="buttonred" position="%d,%d" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;%d" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+                       <widget name="buttongreen" position="%d,%d" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;%d" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+                       <widget name="buttonyellow" position="%d,%d" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;%d" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+                       </screen>""" %(
+                                               (DESKTOP_WIDTH-width)/2, (DESKTOP_HEIGHT-height)/2, width, height,
+                                               width, height,  # config
+                                               buttonsGap, height-45,
+                                               2*buttonsGap+140, height-45,
+                                               3*buttonsGap+2*140, height-45,
+                                               4*buttonsGap+3*140, height-38,
+                                               buttonsGap, height-45, scaleV(22,18),
+                                               2*buttonsGap+140, height-45, scaleV(22,18),
+                                               3*buttonsGap+2*140, height-45, scaleV(22,18)
+                                               )
+               Screen.__init__(self, session)
+               self["buttonred"] = Label(_("remove"))
+               self["buttongreen"] = Label(_("add"))
+               self["buttonyellow"] = Label(_("edit"))
+               self["setupActions"] = ActionMap(["ColorActions", "OkCancelActions", "MenuActions"],
+               {
+                       "menu": self._config,
+                       "red": self._remove,
+                       "green": self._add,
+                       "yellow": self._edit,
+                       "cancel": self._exit,
+                       "ok": self._action,
+               }, -2)
+               for acc in mailAccounts:
+                       if not acc.isConnected():
+                               acc.forceRetry(self._layoutFinish)
+               self["accounts"] = MenuList([], content=eListboxPythonMultiContent)
+               self["accounts"].l.setItemHeight(scaleV(20,18)+5)
+               self["accounts"].l.setFont(0, gFont("Regular", scaleV(20,18)))
+               self.onLayoutFinish.append(self._layoutFinish)
+
+       def _layoutFinish(self):
+               self.setTitle(_("Accounts list"))
+               accList = []
+               for acc in mailAccounts:
+                       if acc.isConnected():
+                               color = 0x00FFFFFF
+                       else:
+                               color = 0x00888888
+                       accList.append([acc, MultiContentEntryText(pos=(0, 0), size=(self.width,scaleV(20,18)+5), text=acc._name, color=color, color_sel=color)])
+               self["accounts"].l.setList(accList)
+
+       def _config(self):
+               debug("[EmailAccountList] _config")
+               self.session.open(EmailConfigOptions, "Rev " + "$Revision$"[11: - 1] + "$Date$"[7:23])
+
+       def _action(self):
+               if self["accounts"].getCurrent():
+                       debug("[EmailAccountList] _action: %s" %self["accounts"].getCurrent()[0]._name)
+                       account = self["accounts"].getCurrent()[0]
+                       if account and account.isConnected():
+                               self.session.open(EmailScreen, account)
+                               self._layoutFinish()
+                       else:
+                               self.session.open(MessageBox,
+                                                               _("account %s is not connected") %self["accounts"].getCurrent()[0]._name,
+                                                               type=MessageBox.TYPE_INFO,
+                                                               timeout=config.plugins.emailimap.timeout.value)
+               else:
+                       debug("[EmailAccountList] _action: no account selected")
+                       self.session.open(MessageBox,
+                                                       _("no account selected"),
+                                                       type=MessageBox.TYPE_ERROR,
+                                                       timeout=config.plugins.emailimap.timeout.value)
+
+       def _add(self):
+               debug("[EmailAccountList] _add")
+               self.session.openWithCallback(self._cbAdd, EmailConfigAccount)
+
+       def _cbAdd(self, params):
+               if params:
+                       EmailAccount(params, writeAccounts)
+               self._layoutFinish()
+
+       def _edit(self):
+               debug("[EmailAccountList] _edit")
+               if self["accounts"].getCurrent():
+                       self.session.openWithCallback(self._cbEdit, EmailConfigAccount, self["accounts"].getCurrent()[0].getConfig())
+               else:
+                       self.session.openWithCallback(self._cbAdd, EmailConfigAccount)
 
-mailChecker = None
-def autostart(reason, **kwargs):
-       debug("[EmailClient] - Autostart")
-       global mailChecker
-       if config.plugins.emailimap.checkForNewMails.value and not mailChecker:
-               mailChecker = CheckMail()
+       def _cbEdit(self, params):
+               if params:
+                       self["accounts"].getCurrent()[0].exit()
+                       EmailAccount(params, writeAccounts)
+               self._layoutFinish()
+               
+       def _remove(self):
+               debug("[EmailAccountList] _remove")
+               if self["accounts"].getCurrent():
+                       self.session.openWithCallback(
+                               self._cbRemove,
+                               MessageBox,
+                               _("Really delete account %s?") % self["accounts"].getCurrent()[0]._name)
+               else:
+                       self.session.open(MessageBox,
+                                                       _("no account selected"),
+                                                       type=MessageBox.TYPE_ERROR,
+                                                       timeout=config.plugins.emailimap.timeout.value)
+
+       def _cbRemove(self, ret):
+               if ret:
+                       self["accounts"].getCurrent()[0].exit()
+                       writeAccounts()
+               self._layoutFinish()
+
+       def _exit(self):
+               for acc in mailAccounts:
+                       acc.removeCallback()
+               self.close()
+
+from Tools.Directories import resolveFilename, SCOPE_SYSETC, SCOPE_CONFIG
+import csv
+MAILCONF = resolveFilename(SCOPE_CONFIG, "EmailClient.csv")
+
+def writeAccounts():
+       global mailAccounts
+       fd = open(MAILCONF, 'w')
+       out = csv.writer(fd, quotechar='"')
+       for acc in mailAccounts:
+               out.writerow(acc.getConfig())
+       fd.close()
+
+def getAccounts():
+       debug("[] getAccounts")
+
+       mailAccountsParams = []
+       if not os.path.exists(MAILCONF):
+               MAILCONF_XML = resolveFilename(SCOPE_SYSETC, "mailconf.xml")
+               debug("[] getAccounts: check for %s" %MAILCONF_XML)
+               if os.path.exists(MAILCONF_XML):
+                       from xml.dom.minidom import parse
+                       Notifications.AddNotification(MessageBox, _("importing configurations from %s") %MAILCONF_XML, type=MessageBox.TYPE_INFO, timeout=config.plugins.emailimap.timeout.value)
+                       maildom = parse(MAILCONF_XML)
+                       for top in maildom.getElementsByTagName("list"):
+                               for acc in top.getElementsByTagName("account"):
+                                       name = str(acc.getElementsByTagName("name")[0].childNodes[0].data)
+                                       server = str(acc.getElementsByTagName("server")[0].childNodes[0].data)
+                                       port = str(acc.getElementsByTagName("port")[0].childNodes[0].data)
+                                       user = str(acc.getElementsByTagName("user")[0].childNodes[0].data)
+                                       password = str(acc.getElementsByTagName("pass")[0].childNodes[0].data)
+                                       interval = str(acc.getElementsByTagName("interval")[0].childNodes[0].data)
+                                       maxmail = str(acc.getElementsByTagName("MaxMail")[0].childNodes[0].data)
+                               
+                                       debug("[] getAccounts: %s, %s, %s, %s, %s, %s, %s" 
+                                               %(name, server, port, user, password, interval, maxmail)
+                                               )
+                                       mailAccountsParams.append((str(name), (name, server, port, user, password, interval, maxmail)))
+               else:
+                       debug("[] getAccounts: no file found, exiting")
+       else:
+               debug("[] getAccounts: reading %s" %MAILCONF)
+               fd = open(MAILCONF)
+               accounts = csv.reader(fd, quotechar='"')
+               for acc in accounts:
+                       mailAccountsParams.append(acc)
+               fd.close()
+
+       return mailAccountsParams
+
+def main(session, **kwargs): #@UnusedVariable kwargs
+       session.open(EmailAccountList)
+
+def autostart(reason, **kwargs): #@UnusedVariable reason
+       debug("[EmailClient] - Autostart reason: %d kwargs: %s" %(reason,repr(kwargs)))
+       debug("[EmailClient] " + "$Revision$"[1:-1]     + "$Date$"[7:23] + " starting")
+       # ouch, this is a hack
+       if kwargs.has_key("session"):
+               global my_global_session
+               my_global_session = kwargs["session"]
+               # return
+
+       if reason == 0:
+               for acc in getAccounts():
+                       debug("[EmailClient] - Autostart: add account %s" %acc[0])
+                       EmailAccount(acc)
+       else:
+               for acc in mailAccounts:
+                       acc.exit()
 
 initLog()
 
-def Plugins(path, **kwargs):
+def Plugins(path, **kwargs): #@UnusedVariable kwargs
        return [
                         PluginDescriptor(name=_("Email Client"), description=_("view Emails via IMAP4"),
                         where = PluginDescriptor.WHERE_PLUGINMENU,
index 2018be6..6b39e44 100755 (executable)
@@ -1,25 +1,14 @@
-from twisted.internet import reactor
-from twisted.internet import protocol
-from twisted.internet import ssl
-from twisted.internet import defer
+from twisted.internet import reactor, protocol, ssl
 from twisted.mail import imap4
 
-from Tools import Notifications
-from Screens.MessageBox import MessageBox
-from twisted.internet.protocol import ReconnectingClientFactory
-
-import time
+# from twisted.internet import defer
 # from twisted.python import log
 # log.startLogging(open("/tmp/twisted.log","w"))
-from . import debug
 # defer.setDebugging(True)
+from . import debug #@UnresolvedImport
 
 class SimpleIMAP4Client(imap4.IMAP4Client):
        greetDeferred = None
-       def __init__(self,e2session, contextFac = None):
-               self.e2session = e2session
-               imap4.IMAP4Client.__init__(self,contextFactory = contextFac)
-               
        def serverGreeting(self, caps):
                debug("[SimpleIMAP4Client] serverGreeting: %s" %caps)
                self.serverCapabilities = caps
@@ -39,7 +28,7 @@ class SimpleIMAP4ClientFactory(protocol.ReconnectingClientFactory):
 
        def buildProtocol(self, addr):
                debug("[SimpleIMAP4ClientFactory] building protocol: %s" %addr)
-               p = self.protocol(self.e2session,contextFac = self.ctx)
+               p = self.protocol(contextFactory = self.ctx)
                p.factory = self
                p.greetDeferred = self.e2session.onConnect
                auth = imap4.CramMD5ClientAuthenticator(self.username)
@@ -47,27 +36,27 @@ class SimpleIMAP4ClientFactory(protocol.ReconnectingClientFactory):
                return p
 
        def startedConnecting(self, connector):
-               debug("[SimpleIMAP4ClientFactory] startedConnecting: %s" %time.ctime())
+               debug("[SimpleIMAP4ClientFactory] startedConnecting")
 
        def clientConnectionFailed(self, connector, reason):
-               debug("[SimpleIMAP4ClientFactory] clientConnectionFailed: %s" %reason.getErrorMessage())
-               self.e2session.onConnectFailed(reason)
-               ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
+               debug("[SimpleIMAP4ClientFactory] clientConnectionFailed: %s" %reason.getErrorMessage())
+               self.e2session.onConnectionFailed(reason)
+               protocol.ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
 
        def clientConnectionLost(self, connector, reason):
-               debug("[SimpleIMAP4ClientFactory] clientConnectionLost: %s" %reason.getErrorMessage())
-               self.e2session.onConnectFailed(reason)
-               ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
+               debug("[SimpleIMAP4ClientFactory] clientConnectionLost: %s" %reason.getErrorMessage())
+               self.e2session.onConnectionLost(reason)
+               protocol.ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
 
 def createFactory( e2session,username,hostname, port):
-       debug("createFactory: for %s@%s:%s at %s" %(username,hostname,port, "time: %s" %time.ctime()))
+       debug("createFactory: for %s@%s:%s" %(username,hostname,port))
 
        f2 = ssl.ClientContextFactory()
        factory = SimpleIMAP4ClientFactory(e2session, username, f2)
        if port == 993:
-               c = reactor.connectSSL( hostname, port,factory,f2)
+               reactor.connectSSL( hostname, port,factory,f2) #@UndefinedVariable
        else:
-               c = reactor.connectTCP( hostname, port,factory)
+               reactor.connectTCP( hostname, port,factory) #@UndefinedVariable
 
        debug("createFactory: factory started")
        return factory
\ No newline at end of file