Class: LeanMail::Data

Inherits:
Object
  • Object
show all
Defined in:
contrib/lib/lean_mail.rb

Overview

RFC 2821 message data representation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, to, subject, message) ⇒ Data

Returns a new instance of Data.



37
38
39
40
41
42
# File 'contrib/lib/lean_mail.rb', line 37

def initialize(from, to, subject, message)
  @from = from
  @to = to
  @subject = subject
  @message = message
end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



35
36
37
# File 'contrib/lib/lean_mail.rb', line 35

def from
  @from
end

#messageObject (readonly)

Returns the value of attribute message.



35
36
37
# File 'contrib/lib/lean_mail.rb', line 35

def message
  @message
end

#subjectObject (readonly)

Returns the value of attribute subject.



35
36
37
# File 'contrib/lib/lean_mail.rb', line 35

def subject
  @subject
end

#toObject (readonly)

Returns the value of attribute to.



35
36
37
# File 'contrib/lib/lean_mail.rb', line 35

def to
  @to
end

Instance Method Details

#to_sObject



44
45
46
47
48
49
50
51
52
53
54
55
# File 'contrib/lib/lean_mail.rb', line 44

def to_s
  <<~MAIL
    Content-type: text/plain; charset=UTF-8
    From: #{@from}
    To: #{to.instance_of?(Array) ? to.join(', ') : to}
    Subject: =?UTF-8?B?#{Base64.strict_encode64(subject)}?=
    Date: #{Time.new.rfc2822}
    Message-Id: <#{SecureRandom.uuid}@#{Socket.gethostname}>

    #{@message}
  MAIL
end