Commit e95cf6a9 authored by Volker Krause's avatar Volker Krause
Browse files

Add workaround for trainline.eu emails containing wrong SNCF ticket tokens

This seems to happen in case there are multiple SNCF legs with different
ticket tokens. The JSON-LD data in the HTML part of the email then uses
only one of those for all legs.

By dropping ticket tokens from the HTML part we end up using those found
in the attached PDF tickets, which are from SNCF itself and thus correct.
parent 64ca2f97
Pipeline #213767 passed with stage
in 2 minutes and 25 seconds
......@@ -11,3 +11,28 @@ function parseEvent(event) {
res.reservationFor.arrivalStation.name = event.summary.match(/.* → (.*) \[/)[1];
return res;
}
function fixBrokenSncfTicketTokens(mail, node)
{
// fix JSON-LD in mail bodies containing messed up SNCF ticket tokens
// and invalid train numbers
const htmlNode = node.findChildNodes({ scope: "Children", mimeType: "text/html"})[0];
const pdfNodes = node.findChildNodes({ scope: "Children", mimeType: "application/pdf"});
if (pdfNodes.length == 0 || pdfNodes[0].result.length == 0 || htmlNode.result.length == 0) {
return;
}
let res = [];
for (pdfNode of pdfNodes) {
res = res.concat(pdfNode.result)
}
for (r of htmlNode.result) {
console.log(r.reservedTicket.ticketToken);
if (r.reservedTicket.ticketToken.match(/^aztecCode:i0CV/i)) {
r.reservedTicket.ticketToken = undefined;
r.reservationFor.trainNumber = undefined;
}
res.push(r);
}
return res;
}
{
[{
"filter": [
{
"field": "uid",
......@@ -10,4 +10,17 @@
"function": "parseEvent",
"mimeType": "internal/event",
"script": "trainline.js"
}
},
{
"filter": [
{
"field": "From",
"match": "@trainline.fr",
"mimeType": "message/rfc822",
"scope": "Current"
}
],
"function": "fixBrokenSncfTicketTokens",
"mimeType": "message/rfc822",
"script": "trainline.js"
}]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment