public EmailServiceImap(IEmailAccountConfiguration emailAccountConfiguration) { //emailClient = new ImapClient(new ProtocolLogger("imap.log")); emailClient = new ImapClient(); this.emailAccountConfiguration = emailAccountConfiguration; emailsReceived.Clear(); }
//główna metoda uruchamiana ręcznie oraz przez timer private async Task <bool> checkForEmails() { bool emailsReceived = false; if (!NetworkInterface.GetIsNetworkAvailable()) //nowe wiadomości sprawdzam tylko wtedy gdy jest internet { handleEmailServiceException(new EmailServiceException("brak internetu")); } else { foreach (string accountName in this.emailAccountDict.Keys) { try { EmailAccount account; emailAccountDict.TryGetValue(accountName, out account); IEmailAccountConfiguration emailConfiguration = account.configuration; getEmailService(emailConfiguration); var token = cancellationTokenSource.Token; Task t = Task.Factory.StartNew(() => { if (token.IsCancellationRequested) { throw new OperationCanceledException(); } tryGetEmails(ref emailsReceived, account); }, token); await t; //try //{ Task.WaitAll(t); //} //catch (AggregateException ae) //{ // handleEmailServiceException(ae, accountName); //} } catch (EmailServiceException e) { handleEmailServiceException(e, accountName); } catch (System.IO.IOException ex) { handleEmailServiceException(ex, accountName); } } } setDefaultStatusLabel(); return(emailsReceived); }
//tworzy nową instancję serwisu w zależności od jego rodzaju private void getEmailService(IEmailAccountConfiguration emailConfiguration) { emailService = null; switch (emailConfiguration.receiveServer.serverType) { case ServerType.POP: emailService = new EmailServicePop(emailConfiguration); break; case ServerType.IMAP: emailService = new EmailServiceImap(emailConfiguration); break; } }
private bool addOrUpdateAccountConfiguration() { string accountName = getAccountName(); if (accountConfigsDict.ContainsKey(accountName)) //aktualizacja { accountConfigsDict.TryGetValue(accountName, out accountConfig); getAccountConfigurationFromGUI(accountConfig); return(true); } if (accountName != "" && accountName != null) //nowy { accountConfig = new EmailAccountConfiguration(); getAccountConfigurationFromGUI(accountConfig); accountConfigsDict.Add(accountName, accountConfig); return(true); } return(false); }
private void getAccountConfigurationFromGUI(IEmailAccountConfiguration emailConfig) { var receiveServer = new EmailServer(); ServerType serverType; Enum.TryParse <ServerType>(protocolTypeComboBox.SelectedValue.ToString(), out serverType); receiveServer.serverType = serverType; receiveServer.url = serverUrlTextBox.Text; receiveServer.port = verifyInt(portTextBox.Text); receiveServer.useAuthorisation = getAuthorisation(); emailConfig.receiveServer = receiveServer; emailConfig.username = userNameTextBox.Text; //nie chcę wyświetlać hasła a z drugiej strony nie chcę nadpisywać zapisanego hasła pustym stringiem if (passwordTextBox.Text != "") { emailConfig.password = passwordTextBox.Text; } }
public EmailServicePop(IEmailAccountConfiguration emailAccountConfiguration) { this.emailAccountConfiguration = emailAccountConfiguration; emailClient = new Pop3Client(); emailsReceived.Clear(); }