Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mail loading fixes & additional Search parameters #69

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions OpaqueMail/Imap/ImapClient.Synchronous.cs
Original file line number Diff line number Diff line change
Expand Up @@ -697,9 +697,9 @@ public bool RenameMailbox(string currentMailboxName, string newMailboxName)
/// Perform a search in the current mailbox and return all matching messages.
/// </summary>
/// <param name="searchQuery">Well-formatted IMAP search criteria.</param>
public List<MailMessage> Search(string searchQuery)
public List<MailMessage> Search(string searchQuery, bool headersOnly = false, bool setSeenFlag = false)
{
return Task.Run(() => SearchAsync(searchQuery)).Result;
return Task.Run(() => SearchAsync(searchQuery, headersOnly, setSeenFlag)).Result;
}

/// <summary>
Expand Down
21 changes: 13 additions & 8 deletions OpaqueMail/Imap/ImapClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1979,7 +1979,7 @@ public async Task<bool> RenameMailboxAsync(string currentMailboxName, string new
/// Perform a search in the current mailbox and return all matching messages.
/// </summary>
/// <param name="searchQuery">Well-formatted IMAP search criteria.</param>
public async Task<List<MailMessage>> SearchAsync(string searchQuery)
public async Task<List<MailMessage>> SearchAsync(string searchQuery, bool headersOnly = false, bool setSeenFlag = false)
{
// Protect against commands being called out of order.
if (!IsAuthenticated)
Expand Down Expand Up @@ -2009,7 +2009,7 @@ public async Task<List<MailMessage>> SearchAsync(string searchQuery)
int numericMessageID = -1;
if (int.TryParse(messageID, out numericMessageID))
{
MailMessage message = await GetMessageAsync(int.Parse(messageID));
MailMessage message = await GetMessageAsync(CurrentMailboxName, int.Parse(messageID), headersOnly, setSeenFlag);
if (message != null)
messages.Add(message);
}
Expand Down Expand Up @@ -2299,6 +2299,8 @@ private async void CheckIdle(object idleInitializedTimeObject)
private async Task<MailMessage> GetMessageHelper(string mailboxName, int id, bool headersOnly, bool setSeenFlag, bool isUid)
{
MessagePartialHelper helper = await GetMessagePartialHelper(mailboxName, id, headersOnly, setSeenFlag, -1, -1, isUid);
if (helper == null)
return null;

MailMessage message = new MailMessage(helper.MessageString, ProcessingFlags);
message.ImapUid = helper.ImapUid;
Expand Down Expand Up @@ -2376,14 +2378,17 @@ private async Task<MessagePartialHelper> GetMessagePartialHelper(string mailboxN
{
// Read the message's UID and flags.
int uid = 0;
if (!int.TryParse(Functions.ReturnBetween(response, "\r\n UID ", " "), out uid))
{
int.TryParse(Functions.ReturnBetween(response, "\r\n UID ", " "), out uid);
if (uid == 0)
int.TryParse(Functions.ReturnBetween(response, "\r\n UID ", ")"), out uid);
}
else if (!int.TryParse(Functions.ReturnBetween(response, "\r\nUID ", " "), out uid))
{
if (uid == 0)
int.TryParse(Functions.ReturnBetween(response, "\r\nUID ", " "), out uid);
if (uid == 0)
int.TryParse(Functions.ReturnBetween(response, "\r\nUID ", ")"), out uid);
}
if (uid == 0)
int.TryParse(Functions.ReturnBetween(response, "UID ", " "), out uid);
if (uid == 0)
int.TryParse(Functions.ReturnBetween(response, "UID ", ")"), out uid);
string flagsString = Functions.ReturnBetween(response, "FLAGS (", ")");

// Strip IMAP response padding.
Expand Down