eventmachine-email_server-maildir 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +14 -0
- data/eventmachine-email_server-maildir.gemspec +27 -0
- data/lib/eventmachine/email_server/maildir.rb +75 -0
- data/lib/eventmachine/email_server/maildir/version.rb +9 -0
- data/test/helper.rb +7 -0
- data/test/test_maildir.rb +172 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 44f2c44b7b9867a5c66feee92fcfd7abba31068e
|
4
|
+
data.tar.gz: 511076f1aa04d2ebc4a6bdaec6297fa9ed479b5d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0bb6ce6b737cd35942e470af2bf9e3e38f11ab01000a828243d4b64ee6ad29159c27f8555ea518f792462906e92b6b46f75bb66bca04b0f8fc63eb1736718f80
|
7
|
+
data.tar.gz: a9012246a4bea7acc53146eed2503f9d30fa2076bb6cd8f71849423486c94f9ae385de7c1820e6e7350ac5343c8869d4d10913a0faacad3ab607d5e773b343bf
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
test/users
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 chrislee35
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Eventmachine::EmailServer::Maildir
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'eventmachine-email_server-maildir'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install eventmachine-email_server-maildir
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/eventmachine-email_server-maildir/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'eventmachine/email_server/maildir/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "eventmachine-email_server-maildir"
|
8
|
+
spec.version = EventMachine::EmailServer::Maildir::VERSION
|
9
|
+
spec.authors = ["chrislee35"]
|
10
|
+
spec.email = ["rubygems@chrislee.dhs.org"]
|
11
|
+
spec.summary = %q{Maildir backend store for eventmachine-email_server}
|
12
|
+
spec.description = %q{This provides the implementation of a user and email store for an EventMachine-based SMTP and POP3 server.}
|
13
|
+
spec.homepage = "https://github.com/chrislee35/eventmachine-email_server-maildir/"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "eventmachine-email_server", "~> 0.0.5"
|
22
|
+
spec.add_runtime_dependency "maildir", "~> 2.2.0"
|
23
|
+
spec.add_development_dependency "eventmachine", ">= 0.12.10"
|
24
|
+
spec.add_development_dependency "minitest", "~> 5.5"
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "eventmachine/email_server/maildir/version"
|
2
|
+
require 'eventmachine/email_server/base'
|
3
|
+
require 'maildir'
|
4
|
+
|
5
|
+
module EventMachine
|
6
|
+
module EmailServer
|
7
|
+
class MaildirEmailStore < AbstractEmailStore
|
8
|
+
def initialize(maildir_path = "/home/:user/Maildir")
|
9
|
+
@maildir_path = maildir_path
|
10
|
+
@user_maildirs = Hash.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_maildir(id)
|
14
|
+
if @user_maildirs[id].nil?
|
15
|
+
user_maildir_path = @maildir_path.gsub(/:user/, id)
|
16
|
+
puts user_maildir_path
|
17
|
+
@user_maildirs[id] = ::Maildir.new(user_maildir_path)
|
18
|
+
end
|
19
|
+
@user_maildirs[id]
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def emails_by_userid(id)
|
24
|
+
maildir = get_maildir(id)
|
25
|
+
messages = @user_maildirs[id].list(:new)
|
26
|
+
# convert into EventMachine::EmailServer::Email, place each message as the subject?
|
27
|
+
m = Array.new
|
28
|
+
counter = -1
|
29
|
+
messages = @user_maildirs[id].list(:new).map do |message|
|
30
|
+
# :id,:from,:to,:subject,:body,:uid,:marked
|
31
|
+
counter += 1
|
32
|
+
EventMachine::EmailServer::Email.new(counter, nil, nil, message.key, message.data, id, 'false')
|
33
|
+
end
|
34
|
+
messages
|
35
|
+
end
|
36
|
+
|
37
|
+
def save_email(email)
|
38
|
+
maildir = get_maildir(email.uid)
|
39
|
+
message = maildir.add(email.body)
|
40
|
+
message
|
41
|
+
end
|
42
|
+
|
43
|
+
def <<(email)
|
44
|
+
save_email(email)
|
45
|
+
end
|
46
|
+
|
47
|
+
def delete_email(email)
|
48
|
+
key = email.subject
|
49
|
+
maildir = get_maildir(email.uid)
|
50
|
+
message = maildir.get(key)
|
51
|
+
message.destroy
|
52
|
+
end
|
53
|
+
|
54
|
+
def -(email)
|
55
|
+
delete_email(email)
|
56
|
+
end
|
57
|
+
|
58
|
+
def delete_id(id)
|
59
|
+
raise "Unsupported in #{self.class}"
|
60
|
+
end
|
61
|
+
|
62
|
+
def delete_user(uid)
|
63
|
+
maildir = get_maildir(email.uid)
|
64
|
+
@user_maildirs[id].list(:new).map do |message|
|
65
|
+
message.destroy
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def count
|
70
|
+
raise "Unimplemented in #{self.class}"
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
unless Kernel.respond_to?(:require_relative)
|
4
|
+
module Kernel
|
5
|
+
def require_relative(path)
|
6
|
+
require File.join(File.dirname(caller[0]), path.to_str)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
require_relative 'helper'
|
12
|
+
require 'eventmachine'
|
13
|
+
require 'eventmachine/email_server'
|
14
|
+
require 'net/pop'
|
15
|
+
require 'net/smtp'
|
16
|
+
require 'fileutils'
|
17
|
+
include EventMachine::EmailServer
|
18
|
+
|
19
|
+
class EmailTemplate < Struct.new(:from, :to, :msg); end
|
20
|
+
|
21
|
+
class TestEmailServer < Minitest::Test
|
22
|
+
def setup
|
23
|
+
@test_vector = Proc.new { |test_name|
|
24
|
+
puts "***** #{test_name} *****"
|
25
|
+
(test_name.to_s =~ /maildir/)
|
26
|
+
}
|
27
|
+
@spam_email = EmailTemplate.new("friend@example.org", "chris@example.org", "From: friend@example.org
|
28
|
+
To: chris@example.org
|
29
|
+
Subject: What to do when you're not doing.
|
30
|
+
|
31
|
+
Could I interest you in some cialis?
|
32
|
+
")
|
33
|
+
@ham_email = EmailTemplate.new("friend@example.org", "chris@example.org", "From: friend@example.org
|
34
|
+
To: chris@example.org
|
35
|
+
Subject: Good show
|
36
|
+
|
37
|
+
Have you seen the latest Peppa Pig?
|
38
|
+
")
|
39
|
+
@default_email = EmailTemplate.new("friend@example.org", "chris@example.org", "From: friend@example.org
|
40
|
+
To: chris@example.org
|
41
|
+
Subject: Can't remember last night
|
42
|
+
|
43
|
+
Looks like we had fun!
|
44
|
+
")
|
45
|
+
@pool = EM::Pool.new
|
46
|
+
SMTPServer.reset
|
47
|
+
remove_scraps
|
48
|
+
create_test_maildir
|
49
|
+
end
|
50
|
+
|
51
|
+
def remove_scraps
|
52
|
+
FileUtils.remove_dir("test/users", true)
|
53
|
+
end
|
54
|
+
|
55
|
+
def teardown
|
56
|
+
remove_scraps
|
57
|
+
end
|
58
|
+
|
59
|
+
def create_test_maildir
|
60
|
+
FileUtils.mkdir_p("test/users/chris")
|
61
|
+
end
|
62
|
+
|
63
|
+
def setup_user(userstore)
|
64
|
+
userstore << User.new("chris", "chris", "chris", "chris@example.org")
|
65
|
+
end
|
66
|
+
|
67
|
+
def start_servers(userstore, emailstore)
|
68
|
+
pop3 = EventMachine::start_server "0.0.0.0", 2110, POP3Server, "example.org", userstore, emailstore
|
69
|
+
smtp = EventMachine::start_server "0.0.0.0", 2025, SMTPServer, "example.org", userstore, emailstore
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def send_email(email=@default_email, &callback)
|
74
|
+
smtp_dispatcher = EventMachine::ThreadedResource.new do
|
75
|
+
smtp = Net::SMTP.new('localhost', 2025)
|
76
|
+
end
|
77
|
+
|
78
|
+
@pool.add smtp_dispatcher
|
79
|
+
|
80
|
+
@pool.perform do |dispatcher|
|
81
|
+
completion = dispatcher.dispatch do |smtp|
|
82
|
+
ret = nil
|
83
|
+
smtp.start do |s|
|
84
|
+
begin
|
85
|
+
ret = s.send_message email.msg, email.from, email.to
|
86
|
+
rescue => e
|
87
|
+
ret = "451"
|
88
|
+
end
|
89
|
+
begin
|
90
|
+
smtp.quit
|
91
|
+
rescue => e
|
92
|
+
end
|
93
|
+
end
|
94
|
+
if ret.respond_to? :status
|
95
|
+
ret = ret.status
|
96
|
+
end
|
97
|
+
ret
|
98
|
+
end
|
99
|
+
|
100
|
+
completion.callback do |result|
|
101
|
+
callback.call(result)
|
102
|
+
end
|
103
|
+
|
104
|
+
completion
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def pop_email(&callback)
|
109
|
+
|
110
|
+
pop3_dispatcher = EventMachine::ThreadedResource.new do
|
111
|
+
end
|
112
|
+
|
113
|
+
@pool.add pop3_dispatcher
|
114
|
+
|
115
|
+
@pool.perform do |dispatcher|
|
116
|
+
completion = dispatcher.dispatch do |pop|
|
117
|
+
pop = Net::POP3.APOP(true).new('localhost',2110)
|
118
|
+
pop.start("chris","chris")
|
119
|
+
answers = Array.new
|
120
|
+
answers << pop.mails.empty?
|
121
|
+
if not pop.mails.empty?
|
122
|
+
pop.each_mail do |m|
|
123
|
+
answers << m.mail
|
124
|
+
m.delete
|
125
|
+
end
|
126
|
+
end
|
127
|
+
pop.finish
|
128
|
+
answers
|
129
|
+
end
|
130
|
+
|
131
|
+
completion.callback do |answers|
|
132
|
+
callback.call(answers)
|
133
|
+
end
|
134
|
+
|
135
|
+
completion
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def run_test(userstore, emailstore)
|
140
|
+
EM.run {
|
141
|
+
start_servers(userstore, emailstore)
|
142
|
+
EM::Timer.new(10) do
|
143
|
+
fail "Test timed out"
|
144
|
+
EM.stop
|
145
|
+
end
|
146
|
+
EM::Timer.new(0.1) do
|
147
|
+
pop_email do |answers|
|
148
|
+
assert_equal(true, answers[0])
|
149
|
+
send_email do |result|
|
150
|
+
assert_equal("250", result)
|
151
|
+
pop_email do |answers|
|
152
|
+
assert_equal(false, answers[0])
|
153
|
+
assert_equal(@default_email.msg.gsub(/[\r\n]+/,"\n"), answers[1].gsub(/[\r\n]+/,"\n"))
|
154
|
+
pop_email do |answers|
|
155
|
+
assert_equal(true, answers[0])
|
156
|
+
EM.stop
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
}
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_maildir_store
|
166
|
+
return unless @test_vector.call(__method__)
|
167
|
+
userstore = MemoryUserStore.new
|
168
|
+
emailstore = MaildirEmailStore.new("test/users/:user")
|
169
|
+
setup_user(userstore)
|
170
|
+
run_test(userstore, emailstore)
|
171
|
+
end
|
172
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eventmachine-email_server-maildir
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- chrislee35
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: eventmachine-email_server
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.5
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.5
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: maildir
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: eventmachine
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.12.10
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.12.10
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.6'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.6'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: This provides the implementation of a user and email store for an EventMachine-based
|
98
|
+
SMTP and POP3 server.
|
99
|
+
email:
|
100
|
+
- rubygems@chrislee.dhs.org
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- eventmachine-email_server-maildir.gemspec
|
111
|
+
- lib/eventmachine/email_server/maildir.rb
|
112
|
+
- lib/eventmachine/email_server/maildir/version.rb
|
113
|
+
- test/helper.rb
|
114
|
+
- test/test_maildir.rb
|
115
|
+
homepage: https://github.com/chrislee35/eventmachine-email_server-maildir/
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 2.2.2
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: Maildir backend store for eventmachine-email_server
|
139
|
+
test_files:
|
140
|
+
- test/helper.rb
|
141
|
+
- test/test_maildir.rb
|