class Mailpeek::Email
Public: Wrapper class for mail object
Attributes
attachments[R]
date[R]
from[R]
html[R]
id[R]
mail[R]
message_id[R]
position[R]
subject[R]
text[R]
to[R]
Public Class Methods
new(timestamp, mail)
click to toggle source
# 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
Public Instance Methods
destroy()
click to toggle source
# File lib/mailpeek/email.rb, line 29 def destroy FileUtils.rm_rf("#{Mailpeek.configuration.location}/#{id}") end
match?(query)
click to toggle source
# File lib/mailpeek/email.rb, line 25 def match?(query) subject&.match(query) || text&.match(query) || html&.match(query) end
read()
click to toggle source
# File lib/mailpeek/email.rb, line 33 def read File.exist?(read_file_path) end
read=(value)
click to toggle source
# 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
Private Instance Methods
parse_body()
click to toggle source
# File lib/mailpeek/email.rb, line 67 def parse_body body = mail.body.decoded.force_encoding('utf-8') if mail.content_type =~ /html/ @html = body else @text = body end end
parse_parts()
click to toggle source
# File lib/mailpeek/email.rb, line 51 def parse_parts if mail.html_part @html = mail.html_part.body.decoded.force_encoding('utf-8') end if mail.text_part @text = mail.text_part.body.decoded.force_encoding('utf-8') end return unless mail.attachments.any? mail.attachments.each do |attachment| @attachments.push(attachment.filename.gsub(/[^\w\-_.]/, '_')) end end
read_file_path()
click to toggle source
# File lib/mailpeek/email.rb, line 47 def read_file_path File.join(Mailpeek.configuration.location, id, '.read') end