From 00a4b1ce46f3a86622836bf54c060bc5d2165711 Mon Sep 17 00:00:00 2001 From: Naveen Nathan Date: Fri, 25 Oct 2013 01:40:50 +1100 Subject: [PATCH] Updated documentation for the IMAP response type structures. --- imapclient/response_types.py | 59 ++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/imapclient/response_types.py b/imapclient/response_types.py index eae23fe..b4a81f7 100644 --- a/imapclient/response_types.py +++ b/imapclient/response_types.py @@ -2,10 +2,63 @@ # Released subject to the New BSD License # Please see http://en.wikipedia.org/wiki/BSD_licenses +""" +Structured representation for IMAP response. +Inspired by Ruby Net::IMAP::Envelope and Net::IMAP::Address +(see http://www.ruby-doc.org/stdlib-2.0.0/libdoc/net/imap/rdoc/Net/IMAP.html). +""" + from collections import namedtuple -Address = namedtuple("Address", "Name Route Mailbox Host") +# the following hacks to add docstrings to namedtuples is courtesy of: +# http://stackoverflow.com/questions/1606436/adding-docstrings-to-namedtuples-in-python + +class Address(namedtuple("Address", "Name Route Mailbox Host")): + """ + Represents electronic mail addresses. + + Fields (in-order): + + Name -- Returns the phrase from [RFC-822] mailbox. + + Route -- Returns the route from [RFC-822] route-addr. + + Mailbox -- None indicates end of [RFC-822] group. If not None and host is None, + returns [RFC-822] group name. Otherwise, returns [RFC-822] local-part. + + Host -- None indicates [RFC-822] group syntax. Otherwise, returns [RFC-822] domain name. + + + """ # note lowercase "from" is a keyword -Envelope = namedtuple("Envelope", "Date Subject From Sender Reply_To To " + \ - "Cc Bcc In_Reply_To Message_Id") +class Envelope(namedtuple("Envelope", "Date Subject From Sender Reply_To To " + \ + "Cc Bcc In_Reply_To Message_Id")): + """ + + Represents envelope structures of messages. + + Fields (in-order): + + Date -- Returns a string that represents the "Date:" header. + + Subject -- Returns a string that represents the "Subject:" header. + + From -- Returns a tuple sequence of Address structure that represents "From:" header. + + Sender -- Returns a tuple sequence of Address structure that represents "Sender:" header. + + Reply_To -- Returns a tuple sequence of Address structure that represents "Reply_To:" header. + + To -- Returns a tuple sequence of Address structure that represents "To:" header. + + Cc -- Returns a tuple sequence of Address structure that represents "Cc:" header. + + Bcc -- Returns a tuple sequence of Address structure that represents "Bcc:" header. + + In_Reply_To -- Returns a string that represents the "In-Reply-To:" header. + + Message_Id -- Returns a string that represents the "Message-Id:" header. + + + """ -- 2.43.0