griddler 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -30,7 +30,7 @@ Defaults
30
30
  --------
31
31
 
32
32
  By default Griddler will look for a class to be created in your application
33
- called EmailProcessor with a class method implemented named process, taking
33
+ called EmailProcessor with a class method implemented, named process, taking
34
34
  in one argument (presumably `email`). For example, in `./lib/email_processor.rb`:
35
35
 
36
36
  ```ruby
@@ -5,12 +5,13 @@ class Griddler::Email
5
5
  attr_accessor :to, :from, :body, :raw_body, :subject, :attachments
6
6
 
7
7
  def initialize(params)
8
+ @params = params
8
9
  @to = extract_address(params[:to], config.to)
9
10
  @from = extract_address(params[:from], :email)
10
11
  @subject = params[:subject]
11
- @body = extract_body(params)
12
+ @body = extract_body
12
13
  @raw_body = params[:text] || params[:html]
13
- @attachments = extract_attachments(params)
14
+ @attachments = extract_attachments
14
15
 
15
16
  processor_class = config.processor_class
16
17
  processor_class.process(self)
@@ -18,12 +19,15 @@ class Griddler::Email
18
19
 
19
20
  private
20
21
 
22
+ attr_reader :params
23
+
21
24
  def config
22
25
  Griddler.configuration
23
26
  end
24
27
 
25
28
  def extract_address(address, type)
26
29
  parsed = EmailParser.parse_address(address)
30
+
27
31
  if type == :hash
28
32
  parsed
29
33
  else
@@ -31,7 +35,7 @@ class Griddler::Email
31
35
  end
32
36
  end
33
37
 
34
- def extract_attachments(params)
38
+ def extract_attachments
35
39
  attachment_count = params[:attachments].to_i
36
40
  attachment_files = []
37
41
 
@@ -42,26 +46,51 @@ class Griddler::Email
42
46
  attachment_files
43
47
  end
44
48
 
45
- def extract_body(params)
46
- body_text = text_or_sanitized_html(params)
49
+ def extract_body
50
+ body_text = text_or_sanitized_html
47
51
  charsets = params[:charsets]
48
52
 
49
53
  if charsets.present?
50
54
  charsets = ActiveSupport::JSON.decode(charsets)
51
- body_text = body_text.encode('UTF-8', invalid: :replace,
52
- undef: :replace, replace: '').force_encoding('UTF-8')
55
+ body_text = body_text.encode(
56
+ 'UTF-8',
57
+ invalid: :replace,
58
+ undef: :replace,
59
+ replace: ''
60
+ ).force_encoding('UTF-8')
53
61
  end
54
62
 
55
63
  EmailParser.extract_reply_body(body_text)
56
64
  end
57
65
 
58
- def text_or_sanitized_html(params)
66
+ def text_or_sanitized_html
59
67
  if params.key? :text
60
- params[:text]
68
+ clean_text(params[:text])
61
69
  elsif params.key? :html
62
- HTMLEntities.new.decode(strip_tags(params[:html]))
70
+ clean_html(params[:html])
63
71
  else
64
72
  raise Griddler::Errors::EmailBodyNotFound
65
73
  end
66
74
  end
75
+
76
+ def clean_text(text)
77
+ clean_invalid_utf8_bytes(text)
78
+ end
79
+
80
+ def clean_html(html)
81
+ cleaned_html = clean_invalid_utf8_bytes(html)
82
+ cleaned_html = strip_tags(cleaned_html)
83
+ cleaned_html = HTMLEntities.new.decode(cleaned_html)
84
+ cleaned_html
85
+ end
86
+
87
+ def clean_invalid_utf8_bytes(text)
88
+ text.encode(
89
+ 'UTF-8',
90
+ 'binary',
91
+ invalid: :replace,
92
+ undef: :replace,
93
+ replace: ''
94
+ )
95
+ end
67
96
  end
@@ -1,3 +1,3 @@
1
1
  module Griddler
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
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.3.0
4
+ version: 0.3.1
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: 2013-01-21 00:00:00.000000000 Z
14
+ date: 2013-02-04 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -115,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
115
  version: '0'
116
116
  segments:
117
117
  - 0
118
- hash: -3729493469419997719
118
+ hash: 4165747324942510967
119
119
  required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  none: false
121
121
  requirements:
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  version: '0'
125
125
  segments:
126
126
  - 0
127
- hash: -3729493469419997719
127
+ hash: 4165747324942510967
128
128
  requirements: []
129
129
  rubyforge_project:
130
130
  rubygems_version: 1.8.24