Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ERROR] request#show (ActionView::Template::Error) "incompatible character encodings: UTF-8 and ASCII-8BIT" #5783

Closed
garethrees opened this issue Jul 2, 2020 · 12 comments
Assignees
Labels
bug Breaks expected functionality f:request-analysis x:eu

Comments

@garethrees
Copy link
Member

An ActionView::Template::Error occurred in request#show:

incompatible character encodings: UTF-8 and ASCII-8BIT
lib/mail_handler/backends/mail_backend.rb:60:in `mail_from_outlook'

-------------------------------
Request:
-------------------------------

* URL : https://www.asktheeu.org/en/request/public_documents_related_to_disi_6
* HTTP Method: GET
* Parameters : {"controller"=>"request", "action"=>"show", "url_title"=>"public_documents_related_to_disi_6", "locale"=>"en"}
* Timestamp : 2020-07-02 11:05:38 +0200
* Rails root : /REDACTED/alaveteli-2020-06-18T09-21-33

-------------------------------
Session:
-------------------------------

* session id: [FILTERED]
* data: {"session_id"=>"REDACTED", "locale"=>"en"}

-------------------------------
Backtrace:
-------------------------------

lib/mail_handler/backends/mail_backend.rb:60:in `mail_from_outlook'
lib/mail_handler/backends/mail_backend.rb:188:in `decode_attached_part'
lib/mail_handler/backends/mail_backend.rb:241:in `expand_and_normalize_parts'
lib/mail_handler/backends/mail_backend.rb:216:in `block in expand_and_normalize_parts'
lib/mail_handler/backends/mail_backend.rb:216:in `expand_and_normalize_parts'
lib/mail_handler/backends/mail_backend.rb:284:in `get_attachment_leaves'
lib/mail_handler/backends/mail_backend.rb:355:in `get_attachment_attributes'
app/models/incoming_message.rb:536:in `extract_attachments!'
app/models/incoming_message.rb:98:in `block in parse_raw_email!'
app/models/incoming_message.rb:97:in `parse_raw_email!'
app/models/incoming_message.rb:178:in `mail_from'
app/models/incoming_message.rb:197:in `safe_mail_from'
app/models/incoming_message.rb:220:in `specific_from_name?'
app/views/request/_incoming_correspondence.html.erb:4:in `_app_views_request__incoming_correspondence_html_erb___4239059047440180258_69914119794420'
app/views/request/_correspondence.html.erb:4:in `_app_views_request__correspondence_html_erb__4133394796544516923_69914122355520'
app/views/request/show.html.erb:70:in `block in _app_views_request_show_html_erb___2337845117304762896_69914123240540'
app/views/request/show.html.erb:68:in `_app_views_request_show_html_erb___2337845117304762896_69914123240540'
app/controllers/request_controller.rb:133:in `block (3 levels) in show'
app/controllers/request_controller.rb:132:in `block in show'
lib/alaveteli_localization.rb:43:in `with_locale'
app/controllers/request_controller.rb:83:in `show'
app/controllers/application_controller.rb:115:in `record_memory'
lib/strip_empty_sessions.rb:13:in `call'
@garethrees garethrees added bug Breaks expected functionality x:eu f:request-analysis labels Jul 2, 2020
@garethrees
Copy link
Member Author

Started seeing a lot of these come in over the past few days.

@gbp
Copy link
Member

gbp commented Jul 8, 2020

Can't even get to the admin request#show page

Request ID: 8270
Incoming message ID: 26831

@gbp
Copy link
Member

gbp commented Jul 8, 2020

This issue is fixed by aquasync/ruby-msg#16 but this conflicts with our changes at mysociety/ruby-msg#3. I'm not really sure what our changes are doing, anyone able to provide context... 5 years later? @crowbot @garethrees ?

@garethrees
Copy link
Member Author

Might be able to manually add the response as a temporary fix until we can fix the underlying problem.

@gbp
Copy link
Member

gbp commented Jul 21, 2020

Might be able to manually add the response as a temporary fix until we can fix the underlying problem.

Not able to follow these step as generating a officer upload URL also errors

@gbp
Copy link
Member

gbp commented Jul 21, 2020

I've attempted to do the officer upload via the console (by calling RequestMailer#fake_response) and while it looks like it worked it hasn't added a message to the request ¯\_(ツ)_/¯

The message in question is only an acknowledgement and there has since been another response to the FOI. To get this working for this case I have simply deleted the acknowledgement.

garethrees added a commit to mysociety/ruby-msg that referenced this issue Sep 22, 2020
In fae72e5 we introduced a fallback for incompatible character
encodings, but that only covered the case where Mapi::Mime#is_multipart?
returns true.

This is a slight variation for the other branch of the conditional.

The error is being raised where we have a `@body` in a different
encoding to the default string encoding. In this case, just always force
the string to be the same encoding as `@body` so we don’t get an error.

This passes the spec for the particular file we’re seeing problems with,
but I’m not at all sure this is the right thing to do. Maybe we should
always treat anything in mapi as ASCII, and then force to UTF-8 for
display? [1]

Fixes mysociety/alaveteli#5783

[1] aquasync#9 (comment)
@garethrees garethrees assigned garethrees and unassigned gbp Sep 22, 2020
@garethrees
Copy link
Member Author

Just noting the relevant snippet for reproducing the error:

require 'mapi/msg'
content = File.read '/home/vagrant/tmp/28101-outlook-attachment.msg'
msg = Mapi::Msg.open(StringIO.new(content))
msg.to_mime.to_s

@garethrees
Copy link
Member Author

@gbp
Copy link
Member

gbp commented Sep 28, 2020

This is also happening for:

Request URL: https://www.asktheeu.org/en/request/contrato_no_lc_01464044
Request ID: 8516
Incoming message ID: 27953

@garethrees
Copy link
Member Author

@garethrees
Copy link
Member Author

garethrees commented Oct 7, 2020

Another case:

Request URL: https://www.asktheeu.org/en/alaveteli_pro/info_requests/vaccine_talks_2
Request ID: 8558
Incoming message ID: 28101
Raw Email ID: 28101

mysociety-pusher pushed a commit that referenced this issue Oct 13, 2020
Sometimes we receive messages with outlook attachments that can't be
parsed due to an issue in mapi [1].

There's a potential fix [2] but it conflicts [3] with an existing patch
we apply [4].

This at least allows users to download the raw attachment, rather than
us preventing the entire request from loading because we raise an
exception.

Part of #5783.

[1] aquasync/ruby-msg#15
[2] aquasync/ruby-msg#16
[3] #5783 (comment)
[4] mysociety/ruby-msg#3
mysociety-pusher pushed a commit that referenced this issue Oct 14, 2020
Sometimes we receive messages with outlook attachments that can't be
parsed due to an issue in mapi [1].

There's a potential fix [2] but it conflicts [3] with an existing patch
we apply [4].

This at least allows users to download the raw attachment, rather than
us preventing the entire request from loading because we raise an
exception.

It's not easy to include an attachment in the specs to replicate a real
error case due to the complexity of removing PII, so I've just stubbed
the call to `.open` as we don't care about the specifics in this spec.

`script/handle-mail-replies` needs an explicit require as we minimise
the load path for that script.

Part of #5783.

[1] aquasync/ruby-msg#15
[2] aquasync/ruby-msg#16
[3] #5783 (comment)
[4] mysociety/ruby-msg#3
@garethrees
Copy link
Member Author

garethrees commented Nov 11, 2020

We haven't fixed the underlying issue (#5783 (comment)), but we've made our parsing much more resilient to failure (#5920) and the message content in the original bug report is now visible.

Request URL: https://www.asktheeu.org/en/alaveteli_pro/info_requests/vaccine_talks_2
https://www.asktheeu.org/en/request/contrato_no_lc_01464044

In these cases, the .msg files are downloadable and openable in (presumably) Outlook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Breaks expected functionality f:request-analysis x:eu
Projects
None yet
Development

No branches or pull requests

2 participants