Commit Graph

49 Commits

Author SHA1 Message Date
R David Murray fdb23c2fe5 #20098: add mangle_from_ policy option.
This defaults to True in the compat32 policy for backward compatibility,
but to False for all new policies.

Patch by Milan Oberkirch, with a few tweaks.
2015-05-17 14:24:33 -04:00
R David Murray e25244657c #21300: Clean up the docs for the email "policy" arguments. 2014-05-06 21:33:18 -04:00
Victor Stinner 7fa767e517 Issue #20976: pyflakes: Remove unused imports 2014-03-20 09:16:38 +01:00
R David Murray e9c31470e1 #14983: always add a line end after a MIME boundary marker.
This is more RFC compliant (see issue) and fixes a problem with
signature verifiers rejecting the part when signed.  There is some
amount of backward compatibility concern here since it changes
the output, but the RFC issue coupled with fixing the problem
with signature verifiers seems worth the small risk of breaking
code that depends on the current incorrect output.
2014-02-08 17:54:56 -05:00
R David Murray 905c8c3d8d #19772: Do not mutate message when downcoding to 7bit.
This is a bit of an ugly hack because of the way generator pieces together the
output message.  The deepcopys aren't too expensive, though, because we know it
is only called on messages that are not multiparts, and the payload (the thing
that could be large) is an immutable object.

Test and preliminary work on patch by Vajrasky Kok.
2014-02-08 11:48:20 -05:00
Ezio Melotti 2af76da7b4 Fix a couple of typos. 2013-08-10 18:47:07 +03:00
R David Murray 965794ed58 Merge: PEP8 fixup on previous patch, remove unused imports in test_email. 2013-03-07 18:16:47 -05:00
R David Murray b9534f4ed5 PEP8 fixup on previous patch, remove unused import in test_email. 2013-03-07 18:15:13 -05:00
R David Murray addb0be63e Merge: #14645: Generator now emits correct linesep for all parts.
Previously the parts of the message retained whatever linesep they had on
read, which means if the messages weren't read in univeral newline mode, the
line endings could well be inconsistent.  In general sending it via smtplib
would result in them getting fixed, but it is better to generate them
correctly to begin with.  Also, the new send_message method of smtplib does
not do the fixup, so that method is producing rfc-invalid output without this
fix.
2013-03-07 16:43:58 -05:00
R David Murray e67c6c545b #14645: Generator now emits correct linesep for all parts.
Previously the parts of the message retained whatever linesep they had on
read, which means if the messages weren't read in univeral newline mode, the
line endings could well be inconsistent.  In general sending it via smtplib
would result in them getting fixed, but it is better to generate them
correctly to begin with.  Also, the new send_message method of smtplib does
not do the fixup, so that method is producing rfc-invalid output without this
fix.
2013-03-07 16:38:03 -05:00
R David Murray 6cb1d67eb3 Merge: #16564: Fix regression in use of encoders.encode_noop with binary data. 2013-02-09 13:10:54 -05:00
R David Murray ceaa8b1d75 #16564: Fix regression in use of encoders.encode_noop with binary data. 2013-02-09 13:02:58 -05:00
R David Murray ad2a7d528a Merge #15249: Mangle From lines correctly when body contains invalid bytes.
Fix by Colin Su.  Test by me, based on a test written by Petri Lehtinen.
2012-08-24 11:23:50 -04:00
R David Murray 638d40b433 #15249: Mangle From lines correctly when body contains invalid bytes.
Fix by Colin Su.  Test by me, based on a test written by Petri Lehtinen.
2012-08-24 11:14:13 -04:00
R David Murray 970bef295d Merge #15232: correctly mangle From lines in MIME preamble and epilogue 2012-07-22 21:53:54 -04:00
R David Murray 6a31bc6d81 #15232: correctly mangle From lines in MIME preamble and epilogue 2012-07-22 21:47:53 -04:00
R David Murray 0b6f6c82b5 #12586: add provisional email policy with new header parsing and folding.
When the new policies are used (and only when the new policies are explicitly
used) headers turn into objects that have attributes based on their parsed
values, and can be set using objects that encapsulate the values, as well as
set directly from unicode strings.  The folding algorithm then takes care of
encoding unicode where needed, and folding according to the highest level
syntactic objects.

With this patch only date and time headers are parsed as anything other than
unstructured, but that is all the helper methods in the existing API handle.
I do plan to add more parsers, and complete the set specified in the RFC
before the package becomes stable.
2012-05-25 18:42:14 -04:00
R David Murray c27e52265b #14731: refactor email policy framework.
This patch primarily does two things: (1) it adds some internal-interface
methods to Policy that allow for Policy to control the parsing and folding of
headers in such a way that we can construct a backward compatibility policy
that is 100% compatible with the 3.2 API, while allowing a new policy to
implement the email6 API.  (2) it adds that backward compatibility policy and
refactors the test suite so that the only differences between the 3.2
test_email.py file and the 3.3 test_email.py file is some small changes in
test framework and the addition of tests for bugs fixed that apply to the 3.2
API.

There are some additional teaks, such as moving just the code needed for the
compatibility policy into _policybase, so that the library code can import
only _policybase.  That way the new code that will be added for email6
will only get imported when a non-compatibility policy is imported.
2012-05-25 15:01:48 -04:00
R David Murray 80e22b56d3 Merge #11686: add missing entries to email __all__ lists.
Original patch by Steffen Daode Nurpmeso
2012-03-16 22:46:14 -04:00
R David Murray 1b6c724df0 #11686: add missing entries to email __all__ lists.
Original patch by Steffen Daode Nurpmeso
2012-03-16 22:43:05 -04:00
R David Murray 8d8f110492 #14062: fix BytesParser handling of Header objects
This is a different fix than the 3.2 fix, but the new tests are the same.

This also affected smtplib.SMTP.send_message, which calls BytesParser.
2012-03-14 14:24:22 -04:00
R David Murray 9fd170e2d0 #14062: fix BytesParser handling of linesep for Header objects
This also affected smtplib.SMTP.send_message, which calls BytesParser.
2012-03-14 14:05:03 -04:00
R David Murray 3edd22ac95 #11731: simplify/enhance parser/generator API by introducing policy objects.
This new interface will also allow for future planned enhancements
in control over the parser/generator without requiring any additional
complexity in the parser/generator API.

Patch reviewed by Éric Araujo and Barry Warsaw.
2011-04-18 13:59:37 -04:00
R David Murray b35c850a3f #11684: Complete parser bytes interface by adding BytesHeaderParser
Patch by Steffen Daode Nurpmeso.
2011-04-13 16:46:05 -04:00
R David Murray cd37dfcfac Harmonize linesep docstrings, and fix the quoting of \r\n 2011-03-14 18:35:56 -04:00
R. David Murray 7372a07fd0 #11019: Make BytesGenerator handle Message with None body.
Bug discovery and initial patch by Victor Stinner.
2011-01-26 21:21:32 +00:00
R. David Murray bdd2d93bfe Revert r88197. I'll refix correctly once there is a test. 2011-01-26 02:31:37 +00:00
Victor Stinner 3a7ee3ab5a Fix BytesGenerator._handle_text() if the message has no payload (None) 2011-01-26 00:39:19 +00:00
R. David Murray 73a559d0c9 Fix the change made for issue 1243654.
Surprisingly, it turns out there was no test that exercised this code path.
2010-12-21 18:07:59 +00:00
R. David Murray 5260a9bbdc #243654: only create a new MIME boundary if we don't already have one.
The rearranged code should do exactly what the old code did, but
the new code avoids a potentially costly re computation in the case
where a boundary already exists.
2010-12-12 20:06:19 +00:00
R. David Murray 719a449ba6 Fix TestBytesGeneratorIdempotent tests and a couple bugs they revealed.
The tests that were failing on (some) windows machines, where the
msg_XX.txt files used native \r\n lineseps are now also run on machines
that use \n natively, and conversely the \n tests are run on Windows.
The failing tests revealed one place where linesep needed to be added
to a flatten call in generator.  There was also another that the tests
didn't catch, so I added a test for that case as well.
2010-11-21 16:53:48 +00:00
R. David Murray 8451c4b6e0 #1349106: add linesep argument to generator.flatten and header.encode. 2010-10-23 22:19:56 +00:00
R. David Murray 96fd54eaec #4661: add bytes parsing and generation to email (email version bump to 5.1.0)
The work on this is not 100% complete, but everything is present to
allow real-world testing of the code.  The only remaining major todo
item is to (hopefully!) enhance the handling of non-ASCII bytes in headers
converted to unicode by RFC2047 encoding them rather than replacing them with
'?'s.
2010-10-08 15:55:28 +00:00
R. David Murray 70a9993bfd Fix docstring typo. 2010-10-01 20:38:33 +00:00
R. David Murray 57c45ac5e5 Merged revisions 78274 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r78274 | r.david.murray | 2010-02-20 23:23:00 -0500 (Sat, 20 Feb 2010) | 9 lines

  Issue 7970: When email.Parser.Parser parses a MIME message of type
  message/rfc822 it turns it into an object whose body consists of
  a list containing a single Message object.  HeaderParser, on the
  other hand, just copies the body as a string.  Generator.flatten
  has a special handler for the message mime type that expected the
  body to be the one item list.  This fails if the message was parsed
  by HeaderParser.  So we now check to see if the body is a string
  first, and if so just we just emit it.
........
2010-02-21 04:39:40 +00:00
R. David Murray a8f480f545 Merged revisions 77517,77525 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

Merge adds an additional test for as_string with a maxheaderlen specified.

........
  r77517 | r.david.murray | 2010-01-16 00:15:17 -0500 (Sat, 16 Jan 2010) | 6 lines

  Issue #1670765: Prevent email.generator.Generator from re-wrapping
  headers in multipart/signed MIME parts, which fixes one of the sources of
  invalid modifications to such parts by Generator.  Patch and tests by
  Martin von Gagern.
........
  r77525 | r.david.murray | 2010-01-16 11:08:32 -0500 (Sat, 16 Jan 2010) | 2 lines

  Fix issue number in comment.
........
2010-01-16 18:30:03 +00:00
Benjamin Peterson 46a9900e09 Merged revisions 77209,77229,77359-77360,77371 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r77209 | georg.brandl | 2010-01-01 07:07:05 -0600 (Fri, 01 Jan 2010) | 1 line

  More yearly updates.
........
  r77229 | georg.brandl | 2010-01-02 06:35:01 -0600 (Sat, 02 Jan 2010) | 1 line

  Fix casing.
........
  r77359 | georg.brandl | 2010-01-07 14:54:45 -0600 (Thu, 07 Jan 2010) | 1 line

  Fix description for Py_GetPath(); it sounded like it always returned sys.path.
........
  r77360 | georg.brandl | 2010-01-07 15:48:47 -0600 (Thu, 07 Jan 2010) | 1 line

  #7653: clarify how the PythonPath registry key should look like.
........
  r77371 | senthil.kumaran | 2010-01-08 13:20:25 -0600 (Fri, 08 Jan 2010) | 3 lines

  Fix for Issue7026. For the Error - RuntimeError: dictionary changed size during iteration
........
2010-01-09 18:45:30 +00:00
Barry Warsaw 70d61cedf7 "Port" the fix for issue 1974 from the trunk (2.7). Because Python 3.x does things much better, less changes are necessary.
This also shoves test_email_codecs_rename.py onto test_email_codecs.py even though the test needs to be ported to Python 3.
2009-03-30 23:12:30 +00:00
Christian Heimes a37d4c693a Removed PyInt_GetMax and sys.maxint
I replaced sys.maxint with sys.maxsize in Lib/*.py. Does anybody see a problem with the change on Win 64bit platforms? Win 64's long is just 32bit but the sys.maxsize is now 2**63-1 on every 64bit platform.
Also added docs for sys.maxsize.
2007-12-04 23:02:19 +00:00
Guido van Rossum 3172c5d263 Patch# 1258 by Christian Heimes: kill basestring.
I like this because it makes the code shorter! :-)
2007-10-16 18:12:55 +00:00
Guido van Rossum 9604e66660 Oops. I copied a slightly older version of the email package from the sandbox.
This should restore the email package in the py3k branch to exactly what's in
the sandbox.

This wipes out 1-2 fixes made post-copy, which I'll re-apply shortly.
2007-08-30 03:46:43 +00:00
Guido van Rossum 8b3febef2f Copying the email package back, despite its failings. 2007-08-30 01:15:14 +00:00
Guido van Rossum 6398b7a351 Remove the email package for now.
Once Barry and the email-sig have a working new version
we'll add it back.
If it doesn't make the 3.0a deadline (release August 31), too bad.
2007-08-25 13:43:02 +00:00
Guido van Rossum 34d1928766 SF patch# 1770008 by Christian Heimes (plus some extras).
Completely get rid of StringIO.py and cStringIO.c.

I had to fix a few tests and modules beyond what Christian did, and
invent a few conventions.  E.g. in elementtree, I chose to
write/return Unicode strings whe no encoding is given, but bytes when
an explicit encoding is given.  Also mimetools was made to always
assume binary files.
2007-08-09 01:03:29 +00:00
Guido van Rossum d4eda825c7 SF patch# 1757839 by Alexandre Vassalotti -- make test_mailbox and
test_old_mailbox pass.
2007-07-21 00:21:26 +00:00
Guido van Rossum ef87d6ed94 Rip out all the u"..." literals and calls to unicode(). 2007-05-02 19:09:54 +00:00
Guido van Rossum be19ed77dd Fix most trivially-findable print statements.
There's one major and one minor category still unfixed:
doctests are the major category (and I hope to be able to augment the
refactoring tool to refactor bona fide doctests soon);
other code generating print statements in strings is the minor category.

(Oh, and I don't know if the compiler package works.)
2007-02-09 05:37:30 +00:00
Guido van Rossum b053cd8f40 Killed the <> operator. You must now use !=.
Opportunistically also fixed one or two places where '<> None' should be
'is not None' and where 'type(x) <> y' should be 'not isinstance(x, y)'.
2006-08-24 03:53:23 +00:00
Thomas Wouters 49fd7fa443 Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
number of tests, all because of the codecs/_multibytecodecs issue described
here (it's not a Py3K issue, just something Py3K discovers):
http://mail.python.org/pipermail/python-dev/2006-April/064051.html

Hye-Shik Chang promised to look for a fix, so no need to fix it here. The
tests that are expected to break are:

test_codecencodings_cn
test_codecencodings_hk
test_codecencodings_jp
test_codecencodings_kr
test_codecencodings_tw
test_codecs
test_multibytecodec

This merge fixes an actual test failure (test_weakref) in this branch,
though, so I believe merging is the right thing to do anyway.
2006-04-21 10:40:58 +00:00