[tuxdroid-svn] r5792 - in software_suite_v3/software/plugin/plugin-email/trunk/plugin-email: resou
Status: Beta
Brought to you by:
ks156
|
From: ks156 <c2m...@c2...> - 2009-10-29 06:36:38
|
Author: ks156
Date: 2009-10-29 07:36:27 +0100 (Thu, 29 Oct 2009)
New Revision: 5792
Modified:
software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/resources/de.po
software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/resources/en.po
software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/resources/fr.po
software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/resources/nl.po
software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/resources/plugin.pot
software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/src/net/karmaLab/tuxDroid/plugins/MailPlugin.java
Log:
* Merged r5659 through r5785 from random_sentences
Modified: software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/resources/de.po
===================================================================
--- software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/resources/de.po 2009-10-29 06:35:12 UTC (rev 5791)
+++ software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/resources/de.po 2009-10-29 06:36:27 UTC (rev 5792)
@@ -41,18 +41,60 @@
msgid "Options"
msgstr "Optionen"
-msgid "You have a new message."
+msgid "You have a new mail."
msgstr "Sie haben eine neue Email."
+msgid "A new mail has arrived !"
+msgstr "Eine neue Mail ist eingetroffen!"
+
+msgid "It appears you have received a new email."
+msgstr "Anscheinend haben Sie eine neue E-Mail erhalten."
+
+msgid "A new email ? I wonder who could be thinking about you."
+msgstr "Eine neue E-Mail? Ich frage mich, wer gerade an Sie denkt."
+
+msgid "It would appear you have received new mails."
+msgstr "Es sieht so aus, als hätten Sie neue E-Mails erhalten."
+
msgid "Mail sent by {0}"
msgstr "Mail gesendet von {0}"
-msgid "The message subject is : {0}"
+msgid "The email was sent by {0}"
+msgstr "Die E-Mail wurde gesendet von {0}"
+
+msgid "The sender of the mail is {0}"
+msgstr "Der Absender der E-Mail ist {0}"
+
+msgid "The sender is {0}"
+msgstr "Der Absender ist {0}"
+
+msgid "The email subject is : {0}"
msgstr "Betreff der Email ist: {0}"
+msgid "The subject of the email is : {0}"
+msgstr "Thema der E-Mail ist: {0}"
+
+msgid "The email topic is : {0}"
+msgstr "Das E-Mail-Thema ist: {0}"
+
+msgid "The topic is : {0}"
+msgstr "Das Thema ist: {0}"
+
+msgid "The title of the email is : {0}"
+msgstr "Der Titel der E-Mail ist: {0}"
+
msgid "No new mail."
msgstr "Keine neue Mail."
+msgid "I'm sorry, nobody sent you any email."
+msgstr "Es tut mir leid, niemand hat Ihnen eine E-Mail gesandt."
+
+msgid "No mails. Nobody seems to be thinking about you."
+msgstr "Keine Mails. Anscheinend denkt niemand an Sie."
+
+msgid "Your mailbox is empty."
+msgstr "Ihre Mailbox ist leer."
+
msgid "your_user"
msgstr "Ihr Benutzer"
@@ -91,4 +133,3 @@
msgid "Start me every x (From full hour)"
msgstr "Prüfen Sie meine Mailbox häufig"
-
Modified: software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/resources/en.po
===================================================================
--- software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/resources/en.po 2009-10-29 06:35:12 UTC (rev 5791)
+++ software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/resources/en.po 2009-10-29 06:36:27 UTC (rev 5792)
@@ -41,18 +41,60 @@
msgid "Options"
msgstr "Options"
-msgid "You have a new message."
-msgstr "You have a new message."
+msgid "You have a new mail."
+msgstr "You have a new mail."
+msgid "A new mail has arrived !"
+msgstr "A new mail has arrived !"
+
+msgid "It appears you have received a new email."
+msgstr "It appears you have received a new email."
+
+msgid "A new email ? I wonder who could be thinking about you."
+msgstr "A new email ? I wonder who could be thinking about you."
+
+msgid "It would appear you have received new mails."
+msgstr "It would appear you have received new mails."
+
msgid "Mail sent by {0}"
msgstr "Mail sent by {0}"
-msgid "The message subject is : {0}"
-msgstr "The message subject is : {0}"
+msgid "The email was sent by {0}"
+msgstr "The email was sent by {0}"
+msgid "The sender of the mail is {0}"
+msgstr "The sender of the mail is {0}"
+
+msgid "The sender is {0}"
+msgstr "The sender is {0}"
+
+msgid "The email subject is : {0}"
+msgstr "The email subject is : {0}"
+
+msgid "The subject of the email is : {0}"
+msgstr "The subject of the email is : {0}"
+
+msgid "The email topic is : {0}"
+msgstr "The email topic is : {0}"
+
+msgid "The topic is : {0}"
+msgstr "The topic is : {0}"
+
+msgid "The title of the email is : {0}"
+msgstr "The title of the email is : {0}"
+
msgid "No new mail."
msgstr "No new mail."
+msgid "I'm sorry, nobody sent you any email."
+msgstr "I'm sorry, nobody sent you any email."
+
+msgid "No mails. Nobody seems to be thinking about you."
+msgstr "No mails. Nobody seems to be thinking about you."
+
+msgid "Your mailbox is empty."
+msgstr "Your mailbox is empty."
+
msgid "your_user"
msgstr "your_user"
Modified: software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/resources/fr.po
===================================================================
--- software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/resources/fr.po 2009-10-29 06:35:12 UTC (rev 5791)
+++ software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/resources/fr.po 2009-10-29 06:36:27 UTC (rev 5792)
@@ -41,18 +41,60 @@
msgid "Options"
msgstr "Options"
-msgid "You have a new message."
-msgstr "Vous avez un nouveau message"
+msgid "You have a new mail."
+msgstr "Vous avez un nouvel email"
+msgid "A new mail has arrived !"
+msgstr "Un nouvel email est arrivé !"
+
+msgid "It appears you have received a new email."
+msgstr "Il semble que vous ayez reçu un email."
+
+msgid "A new email ? I wonder who could be thinking about you."
+msgstr "Un nouvel email ? Je me demande qui peut bien penser à vous."
+
+msgid "It would appear you have received new mails."
+msgstr "Il semble que des emails soient arrivés"
+
msgid "Mail sent by {0}"
-msgstr "Message envoyé par {0}"
+msgstr "Email envoyé par {0}"
-msgid "The message subject is : {0}"
-msgstr "Le sujet du message est : {0}"
+msgid "The email was sent by {0}"
+msgstr "L'email vous a été envoyé par {0}"
+msgid "The sender of the mail is {0}"
+msgstr "L'expéditeur de l'email est {0}"
+
+msgid "The sender is {0}"
+msgstr "L'expéditeur de l'email est : {0}"
+
+msgid "The email subject is : {0}"
+msgstr "L'email a comme sujet : {0}"
+
+msgid "The subject of the email is : {0}"
+msgstr "Le sujet de l'email est : {0}"
+
+msgid "The email topic is : {0}"
+msgstr "Le thème de l'email est : {0}"
+
+msgid "The topic is : {0}"
+msgstr "Le thème est : {0}"
+
+msgid "The title of the email is : {0}"
+msgstr "Le titre de l'email est : {0}"
+
msgid "No new mail."
-msgstr "Aucun nouveau message"
+msgstr "Aucun nouvel email"
+msgid "I'm sorry, nobody sent you any email."
+msgstr "Désolé, personne ne vous a envoyé d'email ..."
+
+msgid "No mails. Nobody seems to be thinking about you."
+msgstr "Pas de nouveaux emails. Personne ne semble avoir pensé à vous."
+
+msgid "Your mailbox is empty."
+msgstr "Votre boîte email est vide."
+
msgid "your_user"
msgstr "votre_identifiant"
Modified: software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/resources/nl.po
===================================================================
--- software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/resources/nl.po 2009-10-29 06:35:12 UTC (rev 5791)
+++ software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/resources/nl.po 2009-10-29 06:36:27 UTC (rev 5792)
@@ -27,7 +27,7 @@
msgstr "Controleer of er nieuwe E-mail is"
msgid "Read your mail"
-msgstr "Lees jouw E-mail"
+msgstr "Lees je E-mail"
msgid "User parameters"
msgstr "Gebruikersinstellingen"
@@ -41,18 +41,60 @@
msgid "Options"
msgstr "Opties"
-msgid "You have a new message."
-msgstr "Je hebt een nieuw bericht."
+msgid "You have a new mail."
+msgstr "Je hebt een nieuwe email."
+msgid "A new mail has arrived !"
+msgstr "Er is een nieuwe mail binnengekomen !"
+
+msgid "It appears you have received a new email."
+msgstr "Ik geloof dat je nieuwe mail hebt."
+
+msgid "A new email ? I wonder who could be thinking about you."
+msgstr "Een nieuwe email ? Ik ben benieuwd van wie het is."
+
+msgid "It would appear you have received new mails."
+msgstr "Ik geloof dat er nieuwe mails zijn binnengekomen."
+
msgid "Mail sent by {0}"
-msgstr "Dit bericht werd verzonden door {0}"
+msgstr "De email werd verzonden door {0}"
-msgid "The message subject is : {0}"
+msgid "The email was sent by {0}"
+msgstr "De email komt van {0}"
+
+msgid "The sender of the mail is {0}"
+msgstr "De afzender van de mail is {0}"
+
+msgid "The sender is {0}"
+msgstr "De afzender is {0}"
+
+msgid "The email subject is : {0}"
msgstr "Het onderwerp is : {0}"
+msgid "The subject of the email is : {0}"
+msgstr "Het onderwerp van de email is : {0}"
+
+msgid "The email topic is : {0}"
+msgstr "Het email onderwerp is : {0}"
+
+msgid "The topic is : {0}"
+msgstr "Het onderwerp is : {0}"
+
+msgid "The title of the email is : {0}"
+msgstr "De titel van de email is : {0}"
+
msgid "No new mail."
msgstr "Geen nieuwe mails."
+msgid "I'm sorry, nobody sent you any email."
+msgstr "Sorry, niemand heeft je een mail gestuurd."
+
+msgid "No mails. Nobody seems to be thinking about you."
+msgstr "Geen nieuwe mails. Er lijkt op het ogenblik niemand aan jou te denken."
+
+msgid "Your mailbox is empty."
+msgstr "Je mailbox is leeg."
+
msgid "your_user"
msgstr "jouw_login"
Modified: software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/resources/plugin.pot
===================================================================
--- software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/resources/plugin.pot 2009-10-29 06:35:12 UTC (rev 5791)
+++ software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/resources/plugin.pot 2009-10-29 06:36:27 UTC (rev 5792)
@@ -1,4 +1,5 @@
-msgid "Mail Gadget"
+
+msgid "Mail Plugin"
msgstr ""
msgid "Username"
@@ -37,18 +38,60 @@
msgid "Options"
msgstr ""
-msgid "You have a new message."
+msgid "You have a new mail."
msgstr ""
+msgid "A new mail has arrived !"
+msgstr ""
+
+msgid "It appears you have received a new email."
+msgstr ""
+
+msgid "A new email ? I wonder who could be thinking about you."
+msgstr ""
+
+msgid "It would appear you have received new mails."
+msgstr ""
+
msgid "Mail sent by {0}"
msgstr ""
-msgid "The message subject is : {0}"
+msgid "The email was sent by {0}"
msgstr ""
+msgid "The sender of the mail is {0}"
+msgstr ""
+
+msgid "The sender is {0}"
+msgstr ""
+
+msgid "The email subject is : {0}"
+msgstr ""
+
+msgid "The subject of the email is : {0}"
+msgstr ""
+
+msgid "The email topic is : {0}"
+msgstr ""
+
+msgid "The topic is : {0}"
+msgstr ""
+
+msgid "The title of the email is : {0}"
+msgstr ""
+
msgid "No new mail."
msgstr ""
+msgid "I'm sorry, nobody sent you any email."
+msgstr ""
+
+msgid "No mails. Nobody seems to be thinking about you."
+msgstr ""
+
+msgid "Your mailbox is empty."
+msgstr ""
+
msgid "your_user"
msgstr ""
@@ -75,3 +118,15 @@
msgid "Sorry, there was an error when connecting to the mail server. Please check your email configuration."
msgstr ""
+
+msgid "Start every x"
+msgstr ""
+
+msgid "Start me every x"
+msgstr ""
+
+msgid "Start every x from full hour"
+msgstr ""
+
+msgid "Start me every x (From full hour)"
+msgstr ""
Modified: software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/src/net/karmaLab/tuxDroid/plugins/MailPlugin.java
===================================================================
--- software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/src/net/karmaLab/tuxDroid/plugins/MailPlugin.java 2009-10-29 06:35:12 UTC (rev 5791)
+++ software_suite_v3/software/plugin/plugin-email/trunk/plugin-email/src/net/karmaLab/tuxDroid/plugins/MailPlugin.java 2009-10-29 06:36:27 UTC (rev 5792)
@@ -1,448 +1,492 @@
-/* This file is part of "TuxDroid Gadget Mail".
- * Copyright 2008, kysoh
- * Author : Yoran Brault
- * eMail : software@_bad_karma-lab.net (remove _bad_ before sending an email)
- * Site : http://www.kysoh.com/
- *
- * "TuxDroid Gadget Mail" is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * "TuxDroid Gadget Mail" is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with "TuxDroid Gadget Mail"; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package net.karmaLab.tuxDroid.plugins;
-
-import java.io.IOException;
-import java.security.Security;
-import java.util.Properties;
-import java.util.Vector;
-
-import javax.mail.Folder;
-import javax.mail.Message;
-import javax.mail.MessagingException;
-import javax.mail.Session;
-import javax.mail.Store;
-import javax.mail.Flags.Flag;
-import javax.mail.internet.InternetAddress;
-
-import java.net.Socket;
-import java.net.UnknownHostException;
-import java.net.InetSocketAddress;
-
-import com.kysoh.tuxdroid.plugin.framework.plugin.SimplePlugin;
-
-/**
- * @author User
- */
-public class MailPlugin extends SimplePlugin<Configuration>
-{
- /**
- * @param args
- * @throws Exception
- */
- public static void main(String[] args) throws Exception
- {
- new MailPlugin().boot(args, new Configuration());
- }
-
- /**
- *
- */
- @Override
- public void start() throws Exception
- {
- if (getCommand().equals("run"))
- {
- run();
- }
- else if (getCommand().equals("check"))
- {
- check();
- }
- else
- {
- run();
- }
- }
-
-
- /**
- * @throws MessagingException
- * @throws IOException
- * @throws ClassNotFoundException
- */
- public void check() throws MessagingException, IOException, ClassNotFoundException, Exception
- {
- Message messages[] = connectToMailBox();
-
- if (messages == null)
- {
- throwResult(false);
- return;
- }
- String sessionId = configuration().getHost() + "_" + configuration().getUser();
- State stateAlert = readState(State.class, sessionId + "ALERT");
- /* Is first check ? */
- boolean firstCheck;
- if (stateAlert.getLastMessages().size() == 0)
- {
- firstCheck = true;
- stateAlert.getLastMessages().add("FIRST_CHECK_HACK");
- }
- else
- {
- firstCheck = false;
- }
- /* Check if you have a new message */
- boolean newMessageAlert = false;
- for (int i = messages.length - 1; i >= 0; i--)
- {
- if (!messages[i].getFlags().contains(Flag.SEEN))
- {
- String subject = messages[i].getSubject();
- if (subject != null)
- {
- if (!stateAlert.getLastMessages().contains(subject))
- {
- newMessageAlert = true;
- stateAlert.getLastMessages().add(subject);
- }
- }
- }
- }
- if((newMessageAlert) && (!firstCheck))
- {
- throwResult(true);
- throwMessage("You have a new message.");
- }
- else
- {
- throwResult(false);
- }
- /* Save the current referenced mails */
- writeState(stateAlert, sessionId + "ALERT");
- }
-
- /**
- *
- * @throws MessagingException
- * @throws IOException
- * @throws ClassNotFoundException
- */
- public void run() throws MessagingException, IOException, ClassNotFoundException
- {
- Message messages[] = connectToMailBox();
- if (messages == null)
- {
- return;
- }
- String sessionId = configuration().getHost() + "_" + configuration().getUser();
- State stateRun = readState(State.class, sessionId + "RUN");
- /* Check for new message */
- boolean newMessageRun = false;
- for (int i = messages.length - 1; i >= 0; i--)
- {
- if (!messages[i].getFlags().contains(Flag.SEEN))
- {
- if (!stateRun.getLastMessages().contains(messages[i].getSubject()))
- {
- newMessageRun = true;
- break;
- }
- }
- }
- /* If new message found */
- if (newMessageRun)
- {
- int mailCounter = 0;
- boolean notifyNoNewMail = true;
- /* For all unread mails */
- for (int i = messages.length - 1; i >= 0; i--)
- {
- String subject;
- String filteredSubject;
- String sender;
- String senderPersonal;
- String senderAddress;
- boolean seen;
- boolean mailAlreadyRead;
-
- try
- {
- /* Get current mail data */
- subject = messages[i].getSubject();
- senderPersonal = ((InternetAddress) messages[i].getFrom()[0]).getPersonal();
- senderAddress = ((InternetAddress)messages[i].getFrom()[0]).getAddress();
- seen = messages[i].getFlags().contains(Flag.SEEN);
- /* Pass if mail is already seen */
- if (seen)
- {
- continue;
- }
- /* Pass if subject is empty */
- if (subject == null)
- {
- continue;
- }
- /* Filtering the mail address */
- if (senderPersonal == null)
- {
- sender = senderAddress;
- }
- else
- {
- sender = senderPersonal;
- }
- if (sender.contains("<"))
- {
- sender = sender.substring(0, sender.indexOf("<"));
- }
- /* Filtering the mail subject */
- filteredSubject = subject.replace("*", " ");
- filteredSubject = filteredSubject.replace("_", " ");
- filteredSubject = filteredSubject.replace("{", " ");
- filteredSubject = filteredSubject.replace("}", " ");
- filteredSubject = filteredSubject.replace("[", " ");
- filteredSubject = filteredSubject.replace("]", " ");
- filteredSubject = filteredSubject.replace("/", " ");
- filteredSubject = filteredSubject.replace("\\", " ");
- filteredSubject = filteredSubject.replace(" ", " ");
- mailAlreadyRead = false;
- /* Check if the mail has already be read */
- for (int j = 0; j < stateRun.getLastMessages().size(); j++)
- {
- if (filteredSubject.equals(stateRun.getLastMessages().get(j)))
- {
- mailAlreadyRead = true;
- break;
- }
- }
- /* If the mail is not already read */
- if (!mailAlreadyRead)
- {
- notifyNoNewMail = false;
- /* Read max 5 mails */
- mailCounter++;
- if (mailCounter <= 5)
- {
- throwMessage("Mail sent by {0}", sender);
- throwMessage("The message subject is : {0}", filteredSubject);
- }
- /* Referencing the current mail */
- stateRun.getLastMessages().add(filteredSubject);
- }
- }
- catch (Exception e)
- {
- /* Prevent unhandled errors */
- ;
- }
- }
- if(notifyNoNewMail)
- {
- throwMessage("No new mail.");
- }
- }
- /* No new message */
- else
- {
- throwMessage("No new mail.");
- }
- /* Save the current referenced mails */
- writeState(stateRun, sessionId + "RUN");
- }
-
- /**
- * Check if the mail server is responding to the x port.
- * @param host Server host
- * @param port Server port
- * @return true or false
- */
- private boolean checkMailServer(String host, Integer port)
- {
- Socket socket = new Socket();
- try
- {
- socket.connect(new InetSocketAddress(host, port), 1000);
- }
- catch (UnknownHostException e)
- {
- socket = null;
- return false;
- }
- catch (IOException e)
- {
- socket = null;
- return false;
- }
- socket = null;
- return true;
- }
-
- /**
- * Find the server mail port.
- * @param host Server host
- * @return Server port or -1.
- */
- private int findMailServerPort(String host)
- {
- int port1;
- int port2;
- int port3;
- int port4;
-
- if ((host.startsWith("pop")) || (host.startsWith("POP")))
- {
- port1 = 110;
- port2 = 995;
- port3 = 143;
- port4 = 993;
- }
- else
- {
- port1 = 143;
- port2 = 993;
- port3 = 110;
- port4 = 995;
- }
- if (checkMailServer(host, port1))
- {
- return port1;
- }
- else if (checkMailServer(host, port2))
- {
- return port2;
- }
- else if (checkMailServer(host, port3))
- {
- return port3;
- }
- else if (checkMailServer(host, port4))
- {
- return port4;
- }
- else
- {
- return -1;
- }
- }
-
- /**
- * Get the mail server protocol from a port.
- * @param port Mail server port.
- * @return The mail server protocol.
- */
- private String portToProtocol(int port)
- {
- switch (port)
- {
- case 110:
- return "pop3";
- case 995:
- return "pop3s";
- case 143:
- return "imap";
- case 993:
- return "imaps";
- default:
- return "pop3";
- }
- }
-
- /**
- *
- * @return
- * @throws MessagingException
- * @throws IOException
- * @throws ClassNotFoundException
- */
- private Message[] connectToMailBox() throws MessagingException, IOException, ClassNotFoundException
- {
- String user;
- String host;
- String password;
- Session session;
- Properties props;
- int port;
- String protocol;
- Store store;
- Folder folder;
- Message messages[];
-
- /* Get user data */
- user = configuration().getUser();
- password = configuration().getPassword();
- host = configuration().getHost();
- /* Set ssl socket */
- Security.setProperty("ssl.SocketFactory.provider", "net.karmaLab.tuxDroid.plugins.DummySSLSocketFactory");
- /* Set text decoder */
- System.setProperty("mail.mime.decodetext.strict", "false");
- /* Configure seesion */
- props = new Properties();
- session = Session.getDefaultInstance(props, null);
- /* Find server port */
- port = findMailServerPort(host);
- if (port == -1)
- {
- throwMessage("Sorry, there was an error when connecting to the mail server. Please check your email configuration.");
- return null;
- }
- /* Get mail protocol */
- protocol = portToProtocol(port);
- /* Create mail store */
- store = session.getStore(protocol);
- /* Connect to the mailbox */
- try
- {
- store.connect(host, port, user, password);
- }
- /* Authentification exception (login / password / protocol / etc) */
- catch (javax.mail.AuthenticationFailedException e)
- {
- if (!getCommand().equals("check"))
- {
- throwMessage("Sorry, there was an error when connecting to the mail server. Please check your email configuration.");
- }
- return null;
- }
- /* Connection failed exception (timeout / network unreachable) */
- catch (javax.mail.MessagingException e)
- {
- if (!getCommand().equals("check"))
- {
- throwMessage("Sorry, I could not connect to the mail server. Please check your internet connection or try again later.");
- }
- return null;
- }
- /* Connect and open inbox folder */
- folder = store.getFolder("INBOX");
- folder.open(Folder.READ_ONLY);
- /* Get messages */
- messages = folder.getMessages();
- return messages;
- }
-
- @Override
- protected void onPluginEvent(String arg0, String[] arg1) throws Throwable
- {
- // TODO Auto-generated method stub
- ;
- }
-
- @Override
- protected void onPluginStop() throws Throwable
- {
- // TODO Auto-generated method stub
- ;
- }
-}
\ No newline at end of file
+/* This file is part of "TuxDroid Gadget Mail".
+ * Copyright 2008, kysoh
+ * Author : Yoran Brault
+ * eMail : software@_bad_karma-lab.net (remove _bad_ before sending an
+ * email)
+ * Site : http://www.kysoh.com/
+ *
+ * "TuxDroid Gadget Mail" is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * "TuxDroid Gadget Mail" is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with "TuxDroid Gadget Mail"; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package net.karmaLab.tuxDroid.plugins;
+
+import java.io.IOException;
+import java.security.Security;
+import java.util.Properties;
+import java.util.Vector;
+import java.util.Random;
+
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.Store;
+import javax.mail.Flags.Flag;
+import javax.mail.internet.InternetAddress;
+
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.net.InetSocketAddress;
+
+import com.kysoh.tuxdroid.plugin.framework.plugin.SimplePlugin;
+
+/**
+ * @author User
+ */
+public class MailPlugin extends SimplePlugin<Configuration>
+{
+
+ String[] newMailSentences = {
+ "You have a new mail.",
+ "A new mail has arrived !",
+ "It appears you have received a new email.",
+ "A new email ? I wonder who could be thinking about you.",
+ "It would appear you have received new mails."
+ };
+
+ String[] mailSenderSentences = {
+ "Mail sent by {0}",
+ "The email was sent by {0}",
+ "The sender of the mail is {0}",
+ "The sender is {0}"
+ };
+
+ String[] mailSubjectSentences = {
+ "The email subject is : {0}",
+ "The subject of the email is : {0}",
+ "The email topic is : {0}",
+ "The topic is : {0}",
+ "The title of the email is : {0}"
+ };
+
+ String[] noNewMailSentences = {
+ "No new mail.",
+ "I'm sorry, nobody sent you any email.",
+ "No mails. Nobody seems to be thinking about you.",
+ "Your mailbox is empty."
+ };
+
+ /**
+ * @param args
+ * @throws Exception
+ */
+ public static void main(String[] args) throws Exception
+ {
+ new MailPlugin().boot(args, new Configuration());
+ }
+
+ /**
+ *
+ */
+ @Override
+ public void start() throws Exception
+ {
+ if (getCommand().equals("run"))
+ {
+ run();
+ }
+ else if (getCommand().equals("check"))
+ {
+ check();
+ }
+ else
+ {
+ run();
+ }
+ }
+
+
+ /**
+ * @throws MessagingException
+ * @throws IOException
+ * @throws ClassNotFoundException
+ */
+ public void check() throws MessagingException, IOException, ClassNotFoundException, Exception
+ {
+ Message messages[] = connectToMailBox();
+
+ if (messages == null)
+ {
+ throwResult(false);
+ return;
+ }
+ String sessionId = configuration().getHost() + "_" + configuration().getUser();
+ State stateAlert = readState(State.class, sessionId + "ALERT");
+ /* Is first check ? */
+ boolean firstCheck;
+ if (stateAlert.getLastMessages().size() == 0)
+ {
+ firstCheck = true;
+ stateAlert.getLastMessages().add("FIRST_CHECK_HACK");
+ }
+ else
+ {
+ firstCheck = false;
+ }
+ /* Check if you have a new message */
+ boolean newMessageAlert = false;
+ for (int i = messages.length - 1; i >= 0; i--)
+ {
+ if (!messages[i].getFlags().contains(Flag.SEEN))
+ {
+ String subject = messages[i].getSubject();
+ if (subject != null)
+ {
+ if (!stateAlert.getLastMessages().contains(subject))
+ {
+ newMessageAlert = true;
+ stateAlert.getLastMessages().add(subject);
+ }
+ }
+ }
+ }
+ if((newMessageAlert) && (!firstCheck))
+ {
+ throwResult(true);
+ throwMessage(this.pickSentence(newMailSentences));
+ }
+ else
+ {
+ throwResult(false);
+ }
+ /* Save the current referenced mails */
+ writeState(stateAlert, sessionId + "ALERT");
+ }
+
+ /**
+ *
+ * @throws MessagingException
+ * @throws IOException
+ * @throws ClassNotFoundException
+ */
+ public void run() throws MessagingException, IOException, ClassNotFoundException
+ {
+ Message messages[] = connectToMailBox();
+ if (messages == null)
+ {
+ return;
+ }
+ String sessionId = configuration().getHost() + "_" + configuration().getUser();
+ State stateRun = readState(State.class, sessionId + "RUN");
+ /* Check for new message */
+ boolean newMessageRun = false;
+ for (int i = messages.length - 1; i >= 0; i--)
+ {
+ if (!messages[i].getFlags().contains(Flag.SEEN))
+ {
+ if (!stateRun.getLastMessages().contains(messages[i].getSubject()))
+ {
+ newMessageRun = true;
+ break;
+ }
+ }
+ }
+ /* If new message found */
+ if (newMessageRun)
+ {
+ int mailCounter = 0;
+ boolean notifyNoNewMail = true;
+
+ String senderSentence = this.pickSentence(mailSenderSentences);
+ String subjectSentence = this.pickSentence(mailSubjectSentences);
+ /* For all unread mails */
+ for (int i = messages.length - 1; i >= 0; i--)
+ {
+ String subject;
+ String filteredSubject;
+ String sender;
+ String senderPersonal;
+ String senderAddress;
+ boolean seen;
+ boolean mailAlreadyRead;
+
+ try
+ {
+ /* Get current mail data */
+ subject = messages[i].getSubject();
+ senderPersonal = ((InternetAddress) messages[i].getFrom()[0]).getPersonal();
+ senderAddress = ((InternetAddress)messages[i].getFrom()[0]).getAddress();
+ seen = messages[i].getFlags().contains(Flag.SEEN);
+ /* Pass if mail is already seen */
+ if (seen)
+ {
+ continue;
+ }
+ /* Pass if subject is empty */
+ if (subject == null)
+ {
+ continue;
+ }
+ /* Filtering the mail address */
+ if (senderPersonal == null)
+ {
+ sender = senderAddress;
+ }
+ else
+ {
+ sender = senderPersonal;
+ }
+ if (sender.contains("<"))
+ {
+ sender = sender.substring(0, sender.indexOf("<"));
+ }
+ /* Filtering the mail subject */
+ filteredSubject = subject.replace("*", " ");
+ filteredSubject = filteredSubject.replace("_", " ");
+ filteredSubject = filteredSubject.replace("{", " ");
+ filteredSubject = filteredSubject.replace("}", " ");
+ filteredSubject = filteredSubject.replace("[", " ");
+ filteredSubject = filteredSubject.replace("]", " ");
+ filteredSubject = filteredSubject.replace("/", " ");
+ filteredSubject = filteredSubject.replace("\\", " ");
+ filteredSubject = filteredSubject.replace(" ", " ");
+ mailAlreadyRead = false;
+ /* Check if the mail has already be read */
+ for (int j = 0; j < stateRun.getLastMessages().size(); j++)
+ {
+ if (filteredSubject.equals(stateRun.getLastMessages().get(j)))
+ {
+ mailAlreadyRead = true;
+ break;
+ }
+ }
+ /* If the mail is not already read */
+ if (!mailAlreadyRead)
+ {
+ notifyNoNewMail = false;
+ /* Read max 5 mails */
+ mailCounter++;
+ if (mailCounter <= 5)
+ {
+ throwMessage(senderSentence, sender);
+ throwMessage(subjectSentence, filteredSubject);
+ }
+ /* Referencing the current mail */
+ stateRun.getLastMessages().add(filteredSubject);
+ }
+ }
+ catch (Exception e)
+ {
+ /* Prevent unhandled errors */
+ ;
+ }
+ }
+ if(notifyNoNewMail)
+ {
+ throwMessage(this.pickSentence(noNewMailSentences));
+ }
+ }
+ /* No new message */
+ else
+ {
+ throwMessage(this.pickSentence(noNewMailSentences));
+ }
+ /* Save the current referenced mails */
+ writeState(stateRun, sessionId + "RUN");
+ }
+
+ /**
+ * This function return a sentences from a defined list
+ */
+ private String pickSentence(String[] list) {
+ Random rand = new Random();
+ return list[rand.nextInt(list.length)];
+ }
+
+ /**
+ * Check if the mail server is responding to the x port.
+ * @param host Server host
+ * @param port Server port
+ * @return true or false
+ */
+ private boolean checkMailServer(String host, Integer port)
+ {
+ Socket socket = new Socket();
+ try
+ {
+ socket.connect(new InetSocketAddress(host, port), 1000);
+ }
+ catch (UnknownHostException e)
+ {
+ socket = null;
+ return false;
+ }
+ catch (IOException e)
+ {
+ socket = null;
+ return false;
+ }
+ socket = null;
+ return true;
+ }
+
+ /**
+ * Find the server mail port.
+ * @param host Server host
+ * @return Server port or -1.
+ */
+ private int findMailServerPort(String host)
+ {
+ int port1;
+ int port2;
+ int port3;
+ int port4;
+
+ if ((host.startsWith("pop")) || (host.startsWith("POP")))
+ {
+ port1 = 110;
+ port2 = 995;
+ port3 = 143;
+ port4 = 993;
+ }
+ else
+ {
+ port1 = 143;
+ port2 = 993;
+ port3 = 110;
+ port4 = 995;
+ }
+ if (checkMailServer(host, port1))
+ {
+ return port1;
+ }
+ else if (checkMailServer(host, port2))
+ {
+ return port2;
+ }
+ else if (checkMailServer(host, port3))
+ {
+ return port3;
+ }
+ else if (checkMailServer(host, port4))
+ {
+ return port4;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+
+ /**
+ * Get the mail server protocol from a port.
+ * @param port Mail server port.
+ * @return The mail server protocol.
+ */
+ private String portToProtocol(int port)
+ {
+ switch (port)
+ {
+ case 110:
+ return "pop3";
+ case 995:
+ return "pop3s";
+ case 143:
+ return "imap";
+ case 993:
+ return "imaps";
+ default:
+ return "pop3";
+ }
+ }
+
+ /**
+ *
+ * @return
+ * @throws MessagingException
+ * @throws IOException
+ * @throws ClassNotFoundException
+ */
+ private Message[] connectToMailBox() throws MessagingException, IOException, ClassNotFoundException
+ {
+ String user;
+ String host;
+ String password;
+ Session session;
+ Properties props;
+ int port;
+ String protocol;
+ Store store;
+ Folder folder;
+ Message messages[];
+
+ /* Get user data */
+ user = configuration().getUser();
+ password = configuration().getPassword();
+ host = configuration().getHost();
+ /* Set ssl socket */
+ Security.setProperty("ssl.SocketFactory.provider", "net.karmaLab.tuxDroid.plugins.DummySSLSocketFactory");
+ /* Set text decoder */
+ System.setProperty("mail.mime.decodetext.strict", "false");
+ /* Configure seesion */
+ props = new Properties();
+ session = Session.getDefaultInstance(props, null);
+ /* Find server port */
+ port = findMailServerPort(host);
+ if (port == -1)
+ {
+ throwMessage("Sorry, there was an error when connecting to the mail server. Please check your email configuration.");
+ return null;
+ }
+ /* Get mail protocol */
+ protocol = portToProtocol(port);
+ /* Create mail store */
+ store = session.getStore(protocol);
+ /* Connect to the mailbox */
+ try
+ {
+ store.connect(host, port, user, password);
+ }
+ /* Authentification exception (login / password / protocol / etc) */
+ catch (javax.mail.AuthenticationFailedException e)
+ {
+ if (!getCommand().equals("check"))
+ {
+ throwMessage("Sorry, there was an error when connecting to the mail server. Please check your email configuration.");
+ }
+ return null;
+ }
+ /* Connection failed exception (timeout / network unreachable) */
+ catch (javax.mail.MessagingException e)
+ {
+ if (!getCommand().equals("check"))
+ {
+ throwMessage("Sorry, I could not connect to the mail server. Please check your internet connection or try again later.");
+ }
+ return null;
+ }
+ /* Connect and open inbox folder */
+ folder = store.getFolder("INBOX");
+ folder.open(Folder.READ_ONLY);
+ /* Get messages */
+ messages = folder.getMessages();
+ return messages;
+ }
+
+ @Override
+ protected void onPluginEvent(String arg0, String[] arg1) throws Throwable
+ {
+ // TODO Auto-generated method stub
+ ;
+ }
+
+ @Override
+ protected void onPluginStop() throws Throwable
+ {
+ // TODO Auto-generated method stub
+ ;
+ }
+}
|