Linter errors fixed
This commit is contained in:
parent
2faebbf111
commit
20aadc1082
1 changed files with 20 additions and 22 deletions
|
|
@ -1,17 +1,16 @@
|
||||||
import { BehaviorSubject } from "rxjs";
|
import { BehaviorSubject } from 'rxjs';
|
||||||
import * as ImapSimple from "imap-simple";
|
import * as ImapSimple from 'imap-simple';
|
||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from '@nestjs/common';
|
||||||
import { MailListenerParams } from "./maillistener-params";
|
import { MailListenerParams } from './maillistener-params';
|
||||||
import { CreateSubjectsParserByRegExp } from "../subjects-parser/subjects-parser";
|
import { CreateSubjectsParserByRegExp } from '../subjects-parser/subjects-parser';
|
||||||
import { EventsListener } from "../events/events-listener";
|
import { EventsListener } from '../events/events-listener';
|
||||||
import {Message} from "imap-simple";
|
import { Message } from 'imap-simple';
|
||||||
|
|
||||||
const UPDATE_INTERVAL_AFTER_ERROR = 5 * 60 * 1000;
|
const UPDATE_INTERVAL_AFTER_ERROR = 5 * 60 * 1000;
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MailListener implements EventsListener {
|
export class MailListener implements EventsListener {
|
||||||
|
issues = new BehaviorSubject<number[]>([]);
|
||||||
issues = new BehaviorSubject<number[]>([])
|
|
||||||
|
|
||||||
private updateTimeout;
|
private updateTimeout;
|
||||||
|
|
||||||
|
|
@ -42,20 +41,18 @@ export class MailListener implements EventsListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchCriteria = [
|
const searchCriteria = ['UNSEEN'];
|
||||||
'UNSEEN'
|
|
||||||
];
|
|
||||||
const fetchOptions = {
|
const fetchOptions = {
|
||||||
bodies: ['HEADER', 'TEXT'],
|
bodies: ['HEADER', 'TEXT'],
|
||||||
markSeen: true
|
markSeen: true,
|
||||||
};
|
};
|
||||||
// const boxes = await connection.getBoxes();
|
// const boxes = await connection.getBoxes();
|
||||||
|
|
||||||
let messages: Message[];
|
let messages: Message[];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await connection.openBox(this.config.boxName)
|
await connection.openBox(this.config.boxName);
|
||||||
messages = await connection.search(searchCriteria, fetchOptions)
|
messages = await connection.search(searchCriteria, fetchOptions);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error('Mail listener error on openBox and search:', ex);
|
console.error('Mail listener error on openBox and search:', ex);
|
||||||
this.closeConnection();
|
this.closeConnection();
|
||||||
|
|
@ -63,14 +60,14 @@ export class MailListener implements EventsListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const subjects: string[] = messages.map(message => {
|
const subjects: string[] = messages.map((message) => {
|
||||||
return message.parts.filter(function (part) {
|
return message.parts.filter(function (part) {
|
||||||
return part.which === 'HEADER';
|
return part.which === 'HEADER';
|
||||||
})[0].body.subject[0]
|
})[0].body.subject[0];
|
||||||
});
|
});
|
||||||
const regexp = new RegExp(this.config.issueNumberParser);
|
const regexp = new RegExp(this.config.issueNumberParser);
|
||||||
const subjectParser = CreateSubjectsParserByRegExp(regexp);
|
const subjectParser = CreateSubjectsParserByRegExp(regexp);
|
||||||
const numbers: number[] = subjects.map(subject => {
|
const numbers: number[] = subjects.map((subject) => {
|
||||||
return subjectParser.getIssueNumber(subject);
|
return subjectParser.getIssueNumber(subject);
|
||||||
});
|
});
|
||||||
this.issues.next(numbers);
|
this.issues.next(numbers);
|
||||||
|
|
@ -81,14 +78,16 @@ export class MailListener implements EventsListener {
|
||||||
private connection: ImapSimple.ImapSimple;
|
private connection: ImapSimple.ImapSimple;
|
||||||
async getConnection(): Promise<ImapSimple.ImapSimple> {
|
async getConnection(): Promise<ImapSimple.ImapSimple> {
|
||||||
if (!this.connection) {
|
if (!this.connection) {
|
||||||
this.connection = await ImapSimple.connect(this.config.imapSimpleConfig as any);
|
this.connection = await ImapSimple.connect(
|
||||||
|
this.config.imapSimpleConfig as any,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return this.connection;
|
return this.connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
private repeatUpdate(interval: number): void {
|
private repeatUpdate(interval: number): void {
|
||||||
this.updateTimeout = setTimeout(() => {
|
this.updateTimeout = setTimeout(() => {
|
||||||
this.updateMessages().catch(reason => {
|
this.updateMessages().catch((reason) => {
|
||||||
console.error('Mail listener unknown error:', reason);
|
console.error('Mail listener unknown error:', reason);
|
||||||
});
|
});
|
||||||
}, interval);
|
}, interval);
|
||||||
|
|
@ -105,5 +104,4 @@ export class MailListener implements EventsListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: 2021-05-08 Добавить функцию получения списка папок на сервере
|
// TODO: 2021-05-08 Добавить функцию получения списка папок на сервере
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue