* Add some user lookup functionality

* Fix INTL to/from order
* Remove VIA kludge when initially creating a NetMail message
This commit is contained in:
Bryan Ashby 2018-01-01 18:10:38 -07:00
parent e7109b0f0c
commit 84a1f70fc2
2 changed files with 42 additions and 4 deletions

View File

@ -332,17 +332,20 @@ function FTNMessageScanTossModule() {
// NetMail messages need a FRL-1005.001 "Via" line // NetMail messages need a FRL-1005.001 "Via" line
// http://ftsc.org/docs/frl-1005.001 // http://ftsc.org/docs/frl-1005.001
// //
// :TODO: We need to do this when FORWARDING NetMail
/*
if(_.isString(message.meta.FtnKludge.Via)) { 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 = message.meta.FtnKludge.Via || []; message.meta.FtnKludge.Via = message.meta.FtnKludge.Via || [];
message.meta.FtnKludge.Via.push(ftnUtil.getVia(options.network.localAddress)); message.meta.FtnKludge.Via.push(ftnUtil.getVia(options.network.localAddress));
*/
// //
// We need to set INTL, and possibly FMPT and/or TOPT // We need to set INTL, and possibly FMPT and/or TOPT
// See http://retro.fidoweb.ru/docs/index=ftsc&doc=FTS-4001&enc=mac // 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) { if(_.isNumber(options.network.localAddress.point) && options.network.localAddress.point > 0) {
message.meta.FtnKludge.FMPT = options.network.localAddress.point; message.meta.FtnKludge.FMPT = options.network.localAddress.point;
@ -1169,8 +1172,7 @@ function FTNMessageScanTossModule() {
const lookupName = self.getLocalUserNameFromAlias(message.toUserName); const lookupName = self.getLocalUserNameFromAlias(message.toUserName);
// :TODO: take into account aliasing, e.g. "root" -> SysOp User.getUserIdAndNameByLookup(lookupName, (err, localToUserId, localUserName) => {
User.getUserIdAndName(lookupName, (err, localToUserId, localUserName) => {
if(err) { if(err) {
return callback(Errors.DoesNotExist(`Could not get local user ID for "${message.toUserName}": ${err.message}`)); return callback(Errors.DoesNotExist(`Could not get local user ID for "${message.toUserName}": ${err.message}`));
} }

View File

@ -420,6 +420,42 @@ module.exports = class User {
); );
} }
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) { static getUserName(userId, cb) {
userDb.get( userDb.get(
`SELECT user_name `SELECT user_name