Ejemplo n.º 1
0
    def verify_account(self, account):
        """
        Verify the credentials provided by logging in.
        Verify the account configuration -- specifically checks for the presence
        of the 'All Mail' folder.

        Raises
        ------
        An inbox.crispin.GmailSettingError if the 'All Mail' folder is
        not present and is required (account.sync_email == True).

        """
        try:
            # Verify login.
            conn = self.connect_account(account)
            # Verify configuration.
            client = GmailCrispinClient(account.id,
                                        provider_info('gmail'),
                                        account.email_address,
                                        conn,
                                        readonly=True)
            client.sync_folders()
            conn.logout()
        except ImapSupportDisabledError:
            if account.sync_email:
                raise

        # Reset the sync_state to 'running' on a successful re-auth.
        # Necessary for API requests to proceed and an account modify delta to
        # be returned to delta/ streaming clients.
        # NOTE: Setting this does not restart the sync. Sync scheduling occurs
        # via the sync_should_run bit (set to True in update_account() above).
        account.sync_state = ('running'
                              if account.sync_state else account.sync_state)
        return True
Ejemplo n.º 2
0
 def _open_crispin_connection(self, db_session):
     account = db_session.query(Account).get(self.account_id)
     conn = account.auth_handler.connect_account(account)
     self.crispin_client = GmailCrispinClient(self.account_id,
                                              provider_info('gmail'),
                                              account.email_address,
                                              conn,
                                              readonly=True)
Ejemplo n.º 3
0
def patch_gmail_client(monkeypatch, folders):
    monkeypatch.setattr(GmailCrispinClient, '_fetch_folder_list',
                        lambda x: folders)

    conn = MockedIMAPClient(host='somehost')
    return GmailCrispinClient(account_id=1, provider_info=None,
                              email_address='*****@*****.**',
                              conn=conn)
Ejemplo n.º 4
0
def gmail_client():
    conn = MockedIMAPClient(host="somehost")
    return GmailCrispinClient(
        account_id=1,
        provider_info=None,
        email_address="*****@*****.**",
        conn=conn,
    )
Ejemplo n.º 5
0
 def verify_config(self, account):
     """Verifies configuration, specifically presence of 'All Mail' folder.
        Will raise an inbox.crispin.GmailSettingError if not present.
     """
     conn = self.connect_account(account)
     # make a crispin client and check the folders
     client = GmailCrispinClient(account.id,
                                 provider_info('gmail'),
                                 account.email_address,
                                 conn,
                                 readonly=True)
     client.sync_folders()
     conn.logout()
     return True
Ejemplo n.º 6
0
    def search_messages(self, db_session, search_query):
        account = db_session.query(Account).get(self.account_id)
        conn = account.auth_handler.connect_account(account)
        crispin_client = GmailCrispinClient(self.account_id,
                                            provider_info('gmail'),
                                            account.email_address,
                                            conn,
                                            readonly=True)
        self.log.debug('Searching {} for `{}`'
                        .format(account.email_address, search_query))

        all_messages = set()
        folders = db_session.query(Folder).filter(
            Folder.account_id == self.account_id).all()

        for folder in folders:
            all_messages.update(self.search_folder(db_session,
                                                   crispin_client,
                                                   folder, search_query))

        crispin_client.logout()

        return sorted(all_messages, key=lambda msg: msg.received_date)