Closed noam7700 closed 2 years ago
You could use WeakMap objects for this where session
is the map key.
const sessions = new WeakMap();
…
// on MAIL FROM
sessions.set(session, { values })
….
// on RCPT TO
let sessData = sessions.get(session);
sessData.prop = 1234;
Allow to maintain custom object in session per transaction.
For example, my use case is that at
onMailFrom
andonRcptTo
steps I dont only validate, but fetches custom info onmailFrom
&rcptTo
that needs to be used atonData
step (where I actually send the mail to our system). More specifically I fetch IDs for them (and by that, validating the mailboxes exist), and I want to use the IDs, and dont refetch them atonData
.I've seen the library maintains
envelope
object per transaction (reset it at_resetSession
etc etc).Im not sure how the library should allow my use case. I suggest couple of options:
session
properties atonMailFrom
step andonRcptTo
step (+reseting the properties atonMailFrom
, because it's the first command of the session). Can be broken if internal implementation changes, should be supported and documented formally. This is my current workaround. Example code:mailFrom
&rcptTo
, given by passing data atonMailFrom
andonRcptTo
steps by callingcallback(null, {customData})
. Similar to the previous but a lot cleaner with proper API. Also, will go along the existing feature to remove duplicates ofrcptTo
. Maybe will be included at theAddress object
withcustomData
property.onCustomSessionDataInit
/onTransactionInit
,session.getCustomSessionData()
,session.setCustomSessionData()
.