diff options
author | Seb Bacon <seb.bacon@gmail.com> | 2011-07-14 08:43:40 +0100 |
---|---|---|
committer | Seb Bacon <seb.bacon@gmail.com> | 2011-07-14 08:43:40 +0100 |
commit | bb790631de2973f8009af558cc9d9a6a70a6efc9 (patch) | |
tree | f8b4eea6246690b724a45adb522d45e1c6708b55 /app/models/incoming_message.rb | |
parent | 13885a4933e7ac4c9e54116dc216e2132ada77da (diff) | |
parent | 4f3f88db01057af00db2796cd5a996e7f69fc8cd (diff) |
Merge branch 'master' of github.com:sebbacon/alaveteli
Conflicts:
app/views/request/_request_listing_single.rhtml
Diffstat (limited to 'app/models/incoming_message.rb')
-rw-r--r-- | app/models/incoming_message.rb | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 4d3c08df3..0ad668afb 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -1144,27 +1144,12 @@ class IncomingMessage < ActiveRecord::Base end elsif content_type == 'application/zip' # recurse into zip files - zip_file = Zip::ZipFile.open(tempfile.path) - for entry in zip_file - if entry.file? - filename = entry.to_s - begin - body = entry.get_input_stream.read - rescue - # move to next attachment silently if there were problems - # XXX really should reduce this to specific exceptions? - # e.g. password protected - next - end - calc_mime = AlaveteliFileTypes.filename_to_mimetype(filename) - if calc_mime - content_type = calc_mime - else - content_type = 'application/octet-stream' - end - - text += _get_attachment_text_internal_one_file(content_type, body) - end + begin + zip_file = Zip::ZipFile.open(tempfile.path) + text += _get_attachment_text_from_zip_file(zip_file) + zip_file.close() + rescue + $stderr.puts("Error processing zip file: #{$!.inspect}") end end tempfile.close @@ -1172,6 +1157,31 @@ class IncomingMessage < ActiveRecord::Base return text end + def _get_attachment_text_from_zip_file(zip_file) + text = "" + for entry in zip_file + if entry.file? + filename = entry.to_s + begin + body = entry.get_input_stream.read + rescue + # move to next attachment silently if there were problems + # XXX really should reduce this to specific exceptions? + # e.g. password protected + next + end + calc_mime = AlaveteliFileTypes.filename_to_mimetype(filename) + if calc_mime + content_type = calc_mime + else + content_type = 'application/octet-stream' + end + + text += _get_attachment_text_internal_one_file(content_type, body) + end + end + return text + end def _get_attachment_text_internal # Extract text from each attachment text = '' |