mirror of
https://github.com/dadada/inbox2matrix.git
synced 2025-06-07 17:43:57 +02:00
Add initial encryption support. Still missing automatic device verification
This commit is contained in:
parent
1579a8022d
commit
7b07ca9cb1
4 changed files with 49 additions and 17 deletions
9
globals.d.ts
vendored
Normal file
9
globals.d.ts
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
declare global {
|
||||||
|
namespace NodeJS {
|
||||||
|
interface Global {
|
||||||
|
Olm : any;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { };
|
|
@ -1,16 +1,25 @@
|
||||||
import Imap = require('imap');
|
import Imap = require('imap');
|
||||||
import config = require('config');
|
import config = require('config');
|
||||||
import matrix = require("matrix-js-sdk");
|
|
||||||
|
global.Olm = require('olm');
|
||||||
|
import matrix = require('matrix-js-sdk');
|
||||||
|
|
||||||
let accounts = config.get('accounts');
|
let accounts = config.get('accounts');
|
||||||
|
|
||||||
let myUserId = accounts.matrix.user;
|
import Storage = require('dom-storage');
|
||||||
|
|
||||||
|
let myUserId = accounts.matrix.user_id;
|
||||||
let myRoom = accounts.matrix.room;
|
let myRoom = accounts.matrix.room;
|
||||||
|
|
||||||
|
var localStorage = new Storage('./db.json', { strict: false, ws: ' ' });
|
||||||
|
const webStorageSessionStore = new matrix.WebStorageSessionStore(localStorage);
|
||||||
|
|
||||||
let client = matrix.createClient({
|
let client = matrix.createClient({
|
||||||
baseUrl: accounts.matrix.baseUrl,
|
baseUrl: accounts.matrix.well_known.homeserver.base_url,
|
||||||
accessToken: accounts.matrix.accessToken,
|
accessToken: accounts.matrix.access_token,
|
||||||
userId: myUserId
|
userId: myUserId,
|
||||||
|
sessionStore: webStorageSessionStore,
|
||||||
|
deviceId: accounts.matrix.device_id
|
||||||
});
|
});
|
||||||
|
|
||||||
var imap = new Imap(accounts.imap);
|
var imap = new Imap(accounts.imap);
|
||||||
|
@ -19,14 +28,6 @@ function openInbox(cb) {
|
||||||
imap.openBox('INBOX', false, cb);
|
imap.openBox('INBOX', false, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
client.on("RoomMember.membership", function(event, member) {
|
|
||||||
if (member.membership === "invite" && member.userId === myUserId) {
|
|
||||||
client.joinRoom(member.roomId).done(function() {
|
|
||||||
console.log("Auto-joined %s", member.roomId);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
imap.once('ready', function() {
|
imap.once('ready', function() {
|
||||||
openInbox(function(err, box) {
|
openInbox(function(err, box) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
@ -106,10 +107,6 @@ imap.once('end', function() {
|
||||||
console.log('Connection ended');
|
console.log('Connection ended');
|
||||||
});
|
});
|
||||||
|
|
||||||
imap.connect();
|
|
||||||
|
|
||||||
client.startClient({initialSyncLimit: 200});
|
|
||||||
|
|
||||||
client.once('sync', function(state, prevState, res) {
|
client.once('sync', function(state, prevState, res) {
|
||||||
if(state === 'PREPARED') {
|
if(state === 'PREPARED') {
|
||||||
console.log("prepared");
|
console.log("prepared");
|
||||||
|
@ -118,4 +115,16 @@ client.once('sync', function(state, prevState, res) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
async function startBot() {
|
||||||
|
try {
|
||||||
|
await imap.connect();
|
||||||
|
await client.initCrypto();
|
||||||
|
await client.startClient({initialSyncLimit: 200});
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
startBot();
|
||||||
setInterval(processUnseen, 5 * 60 * 1000);
|
setInterval(processUnseen, 5 * 60 * 1000);
|
||||||
|
|
|
@ -4,9 +4,12 @@
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "inbox2matrix.js",
|
"main": "inbox2matrix.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/node": "^11.13.8",
|
||||||
"config": "^3.1.0",
|
"config": "^3.1.0",
|
||||||
|
"dom-storage": "^2.1.0",
|
||||||
"imap": "^0.8.19",
|
"imap": "^0.8.19",
|
||||||
"matrix-js-sdk": "^1.1.0-rc.1",
|
"matrix-js-sdk": "^1.1.0-rc.1",
|
||||||
|
"olm": "https://matrix.org/packages/npm/olm/olm-3.0.0.tgz",
|
||||||
"process": "^0.11.10"
|
"process": "^0.11.10"
|
||||||
},
|
},
|
||||||
"devDependencies": {},
|
"devDependencies": {},
|
||||||
|
|
11
tsconfig.json
Normal file
11
tsconfig.json
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"types" : [
|
||||||
|
"node"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"inbox2matrix.ts",
|
||||||
|
"globals.d.ts"
|
||||||
|
]
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue