Class: Inventory::Server::EmailParser

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

Class Method Summary collapse

Class Method Details

.parse(message) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/inventory/server/email_parser.rb', line 8

def self.parse(message)
  InventoryLogger.logger.info "Email parser"

  # Parse the email
  email = Mail.read_from_string(message)

  # Use email subject as an ID
  email_subject = email.subject
  raise InventoryError.new "email subject is missing" if email_subject.nil? || email_subject.empty?
  id = email_subject

  # Decode the email body
  email_body = email.body.decoded
  raise InventoryError.new "email body is missing" if email_body.nil? || email_body.empty?
  body = email_body

  return id, body
end