Revert "feat: auto-move imported emails to IMAP folder and add 90-day cleanup"
This reverts commit b1b30fe1dd.
This commit is contained in:
@@ -12,7 +12,6 @@ import { Task } from '../database/entities/task.entity';
|
||||
import { PaperlessService } from '../paperless/paperless.service';
|
||||
import * as QRCode from 'qrcode';
|
||||
import { EmailPageCacheService } from './email-page-cache.service';
|
||||
import { ImapFolderService } from './imap-folder.service';
|
||||
import { PdfService } from '../preprocessing/pdf.service';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
@@ -54,7 +53,6 @@ export class EmailImportService {
|
||||
private readonly paperlessService: PaperlessService,
|
||||
private readonly pdfService: PdfService,
|
||||
private readonly pageCache: EmailPageCacheService,
|
||||
private readonly imapFolderService: ImapFolderService,
|
||||
) {}
|
||||
|
||||
async ensurePreviews(emailId: number): Promise<void> {
|
||||
@@ -655,12 +653,6 @@ export class EmailImportService {
|
||||
this.logger.log(
|
||||
`Email ${firstAtt.EmailMessageId} als verarbeitet markiert.`,
|
||||
);
|
||||
const emailEntity = await this.emailRepo.findOne({ where: { Id: firstAtt.EmailMessageId } });
|
||||
if (emailEntity) {
|
||||
this.imapFolderService.moveToImportiert(emailEntity.MessageId).catch(err =>
|
||||
this.logger.error('IMAP-Verschieben fehlgeschlagen: ' + err.message),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import { EmailPageCacheService } from './email-page-cache.service';
|
||||
|
||||
import { EmailImportController } from './email-import.controller';
|
||||
import { EmailImportService } from './email-import.service';
|
||||
import { ImapFolderService } from './imap-folder.service';
|
||||
import { CorrespondentEmailMapping } from '../database/entities/correspondent-email-mapping.entity';
|
||||
import { Task } from '../database/entities/task.entity';
|
||||
import { PreprocessingModule } from '../preprocessing/preprocessing.module';
|
||||
@@ -27,7 +26,7 @@ import { PreprocessingModule } from '../preprocessing/preprocessing.module';
|
||||
PreprocessingModule,
|
||||
],
|
||||
controllers: [EmailController, EmailImportController],
|
||||
providers: [EmailImportService, EmailPageCacheService, ImapFolderService],
|
||||
providers: [EmailImportService, EmailPageCacheService],
|
||||
exports: [EmailPageCacheService],
|
||||
})
|
||||
export class EmailModule {}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { ImapFlow } from 'imapflow';
|
||||
|
||||
@Injectable()
|
||||
export class ImapFolderService {
|
||||
private readonly logger = new Logger(ImapFolderService.name);
|
||||
|
||||
constructor(private readonly configService: ConfigService) {}
|
||||
|
||||
private createClient(): ImapFlow {
|
||||
return new ImapFlow({
|
||||
host: this.configService.get<string>('IMAP_HOST', ''),
|
||||
port: this.configService.get<number>('IMAP_PORT', 993),
|
||||
secure: this.configService.get<string>('IMAP_USE_SSL', 'true') === 'true',
|
||||
auth: {
|
||||
user: this.configService.get<string>('IMAP_USERNAME', ''),
|
||||
pass: this.configService.get<string>('IMAP_PASSWORD', ''),
|
||||
},
|
||||
logger: false,
|
||||
});
|
||||
}
|
||||
|
||||
async moveToImportiert(messageId: string): Promise<void> {
|
||||
if (!this.configService.get<string>('IMAP_HOST')) return;
|
||||
|
||||
const importedFolder = this.configService.get<string>('IMAP_IMPORTED_FOLDER', 'importiert');
|
||||
const client = this.createClient();
|
||||
try {
|
||||
await client.connect();
|
||||
|
||||
const mailboxes = await client.list();
|
||||
if (!mailboxes.some(m => m.path === importedFolder)) {
|
||||
await client.mailboxCreate(importedFolder);
|
||||
this.logger.log(`IMAP-Ordner "${importedFolder}" erstellt.`);
|
||||
}
|
||||
|
||||
await client.mailboxOpen('INBOX');
|
||||
const uids = await client.search({ header: { 'message-id': messageId } }, { uid: true });
|
||||
if (Array.isArray(uids) && uids.length > 0) {
|
||||
await client.messageMove(uids, importedFolder, { uid: true });
|
||||
this.logger.log(`E-Mail ${messageId} → "${importedFolder}" verschoben.`);
|
||||
} else {
|
||||
this.logger.warn(`E-Mail ${messageId} nicht in INBOX gefunden (bereits verschoben?).`);
|
||||
}
|
||||
} catch (err: any) {
|
||||
this.logger.error(`IMAP moveToImportiert fehlgeschlagen: ${err.message}`);
|
||||
} finally {
|
||||
await client.logout().catch(() => {});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user