Your IP : 216.73.216.134


Current Path : /opt/rh/rh-python35/root/lib64/python3.5/__pycache__/
Upload File :
Current File : //opt/rh/rh-python35/root/lib64/python3.5/__pycache__/imaplib.cpython-35.pyc



���\��Y@sbdZdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZmZm
Z
ddlmZyddlZdZWnek
r�dZYnXdd	d
ddd
gZdZdZdZdZddfZdZdddfddfdddddfddfddfddfdddfdddfdddfd dfd!ddfd"dfd#dfd$ddfd%ddfd&ddfd'ddfd(ddfd)ddfd*dfdddddfd+ddfd,ddfd-ddddfd.dfd/dfd0ddfd1dfd2ddfd3ddfd4ddfd5ddfd6dfd7dfd8ddfd9dfd:ddfd;dfd<dfd=ddfi(Zejd>�Zejd?�Zejd@�ZejdAej�Z ejdB�Z!ejdC�Z"ejdD�Z#ejdEej�Z$dAZ%dEZ&GdFd�d�Z'er�GdGdH�dHe'�Z(ej)dH�GdId	�d	e'�Z*GdJdK�dK�Z+dLj,dM�Z-dNdO�e.e-dPd��D�Z/dQd
�Z0dRd�Z1dSd�Z2dTd
�Z3e4dUkr^ddl5Z5ddl6Z6y)e5j5ej7dPd�dV�\Z8Z9Wn:e5j:k
r�Z;zfff\Z8Z9WYddZ;[;XnXdZ<xQe8D]I\Z=Z;e=dWkr�e>e;�Zn"e=dXkre;Z<e9re<fZ9q�We9r*dYfZ9e9dZ?e6j@�ZAe6j6dZeAe?pUd[f�ZBd\d]eAd^d_iZCd`eAeBffdadbffdcdbddffddeffdfdeddeCffdgdhdiffdjdeffdkddldmffdndodpffdqdodrdsffdtffduffdvffdwfffZDdjffdxdyffdzd1d{ffdxd|ffdfdddeCffdvffd}fffZEd~d�ZFy�e<r�e*e<�ZGne'e?�ZGeGjHdkr�eDdPd�ZDeGjId�eGjJ�eGjId�eGjKf�x!eDD]\ZLZ9eFeLe9�qWxheFdgd�d�f�D]QZMejNd�eM�ZOeOryeOjPdP�ZQneMj,�dPZQeFd�eQf�qIWx~eED]v\ZLZ9eFeLe9�ZReLe9fdzd1d{ffkr�q�eRdPj,�ZSeSr�q�eFdzd#d�eSdPd�f�q�WeTd��Wn1eTd��erVeTd�ej7d��YnXdS)�z�IMAP4 client.

Based on RFC 2060.

Public class:           IMAP4
Public variable:        Debug
Public functions:       Internaldate2tuple
                        Int2AP
                        ParseFlags
                        Time2Internaldate
z2.58�N)�datetime�timezone�	timedelta)�DEFAULT_BUFFER_SIZETF�IMAP4�IMAP4_stream�Internaldate2tuple�Int2AP�
ParseFlags�Time2Internaldates
�i�Z	IMAP4REV1i@B�APPEND�AUTH�SELECTED�AUTHENTICATE�NONAUTH�
CAPABILITY�LOGOUT�CHECK�CLOSE�COPY�CREATE�DELETE�	DELETEACL�ENABLE�EXAMINE�EXPUNGE�FETCH�GETACL�
GETANNOTATION�GETQUOTA�GETQUOTAROOT�MYRIGHTS�LIST�LOGIN�LSUB�	NAMESPACE�NOOP�PARTIAL�	PROXYAUTH�RENAME�SEARCH�SELECT�SETACL�
SETANNOTATION�SETQUOTA�SORT�STARTTLS�STATUS�STORE�	SUBSCRIBE�THREAD�UID�UNSUBSCRIBEs\+( (?P<data>.*))?s.*FLAGS \((?P<flags>[^\)]*)\)s�.*INTERNALDATE "(?P<day>[ 0123][0-9])-(?P<mon>[A-Z][a-z][a-z])-(?P<year>[0-9][0-9][0-9][0-9]) (?P<hour>[0-9][0-9]):(?P<min>[0-9][0-9]):(?P<sec>[0-9][0-9]) (?P<zonen>[-+])(?P<zoneh>[0-9][0-9])(?P<zonem>[0-9][0-9])"s.*{(?P<size>\d+)}$s
\r\n|\r|\ns)\[(?P<type>[A-Z-]+)( (?P<data>[^\]]*))?\]s$\* (?P<type>[A-Z-]+)( (?P<data>.*))?s3\* (?P<data>\d+) (?P<type>[A-Z-]+)( (?P<data2>.*))?c@seZdZdZGdd�de�ZGdd�de�ZGdd�de�Zded	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdedd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Z d9d:�Z!d;d<�Z"d=d>�Z#d?d@�Z$dAdB�Z%dCdD�Z&dEdF�Z'dGdH�Z(dIdJdKdL�Z)dMdN�Z*dOdP�Z+dQdR�Z,dSdT�Z-dIdJdUdV�Z.dWdX�Z/dYdZ�Z0d[d\�Z1d]d^�Z2d_d`�Z3dadb�Z4dcdd�Z5dedfdgdh�Z6didj�Z7dkdl�Z8dmdn�Z9dodp�Z:dqdrds�Z;dtdu�Z<dvdw�Z=dxdy�Z>dzd{�Z?d|d}�Z@d~d�ZAd�d��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKd�d��ZLd�d��ZMd�d��ZNd�d��ZOdqd�d��ZPd�d��ZQd�d��ZRd�d��ZSdqS)�ra�IMAP4 client class.

    Instantiate with: IMAP4([host[, port]])

            host - host's name (default: localhost);
            port - port number (default: standard IMAP4 port).

    All IMAP4rev1 commands are supported by methods of the same
    name (in lower-case).

    All arguments to commands are converted to strings, except for
    AUTHENTICATE, and the last argument to APPEND which is passed as
    an IMAP4 literal.  If necessary (the string contains any
    non-printing characters or white-space and isn't enclosed with
    either parentheses or double quotes) each string is quoted.
    However, the 'password' argument to the LOGIN command is always
    quoted.  If you want to avoid having an argument string quoted
    (eg: the 'flags' argument to STORE) then enclose the string in
    parentheses (eg: "(\Deleted)").

    Each command returns a tuple: (type, [data, ...]) where 'type'
    is usually 'OK' or 'NO', and 'data' is either the text from the
    tagged response, or untagged results from command. Each 'data'
    is either a string, or a tuple. If a tuple, then the first part
    is the header of the response, and the second part contains
    the data (ie: 'literal' value).

    Errors raise the exception class <instance>.error("<reason>").
    IMAP4 server errors raise <instance>.abort("<reason>"),
    which is a sub-class of 'error'. Mailbox status changes
    from READ-WRITE to READ-ONLY raise the exception class
    <instance>.readonly("<reason>"), which is a sub-class of 'abort'.

    "error" exceptions imply a program error.
    "abort" exceptions imply the connection should be reset, and
            the command re-tried.
    "readonly" exceptions imply the command should be re-tried.

    Note: to use this module, you must read the RFCs pertaining to the
    IMAP4 protocol, as the semantics of the arguments to each IMAP4
    command are left to the invoker, not to mention the results. Also,
    most IMAP servers implement a sub-set of the commands available here.
    c@seZdZdS)zIMAP4.errorN)�__name__�
__module__�__qualname__�r;r;�7/opt/rh/rh-python35/root/usr/lib64/python3.5/imaplib.py�error�sr=c@seZdZdS)zIMAP4.abortN)r8r9r:r;r;r;r<�abort�sr>c@seZdZdS)zIMAP4.readonlyN)r8r9r:r;r;r;r<�readonly�sr?�cCs�t|_d|_d|_i|_i|_d|_d|_d|_d|_	|j
�|j||�y|j�Wn8t
k
r�y|j�Wntk
r�YnX�YnXdS)Nrr@Fr)�Debug�debug�state�literal�tagged_commands�untagged_responses�continuation_response�is_readonly�tagnum�_tls_established�_mode_ascii�open�_connect�	Exception�shutdown�OSError)�self�host�portr;r;r<�__init__�s&									


zIMAP4.__init__cCsFd|_d|_tjttj�|_tjttj�|_dS)NF�ascii)	�utf8_enabled�	_encoding�re�compile�_Literal�ASCII�Literal�_Untagged_status�Untagged_status)rQr;r;r<rK�s		zIMAP4._mode_asciicCs:d|_d|_tjt�|_tjt�|_dS)NTzutf-8)rVrWrXrYrZr\r]r^)rQr;r;r<�
_mode_utf8�s		zIMAP4._mode_utf8cCsTttjdd��|_tjd|jdtj�|_d|_d|_	i|_
|jdkr�|jdt
�|jd	|j�|j�|_d
|jkr�d|_n-d|jkr�d
|_n|j|j��|j�|jdkr|jd|jf�x*tD]"}||jkr3q||_dSW|jd��dS)Nii��s(?P<tag>s"\d+) (?P<type>[A-Z]+) (?P<data>.*)�
r�zimaplib version %sznew IMAP4 connection, tag=%sZPREAUTHr�OKr�zCAPABILITIES: %rzserver not IMAP4 compliant)r	�randomZrandint�tagprerXrYr[�tagre�_cmd_log_len�_cmd_log_idx�_cmd_logrB�_mesg�__version__�
_get_responseZwelcomerFrCr=�_get_capabilities�capabilities�AllowedVersions�PROTOCOL_VERSION)rQ�versionr;r;r<rM�s0			

	zIMAP4._connectcCs3|tkrt||j��Std|��dS)NzUnknown IMAP4 command: '%s')�Commands�getattr�lower�AttributeError)rQ�attrr;r;r<�__getattr__szIMAP4.__getattr__cCs|S)Nr;)rQr;r;r<�	__enter__szIMAP4.__enter__cGs'y|j�Wntk
r"YnXdS)N)�logoutrP)rQ�argsr;r;r<�__exit__	s
zIMAP4.__exit__cCstj|j|jf�S)N)�socketZcreate_connectionrRrS)rQr;r;r<�_create_socketszIMAP4._create_socketcCs:||_||_|j�|_|jjd�|_dS)z�Setup connection to remote server on "host:port"
            (default: localhost:standard IMAP4 port).
        This connection will be used by the routines:
            read, readline, send, shutdown.
        �rbN)rRrSr}�sock�makefile�file)rQrRrSr;r;r<rLs		z
IMAP4.opencCs|jj|�S)zRead 'size' bytes from remote.)r��read)rQ�sizer;r;r<r�"sz
IMAP4.readcCs?|jjtd�}t|�tkr;|jdt��|S)zRead line from remote.razgot more than %d bytes)r��readline�_MAXLINE�lenr=)rQ�liner;r;r<r�'szIMAP4.readlinecCs|jj|�dS)zSend data to remote.N)rZsendall)rQ�datar;r;r<�send/sz
IMAP4.sendcCsz|jj�zXy|jjtj�Wn:tk
rc}z|jtjkrQ�WYdd}~XnXWd|jj�XdS)z Close I/O established in "open".N)	r��closerrOr|Z	SHUT_RDWRrP�errnoZENOTCONN)rQ�er;r;r<rO4s
zIMAP4.shutdowncCs|jS)zfReturn socket instance used to connect to IMAP4 server.

        socket = <instance>.socket()
        )r)rQr;r;r<r|AszIMAP4.socketcCs]d}|jddg|�\}}|dr8||fS|j�\}}|j|||�S)aReturn most recent 'RECENT' responses if any exist,
        else prompt server for an update using the 'NOOP' command.

        (typ, [data]) = <instance>.recent()

        'data' is None if no new messages,
        else list of RECENT responses, most recent last.
        ZRECENTrbNra���)�_untagged_response�noop)rQ�name�typ�datr;r;r<�recentMs	

zIMAP4.recentcCs|j|dg|j��S)z�Return data for response 'code' if received, or None.

        Old value for response 'code' is cleared.

        (code, [data]) = <instance>.response(code)
        N)r��upper)rQ�coder;r;r<�response^szIMAP4.responsecCs�d}|sd}|r?|d|dfdkrEd|}nd}|rZt|�}nd}tjt|�}|jr�d	|d
}||_|j||||�S)
z�Append message to named mailbox.

        (typ, [data]) = <instance>.append(mailbox, flags, date_time, message)

                All args except `message' can be None.
        r
�INBOXrra�(�)z(%s)NsUTF8 (�)r�)r�r�)r�MapCRLF�sub�CRLFrVrD�_simple_command)rQ�mailbox�flags�	date_time�messager�rDr;r;r<�appendls
		zIMAP4.appendcCsh|j�}t|�j|_|jd|�\}}|dkrU|j|d��d|_||fS)asAuthenticate command - requires response processing.

        'mechanism' specifies which authentication mechanism is to
        be used - it must appear in <instance>.capabilities in the
        form AUTH=<mechanism>.

        'authobject' must be a callable object:

                data = authobject(response)

        It will be called to process server continuation responses; the
        response argument it is passed will be a bytes.  It should return bytes
        data that will be base64 encoded and sent to the server.  It should
        return None if the client abort response '*' should be sent instead.
        rrbrarr�)r��_Authenticator�processrDr�r=rC)rQZ	mechanismZ
authobject�mechr�r�r;r;r<�authenticate�s	zIMAP4.authenticatecCs.d}|j|�\}}|j|||�S)zT(typ, [data]) = <instance>.capability()
        Fetch capabilities list from server.r)r�r�)rQr�r�r�r;r;r<�
capability�szIMAP4.capabilitycCs
|jd�S)zRCheckpoint mailbox on server.

        (typ, [data]) = <instance>.check()
        r)r�)rQr;r;r<�check�szIMAP4.checkcCs0z|jd�\}}Wdd|_X||fS)z�Close currently selected mailbox.

        Deleted messages are removed from writable mailbox.
        This is the recommended command before 'LOGOUT'.

        (typ, [data]) = <instance>.close()
        rNr)r�rC)rQr�r�r;r;r<r��s
zIMAP4.closecCs|jd||�S)z�Copy 'message_set' messages onto end of 'new_mailbox'.

        (typ, [data]) = <instance>.copy(message_set, new_mailbox)
        r)r�)rQ�message_setZnew_mailboxr;r;r<�copy�sz
IMAP4.copycCs|jd|�S)zPCreate new mailbox.

        (typ, [data]) = <instance>.create(mailbox)
        r)r�)rQr�r;r;r<�create�szIMAP4.createcCs|jd|�S)zPDelete old mailbox.

        (typ, [data]) = <instance>.delete(mailbox)
        r)r�)rQr�r;r;r<�delete�szIMAP4.deletecCs|jd||�S)z�Delete the ACLs (remove any rights) set for who on mailbox.

        (typ, [data]) = <instance>.deleteacl(mailbox, who)
        r)r�)rQr��whor;r;r<�	deleteacl�szIMAP4.deleteaclcCshd|jkrtjd��|jd|�\}}|dkr^d|j�kr^|j�||fS)zkSend an RFC5161 enable string to the server.

        (typ, [data]) = <intance>.enable(capability)
        rzServer does not support ENABLErbzUTF8=ACCEPT)rnrr=r�r�r_)rQr�r�r�r;r;r<�enable�s
zIMAP4.enablecCs.d}|j|�\}}|j|||�S)z�Permanently remove deleted items from selected mailbox.

        Generates 'EXPUNGE' response for each deleted message.

        (typ, [data]) = <instance>.expunge()

        'data' is list of 'EXPUNGE'd message numbers in order received.
        r)r�r�)rQr�r�r�r;r;r<�expunge�s	z
IMAP4.expungecCs4d}|j|||�\}}|j|||�S)a#Fetch (parts of) messages.

        (typ, [data, ...]) = <instance>.fetch(message_set, message_parts)

        'message_parts' should be a string of selected parts
        enclosed in parentheses, eg: "(UID BODY[TEXT])".

        'data' are tuples of message part envelope and data.
        r)r�r�)rQr�Z
message_partsr�r�r�r;r;r<�fetch�s
zIMAP4.fetchcCs+|jd|�\}}|j||d�S)zXGet the ACLs for a mailbox.

        (typ, [data]) = <instance>.getacl(mailbox)
        rZACL)r�r�)rQr�r�r�r;r;r<�getacl
szIMAP4.getaclcCs1|jd|||�\}}|j||d�S)za(typ, [data]) = <instance>.getannotation(mailbox, entry, attribute)
        Retrieve ANNOTATIONs.r�
ANNOTATION)r�r�)rQr��entryZ	attributer�r�r;r;r<�
getannotationszIMAP4.getannotationcCs+|jd|�\}}|j||d�S)z�Get the quota root's resource usage and limits.

        Part of the IMAP4 QUOTA extension defined in rfc2087.

        (typ, [data]) = <instance>.getquota(root)
        r �QUOTA)r�r�)rQ�rootr�r�r;r;r<�getquotaszIMAP4.getquotacCs^|jd|�\}}|j||d�\}}|j||d�\}}|||gfS)z�Get the list of quota roots for the named mailbox.

        (typ, [[QUOTAROOT responses...], [QUOTA responses]]) = <instance>.getquotaroot(mailbox)
        r!r�Z	QUOTAROOT)r�r�)rQr�r�r�ZquotaZ	quotarootr;r;r<�getquotaroot&szIMAP4.getquotarootz""�*cCs4d}|j|||�\}}|j|||�S)z�List mailbox names in directory matching pattern.

        (typ, [data]) = <instance>.list(directory='""', pattern='*')

        'data' is list of LIST responses.
        r#)r�r�)rQ�	directory�patternr�r�r�r;r;r<�list1sz
IMAP4.listcCsV|jd||j|��\}}|dkrC|j|d��d|_||fS)z�Identify client using plaintext password.

        (typ, [data]) = <instance>.login(user, password)

        NB: 'password' will be quoted.
        r$rbrarr�)r��_quoter=rC)rQ�user�passwordr�r�r;r;r<�login=s
$	zIMAP4.logincCs&|||_|_|jd|j�S)zr Force use of CRAM-MD5 authentication.

        (typ, [data]) = <instance>.login_cram_md5(user, password)
        zCRAM-MD5)r�r�r��_CRAM_MD5_AUTH)rQr�r�r;r;r<�login_cram_md5KszIMAP4.login_cram_md5cCs]ddl}t|jt�r0|jjd�n|j}|jd|j||d�j�S)z1 Authobject to use with CRAM-MD5 authentication. rNzutf-8� Zmd5)�hmac�
isinstancer��str�encoder�ZHMACZ	hexdigest)rQZ	challenger��pwdr;r;r<r�Ts$	zIMAP4._CRAM_MD5_AUTHcCs�d|_y|jd�\}}Wn,ddtj�dd�g}}YnX|j�d|jkr{d|jdfS||fS)z|Shutdown connection to server.

        (typ, [data]) = <instance>.logout()

        Returns server 'BYE' response.
        r�NOz%s: %sN��BYE)rCr��sys�exc_inforOrF)rQr�r�r;r;r<ry\s	)
zIMAP4.logoutcCs4d}|j|||�\}}|j|||�S)z�List 'subscribed' mailbox names in directory matching pattern.

        (typ, [data, ...]) = <instance>.lsub(directory='""', pattern='*')

        'data' are tuples of message part envelope and data.
        r%)r�r�)rQr�r�r�r�r�r;r;r<�lsublsz
IMAP4.lsubcCs+|jd|�\}}|j||d�S)z�Show my ACLs for a mailbox (i.e. the rights that I have on mailbox).

        (typ, [data]) = <instance>.myrights(mailbox)
        r")r�r�)rQr�r�r�r;r;r<�myrightswszIMAP4.myrightscCs.d}|j|�\}}|j|||�S)zb Returns IMAP namespaces ala rfc2342

        (typ, [data, ...]) = <instance>.namespace()
        r&)r�r�)rQr�r�r�r;r;r<�	namespaceszIMAP4.namespacecCs,|jdkr|j|j�|jd�S)zFSend NOOP command.

        (typ, [data]) = <instance>.noop()
        rcr')rB�_dump_urrFr�)rQr;r;r<r��sz
IMAP4.noopcCs:d}|j|||||�\}}|j||d�S)z�Fetch truncated part of a message.

        (typ, [data, ...]) = <instance>.partial(message_num, message_part, start, length)

        'data' is tuple of message part envelope and data.
        r(r)r�r�)rQZmessage_numZmessage_part�startZlengthr�r�r�r;r;r<�partial�s!z
IMAP4.partialcCsd}|jd|�S)z�Assume authentication as "user".

        Allows an authorised administrator to proxy into any user's
        mailbox.

        (typ, [data]) = <instance>.proxyauth(user)
        r))r�)rQr�r�r;r;r<�	proxyauth�s	zIMAP4.proxyauthcCs|jd||�S)zkRename old mailbox name to new.

        (typ, [data]) = <instance>.rename(oldmailbox, newmailbox)
        r*)r�)rQZ
oldmailboxZ
newmailboxr;r;r<�rename�szIMAP4.renamecGspd}|rE|jr$tjd��|j|d||�\}}n|j||�\}}|j|||�S)z�Search mailbox for matching messages.

        (typ, [data]) = <instance>.search(charset, criterion, ...)

        'data' is space separated list of matching message numbers.
        If UTF8 is enabled, charset MUST be None.
        r+z'Non-None charset not valid in UTF8 mode�CHARSET)rVrr=r�r�)rQ�charsetZcriteriar�r�r�r;r;r<�search�s	!zIMAP4.searchr�FcCs�i|_||_|r!d}nd}|j||�\}}|dkr^d|_||fSd|_d|jkr�|r�|jdkr�|j|j�|jd|��||jjd	d
g�fS)atSelect a mailbox.

        Flush all untagged responses.

        (typ, [data]) = <instance>.select(mailbox='INBOX', readonly=False)

        'data' is count of messages in mailbox ('EXISTS' response).

        Mandated responses are ('FLAGS', 'EXISTS', 'RECENT', 'UIDVALIDITY'), so
        other responses should be obtained via <instance>.response('FLAGS') etc.
        rr,rbrrz	READ-ONLYraz%s is not writable�EXISTSN)rFrHr�rCrBr�r?�get)rQr�r?r�r�r�r;r;r<�select�s 				
	zIMAP4.selectcCs|jd|||�S)zZSet a mailbox acl.

        (typ, [data]) = <instance>.setacl(mailbox, who, what)
        r-)r�)rQr�r�Zwhatr;r;r<�setacl�szIMAP4.setaclcGs+|jd|�\}}|j||d�S)z_(typ, [data]) = <instance>.setannotation(mailbox[, entry, attribute]+)
        Set ANNOTATIONs.r.r�)r�r�)rQrzr�r�r;r;r<�
setannotation�szIMAP4.setannotationcCs.|jd||�\}}|j||d�S)ziSet the quota root's resource limits.

        (typ, [data]) = <instance>.setquota(root, limits)
        r/r�)r�r�)rQr�Zlimitsr�r�r;r;r<�setquota�szIMAP4.setquotacGs[d}|d|dfdkr*d|}|j||||�\}}|j|||�S)	z�IMAP4rev1 extension SORT command.

        (typ, [data]) = <instance>.sort(sort_criteria, charset, search_criteria, ...)
        r0rrar�r�z(%s)r�)r�r�)r�r�)rQZ
sort_criteriar��search_criteriar�r�r�r;r;r<�sorts

z
IMAP4.sortNcCs�d}ts|jd��|jr3|jd��||jkrQ|jd��|dkritj�}|j|�\}}|dkr�|j|j	d|j
�|_	|j	jd�|_d|_|j
�n|jd	��|j|||�S)
Nr1zSSL support missingzTLS session already establishedzTLS not supported by serverrb�server_hostnamer~TzCouldn't establish TLS session)�HAVE_SSLr=rJr>rn�ssl�_create_stdlib_contextr��wrap_socketrrRr�r�rmr�)rQ�ssl_contextr�r�r�r;r;r<�starttlss$		
zIMAP4.starttlscCs4d}|j|||�\}}|j|||�S)zpRequest named status conditions for mailbox.

        (typ, [data]) = <instance>.status(mailbox, names)
        r2)r�r�)rQr��namesr�r�r�r;r;r<�status%szIMAP4.statuscCsU|d|dfd	kr$d|}|jd|||�\}}|j||d�S)
z�Alters flag dispositions for messages in mailbox.

        (typ, [data]) = <instance>.store(message_set, command, flags)
        rrar�r�z(%s)r3rr�)r�r�)r�r�)rQr��commandr�r�r�r;r;r<�store1s
zIMAP4.storecCs|jd|�S)zYSubscribe to new mailbox.

        (typ, [data]) = <instance>.subscribe(mailbox)
        r4)r�)rQr�r;r;r<�	subscribe<szIMAP4.subscribecGs7d}|j||||�\}}|j|||�S)z�IMAPrev1 extension THREAD command.

        (type, [data]) = <instance>.thread(threading_algorithm, charset, search_criteria, ...)
        r5)r�r�)rQZthreading_algorithmr�r�r�r�r�r;r;r<�threadDszIMAP4.threadcGs�|j�}|tkr+|jd|��|jt|krj|jd||jdjt|�f��d}|j|||�\}}|d	kr�|}nd}|j|||�S)
z�Execute "command arg ..." with messages identified by UID,
                rather than message number.

        (typ, [data]) = <instance>.uid(command, arg1, arg2, ...)

        Returns response appropriate to 'command'.
        zUnknown IMAP4 UID command: %sz9command %s illegal in state %s, only allowed in states %sz, r6r+r0r5r)zSEARCHzSORTzTHREAD)r�rrr=rC�joinr�r�)rQr�rzr�r�r�r;r;r<�uidNs			z	IMAP4.uidcCs|jd|�S)z_Unsubscribe from old mailbox.

        (typ, [data]) = <instance>.unsubscribe(mailbox)
        r7)r�)rQr�r;r;r<�unsubscribegszIMAP4.unsubscribecGs8|j�}|tkr(|jft|<|j||�S)aAllow simple extension commands
                notified by server in CAPABILITY response.

        Assumes command is legal in current state.

        (typ, [data]) = <instance>.xatom(name, arg, ...)

        Returns response appropriate to extension command `name'.
        )r�rrrCr�)rQr�rzr;r;r<�xatomos
zIMAP4.xatomcCs�|dkrd}|j}|jdkrV|jd|t|j|d��|f�||krv||j|�n
|g||<dS)N��z#untagged_responses[%s] %s += ["%r"]r@)rFrBrjr�r�r�)rQr�r�Zurr;r;r<�_append_untagged�s		#zIMAP4._append_untaggedcCs>|jjd�}|r:|j|dj|jd���dS)Nr�ra�replacer�)rFr�r>�decoderW)rQZbyer;r;r<�
_check_bye�szIMAP4._check_byec
Gs�|jt|krHd|_|jd||jdjt|�f��x'dD]}||jkrO|j|=qOWd|jkr�|jr�|jd��|j�}t	||j
�}|d|}xL|D]D}|dkr�q�t|t�rt	||j
�}|d|}q�W|j}|dk	r}d|_t
|�t
|j�krW|}n&d}|t	d	t|�|j
�}|jd
kr�|jd|�n|jd|�y|j|t�Wn8tk
r}	z|jd|	��WYdd}	~	XnX|dkr|Sx�x!|j�r7|j|r|SqW|rM||j�}|jd
krs|jd
t|��y|j|�|jt�Wn8tk
r�}	z|jd|	��WYdd}	~	XnX|sPqW|S)Nz9command %s illegal in state %s, only allowed in states %sz, rbr��BADz	READ-ONLYz#mailbox status changed to READ-ONLY� z {%s}�z> %rzsocket error: %szwrite literal size %s)zOKzNOr�)rCrrrDr=r�rFrHr?�_new_tag�bytesrWr�r��type�_commandr�rBrj�_logr�r�rPr>rlrErG)
rQr�rzr��tagr��argrDZ	literator�valr;r;r<r�sh			


			 &

&zIMAP4._commandcCs�|dkr|j�y|j|�\}}Wn�|jk
rr}z|jd||f��WYdd}~XnA|jk
r�}z|jd||f��WYdd}~XnX|dkr�|j�|dkr�|jd|||f��||fS)Nrzcommand: %s => %sr�z%s command error: %s %s)r��_get_tagged_responser>r=)rQr�rr�r�rr;r;r<�_command_complete�s
+,
zIMAP4._command_completecCsk|j�\}}|dgkr0|jd��t|d|j�}|j�}t|j��|_dS)Nz"no CAPABILITY response from serverrar�)r�r=r�rWr��tuple�splitrn)rQr�r�r;r;r<rm�szIMAP4._get_capabilitiescCs�|j�}|j|j|�r�|jjd�}||jkrU|jd|��|jjd�}t||j�}|jjd�}||gf|j|<n}d}|jt	|�s�|j|j
|�r�|jjd�}|jdkr0|jt|�r|jjd�|_dS|jd|��|jjd�}t||j�}|jjd�}|dkrxd}|r�|d|}x�|j|j
|�rt|jjd	��}|jd
kr�|jd|�|j|�}|j|||f�|j�}q�W|j||�|dkr|jt|�r|jjd�}t||j�}|j||jjd��|jdkr�|dkr�|jd||f�|S)Nrzunexpected tagged response: %rr�r�Zdata2zunexpected response: %rr�r�r�r�zread literal size %srbr�r�rar�z%s response: %r)zOK�NO�BAD)r	r
zBYE)�	_get_line�_matchrf�mo�grouprEr>r�rW�Untagged_responser^�ContinuationrGr\�intrBrjr�r��
Response_code)rQ�resprr�r�Zdat2r�r�r;r;r<rlsPzIMAP4._get_responsecCs�x�|j|}|dk	r*|j|=|S|j�y|j�Wq|jk
r�}z!|jdkrs|j��WYdd}~XqXqWdS)Nra)rEr�rlr>rB�	print_log)rQr�resultrr;r;r<rPs



zIMAP4._get_tagged_responsecCs�|j�}|s!|jd��|jd�sC|jd|��|dd�}|jdkrv|jd|�n|jd|�|S)Nzsocket error: EOFs
z#socket error: unterminated line: %rr�r�z< %r���)r�r>�endswithrBrjr)rQr�r;r;r<rkszIMAP4._get_linecCs`|j|�|_|jdk	rS|jdkrS|jd|j|jj�f�|jdk	S)Nr�z	matched r'%r' => %r)�matchr
rBrjr��groups)rQZcre�sr;r;r<r~s#zIMAP4._matchcCsC|jtt|j�|j�}|jd|_d|j|<|S)Nra)rer�r�rIrWrE)rQrr;r;r<r��s"
zIMAP4._new_tagcCs0|jdd�}|jdd�}d|dS)N�\z\\�"z\")r�)rQrr;r;r<r��szIMAP4._quotecGs|j||j||��S)N)rr)rQr�rzr;r;r<r��szIMAP4._simple_commandcCst|dkr||fS||jkr2|dgfS|jj|�}|jdkrj|jd||f�||fS)Nr�r�zuntagged_responses[%s] => %s)rF�poprBrj)rQr�r�r�r�r;r;r<r��s

zIMAP4._untagged_responsecCsi|dkrtj�}tjdtj|��}tjjd||dd|f�tjj�dS)Nz%M:%Sz
  %s.%02d %s
�d)�time�strftime�	localtimer��stderr�write�flush)rQrZsecsZtmr;r;r<rj�s
%zIMAP4._mesgcCsU|j�}|sdSd}tdd�|�}|jd||j|�f�dS)Nz
		cSs3d|d|ddr+dj|d�p.dfS)Nz%s: "%s"rraz" "r@)r�)�xr;r;r<�<lambda>�sz IMAP4._dump_ur.<locals>.<lambda>zuntagged responses dump:%s%s)�items�maprjr�)rQ�dict�l�tr;r;r<r��szIMAP4._dump_urcCsJ|tj�f|j|j<|jd7_|j|jkrFd|_dS)Nrar)rrirhrg)rQr�r;r;r<r�sz
IMAP4._logc	Cs�|jdt|j��|j|j}}xV|r�y|j|j|�WnYnX|d7}||jkrxd}|d8}q0WdS)Nzlast %d IMAP4 interactions:rar)rjr�rirhrg)rQ�i�nr;r;r<r�s	
zIMAP4.print_log)Tr8r9r:�__doc__rNr=r>r?�
IMAP4_PORTrTrKr_rMrwrxr{r}rLr�r�r�rOr|r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�ryr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrmrlrrrr�r�r�r�rjr�rrr;r;r;r<r}s�,*

			

 	
M	Pc@sOeZdZdZdeddddd�Zdd�Zdedd	�ZdS)
�	IMAP4_SSLa3IMAP4 client class over SSL connection

        Instantiate with: IMAP4_SSL([host[, port[, keyfile[, certfile[, ssl_context]]]]])

                host - host's name (default: localhost);
                port - port number (default: standard IMAP4 SSL port);
                keyfile - PEM formatted file that contains your private key (default: None);
                certfile - PEM formatted certificate chain file (default: None);
                ssl_context - a SSLContext object that contains your certificate chain
                              and private key (default: None)
                Note: if ssl_context is provided, then parameters keyfile or
                certfile should not be set otherwise ValueError is raised.

        for more documentation see the docstring of the parent class IMAP4.
        r@NcCs�|dk	r$|dk	r$td��|dk	rH|dk	rHtd��||_||_|dkr~tjd|d|�}||_tj|||�dS)Nz8ssl_context and keyfile arguments are mutually exclusivez9ssl_context and certfile arguments are mutually exclusive�certfile�keyfile)�
ValueErrorr2r1r�r�r�rrT)rQrRrSr2r1r�r;r;r<rT�s				zIMAP4_SSL.__init__cCs(tj|�}|jj|d|j�S)Nr�)rr}r�r�rR)rQrr;r;r<r}�szIMAP4_SSL._create_socketcCstj|||�dS)z�Setup connection to remote server on "host:port".
                (default: localhost:standard IMAP4 SSL port).
            This connection will be used by the routines:
                read, readline, send, shutdown.
            N)rrL)rQrRrSr;r;r<rL�szIMAP4_SSL.open)r8r9r:r.�IMAP4_SSL_PORTrTr}rLr;r;r;r<r0�s
	r0c@sdeZdZdZdd�Zdddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)rz�IMAP4 client class over a stream

    Instantiate with: IMAP4_stream(command)

            "command" - a string that can be passed to subprocess.Popen()

    for more documentation see the docstring of the parent class IMAP4.
    cCs||_tj|�dS)N)r�rrT)rQr�r;r;r<rTs	zIMAP4_stream.__init__NcCsd|_d|_d|_d|_tj|jdtdtjdtjdddd�|_	|j	j
|_|j	j|_
dS)z�Setup a stream connection.
        This connection will be used by the routines:
            read, readline, send, shutdown.
        N�bufsize�stdin�stdout�shellTZ	close_fds)rRrSrr��
subprocess�Popenr�r�PIPEr�r6�	writefiler7�readfile)rQrRrSr;r;r<rLs				zIMAP4_stream.opencCs|jj|�S)zRead 'size' bytes from remote.)r=r�)rQr�r;r;r<r�(szIMAP4_stream.readcCs
|jj�S)zRead line from remote.)r=r�)rQr;r;r<r�-szIMAP4_stream.readlinecCs!|jj|�|jj�dS)zSend data to remote.N)r<r#r$)rQr�r;r;r<r�2szIMAP4_stream.sendcCs+|jj�|jj�|jj�dS)z Close I/O established in "open".N)r=r�r<r��wait)rQr;r;r<rO8s

zIMAP4_stream.shutdown)
r8r9r:r.rTrLr�r�r�rOr;r;r;r<rs	c@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)r�zcPrivate class to provide en/decoding
            for base64-based authentication conversation.
    cCs
||_dS)N)r�)rQZmechinstr;r;r<rTFsz_Authenticator.__init__cCs5|j|j|��}|dkr(dS|j|�S)N�*)r�r�r�)rQr�Zretr;r;r<r�Isz_Authenticator.processcCs�d}t|t�r$|jd�}xt|r�t|�dkrb|dd�}|dd�}n|}d}tj|�}|r'||dd�}q'W|S)Nr�zutf-8�0rar�)r�r�r�r��binasciiZ
b2a_base64)rQ�inpZoupr+r�r;r;r<r�Os		z_Authenticator.encodecCs|s
dStj|�S)Nr�)rAZ
a2b_base64)rQrBr;r;r<r�gsz_Authenticator.decodeN)r8r9r:r.rTr�r�r�r;r;r;r<r�@s
r�z0 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Decr�cCs)i|]\}}|d|j��qS)ra)r�)�.0r-rr;r;r<�
<dictcomp>ms	rDrac	Cs4tj|�}|sdSt|jd�}|jd�}t|jd��}t|jd��}t|jd��}t|jd��}t|jd��}t|jd	��}	t|jd
��}
|	d|
d}|dkr�|}||||||dddf	}tj|�|}
tj|
�S)z�Parse an IMAP4 INTERNALDATE string.

    Return corresponding local time.  The return value is a
    time.struct_time tuple or None if the string has wrong format.
    N�mon�zonen�day�year�hour�min�sec�zoneh�zonem�<�-rar�r�r�)	�InternalDater�Mon2numrr�calendarZtimegmrr!)rr
rErFrGrHrIrJrKrLrMZzoneZtt�utcr;r;r<ros$!cCs\d}d}tt|��}x7|rWt|d�\}}|||d�|}q!W|S)z-Convert integer to A-P string representation.r�sABCDEFGHIJKLMNOP�ra)r�abs�divmod)ZnumrZAP�modr;r;r<r	�s	cCs2tj|�}|sfSt|jd�j��S)z-Convert IMAP4 flags response to python tuple.r�)�Flagsrrrr)rr
r;r;r<r
�sc
Cs�t|ttf�r3tj|tj�j�}n0t|t�r�y
|j	}Wnqt
k
r�tjr�|d}|dkr�tj
tj|��d}tjtjf|}n
tj}YnXtd|�}t|dd�dt|��}nlt|t�r*|jdkr!td��|}n9t|t�rW|d|d
fdkrW|Std
��djt|j�}|j|�S)a�Convert date_time to IMAP4 INTERNALDATE representation.

    Return string in form: '"DD-Mmm-YYYY HH:MM:SS +HHMM"'.  The
    date_time argument can be a number (int or float) representing
    seconds since epoch (as returned by time.time()), a 9-tuple
    representing local time, an instance of time.struct_time (as
    returned by time.localtime()), an aware datetime instance or a
    double-quoted string.  In the last case, it is assumed to already
    be in the correct format.
    �raZsecondsN��tzinfozdate_time must be awarerrzdate_time not of a known typez"%d-{}-%Y %H:%M:%S %z"r�r�)rr)r�r�floatrZ
fromtimestamprrSZ
astimezonerZ	tm_gmtoffrurZdaylightr!ZmktimeZaltzonerr[r3r��format�MonthsZmonthr )r�ZdtZgmtoffZdstZdeltaZfmtr;r;r<r�s0	

	
%	)�__main__zd:s:z-dz-sr@zIMAP password for %s on %s: Z	localhostzJFrom: %(user)s@localhost%(lf)sSubject: IMAP4 test%(lf)s%(lf)sdata...%(lf)sr�Zlf�
r�r�z
/tmp/xxx 1r�z/tmp/yyyz
/tmp/yyz 2r�r�z/tmpzyy*r�r�ZSUBJECTZtestr��1z(FLAGS INTERNALDATE RFC822)r��FLAGSz
(\Deleted)r�r�r�r�r�ZUIDVALIDITYr�ZALLr�rycCsftjd||f�tt|�|�\}}tjd|||f�|dkrb|d�|S)Nz%s %sz%s => %s %sr�r)�Mrjrs)�cmdrzr�r�r;r;r<�runs
rezPROTOCOL_VERSION = %szCAPABILITIES = %rz/tmp/zyy%z.*"([^"]+)"$r�z%sz:(FLAGS INTERNALDATE RFC822.SIZE RFC822.HEADER RFC822.TEXT)z
All tests OK.z
Tests failed.z8
If you would like to see debugging output,
try: %s -d5
)Ur.rkrAr�rdrXr|r9r�rrRrrr�iorr�r��ImportError�__all__r�rAr/r4ror�rrrYrrXrPr[r\r�rrr^rZr]rr0r�rr�rr^�	enumeraterQrr	r
rr8ZgetoptZgetpass�argvZoptlistrzr=rZstream_command�optrrRZgetuserZUSERZPASSWDZ	test_mesgZ	test_seq1Z	test_seq2rercrCrjrprnrdZmlrr
r�pathr�r��printr;r;r;r<�<module>s<l

																		����X1
9,##
))%
	
					


Rosenblum TV: Video training, virtual workshops, classes, tutorials
logologologologo
  • About
  • What We Do
  • Our Clients
  • Case Studies
    • The BBC
    • CBS News
    • New York Times Television
    • Spectrum News
    • The Newark Star-Ledger
    • The United Nations
    • McGraw/Hill
    • Oyster Yachts
    • Scottish Environmental Protection Agency
  • The Power of Storytelling
  • Why iPhones?
  • Michael on Media
  • Books
  • Contact
  • About
  • What We Do
  • Our Clients
  • Case Studies
    • The BBC
    • CBS News
    • New York Times Television
    • Spectrum News
    • The Newark Star-Ledger
    • The United Nations
    • McGraw/Hill
    • Oyster Yachts
    • Scottish Environmental Protection Agency
  • The Power of Storytelling
  • Why iPhones?
  • Michael on Media
  • Books
  • Contact

RE-INVENTING THE TELEVISION NEWS BUSINESS*

A revolution in video storytelling

Creating entirely new & cost-effective production methods

From the world leaders in video production training and the creators of Character Driven Storytelling™

*and every other business that uses video

WHAT WE DO

Over the past 35 years, we have designed, built or restructured some of the most powerful news and journalism companies in the world.

We replace the traditional TV news ‘crew’ with one highly trained journalist, working alone with nothing but an iPhone.

No more TV news ‘crews’, no editors and no field producers.

This is television news done the way newspaper journalism is done – one reporter with their electronic pad and pencil.

In doing this, we can cut the cost of production by as much as 75% while increasing ratings and audience engagement.

In the place of conventional TV news ‘packages’ – ie, reporter stand up, interview, b-roll, man on the street, we marry great journalism with Netflix and Hollywood storytelling.

It’s a combination that works.

We have taken most of our clients to #1 in their respective markets.

And it’s not just for news. Any company, any profit, any NGO and anyone else who is online needs to tell their story in compelling yet cost-effective video. We can teach you to do that. Either in person or virtually.

EXAMPLES OF WHAT WE CAN TEACH YOUR STAFF TO PRODUCE

ITAY HOD

Itay Hod, MMJ with KPIX/CBS in San Francisco, took the 5-Day Intensive Video Storytelling Bootcamp in 2018.

Because he works alone, with only an iPhone, he was able to embed himself with a homeless family.

Here’s the story he produced in a one-day turn.

KIET DO

Kiet Do, an MMJ with KPIX/CBS in San Francisco, took the 5-Day Intensive Video Storytelling Bootcamp in 2021.

Here is a story he produced, all on his own, with only an iPhone and in a one-day turn.

TAYLOR SCHAUB

Taylor Schaub, an MMJ with Spectrum News 1 in LA, took the 5-Day Intensive Video Storytelling Bootcamp in 2023.

Here is a story he turned in only one day, using only an iPhone. It was the first video story he ever did and it was nominated for an Emmy.

THE BOOTCAMP

How do we convert stations and whole networks to working in this way?

Since 1988, we have run intensive 5-Day Video Storytelling Bootcamps

We have done these all over the world.

These are hands-on bootcamps, and participants learn an entirely new way of creating TV news stories.

-We shoot at a 3:1 ratio or lower, so turnaround times are fast.

-We go directly from camera to timelilne and edit – no written scripts.  We work in the medium of pictures and sound.

-We are entirely character-driven.

-We are driven by pictures and real events.

-We are focused almost entirely on ’the viewer experience’.

Since 1988, more than 70,000 journalists around the world have taken our bootcamps, either in person on virtualy.

Case Studies

CBS Case Study Logos
CBS News

We have started to work with CBS News, bringing our ideas of character-driven storytelling to one of the most successful and biggest networks in the United States. Since beginning to work with them ratings have climbed and more importantly, audience engagement is through the ceiling.

Learn More
NYT Case Study Logos
New York Times Television

We started New York Times Television in 1990 and it was the first paper to be brought into the world of TV. It quickly became one of the most successful non-fiction production companies in the United States. The series and documentaries we produced won many awards including multiple Emmys.

Learn More
BBC Case Study Logos
The BBC

We have been working with the BBC since the year 2000 helping to convert their national news network to our visual storytelling technique. Most recently we have trained teams from their sports, documentaries, and comedy divisions to make character-driven stories using only smartphones.

Learn More
Spectrum Case Study Logos
Spectrum News

For the past five years we have worked with Spectrum News to introduce and train their journalists on visual, character driven storytelling using smartphones helping to create a different kind of local news for their network of 24-Hour News Stations across the United States.

Learn More
UN Case Study Logos
The United Nations

In 2006, we were approached by the United Nations. Rather than rely on news outlets, it would be much easier to train the field operatives to produce their own stories. We spent two years working with the UN, training more than 100 of their staff in bootcamps in Geneva and Nairobi.

Learn More
Star Ledger Case Study Logos
The Newark Star-Ledger

We trained 50 print reporters at the paper to shoot and tell their own stories, in conjunction with their print work. We built a TV newsroom in their existing print newsroom – you could not ask for a better set and they began to live stream their stories in conjunction with their print work.

Learn More
Mcgraw Hill Case Study Logos
Mcgraw Hill

We spent two years with McGraw Hill, training more than 150 of their staffers, making them completely video literate. McGraw/Hill media properties we transit included Business Week, Aviation Week, (what was the name of the architecture magazine), and JD Power and Associates.

Learn More
VOA Case Study Logos
Voice of America

In 1990, we were approached by The Voice of America, the official broadcasting agency for the United States Government. When we met with VOA, they were only a short wave radio broadcaster, but working with them, we took them into television, launching VOA-TV.

Learn More
Oyster Case Study Logos
Oyster Yachts

British based Oyster Yachts makes some of the finest yachts in the world. Like every other company, they had to find a way to feed the never-ending video demands of social media – sites like Instagram and TikTok. We trained the Oyster staff to tell their own stories, using only iPhones.

Learn More
SEPA Case Study Logos
Scottish Environmental Protection Agency

We were approached by SEPA, the Scottish Environmental Protection Agency because they had to continually find a way to ‘feed the media beast’. The result was that SEPA was able to tell their own stories, whenever they wanted, and at almost no additional cost.

Learn More
Image 11-11-22 at 6.25 PM

Michael on Media

Michael Rosenblum has been writing about the media since 1988. His work and ideas have appeared in The Guardian, The Huffington Post, Ilkeston Life and many other publications.

He has been blogging regularly for the past 35 years on this subject. Having taught media studies at Columbia University, NYU and now the University of Oxford, he is considered an expert on this subject.

Continue reading this post or look back at previous posts.

Read More

Do You Have Questions About Learning Video Skills?

If you would like to know more about our courses contact us and one of our training advisors will be happy to call you.

Contact Us

Copyright 2024. All rights reserved.