Module: Galakei::Email

Defined in:
lib/galakei/email.rb,
lib/galakei/email/version.rb

Constant Summary collapse

GALAKEI_EMAIL_ADDRESS_PATTERNS =
[
/^.+@(.+\.)?pdx\.ne\.jp$/,
/^.+@ezweb\.ne\.jp$/,
/^.+@(?:softbank\.ne\.jp|disney\.ne\.jp)$/,
/^.+@[dhtcrknsq]\.vodafone\.ne\.jp$/,
/^.+@jp-[dhtcrknsq]\.ne\.jp$/,
/^.+@emnet\.ne\.jp$/,
/^.+@docomo\.ne\.jp$/ ]
SANITIZE_OPTIONS =
{
  :elements   => %w{font blink marquee br a div hr img},
  :attributes => {'a' => ['href'],
                  'font' => ['size','color'],
                  'marquee' => ['behaviour'],
                  'hr' => ['color'],
                  'div' => ['align'],
                  'img' => ['src'],
                  },
  :protocols  => {'a' => {'href' => ['http', 'https', 'mailto']}},
  :whitespace_elements => []
}
TAGS_TO_PROCESS =
%w{h1 h2 h3 h4 h5 h6 p}.join(',')
VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.galakei_email_address?(email) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/galakei/email.rb', line 32

def self.galakei_email_address?(email)
  GALAKEI_EMAIL_ADDRESS_PATTERNS.any?{|p| p =~ email }
end

.to_galakei_email(html_email) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/galakei/email.rb', line 36

def self.to_galakei_email(html_email)
  doc = Nokogiri::HTML(html_email)
  doc.css(TAGS_TO_PROCESS).each do |node|
    node.name = "div"
    node.after("<br />")
  end
  #empty the <head>
  doc.css("head").each do |node|
    node.unlink
  end
  doc.css("img").each do |node|
    if node['src'] !~ /^cid:/
      node.after(doc.create_text_node(node['alt'])) if node['alt'].present?
      node.unlink
    end
  end
  encoding = doc.meta_encoding || "UTF-8"
  res = "<html><head>"
  res << "<meta http-equiv=\"Content-type\" content=\"text/html;charset=#{encoding}\" />"
  res << "</head><body>"
  res << Sanitize.clean(doc.to_s, SANITIZE_OPTIONS)
  res << "</body></html>"
end