Class: Chronicle::Email::IMAPExtractor

Inherits:
Chronicle::ETL::Extractor
  • Object
show all
Defined in:
lib/chronicle/email/imap_extractor.rb

Instance Method Summary collapse

Instance Method Details

#extractObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/chronicle/email/imap_extractor.rb', line 30

def extract
  @message_ids.each do |message_id|
    message = fetch_message(message_id)
    email = Mail.new(message.attr['BODY[]'])
    data = {
      raw: email,
      time: email.date&.to_time,
      subject: email.subject,
      from: email&.from&.join(', '),
      to: email&.to&.join(', ')
    }
    yield build_extraction(data:)
  end
end

#prepareObject



21
22
23
24
# File 'lib/chronicle/email/imap_extractor.rb', line 21

def prepare
  @connection = create_connection
  @message_ids = fetch_message_ids
end

#results_countObject



26
27
28
# File 'lib/chronicle/email/imap_extractor.rb', line 26

def results_count
  @message_ids.count
end