Permalink
Browse files

Handle non-multipart messages correctly

  • Loading branch information...
1 parent d62d0e6 commit 2fdce6900aa0929d148786e42e8f58f902bf65c2 @sj26 sj26 committed Nov 4, 2010
Showing with 4 additions and 2 deletions.
  1. +4 −2 lib/mail_catcher/mail.rb
@@ -42,9 +42,11 @@ def add_message(message)
mail = Mail.new(message[:source])
result = @@add_message_query.execute(message[:sender], message[:recipients].inspect, mail.subject, message[:source], message[:source].length)
message_id = db.last_insert_row_id
- (mail.all_parts || [mail]).each do |part|
+ (mail.all_parts.presence || [mail]).each do |part|
body = part.body.to_s
- add_message_part(message_id, part.cid, part.mime_type || 'text/plain', part.attachment? ? 1 : 0, part.filename, part.charset, body, body.length)
+ # Only parts have CIDs, not mail
+ cid = part.cid if part.respond_to? :cid
+ add_message_part(message_id, cid, part.mime_type || 'text/plain', part.attachment? ? 1 : 0, part.filename, part.charset, body, body.length)
end
EventMachine.next_tick do

0 comments on commit 2fdce69

Please sign in to comment.