Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write Net::IMAP email to mikel/mail email

Tags:

ruby

I have problem with passing email fetched with Net::IMAP library to Mail object defined with mikel/mail gem.

I get mail with:

data = imap.uid_fetch(1, "BODY[]")

but how should I later put it into Mail.read convention?

mail = Mail.read(data.to_s)

seems to get Errno::ENAMETOOLONG: File name too long. It understands mail body as filename.

Any ideas?

like image 238
Mateusz Avatar asked Feb 24 '23 07:02

Mateusz


1 Answers

Mail.read wants a filename. Use Mail.new to initialize a Mail object from an email source.

Also, fetch RFC822, not BODY[].

mail = Mail.new(imap.uid_fetch(1, "RFC822")[0].attr["RFC822"])
like image 126
Simone Carletti Avatar answered Mar 08 '23 18:03

Simone Carletti