kelredd-mailer 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -0
- data/lib/mailer/email.rb +20 -0
- data/lib/mailer/file_cache.rb +19 -7
- data/lib/mailer/version.rb +1 -1
- data/lib/mailer.rb +1 -0
- metadata +3 -2
data/README.rdoc
CHANGED
@@ -153,6 +153,10 @@ Mailer provides a file cache object to abstract caching your mail to the file sy
|
|
153
153
|
test_at_example.delete(key)
|
154
154
|
end
|
155
155
|
|
156
|
+
# or yet even better, get Mailer::Email object (which are just special TMail::Mail objects)
|
157
|
+
emails = test_at_example.emails
|
158
|
+
email = test_at_example.email(test_at_example.keys.first)
|
159
|
+
|
156
160
|
|
157
161
|
# test if the cache has any entries
|
158
162
|
test_at_example.empty? # => false
|
data/lib/mailer/email.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'mailer/exceptions'
|
2
|
+
require 'tmail'
|
3
|
+
|
4
|
+
module Mailer
|
5
|
+
|
6
|
+
# this class inherits from TMail::Mail and just adds some niceties to it
|
7
|
+
class Email < TMail::Mail
|
8
|
+
|
9
|
+
# a way to return just a part of a multipart body, if it is multipart
|
10
|
+
def part_of_body(part_content_type)
|
11
|
+
if multipart? && (part = parts.select{|part| part.content_type == part_content_type}.try(:first))
|
12
|
+
part.body
|
13
|
+
else
|
14
|
+
body
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/mailer/file_cache.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'useful/ruby_extensions/object'
|
2
2
|
require 'mailer/exceptions'
|
3
3
|
require 'mailer/mailbox'
|
4
|
+
require 'mailer/email'
|
4
5
|
|
5
6
|
module Mailer
|
6
7
|
|
@@ -30,14 +31,19 @@ module Mailer
|
|
30
31
|
end
|
31
32
|
|
32
33
|
def read(key)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
else
|
39
|
-
raise ArgumentError, "the file '#{path}' does not exists"
|
34
|
+
path = self.key_path(key)
|
35
|
+
if File.exists?(path)
|
36
|
+
File.open(path, 'r') do |file|
|
37
|
+
yield(file) if block_given?
|
40
38
|
end
|
39
|
+
else
|
40
|
+
raise ArgumentError, "the file '#{path}' does not exists"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def email(key)
|
45
|
+
read(key) do |file|
|
46
|
+
Mailer::Email.parse(file.read)
|
41
47
|
end
|
42
48
|
end
|
43
49
|
|
@@ -79,6 +85,12 @@ module Mailer
|
|
79
85
|
self.entries.collect{|file| File.basename(file)}
|
80
86
|
end
|
81
87
|
|
88
|
+
def emails
|
89
|
+
self.collect do |file|
|
90
|
+
Mailer::Email.parse(file.read)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
82
94
|
def length
|
83
95
|
self.entries.length
|
84
96
|
end
|
data/lib/mailer/version.rb
CHANGED
data/lib/mailer.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kelredd-mailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Redding
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-24 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- Rakefile
|
56
56
|
- lib/mailer/config.rb
|
57
57
|
- lib/mailer/deliveries.rb
|
58
|
+
- lib/mailer/email.rb
|
58
59
|
- lib/mailer/exceptions.rb
|
59
60
|
- lib/mailer/file_cache.rb
|
60
61
|
- lib/mailer/mailbox.rb
|