received 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
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/tmp)') {|v| options[:dir] = v}
18
- opts.on('-l', '--log FILE', 'Log file name (default: piddir/received.log)') {|v| options[:logfile] = v}
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
- if options.delete(:daemon)
39
- require 'daemons'
40
- # Monkey patch to rename log file
41
- class Daemons::Application
42
- def output_logfile
43
- (options[:log_output] && logdir) ? File.join(logdir, @group.app_name + '.log') : nil
44
- end
45
- end
46
- params = {:app_name => 'received', :log_output => true, :dir_mode => :normal, :dir => options[:dir] || '/var/tmp'}
47
- # Drop privileges if started as superuser
48
- params.merge!({:user => options[:user] || 'nobody', :group => options[:group] || 'nobody'}) if Process.uid == 0
49
- Daemons.daemonize(params)
50
- File.umask(0007)
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!
@@ -52,7 +52,7 @@ module Received
52
52
  end
53
53
 
54
54
  def logger
55
- @server.logger
55
+ Received.logger
56
56
  end
57
57
  end
58
58
  end
data/lib/received/lmtp.rb CHANGED
@@ -29,7 +29,7 @@ module Received
29
29
  end
30
30
 
31
31
  def event(ev)
32
- @conn.logger.debug {"state was: #{@state.inspect}"}
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
- @conn.logger.debug {"state now: #{@state.inspect}"}
95
+ Received.logger.debug {"state now: #{@state.inspect}"}
96
96
  end
97
97
 
98
98
  def banner
@@ -5,11 +5,11 @@ require 'received/connection'
5
5
 
6
6
  module Received
7
7
  class Server
8
- attr_reader :logger, :options
8
+ attr_reader :options
9
9
 
10
10
  def initialize(options)
11
11
  @options = options
12
- @logger = options[:logger] || Logger.new($stderr)
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
@@ -1,3 +1,3 @@
1
1
  module Received
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/received.rb CHANGED
@@ -1,4 +1,11 @@
1
1
  module Received
2
+ def self.logger=(l)
3
+ @logger = l
4
+ end
5
+
6
+ def self.logger
7
+ @logger
8
+ end
2
9
  end
3
10
 
4
11
  require 'received/backend/base'
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, :logger => Logger.new(STDERR)) }
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.1
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-03 00:00:00.000000000 Z
12
+ date: 2012-10-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: daemons