]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/App.java
Add option to disable adding message to send log
[signal-cli] / src / main / java / org / asamk / signal / App.java
index f500d818d26a04db75f2e9f56d572e8ede4823b6..058ae6bb6936484ae588c8084e2a3a737c5de23a 100644 (file)
@@ -23,6 +23,7 @@ import org.asamk.signal.dbus.DbusProvisioningManagerImpl;
 import org.asamk.signal.dbus.DbusRegistrationManagerImpl;
 import org.asamk.signal.manager.Manager;
 import org.asamk.signal.manager.RegistrationManager;
+import org.asamk.signal.manager.Settings;
 import org.asamk.signal.manager.SignalAccountFiles;
 import org.asamk.signal.manager.api.AccountCheckException;
 import org.asamk.signal.manager.api.NotRegisteredException;
@@ -46,7 +47,7 @@ import java.io.BufferedWriter;
 import java.io.File;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
-import java.nio.charset.Charset;
+import java.util.Set;
 
 import static net.sourceforge.argparse4j.DefaultSettings.VERSION_0_9_0_DEFAULT_SETTINGS;
 
@@ -64,13 +65,16 @@ public class App {
                 .description("Commandline interface for Signal.")
                 .version(BaseConfig.PROJECT_NAME + " " + BaseConfig.PROJECT_VERSION);
 
-        parser.addArgument("-v", "--version").help("Show package version.").action(Arguments.version());
-        parser.addArgument("--verbose")
+        parser.addArgument("--version").help("Show package version.").action(Arguments.version());
+        parser.addArgument("-v", "--verbose")
                 .help("Raise log level and include lib signal logs. Specify multiple times for even more logs.")
                 .action(Arguments.count());
         parser.addArgument("--log-file")
                 .type(File.class)
                 .help("Write log output to the given file. If --verbose is also given, the detailed logs will only be written to the log file.");
+        parser.addArgument("--scrub-log")
+                .action(Arguments.storeTrue())
+                .help("Scrub possibly sensitive information from the log, like phone numbers and UUIDs.");
         parser.addArgument("-c", "--config")
                 .help("Set the path, where to store the config (Default: $XDG_DATA_HOME/signal-cli , $HOME/.local/share/signal-cli).");
 
@@ -98,6 +102,10 @@ public class App {
                 .type(Arguments.enumStringType(TrustNewIdentityCli.class))
                 .setDefault(TrustNewIdentityCli.ON_FIRST_USE);
 
+        parser.addArgument("--disable-send-log")
+                .help("Disable message send log (for resending messages that recipient couldn't decrypt)")
+                .action(Arguments.storeTrue());
+
         var subparsers = parser.addSubparsers().title("subcommands").dest("command");
 
         Commands.getCommandSubparserAttachers().forEach((key, value) -> {
@@ -123,7 +131,7 @@ public class App {
         var outputType = outputTypeInput == null
                 ? command.getSupportedOutputTypes().stream().findFirst().orElse(null)
                 : outputTypeInput;
-        var writer = new BufferedWriter(new OutputStreamWriter(System.out, Charset.defaultCharset()));
+        var writer = new BufferedWriter(new OutputStreamWriter(System.out, IOUtils.getConsoleCharset()));
         var outputWriter = outputType == null
                 ? null
                 : outputType == OutputType.JSON ? new JsonWriterImpl(writer) : new PlainTextWriterImpl(writer);
@@ -164,12 +172,14 @@ public class App {
                 ? TrustNewIdentity.ON_FIRST_USE
                 : trustNewIdentityCli == TrustNewIdentityCli.ALWAYS ? TrustNewIdentity.ALWAYS : TrustNewIdentity.NEVER;
 
+        final var disableSendLog = Boolean.TRUE.equals(ns.getBoolean("disable-send-log"));
+
         final SignalAccountFiles signalAccountFiles;
         try {
             signalAccountFiles = new SignalAccountFiles(configPath,
                     serviceEnvironment,
                     BaseConfig.USER_AGENT,
-                    trustNewIdentity);
+                    new Settings(trustNewIdentity, disableSendLog));
         } catch (IOException e) {
             throw new IOErrorException("Failed to read local accounts list", e);
         }
@@ -189,7 +199,12 @@ public class App {
                 return;
             }
 
-            var accounts = signalAccountFiles.getAllLocalAccountNumbers();
+            Set<String> accounts = null;
+            try {
+                accounts = signalAccountFiles.getAllLocalAccountNumbers();
+            } catch (IOException e) {
+                throw new IOErrorException("Failed to load local accounts file", e);
+            }
             if (accounts.size() == 0) {
                 throw new UserErrorException("No local users found, you first need to register or link an account");
             } else if (accounts.size() > 1) {
@@ -300,6 +315,8 @@ public class App {
     ) throws CommandException {
         try (var multiAccountManager = signalAccountFiles.initMultiAccountManager()) {
             command.handleCommand(ns, multiAccountManager, outputWriter);
+        } catch (IOException e) {
+            throw new IOErrorException("Failed to load local accounts file", e);
         }
     }