@postalsys/email-text-tools 1.2.4 → 1.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.
@@ -11,6 +11,8 @@ async function main() {
11
11
 
12
12
  const summary = await generateSummary(
13
13
  {
14
+ from: parsed.from.value,
15
+ subject: parsed.subject,
14
16
  html: parsed.html,
15
17
  text: parsed.text
16
18
  },
@@ -26,8 +26,8 @@ All the text that follows from now on is the email message:
26
26
 
27
27
  async function generateSummary(message, apiToken) {
28
28
  let text = message.text;
29
- if (!text && message.html) {
30
- text = htmlToText(message.text);
29
+ if (message.html && (!text || message.html.length > text.length * 10)) {
30
+ text = htmlToText(message.html);
31
31
  }
32
32
 
33
33
  text = text.trim();
@@ -35,6 +35,21 @@ async function generateSummary(message, apiToken) {
35
35
  text = text.substring(0, MAX_TEXT_LENGTH);
36
36
  }
37
37
 
38
+ let header = [];
39
+ if (message.subject) {
40
+ header.push(`Subject: ${message.subject}`);
41
+ }
42
+ if (message.from) {
43
+ let from = [].concat(message.from || []).shift();
44
+ header.push(`From: ${from.name || from.address}`);
45
+ }
46
+
47
+ if (header.length) {
48
+ text = `${header.join('\n')}
49
+
50
+ ${text}`;
51
+ }
52
+
38
53
  let headers = {
39
54
  'User-Agent': `${packageData.name}/${packageData.version}`,
40
55
  Authorization: `Bearer ${apiToken}`,
@@ -65,6 +80,11 @@ ${text}`
65
80
 
66
81
  let data = await res.json();
67
82
 
83
+ console.log(`-----
84
+ ${text}
85
+ ----
86
+ ${JSON.stringify(data)}`);
87
+
68
88
  if (!res.ok) {
69
89
  if (data && data.error) {
70
90
  let error = new Error(data.error.message || data.error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postalsys/email-text-tools",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "description": "Email text tools",
5
5
  "main": "index.js",
6
6
  "scripts": {