mailman 0.5.2 → 0.5.3
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/README.md +14 -8
- data/USER_GUIDE.md +58 -38
- data/lib/mailman/application.rb +10 -7
- data/lib/mailman/configuration.rb +8 -0
- data/lib/mailman/receiver/imap.rb +10 -4
- data/lib/mailman/version.rb +1 -1
- metadata +45 -15
data/README.md
CHANGED
@@ -3,14 +3,16 @@
|
|
3
3
|
Mailman is an incoming mail processing microframework (with POP3 and Maildir
|
4
4
|
support), that works with Rails "out of the box".
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
```ruby
|
7
|
+
require 'mailman'
|
8
|
+
Mailman::Application.run do
|
9
|
+
to 'ticket-%id%@example.org' do
|
10
|
+
Ticket.find(params[:id]).add_reply(message)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
```
|
12
14
|
|
13
|
-
See the [User Guide](
|
15
|
+
See the [User Guide](https://github.com/titanous/mailman/blob/master/USER_GUIDE.md) for more information.
|
14
16
|
|
15
17
|
There is also a great [Getting Started Guide](http://dansowter.com/mailman-guide/) written by Dan Sowter.
|
16
18
|
|
@@ -21,7 +23,7 @@ There is also a great [Getting Started Guide](http://dansowter.com/mailman-guide
|
|
21
23
|
|
22
24
|
## Compatibility
|
23
25
|
|
24
|
-
Tested on
|
26
|
+
Tested on Ruby 1.8.7, 1.9.2, 1.9.3, REE, JRuby 1.7, and Rubinius.
|
25
27
|
|
26
28
|
### Dependencies
|
27
29
|
|
@@ -41,13 +43,17 @@ and my mentor was [Steven Soroka](http://github.com/ssoroka).
|
|
41
43
|
- [Nicolas Aguttes](http://github.com/tranquiliste)
|
42
44
|
- [Nathan Broadbent](https://github.com/ndbroadbent)
|
43
45
|
- [Tim Carey-Smith](http://github.com/halorgium)
|
46
|
+
- [Dan Cheail](https://github.com/DanCheail)
|
44
47
|
- [Francis Chong](https://github.com/siuying)
|
45
48
|
- [Kevin Glowacz](https://github.com/kjg)
|
46
49
|
- [Cyril Mougel](http://github.com/shingara)
|
50
|
+
- [Brian Palmer](https://github.com/codekitchen)
|
47
51
|
- [Phillip Ridlen](https://github.com/philtr)
|
48
52
|
- [Daniel Schierbeck](http://github.com/dasch)
|
49
53
|
- [Steven Soroka](http://github.com/ssoroka)
|
54
|
+
- [Benjamin Waldher](https://github.com/lgbr)
|
50
55
|
- [Ian White](http://github.com/ianwhite)
|
56
|
+
- [Andreas Wolff](https://github.com/rubyphunk)
|
51
57
|
|
52
58
|
|
53
59
|
## Copyright
|
data/USER_GUIDE.md
CHANGED
@@ -5,16 +5,18 @@ Mailman is a microframework for processing incoming email.
|
|
5
5
|
Here is an example Mailman app that takes incoming messages to a support
|
6
6
|
email account, and adds them to a database.
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
```ruby
|
9
|
+
# mailman_app.rb
|
10
|
+
require 'mailman'
|
10
11
|
|
11
|
-
|
12
|
+
Mailman.config.maildir = '~/Maildir'
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
Mailman::Application.run do
|
15
|
+
to 'support@example.org' do
|
16
|
+
Ticket.new_from_message(message)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
```
|
18
20
|
|
19
21
|
The Mailman app could then be started by running `ruby mailman_app.rb`.
|
20
22
|
|
@@ -63,9 +65,11 @@ the params helper (`params[:captures]`) as an Array, and as block arguments.
|
|
63
65
|
|
64
66
|
Routes are defined within a Mailman application block:
|
65
67
|
|
66
|
-
|
67
|
-
|
68
|
-
|
68
|
+
```ruby
|
69
|
+
Mailman::Application.run do
|
70
|
+
# routes here
|
71
|
+
end
|
72
|
+
```
|
69
73
|
|
70
74
|
Messages are passed through routes in the order they are defined in the
|
71
75
|
application from top to bottom. The first matching route's block will be
|
@@ -76,42 +80,54 @@ called.
|
|
76
80
|
Conditions can be chained so that the route will only be executed if all
|
77
81
|
conditions pass:
|
78
82
|
|
79
|
-
|
80
|
-
|
81
|
-
|
83
|
+
```ruby
|
84
|
+
to('support@example.org').subject(/urgent/) do
|
85
|
+
# process urgent message here
|
86
|
+
end
|
87
|
+
```
|
82
88
|
|
83
89
|
#### Special routes
|
84
90
|
|
85
91
|
The `default` route is a catch-all that is run if no other routes match:
|
86
92
|
|
87
|
-
|
88
|
-
|
89
|
-
|
93
|
+
```ruby
|
94
|
+
default do
|
95
|
+
# process non-matching messages
|
96
|
+
end
|
97
|
+
```
|
90
98
|
|
91
99
|
#### Block Arguments
|
92
100
|
|
93
101
|
All captures from matchers are available as block arguments:
|
94
102
|
|
95
|
-
|
96
|
-
|
97
|
-
|
103
|
+
```ruby
|
104
|
+
from('%user%@example.org').subject(/Ticket (\d+)/) do |username, ticket_id|
|
105
|
+
puts "Got message from #{username} about Ticket #{ticket_id}"
|
106
|
+
end
|
107
|
+
```
|
98
108
|
|
99
109
|
#### Class Routing
|
100
110
|
|
101
111
|
Messages can also be routed to methods. For instance, to route to an
|
102
112
|
Object with a `receive` instance method defined, this will work:
|
103
113
|
|
104
|
-
|
114
|
+
```ruby
|
115
|
+
from '%user%@example.org', Sample
|
116
|
+
```
|
105
117
|
|
106
118
|
Messages can also be routed to arbitrary instance methods:
|
107
119
|
|
108
|
-
|
120
|
+
```ruby
|
121
|
+
from '%user%@example.org', 'ExampleClass#new_message'
|
122
|
+
```
|
109
123
|
|
110
124
|
The method should accept two arguments, the message object, and the params:
|
111
125
|
|
112
|
-
|
113
|
-
|
114
|
-
|
126
|
+
```ruby
|
127
|
+
def receive(message, params)
|
128
|
+
# process message here
|
129
|
+
end
|
130
|
+
```
|
115
131
|
|
116
132
|
#### Route Helpers
|
117
133
|
|
@@ -119,12 +135,14 @@ There are two helpers available inside of route blocks:
|
|
119
135
|
|
120
136
|
The `params` hash holds all captures from matchers:
|
121
137
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
138
|
+
```ruby
|
139
|
+
from('%user%@example.org').subject(/RE: (.*)/) do
|
140
|
+
params[:user] #=> 'chunkybacon'
|
141
|
+
# it is an indifferent hash, so you can use strings and symbols
|
142
|
+
# interchangeably as keys
|
143
|
+
params['captures'][0] #=> 'A very important message about pigs'
|
144
|
+
end
|
145
|
+
```
|
128
146
|
|
129
147
|
The `message` helper is a `Mail::Message` object that contains the entire
|
130
148
|
message. See the [mail](http://github.com/mikel/mail/) docs for information on
|
@@ -201,13 +219,15 @@ set, Mailman will use POP3 polling as the receiver.
|
|
201
219
|
|
202
220
|
**Example**:
|
203
221
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
222
|
+
```ruby
|
223
|
+
Mailman.config.pop3 = {
|
224
|
+
:username => 'chunkybacon@gmail.com',
|
225
|
+
:password => 'foobar',
|
226
|
+
:server => 'pop.gmail.com',
|
227
|
+
:port => 995, # defaults to 110
|
228
|
+
:ssl => true # defaults to false
|
229
|
+
}
|
230
|
+
```
|
211
231
|
|
212
232
|
|
213
233
|
### Polling
|
data/lib/mailman/application.rb
CHANGED
@@ -68,20 +68,23 @@ module Mailman
|
|
68
68
|
# Maildir
|
69
69
|
elsif Mailman.config.maildir
|
70
70
|
require 'maildir'
|
71
|
-
require 'listen'
|
72
71
|
|
73
72
|
Mailman.logger.info "Maildir receiver enabled (#{Mailman.config.maildir})."
|
74
73
|
@maildir = Maildir.new(Mailman.config.maildir)
|
74
|
+
|
75
75
|
process_maildir
|
76
76
|
|
77
|
-
Mailman.
|
77
|
+
if Mailman.config.watch_maildir
|
78
|
+
require 'listen'
|
79
|
+
Mailman.logger.debug "Monitoring the Maildir for new messages..."
|
78
80
|
|
79
|
-
|
80
|
-
|
81
|
-
|
81
|
+
callback = Proc.new do |modified, added, removed|
|
82
|
+
process_maildir
|
83
|
+
end
|
82
84
|
|
83
|
-
|
84
|
-
|
85
|
+
@listener = Listen.to(File.join(Mailman.config.maildir, 'new')).change(&callback)
|
86
|
+
@listener.start
|
87
|
+
end
|
85
88
|
end
|
86
89
|
end
|
87
90
|
|
@@ -14,6 +14,10 @@ module Mailman
|
|
14
14
|
# @return [String] the path to the maildir
|
15
15
|
attr_accessor :maildir
|
16
16
|
|
17
|
+
# @return [boolean] whether or not to watch for new messages in the maildir.
|
18
|
+
# Settings this to false disables listening for file changes if using the Maildir receiver.
|
19
|
+
attr_accessor :watch_maildir
|
20
|
+
|
17
21
|
# @return [String] the path to the rails root. Setting this to false to stop
|
18
22
|
# the rails environment from loading
|
19
23
|
attr_accessor :rails_root
|
@@ -35,6 +39,10 @@ module Mailman
|
|
35
39
|
@poll_interval ||= 60
|
36
40
|
end
|
37
41
|
|
42
|
+
def watch_maildir
|
43
|
+
@watch_maildir.nil? ? true : @watch_maildir
|
44
|
+
end
|
45
|
+
|
38
46
|
def rails_root
|
39
47
|
@rails_root.nil? ? '.' : @rails_root
|
40
48
|
end
|
@@ -13,22 +13,28 @@ module Mailman
|
|
13
13
|
# messages to
|
14
14
|
# @option options [String] :server the server to connect to
|
15
15
|
# @option options [Integer] :port the port to connect to
|
16
|
+
# @option options [Boolean] :ssl whether or not to use ssl
|
16
17
|
# @option options [String] :username the username to authenticate with
|
17
18
|
# @option options [String] :password the password to authenticate with
|
19
|
+
# @option options [String] :folder the mail folder to search
|
18
20
|
def initialize(options)
|
19
21
|
@processor = options[:processor]
|
22
|
+
@server = options[:server]
|
20
23
|
@username = options[:username]
|
21
24
|
@password = options[:password]
|
22
25
|
@filter = options[:filter] || ['NEW']
|
23
26
|
@port = options[:port] || 143
|
24
|
-
|
25
|
-
@
|
27
|
+
@ssl = options[:ssl] || false
|
28
|
+
@folder = options[:folder] || "INBOX"
|
26
29
|
end
|
27
30
|
|
28
31
|
# Connects to the IMAP server.
|
29
32
|
def connect
|
30
|
-
@connection.
|
31
|
-
|
33
|
+
if @connection.nil? or @connection.disconnected?
|
34
|
+
@connection = Net::IMAP.new(@server, @port, @ssl)
|
35
|
+
@connection.login(@username, @password)
|
36
|
+
end
|
37
|
+
@connection.select(@folder)
|
32
38
|
end
|
33
39
|
|
34
40
|
# Disconnects from the IMAP server.
|
data/lib/mailman/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
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: 2012-
|
12
|
+
date: 2012-08-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mail
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 2.0.3
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.0.3
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: activesupport
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: 2.3.4
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.3.4
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: listen
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: 0.4.1
|
44
54
|
type: :runtime
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.4.1
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: maildir
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: 0.5.0
|
55
70
|
type: :runtime
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.5.0
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: i18n
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ! '>='
|
@@ -65,10 +85,15 @@ dependencies:
|
|
65
85
|
version: 0.4.1
|
66
86
|
type: :runtime
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.4.1
|
69
94
|
- !ruby/object:Gem::Dependency
|
70
95
|
name: rspec
|
71
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
72
97
|
none: false
|
73
98
|
requirements:
|
74
99
|
- - ~>
|
@@ -76,7 +101,12 @@ dependencies:
|
|
76
101
|
version: '2.10'
|
77
102
|
type: :development
|
78
103
|
prerelease: false
|
79
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '2.10'
|
80
110
|
description: Mailman makes it easy to process incoming emails with a simple routing
|
81
111
|
DSL
|
82
112
|
email:
|
@@ -124,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
154
|
version: '0'
|
125
155
|
requirements: []
|
126
156
|
rubyforge_project: mailman
|
127
|
-
rubygems_version: 1.8.
|
157
|
+
rubygems_version: 1.8.23
|
128
158
|
signing_key:
|
129
159
|
specification_version: 3
|
130
160
|
summary: A incoming email processing microframework
|