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