Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attach files with filenames that include non-ASCII characters #69

Merged
merged 2 commits into from
Nov 7, 2016
Merged

Attach files with filenames that include non-ASCII characters #69

merged 2 commits into from
Nov 7, 2016

Conversation

stevenbuccini
Copy link
Contributor

RFC 2231 allows us to specify a language and a charset for filenames that include non-ASCII characters. Python's email module already includes some nifty functionality to handle this. This PR simply exposes that functionality to users of marrow/mailer.

@stevenbuccini
Copy link
Contributor Author

Unsure of why these tests are failing on Python3 -- looks to be a broader issue than just my tests.

@stevenbuccini
Copy link
Contributor Author

cc: @amcgregor, just want to bring this to your attention.

Copy link
Member

@amcgregor amcgregor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Howdy! Indeed, those Travis errors are me, not you, as I attempt to clean up the develop branch a bit. Thanks for the pull, especially with tests! There is the question of the change being breaking, however.

If this could be updated to either allow the old name, but with a DeprecationWarning emitted, or to preserve the original argument name, that'd be awesome.

@@ -258,7 +258,8 @@ def mime(self):
return message

def attach(self, name, data=None, maintype=None, subtype=None,
inline=False, filename=None, encoding=None):
inline=False, filename=None, filename_charset='', filename_language='',
content_encoding=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure of why this needed to be a breaking change? (encodingcontent_encoding) Why write more and needlessly break existing use?

Copy link
Contributor Author

@stevenbuccini stevenbuccini Nov 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! You're totally right. My goal was to clarify the difference between the encoding of the attachment and the encoding of the attachment name. However, RFC uses "charset" rather than "encoding" and I forgot to change it back. Guess this is what code review is for!

If that is your only concern, I'd be happy to push that change up right now. Otherwise, I'll bundle all of my changes into another commit for easier reviewing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's pretty much the only thing stopping me from accepting the pull immediately. :) I'll squash when merging, so don't worry about having multiple individual commits.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

assert 'Farewell cruel world.' in unicode(message)
assert 'filename*="\'en-us\'%E2%98%83.txt"' in unicode(message) # ☃ is encoded in ASCII as \xe2\x98\x83, which is URL encoded as %E2%98%83
assert 'dW5pY29kZSBzbm93bWFu' in unicode(message) # unicode snowman in base64

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very much appreciate tests.

@amcgregor amcgregor merged commit 036ddd6 into marrow:develop Nov 7, 2016
@amcgregor
Copy link
Member

Thanks again!

@stevenbuccini
Copy link
Contributor Author

Do you plan on releasing a bumped version on PyPi? Would make pulling this commit into my project a lot easier. Thanks!

@amcgregor
Copy link
Member

Aye; I'll try to tackle that (and fixing these tests…) for a release this week-end.

@stevenbuccini
Copy link
Contributor Author

Just curious if you had an update on this! Thanks!

@amcgregor
Copy link
Member

Yeah… spent a ludicrous amount of time this week-end wrangling with the tests. Things like the DNS package used previously is not Python 3 compatible, nor was the mock SMTP server. Migration to Pytest (from Nose) is also part of this. T'was a bit bigger of a job than two afternoons on the week-end could account for. I'll continue updating/fixing them as the week progresses and will re-try for a release next week-end.

@stevenbuccini
Copy link
Contributor Author

No worries, didn't realize it would be such a big deal! Thanks so much for slogging through it for a minor change. I do appreciate it.

@amcgregor
Copy link
Member

It never hurts to help. 😆

@amcgregor
Copy link
Member

Tests pass on all supported platforms now.

There's an interesting oddity between Python 2 and 3, where the encoded filename is quoted in Python 2, but not quoted in 3. I've verified that unquoted is acceptable according to the RFC, so no damage beyond extra conditionals in the tests. I've shoved the major test update (ripping out the DNS bits, etc.) into a branch and will roll a release including the changes/fixes so far on Saturday.

Could you do me a huge favour and double-check that the current develop branch operates according to your expectations?

Thanks!

@amcgregor
Copy link
Member

@stevenbuccini
Copy link
Contributor Author

@amcgregor Just seeing this now! Thank you so very much. I really appreciate your dedication to the issue; I know it was a major task getting the tests in order for such a small fix.

@amcgregor amcgregor added 2.enhancement A request for a new feature or altered behaviour. area:message Issue relates to the MIME e-mail Message object representation. labels Apr 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.enhancement A request for a new feature or altered behaviour. area:message Issue relates to the MIME e-mail Message object representation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants