Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jorgemanrubia
Last active June 27, 2022 15:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgemanrubia/51aeb56bf4ee63715d63b31bf67ce626 to your computer and use it in GitHub Desktop.
Save jorgemanrubia/51aeb56bf4ee63715d63b31bf67ce626 to your computer and use it in GitHub Desktop.

Domain

The input to the system will be an Analysis::InboundEmail . We create a separated entity in case we want to incorporate more elements in the future.

An Analysis contains a series of Analysis::Rules. When a rule executes, it receives an Analysis::InboundEmail and returns a list of Analysis::Insights.

The result of executing an Analysis is an Analysis::Result that contains a series of Analysis::Insights.

When the analysis is not ok, we store the analysis along with the ActionMailbox::InboundEmail that originated it. This way we can act before even an entry is created.

An AnalysisInsight has a code, a AnalysisInsightDecision . A decision carries a type and a magnitude. The types can be: bounce, spam.

When the aggregated magnitude for a set of rules is > 1 for a given decision, that decision becomes the result of the analysis.

Domain model

There are four basic entities:

  • An analysis Rule returns Insight for a given email.
  • An Insight determines a kind of action (currently :ok, :reject or :spam), a weight and other attributes to trace the analysis decision.
  • An Analysis contains a series of Rules. Performing an analysis will collect all the insight by the rules and return a Result.
  • A Result groups all the insights for a given analysis.

Result will be associated with ActionMailbox::InboundEmail via a polymorphic association. We will only store it if the email is not ok. I thought about adding at the Receipt level instead, but I think for inbound email it makes more sense to do at the inbound email level, so that we can bounce emails using the same system too.

We won't leverage it right away, but the system of weights allows us to add some fuzziness to the analysis decisions. When performing an analysis, it will execute all the rules in sequence unless the set of weights for a given kind is >= 1.0. Right now, all our insights will have a weight of 1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment