Class: Mailpeek::Email

Inherits:
Object
  • Object
show all
Defined in:
lib/mailpeek/email.rb

Overview

Public: Wrapper class for mail object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timestamp, mail) ⇒ Email

Returns a new instance of Email.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mailpeek/email.rb', line 11

def initialize(timestamp, mail)
  @id          = timestamp
  @position    = timestamp
  @mail        = mail
  @to          = mail[:to].addrs.map(&:format)
  @from        = mail[:from].addrs.map(&:format)
  @subject     = mail.subject
  @message_id  = mail.message_id
  @date        = mail.date
  @attachments = []

  mail.multipart? ? parse_parts : parse_body
end

Instance Attribute Details

#attachmentsObject (readonly)

Returns the value of attribute attachments.



6
7
8
# File 'lib/mailpeek/email.rb', line 6

def attachments
  @attachments
end

#dateObject (readonly)

Returns the value of attribute date.



6
7
8
# File 'lib/mailpeek/email.rb', line 6

def date
  @date
end

#fromObject (readonly)

Returns the value of attribute from.



6
7
8
# File 'lib/mailpeek/email.rb', line 6

def from
  @from
end

#htmlObject (readonly)

Returns the value of attribute html.



6
7
8
# File 'lib/mailpeek/email.rb', line 6

def html
  @html
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/mailpeek/email.rb', line 6

def id
  @id
end

#mailObject (readonly)

Returns the value of attribute mail.



6
7
8
# File 'lib/mailpeek/email.rb', line 6

def mail
  @mail
end

#message_idObject (readonly)

Returns the value of attribute message_id.



6
7
8
# File 'lib/mailpeek/email.rb', line 6

def message_id
  @message_id
end

#positionObject (readonly)

Returns the value of attribute position.



6
7
8
# File 'lib/mailpeek/email.rb', line 6

def position
  @position
end

#subjectObject (readonly)

Returns the value of attribute subject.



6
7
8
# File 'lib/mailpeek/email.rb', line 6

def subject
  @subject
end

#textObject (readonly)

Returns the value of attribute text.



6
7
8
# File 'lib/mailpeek/email.rb', line 6

def text
  @text
end

#toObject (readonly)

Returns the value of attribute to.



6
7
8
# File 'lib/mailpeek/email.rb', line 6

def to
  @to
end

Instance Method Details

#destroyObject



29
30
31
# File 'lib/mailpeek/email.rb', line 29

def destroy
  FileUtils.rm_rf("#{Mailpeek.configuration.location}/#{id}")
end

#match?(query) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/mailpeek/email.rb', line 25

def match?(query)
  subject&.match(query) || text&.match(query) || html&.match(query)
end

#readObject



33
34
35
# File 'lib/mailpeek/email.rb', line 33

def read
  File.exist?(read_file_path)
end

#read=(value) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/mailpeek/email.rb', line 37

def read=(value)
  if value && !read
    FileUtils.touch(read_file_path)
  elsif !value && read
    File.delete(read_file_path)
  end
end