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