email package and line ending

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Manlio Perillo

    #1

    email package and line ending

    Regards.

    The problem is this code:
    [color=blue][color=green][color=darkred]
    >>> import email.Message
    >>> msg = email.Message.M essage()
    >>> msg["subject"] = "email bug"
    >>> msg["from"] = "Manlio Perillo"
    >>> print repr(msg.as_str ing())[/color][/color][/color]
    'subject: email bug\nfrom: Manlio Perillo\n\n'


    Why line ending is '\n' and not '\r\n' ?
    RFC 2822 says that the delimiter must(?) be '\r\n'.

    The same problem is presente in email.Generator and email.Header (for
    multiline headers).


    P.S.
    email.Header has a bug:

    this code causes an infinite recursion:
    [color=blue][color=green][color=darkred]
    >>> from email.Header import Header
    >>> h = Header('multili ne header', 'iso-8859-1', maxlinelen=4)
    >>> e.encode()[/color][/color][/color]




    Manlio Perillo
  • Tim Roberts

    #2
    Re: email package and line ending

    Manlio Perillo <manlio_perillo NO@SPAMlibero.i t> wrote:[color=blue]
    >
    >The problem is this code:
    >[color=green][color=darkred]
    > >>> import email.Message
    > >>> msg = email.Message.M essage()
    > >>> msg["subject"] = "email bug"
    > >>> msg["from"] = "Manlio Perillo"
    > >>> print repr(msg.as_str ing())[/color][/color]
    >'subject: email bug\nfrom: Manlio Perillo\n\n'
    >
    >Why line ending is '\n' and not '\r\n' ?
    >RFC 2822 says that the delimiter must(?) be '\r\n'.[/color]

    Because all you have there is a string. It doesn't have anything to do
    with RFC 2822. \n is probably the safest cross-platform way to represent a
    newline in a Python string.

    Note that smtplib, which DOES have to worry abouot RFC 2822 compliance,
    will replace all standalone \r and \n characters with \r\n.
    [color=blue]
    >email.Header has a bug:
    >
    >this code causes an infinite recursion:
    >[color=green][color=darkred]
    > >>> from email.Header import Header
    > >>> h = Header('multili ne header', 'iso-8859-1', maxlinelen=4)
    > >>> e.encode()[/color][/color][/color]

    I'm not sure I would call that a bug. I'd call that a usage error; you've
    asked it to accomplish something that cannot be done. However, it is true
    that _split has enough information to diagnose this.
    --
    - Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.

    Comment

    Working...