pst-extractor 1.8.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/ColumnDescriptor.class.d.ts +26 -26
  2. package/dist/ColumnDescriptor.class.js +51 -48
  3. package/dist/DescriptorIndexNode.class.d.ts +25 -26
  4. package/dist/DescriptorIndexNode.class.js +53 -53
  5. package/dist/LZFu.class.d.ts +11 -12
  6. package/dist/LZFu.class.js +95 -95
  7. package/dist/NodeInfo.class.d.ts +33 -33
  8. package/dist/NodeInfo.class.js +52 -52
  9. package/dist/NodeMap.class.d.ts +35 -35
  10. package/dist/NodeMap.class.js +86 -83
  11. package/dist/OffsetIndexItem.class.d.ts +23 -24
  12. package/dist/OffsetIndexItem.class.js +45 -45
  13. package/dist/OutlookProperties.d.ts +275 -275
  14. package/dist/OutlookProperties.js +281 -281
  15. package/dist/PSTActivity.class.d.ts +103 -103
  16. package/dist/PSTActivity.class.js +144 -144
  17. package/dist/PSTAppointment.class.d.ts +270 -271
  18. package/dist/PSTAppointment.class.js +376 -376
  19. package/dist/PSTAttachment.class.d.ts +172 -172
  20. package/dist/PSTAttachment.class.js +317 -314
  21. package/dist/PSTContact.class.d.ts +884 -884
  22. package/dist/PSTContact.class.js +1227 -1227
  23. package/dist/PSTDescriptorItem.class.d.ts +45 -46
  24. package/dist/PSTDescriptorItem.class.js +99 -96
  25. package/dist/PSTFile.class.d.ts +215 -216
  26. package/dist/PSTFile.class.js +818 -792
  27. package/dist/PSTFolder.class.d.ts +129 -129
  28. package/dist/PSTFolder.class.js +318 -307
  29. package/dist/PSTMessage.class.d.ts +788 -789
  30. package/dist/PSTMessage.class.js +1321 -1318
  31. package/dist/PSTMessageStore.class.d.ts +13 -13
  32. package/dist/PSTMessageStore.class.js +17 -17
  33. package/dist/PSTNodeInputStream.class.d.ts +122 -123
  34. package/dist/PSTNodeInputStream.class.js +514 -488
  35. package/dist/PSTObject.class.d.ts +133 -134
  36. package/dist/PSTObject.class.js +326 -323
  37. package/dist/PSTRecipient.class.d.ts +65 -65
  38. package/dist/PSTRecipient.class.js +103 -103
  39. package/dist/PSTTable.class.d.ts +52 -52
  40. package/dist/PSTTable.class.js +175 -172
  41. package/dist/PSTTable7C.class.d.ts +45 -45
  42. package/dist/PSTTable7C.class.js +281 -278
  43. package/dist/PSTTableBC.class.d.ts +31 -31
  44. package/dist/PSTTableBC.class.js +111 -108
  45. package/dist/PSTTableItem.class.d.ts +47 -48
  46. package/dist/PSTTableItem.class.js +124 -121
  47. package/dist/PSTTask.class.d.ts +146 -146
  48. package/dist/PSTTask.class.js +205 -205
  49. package/dist/PSTUtil.class.d.ts +134 -135
  50. package/dist/PSTUtil.class.js +795 -790
  51. package/dist/RecurrencePattern.class.d.ts +49 -50
  52. package/dist/RecurrencePattern.class.js +120 -120
  53. package/dist/index.d.ts +6 -6
  54. package/dist/index.js +15 -15
  55. package/example/package.json +7 -7
  56. package/example/test-min.ts +31 -12
  57. package/example/{test-mem.ts → test.ts} +38 -30
  58. package/example/testdata/output.txt +278 -0
  59. package/example/testdata/outputBody.txt +3404 -0
  60. package/example/yarn.lock +112 -50
  61. package/junit.xml +36 -36
  62. package/package.json +28 -27
  63. package/readme.md +1 -3
  64. package/example/test-max.ts +0 -251
@@ -1,251 +0,0 @@
1
- import * as fs from 'fs'
2
- import { PSTAttachment } from '../src/PSTAttachment.class'
3
- import { PSTFile } from '../src/PSTFile.class'
4
- import { PSTFolder } from '../src/PSTFolder.class'
5
- import { PSTMessage } from '../src/PSTMessage.class'
6
-
7
- // TODO - location of pst files
8
- const pstFolder = 'C:/github/testdata/'
9
- // TODO - if saveToFS true, location to store extracted files
10
- const saveToFS = true
11
- const topOutputFolder = 'C:/github/testdataoutput/'
12
-
13
- const verbose = true
14
- const displaySender = true
15
- const displayBody = false
16
- const displayBodyRTF = false
17
- const displayBodyHTML = true
18
- let outputFolder = ''
19
- let depth = -1
20
- let col = 0
21
-
22
- // make a top level folder to hold content
23
- try {
24
- if (saveToFS) {
25
- fs.mkdirSync(topOutputFolder)
26
- }
27
- } catch (err) {
28
- console.error(err)
29
- }
30
-
31
- const directoryListing = fs.readdirSync(pstFolder)
32
- directoryListing.forEach((filename) => {
33
- console.log(pstFolder + filename)
34
-
35
- // time for performance comparison to Java and improvement
36
- const start = Date.now()
37
- const pstFile = new PSTFile(pstFolder + filename)
38
-
39
- // make a sub folder for each PST
40
- try {
41
- if (saveToFS) {
42
- outputFolder = topOutputFolder + filename + '/'
43
- fs.mkdirSync(outputFolder)
44
- }
45
- } catch (err) {
46
- console.error(err)
47
- }
48
-
49
- console.log(pstFile.getMessageStore().displayName)
50
- processFolder(pstFile.getRootFolder())
51
-
52
- const end = Date.now()
53
- console.log('processed in ' + (end - start) + ' ms')
54
- })
55
-
56
- /**
57
- * Walk the folder tree recursively and process emails.
58
- * @param {PSTFolder} folder
59
- */
60
- function processFolder(folder: PSTFolder) {
61
- depth++
62
-
63
- // the root folder doesn't have a display name
64
- if (depth > 0) {
65
- console.log(getDepth(depth) + folder.displayName)
66
- }
67
-
68
- // go through the folders...
69
- if (folder.hasSubfolders) {
70
- const childFolders: PSTFolder[] = folder.getSubFolders()
71
- for (const childFolder of childFolders) {
72
- processFolder(childFolder)
73
- }
74
- }
75
-
76
- // and now the emails for this folder
77
- if (folder.contentCount > 0) {
78
- depth++
79
- let email: PSTMessage = folder.getNextChild()
80
- while (email != null) {
81
- if (verbose) {
82
- console.log(
83
- getDepth(depth) +
84
- 'Email: ' +
85
- email.descriptorNodeId +
86
- ' - ' +
87
- email.subject
88
- )
89
- } else {
90
- printDot()
91
- }
92
-
93
- // sender
94
- const sender = getSender(email)
95
-
96
- // recipients
97
- const recipients = getRecipients(email)
98
-
99
- // display body?
100
- if (displayBody) console.log(email.body)
101
- if (displayBodyRTF) console.log(email.bodyRTF)
102
- if (displayBodyHTML) console.log(email.bodyHTML.length)
103
-
104
- // save content to fs?
105
- if (saveToFS) {
106
- // create date string in format YYYY-MM-DD
107
- let strDate = ''
108
- let d = email.clientSubmitTime
109
- if (!d && email.creationTime) {
110
- d = email.creationTime
111
- }
112
- if (d) {
113
- const month = ('0' + (d.getMonth() + 1)).slice(-2)
114
- const day = ('0' + d.getDate()).slice(-2)
115
- strDate = d.getFullYear() + '-' + month + '-' + day
116
- }
117
-
118
- // create a folder for each day (client submit time)
119
- const emailFolder = outputFolder + strDate + '/'
120
- if (!fs.existsSync(emailFolder)) {
121
- try {
122
- fs.mkdirSync(emailFolder)
123
- } catch (err) {
124
- console.error(err)
125
- }
126
- }
127
-
128
- doSaveToFS(email, emailFolder, sender, recipients)
129
- }
130
- email = folder.getNextChild()
131
- }
132
- depth--
133
- }
134
- depth--
135
- }
136
-
137
- /**
138
- * Save items to filesystem.
139
- * @param {PSTMessage} msg
140
- * @param {string} emailFolder
141
- * @param {string} sender
142
- * @param {string} recipients
143
- */
144
- function doSaveToFS(
145
- msg: PSTMessage,
146
- emailFolder: string,
147
- sender: string,
148
- recipients: string
149
- ) {
150
- try {
151
- // save the msg as a txt file
152
- const filename = emailFolder + msg.descriptorNodeId + '.txt'
153
- if (verbose) {
154
- console.log('saving msg to ' + filename)
155
- }
156
- const fd = fs.openSync(filename, 'w')
157
- fs.writeSync(fd, msg.clientSubmitTime + '\r\n')
158
- fs.writeSync(fd, 'Type: ' + msg.messageClass + '\r\n')
159
- fs.writeSync(fd, 'From: ' + sender + '\r\n')
160
- fs.writeSync(fd, 'To: ' + recipients + '\r\n')
161
- fs.writeSync(fd, 'Subject: ' + msg.subject)
162
- fs.writeSync(fd, msg.body)
163
- fs.closeSync(fd)
164
- } catch (err) {
165
- console.error(err)
166
- }
167
-
168
- // walk list of attachments and save to fs
169
- for (let i = 0; i < msg.numberOfAttachments; i++) {
170
- const attachment: PSTAttachment = msg.getAttachment(i)
171
- // Log.debug1(JSON.stringify(activity, null, 2));
172
- if (attachment.filename) {
173
- const filename =
174
- emailFolder + msg.descriptorNodeId + '-' + attachment.longFilename
175
- if (verbose) {
176
- console.log('saving attachment to ' + filename)
177
- }
178
- try {
179
- const fd = fs.openSync(filename, 'w')
180
- const attachmentStream = attachment.fileInputStream
181
- if (attachmentStream) {
182
- const bufferSize = 8176
183
- const buffer = Buffer.alloc(bufferSize)
184
- let bytesRead
185
- do {
186
- bytesRead = attachmentStream.read(buffer)
187
- fs.writeSync(fd, buffer, 0, bytesRead)
188
- } while (bytesRead == bufferSize)
189
- fs.closeSync(fd)
190
- }
191
- } catch (err) {
192
- console.error(err)
193
- }
194
- }
195
- }
196
- }
197
-
198
- /**
199
- * Get the sender and display.
200
- * @param {PSTMessage} email
201
- * @returns {string}
202
- */
203
- function getSender(email: PSTMessage): string {
204
- let sender = email.senderName
205
- if (sender !== email.senderEmailAddress) {
206
- sender += ' (' + email.senderEmailAddress + ')'
207
- }
208
- if (verbose && displaySender && email.messageClass === 'IPM.Note') {
209
- console.log(getDepth(depth) + ' sender: ' + sender)
210
- }
211
- return sender
212
- }
213
-
214
- /**
215
- * Get the recipients and display.
216
- * @param {PSTMessage} email
217
- * @returns {string}
218
- */
219
- function getRecipients(email: PSTMessage): string {
220
- // could walk recipients table, but be fast and cheap
221
- return email.displayTo
222
- }
223
-
224
- /**
225
- * Print a dot representing a message.
226
- */
227
- function printDot() {
228
- process.stdout.write('.')
229
- if (col++ > 100) {
230
- console.log('')
231
- col = 0
232
- }
233
- }
234
-
235
- /**
236
- * Returns a string with visual indicattion of depth in tree.
237
- * @param {number} depth
238
- * @returns {string}
239
- */
240
- function getDepth(depth: number): string {
241
- let sdepth = ''
242
- if (col > 0) {
243
- col = 0
244
- sdepth += '\n'
245
- }
246
- for (let x = 0; x < depth - 1; x++) {
247
- sdepth += ' | '
248
- }
249
- sdepth += ' |- '
250
- return sdepth
251
- }