Closed msimerson closed 5 months ago
@lnedry Thanks for the fix in PR #58, that was some good sleuthing. Rather that using exec in a stateful way (as we had), I like the idea of making the code simpler and clearer. What do you think of this implementation that uses matchAll
and the ... iterator?
exports.received_headers = function (connection) {
const received = connection.transaction.header.get_all('received')
if (!received.length) return []
const results = []
const ipany_re = net_utils.get_ipany_re('[\\[\\(](?:IPv6:)?', '[\\]\\)]')
// Try and parse each received header
for (const header of received) {
for (const match of [...header.matchAll(ipany_re)]) {
if (net_utils.is_private_ip(match[1])) continue // exclude private IP
const gi = this.get_geoip(match[1])
const country = get_country(gi)
let logmsg = `received=${match[1]}`
if (country) {
logmsg += ` country=${country}`
results.push(`${match[1]}:${country}`)
}
connection.loginfo(this, logmsg)
}
}
return results
}