[issue28934] _mboxMMDF#get_message should delegate to get_bytes

2016-12-10 Thread bpoaugust

New submission from bpoaugust:

At present both _mboxMMDF#get_message and get_bytes read the file directly.

However the code in get_bytes duplicates some of the code in get_message. 
get_message should be recoded to use get_bytes.

It would then be possible to override get_bytes (which is also used by 
get_string) in order to transform the input stream e.g. to unmangle '>From ' 
lines.

But in any case it makes sense to reuse the code - DRY

--
components: email
messages: 282863
nosy: barry, bpoaugust, r.david.murray
priority: normal
severity: normal
status: open
title: _mboxMMDF#get_message should delegate to get_bytes
type: enhancement

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28934>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28934] _mboxMMDF#get_message should delegate to get_bytes

2016-12-10 Thread bpoaugust

bpoaugust added the comment:

On further investigation it sppears that overriding the get_bytes function does 
not help with unmangling >From.
However it would still be worth re-using the code.

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28934>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue795081] email.Message param parsing problem II

2016-12-12 Thread bpoaugust

bpoaugust added the comment:

Rather that change unquote to deal with such malformed input, why not just 
enhance get/set boundary? That would reduce the impact of any changes.

Also it should be easier to detect trailing rubbish in the value if you know it 
is a boundary value.

--
nosy: +bpoaugust

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue795081>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28945] get_boundary invokes unquote twice

2016-12-12 Thread bpoaugust

New submission from bpoaugust:

get_boundary calls get_param('boundary') which unquotes the value.
It then calls utils.collapse_rfc2231_value which also calls unquote.

This causes problems for boundaries that have two sets of quotes.
For example, I have seen the following in the wild:

Content-Type: multipart/mixed; boundary="<<001-3e1dcd5a-119e>>"

Both "" and <> are treated as quotes by unquote.

The result is that both "< and >" are stripped off.
This means that the boundaries no longer match.

--
components: email
messages: 282991
nosy: barry, bpoaugust, r.david.murray
priority: normal
severity: normal
status: open
title: get_boundary invokes unquote twice
type: behavior
versions: Python 3.4, Python 3.5

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28945>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29053] Implement >From_ decoding on input from mbox

2016-12-29 Thread bpoaugust

Changes by bpoaugust <sebbaz+...@gmail.com>:


--
versions: +Python 3.5 -Python 3.7

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29053>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28945] get_boundary (and get_filename) invokes unquote twice

2016-12-29 Thread bpoaugust

bpoaugust added the comment:

This is actually a bug in collapse_rfc2231_value: issue29020

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28945>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29020] collapse_rfc2231_value has inconsistent unquoting

2016-12-29 Thread bpoaugust

bpoaugust added the comment:

I have just checked and AFAICT collapse_rfc2231_value is only called by 
get_filename and get_boundary in message.py.

Both of these call get_param and default to unquote=True.

So in all cases the parameter value passed to collapse_rfc2231_value will 
already have been unquoted. Calling unquote again is a bug.

The obvious fix is to remove the calls to unquote from collapse_rfc2231_value.

This will also fix issue28945.

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29020>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29053] Implement >From_ decoding on input from mbox

2017-01-02 Thread bpoaugust

bpoaugust added the comment:

The patch can be simplified by just looking for b'\n' in the last 6 chars, and 
caching from b'\n' if found.

This would mean more file seeking in exchange for less buffer matching.

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29053>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29020] collapse_rfc2231_value has inconsistent unquoting

2017-01-02 Thread bpoaugust

bpoaugust added the comment:

If there are concerns about 3rd party code relying on the current behaviour of 
the function, then just create a new function without the unquoting, and 
deprecate the original function.

The existing function does not always unquote, so any code which relies on it 
is liable to break.

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29020>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28945] get_boundary (and get_filename) invokes unquote twice

2017-01-02 Thread bpoaugust

bpoaugust added the comment:

The patch is incomplete.

There is another unquote call:

336 return unquote(text)

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28945>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28945] get_boundary invokes unquote twice

2016-12-20 Thread bpoaugust

bpoaugust added the comment:

It looks like a simpler alternative is to just change

boundary = self.get_param('boundary', missing)
to
boundary = self.get_param('boundary', missing, unquote=False)

and let collapse_rfc2231_value do the unquoting

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28945>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28945] get_boundary invokes unquote twice

2016-12-20 Thread bpoaugust

bpoaugust added the comment:

According to RFC822, a quoted-string should only be wrapped in double-quotes. 

So I'm not sure why unquote treats <> as quotes. If it did not, then again this 
issue would not arise.

However maybe utils.unquote is needed by other code that uses <>, so it cannot 
just be updated without further analysis.

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28945>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29053] Implement >From_ decoding on input from mbox

2016-12-23 Thread bpoaugust

New submission from bpoaugust:

The email package implements mboxo From_ mangling on output by default.

However there is no provision to unmangle >From_ on input.

This means that it's not possible to import mboxo files correctly.

--
components: email
messages: 283879
nosy: barry, bpoaugust, r.david.murray
priority: normal
severity: normal
status: open
title: Implement >From_ decoding on input from mbox
type: behavior

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29053>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29053] Implement >From_ decoding on input from mbox

2016-12-23 Thread bpoaugust

bpoaugust added the comment:

Is there any way to override the current behaviour?

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29053>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29053] Implement >From_ decoding on input from mbox

2016-12-23 Thread bpoaugust

bpoaugust added the comment:

Attached please find patch which works for me.

To use it independently of email, do something like:

messages = mailbox.mbox(filename, MboxoFactory)

where:

class MboxoFactory(mailbox.mboxMessage):
def __init__(self, message=None):
super().__init__(message=MboxoReader(message))

HTH

--
Added file: http://bugs.python.org/file46017/mboxo_patch.py

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29053>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29020] collapse_rfc2231_value has inconsistent unquoting

2016-12-24 Thread bpoaugust

bpoaugust added the comment:

Another case is get_filename.

The second call to unquote will only change the incoming parameter if the 
original value was enclosed in <> or "". This is not a common scenario, and was 
only discovered because a mailer used the form <<>> as a boundary marker 
(yes, this is invalid). So existing tests are unlikely to notice any difference.

Note that it is wrong to unquote more times than the original value has been 
quoted. So the only possible reason for keeping unquote in the function is if 
unquote has not already been called on a quoted value. (It is not possible to 
tell from the parameter whether or not it is currently quoted).

The two sample callers are get_boundary and get_filename.
Both pass the value already unquoted.

This method should be fixed to remove the unquote calls.
If there is a caller (is there one?) that does not unquote the value first, 
then that needs to be fixed as well.

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29020>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28945] get_boundary (and get_filename) invokes unquote twice

2016-12-22 Thread bpoaugust

bpoaugust added the comment:

I have just discovered the same problem with get_filename.
Not surprising as its code is basically the same as get_boundary.

Unix paths can contain anything, so it's not correct to remove special 
characters. [It's up to the receiving file system to decide how to deal with 
chars that are not valid for it; the original name must be passed unchanged]

If the quoting/unquoting is fixed for filenames, then it should be OK for the 
boundary as well.

I think collapse_rfc2231_value should assume that any unquoting has already 
been done, and should therefore not call utils.unquote at all.

The get_param() method by default unquotes both single strings and encoded 
triplets, so it's certainly the case that get_boundary and get_filename will 
pass an unquoted value to rfc2231, as will any other caller that calls 
get_param with the default parameters.

--
title: get_boundary invokes unquote twice -> get_boundary (and get_filename) 
invokes unquote twice

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28945>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28945] get_boundary (and get_filename) invokes unquote twice

2016-12-22 Thread bpoaugust

bpoaugust added the comment:

Note: it's easy to create test e-mails with attachments using mutt.

echo test | mutt -s "test" -a files... -- user@domain

I did some testing with the following names:

<>
><
""
""
<"abc">
>abc<
">abc<"
>"abc"<

There are no doubt other awkward names one can devise; in particular it would 
be useful to generate similar names with non-ASCII characters in them to force 
the use of value triples.

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28945>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29020] collapse_rfc2231_value has inconsistent unquoting

2016-12-19 Thread bpoaugust

New submission from bpoaugust:

collapse_rfc2231_value unquotes the value before returning it except here:

rawbytes = bytes(text, 'raw-unicode-escape')
return str(rawbytes, charset, errors)

Why is the text not unquoted in this case?

Actually I wonder whether the function should do any unquoting at all.
There is at least one case where it is called with an already unquoted value 
(get_boundary, see issue28945).

But if it is intended to do unquoting, it should be consistent.

--
components: email
messages: 283658
nosy: barry, bpoaugust, r.david.murray
priority: normal
severity: normal
status: open
title: collapse_rfc2231_value has inconsistent unquoting
versions: Python 3.5

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29020>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29020] collapse_rfc2231_value has inconsistent unquoting

2016-12-19 Thread bpoaugust

Changes by bpoaugust <sebbaz+...@gmail.com>:


--
type:  -> behavior

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29020>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28945] get_boundary invokes unquote twice

2016-12-19 Thread bpoaugust

bpoaugust added the comment:

I agree that strictly speaking the boundary is invalid.
However:
'Be strict in what you generate, be liberal in what you accept'
The mail package should never create such boundaries.
However it should process them if possible.

If the boundary definition is mangled by stripping out all the invalid 
characters, then it won't match the markers. So it won't solve the issue.

Whereas ensuring that only a single level of quotes is removed does fix the 
issue.

This is what works for me:

def get_boundary(self, failobj=None):
missing = object()
# get_param removes the outer quotes
boundary = self.get_param('boundary', missing)
if boundary is missing:
return failobj
# Don't unquote again in collapse_rfc2231_value
if not isinstance(boundary, tuple) or len(boundary) != 3:
return boundary
# RFC 2046 says that boundaries may begin but not end in w/s
return utils.collapse_rfc2231_value(boundary).rstrip()

I think the bug is actually in collapse_rfc2231_value - that should not do any 
unquoting, as the value will be passed to it already unquoted (at least in this 
case). However there might perhaps be some cases where collapse_rfc2231_value 
is called with a quoted value, so to fix the immediate problem it's safer to 
fix get_boundary. (I could have re-quoted the value instead, and let 
collapse_rfc2231_value do its thing.)

unquote is correct as it stands - it should only remove the outer quotes. There 
may be a need to quote strings that just happen to be enclosed in quote chars.

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28945>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31524] mailbox._mboxMMDF.get_message throws away From envelope

2017-09-19 Thread bpoaugust

bpoaugust added the comment:

I believe that setting the file back to the start is probably the best solution.

The message as provided by e.g. postfix will include the From header and the 
parser is able to deal with that successfully, so I'm not sure why the mbox 
reader removes it before calling the parser. It only really needs to drop the 
trailing newline to ensure that the parser gets the same data.

--

___
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31524>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31522] mailbox._mboxMMDF.get_message throws away From envelope

2017-09-19 Thread bpoaugust

bpoaugust added the comment:

https://github.com/python/cpython/blob/master/Lib/mailbox.py#L778

The code here reads the first line, but fails to save it as the unixfrom line.

Alternatively perhaps it should reset the file back to the start so the message 
factory has sight of the envelope.

The end result is that the envelope is lost.

--
title: _mboxMMDF.get_string() fails to pass param to get_bytes() -> 
mailbox._mboxMMDF.get_message throws away From envelope

___
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31522>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31522] _mboxMMDF.get_string() fails to pass param to get_bytes()

2017-09-19 Thread bpoaugust

Changes by bpoaugust <sebbaz+...@gmail.com>:


--
title: mailbox._mboxMMDF.get_message throws away From envelope -> 
_mboxMMDF.get_string() fails to pass param to get_bytes()

___
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31522>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31524] mailbox._mboxMMDF.get_message throws away From envelope

2017-09-19 Thread bpoaugust

New submission from bpoaugust:

https://github.com/python/cpython/blob/master/Lib/mailbox.py#L778

The code here reads the first line, but fails to save it as the unixfrom line.

Alternatively perhaps it should reset the file back to the start so the message 
factory has sight of the envelope.

The end result is that the envelope is lost.

--
components: email
messages: 302570
nosy: barry, bpoaugust, r.david.murray
priority: normal
severity: normal
status: open
title: mailbox._mboxMMDF.get_message throws away From envelope
type: behavior
versions: Python 3.5, Python 3.6, Python 3.7

___
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31524>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31524] mailbox._mboxMMDF.get_message throws away From envelope

2017-09-19 Thread bpoaugust

bpoaugust added the comment:

It is not saving the unix from line.

#!/usr/bin/env python3

with open("test.mbox",'w') as f:
f.write("From sender@invalid Thu Nov 17 00:49:30 2016\n")
f.write("Subject: Test\n")
f.write("\n")
f.write("\n")

import mailbox
messages = mailbox.mbox("test.mbox")
for msg in messages:
print(msg.get('subject'))
print(msg.get_from())
print(msg.get_unixfrom())

--

___
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31524>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31522] _mboxMMDF.get_string() fails to pass param to get_bytes()

2017-09-19 Thread bpoaugust

New submission from bpoaugust:

See:
https://github.com/python/cpython/blob/master/Lib/mailbox.py#L787

The code should be

self.get_bytes(key, from_)).as_string(unixfrom=from_)

--
components: email
messages: 302564
nosy: barry, bpoaugust, r.david.murray
priority: normal
severity: normal
status: open
title: _mboxMMDF.get_string() fails to pass param to get_bytes()
type: behavior
versions: Python 3.5, Python 3.6, Python 3.7

___
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31522>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31522] _mboxMMDF.get_string() fails to pass param to get_bytes()

2017-09-19 Thread bpoaugust

bpoaugust added the comment:

Ignore msg302569 - that was supposed to be a new issue.

--

___
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31522>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31538] mailbox does not treat external factories the same

2017-09-20 Thread bpoaugust

New submission from bpoaugust:

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:


Test
sender@invalid Thu Nov 17 00:49:30 2016
None

Test
MAILER-DAEMON Thu Sep 21 01:31:15 2017
None

Note that the original from has been lost in the second parse.

--
components: email
files: mb.py
messages: 302667
nosy: barry, bpoaugust, r.david.murray
priority: normal
severity: normal
status: open
title: mailbox does not treat external factories the same
type: behavior
versions: Python 3.5, Python 3.6, Python 3.7
Added file: https://bugs.python.org/file47159/mb.py

___
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31538>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45910] mailbox should support options for calling email parser

2021-11-27 Thread bpoaugust


New submission from bpoaugust :

It looks like mailbox uses email.message_from_... for parsing emails.

However it does not allow for passing any options to the parser.

In particular the policy cannot be provided.

It would be useful if there was a way to pass such options.

--
components: email
messages: 407154
nosy: barry, bpoaugust, r.david.murray
priority: normal
severity: normal
status: open
title: mailbox should support options for calling email parser

___
Python tracker 
<https://bugs.python.org/issue45910>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46392] MessageIDHeader is too strict for message-id

2022-01-15 Thread bpoaugust


New submission from bpoaugust :

The email headerregistry class MessageIDHeader is too strict when parsing 
existing Message-Ids. It can truncate Message-Ids that are valid according to 
the obsolete rules.

As the saying has it: 
"Be liberal in what you accept, and conservative in what you send."

I think the parser should be much closer to the UnstructuredHeader.

--
components: email
messages: 410665
nosy: barry, bpoaugust, r.david.murray
priority: normal
severity: normal
status: open
title: MessageIDHeader is too strict for message-id

___
Python tracker 
<https://bugs.python.org/issue46392>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46392] MessageIDHeader is too strict for message-id

2022-01-16 Thread bpoaugust


bpoaugust  added the comment:

The easiest might be for me to provide some test cases, but I have not been 
able to work out where the existing unit tests are.

One failure which I believe should be permitted under current rules is:

 - i.e. trailing space
The space gets added AFTER the >

However the following is parsed correctly:

 - i.e. trailing space but with previous comment

The obsolete rules I referred to are here:
https://datatracker.ietf.org/doc/html/rfc5322#section-4

--

___
Python tracker 
<https://bugs.python.org/issue46392>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46392] MessageIDHeader is too strict for message-id

2022-01-18 Thread bpoaugust


bpoaugust  added the comment:

When the library is being used to parse existing emails, I think it needs to do 
the minimum validation and canonicalisation.

It may be useful in some circumstances to report where the input is not 
syntactically correct, but I'm not sure it is helpful to truncate the input at 
the first syntax error.

When the library is used to generate emails, validation should be very strict.

--

___
Python tracker 
<https://bugs.python.org/issue46392>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46392] MessageIDHeader is too strict for message-id

2022-01-18 Thread bpoaugust


bpoaugust  added the comment:

I think an id of the form



should be allowed, but it generates

 obs-id-left => local-part => obs-local-part => word *("." word)
word => atom => [CFWS] 1*atext [CFWS]

'' should also be allowed but generates ' (A A)'
and '' gives ' '

--

___
Python tracker 
<https://bugs.python.org/issue46392>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46392] MessageIDHeader is too strict for message-id

2022-01-18 Thread bpoaugust


bpoaugust  added the comment:

Sorry, I think '' is not valid, as spaces are not allowed between 
words.

However I am not seeing the original unfolded source if there is an error, 
unless I am misunderstanding the API.

For example:

--- cut here ---
import email.header
import email.utils
import email.policy

def test(test):
msg_string = f"Message-id: {test}"
message = email.message_from_string(msg_string, policy=email.policy.default)
out = message['Message-id']
print(test)
print(out)

test('') # invalid
test('') # valid
--- cut here ---

This produces:


 # truncated at error



i.e. the invalid input is truncated

--

___
Python tracker 
<https://bugs.python.org/issue46392>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46435] MessageID parser can crash with IndexError: string index out of range

2022-01-19 Thread bpoaugust


New submission from bpoaugust :

The Message-ID parser can crash on truncated input.

For example:

import email.policy
message=email.message_from_string("Message-id: 
message['Message-id']
  File 
"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/email/message.py",
 line 391, in __getitem__
return self.get(name)
  File 
"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/email/message.py",
 line 471, in get
return self.policy.header_fetch_parse(k, v)
  File 
"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/email/policy.py",
 line 163, in header_fetch_parse
return self.header_factory(name, value)
  File 
"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/email/headerregistry.py",
 line 604, in __call__
return self[name](name, value)
  File 
"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/email/headerregistry.py",
 line 192, in __new__
cls.parse(value, kwds)
  File 
"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/email/headerregistry.py",
 line 532, in parse
kwds['parse_tree'] = parse_tree = cls.value_parser(value)
  File 
"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/email/_header_value_parser.py",
 line 2126, in parse_message_id
token, value = get_msg_id(value)
  File 
"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/email/_header_value_parser.py",
 line 2101, in get_msg_id
token, value = get_domain(value)
  File 
"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/email/_header_value_parser.py",
 line 1604, in get_domain
if value[0] in CFWS_LEADER:
IndexError: string index out of range

--
components: email
messages: 410972
nosy: barry, bpoaugust, r.david.murray
priority: normal
severity: normal
status: open
title: MessageID parser can crash with IndexError: string index out of range
type: crash

___
Python tracker 
<https://bugs.python.org/issue46435>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10197] subprocess.getoutput fails on win32

2011-10-17 Thread bpoaugust

bpoaugust sebbaz+...@gmail.com added the comment:

subprocess.getoutput does not currently work at all on Windows.
So it's not necessary to maintain backwards compatibility.

The following fix works for me on WinXP/Python 3.2.2.

Replace

pipe = os.popen('{ ' + cmd + '; } 21', 'r') # line 613 of subprocess.py

with

if mswindows:
pipe = os.popen(cmd + ' 21', 'r') # Windows does not support { }
else:
pipe = os.popen('{ ' + cmd + '; } 21', 'r')

--
nosy: +bpoaugust
versions: +Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10197
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10197] subprocess.getoutput fails on win32

2011-10-17 Thread bpoaugust

bpoaugust sebbaz+...@gmail.com added the comment:

A better fix, which supports multiple windows commands:

if mswindows:
pipe = os.popen('( ' + cmd + ' ) 21', 'r') # Windows uses () rather 
than { }
else:
pipe = os.popen('{ ' + cmd + '; } 21', 'r')

This works with the command

subprocess.getoutput(echo before  python -V  echo after)

Note that python -V writes to stderr, so without the enclosing ( ) the version 
information is not captured.

--
Added file: http://bugs.python.org/file23433/subprocess.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10197
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10197] subprocess.getoutput fails on win32

2011-10-17 Thread bpoaugust

Changes by bpoaugust sebbaz+...@gmail.com:


--
versions:  -Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10197
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10197] subprocess.getoutput fails on win32

2011-10-18 Thread bpoaugust

bpoaugust sebbaz+...@gmail.com added the comment:

I got the () syntax from:

http://technet.microsoft.com/en-us/library/cc737438%28WS.10%29.aspx

which refers to grouping, not subshell.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10197
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com