Author: ks156
Date: 2009-10-14 15:30:33 +0200 (Wed, 14 Oct 2009)
New Revision: 5661
Modified:
software_suite_v3/software/plugin/plugin-email/branches/random_sentences/plugin-email/src/net/karmaLab/tuxDroid/plugins/MailPlugin.java
Log:
* Changed the file format to Unix. Bouh !
Modified:
software_suite_v3/software/plugin/plugin-email/branches/random_sentences/plugin-email/src/net/karmaLab/tuxDroid/plugins/MailPlugin.java
===================================================================
---
software_suite_v3/software/plugin/plugin-email/branches/random_sentences/plugin-email/src/net/karmaLab/tuxDroid/plugins/MailPlugin.java
2009-10-14 13:29:19 UTC (rev 5660)
+++
software_suite_v3/software/plugin/plugin-email/branches/random_sentences/plugin-email/src/net/karmaLab/tuxDroid/plugins/MailPlugin.java
2009-10-14 13:30:33 UTC (rev 5661)
@@ -1,485 +1,485 @@
-/* This file is part of "TuxDroid Gadget Mail".
- * Copyright 2008, kysoh
- * Author : Yoran Brault
- * eMail : softw...@_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 message.",
- "A new message has arrived !",
- "It appears you have received a new email.",
- "A new message ? I wonder who could be thinking about you.",
- "It would appear you have received new messages."
- };
-
- String[] mailSenderSentences = {
- "Mail sent by {0}",
- "The message was sent by {0}",
- "The sender of the message is {0}"
- };
-
- String[] mailSubjectSentences = {
- "The message subject is : {0}",
- "The subject of the message is : {0}"
- };
-
- String[] noNewMailSentences = {
- "No new mail.",
- "I'm sorry, nobody sent you any messages.",
- "No messages. 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;
- /* 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(this.pickSentence(mailSenderSentences), sender);
-
throwMessage(this.pickSentence(mailSubjectSentences), 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
- ;
- }
-}
+/* This file is part of "TuxDroid Gadget Mail".
+ * Copyright 2008, kysoh
+ * Author : Yoran Brault
+ * eMail : softw...@_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 message.",
+ "A new message has arrived !",
+ "It appears you have received a new email.",
+ "A new message ? I wonder who could be thinking about you.",
+ "It would appear you have received new messages."
+ };
+
+ String[] mailSenderSentences = {
+ "Mail sent by {0}",
+ "The message was sent by {0}",
+ "The sender of the message is {0}"
+ };
+
+ String[] mailSubjectSentences = {
+ "The message subject is : {0}",
+ "The subject of the message is : {0}"
+ };
+
+ String[] noNewMailSentences = {
+ "No new mail.",
+ "I'm sorry, nobody sent you any messages.",
+ "No messages. 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;
+ /* 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(this.pickSentence(mailSenderSentences), sender);
+
throwMessage(this.pickSentence(mailSubjectSentences), 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
+ ;
+ }
+}
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn