Class: Postpeek::Metadata::Extractor
- Inherits:
-
Object
- Object
- Postpeek::Metadata::Extractor
- Defined in:
- lib/postpeek/metadata/extractor.rb
Instance Method Summary collapse
- #attachments ⇒ Object
- #bcc ⇒ Object
- #cc ⇒ Object
- #content_type ⇒ Object
- #encoding ⇒ Object
- #from ⇒ Object
-
#initialize(mail) ⇒ Extractor
constructor
A new instance of Extractor.
- #locale ⇒ Object
- #message_id ⇒ Object
- #parts ⇒ Object
- #reply_to ⇒ Object
- #sent_at ⇒ Object
- #subject ⇒ Object
- #to ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(mail) ⇒ Extractor
Returns a new instance of Extractor.
6 7 8 |
# File 'lib/postpeek/metadata/extractor.rb', line 6 def initialize(mail) @mail = mail end |
Instance Method Details
#attachments ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/postpeek/metadata/extractor.rb', line 70 def mail..map do |att| { filename: att.filename, content_type: att.mime_type, size: att.body.decoded.bytesize } end end |
#bcc ⇒ Object
26 27 28 |
# File 'lib/postpeek/metadata/extractor.rb', line 26 def bcc normalise_addresses(mail.bcc) end |
#cc ⇒ Object
22 23 24 |
# File 'lib/postpeek/metadata/extractor.rb', line 22 def cc normalise_addresses(mail.cc) end |
#content_type ⇒ Object
40 41 42 43 44 |
# File 'lib/postpeek/metadata/extractor.rb', line 40 def content_type return nil unless mail.content_type mail.mime_type end |
#encoding ⇒ Object
58 59 60 |
# File 'lib/postpeek/metadata/extractor.rb', line 58 def encoding mail.content_transfer_encoding&.to_s end |
#from ⇒ Object
14 15 16 |
# File 'lib/postpeek/metadata/extractor.rb', line 14 def from normalise_addresses(mail.from) end |
#locale ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/postpeek/metadata/extractor.rb', line 62 def locale header_val = mail["X-Mailer-Locale"]&.value return header_val if header_val && !header_val.empty? defined?(I18n) ? I18n.locale&.to_s : nil end |
#message_id ⇒ Object
80 81 82 |
# File 'lib/postpeek/metadata/extractor.rb', line 80 def mail. end |
#parts ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/postpeek/metadata/extractor.rb', line 46 def parts return [] unless mail.multipart? mail.parts.map do |part| { content_type: part.mime_type, encoding: part.content_transfer_encoding, charset: part.charset } end end |
#reply_to ⇒ Object
30 31 32 |
# File 'lib/postpeek/metadata/extractor.rb', line 30 def reply_to normalise_addresses(mail.reply_to).first end |
#sent_at ⇒ Object
34 35 36 37 38 |
# File 'lib/postpeek/metadata/extractor.rb', line 34 def sent_at return nil unless mail.date mail.date.to_time.utc.iso8601 end |
#subject ⇒ Object
10 11 12 |
# File 'lib/postpeek/metadata/extractor.rb', line 10 def subject mail.subject end |
#to ⇒ Object
18 19 20 |
# File 'lib/postpeek/metadata/extractor.rb', line 18 def to normalise_addresses(mail.to) end |
#to_h ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/postpeek/metadata/extractor.rb', line 84 def to_h { subject: subject, from: from, to: to, cc: cc, bcc: bcc, reply_to: reply_to, sent_at: sent_at, content_type: content_type, parts: parts, encoding: encoding, locale: locale, attachments: , message_id: } end |