Email IMAP IDLE似乎不适用于iCloud电子邮件和S22.IMAP

Email IMAP IDLE似乎不适用于iCloud电子邮件和S22.IMAP,email,imap,icloud,Email,Imap,Icloud,我正在使用S22.IMAP实现所示的示例,特别是NewMessage事件 我正在从我的Gmail帐户向我的iCloud发送测试电子邮件,但活动没有启动。我把它们颠倒过来,发送到我的Gmail,事件就被触发了。iCloud实际上不支持IMAP IDLE吗?它没有抛出异常,说它没有,或者您需要做一些特殊的事情才能让iCloud推送到您的应用程序中 public EmailInstance(String email, SupportedMailTypes type) {

我正在使用S22.IMAP实现所示的示例,特别是NewMessage事件

我正在从我的Gmail帐户向我的iCloud发送测试电子邮件,但活动没有启动。我把它们颠倒过来,发送到我的Gmail,事件就被触发了。iCloud实际上不支持IMAP IDLE吗?它没有抛出异常,说它没有,或者您需要做一些特殊的事情才能让iCloud推送到您的应用程序中

    public EmailInstance(String email, SupportedMailTypes type)
    {
        _emailAddress = email;
        _mailType = type;
        InitializeEmail();
    }

    private void InitializeEmail()
    {
        if (_mailType == SupportedMailTypes.Gmail)
        {
            _client = new ImapClient(GMAIL_SERVER, PORT, _emailAddress, PASSWORD, AuthMethod.Login, true);                          
        }
        else if (_mailType == SupportedMailTypes.iCloud)
        {
            _client = new ImapClient(ICLOUD_SERVER, PORT, _emailAddress, PASSWORD, AuthMethod.Login, true);
        }

        // Download mail messages from the default mailbox.
        NewEmailCount = GetMessageCount();

        // Check that IDLE is supported by the server
        if (_client.Supports("IDLE") == false)
        {
            throw new Exception("Server does not support IDLE.");
        }

        _client.IdleError += OnIdleError;
        _client.NewMessage += OnNewMessage;
        _client.MessageDeleted += OnMessageDeleted;
    }

    /// <summary>
    /// If idling throws an error.
    /// </summary>
    private void OnIdleError(object sender, IdleErrorEventArgs e)
    {
        throw new Exception(e.Exception.Message);
    }

    /// <summary>
    /// What to do when the client receives a new message.
    /// </summary>
    private void OnNewMessage(object sender, IdleMessageEventArgs e)
    {
        NewEmailCount = GetMessageCount(); 
        var header = _client.GetMessage(e.MessageUID, FetchOptions.HeadersOnly, false);
    }

    private void OnMessageDeleted(object sender, IdleMessageEventArgs e)
    {
        NewEmailCount = GetMessageCount();
    }

    /// <summary>
    /// Returns the message count
    /// </summary>
    private int GetMessageCount()
    {
        var uids = _client.Search(SearchCondition.Unseen());                    
        return _client.GetMessages(uids, FetchOptions.HeadersOnly, false).Count();
    }

您是否实现了示例中的if!Client.SupportsIDLE…?@arnt是的。这就是让我困惑的地方。它没有出错,事件也没有像Gmail收到它时那样被调用。Gmail工作,iCloud没有。IIRC,iCloud基于dovecot,一种支持空闲的开源软件,所以他们肯定已经主动删除了它。我建议使用openssl s_client-connect foo:993-crlf,然后是dustin asdfasdf登录,然后是b select inbox,然后是c idle来测试是服务器还是客户端。阅读邮件或使用任何客户端删除一些邮件,您应该会看到openssl会话中出现的行,通知您这些更改。@arnt我今晚会这样做,并发布结果。干杯。iCloud支持空闲。