コード例 #1
0
 public static void Connect(
     this MailBoxDto mailBox,
     IImapClient client,
     CancellationTokenSource cancelToken)
 {
     client.Connect(mailBox.Server, mailBox.Port, MailKit.Security.SecureSocketOptions.Auto, cancelToken.Token);
 }
コード例 #2
0
 public EmailService(IImapClient client)
 {
     if (client == null)
     {
         throw new ArgumentNullException("client");
     }
     _imapClient = client;
 }
コード例 #3
0
 /// <summary>
 /// Returns imap folders collection.
 /// </summary>
 /// <param name="mailboxId">Mailbox sync settings Id.</param>
 /// <param name="mailServerId">Mail server Id.</param>
 /// <param name="mailboxName">Mailbox name.</param>
 /// <param name="mailboxPassword">Mailbox password.</param>
 /// <returns>Imap folders collection.</returns>
 protected virtual List <IImapFolder> GetImapFolders(string mailboxId, string mailServerId,
                                                     string mailboxName, string mailboxPassword)
 {
     try {
         IImapClient imapClient = !string.IsNullOrEmpty(mailboxId)
                                 ? GetImapClientByMailboxId(mailboxId, out mailboxName)
                                 : GetImapClient(mailServerId, mailboxName, mailboxPassword);
         return(imapClient.GetFolders());
     } catch (Exception e) {
         _log.ErrorFormat("GetImapFolders method error for {0} mailbox.", e, mailboxName);
     }
     return(null);
 }
コード例 #4
0
 public void Connect(MapConfig config)
 {
     try
     {
         _log.Info("Connecting to SMTP server");
         _client = new ImapClient(config.Host, config.Port, config.Ssl);
         _log.Info("logging to SMTP server");
         this.Authentificate(config);
     }
     catch (Exception ex)
     {
         _log.Error(ex);
     }
 }
コード例 #5
0
        private static IObservable<IMessage> SearchImap(IImapClient imapClient, IEnumerable<string> contactKeys, IAccount account)
        {
            var query = from isConnected in imapClient.Connect("imap.gmail.com", 993)
                                         .Select(isConnected =>
                                         {
                                             if (isConnected) return true;
                                             throw new IOException("Failed to connect to Gmail IMAP server.");
                                         })
                        from isAuthenticated in imapClient.Authenticate(account.AccountId, account.CurrentSession.AccessToken)
                                                          .Select(isAuthenticated =>
                                                          {
                                                              if (isAuthenticated) return true;
                                                              throw new AuthenticationException("Failed to authenticate for Gmail search.");
                                                          })
                        from isSelected in imapClient.SelectFolder("[Gmail]/All Mail")
                        let queryText = ToSearchQuery(contactKeys)
                        from emailIds in imapClient.FindEmailIds(queryText)
                        from email in imapClient.FetchEmailSummaries(emailIds.Reverse(), account.Handles.Single(ch => ch.HandleType == ContactHandleTypes.Email).Handle)
                        select email;

            return query.Distinct(msg => msg.DeepLink)
                        .Take(10);
        }
コード例 #6
0
ファイル: IImapClient.cs プロジェクト: alexed1/dtrack
 public IdleErrorEventArgsWrapper(IImapClient client, Exception exception)
 {
     Client = client;
     Exception = exception;
 }
コード例 #7
0
ファイル: IImapClient.cs プロジェクト: alexed1/dtrack
 public IdleMessageEventArgsWrapper(IImapClient client)
 {
     Client = client;
 }
コード例 #8
0
 public void Should_Throw_With_Null_Client()
 {
     IImapClient client = null;
     var         target = new EmailService(client);
 }
コード例 #9
0
 public IdleErrorEventArgsWrapper(IImapClient client, Exception exception)
 {
     Client    = client;
     Exception = exception;
 }
コード例 #10
0
 public IdleMessageEventArgsWrapper(IImapClient client)
 {
     Client = client;
 }
コード例 #11
0
ファイル: ImapIdler.cs プロジェクト: ptfuller/InboxWatcher
        public virtual async Task Setup(bool isRecoverySetup = false)
        {
            //we should throw an exception if the initial setup is unable to successfully get a client
            //but after that we know that credentials are good and should handle exceptions for any new clients that we need to create
            if (isRecoverySetup)
            {
                try
                {
                    if (ImapClient != null && ImapClient.IsConnected)
                    {
                        await ImapClient.DisconnectAsync(true, Util.GetCancellationToken(15000));
                    }

                    ImapClient = await Factory.GetClient();
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex.Message);

                    //wait 10 seconds before trying again
                    await Task.Delay(10000);
                    await Setup(true);
                    return;
                }
            }
            else
            {
                ImapClient = await Factory.GetClient();
            }

            ImapClient.Disconnected += (sender, args) =>
            {
                Trace.WriteLine("ImapClient disconnected");
            };
                
            ImapClient.Inbox.Opened += (sender, args) => { Trace.WriteLine($"{Factory.MailBoxName} {GetType().Name} Inbox opened"); };
            ImapClient.Inbox.Closed += (sender, args) => { Trace.WriteLine($"{Factory.MailBoxName} {GetType().Name} Inbox closed"); };
            
            IdleTask = null;

            Trace.WriteLine($"{Factory.MailBoxName}: {GetType().Name} setup complete");

            IntegrityCheckTimer.Start();

            await StartIdling();
        }