Skip to content

Commit

Permalink
Added logic to ImapFolder.GetSubfolders() to filter out unexpected fo…
Browse files Browse the repository at this point in the history
…lders

This shouldn't be necessary, but broken IMAP servers like SmarterMail 13.0
(which is apparently not very smart at all) ruin it for the rest of us.

Fixes issue #149
  • Loading branch information
jstedfast committed Feb 17, 2015
1 parent b4388e9 commit b5cf15c
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions MailKit/Net/Imap/ImapFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -805,26 +805,37 @@ static void QResyncFetch (ImapEngine engine, ImapCommand ic, int index)
{
CheckState (false, false);

var pattern = EncodedName.Length > 0 ? EncodedName + DirectorySeparator + "%" : "%";
var pattern = EncodedName.Length > 0 ? EncodedName + DirectorySeparator : string.Empty;
var command = subscribedOnly ? "LSUB" : "LIST";
var children = new List<IMailFolder> ();
var list = new List<ImapFolder> ();

var ic = new ImapCommand (Engine, cancellationToken, null, command + " \"\" %S\r\n", pattern);
var ic = new ImapCommand (Engine, cancellationToken, null, command + " \"\" %S\r\n", pattern + "%");
ic.RegisterUntaggedHandler (command, ImapUtils.ParseFolderList);
ic.UserData = list;

Engine.QueueCommand (ic);
Engine.Wait (ic);

foreach (var folder in list)
// Note: Some broken IMAP servers (*cough* SmarterMail 13.0 *cough*) return folders
// that are not children of the folder we requested, so we need to filter those
// folders out of the list we'll be returning to our caller.
//
// See https://github.com/jstedfast/MailKit/issues/149 for more details.
foreach (var folder in list) {
if (folder.FullName != pattern + folder.Name)
continue;

folder.ParentFolder = this;
children.Add (folder);
}

ProcessResponseCodes (ic, null);

if (ic.Result != ImapCommandResult.Ok)
throw ImapCommandException.Create (subscribedOnly ? "LSUB" : "LIST", ic);

return list;
return children;
}

/// <summary>
Expand Down

0 comments on commit b5cf15c

Please sign in to comment.