Module: EmailParser

Defined in:
lib/html-griddler/email_parser.rb

Overview

Parse emails from their full format into a hash containing full email, host, local token, and the raw argument.

Some Body <[email protected]> # =>

token: 'somebody',
host: 'example.com',
email: '[email protected]',
full: 'Some Body <[email protected]>',

Class Method Summary collapse

Class Method Details

.extract_reply_body(body) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/html-griddler/email_parser.rb', line 23

def self.extract_reply_body(body)
  if body
    delimeter = Griddler.configuration.reply_delimiter
    body.split(delimeter).first.
      split(/^\s*[-]+\s*Original Message\s*[-]+\s*$/).first.
      split(/^\s*--\s*$/).first.
      gsub(/On.*wrote:/, '').
      split(/[\r]*\n/).reject do |line|
        line =~ /^\s*>/ ||
          line =~ /^\s*Sent from my /
      end.
      join("\n").
      gsub(/^\s*On.*\r?\n?\s*.*\s*wrote:$/,'').
      strip
  end
end

.parse_address(full_address) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/html-griddler/email_parser.rb', line 12

def self.parse_address(full_address)
  email_address = extract_email_address(full_address)
  token, host = split_address(email_address)
  {
    token: token,
    host: host,
    email: email_address,
    full: full_address,
  }
end