Skip to content

Commit 1e9797e

Browse files
committed
Save mail attachments
1 parent 48dbf83 commit 1e9797e

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

app/models/message.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,18 @@ def from_mail(mail, list, list_seq)
6767
end
6868

6969
private def handle_multipart(part)
70-
case part.content_type.downcase
71-
when /^text\/plain/
72-
(self.body ||= '') << Kconv.toutf8(part.body.raw_source)
73-
when /^text\/html;/
74-
(self.html_body ||= '') << Kconv.toutf8(part.body.raw_source)
70+
if part.attachment?
71+
file = StringIO.new(part.decoded)
72+
attachments.attach(io: file, filename: part.filename, content_type: part.content_type)
7573
else
76-
puts "Unknown content_type: #{part.content_type}"
74+
case part.content_type.downcase
75+
when /^text\/plain/
76+
(self.body ||= '') << Kconv.toutf8(part.body.raw_source)
77+
when /^text\/html;/
78+
(self.html_body ||= '') << Kconv.toutf8(part.body.raw_source)
79+
else
80+
puts "Unknown content_type: #{part.content_type}"
81+
end
7782
end
7883
end
7984

0 commit comments

Comments
 (0)