postal-mime 2.2.3 → 2.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +52 -0
- package/package.json +1 -1
- package/postal-mime.d.ts +16 -1
- package/src/postal-mime.js +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.2.5](https://github.com/postalsys/postal-mime/compare/v2.2.4...v2.2.5) (2024-04-11)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **types:** Fixed Address type ([57908e4](https://github.com/postalsys/postal-mime/commit/57908e428929904ee312d9e95343a9fbf52542b4))
|
|
9
|
+
|
|
10
|
+
## [2.2.4](https://github.com/postalsys/postal-mime/compare/v2.2.3...v2.2.4) (2024-04-11)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **exports:** Export addressParser and decodeWords functions ([43d3187](https://github.com/postalsys/postal-mime/commit/43d31873308d8eff61876f32614e5cc5143c90dd))
|
|
16
|
+
|
|
3
17
|
## [2.2.3](https://github.com/postalsys/postal-mime/compare/v2.2.2...v2.2.3) (2024-04-11)
|
|
4
18
|
|
|
5
19
|
|
package/README.md
CHANGED
|
@@ -123,6 +123,58 @@ This method parses an email message into a structured object with the following
|
|
|
123
123
|
- **attachment[].contentId** is the ID from Content-ID header
|
|
124
124
|
- **attachment[].content** is an Uint8Array value that contains the attachment file
|
|
125
125
|
|
|
126
|
+
### Utility functions
|
|
127
|
+
|
|
128
|
+
#### addressParser
|
|
129
|
+
|
|
130
|
+
Parse email address strings
|
|
131
|
+
|
|
132
|
+
```js
|
|
133
|
+
addressParser(addressStr, opts) -> Array
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
where
|
|
137
|
+
|
|
138
|
+
- **addressStr** is the header value for an address header
|
|
139
|
+
- **opts** is an optional options object
|
|
140
|
+
- **flatten** 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
|
|
141
|
+
|
|
142
|
+
The result is an array of objects
|
|
143
|
+
|
|
144
|
+
- **name** is the name string. An empty string is used if name value was not set.
|
|
145
|
+
- **address** is the email address value
|
|
146
|
+
- **group** is an array of nested address objects. This is used when `flatten` is `false` (the default) and the address string contains address group syntax
|
|
147
|
+
|
|
148
|
+
```js
|
|
149
|
+
import { addressParser } from 'postal-mime';
|
|
150
|
+
|
|
151
|
+
const addressStr = '=?utf-8?B?44Ko44Od44K544Kr44O844OJ?= <support@example.com>';
|
|
152
|
+
console.log(addressParser(addressStr));
|
|
153
|
+
// [ { name: 'エポスカード', address: 'support@example.com' } ]
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
#### decodeWords
|
|
157
|
+
|
|
158
|
+
Decode MIME encoded-words
|
|
159
|
+
|
|
160
|
+
```js
|
|
161
|
+
decodeWords(encodedStr) -> String
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
where
|
|
165
|
+
|
|
166
|
+
- **encodedStr** is a string value that _may_ include MIME encoded-words
|
|
167
|
+
|
|
168
|
+
The result is a unicode string
|
|
169
|
+
|
|
170
|
+
```js
|
|
171
|
+
import { decodeWords } from 'postal-mime';
|
|
172
|
+
|
|
173
|
+
const encodedStr = 'Hello, =?utf-8?B?44Ko44Od44K544Kr44O844OJ?=';
|
|
174
|
+
console.log(decodeWords(encodedStr));
|
|
175
|
+
// Hello, エポスカード
|
|
176
|
+
```
|
|
177
|
+
|
|
126
178
|
## License
|
|
127
179
|
|
|
128
180
|
© 2021-2024 Andris Reinman
|
package/package.json
CHANGED
package/postal-mime.d.ts
CHANGED
|
@@ -3,8 +3,9 @@ export type RawEmail = string | ArrayBuffer | Uint8Array | Blob | Buffer | Reada
|
|
|
3
3
|
export type Header = Record<string, string>;
|
|
4
4
|
|
|
5
5
|
export type Address = {
|
|
6
|
-
address: string;
|
|
7
6
|
name: string;
|
|
7
|
+
address?: string;
|
|
8
|
+
group?: Address[]
|
|
8
9
|
};
|
|
9
10
|
|
|
10
11
|
export type Attachment = {
|
|
@@ -38,9 +39,23 @@ export type Email = {
|
|
|
38
39
|
attachments: Attachment[];
|
|
39
40
|
};
|
|
40
41
|
|
|
42
|
+
declare type AddressParserOptions = {
|
|
43
|
+
flatten?: boolean
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
declare function addressParser (
|
|
47
|
+
str: string,
|
|
48
|
+
opts?: AddressParserOptions
|
|
49
|
+
): Address[];
|
|
50
|
+
|
|
51
|
+
declare function decodeWords (
|
|
52
|
+
str: string
|
|
53
|
+
): string;
|
|
54
|
+
|
|
41
55
|
declare class PostalMime {
|
|
42
56
|
static parse(email: RawEmail): Promise<Email>;
|
|
43
57
|
parse(email: RawEmail): Promise<Email>;
|
|
44
58
|
}
|
|
45
59
|
|
|
60
|
+
export { addressParser, decodeWords };
|
|
46
61
|
export default PostalMime;
|
package/src/postal-mime.js
CHANGED
|
@@ -3,6 +3,8 @@ import { textToHtml, htmlToText, formatTextHeader, formatHtmlHeader } from './te
|
|
|
3
3
|
import addressParser from './address-parser.js';
|
|
4
4
|
import { decodeWords, textEncoder, blobToArrayBuffer } from './decode-strings.js';
|
|
5
5
|
|
|
6
|
+
export { addressParser, decodeWords };
|
|
7
|
+
|
|
6
8
|
export default class PostalMime {
|
|
7
9
|
static parse(buf) {
|
|
8
10
|
const parser = new PostalMime();
|