# Help with IMAP documentation

**URL:** <https://www.ruby-forum.com/t/help-with-imap-documentation/85581>\
**Category:** Ruby\
**Created:** [February 14, 2007, 7:07pm UTC](https://www.ruby-forum.com/t/help-with-imap-documentation/85581 "2007-02-14T19:07:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![barjunk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@barjunk](https://www.ruby-forum.com/u/barjunk)\
**Post date:** [February 14, 2007, 7:07pm UTC](https://www.ruby-forum.com/t/help-with-imap-documentation/85581/1 "2007-02-14T19:07:13Z")

</div>

Being new to ruby, I’m having a little trouble getting my mind around  
the documentation for net/imap, located here:

[http://www.ruby-doc.org/stdlib/libdoc/net/imap/rdoc/index.html](http://www.ruby-doc.org/stdlib/libdoc/net/imap/rdoc/index.html)

I understand that if I do:

messagestruct = imap.uid\_fetch(10,[“BODYSTRUCTURE”])[0]

I will get a FetchData object and further processing, like:

message = messagestruct.attr[“BODYSTRUCTURE”].parts[0].subtype

would provide me the type of message (Plain, Html, etc) part 0 is.

But I don’t get what I’m ‘doing’. What words would describe the above  
commands?

I know that message will be an array of FetchData objects.

Just looking for some help on how to read the documentation.

The current question I’m trying to answer is:

In order to get the plain text portion of a multipart message, am I  
really going to have to call uid\_fetch (or fetch), twice? Once to get  
the BODYSTRUCTURE, then again to actually get at the text?

Thanks for any direction you may provide.

Mike B.

---

<div class="post-metadata">

**Author:** ![barjunk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@barjunk](https://www.ruby-forum.com/u/barjunk)\
**Post date:** [February 14, 2007, 8:33pm UTC](https://www.ruby-forum.com/t/help-with-imap-documentation/85581/2 "2007-02-14T20:33:26Z")

</div>

On Feb 14, 2007, at 10:05, barjunk wrote:

> message = messagestruct.attr[“BODYSTRUCTURE”].parts[0].subtype
> 
> would provide me the type of message (Plain, Html, etc) part 0 is.
> 
> But I don’t get what I’m ‘doing’. What words would describe the above  
> commands?

You’ll have to pass the message through a library like TMail to do  
further processing on the body.

---

<div class="post-metadata">

**Author:** ![barjunk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@barjunk](https://www.ruby-forum.com/u/barjunk)\
**Post date:** [February 14, 2007, 11:20pm UTC](https://www.ruby-forum.com/t/help-with-imap-documentation/85581/3 "2007-02-14T23:20:51Z")

</div>

On Feb 14, 10:32 am, Eric H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> You’ll have to pass the message through a library like TMail to do  
> further processing on the body.

Thanks for that…the thing is, its not very clear to me, by reading  
the docs provided, how those message objects are “organized”.

How does one use the documentation provided, along with some  
guesswork, about what the different objects “look” like?

Maybe this is just too broad of a question and as I run into issues, I  
should just ask specific questions about how to solve a specific  
problem…

This is where I see the adopt-a-newbie might come in handy. I don’t  
want to be told how to do it, just what things I should be considering  
as I read through the docs. Experience will fill in the gaps…it  
would be nice if it included experience of others. 🙂

Mike B.  
Mike B.

---

<div class="post-metadata">

**Author:** ![barjunk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@barjunk](https://www.ruby-forum.com/u/barjunk)\
**Post date:** [February 15, 2007, 12:28am UTC](https://www.ruby-forum.com/t/help-with-imap-documentation/85581/4 "2007-02-15T00:28:57Z")

</div>

On Feb 14, 2007, at 14:20, barjunk wrote:

> > > messagestruct = imap.uid\_fetch(10,[“BODYSTRUCTURE”])[0]
> > 
> > You’ll have to pass the message through a library like TMail to do  
> > further processing on the body.
> 
> Thanks for that…the thing is, its not very clear to me, by reading  
> the docs provided, how those message objects are “organized”.
> 
> How does one use the documentation provided, along with some  
> guesswork, about what the different objects “look” like?

There’s two pieces, RFC 3501:

[http://www.rfc-editor.org/rfc/rfc3501.txt](http://www.rfc-editor.org/rfc/rfc3501.txt)

and Net::IMAP docs, particularly fetch:

## $ ri Net::IMAP.fetch -------------------------------------------------------- Net::IMAP#fetch fetch(set, attr)

```
  Sends a FETCH command to retrieve data associated with a message
  in the mailbox. The set parameter is a number or an array of
  numbers or a Range object. The number is a message sequence
  number. attr is a list of attributes to fetch; see the
  documentation for Net::IMAP::FetchData for a list of valid
  attributes. The return value is an array of Net::IMAP::FetchData.
  For example:

    p imap.fetch(6..8, "UID")
    #=> [#<Net::IMAP::FetchData seqno=6, attr={"UID"=>98}>, \
         #<Net::IMAP::FetchData seqno=7, attr={"UID"=>99}>, \
         #<Net::IMAP::FetchData seqno=8, attr={"UID"=>100}>]
    p imap.fetch(6, "BODY[HEADER.FIELDS (SUBJECT)]")
    #=> [#<Net::IMAP::FetchData seqno=6, attr={"BODY

```

[HEADER.FIELDS (SUBJECT)]"=\>“Subject: test\r\n\r\n”}\>]  
data = imap.uid\_fetch(98, [“RFC822.SIZE”, “INTERNALDATE”])[0]  
p data.seqno  
#=\> 6  
p data.attr[“RFC822.SIZE”]  
#=\> 611  
p data.attr[“INTERNALDATE”]  
#=\> “12-Oct-2000 22:40:59 +0900”  
p data.attr[“UID”]  
#=\> 98

> Maybe this is just too broad of a question and as I run into issues, I  
> should just ask specific questions about how to solve a specific  
> problem…

Well, the ri has been immensely helpful to me in writing IMAPCleanse.

> This is where I see the adopt-a-newbie might come in handy. I don’t  
> want to be told how to do it, just what things I should be considering  
> as I read through the docs. Experience will fill in the gaps…it  
> would be nice if it included experience of others. 🙂

What are you building?
