Skip to content

Commit

Permalink
Zms 91 (#545)
Browse files Browse the repository at this point in the history
* added new file to test git repo setup

* add limit_allowed and limit_sent to loggelf in messages in API. Also if multiple recipients log each message separately

* typo fix

* messages.js refactor code. Make cleaner

* fix _limit_sent. Fix earlier issue too

* session -> sess. Session doesn't exist on request objs, sess exists

* return pback the general SUBMIT log message to track API endpoint usage
  • Loading branch information
NickOvt authored Oct 26, 2023
1 parent 779bb11 commit aae91bb
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions lib/api/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -1910,7 +1910,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti
envelope,
files
},
session: result.value.session,
session: result.value.sess,
date,
verificationResults,
flags: []
Expand Down Expand Up @@ -2316,7 +2316,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti
});
}

let maxRecipients = Number(userData.maxRecipients) || (await settingsHandler.get('const:max:recipients'));
let maxRecipients = Number(userData.recipients) || (await settingsHandler.get('const:max:recipients'));
let maxRptsTo = await settingsHandler.get('const:max:rcpt_to');

// Trying to send more than allowed recipients count per email
Expand Down Expand Up @@ -2464,6 +2464,26 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti
}
}

for (const to of Array.isArray(envelope.to) ? envelope.to : [envelope.to]) {
server.loggelf({
short_message: `[RCPT TO: ${to}] ${result.value.sess}`,
_mail_action: 'rcpt_to',
_user: userData._id.toString(),
_queue_id: queueId,
_sent_mailbox: response.message && response.message.mailbox,
_sent_message: response.message && response.message.id,
_send_time: sendTime && sendTime.toISOString && sendTime.toISOString(),
_from: envelope.from,
_to: to,
_message_id: messageData.msgid,
_subject: messageData.subject,
_sess: result.value.sess,
_ip: result.value.ip,
_limit_allowed: userData.recipients,
_limit_sent: messagesSent + envelope.to.length
});
}

server.loggelf({
short_message: '[SUBMIT] draft',
_mail_action: 'submit_draft',
Expand All @@ -2476,7 +2496,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti
_to: envelope.to && envelope.to.join(','),
_message_id: messageData.msgid,
_subject: messageData.subject,
_sess: result.value.session,
_sess: result.value.sess,
_ip: result.value.ip
});

Expand Down

0 comments on commit aae91bb

Please sign in to comment.