Example #1
0
def get_cached_thumb( fpath ):
    # fixe me: xbmc not change/reload/refresh image if path is same
    fpath = translatePath( fpath )
    filename = _hash( repr( fpath ) + open( fpath ).read( 250 ) ).hexdigest()
    temp = MOVIESET_CACHED_THUMB % filename
    if not path_exists( temp ):
        #executehttpapi( "FileCopy(%s,%s)" % ( fpath, temp ) )#.replace( "<li>", "" )
        xbmcvfs.copy( fpath, temp )
    return ( fpath, temp )[ path_exists( temp ) ]
Example #2
0
def get_cached_filename(fpath):
    c_filename = "%s.json" % _hash(repr(fpath)).hexdigest()
    return os.path.join(ADDON_CACHE, c_filename)
Example #3
0
def hash(s):
    return _hash(bytearray(s, "utf-8")).hexdigest()
Example #4
0
def get_cached_filename( fpath ):
    c_filename = "%s.json" % _hash( repr( fpath ) ).hexdigest()
    return os.path.join( ADDON_CACHE, c_filename )
def get_cached_filename(path):
    """ function docstring """
    filename = "%s" % _hash(repr(path)).hexdigest()
    return os.path.join(ADDON_CACHE_BASEDIR, filename)
Example #6
0
def get_cached_filename(path):
    """ function docstring """
    filename = "%s" % _hash(repr(path)).hexdigest()
    return os.path.join(ADDON_CACHE_BASEDIR, filename)
Example #7
0
async def handle_connection(reader, writer):
    print("Got connection")
    state = {
        'username': None,
        'addr': writer.get_extra_info('peername')[0],
    }

    def _rwrite(message):
        if not message.endswith('\r\n'):
            message += '\r\n'
        print("{} -->\t{!r}".format(state['addr'], message))
        writer.write(message.encode())

    def _write(fmt, **kwargs):
        line = (fmt + '\r\n').format(**kwargs)
        _rwrite(line)

    _write('+OK POP3 server ready')
    await writer.drain()

    while True:
        bline = await reader.readline()

        if not bline:
            break

        if not bline.startswith(b'PASS'):  # Probs don't print passwords
            print("{} <--\t{!r}".format(state['addr'], bline))

        parts = bline.decode().rstrip().split(' ')
        command = parts[0]
        if len(parts) > 1:
            params = parts[1:]
        else:
            params = []

        if command == 'CAPA':
            _write('+OK Capability list follows')
            _write('USER')
            _write('LOGIN-DELAY 900')
            _write('EXPIRE NEVER')
            _write('UIDL')
            _write('TOP')
            _write('.')
        elif command == 'USER':
            state['username'] = params[0]
            _write('+OK')
        elif command == 'PASS':
            if state['username']:
                try:
                    state['o365'] = o365(state['username'], params[0])
                    _write('+OK')
                except Exception as e:
                    _write('-ERR o365 bounced us')
            else:
                _write('-ERR Who are you?')
        elif command == 'NOOP':
            _write('+OK')
        elif command == 'QUIT':
            _write('+OK')
            await writer.drain()
            break

        # Are we authenticated?
        if not 'o365' in state:
            continue

        if command == 'STAT':
            _write('+OK {count}', count=state['o365'].unread)
        elif command == 'RETR':
            omsg = state['o365'].inbox_all[int(params[0]) - 1]
            obody = omsg.text_body if omsg.text_body != None else omsg.body
            obody = obody if obody != None else ''
            message = EmailMessage(policy=policy.default.clone(
                linesep='\r\n', mangle_from_=True))  # Use /r/n lin endings
            message['message-id'] = _hash(obody.encode()).hexdigest()
            message['to'] = ', '.join([
                formataddr((x.name, x.email_address))
                for x in assurelist(omsg.to_recipients)
            ])
            message['cc'] = ', '.join([
                formataddr((x.name, x.email_address))
                for x in assurelist(omsg.cc_recipients)
            ])
            message['bcc'] = ', '.join([
                formataddr((x.name, x.email_address))
                for x in assurelist(omsg.bcc_recipients)
            ])
            message['from'] = formataddr(
                (omsg.sender.name, omsg.sender.email_address))
            if omsg.reply_to:
                message['reply-to'] = formataddr(
                    (omsg.reply_to.name, omsg.reply_to.email_address))
            message['date'] = formatdate(omsg.datetime_received.timestamp(),
                                         localtime=True)
            message['subject'] = omsg.subject

            message.set_content(obody)

            # handle all attachments
            for attachment in omsg.attachments:
                maintype, subtype = attachment.content_type.split('/', 1)
                message.add_attachment(attachment.content,
                                       maintype=maintype,
                                       subtype=subtype,
                                       filename=attachment.name)

            _write('+OK message follows')
            _rwrite(message.as_string().replace(
                '\r\n.',
                '\r\n..'))  # be sure to byte stuff the termination character
            _write('.')
        elif command == 'DELE':
            oid = int(params[0])
            msg = state['o365'].inbox_all[oid - 1]
            if isinstance(msg, ex.items.MeetingRequest):
                if msg.meeting_request_type != 'InformationalUpdate':
                    if msg.conflicting_meeting_count > 0:
                        msg.accept()
                    else:
                        msg.tentatively_accept(
                            body="Meeting conflict, will review")
            msg.is_read = True
            msg.save()
            _write('+OK message {oid} deleted', oid=oid)

        await writer.drain()

    writer.close()
    print('Server client closed for {}'.format(state['addr']))