[tuxdroid-svn] r5659 - software_suite_v3/software/plugin/plugin-email/branches/random_sentences/plu
Status: Beta
Brought to you by:
ks156
|
From: ks156 <c2m...@c2...> - 2009-10-14 13:27:35
|
Author: ks156 Date: 2009-10-14 15:27:23 +0200 (Wed, 14 Oct 2009) New Revision: 5659 Modified: software_suite_v3/software/plugin/plugin-email/branches/random_sentences/plugin-email/src/net/karmaLab/tuxDroid/plugins/MailPlugin.java Log: * Re-indented, remove trailing spaces, etc etc. 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:23:08 UTC (rev 5658) +++ software_suite_v3/software/plugin/plugin-email/branches/random_sentences/plugin-email/src/net/karmaLab/tuxDroid/plugins/MailPlugin.java 2009-10-14 13:27:23 UTC (rev 5659) @@ -1,7 +1,8 @@ /* 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) + * 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 @@ -46,52 +47,52 @@ */ public class MailPlugin extends SimplePlugin<Configuration> { - /** - * @param args - * @throws Exception - */ - public static void main(String[] args) throws Exception + /** + * @param args + * @throws Exception + */ + public static void main(String[] args) throws Exception { - new MailPlugin().boot(args, new Configuration()); - } + new MailPlugin().boot(args, new Configuration()); + } /** - * - */ - @Override - public void start() throws Exception + * + */ + @Override + public void start() throws Exception { - if (getCommand().equals("run")) + if (getCommand().equals("run")) { - run(); - } - else if (getCommand().equals("check")) + run(); + } + else if (getCommand().equals("check")) { - check(); - } + check(); + } else { run(); } - } + } /** - * @throws MessagingException - * @throws IOException - * @throws ClassNotFoundException - */ - public void check() throws MessagingException, IOException, ClassNotFoundException, Exception + * @throws MessagingException + * @throws IOException + * @throws ClassNotFoundException + */ + public void check() throws MessagingException, IOException, ClassNotFoundException, Exception { - Message messages[] = connectToMailBox(); + Message messages[] = connectToMailBox(); - if (messages == null) - { - throwResult(false); - return; - } + if (messages == null) + { + throwResult(false); + return; + } String sessionId = configuration().getHost() + "_" + configuration().getUser(); - State stateAlert = readState(State.class, sessionId + "ALERT"); + State stateAlert = readState(State.class, sessionId + "ALERT"); /* Is first check ? */ boolean firstCheck; if (stateAlert.getLastMessages().size() == 0) @@ -104,11 +105,11 @@ 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)) - { + 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) { @@ -118,8 +119,8 @@ stateAlert.getLastMessages().add(subject); } } - } - } + } + } if((newMessageAlert) && (!firstCheck)) { throwResult(true); @@ -129,46 +130,46 @@ { throwResult(false); } - /* Save the current referenced mails */ - writeState(stateAlert, sessionId + "ALERT"); - } + /* Save the current referenced mails */ + writeState(stateAlert, sessionId + "ALERT"); + } - /** - * - * @throws MessagingException - * @throws IOException - * @throws ClassNotFoundException - */ - public void run() throws MessagingException, IOException, ClassNotFoundException + /** + * + * @throws MessagingException + * @throws IOException + * @throws ClassNotFoundException + */ + public void run() throws MessagingException, IOException, ClassNotFoundException { - Message messages[] = connectToMailBox(); - if (messages == null) - { - return; - } + Message messages[] = connectToMailBox(); + if (messages == null) + { + return; + } String sessionId = configuration().getHost() + "_" + configuration().getUser(); - State stateRun = readState(State.class, sessionId + "RUN"); + State stateRun = readState(State.class, sessionId + "RUN"); /* Check for new message */ - boolean newMessageRun = false; + 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; + 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--) - { + /* For all unread mails */ + for (int i = messages.length - 1; i >= 0; i--) + { String subject; String filteredSubject; String sender; @@ -247,20 +248,20 @@ /* 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"); - } + } + 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. @@ -272,19 +273,19 @@ { 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; - } + } + catch (UnknownHostException e) + { + socket = null; + return false; + } + catch (IOException e) + { + socket = null; + return false; + } socket = null; return true; } @@ -359,13 +360,13 @@ } } - /** - * - * @return - * @throws MessagingException - * @throws IOException - * @throws ClassNotFoundException - */ + /** + * + * @return + * @throws MessagingException + * @throws IOException + * @throws ClassNotFoundException + */ private Message[] connectToMailBox() throws MessagingException, IOException, ClassNotFoundException { String user; @@ -384,14 +385,14 @@ 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"); + 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); + props = new Properties(); + session = Session.getDefaultInstance(props, null); /* Find server port */ - port = findMailServerPort(host); + port = findMailServerPort(host); if (port == -1) { throwMessage("Sorry, there was an error when connecting to the mail server. Please check your email configuration."); @@ -404,20 +405,20 @@ /* Connect to the mailbox */ try { - store.connect(host, port, user, password); - } - /* Authentification exception (login / password / protocol / etc) */ - catch (javax.mail.AuthenticationFailedException e) - { + 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) - { + } + /* 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."); @@ -426,23 +427,23 @@ } /* Connect and open inbox folder */ folder = store.getFolder("INBOX"); - folder.open(Folder.READ_ONLY); + folder.open(Folder.READ_ONLY); /* Get messages */ - messages = folder.getMessages(); + messages = folder.getMessages(); return messages; } - @Override - protected void onPluginEvent(String arg0, String[] arg1) throws Throwable - { - // TODO Auto-generated method stub - ; - } + @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 + @Override + protected void onPluginStop() throws Throwable + { + // TODO Auto-generated method stub + ; + } +} |