Skip to content

Commit

Permalink
#72 fixed alt idle task initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
danzuep committed Aug 27, 2024
1 parent 9a0b34d commit cbbd242
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 3 additions & 1 deletion samples/WorkerServiceExample/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,9 @@ await _imapReceiver.MonitorFolder
.SetIgnoreExistingMailOnConnect()
.OnMessageArrival(ProcessMessage)
.OnMessageDeparture(ProcessMessage)
.IdleAsync(cancellationToken);
.IdleAsync(cancellationToken)
.ContinueWith(t => _logger.LogError(t.Exception?.GetBaseException(),
"Arrival queue processing failed."), TaskContinuationOptions.OnlyOnFaulted);
await sendTask;
}

Expand Down
14 changes: 8 additions & 6 deletions source/MailKitSimplified.Receiver/Services/ImapReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public sealed class ImapReceiver : IImapReceiver
{
private Lazy<MailFolderClient> _mailFolderClient;
private Lazy<MailFolderReader> _mailFolderReader;
private Lazy<MailFolderMonitor> _mailFolderMonitor;
private Lazy<IMailFolderMonitor> _mailFolderMonitor;
private bool _isClientInjected;
private IImapClient _imapClient;
private IProtocolLogger _imapLogger;
Expand Down Expand Up @@ -86,7 +86,7 @@ private ImapReceiver SetOptions(EmailReceiverOptions emailReceiverOptions)
_imapClient, _receiverOptions, _loggerFactory.CreateLogger<MailFolderClient>(), _loggerFactory.CreateLogger<ImapReceiver>()));
_mailFolderReader = new Lazy<MailFolderReader>(() => MailFolderReader.Create(
_imapClient, _receiverOptions, _loggerFactory.CreateLogger<MailFolderReader>(), _loggerFactory.CreateLogger<ImapReceiver>()));
_mailFolderMonitor = new Lazy<MailFolderMonitor>(() => MailFolderMonitor.Create(
_mailFolderMonitor = new Lazy<IMailFolderMonitor>(() => MailFolderMonitor.Create(
_receiverOptions, _loggerFactory.CreateLogger<MailFolderMonitor>(), _loggerFactory.CreateLogger<ImapReceiver>(), _imapLogger));
return this;
}
Expand Down Expand Up @@ -123,7 +123,7 @@ public ImapReceiver SetProtocolLog(IProtocolLogger protocolLogger)
new LogFileWriter(_loggerFactory.CreateLogger<LogFileWriter>()),
Options.Create(_receiverOptions.ProtocolLogger),
_loggerFactory.CreateLogger<MailKitProtocolLogger>());
_mailFolderMonitor = new Lazy<MailFolderMonitor>(() => MailFolderMonitor.Create(
_mailFolderMonitor = new Lazy<IMailFolderMonitor>(() => MailFolderMonitor.Create(
_receiverOptions, _loggerFactory.CreateLogger<MailFolderMonitor>(), _loggerFactory.CreateLogger<ImapReceiver>(), _imapLogger));
return SetImapClient(null);
}
Expand Down Expand Up @@ -212,21 +212,23 @@ public ImapReceiver SetCustomAuthentication(SaslMechanism saslMechanism)
return this;
}

public IMailFolderClient GetFolder(string mailFolderName)
public IMailFolderClient GetFolder(string mailFolderName) //TODO add IMailFolderClient overload
{
_receiverOptions.MailFolderName = mailFolderName;
return MailFolderClient;
}

public IMailFolderReader ReadFrom(string mailFolderName)
public IMailFolderReader ReadFrom(string mailFolderName) //TODO add IMailFolderReader overload
{
_receiverOptions.MailFolderName = mailFolderName;
return ReadMail;
}

public IMailFolderMonitor Monitor(string mailFolderName)
public IMailFolderMonitor Monitor(string mailFolderName, IMailFolderMonitor mailFolderMonitor = null)
{
_receiverOptions.MailFolderName = mailFolderName;
if (mailFolderMonitor != null)
_mailFolderMonitor = new Lazy<IMailFolderMonitor>(() => mailFolderMonitor);
return MonitorFolder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public async Task IdleAsync(CancellationToken cancellationToken = default, bool
"Flag change queue processing failed."), TaskContinuationOptions.OnlyOnFaulted)
} : new Task[] {
IdleStartAsync(_cancel.Token),
ProcessDepartureQueueAsync(_messageArrivalMethod, _cancel.Token),
ProcessArrivalQueueAsync(_messageArrivalMethod, _cancel.Token),
ProcessDepartureQueueAsync(_messageDepartureMethod, _cancel.Token),
ProcessFlagChangeQueueAsync(_messageFlagsChangedMethod, _cancel.Token)
};
Expand Down

0 comments on commit cbbd242

Please sign in to comment.