Sha256: cf4247f8a6a068fc9f7796268c4eaf93115341f766382fe49b00e38cba16a4ad

Contents?: true

Size: 1.79 KB

Versions: 16

Compression:

Stored size: 1.79 KB

Contents

# encoding: UTF-8
require 'mail'
require 'time'

module Vmail
  module ReplyTemplating

    def reply_template(replyall=false)
      @replyall = replyall
      log "Sending reply template"
      h = reply_headers
      body = h.delete('body')
      format_headers(h) + "\n\n\n" + body + signature
    end

    def reply_headers
      reply_subject = current_message.subject
      if reply_subject !~ /Re: /
        reply_subject = "Re: #{reply_subject}"
      end
      date = DateTime.parse(current_message.date)
      sender = current_message.sender
      reply_quote_header = date ? "On #{date.strftime('%a, %b %d, %Y at %I:%M %p')}, #{sender} wrote:\n\n" : "#{sender} wrote:\n"

      reply_body = reply_quote_header + 
        ( current_message.plaintext.split(/^-+$/,2)[1].strip.gsub(/^(?=>)/, ">").gsub(/^(?!>)/, "> ") )

      {
        'references' => current_message.message_id,
        'from' => "#@name <#@username>", 
        'to' => reply_recipient, 
        'cc' => reply_cc, 
        'bcc' => @always_bcc,
        'subject' => reply_subject, 
        'body' => reply_body
      }
    rescue
      $logger.debug $!
      raise
    end

    def reply_recipient
      current_mail.header['Reply-To'] || current_message.sender
    end

    def reply_cc
      return nil unless (@replyall || @always_cc)
      xs = if @replyall
             ((current_mail['cc'] && current_mail['cc'].decoded) || "") .split(/,\s*/)  + ((current_mail['to'] && current_mail['to'].decoded) || "") .split(/,\s*/)
           else
             []
           end
      xs = xs.select {|x|
        email = (x[/<([^>]+)>/, 1] || x) 
        email !~ /#{reply_recipient}/ && email !~ /#{@always_cc}/ 
      }
      if @always_cc 
        xs << @always_cc
      end
      xs.uniq.select {|x| x != reply_recipient }.join(', ')
    end

  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
vmail-2.3.2 lib/vmail/reply_templating.rb
vmail-2.3.0 lib/vmail/reply_templating.rb
vmail-2.2.9 lib/vmail/reply_templating.rb
vmail-2.2.8 lib/vmail/reply_templating.rb
vmail-2.2.6 lib/vmail/reply_templating.rb
vmail-2.2.5 lib/vmail/reply_templating.rb
vmail-2.2.4 lib/vmail/reply_templating.rb
vmail-2.2.3 lib/vmail/reply_templating.rb
vmail-2.2.2 lib/vmail/reply_templating.rb
vmail-2.2.1 lib/vmail/reply_templating.rb
vmail-2.2.0 lib/vmail/reply_templating.rb
vmail-2.1.9 lib/vmail/reply_templating.rb
vmail-2.1.8 lib/vmail/reply_templating.rb
vmail-2.1.7 lib/vmail/reply_templating.rb
vmail-2.1.6 lib/vmail/reply_templating.rb
vmail-2.1.5 lib/vmail/reply_templating.rb