]> nmode's Git Repositories - signal-cli/commitdiff
Make use of attachment size and preview
authorAsamK <asamk@gmx.de>
Tue, 22 Sep 2015 11:23:16 +0000 (13:23 +0200)
committerAsamK <asamk@gmx.de>
Tue, 22 Sep 2015 11:23:16 +0000 (13:23 +0200)
src/main/java/cli/Main.java
src/main/java/cli/Manager.java

index f80a74b67c394e920c060f9271c38f021d314ee3..b1822aafb02ad413e8f3f1bb1ac36c40f9b71768 100644 (file)
@@ -262,9 +262,11 @@ public class Main {
                             for (TextSecureAttachment attachment : message.getAttachments().get()) {
                                 System.out.println("- " + attachment.getContentType() + " (" + (attachment.isPointer() ? "Pointer" : "") + (attachment.isStream() ? "Stream" : "") + ")");
                                 if (attachment.isPointer()) {
                             for (TextSecureAttachment attachment : message.getAttachments().get()) {
                                 System.out.println("- " + attachment.getContentType() + " (" + (attachment.isPointer() ? "Pointer" : "") + (attachment.isStream() ? "Stream" : "") + ")");
                                 if (attachment.isPointer()) {
-                                    System.out.println("  Id: " + attachment.asPointer().getId() + " Key length: " + attachment.asPointer().getKey().length + (attachment.asPointer().getRelay().isPresent() ? " Relay: " + attachment.asPointer().getRelay().get() : ""));
+                                    final TextSecureAttachmentPointer pointer = attachment.asPointer();
+                                    System.out.println("  Id: " + pointer.getId() + " Key length: " + pointer.getKey().length + (pointer.getRelay().isPresent() ? " Relay: " + pointer.getRelay().get() : ""));
+                                    System.out.println((pointer.getSize().isPresent() ? " Size: " + pointer.getSize().get() : " bytes") + (pointer.getPreview().isPresent() ? " (Preview is available: " + pointer.getPreview().get().length + " bytes)" : ""));
                                     try {
                                     try {
-                                        File file = m.retrieveAttachment(attachment.asPointer());
+                                        File file = m.retrieveAttachment(pointer);
                                         System.out.println("  Stored plaintext in: " + file);
                                     } catch (IOException | InvalidMessageException e) {
                                         System.out.println("Failed to retrieve attachment: " + e.getMessage());
                                         System.out.println("  Stored plaintext in: " + file);
                                     } catch (IOException | InvalidMessageException e) {
                                         System.out.println("Failed to retrieve attachment: " + e.getMessage());
index 3f9237fb3839b483db6bb18b684a1dc1daf1e517..fef7c81d8fcbca67fa7c7cf5d6c201e375f23290 100644 (file)
@@ -292,11 +292,27 @@ class Manager {
         } finally {
             if (output != null) {
                 output.close();
         } finally {
             if (output != null) {
                 output.close();
+                output = null;
             }
             if (!tmpFile.delete()) {
                 System.err.println("Failed to delete temp file: " + tmpFile);
             }
         }
             }
             if (!tmpFile.delete()) {
                 System.err.println("Failed to delete temp file: " + tmpFile);
             }
         }
+        if (pointer.getPreview().isPresent()) {
+            File previewFile = new File(outputFile + ".preview");
+            try {
+                output = new FileOutputStream(previewFile);
+                byte[] preview = pointer.getPreview().get();
+                output.write(preview, 0, preview.length);
+            } catch (FileNotFoundException e) {
+                e.printStackTrace();
+                return null;
+            } finally {
+                if (output != null) {
+                    output.close();
+                }
+            }
+        }
         return outputFile;
     }
 
         return outputFile;
     }