diff --git a/WebCallerID/src/main/java/de/tilman/callerid/CallerIdClient.java b/WebCallerID/src/main/java/de/tilman/callerid/CallerIdClient.java index 5c7de73..49bdfa0 100755 --- a/WebCallerID/src/main/java/de/tilman/callerid/CallerIdClient.java +++ b/WebCallerID/src/main/java/de/tilman/callerid/CallerIdClient.java @@ -30,7 +30,6 @@ 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; @@ -75,10 +74,10 @@ public class CallerIdClient { if (calls.size() > 0) { List contacts = null; - if (config.getString("google username") != null) { + if (config.getBoolean("check contacts")) { log.info("retrieving Google contacts"); ContactsService service = new ContactsService("SpeedportCallerIdClient"); - service.setUserCredentials(config.getString("google username"), config.getString("google password")); + service.setUserCredentials(config.getString("e-mail adress"), config.getString("e-mail password")); URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/full"); Query myQuery = new Query(feedUrl); myQuery.setMaxResults(1000); @@ -187,9 +186,6 @@ 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) { @@ -235,17 +231,15 @@ public class CallerIdClient { } private void sendNotification(String time, String caller) throws Exception { - String host = config.getString("SMTP server address"); + String host = "smtp.gmail.com"; String from = config.getString("e-mail adress"); String pass = config.getString("e-mail password"); Properties props = System.getProperties(); - props.put("mail.smtp.ssl.enable", "true"); // Arcor -// props.put("mail.smtp.starttls.enable", "true"); // Google Mail + 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", "465"); // Arcor -// props.put("mail.smtp.port", "587"); // Google Mail + props.put("mail.smtp.port", "587"); props.put("mail.smtp.auth", "true"); String[] to = config.getStringArray("recipient"); @@ -275,6 +269,7 @@ 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"); @@ -292,19 +287,14 @@ 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("e-mail address to send from"); + fromAddress.setHelp("Google 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 e-mail account"); + emailPassword.setHelp("the login password for the Google account"); jsap.registerParameter(emailPassword); UnflaggedOption recipients = new UnflaggedOption("recipient").setStringParser(JSAP.STRING_PARSER).setRequired(true) @@ -312,15 +302,9 @@ 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'); - 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 contactsSwitch = new Switch("check contacts").setLongFlag("contacts"); + contactsSwitch.setHelp("retrieve contacts from Google account and resolve caller names"); + jsap.registerParameter(contactsSwitch); Switch debugSwitch = new Switch("debug").setLongFlag("debug"); debugSwitch.setHelp("print debug messages");