(mail, filters = {})
| 350 | } |
| 351 | |
| 352 | function mailMatchesLuckmailFilters(mail, filters = {}) { |
| 353 | const normalizedMail = normalizeLuckmailTokenMail(mail); |
| 354 | const afterTimestamp = normalizeTimestamp(filters.afterTimestamp); |
| 355 | const receivedAt = normalizeTimestamp(normalizedMail.received_at); |
| 356 | if (afterTimestamp && receivedAt && receivedAt < afterTimestamp) { |
| 357 | return null; |
| 358 | } |
| 359 | |
| 360 | const senderFilters = (filters.senderFilters || []).map(normalizeText).filter(Boolean); |
| 361 | const subjectFilters = (filters.subjectFilters || []).map(normalizeText).filter(Boolean); |
| 362 | const excludedCodes = new Set((filters.excludeCodes || []).filter(Boolean)); |
| 363 | const combinedText = [ |
| 364 | normalizedMail.subject, |
| 365 | normalizedMail.from, |
| 366 | normalizedMail.body, |
| 367 | normalizedMail.html_body, |
| 368 | ].filter(Boolean).join(' '); |
| 369 | const combinedTextNormalized = normalizeText(combinedText); |
| 370 | const senderNormalized = normalizeText(normalizedMail.from); |
| 371 | const subjectNormalized = normalizeText(normalizedMail.subject); |
| 372 | const code = normalizedMail.verification_code || extractLuckmailVerificationCode(combinedText); |
| 373 | |
| 374 | if (!code || excludedCodes.has(code)) { |
| 375 | return null; |
| 376 | } |
| 377 | |
| 378 | const senderMatch = senderFilters.length === 0 |
| 379 | ? true |
| 380 | : senderFilters.some((item) => senderNormalized.includes(item) || combinedTextNormalized.includes(item)); |
| 381 | const subjectMatch = subjectFilters.length === 0 |
| 382 | ? true |
| 383 | : subjectFilters.some((item) => subjectNormalized.includes(item) || combinedTextNormalized.includes(item)); |
| 384 | |
| 385 | if (!senderMatch && !subjectMatch) { |
| 386 | return null; |
| 387 | } |
| 388 | |
| 389 | return { |
| 390 | code, |
| 391 | mail: normalizedMail, |
| 392 | receivedAt, |
| 393 | }; |
| 394 | } |
| 395 | |
| 396 | function pickLuckmailVerificationMail(mails, filters = {}) { |
| 397 | const matches = normalizeLuckmailTokenMails(mails) |
no test coverage detected