Skip to content

Commit

Permalink
remove Python2 crumbs
Browse files Browse the repository at this point in the history
  • Loading branch information
a-detiste committed May 21, 2024
1 parent cdaccfa commit 93465ed
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 16 deletions.
4 changes: 1 addition & 3 deletions muttdown/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os.path
from subprocess import check_output

import six
import yaml

# largely copied from my earlier work in fakemtpd
Expand Down Expand Up @@ -43,8 +42,7 @@ def __str__(self):
return "%s(%r)" % (self.__class__.__name__, self.message)


@six.add_metaclass(_ParamsAsProps)
class Config(object):
class Config(metaclass=_ParamsAsProps):
_parameters = {
"smtp_host": "127.0.0.1",
"smtp_port": 25,
Expand Down
11 changes: 3 additions & 8 deletions muttdown/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function

import argparse
import email
import email.iterators
Expand All @@ -13,7 +11,6 @@

import markdown
import pynliner
import six

from . import __version__, config

Expand All @@ -31,7 +28,7 @@ def convert_one(part, config, charset):
text = part.get_payload(decode=True)
if part.get_charset():
charset = get_charset_from_message_fragment(part)
if not isinstance(text, six.text_type):
if not isinstance(text, str):
# decode=True only decodes the base64/uuencoded nature, and
# will always return bytes; gotta decode it
if charset is not None:
Expand Down Expand Up @@ -214,17 +211,15 @@ def main(argv=None):

proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, shell=False)
msg = rebuilt.as_string()
if sys.version_info > (3, 0):
msg = msg.encode("utf-8")
msg = msg.encode("utf-8")
proc.stdin.write(msg)
proc.stdin.close()
proc.wait()
return proc.returncode
else:
conn = smtp_connection(c)
msg = rebuilt.as_string()
if sys.version_info > (3, 0):
msg = msg.encode("utf-8")
msg = msg.encode("utf-8")
conn.sendmail(args.envelope_from, args.addresses, msg)
conn.quit()
return 0
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"Markdown>=3.0,<4.0",
"PyYAML>=3.0",
"pynliner==0.8.0",
"six",
],
entry_points={
"console_scripts": [
Expand Down
5 changes: 1 addition & 4 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,7 @@ def test_main_passthru(tempdir, mocker):

def test_raw_unicode(basic_config):
raw_message = b"Date: Fri, 1 Mar 2019 17:54:06 -0800\nFrom: Test <test@example.com>\nTo: Test <test@example.com>\nSubject: Re: Fwd: Important: 2019 =?utf-8?Q?Securit?=\n =?utf-8?B?eSBVcGRhdGUg4oCU?=\nReferences: <BypjV000000000000000000000000000000000000000000000PNNK9E00HcUNxx_7QEaZBosNNgqKSw@sfdc.net>\n <CAPe=KFgfaFd5U7KX=3ugNs5vPzHkRgAij9md8TL-WX-ypEszug@mail.gmail.com>\nMIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\nContent-Disposition: inline\nContent-Transfer-Encoding: 8bit\nUser-Agent: Mutt/1.11.3 (2019-02-01)\n\nThis is a test\n\n\nOn Fri, Mar 01, 2019 at 03:08:35PM -0800, Test Wrote:\n> :)\n> \n> \n> \xc3\x98 Text\n> \n> \xc2\xb7 text\n-- \nend\n" # noqa
if sys.version_info > (3, 0):
mail = email.message_from_string(raw_message.decode("utf-8"))
else:
mail = email.message_from_string(raw_message)
mail = email.message_from_string(raw_message.decode("utf-8"))
converted = process_message(mail, basic_config)
assert converted["From"] == "Test <test@example.com>"
assert "Ø" in converted.get_payload()
Expand Down

0 comments on commit 93465ed

Please sign in to comment.