astrotrain 0.5.4 → 0.6.0
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/Gemfile +8 -0
- data/LICENSE +18 -17
- data/Rakefile +118 -103
- data/astrotrain.gemspec +87 -136
- data/lib/astrotrain.rb +47 -51
- data/lib/astrotrain/attachment.rb +55 -0
- data/lib/astrotrain/message.rb +221 -235
- data/lib/astrotrain/transports/http_post.rb +67 -0
- data/lib/astrotrain/transports/resque.rb +63 -0
- data/test/fixtures/bad_email_format.txt +15 -0
- data/test/fixtures/basic.txt +4 -1
- data/test/fixtures/iso-8859-1.txt +1 -0
- data/test/message_test.rb +146 -457
- data/test/test_helper.rb +20 -42
- data/test/transport_test.rb +98 -100
- metadata +100 -243
- data/.gitignore +0 -26
- data/README +0 -47
- data/VERSION +0 -1
- data/config/sample.rb +0 -12
- data/lib/astrotrain/api.rb +0 -52
- data/lib/astrotrain/logged_mail.rb +0 -48
- data/lib/astrotrain/mapping.rb +0 -162
- data/lib/astrotrain/mapping/http_post.rb +0 -18
- data/lib/astrotrain/mapping/jabber.rb +0 -28
- data/lib/astrotrain/mapping/transport.rb +0 -55
- data/lib/astrotrain/tmail.rb +0 -58
- data/lib/astrotrain/worker.rb +0 -65
- data/lib/vendor/rest-client/README.rdoc +0 -104
- data/lib/vendor/rest-client/Rakefile +0 -84
- data/lib/vendor/rest-client/bin/restclient +0 -65
- data/lib/vendor/rest-client/foo.diff +0 -66
- data/lib/vendor/rest-client/lib/rest_client.rb +0 -188
- data/lib/vendor/rest-client/lib/rest_client/net_http_ext.rb +0 -23
- data/lib/vendor/rest-client/lib/rest_client/payload.rb +0 -185
- data/lib/vendor/rest-client/lib/rest_client/request_errors.rb +0 -75
- data/lib/vendor/rest-client/lib/rest_client/resource.rb +0 -103
- data/lib/vendor/rest-client/rest-client.gemspec +0 -18
- data/lib/vendor/rest-client/spec/base.rb +0 -5
- data/lib/vendor/rest-client/spec/master_shake.jpg +0 -0
- data/lib/vendor/rest-client/spec/payload_spec.rb +0 -71
- data/lib/vendor/rest-client/spec/request_errors_spec.rb +0 -44
- data/lib/vendor/rest-client/spec/resource_spec.rb +0 -52
- data/lib/vendor/rest-client/spec/rest_client_spec.rb +0 -219
- data/test/api_test.rb +0 -32
- data/test/logged_mail_test.rb +0 -67
- data/test/mapping_test.rb +0 -129
data/test/api_test.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
|
-
|
3
|
-
class Astrotrain::ApiTest < Astrotrain::ApiTestCase
|
4
|
-
before :all do
|
5
|
-
@filename1 = Astrotrain::Message.queue("boo!")
|
6
|
-
@filename2 = Astrotrain::Message.queue("foo!")
|
7
|
-
end
|
8
|
-
|
9
|
-
it "counts queue" do
|
10
|
-
get '/queue_size'
|
11
|
-
assert_equal '2', last_response.body
|
12
|
-
end
|
13
|
-
|
14
|
-
it "lists queue files" do
|
15
|
-
get '/queue'
|
16
|
-
files = last_response.body.split("\n")
|
17
|
-
assert_equal 2, files.size
|
18
|
-
assert files.include?(File.basename(@filename1))
|
19
|
-
assert files.include?(File.basename(@filename2))
|
20
|
-
end
|
21
|
-
|
22
|
-
it "reads queue file" do
|
23
|
-
get "/queue/#{File.basename(@filename1)}"
|
24
|
-
assert_equal 'boo!', last_response.body
|
25
|
-
end
|
26
|
-
|
27
|
-
it "does not read missing file" do
|
28
|
-
get "/queue//etc/passwd"
|
29
|
-
assert_equal "\"etc/passwd\" was not found.", last_response.body
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
data/test/logged_mail_test.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "test_helper")
|
2
|
-
|
3
|
-
class Astrotrain::LoggedMailTest < Astrotrain::TestCase
|
4
|
-
describe "being created from Message" do
|
5
|
-
before :all do
|
6
|
-
Astrotrain::Mapping.all.destroy!
|
7
|
-
@mapping = Astrotrain::Mapping.create!(:email_user => '*')
|
8
|
-
@raw = mail(:custom)
|
9
|
-
@message = Astrotrain::Message.parse(@raw)
|
10
|
-
@logged = Astrotrain::LoggedMail.from(@message, 'foo/bar') do |l|
|
11
|
-
l.recipient = @message.recipients(%w(delivered_to)).first
|
12
|
-
l.mapping = @mapping
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
it "sets recipient" do
|
17
|
-
assert_equal @message.recipients(%w(delivered_to)).first, @logged.recipient
|
18
|
-
end
|
19
|
-
|
20
|
-
it "sets mail_file" do
|
21
|
-
assert_equal 'foo/bar', @logged.mail_file
|
22
|
-
end
|
23
|
-
|
24
|
-
it "sets sender" do
|
25
|
-
assert_equal 'user@example.com', @logged.sender
|
26
|
-
end
|
27
|
-
|
28
|
-
it "sets subject" do
|
29
|
-
assert_equal @message.subject, @logged.subject
|
30
|
-
end
|
31
|
-
|
32
|
-
it "sets mapping" do
|
33
|
-
assert_equal @mapping, @logged.mapping
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "attempted creation with badly encoded message" do
|
38
|
-
before :all do
|
39
|
-
Astrotrain::Mapping.all.destroy!
|
40
|
-
@mapping = Astrotrain::Mapping.create!(:email_user => '*')
|
41
|
-
@raw = mail(:custom)
|
42
|
-
@subject = "=?gb2312?B?usO80rXnubrO78341b68urjEsOajrLfJwPvG1tfu0MKxqLzbo6jUsbmkvNuj?= =?gb2312?B?qQ==?="
|
43
|
-
@raw.sub! /Subject\: Fwd\: blah blah/, "Subject: #{@subject}"
|
44
|
-
@message = Astrotrain::Message.parse(@raw)
|
45
|
-
@logged = Astrotrain::LoggedMail.from(@message) do |l|
|
46
|
-
l.recipient = @message.recipients(%w(delivered_to)).first
|
47
|
-
l.mapping = @mapping
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
it "sets recipient" do
|
52
|
-
assert_equal @message.recipients(%w(delivered_to)).first, @logged.recipient
|
53
|
-
end
|
54
|
-
|
55
|
-
it "sets subject" do
|
56
|
-
assert_equal @subject, @logged.subject
|
57
|
-
end
|
58
|
-
|
59
|
-
it "sets sender" do
|
60
|
-
assert_equal 'user@example.com', @logged.sender
|
61
|
-
end
|
62
|
-
|
63
|
-
it "sets mapping" do
|
64
|
-
assert_equal @mapping, @logged.mapping
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
data/test/mapping_test.rb
DELETED
@@ -1,129 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "test_helper")
|
2
|
-
|
3
|
-
class Astrotrain::MappingTest < Astrotrain::TestCase
|
4
|
-
it "defaults #email_domain to Mapping.default_domain" do
|
5
|
-
assert_equal Astrotrain::Mapping.default_domain, Astrotrain::Mapping.new.email_domain
|
6
|
-
end
|
7
|
-
|
8
|
-
it "defaults #transport to 'http_post" do
|
9
|
-
assert_equal 'http_post', Astrotrain::Mapping.new.transport
|
10
|
-
end
|
11
|
-
|
12
|
-
it "knows http_post transport uses urls" do
|
13
|
-
assert Astrotrain::Mapping.new(:transport => 'http_post').destination_uses_url?
|
14
|
-
end
|
15
|
-
|
16
|
-
it "knows jabber transport uses emails" do
|
17
|
-
assert Astrotrain::Mapping.new(:transport => 'jabber').destination_uses_email?
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "matching" do
|
21
|
-
before :all do
|
22
|
-
Astrotrain::Mapping.transaction do
|
23
|
-
Astrotrain::Mapping.all.destroy!
|
24
|
-
@mapping1 = Astrotrain::Mapping.create!(:email_user => '*')
|
25
|
-
@mapping2 = Astrotrain::Mapping.create!(:email_user => 'abc*')
|
26
|
-
@mapping3 = Astrotrain::Mapping.create!(:email_user => 'abc')
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
it "matches email user" do
|
31
|
-
assert_equal [@mapping3, "abc@#{Astrotrain::Mapping.default_domain}"],
|
32
|
-
Astrotrain::Mapping.match(["abc@#{Astrotrain::Mapping.default_domain}"])
|
33
|
-
end
|
34
|
-
|
35
|
-
it "matches email partial wildcard" do
|
36
|
-
assert_equal [@mapping2, "abc1@#{Astrotrain::Mapping.default_domain}"],
|
37
|
-
Astrotrain::Mapping.match(["abc1@#{Astrotrain::Mapping.default_domain}"])
|
38
|
-
end
|
39
|
-
|
40
|
-
it "matches email full wildcard" do
|
41
|
-
assert_equal [@mapping1, "def@#{Astrotrain::Mapping.default_domain}"],
|
42
|
-
Astrotrain::Mapping.match(["def@#{Astrotrain::Mapping.default_domain}"])
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "finding reply text" do
|
47
|
-
delim = "xyz"
|
48
|
-
|
49
|
-
before :all do
|
50
|
-
@mapping = Astrotrain::Mapping.new :separator => delim
|
51
|
-
end
|
52
|
-
|
53
|
-
{
|
54
|
-
"foo bar\n\n#{delim}\nfoo" => "foo bar",
|
55
|
-
"foo bar\n\nOn 13-Jan-09, at 9:17 AM, ENTP Support wrote:\n\n\n#{delim}\nfoo" => "foo bar",
|
56
|
-
"foo bar\n\nOn Jan 13, 2009 at 2:20 PM, ENTP Support wrote:\n\n\n#{delim}\nfoo" => "foo bar",
|
57
|
-
"foo bar\n\nAm Tuesday 02 December 2008 schrieb Ricky Bobby:\n\n\n#{delim}\nfoo" => "foo bar",
|
58
|
-
"foo bar\n\nLe 18 sept. 08 à 09:08, theRemix a écrit :\n\n\n#{delim}\nfoo" => "foo bar",
|
59
|
-
"foo\n bar\nbaz\n\n\n> #{delim}" => "foo\n bar\nbaz",
|
60
|
-
"foo\n\nbar\nbaz\n#{delim}" => "foo",
|
61
|
-
"foo\n bar\nbaz2\n\n\n\n" => "foo\n bar\nbaz2",
|
62
|
-
">> #{delim}\n foo bar" => ""
|
63
|
-
}.each do |before, after|
|
64
|
-
it "parses #{after.inspect} from #{before.inspect}" do
|
65
|
-
assert_equal after, @mapping.find_reply_from(before)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "validation" do
|
71
|
-
before :all do
|
72
|
-
Astrotrain::Mapping.all.destroy!
|
73
|
-
@mapping = Astrotrain::Mapping.create!(:email_user => 'xyz')
|
74
|
-
end
|
75
|
-
|
76
|
-
%w(abc abc_def abc-123 abc+def abc%def foo* *).each do |valid|
|
77
|
-
it "allows #email_user == #{valid.inspect}" do
|
78
|
-
assert valid_mapping(:email_user => valid).valid?
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
%w(a\ b abc! abc? foo*bar *foo).each do |valid|
|
83
|
-
it "rejects #email_user == #{valid.inspect}" do
|
84
|
-
assert !valid_mapping(:email_user => valid).valid?
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
%w(abc abc_def abc-123 abc.def).each do |valid|
|
89
|
-
it "allows #email_domain == #{valid.inspect}" do
|
90
|
-
assert valid_mapping(:email_domain => valid).valid?
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
%w(a\ b abc! abc? abc+def abc%def).each do |valid|
|
95
|
-
it "rejects #email_domain == #{valid.inspect}" do
|
96
|
-
assert !valid_mapping(:email_domain => valid).valid?
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
%w(http://example.com https://example.com http://example.com/ http://example.com/foo http://rick:monkey@example.com http://example.com:4567/foo http://localhost:3000/foo http://localhost/foo http://example.com/foo/bar.html http://example.com/foo?blah[baz]=1).each do |valid|
|
101
|
-
it "allows #destination == #{valid.inspect} for http_post transport" do
|
102
|
-
assert valid_mapping(:destination => valid, :transport => 'http_post').valid?
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
%w(foo@bar.com).each do |valid|
|
107
|
-
it "allows #destination == #{valid.inspect} for jabber transport" do
|
108
|
-
assert valid_mapping(:destination => valid, :transport => 'jabber').valid?
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
it "rejects duplicate email_user/email_domain" do
|
113
|
-
assert !valid_mapping(:email_user => @mapping.email_user).valid?
|
114
|
-
end
|
115
|
-
|
116
|
-
it "accepts unique email_user" do
|
117
|
-
assert valid_mapping.valid?
|
118
|
-
end
|
119
|
-
|
120
|
-
it "accepts unique email_user + email_domain" do
|
121
|
-
assert valid_mapping(:email_user => @mapping.email_user, :email_domain => 'example.com').valid?
|
122
|
-
end
|
123
|
-
|
124
|
-
protected
|
125
|
-
def valid_mapping(options = {})
|
126
|
-
Astrotrain::Mapping.new({:destination => 'http://foo.com', :email_user => 'sample', :transport => 'http_post'}.update(options))
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|