diff --git a/INTEGRATIONS.md b/INTEGRATIONS.md index b6c85f5..7e328b8 100644 --- a/INTEGRATIONS.md +++ b/INTEGRATIONS.md @@ -164,10 +164,11 @@ the dashboard views themselves load fine. here is yours to close in osTicket. - **Only partly verified against a real osTicket.** It was built from osTicket's published API documentation and tested against a stand-in server that checks what is sent (the key header, the JSON fields, the message encoding, - and how each answer — created, refused key, bad request, redirect — is handled). The first test ticket sent to a - real osTicket arrived with every space shown as `%20`: osTicket takes the message from a `data:` URL but does not - decode percent-encoding, so the message is now sent as base64, which it does decode (not yet re-checked against a - real osTicket). If osTicket rejects a ticket, "Send a test ticket" shows the reason it gave. + and how each answer — created, refused key, bad request, redirect — is handled). Tickets sent to a + real osTicket first arrived with every space shown as `%20`, then as base64: osTicket takes the message's type from a + `data:` prefix but uses everything after the first comma exactly as it is, decoding nothing (its source and its own + documented example agree). The text is now sent raw after the prefix (not yet re-checked against a real osTicket). If + osTicket rejects a ticket, "Send a test ticket" shows the reason it gave. ### phpIPAM diff --git a/server/src/integrations/osticket/ticketApi.ts b/server/src/integrations/osticket/ticketApi.ts index c75dab1..594b7a5 100644 --- a/server/src/integrations/osticket/ticketApi.ts +++ b/server/src/integrations/osticket/ticketApi.ts @@ -106,9 +106,11 @@ export function createOsTicketTicketApi(config: OsTicketApiConfig) { name: ticket.name, email: ticket.email, subject: ticket.subject, - // osTicket reads the type of the message from an RFC 2397 data URL. Base64, not percent-encoding: osTicket strips the - // "data:" part but leaves percent-encoded text as it is (a test ticket arrived full of %20), while base64 is decoded. - message: `data:text/plain;charset=utf-8;base64,${Buffer.from(ticket.message, "utf8").toString("base64")}`, + // osTicket takes the message's type from a "data:" prefix, and then uses everything after the FIRST comma exactly as it is: + // it does no decoding of any kind (percent-encoded text arrived as "%20"s, base64 as base64), and its own documented example is + // plain text after the comma. So the text goes in raw. JSON takes care of quotes and line breaks, and any further commas are + // fine — osTicket splits at the first one only. + message: `data:text/plain;charset=utf-8,${ticket.message}`, ...(ticket.topicId ? { topicId: ticket.topicId } : {}), ...(ticket.priorityId ? { priority: ticket.priorityId } : {}), }); diff --git a/server/test/alertTickets.test.ts b/server/test/alertTickets.test.ts index d97d7bc..53bb20b 100644 --- a/server/test/alertTickets.test.ts +++ b/server/test/alertTickets.test.ts @@ -229,11 +229,11 @@ describe("osTicket API client", () => { assert.equal(s.body.source, "API"); assert.equal(s.body.alert, true); assert.equal(s.body.autorespond, false, "an acknowledgement to the app's own address would only bounce"); - // osTicket reads a message's type from an RFC 2397 data URL. It must be base64: osTicket leaves percent-encoded text as it is, - // which put "%20" in place of every space in a real ticket. - assert.match(s.body.message, /^data:text\/plain;charset=utf-8;base64,[A-Za-z0-9+/=]+$/); - assert.doesNotMatch(s.body.message, /%[0-9A-Fa-f]{2}/, "percent-encoding ends up in the ticket as literal text"); - assert.equal(Buffer.from(s.body.message.replace(/^data:text\/plain;charset=utf-8;base64,/, ""), "base64").toString("utf8"), "Line one\nLine two — åäö ✓"); + // What osTicket does with the message (include/class.format.php, parseRfc2397): split at the FIRST comma, use the rest as it is. + // It applies no decoding, so any encoding here shows up in the ticket — percent-encoding as "%20", base64 as base64. + const comma = s.body.message.indexOf(","); + assert.equal(s.body.message.slice(0, comma + 1), "data:text/plain;charset=utf-8,"); + assert.equal(s.body.message.slice(comma + 1), "Line one\nLine two — åäö ✓", "the text must reach osTicket exactly as written"); }); test("topic and priority are sent only when set; staff alerts can be switched off", async () => {