messages.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. const stripAnsi = require('strip-ansi')
  2. const chalk = require('chalk')
  3. const iPhoneBackup = require('../util/iphone_backup.js').iPhoneBackup
  4. const normalizeCols = require('../util/normalize.js')
  5. module.exports.name = 'messages'
  6. module.exports.description = 'List all SMS and iMessage messages in a conversation'
  7. module.exports.func = function (program, base) {
  8. if (!program.backup) {
  9. console.log('use -b or --backup <id> to specify backup.')
  10. process.exit(1)
  11. }
  12. // Grab the backup
  13. var backup = iPhoneBackup.fromID(program.backup, base)
  14. backup.getMessages(program.messages, program.dump)
  15. .then((items) => {
  16. if (program.dump) return
  17. items = items.map(el => [
  18. chalk.gray(el.XFORMATTEDDATESTRING + ''),
  19. chalk.blue(el.x_sender + ''),
  20. el.text || ''
  21. ])
  22. items = normalizeCols(items, 2).map(el => el.join(' | ')).join('\n')
  23. if (!program.color) { items = stripAnsi(items) }
  24. console.log(items)
  25. })
  26. .catch((e) => {
  27. console.log('[!] Encountered an Error:', e)
  28. })
  29. }