2024-12-03 04:54:17 +00:00
|
|
|
'use strict';
|
|
|
|
require('ansitex/load/defs.js','ANSITEX_HOME');
|
|
|
|
|
|
|
|
// Our message bases that are enabled to render Videotex Messages
|
|
|
|
/*
|
|
|
|
* If a message area doesnt have:
|
|
|
|
* + a zone_id, then the group isnt Videotex enabled
|
|
|
|
* + a area_id, then the area isnt Videotex enabled
|
|
|
|
*/
|
2022-04-18 11:27:25 +00:00
|
|
|
function MsgAreas() {
|
2024-12-03 04:54:17 +00:00
|
|
|
this.areas = []; // Message areas
|
2022-04-18 11:27:25 +00:00
|
|
|
var zone_id;
|
|
|
|
var zone_name;
|
|
|
|
var ma;
|
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
// Load the message areas
|
|
|
|
for (var g in msg_area.grp_list) {
|
|
|
|
for (var a in msg_area.grp_list[g].sub_list) {
|
|
|
|
//writeln('group:'+g+' name:'+msg_area.grp_list[g].name+' FIDO:'+JSON.stringify(msg_area.grp_list[g].sub_list[a].fidonet_addr)+' INDEX:'+JSON.stringify(msg_area.grp_list[g].sub_list[a].ptridx));
|
|
|
|
|
|
|
|
ma = new MsgArea();
|
|
|
|
ma.group_id = g;
|
|
|
|
ma.sub_id = a;
|
|
|
|
|
|
|
|
if (msg_area.grp_list[g].name.indexOf(':') === -1) {
|
|
|
|
// If the sub is enabled for FTN, and the zone < 9999, then we'll us that if zone_id is undefined
|
|
|
|
if ((msg_area.grp_list[g].sub_list[a].settings & SUB_FIDO) && msg_area.grp_list[g].sub_list[a].fidonet_addr) {
|
|
|
|
var x = msg_area.grp_list[g].sub_list[a].fidonet_addr.split(/([0-9]+):/)[1];
|
|
|
|
if ((x > 0) && (x < 9999)) {
|
|
|
|
zone_id = x.padStart(4,'0');
|
|
|
|
zone_name = msg_area.grp_list[g].name;
|
|
|
|
}
|
2022-04-18 11:27:25 +00:00
|
|
|
}
|
2024-12-03 04:54:17 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
zone_id = msg_area.grp_list[g].name.split(':')[0];
|
|
|
|
zone_name = msg_area.grp_list[g].name.split(':')[1];
|
2022-04-18 11:27:25 +00:00
|
|
|
}
|
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
if (zone_id) {
|
|
|
|
ma.zone_id = zone_id;
|
|
|
|
ma.zone_name = zone_name;
|
2022-04-18 11:27:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
if (msg_area.grp_list[g].sub_list[a].name.indexOf(':') !== -1) {
|
|
|
|
var sublist = msg_area.grp_list[g].sub_list[a].name.split(':');
|
|
|
|
ma.area_id = sublist[0];
|
|
|
|
ma.area_name = sublist[1];
|
|
|
|
|
|
|
|
/*
|
|
|
|
writeln(' code:'+ma.code);
|
|
|
|
writeln(' fullname:'+ma.full_name);
|
|
|
|
writeln(' pageprefix:'+ma.page_prefix)
|
|
|
|
writeln();
|
|
|
|
*/
|
|
|
|
}
|
2022-04-18 11:27:25 +00:00
|
|
|
}
|
2024-12-03 04:54:17 +00:00
|
|
|
|
|
|
|
this.areas.push(ma);
|
2022-04-18 11:27:25 +00:00
|
|
|
}
|
|
|
|
}
|
2023-12-24 06:44:02 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
/* List areas that we do and dont manage */
|
2023-12-24 06:44:02 +00:00
|
|
|
Object.defineProperty(this,'list',{
|
|
|
|
get: function() {
|
2024-12-03 04:54:17 +00:00
|
|
|
var areas = this.managed;
|
|
|
|
writeln('Areas that we ARE managing mail:'+areas.length);
|
|
|
|
for (var x in areas.sort(function(a,b) { return a.page_prefix > b.page_prefix; })) {
|
|
|
|
writeln(x+':'+areas[x].code+' prefix:'+areas[x].page_prefix);
|
2023-12-24 06:44:02 +00:00
|
|
|
}
|
2024-12-03 04:54:17 +00:00
|
|
|
|
|
|
|
areas = this.unmanaged;
|
|
|
|
writeln('Areas that we are NOT managing mail:'+areas.length);
|
|
|
|
for (var x in areas)
|
|
|
|
writeln(x+':'+areas[x].code);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/* List of message areas managed */
|
|
|
|
Object.defineProperty(this,'managed',{
|
|
|
|
get: function() {
|
|
|
|
return this.areas.filter(function(item) {
|
|
|
|
return item.managed;
|
|
|
|
});
|
2023-12-24 06:44:02 +00:00
|
|
|
}
|
|
|
|
});
|
2024-12-03 04:54:17 +00:00
|
|
|
|
|
|
|
/* List of message areas unmanaged */
|
|
|
|
Object.defineProperty(this,'unmanaged',{
|
|
|
|
get: function() {
|
|
|
|
return this.areas.filter(function(item) {
|
|
|
|
return ! item.managed;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/* Fetch a specific message area */
|
|
|
|
MsgAreas.prototype.getArea = function(area) {
|
|
|
|
if (area === undefined)
|
|
|
|
return undefined;
|
|
|
|
|
|
|
|
return this.areas.filter(function(x) {
|
|
|
|
// If the area is a 6 digits, then its a page prefix, otherwise its an area code name
|
|
|
|
if ((area.length === 6) && (NUMERIC_REGEX.test(area)))
|
|
|
|
return x.page_prefix === area;
|
|
|
|
|
|
|
|
else
|
|
|
|
return x.code === area;
|
|
|
|
}).pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
// @todo review
|
|
|
|
MsgAreas.prototype.getMessage = function(page) {
|
|
|
|
var area = this.getArea(page);
|
|
|
|
log(LOG_DEBUG,' - msg:'+JSON.stringify(page.substr(7,4)));
|
|
|
|
|
|
|
|
return area ? area.getMessage(page.substr(7,4)) : undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @todo review
|
|
|
|
MsgAreas.prototype.getUserStats = function(page) {
|
|
|
|
var area = this.getArea(page);
|
|
|
|
|
|
|
|
return area ? msg_area.grp_list[area.msgbase.cfg.grp_number].sub_list[msg_area.sub[area.msgbase.cfg.code].index] : undefined;
|
|
|
|
}
|
2022-04-18 11:27:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function MsgArea() {
|
2024-12-03 04:54:17 +00:00
|
|
|
this.zone_id = undefined; // Zone this message area belongs to, eg: 0516
|
|
|
|
this.zone_name = undefined; // Zone Name, eg: VIDEOTEX
|
|
|
|
this.area_id = undefined; // Sub Area ID for this message area, eg: 01
|
|
|
|
this.area_name = undefined; // Sub Area Name for this message area, eg: CHAT
|
|
|
|
this.group_id = undefined; // SBBS Message Group ID
|
|
|
|
this.sub_id = undefined; // SBBS Message Sub ID
|
|
|
|
|
|
|
|
// MSG Base Code
|
2022-04-18 11:27:25 +00:00
|
|
|
Object.defineProperty(this,'code',{
|
2024-12-03 04:54:17 +00:00
|
|
|
get: function() {
|
|
|
|
//writeln('group_id:'+this.group_id+' sub_id:'+this.sub_id);
|
|
|
|
return msg_area.grp_list[this.group_id].sub_list[this.sub_id].code;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Get all frames that are tagged
|
|
|
|
Object.defineProperty(this,'frames',{
|
|
|
|
get: function() {
|
2024-12-03 23:13:28 +00:00
|
|
|
var msgbase;
|
|
|
|
var regex = false;
|
|
|
|
|
|
|
|
if (this.code === FRAMES_MSG_BASE) {
|
|
|
|
msgbase = this.msgbase;
|
|
|
|
|
|
|
|
} else if (this.managed) {
|
|
|
|
msgbase = new MsgAreas().getArea(FRAMES_MSG_BASE).msgbase;
|
|
|
|
regex = this.page_prefix_regex;
|
|
|
|
|
|
|
|
} else
|
2024-12-03 04:54:17 +00:00
|
|
|
return undefined;
|
|
|
|
|
|
|
|
var frames = [];
|
2022-04-18 11:27:25 +00:00
|
|
|
|
2022-05-13 13:32:22 +00:00
|
|
|
try {
|
2024-12-03 04:54:17 +00:00
|
|
|
if (msgbase.open()) {
|
|
|
|
var headers = msgbase.get_all_msg_headers(false,false) || [];
|
2022-12-15 12:28:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
for (var i in headers) {
|
2024-12-03 23:13:28 +00:00
|
|
|
if ((! (headers[i].attr&MSG_DELETE)) && headers[i].tags && ((! regex) || regex.test(headers[i].tags)))
|
2024-12-03 04:54:17 +00:00
|
|
|
frames.push(headers[i]);
|
|
|
|
}
|
2022-12-15 12:28:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
msgbase.close();
|
2022-05-13 13:32:22 +00:00
|
|
|
|
|
|
|
} else {
|
2024-12-03 04:54:17 +00:00
|
|
|
writeln('*** NOPE WONT OPEN msgbase:'+JSON.stringify(msgbase));
|
2022-05-13 13:32:22 +00:00
|
|
|
}
|
2022-04-18 11:27:25 +00:00
|
|
|
|
2022-05-13 13:32:22 +00:00
|
|
|
} catch (e) {
|
2024-12-03 04:54:17 +00:00
|
|
|
log(LOG_ERROR,this.code+' cannot be opened (frames):'+e.message);
|
|
|
|
|
|
|
|
return undefined;
|
2022-05-13 13:32:22 +00:00
|
|
|
}
|
2024-12-03 04:54:17 +00:00
|
|
|
|
|
|
|
return frames.sort(function(a,b) {
|
|
|
|
return (a.when_imported_time !== b.when_imported_time)
|
|
|
|
? a.when_imported_time > b.when_imported_time
|
|
|
|
: a.number > b.number;
|
|
|
|
});
|
2022-04-18 11:27:25 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Get Area's full name
|
|
|
|
Object.defineProperty(this,'full_name',{
|
|
|
|
get: function() {
|
|
|
|
return this.zone_name+':'+this.area_name;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
// @deprecated use frames instead
|
2022-04-18 11:27:25 +00:00
|
|
|
// Total tagged messages
|
|
|
|
Object.defineProperty(this,'list_tagged',{
|
|
|
|
get: function() {
|
|
|
|
if (this.tagged_list === undefined) {
|
|
|
|
this.tagged_list = [];
|
|
|
|
|
|
|
|
if (! this.headers)
|
|
|
|
return this.tagged_list;
|
|
|
|
|
|
|
|
for(var x in this.headers) {
|
|
|
|
if (this.headers[x].tags && (this.headers[x].tags.length === PAGE_LENGTH)) {
|
|
|
|
this.tagged_list.push(this.headers[x]);
|
|
|
|
write(); // @todo This is needed for this to work?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.tagged_list;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-12-03 23:13:28 +00:00
|
|
|
// Retrieve the last tagged frame
|
|
|
|
Object.defineProperty(this,'last_tagged_message',{
|
2022-04-18 11:27:25 +00:00
|
|
|
get: function() {
|
2024-12-03 04:54:17 +00:00
|
|
|
var last_tag = this.frames.sort(function(a,b) {
|
|
|
|
if (a.when_imported_time === b.when_imported_time)
|
|
|
|
return a.number > b.number
|
|
|
|
else
|
|
|
|
return (a.when_imported_time > b.when_imported_time);
|
|
|
|
}).pop();
|
2022-04-18 11:27:25 +00:00
|
|
|
|
2024-12-03 23:13:28 +00:00
|
|
|
if (last_tag === undefined)
|
|
|
|
return undefined;
|
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
var msgbase = new MsgAreas().getArea(FRAMES_MSG_BASE).msgbase;
|
2022-04-18 11:27:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
try {
|
|
|
|
if (msgbase.open()) {
|
|
|
|
var body = JSON.parse(LZString.decompressFromBase64(msgbase.get_msg_body(last_tag.number)));
|
|
|
|
|
|
|
|
msgbase.close();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
writeln('*** NOPE WONT OPEN msgbase:'+JSON.stringify(msgbase));
|
2022-04-18 11:27:25 +00:00
|
|
|
}
|
2024-12-03 04:54:17 +00:00
|
|
|
|
|
|
|
} catch (e) {
|
2024-12-03 23:13:28 +00:00
|
|
|
log(LOG_ERROR,this.code+' cannot be opened (last_tagged_message):'+e.message);
|
2024-12-03 04:54:17 +00:00
|
|
|
|
|
|
|
return undefined;
|
2022-04-18 11:27:25 +00:00
|
|
|
}
|
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
msgbase = this.msgbase;
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (msgbase.open()) {
|
|
|
|
var index = msgbase.get_msg_header(body.id);
|
|
|
|
|
|
|
|
msgbase.close();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
writeln('*** NOPE WONT OPEN msgbase:'+JSON.stringify(msgbase));
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (e) {
|
2024-12-03 23:13:28 +00:00
|
|
|
log(LOG_ERROR,this.code+' cannot be opened (last_tagged_message_base):'+e.message);
|
2024-12-03 04:54:17 +00:00
|
|
|
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-12-03 23:13:28 +00:00
|
|
|
// Is this area defined for ansitex messages
|
2024-12-03 04:54:17 +00:00
|
|
|
Object.defineProperty(this,'managed',{
|
|
|
|
get: function() {
|
|
|
|
return (this.zone_id !== undefined) && (this.area_id !== undefined);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.defineProperty(this,'max_page',{
|
|
|
|
get: function() {
|
|
|
|
return parseInt('9'.repeat(PAGE_LENGTH),10);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.defineProperty(this,'msgbase',{
|
|
|
|
get: function() {
|
|
|
|
return new MsgBase(this.code);
|
2022-04-18 11:27:25 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Get Next page number
|
|
|
|
Object.defineProperty(this,'page_next',{
|
|
|
|
get: function() {
|
2024-12-03 04:54:17 +00:00
|
|
|
if (! this.managed)
|
|
|
|
return undefined;
|
2022-04-18 11:27:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
var next_tag = this.frames.pop();
|
|
|
|
|
|
|
|
if (next_tag !== undefined) {
|
|
|
|
next_tag = next_tag.tags;
|
|
|
|
|
|
|
|
if (next_tag.indexOf('1'+this.page_prefix) === 0)
|
|
|
|
next_tag = next_tag.slice(this.page_prefix.length+1);
|
2022-04-18 11:27:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
next_tag = parseInt(next_tag,10)+1;
|
|
|
|
|
|
|
|
if (next_tag > this.max_page)
|
|
|
|
next_tag = 0;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
next_tag = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (''+next_tag).padStart(4,'0');
|
2022-04-18 11:27:25 +00:00
|
|
|
},
|
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
/*
|
2022-04-18 11:27:25 +00:00
|
|
|
set: function(page) {
|
|
|
|
var f = new File(file_cfgname(system.mods_dir,'ansitex/ctrl/videotex.ini'));
|
|
|
|
if (! f.open('r+')) {
|
|
|
|
writeln('Unable to open ini file');
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
2022-04-26 11:54:34 +00:00
|
|
|
f.iniSetValue('prefix:'+this.page_prefix,PAGE_LAST_KEY,(''+page).padStart(4,'0'));
|
2022-04-18 11:27:25 +00:00
|
|
|
f.close();
|
|
|
|
}
|
2024-12-03 04:54:17 +00:00
|
|
|
*/
|
2022-04-18 11:27:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Our page prefix for this msg area
|
|
|
|
Object.defineProperty(this,'page_prefix',{
|
|
|
|
get: function() {
|
|
|
|
return ''+this.zone_id+this.area_id;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
// Return a REG to test if this frame is part of this msgbase
|
|
|
|
Object.defineProperty(this,'page_prefix_regex',{
|
|
|
|
get: function() {
|
|
|
|
return new RegExp( '^1'+this.page_prefix);
|
|
|
|
},
|
|
|
|
});
|
2022-05-03 11:10:09 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
// Total Messages in a msgbase
|
|
|
|
Object.defineProperty(this,'total_msgs',{
|
|
|
|
get: function() {
|
|
|
|
if (! this.managed)
|
|
|
|
return undefined;
|
2022-05-06 05:32:35 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
var msgbase = this.msgbase;
|
2022-05-06 05:32:35 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
try {
|
|
|
|
if (msgbase.open()) {
|
|
|
|
var index = msgbase.get_index() || [];
|
2022-05-06 05:32:35 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
msgbase.close();
|
2022-05-06 05:32:35 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
} else {
|
|
|
|
writeln('*** NOPE WONT OPEN msgbase:'+JSON.stringify(msgbase));
|
|
|
|
}
|
2022-12-15 12:28:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
} catch (e) {
|
|
|
|
log(LOG_ERROR,this.code+' cannot be opened (total_msgs):'+e.message);
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return index.length;
|
2022-12-15 12:28:25 +00:00
|
|
|
}
|
2024-12-03 04:54:17 +00:00
|
|
|
});
|
2022-12-15 12:28:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
// List untagged messages
|
|
|
|
Object.defineProperty(this,'untagged', {
|
|
|
|
get: function() {
|
|
|
|
if (! this.managed)
|
|
|
|
return undefined;
|
2022-05-03 11:10:09 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
var msgbase = this.msgbase;
|
2024-12-03 23:13:28 +00:00
|
|
|
var last_tag = this.last_tagged_message;
|
2024-12-03 04:54:17 +00:00
|
|
|
var msgs = [];
|
2022-05-03 11:10:09 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
try {
|
|
|
|
if (msgbase.open()) {
|
|
|
|
var headers = msgbase.get_all_msg_headers(false,false);
|
2022-05-03 11:10:09 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
for (var x in headers) {
|
|
|
|
if (last_tag
|
|
|
|
&& ((headers[x].when_imported_time < last_tag.when_imported_time)
|
|
|
|
|| ((headers[x].when_imported_time === last_tag.when_imported_time) && (headers[x].number <= last_tag.number))))
|
|
|
|
continue;
|
2022-05-03 11:10:09 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
msgs.push(headers[x]);
|
|
|
|
}
|
2022-04-18 11:27:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
msgbase.close();
|
2022-04-18 11:27:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
} else {
|
|
|
|
writeln('*** NOPE WONT OPEN msgbase:'+JSON.stringify(msgbase));
|
|
|
|
}
|
2022-04-18 11:27:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
} catch (e) {
|
|
|
|
log(LOG_ERROR,this.code+' cannot be opened (untagged):'+e.message);
|
2022-04-20 11:19:01 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
2022-04-18 11:27:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
return msgs.sort(function(a,b) {
|
|
|
|
return (a.when_imported_time !== b.when_imported_time)
|
|
|
|
? a.when_imported_time > b.when_imported_time
|
|
|
|
: a.number > b.number;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2022-04-18 11:27:25 +00:00
|
|
|
|
2024-12-03 23:13:28 +00:00
|
|
|
// Get frame content
|
|
|
|
MsgArea.prototype.getContent = function(id) {
|
|
|
|
// @todo If this is for a echomail/netmail content, then we need to switch message bases
|
|
|
|
if (this.code !== FRAMES_MSG_BASE)
|
|
|
|
return undefined;
|
|
|
|
|
|
|
|
var msgbase = this.msgbase;
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (msgbase.open()) {
|
2024-12-07 08:32:42 +00:00
|
|
|
var raw = msgbase.get_msg_body(false,id,false,false,true,true);
|
2024-12-03 23:13:28 +00:00
|
|
|
|
2024-12-07 08:32:42 +00:00
|
|
|
// Our messages are terminated with \r=== EOF
|
|
|
|
if (! /^(.*)\r=== EOF/.test(raw))
|
|
|
|
return undefined;
|
|
|
|
|
|
|
|
var content = JSON.parse(LZString.decompressFromBase64(raw.replace(/\r=== EOF[.\s\S]*$/,'')));
|
|
|
|
msgbase.close();
|
2024-12-03 23:13:28 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
writeln('*** NOPE WONT OPEN msgbase:'+JSON.stringify(msgbase));
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
log(LOG_ERROR,this.code+' cannot be opened (frames):'+e.message);
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return content;
|
|
|
|
};
|
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
// @todo review
|
|
|
|
/**
|
|
|
|
* Unread messages [1..]
|
|
|
|
* Array key 0 returns the last read message
|
|
|
|
*
|
|
|
|
* @returns {*[]}
|
|
|
|
*/
|
|
|
|
MsgArea.prototype.newMsgs = function() {
|
|
|
|
var msgs = [];
|
|
|
|
var stats = this.getUserStats();
|
|
|
|
//log(LOG_DEBUG,'Users last_read pointer: '+JSON.stringify(stats.last_read));
|
2022-05-06 10:14:58 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
for(var x in this.list_tagged) {
|
|
|
|
// Advance past our last scan_ptr
|
|
|
|
if (this.list_tagged[x].number <= stats.last_read)
|
|
|
|
continue;
|
2022-05-03 11:10:09 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
msgs.push(this.list_tagged[x]);
|
2022-05-12 12:27:06 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
write(); // @todo This is needed for this to work?
|
2022-05-06 10:14:58 +00:00
|
|
|
}
|
2024-12-03 04:54:17 +00:00
|
|
|
|
|
|
|
return msgs;
|
2022-05-06 10:14:58 +00:00
|
|
|
}
|
2022-05-03 11:10:09 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
// @todo review
|
|
|
|
/**
|
|
|
|
* New Messages for the logged in user
|
|
|
|
*/
|
|
|
|
MsgArea.prototype.newMsgsToMe = function() {
|
|
|
|
var msgs = [];
|
|
|
|
var stats = this.getUserStats();
|
|
|
|
var last = null;
|
|
|
|
//log(LOG_DEBUG,'Users scan_ptr pointer: '+JSON.stringify(stats.scan_ptr));
|
|
|
|
|
|
|
|
for(var x in this.list_tagged) {
|
|
|
|
// Advance past our last scan_ptr
|
|
|
|
if (this.list_tagged[x].number <= stats.scan_ptr) {
|
|
|
|
if ((this.list_tagged[x].to === user.name) || (this.list_tagged[x].to === user.alias))
|
|
|
|
last = x;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
2022-05-03 11:10:09 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
// Add our previous to me message
|
|
|
|
if (msgs.length === 0)
|
|
|
|
msgs.push(last !== null ? this.list_tagged[last] : []);
|
2022-05-03 11:10:09 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
if ((this.list_tagged[x].to === user.name) || (this.list_tagged[x].to === user.alias))
|
|
|
|
msgs.push(this.list_tagged[x]);
|
|
|
|
|
|
|
|
write(); // @todo This is needed for this to work?
|
|
|
|
}
|
|
|
|
|
|
|
|
return msgs;
|
|
|
|
}
|
2022-05-03 11:10:09 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
// @todo review
|
|
|
|
/**
|
|
|
|
* Get a specific message with a tag
|
|
|
|
*/
|
|
|
|
MsgArea.prototype.getMessage = function(page) {
|
|
|
|
var msg = undefined;
|
2022-12-15 12:28:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
for(var x in this.list_tagged) {
|
|
|
|
if (this.list_tagged[x].tags === page) {
|
|
|
|
msg = this.list_tagged[x];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
write(); // @todo This is needed for this to work?
|
|
|
|
}
|
2022-12-15 12:28:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
if (! msg)
|
|
|
|
return undefined;
|
2022-12-15 12:28:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
if (! this.msgbase.open()) {
|
|
|
|
writeln(code+' cannot be opened (getMessage):'+this.msgbase.error);
|
|
|
|
return undefined;
|
2022-12-15 12:28:25 +00:00
|
|
|
}
|
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
msg.grp_number = this.msgbase.cfg.grp_number;
|
|
|
|
var cfg = this.msgbase.cfg;
|
|
|
|
msg.subnum = msg_area.grp_list[cfg.grp_number].sub_list.filter(function(x) { return x.number === cfg.number; }).pop().index;
|
|
|
|
msg.content = this.msgbase.get_msg_body(false,msg.number,false,false,true,true);
|
|
|
|
this.msgbase.close();
|
2022-12-15 12:28:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
return msg;
|
|
|
|
}
|
2022-12-15 12:28:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
// @todo review
|
|
|
|
/**
|
|
|
|
* Get a message page by pointer
|
|
|
|
*
|
|
|
|
* @param number
|
|
|
|
* @returns {string}
|
2022-12-15 12:28:25 +00:00
|
|
|
*/
|
2024-12-03 04:54:17 +00:00
|
|
|
MsgArea.prototype.getMessagePage = function(number) {
|
|
|
|
log(LOG_DEBUG,'Get Message Page with number ['+number+']');
|
2022-12-15 12:28:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
var r;
|
2022-12-15 12:28:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
for (var x in this.list_tagged) {
|
|
|
|
if (this.list_tagged[x].number === number) {
|
|
|
|
r = this.list_tagged[x];
|
2022-12-15 12:28:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-12-15 12:28:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
if (! r || r.tags === undefined)
|
|
|
|
return null;
|
2022-12-15 12:28:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
return '1'+this.zone_id+this.area_id+r.tags;
|
|
|
|
}
|
2022-12-15 12:28:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
// @todo review
|
|
|
|
MsgArea.prototype.getUserStats = function() {
|
|
|
|
return this.msgbase.cfg ? msg_area.grp_list[this.msgbase.cfg.grp_number].sub_list[msg_area.sub[this.msgbase.cfg.code].index] : [];
|
|
|
|
}
|
|
|
|
|
|
|
|
// @todo review
|
|
|
|
MsgArea.prototype.MessageNext = function(page) {
|
|
|
|
var x = null;
|
|
|
|
|
|
|
|
if (! page)
|
|
|
|
return undefined;
|
|
|
|
|
|
|
|
var msgid = page.substr(7,4);
|
|
|
|
|
|
|
|
for(var x in this.list_tagged) {
|
|
|
|
if (this.list_tagged[x].tags === msgid) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
write(); // @todo This is needed for this to work?
|
2022-12-15 12:28:25 +00:00
|
|
|
}
|
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
//log(LOG_DEBUG,'- Next Message is:'+JSON.stringify(this.list_tagged[(parseInt(x)+1)])+', msgid:'+msgid+', page:'+page+', x:'+x);
|
|
|
|
|
|
|
|
/*
|
|
|
|
= Our next message is either
|
|
|
|
+ x+1 if x < this.list_tagged.length
|
|
|
|
+ x=0 if x == this.list_tagged.length (-1)
|
|
|
|
+ null if this.list_tagged.length == null; (thus no messages)
|
|
|
|
*/
|
|
|
|
|
|
|
|
return x === null ? null : this.list_tagged[(parseInt(x) === this.list_tagged.length-1) ? 0 : (parseInt(x)+1)];
|
2022-12-15 12:28:25 +00:00
|
|
|
}
|
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
// @todo review
|
|
|
|
MsgArea.prototype.MessagePrev = function(page) {
|
|
|
|
var prev = null;
|
|
|
|
var x = null;
|
2022-12-15 12:28:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
if (! page)
|
|
|
|
return undefined;
|
2022-12-15 12:28:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
var msgid = page.substr(7,4);
|
|
|
|
|
|
|
|
for(var x in this.list_tagged) {
|
|
|
|
if (this.list_tagged[x].tags === msgid) {
|
|
|
|
break;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
prev = x;
|
|
|
|
}
|
2022-04-18 11:27:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
write(); // @todo This is needed for this to work?
|
|
|
|
}
|
2022-12-15 12:28:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
/*
|
|
|
|
= Our previous message is either
|
|
|
|
+ prev if a tag was found, unless
|
|
|
|
+ prev is null, in which case it is this.list_tagged.length -1
|
|
|
|
+ null if x is still null (thus no messages)
|
|
|
|
*/
|
2022-04-18 11:27:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
// If prev is still null, then our last message must be the last one, unless x is null then there are no messages
|
|
|
|
return x === null ? null : this.list_tagged[(prev === null) ? this.list_tagged.length-1 : parseInt(prev)];
|
2022-04-18 11:27:25 +00:00
|
|
|
}
|
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
/**
|
|
|
|
* Tag messages with a frame number
|
|
|
|
* @note: May need to run jsexec with -m 32MB to overcome memory issues
|
|
|
|
*
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
MsgArea.prototype.tag_msgs = function() {
|
|
|
|
var msgs = this.untagged;
|
|
|
|
var msgbase = new MsgAreas().getArea(FRAMES_MSG_BASE).msgbase;
|
|
|
|
var page_next = this.page_next;
|
2022-04-22 12:42:20 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
writeln('* We have '+msgs.length+' messages to tag, starting at '+page_next);
|
2022-04-22 12:42:20 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
// See if we need to tag something
|
|
|
|
if (! msgs.length)
|
|
|
|
return;
|
2022-04-18 11:27:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
if (! msgbase.open()) {
|
|
|
|
writeln(code+' cannot be opened (tag_msgs):'+msgbase.error);
|
|
|
|
return false;
|
2022-04-18 11:27:25 +00:00
|
|
|
}
|
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
writeln('Starting at:'+page_next+' (max:'+this.max_page+')');
|
2022-04-20 11:19:01 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
for (var x in msgs) {
|
|
|
|
//writeln('- '+msgs[x].when_imported_time+', #:'+msgs[x].number);
|
2022-04-18 11:27:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
var frame = '1'+this.page_prefix+page_next;
|
2022-12-15 12:28:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
var hdr = {
|
|
|
|
to: frame+'a',
|
|
|
|
from: 'SYSTEM',
|
|
|
|
tags: frame,
|
|
|
|
date: msgs[x].date,
|
|
|
|
subject: this.code+':'+msgs[x].id,
|
|
|
|
};
|
2022-04-20 11:19:01 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
var page = {
|
|
|
|
id: msgs[x].number,
|
|
|
|
area_id: this.area_id,
|
|
|
|
group_id: this.group_id,
|
|
|
|
date: msgs[x].date,
|
|
|
|
msgid: msgs[x].id,
|
|
|
|
imported: msgs[x].when_imported_time,
|
|
|
|
};
|
2022-04-18 11:27:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
var body = LZString.compressToBase64(JSON.stringify(page));
|
2022-05-01 07:42:19 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
writeln('Tagging:'+page.id+' Tag:'+page_next+' MSGID:'+page.msgid);
|
2022-05-01 07:42:19 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
if (! msgbase.save_msg(hdr,body)) {
|
|
|
|
writeln('! ERROR: Failed to tag '+msgs[x].number);
|
|
|
|
exit(1);
|
|
|
|
}
|
2022-05-01 07:42:19 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
page_next++;
|
|
|
|
if (page_next > this.max_page)
|
|
|
|
page_next = 0;
|
2022-04-18 11:27:25 +00:00
|
|
|
|
2024-12-03 04:54:17 +00:00
|
|
|
page_next = (''+page_next).padStart(4,'0');
|
|
|
|
}
|
|
|
|
|
|
|
|
msgbase.close();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @todo review
|
|
|
|
MsgArea.prototype.page = function(msgid) {
|
|
|
|
return '1'+this.page_prefix+msgid;
|
|
|
|
}
|
2022-04-18 11:27:25 +00:00
|
|
|
}
|