Class: Rockdove::EmailParser

Inherits:
Object
  • Object
show all
Defined in:
lib/rockdove/email_parser.rb

Constant Summary collapse

HTML_REGEXP =
/<\/?[^>]*>/
FWD_REGEXP =
/^(On(.+)wrote:.+\z)$/inm
SIGNATURE_REGEXP =
/^(Thanks(.+)Regards.+\z)$/inm
REPLY_REGEXP =
/^(From:(.+)Sent:.+\z)$/inm
DASHES =
"________________________________________"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse_mail(mail, body_type) ⇒ Object



9
10
11
# File 'lib/rockdove/email_parser.rb', line 9

def self.parse_mail(mail, body_type)
  new().parse_email_tags(mail,body_type)
end

Instance Method Details

#choose_and_parse(content) ⇒ Object



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

def choose_and_parse(content)
  content.gsub!(DASHES,"")      
  case content       
  when SIGNATURE_REGEXP 
    content.gsub(SIGNATURE_REGEXP,"").strip! 
  when REPLY_REGEXP
    content.gsub(REPLY_REGEXP,"").strip!
  when FWD_REGEXP
    content.gsub(FWD_REGEXP,"").strip!
  else
    content
  end      
end

#parse_email_tags(mail, body_type) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/rockdove/email_parser.rb', line 13

def parse_email_tags(mail,body_type)
  Rockdove.logger.info "Rockdove is parsing the mail content now..."
  return nil unless mail
  mail.gsub!(HTML_REGEXP, "")  
  mail.strip!          
  parsed_content = EmailReplyParser.parse_reply(mail)
  choose_and_parse(parsed_content)      
end