accounts.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. const plist = require('../../../util/plist')
  2. const fs = require('fs')
  3. // Derive filenames based on domain + file path
  4. const fileHash = require('../../../util/backup_filehash')
  5. const file = fileHash('Library/Preferences/group.com.google.Gmail.plist', 'AppDomainGroup-group.com.google.Gmail')
  6. module.exports = {
  7. version: 4,
  8. name: 'gmail_accounts',
  9. description: `Show Gmail account(s) information`,
  10. requiresBackup: true,
  11. // Run on a v3 lib / backup object.
  12. run (lib, { backup }) {
  13. return gmailAccountsReport(backup)
  14. },
  15. // Fields for apps report
  16. output: {
  17. 'Id': el => el.id,
  18. 'Email': el => el.email,
  19. 'Avatar': el => el.avatar || null
  20. }
  21. }
  22. const gmailAccountsReport = (backup) => {
  23. return new Promise((resolve, reject) => {
  24. var filename = backup.getFileName(file)
  25. try {
  26. let gmailPlist = plist.parseFile(filename)
  27. let gmailAccountIds = Object.keys(gmailPlist).filter(key => key.indexOf('kIdToEmailMapKey') !== -1)
  28. let gmailAvatars = Object.keys(gmailPlist).filter(key => key.indexOf('kCurrentAvatarUrlKey') !== -1)
  29. gmailAvatars = gmailAvatars.map(avatarKey => {
  30. let id = avatarKey.split('kCurrentAvatarUrlKey')[1].split('-')
  31. id = id[id.length - 1]
  32. return {
  33. avatarKey: avatarKey,
  34. accountId: id
  35. }
  36. })
  37. gmailAccountIds = gmailAccountIds.map(key => {
  38. const split = key.split('-')
  39. let avatar = gmailAvatars.find(avatar => avatar.accountId === split[split.length - 1])
  40. return {
  41. id: split[split.length - 1],
  42. email: gmailPlist[key],
  43. avatar: gmailPlist[(avatar || {}).avatarKey]
  44. }
  45. })
  46. resolve(gmailAccountIds)
  47. } catch (e) {
  48. reject(e)
  49. }
  50. })
  51. }