Rufnummern-Abgleich Google Contacts
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>WebCallerID</groupId>
|
<groupId>WebCallerID</groupId>
|
||||||
<artifactId>WebCallerID</artifactId>
|
<artifactId>WebCallerID</artifactId>
|
||||||
<version>1.0.2</version>
|
<version>1.1.2</version>
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>mandubian-mvn</id>
|
<id>mandubian-mvn</id>
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import java.net.URL;
|
|||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.mail.Message;
|
import javax.mail.Message;
|
||||||
@@ -23,6 +25,11 @@ import org.apache.log4j.Level;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.apache.log4j.PatternLayout;
|
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.FlaggedOption;
|
||||||
import com.martiansoftware.jsap.JSAP;
|
import com.martiansoftware.jsap.JSAP;
|
||||||
import com.martiansoftware.jsap.JSAPException;
|
import com.martiansoftware.jsap.JSAPException;
|
||||||
@@ -46,6 +53,7 @@ public class CallerIdClient {
|
|||||||
String password;
|
String password;
|
||||||
int updateInterval;
|
int updateInterval;
|
||||||
JSAPResult config;
|
JSAPResult config;
|
||||||
|
LinkedList<String[]> calls = new LinkedList<String[]>();
|
||||||
String cookie = null;
|
String cookie = null;
|
||||||
|
|
||||||
public CallerIdClient(JSAPResult config) {
|
public CallerIdClient(JSAPResult config) {
|
||||||
@@ -63,6 +71,47 @@ public class CallerIdClient {
|
|||||||
|
|
||||||
log.info("logging out");
|
log.info("logging out");
|
||||||
postUrl("https://speedport.ip/auth/logout.cgi?RequestFile=/pub/top_beenden.php&cookie=SessionID_R3," + cookie, "");
|
postUrl("https://speedport.ip/auth/logout.cgi?RequestFile=/pub/top_beenden.php&cookie=SessionID_R3," + cookie, "");
|
||||||
|
|
||||||
|
if (calls.size() > 0) {
|
||||||
|
|
||||||
|
List<ContactEntry> contacts = null;
|
||||||
|
if (config.getString("google username") != null) {
|
||||||
|
log.info("retrieving Google contacts");
|
||||||
|
ContactsService service = new ContactsService("<var>SpeedportCallerIdClient</var>");
|
||||||
|
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) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
@@ -109,7 +158,9 @@ public class CallerIdClient {
|
|||||||
lastCheck.setTimeInMillis(System.currentTimeMillis() - updateInterval * 1000 * 60);
|
lastCheck.setTimeInMillis(System.currentTimeMillis() - updateInterval * 1000 * 60);
|
||||||
|
|
||||||
if (callTime.after(lastCheck)) {
|
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 {
|
private void sendNotification(String time, String caller) throws Exception {
|
||||||
|
|
||||||
if (number.equals(" "))
|
|
||||||
number = TEXT_UNKNOWN;
|
|
||||||
|
|
||||||
String host = config.getString("SMTP server address");
|
String host = config.getString("SMTP server address");
|
||||||
String from = config.getString("e-mail adress");
|
String from = config.getString("e-mail adress");
|
||||||
String pass = config.getString("e-mail password");
|
String pass = config.getString("e-mail password");
|
||||||
@@ -217,10 +264,10 @@ public class CallerIdClient {
|
|||||||
message.addRecipient(Message.RecipientType.TO, toAddress[i]);
|
message.addRecipient(Message.RecipientType.TO, toAddress[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
message.setSubject(TEXT_MAILPREFIX + number);
|
message.setSubject(TEXT_MAILPREFIX + caller);
|
||||||
message.setText(TEXT_MAILPREFIX + number + "\n" + time);
|
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 transport = session.getTransport("smtp");
|
||||||
transport.connect(host, from, pass);
|
transport.connect(host, from, pass);
|
||||||
@@ -265,11 +312,13 @@ public class CallerIdClient {
|
|||||||
recipients.setHelp("e-mail addresses to send notifications to");
|
recipients.setHelp("e-mail addresses to send notifications to");
|
||||||
jsap.registerParameter(recipients);
|
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");
|
googleUsername.setHelp("the Google username for contact name resolution");
|
||||||
jsap.registerParameter(googleUsername);
|
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");
|
googleUsername.setHelp("the Google password for contact name resolution");
|
||||||
jsap.registerParameter(googlePassword);
|
jsap.registerParameter(googlePassword);
|
||||||
|
|
||||||
|
|||||||
@@ -54,33 +54,6 @@ public class GoogleTest {
|
|||||||
}
|
}
|
||||||
System.out.println("\\\t\\\t" + fullNameToDisplay);
|
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 {
|
} else {
|
||||||
System.out.println("\t (no name found)");
|
System.out.println("\t (no name found)");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user