@@ -61,17 +61,31 @@ export class ImapService {
6161 ) : Promise < void > {
6262 const { from, subject, text, html, textAsHtml } = parsed ;
6363
64+ console . log ( "isReply" , isReply ) ;
65+
6466 if ( isReply ) {
65- const ticketIdMatch = subject . match ( / # ( \d + ) / ) ;
66- if ( ! ticketIdMatch ) {
67+ // First try to match UUID format
68+ const uuidMatch = subject . match (
69+ / (?: r e f : | # ) ( [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 12 } ) / i
70+ ) ;
71+ console . log ( "UUID MATCH" , uuidMatch ) ;
72+
73+ const ticketId = uuidMatch ?. [ 1 ] ;
74+
75+ console . log ( "TICKET ID" , ticketId ) ;
76+
77+ if ( ! ticketId ) {
6778 throw new Error ( `Could not extract ticket ID from subject: ${ subject } ` ) ;
6879 }
6980
70- const ticketId = ticketIdMatch [ 1 ] ;
7181 const ticket = await prisma . ticket . findFirst ( {
72- where : { Number : Number ( ticketId ) } ,
82+ where : {
83+ id : ticketId ,
84+ } ,
7385 } ) ;
7486
87+ console . log ( "TICKET" , ticket ) ;
88+
7589 if ( ! ticket ) {
7690 throw new Error ( `Ticket not found: ${ ticketId } ` ) ;
7791 }
@@ -152,7 +166,10 @@ export class ImapService {
152166 msg . on ( "body" , ( stream ) => {
153167 simpleParser ( stream , async ( err , parsed ) => {
154168 if ( err ) throw err ;
155- const isReply = parsed . subject ?. includes ( "Re:" ) ;
169+ const subjectLower = parsed . subject ?. toLowerCase ( ) || "" ;
170+ const isReply =
171+ subjectLower . includes ( "re:" ) ||
172+ subjectLower . includes ( "ref:" ) ;
156173 await this . processEmail ( parsed , isReply || false ) ;
157174 } ) ;
158175 } ) ;
0 commit comments