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

bug with ill-formed rfc822 attachments #39341

Closed
customdesigned mannequin opened this issue Oct 1, 2003 · 5 comments
Closed

bug with ill-formed rfc822 attachments #39341

customdesigned mannequin opened this issue Oct 1, 2003 · 5 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@customdesigned
Copy link
Mannequin

customdesigned mannequin commented Oct 1, 2003

BPO 815563
Nosy @warsaw
Files
  • fail: example of a failing message
  • 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:

    assignee = None
    closed_at = <Date 2007-03-30.14:50:12.000>
    created_at = <Date 2003-10-01.02:32:02.000>
    labels = ['type-feature', 'library']
    title = 'bug with ill-formed rfc822 attachments'
    updated_at = <Date 2007-03-30.14:50:12.000>
    user = 'https://bugs.python.org/customdesigned'

    bugs.python.org fields:

    activity = <Date 2007-03-30.14:50:12.000>
    actor = 'collinwinter'
    assignee = 'none'
    closed = True
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2003-10-01.02:32:02.000>
    creator = 'customdesigned'
    dependencies = []
    files = ['8233']
    hgrepos = []
    issue_num = 815563
    keywords = []
    message_count = 5.0
    messages = ['54024', '54025', '54026', '54027', '54028']
    nosy_count = 3.0
    nosy_names = ['barry', 'collinwinter', 'customdesigned']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue815563'
    versions = []

    @customdesigned
    Copy link
    Mannequin Author

    customdesigned mannequin commented Oct 1, 2003

    The following proglet gets an except with the attached
    message:
    -----te.py--------

    import email
    import sys
    
    msg = email.message_from_file(sys.stdin)
    sys.stdout.write(msg.as_string())

    python2 te.py <failingmsg
    Traceback (most recent call last):
      File "te.py", line 4, in ?
        msg = email.message_from_file(sys.stdin)
      File "/usr/lib/python2.2/email/__init__.py", line 63,
    in message_from_file
        return Parser(_class, strict=strict).parse(fp)
      File "/usr/lib/python2.2/email/Parser.py", line 64,
    in parse
        self._parsebody(root, fp, firstbodyline)
      File "/usr/lib/python2.2/email/Parser.py", line 239,
    in _parsebody
        msgobj = self.parsestr(part)
      File "/usr/lib/python2.2/email/Parser.py", line 75,
    in parsestr
        return self.parse(StringIO(text),
    headersonly=headersonly)
      File "/usr/lib/python2.2/email/Parser.py", line 64,
    in parse
        self._parsebody(root, fp, firstbodyline)
      File "/usr/lib/python2.2/email/Parser.py", line 264,
    in _parsebody
        msg = self.parse(fp)
      File "/usr/lib/python2.2/email/Parser.py", line 64,
    in parse
        self._parsebody(root, fp, firstbodyline)
      File "/usr/lib/python2.2/email/Parser.py", line 205,
    in _parsebody
        raise Errors.BoundaryError(
    email.Errors.BoundaryError: No terminating boundary and
    no trailing empty line

    The message/rfc822 attachment really is missing the
    boundary. However, that is why it is being returned as
    an attachment in the first place! Is it illegal for
    message/rfc822 attachments to have invalid MIME
    construction?

    I suggest that a message attachment that fails MIME
    boundary decoding, should become a plain rfc822 object,
    or perhaps a text object. I don't know.

    Anyway, I get tons of messages with this property that
    have to be processed by my Python milter.

    @customdesigned customdesigned mannequin closed this as completed Oct 1, 2003
    @customdesigned customdesigned mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Oct 1, 2003
    @customdesigned customdesigned mannequin closed this as completed Oct 1, 2003
    @customdesigned customdesigned mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Oct 1, 2003
    @warsaw
    Copy link
    Member

    warsaw commented Nov 21, 2003

    Logged In: YES
    user_id=12800

    I'm moving this to a feature request for Python 2.4.
    There's little that we can do about this in Python 2.3 since
    the lax parser is only so good at guessing the intent of
    ill-formed messages. email 2.x can't do what you suggest
    because that would be a new feature and can't be introduced
    into Python 2.3. The email-sig is chartered with developing
    an improved parser for Python 2.4 that might be able to
    handle this.

    In the meantime, you could probably derive your own Parser
    class that might be able to worm around this problem in an
    application specific way.

    @customdesigned
    Copy link
    Mannequin Author

    customdesigned mannequin commented Nov 21, 2003

    Logged In: YES
    user_id=142072

    Your disposition makes sense.

    Since all messages with invalid MIME boundaries are either
    invalid themselves, or bounces or forwards of invalid
    messages, my work around is to issue an SMTP reject:

          if exc_type == email.Errors.BoundaryError:
            self.setreply('554','5.7.7',
                    'Boundary error in your message, are you a
    spammer?')

    For 2.4, I recommend that rfc822 attachments be parsed
    independently of the enclosing message. If the attachment
    is invalid, turn it into a plain rfc822 message object or a
    string.

    Although the rfc822 module is deprecated, I find it very
    useful to represent mail that may or may not correctly
    follow MIME standards. Examples include forwarded spam
    (using the new innoculation RFC), and generic mailbox
    processing. I suggest retaining rfc822 as a 'featureless'
    message with only headers and body.

    @warsaw
    Copy link
    Member

    warsaw commented Nov 21, 2003

    Logged In: YES
    user_id=12800

    Note that if you're looking for something that just parses
    messages into headers and bodies, you might look at the
    HeaderParser class. You'd have to write a bit of code to
    get an outer parser that falls back to a HeaderParser on
    invalid unparseable inner messages.

    @collinwinter
    Copy link
    Mannequin

    collinwinter mannequin commented Mar 30, 2007

    I don't see any exception as of Python 2.5. Closing as "fixed".

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant