messages.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. // Specify this reporter requires a backup.
  8. // The second parameter to func() is now a backup instead of the path to one.
  9. module.exports.requiresBackup = true
  10. // Specify this reporter supports the promises API for allowing chaining of reports.
  11. module.exports.usesPromises = true
  12. // Should this report be skipped in automated reports?
  13. // This is used when the 'all' report type is specified, and all possible reports are generated.
  14. // with this set to true, the report WILL NOT run when report type = 'all'
  15. module.exports.requiresInteractivity = true
  16. module.exports.func = function (program, backup, resolve, reject) {
  17. if (!program.id) {
  18. console.log('use -i or --id <id> to specify conversation ID.')
  19. process.exit(1)
  20. }
  21. backup.getMessages(program.id)
  22. .then((items) => {
  23. var result = program.formatter.format(items, {
  24. program: program,
  25. columns: {
  26. 'ID' : el => el.ROWID,
  27. 'Date': el => el.XFORMATTEDDATESTRING,
  28. 'Sender': el => el.x_sender,
  29. 'Text': el => (el.text || '').trim()
  30. }
  31. })
  32. resolve(result)
  33. })
  34. .catch(reject)
  35. }