This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: mailbox does not treat external factories the same
Type: behavior Stage: patch review
Components: email Versions: Python 3.11, Python 3.10
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Cryvate, barry, bpoaugust, cryvate, r.david.murray
Priority: normal Keywords: patch

Created on 2017-09-21 01:37 by bpoaugust, last changed 2022-04-11 14:58 by admin.

File name Uploaded Description Edit bpoaugust, 2017-09-21 01:37 Show external factory is treated differently
Pull Requests
URL Status Linked Edit
PR 26776 open Cryvate, 2021-06-17 19:43
Messages (2)
msg302667 - (view) Author: (bpoaugust) Date: 2017-09-21 01:37
The default mailbox factory is mailbox.mboxMessage so I expect the following two statements to work the same:

messages = mailbox.mbox("test.mbox")
messages = mailbox.mbox("test.mbox", mailbox.mboxMessage)

However they do not.

The attached file generates the output:

<class 'mailbox.mboxMessage'>
sender@invalid Thu Nov 17 00:49:30 2016
<class 'mailbox.mboxMessage'>
MAILER-DAEMON Thu Sep 21 01:31:15 2017

Note that the original from has been lost in the second parse.
msg302682 - (view) Author: Henk-Jaap Wagenaar (cryvate) * Date: 2017-09-21 10:41
To me the documentation doesn't quite look right, in the case of no factory being passed, it runs:

    def __getitem__(self, key):
        """Return the keyed message; raise KeyError if it doesn't exist."""
        if not self._factory:
            return self.get_message(key)
            return self._factory(self.get_file(key))

from the Mailbox base class. The get_message is thus:

    def get_message(self, key):
        """Return a Message representation or raise a KeyError."""
        start, stop = self._lookup(key)
        from_line = self._file.readline().replace(linesep, b'')
        string = - self._file.tell())
        msg = self._message_factory(string.replace(linesep, b'\n'))
        return msg

where self._message_factory is set to mailbox.mboxMessage.

I am not familiar with this module, so am unsure whether the documentation is ill-worded or it is a bug.
Date User Action Args
2022-04-11 14:58:52adminsetgithub: 75719
2021-06-17 19:43:45cryvatesetversions: + Python 3.10, Python 3.11, - Python 3.5, Python 3.6, Python 3.7
2021-06-17 19:43:21Cryvatesetkeywords: + patch
nosy: + Cryvate

pull_requests: + pull_request25362
stage: patch review
2017-09-21 10:41:29cryvatesetnosy: + cryvate
messages: + msg302682
2017-09-21 01:37:52bpoaugustcreate