@@ -870,6 +870,37 @@ class ThreadMember < Struct.new(:seqno, :children)
870870 # children of this in the thread.
871871 end
872872
873+ # Net::IMAP::BodyStructure is included by all of the structs that can be
874+ # returned from a <tt>"BODYSTRUCTURE"</tt> or <tt>"BODY"</tt>
875+ # FetchData#attr value. Although these classes don't share a base class,
876+ # this module can be used to pattern match all of them.
877+ #
878+ # See {[IMAP4rev1] §7.4.2}[https://www.rfc-editor.org/rfc/rfc3501.html#section-7.4.2]
879+ # and {[IMAP4rev2] §7.5.2}[https://www.rfc-editor.org/rfc/rfc9051.html#section-7.5.2-4.9]
880+ # for full description of all +BODYSTRUCTURE+ fields, and also
881+ # Net::IMAP@Message+envelope+and+body+structure for other relevant RFCs.
882+ #
883+ # === Classes that include BodyStructure
884+ # BodyTypeBasic:: Represents any message parts that are not handled by
885+ # BodyTypeText, BodyTypeMessage, or BodyTypeMultipart.
886+ # BodyTypeText:: Used by <tt>text/*</tt> parts. Contains all of the
887+ # BodyTypeBasic fields.
888+ # BodyTypeMessage:: Used by <tt>message/rfc822</tt> and
889+ # <tt>message/global</tt> parts. Contains all of the
890+ # BodyTypeBasic fields. Other <tt>message/*</tt> types
891+ # should use BodyTypeBasic.
892+ # BodyTypeMultipart:: for <tt>multipart/*</tt> parts
893+ #
894+ # ==== Deprecated BodyStructure classes
895+ # The following classes represent invalid server responses or parser bugs:
896+ # BodyTypeExtension:: parser bug: used for <tt>message/*</tt> where
897+ # BodyTypeBasic should have been used.
898+ # BodyTypeAttachment:: server bug: some servers sometimes return the
899+ # "Content-Disposition: attachment" data where the
900+ # entire body structure for a message part is expected.
901+ module BodyStructure
902+ end
903+
873904 # Net::IMAP::BodyTypeBasic represents basic body structures of messages and
874905 # message parts, unless they have a <tt>Content-Type</tt> that is handled by
875906 # BodyTypeText, BodyTypeMessage, or BodyTypeMultipart.
@@ -884,6 +915,7 @@ class BodyTypeBasic < Struct.new(:media_type, :subtype,
884915 :description , :encoding , :size ,
885916 :md5 , :disposition , :language ,
886917 :extension )
918+ include BodyStructure
887919
888920 ##
889921 # method: media_type
@@ -1018,6 +1050,7 @@ class BodyTypeText < Struct.new(:media_type, :subtype,
10181050 :lines ,
10191051 :md5 , :disposition , :language ,
10201052 :extension )
1053+ include BodyStructure
10211054
10221055 ##
10231056 # method: lines
@@ -1062,6 +1095,7 @@ class BodyTypeMessage < Struct.new(:media_type, :subtype,
10621095 :envelope , :body , :lines ,
10631096 :md5 , :disposition , :language ,
10641097 :extension )
1098+ include BodyStructure
10651099
10661100 ##
10671101 # method: envelope
@@ -1120,6 +1154,7 @@ def media_subtype
11201154 # structure.
11211155 #
11221156 class BodyTypeAttachment < Struct . new ( :dsp_type , :_unused_ , :param )
1157+ include BodyStructure
11231158
11241159 # *invalid for BodyTypeAttachment*
11251160 def media_type
@@ -1161,6 +1196,7 @@ class BodyTypeMultipart < Struct.new(:media_type, :subtype,
11611196 :parts ,
11621197 :param , :disposition , :language ,
11631198 :extension )
1199+ include BodyStructure
11641200
11651201 ##
11661202 # method: media_type
@@ -1240,6 +1276,8 @@ def media_subtype
12401276 class BodyTypeExtension < Struct . new ( :media_type , :subtype ,
12411277 :params , :content_id ,
12421278 :description , :encoding , :size )
1279+ include BodyStructure
1280+
12431281 def multipart?
12441282 return false
12451283 end
0 commit comments