Search code examples
pythonimap

get octet value in imap session


In a telnet session for imap, how can I calculate the value for octet to be passed in the search command. for example:

telnet 0 <port for imap>
. login <user> <paswd>
.  select <folder>
. search charset utf-8 body {<octet value>}    

Solution

  • INTERNET MESSAGE ACCESS PROTOCOL - VERSION 4rev1

    4. Data Formats

    IMAP4rev1 uses textual commands and responses. Data in IMAP4rev1 can be in one of several forms: atom, number, string, parenthesized list, or NIL.

    4.3. String

    A string is in one of two forms: either literal or quoted string. A literal is a sequence of zero or more octets (including CR and LF), prefix-quoted with an octet count in the form of an open brace ("{"), the number of octets, close brace ("}"), and CRLF.

    In short, the number inside {} is the number of bytes(octets) or size of data which will be send from client to server.

    For example: Suppose a mail needs to be stored in Sent folder via IMAP APPEND command.

    A003 APPEND "Sent" (\Seen) "24-Oct-2016 14:16:00 +0530" {311}

    Date: Mon, 24 Oct 2016 14:16:00 +0530 (IST)
    From: Fred Foobar <foobar@Blurdybloop.COM>
    Subject: afternoon meeting
    To: mooch@owatagu.siam.edu
    Message-Id: <B27397-0100000@Blurdybloop.COM>
    MIME-Version: 1.0
    Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
    
    Hello Jo2, do you think we can meet at 3:30 tomorrow?
    

    Therefore, {311} is the size of mail.