mysociety/alaveteli — pull request #979 by mhl (2013-06-05 15:53:06+00:00)
Title: Deal with a cached attachment file disappearing and hexdigest changing

When fetching the body of an attachment with FoiAttachment.body,
it's possible that the contents of the attachment body won't be
cached on disk where we expect. The behaviour then was to cause
a reparse from the raw email, but if the parsing of the email
has changed, this will mean that the attachment has a different
hexdigest, and that FoiAttachment will have been deleted.

In that case, we should throw an exception, since code at a
higher level will have to reload the foi_attachments. This
commit introduces a wrapper function that will retry once on
catching an AttachmentDeletedByReparse. This is then used
in:

- RequestController.get_attachment
- RequestController.get_attachment_as_html
- RequestController.download_entire_request
- IncomingMessage.get_main_body_text_internal

... and tests for each of those uses. (Each test can be
made to fail by commenting out the corresponding use of
cope_with_attachment_deleted_after_reparse.)

Fixes #970

Conflicts:
app/controllers/request_controller.rb