File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -64,11 +64,24 @@ const testMsgAttachment0 = testMsg.getAttachment(testMsgInfo.attachments[0])
6464 const testMsgInfo = testMsg .getFileData ()
6565
6666 for (const att of testMsgInfo .attachments ) {
67- console .log (att .fileName );
68- // testMsg.getAttachment(att).content
69- }
67+ const attachment = testMsg .getAttachment (att);
68+ console .log (attachment .fileName );
69+
70+ // fs.writeFileSync("save-" + attachment.fileName, attachment.content);
71+
72+ // Node.js ≧ v0.1.90
73+ // Buffer.from(attachment.content).toString('base64')
74+
75+ // Node.js ≧ v25
76+ // attachment.content.toBase64()
77+ }
7078```
7179
80+ For a reference:
81+
82+ - [ Buffer | Node.js v25.2.1 Documentation] ( https://nodejs.org/api/buffer.html#buftostringencoding-start-end )
83+ - [ Uint8Array.prototype.toBase64() - JavaScript | MDN] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64 )
84+
7285## Build msgreader locally
7386
7487``` bat
Original file line number Diff line number Diff line change @@ -258,8 +258,6 @@ program
258258 walk ( reader . rootFolder ( ) , "/" ) ;
259259 } ) ;
260260
261-
262-
263261program
264262 . command ( 'dummy1' )
265263 . action ( ( ) => {
@@ -273,10 +271,17 @@ program
273271program
274272 . command ( 'dummy2' )
275273 . action ( ( ) => {
276- const msgFileBuffer = fs . readFileSync ( 'test/voteItems.msg' ) ;
277- const testMsg = new MsgReader ( msgFileBuffer ) ;
278- const testMsgInfo = testMsg . getFileData ( ) ;
279- console . log ( testMsgInfo ) ;
274+ const msgFileBuffer = fs . readFileSync ( 'test/msgInMsg.msg' ) ;
275+ const testMsg = new MsgReader ( msgFileBuffer )
276+ const testMsgInfo = testMsg . getFileData ( )
277+
278+ for ( const att of testMsgInfo . attachments ) {
279+ const attachment = testMsg . getAttachment ( att ) ;
280+ console . log ( attachment . fileName ) ;
281+
282+ //console.log(Buffer.from(attachment.content).toString('base64'));
283+ fs . writeFileSync ( "save-" + attachment . fileName , attachment . content ) ;
284+ }
280285 } ) ;
281286
282287program
Original file line number Diff line number Diff line change 11{
22 "name" : " @kenjiuno/msgreader" ,
3- "version" : " 1.27.0 " ,
3+ "version" : " 1.27.1-alpha.1 " ,
44 "description" : " Outlook Item File (.msg) reader in JavaScript Npm Module" ,
55 "main" : " lib/index.js" ,
66 "types" : " lib/index.d.ts" ,
Original file line number Diff line number Diff line change @@ -1427,6 +1427,45 @@ function removeTrailingNull(text: string): string {
14271427 return text ;
14281428}
14291429
1430+ export interface AttachmentData {
1431+ /**
1432+ * A file name of this attachment without directory specification.
1433+ *
1434+ * @see {@link SomeOxProps.fileName }
1435+ *
1436+ * e.g.
1437+ *
1438+ * - `blue.png`
1439+ * - `Microsoft Outlook テスト メッセージ.msg`
1440+ */
1441+ fileName : string ;
1442+
1443+ /**
1444+ * The binary content of this attachment.
1445+ *
1446+ * ---
1447+ *
1448+ * You can select a method to handle this content:
1449+ *
1450+ * @see [Uint8Array - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)
1451+ *
1452+ * ```js
1453+ * // Node.js ≧ v25
1454+ * attachment.content.toBase64()
1455+ * ```
1456+ *
1457+ * @see [Buffer | Node.js v25.2.1 Documentation](https://nodejs.org/api/buffer.html)
1458+ *
1459+ * ```js
1460+ * // Node.js ≧ v0.1.90
1461+ * Buffer.from(attachment.content).toString('base64')
1462+ * ```
1463+ *
1464+ * ---
1465+ */
1466+ content : Uint8Array ;
1467+ }
1468+
14301469/**
14311470 * The core implementation of MsgReader
14321471 */
@@ -1895,11 +1934,12 @@ export default class MsgReader {
18951934 }
18961935
18971936 /**
1898- Reads an attachment content by key/ID
1899-
1900- @return {Object } The attachment for specific attachment key
1901- */
1902- getAttachment ( attach : number | FieldsData ) : { fileName : string ; content : Uint8Array } {
1937+ * Reads an attachment content by key/ID
1938+ *
1939+ * @param attach
1940+ * @returns The attachment for specific attachment key
1941+ */
1942+ getAttachment ( attach : number | FieldsData ) : AttachmentData {
19031943 const attachData = typeof attach === 'number' ? this . fieldsData . attachments [ attach ] : attach ;
19041944 if ( attachData . innerMsgContent === true && typeof attachData . folderId === "number" ) {
19051945 // embedded msg
You can’t perform that action at this time.
0 commit comments