aboutsummaryrefslogtreecommitdiffstats
path: root/test/wamail-mime.test.js
diff options
context:
space:
mode:
authorElvis Claros Castro <elvis@claros.ar>2026-09-26 19:26:33 -0300
committerElvis Claros Castro <elvis@claros.ar>2026-09-26 19:26:33 -0300
commitd80640d01eeb84907e36ff4af33add9081eda17c (patch)
tree27698b34e06e28d111c2196700015d9c82f78274 /test/wamail-mime.test.js
downloadwa-cli-main.tar.gz
wa-cli-main.zip
wa-cli: WhatsApp from the terminal, with a neomutt Maildir bridgeHEADmain
Diffstat (limited to 'test/wamail-mime.test.js')
-rw-r--r--test/wamail-mime.test.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/wamail-mime.test.js b/test/wamail-mime.test.js
new file mode 100644
index 0000000..a2ff7cb
--- /dev/null
+++ b/test/wamail-mime.test.js
@@ -0,0 +1,48 @@
+import assert from 'node:assert/strict';
+import fs from 'node:fs';
+import test from 'node:test';
+import { addresses, decodeWords, parseMessage, unflow } from '../src/wamail/mime.js';
+
+const fixture = (name) => fs.readFileSync(new URL(`./fixtures/${name}`, import.meta.url));
+
+test('neomutt: 8-bit flowed text + QP attachment with an RFC 2231 filename', () => {
+ const m = parseMessage(fixture('neomutt-adjunto.eml'));
+ assert.equal(m.header('Subject'), 'asunto ñ');
+ assert.deepEqual(addresses(m.header('To')), ['5491122334455@c.us']);
+ assert.match(m.text, /^hola, ¿qué tal\? ñandú 🎉\n\n> línea citada\n-- \nfirma/);
+ assert.equal(m.attachments.length, 1);
+ assert.equal(m.attachments[0].filename, 'informe año.pdf');
+ assert.equal(m.attachments[0].contentType, 'application/pdf');
+ assert.equal(m.attachments[0].data.toString(), 'PDF-FAKE-'.repeat(50));
+});
+
+test('neomutt: reply with In-Reply-To and several recipients', () => {
+ const m = parseMessage(fixture('neomutt-respuesta.eml'));
+ assert.equal(m.header('In-Reply-To'), '<3EB0AAA1@wa>');
+ assert.deepEqual(addresses(m.header('To')), ['5491122334455@c.us', '120363000000@g.us']);
+ assert.equal(m.attachments.length, 0);
+ assert.match(m.text, /la otra vez \nOn Wed, Juan wrote:\n> ¿venís mañana\?/); // "vez " + empty line = soft break
+});
+
+test('encoded-words, flowed and addresses', () => {
+ assert.equal(decodeWords('=?UTF-8?B?SnVhbiBQw6lyZXo=?= <x@c.us>'), 'Juan Pérez <x@c.us>');
+ assert.equal(decodeWords('=?utf-8?Q?a=C3=B1o?= =?utf-8?Q?_nuevo?='), 'año nuevo');
+ assert.equal(unflow('una línea \nlarga\n-- \nfirma'), 'una línea larga\n-- \nfirma');
+ assert.deepEqual(addresses('"Pérez, Juan" <1@c.us>, 2@g.us'), ['1@c.us', '2@g.us']);
+});
+
+test('multipart with base64 and a latin1 charset', () => {
+ const raw = [
+ 'To: 1@c.us', 'Subject: =?iso-8859-1?Q?caf=E9?=', 'MIME-Version: 1.0',
+ 'Content-Type: multipart/mixed; boundary="b1"', '',
+ '--b1', 'Content-Type: multipart/alternative; boundary="b2"', '',
+ '--b2', 'Content-Type: text/plain; charset=iso-8859-1', 'Content-Transfer-Encoding: quoted-printable', '', 'caf=E9 con leche', '--b2--',
+ '--b1', 'Content-Type: image/png; name="foto.png"', 'Content-Transfer-Encoding: base64', '', Buffer.from('PNG!').toString('base64'),
+ '--b1--', '',
+ ].join('\r\n');
+ const m = parseMessage(raw);
+ assert.equal(m.header('subject'), 'café');
+ assert.equal(m.text, 'café con leche');
+ assert.equal(m.attachments[0].filename, 'foto.png');
+ assert.equal(m.attachments[0].data.toString(), 'PNG!');
+});