Mateusz
Mateusz

Reputation: 1197

Write Net::IMAP email to mikel/mail email

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?

Upvotes: 4

Views: 1035

Answers (1)

Simone Carletti
Simone Carletti

Reputation: 176472

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"])

Upvotes: 8

Related Questions