473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

email bug?

Running the following with Python 2.2.2:

from email.Parser import Parser

txt = """Subject: IE is Evil
Content-Type: image/pjpeg; name="Jim&&Jill"

<html>
</html>
"""

msg = email.message_from_string(txt)
print msg.get_params()

I get:
[('image/pjpeg', ''), ('name', '"Jim&amp'), ('&amp', ''), ('Jill"', '')]

What IE apparently gets is:

[('image/pjpeg', ''), ('name', '"Jim&amp;&amp;Jill"')]

Is this a bug (in the email package, I mean - obviously IE is buggy)?

Do I have to write my own custom param parsing routines to handle this?

--
Stuart D. Gathman <st****@bmsi.com>
Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.
Jul 18 '05 #1
3 1610
Stuart D. Gathman:
Content-Type: image/pjpeg; name="Jim&amp;&amp;Jill" What IE apparently gets is:

[('image/pjpeg', ''), ('name', '"Jim&amp;&amp;Jill"')]

Is this a bug (in the email package, I mean - obviously IE is buggy)?

Do I have to write my own custom param parsing routines to handle this?


BTW, I verified this in 2.3.

Looks like the Content-Type syntax is defined in
http://www.faqs.org/rfcs/rfc2045.html
5.1. Syntax of the Content-Type Header Field

content := "Content-Type" ":" type "/" subtype
*(";" parameter)

parameter := attribute "=" value

value := token / quoted-string

token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
or tspecials>

tspecials := "(" / ")" / "<" / ">" / "@" /
"," / ";" / ":" / "\" / <">
"/" / "[" / "]" / "?" / "="
; Must be in quoted-string,
; to use within parameter values

So the ";" must be in a quoted string. That's defined in
RFC 822, http://www.faqs.org/rfcs/rfc822.html
(now obsolete)

quoted-string = <"> *(qtext/quoted-pair) <">

qtext = <any CHAR excepting <">, ; => may be folded
"\" & CR, and including
linear-white-space>

CHAR = <any ASCII character>

The ';' is in CHAR and is not "\" nor CR so it's in qtext,
so it's part of quoted-string, so it's allowed in a value
without extra interpretation.

I looks like 2822 (the updated version of 822) a
http://www.faqs.org/rfcs/rfc2822.html agrees.

So I think it's a bug in the email module's parser.

The actual bug is in email/Parser.py with

# Regular expression used to split header parameters. BAW: this may be too
# simple. It isn't strictly RFC 2045 (section 5.1) compliant, but it
catches
# most headers found in the wild. We may eventually need a full fledged
# parser eventually.
paramre = re.compile(r'\s*;\s*')

A quick scan of the code suggests that it isn't a quick fix (eg,
not just a matter of tweaking that regexp.

Could you file a bug report against it?

Andrew
da***@dalkescientific.com
Jul 18 '05 #2
On Sun, 24 Aug 2003 00:14:45 -0400, Andrew Dalke wrote:

A quick scan of the code suggests that it isn't a quick fix (eg, not
just a matter of tweaking that regexp.


Here is my quick (and probably incorrect) fix:

from email.Message import Message
from email.Utils import unquote

# helper to split params while ignoring ';' inside quotes
def _parseparam(str):
plist = []
while str[:1] == ';':
str = str[1:]
end = str.find(';')
while end > 0 and (str.count('"',0,end) & 1):
end = str.find(';',end + 1)
if end < 0: end = len(str)
f = str[:end]
if '=' in f:
i = f.index('=')
f = f[:i].strip().lower() + \
'=' + f[i+1:].strip()
plist.append(f.strip())
str = str[end:]
return plist

class MimeMessage(Message):

def getparam(self,name,header='content-type'):
for key,val in self.getparams(header):
if key == name: return unquote(val)
return None

# like get_params but obey quotes
def getparams(self,header='content-type'):
"Return all parameter names and values. Use parser that handles quotes."
val = self.get(header)
result = []
if val:
plist = _parseparam(';' + val)
for p in plist:
i = p.find('=')
if i >= 0: result.append((p[:i].lower(),unquote(p[i+1:])))
return result

--
Stuart D. Gathman <st****@bmsi.com>
Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.
Jul 18 '05 #3
Stuart D. Gathman:
Here is my quick (and probably incorrect) fix:


There's a test suite in email.tests. It includes tests for
getparams, and I see some commented out code which
lists a test known to fail.

You could use that to check the validity of your code.

Andrew
da***@dalkescientific.com
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Chuck Anderson | last post by:
Can anyone point me in the right direction? I want to use Php to automate confirmation of someone joining an email list by them replying to an email (so they don't have to have a browser?). I...
4
by: dmiller23462 | last post by:
So here's my problem.....I need to set up different email distributions based on which option in the following Select form has been chosen....For instance if "Putaway" is chosen it needs to email...
88
by: Mike | last post by:
Is there a way to determine what a user's default email client is? I read a post from 3 years ago that said no. I guess I'm hoping something has come along since then.
2
by: BSG-SMTP-Gateway | last post by:
The following message sent by this account has violated system policy: Connection From: 64.253.55.90 From: python-list@python.org To: terriss@birdsall.com, q4dzsAEAAAAA@birdsall.com,...
26
by: libsfan01 | last post by:
Hi all! Can anyone show me how to check and email field on a form for the existence of these two characters. Kind regards Marc
3
by: g0c | last post by:
hi, how to hide or replace email addresses in php mail function with something like "group" so the email addresses to which email is sent are not visible ? i have : $subs = "email1@dot.com,...
3
by: Erik Johnson | last post by:
THE GOAL: I need to send an email with a simple ASCII text body and an attached HTML file. I have scripts that send basic emails via the smtplib module that don't have any attachements and that...
15
by: Craig Hurley | last post by:
Hello, user@x.com receives an email from user@a.com. I want to forward that email to user@y.com. I want the contents/header to remain intact, with the exception of adding "X-Forwarded-For". ...
3
by: IGD | last post by:
I don't know if this is the right place to post this or not. If not, could someone direct me elsewhere where I would find more information on how to solve my problem? Thanks! My problem is this:...
27
matheussousuke
by: matheussousuke | last post by:
I'm having trouble with e-mail sending, I mean, the website is suposed to send a confirmation email after sign up, but it gets like text plain instead of HTML May someone help me, please? ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.