Module: Vmail::ReplyTemplating

Included in:
ImapClient
Defined in:
lib/vmail/reply_templating.rb

Instance Method Summary collapse

Instance Method Details

#reply_ccObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/vmail/reply_templating.rb', line 46

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

#reply_headersObject



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
# File 'lib/vmail/reply_templating.rb', line 16

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

#reply_recipientObject



42
43
44
# File 'lib/vmail/reply_templating.rb', line 42

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

#reply_template(replyall = false) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/vmail/reply_templating.rb', line 8

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