# Changelog

## 5.2.0

### Added

- New friendly field mappings: `importance` (0017), `priority` (0026),
  `sensitivity` (0036), `clientSubmitTime` (0039), `sentRepresentingName`
  (0042), `submitFlags` (0047), `sentRepresentingAddressType` (0064),
  `sentRepresentingEmail` (0065), `conversationTopic` (0070),
  `deliverTime` (0E06), `messageFlags` (0E07), `hasAttachments` (0E1B),
  `lastModifierName` (3FFA).
- `getAttachment()` / `getAttachmentByIndex()` / `getAttachmentData()` now
  also return `dataId`, `attachMethod`, `attachContentLocation` and
  `extraProperties` alongside the content.

### Fixed

- OLE header is validated (byte-order mark, sector shift 9/12, major
  version 3/4 with consistency check, mini sector shift, minimum size);
  corrupt headers throw `InvalidMsgFileError` instead of parsing with a
  wrong sector size.
- Same-ID/different-type streams (e.g. `0070_0102` binary vs `0070_001F`
  topic string, `0047_0102` blob vs `submitFlags`) no longer overwrite
  typed fields — values whose kind mismatches the mapping are ignored.
- Absolute-offset reads (`readByte`/`readShort`/`readInt`/`readStringAt`)
  throw `RangeError` with the true offset instead of a clamped position.
- Truncated RTF payloads (LZFu and MELA) throw instead of silently
  returning partial output; pass `{ verifyCrc: false }` to `decompressRtf()`
  to salvage partial data.
- Removed duplicate `bodyHtml` row in the README field table; documented
  the new fields and attachment metadata.

## 5.1.0

### Added

- Embedded messages parse recursively into `attachment.embeddedMessage`
  (depth-bounded at 10 levels); `getAttachment()` on one throws a
  descriptive error pointing at the field.
- `getHtmlBody()` decodes `PidTagBodyHtml` for both binary (`0102`) and
  string (`001E`) storage (BOM → `<meta charset>` → strict-UTF-8 →
  message codepage); `bodyHtml` is typed `Uint8Array | string`.
- True dual ESM + CommonJS builds (`lib-esm/` with `module`/`exports` map,
  `.js`-suffixed imports).
- Regression fixtures and suites: 9 Apache POI samples plus an OSS-Fuzz
  crasher (47 assertions total).
- `001E` codepage also resolved from `__properties_version1.0` fixed
  properties, per directory scope (fixes e.g. CP1251 messages like
  `cyrillic_message.msg`).

## 5.0.0

Major release — correctness, API, packaging and feature overhaul.

### Breaking changes

- Invalid files now throw `InvalidMsgFileError` instead of returning
  `{ error: 'Unsupported file type!' }`. Use the new non-throwing
  `MsgReader.isMsgFile(input)` guard when the input type is unknown.
- `getAttachment()` returns a richer object (`fileName`, `fileNameShort`,
  `extension`, `mimeType`, `pidContentId`, `contentLength`, `content`);
  `contentLength` is the actual decoded byte length. Out-of-range indexes
  throw `RangeError`, invalid descriptors throw `TypeError`.
- Empty text streams decode as `''` instead of `null`.
- Corrupt OLE structure (bad FAT / property chain) throws instead of
  hanging or returning garbage.
- License corrected to Apache-2.0 (matching the source file headers).
- TypeScript build target raised to ES2020 with `strict` mode; the public
  type surface is exported from the package entry point.

### Fixes

- SBAT chain walk no longer treats block id `0` as end-of-chain.
- Property-hierarchy builder is cycle-safe (visited sets, bounded queues).
- Null property entries are guarded everywhere (no more `TypeError` on
  sparse/unknown entry types).
- Large (BAT) streams spanning multiple big blocks are now reassembled by
  following the FAT chain (previously only the first block's file offset was
  read, which only worked when blocks happened to be contiguous).
- Mini-stream reads are memoized (root chain resolved once) and chunked
  instead of re-walking the chain per small block (O(n²) → O(n)).
- `DataStream` rewritten read-only: no reallocation on reads, correct
  handling of views with nonzero `byteOffset` (e.g. pooled Node Buffers),
  `RangeError` on overruns, fixed `readInt32Array`/`readUint16Array` default
  length computation, removed write paths and dead code.
- Property names and string values are stripped of trailing NUL terminators.
- Unchecked allocations (`new Array(batCount)`, `new Int8Array(size)`) are
  validated and capped (`MAX_DOCUMENT_SIZE`).

### Features

- New field mappings: `messageClass`, `subjectPrefix`, `normalizedSubject`,
  `senderSmtpAddress`, `displayTo/Cc/Bcc`, `bodyHtml` (1013), `internetMessageId`,
  `addressType`, `smtpAddress`, `searchKey`, `extension`, `attachMethod`,
  `mimeType` (370E), `attachContentLocation`; scalar `0003` (int), `000B`
  (bool) and `0040` (FILETIME → `Date`) types decode.
- Unmapped scalar tags are preserved in `extraProperties` (keyed by tag).
- `decompressRtf()` / `decompressRtfToString()` (MS-OXRTFCP LZFu, CRC-checked)
  plus `MsgReader.getRtfBody()`.
- New APIs: `getAttachmentByIndex`, `getAttachmentData`, `getProperties`,
  `MsgReader.isMsgFile`, `codepageToEncoding`.
- `001E` strings decode with `PidTagMessageCodepage` when present
  (windows-1252 fallback); embedded-message attachments throw a descriptive
  error from `getAttachment()`.
- Constructor accepts `Buffer`, `Uint8Array`, `ArrayBuffer`, `DataView` and
  generic buffer views; `getAttachment()` auto-parses (no need to call
  `getFileData()` first); `getFileData()` returns a defensive copy.
- Named ESM exports work (`import { MsgReader } from ...`); `exports` map,
  `files` list, keywords, description and `engines` added to package.json.

### Tooling

- `npm test` now builds and runs 30+ assertions with the Node test runner
  against `data/test.msg` (metadata, recipients, attachment md5, RTF
  round-trip, error paths, input-type matrix, ESM interop).
- TypeScript 5.x, `strict` + `noUncheckedIndexedAccess`, sourcemaps and
  declaration maps; `.prettierrc` moved to the repo root.
