mails_viewer 0.0.2 → 0.0.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 +41 -4
- data/lib/mails_viewer/engine.rb +1 -1
- data/lib/mails_viewer/file_delivery.rb +29 -12
- data/lib/mails_viewer/mail.rb +0 -6
- data/lib/mails_viewer/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -17,13 +17,50 @@ and enable assets pipeline by adding `config.assets.enabled = true` to config fi
|
|
17
17
|
|
18
18
|
Add the gem to your Gemfile :
|
19
19
|
|
20
|
-
|
20
|
+
```ruby
|
21
|
+
gem "mails_viewer"
|
22
|
+
```
|
21
23
|
|
22
|
-
|
24
|
+
Set ActionMailer's delivery method to :file :
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
config.action_mailer.delivery_method = :file
|
28
|
+
```
|
23
29
|
|
24
|
-
|
30
|
+
put this in your routes.rb:
|
25
31
|
|
26
|
-
|
32
|
+
```ruby
|
33
|
+
mount MailsViewer::Engine => '/delivered_mails'
|
34
|
+
```
|
35
|
+
|
36
|
+
Now just load up http://localhost:3000/delivered_mails
|
37
|
+
|
38
|
+
##### Advanced #####
|
39
|
+
|
40
|
+
You can choose to send out some mails to the inbox instead of just
|
41
|
+
storing them in the file system by specifying which mails to sent:
|
42
|
+
|
43
|
+
- `: send_if` - Send mails that satisfy some condition
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
config.action_mailer.delivery_method = :file
|
47
|
+
config.action_mailer.file_settings = {
|
48
|
+
location: 'tmp/mails',
|
49
|
+
smtp_settings: {
|
50
|
+
address: "localhost",
|
51
|
+
port: 25,
|
52
|
+
domain: 'localhost.localdomain',
|
53
|
+
user_name: nil,
|
54
|
+
password: nil,
|
55
|
+
authentication: nil,
|
56
|
+
enable_starttls_auto: true
|
57
|
+
},
|
58
|
+
send_if: lambda { |mail| mail.destinations.select { |address| ["yedingding@gmail.com"].include?(address) }.any?
|
59
|
+
}
|
60
|
+
```
|
61
|
+
|
62
|
+
Now any mails sent to yedingding@gmail.com will not only store in the
|
63
|
+
filesystem for you to browse later, but also send out to his inbox.
|
27
64
|
|
28
65
|
Credits
|
29
66
|
-------
|
data/lib/mails_viewer/engine.rb
CHANGED
@@ -8,7 +8,7 @@ module MailsViewer
|
|
8
8
|
|
9
9
|
# Enabling assets precompiling under rails 3.1
|
10
10
|
if Rails.version >= '3.1' && Rails.env != 'production'
|
11
|
-
initializer :
|
11
|
+
initializer "MailsViewer precompile hook", :group => :all do |app|
|
12
12
|
app.config.assets.precompile += %w(mails_viewer.js mails_viewer.css)
|
13
13
|
end
|
14
14
|
end
|
@@ -1,15 +1,32 @@
|
|
1
1
|
Mail::FileDelivery.class_eval do
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
mail.destinations.uniq.each do |to|
|
12
|
-
::File.open(::File.join(settings[:location], mail.filename_for(to)), 'w') { |f| "#{f.write(mail.encoded)}\r\n\r\n" }
|
13
|
-
end
|
2
|
+
# We need to save the mail to seperate files when have several destination addresses
|
3
|
+
# So we generate different file name and save them.
|
4
|
+
def deliver!(mail)
|
5
|
+
if ::File.respond_to?(:makedirs)
|
6
|
+
::File.makedirs settings[:location]
|
7
|
+
else
|
8
|
+
::FileUtils.mkdir_p settings[:location]
|
14
9
|
end
|
10
|
+
|
11
|
+
mail.destinations.uniq.each do |to|
|
12
|
+
::File.open(::File.join(settings[:location], mail.filename_for(to)), 'w') { |f| "#{f.write(mail.encoded)}\r\n\r\n" }
|
13
|
+
end
|
14
|
+
|
15
|
+
if conditionally_sent(mail)
|
16
|
+
send(mail)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def conditionally_sent(mail)
|
21
|
+
if settings[:send_if] && settings[:smtp_settings]
|
22
|
+
settings[:send_if].call(mail)
|
23
|
+
end
|
24
|
+
rescue Exception => ex
|
25
|
+
false
|
26
|
+
end
|
27
|
+
|
28
|
+
def send(mail)
|
29
|
+
mail.delivery_method(:smtp, settings[:smtp_settings])
|
30
|
+
mail.deliver
|
31
|
+
end
|
15
32
|
end
|
data/lib/mails_viewer/mail.rb
CHANGED
@@ -1,15 +1,9 @@
|
|
1
1
|
module Mail
|
2
2
|
class Message
|
3
|
-
|
4
|
-
#def html_part
|
5
|
-
#find_first_mime_type('text/html')
|
6
|
-
#end
|
7
|
-
|
8
3
|
# Save the mail to seperate files when have several destination addresses
|
9
4
|
# This function used to return a filename by mail's date and destination address
|
10
5
|
def filename_for(to)
|
11
6
|
"#{date.to_time.to_i}.#{to}.txt"
|
12
7
|
end
|
13
|
-
|
14
8
|
end
|
15
9
|
end
|
data/lib/mails_viewer/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mails_viewer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-09-
|
13
|
+
date: 2012-09-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|