當前位置: 首頁>>代碼示例>>Python>>正文


Python imapclient.IMAPClient方法代碼示例

本文整理匯總了Python中imapclient.IMAPClient方法的典型用法代碼示例。如果您正苦於以下問題:Python imapclient.IMAPClient方法的具體用法?Python imapclient.IMAPClient怎麽用?Python imapclient.IMAPClient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在imapclient的用法示例。


在下文中一共展示了imapclient.IMAPClient方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import imapclient [as 別名]
# 或者: from imapclient import IMAPClient [as 別名]
def __init__(self, user, access_token):
        self._selected_folder = None
        self.client = imapclient.IMAPClient('imap.gmail.com', use_uid=True,
                                            ssl=True)
        if 'COMPRESS=DEFLATE' in self.client.capabilities:
            self.client.enable_compression()
            # WARNING: never set enable this in productive environment
        # It has a bug.
        self.client.debug = 0
        try:
            self.client.oauth2_login(user, access_token)
        except IMAPError, e:
            self.quit()
            raise AuthenticationError('oauth login failed: ' + str(e))
        try:
            self._list_folders()
            # make sure it fails early if those mailboxes do not exist.
            self.get_trash_box()
            self.get_all_box()
        except Exception:
            self.quit()
            raise 
開發者ID:Schibum,項目名稱:sndlatr,代碼行數:24,代碼來源:gmail.py

示例2: create_client_from_config

# 需要導入模塊: import imapclient [as 別名]
# 或者: from imapclient import IMAPClient [as 別名]
def create_client_from_config(conf):
    client = imapclient.IMAPClient(conf.host, port=conf.port,
                                   ssl=conf.ssl, stream=conf.stream)
    if conf.oauth:
        client.oauth_login(conf.oauth_url,
                           conf.oauth_token,
                           conf.oauth_token_secret)
    elif conf.oauth2:
        access_token = get_oauth2_token(conf.oauth2_client_id,
                                        conf.oauth2_client_secret,
                                        conf.oauth2_refresh_token)
        client.oauth2_login(conf.username, access_token)

    elif not conf.stream:
        client.login(conf.username, conf.password)
    return client 
開發者ID:Schibum,項目名稱:sndlatr,代碼行數:18,代碼來源:config.py

示例3: __init__

# 需要導入模塊: import imapclient [as 別名]
# 或者: from imapclient import IMAPClient [as 別名]
def __init__(self, cfg):
        super().__init__(cfg)

        # Use default client behavior if ca_file not provided.
        context = None
        if 'ca_file' in cfg['server']:
            context = ssl.create_default_context(
                cafile=cfg['server']['ca_file']
            )

        self._conn = imapclient.IMAPClient(
            cfg['server']['hostname'],
            use_uid=True,
            ssl=True,
            port=cfg['server'].get('port'),
            ssl_context=context,
        )
        username = cfg['server']['username']
        password = secrets.get_password(cfg)
        self._conn.login(username, password) 
開發者ID:dhellmann,項目名稱:imapautofiler,代碼行數:22,代碼來源:client.py

示例4: test_imap

# 需要導入模塊: import imapclient [as 別名]
# 或者: from imapclient import IMAPClient [as 別名]
def test_imap(user):
    credentials = get_credentials()
    conn = IMAPClient('imap.googlemail.com', use_uid=True, ssl=True)
    # conn.debug = 4

    conn.oauth2_login(user, credentials.access_token)

    # status, labels = conn.list()
    folders = conn.list_folders()
    try:
        all_box = next(box for (flags, _, box) in folders if '\All' in flags)
    except StopIteration:
        raise Error('all message box not found')

    logging.debug('All message box is {}'.format(all_box))

    conn.select_folder(all_box)
    # Once authenticated everything from the impalib.IMAP4_SSL class will
    # work as per usual without any modification to your code.
    # typ, msgnums = conn.search('X-GM-RAW vget')
    tid = int('14095f27c538b207', 16)
    # msgs = conn.search('X-GM-THRID {}'.format(tid))
    msgs = conn.search('X-GM-RAW uniquetokenXXX')

    print msgs
    # print conn.fetch(msgs, 'X-GM-MSGID')
    # print conn.fetch(msgs, 'RFC822')
    # conn.select('INBOX')
    # print conn.list() 
開發者ID:Schibum,項目名稱:sndlatr,代碼行數:31,代碼來源:cli.py

示例5: test_imap

# 需要導入模塊: import imapclient [as 別名]
# 或者: from imapclient import IMAPClient [as 別名]
def test_imap(user):
    credentials = decorator.credentials
    if credentials.access_token_expired:
        logging.debug('Refreshing...')
        credentials.refresh(httplib2.Http())
    conn = IMAPClient('imap.gmail.com', use_uid=True, ssl=True)
    conn.debug = 4

    conn.oauth2_login(user, credentials.access_token)

    # status, labels = conn.list()
    folders = conn.list_folders()
    try:
        all_box = next(box for (flags, _, box) in folders if '\All' in flags)
    except StopIteration:
        raise Error('all message box not found')

    logging.debug('All message box is {}'.format(all_box))

    conn.select_folder(all_box)
    # Once authenticated everything from the impalib.IMAP4_SSL class will
    # work as per usual without any modification to your code.
    # typ, msgnums = conn.search('X-GM-RAW vget')
    tid = int('14095f27c538b207', 16)
    # msgs = conn.search('X-GM-THRID {}'.format(tid))
    msgs = conn.search('X-GM-RAW uniquetokenXXX')

    logging.info(msgs)
    logging.info(conn.fetch(msgs, 'X-GM-MSGID'))
    msg = conn.fetch(msgs, 'RFC822')
    logging.info(msg)
    return msg 
開發者ID:Schibum,項目名稱:sndlatr,代碼行數:34,代碼來源:mainold.py

示例6: check_and_run

# 需要導入模塊: import imapclient [as 別名]
# 或者: from imapclient import IMAPClient [as 別名]
def check_and_run() :
    imap_conn = imapclient.IMAPClient (domain_name, ssl = True)
    print (imap_conn)
    try :
        print (imap_conn.login (emailaddress, password))
    except :
        print ('Wrong username password combination! Please try again.')
        sys.exit()
    print (imap_conn.select_folder ('INBOX', readonly = False))
    uids = imap_conn.gmail_search ('label:' + label + ' label:Inbox ' + emailaddress + ' subject:' + mysubject + ' label:unread')
    print (uids)
    messages = imap_conn.fetch (uids, ['BODY[]'])
    for x in messages.keys() :
        lstcomm = pyzmail.PyzMessage.factory (messages[x][b'BODY[]'])
        commands.append (lstcomm.text_part.get_payload().decode (lstcomm.text_part.charset))   
    print (imap_conn.logout())
    twilioClient = TwilioRestClient (twilioSID, twilioAuthToken)
    for x in commands[::-1] :
        newfile = open ('commandstorun.py', 'w')
        newfile.write ('#! /usr/bin/python3\n')
        newfile.write (x)
        newfile.close()
        os.system ('chmod +x commandstorun.py')
        os.system ('./commandstorun.py')
        print ('Executed script :\n' + x)
        msg = twilioClient.messages.create (body = 'Your script has been executed! ' + x, from_ = sender, to = receiver)        
        print (msg.status) 
開發者ID:Anishka0107,項目名稱:Cool-Scripts,代碼行數:29,代碼來源:Execute_Instructions_Remotely.py

示例7: __init__

# 需要導入模塊: import imapclient [as 別名]
# 或者: from imapclient import IMAPClient [as 別名]
def __init__(self, host=None, username=None, password=None,
                 port=None, SSL=True):
        self.server = IMAPClient(host=host, ssl=SSL, timeout=10)
        self.username = username
        self.password = password 
開發者ID:wuyue92tree,項目名稱:crwy,代碼行數:7,代碼來源:mail.py

示例8: setup

# 需要導入模塊: import imapclient [as 別名]
# 或者: from imapclient import IMAPClient [as 別名]
def setup(self, client, hostname, username, password):
        self._imap  = IMAPClient(hostname, use_uid=True, ssl=True)
        # self._imap.debug = True
        self._imap.login(username, password)
        self._client = client
        self._folder = None 
開發者ID:dividuum,項目名稱:one-time-mail,代碼行數:8,代碼來源:otm.py

示例9: setup_inbox

# 需要導入模塊: import imapclient [as 別名]
# 或者: from imapclient import IMAPClient [as 別名]
def setup_inbox(self, password, user=None, folder='INBOX', refresh=False, auto=False, ssl=True):
        """
        Configure an IMAP connection for receiving SMS.

        Optionally configure behaviours such as auto-refresh,
        refresh immediately once configured, or specify a folder.

        This method will also attempt to create a folder/label in your
        Gmail account to store processed messages in.

        Folder specifications are useful if you configure your Gmail account to
        filter messages from certain senders to be moved to a specific folder,
        that way they don't clutter your Gmail Inbox folder.
        """

        # Apply user if not provided
        if not user:
            user = self.__user

        # Connect IMAP server
        self.imap = imapclient.IMAPClient('imap.gmail.com', ssl=ssl)
        self.imap.login(user, password)
        self.imap.select_folder(folder)

        # Create processed folder
        if not self.imap.folder_exists(self.processed_label):
            self.imap.create_folder(self.processed_label)

        # Refresh if requested
        if refresh and not auto:
            self.refresh()
        elif auto:
            self.enable_auto_refresh(start=True) 
開發者ID:hawkins,項目名稱:Shawk,代碼行數:35,代碼來源:Client.py

示例10: login

# 需要導入模塊: import imapclient [as 別名]
# 或者: from imapclient import IMAPClient [as 別名]
def login(self):
        try:
            context = ssl.create_default_context(cafile=certifi.where())
            # context.check_hostname = False
            # context.verify_mode = ssl.CERT_NONE
            mailbox = IMAPClient(
                self.source.host,
                port=self.source.port,
                use_uid=True,
                ssl=self.source.use_ssl,
                ssl_context=context)
            # mailbox.debug = 5
            capabilities = mailbox.capabilities()
            if b'STARTTLS' in capabilities:
                # Always use starttls if server supports it
                mailbox.starttls(context)
            if b'IDLE' in capabilities:
                self.can_push = True
            mailbox.login(self.source.username, self.source.password)
            mailbox.select_folder(self.source.folder)
            self.selected_folder = True
            self.mailbox = mailbox
        except IMAP4.abort as e:
            raise IrrecoverableError(e)
        except IMAP4.error as e:
            raise ClientError(e) 
開發者ID:conversence,項目名稱:idealoom,代碼行數:28,代碼來源:imapclient_source_reader.py

示例11: open_connection

# 需要導入模塊: import imapclient [as 別名]
# 或者: from imapclient import IMAPClient [as 別名]
def open_connection(cfg):
    "Open a connection to the mail server."
    if 'server' in cfg:
        return IMAPClient(cfg)
    if 'maildir' in cfg:
        return MaildirClient(cfg)
    raise ValueError('Could not find connection information in config') 
開發者ID:dhellmann,項目名稱:imapautofiler,代碼行數:9,代碼來源:client.py


注:本文中的imapclient.IMAPClient方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。