Domanda

I'm playing around with SMTP and using email.mime to provide the header structure. For some reason when a try to add a header that exceeds a certain length a line break is added into my header line.

e.g.

from email.mime.text import MIMEText
message = 'some message'
msg = MIMEText(message)
msg.add_header('some header', 'just wondering why this sentence is continually cut in half for a reason I can not find')

print msg['some header']
print msg

print msg['some header'] prints:-

some header: just wondering just wondering why this sentence is continually cut in half for a reason I can not find

print msg prints:-

some header: just wondering why this sentence is continually cut in half for a
 reason I can not find

One thing I did discover is that the length at which it's cut off is a combination of the header title and its value. So when I shorted 'some header' to 'some', the line return changes to after 'reason' instead of before.

It's not just my viewing page width :), it actually sends the email with the new line character in the email header.

Any thoughts?

È stato utile?

Soluzione

This is correct behaviour, and it's the email package that does this (as well as most of the email generating code out there.) RFC822 messages (and all successors to that standard) have a way of continuing headers so they don't have to be a single line. It's considered good practice to fold headers like that, and the tab character that indents the rest of the header's body means the header is continued.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top