vmail 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +7 -0
- data/lib/vmail.rb +2 -0
- data/lib/vmail/imap_client.rb +0 -2
- data/lib/vmail/message_formatter.rb +10 -8
- data/lib/vmail/reply_template.rb +7 -7
- data/lib/vmail/version.rb +1 -1
- data/test/fixtures/reply-template-encoding-test.eml +40 -0
- data/test/reply_template_test.rb +37 -21
- metadata +4 -2
data/README.markdown
CHANGED
@@ -44,6 +44,13 @@ installation command again.
|
|
44
44
|
|
45
45
|
gem install vmail
|
46
46
|
|
47
|
+
If you ever want to uninstall vmail from your system, just execute this command:
|
48
|
+
|
49
|
+
gem uninstall vmail
|
50
|
+
|
51
|
+
... and all traces of vmail will removed, except the few files it creates
|
52
|
+
during execution (see below).
|
53
|
+
|
47
54
|
## Configuration file
|
48
55
|
|
49
56
|
To run vmail, create a yaml file called `.vmailrc` and save it either in the
|
data/lib/vmail.rb
CHANGED
data/lib/vmail/imap_client.rb
CHANGED
@@ -132,15 +132,17 @@ module Vmail
|
|
132
132
|
|
133
133
|
def utf8(string)
|
134
134
|
return '' unless string
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
135
|
+
out = if encoding && encoding.upcase != 'UTF-8'
|
136
|
+
Iconv.conv('UTF-8//TRANSLIT/IGNORE', encoding, string)
|
137
|
+
elsif encoding.upcase == 'UTF-8'
|
138
|
+
string
|
139
|
+
else
|
140
|
+
# assume UTF-8
|
141
|
+
Iconv.conv('US-ASCII//TRANSLIT/IGNORE', 'UTF-8', string)
|
142
|
+
end
|
143
|
+
out
|
141
144
|
rescue
|
142
|
-
|
143
|
-
string
|
145
|
+
"[error: #$!]"
|
144
146
|
end
|
145
147
|
end
|
146
148
|
end
|
data/lib/vmail/reply_template.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'vmail/message_formatter'
|
2
1
|
require 'mail'
|
3
2
|
require 'time'
|
4
3
|
|
@@ -12,20 +11,21 @@ module Vmail
|
|
12
11
|
|
13
12
|
def reply_headers(try_again = true)
|
14
13
|
formatter = Vmail::MessageFormatter.new(@mail)
|
15
|
-
|
16
|
-
subject =
|
14
|
+
@orig_headers = formatter.extract_headers
|
15
|
+
subject = @orig_headers['subject']
|
17
16
|
if subject !~ /Re: /
|
18
17
|
subject = "Re: #{subject}"
|
19
18
|
end
|
20
|
-
date =
|
21
|
-
quote_header = "On #{date.strftime('%a, %b %d, %Y at %I:%M %p')}, #{sender} wrote:\n\n"
|
19
|
+
date = @orig_headers['date'].is_a?(String) ? Time.parse(@orig_headers['date']) : @orig_headers['date']
|
20
|
+
quote_header = date ? "On #{date.strftime('%a, %b %d, %Y at %I:%M %p')}, #{sender} wrote:\n\n" : "#{sender} wrote:\n\n"
|
22
21
|
body = quote_header + formatter.process_body.gsub(/^(?=>)/, ">").gsub(/^(?!>)/, "> ")
|
23
22
|
{'from' => "#@name <#@username>", 'to' => primary_recipient, 'cc' => cc, 'subject' => subject, :body => body}
|
24
23
|
end
|
25
24
|
|
26
25
|
def primary_recipient
|
27
|
-
|
28
|
-
|
26
|
+
reply_headers unless @orig_headers
|
27
|
+
from = @orig_headers['from']
|
28
|
+
reply_to = @orig_headers['reply-to']
|
29
29
|
[ reply_to, from ].flatten.compact.map(&:to_s)[0]
|
30
30
|
end
|
31
31
|
|
data/lib/vmail/version.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
Return-Path: <bjorn.anon@gmail.com>
|
2
|
+
Received: by 10.213.2.204 with SMTP id 12cs17792ebk; Tue, 21 Dec 2010 05:40:30 -0800
|
3
|
+
Received: from mr.google.com ([10.229.226.72]) by 10.229.226.72 with SMTP id iv8mr5009442qcb.204.1292938829929 (num_hops = 1); Tue, 21 Dec 2010 05:40:29 -0800
|
4
|
+
Received: by 10.229.226.72 with SMTP id iv8mr5009442qcb.204.1292938829911; Tue, 21 Dec 2010 05:40:29 -0800
|
5
|
+
Received: by 10.229.49.20 with HTTP; Tue, 21 Dec 2010 05:40:09 -0800
|
6
|
+
Date: Tue, 21 Dec 2010 14:40:09 +0100
|
7
|
+
From: =?ISO-8859-1?Q?bj=F6rn?= <bjorn.anon@gmail.com>
|
8
|
+
To: dhchoi@gmail.com
|
9
|
+
Message-ID: <AANLkTim-YQ=ZknU9kTn6E+gFz2fuYwPATH0p8awLeW4+@mail.gmail.com>
|
10
|
+
Subject: MacVim and vmail
|
11
|
+
Mime-Version: 1.0
|
12
|
+
Content-Type: text/plain;
|
13
|
+
charset=ISO-8859-1
|
14
|
+
Content-Transfer-Encoding: quoted-printable
|
15
|
+
Delivered-To: dhchoi@gmail.com
|
16
|
+
Received-SPF: pass (google.com: domain of bjorn.anon@gmail.com designates
|
17
|
+
10.229.226.72 as permitted sender) client-ip=10.229.226.72;
|
18
|
+
Authentication-Results: mr.google.com; spf=pass (google.com: domain of
|
19
|
+
bjorn.anon@gmail.com designates 10.229.226.72 as permitted sender)
|
20
|
+
smtp.mail=bjorn.anon@gmail.com; dkim=pass
|
21
|
+
header.i=bjorn.anon@gmail.com
|
22
|
+
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;
|
23
|
+
h=domainkey-signature:received:mime-version:received:from:date
|
24
|
+
:message-id:subject:to:content-type:content-transfer-encoding;
|
25
|
+
bh=tGJ8CJFcQHFOWkIFqkJNeTR7/cdlltnCQhqqvmM0/J0=;
|
26
|
+
b=XT4QNhPsFHy/c+dd6FqJwhCDGmdBCwnvZqXuG9URh1KGlGBtU0DJX41HW9kZyrAvXj
|
27
|
+
aOxp55FueAXyXUZQm15P2A8/9SrYvMOc9hWOS5Se9a4mlnYqXXcp+W2oE5DqEKGb7YlH
|
28
|
+
ap6btHS1XLryXkO8SjZc+scMk50wqjDzQL7hU=
|
29
|
+
DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;
|
30
|
+
h=mime-version:from:date:message-id:subject:to:content-type
|
31
|
+
:content-transfer-encoding;
|
32
|
+
b=D73071TdLGB8O2FMAVeQM8P3FCKldlkhJ1x4cZsa3IBg7Kt39PfVl975M/fopHbUHL
|
33
|
+
ctStLGhrRByypG6+elo0PnHPOwMqnRLN7Smt4yY2DgyJ5IIdFF8HVNswMbRaIJ2kAzYj
|
34
|
+
Ni3lTZC0BwwlBcMfL3/hIxAHTMKTf5oWQgZyA=
|
35
|
+
|
36
|
+
Hi Daniel,=0D
|
37
|
+
=0D
|
38
|
+
I saw the following on your vmail page:=0D
|
39
|
+
Best wishes,=0D
|
40
|
+
Bj=F6rn=
|
data/test/reply_template_test.rb
CHANGED
@@ -1,32 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'test_helper'
|
3
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
2
4
|
require 'vmail/reply_template'
|
5
|
+
require 'vmail/message_formatter'
|
3
6
|
|
4
7
|
describe Vmail::ReplyTemplate do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
8
|
+
describe 'normal rfc822 message' do
|
9
|
+
before do
|
10
|
+
@raw = read_fixture('reply_all.eml')
|
11
|
+
@mail = Mail.new(@raw)
|
12
|
+
@rt = Vmail::ReplyTemplate.new(@mail, 'dhchoi@gmail.com', 'Daniel Choi', true)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_detect_primary_recipient
|
16
|
+
assert_equal "Chappy Youn <chappy1@gmail.com>", @rt.primary_recipient
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_detect_cc
|
20
|
+
expected = "Draculette Ko <violinist.ko@gmail.com>, Cookiemonster Youn <cookiemonster@gmail.com>, Racoon <raycoon@gmail.com>"
|
21
|
+
assert_equal expected, @rt.cc
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_sender
|
25
|
+
assert_equal "Chappy Youn <chappy1@gmail.com>", @rt.sender
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_template
|
29
|
+
expected = {"from"=>"Daniel Choi <dhchoi@gmail.com>", "to"=>"Chappy Youn <chappy1@gmail.com>", "cc"=>"Draculette Ko <violinist.ko@gmail.com>, Cookiemonster Youn <cookiemonster@gmail.com>, Racoon <raycoon@gmail.com>", "subject"=>"Re: Holiday potluck at Ray's", :body=>"On Sun, Dec 12, 2010 at 01:13 PM, Chappy Youn <chappy1@gmail.com> wrote:\n\n> Guys,\n> Tonight we will have a potluck at Ray's at 7. Pls bring food for 1.5 \n> ppl.\n> \n> Ray will provide wine and dessert.\n> \n> Also, we will be having a poor man's Yankee swap. Pls bring something \n> gift wrapped from home. Nothing fancy, but something halfway decent or \n> funny.\n> \n> El, make sure it's worth more than 50 cents.\n> \n> Chappy\n> \n> Sent from my iPhone"}
|
30
|
+
|
31
|
+
assert_equal expected, @rt.reply_headers
|
32
|
+
end
|
9
33
|
end
|
10
34
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
assert_equal expected, @rt.cc
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_sender
|
21
|
-
assert_equal "Chappy Youn <chappy1@gmail.com>", @rt.sender
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_template
|
25
|
-
expected = {"from"=>"Daniel Choi <dhchoi@gmail.com>", "to"=>"Chappy Youn <chappy1@gmail.com>", "cc"=>"Draculette Ko <violinist.ko@gmail.com>, Cookiemonster Youn <cookiemonster@gmail.com>, Racoon <raycoon@gmail.com>", "subject"=>"Re: Holiday potluck at Ray's", :body=>"On Sun, Dec 12, 2010 at 01:13 PM, Chappy Youn <chappy1@gmail.com> wrote:\n\n> Guys,\n> Tonight we will have a potluck at Ray's at 7. Pls bring food for 1.5 \n> ppl.\n> \n> Ray will provide wine and dessert.\n> \n> Also, we will be having a poor man's Yankee swap. Pls bring something \n> gift wrapped from home. Nothing fancy, but something halfway decent or \n> funny.\n> \n> El, make sure it's worth more than 50 cents.\n> \n> Chappy\n> \n> Sent from my iPhone"}
|
35
|
+
describe 'encoded rfc822 message' do
|
36
|
+
before do
|
37
|
+
@raw = read_fixture("reply-template-encoding-test.eml")
|
38
|
+
@mail = Mail.new @raw
|
39
|
+
@rt = Vmail::ReplyTemplate.new(@mail, 'dhchoi@gmail.com', 'Daniel Choi', true)
|
40
|
+
end
|
26
41
|
|
27
|
-
|
42
|
+
def test_encoded_header
|
43
|
+
assert_equal '"björn" <bjorn.anon@gmail.com>', @rt.reply_headers['to']
|
44
|
+
end
|
28
45
|
end
|
29
46
|
|
30
|
-
|
31
47
|
end
|
32
48
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 8
|
9
|
+
version: 1.0.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Daniel Choi
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- test/fixtures/google-affiliate.eml
|
85
85
|
- test/fixtures/htmlbody.eml
|
86
86
|
- test/fixtures/moleskine-html.eml
|
87
|
+
- test/fixtures/reply-template-encoding-test.eml
|
87
88
|
- test/fixtures/reply_all.eml
|
88
89
|
- test/fixtures/rfc_part.eml
|
89
90
|
- test/fixtures/textbody-nocontenttype.eml
|
@@ -165,6 +166,7 @@ test_files:
|
|
165
166
|
- test/fixtures/google-affiliate.eml
|
166
167
|
- test/fixtures/htmlbody.eml
|
167
168
|
- test/fixtures/moleskine-html.eml
|
169
|
+
- test/fixtures/reply-template-encoding-test.eml
|
168
170
|
- test/fixtures/reply_all.eml
|
169
171
|
- test/fixtures/rfc_part.eml
|
170
172
|
- test/fixtures/textbody-nocontenttype.eml
|