Пример #1
0
    def _fetch(self, uid, message_list, message_parts="(FLAGS)"):
        """Fetch (parts of) messages"""
        if uid:
            process_command = self.processCommandUID
        else:
            process_command = self.processCommand

        name = "FETCH"

        self.sstatus["fetch_response"] = {}

        # The message list can be rather long sometimes. Each
        # IMAP server has a maximum lenght for the command line
        # so if the command line is bigger than a MAXCLILEN we
        # have to make severall fetch commands to complete the
        # fetch.
        if isinstance(message_list, list) or isinstance(message_list, tuple):
            shrinked_list = shrink_fetch_list(message_list)
            message_list = ",".join("%s" % Xi for Xi in shrinked_list)

            # Worst case cenario command lenght
            command_len = len("UID FETCH %s %s" % (message_list, message_parts)) + 2

            if command_len > MAXCLILEN:
                shrinked_list = list(shrinked_list)
                len_overhead = len("UID FETCH %s" % (message_parts)) + 2
                message_list = ""
                result = {}
                while shrinked_list:
                    msg = "%s" % shrinked_list.pop()
                    if len(message_list) + len(msg) + len_overhead <= MAXCLILEN:
                        # Compose the partial message list
                        message_list += ",%s" % msg
                    else:
                        # Make a partial fetch
                        shrinked_list.append(msg)
                        args = "%s %s" % (message_list.strip(","), message_parts)
                        tmp_result = process_command(name, args)["fetch_response"]

                        # Merge the results:
                        for key in tmp_result:
                            result[key] = tmp_result[key]
                        message_list = ""

                if message_list:
                    args = "%s %s" % (message_list.strip(","), message_parts)
                    tmp_result = process_command(name, args)["fetch_response"]
                    for key in tmp_result:
                        result[key] = tmp_result[key]

                self.sstatus["fetch_response"] = result
                return result

        args = "%s %s" % (message_list, message_parts)
        return process_command(name, args)["fetch_response"]
Пример #2
0
    def copy_uid(self, message_set, mailbox):
        '''Copy messages to mailbox'''

        name = 'COPY'

        if isinstance(message_set, list):
            message_set = shrink_fetch_list(message_set)
            message_set = ','.join('%s' % Xi for Xi in message_set)

        args = '%s "%s"' % (message_set, mailbox)

        return self.processCommandUID(name, args)
Пример #3
0
    def copy_uid(self, message_set, mailbox ):
        '''Copy messages to mailbox'''

        name = 'COPY'

        if isinstance(message_set, list):
            message_set = shrink_fetch_list(message_set)
            message_set = ','.join( '%s' % Xi for Xi in message_set)

        args = '%s "%s"' % (message_set, mailbox)

        return self.processCommandUID(name, args )
Пример #4
0
    def store_uid(self, message_set, command, flags):
        '''Alters flag dispositions for messages in mailbox UID version.
        '''

        name = 'STORE'

        flags = '(' + ' '.join(flags) + ')'

        if isinstance(message_set, list):
            message_set = shrink_fetch_list(message_set)
            message_set = ','.join('%s' % Xi for Xi in message_set)
        args = '%s %s %s' % (message_set, command, flags)

        result = self.processCommandUID(name, args)
        return result
Пример #5
0
    def store_uid(self, message_set, command, flags):
        '''Alters flag dispositions for messages in mailbox UID version.
        '''

        name = 'STORE'

        flags = '(' + ' '.join(flags) + ')'

        if isinstance(message_set, list):
            message_set = shrink_fetch_list( message_set )
            message_set = ','.join( '%s' % Xi for Xi in message_set)
        args = '%s %s %s' % (message_set, command, flags )

        result = self.processCommandUID( name, args)
        return result
Пример #6
0
    def store_uid(self, message_set, command, flags):
        """Alters flag dispositions for messages in mailbox UID version.
        """

        name = "STORE"

        flags = "(" + " ".join(flags) + ")"

        if isinstance(message_set, list):
            message_set = shrink_fetch_list(message_set)
            message_set = ",".join("%s" % Xi for Xi in message_set)
        args = "%s %s %s" % (message_set, command, flags)

        result = self.processCommandUID(name, args)
        return result
Пример #7
0
    def _fetch(self, uid, message_list, message_parts='(FLAGS)'):
        '''Fetch (parts of) messages'''

        if uid:
            process_command = self.processCommandUID
        else:
            process_command = self.processCommand

        name = 'FETCH'

        self.sstatus['fetch_response'] = {}

        # The message list can be rather long sometimes. Each
        # IMAP server has a maximum lenght for the command line
        # so if the command line is bigger than a MAXCLILEN we
        # have to make severall fetch commands to complete the
        # fetch.
        if isinstance(message_list, list) or \
           isinstance(message_list, tuple):
            if not message_list:
                raise self.Error('Can\'t fetch an empty message list.')

            shrinked_list = shrink_fetch_list(message_list)
            message_list = ','.join('%s' % Xi for Xi in shrinked_list)

            # Worst case cenario command lenght
            command_len = len('UID FETCH %s %s' %
                              (message_list, message_parts)) + 2

            if command_len > MAXCLILEN:
                shrinked_list = list(shrinked_list)
                len_overhead = len('UID FETCH %s' % (message_parts)) + 2
                message_list = ''
                result = {}
                while shrinked_list:
                    msg = '%s' % shrinked_list.pop()
                    if len(message_list) + len(
                            msg) + len_overhead <= MAXCLILEN:
                        # Compose the partial message list
                        message_list += ',%s' % msg
                    else:
                        # Make a partial fetch
                        shrinked_list.append(msg)
                        args = '%s %s' % (message_list.strip(','),
                                          message_parts)
                        tmp_result = process_command(name,
                                                     args)['fetch_response']

                        # Merge the results:
                        for key in tmp_result:
                            result[key] = tmp_result[key]
                        message_list = ''

                if message_list:
                    args = '%s %s' % (message_list.strip(','), message_parts)
                    tmp_result = process_command(name, args)['fetch_response']
                    for key in tmp_result:
                        result[key] = tmp_result[key]

                self.sstatus['fetch_response'] = result
                return result
        elif isinstance(message_list, str):
            message_list = message_list.strip()

        if not message_list:
            raise Error('Can\'t fetch an empty message list.')
        args = '%s %s' % (message_list, message_parts)
        return process_command(name, args)['fetch_response']
Пример #8
0
    def _fetch(self, uid, message_list, message_parts='(FLAGS)' ):
        '''Fetch (parts of) messages'''

        if uid:
            process_command = self.processCommandUID
        else:
            process_command = self.processCommand

        name = 'FETCH'

        self.sstatus['fetch_response'] = {}

        # The message list can be rather long sometimes. Each
        # IMAP server has a maximum lenght for the command line
        # so if the command line is bigger than a MAXCLILEN we
        # have to make severall fetch commands to complete the
        # fetch.
        if isinstance(message_list, list) or \
           isinstance(message_list, tuple):
            if not message_list:
                raise self.Error('Can\'t fetch an empty message list.')

            shrinked_list = shrink_fetch_list( message_list )
            message_list = ','.join( '%s' % Xi for Xi in shrinked_list )

            # Worst case cenario command lenght
            command_len = len( 'UID FETCH %s %s' % (message_list,
                message_parts)) + 2

            if command_len > MAXCLILEN:
                shrinked_list = list(shrinked_list)
                len_overhead = len('UID FETCH %s' % (message_parts)) + 2
                message_list = ''
                result = {}
                while shrinked_list:
                    msg = '%s' % shrinked_list.pop()
                    if len(message_list)+len(msg)+len_overhead <= MAXCLILEN:
                        # Compose the partial message list
                        message_list += ',%s' % msg
                    else:
                        # Make a partial fetch
                        shrinked_list.append(msg)
                        args = '%s %s' % (message_list.strip(','),
                            message_parts)
                        tmp_result = process_command(name,
                            args)['fetch_response']

                        # Merge the results:
                        for key in tmp_result:
                            result[key] = tmp_result[key]
                        message_list = ''

                if message_list:
                    args = '%s %s' % (message_list.strip(','),
                        message_parts)
                    tmp_result = process_command(name,
                        args)['fetch_response']
                    for key in tmp_result:
                        result[key] = tmp_result[key]

                self.sstatus['fetch_response'] = result
                return result
        elif isinstance(message_list, str):
            message_list = message_list.strip()

        if not message_list:
            raise Error('Can\'t fetch an empty message list.')
        args = '%s %s' % (message_list,  message_parts)
        return process_command(name, args)['fetch_response']