mailqa 0.0.0-stage → 0.1.0
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/CONTRIBUTING.md +19 -0
- package/LICENSE +21 -0
- package/README.md +71 -2
- package/action.yml +16 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +139 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/rules.d.ts +6 -0
- package/dist/rules.js +127 -0
- package/dist/rules.js.map +1 -0
- package/dist/smtp.d.ts +28 -0
- package/dist/smtp.js +241 -0
- package/dist/smtp.js.map +1 -0
- package/dist/types.d.ts +32 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +52 -4
- package/skills/mailqa/SKILL.md +19 -0
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Contributing to mailqa
|
|
2
|
+
|
|
3
|
+
Contributions expanding email client compatibility rules, MIME parsing edge cases, and report formats are welcome!
|
|
4
|
+
|
|
5
|
+
## Development Setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun install
|
|
9
|
+
bun run typecheck
|
|
10
|
+
bun run build
|
|
11
|
+
bun test
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Good First Issues
|
|
15
|
+
|
|
16
|
+
- Add dark-mode (`prefers-color-scheme: dark` / `[data-ogsc]`) validation warnings in `src/rules.ts`
|
|
17
|
+
- Add spam-trigger phrasing and missing `List-Unsubscribe` header checks in `src/smtp.ts`
|
|
18
|
+
- Add Markdown report formatting (`--format markdown`) alongside `text` and `json`
|
|
19
|
+
- Add MJML / React Email example fixtures in `tests/`
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vidit Jain
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,72 @@
|
|
|
1
|
-
#
|
|
1
|
+
# mailqa
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Zero-dependency **local SMTP sandbox & email template QA CLI** for developers and AI coding agents—no Mailtrap account, SaaS sandbox, or Docker container required (`CLI + SDK + GitHub Action + Agent Skill`).
|
|
4
|
+
|
|
5
|
+
## Why?
|
|
6
|
+
|
|
7
|
+
Transactional emails routinely pass local compilation while silently breaking in real inboxes:
|
|
8
|
+
- **Gmail clips emails over 102 KB**, hiding footers and unsubscribe links
|
|
9
|
+
- **Outlook Desktop ignores `display:flex` / `display:grid`** and strips `position:fixed`/`absolute`
|
|
10
|
+
- **External `<link rel="stylesheet">` CSS and `data:image/*` payloads** get blocked across webmail clients
|
|
11
|
+
- **Placeholder `#` / `http://localhost` hrefs** or **unrendered `{{firstName}}` / `${url}` tokens** slip straight into production
|
|
12
|
+
|
|
13
|
+
`mailqa` runs both an offline HTML linter (`mailqa check`) and a real ephemeral local SMTP catcher (`mailqa sink`) that automatically audits every captured `.eml` message on arrival.
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
### 1. Audit rendered HTML / React Email / MJML outputs
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx mailqa check ./dist/emails
|
|
21
|
+
npx mailqa check ./welcome.html --format json
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### 2. Run a local SMTP sink & inspect captured mail
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# Terminal 1: point SMTP_HOST=127.0.0.1 SMTP_PORT=2525 here
|
|
28
|
+
npx mailqa sink --port 2525 --inbox .mailqa
|
|
29
|
+
|
|
30
|
+
# Terminal 2 / AI Agent: inspect captured emails + QA pass/fail reports
|
|
31
|
+
npx mailqa inbox --inbox .mailqa --format json
|
|
32
|
+
npx mailqa clear --inbox .mailqa
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Implemented QA Rules
|
|
36
|
+
|
|
37
|
+
| Rule ID | Severity | Check |
|
|
38
|
+
| :--- | :---: | :--- |
|
|
39
|
+
| `MQ-SIZE-001` | `warning` | Rendered HTML exceeds Gmail's `102 KB` clipping limit |
|
|
40
|
+
| `MQ-SEC-001` | `error` | Embedded `<script>` tag present in email body |
|
|
41
|
+
| `MQ-STYLE-001` | `error` | External `<link rel="stylesheet">` blocked by clients |
|
|
42
|
+
| `MQ-LAYOUT-001` | `warning` | `display:flex` / `display:grid` breaks Outlook Word renderer |
|
|
43
|
+
| `MQ-LAYOUT-002` | `warning` | `position:fixed` / `position:absolute` stripped by clients |
|
|
44
|
+
| `MQ-IMG-001` | `error` | Base64 `data:image/` URI blocked in Gmail and Outlook |
|
|
45
|
+
| `MQ-A11Y-001` | `warning` | `<img>` missing `alt` attribute |
|
|
46
|
+
| `MQ-LINK-001` | `error` | Placeholder (`#`, empty, `javascript:`) or `localhost`/`127.0.0.1` link |
|
|
47
|
+
| `MQ-TPL-001` | `error` | Unrendered `{{var}}`, `${var}`, or `<%= var %>` token |
|
|
48
|
+
|
|
49
|
+
## Programmatic SDK
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { auditEmailHtml, startSmtpSink, loadInbox } from 'mailqa';
|
|
53
|
+
|
|
54
|
+
const report = auditEmailHtml('<html><body><a href="#">Reset</a></body></html>', 'reset.html');
|
|
55
|
+
console.log(report.passed, report.issues);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## GitHub Actions
|
|
59
|
+
|
|
60
|
+
```yaml
|
|
61
|
+
- name: Verify rendered transactional emails
|
|
62
|
+
run: npx mailqa check ./dist/emails --format json
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Contributing & Agent Skill
|
|
66
|
+
|
|
67
|
+
- Copy [`skills/mailqa/SKILL.md`](./skills/mailqa/SKILL.md) to give coding agents local SMTP + template verification tools.
|
|
68
|
+
- See [CONTRIBUTING.md](./CONTRIBUTING.md) for local setup and `good first issue` ideas.
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
[MIT](./LICENSE)
|
package/action.yml
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: 'mailqa'
|
|
2
|
+
description: 'Audit rendered transactional HTML emails for Gmail/Outlook compatibility, broken links, and unrendered templates'
|
|
3
|
+
inputs:
|
|
4
|
+
path:
|
|
5
|
+
description: 'HTML email file or directory to audit'
|
|
6
|
+
required: true
|
|
7
|
+
format:
|
|
8
|
+
description: 'Output format (text or json)'
|
|
9
|
+
required: false
|
|
10
|
+
default: 'text'
|
|
11
|
+
runs:
|
|
12
|
+
using: 'composite'
|
|
13
|
+
steps:
|
|
14
|
+
- name: Run mailqa check
|
|
15
|
+
shell: bash
|
|
16
|
+
run: npx --yes mailqa@latest check "${{ inputs.path }}" --format "${{ inputs.format }}"
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { auditEmailHtml } from './rules.js';
|
|
5
|
+
import { loadInbox, startSmtpSink } from './smtp.js';
|
|
6
|
+
const VERSION = '0.1.0';
|
|
7
|
+
const HELP = `mailqa v${VERSION}
|
|
8
|
+
Zero-dependency local SMTP sandbox and email template QA CLI.
|
|
9
|
+
|
|
10
|
+
Usage:
|
|
11
|
+
mailqa check <fileOrDir> [--format text|json]
|
|
12
|
+
mailqa sink [--port 2525] [--inbox .mailqa]
|
|
13
|
+
mailqa inbox [--inbox .mailqa] [--format text|json]
|
|
14
|
+
mailqa clear [--inbox .mailqa]
|
|
15
|
+
`;
|
|
16
|
+
function collectHtmlFiles(target) {
|
|
17
|
+
const resolved = path.resolve(target);
|
|
18
|
+
if (!fs.existsSync(resolved)) {
|
|
19
|
+
throw new Error(`Path not found: ${resolved}`);
|
|
20
|
+
}
|
|
21
|
+
const stat = fs.statSync(resolved);
|
|
22
|
+
if (stat.isFile()) {
|
|
23
|
+
return [resolved];
|
|
24
|
+
}
|
|
25
|
+
const files = [];
|
|
26
|
+
for (const entry of fs.readdirSync(resolved, { withFileTypes: true })) {
|
|
27
|
+
if (entry.name === 'node_modules' || entry.name === '.git') {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const child = path.join(resolved, entry.name);
|
|
31
|
+
if (entry.isDirectory()) {
|
|
32
|
+
files.push(...collectHtmlFiles(child));
|
|
33
|
+
}
|
|
34
|
+
else if (/\.(html|htm)$/i.test(entry.name)) {
|
|
35
|
+
files.push(child);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return files;
|
|
39
|
+
}
|
|
40
|
+
function formatReportsText(reports) {
|
|
41
|
+
const lines = [];
|
|
42
|
+
for (const report of reports) {
|
|
43
|
+
const status = report.passed ? 'PASS' : 'FAIL';
|
|
44
|
+
lines.push(`${status} ${report.target} (${(report.byteSize / 1024).toFixed(1)} KB) — ${report.counts.error} error(s), ${report.counts.warning} warning(s)`);
|
|
45
|
+
for (const issue of report.issues) {
|
|
46
|
+
lines.push(` [${issue.severity.toUpperCase()}] ${issue.ruleId}: ${issue.title}`);
|
|
47
|
+
lines.push(` Detail: ${issue.detail}`);
|
|
48
|
+
lines.push(` Fix : ${issue.fix}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return lines.join('\n');
|
|
52
|
+
}
|
|
53
|
+
function getFlag(args, name, fallback) {
|
|
54
|
+
const idx = args.indexOf(name);
|
|
55
|
+
if (idx !== -1 && args[idx + 1]) {
|
|
56
|
+
return args[idx + 1];
|
|
57
|
+
}
|
|
58
|
+
return fallback;
|
|
59
|
+
}
|
|
60
|
+
async function main() {
|
|
61
|
+
const argv = process.argv.slice(2);
|
|
62
|
+
const cmd = argv[0];
|
|
63
|
+
if (!cmd || cmd === '-h' || cmd === '--help') {
|
|
64
|
+
console.log(HELP);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (cmd === '-v' || cmd === '--version') {
|
|
68
|
+
console.log(VERSION);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const format = getFlag(argv, '--format', 'text');
|
|
72
|
+
const inboxDir = path.resolve(getFlag(argv, '--inbox', '.mailqa'));
|
|
73
|
+
if (cmd === 'check') {
|
|
74
|
+
const target = argv[1];
|
|
75
|
+
if (!target || target.startsWith('-')) {
|
|
76
|
+
throw new Error('Usage: mailqa check <fileOrDir> [--format text|json]');
|
|
77
|
+
}
|
|
78
|
+
const files = collectHtmlFiles(target);
|
|
79
|
+
if (files.length === 0) {
|
|
80
|
+
throw new Error(`No .html/.htm files found under ${target}`);
|
|
81
|
+
}
|
|
82
|
+
const reports = files.map((file) => auditEmailHtml(fs.readFileSync(file, 'utf8'), path.relative(process.cwd(), file) || file));
|
|
83
|
+
if (format === 'json') {
|
|
84
|
+
console.log(JSON.stringify(reports, null, 2));
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
console.log(formatReportsText(reports));
|
|
88
|
+
}
|
|
89
|
+
if (reports.some((r) => !r.passed)) {
|
|
90
|
+
process.exitCode = 1;
|
|
91
|
+
}
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (cmd === 'sink') {
|
|
95
|
+
const port = Number.parseInt(getFlag(argv, '--port', '2525'), 10);
|
|
96
|
+
const sink = await startSmtpSink({
|
|
97
|
+
port,
|
|
98
|
+
inboxDir,
|
|
99
|
+
onCapture: (email) => {
|
|
100
|
+
const badge = email.qa.passed ? 'PASS' : 'FAIL';
|
|
101
|
+
console.log(`[${email.receivedAt}] ${badge} id=${email.id} from=${email.from} to=${email.to.join(',')} subject="${email.subject}" errors=${email.qa.counts.error} warnings=${email.qa.counts.warning}`);
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
console.log(`mailqa SMTP sink listening on smtp://${sink.host}:${sink.port} (inbox: ${inboxDir})`);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (cmd === 'inbox') {
|
|
108
|
+
const emails = loadInbox(inboxDir);
|
|
109
|
+
if (format === 'json') {
|
|
110
|
+
console.log(JSON.stringify(emails, null, 2));
|
|
111
|
+
}
|
|
112
|
+
else if (emails.length === 0) {
|
|
113
|
+
console.log(`Inbox is empty (${inboxDir}).`);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
for (const e of emails) {
|
|
117
|
+
console.log(`${e.id} | ${e.receivedAt} | ${e.qa.passed ? 'PASS' : 'FAIL'} | "${e.subject}" -> ${e.to.join(', ')}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (cmd === 'clear') {
|
|
123
|
+
if (fs.existsSync(inboxDir)) {
|
|
124
|
+
fs.rmSync(inboxDir, { recursive: true, force: true });
|
|
125
|
+
}
|
|
126
|
+
console.log(`Cleared ${inboxDir}`);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
throw new Error(`Unknown command: ${cmd}`);
|
|
130
|
+
}
|
|
131
|
+
const isEntrypoint = process.argv[1] !== undefined &&
|
|
132
|
+
(process.argv[1].endsWith('cli.js') || process.argv[1].endsWith('cli.ts'));
|
|
133
|
+
if (isEntrypoint) {
|
|
134
|
+
main().catch((err) => {
|
|
135
|
+
console.error(`mailqa error: ${err instanceof Error ? err.message : String(err)}`);
|
|
136
|
+
process.exitCode = 2;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAGrD,MAAM,OAAO,GAAG,OAAO,CAAC;AAExB,MAAM,IAAI,GAAG,WAAW,OAAO;;;;;;;;CAQ9B,CAAC;AAEF,SAAS,gBAAgB,CAAC,MAAc;IACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACtC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,mBAAmB,QAAQ,EAAE,CAAC,CAAC;IACjD,CAAC;IACD,MAAM,IAAI,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACnC,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,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AAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { auditEmailHtml } from './rules.js';
|
|
2
|
+
export { loadInbox, parseRawEmail, startSmtpSink } from './smtp.js';
|
|
3
|
+
export type { SmtpSinkHandle, SmtpSinkOptions, ParsedMimeEmail } from './smtp.js';
|
|
4
|
+
export type { CapturedEmail, EmailIssue, EmailReport, QaSeverity } from './types.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/rules.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { EmailReport } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Runs deterministic cross-client rendering, deliverability, link,
|
|
4
|
+
* and template-interpolation QA checks against an HTML email payload.
|
|
5
|
+
*/
|
|
6
|
+
export declare function auditEmailHtml(html: string, target?: string): EmailReport;
|
package/dist/rules.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
const GMAIL_CLIP_BYTES = 102 * 1024;
|
|
2
|
+
function extractSnippet(html, matchIndex) {
|
|
3
|
+
const start = Math.max(0, matchIndex - 20);
|
|
4
|
+
const end = Math.min(html.length, matchIndex + 90);
|
|
5
|
+
return html.slice(start, end).replace(/\s+/g, ' ').trim();
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Runs deterministic cross-client rendering, deliverability, link,
|
|
9
|
+
* and template-interpolation QA checks against an HTML email payload.
|
|
10
|
+
*/
|
|
11
|
+
export function auditEmailHtml(html, target = 'inline.html') {
|
|
12
|
+
const issues = [];
|
|
13
|
+
const byteSize = Buffer.byteLength(html, 'utf8');
|
|
14
|
+
if (byteSize > GMAIL_CLIP_BYTES) {
|
|
15
|
+
issues.push({
|
|
16
|
+
ruleId: 'MQ-SIZE-001',
|
|
17
|
+
severity: 'warning',
|
|
18
|
+
title: 'Email exceeds Gmail 102 KB clipping threshold',
|
|
19
|
+
detail: `Rendered HTML is ${(byteSize / 1024).toFixed(1)} KB; Gmail truncates emails above 102 KB with "[Message clipped]".`,
|
|
20
|
+
fix: 'Trim redundant inline CSS, minify HTML, or shorten long inline SVGs/tables.',
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const scriptMatch = /<script\b[^>]*>/i.exec(html);
|
|
24
|
+
if (scriptMatch) {
|
|
25
|
+
issues.push({
|
|
26
|
+
ruleId: 'MQ-SEC-001',
|
|
27
|
+
severity: 'error',
|
|
28
|
+
title: 'Embedded <script> tag in email HTML',
|
|
29
|
+
detail: 'Email clients strip <script> tags and spam filters heavily penalize JavaScript inside messages.',
|
|
30
|
+
fix: 'Remove all <script> tags from email templates.',
|
|
31
|
+
snippet: extractSnippet(html, scriptMatch.index),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
const extCssMatch = /<link\b[^>]*rel\s*=\s*["']stylesheet["'][^>]*>/i.exec(html);
|
|
35
|
+
if (extCssMatch) {
|
|
36
|
+
issues.push({
|
|
37
|
+
ruleId: 'MQ-STYLE-001',
|
|
38
|
+
severity: 'error',
|
|
39
|
+
title: 'External stylesheet <link> blocked by email clients',
|
|
40
|
+
detail: 'Gmail, Outlook, and Apple Mail largely strip or ignore external CSS links.',
|
|
41
|
+
fix: 'Inline critical styles directly onto elements or use a <style> block compiled via MJML/React Email.',
|
|
42
|
+
snippet: extractSnippet(html, extCssMatch.index),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const modernLayoutMatch = /\bdisplay\s*:\s*(?:flex|inline-flex|grid|inline-grid)\b/i.exec(html);
|
|
46
|
+
if (modernLayoutMatch) {
|
|
47
|
+
issues.push({
|
|
48
|
+
ruleId: 'MQ-LAYOUT-001',
|
|
49
|
+
severity: 'warning',
|
|
50
|
+
title: 'Flexbox or CSS Grid layout breaks in Outlook Desktop',
|
|
51
|
+
detail: 'Outlook Windows uses Word rendering, which ignores display:flex and display:grid.',
|
|
52
|
+
fix: 'Use table-based layout cells (role="presentation") for multi-column alignment.',
|
|
53
|
+
snippet: extractSnippet(html, modernLayoutMatch.index),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const positionMatch = /\bposition\s*:\s*(?:fixed|absolute)\b/i.exec(html);
|
|
57
|
+
if (positionMatch) {
|
|
58
|
+
issues.push({
|
|
59
|
+
ruleId: 'MQ-LAYOUT-002',
|
|
60
|
+
severity: 'warning',
|
|
61
|
+
title: 'CSS position: fixed/absolute stripped across major clients',
|
|
62
|
+
detail: 'Most webmail and desktop clients strip fixed/absolute positioning.',
|
|
63
|
+
fix: 'Replace positioned overlays with stacked table rows or background images.',
|
|
64
|
+
snippet: extractSnippet(html, positionMatch.index),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
const base64Img = /<img\b[^>]*\bsrc\s*=\s*["']data:image\//i.exec(html);
|
|
68
|
+
if (base64Img) {
|
|
69
|
+
issues.push({
|
|
70
|
+
ruleId: 'MQ-IMG-001',
|
|
71
|
+
severity: 'error',
|
|
72
|
+
title: 'Base64 data:image URI blocked in Gmail and Outlook',
|
|
73
|
+
detail: 'Major clients block inline data:image/* URIs for security and tracking protection.',
|
|
74
|
+
fix: 'Host images over HTTPS or attach them as multipart Content-ID (cid:) attachments.',
|
|
75
|
+
snippet: extractSnippet(html, base64Img.index),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
for (const imgMatch of html.matchAll(/<img\b([^>]*)>/gi)) {
|
|
79
|
+
const attrs = imgMatch[1] ?? '';
|
|
80
|
+
if (!/\balt\s*=\s*["'][^"']*["']/i.test(attrs)) {
|
|
81
|
+
issues.push({
|
|
82
|
+
ruleId: 'MQ-A11Y-001',
|
|
83
|
+
severity: 'warning',
|
|
84
|
+
title: 'Image tag missing alt attribute',
|
|
85
|
+
detail: 'When images are blocked by default, missing alt attributes leave blank broken boxes and fail accessibility.',
|
|
86
|
+
fix: 'Add a descriptive alt="..." attribute (or alt="" for purely decorative icons).',
|
|
87
|
+
snippet: extractSnippet(html, imgMatch.index ?? 0),
|
|
88
|
+
});
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const badHref = /<a\b[^>]*\bhref\s*=\s*["'](?:#|javascript:|https?:\/\/(?:localhost|127\.0\.0\.1)[^"']*|\s*)["']/i.exec(html);
|
|
93
|
+
if (badHref) {
|
|
94
|
+
issues.push({
|
|
95
|
+
ruleId: 'MQ-LINK-001',
|
|
96
|
+
severity: 'error',
|
|
97
|
+
title: 'Placeholder or localhost link found in email template',
|
|
98
|
+
detail: 'Anchor tag points to "#", empty URL, or localhost/127.0.0.1, breaking links for real recipients.',
|
|
99
|
+
fix: 'Replace with a valid HTTPS production URL configured via environment variables.',
|
|
100
|
+
snippet: extractSnippet(html, badHref.index),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
const unrenderedMatch = /(\{\{\s*[a-zA-Z0-9_.-]+\s*\}\}|\$\{[a-zA-Z0-9_.-]+\}|<%\s*=\s*[^%]+%>)/.exec(html);
|
|
104
|
+
if (unrenderedMatch) {
|
|
105
|
+
issues.push({
|
|
106
|
+
ruleId: 'MQ-TPL-001',
|
|
107
|
+
severity: 'error',
|
|
108
|
+
title: 'Unrendered template placeholder found in output',
|
|
109
|
+
detail: `Template marker "${unrenderedMatch[1]}" appears literally in the rendered email.`,
|
|
110
|
+
fix: 'Ensure all template variables are interpolated before sending.',
|
|
111
|
+
snippet: extractSnippet(html, unrenderedMatch.index),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const counts = {
|
|
115
|
+
error: issues.filter((i) => i.severity === 'error').length,
|
|
116
|
+
warning: issues.filter((i) => i.severity === 'warning').length,
|
|
117
|
+
info: issues.filter((i) => i.severity === 'info').length,
|
|
118
|
+
};
|
|
119
|
+
return {
|
|
120
|
+
target,
|
|
121
|
+
byteSize,
|
|
122
|
+
passed: counts.error === 0,
|
|
123
|
+
counts,
|
|
124
|
+
issues,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rules.js","sourceRoot":"","sources":["../src/rules.ts"],"names":[],"mappings":"AAEA,MAAM,gBAAgB,GAAG,GAAG,GAAG,IAAI,CAAC;AAEpC,SAAS,cAAc,CAAC,IAAY,EAAE,UAAkB;IACtD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,GAAG,EAAE,CAAC,CAAC;IAC3C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,EAAE,CAAC,CAAC;IACnD,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AAC5D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,MAAM,GAAG,aAAa;IACjE,MAAM,MAAM,GAAiB,EAAE,CAAC;IAChC,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAEjD,IAAI,QAAQ,GAAG,gBAAgB,EAAE,CAAC;QAChC,MAAM,CAAC,IAAI,CAAC;YACV,MAAM,EAAE,aAAa;YACrB,QAAQ,EAAE,SAAS;YACnB,KAAK,EAAE,+CAA+C;YACtD,MAAM,EAAE,oBAAoB,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,oEAAoE;YAC5H,GAAG,EAAE,6EAA6E;SACnF,CAAC,CA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|
4
|
+
headers: Record<string, string>;
|
|
5
|
+
html: string;
|
|
6
|
+
text: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Parses a raw RFC 5322 / MIME email payload into headers, HTML, and plain-text parts.
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseRawEmail(raw: string): ParsedMimeEmail;
|
|
12
|
+
export interface SmtpSinkOptions {
|
|
13
|
+
port: number;
|
|
14
|
+
host?: string;
|
|
15
|
+
inboxDir: string;
|
|
16
|
+
onCapture?: (email: CapturedEmail) => void;
|
|
17
|
+
}
|
|
18
|
+
export interface SmtpSinkHandle {
|
|
19
|
+
port: number;
|
|
20
|
+
host: string;
|
|
21
|
+
close: () => Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Starts a local zero-dependency SMTP server that captures outgoing dev/test emails
|
|
25
|
+
* and runs email QA checks on every received message.
|
|
26
|
+
*/
|
|
27
|
+
export declare function startSmtpSink(options: SmtpSinkOptions): Promise<SmtpSinkHandle>;
|
|
28
|
+
export declare function loadInbox(inboxDir: string): CapturedEmail[];
|
package/dist/smtp.js
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import net from 'node:net';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { auditEmailHtml } from './rules.js';
|
|
6
|
+
function splitHeadersAndBody(rawSection) {
|
|
7
|
+
const crlfIdx = rawSection.indexOf('\r\n\r\n');
|
|
8
|
+
const lfIdx = rawSection.indexOf('\n\n');
|
|
9
|
+
if (crlfIdx !== -1 && (lfIdx === -1 || crlfIdx < lfIdx)) {
|
|
10
|
+
return {
|
|
11
|
+
headersBlock: rawSection.slice(0, crlfIdx),
|
|
12
|
+
body: rawSection.slice(crlfIdx + 4),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
if (lfIdx !== -1) {
|
|
16
|
+
return {
|
|
17
|
+
headersBlock: rawSection.slice(0, lfIdx),
|
|
18
|
+
body: rawSection.slice(lfIdx + 2),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return { headersBlock: '', body: rawSection };
|
|
22
|
+
}
|
|
23
|
+
function parseHeaders(block) {
|
|
24
|
+
const unfolded = block.replace(/\r?\n[ \t]+/g, ' ');
|
|
25
|
+
const headers = {};
|
|
26
|
+
for (const line of unfolded.split(/\r?\n/)) {
|
|
27
|
+
const colon = line.indexOf(':');
|
|
28
|
+
if (colon <= 0) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const key = line.slice(0, colon).trim().toLowerCase();
|
|
32
|
+
const val = line.slice(colon + 1).trim();
|
|
33
|
+
headers[key] = val;
|
|
34
|
+
}
|
|
35
|
+
return headers;
|
|
36
|
+
}
|
|
37
|
+
function decodeQuotedPrintable(input) {
|
|
38
|
+
return input
|
|
39
|
+
.replace(/=\r?\n/g, '')
|
|
40
|
+
.replace(/=([0-9A-Fa-f]{2})/g, (_, hex) => String.fromCharCode(Number.parseInt(hex, 16)));
|
|
41
|
+
}
|
|
42
|
+
function decodeBody(body, transferEncoding) {
|
|
43
|
+
const enc = (transferEncoding ?? '').toLowerCase().trim();
|
|
44
|
+
if (enc === 'base64') {
|
|
45
|
+
return Buffer.from(body.replace(/\s+/g, ''), 'base64').toString('utf8');
|
|
46
|
+
}
|
|
47
|
+
if (enc === 'quoted-printable') {
|
|
48
|
+
return decodeQuotedPrintable(body);
|
|
49
|
+
}
|
|
50
|
+
return body;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Parses a raw RFC 5322 / MIME email payload into headers, HTML, and plain-text parts.
|
|
54
|
+
*/
|
|
55
|
+
export function parseRawEmail(raw) {
|
|
56
|
+
const { headersBlock, body } = splitHeadersAndBody(raw);
|
|
57
|
+
const headers = parseHeaders(headersBlock);
|
|
58
|
+
const subject = headers['subject'] ?? '(no subject)';
|
|
59
|
+
const contentType = headers['content-type'] ?? 'text/plain';
|
|
60
|
+
const boundaryMatch = /boundary\s*=\s*"?([^";\s]+)"?/i.exec(contentType);
|
|
61
|
+
if (!boundaryMatch?.[1]) {
|
|
62
|
+
const decoded = decodeBody(body, headers['content-transfer-encoding']);
|
|
63
|
+
const isHtml = /text\/html/i.test(contentType);
|
|
64
|
+
return {
|
|
65
|
+
subject,
|
|
66
|
+
headers,
|
|
67
|
+
html: isHtml ? decoded : '',
|
|
68
|
+
text: isHtml ? '' : decoded,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
let html = '';
|
|
72
|
+
let text = '';
|
|
73
|
+
const parts = body.split(`--${boundaryMatch[1]}`);
|
|
74
|
+
for (const part of parts) {
|
|
75
|
+
const trimmed = part.trim();
|
|
76
|
+
if (!trimmed || trimmed === '--') {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const parsedPart = parseRawEmail(part.replace(/^\r?\n/, ''));
|
|
80
|
+
if (!html && parsedPart.html) {
|
|
81
|
+
html = parsedPart.html;
|
|
82
|
+
}
|
|
83
|
+
if (!text && parsedPart.text) {
|
|
84
|
+
text = parsedPart.text;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return { subject, headers, html, text };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Starts a local zero-dependency SMTP server that captures outgoing dev/test emails
|
|
91
|
+
* and runs email QA checks on every received message.
|
|
92
|
+
*/
|
|
93
|
+
export function startSmtpSink(options) {
|
|
94
|
+
const host = options.host ?? '127.0.0.1';
|
|
95
|
+
fs.mkdirSync(options.inboxDir, { recursive: true });
|
|
96
|
+
const server = net.createServer((socket) => {
|
|
97
|
+
let buffer = '';
|
|
98
|
+
let inData = false;
|
|
99
|
+
let mailFrom = '';
|
|
100
|
+
let rcptTo = [];
|
|
101
|
+
let dataLines = [];
|
|
102
|
+
let awaitingAuthSecret = false;
|
|
103
|
+
const send = (line) => {
|
|
104
|
+
socket.write(`${line}\r\n`);
|
|
105
|
+
};
|
|
106
|
+
send('220 mailqa.local ESMTP Service Ready');
|
|
107
|
+
socket.on('data', (chunk) => {
|
|
108
|
+
buffer += chunk.toString('utf8');
|
|
109
|
+
while (true) {
|
|
110
|
+
const lineEnd = buffer.indexOf('\n');
|
|
111
|
+
if (lineEnd === -1) {
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
const rawLine = buffer.slice(0, lineEnd).replace(/\r$/, '');
|
|
115
|
+
buffer = buffer.slice(lineEnd + 1);
|
|
116
|
+
if (inData) {
|
|
117
|
+
if (rawLine === '.') {
|
|
118
|
+
inData = false;
|
|
119
|
+
const rawEmail = dataLines.join('\r\n');
|
|
120
|
+
dataLines = [];
|
|
121
|
+
const captured = persistCapturedEmail(options.inboxDir, mailFrom, rcptTo, rawEmail);
|
|
122
|
+
options.onCapture?.(captured);
|
|
123
|
+
send(`250 2.0.0 OK queued as ${captured.id}`);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
dataLines.push(rawLine.startsWith('..') ? rawLine.slice(1) : rawLine);
|
|
127
|
+
}
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (awaitingAuthSecret) {
|
|
131
|
+
awaitingAuthSecret = false;
|
|
132
|
+
send('235 2.7.0 Authentication successful');
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const upper = rawLine.toUpperCase();
|
|
136
|
+
if (upper.startsWith('EHLO') || upper.startsWith('HELO')) {
|
|
137
|
+
if (upper.startsWith('EHLO')) {
|
|
138
|
+
send('250-mailqa.local');
|
|
139
|
+
send('250 AUTH PLAIN LOGIN');
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
send('250 mailqa.local');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else if (upper.startsWith('AUTH PLAIN ')) {
|
|
146
|
+
send('235 2.7.0 Authentication successful');
|
|
147
|
+
}
|
|
148
|
+
else if (upper.startsWith('AUTH LOGIN')) {
|
|
149
|
+
awaitingAuthSecret = true;
|
|
150
|
+
send('334 VXNlcm5hbWU6');
|
|
151
|
+
}
|
|
152
|
+
else if (upper.startsWith('MAIL FROM:')) {
|
|
153
|
+
mailFrom = rawLine.slice(10).trim().replace(/^<|>$/g, '');
|
|
154
|
+
rcptTo = [];
|
|
155
|
+
send('250 2.1.0 OK');
|
|
156
|
+
}
|
|
157
|
+
else if (upper.startsWith('RCPT TO:')) {
|
|
158
|
+
rcptTo.push(rawLine.slice(8).trim().replace(/^<|>$/g, ''));
|
|
159
|
+
send('250 2.1.5 OK');
|
|
160
|
+
}
|
|
161
|
+
else if (upper === 'DATA') {
|
|
162
|
+
inData = true;
|
|
163
|
+
dataLines = [];
|
|
164
|
+
send('354 End data with <CR><LF>.<CR><LF>');
|
|
165
|
+
}
|
|
166
|
+
else if (upper === 'RSET') {
|
|
167
|
+
mailFrom = '';
|
|
168
|
+
rcptTo = [];
|
|
169
|
+
send('250 2.0.0 Reset');
|
|
170
|
+
}
|
|
171
|
+
else if (upper === 'NOOP') {
|
|
172
|
+
send('250 2.0.0 OK');
|
|
173
|
+
}
|
|
174
|
+
else if (upper === 'QUIT') {
|
|
175
|
+
send('221 2.0.0 Bye');
|
|
176
|
+
socket.end();
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
send('250 2.0.0 OK');
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
return new Promise((resolve, reject) => {
|
|
185
|
+
server.once('error', reject);
|
|
186
|
+
server.listen(options.port, host, () => {
|
|
187
|
+
const addr = server.address();
|
|
188
|
+
const boundPort = typeof addr === 'object' && addr ? addr.port : options.port;
|
|
189
|
+
resolve({
|
|
190
|
+
port: boundPort,
|
|
191
|
+
host,
|
|
192
|
+
close: () => new Promise((res, rej) => {
|
|
193
|
+
server.close((err) => (err ? rej(err) : res()));
|
|
194
|
+
}),
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
function persistCapturedEmail(inboxDir, from, to, raw) {
|
|
200
|
+
const id = crypto.randomBytes(4).toString('hex');
|
|
201
|
+
const receivedAt = new Date().toISOString();
|
|
202
|
+
const parsed = parseRawEmail(raw);
|
|
203
|
+
const targetName = `${id}.eml`;
|
|
204
|
+
const qa = parsed.html
|
|
205
|
+
? auditEmailHtml(parsed.html, targetName)
|
|
206
|
+
: {
|
|
207
|
+
target: targetName,
|
|
208
|
+
byteSize: Buffer.byteLength(raw, 'utf8'),
|
|
209
|
+
passed: true,
|
|
210
|
+
counts: { error: 0, warning: 0, info: 0 },
|
|
211
|
+
issues: [],
|
|
212
|
+
};
|
|
213
|
+
const record = {
|
|
214
|
+
id,
|
|
215
|
+
receivedAt,
|
|
216
|
+
from,
|
|
217
|
+
to,
|
|
218
|
+
subject: parsed.subject,
|
|
219
|
+
headers: parsed.headers,
|
|
220
|
+
raw,
|
|
221
|
+
html: parsed.html,
|
|
222
|
+
text: parsed.text,
|
|
223
|
+
qa,
|
|
224
|
+
};
|
|
225
|
+
const stamp = receivedAt.replace(/[:.]/g, '-');
|
|
226
|
+
fs.writeFileSync(path.join(inboxDir, `${stamp}-${id}.eml`), raw, 'utf8');
|
|
227
|
+
fs.writeFileSync(path.join(inboxDir, `${stamp}-${id}.json`), JSON.stringify(record, null, 2), 'utf8');
|
|
228
|
+
return record;
|
|
229
|
+
}
|
|
230
|
+
export function loadInbox(inboxDir) {
|
|
231
|
+
if (!fs.existsSync(inboxDir)) {
|
|
232
|
+
return [];
|
|
233
|
+
}
|
|
234
|
+
return fs
|
|
235
|
+
.readdirSync(inboxDir)
|
|
236
|
+
.filter((f) => f.endsWith('.json'))
|
|
237
|
+
.sort()
|
|
238
|
+
.reverse()
|
|
239
|
+
.map((f) => JSON.parse(fs.readFileSync(path.join(inboxDir, f), 'utf8')));
|
|
240
|
+
}
|
|
241
|
+
//# sourceMappingURL=smtp.js.map
|
package/dist/smtp.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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AE,OAAO,CAAC,EAC1C,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAC/B,MAAM,CACP,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,QAAgB;IACxC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7B,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,EAAE;SACN,WAAW,CAAC,QAAQ,CAAC;SACrB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;SAClC,IAAI,EAAE;SACN,OAAO,EAAE;SACT,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,CAAkB,CAAC,CAAC;AAC9F,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type QaSeverity = 'error' | 'warning' | 'info';
|
|
2
|
+
export interface EmailIssue {
|
|
3
|
+
ruleId: string;
|
|
4
|
+
severity: QaSeverity;
|
|
5
|
+
title: string;
|
|
6
|
+
detail: string;
|
|
7
|
+
fix: string;
|
|
8
|
+
snippet?: string | undefined;
|
|
9
|
+
}
|
|
10
|
+
export interface EmailReport {
|
|
11
|
+
target: string;
|
|
12
|
+
byteSize: number;
|
|
13
|
+
passed: boolean;
|
|
14
|
+
counts: {
|
|
15
|
+
error: number;
|
|
16
|
+
warning: number;
|
|
17
|
+
info: number;
|
|
18
|
+
};
|
|
19
|
+
issues: EmailIssue[];
|
|
20
|
+
}
|
|
21
|
+
export interface CapturedEmail {
|
|
22
|
+
id: string;
|
|
23
|
+
receivedAt: string;
|
|
24
|
+
from: string;
|
|
25
|
+
to: string[];
|
|
26
|
+
subject: string;
|
|
27
|
+
headers: Record<string, string>;
|
|
28
|
+
raw: string;
|
|
29
|
+
html: string;
|
|
30
|
+
text: string;
|
|
31
|
+
qa: EmailReport;
|
|
32
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mailqa",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Zero-dependency local SMTP sandbox and email template QA CLI for developers and AI agents (no Mailtrap/Docker required).",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"mailqa": "./dist/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"skills",
|
|
20
|
+
"action.yml",
|
|
21
|
+
"README.md",
|
|
22
|
+
"CONTRIBUTING.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"test": "bun test",
|
|
29
|
+
"prepublishOnly": "bun run build && bun test"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"email",
|
|
33
|
+
"smtp",
|
|
34
|
+
"mailtrap",
|
|
35
|
+
"qa",
|
|
36
|
+
"testing",
|
|
37
|
+
"cli",
|
|
38
|
+
"ai-agents",
|
|
39
|
+
"deliverability"
|
|
40
|
+
],
|
|
41
|
+
"author": "Vidit Jain <viditjain180@gmail.com>",
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=18.0.0"
|
|
45
|
+
},
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "https://github.com/viditjain25/mailqa.git"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/node": "^22.10.0",
|
|
52
|
+
"typescript": "^5.7.2"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: mailqa
|
|
3
|
+
description: Catch email rendering, deliverability, link, and template-variable bugs locally using mailqa without Mailtrap or cloud accounts.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# mailqa
|
|
7
|
+
|
|
8
|
+
1. Audit compiled email templates before sending:
|
|
9
|
+
```bash
|
|
10
|
+
npx mailqa check ./emails --format json
|
|
11
|
+
```
|
|
12
|
+
2. Capture and auto-audit live local test emails via local SMTP (`localhost:2525`):
|
|
13
|
+
```bash
|
|
14
|
+
npx mailqa sink --port 2525
|
|
15
|
+
```
|
|
16
|
+
3. Inspect captured emails from your terminal or coding agent:
|
|
17
|
+
```bash
|
|
18
|
+
npx mailqa inbox --format json
|
|
19
|
+
```
|