2015-07-14 06:13:29 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2017-07-23 19:03:47 +00:00
|
|
|
let Config = require('./config.js').config;
|
|
|
|
let Address = require('./ftn_address.js');
|
|
|
|
let FNV1a = require('./fnv1a.js');
|
|
|
|
const getCleanEnigmaVersion = require('./misc_util.js').getCleanEnigmaVersion;
|
|
|
|
|
|
|
|
let _ = require('lodash');
|
|
|
|
let iconv = require('iconv-lite');
|
|
|
|
let moment = require('moment');
|
2017-01-31 07:17:19 +00:00
|
|
|
//let uuid = require('node-uuid');
|
2017-07-23 19:03:47 +00:00
|
|
|
let os = require('os');
|
2016-02-21 00:57:38 +00:00
|
|
|
|
2017-07-23 19:03:47 +00:00
|
|
|
let packageJson = require('../package.json');
|
2015-07-14 06:13:29 +00:00
|
|
|
|
2015-09-21 01:10:09 +00:00
|
|
|
// :TODO: Remove "Ftn" from most of these -- it's implied in the module
|
2016-02-03 04:35:59 +00:00
|
|
|
exports.stringToNullPaddedBuffer = stringToNullPaddedBuffer;
|
2016-02-21 00:57:38 +00:00
|
|
|
exports.getMessageSerialNumber = getMessageSerialNumber;
|
2016-02-16 00:56:05 +00:00
|
|
|
exports.getDateFromFtnDateTime = getDateFromFtnDateTime;
|
|
|
|
exports.getDateTimeString = getDateTimeString;
|
2015-07-14 06:13:29 +00:00
|
|
|
|
2016-02-16 00:56:05 +00:00
|
|
|
exports.getMessageIdentifier = getMessageIdentifier;
|
|
|
|
exports.getProductIdentifier = getProductIdentifier;
|
|
|
|
exports.getUTCTimeZoneOffset = getUTCTimeZoneOffset;
|
|
|
|
exports.getOrigin = getOrigin;
|
|
|
|
exports.getTearLine = getTearLine;
|
2016-02-17 05:11:55 +00:00
|
|
|
exports.getVia = getVia;
|
2018-01-01 00:54:11 +00:00
|
|
|
exports.getIntl = getIntl;
|
2016-02-16 00:56:05 +00:00
|
|
|
exports.getAbbreviatedNetNodeList = getAbbreviatedNetNodeList;
|
|
|
|
exports.parseAbbreviatedNetNodeList = parseAbbreviatedNetNodeList;
|
|
|
|
exports.getUpdatedSeenByEntries = getUpdatedSeenByEntries;
|
|
|
|
exports.getUpdatedPathEntries = getUpdatedPathEntries;
|
2016-02-10 05:30:59 +00:00
|
|
|
|
2016-02-21 00:57:38 +00:00
|
|
|
exports.getCharacterSetIdentifierByEncoding = getCharacterSetIdentifierByEncoding;
|
|
|
|
exports.getEncodingFromCharacterSetIdentifier = getEncodingFromCharacterSetIdentifier;
|
|
|
|
|
2016-02-16 00:56:05 +00:00
|
|
|
exports.getQuotePrefix = getQuotePrefix;
|
2015-09-21 01:10:09 +00:00
|
|
|
|
2016-02-10 05:30:59 +00:00
|
|
|
//
|
|
|
|
// Namespace for RFC-4122 name based UUIDs generated from
|
|
|
|
// FTN kludges MSGID + AREA
|
|
|
|
//
|
2017-01-31 07:17:19 +00:00
|
|
|
//const ENIGMA_FTN_MSGID_NAMESPACE = uuid.parse('a5c7ae11-420c-4469-a116-0e9a6d8d2654');
|
2016-02-10 05:30:59 +00:00
|
|
|
|
2015-07-14 23:08:52 +00:00
|
|
|
// See list here: https://github.com/Mithgol/node-fidonet-jam
|
|
|
|
|
2018-01-15 19:22:11 +00:00
|
|
|
function stringToNullPaddedBuffer(s, bufLen) {
|
2018-04-28 20:39:04 +00:00
|
|
|
let buffer = Buffer.alloc(bufLen);
|
2016-02-03 04:35:59 +00:00
|
|
|
let enc = iconv.encode(s, 'CP437').slice(0, bufLen);
|
|
|
|
for(let i = 0; i < enc.length; ++i) {
|
|
|
|
buffer[i] = enc[i];
|
|
|
|
}
|
|
|
|
return buffer;
|
|
|
|
}
|
2015-07-16 05:51:00 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Convert a FTN style DateTime string to a Date object
|
2018-01-15 19:22:11 +00:00
|
|
|
//
|
2016-02-10 05:30:59 +00:00
|
|
|
// :TODO: Name the next couple methods better - for FTN *packets*
|
2015-07-16 05:51:00 +00:00
|
|
|
function getDateFromFtnDateTime(dateTime) {
|
|
|
|
//
|
|
|
|
// Examples seen in the wild (Working):
|
|
|
|
// "12 Sep 88 18:17:59"
|
|
|
|
// "Tue 01 Jan 80 00:00"
|
|
|
|
// "27 Feb 15 00:00:03"
|
|
|
|
//
|
2016-02-03 04:35:59 +00:00
|
|
|
// :TODO: Use moment.js here
|
2016-03-15 04:29:41 +00:00
|
|
|
return moment(Date.parse(dateTime)); // Date.parse() allows funky formats
|
|
|
|
// return (new Date(Date.parse(dateTime))).toISOString();
|
2015-07-16 05:51:00 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 04:35:59 +00:00
|
|
|
function getDateTimeString(m) {
|
|
|
|
//
|
|
|
|
// From http://ftsc.org/docs/fts-0001.016:
|
|
|
|
// DateTime = (* a character string 20 characters long *)
|
2016-02-10 05:30:59 +00:00
|
|
|
// (* 01 Jan 86 02:34:56 *)
|
|
|
|
// DayOfMonth " " Month " " Year " "
|
|
|
|
// " " HH ":" MM ":" SS
|
|
|
|
// Null
|
2016-02-03 04:35:59 +00:00
|
|
|
//
|
|
|
|
// DayOfMonth = "01" | "02" | "03" | ... | "31" (* Fido 0 fills *)
|
|
|
|
// Month = "Jan" | "Feb" | "Mar" | "Apr" | "May" | "Jun" |
|
|
|
|
// "Jul" | "Aug" | "Sep" | "Oct" | "Nov" | "Dec"
|
|
|
|
// Year = "01" | "02" | .. | "85" | "86" | ... | "99" | "00"
|
|
|
|
// HH = "00" | .. | "23"
|
|
|
|
// MM = "00" | .. | "59"
|
|
|
|
// SS = "00" | .. | "59"
|
|
|
|
//
|
|
|
|
if(!moment.isMoment(m)) {
|
|
|
|
m = moment(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
return m.format('DD MMM YY HH:mm:ss');
|
|
|
|
}
|
|
|
|
|
2016-02-29 05:04:03 +00:00
|
|
|
function getMessageSerialNumber(messageId) {
|
2016-02-21 00:57:38 +00:00
|
|
|
const msSinceEnigmaEpoc = (Date.now() - Date.UTC(2016, 1, 1));
|
2016-02-29 05:04:03 +00:00
|
|
|
const hash = Math.abs(new FNV1a(msSinceEnigmaEpoc + messageId).value).toString(16);
|
2016-02-21 00:57:38 +00:00
|
|
|
return `00000000${hash}`.substr(-8);
|
2015-07-14 06:13:29 +00:00
|
|
|
}
|
|
|
|
|
2016-02-10 05:30:59 +00:00
|
|
|
//
|
|
|
|
// Return a FTS-0009.001 compliant MSGID value given a message
|
|
|
|
// See http://ftsc.org/docs/fts-0009.001
|
2018-01-15 19:22:11 +00:00
|
|
|
//
|
2016-02-10 05:30:59 +00:00
|
|
|
// "A MSGID line consists of the string "^AMSGID:" (where ^A is a
|
|
|
|
// control-A (hex 01) and the double-quotes are not part of the
|
|
|
|
// string), followed by a space, the address of the originating
|
|
|
|
// system, and a serial number unique to that message on the
|
|
|
|
// originating system, i.e.:
|
|
|
|
//
|
|
|
|
// ^AMSGID: origaddr serialno
|
|
|
|
//
|
|
|
|
// The originating address should be specified in a form that
|
2018-01-15 19:22:11 +00:00
|
|
|
// constitutes a valid return address for the originating network.
|
2016-02-10 05:30:59 +00:00
|
|
|
// If the originating address is enclosed in double-quotes, the
|
2018-01-15 19:22:11 +00:00
|
|
|
// entire string between the beginning and ending double-quotes is
|
2016-02-10 05:30:59 +00:00
|
|
|
// considered to be the orginating address. A double-quote character
|
|
|
|
// within a quoted address is represented by by two consecutive
|
|
|
|
// double-quote characters. The serial number may be any eight
|
|
|
|
// character hexadecimal number, as long as it is unique - no two
|
|
|
|
// messages from a given system may have the same serial number
|
|
|
|
// within a three years. The manner in which this serial number is
|
|
|
|
// generated is left to the implementor."
|
2018-01-15 19:22:11 +00:00
|
|
|
//
|
2016-02-10 05:30:59 +00:00
|
|
|
//
|
|
|
|
// Examples & Implementations
|
|
|
|
//
|
|
|
|
// Synchronet: <msgNum>.<conf+area>@<ftnAddr> <serial>
|
|
|
|
// 2606.agora-agn_tst@46:1/142 19609217
|
2018-01-15 19:22:11 +00:00
|
|
|
//
|
2016-02-10 05:30:59 +00:00
|
|
|
// Mystic: <ftnAddress> <serial>
|
|
|
|
// 46:3/102 46686263
|
|
|
|
//
|
|
|
|
// ENiGMA½: <messageId>.<areaTag>@<5dFtnAddress> <serial>
|
|
|
|
//
|
2018-01-10 02:38:36 +00:00
|
|
|
// 0.0.8-alpha:
|
|
|
|
// Made compliant with FTN spec *when exporting NetMail* due to
|
|
|
|
// Mystic rejecting messages with the true-unique version.
|
|
|
|
// Strangely, Synchronet uses the unique format and Mystic does
|
|
|
|
// OK with it. Will need to research further. Note also that
|
|
|
|
// g00r00 was kind enough to fix Mystic to allow for the Sync/Enig
|
|
|
|
// format, but that will only help when using newer Mystic versions.
|
|
|
|
//
|
|
|
|
function getMessageIdentifier(message, address, isNetMail = false) {
|
2016-02-16 00:56:05 +00:00
|
|
|
const addrStr = new Address(address).toString('5D');
|
2018-01-15 19:22:11 +00:00
|
|
|
return isNetMail ?
|
2018-01-10 02:38:36 +00:00
|
|
|
`${addrStr} ${getMessageSerialNumber(message.messageId)}` :
|
|
|
|
`${message.messageId}.${message.areaTag.toLowerCase()}@${addrStr} ${getMessageSerialNumber(message.messageId)}`
|
2018-01-15 19:22:11 +00:00
|
|
|
;
|
2016-02-10 05:30:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Return a FSC-0046.005 Product Identifier or "PID"
|
|
|
|
// http://ftsc.org/docs/fsc-0046.005
|
|
|
|
//
|
2016-02-17 05:11:55 +00:00
|
|
|
// Note that we use a variant on the spec for <serial>
|
|
|
|
// in which (<os>; <arch>; <nodeVer>) is used instead
|
|
|
|
//
|
2016-02-10 05:30:59 +00:00
|
|
|
function getProductIdentifier() {
|
2017-07-23 19:03:47 +00:00
|
|
|
const version = getCleanEnigmaVersion();
|
2016-02-10 05:30:59 +00:00
|
|
|
const nodeVer = process.version.substr(1); // remove 'v' prefix
|
|
|
|
|
|
|
|
return `ENiGMA1/2 ${version} (${os.platform()}; ${os.arch()}; ${nodeVer})`;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2018-01-15 19:22:11 +00:00
|
|
|
// Return a FRL-1004 style time zone offset for a
|
2016-02-10 05:30:59 +00:00
|
|
|
// 'TZUTC' kludge line
|
|
|
|
//
|
|
|
|
// http://ftsc.org/docs/frl-1004.002
|
|
|
|
//
|
|
|
|
function getUTCTimeZoneOffset() {
|
|
|
|
return moment().format('ZZ').replace(/\+/, '');
|
2015-07-14 06:13:29 +00:00
|
|
|
}
|
|
|
|
|
2017-08-27 17:17:29 +00:00
|
|
|
//
|
|
|
|
// Get a FSC-0032 style quote prefix
|
|
|
|
// http://ftsc.org/docs/fsc-0032.001
|
2018-01-15 19:22:11 +00:00
|
|
|
//
|
2015-09-21 01:10:09 +00:00
|
|
|
function getQuotePrefix(name) {
|
2017-08-25 04:20:07 +00:00
|
|
|
let initials;
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2017-08-25 04:20:07 +00:00
|
|
|
const parts = name.split(' ');
|
|
|
|
if(parts.length > 1) {
|
|
|
|
// First & Last initials - (Bryan Ashby -> BA)
|
|
|
|
initials = `${parts[0].slice(0, 1)}${parts[parts.length - 1].slice(0, 1)}`.toUpperCase();
|
|
|
|
} else {
|
|
|
|
// Just use the first two - (NuSkooler -> Nu)
|
|
|
|
initials = _.capitalize(name.slice(0, 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ` ${initials}> `;
|
2015-09-21 01:10:09 +00:00
|
|
|
}
|
|
|
|
|
2015-07-14 23:08:52 +00:00
|
|
|
//
|
2016-02-10 05:30:59 +00:00
|
|
|
// Return a FTS-0004 Origin line
|
|
|
|
// http://ftsc.org/docs/fts-0004.001
|
|
|
|
//
|
|
|
|
function getOrigin(address) {
|
2018-01-15 19:22:11 +00:00
|
|
|
const origin = _.has(Config, 'messageNetworks.originLine') ?
|
2018-01-06 05:02:36 +00:00
|
|
|
Config.messageNetworks.originLine :
|
2016-02-10 05:30:59 +00:00
|
|
|
Config.general.boardName;
|
2015-07-14 23:08:52 +00:00
|
|
|
|
2016-02-16 00:56:05 +00:00
|
|
|
const addrStr = new Address(address).toString('5D');
|
2016-06-20 20:24:11 +00:00
|
|
|
return ` * Origin: ${origin} (${addrStr})`;
|
2016-02-16 00:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getTearLine() {
|
2016-02-21 00:57:38 +00:00
|
|
|
const nodeVer = process.version.substr(1); // remove 'v' prefix
|
|
|
|
return `--- ENiGMA 1/2 v${packageJson.version} (${os.platform()}; ${os.arch()}; ${nodeVer})`;
|
2016-02-16 00:56:05 +00:00
|
|
|
}
|
|
|
|
|
2016-02-17 05:11:55 +00:00
|
|
|
//
|
|
|
|
// Return a FRL-1005.001 "Via" line
|
|
|
|
// http://ftsc.org/docs/frl-1005.001
|
|
|
|
//
|
|
|
|
function getVia(address) {
|
|
|
|
/*
|
|
|
|
FRL-1005.001 states teh following format:
|
|
|
|
|
2018-01-15 19:22:11 +00:00
|
|
|
^AVia: <FTN Address> @YYYYMMDD.HHMMSS[.Precise][.Time Zone]
|
2016-02-17 05:11:55 +00:00
|
|
|
<Program Name> <Version> [Serial Number]<CR>
|
|
|
|
*/
|
|
|
|
const addrStr = new Address(address).toString('5D');
|
|
|
|
const dateTime = moment().utc().format('YYYYMMDD.HHmmSS.SSSS.UTC');
|
2018-01-15 19:22:11 +00:00
|
|
|
const version = getCleanEnigmaVersion();
|
2016-02-17 05:11:55 +00:00
|
|
|
|
|
|
|
return `${addrStr} @${dateTime} ENiGMA1/2 ${version}`;
|
|
|
|
}
|
|
|
|
|
2018-01-01 00:54:11 +00:00
|
|
|
//
|
|
|
|
// Creates a INTL kludge value as per FTS-4001
|
|
|
|
// http://retro.fidoweb.ru/docs/index=ftsc&doc=FTS-4001&enc=mac
|
|
|
|
//
|
|
|
|
function getIntl(toAddress, fromAddress) {
|
|
|
|
//
|
|
|
|
// INTL differs from 'standard' kludges in that there is no ':' after "INTL"
|
|
|
|
//
|
|
|
|
// "<SOH>"INTL "<destination address>" "<origin address><CR>"
|
|
|
|
// "...These addresses shall be given on the form <zone>:<net>/<node>"
|
|
|
|
//
|
|
|
|
return `${toAddress.toString('3D')} ${fromAddress.toString('3D')}`;
|
|
|
|
}
|
|
|
|
|
2016-02-16 00:56:05 +00:00
|
|
|
function getAbbreviatedNetNodeList(netNodes) {
|
|
|
|
let abbrList = '';
|
|
|
|
let currNet;
|
|
|
|
netNodes.forEach(netNode => {
|
2016-03-09 05:30:04 +00:00
|
|
|
if(_.isString(netNode)) {
|
|
|
|
netNode = Address.fromString(netNode);
|
|
|
|
}
|
2016-02-16 00:56:05 +00:00
|
|
|
if(currNet !== netNode.net) {
|
|
|
|
abbrList += `${netNode.net}/`;
|
|
|
|
currNet = netNode.net;
|
|
|
|
}
|
|
|
|
abbrList += `${netNode.node} `;
|
|
|
|
});
|
|
|
|
|
|
|
|
return abbrList.trim(); // remove trailing space
|
|
|
|
}
|
|
|
|
|
2016-03-09 05:30:04 +00:00
|
|
|
//
|
|
|
|
// Parse an abbreviated net/node list commonly used for SEEN-BY and PATH
|
|
|
|
//
|
2016-02-16 00:56:05 +00:00
|
|
|
function parseAbbreviatedNetNodeList(netNodes) {
|
2016-03-10 05:32:00 +00:00
|
|
|
const re = /([0-9]+)\/([0-9]+)\s?|([0-9]+)\s?/g;
|
|
|
|
let net;
|
|
|
|
let m;
|
2018-01-15 19:22:11 +00:00
|
|
|
let results = [];
|
2016-03-10 05:32:00 +00:00
|
|
|
while(null !== (m = re.exec(netNodes))) {
|
|
|
|
if(m[1] && m[2]) {
|
|
|
|
net = parseInt(m[1]);
|
|
|
|
results.push(new Address( { net : net, node : parseInt(m[2]) } ));
|
|
|
|
} else if(net) {
|
|
|
|
results.push(new Address( { net : net, node : parseInt(m[3]) } ));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
2016-02-16 00:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Return a FTS-0004.001 SEEN-BY entry(s) that include
|
|
|
|
// all pre-existing SEEN-BY entries with the addition
|
2018-01-15 19:22:11 +00:00
|
|
|
// of |additions|.
|
2016-02-16 00:56:05 +00:00
|
|
|
//
|
|
|
|
// See http://ftsc.org/docs/fts-0004.001
|
|
|
|
// and notes at http://ftsc.org/docs/fsc-0043.002.
|
|
|
|
//
|
|
|
|
// For a great write up, see http://www.skepticfiles.org/aj/basics03.htm
|
|
|
|
//
|
|
|
|
// This method returns an sorted array of values, but
|
|
|
|
// not the "SEEN-BY" prefix itself
|
|
|
|
//
|
|
|
|
function getUpdatedSeenByEntries(existingEntries, additions) {
|
|
|
|
/*
|
|
|
|
From FTS-0004:
|
|
|
|
|
|
|
|
"There can be many seen-by lines at the end of Conference
|
|
|
|
Mail messages, and they are the real "meat" of the control
|
|
|
|
information. They are used to determine the systems to
|
|
|
|
receive the exported messages. The format of the line is:
|
|
|
|
|
|
|
|
SEEN-BY: 132/101 113 136/601 1014/1
|
|
|
|
|
|
|
|
The net/node numbers correspond to the net/node numbers of
|
|
|
|
the systems having already received the message. In this way
|
|
|
|
a message is never sent to a system twice. In a conference
|
|
|
|
with many participants the number of seen-by lines can be
|
|
|
|
very large. This line is added if it is not already a part
|
|
|
|
of the message, or added to if it already exists, each time
|
|
|
|
a message is exported to other systems. This is a REQUIRED
|
|
|
|
field, and Conference Mail will not function correctly if
|
|
|
|
this field is not put in place by other Echomail compatible
|
|
|
|
programs."
|
|
|
|
*/
|
|
|
|
existingEntries = existingEntries || [];
|
|
|
|
if(!_.isArray(existingEntries)) {
|
|
|
|
existingEntries = [ existingEntries ];
|
|
|
|
}
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2016-03-09 05:30:04 +00:00
|
|
|
if(!_.isString(additions)) {
|
2018-01-15 19:22:11 +00:00
|
|
|
additions = parseAbbreviatedNetNodeList(getAbbreviatedNetNodeList(additions));
|
2016-03-09 05:30:04 +00:00
|
|
|
}
|
2016-02-16 00:56:05 +00:00
|
|
|
|
2016-03-09 05:30:04 +00:00
|
|
|
additions = additions.sort(Address.getComparator());
|
2016-02-16 00:56:05 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// For now, we'll just append a new SEEN-BY entry
|
|
|
|
//
|
|
|
|
// :TODO: we should at least try and update what is already there in a smart way
|
|
|
|
existingEntries.push(getAbbreviatedNetNodeList(additions));
|
|
|
|
return existingEntries;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getUpdatedPathEntries(existingEntries, localAddress) {
|
|
|
|
// :TODO: append to PATH in a smart way! We shoudl try to fit at least the last existing line
|
|
|
|
|
|
|
|
existingEntries = existingEntries || [];
|
|
|
|
if(!_.isArray(existingEntries)) {
|
|
|
|
existingEntries = [ existingEntries ];
|
|
|
|
}
|
|
|
|
|
|
|
|
existingEntries.push(getAbbreviatedNetNodeList(
|
|
|
|
parseAbbreviatedNetNodeList(localAddress)));
|
|
|
|
|
|
|
|
return existingEntries;
|
2015-07-14 06:13:29 +00:00
|
|
|
}
|
2016-02-21 00:57:38 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Return FTS-5000.001 "CHRS" value
|
|
|
|
// http://ftsc.org/docs/fts-5003.001
|
|
|
|
//
|
|
|
|
const ENCODING_TO_FTS_5003_001_CHARS = {
|
|
|
|
// level 1 - generally should not be used
|
|
|
|
ascii : [ 'ASCII', 1 ],
|
|
|
|
'us-ascii' : [ 'ASCII', 1 ],
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2016-02-21 00:57:38 +00:00
|
|
|
// level 2 - 8 bit, ASCII based
|
|
|
|
cp437 : [ 'CP437', 2 ],
|
|
|
|
cp850 : [ 'CP850', 2 ],
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2016-02-21 00:57:38 +00:00
|
|
|
// level 3 - reserved
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2016-02-21 00:57:38 +00:00
|
|
|
// level 4
|
|
|
|
utf8 : [ 'UTF-8', 4 ],
|
|
|
|
'utf-8' : [ 'UTF-8', 4 ],
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function getCharacterSetIdentifierByEncoding(encodingName) {
|
|
|
|
const value = ENCODING_TO_FTS_5003_001_CHARS[encodingName.toLowerCase()];
|
|
|
|
return value ? `${value[0]} ${value[1]}` : encodingName.toUpperCase();
|
|
|
|
}
|
|
|
|
|
|
|
|
function getEncodingFromCharacterSetIdentifier(chrs) {
|
|
|
|
const ident = chrs.split(' ')[0].toUpperCase();
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2016-02-21 00:57:38 +00:00
|
|
|
// :TODO: fill in the rest!!!
|
|
|
|
return {
|
|
|
|
// level 1
|
|
|
|
'ASCII' : 'iso-646-1',
|
|
|
|
'DUTCH' : 'iso-646',
|
|
|
|
'FINNISH' : 'iso-646-10',
|
|
|
|
'FRENCH' : 'iso-646',
|
|
|
|
'CANADIAN' : 'iso-646',
|
|
|
|
'GERMAN' : 'iso-646',
|
|
|
|
'ITALIAN' : 'iso-646',
|
|
|
|
'NORWEIG' : 'iso-646',
|
|
|
|
'PORTU' : 'iso-646',
|
|
|
|
'SPANISH' : 'iso-656',
|
|
|
|
'SWEDISH' : 'iso-646-10',
|
|
|
|
'SWISS' : 'iso-646',
|
|
|
|
'UK' : 'iso-646',
|
|
|
|
'ISO-10' : 'iso-646-10',
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2016-02-21 00:57:38 +00:00
|
|
|
// level 2
|
|
|
|
'CP437' : 'cp437',
|
|
|
|
'CP850' : 'cp850',
|
|
|
|
'CP852' : 'cp852',
|
|
|
|
'CP866' : 'cp866',
|
|
|
|
'CP848' : 'cp848',
|
|
|
|
'CP1250' : 'cp1250',
|
|
|
|
'CP1251' : 'cp1251',
|
|
|
|
'CP1252' : 'cp1252',
|
|
|
|
'CP10000' : 'macroman',
|
|
|
|
'LATIN-1' : 'iso-8859-1',
|
|
|
|
'LATIN-2' : 'iso-8859-2',
|
|
|
|
'LATIN-5' : 'iso-8859-9',
|
|
|
|
'LATIN-9' : 'iso-8859-15',
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2016-02-21 00:57:38 +00:00
|
|
|
// level 4
|
|
|
|
'UTF-8' : 'utf8',
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2016-02-21 00:57:38 +00:00
|
|
|
// deprecated stuff
|
2018-01-15 19:22:11 +00:00
|
|
|
'IBMPC' : 'cp1250', // :TODO: validate
|
2016-02-21 00:57:38 +00:00
|
|
|
'+7_FIDO' : 'cp866',
|
2018-01-15 19:22:11 +00:00
|
|
|
'+7' : 'cp866',
|
2016-02-21 00:57:38 +00:00
|
|
|
'MAC' : 'macroman', // :TODO: validate
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2016-02-21 00:57:38 +00:00
|
|
|
}[ident];
|
|
|
|
}
|