received 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,6 +18,7 @@ OptionParser.new do |opts|
18
18
  opts.on('-l', '--log FILE', 'Log file name (default: piddir/received.log)') {|v| options[:logfile] = v}
19
19
  opts.on('-u', '--user NAME', 'Effective user when daemon (default: nobody)') {|v| options[:user] = v}
20
20
  opts.on('-g', '--group NAME', 'Effective group when daemon (default: nobody)') {|v| options[:group] = v}
21
+ opts.on('-r', '--require FILE1,FILE2,...', 'Require ruby file(s)') {|v| options[:require] = v}
21
22
  opts.on('-v', '--verbose', 'Verbose logging') {options[:level] = Logger::DEBUG}
22
23
  opts.on_tail('-h', '--help', 'Show this message') do
23
24
  puts opts
@@ -53,4 +54,9 @@ server = Received::Server.new(options)
53
54
  %w(TERM INT).each do |sig|
54
55
  Signal.trap(sig) {server.stop}
55
56
  end
57
+
58
+ if files = options[:require]
59
+ files.split(',').each { |file| require file }
60
+ end
61
+
56
62
  server.serve!
@@ -11,6 +11,33 @@ module Received
11
11
  def store(mail)
12
12
  raise NotImplementedError
13
13
  end
14
+
15
+ def notify_observers(*args)
16
+ self.class.notify_observers(*args)
17
+ end
18
+
19
+ class << self
20
+ def observers
21
+ @@observers ||= []
22
+ end
23
+
24
+ def add_observer(observer)
25
+ observers.push(observer)
26
+ end
27
+
28
+ def remove_observer(observer)
29
+ observers.delete(observer)
30
+ end
31
+
32
+ def notify_observers(method, payload)
33
+ observers.each do |observer|
34
+ if observer.respond_to?(method)
35
+ observer.send(method, payload) rescue nil
36
+ end
37
+ end
38
+ end
39
+ end
40
+
14
41
  end
15
42
  end
16
43
  end
@@ -21,7 +21,9 @@ module Received
21
21
  # @return [ObjectId] object_id
22
22
  def store(mail)
23
23
  mail = mail.merge(:ts => Time.now.to_i, :body => BSON::Binary.new(mail[:body]))
24
- @coll.insert(mail, :safe => {:fsync => true})
24
+ @coll.insert(mail, :safe => {:fsync => true}).tap do |result|
25
+ notify_observers(:after_save, result) if result
26
+ end
25
27
  end
26
28
  end
27
29
  end
@@ -1,3 +1,3 @@
1
1
  module Received
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -0,0 +1,19 @@
1
+ require 'received/backend/base'
2
+ require 'received/backend/mongodb'
3
+
4
+ describe 'Observable' do
5
+ subject { Received::Backend::Mongodb.new('host' => '127.0.0.1', 'database' => 'spec', 'collection' => 'inbox') }
6
+
7
+ it "notifies observers" do
8
+ observer = mock('observer', :after_save => true)
9
+ Received::Backend::Base.add_observer(observer)
10
+ mail = {
11
+ from: 'spec@example.com',
12
+ rcpt: ['to1@example.com', 'to2@example.com'],
13
+ body: 'spec'
14
+ }
15
+ observer.should_receive(:after_save)
16
+ subject.store(mail)
17
+ end
18
+
19
+ 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.0
4
+ version: 0.4.1
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-09-12 00:00:00.000000000 Z
12
+ date: 2012-10-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: daemons
@@ -98,6 +98,7 @@ files:
98
98
  - lib/received/server.rb
99
99
  - lib/received/version.rb
100
100
  - received.gemspec
101
+ - spec/backend_spec.rb
101
102
  - spec/lmtp_spec.rb
102
103
  - spec/spec_helper.rb
103
104
  homepage: ''
@@ -125,6 +126,7 @@ signing_key:
125
126
  specification_version: 3
126
127
  summary: Receive mail from Postfix and store it somewhere
127
128
  test_files:
129
+ - spec/backend_spec.rb
128
130
  - spec/lmtp_spec.rb
129
131
  - spec/spec_helper.rb
130
132
  has_rdoc: