From 84a1f70fc26ecd1be1275971a82773250f23638e Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Mon, 1 Jan 2018 18:10:38 -0700 Subject: [PATCH] * Add some user lookup functionality * Fix INTL to/from order * Remove VIA kludge when initially creating a NetMail message --- core/scanner_tossers/ftn_bso.js | 8 ++++--- core/user.js | 38 ++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/core/scanner_tossers/ftn_bso.js b/core/scanner_tossers/ftn_bso.js index 35cf6316..a72c45ff 100644 --- a/core/scanner_tossers/ftn_bso.js +++ b/core/scanner_tossers/ftn_bso.js @@ -332,17 +332,20 @@ function FTNMessageScanTossModule() { // NetMail messages need a FRL-1005.001 "Via" line // http://ftsc.org/docs/frl-1005.001 // + // :TODO: We need to do this when FORWARDING NetMail + /* if(_.isString(message.meta.FtnKludge.Via)) { message.meta.FtnKludge.Via = [ message.meta.FtnKludge.Via ]; } message.meta.FtnKludge.Via = message.meta.FtnKludge.Via || []; message.meta.FtnKludge.Via.push(ftnUtil.getVia(options.network.localAddress)); + */ // // We need to set INTL, and possibly FMPT and/or TOPT // See http://retro.fidoweb.ru/docs/index=ftsc&doc=FTS-4001&enc=mac // - message.meta.FtnKludge.INTL = ftnUtil.getIntl(options.network.localAddress, options.destAddress); + message.meta.FtnKludge.INTL = ftnUtil.getIntl(options.destAddress, options.network.localAddress); if(_.isNumber(options.network.localAddress.point) && options.network.localAddress.point > 0) { message.meta.FtnKludge.FMPT = options.network.localAddress.point; @@ -1169,8 +1172,7 @@ function FTNMessageScanTossModule() { const lookupName = self.getLocalUserNameFromAlias(message.toUserName); - // :TODO: take into account aliasing, e.g. "root" -> SysOp - User.getUserIdAndName(lookupName, (err, localToUserId, localUserName) => { + User.getUserIdAndNameByLookup(lookupName, (err, localToUserId, localUserName) => { if(err) { return callback(Errors.DoesNotExist(`Could not get local user ID for "${message.toUserName}": ${err.message}`)); } diff --git a/core/user.js b/core/user.js index fb125f6b..db9245f5 100644 --- a/core/user.js +++ b/core/user.js @@ -414,12 +414,48 @@ module.exports = class User { if(row) { return cb(null, row.id, row.user_name); } - + return cb(Errors.DoesNotExist('No matching username')); } ); } + static getUserIdAndNameByRealName(realName, cb) { + userDb.get( + `SELECT id, user_name + FROM user + WHERE id = ( + SELECT user_id + FROM user_property + WHERE prop_name='real_name' AND prop_value=? + );`, + [ realName ], + (err, row) => { + if(err) { + return cb(err); + } + + if(row) { + return cb(null, row.id, row.user_name); + } + + return cb(Errors.DoesNotExist('No matching real name')); + } + ); + } + + static getUserIdAndNameByLookup(lookup, cb) { + User.getUserIdAndName(lookup, (err, userId, userName) => { + if(err) { + User.getUserIdAndNameByRealName(lookup, (err, userId, userName) => { + return cb(err, userId, userName); + }); + } else { + return cb(null, userId, userName); + } + }); + } + static getUserName(userId, cb) { userDb.get( `SELECT user_name