Skip to content

Commit

Permalink
add subject line limit to gelf in case of errors on gelf side
Browse files Browse the repository at this point in the history
  • Loading branch information
NickOvt committed Oct 10, 2024
1 parent 1f4eeb4 commit 1a9dc0b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ module.exports.init = function (app, done) {
const gridfsdb = app.db.gridfs;

const component = ((app.config.gelf && app.config.gelf.component) || 'mta').toUpperCase();

const maxSubjectLineLogLengthBytes = app.config.gelf.subjectLength || 32766 - 1; // 32766 is max gelf default, do -1 for good measure

const hostname = app.config.hostname || os.hostname();
const gelf =
app.config.gelf && app.config.gelf.enabled
Expand Down Expand Up @@ -1077,7 +1080,10 @@ module.exports.init = function (app, done) {
message._spam_score = Number(entry.score) || '';
message._interface = entry.interface;
message._proto = entry.transtype;
message._subject = entry.subject;
message._subject =
Buffer.byteLength(entry.subject, 'utf8') > maxSubjectLineLogLengthBytes
? entry.subject.substring(0, maxSubjectLineLogLengthBytes / 4)
: entry.subject;

message._authenticated_sender = username;
}
Expand Down

0 comments on commit 1a9dc0b

Please sign in to comment.