From 960e97bc122dd3cd020452038b0abb4781496042 Mon Sep 17 00:00:00 2001 From: AsamK Date: Tue, 7 Jul 2015 11:42:24 +0200 Subject: [PATCH] Canonicalize recipient addresses --- src/main/java/cli/Main.java | 8 ++++---- src/main/java/cli/Manager.java | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/cli/Main.java b/src/main/java/cli/Main.java index 9a3e5b36..adeb5262 100644 --- a/src/main/java/cli/Main.java +++ b/src/main/java/cli/Main.java @@ -24,7 +24,7 @@ import org.whispersystems.textsecure.api.TextSecureMessageSender; import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException; import org.whispersystems.textsecure.api.messages.*; import org.whispersystems.textsecure.api.messages.multidevice.TextSecureSyncMessage; -import org.whispersystems.textsecure.api.push.TextSecureAddress; +import org.whispersystems.textsecure.api.util.InvalidNumberException; import java.io.File; import java.io.FileInputStream; @@ -152,9 +152,9 @@ public class Main { TextSecureDataMessage message = messageBuilder.build(); for (String recipient : ns.getList("recipient")) { try { - messageSender.sendMessage(new TextSecureAddress(recipient), message); - } catch (UntrustedIdentityException | IOException e) { - System.out.println("Send message: " + e.getMessage()); + messageSender.sendMessage(m.getPushAddress(recipient), message); + } catch (UntrustedIdentityException | IOException | InvalidNumberException e) { + System.out.println("Failed to send message to \"" + recipient + "\": " + e.getMessage()); } } break; diff --git a/src/main/java/cli/Manager.java b/src/main/java/cli/Manager.java index cd5f6305..3da46f1d 100644 --- a/src/main/java/cli/Manager.java +++ b/src/main/java/cli/Manager.java @@ -206,4 +206,14 @@ public class Manager { messagePipe.shutdown(); } } + + public String canonicalizeNumber(String number) throws InvalidNumberException { + String localNumber = username; + return PhoneNumberFormatter.formatNumber(number, localNumber); + } + + protected TextSecureAddress getPushAddress(String number) throws InvalidNumberException { + String e164number = canonicalizeNumber(number); + return new TextSecureAddress(e164number); + } }