{"library":"node-tnef","title":"TNEF Parser for Node.js","description":"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.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install node-tnef"],"cli":{"name":"tnef","version":null}},"imports":["const tnef = require('node-tnef')","const tnef = require('node-tnef');\ntnef.parse('/path/to/winmail.dat', (err, content) => { /* ... */ });","const tnef = require('node-tnef');\ntnef.parseBuffer(yourBuffer, (err, content) => { /* ... */ });"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const tnef = require('node-tnef');\nconst fs = require('fs');\nconst path = require('path');\n\n// A minimal, valid TNEF signature prefix for demonstration.\n// A real winmail.dat file would be much larger and complex.\nconst dummyTnefBuffer = Buffer.from(\n  '\\x22\\x34\\x71\\x9A\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00',\n  'binary'\n);\n\ntnef.parseBuffer(dummyTnefBuffer, (err, content) => {\n  if (err) {\n    console.error('Error parsing TNEF buffer:', err);\n    return;\n  }\n\n  if (content && content.length > 0) {\n    console.log(`Found ${content.length} attachment(s).`);\n    const firstAttachment = content[0];\n    console.log('First attachment title:', firstAttachment.Title);\n\n    // Example: Writing the attachment data to a file\n    const outputPath = path.join(__dirname, firstAttachment.Title || 'extracted_attachment.bin');\n    fs.writeFile(outputPath, firstAttachment.Data, (writeErr) => {\n      if (writeErr) {\n        console.error('Error writing attachment to file:', writeErr);\n      } else {\n        console.log(`Attachment written to: ${outputPath}`);\n      }\n    });\n  } else {\n    console.log('No attachments or content found in TNEF buffer.');\n  }\n});\n","lang":"javascript","description":"Demonstrates how to use `tnef.parseBuffer` to process an in-memory TNEF buffer and extract its contents, including writing an attachment to a file.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}