diff --git a/WebCallerID/pom.xml b/WebCallerID/pom.xml
index 3d4dc2a..1193200 100755
--- a/WebCallerID/pom.xml
+++ b/WebCallerID/pom.xml
@@ -3,7 +3,7 @@
4.0.0
WebCallerID
WebCallerID
- 1.0.2
+ 1.1.2
mandubian-mvn
diff --git a/WebCallerID/src/main/java/de/tilman/callerId/CallerIdClient.java b/WebCallerID/src/main/java/de/tilman/callerId/CallerIdClient.java
index dc66529..ee0f307 100755
--- a/WebCallerID/src/main/java/de/tilman/callerId/CallerIdClient.java
+++ b/WebCallerID/src/main/java/de/tilman/callerId/CallerIdClient.java
@@ -8,6 +8,8 @@ import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Calendar;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Properties;
import javax.mail.Message;
@@ -23,6 +25,11 @@ import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
+import com.google.gdata.client.Query;
+import com.google.gdata.client.contacts.ContactsService;
+import com.google.gdata.data.contacts.ContactEntry;
+import com.google.gdata.data.contacts.ContactFeed;
+import com.google.gdata.data.extensions.PhoneNumber;
import com.martiansoftware.jsap.FlaggedOption;
import com.martiansoftware.jsap.JSAP;
import com.martiansoftware.jsap.JSAPException;
@@ -46,6 +53,7 @@ public class CallerIdClient {
String password;
int updateInterval;
JSAPResult config;
+ LinkedList calls = new LinkedList();
String cookie = null;
public CallerIdClient(JSAPResult config) {
@@ -63,6 +71,47 @@ public class CallerIdClient {
log.info("logging out");
postUrl("https://speedport.ip/auth/logout.cgi?RequestFile=/pub/top_beenden.php&cookie=SessionID_R3," + cookie, "");
+
+ if (calls.size() > 0) {
+
+ List contacts = null;
+ if (config.getString("google username") != null) {
+ log.info("retrieving Google contacts");
+ ContactsService service = new ContactsService("SpeedportCallerIdClient");
+ service.setUserCredentials(config.getString("google username"), config.getString("google password"));
+ URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/full");
+ Query myQuery = new Query(feedUrl);
+ myQuery.setMaxResults(1000);
+ ContactFeed resultFeed = service.query(myQuery, ContactFeed.class);
+ contacts = resultFeed.getEntries();
+ }
+
+ log.info("sending notifications");
+ for (String[] call : calls) {
+ String time = call[0];
+ String caller = call[1];
+
+ if (caller.equals(" ")) {
+ caller = TEXT_UNKNOWN;
+ }
+ else {
+ numberSearch:
+ for (ContactEntry contact : contacts) {
+ for (PhoneNumber phone : contact.getPhoneNumbers()) {
+ if (phone.getPhoneNumber().endsWith(caller.substring(1))) {
+ if (contact.getName().hasFullName()) {
+ caller = contact.getName().getFullName().getValue() + " (" + caller + ")";
+ log.info("found number in contact data for " + contact.getName().getFullName().getValue());
+ }
+ break numberSearch;
+ }
+ }
+ }
+ }
+
+ sendNotification(time, caller);
+ }
+ }
} catch (Exception e) {
log.error(e.getMessage(), e);
}
@@ -109,7 +158,9 @@ public class CallerIdClient {
lastCheck.setTimeInMillis(System.currentTimeMillis() - updateInterval * 1000 * 60);
if (callTime.after(lastCheck)) {
- sendNotification(result[x].substring(1, 20), result[x].substring(23, result[x].indexOf('"', 23)));
+ String time = result[x].substring(1, 20);
+ String number = result[x].substring(23, result[x].indexOf('"', 23));
+ calls.add(new String[] { time, number });
}
}
}
@@ -183,11 +234,7 @@ public class CallerIdClient {
}
}
- private void sendNotification(String time, String number) throws Exception {
-
- if (number.equals(" "))
- number = TEXT_UNKNOWN;
-
+ private void sendNotification(String time, String caller) throws Exception {
String host = config.getString("SMTP server address");
String from = config.getString("e-mail adress");
String pass = config.getString("e-mail password");
@@ -217,10 +264,10 @@ public class CallerIdClient {
message.addRecipient(Message.RecipientType.TO, toAddress[i]);
}
- message.setSubject(TEXT_MAILPREFIX + number);
- message.setText(TEXT_MAILPREFIX + number + "\n" + time);
+ message.setSubject(TEXT_MAILPREFIX + caller);
+ message.setText(TEXT_MAILPREFIX + caller + "\n" + time);
- log.info("sending message for call from " + number + " at " + time);
+ log.info("sending message for call from " + caller + " at " + time);
Transport transport = session.getTransport("smtp");
transport.connect(host, from, pass);
@@ -265,11 +312,13 @@ public class CallerIdClient {
recipients.setHelp("e-mail addresses to send notifications to");
jsap.registerParameter(recipients);
- FlaggedOption googleUsername = new FlaggedOption("google username").setStringParser(JSAP.STRING_PARSER).setShortFlag('u');
+ FlaggedOption googleUsername = new FlaggedOption("google username").setStringParser(JSAP.STRING_PARSER).setShortFlag(
+ 'u');
googleUsername.setHelp("the Google username for contact name resolution");
jsap.registerParameter(googleUsername);
- FlaggedOption googlePassword = new FlaggedOption("google password").setStringParser(JSAP.STRING_PARSER).setShortFlag('p');
+ FlaggedOption googlePassword = new FlaggedOption("google password").setStringParser(JSAP.STRING_PARSER).setShortFlag(
+ 'p');
googleUsername.setHelp("the Google password for contact name resolution");
jsap.registerParameter(googlePassword);
diff --git a/WebCallerID/src/main/java/de/tilman/callerId/GoogleTest.java b/WebCallerID/src/main/java/de/tilman/callerId/GoogleTest.java
index 26fe8e0..435a1ad 100644
--- a/WebCallerID/src/main/java/de/tilman/callerId/GoogleTest.java
+++ b/WebCallerID/src/main/java/de/tilman/callerId/GoogleTest.java
@@ -54,33 +54,6 @@ public class GoogleTest {
}
System.out.println("\\\t\\\t" + fullNameToDisplay);
}
- if (name.hasNamePrefix()) {
- System.out.println("\\\t\\\t" + name.getNamePrefix().getValue());
- }
- if (name.hasGivenName()) {
- String givenNameToDisplay = name.getGivenName().getValue();
- if (name.getGivenName().hasYomi()) {
- givenNameToDisplay += " (" + name.getGivenName().getYomi() + ")";
- }
- System.out.println("\\\t\\\t" + givenNameToDisplay);
- }
- if (name.hasAdditionalName()) {
- String additionalNameToDisplay = name.getAdditionalName().getValue();
- if (name.getAdditionalName().hasYomi()) {
- additionalNameToDisplay += " (" + name.getAdditionalName().getYomi() + ")";
- }
- System.out.println("\\\t\\\t" + additionalNameToDisplay);
- }
- if (name.hasFamilyName()) {
- String familyNameToDisplay = name.getFamilyName().getValue();
- if (name.getFamilyName().hasYomi()) {
- familyNameToDisplay += " (" + name.getFamilyName().getYomi() + ")";
- }
- System.out.println("\\\t\\\t" + familyNameToDisplay);
- }
- if (name.hasNameSuffix()) {
- System.out.println("\\\t\\\t" + name.getNameSuffix().getValue());
- }
} else {
System.out.println("\t (no name found)");
}