Class: Uniword::Mhtml::MimePart
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Uniword::Mhtml::MimePart
show all
- Defined in:
- lib/uniword/mhtml/mime_part.rb
Overview
Base class for MIME parts in an MHTML document.
Each MIME part has headers (Content-Type, Content-Location, Content-Transfer-Encoding) and a body (raw content).
Subclasses: HtmlPart, XmlPart, ImagePart, FileListPart, HeaderPart
Instance Method Summary
collapse
Instance Method Details
#decoded_content ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/uniword/mhtml/mime_part.rb', line 20
def decoded_content
case content_transfer_encoding&.downcase
when "base64"
Base64.strict_decode64(raw_content.gsub(/\s+/, ""))
when "quoted-printable"
content = raw_content.dup.force_encoding("BINARY")
content
.gsub(/=\r?\n/, "")
.gsub(/=([0-9A-Fa-f]{2})/) { [::Regexp.last_match(1).hex].pack("C") }
.force_encoding("UTF-8")
else
raw_content
end
end
|
#decoded_content=(value) ⇒ Object
38
39
40
|
# File 'lib/uniword/mhtml/mime_part.rb', line 38
def decoded_content=(value)
self.raw_content = value
end
|
#filename ⇒ Object
42
43
44
45
46
47
48
49
|
# File 'lib/uniword/mhtml/mime_part.rb', line 42
def filename
return nil unless content_location
location = content_location.sub(/^cid:/i, "")
if (match = location.match(%r{([^/\\]+\.[a-z0-9]+)$}i))
match[1]
end
end
|
#html_content? ⇒ Boolean
59
60
61
|
# File 'lib/uniword/mhtml/mime_part.rb', line 59
def html_content?
content_type.to_s.include?("text/html")
end
|
#image_content? ⇒ Boolean
63
64
65
|
# File 'lib/uniword/mhtml/mime_part.rb', line 63
def image_content?
content_type.to_s.start_with?("image/")
end
|
#text_content? ⇒ Boolean
51
52
53
|
# File 'lib/uniword/mhtml/mime_part.rb', line 51
def text_content?
content_type.to_s.start_with?("text/")
end
|
#theme_content? ⇒ Boolean
67
68
69
|
# File 'lib/uniword/mhtml/mime_part.rb', line 67
def theme_content?
content_type.to_s.include?("officetheme")
end
|
#xml_content? ⇒ Boolean
55
56
57
|
# File 'lib/uniword/mhtml/mime_part.rb', line 55
def xml_content?
content_type.to_s.match?(%r{text/xml|application/xml})
end
|