sortah 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +17 -0
- data/bin/sortah +27 -2
- data/lib/sortah/handler.rb +7 -1
- data/lib/sortah/parser.rb +12 -0
- data/lib/sortah/version.rb +1 -1
- data/spec/bin_spec.rb +26 -2
- data/spec/fixtures/rc +3 -0
- data/spec/parser_spec.rb +29 -1
- data/spec/sortah_handler_spec.rb +2 -5
- metadata +6 -6
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
##11/04/11
|
2
|
+
|
3
|
+
### IMPROVEMENTS
|
4
|
+
|
5
|
+
- if you specify "type :maildir" in the sortah rc file, then sortah will
|
6
|
+
automatically scaffold your destinations into maildir directories (eg, it'll
|
7
|
+
`mkdir -p #{maildir}/#{dest}/{cur,new,tmp}` your destinations), and it will
|
8
|
+
automatically write any new mail into the `/new` subdirectory of your
|
9
|
+
destination.
|
10
|
+
|
11
|
+
- Rather than dumping error-causing emails into the vast oblivion, sortah now
|
12
|
+
puts them in the directory specified by the `#error_dest` method
|
13
|
+
|
14
|
+
### ADDITIONS
|
15
|
+
|
16
|
+
- added `#error_dest` to the main sortah file
|
17
|
+
|
1
18
|
##11/02/11
|
2
19
|
|
3
20
|
### BUG FIXES
|
data/bin/sortah
CHANGED
@@ -18,13 +18,38 @@ email = Mail.new(ARGF.read)
|
|
18
18
|
puts "Loading sortah rc" if opts[:verbose]
|
19
19
|
load File.expand_path(opts[:rc])
|
20
20
|
|
21
|
-
|
21
|
+
if sortah.type == :maildir
|
22
|
+
puts "detected maildir format, building maildir directories." if opts[:verbose]
|
23
|
+
maildir = sortah.maildir
|
24
|
+
puts "creating: #{maildir}/#{dest}/{tmp,cur,new}" if opts[:verbose]
|
25
|
+
unless opts[:"dry-run"]
|
26
|
+
sortah.destinations.values.each do |dest|
|
27
|
+
puts dest
|
28
|
+
|
29
|
+
system "mkdir -p #{maildir}/#{dest}/tmp"
|
30
|
+
system "mkdir -p #{maildir}/#{dest}/cur"
|
31
|
+
system "mkdir -p #{maildir}/#{dest}/new"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
begin
|
38
|
+
dest = sortah.sort(email).full_destination
|
39
|
+
rescue
|
40
|
+
STDERR.puts "DELIVERY ERROR: #{$!.message}"
|
41
|
+
dest = sortah.full_error_destination
|
42
|
+
end
|
22
43
|
puts "writing email to: #{dest}" if opts[:"dry-run"] || opts[:verbose]
|
23
44
|
|
45
|
+
if sortah.type == :maildir
|
46
|
+
puts "adjusting destination to maildir style" if opts[:verbose]
|
47
|
+
dest = dest + "new"
|
48
|
+
end
|
49
|
+
|
24
50
|
exit 0 if opts[:"dry-run"]
|
25
51
|
|
26
52
|
#no need to check for dry-run here, we would have exited otherwise
|
27
|
-
system "mkdir -p #{dest}"
|
28
53
|
File.open("#{dest}/#{Digest::SHA1.hexdigest(email.to_s)}.eml", 'w') do |f|
|
29
54
|
f << email.to_s
|
30
55
|
end
|
data/lib/sortah/handler.rb
CHANGED
@@ -12,7 +12,7 @@ module Sortah
|
|
12
12
|
self
|
13
13
|
end
|
14
14
|
|
15
|
-
attr_reader :destinations, :lenses, :routers, :maildir
|
15
|
+
attr_reader :destinations, :lenses, :routers, :maildir, :error_dest, :type
|
16
16
|
|
17
17
|
def metadata(key)
|
18
18
|
@result.metadata(key)
|
@@ -26,6 +26,10 @@ module Sortah
|
|
26
26
|
maildir + destination.to_s
|
27
27
|
end
|
28
28
|
|
29
|
+
def full_error_destination
|
30
|
+
maildir + error_dest.to_s
|
31
|
+
end
|
32
|
+
|
29
33
|
private
|
30
34
|
|
31
35
|
def clear_state!
|
@@ -40,7 +44,9 @@ module Sortah
|
|
40
44
|
@destinations = context.destinations
|
41
45
|
@lenses = context.lenses
|
42
46
|
@routers = context.routers
|
47
|
+
@error_dest = context.error_dest
|
43
48
|
@maildir = context.maildir
|
49
|
+
@type = context.type
|
44
50
|
end
|
45
51
|
end
|
46
52
|
end
|
data/lib/sortah/parser.rb
CHANGED
@@ -41,6 +41,18 @@ module Sortah
|
|
41
41
|
@maildir
|
42
42
|
end
|
43
43
|
|
44
|
+
#double-duty getter/setter
|
45
|
+
def error_dest(dest = nil)
|
46
|
+
@error_dest = dest if dest
|
47
|
+
@error_dest
|
48
|
+
end
|
49
|
+
|
50
|
+
#double-duty getter/setter
|
51
|
+
def type(type = nil)
|
52
|
+
@type = type if type
|
53
|
+
@type
|
54
|
+
end
|
55
|
+
|
44
56
|
## language elements
|
45
57
|
def destination(name, args)
|
46
58
|
@destinations << Destination.new(name, args)
|
data/lib/sortah/version.rb
CHANGED
data/spec/bin_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
def run_with(arg, email = "")
|
2
2
|
#uses the sortah defn in spec/fixtures/rc
|
3
3
|
cmd =<<-CMD
|
4
|
-
bundle exec bin/sortah #{arg} --rc "spec/fixtures/rc" <<-EMAIL
|
4
|
+
bundle exec bin/sortah #{arg} --rc "spec/fixtures/rc" 2>/dev/null <<-EMAIL
|
5
5
|
#{email}
|
6
6
|
EMAIL
|
7
7
|
CMD
|
@@ -29,6 +29,19 @@ describe "the sortah executable" do
|
|
29
29
|
NOPE. CHUCK TESTA
|
30
30
|
TXT
|
31
31
|
end
|
32
|
+
|
33
|
+
@failing_email = Mail.new do
|
34
|
+
to 'fail@example.com'
|
35
|
+
from 'fail@nope.com'
|
36
|
+
subject "Taximerdizin'"
|
37
|
+
body <<-TXT
|
38
|
+
OJAI VALLEY TAXIDERMY
|
39
|
+
|
40
|
+
BET YOU THOUGHT THIS EMAIL WAS REAL
|
41
|
+
|
42
|
+
NOPE. CHUCK TESTA
|
43
|
+
TXT
|
44
|
+
end
|
32
45
|
end
|
33
46
|
|
34
47
|
before :each do
|
@@ -48,7 +61,18 @@ describe "the sortah executable" do
|
|
48
61
|
end
|
49
62
|
|
50
63
|
it "should print to STDOUT the location it intends to write the file" do
|
51
|
-
run_with('--dry-run', @email.to_s)[:result].
|
64
|
+
run_with('--dry-run', @email.to_s)[:result].
|
65
|
+
should =~ %r|writing email to: /tmp/\.mail/foo/|
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should write to the destination specified by #error_dest when an exception is raised during sorting" do
|
69
|
+
run_with('--dry-run', @failing_email.to_s)[:result].
|
70
|
+
should =~ %r|writing email to: /tmp/\.mail/errors/|
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should try to create maildir directories if the maildir type is maildir" do
|
74
|
+
run_with('--dry-run --verbose', @failing_email.to_s)[:result].
|
75
|
+
should =~ %r|detected maildir format, building maildir directories.|
|
52
76
|
end
|
53
77
|
end
|
54
78
|
end
|
data/spec/fixtures/rc
CHANGED
data/spec/parser_spec.rb
CHANGED
@@ -15,7 +15,6 @@ describe Sortah::Parser do
|
|
15
15
|
sortah.should_not be_nil
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
18
|
it "should parse defined 'simple' destinations" do
|
20
19
|
expect {
|
21
20
|
sortah do
|
@@ -198,6 +197,35 @@ describe Sortah::Parser do
|
|
198
197
|
end
|
199
198
|
|
200
199
|
context "when dealing in general with sortah, " do
|
200
|
+
it "should parse a 'type' clause" do
|
201
|
+
expect {
|
202
|
+
sortah do
|
203
|
+
type :maildir
|
204
|
+
end
|
205
|
+
}.should_not raise_error
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should provide an inspection method to determine the maildir type" do
|
209
|
+
sortah do
|
210
|
+
type :maildir
|
211
|
+
end
|
212
|
+
sortah.type.should == :maildir
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should parse an 'error_dest' clause" do
|
216
|
+
expect {
|
217
|
+
sortah do
|
218
|
+
error_dest 'errors/'
|
219
|
+
end
|
220
|
+
}.should_not raise_error
|
221
|
+
end
|
222
|
+
|
223
|
+
it "error_dest should provide access via a #error_dest method" do
|
224
|
+
sortah do
|
225
|
+
error_dest 'errors/'
|
226
|
+
end
|
227
|
+
sortah.error_dest.should == "errors/"
|
228
|
+
end
|
201
229
|
|
202
230
|
it "should maintain one state across multiple sortah blocks" do
|
203
231
|
expect {
|
data/spec/sortah_handler_spec.rb
CHANGED
@@ -2,20 +2,17 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Sortah::Handler do
|
4
4
|
context "when building the handler" do
|
5
|
-
before :all do
|
6
|
-
end
|
7
|
-
|
8
5
|
it "should ask for the parsed content" do
|
9
6
|
context = mock(:context)
|
10
7
|
context.should_receive(:destinations).and_return(instance_of(Sortah::Destinations))
|
11
8
|
context.should_receive(:lenses).and_return(instance_of(Sortah::Lenses))
|
12
9
|
context.should_receive(:routers).and_return(instance_of(Sortah::Routers))
|
13
10
|
context.should_receive(:maildir).and_return(instance_of(String))
|
11
|
+
context.should_receive(:error_dest).and_return(instance_of(String))
|
12
|
+
context.should_receive(:type).and_return(instance_of(Symbol))
|
14
13
|
|
15
14
|
Sortah::Handler.build_from(context)
|
16
15
|
end
|
17
16
|
end
|
18
|
-
|
19
|
-
|
20
17
|
end
|
21
18
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sortah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-07 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mail
|
16
|
-
requirement: &
|
16
|
+
requirement: &2161248620 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2161248620
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: trollop
|
27
|
-
requirement: &
|
27
|
+
requirement: &2161247740 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2161247740
|
36
36
|
description: ! "\n Sortah provides a simple, declarative internal DSL for sorting
|
37
37
|
\n your email. It provides an executable which may serve as an external\n mail
|
38
38
|
delivery agent for such programs as `getmail`. Finally, since\n your sorting
|