- switch (ns.getString("command")) {
- case "register":
- if (dBusConn != null) {
- System.err.println("register is not yet implementd via dbus");
- System.exit(1);
- }
- if (!m.userHasKeys()) {
- m.createNewIdentity();
- }
- try {
- m.register(ns.getBoolean("voice"));
- } catch (IOException e) {
- System.err.println("Request verify error: " + e.getMessage());
- System.exit(3);
- }
- break;
- case "verify":
- if (dBusConn != null) {
- System.err.println("verify is not yet implementd via dbus");
- System.exit(1);
- }
- if (!m.userHasKeys()) {
- System.err.println("User has no keys, first call register.");
- System.exit(1);
- }
- if (m.isRegistered()) {
- System.err.println("User registration is already verified");
- System.exit(1);
- }
- try {
- m.verifyAccount(ns.getString("verificationCode"));
- } catch (IOException e) {
- System.err.println("Verify error: " + e.getMessage());
- System.exit(3);
- }
- break;
- case "send":
- if (dBusConn == null && !m.isRegistered()) {
- System.err.println("User is not registered.");
- System.exit(1);
- }
-
- if (ns.getBoolean("endsession")) {
- if (ns.getList("recipient") == null) {
- System.err.println("No recipients given");
- System.err.println("Aborting sending.");
- System.exit(1);
- }
- try {
- ts.sendEndSessionMessage(ns.<String>getList("recipient"));
- } catch (IOException e) {
- handleIOException(e);
- } catch (EncapsulatedExceptions e) {
- handleEncapsulatedExceptions(e);
- } catch (AssertionError e) {
- handleAssertionError(e);
- } catch (DBusExecutionException e) {
- handleDBusExecutionException(e);
- }
- } else {
- String messageText = ns.getString("message");
- if (messageText == null) {
- try {
- messageText = IOUtils.toString(System.in);
- } catch (IOException e) {
- System.err.println("Failed to read message from stdin: " + e.getMessage());
- System.err.println("Aborting sending.");
- System.exit(1);
- }
- }
-
- try {
- List<String> attachments = ns.getList("attachment");
- if (attachments == null) {
- attachments = new ArrayList<>();
- }
- if (ns.getString("group") != null) {
- byte[] groupId = decodeGroupId(ns.getString("group"));
- ts.sendGroupMessage(messageText, attachments, groupId);
- } else {
- ts.sendMessage(messageText, attachments, ns.<String>getList("recipient"));
- }
- } catch (IOException e) {
- handleIOException(e);
- } catch (EncapsulatedExceptions e) {
- handleEncapsulatedExceptions(e);
- } catch (AssertionError e) {
- handleAssertionError(e);
- } catch (GroupNotFoundException e) {
- handleGroupNotFoundException(e);
- } catch (AttachmentInvalidException e) {
- System.err.println("Failed to add attachment: " + e.getMessage());
- System.err.println("Aborting sending.");
- System.exit(1);
- } catch (DBusExecutionException e) {
- handleDBusExecutionException(e);
- }
- }