【问题标题】:Howto run XLIST command in python imap lib on google imap server?如何在谷歌 imap 服务器上的 python imaplib 中运行 XLIST 命令?
【发布时间】:2012-01-16 14:58:16
【问题描述】:

我想从 python lib 运行 XLIST 命令,有人知道怎么做吗? (python 文档中没有关于此命令的内容)。本题地址this issue

【问题讨论】:

    标签: python gmail imap


    【解决方案1】:

    此命令不是由 imaplib 实现的。

    我知道这有点小题大做,但出于完全相同的原因,我确实需要运行 XLIST。

    查看list() 在imaplib 源代码中的实现方式,我继承了imaplib 的IMAP4_SSL 类并添加了xlist() 命令。所以,在 adv_imaplib.py 中添加:

    import imaplib
    
    imaplib.Commands['XLIST'] =  ('AUTH', 'SELECTED')
    
    class ADV_IMAP4_SSL(imaplib.IMAP4_SSL):
    
      def xlist(self, directory='""', pattern='*'):
        """(X)List mailbox names in directory matching pattern. Using Google's XLIST extension
    
        (typ, [data]) = <instance>.xlist(directory='""', pattern='*')
    
        'data' is list of XLIST responses.
        """
        name = 'XLIST'
        typ, dat = self._simple_command(name, directory, pattern)
        return self._untagged_response(typ, dat, name)
    

    现在只需创建 ADV_IMAP4_SSL 而不是 IMAP4_SSL 并调用 xlist(),对我有用。

    【讨论】:

      【解决方案2】:

      解决此问题的另一种方法是使用第 3 方 IMAPClient 库。

      它支持 XLIST out of the box

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-05-09
        • 1970-01-01
        • 2011-08-13
        • 1970-01-01
        • 1970-01-01
        • 2021-01-03
        • 2020-11-08
        相关资源
        最近更新 更多