Skip to content

Commit 7b4b1fc

Browse files
committed
#72 removed cancel from move
1 parent e881f9b commit 7b4b1fc

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

source/MailKitSimplified.Receiver/Extensions/MessageSummaryExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ public static async Task AddFlagsAsync(this IMessageSummary messageSummary, Mess
408408
bool peekSourceFolder = !messageSummary.Folder.IsOpen;
409409
if (peekSourceFolder || messageSummary.Folder.Access != FolderAccess.ReadWrite)
410410
_ = await messageSummary.Folder.OpenAsync(FolderAccess.ReadWrite, cancellationToken).ConfigureAwait(false);
411-
resultUid = await messageSummary.Folder.MoveToAsync(messageSummary.UniqueId, destination, cancellationToken).ConfigureAwait(false);
411+
resultUid = await messageSummary.Folder.MoveToAsync(messageSummary.UniqueId, destination, CancellationToken.None).ConfigureAwait(false);
412412
if (peekSourceFolder)
413413
await messageSummary.Folder.CloseAsync(expunge: false, cancellationToken).ConfigureAwait(false);
414414
}

source/MailKitSimplified.Receiver/Services/MailFolderClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public async Task<int> DeleteMessagesAsync(TimeSpan relativeOffset, SearchQuery
324324
bool peekSourceFolder = !source.IsOpen;
325325
// Beware, source must be opened after destination to keep it open
326326
_ = await OpenAsync(source, enableWrite: move, cancellationToken).ConfigureAwait(false);
327-
resultUid = await source.MoveToAsync(messageUid, destination, cancellationToken).ConfigureAwait(false);
327+
resultUid = await source.MoveToAsync(messageUid, destination, CancellationToken.None).ConfigureAwait(false);
328328
_logger.LogTrace("{0} {1} {2} to {3} in {4}.", _imapReceiver, messageUid, verb, resultUid, destination.FullName);
329329
if (peekSourceFolder && source.IsOpen)
330330
await source.CloseAsync(expunge: false, cancellationToken).ConfigureAwait(false);

source/MailKitSimplified.Receiver/Services/MailFolderMonitor.cs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ public MailFolderMonitor(IImapReceiver imapReceiver, IOptions<FolderMonitorOptio
4848
_folderMonitorOptions = folderMonitorOptions?.Value ?? new FolderMonitorOptions();
4949
_messageArrivalMethod = (m) =>
5050
{
51-
_logger.Log<MailFolderMonitor>($"{_imapReceiver} message #{m.UniqueId} arrival processed.");
51+
_logger.Log<MailFolderMonitor>($"{_imapReceiver} message #{m.UniqueId} arrival processed.", LogLevel.Debug);
5252
return _completedTask;
5353
};
5454
_messageDepartureMethod = (m) =>
5555
{
56-
_logger.Log<MailFolderMonitor>($"{_imapReceiver} message #{m.UniqueId} departure processed.");
56+
_logger.Log<MailFolderMonitor>($"{_imapReceiver} message #{m.UniqueId} departure processed.", LogLevel.Debug);
5757
return _completedTask;
5858
};
5959
}
@@ -224,7 +224,7 @@ private async Task IdleStartAsync(CancellationToken cancellationToken = default)
224224
_mailFolder = await _imapReceiver.ConnectMailFolderAsync(cancellationToken).ConfigureAwait(false);
225225
_ = await _mailFolder.OpenAsync(FolderAccess.ReadOnly, cancellationToken).ConfigureAwait(false);
226226
var connectOption = _folderMonitorOptions.IgnoreExistingMailOnConnect ? "ignoring" : "fetching";
227-
_logger.Log<MailFolderMonitor>($"{_imapReceiver} ({_mailFolder.Count}) idle monitor started, {connectOption} existing emails.");
227+
_logger.Log<MailFolderMonitor>($"{_imapReceiver} ({_mailFolder.Count}) idle monitor started, {connectOption} existing emails.", LogLevel.Information);
228228

229229
_mailFolder.CountChanged += OnCountChanged;
230230
_mailFolder.MessageExpunged += OnMessageExpunged;
@@ -297,19 +297,30 @@ private async ValueTask ReconnectAsync(CancellationToken cancellationToken = def
297297
{
298298
await LogDelayAsync(ex, "IMAP protocol exception").ConfigureAwait(false);
299299
}
300+
catch (ImapCommandException ex)
301+
{
302+
await LogDelayAsync(ex, "IMAP command exception").ConfigureAwait(false);
303+
}
300304
catch (SocketException ex)
301305
{
302306
await LogDelayAsync(ex, "IMAP socket exception").ConfigureAwait(false);
303307
}
304-
305-
async Task LogDelayAsync(Exception exception, string exceptionType)
308+
catch (IOException ex)
306309
{
307-
var message = $"{exceptionType} during connection attempt #{++attemptCount}, backing off for {_folderMonitorOptions.EmptyQueueMaxDelayMs}ms. {_imapReceiver}.";
310+
await LogDelayAsync(ex, "IMAP I/O exception").ConfigureAwait(false);
311+
}
312+
313+
async ValueTask LogDelayAsync(Exception exception, string exceptionType)
314+
{
315+
bool isBackoff = attemptCount > 0;
316+
var backoff = isBackoff ? $", backing off for {_folderMonitorOptions.EmptyQueueMaxDelayMs}ms" : string.Empty;
317+
var message = $"{exceptionType} during connection attempt #{++attemptCount}{backoff}. {_imapReceiver}.";
308318
if (attemptCount < _folderMonitorOptions.MaxRetries)
309-
_logger.Log<MailFolderMonitor>(exceptionType, LogLevel.Warning);
319+
_logger.Log<MailFolderMonitor>(message, LogLevel.Information);
310320
else
311-
_logger.Log<MailFolderMonitor>(exception, exceptionType, LogLevel.Error);
312-
await Task.Delay(_folderMonitorOptions.EmptyQueueMaxDelayMs, cancellationToken).ConfigureAwait(false);
321+
_logger.Log<MailFolderMonitor>(exception, message, LogLevel.Error);
322+
if (isBackoff)
323+
await Task.Delay(_folderMonitorOptions.EmptyQueueMaxDelayMs, cancellationToken).ConfigureAwait(false);
313324
}
314325
}
315326
}
@@ -345,7 +356,8 @@ private async ValueTask WaitForNewMessagesAsync(CancellationToken cancellationTo
345356
}
346357
catch (ImapProtocolException ex)
347358
{
348-
var message = $"{ex.Message} Reconnecting and trying again.";
359+
string error = ex.Message.TrimEnd(new char[] { ' ', '.' });
360+
var message = $"{error}. IMAP protocol exception, reconnecting and trying again.";
349361
if (ex.Message.StartsWith("Idle timeout"))
350362
_logger.Log<MailFolderMonitor>(message, LogLevel.Debug);
351363
else

0 commit comments

Comments
 (0)