Skip to content

Commit

Permalink
updated readme to use Top()
Browse files Browse the repository at this point in the history
  • Loading branch information
danzuep committed Sep 28, 2023
1 parent 1ec0b12 commit 09fdb31
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Receiving emails with MailKitSimplified.Receiver is as easy as:

```csharp
using var imapReceiver = ImapReceiver.Create("localhost");
var mimeMessages = await imapReceiver.ReadMail.GetMimeMessagesAsync();
var mimeMessages = await imapReceiver.ReadMail.Top(1).GetMimeMessagesAsync();
```

You can even monitor an email folder for new messages asynchronously, never before has it been this easy!
Expand All @@ -29,7 +29,7 @@ await imapReceiver.MonitorFolder.OnMessageArrival(m => Console.WriteLine(m.Uniqu
Once you've got either a mime message or a message summary, replying is now equally as intuitive.

```csharp
var mimeReply = mimeMessages.GetReplyMessage("<p>Reply here.</p>");
var mimeReply = mimeMessage.GetReplyMessage("<p>Reply here.</p>").From("noreply@example.com");
```

You're welcome. 🥲
Expand Down Expand Up @@ -69,13 +69,17 @@ var mimeMessages = await imapReceiver.ReadMail
.GetMimeMessagesAsync(cancellationToken);
```

Note: Use imapReceiver.ReadMail.Top(#) to get the newest (descending) results.

To only download the email parts you want to use:

```csharp
var messageSummaries = await imapReceiver.ReadMail
.GetMessageSummariesAsync(cancellationToken);
```

Note: MailKit returns results in ascending order by default, use messageSummaries.Reverse() to get descending results.

To query unread emails from the IMAP server and specify which message parts to download:

```csharp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,10 @@ public async Task<IList<MimeMessage>> GetMimeMessagesAsync(CancellationToken can
}
else if ((_take == _all && !_top.HasValue) || _searchQuery != _queryAll)
{
if (_take > _queryAmount)
_logger.LogWarning($"Take({_take}) limited by SearchQuery to 250 results.");
if (_take != _all && (uint)_skip + _take > _queryAmount)
_logger.LogWarning($"Skip({_skip}).Take({_take}) limited by SearchQuery to 250 results.");
else if (_take == _all)
_logger.LogDebug("GetMimeMessagesAsync() limited by SearchQuery to 250 results.");
var uniqueIds = await mailFolder.SearchAsync(_searchQuery, cancellationToken).ConfigureAwait(false);
var descendingUids = new UniqueIdSet(uniqueIds, SortOrder.Descending).Skip(_skip);
var filteredUids = _take == _all ? descendingUids : descendingUids.Take(_take);
Expand Down

0 comments on commit 09fdb31

Please sign in to comment.