Class: SimpleMailBuilder::Message
- Inherits:
-
Object
- Object
- SimpleMailBuilder::Message
- Defined in:
- lib/simple_mail_builder.rb
Instance Method Summary collapse
-
#initialize(from:, to:, subject:, text:, html:, reply_to: nil, boundary: '--MESSAGE BOUNDARY--', date: Time.now, domain: 'local.mail') ⇒ Message
constructor
A new instance of Message.
- #to_s ⇒ Object
Constructor Details
#initialize(from:, to:, subject:, text:, html:, reply_to: nil, boundary: '--MESSAGE BOUNDARY--', date: Time.now, domain: 'local.mail') ⇒ Message
Returns a new instance of Message.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/simple_mail_builder.rb', line 11 def initialize(from:, to:, subject:, text:, html:, reply_to: nil, boundary: '--MESSAGE BOUNDARY--', date: Time.now, domain: 'local.mail') from, to, reply_to = [from, to, reply_to].map do |address| next address if address.nil? || String === address # otherwise we assume it's a Hash address.map do |name, email| name == email ? email : "#{Encoder::Base64.encode_or_quote(name)} <#{email}>" end.map do |addr| addr.gsub "\r\n", '' # basic protection against SMTP commands injection end.join ", \r\n " end text, html = [text, html].map{|s| [s].pack('M').chomp("=\n").gsub "\n", "\r\n"} = [] fdate = date.strftime '%a, %d %b %Y %H:%M:%S %z' << "Date: #{fdate}" << "From: #{from}" << "To: #{to}" << "Reply-to: #{reply_to}" if reply_to = Digest::MD5.hexdigest [fdate, to, text, html].join << "Message-ID: <#{message_id}@#{domain}>" << "Subject: #{Encoder::Quote.encode_if_required subject}" << 'Mime-Version: 1.0' << 'Content-Type: multipart/alternative;' << %Q{ boundary="#{boundary}";} << ' charset=UTF-8' << 'Content-Transfer-Encoding: 7bit' << '' << '' << "--#{boundary}" << 'Content-Type: text/plain; charset=UTF-8; format=flowed' << 'Content-Transfer-Encoding: quoted-printable' << '' << text << '' << "--#{boundary}" << 'Content-Type: text/html; charset=UTF-8' << 'Content-Transfer-Encoding: quoted-printable' << '' << html << '' << "--#{boundary}--" = .join "\r\n" end |
Instance Method Details
#to_s ⇒ Object
53 54 55 |
# File 'lib/simple_mail_builder.rb', line 53 def to_s end |