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
mailbox.Maildir doesn't create subdir structure when create=True and base dir exists #74274
Comments
Hi, I've faced an issue w/
Expected result: subdirs are created during **Actual result:** subdirs are assumed as existing which leads to exceptions during use. Workaround: remove the actual dir before passing the path to **Fix:** PR linked. Basically it adds creation of subdirs regardless of whether the base dir existed before. |
I think this patch make the behavior changed. Documentation wrote that: "If create is True, the mailbox is created if it does not exist.", the current version did that exactly, it won't create subdir (tmp, new, and cur) when dir exists. The situation face here is that TemporaryDirectory() create a valid dir without Maildir structure subdir (tmp, new, and cur), and the Not sure if this behavior change is worth or not. I'll also upload an PoC for this. |
Just create a subdirectory inside the tempdir to hold your Maildir folder. I think it is not worth complicating the API for this use case, since it does have a simple solution. |
I concur with David. Rather than using a temporary directory as a Maildir folder: with tempfile.TemporaryDirectory() as tmpdir:
with mailbox.Maildir(tmpdir, create=True) as box:
... create a Maildir folder in a temporary directory: with tempfile.TemporaryDirectory() as tmpdir:
with mailbox.Maildir(os.path.join(tmpdir, 'mail'), create=True) as box:
... |
Yeah, I came up with the same solution. It just seems weird to me. The doc says "If create is True, the mailbox is created if it does not exist.". So it operates the term mailbox, not a folder. I would assume that a valid mailbox [1] is the whole **valid** directory structure with subfolders. If the corresponding subdirs are missing the folder should not be considered as a valid maildir, right? Given above, I think the documentation doesn't clearly promise the same behavior that the code does. Shouldn't this be fixed? (Either docs, or code) |
Right. Which is why you get an error if you try to use an empty directory as if it was a maildir :) create=True creates the *directory* and initializes it. That seems clear to me, and exactly what I would expect. "The mailbox" is the directory. If it already exists, it should be a Maildir folder. I wouldn't want a program messing with an existing directory if it was invalid...it might trash my data :) I don't think even a doc change is needed here, but if you want to propose something we can evaluate it. |
Hi, I've tried clarifying this in docs as suggested @ #1163 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: