-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add a method to list subfolders of a MailFolder recursively #293
Conversation
|
||
private def listRecursive( | ||
folder: Folder, | ||
folderList: List[Folder] = Nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm… it seems the folder
is never added to the result? So "INBOX" doesn't belong to the result - or the parent folder? Then folderList
is unused, the method is not called with other than Nil
.
It would be nice, if it would be tail-recursive, wdyt? Probably not so important in practice, but I tend to prefer it in general as it is usually not harder to write/read, imho, and so we get stack safety from scala.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right about the folderList
parameter, I was a bit tired writing this, sorry.
Not including the parent folder is intended, maybe renaming to ListSubFolders
would be more appropriate?
How would someone transform this into a tail-recursive method? Maybe I just can't wrap my head around it, but it seems to be hard because it's a tree like structure - I'm open for ideas!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not including the parent folder is intended, maybe renaming to
ListSubFolders
would be more appropriate?
Ah ok - I looked at the example in the description, it seems to be included there. Maybe we can return a NonEmptyList
with the input folder as first element? The user can then decide whether to use it or not. I thought it may be convenient when returning the INBOX when giving a None
as input.
Regarding the recursive thing. I thought maybe something like this could work:
@annotation.tailrec
def flatten(folder: Vector[Folder], result: Vector[Folder] = Vector.empty): Vector[Folder] =
if (folder.isEmpty) result
else flatten(folder.flatMap(_.list().tovector), folder ++ result)
// flatten(Vector(parent))
(modulo all the syntax errors) But I may just miss something here! can totally relate to the tiredness:) then just leave it - it's not important anyways.
f948d31
to
4287d92
Compare
We've converted our method to be tail recursive now. |
Ah yes, that is true! I would be ok with not adding it in the |
Hey @Moerfi666 if you want to rather remove the input folder from the results, I'm totally fine with that. I'm also fine with current state, let me know what you think/want to do. No need to hurry, just wanting to let you know … |
Hey! Sorry for the long delay. Conceptually, we thought about the method more as a way to get the subfolders within a given path. |
Also as discussed on Matrix with @seijikun,
here the PR that adds an implementation for recursive folder listing.
This takes an optional parent folder, and returns all folders and subfolders in the hierarchy as flattened list.
So a hierarchy:
becomes this flattened sequential list:
Normally, IMAP supports this operation directly (
O(1)
), butJavaMail
does not seem to provide this functionality, forcing one to traverse the hierarchy manually.