Skip to content

Commit

Permalink
Add automatic parsing of emails with spreadsheets
Browse files Browse the repository at this point in the history
We want to parse these email automatically so the Excel Analyzer runs
and detects issues with hidden data.

Fixes #8047
  • Loading branch information
gbp committed Feb 9, 2024
1 parent d4f8c63 commit bcd107e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config/initializers/excel_analyzer.rb
@@ -1 +1,7 @@
require "excel_analyzer"

ExcelAnalyzer.on_spreadsheet_received = ->(raw_email_blob) do
incoming_message = IncomingMessage.joins(raw_email: :file_blob).
find_by(active_storage_blobs: { id: raw_email_blob })
incoming_message&.parse_raw_email!
end
1 change: 1 addition & 0 deletions doc/CHANGES.md
Expand Up @@ -2,6 +2,7 @@

## Highlighted Features

* Add automatic parsing of emails contain Excel spreadsheets (Graeme Porteous)
* Add admin list of all citations (Gareth Rees)
* Improve redirection flow after user account closure actions (Gareth Rees)
* Fix duplicated attachment masking jobs (Graeme Porteous)
Expand Down
22 changes: 22 additions & 0 deletions spec/integration/incoming_mail_spec.rb
Expand Up @@ -132,4 +132,26 @@
expect(page.response_headers['Content-Type']).to eq("application/octet-stream; charset=utf-8")
expect(page).to have_content "an unusual sort of file"
end

it "does not automatically extract attachments after receiving email" do
receive_incoming_mail('incoming-request-plain.email',
email_to: info_request.incoming_email)
perform_enqueued_jobs

im = info_request.incoming_messages.first
expect(im.foi_attachments).to be_empty
end

it "extract attachments when inbound email contains an Excel spreadsheet" do
mail = Mail.new(to: info_request.incoming_email) do
body 'My excel spreadsheet'
add_file 'gems/excel_analyzer/spec/fixtures/data.xlsx'
end

receive_incoming_mail(mail.to_s)
perform_enqueued_jobs

im = info_request.incoming_messages.first
expect(im.foi_attachments).to_not be_empty
end
end

0 comments on commit bcd107e

Please sign in to comment.