Yugo.Filter (Yugo v1.0.1)

View Source

A construct that enables you to specify which emails you would like a Client to notify you about.

Example

To create a filter that only accepts emails that have been read and not replied to, and whose subject contains "Order Information":

alias Yugo.Filter

my_filter =
  Filter.all()
  |> Filter.has_flag(:seen)
  |> Filter.lacks_flag(:answered)
  |> Filter.subject_matches(~r/Order Information/)

Summary

Functions

Returns a Filter that accepts all emails.

Only accepts emails that have the specified flag.

Only accepts emails that do not have the specified flag. See has_flag/2 for more information about flags.

Accepts emails where the email address of the sender matches the given Regex.

Accepts emails whose "subject" line matches the given Regex.

Types

t()

@type t() :: %Yugo.Filter{
  has_flags: [Yugo.flag()],
  lacks_flags: [Yugo.flag()],
  sender_regex: nil | Regex.t(),
  subject_regex: nil | Regex.t()
}

Functions

all()

@spec all() :: t()

Returns a Filter that accepts all emails.

has_flag(filter, flag)

@spec has_flag(t(), Yugo.flag()) :: t()

Only accepts emails that have the specified flag.

"Flags" are tags that are associated with an email message.

Flags

IMAP defines several flags that can be set by clients. Possible flags are:

  • :seen - Message has been read.

  • :answered - Message has been answered.

  • :flagged - Message is "flagged" for urgent/special attention.

  • :draft - Message has not completed composition (marked as a draft).

  • :deleted - Message is "deleted". In most email clients, this means it was moved to the trash folder.

Example

alias Filter

# build a filter that only allows messages that have been seen.
Filter.all()
|> Filter.has_flag(:seen)

lacks_flag(filter, flag)

@spec lacks_flag(t(), Yugo.flag()) :: t()

Only accepts emails that do not have the specified flag. See has_flag/2 for more information about flags.

Example

alias Filter

# build a filter that allows all messages that do not have the :deleted flag
Filter.all()
|> Filter.lacks_flag(:deleted)

sender_matches(filter, pattern)

@spec sender_matches(t(), Regex.t()) :: t()

Accepts emails where the email address of the sender matches the given Regex.

Example

alias Yugo.Filter

# make a filter that only accepts emails sent from "peter@example.com" or "alex@example.com"
Filter.all()
|> Filter.sender_matches(~r/^(peter|alex)@example.com$/i)

subject_matches(filter, pattern)

@spec subject_matches(t(), Regex.t()) :: t()

Accepts emails whose "subject" line matches the given Regex.