asterisk-mailcmd 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +27 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +59 -0
- data/LICENSE.txt +22 -0
- data/README.md +111 -0
- data/README.rdoc +23 -0
- data/Rakefile +62 -0
- data/asterisk-mailcmd.gemspec +29 -0
- data/bin/asterisk-mailcmd +43 -0
- data/features/asterisk-mailcmd.feature +13 -0
- data/features/step_definitions/asterisk-mailcmd_steps.rb +1 -0
- data/features/support/env.rb +16 -0
- data/lib/asterisk/mailcmd.rb +8 -0
- data/lib/asterisk/mailcmd/email.rb +119 -0
- data/lib/asterisk/mailcmd/settings.rb +30 -0
- data/lib/asterisk/mailcmd/version.rb +5 -0
- data/sample/html_email.png +0 -0
- data/sample/html_tmpl.erb +96 -0
- data/sample/mailcmd.rvm.sh +16 -0
- data/sample/text_tmpl.erb +19 -0
- data/test/fixtures/email.text +43 -0
- data/test/fixtures/html_tmpl.erb +96 -0
- data/test/fixtures/text_tmpl.erb +19 -0
- data/test/helper.rb +25 -0
- data/test/test_read_stdin.rb +42 -0
- data/test/test_set_mail_send.rb +100 -0
- data/test/test_set_tmpl.rb +61 -0
- data/test/test_settings.rb +51 -0
- metadata +196 -0
data/test/helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'mocha/setup'
|
3
|
+
require 'stringio'
|
4
|
+
require 'methadone'
|
5
|
+
require 'asterisk/mailcmd'
|
6
|
+
|
7
|
+
require 'pp'
|
8
|
+
|
9
|
+
class MiniTest::Unit::TestCase
|
10
|
+
def mock_ast_stdin
|
11
|
+
# get raw email from fixture file
|
12
|
+
file = File.expand_path('fixtures/email.text',File.dirname(__FILE__))
|
13
|
+
# return mocked IO
|
14
|
+
StringIO.new(File.read file)
|
15
|
+
end
|
16
|
+
|
17
|
+
def html_tmpl_file_path
|
18
|
+
File.expand_path('fixtures/html_tmpl.erb',File.dirname(__FILE__))
|
19
|
+
end
|
20
|
+
|
21
|
+
def text_tmpl_file_path
|
22
|
+
File.expand_path('fixtures/text_tmpl.erb',File.dirname(__FILE__))
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'helper'
|
2
|
+
include Asterisk::Mailcmd
|
3
|
+
|
4
|
+
describe Email, "reading email data from Asterisk" do
|
5
|
+
|
6
|
+
before do # setup
|
7
|
+
$stdin = mock_ast_stdin
|
8
|
+
end
|
9
|
+
|
10
|
+
after do #teardown
|
11
|
+
$stdin = STDIN
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "Reading from Asterisk" do
|
15
|
+
|
16
|
+
it "must read valid raw email from STDIO" do
|
17
|
+
email = Email.read
|
18
|
+
email.rawdata.size.must_be :>, 0
|
19
|
+
end
|
20
|
+
|
21
|
+
it "must return false if invalid raw email message" do
|
22
|
+
# Valid raw email must endin
|
23
|
+
# with full stop (period) on new line
|
24
|
+
# RFC772: The last line must consist of only a single period.
|
25
|
+
$stdin.stubs(:read).once.returns("This is invalid \n.\nraw email")
|
26
|
+
email = Email.read
|
27
|
+
email.raw_valid?.must_equal false
|
28
|
+
end
|
29
|
+
|
30
|
+
it "must return true if valid raw email" do
|
31
|
+
email = Email.read
|
32
|
+
email.raw_valid?.must_equal true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "must read mail to Mail class instance" do
|
36
|
+
Email.read.
|
37
|
+
mail.from.first.
|
38
|
+
must_equal "asterisk@localhost.localdomain"
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'helper'
|
2
|
+
include Asterisk::Mailcmd
|
3
|
+
include Mail::Matchers
|
4
|
+
|
5
|
+
describe Email, "setting up and delivering email" do
|
6
|
+
|
7
|
+
before do # setup
|
8
|
+
@html_tmpl_path = html_tmpl_file_path # helper method
|
9
|
+
@text_tmpl_path = text_tmpl_file_path
|
10
|
+
$stdin = mock_ast_stdin
|
11
|
+
end
|
12
|
+
|
13
|
+
after do #teardown
|
14
|
+
$stdin = STDIN
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "Setting up email" do
|
18
|
+
|
19
|
+
it "must set email date to now" do
|
20
|
+
email = Email.read
|
21
|
+
# stub date
|
22
|
+
time = Time.new
|
23
|
+
Time.stubs(:now).returns(time)
|
24
|
+
email.set_date
|
25
|
+
email.mail.date.to_time. # Mail.date is DateTime class
|
26
|
+
to_s.must_equal time.to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
it "must set default date" do
|
30
|
+
email = Email.read
|
31
|
+
time = Time.now
|
32
|
+
email.set_date time
|
33
|
+
email.mail.date.to_time.
|
34
|
+
to_s.must_equal time.to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
it "must raise when invalid Time object" do
|
38
|
+
email = Email.read
|
39
|
+
proc {
|
40
|
+
email.set_date "some time"
|
41
|
+
}.must_raise ArgumentError
|
42
|
+
end
|
43
|
+
|
44
|
+
it "must return charset UTF-8 by default" do
|
45
|
+
email = Email.read
|
46
|
+
email.get_charset.must_equal 'UTF-8'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "must set charset" do
|
50
|
+
email = Email.read
|
51
|
+
email.charset = 'ASCII'
|
52
|
+
email.get_charset.must_equal 'ASCII'
|
53
|
+
end
|
54
|
+
|
55
|
+
it "must set html template with charset ISO-8859-1" do
|
56
|
+
email = Email.read
|
57
|
+
email.extract_vars
|
58
|
+
email.set_date
|
59
|
+
chrst = 'ISO-8859-1'
|
60
|
+
email.charset = chrst
|
61
|
+
Settings.read @text_tmpl_path, :text
|
62
|
+
email.text_tmpl Settings.text_tmpl
|
63
|
+
Settings.read @html_tmpl_path
|
64
|
+
email.html_tmpl Settings.html_tmpl
|
65
|
+
email.mail.html_part.content_type.must_match(/charset=#{chrst}/)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "must set default deliver method and params" do
|
69
|
+
email = Email.read
|
70
|
+
email.delivery_method.must_equal :sendmail
|
71
|
+
email.delivery_params.class.must_equal Hash
|
72
|
+
email.delivery_params.size.must_equal 0
|
73
|
+
end
|
74
|
+
|
75
|
+
it "must raise if set_and_send has no text templates set" do
|
76
|
+
proc {
|
77
|
+
Email.set_and_send :charset => 'UTF-8'
|
78
|
+
}.must_raise InvalidTxtTmpl
|
79
|
+
end
|
80
|
+
|
81
|
+
it "must raise if set_and_send has no HTML templates set" do
|
82
|
+
proc {
|
83
|
+
Email.set_and_send :text_tmpl => @text_tmpl_path
|
84
|
+
}.must_raise InvalidHtmlTmpl
|
85
|
+
end
|
86
|
+
|
87
|
+
it "must send email with set_and_send" do
|
88
|
+
Email.set_and_send :text_tmpl => @text_tmpl_path,
|
89
|
+
:html_tmpl => @html_tmpl_path,
|
90
|
+
:charset => 'ISO-8859-1',
|
91
|
+
:delivery_method => :test
|
92
|
+
# should send one email
|
93
|
+
Mail::TestMailer.deliveries.length.must_equal 1
|
94
|
+
Mail::TestMailer.deliveries.first.from.first.must_equal "asterisk@localhost.localdomain"
|
95
|
+
Mail::TestMailer.deliveries.first.html_part.content_type.must_match(/charset=ISO-8859-1/)
|
96
|
+
Mail::TestMailer.deliveries.first.html_part.body.decoded.must_match(/2275550168/)
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'helper'
|
2
|
+
include Asterisk::Mailcmd
|
3
|
+
|
4
|
+
describe Email, "Body templates" do
|
5
|
+
|
6
|
+
before do # setup
|
7
|
+
@html_tmpl_path = html_tmpl_file_path # helper method
|
8
|
+
@text_tmpl_path = text_tmpl_file_path
|
9
|
+
$stdin = mock_ast_stdin
|
10
|
+
end
|
11
|
+
|
12
|
+
after do #teardown
|
13
|
+
$stdin = STDIN
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "Setting up email variables and templates" do
|
17
|
+
|
18
|
+
it "must extract Asterisk variables from email" do
|
19
|
+
email = Email.read
|
20
|
+
email.extract_vars
|
21
|
+
# see fixtures for expected values
|
22
|
+
email.astvars[:VM_CIDNUM].must_equal "2275550168"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "must set email HTML tamplate and inline variables" do
|
26
|
+
email = Email.read
|
27
|
+
email.extract_vars
|
28
|
+
Settings.read @html_tmpl_path
|
29
|
+
email.html_tmpl Settings.html_tmpl
|
30
|
+
email.htmlpart.must_match(email.astvars[:VM_CIDNUM])
|
31
|
+
email.mail.html_part.body.decoded.
|
32
|
+
must_match(email.astvars[:VM_CIDNUM])
|
33
|
+
end
|
34
|
+
|
35
|
+
it "must raise if variables were not extracted" do
|
36
|
+
proc {
|
37
|
+
email = Email.read
|
38
|
+
Settings.read @html_tmpl_path
|
39
|
+
email.html_tmpl Settings.html_tmpl
|
40
|
+
}.must_raise ArgumentError
|
41
|
+
end
|
42
|
+
|
43
|
+
it "must raise if invalid template type" do
|
44
|
+
proc {
|
45
|
+
email = Email.read
|
46
|
+
email.tmpl "template text", :unknown_type
|
47
|
+
}.must_raise ArgumentError
|
48
|
+
end
|
49
|
+
|
50
|
+
it "must set email TEXT tamplate and inline variables" do
|
51
|
+
email = Email.read
|
52
|
+
email.extract_vars
|
53
|
+
Settings.read @text_tmpl_path, :text
|
54
|
+
email.text_tmpl Settings.text_tmpl
|
55
|
+
email.textpart.must_match(email.astvars[:VM_CIDNUM])
|
56
|
+
email.mail.text_part.body.decoded.
|
57
|
+
must_match(email.astvars[:VM_CIDNUM])
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'helper'
|
2
|
+
include Asterisk::Mailcmd
|
3
|
+
|
4
|
+
describe Settings, "Application settings" do
|
5
|
+
|
6
|
+
before do # setup
|
7
|
+
# helper methods
|
8
|
+
@html_tmpl_path = html_tmpl_file_path
|
9
|
+
@text_tmpl_path = text_tmpl_file_path
|
10
|
+
end
|
11
|
+
|
12
|
+
after do #teardown
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "Settings processing" do
|
16
|
+
|
17
|
+
it "must raise ArgumentError if template file does not exist" do
|
18
|
+
File.stubs(:exists?).once.returns(false)
|
19
|
+
proc {
|
20
|
+
Settings.read('/not/existing/file.tmpl')
|
21
|
+
}.must_raise ArgumentError
|
22
|
+
end
|
23
|
+
|
24
|
+
it "must raise ArgumentError if template file is not readable" do
|
25
|
+
File.stubs(:exists?).once.returns(true)
|
26
|
+
File.stubs(:readable?).once.returns(false)
|
27
|
+
proc {
|
28
|
+
Settings.read('/not/readable/file.tmpl')
|
29
|
+
}.must_raise ArgumentError
|
30
|
+
end
|
31
|
+
|
32
|
+
it "must set instance variable after reading html template file" do
|
33
|
+
Settings.read(@html_tmpl_path, :html).must_equal Settings.html_tmpl
|
34
|
+
end
|
35
|
+
|
36
|
+
it "must set instance variable after reading text template file" do
|
37
|
+
Settings.read(@text_tmpl_path, :text).must_equal Settings.text_tmpl
|
38
|
+
end
|
39
|
+
|
40
|
+
it "must set default template as html" do
|
41
|
+
Settings.read(@html_tmpl_path, :html).must_equal Settings.read(@html_tmpl_path)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "must raise ArgumentError when template type is invalid" do
|
45
|
+
proc {
|
46
|
+
Settings.read(@html_tmpl_path, :unknown_template_type)
|
47
|
+
}.must_raise ArgumentError
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: asterisk-mailcmd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stas Kobzar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rdoc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: aruba
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mocha
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
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.9.2
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.9.2
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: mail
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: methadone
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.2.6
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.2.6
|
125
|
+
description: Asterisk voicemail emails enhancement
|
126
|
+
email:
|
127
|
+
- stas@modulis.ca
|
128
|
+
executables:
|
129
|
+
- asterisk-mailcmd
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- .gitignore
|
134
|
+
- Gemfile
|
135
|
+
- Gemfile.lock
|
136
|
+
- LICENSE.txt
|
137
|
+
- README.md
|
138
|
+
- README.rdoc
|
139
|
+
- Rakefile
|
140
|
+
- asterisk-mailcmd.gemspec
|
141
|
+
- bin/asterisk-mailcmd
|
142
|
+
- features/asterisk-mailcmd.feature
|
143
|
+
- features/step_definitions/asterisk-mailcmd_steps.rb
|
144
|
+
- features/support/env.rb
|
145
|
+
- lib/asterisk/mailcmd.rb
|
146
|
+
- lib/asterisk/mailcmd/email.rb
|
147
|
+
- lib/asterisk/mailcmd/settings.rb
|
148
|
+
- lib/asterisk/mailcmd/version.rb
|
149
|
+
- sample/html_email.png
|
150
|
+
- sample/html_tmpl.erb
|
151
|
+
- sample/mailcmd.rvm.sh
|
152
|
+
- sample/text_tmpl.erb
|
153
|
+
- test/fixtures/email.text
|
154
|
+
- test/fixtures/html_tmpl.erb
|
155
|
+
- test/fixtures/text_tmpl.erb
|
156
|
+
- test/helper.rb
|
157
|
+
- test/test_read_stdin.rb
|
158
|
+
- test/test_set_mail_send.rb
|
159
|
+
- test/test_set_tmpl.rb
|
160
|
+
- test/test_settings.rb
|
161
|
+
homepage: http://www.modulis.ca
|
162
|
+
licenses:
|
163
|
+
- MIT
|
164
|
+
metadata: {}
|
165
|
+
post_install_message:
|
166
|
+
rdoc_options: []
|
167
|
+
require_paths:
|
168
|
+
- lib
|
169
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - ! '>='
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
179
|
+
requirements: []
|
180
|
+
rubyforge_project:
|
181
|
+
rubygems_version: 2.0.2
|
182
|
+
signing_key:
|
183
|
+
specification_version: 4
|
184
|
+
summary: ! 'Command to use with Asterisk mailcmp option. See: voicemail.conf'
|
185
|
+
test_files:
|
186
|
+
- features/asterisk-mailcmd.feature
|
187
|
+
- features/step_definitions/asterisk-mailcmd_steps.rb
|
188
|
+
- features/support/env.rb
|
189
|
+
- test/fixtures/email.text
|
190
|
+
- test/fixtures/html_tmpl.erb
|
191
|
+
- test/fixtures/text_tmpl.erb
|
192
|
+
- test/helper.rb
|
193
|
+
- test/test_read_stdin.rb
|
194
|
+
- test/test_set_mail_send.rb
|
195
|
+
- test/test_set_tmpl.rb
|
196
|
+
- test/test_settings.rb
|