<s> import logging <EOL> from contextio . lib import helpers <EOL> from contextio . lib . resources . base_resource import BaseResource , only <EOL> from contextio . lib . resources . file import File <EOL> from contextio . lib . resources . thread import Thread <EOL> class Message ( BaseResource ) : <EOL> """<STR_LIT>""" <EOL> resource_id = "<STR_LIT>" <EOL> keys = { <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT:date>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" <EOL> ] , <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" <EOL> ] <EOL> } <EOL> body = None <EOL> flags = None <EOL> headers = None <EOL> folders = None <EOL> source = None <EOL> thread = None <EOL> raw = None <EOL> attachments = None <EOL> def __init__ ( self , parent , definition ) : <EOL> """<STR_LIT>""" <EOL> super ( Message , self ) . __init__ ( parent , '<STR_LIT>' , definition ) <EOL> if '<STR_LIT>' in definition : <EOL> self . files = [ File ( self . parent , file ) for file in definition [ '<STR_LIT>' ] ] <EOL> if '<STR_LIT:body>' in definition : <EOL> self . body = definition [ '<STR_LIT:body>' ] <EOL> if '<STR_LIT>' in definition : <EOL> self . flags = definition [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in definition : <EOL> self . headers = definition [ '<STR_LIT>' ] <EOL> def get ( self , ** params ) : <EOL> """<STR_LIT>""" <EOL> all_args = [ <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> return super ( Message , self ) . get ( params = params , all_args = all_args ) <EOL> def put ( self ) : <EOL> logging . info ( "<STR_LIT>" ) <EOL> def post ( self , return_bool = True , ** params ) : <EOL> """<STR_LIT>""" <EOL> req_args = [ '<STR_LIT>' , ] <EOL> all_args = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> return super ( Message , self ) . post ( return_bool = return_bool , params = params , all_args = all_args , required_args = req_args ) <EOL> def delete ( self ) : <EOL> """<STR_LIT>""" <EOL> return super ( Message , self ) . delete ( ) <EOL> def get_body ( self , ** params ) : <EOL> """<STR_LIT>""" <EOL> all_args = [ '<STR_LIT:type>' ] <EOL> params = helpers . sanitize_params ( params , all_args ) <EOL> self . body = self . _request_uri ( "<STR_LIT:body>" , params = params ) <EOL> return self . body <EOL> def get_flags ( self ) : <EOL> """<STR_LIT>""" <EOL> self . flags = self . _request_uri ( "<STR_LIT>" ) <EOL> return self . flags <EOL> @ only ( "<STR_LIT>" ) <EOL> def post_flag ( self , ** params ) : <EOL> """<STR_LIT>""" <EOL> all_args = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> params = helpers . sanitize_params ( params , all_args ) <EOL> data = self . _request_uri ( "<STR_LIT>" , method = "<STR_LIT:POST>" , params = params ) <EOL> status = bool ( data [ "<STR_LIT:success>" ] ) <EOL> if status : <EOL> self . flags = data [ "<STR_LIT>" ] <EOL> return status <EOL> @ only ( "<STR_LIT>" ) <EOL> def get_folders ( self ) : <EOL> """<STR_LIT>""" <EOL> self . folders = self . _request_uri ( '<STR_LIT>' ) <EOL> return self . folders <EOL> @ only ( "<STR_LIT>" ) <EOL> def post_folder ( self , ** params ) : <EOL> """<STR_LIT>""" <EOL> all_args = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> params = helpers . sanitize_params ( params , all_args ) <EOL> return super ( Message , self ) . post ( "<STR_LIT>" , params = params ) <EOL> @ only ( "<STR_LIT>" ) <EOL> def put_folders ( self , body ) : <EOL> """<STR_LIT>""" <EOL> status = self . _request_uri ( "<STR_LIT>" , method = "<STR_LIT>" , body = body ) <EOL> status = bool ( status [ '<STR_LIT:success>' ] ) <EOL> if status : <EOL> self . folders = body <EOL> return status <EOL> def get_headers ( self , ** params ) : <EOL> """<STR_LIT>""" <EOL> all_args = [ '<STR_LIT>' ] <EOL> params = helpers . sanitize_params ( params , all_args ) <EOL> self . headers = self . _request_uri ( '<STR_LIT>' , params = params ) <EOL> return self . headers <EOL> @ only ( "<STR_LIT>" ) <EOL> def get_source ( self ) : <EOL> """<STR_LIT>""" <EOL> self . source = self . _request_uri ( '<STR_LIT:source>' ) <EOL> return self . source <EOL> @ only ( "<STR_LIT>" ) <EOL> def get_thread ( self , ** params ) : <EOL> """<STR_LIT>""" <EOL> all_args = [ <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" <EOL> ] <EOL> params = helpers . sanitize_params ( params , all_args ) <EOL> data = self . _request_uri ( "<STR_LIT>" , params = params ) <EOL> gmail_thread_id = None <EOL> messages = data . get ( "<STR_LIT>" ) <EOL> if messages is not None : <EOL> first_message = messages [ <NUM_LIT:0> ] <EOL> gmail_thread_id = first_message . get ( "<STR_LIT>" ) <EOL> if gmail_thread_id : <EOL> data [ "<STR_LIT>" ] = "<STR_LIT>" . format ( gmail_thread_id ) <EOL> self . thread = Thread ( self . parent , data ) if gmail_thread_id else data <EOL> if self . subject and self . thread : <EOL> self . thread . subject = self . subject <EOL> return self . thread <EOL> @ only ( "<STR_LIT>" ) <EOL> def get_raw ( self , ** params ) : <EOL> all_args = [ '<STR_LIT>' ] <EOL> params = helpers . sanitize_params ( params , all_args ) <EOL> self . raw = self . _request_uri ( '<STR_LIT>' , params = params ) <EOL> @ only ( "<STR_LIT>" ) <EOL> def get_attachments ( self , ** params ) : <EOL> all_args = [ '<STR_LIT>' ] <EOL> params = helpers . sanitize_params ( params , all_args ) <EOL> self . attachments = self . _request_uri ( '<STR_LIT>' , params = params ) <EOL> @ only ( "<STR_LIT>" ) <EOL> def post_read ( self , ** params ) : <EOL> all_args = [ "<STR_LIT>" ] <EOL> params = helpers . sanitize_params ( params , all_args ) <EOL> return super ( Message , self ) . post ( "<STR_LIT>" , params = params ) <EOL> @ only ( "<STR_LIT>" ) <EOL> def delete_read ( self , ** params ) : <EOL> all_args = [ "<STR_LIT>" ] <EOL> params = helpers . sanitize_params ( params , all_args ) <EOL> return super ( Message , self ) . delete ( "<STR_LIT>" ) </s>
