当前位置: 首页>>代码示例>>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;未经允许,请勿转载。