How to use the imaplib2.IMAP4 function in imaplib2

To help you get started, we’ve selected a few imaplib2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github assembl / assembl / assembl / processes / imaplib2_source_reader.py View on Github external
try:
                if self.source.message_ok_to_import(message_string):
                    (email_object, dummy, error) = self.source.parse_email(message_string)
                    if error:
                        raise ReaderError(error)
                    self.source.db.add(email_object)
                else:
                    print "Skipped message with imap id %s (bounce or vacation message)" % (email_id)
                # print "Setting self.source.last_imported_email_uid to "+email_id
                self.source.last_imported_email_uid = email_id
                self.source.db.commit()
            finally:
                self.source = ContentSource.get(self.source.id)
        except IMAP4.abort as e:
            raise IrrecoverableError(e)
        except IMAP4.error as e:
            raise ClientError(e)
github assembl / assembl / assembl / models / mail.py View on Github external
    @staticmethod
    def do_import_content(mbox, only_new=True):
        mbox = mbox.db.merge(mbox)
        session = mbox.db
        session.add(mbox)
        if mbox.use_ssl:
            mailbox = IMAP4_SSL(host=mbox.host.encode('utf-8'), port=mbox.port)
        else:
            mailbox = IMAP4(host=mbox.host.encode('utf-8'), port=mbox.port)
        if 'STARTTLS' in mailbox.capabilities:
            # Always use starttls if server supports it
            mailbox.starttls()
        mailbox.login(mbox.username, mbox.password)
        mailbox.select(mbox.folder)

        command = "ALL"
        search_status = None

        email_ids = None
        if only_new and mbox.last_imported_email_uid:
            command = "(UID %s:*)" % mbox.last_imported_email_uid

            search_status, search_result = mailbox.uid('search', None, command)
            # print "UID searched with: "+ command + ", got result "+repr(search_status)+" and found "+repr(search_result)
            email_ids = search_result[0].split()
github assembl / assembl / assembl / processes / imaplib2_source_reader.py View on Github external
if not message_string:
                raise ClientError()
            try:
                if self.source.message_ok_to_import(message_string):
                    (email_object, dummy, error) = self.source.parse_email(message_string)
                    if error:
                        raise ReaderError(error)
                    self.source.db.add(email_object)
                else:
                    print "Skipped message with imap id %s (bounce or vacation message)" % (email_id)
                # print "Setting self.source.last_imported_email_uid to "+email_id
                self.source.last_imported_email_uid = email_id
                self.source.db.commit()
            finally:
                self.source = ContentSource.get(self.source.id)
        except IMAP4.abort as e:
            raise IrrecoverableError(e)
        except IMAP4.error as e:
            raise ClientError(e)
github assembl / assembl / assembl / processes / imaplib2_source_reader.py View on Github external
def login(self):
        try:
            if self.source.use_ssl:
                mailbox = IMAP4_SSL(host=self.source.host.encode('utf-8'), port=self.source.port)
            else:
                mailbox = IMAP4(host=self.source.host.encode('utf-8'), port=self.source.port)
            if 'STARTTLS' in mailbox.capabilities:
                #Always use starttls if server supports it
                res = mailbox.starttls()
                if not is_ok(res):
                    # TODO: Require bad login from client error
                    raise ReaderError(res)
            if 'IDLE' in mailbox.capabilities:
                self.can_push = True
            res = mailbox.login(self.source.username, self.source.password)
            if not is_ok(res):
                # TODO: Require bad login from client error
                raise ClientError(res)
            res = mailbox.select(self.source.folder)
            if not is_ok(res):
                # TODO: Require bad login from client error
                raise ClientError(res)
github assembl / assembl / assembl / processes / imaplib2_source_reader.py View on Github external
res = self.mailbox.idle(int(self.max_idle_period.total_seconds()))
            if not is_ok(res):
                raise ClientError(res)
            # was it a timeout?
            res = self.mailbox.response('IDLE')
            if res and len(res) > 1 and len(res[1]) > 1 and res[1][1] == 'TIMEOUT':
                self.set_status(ReaderStatus.PAUSED)
                return
            if not self.is_connected():
                return
            if self.status == ReaderStatus.WAIT_FOR_PUSH:
                self.do_read()
            if self.is_connected():
                # am I still in IDLE state (WAIT_FOR_PUSH), or PAUSED?
                self.set_status(ReaderStatus.WAIT_FOR_PUSH)
        except IMAP4.abort as e:
            raise IrrecoverableError(e)
        except IMAP4.error as e:
            raise ClientError(e)

imaplib2

A threaded Python IMAP4 client.

MIT
Latest version published 3 years ago

Package Health Score

63 / 100
Full package analysis

Similar packages