### Home Classes Methods

### In Files

- lib/vmail/reply_template.rb

### Parent

Object

### Methods

- ::new
- #address_to_string
- #cc
- #primary_recipient
- #reply_headers
- #sender

### Class/Module Index

Quicksearch

- Vmail
- Vmail::AddressQuoter
- Vmail::ContactsExtractor
- Vmail::ImapClient
- Vmail::MessageFormatter
- Vmail::Options
- Vmail::Query
- Vmail::ReplyTemplate
- Vmail::SendOptions
- Vmail::Sender
- String

No matching classes.

# Vmail::ReplyTemplate

### Public Class Methods

new(mail, username, name, replyall) click to toggle source

    # 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

### Public Instance Methods

address_to_string(x) click to toggle source

deprecated

    # File lib/vmail/reply_template.rb, line 51
    def address_to_string(x)
      x.name ? "#{x.name} <#{x.mailbox}@#{x.host}>" : "#{x.mailbox}@#{x.host}"
    end

cc() click to toggle source

    # File lib/vmail/reply_template.rb, line 34
    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() click to toggle source

    # File lib/vmail/reply_template.rb, line 27
    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) click to toggle source

    # 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
      body.force_encoding("UTF-8")
      body = body.gsub(/^(?=>)/, ">").gsub(/^(?!>)/, "> ")
      {'from' => "#@name <#@username>", 'to' => primary_recipient, 'cc' => cc, 'subject' => subject, :body => body}
    end

sender() click to toggle source

    # File lib/vmail/reply_template.rb, line 46
    def sender
      @mail.header['from'].value
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.