Compare commits

1 Commits

Author SHA1 Message Date
tilman 71af095301 Header eclipse 2012-09-11 10:10:13 +02:00
5 changed files with 31 additions and 15 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
eclipse II
Test eclipse
https://speedport.ip/index/login.cgi
@@ -1,4 +1,4 @@
package de.tilman.callerid;
package de.tilman.callerId;
import java.io.BufferedReader;
import java.io.InputStreamReader;
@@ -30,6 +30,7 @@ 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;
import com.martiansoftware.jsap.JSAPResult;
@@ -74,10 +75,10 @@ public class CallerIdClient {
if (calls.size() > 0) {
List<ContactEntry> contacts = null;
if (config.getBoolean("check contacts")) {
if (config.getString("google username") != null) {
log.info("retrieving Google contacts");
ContactsService service = new ContactsService("<var>SpeedportCallerIdClient</var>");
service.setUserCredentials(config.getString("e-mail adress"), config.getString("e-mail password"));
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);
@@ -186,6 +187,9 @@ public class CallerIdClient {
if (cookie != null) {
connection.setRequestProperty("Cookie", "SessionID_R3=" + cookie);
}
// connection.setRequestProperty("Referer",
// "https://speedport.ip/auth/hcti_status_telanrl.php?cookie=SessionID_R3,"
// + cookie);
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
if (payload.length() > 0) {
@@ -231,15 +235,17 @@ public class CallerIdClient {
}
private void sendNotification(String time, String caller) throws Exception {
String host = "smtp.gmail.com";
String host = config.getString("SMTP server address");
String from = config.getString("e-mail adress");
String pass = config.getString("e-mail password");
Properties props = System.getProperties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.ssl.enable", "true");
// props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", "587");
props.put("mail.smtp.port", "465");
// props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
String[] to = config.getStringArray("recipient");
@@ -269,10 +275,9 @@ public class CallerIdClient {
transport.close();
}
@SuppressWarnings("rawtypes")
public static void main(String[] args) {
BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%d{ISO8601} - %m%n")));
log.info("Starting CallerIdClient version 1.1.2");
log.info("Starting CallerIdClient version 1.0.2");
JSAP jsap = new JSAP();
@@ -287,14 +292,19 @@ public class CallerIdClient {
updateInterval.setHelp("the interval beetween runs in minutes");
jsap.registerParameter(updateInterval);
UnflaggedOption smtpServer = new UnflaggedOption("SMTP server address").setStringParser(JSAP.STRING_PARSER)
.setRequired(true);
smtpServer.setHelp("the SMTP server to send notifications with");
jsap.registerParameter(smtpServer);
UnflaggedOption fromAddress = new UnflaggedOption("e-mail adress").setStringParser(JSAP.STRING_PARSER).setRequired(
true);
fromAddress.setHelp("Google mail address to send from");
fromAddress.setHelp("e-mail address to send from");
jsap.registerParameter(fromAddress);
UnflaggedOption emailPassword = new UnflaggedOption("e-mail password").setStringParser(JSAP.STRING_PARSER)
.setRequired(true);
emailPassword.setHelp("the login password for the Google account");
emailPassword.setHelp("the login password for the e-mail account");
jsap.registerParameter(emailPassword);
UnflaggedOption recipients = new UnflaggedOption("recipient").setStringParser(JSAP.STRING_PARSER).setRequired(true)
@@ -302,9 +312,15 @@ public class CallerIdClient {
recipients.setHelp("e-mail addresses to send notifications to");
jsap.registerParameter(recipients);
Switch contactsSwitch = new Switch("check contacts").setLongFlag("contacts");
contactsSwitch.setHelp("retrieve contacts from Google account and resolve caller names");
jsap.registerParameter(contactsSwitch);
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');
googleUsername.setHelp("the Google password for contact name resolution");
jsap.registerParameter(googlePassword);
Switch debugSwitch = new Switch("debug").setLongFlag("debug");
debugSwitch.setHelp("print debug messages");
@@ -1,4 +1,4 @@
package de.tilman.callerid;
package de.tilman.callerId;
import java.io.IOException;
import java.net.URL;