I would like to use Net::IMAP to connect to an IMAP server and produce a
list of unread mail messages. For each message, I would like to know 1)
the sender, 2) the subject and 3) a snippet of the body (i.e., first few
I’ve managed to figure out 1 and 2 (sender and subject) but am stumped
on 3. For a plain text message, I see that I can do something like this:
message = imap.fetch(message_id, [“ENVELOPE”, “RFC822.TEXT”])
body = message.attr[“RFC822.TEXT”]
snippet = body[0, 100] # first 100 characters
But what about a multi-part MIME message? I’ve noticed that by fetching
BODYSTRUCTURE, I can get the parts of the mail message. Is there a way
to extract what I want from the BodyTypeText or BodyTypeMultipart
objects? I’ve noticed that these objects give the correct size and
number of lines, etc., but they don’t seem to hold the actual plain text
or HTML content.
I’ve read the docs a few times, but think that I’m missing something
fundamental here. How do I use Net::IMAP as-is to do what I want?
Thanks in advance.