mailhopper_mongoid 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/MIT-LICENSE +21 -0
- data/README.md +22 -0
- data/app/models/mailhopper/email.rb +49 -0
- data/lib/mailhopper_mongoid.rb +13 -0
- data/lib/mailhopper_mongoid/engine.rb +4 -0
- data/lib/mailhopper_mongoid/version.rb +3 -0
- data/mailhopper_mongoid.gemspec +23 -0
- metadata +86 -0
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright 2012 MobVox
|
2
|
+
http://www.mobvox.com.br
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# MailhopperMongoid
|
2
|
+
|
3
|
+
MailhopperMongoid is a drop-in replacement for the Mailhopper::Email class.
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
[Mailhopper](https://github.com/cerebris/mailhopper) ~> 0.2.0
|
8
|
+
[Mongoid](https://github.com/mongoid/mongoid)
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add to your project's Gemfile before any gem wich depends on Mailhopper:
|
13
|
+
|
14
|
+
```
|
15
|
+
gem 'mailhopper_mongoid'
|
16
|
+
```
|
17
|
+
|
18
|
+
Install with bundler:
|
19
|
+
|
20
|
+
```
|
21
|
+
bundle install
|
22
|
+
```
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Mailhopper
|
2
|
+
class Email
|
3
|
+
include Mongoid::Document
|
4
|
+
|
5
|
+
attr_accessible :to_address, :from_address, :cc_address, :bcc_address,
|
6
|
+
:reply_to_address, :subject, :content
|
7
|
+
default_scope proc { desc :created_at }
|
8
|
+
scope :unsent, proc { where :sent_at => nil }
|
9
|
+
|
10
|
+
field :sent_at
|
11
|
+
|
12
|
+
validates :from_address, :presence => true
|
13
|
+
|
14
|
+
def send!(delivery_method = nil)
|
15
|
+
mail = Mail.new(self.content)
|
16
|
+
mail[:bcc] = self.bcc_address unless self.bcc_address.blank?
|
17
|
+
Base.mailer_class.wrap_delivery_behavior(mail, delivery_method || Base.default_delivery_method)
|
18
|
+
mail.deliver
|
19
|
+
self.sent_at = Time.now
|
20
|
+
self.save!
|
21
|
+
end
|
22
|
+
|
23
|
+
class << self
|
24
|
+
def create_from_mail(mail)
|
25
|
+
create({
|
26
|
+
:to_address => address_to_s(mail.to),
|
27
|
+
:from_address => address_to_s(mail.from),
|
28
|
+
:cc_address => address_to_s(mail.cc),
|
29
|
+
:bcc_address => address_to_s(mail.bcc),
|
30
|
+
:reply_to_address => address_to_s(mail.reply_to),
|
31
|
+
:subject => mail.subject,
|
32
|
+
:content => mail.to_s
|
33
|
+
})
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def address_to_s(field)
|
39
|
+
if field
|
40
|
+
if field.is_a?(Array)
|
41
|
+
field.join(',') unless field.empty?
|
42
|
+
else
|
43
|
+
field
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# HACK: Since we don't want to add ActiveRecord as a dependency,
|
2
|
+
# let's trick Ruby into thinking the file where Mailhopper::Email is defined was already loaded
|
3
|
+
mailhopper_gem_dir = Gem::Specification.find_by_name("mailhopper").gem_dir
|
4
|
+
$LOADED_FEATURES << "#{mailhopper_gem_dir}/app/models/mailhopper/email.rb"
|
5
|
+
|
6
|
+
# HACK: Let's load our own Mailhopper::Email class, with blackjack and hookers.
|
7
|
+
require File.expand_path('../../app/models/mailhopper/email', __FILE__)
|
8
|
+
|
9
|
+
require "mailhopper"
|
10
|
+
require "mailhopper_mongoid/engine"
|
11
|
+
|
12
|
+
module MailhopperMongoid
|
13
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "mailhopper_mongoid/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "mailhopper_mongoid"
|
7
|
+
s.version = MailhopperMongoid::VERSION
|
8
|
+
s.authors = ["danxexe"]
|
9
|
+
s.email = ["danilo@mobvox.com.br"]
|
10
|
+
s.homepage = "http://www.mobvox.com.br"
|
11
|
+
s.summary = %q{Mongoid backend for Mailhopper}
|
12
|
+
s.description = %q{Mongoid based replacement Mailhopper::Email model}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
# specify any dependencies here; for example:
|
20
|
+
# s.add_development_dependency "rspec"
|
21
|
+
s.add_runtime_dependency "mailhopper", "~> 0.2.0"
|
22
|
+
s.add_runtime_dependency "mongoid"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mailhopper_mongoid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- danxexe
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mailhopper
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.2.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.2.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: mongoid
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Mongoid based replacement Mailhopper::Email model
|
47
|
+
email:
|
48
|
+
- danilo@mobvox.com.br
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- Gemfile
|
54
|
+
- MIT-LICENSE
|
55
|
+
- README.md
|
56
|
+
- app/models/mailhopper/email.rb
|
57
|
+
- lib/mailhopper_mongoid.rb
|
58
|
+
- lib/mailhopper_mongoid/engine.rb
|
59
|
+
- lib/mailhopper_mongoid/version.rb
|
60
|
+
- mailhopper_mongoid.gemspec
|
61
|
+
homepage: http://www.mobvox.com.br
|
62
|
+
licenses: []
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.8.24
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Mongoid backend for Mailhopper
|
85
|
+
test_files: []
|
86
|
+
has_rdoc:
|