Sfoglia il codice sorgente

Added fields to the conversations_full report to include them using the JSON formatter (#26)

Alberto Güerere 7 anni fa
parent
commit
379a9d0b8f
2 ha cambiato i file con 47 aggiunte e 7 eliminazioni
  1. 24 7
      tools/reports/conversations_full.js
  2. 23 0
      tools/util/iphone_backup.js

+ 24 - 7
tools/reports/conversations_full.js

@@ -12,23 +12,40 @@ module.exports.func = async function (program, backup, resolve, reject) {
   // if (program.dump) {
   // return new Promise(async (resolve, reject) => {
   let conversations = await backup.getConversations()
+  let conversations_full = []
   for (let el of conversations) {
-    el.messages = await backup.getMessages(el.ROWID, true)
+    let messages = await backup.getMessages(el.ROWID, true)
+    for (let message of messages) {
+      message.conversation = el
+      message.attachments = await backup.getMessageAttachments(message.ROWID)
+    }
+    conversations_full.push(...messages)
   }
 
   // Use the configured formatter to print the rows.
-  const result = program.formatter.format(conversations, {
+  const result = program.formatter.format(conversations_full, {
     // Color formatting?
     program: program,
 
     // Columns to be displayed in human-readable printouts.
     // Some formatters, like raw or CSV, ignore these.
     columns: {
-      'ID': el => el.ROWID,
-      'Date': el => el.XFORMATTEDDATESTRING || '??',
-      'Service': el => el.service_name + '',
-      'Chat Name': el => el.chat_identifier + '',
-      'Display Name': el => el.display_name + ''
+      'conversation_id': el => el.conversation.ROWID,
+      'date': el => el.conversation.XFORMATTEDDATESTRING || '??',
+      'service': el => el.conversation.service_name + '',
+      'chat_name': el => el.conversation.chat_identifier + '',
+      'display_name': el => el.conversation.display_name + '',
+      'message_id': el => el.ROWID + '',
+      'content': el => el.text + '',
+      'date': el => el.date + '',
+      'date_read': el => el.date_read + '',
+      'date_delivered': el => el.date_delivered + '',
+      'is_delivered': el => el.is_delivered + '',
+      'is_finished': el => el.is_finished + '',
+      'is_from_me': el => el.is_from_me + '',
+      'is_read': el => el.is_read + '',
+      'is_sent': el => el.is_sent + '',
+      'attachments': el => el.attachments.map((at) => at.filename)
     }
   })
 

+ 23 - 0
tools/util/iphone_backup.js

@@ -289,6 +289,29 @@ class IPhoneBackup {
     }
   }
 
+  getMessageAttachments (messageId) {
+    var backup = this
+    return new Promise((resolve, reject) => {
+      const messagedb = this.getDatabase(databases.SMS)
+      const query = `
+        SELECT
+          attachment.*
+        FROM message_attachment_join
+        INNER JOIN attachment
+          ON attachment.ROWID = message_attachment_join.attachment_id
+        WHERE message_attachment_join.message_id = ${parseInt(messageId)}
+      `
+      messagedb.all(query,
+      async function (err, attachments) {
+        if (err) return reject(err)
+
+        attachments = attachments || []
+
+        resolve(attachments)
+      })
+    })
+  }
+
   getConversationsiOS9 () {
     var backup = this
     return new Promise((resolve, reject) => {