Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="libs/imap.jar"/>
<classpathentry exported="true" kind="lib" path="libs/mailapi.jar"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
Expand Down
Binary file added libs/imap.jar
Binary file not shown.
Binary file added libs/mailapi.jar
Binary file not shown.
13 changes: 13 additions & 0 deletions res/layout/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@
android:enabled="true"
android:defaultValue="3"
/>

<EditTextPreference
android:title="@string/settings_GmailUsername"
android:key="GmailUsername"
android:summary="@string/settings_GmailUsername_desc"
/>
<EditTextPreference
android:title="@string/settings_GmailPassword"
android:key="GmailPassword"
android:summary="@string/settings_GmailPassword_desc"
/>


<CheckBoxPreference
android:title="@string/settings_K9"
android:key="NotifyK9"
Expand Down
4 changes: 4 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<string name="settings_Gmail">Gmail</string>
<string name="settings_Gmail_desc">New E-mail notification (Gmail)</string>
<string name="settings_Gmail_Vibrate_Pattern">Gmail Vibrate Pattern</string>
<string name="settings_GmailUsername">Gmail Username</string>
<string name="settings_GmailUsername_desc"></string>
<string name="settings_GmailPassword">Gmail Password</string>
<string name="settings_GmailPassword_desc"></string>
<string name="settings_K9">K-9 mail</string>
<string name="settings_K9_desc">New E-mail notification (K-9 mail)</string>
<string name="settings_K9_Vibrate_Pattern">K-9 Vibrate Pattern</string>
Expand Down
53 changes: 53 additions & 0 deletions src/org/metawatch/manager/GMailReader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.metawatch.manager;

import java.util.Properties;

import javax.mail.*;

import android.util.Log;

public class GMailReader extends javax.mail.Authenticator {
private static final String TAG = "GMailReader";

private String mailhost = "imap.gmail.com";
private Session session;
private Store store;

public GMailReader(String user, String password) {
Properties props = System.getProperties();
if (props == null){
Log.e(TAG, "Properties are null !!");
}else{
props.setProperty("mail.store.protocol", "imaps");

Log.d(TAG, "Transport: "+props.getProperty("mail.transport.protocol"));
Log.d(TAG, "Store: "+props.getProperty("mail.store.protocol"));
Log.d(TAG, "Host: "+props.getProperty("mail.imap.host"));
Log.d(TAG, "Authentication: "+props.getProperty("mail.imap.auth"));
Log.d(TAG, "Port: "+props.getProperty("mail.imap.port"));
}
try {
session = Session.getDefaultInstance(props, null);
store = session.getStore("imaps");
store.connect(mailhost, user, password);
Log.i(TAG, "Store: "+store.toString());
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public synchronized Message readMail() throws Exception {
try {
Folder folder = store.getFolder("Inbox");
folder.open(Folder.READ_ONLY);

Message msg = folder.getMessage(folder.getMessageCount());
return msg;

} catch (Exception e) {
Log.e("readMail", e.getMessage(), e);
return null;
}
}
}
19 changes: 18 additions & 1 deletion src/org/metawatch/manager/GmailAPIMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
import java.util.ArrayList;
import java.util.List;

import javax.mail.Address;
import javax.mail.Message;

import org.metawatch.manager.MetaWatchService.Preferences;

import com.google.android.gm.contentprovider.GmailContract;
Expand Down Expand Up @@ -177,7 +180,21 @@ public void onChange(boolean selfChange) {

}
}
NotificationBuilder.createGmailBlank(context, recipient, currentUnreadCount);

try {
GMailReader g = new GMailReader(Preferences.GmailUsername, Preferences.GmailPassword);
Message m = g.readMail();

Address[] a = m.getFrom();
String from = a[0].toString().replaceAll("<(.*?)>", "").trim();

NotificationBuilder.createGmailBlank(context, recipient, currentUnreadCount, m.getSubject(), from);

} catch (Exception e) {
if (Preferences.logging)
Log.d(MetaWatch.TAG, "GmailAPIMonitor.onChange(): caught exception: " + e.toString());
}

}

if (currentUnreadCount != lastUnreadCount)
Expand Down
2 changes: 1 addition & 1 deletion src/org/metawatch/manager/IntentReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void onReceive(Context context, Intent intent) {
/* This is a new message notification. */
if (count > 0) {
NotificationBuilder.createGmailBlank(context,
recipient, count);
recipient, count, "", "");
if (Preferences.logging) Log.d(MetaWatch.TAG,
"Received Gmail new message notification; "
+ count + " new message(s).");
Expand Down
4 changes: 4 additions & 0 deletions src/org/metawatch/manager/MetaWatchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ public static class Preferences {
public static boolean displayWidgetIconOnTop = true;
public static String displayCalendars = "";
public static int calendarLookahead = 24;
public static String GmailUsername = "";
public static String GmailPassword = "";
}

public final class WatchType {
Expand Down Expand Up @@ -397,6 +399,8 @@ public static void loadPreferences(Context context) {
Preferences.displayCalendars = sharedPreferences.getString("DisplayCalendars",
Preferences.displayCalendars);

Preferences.GmailUsername = sharedPreferences.getString("GmailUsername", Preferences.GmailUsername);
Preferences.GmailPassword = sharedPreferences.getString("GmailPassword", Preferences.GmailPassword);

boolean silent = sharedPreferences.getBoolean("SilentMode", silentMode );
if (silent!=silentMode)
Expand Down
11 changes: 5 additions & 6 deletions src/org/metawatch/manager/NotificationBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,17 @@ public static void createGmail(Context context, String sender, String email, Str
}
}

public static void createGmailBlank(Context context, String recipient, int count) {
public static void createGmailBlank(Context context, String recipient, int count, String subject, String from) {
VibratePattern vibratePattern = createVibratePatternFromPreference(context, "settingsGmailNumberBuzzes");
String messages = count + " new " + (count == 1 ? "message" : "messages");
String messages = "From: " + from;
Bitmap icon = Utils.getBitmap(context, "gmail.bmp");
String description = "Gmail: unread "+count;
if (MetaWatchService.watchType == WatchType.DIGITAL) {
Bitmap bitmap = smartLines(context, icon, "Gmail", new String[] {messages, recipient});
Notification.addBitmapNotification(context, bitmap, vibratePattern, Notification.getDefaultNotificationTimeout(context), description);
Bitmap bitmap = smartLines(context, icon, "Gmail", new String[] {messages, subject});
Notification.addBitmapNotification(context, bitmap, vibratePattern, Notification.getDefaultNotificationTimeout(context), subject);
} else {
byte[] scroll = new byte[800];
int len = Protocol.createOled2linesLong(context, recipient, scroll);
Notification.addOledNotification(context, Protocol.createOled1line(context, icon, " Gmail"), Protocol.createOled2lines(context, messages, recipient), scroll, len, vibratePattern, description);
Notification.addOledNotification(context, Protocol.createOled1line(context, icon, " Gmail"), Protocol.createOled2lines(context, messages, recipient), scroll, len, vibratePattern, subject);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/org/metawatch/manager/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public boolean onPreferenceClick(Preference arg0) {

preferenceScreen.findPreference("gmail_short").setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference arg0) {
NotificationBuilder.createGmailBlank(context, "me@gmail.com", 513);
NotificationBuilder.createGmailBlank(context, "me@gmail.com", 513, "", "");
return true;
}
});
Expand Down