From 2cb24e089b685569e94bbfe037e9649d589672c6 Mon Sep 17 00:00:00 2001 From: Luke Miller Date: Fri, 29 Oct 2010 19:45:58 +0100 Subject: Added functionality for sending/receiving email. Fixed program hang when monitoring for new email. Added functionality for delivery report via sms. --- workspace/BlaMail/.classpath | 2 + workspace/BlaMail/bin/BlaMail.apk | Bin 235057 -> 283981 bytes workspace/BlaMail/bin/classes.dex | Bin 476252 -> 567060 bytes .../bin/com/blatech/blamail/BlaMail$1.class | Bin 1306 -> 1463 bytes .../bin/com/blatech/blamail/BlaMail$2.class | Bin 1348 -> 1366 bytes .../bin/com/blatech/blamail/BlaMail$3.class | Bin 1174 -> 2101 bytes .../BlaMail/bin/com/blatech/blamail/BlaMail.class | Bin 3849 -> 2892 bytes workspace/BlaMail/bin/resources.ap_ | Bin 11064 -> 11064 bytes .../BlaMail/src/com/blatech/blamail/BlaMail.java | 84 +++++++++++++--- .../src/com/blatech/blamail/GMailSender.java | 106 +++++++++++++++++++++ .../src/com/blatech/blamail/JSSEProvider.java | 51 ++++++++++ 11 files changed, 230 insertions(+), 13 deletions(-) create mode 100644 workspace/BlaMail/src/com/blatech/blamail/GMailSender.java create mode 100644 workspace/BlaMail/src/com/blatech/blamail/JSSEProvider.java diff --git a/workspace/BlaMail/.classpath b/workspace/BlaMail/.classpath index 75d908e..40dad89 100644 --- a/workspace/BlaMail/.classpath +++ b/workspace/BlaMail/.classpath @@ -4,5 +4,7 @@ + + diff --git a/workspace/BlaMail/bin/BlaMail.apk b/workspace/BlaMail/bin/BlaMail.apk index 59acad9..1c09fbb 100644 Binary files a/workspace/BlaMail/bin/BlaMail.apk and b/workspace/BlaMail/bin/BlaMail.apk differ diff --git a/workspace/BlaMail/bin/classes.dex b/workspace/BlaMail/bin/classes.dex index b94b7e2..1a2bed7 100644 Binary files a/workspace/BlaMail/bin/classes.dex and b/workspace/BlaMail/bin/classes.dex differ diff --git a/workspace/BlaMail/bin/com/blatech/blamail/BlaMail$1.class b/workspace/BlaMail/bin/com/blatech/blamail/BlaMail$1.class index 310ff58..62e1e4a 100644 Binary files a/workspace/BlaMail/bin/com/blatech/blamail/BlaMail$1.class and b/workspace/BlaMail/bin/com/blatech/blamail/BlaMail$1.class differ diff --git a/workspace/BlaMail/bin/com/blatech/blamail/BlaMail$2.class b/workspace/BlaMail/bin/com/blatech/blamail/BlaMail$2.class index 55ab08d..7b81c02 100644 Binary files a/workspace/BlaMail/bin/com/blatech/blamail/BlaMail$2.class and b/workspace/BlaMail/bin/com/blatech/blamail/BlaMail$2.class differ diff --git a/workspace/BlaMail/bin/com/blatech/blamail/BlaMail$3.class b/workspace/BlaMail/bin/com/blatech/blamail/BlaMail$3.class index c341144..344cb5e 100644 Binary files a/workspace/BlaMail/bin/com/blatech/blamail/BlaMail$3.class and b/workspace/BlaMail/bin/com/blatech/blamail/BlaMail$3.class differ diff --git a/workspace/BlaMail/bin/com/blatech/blamail/BlaMail.class b/workspace/BlaMail/bin/com/blatech/blamail/BlaMail.class index d94243d..10e33ac 100644 Binary files a/workspace/BlaMail/bin/com/blatech/blamail/BlaMail.class and b/workspace/BlaMail/bin/com/blatech/blamail/BlaMail.class differ diff --git a/workspace/BlaMail/bin/resources.ap_ b/workspace/BlaMail/bin/resources.ap_ index 246f124..f564292 100644 Binary files a/workspace/BlaMail/bin/resources.ap_ and b/workspace/BlaMail/bin/resources.ap_ differ diff --git a/workspace/BlaMail/src/com/blatech/blamail/BlaMail.java b/workspace/BlaMail/src/com/blatech/blamail/BlaMail.java index 864afec..dede9fc 100644 --- a/workspace/BlaMail/src/com/blatech/blamail/BlaMail.java +++ b/workspace/BlaMail/src/com/blatech/blamail/BlaMail.java @@ -39,6 +39,7 @@ import javax.mail.Session; import javax.mail.Store; import javax.mail.event.MessageCountAdapter; import javax.mail.event.MessageCountEvent; +import javax.mail.internet.AddressException; import android.app.Activity; import android.app.PendingIntent; @@ -48,6 +49,9 @@ import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.telephony.SmsManager; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; import android.widget.Toast; import com.sun.mail.imap.IMAPFolder; @@ -65,13 +69,45 @@ public class BlaMail extends Activity { super.onCreate(savedInstanceState); setContentView(R.layout.main); - /** monitor e-mail */ + Thread t = new Thread(new Monitor()); + t.start(); + + Button send = (Button) findViewById(R.id.send); + + send.setOnClickListener(new View.OnClickListener() { + + public void onClick(View view) { + EditText text = (EditText) findViewById(R.id.text); + try { + sendSMS("0000000000000000000", "07927278978", text.getText().toString()); + } catch (AddressException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (MessagingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }); + } + + private class Monitor implements Runnable { + + String id; + String phoneNumber; + String message; + + public void run() { + /** monitor e-mail */ try { Properties props = new Properties(); + + props.put("mail.smtps.auth", "true"); + //IMAPS protocol props.setProperty("mail.store.protocol", "imaps"); - //Set host address + //Set receiveHost address props.setProperty("mail.imaps.host", "imaps.gmail.com"); //Set specified port props.setProperty("mail.imaps.port", "993"); @@ -79,9 +115,9 @@ public class BlaMail extends Activity { props.setProperty("mail.imaps.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.setProperty("mail.imaps.socketFactory.fallback", "false"); //Setting IMAP session - Session imapSession = Session.getInstance(props); + Session session = Session.getInstance(props); - Store store = imapSession.getStore("imaps"); + Store store = session.getStore("imaps"); store.connect(host, user, pass); @@ -100,14 +136,19 @@ public class BlaMail extends Activity { public void messagesAdded(MessageCountEvent ev) { Message[] msgs = ev.getMessages(); try { - sendSMS(msgs[0].getSubject().substring(0, 13), msgs[0].getSubject().substring(14)); + for(int i=0; i 0) + message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients)); + else + message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients)); + Transport.send(message); + }catch(Exception e){ + + } + } + + public class ByteArrayDataSource implements DataSource { + private byte[] data; + private String type; + + public ByteArrayDataSource(byte[] data, String type) { + super(); + this.data = data; + this.type = type; + } + + public ByteArrayDataSource(byte[] data) { + super(); + this.data = data; + } + + public void setType(String type) { + this.type = type; + } + + public String getContentType() { + if (type == null) + return "application/octet-stream"; + else + return type; + } + + public InputStream getInputStream() throws IOException { + return new ByteArrayInputStream(data); + } + + public String getName() { + return "ByteArrayDataSource"; + } + + public OutputStream getOutputStream() throws IOException { + throw new IOException("Not Supported"); + } + } +} diff --git a/workspace/BlaMail/src/com/blatech/blamail/JSSEProvider.java b/workspace/BlaMail/src/com/blatech/blamail/JSSEProvider.java new file mode 100644 index 0000000..2fe1b37 --- /dev/null +++ b/workspace/BlaMail/src/com/blatech/blamail/JSSEProvider.java @@ -0,0 +1,51 @@ +package com.blatech.blamail; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Alexander Y. Kleymenov + * @version $Revision$ + */ + + +import java.security.AccessController; +import java.security.Provider; + +public final class JSSEProvider extends Provider { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public JSSEProvider() { + super("HarmonyJSSE", 1.0, "Harmony JSSE Provider"); + AccessController.doPrivileged(new java.security.PrivilegedAction() { + public Void run() { + put("SSLContext.TLS", + "org.apache.harmony.xnet.provider.jsse.SSLContextImpl"); + put("Alg.Alias.SSLContext.TLSv1", "TLS"); + put("KeyManagerFactory.X509", + "org.apache.harmony.xnet.provider.jsse.KeyManagerFactoryImpl"); + put("TrustManagerFactory.X509", + "org.apache.harmony.xnet.provider.jsse.TrustManagerFactoryImpl"); + return null; + } + }); + } +} -- cgit v1.2.3