Class: Vmail::ReplyTemplate
- Inherits:
-
Object
- Object
- Vmail::ReplyTemplate
- Defined in:
- lib/vmail/reply_template.rb
Instance Method Summary collapse
-
#address_to_string(x) ⇒ Object
deprecated.
- #cc ⇒ Object
-
#initialize(mail, username, name, replyall) ⇒ ReplyTemplate
constructor
A new instance of ReplyTemplate.
- #primary_recipient ⇒ Object
- #reply_headers ⇒ Object
- #sender ⇒ Object
Constructor Details
#initialize(mail, username, name, replyall) ⇒ ReplyTemplate
Returns a new instance of ReplyTemplate.
8 9 10 11 |
# File 'lib/vmail/reply_template.rb', line 8 def initialize(mail, username, name, replyall) @username, @name, @replyall = username, name, replyall @mail = Mail.new(mail) end |
Instance Method Details
#address_to_string(x) ⇒ Object
deprecated
49 50 51 |
# File 'lib/vmail/reply_template.rb', line 49 def address_to_string(x) x.name ? "#{x.name} <#{x.mailbox}@#{x.host}>" : "#{x.mailbox}@#{x.host}" end |
#cc ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vmail/reply_template.rb', line 32 def cc return nil unless @replyall cc = @mail.header['to'].value.split(/,\s*/) if @mail.header['cc'] cc += @mail.header['cc'].value.split(/,\s*/) end cc = cc.flatten.compact. select {|x| x.to_s[/<([^>]+)>/, 1] !~ /#{@username}/ && x.to_s[/^[^<]+/, 1] !~ /#{@name}/ }.join(', ') end |
#primary_recipient ⇒ Object
26 27 28 29 30 |
# File 'lib/vmail/reply_template.rb', line 26 def primary_recipient from = @mail.header['from'] reply_to = @mail.header['reply-to'] [ reply_to, from ].flatten.compact.map(&:to_s)[0] end |
#reply_headers ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/vmail/reply_template.rb', line 13 def reply_headers formatter = Vmail::MessageFormatter.new(@mail) headers = formatter.extract_headers subject = headers['subject'] if subject !~ /Re: / subject = "Re: #{subject}" end date = headers['date'].is_a?(String) ? Time.parse(headers['date']) : headers['date'] quote_header = "On #{date.strftime('%a, %b %d, %Y at %I:%M %p')}, #{sender} wrote:\n\n" body = quote_header + formatter.process_body.gsub(/^(?=>)/, ">").gsub(/^(?!>)/, "> ") {'from' => "#@name <#@username>", 'to' => primary_recipient, 'cc' => cc, 'subject' => subject, :body => body} end |
#sender ⇒ Object
44 45 46 |
# File 'lib/vmail/reply_template.rb', line 44 def sender @mail.header['from'].value end |