MCPcopy Create free account
hub / github.com/buggregator/server / matchesFilter

Function matchesFilter

modules/smtp/api.go:366–407  ·  view source on GitHub ↗

matchesFilter returns true if ev satisfies all criteria in f.

(ev event.Event, f MessageFilter)

Source from the content-addressed store, hash-verified

364
365// matchesFilter returns true if ev satisfies all criteria in f.
366func matchesFilter(ev event.Event, f MessageFilter) bool {
367 if f.Since > 0 && ev.Timestamp < f.Since {
368 return false
369 }
370 if f.Until > 0 && ev.Timestamp > f.Until {
371 return false
372 }
373
374 var email ParsedEmail
375 if err := json.Unmarshal(ev.Payload, &email); err != nil {
376 return false
377 }
378
379 if f.To != "" && !matchAddresses(email.To, f.To) {
380 return false
381 }
382 if f.From != "" && !matchAddresses(email.From, f.From) {
383 return false
384 }
385 if f.Cc != "" && !matchAddresses(email.Cc, f.Cc) {
386 return false
387 }
388 if f.Subject != "" && email.Subject != f.Subject {
389 return false
390 }
391 if f.SubjectContains != "" && !strings.Contains(email.Subject, f.SubjectContains) {
392 return false
393 }
394 if f.SubjectRegex != "" {
395 re, err := regexp.Compile(f.SubjectRegex)
396 if err != nil || !re.MatchString(email.Subject) {
397 return false
398 }
399 }
400 if f.BodyContains != "" &&
401 !strings.Contains(email.Text, f.BodyContains) &&
402 !strings.Contains(email.HTML, f.BodyContains) {
403 return false
404 }
405
406 return true
407}
408
409func matchAddresses(addrs []EmailAddress, query string) bool {
410 lq := strings.ToLower(query)

Callers 3

applyFilterFunction · 0.85
TestMatchesFilterFunction · 0.85
OnEventStoredMethod · 0.85

Calls 1

matchAddressesFunction · 0.85

Tested by 1

TestMatchesFilterFunction · 0.68