postal-mime
Advanced tools
Comparing version 2.2.3 to 2.2.4
# Changelog | ||
## [2.2.4](https://github.com/postalsys/postal-mime/compare/v2.2.3...v2.2.4) (2024-04-11) | ||
### Bug Fixes | ||
* **exports:** Export addressParser and decodeWords functions ([43d3187](https://github.com/postalsys/postal-mime/commit/43d31873308d8eff61876f32614e5cc5143c90dd)) | ||
## [2.2.3](https://github.com/postalsys/postal-mime/compare/v2.2.2...v2.2.3) (2024-04-11) | ||
@@ -4,0 +11,0 @@ |
{ | ||
"name": "postal-mime", | ||
"version": "2.2.3", | ||
"version": "2.2.4", | ||
"description": "Email parser for browser environments", | ||
@@ -5,0 +5,0 @@ "main": "./src/postal-mime.js", |
@@ -41,2 +41,15 @@ export type RawEmail = string | ArrayBuffer | Uint8Array | Blob | Buffer | ReadableStream; | ||
declare type AddressParserOptions = { | ||
flatten?: boolean | ||
} | ||
declare function addressParser ( | ||
str: string, | ||
opts?: AddressParserOptions | ||
): Address[]; | ||
declare function decodeWords ( | ||
str: string | ||
): string; | ||
declare class PostalMime { | ||
@@ -47,2 +60,3 @@ static parse(email: RawEmail): Promise<Email>; | ||
export { addressParser, decodeWords }; | ||
export default PostalMime; |
@@ -126,2 +126,53 @@ # postal-mime | ||
### Utility functions | ||
#### addressParser | ||
Parse email address strings | ||
```js | ||
addressParser(addressStr, opts) -> Array | ||
``` | ||
where | ||
- **addressStr** is the header value for an address header | ||
- **opts** is an optional options object | ||
- **flattem** is a boolean value. If set to `true`, then ignores address groups and returns a flat array of addresses. By default (`flatten` is `false`) the result might include nested groups | ||
The result is an array of objects | ||
- **name** is the name string. An empty string is used if name value was not set. | ||
- **address** is the email address value | ||
```js | ||
import { addressParser } from 'postal-mime'; | ||
const addressStr = '=?utf-8?B?44Ko44Od44K544Kr44O844OJ?= <support@example.com>'; | ||
console.log(addressParser(addressStr)); | ||
// [ { name: 'γ¨γγΉγ«γΌγ', address: 'support@example.com' } ] | ||
``` | ||
#### decodeWords | ||
Decode MIME encoded-words | ||
```js | ||
decodeWords(encodedStr) -> String | ||
``` | ||
where | ||
- **encodedStr** is a string value that _may_ include MIME encoded-words | ||
The result is a unicode string | ||
```js | ||
import { decodeWords } from 'postal-mime'; | ||
const encodedStr = 'Hello, =?utf-8?B?44Ko44Od44K544Kr44O844OJ?='; | ||
console.log(decodeWords(encodedStr)); | ||
// Hello, γ¨γγΉγ«γΌγ | ||
``` | ||
## License | ||
@@ -128,0 +179,0 @@ |
@@ -6,2 +6,4 @@ import MimeNode from './mime-node.js'; | ||
export { addressParser, decodeWords }; | ||
export default class PostalMime { | ||
@@ -8,0 +10,0 @@ static parse(buf) { |
133626
3862
182