[tuxdroid-svn] r5619 - in software_suite_v3/software/plugin/plugin-gmail/trunk/plugin-gmail: resou
Status: Beta
Brought to you by:
ks156
|
From: remi <c2m...@c2...> - 2009-10-09 10:19:47
|
Author: remi
Date: 2009-10-09 12:19:39 +0200 (Fri, 09 Oct 2009)
New Revision: 5619
Removed:
software_suite_v3/software/plugin/plugin-gmail/trunk/plugin-gmail/src/net/karmaLab/tuxDroid/plugins/ServerProtocol.java
Modified:
software_suite_v3/software/plugin/plugin-gmail/trunk/plugin-gmail/resources/plugin.xml
software_suite_v3/software/plugin/plugin-gmail/trunk/plugin-gmail/src/net/karmaLab/tuxDroid/plugins/Configuration.java
software_suite_v3/software/plugin/plugin-gmail/trunk/plugin-gmail/src/net/karmaLab/tuxDroid/plugins/MailPlugin.java
Log:
* Applied same changes than email plugin
Modified: software_suite_v3/software/plugin/plugin-gmail/trunk/plugin-gmail/resources/plugin.xml
===================================================================
--- software_suite_v3/software/plugin/plugin-gmail/trunk/plugin-gmail/resources/plugin.xml 2009-10-09 10:11:12 UTC (rev 5618)
+++ software_suite_v3/software/plugin/plugin-gmail/trunk/plugin-gmail/resources/plugin.xml 2009-10-09 10:19:39 UTC (rev 5619)
@@ -26,47 +26,6 @@
description="Password"
type="password"
defaultValue="password" />
- <!-- <parameter
- category="Advances Server parameters"
- name="port"
- description="Server port"
- type="integer"
- defaultValue="-1" /> -->
- <parameter
- name="folder"
- category="Advanced Server parameters"
- description="IMAP folder to retreive"
- type="string"
- defaultValue="INBOX"
- visible="false" />
- <parameter
- name="filterSender"
- category= "User parameters"
- description="Use sender filter"
- type="boolean"
- defaultValue="false"
- visible="false" />
- <parameter
- name="senderFilter"
- category= "User parameters"
- description="Sender filter to apply"
- type="string"
- defaultValue="bo...@my...,myg...@ho..."
- visible="false" />
- <parameter
- name="filerSubject"
- category= "User parameters"
- description="Use subject filter"
- type="boolean"
- defaultValue="false"
- visible="false" />
- <parameter
- name="subjectFilter"
- category= "User parameters"
- description="Subject filter to apply"
- type="string"
- defaultValue="Re:important document"
- visible="false" />
</parameters>
<tasks>
<task
@@ -75,41 +34,11 @@
command="check"
type="every x"
activated="false"
-
- weekMask="true,true,true,true,true,true,true"
- weekMaskType="weekpart"
- weekMaskVisible="true"
delay="00:01:00"
delayMask="true,true,true"
delayVisible="false"
/>
- <task
- name="Start every x from full hour"
- description="Start me every x (From full hour)"
- command="run"
- type="every x from full hour"
- activated="false"
-
- weekMask="true,true,true,true,true,true,true"
- weekMaskType="weekpart"
- weekMaskVisible="true"
-
- date="0000/00/00"
- dateVisible="false"
-
- hoursBegin="00:00:00"
- hoursBeginMask="true,true,true"
- hoursBeginVisible="false"
-
- hoursEnd="23:59:00"
- hoursEndMask="true,true,true"
- hoursEndVisible="false"
-
- delay="00:15:00"
- delayMask="true,true,false"
- delayVisible="true"
- />
</tasks>
<commands>
<command
Modified: software_suite_v3/software/plugin/plugin-gmail/trunk/plugin-gmail/src/net/karmaLab/tuxDroid/plugins/Configuration.java
===================================================================
--- software_suite_v3/software/plugin/plugin-gmail/trunk/plugin-gmail/src/net/karmaLab/tuxDroid/plugins/Configuration.java 2009-10-09 10:11:12 UTC (rev 5618)
+++ software_suite_v3/software/plugin/plugin-gmail/trunk/plugin-gmail/src/net/karmaLab/tuxDroid/plugins/Configuration.java 2009-10-09 10:19:39 UTC (rev 5619)
@@ -29,37 +29,10 @@
public class Configuration extends SimplePluginConfiguration
{
- private String host;
- private int port;
- private ServerProtocol protocol;
private String password;
private String user;
- private String folder;
-
- private boolean filerSubject;
- private boolean filterSender;
-
- private String subjectFilter;
- private String senderFilter;
/**
- * @return the folder
- */
- public String getFolder()
- {
- return folder;
- }
-
- /**
- * @param folder
- * the folder to set
- */
- public void setFolder(String folder)
- {
- this.folder = folder;
- }
-
- /**
* @return the password
*/
public String getPassword()
@@ -92,112 +65,4 @@
{
this.user = user;
}
-
- /**
- * @return the port
- */
- public int getPort()
- {
- return port;
- }
-
- /**
- * @param port
- * the port to set
- */
- public void setPort(int port)
- {
- this.port = port;
- }
-
- /**
- * @return the kind
- */
- public ServerProtocol getProtocol()
- {
- return protocol;
- }
-
- /**
- * @param kind
- * the kind to set
- */
- public void setProtocol(ServerProtocol kind)
- {
- this.protocol = kind;
- }
-
- /**
- *
- * @return
- */
- public String getHost()
- {
- return host;
- }
-
- /**
- *
- * @param host
- */
- public void setHost(String host)
- {
- this.host = host;
- }
-
-
- /**
- * Return true if sender is filtered.
- * @return
- */
- public boolean isSenderFiltered()
- {
- return this.filterSender;
- }
-
-
- /**
- * Return true if Subject is filtered.
- * @return
- */
- public boolean isSubjectFiltered()
- {
- return this.filerSubject;
- }
-
-
- /**
- * Return a list of allowed sender.
- * @return
- */
- public Vector<String> getSenderFilter()
- {
- Vector<String> ret = new Vector<String>();
- String value = this.senderFilter;
- while(value.contains(","))
- {
- ret.add(value.substring(0, value.indexOf(",")));
- value = value.substring(value.indexOf(",") + 1);
- }
- ret.add(value);
- return ret;
- }
-
-
- /**
- * Return a list of allowed words.
- * @return
- */
- public Vector<String> getSubjectFilter()
- {
- Vector<String> ret = new Vector<String>();
- String value = this.subjectFilter;
- while(value.contains(","))
- {
- ret.add(value.substring(0, value.indexOf(",")));
- value = value.substring(value.indexOf(",") + 1);
- }
- ret.add(value);
- return ret;
- }
}
\ No newline at end of file
Modified: software_suite_v3/software/plugin/plugin-gmail/trunk/plugin-gmail/src/net/karmaLab/tuxDroid/plugins/MailPlugin.java
===================================================================
--- software_suite_v3/software/plugin/plugin-gmail/trunk/plugin-gmail/src/net/karmaLab/tuxDroid/plugins/MailPlugin.java 2009-10-09 10:11:12 UTC (rev 5618)
+++ software_suite_v3/software/plugin/plugin-gmail/trunk/plugin-gmail/src/net/karmaLab/tuxDroid/plugins/MailPlugin.java 2009-10-09 10:19:39 UTC (rev 5619)
@@ -57,9 +57,6 @@
@Override
public void start()
{
- this.configuration().setHost("pop.gmail.com");
- this.configuration().setProtocol(ServerProtocol.pop3s);
-
try
{
if (getCommand().equals("run"))
@@ -86,7 +83,6 @@
*/
public void check() throws MessagingException, IOException, ClassNotFoundException, Exception
{
- boolean notify = false;
Message messages[] = connectToMailBox();
if (messages == null)
@@ -94,7 +90,7 @@
throwResult(false);
return;
}
- String sessionId = configuration().getHost() + "_" + configuration().getPort() + "_" + configuration().getUser();
+ String sessionId = "pop.gmail.com_" + configuration().getUser();
State stateAlert = readState(State.class, sessionId + "ALERT");
/* Is first check ? */
boolean firstCheck;
@@ -119,57 +115,12 @@
if (!stateAlert.getLastMessages().contains(subject))
{
newMessageAlert = true;
- break;
+ stateAlert.getLastMessages().add(subject);
}
}
}
}
- /* If new message */
- if (newMessageAlert)
- {
- /* Check for allowed messages. */
- for(int i = messages.length - 1; i >= 0; i--)
- {
- String subject;
- String mail;
- boolean seen;
-
- try
- {
- /* Get mail data */
- subject = messages[i].getSubject();
- mail = ((InternetAddress)messages[i].getFrom()[0]).getAddress();
- seen = messages[i].getFlags().contains(Flag.SEEN);
- /* Pass if mail is already seen */
- if (seen)
- {
- continue;
- }
- /* Pass if empty subject */
- if (subject == null)
- {
- continue;
- }
- /* Check if the mail already read */
- for (int j = 0; j < stateAlert.getLastMessages().size(); j++)
- {
- if (!subject.equals(stateAlert.getLastMessages().get(j)))
- {
- notify = true;
- break;
- }
- }
- /* Referencing the current mail */
- stateAlert.getLastMessages().add(subject);
- }
- catch (Exception e)
- {
- /* Prevent unhandled errors */
- ;
- }
- }
- }
- if((notify) && (!firstCheck))
+ if((newMessageAlert) && (!firstCheck))
{
throwResult(true);
throwMessage("You have a new message.");
@@ -195,7 +146,7 @@
{
return;
}
- String sessionId = configuration().getHost() + "_" + configuration().getPort() + "_" + configuration().getUser();
+ String sessionId = "pop.gmail.com_" + configuration().getUser();
State stateRun = readState(State.class, sessionId + "RUN");
/* Check for new message */
boolean newMessageRun = false;
@@ -320,37 +271,40 @@
*/
private Message[] connectToMailBox() throws MessagingException, IOException, ClassNotFoundException
{
- this.configuration().setPort(-1);
+ 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 = "pop.gmail.com";
+ /* Set ssl socket */
Security.setProperty("ssl.SocketFactory.provider", "net.karmaLab.tuxDroid.plugins.DummySSLSocketFactory");
- /* Connect to the mail box */
+ /* Set text decoder */
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;
- }
- }
+ /* Configure seesion */
+ props = new Properties();
+ session = Session.getDefaultInstance(props, null);
+ /* Find server port */
+ port = 995;
+ /* Get mail protocol */
+ protocol = "pop3s";
+ /* Create mail store */
+ store = session.getStore(protocol);
+ /* Connect to the mailbox */
try
{
- store.connect(configuration().getHost(), port, configuration().getUser(), configuration().getPassword());
+ store.connect(host, port, user, password);
}
- // Authentification exception (login / password / protocol / etc)
+ /* Authentification exception (login / password / protocol / etc) */
catch (javax.mail.AuthenticationFailedException e)
{
if (!getCommand().equals("check"))
@@ -367,7 +321,7 @@
}
return null;
}
- // Connection failed exception (timeout / network unreachable)
+ /* Connection failed exception (timeout / network unreachable) */
catch (javax.mail.MessagingException e)
{
if (!getCommand().equals("check"))
@@ -376,62 +330,14 @@
}
return null;
}
- Folder folder = store.getFolder(configuration().getFolder());
+ /* Connect and open inbox folder */
+ folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
- Message messages[] = folder.getMessages();
+ /* Get messages */
+ 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;
- }
-
@Override
protected void onPluginEvent(String arg0, String[] arg1) throws Throwable
{
Deleted: software_suite_v3/software/plugin/plugin-gmail/trunk/plugin-gmail/src/net/karmaLab/tuxDroid/plugins/ServerProtocol.java
===================================================================
--- software_suite_v3/software/plugin/plugin-gmail/trunk/plugin-gmail/src/net/karmaLab/tuxDroid/plugins/ServerProtocol.java 2009-10-09 10:11:12 UTC (rev 5618)
+++ software_suite_v3/software/plugin/plugin-gmail/trunk/plugin-gmail/src/net/karmaLab/tuxDroid/plugins/ServerProtocol.java 2009-10-09 10:19:39 UTC (rev 5619)
@@ -1,27 +0,0 @@
-/* This file is part of "TuxDroid Gadget GMail".
- * 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 GMail" 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 GMail" 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 GMail"; 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;
-
-public enum ServerProtocol {
- pop3, imap, imaps, pop3s;
-}
\ No newline at end of file
|