def find_attachment
      content_type_name = header[:content_type].filename rescue nil
      content_disp_name = header[:content_disposition].filename rescue nil
      content_loc_name = header[:content_location].location rescue nil

      if content_type && content_type_name
        filename = content_type_name
      elsif content_disposition && content_disp_name
        filename = content_disp_name
      elsif content_location && content_loc_name
        filename = content_loc_name
      elsif self.mime_type == "message/rfc822"
        filename = "#{rand(100000000)}.eml"
      else
        filename = nil
      end

      if filename
        # Normal decode
        filename = Mail::Encodings.decode_encode(filename, :decode) rescue filename
      end
      filename
    end
def find_attachment
      content_type_name = header[:content_type].filename rescue nil
      content_disp_name = header[:content_disposition].filename rescue nil
      content_loc_name = header[:content_location].location rescue nil

      if content_type && content_type_name
        filename = content_type_name
      elsif content_disposition && content_disp_name
        filename = content_disp_name
      elsif content_location && content_loc_name
        filename = content_loc_name
      elsif self.mime_type == "message/rfc822"
        filename = "#{rand(100000000)}.eml"
      else
        filename = nil
      end

      if filename
        # Normal decode
        filename = Mail::Encodings.decode_encode(filename, :decode) rescue filename
      end
      filename
    end
Handle attached emails as attachments
 Returns the filename of the attachment (if it exists) or returns nil
 Make up a filename for rfc822 attachments if it isn't specified