Explorar el Código

Gmail reports (#40)

* Gmail configured accounts, shared contacts
Alberto Güerere hace 7 años
padre
commit
81b6bd174f
Se han modificado 3 ficheros con 157 adiciones y 0 borrados
  1. 2 0
      tools/index.js
  2. 71 0
      tools/reports/gmail_accounts.js
  3. 84 0
      tools/reports/gmail_shared_contacts.js

+ 2 - 0
tools/index.js

@@ -37,6 +37,8 @@ var reportTypes = {
   'bluetooth_devices': require('./reports/bluetooth_devices'),
   'safari_open_tabs': require('./reports/safari_open_tabs'),
   'safari_recent_searches': require('./reports/safari_recent_searches'),
+  'gmail_accounts': require('./reports/gmail_accounts'),
+  'gmail_shared_contacts': require('./reports/gmail_shared_contacts'),
   'waze_favorites': require('./reports/waze_favorites'),
   'waze_places': require('./reports/waze_places'),
   'waze_recents': require('./reports/waze_recents')

+ 71 - 0
tools/reports/gmail_accounts.js

@@ -0,0 +1,71 @@
+const log = require('../util/log')
+const path = require('path')
+const sqlite3 = require('sqlite3')
+const bplist = require('bplist-parser')
+const fs = require('fs')
+const plist = require('plist')
+
+
+// Derive filenames based on domain + file path
+const fileHash = require('../util/backup_filehash')
+
+const file = fileHash('Library/Preferences/group.com.google.Gmail.plist', 'AppDomainGroup-group.com.google.Gmail')
+
+module.exports.name = 'gmail_accounts'
+module.exports.description = 'Show Gmail account(s) information'
+
+// Specify this reporter requires a backup.
+// The second parameter to func() is now a backup instead of the path to one.
+module.exports.requiresBackup = true
+
+// Specify this reporter supports the promises API for allowing chaining of reports.
+module.exports.usesPromises = true
+
+module.exports.func = function (program, backup, resolve, reject) {
+  gmailAccountsReport(backup)
+    .then((items) => {
+      var result = program.formatter.format(items, {
+        program: program,
+        columns: { 
+          'Id': el => el.id,
+          'Email': el => el.email,
+          'Avatar': el => el.avatar
+        }
+      })
+
+      resolve(result)
+    })
+    .catch(reject)
+}
+
+const gmailAccountsReport = (backup) => {
+  return new Promise((resolve, reject) => {
+    var filename = backup.getFileName(file)
+    try {
+      let gmailPlist = bplist.parseBuffer(fs.readFileSync(filename))[0]
+      let gmailAccountIds = Object.keys(gmailPlist).filter(key => key.indexOf('kIdToEmailMapKey') !== -1);
+      let gmailAvatars = Object.keys(gmailPlist).filter(key => key.indexOf('kCurrentAvatarUrlKey') !== -1);
+      gmailAvatars = gmailAvatars.map(avatarKey => {
+        let id = avatarKey.split('kCurrentAvatarUrlKey')[1].split('-')
+        id = id[id.length - 1]
+        return {
+          avatarKey: avatarKey,
+          accountId: id
+        }
+      })
+
+      gmailAccountIds = gmailAccountIds.map(key => {
+        const split = key.split('-')
+        return {
+          id: split[split.length - 1],
+          email: gmailPlist[key],
+          avatar: gmailPlist[gmailAvatars.find(avatar => avatar.accountId === split[split.length - 1]).avatarKey]
+        }
+      });
+
+      resolve(gmailAccountIds)
+    } catch (e) {
+      reject(e)
+    }
+  })
+}

+ 84 - 0
tools/reports/gmail_shared_contacts.js

@@ -0,0 +1,84 @@
+const log = require('../util/log')
+const path = require('path')
+const sqlite3 = require('sqlite3')
+const bplist = require('bplist-parser')
+const fs = require('fs')
+const plist = require('plist')
+
+
+// Derive filenames based on domain + file path
+const fileHash = require('../util/backup_filehash')
+
+const file = fileHash('Library/Preferences/group.com.google.Gmail.plist', 'AppDomainGroup-group.com.google.Gmail')
+
+module.exports.name = 'gmail_shared_contacts'
+module.exports.description = 'Show Gmail account(s) shared contacts information'
+
+// Specify this reporter requires a backup.
+// The second parameter to func() is now a backup instead of the path to one.
+module.exports.requiresBackup = true
+
+// Specify this reporter supports the promises API for allowing chaining of reports.
+module.exports.usesPromises = true
+
+module.exports.func = function (program, backup, resolve, reject) {
+  gmailAccountsReport(backup)
+    .then((items) => {
+      var result = program.formatter.format(items, {
+        program: program,
+        columns: { 
+          'Account': el => el.account,
+          'Name': el => el.name,
+          'Email': el => el.email,
+          'Avatar': el => el.avatar
+        }
+      })
+
+      resolve(result)
+    })
+    .catch(reject)
+}
+
+const gmailAccountsReport = (backup) => {
+  return new Promise((resolve, reject) => {
+    var filename = backup.getFileName(file)
+    try {
+      let gmailPlist = bplist.parseBuffer(fs.readFileSync(filename))[0]
+      let gmailAccountIds = Object.keys(gmailPlist).filter(key => key.indexOf('kIdToEmailMapKey') !== -1);
+      let gmailContactsByAccount = Object.keys(gmailPlist).filter(key => key.indexOf('kInboxSharedStorageContacts') !== -1);
+      gmailContactsByAccount = gmailContactsByAccount.map(contactsKey => {
+        let id = contactsKey.split('kInboxSharedStorageContacts')[1].split('_')
+        id = id[id.length - 1]
+        return {
+          contactsKey: contactsKey,
+          accountId: id
+        }
+      })
+
+      gmailAccountIds = gmailAccountIds.map(key => {
+        const split = key.split('kIdToEmailMapKey-')
+        return {
+          id: split[split.length - 1],
+          email: gmailPlist[key],
+          contacts: gmailPlist[gmailContactsByAccount.find(contacts => contacts.accountId === split[split.length - 1]).contactsKey]
+        }
+      });
+
+      let contacts = []
+      gmailAccountIds.forEach(gmailAccount => {
+        gmailAccount.contacts.forEach(contact => {
+          contacts.push({
+            account: gmailAccount.email,
+            name: contact[0],
+            email: contact[1],
+            avatar: contact[2]
+          })
+        })
+      })
+
+      resolve(contacts)
+    } catch (e) {
+      reject(e)
+    }
+  })
+}