postal-mime 2.2.3 → 2.2.4

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.2.4](https://github.com/postalsys/postal-mime/compare/v2.2.3...v2.2.4) (2024-04-11)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **exports:** Export addressParser and decodeWords functions ([43d3187](https://github.com/postalsys/postal-mime/commit/43d31873308d8eff61876f32614e5cc5143c90dd))
9
+
3
10
  ## [2.2.3](https://github.com/postalsys/postal-mime/compare/v2.2.2...v2.2.3) (2024-04-11)
4
11
 
5
12
 
package/README.md CHANGED
@@ -123,6 +123,57 @@ 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
+ - **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
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
+
147
+ ```js
148
+ import { addressParser } from 'postal-mime';
149
+
150
+ const addressStr = '=?utf-8?B?44Ko44Od44K544Kr44O844OJ?= <support@example.com>';
151
+ console.log(addressParser(addressStr));
152
+ // [ { name: 'エポスカード', address: 'support@example.com' } ]
153
+ ```
154
+
155
+ #### decodeWords
156
+
157
+ Decode MIME encoded-words
158
+
159
+ ```js
160
+ decodeWords(encodedStr) -> String
161
+ ```
162
+
163
+ where
164
+
165
+ - **encodedStr** is a string value that _may_ include MIME encoded-words
166
+
167
+ The result is a unicode string
168
+
169
+ ```js
170
+ import { decodeWords } from 'postal-mime';
171
+
172
+ const encodedStr = 'Hello, =?utf-8?B?44Ko44Od44K544Kr44O844OJ?=';
173
+ console.log(decodeWords(encodedStr));
174
+ // Hello, エポスカード
175
+ ```
176
+
126
177
  ## License
127
178
 
128
179
  &copy; 2021-2024 Andris Reinman
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postal-mime",
3
- "version": "2.2.3",
3
+ "version": "2.2.4",
4
4
  "description": "Email parser for browser environments",
5
5
  "main": "./src/postal-mime.js",
6
6
  "exports": {
package/postal-mime.d.ts CHANGED
@@ -38,9 +38,23 @@ export type Email = {
38
38
  attachments: Attachment[];
39
39
  };
40
40
 
41
+ declare type AddressParserOptions = {
42
+ flatten?: boolean
43
+ }
44
+
45
+ declare function addressParser (
46
+ str: string,
47
+ opts?: AddressParserOptions
48
+ ): Address[];
49
+
50
+ declare function decodeWords (
51
+ str: string
52
+ ): string;
53
+
41
54
  declare class PostalMime {
42
55
  static parse(email: RawEmail): Promise<Email>;
43
56
  parse(email: RawEmail): Promise<Email>;
44
57
  }
45
58
 
59
+ export { addressParser, decodeWords };
46
60
  export default PostalMime;
@@ -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();