You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
/**
* 将库内已拉入的非预报/装箱相关邮件标为 IGNORED( 列表默认隐藏) <E8978F> ?
* Usage: pnpm exec tsx scripts/mark-non-business-ignored.ts
*/
import { PrismaClient } from "@prisma/client" ;
import { isBusinessRelevantMail } from "../src/services/parse/classify" ;
import { NON_BUSINESS_SKIP } from "../src/services/imap/poller" ;
const prisma = new PrismaClient ( ) ;
async function main() {
const mails = await prisma . mailMessage . findMany ( {
where : { status : { not : "IGNORED" } } ,
include : { attachments : { select : { filename : true } } } ,
} ) ;
let marked = 0 ;
for ( const m of mails ) {
const relevant = isBusinessRelevantMail ( {
subject : m.subject ,
body : m.bodyText || "" ,
filenames : m.attachments.map ( ( a ) = > a . filename ) ,
} ) ;
if ( relevant ) continue ;
await prisma . mailMessage . update ( {
where : { id : m.id } ,
data : {
status : "IGNORED" ,
lastError : NON_BUSINESS_SKIP ,
version : { increment : 1 } ,
} ,
} ) ;
marked += 1 ;
console . log (
` IGNORED id= ${ m . id } from= ${ m . fromAddr } subject= ${ m . subject . slice ( 0 , 80 ) } ` ,
) ;
}
console . log ( ` done: scanned= ${ mails . length } marked= ${ marked } ` ) ;
}
main ( )
. catch ( ( e ) = > {
console . error ( e ) ;
process . exitCode = 1 ;
} )
. finally ( ( ) = > prisma . $disconnect ( ) ) ;