voicemail-files.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const log = require('../util/log')
  2. const path = require('path')
  3. const fs = require('fs-extra')
  4. module.exports.name = 'voicemail-files'
  5. module.exports.description = 'List all or extract voicemail files (iOS 10+)'
  6. // Specify this reporter requires a backup.
  7. // The second parameter to func() is now a backup instead of the path to one.
  8. module.exports.requiresBackup = true
  9. // Specify this reporter supports the promises API for allowing chaining of reports.
  10. module.exports.usesPromises = true
  11. module.exports.func = function (program, backup, resolve, reject) {
  12. backup.getVoicemailFileList()
  13. .then((list) => {
  14. // Extract to the specified location
  15. if (program.extract) {
  16. for (var item of list) {
  17. try {
  18. var outDir = path.join(program.extract, path.basename(item.relativePath))
  19. fs.ensureDirSync(path.dirname(outDir))
  20. fs.createReadStream(backup.getFileName(item.fileID)).pipe(fs.createWriteStream(outDir))
  21. item.output_dir = outDir
  22. } catch (e) {
  23. log.error(`Couldn't Export: ${item.relativePath}`, e)
  24. }
  25. }
  26. }
  27. // Generate report.
  28. var result = program.formatter.format(list, {
  29. program: program,
  30. columns: {
  31. 'ID': el => el.fileID,
  32. 'Path': el => el.relativePath,
  33. 'Export Path': el => el.output_dir || '<not exported>'
  34. }
  35. })
  36. resolve(result)
  37. })
  38. .catch(reject)
  39. }