asterisk-mailcmd 0.0.1
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.
- 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
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NTdkMjFjYTkwZTNlNDUzY2UwYTkxYWEyM2FmYzZjYjlmNzAyMzdhYQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YmI2ZGI1YmZiMzhkMDM4NDExNzUzMWYxNWM5ZTc1NTEwNDg4NWIxOA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
Y2Q0MWIwZDY5Y2EyOWM1MDBhZmNmNmQ4ZTcyM2YwMTNiODY4NDFjNzM3OGFh
|
10
|
+
MGJmM2I3MDMxOGU5NTU3ZjAwYWQ0ZWVhYzBjNzRlMWEyZWU4NzFjNmRhMDkw
|
11
|
+
OWQ2NzM4Mzg1MTcxYWU5NDExMDcyYjkwMTg3ZTM0MzVmNmM2YTI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MzY5MjJhNzkzNmE4NmU3ZjRiNzcxNmY5YmNhYzA0MTFmOTJkZTAzZTQ1ODYx
|
14
|
+
ZjNkMWUyM2MyNzRlMDY5Mjc4MDU2MzdkZTdlNmJkNGQ5NWUwYWZjOTg4ZDc4
|
15
|
+
ZTM3ZTg1NWUyYjQzMDBiNGJiMGU4ZjUyYzdlZWYxMTVmN2JjOTA=
|
data/.gitignore
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Ignore temporary files
|
2
|
+
.*swp
|
3
|
+
*~
|
4
|
+
|
5
|
+
*.gem
|
6
|
+
*.rbc
|
7
|
+
.bundle
|
8
|
+
.config
|
9
|
+
coverage
|
10
|
+
InstalledFiles
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
|
19
|
+
# YARD artifacts
|
20
|
+
.yardoc
|
21
|
+
_yardoc
|
22
|
+
doc/
|
23
|
+
|
24
|
+
.DS_Store
|
25
|
+
results.html
|
26
|
+
html
|
27
|
+
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
asterisk-mailcmd (0.0.1)
|
5
|
+
mail
|
6
|
+
methadone (~> 1.2.6)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
aruba (0.5.1)
|
12
|
+
childprocess (~> 0.3.6)
|
13
|
+
cucumber (>= 1.1.1)
|
14
|
+
rspec-expectations (>= 2.7.0)
|
15
|
+
builder (3.2.0)
|
16
|
+
childprocess (0.3.9)
|
17
|
+
ffi (~> 1.0, >= 1.0.11)
|
18
|
+
cucumber (1.2.3)
|
19
|
+
builder (>= 2.1.2)
|
20
|
+
diff-lcs (>= 1.1.3)
|
21
|
+
gherkin (~> 2.11.6)
|
22
|
+
multi_json (~> 1.3)
|
23
|
+
diff-lcs (1.2.1)
|
24
|
+
ffi (1.4.0)
|
25
|
+
gherkin (2.11.6)
|
26
|
+
json (>= 1.7.6)
|
27
|
+
i18n (0.6.4)
|
28
|
+
json (1.7.7)
|
29
|
+
mail (2.5.3)
|
30
|
+
i18n (>= 0.4.0)
|
31
|
+
mime-types (~> 1.16)
|
32
|
+
treetop (~> 1.4.8)
|
33
|
+
metaclass (0.0.1)
|
34
|
+
methadone (1.2.6)
|
35
|
+
bundler
|
36
|
+
mime-types (1.21)
|
37
|
+
mocha (0.13.3)
|
38
|
+
metaclass (~> 0.0.1)
|
39
|
+
multi_json (1.6.1)
|
40
|
+
polyglot (0.3.3)
|
41
|
+
rake (0.9.6)
|
42
|
+
rdoc (4.0.0)
|
43
|
+
json (~> 1.4)
|
44
|
+
rspec-expectations (2.13.0)
|
45
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
46
|
+
treetop (1.4.12)
|
47
|
+
polyglot
|
48
|
+
polyglot (>= 0.3.1)
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
aruba
|
55
|
+
asterisk-mailcmd!
|
56
|
+
bundler (~> 1.3)
|
57
|
+
mocha
|
58
|
+
rake (~> 0.9.2)
|
59
|
+
rdoc
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Stas Kobzar
|
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,111 @@
|
|
1
|
+
# Asterisk::Mailcmd
|
2
|
+
|
3
|
+
# Extending Asterisk voicemail message body for emails
|
4
|
+
|
5
|
+
Asterisk Voicemail email seems to be quite limited when it comes about
|
6
|
+
configuring email body:
|
7
|
+
* Email body is a one line text with backslash escapes and Asterisk variables.
|
8
|
+
* It is limited to *512* characters (see voicemail.conf.sample)
|
9
|
+
|
10
|
+
Under these circumstances it is impossible to create nice looking, formatted emails,
|
11
|
+
to have individual email templates per user or multi-languages emails' templates.
|
12
|
+
|
13
|
+
This simple a simple library which is supposed to address these shortcomings.
|
14
|
+
|
15
|
+
## HTML Voicemail notification example
|
16
|
+

|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
### Library for your application
|
21
|
+
Add this line to your application's Gemfile:
|
22
|
+
|
23
|
+
gem 'asterisk-mailcmd', :git => git://github.com/staskobzar/asterisk-mailcmd.git
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
$ bundle
|
28
|
+
|
29
|
+
### Command line application
|
30
|
+
Or install it yourself as:
|
31
|
+
|
32
|
+
$ git clone git://github.com/staskobzar/asterisk-mailcmd.git
|
33
|
+
$ cd asterisk-mailcmd
|
34
|
+
$ gem build asterisk-mailcmd.gemspec
|
35
|
+
$ gem install asterisk-mailcmd-X.X.X.gem
|
36
|
+
|
37
|
+
## Asterisk configuration
|
38
|
+
Asterisk voice mail must be configured to run this library when new voicemail received. There is an option **mailcmd** in voicemail.conf which must link to the executable script with this library:
|
39
|
+
|
40
|
+
mailcmd=/usr/local/bin/mailcmd
|
41
|
+
|
42
|
+
Another option that must be set is the `mailbody` :
|
43
|
+
```
|
44
|
+
mailbody=VM_NAME:${VM_NAME}\nVM_DUR:${VM_DUR}\nVM_MSGNUM:${VM_MSGNUM}\nVM_MAILBOX:${VM_MAILBOX}\nVM_CALLERID:${VM_CALLERID}\nVM_CIDNUM:${VM_CIDNUM}\nVM_CIDNAME:${VM_CIDNAME}\nVM_DATE:${VM_DATE}\nVM_MESSAGEFILE:${VM_MESSAGEFILE}
|
45
|
+
```
|
46
|
+
|
47
|
+
This is a list of variables that will be used in ERB templates.
|
48
|
+
|
49
|
+
You can not use *asterisk-mailcmd* CLI application installed with this gem directly as a reference in in option **mailcmd** because Asterisk when asterisk run the command, it will not have information about your environment like path to ruby interpreter.
|
50
|
+
For that you must have a wrapper. Example of the wrapper can be found with the source: "sample/mailcmd.rvm.sh". Here is sample code:
|
51
|
+
|
52
|
+
|
53
|
+
```bash
|
54
|
+
|
55
|
+
#!/bin/sh
|
56
|
+
|
57
|
+
# This is as simple wrapper for ruby application asterisk-mailcmd
|
58
|
+
# when using RVM (Ruby Version Manager: https://rvm.io/)
|
59
|
+
|
60
|
+
# path to HTML and TEXT templates in ERB format
|
61
|
+
# see samples in "sample" directory
|
62
|
+
HTML_TMPL=/etc/asterisk/vmtemplate/html.erb
|
63
|
+
TEXT_TMPL=/etc/asterisk/vmtemplate/text.erb
|
64
|
+
|
65
|
+
# load RVM profile
|
66
|
+
source /etc/profile.d/rvm.sh
|
67
|
+
# run mail command
|
68
|
+
asterisk-mailcmd -t $TEXT_TMPL -m $HTML_TMPL
|
69
|
+
|
70
|
+
exit 0
|
71
|
+
|
72
|
+
```
|
73
|
+
|
74
|
+
Save this to file */usr/local/bin/mailcmd*, just like it is set with **mailcmd** option.
|
75
|
+
Make sure that the file is executable.
|
76
|
+
|
77
|
+
|
78
|
+
### Ruby gem library
|
79
|
+
You can create your own ruby script:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
require 'asterisk/mailcmd'
|
83
|
+
|
84
|
+
Asterisk::Mailcmd::Email.set_and_send :text_tmpl => '/path/text.erb',
|
85
|
+
:html_tmpl => '/path/html.erb'
|
86
|
+
```
|
87
|
+
|
88
|
+
## `Asterisk::Mailcmd::Email.set_and_send` parameters list:
|
89
|
+
|
90
|
+
```
|
91
|
+
:html_tmpl => String: MANDATORY: HTML part ERB template file path
|
92
|
+
:text_tmpl => String: MANDATORY: Text part ERB template file path
|
93
|
+
:charset => String: OPTIONAL: Content type charset
|
94
|
+
:date => Time: OPTIONAL: Email date
|
95
|
+
```
|
96
|
+
## Templates
|
97
|
+
Templates are ERB format with variables that are set with Asterisk (see option *mailbody*):
|
98
|
+
|
99
|
+
```
|
100
|
+
<h1>There is new mail in mailbox: <%= @astvars[:VM_MAILBOX].to_s %> </h1>
|
101
|
+
```
|
102
|
+
There are two example files in directory *sample*.
|
103
|
+
|
104
|
+
## Contributing
|
105
|
+
|
106
|
+
1. Fork it
|
107
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
108
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
109
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
110
|
+
5. Create new Pull Request
|
111
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
= asterisk-mailcmd - DESCRIBE YOUR GEM
|
2
|
+
|
3
|
+
Author:: YOUR NAME (YOUR EMAIL)
|
4
|
+
Copyright:: Copyright (c) 2013 YOUR NAME
|
5
|
+
|
6
|
+
|
7
|
+
License:: mit, see LICENSE.txt
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
DESCRIBE YOUR GEM HERE
|
12
|
+
|
13
|
+
== Links
|
14
|
+
|
15
|
+
* {Source on Github}[LINK TO GITHUB]
|
16
|
+
* RDoc[LINK TO RDOC.INFO]
|
17
|
+
|
18
|
+
== Install
|
19
|
+
|
20
|
+
== Examples
|
21
|
+
|
22
|
+
== Contributing
|
23
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
def dump_load_path
|
2
|
+
puts $LOAD_PATH.join("\n")
|
3
|
+
found = nil
|
4
|
+
$LOAD_PATH.each do |path|
|
5
|
+
if File.exists?(File.join(path,"rspec"))
|
6
|
+
puts "Found rspec in #{path}"
|
7
|
+
if File.exists?(File.join(path,"rspec","core"))
|
8
|
+
puts "Found core"
|
9
|
+
if File.exists?(File.join(path,"rspec","core","rake_task"))
|
10
|
+
puts "Found rake_task"
|
11
|
+
found = path
|
12
|
+
else
|
13
|
+
puts "!! no rake_task"
|
14
|
+
end
|
15
|
+
else
|
16
|
+
puts "!!! no core"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
if found.nil?
|
21
|
+
puts "Didn't find rspec/core/rake_task anywhere"
|
22
|
+
else
|
23
|
+
puts "Found in #{path}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
require 'bundler'
|
27
|
+
require 'rake/clean'
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
|
31
|
+
require 'cucumber'
|
32
|
+
require 'cucumber/rake/task'
|
33
|
+
gem 'rdoc' # we need the installed RDoc gem, not the system one
|
34
|
+
require 'rdoc/task'
|
35
|
+
|
36
|
+
include Rake::DSL
|
37
|
+
|
38
|
+
Bundler::GemHelper.install_tasks
|
39
|
+
|
40
|
+
|
41
|
+
Rake::TestTask.new do |t|
|
42
|
+
t.libs << 'test'
|
43
|
+
t.pattern = 'test/test_*.rb'
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
CUKE_RESULTS = 'results.html'
|
48
|
+
CLEAN << CUKE_RESULTS
|
49
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
50
|
+
t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
|
51
|
+
t.fork = false
|
52
|
+
end
|
53
|
+
|
54
|
+
Rake::RDocTask.new do |rd|
|
55
|
+
|
56
|
+
rd.main = "README.rdoc"
|
57
|
+
|
58
|
+
rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
|
59
|
+
end
|
60
|
+
|
61
|
+
task :default => [:test,:features]
|
62
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'asterisk/mailcmd/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "asterisk-mailcmd"
|
8
|
+
spec.version = Asterisk::Mailcmd::VERSION
|
9
|
+
spec.authors = ["Stas Kobzar"]
|
10
|
+
spec.email = ["stas@modulis.ca"]
|
11
|
+
spec.description = %q{Asterisk voicemail emails enhancement}
|
12
|
+
spec.summary = %q{Command to use with Asterisk mailcmp option. See: voicemail.conf}
|
13
|
+
spec.homepage = "http://www.modulis.ca"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency('rdoc')
|
24
|
+
spec.add_development_dependency('aruba')
|
25
|
+
spec.add_development_dependency('mocha')
|
26
|
+
spec.add_development_dependency('rake', '~> 0.9.2')
|
27
|
+
spec.add_dependency('mail')
|
28
|
+
spec.add_dependency('methadone', '~> 1.2.6')
|
29
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'methadone'
|
5
|
+
require 'asterisk/mailcmd'
|
6
|
+
|
7
|
+
require 'pp'
|
8
|
+
|
9
|
+
class App
|
10
|
+
include Methadone::Main
|
11
|
+
include Methadone::CLILogging
|
12
|
+
|
13
|
+
main do # main proc
|
14
|
+
Asterisk::Mailcmd::Email.set_and_send options
|
15
|
+
end
|
16
|
+
|
17
|
+
# supplemental methods here
|
18
|
+
|
19
|
+
# Description
|
20
|
+
description %Q{Command to use with Asterisk mailcmp option. See: voicemail.conf.
|
21
|
+
Default delivery method is sendmail}
|
22
|
+
|
23
|
+
# Email text template file
|
24
|
+
on("-t FILE","--text-tmpl","Email TEXT template file (ERB format).") do |file|
|
25
|
+
options[:text_tmpl] = file
|
26
|
+
end
|
27
|
+
|
28
|
+
# Email HTML template file
|
29
|
+
on("-m FILE","--html-tmpl","Email HTML template file (ERB format).") do |file|
|
30
|
+
options[:html_tmpl] = file
|
31
|
+
end
|
32
|
+
|
33
|
+
# Email HTML charset
|
34
|
+
on("-c CHARSET","--charset","Email HTML content-type charset.") do |ch|
|
35
|
+
options[:charset] = ch
|
36
|
+
end
|
37
|
+
|
38
|
+
version Asterisk::Mailcmd::VERSION
|
39
|
+
|
40
|
+
use_log_level_option
|
41
|
+
|
42
|
+
go!
|
43
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Feature: My bootstrapped app kinda works
|
2
|
+
In order to get going on coding my awesome app
|
3
|
+
I want to have aruba and cucumber setup
|
4
|
+
So I don't have to do it myself
|
5
|
+
|
6
|
+
Scenario: App just runs
|
7
|
+
When I get help for "asterisk-mailcmd"
|
8
|
+
Then the exit status should be 0
|
9
|
+
And the banner should be present
|
10
|
+
And the banner should document that this app takes options
|
11
|
+
And the following options should be documented:
|
12
|
+
|--version|
|
13
|
+
And the banner should document that this app takes no arguments
|
@@ -0,0 +1 @@
|
|
1
|
+
# Put your step definitions here
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'aruba/cucumber'
|
2
|
+
require 'methadone/cucumber'
|
3
|
+
|
4
|
+
ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
|
5
|
+
LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
|
6
|
+
|
7
|
+
Before do
|
8
|
+
# Using "announce" causes massive warnings on 1.9.2
|
9
|
+
@puts = true
|
10
|
+
@original_rubylib = ENV['RUBYLIB']
|
11
|
+
ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
|
12
|
+
end
|
13
|
+
|
14
|
+
After do
|
15
|
+
ENV['RUBYLIB'] = @original_rubylib
|
16
|
+
end
|