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(try_again = true) ⇒ Object
- #sender ⇒ Object
Constructor Details
#initialize(mail, username, name, replyall) ⇒ ReplyTemplate
Returns a new instance of ReplyTemplate.
7 8 9 10 |
# File 'lib/vmail/reply_template.rb', line 7 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
25 26 27 28 29 30 |
# File 'lib/vmail/reply_template.rb', line 25 def primary_recipient reply_headers unless @orig_headers from = @orig_headers['from'] reply_to = @orig_headers['reply-to'] [ reply_to, from ].flatten.compact.map(&:to_s)[0] end |
#reply_headers(try_again = true) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/vmail/reply_template.rb', line 12 def reply_headers(try_again = true) formatter = Vmail::MessageFormatter.new(@mail) @orig_headers = formatter.extract_headers subject = @orig_headers['subject'] if subject !~ /Re: / subject = "Re: #{subject}" end date = @orig_headers['date'].is_a?(String) ? Time.parse(@orig_headers['date']) : @orig_headers['date'] quote_header = date ? "On #{date.strftime('%a, %b %d, %Y at %I:%M %p')}, #{sender} wrote:\n\n" : "#{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 |