griddler 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/griddler/email.rb +24 -9
- data/lib/griddler/version.rb +1 -1
- metadata +2 -8
data/lib/griddler/email.rb
CHANGED
@@ -1,18 +1,14 @@
|
|
1
1
|
require 'iconv'
|
2
2
|
|
3
3
|
class Griddler::Email
|
4
|
-
attr_accessor :to, :from, :body, :subject
|
4
|
+
attr_accessor :to, :from, :body, :subject, :attachments
|
5
5
|
|
6
6
|
def initialize(params)
|
7
7
|
@to = extract_address(params[:to], config.to)
|
8
8
|
@from = extract_address(params[:from], :email)
|
9
9
|
@subject = params[:subject]
|
10
|
-
|
11
|
-
|
12
|
-
@body = params[:text]
|
13
|
-
else
|
14
|
-
@body = extract_body(params[:text], params[:charsets])
|
15
|
-
end
|
10
|
+
@body = raw_or_extracted_body(params)
|
11
|
+
@attachments = extract_attachments(params)
|
16
12
|
|
17
13
|
handler_class = config.handler_class
|
18
14
|
handler_method = config.handler_method
|
@@ -21,6 +17,10 @@ class Griddler::Email
|
|
21
17
|
|
22
18
|
private
|
23
19
|
|
20
|
+
def config
|
21
|
+
Griddler.configuration
|
22
|
+
end
|
23
|
+
|
24
24
|
def extract_address(address, type)
|
25
25
|
parsed = EmailParser.parse_address(address)
|
26
26
|
if type == :hash
|
@@ -30,6 +30,17 @@ class Griddler::Email
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
+
def extract_attachments(params)
|
34
|
+
attachment_count = params[:attachments].to_i
|
35
|
+
attachment_files = []
|
36
|
+
|
37
|
+
attachment_count.times do |index|
|
38
|
+
attachment_files << params["attachment#{index + 1}".to_sym]
|
39
|
+
end
|
40
|
+
|
41
|
+
attachment_files
|
42
|
+
end
|
43
|
+
|
33
44
|
def extract_body(body_text, charsets)
|
34
45
|
if charsets.present?
|
35
46
|
charsets = ActiveSupport::JSON.decode(charsets)
|
@@ -39,7 +50,11 @@ class Griddler::Email
|
|
39
50
|
EmailParser.extract_reply_body(body_text)
|
40
51
|
end
|
41
52
|
|
42
|
-
def
|
43
|
-
|
53
|
+
def raw_or_extracted_body(params)
|
54
|
+
if config.raw_body
|
55
|
+
@body = params[:text]
|
56
|
+
else
|
57
|
+
@body = extract_body(params[:text], params[:charsets])
|
58
|
+
end
|
44
59
|
end
|
45
60
|
end
|
data/lib/griddler/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: griddler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-11-
|
14
|
+
date: 2012-11-10 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rails
|
@@ -96,18 +96,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
96
|
- - ! '>='
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '0'
|
99
|
-
segments:
|
100
|
-
- 0
|
101
|
-
hash: -1174056135577180289
|
102
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
100
|
none: false
|
104
101
|
requirements:
|
105
102
|
- - ! '>='
|
106
103
|
- !ruby/object:Gem::Version
|
107
104
|
version: '0'
|
108
|
-
segments:
|
109
|
-
- 0
|
110
|
-
hash: -1174056135577180289
|
111
105
|
requirements: []
|
112
106
|
rubyforge_project:
|
113
107
|
rubygems_version: 1.8.24
|