+ if (ns.getBoolean("endsession")) {
+ sendEndSessionMessage(m, recipients);
+ } else {
+ final List<String> attachments = ns.getList("attachment");
+ List<TextSecureAttachment> textSecureAttachments = null;
+ if (attachments != null) {
+ textSecureAttachments = new ArrayList<>(attachments.size());
+ for (String attachment : attachments) {
+ try {
+ File attachmentFile = new File(attachment);
+ InputStream attachmentStream = new FileInputStream(attachmentFile);
+ final long attachmentSize = attachmentFile.length();
+ String mime = Files.probeContentType(Paths.get(attachment));
+ textSecureAttachments.add(new TextSecureAttachmentStream(attachmentStream, mime, attachmentSize, null));
+ } catch (IOException e) {
+ System.err.println("Failed to add attachment \"" + attachment + "\": " + e.getMessage());
+ System.err.println("Aborting sending.");
+ System.exit(1);
+ }
+ }
+ }
+
+ 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);
+ }
+ }
+
+ sendMessage(m, messageText, textSecureAttachments, recipients, group);
+ }
+