vmail 1.8.7 → 1.8.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/vmail.rb +0 -1
- data/lib/vmail/imap_client.rb +17 -11
- data/lib/vmail/message_formatter.rb +4 -0
- data/lib/vmail/reply_templating.rb +59 -0
- data/lib/vmail/showing_headers.rb +1 -0
- data/lib/vmail/version.rb +1 -1
- metadata +8 -21
- data/lib/vmail/reply_template.rb +0 -59
data/lib/vmail.rb
CHANGED
data/lib/vmail/imap_client.rb
CHANGED
@@ -13,6 +13,7 @@ require 'vmail/searching'
|
|
13
13
|
require 'vmail/showing_headers'
|
14
14
|
require 'vmail/showing_message'
|
15
15
|
require 'vmail/flagging_and_moving'
|
16
|
+
require 'vmail/reply_templating'
|
16
17
|
|
17
18
|
module Vmail
|
18
19
|
class ImapClient
|
@@ -22,6 +23,7 @@ module Vmail
|
|
22
23
|
include Vmail::ShowingHeaders
|
23
24
|
include Vmail::ShowingMessage
|
24
25
|
include Vmail::FlaggingAndMoving
|
26
|
+
include Vmail::ReplyTemplating
|
25
27
|
|
26
28
|
attr_accessor :max_seqno # of current mailbox
|
27
29
|
|
@@ -34,6 +36,7 @@ module Vmail
|
|
34
36
|
@mailbox = nil
|
35
37
|
@logger = Logger.new(config['logfile'] || STDERR)
|
36
38
|
@logger.level = Logger::DEBUG
|
39
|
+
$logger = @logger
|
37
40
|
@imap_server = config['server'] || 'imap.gmail.com'
|
38
41
|
@imap_port = config['port'] || 993
|
39
42
|
current_message = nil
|
@@ -286,12 +289,6 @@ module Vmail
|
|
286
289
|
lines.join("\n")
|
287
290
|
end
|
288
291
|
|
289
|
-
def reply_template(replyall=false)
|
290
|
-
log "Sending reply template"
|
291
|
-
reply_headers = Vmail::ReplyTemplate.new(current_message.rfc822, @username, @name, replyall, @always_cc).reply_headers
|
292
|
-
body = reply_headers.delete(:body)
|
293
|
-
format_headers(reply_headers) + "\n\n\n" + body + signature
|
294
|
-
end
|
295
292
|
|
296
293
|
def signature
|
297
294
|
return '' unless @signature
|
@@ -348,11 +345,16 @@ EOF
|
|
348
345
|
headers = {}
|
349
346
|
raw_headers.split("\n").each do |line|
|
350
347
|
key, value = *line.split(/:\s*/, 2)
|
351
|
-
|
352
|
-
|
353
|
-
|
348
|
+
if key == 'message-id'
|
349
|
+
mail.references = value
|
350
|
+
else
|
351
|
+
next if (value.nil? || value.strip == '')
|
352
|
+
log [key, value].join(':')
|
353
|
+
if %w(from to cc bcc).include?(key)
|
354
|
+
value = quote_addresses(value)
|
355
|
+
end
|
356
|
+
headers[key] = value
|
354
357
|
end
|
355
|
-
headers[key] = value
|
356
358
|
end
|
357
359
|
log "Delivering message with headers: #{headers.to_yaml}"
|
358
360
|
mail.from = headers['from'] || @username
|
@@ -384,6 +386,9 @@ EOF
|
|
384
386
|
end
|
385
387
|
end
|
386
388
|
mail
|
389
|
+
rescue
|
390
|
+
$logger.debug $!
|
391
|
+
raise
|
387
392
|
end
|
388
393
|
|
389
394
|
def save_attachments(dir)
|
@@ -486,7 +491,8 @@ trap("INT") {
|
|
486
491
|
puts "Closing imap connection"
|
487
492
|
begin
|
488
493
|
Timeout::timeout(2) do
|
489
|
-
|
494
|
+
# just try to quit
|
495
|
+
# $gmail.close
|
490
496
|
end
|
491
497
|
rescue Timeout::Error
|
492
498
|
puts "Close connection attempt timed out"
|
@@ -96,6 +96,9 @@ module Vmail
|
|
96
96
|
if !mail.reply_to.nil?
|
97
97
|
headers['reply_to'] = utf8(mail['reply_to'].decoded)
|
98
98
|
end
|
99
|
+
if mail['message-id']
|
100
|
+
headers['references'] = mail['message-id']
|
101
|
+
end
|
99
102
|
headers
|
100
103
|
rescue
|
101
104
|
{'error' => $!}
|
@@ -117,6 +120,7 @@ module Vmail
|
|
117
120
|
end
|
118
121
|
out
|
119
122
|
rescue
|
123
|
+
$logger.debug $!
|
120
124
|
"[error: #$!]"
|
121
125
|
end
|
122
126
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'mail'
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
module Vmail
|
6
|
+
module ReplyTemplating
|
7
|
+
|
8
|
+
def reply_template(replyall=false)
|
9
|
+
@replyall = replyall
|
10
|
+
log "Sending reply template"
|
11
|
+
h = reply_headers
|
12
|
+
body = h.delete('body')
|
13
|
+
format_headers(h) + "\n\n\n" + body + signature
|
14
|
+
end
|
15
|
+
|
16
|
+
def reply_headers
|
17
|
+
reply_subject = current_message.subject
|
18
|
+
if reply_subject !~ /Re: /
|
19
|
+
reply_subject = "Re: #{reply_subject}"
|
20
|
+
end
|
21
|
+
date = DateTime.parse(current_message.date)
|
22
|
+
sender = current_message.sender
|
23
|
+
reply_quote_header = date ? "On #{date.strftime('%a, %b %d, %Y at %I:%M %p')}, #{sender} wrote:\n\n" : "#{sender} wrote:\n"
|
24
|
+
|
25
|
+
reply_body = reply_quote_header + divider('-') +
|
26
|
+
(current_message.plaintext.split(/^-+$/,2)[1])
|
27
|
+
{
|
28
|
+
'message-id' => current_message.message_id,
|
29
|
+
'from' => "#@name <#@username>",
|
30
|
+
'to' => reply_recipient,
|
31
|
+
'cc' => reply_cc,
|
32
|
+
'bcc' => @always_bcc,
|
33
|
+
'subject' => reply_subject,
|
34
|
+
'body' => reply_body
|
35
|
+
}
|
36
|
+
rescue
|
37
|
+
$logger.debug $!
|
38
|
+
raise
|
39
|
+
end
|
40
|
+
|
41
|
+
def reply_recipient
|
42
|
+
current_mail.header['Reply-To'] || current_message.sender
|
43
|
+
end
|
44
|
+
|
45
|
+
def reply_cc
|
46
|
+
return nil unless (@replyall || @always_cc)
|
47
|
+
xs = if @replyall
|
48
|
+
((current_mail['cc'] && current_mail['cc'].decoded) || "") .split(/,\s*/)
|
49
|
+
else
|
50
|
+
[]
|
51
|
+
end
|
52
|
+
if @always_cc && xs.none? {|x| x =~ %r{#{@always_cc}}}
|
53
|
+
xs << @always_cc
|
54
|
+
end
|
55
|
+
xs.uniq.select {|x| x != reply_recipient }.join(', ')
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
data/lib/vmail/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: vmail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.8.
|
5
|
+
version: 1.8.8
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Daniel Choi
|
@@ -10,7 +10,8 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-28 00:00:00
|
13
|
+
date: 2011-06-28 00:00:00 -04:00
|
14
|
+
default_executable:
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: mail
|
@@ -89,7 +90,7 @@ files:
|
|
89
90
|
- lib/vmail/message_formatter.rb
|
90
91
|
- lib/vmail/options.rb
|
91
92
|
- lib/vmail/query.rb
|
92
|
-
- lib/vmail/
|
93
|
+
- lib/vmail/reply_templating.rb
|
93
94
|
- lib/vmail/searching.rb
|
94
95
|
- lib/vmail/send_options.rb
|
95
96
|
- lib/vmail/sender.rb
|
@@ -114,6 +115,7 @@ files:
|
|
114
115
|
- test/test_helper.rb
|
115
116
|
- test/time_format_test.rb
|
116
117
|
- vmail.gemspec
|
118
|
+
has_rdoc: true
|
117
119
|
homepage: http://danielchoi.com/software/vmail.html
|
118
120
|
licenses: []
|
119
121
|
|
@@ -137,24 +139,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
139
|
requirements: []
|
138
140
|
|
139
141
|
rubyforge_project: vmail
|
140
|
-
rubygems_version: 1.
|
142
|
+
rubygems_version: 1.6.1
|
141
143
|
signing_key:
|
142
144
|
specification_version: 3
|
143
145
|
summary: A Vim interface to Gmail
|
144
|
-
test_files:
|
145
|
-
|
146
|
-
- test/base64_test.rb
|
147
|
-
- test/fixtures/euc-kr-header.eml
|
148
|
-
- test/fixtures/euc-kr-html.eml
|
149
|
-
- test/fixtures/google-affiliate.eml
|
150
|
-
- test/fixtures/htmlbody.eml
|
151
|
-
- test/fixtures/moleskine-html.eml
|
152
|
-
- test/fixtures/reply-template-encoding-test.eml
|
153
|
-
- test/fixtures/reply_all.eml
|
154
|
-
- test/fixtures/rfc_part.eml
|
155
|
-
- test/fixtures/textbody-nocontenttype.eml
|
156
|
-
- test/fixtures/with-attachments.eml
|
157
|
-
- test/message_formatter_test.rb
|
158
|
-
- test/reply_template_test.rb
|
159
|
-
- test/test_helper.rb
|
160
|
-
- test/time_format_test.rb
|
146
|
+
test_files: []
|
147
|
+
|
data/lib/vmail/reply_template.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'mail'
|
3
|
-
require 'time'
|
4
|
-
|
5
|
-
module Vmail
|
6
|
-
class ReplyTemplate
|
7
|
-
|
8
|
-
def initialize(mail, username, name, replyall, always_cc=nil)
|
9
|
-
@username, @name, @replyall, @always_cc = username, name, replyall, always_cc
|
10
|
-
@mail = Mail.new(mail)
|
11
|
-
end
|
12
|
-
|
13
|
-
def reply_headers(try_again = true)
|
14
|
-
formatter = Vmail::MessageFormatter.new(@mail)
|
15
|
-
@orig_headers = formatter.extract_headers
|
16
|
-
subject = @orig_headers['subject']
|
17
|
-
if subject !~ /Re: /
|
18
|
-
subject = "Re: #{subject}"
|
19
|
-
end
|
20
|
-
date = @orig_headers['date'].is_a?(String) ? Time.parse(@orig_headers['date']) : @orig_headers['date']
|
21
|
-
quote_header = date ? "On #{date.strftime('%a, %b %d, %Y at %I:%M %p')}, #{sender} wrote:\n\n" : "#{sender} wrote:\n\n"
|
22
|
-
body = quote_header + formatter.plaintext_part
|
23
|
-
begin
|
24
|
-
body = body.gsub(/^(?=>)/, ">").gsub(/^(?!>)/, "> ")
|
25
|
-
rescue
|
26
|
-
body = Iconv.conv(body, "US-ASCII//TRANSLIT//IGNORE", "UTF-8").gsub(/^(?=>)/, ">").gsub(/^(?!>)/, "> ")
|
27
|
-
end
|
28
|
-
{'from' => "#@name <#@username>", 'to' => primary_recipient, 'cc' => cc, 'subject' => subject, :body => body}
|
29
|
-
end
|
30
|
-
|
31
|
-
def primary_recipient
|
32
|
-
from = @orig_headers['from']
|
33
|
-
reply_to = @mail.header['Reply-To']
|
34
|
-
@primary_recipient = (reply_to || from).to_s
|
35
|
-
end
|
36
|
-
|
37
|
-
def cc
|
38
|
-
return nil unless (@replyall || @always_cc)
|
39
|
-
cc = @mail.header['to'] ? @mail.header['to'].value.split(/,\s*/) : []
|
40
|
-
if @mail.header['cc']
|
41
|
-
cc += @mail.header['cc'].value.split(/,\s*/)
|
42
|
-
end
|
43
|
-
cc = cc.flatten.compact.
|
44
|
-
select {|x| x !~ /#{@username}/}
|
45
|
-
cc << @always_cc
|
46
|
-
cc.select {|x| x !~ /#{@primary_recipient}/}.join(', ')
|
47
|
-
end
|
48
|
-
|
49
|
-
def sender
|
50
|
-
@mail.header['from'].value
|
51
|
-
end
|
52
|
-
|
53
|
-
# deprecated
|
54
|
-
def address_to_string(x)
|
55
|
-
x.name ? "#{x.name} <#{x.mailbox}@#{x.host}>" : "#{x.mailbox}@#{x.host}"
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|