Minor fixes, tidy up FTS CHRS table a bit

This commit is contained in:
Bryan Ashby 2020-05-03 11:10:40 -06:00
parent b32dae9b48
commit c6bde65be0
No known key found for this signature in database
GPG Key ID: B49EB437951D2542
2 changed files with 27 additions and 16 deletions

View File

@ -375,26 +375,28 @@ function getCharacterSetIdentifierByEncoding(encodingName) {
return value ? `${value[0]} ${value[1]}` : encodingName.toUpperCase();
}
// http://ftsc.org/docs/fts-5003.001
// http://www.unicode.org/L2/L1999/99325-N.htm
function getEncodingFromCharacterSetIdentifier(chrs) {
const ident = chrs.split(' ')[0].toUpperCase();
// :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',
'ASCII' : 'ascii', // ISO-646-1
'DUTCH' : 'ascii', // ISO-646
'FINNISH' : 'ascii', // ISO-646-10
'FRENCH' : 'ascii', // ISO-646
'CANADIAN' : 'ascii', // ISO-646
'GERMAN' : 'ascii', // ISO-646
'ITALIAN' : 'ascii', // ISO-646
'NORWEIG' : 'ascii', // ISO-646
'PORTU' : 'ascii', // ISO-646
'SPANISH' : 'iso-656',
'SWEDISH' : 'iso-646-10',
'SWISS' : 'iso-646',
'UK' : 'iso-646',
'ISO-10' : 'iso-646-10',
'SWEDISH' : 'ascii', // ISO-646-10
'SWISS' : 'ascii', // ISO-646
'UK' : 'ascii', // ISO-646
'ISO-10' : 'ascii', // ISO-646-10
// level 2
'CP437' : 'cp437',

View File

@ -963,6 +963,15 @@ class QWKPacketWriter extends EventEmitter {
return `<${message.messageId}.${message.messageUuid}@${this.options.systemDomain}>`;
}
_encodeWithFallback(s, encoding) {
try {
return iconv.encode(s, encoding);
} catch (e) {
this.emit('warning', Errors.General(`Failed to encode buffer using ${encoding}; Falling back to 'ascii'`));
return iconv.encode(s, 'ascii');
}
}
appendMessage(message) {
//
// Each message has to:
@ -1014,7 +1023,7 @@ class QWKPacketWriter extends EventEmitter {
const encoding = this._getEncoding(message);
const encodedMessage = iconv.encode(fullMessageBody, encoding);
const encodedMessage = this._encodeWithFallback(fullMessageBody, encoding);
//
// QWK spec wants line feeds as 0xe3 for some reason, so we'll have
@ -1504,11 +1513,11 @@ class QWKPacketWriter extends EventEmitter {
messageData.Editor = `ENiGMA 1/2 BBS FSE v${enigmaVersion}`;
}
this.headersDatStream.write(iconv.encode(`[${this.currentMessageOffset.toString(16)}]\r\n`, encoding));
this.headersDatStream.write(this._encodeWithFallback(`[${this.currentMessageOffset.toString(16)}]\r\n`, encoding));
for (let [name, value] of Object.entries(messageData)) {
if (value) {
this.headersDatStream.write(iconv.encode(`${name}: ${value}\r\n`, encoding));
this.headersDatStream.write(this._encodeWithFallback(`${name}: ${value}\r\n`, encoding));
}
}