Skip to content

Commit

Permalink
Add Maildir support
Browse files Browse the repository at this point in the history
While here, remove some cruft that passed through previously.
  • Loading branch information
smortex committed Jan 31, 2024
1 parent a1d94d0 commit 7701354
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 13 deletions.
26 changes: 20 additions & 6 deletions exe/email-report-processor
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ require 'email_report_processor'
require 'optparse'

options = {
class: nil,
mbox: false,
os: {},
class: nil,
mbox: false,
maildir: false,
os: {},
}

OptionParser.new do |opts|
Expand All @@ -35,16 +36,24 @@ OptionParser.new do |opts|
end

opts.separator("\nMiscellaneous options:")
opts.on('--mbox', 'Treat the provided file as a mailbox') do
opts.on('--mbox', 'Treat the provided files as Mbox') do
options[:mbox] = true
end
opts.on('--maildir', 'Treat the provided files as Maildir') do
options[:maildir] = true
end
end.parse!

if options[:class].nil?
warn('A processor type must be passed')
exit 1
end

if options[:mbox] && options[:maildir]
warn('The --mbox and --maildir options are mutualy exclusive')
exit 1
end

processor = options[:class].new(**options[:os])

if ARGV.empty?
Expand All @@ -55,8 +64,13 @@ else
if options[:mbox]
m = EmailReportProcessor::MailBox.new(filename)

while (message = m.next_message)
mail = Mail.new(message)
while (mail = m.next_message)
processor.process_message(mail)
end
elsif options[:maildir]
m = EmailReportProcessor::MailDir.new(filename)

while (mail = m.next_message)
processor.process_message(mail)
end
else
Expand Down
1 change: 0 additions & 1 deletion features/support/aruba.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
$server = WEBrick::HTTPServer.new(server_options)
Thread.new { $server.start }
Timeout.timeout(1) { sleep(0.1) until started }
puts 'go'
end

AfterAll do
Expand Down
1 change: 1 addition & 0 deletions lib/email_report_processor.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'email_report_processor/mailbox'
require 'email_report_processor/maildir'
require 'email_report_processor/dmarc_rua'
require 'email_report_processor/tlsrpt_rua'
4 changes: 2 additions & 2 deletions lib/email_report_processor/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def send_report(report)
req.basic_auth(uri.user, uri.password)

res = http.request(req)
puts res.inspect
puts res.body.inspect
#puts res.inspect
#puts res.body.inspect
end

def process_message(mail)
Expand Down
2 changes: 1 addition & 1 deletion lib/email_report_processor/mailbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def next_message
if message.empty?
nil
else
message
Mail.new(message)
end
end
# rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity
Expand Down
2 changes: 0 additions & 2 deletions spec/fixtures/sample-reports/dmarc/report.elm
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
From SRS0=XBdr=6A=google.com=noreply-dmarc-support@example.com Sat Feb 4 13:46:24 2023
>From SRS0=XBdr=6A=google.com=noreply-dmarc-support@example.com Sat Feb 4 13:46:24 2023
Return-Path: <SRS0=XBdr=6A=google.com=noreply-dmarc-support@example.com>
X-Original-To: romain@blogreen.org
Delivered-To: romain@blogreen.org
Expand Down
1 change: 0 additions & 1 deletion spec/fixtures/sample-reports/tlsrpt/report.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
From SRS0=pMZs=57=smtp-tls-reporting.bounces.google.com=3Nd3cYxoKAIgz03q1xA-4y51-5x4-3q1035uzss00sxq.o0y@blogreen.org Fri Feb 3 12:09:04 2023
Return-Path: <SRS0=pMZs=57=smtp-tls-reporting.bounces.google.com=3Nd3cYxoKAIgz03q1xA-4y51-5x4-3q1035uzss00sxq.o0y@blogreen.org>
X-Original-To: romain@blogreen.org
Delivered-To: romain@blogreen.org
Expand Down

0 comments on commit 7701354

Please sign in to comment.