Class: Mail::Message
- Inherits:
-
Object
- Object
- Mail::Message
- Defined in:
- lib/jpmobile/mail.rb
Overview
encoding patch
Instance Attribute Summary collapse
-
#mobile ⇒ Object
Returns the value of attribute mobile.
Instance Method Summary collapse
- #add_charset_with_jpmobile ⇒ Object (also: #add_charset)
- #encoded_with_jpmobile ⇒ Object (also: #encoded)
- #find_part_by_content_type(content_type) ⇒ Object
- #init_with_hash_with_jpmobile(hash) ⇒ Object (also: #init_with_hash)
- #init_with_string(string) ⇒ Object
- #parse_message_with_jpmobile ⇒ Object (also: #parse_message)
- #process_body_raw_with_jpmobile ⇒ Object (also: #process_body_raw)
-
#raw_source=(value) ⇒ Object
In jpmobile, value is already transfered correctly encodings.
-
#rearrange! ⇒ Object
– normal multipart/mixed |- multipart/alternative | |- text/plain | |- text/html | |- image/xxxx (インライン画像) |- image/xxxx (添付画像).
- #separate_parts_with_jpmobile ⇒ Object (also: #separate_parts)
Instance Attribute Details
#mobile ⇒ Object
Returns the value of attribute mobile.
6 7 8 |
# File 'lib/jpmobile/mail.rb', line 6 def mobile @mobile end |
Instance Method Details
#add_charset_with_jpmobile ⇒ Object Also known as: add_charset
119 120 121 |
# File 'lib/jpmobile/mail.rb', line 119 def add_charset_with_jpmobile add_charset_without_jpmobile unless multipart? && @mobile end |
#encoded_with_jpmobile ⇒ Object Also known as: encoded
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/jpmobile/mail.rb', line 15 def encoded_with_jpmobile if @mobile header['subject'].mobile = @mobile if header['subject'] header['from'].mobile = @mobile if header['from'] header['to'].mobile = @mobile if header['to'] self.charset = @mobile.mail_charset unless multipart? ready_to_send! self.body.mobile = @mobile self.header['Content-Transfer-Encoding'].value = @mobile.content_transfer_encoding(self.header) if @mobile.decorated? unless self.content_type.match?(%r{image/}) self.header['Content-ID'] = nil end unless self.header['Content-Type'].sub_type == 'mixed' self.header['Date'] = nil self.header['Mime-Version'] = nil end end buffer = header.encoded buffer << "\r\n" buffer = @mobile.utf8_to_mail_encode(buffer) buffer << body.encoded(content_transfer_encoding) ascii_compatible!(buffer) else encoded_without_jpmobile end end |
#find_part_by_content_type(content_type) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/jpmobile/mail.rb', line 213 def find_part_by_content_type(content_type) finded_parts = [] self.parts.each do |part| if part.multipart? finded_parts << part.find_part_by_content_type(content_type) elsif part.content_type.match?(/^#{content_type}/) finded_parts << part end end finded_parts.flatten end |
#init_with_hash_with_jpmobile(hash) ⇒ Object Also known as: init_with_hash
64 65 66 67 68 69 70 71 |
# File 'lib/jpmobile/mail.rb', line 64 def init_with_hash_with_jpmobile(hash) if hash[:body_raw] @mobile = hash[:mobile] init_with_string(hash[:body_raw]) else init_with_hash_without_jpmobile(hash) end end |
#init_with_string(string) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/jpmobile/mail.rb', line 76 def init_with_string(string) # convert to ASCII-8BIT for ascii incompatible encodings s = Jpmobile::Util.ascii_8bit(string) unless s.ascii_only? s = s.is_a?(String) ? s.to_str.encode(s.encoding, universal_newline: true).encode!(s.encoding, crlf_newline: true) : '' end self.raw_source = s set_envelope_header @separate_parts = multipart? end |
#parse_message_with_jpmobile ⇒ Object Also known as: parse_message
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/jpmobile/mail.rb', line 48 def _crlf_raw_source = raw_source.encode(raw_source.encoding, universal_newline: true).encode!(raw_source.encoding, crlf_newline: true) header_part, body_part = _crlf_raw_source.lstrip.split( /#{Constants::CRLF}#{Constants::CRLF}|#{Constants::CRLF}#{Constants::WSP}*#{Constants::CRLF}(?!#{Constants::WSP})/mo, 2 ) # header_part, body_part = raw_source.lstrip.split(HEADER_SEPARATOR, 2) self.header = header_part @body_part_jpmobile = body_part convert_encoding_jpmobile body_part = @body_part_jpmobile self.body = body_part end |
#process_body_raw_with_jpmobile ⇒ Object Also known as: process_body_raw
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/jpmobile/mail.rb', line 88 def process_body_raw_with_jpmobile process_body_raw_without_jpmobile return unless @mobile @body.mobile = @mobile @body.content_type_with_jpmobile = self.content_type if has_content_transfer_encoding? && ['base64', 'quoted-printable'].include?(self.content_transfer_encoding) && ['text'].include?(@mobile_main_type) @body.decode_transfer_encoding end if @body.multipart? @body.parts.each do |p| p.mobile = @mobile end end end |
#raw_source=(value) ⇒ Object
In jpmobile, value is already transfered correctly encodings.
110 111 112 |
# File 'lib/jpmobile/mail.rb', line 110 def raw_source=(value) @raw_source = ::Mail::Utilities.to_crlf(value) end |
#rearrange! ⇒ Object
– normal multipart/mixed
|- multipart/alternative
| |- text/plain
| |- text/html
| |- image/xxxx (インライン画像)
|- image/xxxx (添付画像)
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/jpmobile/mail.rb', line 163 def rearrange! return unless @mobile && @mobile.decoratable? @mobile.decorated = true text_body_part = find_part_by_content_type('text/plain').first html_body_part = find_part_by_content_type('text/html').first html_body_part.transport_encoding = 'quoted-printable' if html_body_part inline_images = [] attached_files = [] .each do |p| if p.content_type.match(%r{^image/}) && p.content_disposition.match(/^inline/) if p.header['Content-Type'].parameters['filename'] p.header['Content-Type'].parameters['name'] = p.header['Content-Type'].parameters['filename'].to_s end inline_images << p elsif p.content_disposition attached_files << p end end alternative_part = Mail::Part.new { content_type 'multipart/alternative' } alternative_part.add_part(text_body_part) if text_body_part alternative_part.add_part(html_body_part) if html_body_part if @mobile. = Mail::Part.new { content_type 'multipart/related' } .add_part(alternative_part) inline_images.each do |inline_image| .add_part(inline_image) end inline_images.clear else = alternative_part end unless self.header['Content-Type'].sub_type == 'mixed' self.header['Content-Type'] = self.content_type.gsub(/#{self.header["Content-Type"].sub_type}/, 'mixed') end self.parts.clear self.body = nil self.add_part() inline_images.each do |inline_image| self.add_part(inline_image) end attached_files.each do |attached_file| self.add_part(attached_file) end end |
#separate_parts_with_jpmobile ⇒ Object Also known as: separate_parts
114 115 116 117 |
# File 'lib/jpmobile/mail.rb', line 114 def separate_parts_with_jpmobile @body.mobile = @mobile separate_parts_without_jpmobile end |