Permalink
Browse files

move attachment handling code into its own method

  • Loading branch information...
1 parent e0c8fc3 commit dd8e22c1fe2b7fc704ed39919ed6816b4503d85a @maxogden committed Apr 29, 2011
Showing with 18 additions and 13 deletions.
  1. +18 −13 gmail/fetch_data.rb
View
@@ -29,20 +29,8 @@ def to_json
:size => @size,
:flags => @flags,
:raw_mail => @mail.to_s,
- '_attachments' => {}
+ '_attachments' => format_attachments
}
- if @mail.attachments.length > 0
- @mail.attachments.each do |attachment|
- begin
- obj['_attachments'][attachment.filename] = {
- content_type: attachment.content_type.to_s.split("\;")[0],
- data: Base64.encode64(attachment.body.decoded)
- }
- rescue Exception => e
- puts "unable to process #{attachment.filename}"
- end
- end
- end
obj.to_json
end
@@ -73,6 +61,23 @@ def message
#{formatter.process_body}
EOF
end
+
+ def format_attachments
+ attachments = {}
+ if @mail.attachments.length > 0
+ @mail.attachments.each do |attachment|
+ begin
+ attachments[attachment.filename] = {
+ content_type: attachment.content_type.to_s.split("\;")[0],
+ data: Base64.encode64(attachment.body.decoded)
+ }
+ rescue Exception => e
+ puts "unable to process #{attachment.filename}"
+ end
+ end
+ end
+ attachments
+ end
def format_subject(subject)
Mail::Encodings.unquote_and_convert_to((subject || ''), 'UTF-8')

0 comments on commit dd8e22c

Please sign in to comment.