Module: Hermes::Extractors
Instance Method Summary collapse
-
#complex_extract(address_container) ⇒ Object
when passing in to/from addresses that are complex objects like a Hash or Twitter::Client instance, they will be YAMLed and then Base64ed since Mail::Message really only wants to play with strings for these fields.
-
#extract_from(rails_message, format: :full) ⇒ Object
format can be full|name|address.
- #extract_html(rails_message) ⇒ Object
- #extract_text(rails_message) ⇒ Object
-
#extract_to(rails_message, format: :full) ⇒ Object
format can be full|name|address.
Instance Method Details
#complex_extract(address_container) ⇒ Object
when passing in to/from addresses that are complex objects like a Hash or Twitter::Client instance, they will be YAMLed and then Base64ed since Mail::Message really only wants to play with strings for these fields
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/support/extractors.rb', line 54 def complex_extract(address_container) if B64Y.decodable?(address_container) { decoded: true, value: B64Y.decode(address_container) } else { decoded: false, value: address_container } end end |
#extract_from(rails_message, format: :full) ⇒ Object
format can be full|name|address
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/support/extractors.rb', line 21 def extract_from(, format: :full) from = complex_extract(.from.first) return from[:value] if from[:decoded] case format when :full [:from].formatted.first when :name [:from].address_list.addresses.first.name when :address [:from].address_list.addresses.first.address end end |
#extract_html(rails_message) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/support/extractors.rb', line 4 def extract_html() if .html_part .html_part.body.decoded else .content_type =~ /text\/html/ ? .body.decoded : nil end end |
#extract_text(rails_message) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/support/extractors.rb', line 12 def extract_text() if .multipart? .text_part ? .text_part.body.decoded.strip : nil else .content_type =~ /text\/plain/ ? .body.decoded.strip : nil end end |
#extract_to(rails_message, format: :full) ⇒ Object
format can be full|name|address
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/support/extractors.rb', line 36 def extract_to(, format: :full) to = complex_extract(.to.first) return to[:value] if to[:decoded] case format when :full [:to].formatted.first when :name [:to].address_list.addresses.first.name when :address [:to].address_list.addresses.first.address end end |