emailengine-app 2.79.1 → 2.79.3

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.
Files changed (87) hide show
  1. package/.github/workflows/deploy.yml +92 -39
  2. package/.github/workflows/release.yaml +94 -34
  3. package/.release-please-manifest.json +1 -1
  4. package/CHANGELOG.md +85 -0
  5. package/bin/emailengine.js +8 -1
  6. package/config/default.toml +6 -0
  7. package/copy-static-files.sh +23 -2
  8. package/data/google-crawlers.json +1 -1
  9. package/lib/account.js +138 -18
  10. package/lib/api-routes/account-routes.js +13 -1
  11. package/lib/api-routes/index.js +12 -0
  12. package/lib/api-routes/mailbox-routes.js +6 -0
  13. package/lib/api-routes/mcp-oauth-routes.js +259 -0
  14. package/lib/api-routes/mcp-routes.js +172 -0
  15. package/lib/api-routes/message-routes.js +125 -4
  16. package/lib/api-routes/outbox-routes.js +7 -0
  17. package/lib/api-routes/permission-map.js +97 -1
  18. package/lib/api-routes/route-helpers.js +16 -4
  19. package/lib/api-routes/route-metadata.js +24 -4
  20. package/lib/api-routes/submit-routes.js +41 -0
  21. package/lib/api-routes/template-routes.js +7 -0
  22. package/lib/api-routes/token-routes.js +4 -2
  23. package/lib/consts.js +30 -1
  24. package/lib/email-client/base-client.js +235 -163
  25. package/lib/email-client/gmail-client.js +99 -22
  26. package/lib/email-client/imap/mailbox.js +140 -66
  27. package/lib/email-client/imap-client.js +74 -68
  28. package/lib/email-client/outlook-client.js +29 -14
  29. package/lib/enum-descriptions.js +2 -1
  30. package/lib/field-usage.js +17 -1
  31. package/lib/logger.js +43 -3
  32. package/lib/lua/s-list-accounts.lua +5 -2
  33. package/lib/mcp/index.js +29 -0
  34. package/lib/mcp/inject.js +70 -0
  35. package/lib/mcp/json-schema.js +120 -0
  36. package/lib/mcp/listen.js +171 -0
  37. package/lib/mcp/oauth.js +324 -0
  38. package/lib/mcp/protocol.js +489 -0
  39. package/lib/mcp/resources.js +139 -0
  40. package/lib/mcp/tools.js +655 -0
  41. package/lib/openapi/index.js +3 -1
  42. package/lib/response-stream.js +52 -21
  43. package/lib/routes-ui.js +4 -0
  44. package/lib/schemas.js +24 -3
  45. package/lib/token-permission-view.js +104 -8
  46. package/lib/tokens.js +34 -5
  47. package/lib/tools.js +96 -0
  48. package/lib/ui-routes/account-routes.js +43 -1
  49. package/lib/ui-routes/admin-config-routes.js +114 -1
  50. package/lib/ui-routes/admin-entities-routes.js +54 -5
  51. package/lib/ui-routes/auth-routes.js +13 -0
  52. package/lib/ui-routes/mcp-consent-routes.js +330 -0
  53. package/lib/ui-routes/route-helpers.js +116 -1
  54. package/lib/utils/network.js +9 -1
  55. package/lib/web-safe-html.js +61 -0
  56. package/lib/webhooks.js +3 -8
  57. package/package.json +15 -14
  58. package/sbom.json +1 -1
  59. package/scripts/README.md +25 -0
  60. package/scripts/build-icon.js +77 -0
  61. package/server.js +21 -9
  62. package/static/css/flyonui.css +1 -1
  63. package/static/css/src/app.tailwind.css +98 -0
  64. package/static/emailengine.ico +0 -0
  65. package/static/js/ui.js +465 -1
  66. package/static/licenses.html +85 -135
  67. package/translations/messages.pot +103 -103
  68. package/views/config/mcp.hbs +361 -0
  69. package/views/config/oauth/index.hbs +7 -0
  70. package/views/layout/prompt.hbs +62 -0
  71. package/views/mcp/authorize.hbs +136 -0
  72. package/views/partials/head_assets.hbs +3 -3
  73. package/views/partials/mcp_access_levels.hbs +13 -0
  74. package/views/partials/mcp_account_limit.hbs +14 -0
  75. package/views/partials/mcp_tool_count.hbs +19 -0
  76. package/views/partials/side_menu.hbs +1 -0
  77. package/views/partials/ui/account-picker.hbs +59 -0
  78. package/views/partials/ui/code-block.hbs +26 -0
  79. package/views/partials/ui/menu-item.hbs +5 -0
  80. package/views/partials/ui/radio.hbs +41 -0
  81. package/views/partials/ui/tab.hbs +15 -10
  82. package/views/partials/ui/tabs.hbs +8 -5
  83. package/views/templates/template.hbs +4 -3
  84. package/views/tokens/index.hbs +8 -2
  85. package/views/tokens/new.hbs +514 -243
  86. package/winconf.js +148 -48
  87. package/workers/api.js +198 -48
package/winconf.js CHANGED
@@ -3,17 +3,42 @@
3
3
  const { load } = require('resedit/cjs');
4
4
  const PackageData = require('./package.json');
5
5
 
6
- const { readFileSync, writeFileSync, existsSync } = require('fs');
6
+ const { readFileSync, writeFileSync, renameSync, existsSync } = require('fs');
7
+
8
+ // Windows reads this as the file's "Company". Leaving it unset is not neutral: the exe then
9
+ // inherits "Node.js" from the pkg base binary the build starts from, and that is what every
10
+ // release up to 2.79.1 shipped.
11
+ const COMPANY = 'Postal Systems OÜ';
12
+
13
+ // pkg writes <name>-<target minus its node prefix>.exe into pkg.outputPath, so the file this
14
+ // script rewrites is derived from the same config pkg built it from and cannot drift out of it.
15
+ const winTarget = PackageData.pkg.targets.find(target => /-win-/.test(target));
16
+ if (!winTarget) {
17
+ throw new Error('No Windows target found in package.json pkg.targets');
18
+ }
19
+
20
+ // The command this binary is installed as, which is what OriginalFilename and InternalName are
21
+ // supposed to name.
22
+ const binName = Object.keys(PackageData.bin)[0];
7
23
 
8
24
  const options = {
9
- in: './ee-dist/emailengine-app-win-x64.exe',
10
- out: './ee-dist/emailengine-app-win-x64.exe',
25
+ exe: `./${PackageData.pkg.outputPath}/${PackageData.name}-${winTarget.replace(/^node\d+-/, '')}.exe`,
11
26
  version: PackageData.version,
12
27
  properties: {
13
- LegalCopyright: 'Postal Systems OÜ',
28
+ CompanyName: COMPANY,
29
+ LegalCopyright: `Copyright (c) ${COMPANY}`,
14
30
  FileDescription: 'EmailEngine allows access to email accounts using REST API',
15
- ProductName: 'EmailEngine'
31
+ ProductName: PackageData.productTitle,
32
+ // These describe the file as it actually ships. pkg leaves node.exe's own values here,
33
+ // which the previous revision of this script deleted outright rather than correcting.
34
+ OriginalFilename: `${binName}.exe`,
35
+ InternalName: binName,
36
+ // setProductVersion() below writes the four-part numeric form into this string as well.
37
+ // Restating it here puts the exact package version back, which is the only place a
38
+ // prerelease suffix can survive and the field the properties dialog shows.
39
+ ProductVersion: PackageData.version
16
40
  },
41
+ // Rebuilt by scripts/build-icon.js, which keeps it small enough for the check below
17
42
  icon: 'static/emailengine.ico'
18
43
  };
19
44
 
@@ -22,16 +47,62 @@ const language = {
22
47
  codepage: 1200
23
48
  };
24
49
 
50
+ /**
51
+ * Offset of the payload pkg appends after the last PE section.
52
+ *
53
+ * pkg addresses that payload by absolute file offset, so rewriting resources is only safe while
54
+ * .rsrc still fits the raw allocation the linker gave it. Once it does not, the section grows,
55
+ * every later section and the payload slide down the file, and the binary dies on startup with
56
+ * "SyntaxError: Invalid or unexpected token" out of readPrelude. The icon is the only input here
57
+ * big enough to cross that line - an .ico whose large members are uncompressed BMP rather than
58
+ * PNG is several hundred KB on its own - and nothing downstream would catch it: the exe is still
59
+ * well formed, its icons and version strings still read back correctly, and it still signs and
60
+ * hashes like a good build.
61
+ *
62
+ * Reads the section table off the parsed executable, which reflects the edit as soon as
63
+ * outputResource() has run, so the same call answers for both the before and the after image.
64
+ */
65
+ function payloadOffset(executable) {
66
+ return executable.getAllSections().reduce((offset, section) => Math.max(offset, section.info.pointerToRawData + section.info.sizeOfRawData), 0);
67
+ }
68
+
69
+ function resourceSection(executable) {
70
+ return executable.getAllSections().find(section => section.info.name === '.rsrc');
71
+ }
72
+
73
+ /**
74
+ * A Windows version resource is four 16-bit numbers, and semver does not map onto it - the
75
+ * prerelease and build parts have nowhere to go. Take the leading integer of each of the first
76
+ * four dot-separated components. The string overload of setFileVersion() is used rather than the
77
+ * numeric one because a tuple shorter than four slides the language argument into the revision
78
+ * slot, so a two-part version would be stamped as 2.79.0.1033.
79
+ */
80
+ function toWindowsVersion(version) {
81
+ const parts = String(version || '').split('.');
82
+
83
+ // Indexing fixed slots rather than padding: a missing component and an unparseable one both
84
+ // have to end up as 0, and parseInt(undefined) is NaN just like parseInt('x')
85
+ return [0, 1, 2, 3]
86
+ .map(index => parseInt(parts[index], 10))
87
+ .map(value => (value >= 0 ? Math.min(value, 0xffff) : 0))
88
+ .join('.');
89
+ }
90
+
25
91
  load()
26
92
  .then(ResEdit => {
27
- // Check if input file exists
28
- if (!existsSync(options.in)) {
29
- throw new Error(`Input file not found: ${options.in}`);
93
+ // Both inputs checked up front, so a missing one is reported as itself rather than as
94
+ // whatever readFileSync happens to throw further down
95
+ if (!existsSync(options.exe)) {
96
+ throw new Error(`Input file not found: ${options.exe}`);
97
+ }
98
+
99
+ if (!existsSync(options.icon)) {
100
+ throw new Error(`Icon file not found: ${options.icon}`);
30
101
  }
31
102
 
32
103
  // Modify .exe w/ ResEdit
33
- const data = readFileSync(options.in);
34
- const executable = ResEdit.NtExecutable.from(data);
104
+ const original = readFileSync(options.exe);
105
+ const executable = ResEdit.NtExecutable.from(original);
35
106
  const res = ResEdit.NtExecutableResource.from(executable);
36
107
  const versionInfos = ResEdit.Resource.VersionInfo.fromEntries(res.entries);
37
108
 
@@ -41,53 +112,82 @@ load()
41
112
 
42
113
  const vi = versionInfos[0];
43
114
 
44
- // Remove original filename
45
- vi.removeStringValue(language, 'OriginalFilename');
46
- vi.removeStringValue(language, 'InternalName');
47
-
48
- // Product version
49
- if (options.version) {
50
- // Convert version to tuple of 3 numbers
51
- const version = options.version
52
- .split('.')
53
- .map(v => Number(v) || 0)
54
- .slice(0, 3);
55
-
56
- // Update versions
57
- vi.setProductVersion(...version, 0, language.lang);
58
- vi.setFileVersion(...version, 0, language.lang);
59
- }
60
-
61
- // Add additional user specified properties
62
- if (options.properties) {
63
- vi.setStringValues(language, options.properties);
64
- }
115
+ const fileVersion = toWindowsVersion(options.version);
116
+ vi.setFileVersion(fileVersion, language.lang);
117
+ vi.setProductVersion(fileVersion, language.lang);
65
118
 
119
+ vi.setStringValues(language, options.properties);
66
120
  vi.outputToResourceEntries(res.entries);
67
121
 
68
122
  // Add icon
69
- if (options.icon) {
70
- if (!existsSync(options.icon)) {
71
- throw new Error(`Icon file not found: ${options.icon}`);
72
- }
73
- const iconFile = ResEdit.Data.IconFile.from(readFileSync(options.icon));
74
- ResEdit.Resource.IconGroupEntry.replaceIconsForResource(
75
- res.entries,
76
- 1,
77
- language.lang,
78
- iconFile.icons.map(item => item.data)
123
+ const iconFile = ResEdit.Data.IconFile.from(readFileSync(options.icon));
124
+ ResEdit.Resource.IconGroupEntry.replaceIconsForResource(
125
+ res.entries,
126
+ 1,
127
+ language.lang,
128
+ iconFile.icons.map(item => item.data)
129
+ );
130
+
131
+ // Regenerate the .exe. The allocation is read before the edit because that is the budget
132
+ // the linker set; once the section has grown, it has already grown to fit
133
+ const offsetBefore = payloadOffset(executable);
134
+ const allocated = resourceSection(executable).info.sizeOfRawData;
135
+ res.outputResource(executable);
136
+ const offsetAfter = payloadOffset(executable);
137
+ const rsrc = resourceSection(executable);
138
+ const updated = Buffer.from(executable.generate());
139
+
140
+ // Refuse to write a binary whose payload moved - see payloadOffset() above. Checked
141
+ // before the write so a build that would not start never reaches the disk at all
142
+ if (offsetAfter !== offsetBefore || !original.subarray(offsetBefore).equals(updated.subarray(offsetAfter))) {
143
+ throw new Error(
144
+ `Rewriting the resources moved the appended pkg payload (${offsetBefore} -> ${offsetAfter}), which produces an executable that cannot start. ` +
145
+ `The resources need ${rsrc.info.virtualSize} bytes but only ${allocated} are allocated for .rsrc - ` +
146
+ `shrink ${options.icon} by at least ${rsrc.info.virtualSize - allocated} bytes, PNG-compressing its largest members.`
79
147
  );
80
148
  }
81
149
 
82
- // Regenerate and write to .exe
83
- res.outputResource(executable);
84
- writeFileSync(options.out, Buffer.from(executable.generate()));
150
+ // Written beside the target and renamed into place, as a half-written 140MB exe would
151
+ // otherwise look like a finished build to every later step
152
+ const tmpPath = `${options.exe}.tmp`;
153
+ writeFileSync(tmpPath, updated);
154
+ renameSync(tmpPath, options.exe);
155
+
156
+ // Read back what was written. Signing, hashing and the release upload all treat this
157
+ // file as final, so a resource edit that silently did not apply has no later chance of
158
+ // being caught
159
+ const writtenRes = ResEdit.NtExecutableResource.from(ResEdit.NtExecutable.from(readFileSync(options.exe)));
160
+ const writtenInfo = ResEdit.Resource.VersionInfo.fromEntries(writtenRes.entries)[0];
161
+ const written = writtenInfo ? writtenInfo.getStringValues(language) : {};
162
+
163
+ const expected = Object.assign({ FileVersion: fileVersion }, options.properties);
164
+ for (const [key, value] of Object.entries(expected)) {
165
+ if (written[key] !== value) {
166
+ throw new Error(`Property ${key} did not apply, expected ${JSON.stringify(value)} but found ${JSON.stringify(written[key])}`);
167
+ }
168
+ }
85
169
 
86
- console.log(`Successfully updated ${options.out}`);
87
- console.log(` Version: ${options.version}`);
88
- console.log(` Icon: ${options.icon || 'not set'}`);
170
+ const iconSizes = iconFile.icons.map(icon => `${icon.width || 256}x${icon.height || 256}`);
171
+
172
+ console.log(`Successfully updated ${options.exe}`);
173
+ console.log(` Version: ${options.version} (resource ${fileVersion})`);
174
+ console.log(` Company: ${options.properties.CompanyName}`);
175
+ console.log(` Icon: ${options.icon} (${iconSizes.join(', ')})`);
176
+
177
+ // The margin the payload check above depends on. Reported on every build so it is a
178
+ // visible gauge rather than a cliff that a slightly larger icon walks off
179
+ console.log(
180
+ ` Resources: ${rsrc.info.virtualSize} of ${rsrc.info.sizeOfRawData} bytes allocated for .rsrc (${rsrc.info.sizeOfRawData - rsrc.info.virtualSize} spare)`
181
+ );
182
+
183
+ // Windows picks the closest image out of the group and scales it down. Without a small
184
+ // one, the Explorer list view, the title bar and the taskbar all show a resampled 256px
185
+ // image, which is visibly softer than a purpose-drawn 16x16
186
+ if (!iconFile.icons.some(icon => (icon.width || 256) <= 48)) {
187
+ console.log(' Note: the icon has no image at 48x48 or smaller, Windows will downscale the largest one');
188
+ }
89
189
  })
90
190
  .catch(err => {
91
- console.error('Error modifying Windows executable:', err.message);
191
+ console.error('Error modifying Windows executable:', err);
92
192
  process.exit(1);
93
193
  });