Class: PecRuby::NestedPostacertMessage
- Inherits:
-
Object
- Object
- PecRuby::NestedPostacertMessage
- Defined in:
- lib/pec_ruby/attachment.rb
Overview
Simplified message class for nested postacert emails
Instance Attribute Summary collapse
-
#mail ⇒ Object
readonly
Returns the value of attribute mail.
Instance Method Summary collapse
- #attachments ⇒ Object
- #body ⇒ Object
- #body_html ⇒ Object
- #body_text ⇒ Object
- #date ⇒ Object
- #from ⇒ Object
-
#has_nested_postacerts? ⇒ Boolean
Check if this nested message has any nested postacert.eml files.
-
#initialize(mail) ⇒ NestedPostacertMessage
constructor
A new instance of NestedPostacertMessage.
-
#nested_postacerts ⇒ Object
Find any nested postacert.eml files in this message’s attachments.
- #subject ⇒ Object
- #summary ⇒ Object
- #to ⇒ Object
Constructor Details
#initialize(mail) ⇒ NestedPostacertMessage
Returns a new instance of NestedPostacertMessage.
90 91 92 |
# File 'lib/pec_ruby/attachment.rb', line 90 def initialize(mail) @mail = mail end |
Instance Attribute Details
#mail ⇒ Object (readonly)
Returns the value of attribute mail.
88 89 90 |
# File 'lib/pec_ruby/attachment.rb', line 88 def mail @mail end |
Instance Method Details
#attachments ⇒ Object
156 157 158 159 160 |
# File 'lib/pec_ruby/attachment.rb', line 156 def return [] unless @mail&. @mail..map { |att| Attachment.new(att) } end |
#body ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/pec_ruby/attachment.rb', line 110 def body # Try to get text/plain first, then text/html text_part = extract_text_part(@mail, "text/plain") html_part = extract_text_part(@mail, "text/html") selected_part = text_part || html_part return nil unless selected_part raw_body = selected_part.body.decoded charset = selected_part.charset || selected_part.content_type_parameters&.[]("charset") || "UTF-8" content = raw_body.dup.force_encoding(charset).encode("UTF-8") { content: content, content_type: selected_part.mime_type, charset: charset } end |
#body_html ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/pec_ruby/attachment.rb', line 144 def body_html html_part = extract_text_part(@mail, "text/html") return nil unless html_part raw_body = html_part.body.decoded charset = html_part.charset || html_part.content_type_parameters&.[]("charset") || "UTF-8" raw_body.dup.force_encoding(charset).encode("UTF-8") end |
#body_text ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/pec_ruby/attachment.rb', line 132 def body_text text_part = extract_text_part(@mail, "text/plain") return nil unless text_part raw_body = text_part.body.decoded charset = text_part.charset || text_part.content_type_parameters&.[]("charset") || "UTF-8" raw_body.dup.force_encoding(charset).encode("UTF-8") end |
#date ⇒ Object
106 107 108 |
# File 'lib/pec_ruby/attachment.rb', line 106 def date @mail.date end |
#from ⇒ Object
98 99 100 |
# File 'lib/pec_ruby/attachment.rb', line 98 def from @mail.from&.first end |
#has_nested_postacerts? ⇒ Boolean
Check if this nested message has any nested postacert.eml files
179 180 181 |
# File 'lib/pec_ruby/attachment.rb', line 179 def has_nested_postacerts? !nested_postacerts.empty? end |
#nested_postacerts ⇒ Object
Find any nested postacert.eml files in this message’s attachments
174 175 176 |
# File 'lib/pec_ruby/attachment.rb', line 174 def nested_postacerts .select(&:postacert?) end |
#subject ⇒ Object
94 95 96 |
# File 'lib/pec_ruby/attachment.rb', line 94 def subject @mail.subject end |
#summary ⇒ Object
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/pec_ruby/attachment.rb', line 162 def summary { subject: subject, from: from, to: to, date: date, attachments_count: .size, nested_postacerts_count: nested_postacerts.size } end |
#to ⇒ Object
102 103 104 |
# File 'lib/pec_ruby/attachment.rb', line 102 def to @mail.to || [] end |