Registry / serialization / node-tnef

node-tnef

JSON →
library1.4.0jsnpmunverified

node-tnef is a Node.js library designed to parse Transport Neutral Encapsulation Format (TNEF) files, commonly encountered as `winmail.dat` attachments in emails. This proprietary Microsoft format is often sent by Outlook users but is not natively understood by other email clients. The library extracts embedded content and attachments from these files, addressing a niche but persistent interoperability problem. It offers both a command-line interface for direct file or directory parsing and a programmatic API for use within Node.js projects, primarily through its `parse` (for file paths) and `parseBuffer` (for in-memory buffers) methods. The current stable version is 1.4.0. The package maintains an ad-hoc release cadence, focusing on bug fixes and feature enhancements, such as the addition of `parseBuffer` in version 1.3.0 and the removal of the `bluebird` dependency in 1.4.0.

npm install node-tnef
INSTALL
IMPORT
SIG · NODE-TNEF
N
node-tnef
serializationjavascriptv1.4.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

tnef
const tnef = require('node-tnef')
import tnef from 'node-tnef'
This module is primarily designed for CommonJS. Direct ESM import syntax is not officially documented or guaranteed to work without specific Node.js configuration for CJS interoperability.
tnef.parse
const tnef = require('node-tnef'); tnef.parse('/path/to/winmail.dat', (err, content) => { /* ... */ });
import { parse } from 'node-tnef'
The `parse` method is a property of the main module object, not a top-level named export. Attempting to destructure it as a named export from an ESM import will likely result in a runtime error.
tnef.parseBuffer
const tnef = require('node-tnef'); tnef.parseBuffer(yourBuffer, (err, content) => { /* ... */ });
import { parseBuffer } from 'node-tnef'
The `parseBuffer` method, introduced in v1.3.0, is accessed as a property of the main module object. It is not a named export directly from the module.

Demonstrates how to use `tnef.parseBuffer` to process an in-memory TNEF buffer and extract its contents, including writing an attachment to a file.

const tnef = require('node-tnef'); const fs = require('fs'); const path = require('path'); // A minimal, valid TNEF signature prefix for demonstration. // A real winmail.dat file would be much larger and complex. const dummyTnefBuffer = Buffer.from( '\x22\x34\x71\x9A\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'binary' ); tnef.parseBuffer(dummyTnefBuffer, (err, content) => { if (err) { console.error('Error parsing TNEF buffer:', err); return; } if (content && content.length > 0) { console.log(`Found ${content.length} attachment(s).`); const firstAttachment = content[0]; console.log('First attachment title:', firstAttachment.Title); // Example: Writing the attachment data to a file const outputPath = path.join(__dirname, firstAttachment.Title || 'extracted_attachment.bin'); fs.writeFile(outputPath, firstAttachment.Data, (writeErr) => { if (writeErr) { console.error('Error writing attachment to file:', writeErr); } else { console.log(`Attachment written to: ${outputPath}`); } }); } else { console.log('No attachments or content found in TNEF buffer.'); } });
tnef --version
Debug
Known issues
gotchaThe library utilizes a callback-based asynchronous API (`(err, content) => { ... }`) for its `parse` and `parseBuffer` methods. Modern Node.js development often favors Promises or async/await syntax. Developers expecting Promise-based functions will need to wrap the callback-based methods or adapt their code accordingly.
fix
Use Node.js's `util.promisify` to convert the callback-based methods into Promise-returning functions if `async/await` is desired, or adhere to the callback pattern.
affects: >=1.0.0
breakingIn version 1.4.0, the `bluebird` promise library was removed as a dependency. While primarily an internal change for promise management, if any consuming application had an implicit reliance on `bluebird` being present or its specific promise behavior when interacting with `node-tnef`'s internals, this could lead to unexpected behavior.
fix
If your project implicitly relied on `bluebird` through `node-tnef`, explicitly install `bluebird` as a direct dependency or migrate to native Promises where appropriate. The library itself now uses native Node.js asynchronous patterns.
affects: >=1.4.0
gotchaWhen processing files or directories, `node-tnef` explicitly checks for the TNEF signature. If a file does not contain this signature, the parser will log a message to the console and skip the file without throwing an error in the programmatic API. Users should implement their own validation if specific error handling for non-TNEF files is required.
fix
Before passing files to `tnef.parse`, consider pre-validating their content or implementing custom error handling in your callback to differentiate between actual parsing failures and non-TNEF files.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'bluebird'
An application (or an older version of node-tnef) implicitly or explicitly expected `bluebird` to be available, but it was removed in v1.4.0 or not installed.
fix
For `node-tnef` v1.4.0 and later, `bluebird` is no longer a dependency. If your project still requires `bluebird`, install it explicitly: `npm install bluebird`.
TypeError: tnef.parse is not a function
This error often occurs when attempting to use ESM `import { parse } from 'node-tnef'` or similar destructuring, but the module primarily exposes an object via CommonJS `module.exports` or properties on `module.exports`.
fix
Ensure you are using the CommonJS `require` syntax and accessing methods as properties: `const tnef = require('node-tnef'); tnef.parse(...);`
Error: callback is not a function
The `parse` or `parseBuffer` method was called without providing a valid callback function as its second argument, or the provided argument was not a function.
fix
Always provide a callback function in the format `(err, content) => { ... }` as the second argument to `tnef.parse` and `tnef.parseBuffer`.
file does not contain the TNEF signature
The input file specified to `tnef.parse` (or a file within a directory scanned by the CLI) was not a valid TNEF file. The library detected that the file did not begin with the expected TNEF magic number.
fix
Verify that the file you are attempting to parse is indeed a TNEF-encoded file (e.g., typically named `winmail.dat`). The library will skip non-TNEF files without throwing a programmatic error, but logs this message to the console.
Upgrade
Version history
1.4.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
node-tnef — npm install node-tnef · libregistry