From 8b2be6769cace8fd64d1a42d5545e1a63eb3f004 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Tue, 17 Nov 2020 19:06:54 -0700 Subject: [PATCH] * TZUTC/TZUTCINFO handling should work properly * Don't bork message timestamp when we write to the DB * Fix read byte len which could prevent message imports! --- core/ftn_mail_packet.js | 25 +++++++++++++++++++++---- core/message.js | 7 +++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/core/ftn_mail_packet.js b/core/ftn_mail_packet.js index 781ed929..973954c8 100644 --- a/core/ftn_mail_packet.js +++ b/core/ftn_mail_packet.js @@ -678,11 +678,28 @@ function Packet(options) { } // - // If we have a UTC offset kludge (e.g. TZUTC) then update - // modDateTime with it + // Attempt to handle FTN time zone kludges of 'TZUTC' and + // 'TZUTCINFO'. // - if(_.isString(msg.meta.FtnKludge.TZUTC) && msg.meta.FtnKludge.TZUTC.length > 0) { - msg.modDateTime = msg.modTimestamp.utcOffset(msg.meta.FtnKludge.TZUTC); + // See http://ftsc.org/docs/frl-1004.002 + // + const tzKludge = msg.meta.FtnKludge.TZUTC || msg.meta.FtnKludge.TZUTCINFO; + const tzMatch = /([+-]?)([0-9]{2})([0-9]{2})/.exec(tzKludge); + if (tzMatch) { + // + // - Both kludges should provide a offset in hhmm format + // - Negative offsets must proceed with '-' + // - Positive offsets must not (to spec) proceed with '+', but + // we'll allow it. + // + const [, sign, hours, minutes ] = tzMatch; + + // convert to a [+|-]hh:mm format. + // example: 1300 -> +13:00 + const utcOffset = `${sign||'+'}${hours}:${minutes}`; + + // finally, update our modTimestamp + msg.modTimestamp = msg.modTimestamp.utcOffset(utcOffset); } // :TODO: Parser should give is this info: diff --git a/core/message.js b/core/message.js index 9b7a980e..73ebe761 100644 --- a/core/message.js +++ b/core/message.js @@ -134,7 +134,7 @@ module.exports = class Message { modTimestamp = moment(modTimestamp); } - this.modTimestamp = modTimestamp; + this.modTimestamp = modTimestamp || moment(); this.meta = {}; _.defaultsDeep(this.meta, { System : {} }, meta); @@ -695,11 +695,10 @@ module.exports = class Message { }, function storeMessage(trans, callback) { // generate a UUID for this message if required (general case) - const msgTimestamp = moment(); if(!self.messageUuid) { self.messageUuid = Message.createMessageUUID( self.areaTag, - msgTimestamp, + self.modTimestamp, self.subject, self.message ); @@ -710,7 +709,7 @@ module.exports = class Message { VALUES (?, ?, ?, ?, ?, ?, ?, ?);`, [ self.areaTag, self.messageUuid, self.replyToMsgId, self.toUserName, - self.fromUserName, self.subject, self.message, getISOTimestampString(msgTimestamp) + self.fromUserName, self.subject, self.message, getISOTimestampString(self.modTimestamp) ], function inserted(err) { // use non-arrow function for 'this' scope if(!err) {