Skip to content

Commit 260d5a5

Browse files
committed
📚 Document fields for FetchData as methods
* Move struct field docs from the class to methods inside the class. * Remove ABNF comments. * Add type information to the call-seq or the method rdoc text. * Link to the data type(s) that are returned, when possible. Expand the attr hash documentation, to provide more examples. Add more data item details from the RFCs.
1 parent a115e1a commit 260d5a5

File tree

1 file changed

+193
-36
lines changed

1 file changed

+193
-36
lines changed

lib/net/imap/response_data.rb

Lines changed: 193 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -448,51 +448,208 @@ class StatusData < Struct.new(:mailbox, :attr)
448448
# "UIDVALIDITY", "UNSEEN". Each value is a number.
449449
end
450450

451-
# Net::IMAP::FetchData represents the contents of the FETCH response.
451+
# Net::IMAP::FetchData represents the contents of a FETCH response.
452452
#
453-
# ==== Fields:
453+
# Net::IMAP#fetch and Net::IMAP#uid_fetch both return an array of
454+
# FetchData objects.
455+
#
456+
# === Fetch attributes
454457
#
455-
# seqno:: Returns the message sequence number.
456-
# (Note: not the unique identifier, even for the UID command response.)
457-
#
458-
# attr:: Returns a hash. Each key is a data item name, and each value is
459-
# its value.
460-
#
461-
# The current data items are:
462-
#
463-
# [BODY]
464-
# A form of BODYSTRUCTURE without extension data.
465-
# [BODY[<section>]<<origin_octet>>]
466-
# A string expressing the body contents of the specified section.
467-
# [BODYSTRUCTURE]
468-
# An object that describes the [MIME-IMB] body structure of a message.
469-
# See Net::IMAP::BodyTypeBasic, Net::IMAP::BodyTypeText,
470-
# Net::IMAP::BodyTypeMessage, Net::IMAP::BodyTypeMultipart.
471-
# [ENVELOPE]
472-
# A Net::IMAP::Envelope object that describes the envelope
473-
# structure of a message.
474-
# [FLAGS]
475-
# A array of flag symbols that are set for this message. Flag symbols
476-
# are capitalized by String#capitalize.
477-
# [INTERNALDATE]
478-
# A string representing the internal date of the message.
479-
# [RFC822]
480-
# Equivalent to +BODY[]+.
481-
# [RFC822.HEADER]
482-
# Equivalent to +BODY.PEEK[HEADER]+.
483-
# [RFC822.SIZE]
484-
# A number expressing the [RFC-822] size of the message.
485-
# [RFC822.TEXT]
486-
# Equivalent to +BODY[TEXT]+.
487-
# [UID]
488-
# A number expressing the unique identifier of the message.
458+
#--
459+
# TODO: merge branch with accessor methods for each type of attr. Then
460+
# move nearly all of the +attr+ documentation onto the appropriate
461+
# accessor methods.
462+
#++
463+
#
464+
# Each key of the #attr hash is the data item name for the fetched value.
465+
# Each data item represents a message attribute, part of one, or an
466+
# interpretation of one. #seqno is not a message attribute. Most message
467+
# attributes are static and must never change for a given <tt>[server,
468+
# account, mailbox, UIDVALIDITY, UID]</tt> tuple. A few message attributes
469+
# can be dynamically changed, e.g. using the {STORE
470+
# command}[rdoc-ref:Net::IMAP#store].
489471
#
490472
# See {[IMAP4rev1] §7.4.2}[https://www.rfc-editor.org/rfc/rfc3501.html#section-7.4.2]
491473
# and {[IMAP4rev2] §7.5.2}[https://www.rfc-editor.org/rfc/rfc9051.html#section-7.5.2]
492474
# for full description of the standard fetch response data items, and
493475
# Net::IMAP@Message+envelope+and+body+structure for other relevant RFCs.
494476
#
477+
# ==== Static fetch data items
478+
#
479+
# The static data items
480+
# defined by [IMAP4rev1[https://www.rfc-editor.org/rfc/rfc3501.html]] are:
481+
#
482+
# [<tt>"UID"</tt>]
483+
# A number expressing the unique identifier of the message.
484+
#
485+
# [<tt>"BODY[]"</tt>, <tt>"BODY[]<#{offset}>"</tt>]
486+
# The [RFC5322[https://tools.ietf.org/html/rfc5322]] expression of the
487+
# entire message, as a string.
488+
#
489+
# If +offset+ is specified, this returned string is a substring of the
490+
# entire contents, starting at that origin octet. This means that
491+
# <tt>BODY[]<0></tt> MAY be truncated, but <tt>BODY[]</tt> is NEVER
492+
# truncated.
493+
#
494+
# <em>Messages can be parsed using the "mail" gem.</em>
495+
#
496+
# [Note]
497+
# When fetching <tt>BODY.PEEK[#{specifier}]</tt>, the data will be
498+
# returned in <tt>BODY[#{specifier}]</tt>, without the +PEEK+. This is
499+
# true for all of the <tt>BODY[...]</tt> attribute forms.
500+
#
501+
# [<tt>"BODY[HEADER]"</tt>, <tt>"BODY[HEADER]<#{offset}>"</tt>]
502+
# The [RFC5322[https://tools.ietf.org/html/rfc5322]] header of the
503+
# message.
504+
#
505+
# <em>Message headers can be parsed using the "mail" gem.</em>
506+
#
507+
# [<tt>"BODY[HEADER.FIELDS (#{fields.join(" ")})]"</tt>,]
508+
# [<tt>"BODY[HEADER.FIELDS (#{fields.join(" ")})]<#{offset}>"</tt>]
509+
# When field names are given, the subset contains only the header fields
510+
# that matches one of the names in the list. The field names are based
511+
# on what was requested, not on what was returned.
512+
#
513+
# [<tt>"BODY[HEADER.FIELDS.NOT (#{fields.join(" ")})]"</tt>,]
514+
# [<tt>"BODY[HEADER.FIELDS.NOT (#{fields.join(" ")})]<#{offset}>"</tt>]
515+
# When the <tt>HEADER.FIELDS.NOT</tt> is used, the subset is all of the
516+
# fields that <em>do not</em> match any names in the list.
517+
#
518+
# [<tt>"BODY[TEXT]"</tt>, <tt>"BODY[TEXT]<#{offset}>"</tt>]
519+
# The text body of the message, omitting
520+
# the [RFC5322[https://tools.ietf.org/html/rfc5322]] header.
521+
#
522+
# [<tt>"BODY[#{part}]"</tt>, <tt>"BODY[#{part}]<#{offset}>"</tt>]
523+
# The text of a particular body section, if it was fetched.
524+
#
525+
# Multiple part specifiers will be joined with <tt>"."</tt>. Numeric
526+
# part specifiers refer to the MIME part number, counting up from +1+.
527+
# Messages that don't use MIME, or MIME messages that are not multipart
528+
# and don't hold an encapsulated message, only have a part +1+.
529+
#
530+
# 8-bit textual data is permitted if
531+
# a [CHARSET[https://tools.ietf.org/html/rfc2978]] identifier is part of
532+
# the body parameter parenthesized list for this section. See
533+
# BodyTypeBasic.
534+
#
535+
# MESSAGE/RFC822 or MESSAGE/GLOBAL message, or a subset of the header, if
536+
# it was fetched.
537+
#
538+
# [<tt>"BODY[#{part}.HEADER]"</tt>,]
539+
# [<tt>"BODY[#{part}.HEADER]<#{offset}>"</tt>,]
540+
# [<tt>"BODY[#{part}.HEADER.FIELDS.NOT (#{fields.join(" ")})]"</tt>,]
541+
# [<tt>"BODY[#{part}.HEADER.FIELDS.NOT (#{fields.join(" ")})]<#{offset}>"</tt>,]
542+
# [<tt>"BODY[#{part}.TEXT]"</tt>,]
543+
# [<tt>"BODY[#{part}.TEXT]<#{offset}>"</tt>,]
544+
# [<tt>"BODY[#{part}.MIME]"</tt>,]
545+
# [<tt>"BODY[#{part}.MIME]<#{offset}>"</tt>]
546+
# +HEADER+, <tt>HEADER.FIELDS</tt>, <tt>HEADER.FIELDS.NOT</tt>, and
547+
# <tt>TEXT</tt> can be prefixed by numeric part specifiers, if it refers
548+
# to a part of type <tt>message/rfc822</tt> or <tt>message/global</tt>.
549+
#
550+
# +MIME+ refers to the [MIME-IMB[https://tools.ietf.org/html/rfc2045]]
551+
# header for this part.
552+
#
553+
# [<tt>"BODY"</tt>]
554+
# A form of +BODYSTRUCTURE+, without any extension data.
555+
#
556+
# [<tt>"BODYSTRUCTURE"</tt>]
557+
# Returns a BodyStructure object that describes
558+
# the [MIME-IMB[https://tools.ietf.org/html/rfc2045]] body structure of
559+
# a message, if it was fetched.
560+
#
561+
# [<tt>"ENVELOPE"</tt>]
562+
# An Envelope object that describes the envelope structure of a message.
563+
# See the documentation for Envelope for a description of the envelope
564+
# structure attributes.
565+
#
566+
# [<tt>"INTERNALDATE"</tt>]
567+
# The internal date and time of the message on the server. This is not
568+
# the date and time in
569+
# the [RFC5322[https://tools.ietf.org/html/rfc5322]] header, but rather
570+
# a date and time which reflects when the message was received.
571+
#
572+
# [<tt>"RFC822.SIZE"</tt>]
573+
# A number expressing the [RFC5322[https://tools.ietf.org/html/rfc5322]]
574+
# size of the message.
575+
#
576+
# [Note]
577+
# \IMAP was originally developed for the older RFC-822 standard, and
578+
# as a consequence several fetch items in \IMAP incorporate "RFC822"
579+
# in their name. With the exception of +RFC822.SIZE+, there are more
580+
# modern replacements; for example, the modern version of
581+
# +RFC822.HEADER+ is <tt>BODY.PEEK[HEADER]</tt>. In all cases,
582+
# "RFC822" should be interpreted as a reference to the
583+
# updated [RFC5322[https://tools.ietf.org/html/rfc5322]] standard.
584+
#
585+
# [<tt>"RFC822"</tt>]
586+
# Semantically equivalent to <tt>BODY[]</tt>.
587+
# [<tt>"RFC822.HEADER"</tt>]
588+
# Semantically equivalent to <tt>BODY[HEADER]</tt>.
589+
# [<tt>"RFC822.TEXT"</tt>]
590+
# Semantically equivalent to <tt>BODY[TEXT]</tt>.
591+
#
592+
# [Note:]
593+
# >>>
594+
# Additional static fields are defined in \IMAP extensions and
595+
# [IMAP4rev2[https://www.rfc-editor.org/rfc/rfc9051.html]], but
596+
# Net::IMAP can't parse them yet.
597+
#
598+
#--
599+
# <tt>"BINARY[#{section_binary}]<#{offset}>"</tt>:: TODO...
600+
# <tt>"BINARY.SIZE[#{sectionbinary}]"</tt>:: TODO...
601+
# <tt>"EMAILID"</tt>:: TODO...
602+
# <tt>"THREADID"</tt>:: TODO...
603+
# <tt>"SAVEDATE"</tt>:: TODO...
604+
#++
605+
#
606+
# ==== Dynamic message attributes
607+
# The only dynamic item defined
608+
# by [{IMAP4rev1}[https://www.rfc-editor.org/rfc/rfc3501.html]] is:
609+
# [<tt>"FLAGS"</tt>]
610+
# An array of flags that are set for this message. System flags are
611+
# symbols that have been capitalized by String#capitalize. Keyword
612+
# flags are strings and their case is not changed.
613+
#
614+
# \IMAP extensions define new dynamic fields, e.g.:
615+
#
616+
# [<tt>"MODSEQ"</tt>]
617+
# The modification sequence number associated with this IMAP message.
618+
#
619+
# Requires the [CONDSTORE[https://tools.ietf.org/html/rfc7162]]
620+
# server {capability}[rdoc-ref:Net::IMAP#capability].
621+
#
622+
# [Note:]
623+
# >>>
624+
# Additional dynamic fields are defined in \IMAP extensions, but
625+
# Net::IMAP can't parse them yet.
626+
#
627+
#--
628+
# <tt>"ANNOTATE"</tt>:: TODO...
629+
# <tt>"PREVIEW"</tt>:: TODO...
630+
#++
631+
#
495632
class FetchData < Struct.new(:seqno, :attr)
633+
##
634+
# method: seqno
635+
# :call-seq: seqno -> Integer
636+
#
637+
# The message sequence number.
638+
#
639+
# [Note]
640+
# This is never the unique identifier (UID), not even for the
641+
# Net::IMAP#uid_fetch result. If it was returned, the UID is available
642+
# from <tt>attr["UID"]</tt>.
643+
644+
##
645+
# method: attr
646+
# :call-seq: attr -> hash
647+
#
648+
# A hash. Each key is specifies a message attribute, and the value is the
649+
# corresponding data item.
650+
#
651+
# See rdoc-ref:FetchData@Fetch+attributes for descriptions of possible
652+
# values.
496653
end
497654

498655
# Net::IMAP::Envelope represents envelope structures of messages.

0 commit comments

Comments
 (0)