Class: Shrinker::Parser::Mime
Instance Attribute Summary
Attributes inherited from Abstract
#attributes, #config, #content
Instance Method Summary
collapse
Methods inherited from Abstract
#initialize, replace
Instance Method Details
#email ⇒ Object
20
21
22
|
# File 'lib/shrinker/parser/mime.rb', line 20
def email
@email ||= Mail.read_from_string(content)
end
|
#replace ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/shrinker/parser/mime.rb', line 6
def replace
parts = email.all_parts.empty? ? [email] : email.all_parts
parts.each do |part|
new_body = replace_part_body(part)
part.body = if part.content_transfer_encoding
Mail::Body.new(new_body).encoded(part.content_transfer_encoding)
else
new_body.to_s
end
end
email.to_s
end
|
#replace_part_body(part) ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/shrinker/parser/mime.rb', line 24
def replace_part_body(part)
replace_config = config.dup
if part.mime_type == "text/html" && anchors_only_in_html?
replace_config.merge!({:around_pattern => anchor_tag_around_regex})
end
Text::replace(part.body.decoded, attributes, replace_config)
end
|