diff options
-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 = '' |