uron 1.0.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/README.md +13 -2
- data/bin/uron.rb +33 -12
- data/test/test_uron.rb +26 -0
- data/uron.gemspec +3 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c3fd3a3d7da61594f5acf17e0543a8b022cdb28
|
4
|
+
data.tar.gz: f311b5bf137a009b20917816698a3fd2b645cd22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 656a133a04b2eb9b333034e581ff4ebfb7a9347fd28ba724527faf750c619c23cecc384c58ea3ab449c919549bc7e84b5caf7da79af0df4d1822931b76139434
|
7
|
+
data.tar.gz: 300f29edaa9d2a25c9901e9002ac197eb374ca2992b37e1e69152c1714997df40ceea339b5cbcb15086c421ea0f18efe96af60b4f3b755875f70f227a565ad20
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
[![Build Status](https://img.shields.io/travis/unak/uron.svg)](https://travis-ci.org/unak/uron)
|
2
|
-
|
2
|
+
[![Version ](https://img.shields.io/gem/v/uron.svg)](https://rubygems.org/gems/uron)
|
3
3
|
uron
|
4
4
|
====
|
5
5
|
|
@@ -72,6 +72,7 @@ If a block is passed, call the block.
|
|
72
72
|
Examples:
|
73
73
|
|
74
74
|
header :subject => /\A[mailing-list:/, :delivery => "mailing-list"
|
75
|
+
|
75
76
|
This means that if the subject of the mail starts with `[mailing-list:`,
|
76
77
|
delivery the mail to `mailing-list` directory (it's relative from your
|
77
78
|
Maildir.)
|
@@ -79,8 +80,18 @@ Maildir.)
|
|
79
80
|
header :subject => /\A[mailing-list:/ do
|
80
81
|
delivery "mailing-list"
|
81
82
|
end
|
83
|
+
|
82
84
|
Same as above.
|
83
85
|
|
86
|
+
If you want to check multiple headers, simple put them as:
|
87
|
+
|
88
|
+
header :subject => /\A[mailing-list:/,
|
89
|
+
:from => /\Amailing-list-owner\b/,
|
90
|
+
:delivery => "mailing-list"
|
91
|
+
|
92
|
+
When `subject` and `from` are both matched, the mail will be delivered to `mailling-list` directory.
|
93
|
+
|
94
|
+
|
84
95
|
### Delivery Commands
|
85
96
|
|
86
97
|
#### `delivery`
|
@@ -126,7 +137,7 @@ Takes one String parameter and outout it to the log file.
|
|
126
137
|
License
|
127
138
|
-------
|
128
139
|
|
129
|
-
Copyright (c) 2012 NAKAMURA Usaku usa@garbagecollect.jp
|
140
|
+
Copyright (c) 2012,2014 NAKAMURA Usaku usa@garbagecollect.jp
|
130
141
|
|
131
142
|
Redistribution and use in source and binary forms, with or without
|
132
143
|
modification, are permitted provided that the following conditions are met:
|
data/bin/uron.rb
CHANGED
@@ -34,6 +34,8 @@ require "socket"
|
|
34
34
|
#= uron - a mail delivery agent
|
35
35
|
#
|
36
36
|
class Uron
|
37
|
+
VERSION = "1.2.0"
|
38
|
+
|
37
39
|
ConfigError = Class.new(RuntimeError)
|
38
40
|
|
39
41
|
# execute uron
|
@@ -59,7 +61,7 @@ class Uron
|
|
59
61
|
# _rc_ is a String of the configuration file.
|
60
62
|
# _io_ is a IO of the mail.
|
61
63
|
def initialize(rc)
|
62
|
-
self.class.
|
64
|
+
self.class.class_exec do
|
63
65
|
remove_const :Maildir if defined?(Maildir)
|
64
66
|
remove_const :Log if defined?(Log)
|
65
67
|
end
|
@@ -84,19 +86,38 @@ class Uron
|
|
84
86
|
logging " Subject: #{@mail.headers[:subject].first[0, 69]}" if @mail.headers.include?(:subject)
|
85
87
|
|
86
88
|
catch(:tag) do
|
87
|
-
@ruleset.each do |
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
89
|
+
@ruleset.each do |args, block|
|
90
|
+
matched = false
|
91
|
+
args.each_pair do |sym, conds|
|
92
|
+
unless @mail.headers[sym]
|
93
|
+
matched = false
|
94
|
+
break
|
95
|
+
end
|
96
|
+
|
97
|
+
conds = Array(conds)
|
98
|
+
found = false
|
99
|
+
@mail.headers[sym].each do |header|
|
100
|
+
conds.each do |cond|
|
101
|
+
if cond =~ header
|
102
|
+
found = true
|
103
|
+
break
|
97
104
|
end
|
98
105
|
end
|
99
106
|
end
|
107
|
+
|
108
|
+
if found
|
109
|
+
matched = true
|
110
|
+
else
|
111
|
+
matched = false
|
112
|
+
break
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
begin
|
117
|
+
block.call(@mail) && throw(:tag) if matched
|
118
|
+
rescue
|
119
|
+
logging $!
|
120
|
+
raise $!
|
100
121
|
end
|
101
122
|
end
|
102
123
|
|
@@ -141,7 +162,7 @@ class Uron
|
|
141
162
|
block = proc{ delivery deliv } if deliv
|
142
163
|
block = proc{ transfer *trans } if trans
|
143
164
|
block = proc{ invoke(*invok) == 0 } if invok
|
144
|
-
@ruleset.push([h
|
165
|
+
@ruleset.push([h, block])
|
145
166
|
end
|
146
167
|
|
147
168
|
# deliver the mail to a directory
|
data/test/test_uron.rb
CHANGED
@@ -177,6 +177,32 @@ header :to => /\\Ausa3@/, :invoke => ["#{ruby}", "-e", "exit /^To:.*usa3@/ =~ AR
|
|
177
177
|
assert_match /\AFrom [^\n]+\r?\n\z/, File.read(@logfile)
|
178
178
|
end
|
179
179
|
tmprc.unlink
|
180
|
+
File.unlink(@logfile) if File.exist?(@logfile)
|
181
|
+
|
182
|
+
tmprc = make_rc <<-END_OF_RC
|
183
|
+
Log = "#{@logfile}"
|
184
|
+
header :from => /\\Ausa\\b/, :to => /\\Ausa\\b/ do
|
185
|
+
delivery ".mine"
|
186
|
+
end
|
187
|
+
header :from => /\\Ausa\\b/ do
|
188
|
+
delivery ".others"
|
189
|
+
end
|
190
|
+
END_OF_RC
|
191
|
+
assert_nothing_raised do
|
192
|
+
io = StringIO.new("From: usa@example.com\r\nTo: usa@example.com\r\n\r\n")
|
193
|
+
assert_equal 0, Uron.run(tmprc.path, io)
|
194
|
+
mail = Dir.glob(File.join(@maildir, "new", "*")).find{|e| /\A[^\.]/ =~ e}
|
195
|
+
assert_nil mail
|
196
|
+
assert_match /\AFrom [^\n]+\r?\n\s+Folder: .mine/, File.read(@logfile)
|
197
|
+
File.unlink(@logfile) if File.exist?(@logfile)
|
198
|
+
|
199
|
+
io = StringIO.new("From: usa@example.com\r\nTo: hoge@example.com\r\n\r\n")
|
200
|
+
assert_equal 0, Uron.run(tmprc.path, io)
|
201
|
+
mail = Dir.glob(File.join(@maildir, "new", "*")).find{|e| /\A[^\.]/ =~ e}
|
202
|
+
assert_nil mail
|
203
|
+
assert_match /\AFrom [^\n]+\r?\n\s+Folder: .others/, File.read(@logfile)
|
204
|
+
end
|
205
|
+
tmprc.unlink
|
180
206
|
end
|
181
207
|
|
182
208
|
def test_delivery
|
data/uron.gemspec
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
# -*- Ruby -*-
|
3
|
+
require File.expand_path("bin/uron")
|
4
|
+
|
3
5
|
Gem::Specification.new do |spec|
|
4
6
|
spec.name = "uron"
|
5
|
-
spec.version =
|
7
|
+
spec.version = Uron::VERSION
|
6
8
|
spec.authors = ["U.Nakamura"]
|
7
9
|
spec.email = ["usa@garbagecollect.jp"]
|
8
10
|
spec.description = %q{uron is a mail delivery agent}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- U.Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
89
|
version: '0'
|
90
90
|
requirements: []
|
91
91
|
rubyforge_project:
|
92
|
-
rubygems_version: 2.
|
92
|
+
rubygems_version: 2.4.5.1
|
93
93
|
signing_key:
|
94
94
|
specification_version: 4
|
95
95
|
summary: uron is a mail delivery agent
|