diff --git a/package-lock.json b/package-lock.json index 695910f..e3c223f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "herald", - "version": "2.0.0", + "version": "2.0.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "herald", - "version": "2.0.0", + "version": "2.0.2", "license": "MIT", "dependencies": { "@slack/bolt": "^3.12.1", diff --git a/package.json b/package.json index 5e76e12..eba74a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "herald", - "version": "2.0.0", + "version": "2.0.2", "description": "A package to parse text message dispatches and send them to Slack", "main": "server.js", "scripts": { diff --git a/server.js b/server.js index 3ce26dd..6cc5c1c 100644 --- a/server.js +++ b/server.js @@ -60,6 +60,24 @@ function parseKeyValueText(text) { return obj; } +// Decode simple quoted-printable artifacts commonly found in raw email bodies. +// Removes soft line breaks (=) and converts =HH hex escapes to characters. +function decodeQuotedPrintable(s) { + if (!s || typeof s !== "string") return s; + // remove soft line breaks + let out = s.replace(/=\r?\n/g, ""); + // handle common hex escapes like =0A, sometimes mis-encoded as =OA + out = out.replace(/=0A/gi, "\n"); + out = out.replace(/=0D/gi, "\r"); + out = out.replace(/=OA/gi, "\n"); + out = out.replace(/=OD/gi, "\r"); + // general =HH hex escapes + out = out.replace(/=([0-9A-Fa-f]{2})/g, function (_, hex) { + return String.fromCharCode(parseInt(hex, 16)); + }); + return out; +} + // Use Google Geocoding API to turn an address into lat/lng. // We "bias" to Troy, NY by setting components=locality:Troy|administrative_area:NY|country:US // which will prefer results in Troy, NY. @@ -272,7 +290,7 @@ async function handleDispatchText(text) { } // Compose the short text and post to Slack - const shortText = `${info["CALL TYPE"].determinant.toLowerCase()} ${info["CALL TYPE"].complaint.toLowerCase()} at ${info.Location}`; + const shortText = `${info["CALL TYPE"].determinant.toUpperCase()} ${info["CALL TYPE"].complaint.toLowerCase()} at ${info.Location}`; await postMessage({ token: SLACK_TOKEN, @@ -355,6 +373,8 @@ const server = new SMTPServer({ } // Trim and pass to handler + // Decode quoted-printable artifacts (soft breaks, =0A etc.) before parsing. + bodyCandidate = decodeQuotedPrintable(bodyCandidate); await handleDispatchText(bodyCandidate); callback(); } catch (err) { @@ -370,7 +390,7 @@ const server = new SMTPServer({ server.listen(PORT, () => { console.log(`Dispatch SMTP server listening on port ${PORT}`); - console.log(`Expecting messages sent TO: ${RECEIVE_EMAIL}`); + console.log(`Expecting messages sent to: ${RECEIVE_EMAIL}`); console.log(`herald v${VERSION} running`); });