received 0.4.1 → 0.5.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/bin/received +20 -19
- data/lib/received/connection.rb +1 -1
- data/lib/received/lmtp.rb +2 -2
- data/lib/received/server.rb +6 -2
- data/lib/received/version.rb +1 -1
- data/lib/received.rb +7 -0
- data/spec/lmtp_spec.rb +7 -3
- metadata +2 -2
data/bin/received
CHANGED
@@ -4,6 +4,7 @@ require 'logger'
|
|
4
4
|
require 'optparse'
|
5
5
|
$:<< File.expand_path('../../lib', __FILE__)
|
6
6
|
require 'received'
|
7
|
+
require 'daemons'
|
7
8
|
|
8
9
|
options = {}
|
9
10
|
OptionParser.new do |opts|
|
@@ -14,8 +15,8 @@ OptionParser.new do |opts|
|
|
14
15
|
opts.on('-s', '--unix-socket PATH', 'Use UNIX socket') {|v| options[:unix_socket] = v}
|
15
16
|
opts.on('-p', '--port NUM', 'Listen to TCP port') {|v| options[:port] = v.to_i}
|
16
17
|
opts.on('-i', '--host NAME', 'Bind to this IP (default: 127.0.0.1)') {|v| options[:host] = v}
|
17
|
-
opts.on('-a', '--piddir PATH', 'Directory for pid file (default: /var/
|
18
|
-
opts.on('-l', '--log FILE', 'Log file name (default:
|
18
|
+
opts.on('-a', '--piddir PATH', 'Directory for pid file (default: /var/run/received)') {|v| options[:dir] = v}
|
19
|
+
opts.on('-l', '--log FILE', 'Log file name (default: /var/log/received.log)') {|v| options[:logfile] = v}
|
19
20
|
opts.on('-u', '--user NAME', 'Effective user when daemon (default: nobody)') {|v| options[:user] = v}
|
20
21
|
opts.on('-g', '--group NAME', 'Effective group when daemon (default: nobody)') {|v| options[:group] = v}
|
21
22
|
opts.on('-r', '--require FILE1,FILE2,...', 'Require ruby file(s)') {|v| options[:require] = v}
|
@@ -30,24 +31,28 @@ raise "Config file is required, please provide with -c config.yml" unless option
|
|
30
31
|
|
31
32
|
# Default backend
|
32
33
|
options[:backend] ||= 'mongodb'
|
34
|
+
options[:dir] ||= '/var/run/received'
|
33
35
|
|
34
36
|
options[:logger] = Logger.new(options[:logfile] || $stderr).tap do |logger|
|
35
37
|
logger.level = options[:level] || Logger::INFO
|
36
38
|
end
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
40
|
+
ontop = !options.delete(:daemon)
|
41
|
+
params = {
|
42
|
+
:ontop => ontop,
|
43
|
+
:app_name => 'received',
|
44
|
+
:log_output => true,
|
45
|
+
:dir_mode => :normal,
|
46
|
+
:dir => options[:dir]
|
47
|
+
}
|
48
|
+
|
49
|
+
# Drop privileges if started as superuser
|
50
|
+
params.merge!(:user => options[:user] || 'nobody', :group => options[:group] || 'nobody') if Process.uid == 0
|
51
|
+
Daemons.daemonize(params)
|
52
|
+
File.umask(0007)
|
53
|
+
|
54
|
+
if files = options[:require]
|
55
|
+
files.split(',').each { |file| require file }
|
51
56
|
end
|
52
57
|
|
53
58
|
server = Received::Server.new(options)
|
@@ -55,8 +60,4 @@ server = Received::Server.new(options)
|
|
55
60
|
Signal.trap(sig) {server.stop}
|
56
61
|
end
|
57
62
|
|
58
|
-
if files = options[:require]
|
59
|
-
files.split(',').each { |file| require file }
|
60
|
-
end
|
61
|
-
|
62
63
|
server.serve!
|
data/lib/received/connection.rb
CHANGED
data/lib/received/lmtp.rb
CHANGED
@@ -29,7 +29,7 @@ module Received
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def event(ev)
|
32
|
-
|
32
|
+
Received.logger.debug {"state was: #{@state.inspect}"}
|
33
33
|
@state = case @state
|
34
34
|
when :start
|
35
35
|
reset!
|
@@ -92,7 +92,7 @@ module Received
|
|
92
92
|
else
|
93
93
|
raise "Where am I? (#{@state.inspect})"
|
94
94
|
end || @state
|
95
|
-
|
95
|
+
Received.logger.debug {"state now: #{@state.inspect}"}
|
96
96
|
end
|
97
97
|
|
98
98
|
def banner
|
data/lib/received/server.rb
CHANGED
@@ -5,11 +5,11 @@ require 'received/connection'
|
|
5
5
|
|
6
6
|
module Received
|
7
7
|
class Server
|
8
|
-
attr_reader :
|
8
|
+
attr_reader :options
|
9
9
|
|
10
10
|
def initialize(options)
|
11
11
|
@options = options
|
12
|
-
|
12
|
+
Received.logger ||= (options[:logger] || Logger.new(STDERR))
|
13
13
|
@connections = []
|
14
14
|
# For how long the server will wait for connections to finish
|
15
15
|
@grace_period = options[:grace_period] || 10
|
@@ -63,6 +63,10 @@ module Received
|
|
63
63
|
set_title
|
64
64
|
end
|
65
65
|
|
66
|
+
def logger
|
67
|
+
Received.logger
|
68
|
+
end
|
69
|
+
|
66
70
|
private
|
67
71
|
|
68
72
|
# Sets the process title as seen in ps
|
data/lib/received/version.rb
CHANGED
data/lib/received.rb
CHANGED
data/spec/lmtp_spec.rb
CHANGED
@@ -2,12 +2,16 @@ require 'spec_helper'
|
|
2
2
|
require 'logger'
|
3
3
|
|
4
4
|
describe Received::LMTP do
|
5
|
-
let(:conn) { mock(:conn
|
5
|
+
let(:conn) { mock(:conn) }
|
6
6
|
let(:proto) { Received::LMTP.new(conn) }
|
7
7
|
|
8
|
+
before :all do
|
9
|
+
Received.logger = Logger.new(STDERR)
|
10
|
+
end
|
11
|
+
|
8
12
|
before do
|
9
13
|
conn.should_receive(:send_data).with("220 localhost LMTP server ready\r\n")
|
10
|
-
conn.logger.debug "*** Starting test ***"
|
14
|
+
#conn.logger.debug "*** Starting test ***"
|
11
15
|
proto.start!
|
12
16
|
end
|
13
17
|
|
@@ -17,7 +21,7 @@ describe Received::LMTP do
|
|
17
21
|
def begin_flow!
|
18
22
|
["LHLO", "MAIL FROM:<spec1@example.com>", "RCPT TO:<spec2@example.com>",
|
19
23
|
"RCPT TO:<spec3@example.com>", "DATA", "#{body}.", "QUIT"].each do |line|
|
20
|
-
conn.logger.debug "client: #{line}"
|
24
|
+
# conn.logger.debug "client: #{line}"
|
21
25
|
proto.on_data(line + "\r\n")
|
22
26
|
end
|
23
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: received
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: daemons
|