Module: Email

Defined in:
lib/email/styles.rb,
lib/email.rb,
lib/email/poller.rb,
lib/email/sender.rb,
lib/email/cleaner.rb,
lib/email/receiver.rb,
lib/email/renderer.rb,
lib/email/processor.rb,
lib/email/validator.rb,
lib/email/message_builder.rb,
lib/email/build_email_helper.rb,
lib/email/message_id_service.rb,
lib/email/authentication_results.rb

Overview

Builds a Mail::Message we can use for sending. Optionally supports using a template for the body and subject

Defined Under Namespace

Modules: BuildEmailHelper Classes: AuthenticationResults, Cleaner, MessageBuilder, MessageIdService, Poller, Processor, Receiver, Renderer, Sender, Styles, Validator

Constant Summary collapse

SMTP_STATUS_SUCCESS =
"2."
SMTP_STATUS_TRANSIENT_FAILURE =
"4."
SMTP_STATUS_PERMANENT_FAILURE =
"5."

Class Method Summary collapse

Class Method Details

.cleanup_alias(name) ⇒ Object



35
36
37
# File 'lib/email.rb', line 35

def self.cleanup_alias(name)
  name ? name.gsub(/[:<>,"]/, "") : name
end

.downcase(email) ⇒ Object



16
17
18
19
# File 'lib/email.rb', line 16

def self.downcase(email)
  return email unless Email.is_valid?(email)
  email.downcase
end

.extract_parts(raw) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/email.rb', line 39

def self.extract_parts(raw)
  mail = Mail.new(raw)
  text = nil
  html = nil

  if mail.multipart?
    text = mail.text_part
    html = mail.html_part
  elsif mail.content_type.to_s["text/html"]
    html = mail
  else
    text = mail
  end

  [text&.decoded, html&.decoded]
end

.is_valid?(email) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
# File 'lib/email.rb', line 11

def self.is_valid?(email)
  return false unless String === email
  EmailAddressValidator.valid_value?(email)
end

.obfuscate(email) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/email.rb', line 21

def self.obfuscate(email)
  return email if !Email.is_valid?(email)

  first, _, last = email.rpartition("@")

  # Obfuscate each last part, except tld
  last = last.split(".")
  tld = last.pop
  last.map! { |part| obfuscate_part(part) }
  last << tld

  "#{obfuscate_part(first)}@#{last.join(".")}"
end

.site_titleObject



56
57
58
# File 'lib/email.rb', line 56

def self.site_title
  SiteSetting.email_site_title.presence || SiteSetting.title
end