Author: remi
Date: 2009-04-14 11:08:43 +0200 (Tue, 14 Apr 2009)
New Revision: 4499
Removed:
softwares_suite_v3/community/gadget/tuxdroid-gadget-mail/trunk/tuxdroid-gadget-mail/.classpath
softwares_suite_v3/community/gadget/tuxdroid-gadget-mail/trunk/tuxdroid-gadget-mail/.project
softwares_suite_v3/community/gadget/tuxdroid-gadget-mail/trunk/tuxdroid-gadget-mail/.settings/
softwares_suite_v3/community/gadget/tuxdroid-gadget-mail/trunk/tuxdroid-gadget-mail/libraries/
Modified:
softwares_suite_v3/community/gadget/tuxdroid-gadget-mail/trunk/tuxdroid-gadget-mail/pom.xml
softwares_suite_v3/community/gadget/tuxdroid-gadget-mail/trunk/tuxdroid-gadget-mail/resources/gadget.xml
softwares_suite_v3/community/gadget/tuxdroid-gadget-mail/trunk/tuxdroid-gadget-mail/sources/net/karmaLab/tuxDroid/gadgets/MailGadget.java
Log:
* removed unneeded files and directories
* adapted the gadget to perfectly run in the python framework.
* bumped to 2.2
Deleted:
softwares_suite_v3/community/gadget/tuxdroid-gadget-mail/trunk/tuxdroid-gadget-mail/.classpath
===================================================================
---
softwares_suite_v3/community/gadget/tuxdroid-gadget-mail/trunk/tuxdroid-gadget-mail/.classpath
2009-04-14 07:51:05 UTC (rev 4498)
+++
softwares_suite_v3/community/gadget/tuxdroid-gadget-mail/trunk/tuxdroid-gadget-mail/.classpath
2009-04-14 09:08:43 UTC (rev 4499)
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="sources"/>
- <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="lib" path="libraries/javamail-1.4.1.jar"/>
- <classpathentry combineaccessrules="false" kind="src"
path="/tuxdroid-gadget-java-kit"/>
- <classpathentry kind="output" path="targets/eclipse"/>
-</classpath>
Deleted:
softwares_suite_v3/community/gadget/tuxdroid-gadget-mail/trunk/tuxdroid-gadget-mail/.project
===================================================================
---
softwares_suite_v3/community/gadget/tuxdroid-gadget-mail/trunk/tuxdroid-gadget-mail/.project
2009-04-14 07:51:05 UTC (rev 4498)
+++
softwares_suite_v3/community/gadget/tuxdroid-gadget-mail/trunk/tuxdroid-gadget-mail/.project
2009-04-14 09:08:43 UTC (rev 4499)
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>tuxdroid-gadget-mail</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
Modified:
softwares_suite_v3/community/gadget/tuxdroid-gadget-mail/trunk/tuxdroid-gadget-mail/pom.xml
===================================================================
---
softwares_suite_v3/community/gadget/tuxdroid-gadget-mail/trunk/tuxdroid-gadget-mail/pom.xml
2009-04-14 07:51:05 UTC (rev 4498)
+++
softwares_suite_v3/community/gadget/tuxdroid-gadget-mail/trunk/tuxdroid-gadget-mail/pom.xml
2009-04-14 09:08:43 UTC (rev 4499)
@@ -4,7 +4,7 @@
<groupId>com.kysoh</groupId>
<artifactId>tuxdroid-gadget-mail</artifactId>
<packaging>jar</packaging>
- <version>2.1</version>
+ <version>2.2</version>
<name>eMail gadget for Tux Droid</name>
<url>http://www.tuxisalive.com</url>
@@ -13,7 +13,7 @@
<dependency>
<groupId>com.kysoh</groupId>
<artifactId>tuxdroid-gadget-java-kit</artifactId>
- <version>0.0.1</version>
+ <version>0.0.2</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
@@ -84,10 +84,14 @@
<copy
file="${project.build.directory}/${project.artifactId}-${project.version}.jar"
todir="./libraries" />
<zip destfile="./${project.artifactId}.tgf">
- <zipfileset dir="." includes="resources/*"
/>
- <zipfileset dir="." includes="libraries/*"
/>
- <zipfileset dir="."
includes="executables/*" />
- </zip>
+ <zipfileset dir="." includes="resources/*" />
+ <zipfileset dir="." includes="libraries/*" >
+ <exclude name="libraries/tuxdroid-gadget-java-kit*" />
+ <exclude name="libraries/karmalab-commons*" />
+ <exclude name="libraries/tuxdroid-java-api*" />
+ </zipfileset>
+ <zipfileset dir="." includes="executables/*" />
+ </zip>
</tasks>
</configuration>
<goals>
Modified:
softwares_suite_v3/community/gadget/tuxdroid-gadget-mail/trunk/tuxdroid-gadget-mail/resources/gadget.xml
===================================================================
---
softwares_suite_v3/community/gadget/tuxdroid-gadget-mail/trunk/tuxdroid-gadget-mail/resources/gadget.xml
2009-04-14 07:51:05 UTC (rev 4498)
+++
softwares_suite_v3/community/gadget/tuxdroid-gadget-mail/trunk/tuxdroid-gadget-mail/resources/gadget.xml
2009-04-14 09:08:43 UTC (rev 4499)
@@ -8,9 +8,8 @@
<name>Mail Gadget</name>
<description>Mail Gadget</description>
<author>Yoran Brault</author>
- <version>2.1</version>
+ <version>2.2</version>
<iconFile>resources/gadget.png</iconFile>
- <executionMode>service</executionMode>
<uuid>f63af23e-7ae0-4389-b89b-bc5a8185b0c8</uuid>
</description>
<parameters>
@@ -38,15 +37,9 @@
description="Password"
type="string"
defaultValue="your_secret_password" />
- <!-- <parameter
- category="Advances Server parameters"
- name="port"
- description="Server port"
- type="integer"
- defaultValue="-1" /> -->
<parameter
name="folder"
- category="Advanced Server parameters"
+ category="internals"
description="IMAP folder to retreive"
type="string"
defaultValue="INBOX" />
@@ -76,11 +69,11 @@
defaultValue="Re:important document" />
</parameters>
<commands>
- <command
- name="check"
- description="Check if there is any new mail" />
<command
name="run"
description="Read your new mails" />
+ <command
+ name="check"
+ description="Check if there is any new mail" />
</commands>
</gadget>
Modified:
softwares_suite_v3/community/gadget/tuxdroid-gadget-mail/trunk/tuxdroid-gadget-mail/sources/net/karmaLab/tuxDroid/gadgets/MailGadget.java
===================================================================
---
softwares_suite_v3/community/gadget/tuxdroid-gadget-mail/trunk/tuxdroid-gadget-mail/sources/net/karmaLab/tuxDroid/gadgets/MailGadget.java
2009-04-14 07:51:05 UTC (rev 4498)
+++
softwares_suite_v3/community/gadget/tuxdroid-gadget-mail/trunk/tuxdroid-gadget-mail/sources/net/karmaLab/tuxDroid/gadgets/MailGadget.java
2009-04-14 09:08:43 UTC (rev 4499)
@@ -1,355 +1,380 @@
-/* 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.gadgets;
-
-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 com.kysoh.tuxdroid.gadget.framework.gadget.SimpleGadget;
-
-/**
- * @author User
- */
-public class MailGadget extends SimpleGadget<Configuration> {
- /**
- * @param args
- * @throws Exception
- */
- public static void main(String[] args) throws Exception {
- new MailGadget().boot(args, new Configuration());
- }
-
- /**
- *
- * @param readOne
- * @throws MessagingException
- * @throws IOException
- * @throws ClassNotFoundException
- */
- public void mailBox(boolean readOne) throws MessagingException,
IOException, ClassNotFoundException {
- this.configuration().setPort(-1);
- String sessionId = configuration().getHost() + "_" +
configuration().getPort() + "_" + configuration().getUser();
- State stateAlert = readState(State.class, sessionId + "ALERT");
- State stateRun = readState(State.class, sessionId + "RUN");
-
- Security.setProperty("ssl.SocketFactory.provider",
"net.karmaLab.tuxDroid.gadgets.DummySSLSocketFactory");
-
- /* Connect to the mail box */
- System.setProperty("mail.mime.decodetext.strict", "false");
- Properties props = new Properties();
- Session session = Session.getDefaultInstance(props, null);
- Store store =
session.getStore(configuration().getProtocol().toString());
- int port = configuration().getPort();
- if (port == -1) {
- switch (configuration().getProtocol()) {
- case imap:
- port = 143;
- break;
- case pop3:
- port = 110;
- break;
- case imaps:
- port = 993;
- break;
- case pop3s:
- port = 995;
- break;
- }
- }
- try {
- store.connect(configuration().getHost(), port,
configuration().getUser(), configuration().getPassword());
- }
- // Authentification exception (login / password / protocol /
etc)
- catch (javax.mail.AuthenticationFailedException e)
- {
- throwMessage("Sorry, there was an error when connecting to
the mail server. Please check your email configuration.");
- }
- // Connection failed exception (timeout / network unreachable)
- catch (javax.mail.MessagingException e)
- {
- throwMessage("Sorry, I could not connect to the mail
server. Please check your internet connection or try again later.");
- }
-
-
- Folder folder = store.getFolder(configuration().getFolder());
- folder.open(Folder.READ_ONLY);
- Message messages[] = folder.getMessages();
-
- /* Check if you have a new message */
- boolean newMessageAlert = false;
- boolean newMessageRun = false;
- for (int i = 0; i < messages.length; i++) {
- if (!messages[i].getFlags().contains(Flag.SEEN)) {
- if
(!stateAlert.getLastMessages().contains(messages[i].getSubject())) {
- newMessageAlert = true;
- break;
- }
- }
- }
-
- for (int i = 0; i < messages.length; i++) {
- if (!messages[i].getFlags().contains(Flag.SEEN)) {
- if
(!stateRun.getLastMessages().contains(messages[i].getSubject())) {
- newMessageRun = true;
- break;
- }
- }
- }
-
- /* If (ALERT MODE) */
- if (readOne) {
- /* If new message */
- if (newMessageAlert) {
-
- Vector<Boolean> ver = new Vector<Boolean>();
- boolean notify = false;
-
- //Check for allowed messages.
- for(int i = 0; i < messages.length; i++)
- {
- String subject =
messages[i].getSubject();
- String mail =
((InternetAddress)messages[i].getFrom()[0]).getAddress();
- boolean mFilter =
this.filterSender(mail);
- boolean sFilter =
this.filterSubject(subject);
-
- if(mFilter)
- {
- ver.add(new Boolean(false));
- }
-
- else if(sFilter)
- {
- ver.add(new Boolean(false));
- }
-
-
stateAlert.getLastMessages().add(messages[i].getSubject());
- }
-
- for(Boolean bool : ver)
- {
- if(!bool.booleanValue())
- notify = true;
- }
-
- if(notify)
- {
- throwMessage("You have a new message.");
- }
- }
- }
- /* If (RUN MODE) */
- else {
- boolean notifyNoNewMail = true;
- /* If new message */
- if (newMessageRun) {
- int mailCounter = 0;
-
- /* For all unread mails */
- for (int i = 0; i < messages.length; i++) {
- /* Get the subject and the sender of
the current mail */
- String subject =
messages[i].getSubject();
- String sender = ((InternetAddress)
messages[i].getFrom()[0]).getPersonal();
- String mail =
((InternetAddress)messages[i].getFrom()[0]).getAddress();
-
- if (sender == null) {
- sender = ((InternetAddress)
messages[i].getFrom()[0]).getAddress();
- }
-
- /* Filtering the mail address */
- if (sender.contains("<")) {
- sender = sender.substring(0,
sender.indexOf("<"));
- }
-
- /* Filtering the mail subject */
- subject = subject.replace("*", " ");
- subject = subject.replace("_", " ");
- subject = subject.replace("{", " ");
- subject = subject.replace("}", " ");
- subject = subject.replace("[", " ");
- subject = subject.replace("]", " ");
- subject = subject.replace("/", " ");
- subject = subject.replace("\\", " ");
- subject = subject.replace(" ", " ");
-
- /* If the mail is marked as not seen */
- if
(!messages[i].getFlags().contains(Flag.SEEN)) {
- boolean mailAlreadyRead = false;
-
-
if(this.configuration().isSenderFiltered())
- {
- //Set sender filter.
- mailAlreadyRead =
filterSender(mail);
- }
-
- else
if(this.configuration().isSubjectFiltered())
- {
- //Set subject filter.
- mailAlreadyRead =
filterSubject(subject);
- }
-
- else
- {
- /* Check if the mail is
not already read */
- for (int j = 0; j <
stateRun.getLastMessages().size(); j++) {
- if
(subject.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) {
- //TODO set
filters.
-
throwMessage("Mail sent by {0}", sender);
-
throwMessage("The message subject is : {0}", subject);
- }
-
- /* Referencing the
current mail */
-
stateRun.getLastMessages().add(messages[i].getSubject());
-
- }
- }
- }
- if(notifyNoNewMail)
- {
- throwMessage("No new mail.");
- }
- }
- /* No new message */
- else {
- throwMessage("No new mail.");
- }
- }
-
- /* Save the current referenced mails */
- writeState(stateAlert, sessionId + "ALERT");
- writeState(stateRun, sessionId + "RUN");
- }
-
-
- /**
- * Return true if the sender is not allowed.
- * @param mail
- * @return
- */
- private boolean filterSender(String mail)
- {
- Vector<Boolean> ver = new Vector<Boolean>();
- for(String allowedSender :
this.configuration().getSenderFilter())
- {
- if(!mail.equals(allowedSender))
- {
- ver.add(new Boolean(false));
- }
- }
-
- for(Boolean bool : ver)
- {
- if(!bool.booleanValue())
- {
- return true;
- }
- }
-
- return false;
- }
-
-
- /**
- * Return true if subject is not allowed.
- * @param subject
- * @return
- */
- private boolean filterSubject(String subject)
- {
- Vector<Boolean> ver = new Vector<Boolean>();
- for(String allowedContent :
this.configuration().getSubjectFilter())
- {
- if(!subject.contains(allowedContent))
- {
- ver.add(new Boolean(false));
- }
- }
-
- for(Boolean bool : ver)
- {
- if(!bool.booleanValue())
- {
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * @throws MessagingException
- * @throws IOException
- * @throws ClassNotFoundException
- */
- public void check() throws MessagingException, IOException,
ClassNotFoundException {
- mailBox(true);
- }
-
- /**
- *
- * @throws MessagingException
- * @throws IOException
- * @throws ClassNotFoundException
- */
- public void run() throws MessagingException, IOException,
ClassNotFoundException {
- mailBox(false);
- }
-
- /**
- *
- */
- @Override
- public void start() throws Exception {
-
- if (getCommand().equals("check")) {
- check();
- return;
- }
- else if (getCommand().equals("run")) {
- run();
- return;
- }
- }
-
-}
+/* 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.gadgets;
+
+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 com.kysoh.tuxdroid.gadget.framework.gadget.SimpleGadget;
+
+/**
+ * @author User
+ */
+public class MailGadget extends SimpleGadget<Configuration>
+{
+ /**
+ * @param args
+ * @throws Exception
+ */
+ public static void main(String[] args) throws Exception
+ {
+ new MailGadget().boot(args, new Configuration());
+ }
+
+ /**
+ *
+ */
+ @Override
+ public void start() throws Exception
+ {
+ if (getCommand().equals("run"))
+ {
+ run();
+ }
+ else if (getCommand().equals("check"))
+ {
+ check();
+ }
+ else
+ {
+ run();
+ }
+ }
+
+ /**
+ *
+ */
+ @Override
+ public void onGadgetStop() {}
+
+ /**
+ * @throws MessagingException
+ * @throws IOException
+ * @throws ClassNotFoundException
+ */
+ public void check() throws MessagingException, IOException,
ClassNotFoundException
+ {
+ Message messages[] = connectToMailBox();
+ if (messages == null)
+ {
+ throwResult(false);
+ return;
+ }
+ String sessionId = configuration().getHost() + "_" +
configuration().getPort() + "_" + configuration().getUser();
+ State stateAlert = readState(State.class, sessionId + "ALERT");
+ /* Check if you have a new message */
+ boolean newMessageAlert = false;
+ for (int i = 0; i < messages.length; i++)
+ {
+ if (!messages[i].getFlags().contains(Flag.SEEN))
+ {
+ if
(!stateAlert.getLastMessages().contains(messages[i].getSubject()))
+ {
+ newMessageAlert = true;
+ break;
+ }
+ }
+ }
+ /* If new message */
+ if (newMessageAlert)
+ {
+ Vector<Boolean> ver = new Vector<Boolean>();
+ boolean notify = false;
+ //Check for allowed messages.
+ for(int i = 0; i < messages.length; i++)
+ {
+ String subject = messages[i].getSubject();
+ String mail =
((InternetAddress)messages[i].getFrom()[0]).getAddress();
+ boolean mFilter = this.filterSender(mail);
+ boolean sFilter = this.filterSubject(subject);
+ if(mFilter)
+ {
+ ver.add(new Boolean(false));
+ }
+ else if(sFilter)
+ {
+ ver.add(new Boolean(false));
+ }
+
stateAlert.getLastMessages().add(messages[i].getSubject());
+ }
+ for(Boolean bool : ver)
+ {
+ if(!bool.booleanValue())
+ {
+ notify = true;
+ break;
+ }
+ }
+ if(notify)
+ {
+ throwResult(true);
+ }
+ 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().getPort() + "_" + configuration().getUser();
+ State stateRun = readState(State.class, sessionId + "RUN");
+ /* Check if you have a new message */
+ boolean newMessageRun = false;
+ for (int i = 0; i < messages.length; i++)
+ {
+ if (!messages[i].getFlags().contains(Flag.SEEN))
+ {
+ if
(!stateRun.getLastMessages().contains(messages[i].getSubject()))
+ {
+ newMessageRun = true;
+ break;
+ }
+ }
+ }
+ boolean notifyNoNewMail = true;
+ /* If new message */
+ if (newMessageRun)
+ {
+ int mailCounter = 0;
+
+ /* For all unread mails */
+ for (int i = 0; i < messages.length; i++)
+ {
+ /* Get the subject and the sender of the
current mail */
+ String subject = messages[i].getSubject();
+ String sender = ((InternetAddress)
messages[i].getFrom()[0]).getPersonal();
+ String mail =
((InternetAddress)messages[i].getFrom()[0]).getAddress();
+ if (sender == null)
+ {
+ sender = ((InternetAddress)
messages[i].getFrom()[0]).getAddress();
+ }
+ /* Filtering the mail address */
+ if (sender.contains("<"))
+ {
+ sender = sender.substring(0,
sender.indexOf("<"));
+ }
+ /* Filtering the mail subject */
+ subject = subject.replace("*", " ");
+ subject = subject.replace("_", " ");
+ subject = subject.replace("{", " ");
+ subject = subject.replace("}", " ");
+ subject = subject.replace("[", " ");
+ subject = subject.replace("]", " ");
+ subject = subject.replace("/", " ");
+ subject = subject.replace("\\", " ");
+ subject = subject.replace(" ", " ");
+ /* If the mail is marked as not seen */
+ if (!messages[i].getFlags().contains(Flag.SEEN))
+ {
+ boolean mailAlreadyRead = false;
+
if(this.configuration().isSenderFiltered())
+ {
+ //Set sender filter.
+ mailAlreadyRead =
filterSender(mail);
+ }
+ else
if(this.configuration().isSubjectFiltered())
+ {
+ //Set subject filter.
+ mailAlreadyRead =
filterSubject(subject);
+ }
+ else
+ {
+ /* Check if the mail is not
already read */
+ for (int j = 0; j <
stateRun.getLastMessages().size(); j++)
+ {
+ if
(subject.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}", subject);
+ }
+ /* Referencing the current mail
*/
+
stateRun.getLastMessages().add(messages[i].getSubject());
+
+ }
+ }
+ }
+ if(notifyNoNewMail)
+ {
+ throwMessage("No new mail.");
+ }
+ }
+ /* No new message */
+ else
+ {
+ throwMessage("No new mail.");
+ }
+ /* Save the current referenced mails */
+ writeState(stateRun, sessionId + "RUN");
+ }
+
+ /**
+ *
+ * @return
+ * @throws MessagingException
+ * @throws IOException
+ * @throws ClassNotFoundException
+ */
+ private Message[] connectToMailBox() throws MessagingException,
IOException, ClassNotFoundException
+ {
+ this.configuration().setPort(-1);
+ Security.setProperty("ssl.SocketFactory.provider",
"net.karmaLab.tuxDroid.gadgets.DummySSLSocketFactory");
+ /* Connect to the mail box */
+ System.setProperty("mail.mime.decodetext.strict", "false");
+ Properties props = new Properties();
+ Session session = Session.getDefaultInstance(props, null);
+ Store store =
session.getStore(configuration().getProtocol().toString());
+ int port = configuration().getPort();
+ if (port == -1)
+ {
+ switch (configuration().getProtocol())
+ {
+ case imap:
+ port = 143;
+ break;
+ case pop3:
+ port = 110;
+ break;
+ case imaps:
+ port = 993;
+ break;
+ case pop3s:
+ port = 995;
+ break;
+ }
+ }
+ try
+ {
+ store.connect(configuration().getHost(), port,
configuration().getUser(), configuration().getPassword());
+ }
+ // 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;
+ }
+ Folder folder = store.getFolder(configuration().getFolder());
+ folder.open(Folder.READ_ONLY);
+ Message messages[] = folder.getMessages();
+ return messages;
+ }
+
+ /**
+ * Return true if the sender is not allowed.
+ * @param mail
+ * @return
+ */
+ private boolean filterSender(String mail)
+ {
+ Vector<Boolean> ver = new Vector<Boolean>();
+ for(String allowedSender :
this.configuration().getSenderFilter())
+ {
+ if(!mail.equals(allowedSender))
+ {
+ ver.add(new Boolean(false));
+ }
+ }
+ for(Boolean bool : ver)
+ {
+ if(!bool.booleanValue())
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Return true if subject is not allowed.
+ * @param subject
+ * @return
+ */
+ private boolean filterSubject(String subject)
+ {
+ Vector<Boolean> ver = new Vector<Boolean>();
+ for(String allowedContent :
this.configuration().getSubjectFilter())
+ {
+ if(!subject.contains(allowedContent))
+ {
+ ver.add(new Boolean(false));
+ }
+ }
+ for(Boolean bool : ver)
+ {
+ if(!bool.booleanValue())
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+}
------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn