We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
mail attachs tcmime***
```shell
$scrapy shell
2019-12-13 20:21:33 [scrapy.utils.log] INFO: Scrapy 1.8.0 started (bot: Book)
2019-12-13 20:21:33 [scrapy.utils.log] INFO: Versions: lxml 4.4.1.0, libxml2 2.9.4, cssselect 1.1.0, parsel 1.5.2, w3lib 1.21.0, Twisted 19.10.0, Python 3.8.0 (v3.8.0:fa919fdf25, Oct 14 2019, 10:23:27) - [Clang 6.0 (clang-600.0.57)], pyOpenSSL 19.0.0 (OpenSSL 1.1.1d  10 Sep 2019), cryptography 2.8, Platform macOS-10.15.2-x86_64-i386-64bit
.....
In [1]: from scrapy.mail import MailSender                                                                                       

In [2]:  mailer = MailSender.from_settings(crawler.settings)                                                                     

In [3]:  book = open('为了媳妇去修仙.zip', 'rb')                                                                                 

In [4]: attachments = [('为了媳妇去修仙.zip', 
   ...:                             'application/zip', book)]                                                                    

In [5]: mailer.send(to=['1173372284@qq.com'], 
   ...:                                     attachs=attachments, 
   ...:                                     subject="Convert", 
   ...:                                     body = '', 
   ...:                                     mimetype='application/zip' 
   ...:                                     ) 

In [6]: mailer.e2019-12-13 20:25:33 [parso.python.diff] DEBUG: diff parser start
2019-12-13 20:25:33 [parso.python.diff] DEBUG: line_lengths old: 1; new: 1
2019-12-13 20:25:33 [parso.python.diff] DEBUG: -> code[replace] old[1:1] new[1:1]
2019-12-13 20:25:33 [parso.python.diff] DEBUG: parse_part from 1 to 1 (to 0 in part parser)
2019-12-13 20:25:33 [parso.python.diff] DEBUG: diff parser end
2019-12-13 20:25:35 [scrapy.mail] INFO: Mail sent OK: To=['1173372284@qq.com'] Cc=[] Subject="Convert" Attachs=1                 

```

get mail 
<img width="584" alt="截屏2019-12-13下午8 34 15" src="https://user-images.githubusercontent.com/17330686/70800846-45ddbf80-1de8-11ea-9a6f-d44b13791c20.png">

why attachs `为了媳妇去修仙.zip` change  to `tcmime.954.1140.14065.bin `




--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `scrapy/mail.py`
Content:
```
1 """
2 Mail sending helpers
3 
4 See documentation in docs/topics/email.rst
5 """
6 import logging
7 from email import encoders as Encoders
8 from email.mime.base import MIMEBase
9 from email.mime.multipart import MIMEMultipart
10 from email.mime.nonmultipart import MIMENonMultipart
11 from email.mime.text import MIMEText
12 from email.utils import COMMASPACE, formatdate
13 from io import BytesIO
14 
15 from twisted.internet import defer, reactor, ssl
16 
17 from scrapy.utils.misc import arg_to_iter
18 from scrapy.utils.python import to_bytes
19 
20 
21 logger = logging.getLogger(__name__)
22 
23 
24 def _to_bytes_or_none(text):
25     if text is None:
26         return None
27     return to_bytes(text)
28 
29 
30 class MailSender(object):
31 
32     def __init__(self, smtphost='localhost', mailfrom='scrapy@localhost',
33             smtpuser=None, smtppass=None, smtpport=25, smtptls=False, smtpssl=False, debug=False):
34         self.smtphost = smtphost
35         self.smtpport = smtpport
36         self.smtpuser = _to_bytes_or_none(smtpuser)
37         self.smtppass = _to_bytes_or_none(smtppass)
38         self.smtptls = smtptls
39         self.smtpssl = smtpssl
40         self.mailfrom = mailfrom
41         self.debug = debug
42 
43     @classmethod
44     def from_settings(cls, settings):
45         return cls(settings['MAIL_HOST'], settings['MAIL_FROM'], settings['MAIL_USER'],
46             settings['MAIL_PASS'], settings.getint('MAIL_PORT'),
47             settings.getbool('MAIL_TLS'), settings.getbool('MAIL_SSL'))
48 
49     def send(self, to, subject, body, cc=None, attachs=(), mimetype='text/plain', charset=None, _callback=None):
50         if attachs:
51             msg = MIMEMultipart()
52         else:
53             msg = MIMENonMultipart(*mimetype.split('/', 1))
54 
55         to = list(arg_to_iter(to))
56         cc = list(arg_to_iter(cc))
57 
58         msg['From'] = self.mailfrom
59         msg['To'] = COMMASPACE.join(to)
60         msg['Date'] = formatdate(localtime=True)
61         msg['Subject'] = subject
62         rcpts = to[:]
63         if cc:
64             rcpts.extend(cc)
65             msg['Cc'] = COMMASPACE.join(cc)
66 
67         if charset:
68             msg.set_charset(charset)
69 
70         if attachs:
71             msg.attach(MIMEText(body, 'plain', charset or 'us-ascii'))
72             for attach_name, mimetype, f in attachs:
73                 part = MIMEBase(*mimetype.split('/'))
74                 part.set_payload(f.read())
75                 Encoders.encode_base64(part)
76                 part.add_header('Content-Disposition', 'attachment; filename="%s"' \
77                     % attach_name)
78                 msg.attach(part)
79         else:
80             msg.set_payload(body)
81 
82         if _callback:
83             _callback(to=to, subject=subject, body=body, cc=cc, attach=attachs, msg=msg)
84 
85         if self.debug:
86             logger.debug('Debug mail sent OK: To=%(mailto)s Cc=%(mailcc)s '
87                          'Subject="%(mailsubject)s" Attachs=%(mailattachs)d',
88                          {'mailto': to, 'mailcc': cc, 'mailsubject': subject,
89                           'mailattachs': len(attachs)})
90             return
91 
92         dfd = self._sendmail(rcpts, msg.as_string().encode(charset or 'utf-8'))
93         dfd.addCallbacks(self._sent_ok, self._sent_failed,
94             callbackArgs=[to, cc, subject, len(attachs)],
95             errbackArgs=[to, cc, subject, len(attachs)])
96         reactor.addSystemEventTrigger('before', 'shutdown', lambda: dfd)
97         return dfd
98 
99     def _sent_ok(self, result, to, cc, subject, nattachs):
100         logger.info('Mail sent OK: To=%(mailto)s Cc=%(mailcc)s '
101                     'Subject="%(mailsubject)s" Attachs=%(mailattachs)d',
102                     {'mailto': to, 'mailcc': cc, 'mailsubject': subject,
103                      'mailattachs': nattachs})
104 
105     def _sent_failed(self, failure, to, cc, subject, nattachs):
106         errstr = str(failure.value)
107         logger.error('Unable to send mail: To=%(mailto)s Cc=%(mailcc)s '
108                      'Subject="%(mailsubject)s" Attachs=%(mailattachs)d'
109                      '- %(mailerr)s',
110                      {'mailto': to, 'mailcc': cc, 'mailsubject': subject,
111                       'mailattachs': nattachs, 'mailerr': errstr})
112 
113     def _sendmail(self, to_addrs, msg):
114         # Import twisted.mail here because it is not available in python3
115         from twisted.mail.smtp import ESMTPSenderFactory
116         msg = BytesIO(msg)
117         d = defer.Deferred()
118         factory = ESMTPSenderFactory(self.smtpuser, self.smtppass, self.mailfrom, \
119             to_addrs, msg, d, heloFallback=True, requireAuthentication=False, \
120             requireTransportSecurity=self.smtptls)
121         factory.noisy = False
122 
123         if self.smtpssl:
124             reactor.connectSSL(self.smtphost, self.smtpport, factory, ssl.ClientContextFactory())
125         else:
126             reactor.connectTCP(self.smtphost, self.smtpport, factory)
127 
128         return d
129
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/scrapy/mail.py b/scrapy/mail.py
--- a/scrapy/mail.py
+++ b/scrapy/mail.py
@@ -73,8 +73,7 @@
                 part = MIMEBase(*mimetype.split('/'))
                 part.set_payload(f.read())
                 Encoders.encode_base64(part)
-                part.add_header('Content-Disposition', 'attachment; filename="%s"' \
-                    % attach_name)
+                part.add_header('Content-Disposition', 'attachment', filename=attach_name)
                 msg.attach(part)
         else:
             msg.set_payload(body)

{"golden_diff": "diff --git a/scrapy/mail.py b/scrapy/mail.py\n--- a/scrapy/mail.py\n+++ b/scrapy/mail.py\n@@ -73,8 +73,7 @@\n                 part = MIMEBase(*mimetype.split('/'))\n                 part.set_payload(f.read())\n                 Encoders.encode_base64(part)\n-                part.add_header('Content-Disposition', 'attachment; filename=\"%s\"' \\\n-                    % attach_name)\n+                part.add_header('Content-Disposition', 'attachment', filename=attach_name)\n                 msg.attach(part)\n         else:\n             msg.set_payload(body)\n", "issue": "mail attachs tcmime***\n```shell\r\n$scrapy shell\r\n2019-12-13 20:21:33 [scrapy.utils.log] INFO: Scrapy 1.8.0 started (bot: Book)\r\n2019-12-13 20:21:33 [scrapy.utils.log] INFO: Versions: lxml 4.4.1.0, libxml2 2.9.4, cssselect 1.1.0, parsel 1.5.2, w3lib 1.21.0, Twisted 19.10.0, Python 3.8.0 (v3.8.0:fa919fdf25, Oct 14 2019, 10:23:27) - [Clang 6.0 (clang-600.0.57)], pyOpenSSL 19.0.0 (OpenSSL 1.1.1d  10 Sep 2019), cryptography 2.8, Platform macOS-10.15.2-x86_64-i386-64bit\r\n.....\r\nIn [1]: from scrapy.mail import MailSender                                                                                       \r\n\r\nIn [2]:  mailer = MailSender.from_settings(crawler.settings)                                                                     \r\n\r\nIn [3]:  book = open('\u4e3a\u4e86\u5ab3\u5987\u53bb\u4fee\u4ed9.zip', 'rb')                                                                                 \r\n\r\nIn [4]: attachments = [('\u4e3a\u4e86\u5ab3\u5987\u53bb\u4fee\u4ed9.zip', \r\n   ...:                             'application/zip', book)]                                                                    \r\n\r\nIn [5]: mailer.send(to=['1173372284@qq.com'], \r\n   ...:                                     attachs=attachments, \r\n   ...:                                     subject=\"Convert\", \r\n   ...:                                     body = '', \r\n   ...:                                     mimetype='application/zip' \r\n   ...:                                     ) \r\n\r\nIn [6]: mailer.e2019-12-13 20:25:33 [parso.python.diff] DEBUG: diff parser start\r\n2019-12-13 20:25:33 [parso.python.diff] DEBUG: line_lengths old: 1; new: 1\r\n2019-12-13 20:25:33 [parso.python.diff] DEBUG: -> code[replace] old[1:1] new[1:1]\r\n2019-12-13 20:25:33 [parso.python.diff] DEBUG: parse_part from 1 to 1 (to 0 in part parser)\r\n2019-12-13 20:25:33 [parso.python.diff] DEBUG: diff parser end\r\n2019-12-13 20:25:35 [scrapy.mail] INFO: Mail sent OK: To=['1173372284@qq.com'] Cc=[] Subject=\"Convert\" Attachs=1                 \r\n\r\n```\r\n\r\nget mail \r\n<img width=\"584\" alt=\"\u622a\u5c4f2019-12-13\u4e0b\u53488 34 15\" src=\"https://user-images.githubusercontent.com/17330686/70800846-45ddbf80-1de8-11ea-9a6f-d44b13791c20.png\">\r\n\r\nwhy attachs `\u4e3a\u4e86\u5ab3\u5987\u53bb\u4fee\u4ed9.zip` change  to `tcmime.954.1140.14065.bin `\r\n\r\n\r\n\n", "before_files": [{"content": "\"\"\"\nMail sending helpers\n\nSee documentation in docs/topics/email.rst\n\"\"\"\nimport logging\nfrom email import encoders as Encoders\nfrom email.mime.base import MIMEBase\nfrom email.mime.multipart import MIMEMultipart\nfrom email.mime.nonmultipart import MIMENonMultipart\nfrom email.mime.text import MIMEText\nfrom email.utils import COMMASPACE, formatdate\nfrom io import BytesIO\n\nfrom twisted.internet import defer, reactor, ssl\n\nfrom scrapy.utils.misc import arg_to_iter\nfrom scrapy.utils.python import to_bytes\n\n\nlogger = logging.getLogger(__name__)\n\n\ndef _to_bytes_or_none(text):\n    if text is None:\n        return None\n    return to_bytes(text)\n\n\nclass MailSender(object):\n\n    def __init__(self, smtphost='localhost', mailfrom='scrapy@localhost',\n            smtpuser=None, smtppass=None, smtpport=25, smtptls=False, smtpssl=False, debug=False):\n        self.smtphost = smtphost\n        self.smtpport = smtpport\n        self.smtpuser = _to_bytes_or_none(smtpuser)\n        self.smtppass = _to_bytes_or_none(smtppass)\n        self.smtptls = smtptls\n        self.smtpssl = smtpssl\n        self.mailfrom = mailfrom\n        self.debug = debug\n\n    @classmethod\n    def from_settings(cls, settings):\n        return cls(settings['MAIL_HOST'], settings['MAIL_FROM'], settings['MAIL_USER'],\n            settings['MAIL_PASS'], settings.getint('MAIL_PORT'),\n            settings.getbool('MAIL_TLS'), settings.getbool('MAIL_SSL'))\n\n    def send(self, to, subject, body, cc=None, attachs=(), mimetype='text/plain', charset=None, _callback=None):\n        if attachs:\n            msg = MIMEMultipart()\n        else:\n            msg = MIMENonMultipart(*mimetype.split('/', 1))\n\n        to = list(arg_to_iter(to))\n        cc = list(arg_to_iter(cc))\n\n        msg['From'] = self.mailfrom\n        msg['To'] = COMMASPACE.join(to)\n        msg['Date'] = formatdate(localtime=True)\n        msg['Subject'] = subject\n        rcpts = to[:]\n        if cc:\n            rcpts.extend(cc)\n            msg['Cc'] = COMMASPACE.join(cc)\n\n        if charset:\n            msg.set_charset(charset)\n\n        if attachs:\n            msg.attach(MIMEText(body, 'plain', charset or 'us-ascii'))\n            for attach_name, mimetype, f in attachs:\n                part = MIMEBase(*mimetype.split('/'))\n                part.set_payload(f.read())\n                Encoders.encode_base64(part)\n                part.add_header('Content-Disposition', 'attachment; filename=\"%s\"' \\\n                    % attach_name)\n                msg.attach(part)\n        else:\n            msg.set_payload(body)\n\n        if _callback:\n            _callback(to=to, subject=subject, body=body, cc=cc, attach=attachs, msg=msg)\n\n        if self.debug:\n            logger.debug('Debug mail sent OK: To=%(mailto)s Cc=%(mailcc)s '\n                         'Subject=\"%(mailsubject)s\" Attachs=%(mailattachs)d',\n                         {'mailto': to, 'mailcc': cc, 'mailsubject': subject,\n                          'mailattachs': len(attachs)})\n            return\n\n        dfd = self._sendmail(rcpts, msg.as_string().encode(charset or 'utf-8'))\n        dfd.addCallbacks(self._sent_ok, self._sent_failed,\n            callbackArgs=[to, cc, subject, len(attachs)],\n            errbackArgs=[to, cc, subject, len(attachs)])\n        reactor.addSystemEventTrigger('before', 'shutdown', lambda: dfd)\n        return dfd\n\n    def _sent_ok(self, result, to, cc, subject, nattachs):\n        logger.info('Mail sent OK: To=%(mailto)s Cc=%(mailcc)s '\n                    'Subject=\"%(mailsubject)s\" Attachs=%(mailattachs)d',\n                    {'mailto': to, 'mailcc': cc, 'mailsubject': subject,\n                     'mailattachs': nattachs})\n\n    def _sent_failed(self, failure, to, cc, subject, nattachs):\n        errstr = str(failure.value)\n        logger.error('Unable to send mail: To=%(mailto)s Cc=%(mailcc)s '\n                     'Subject=\"%(mailsubject)s\" Attachs=%(mailattachs)d'\n                     '- %(mailerr)s',\n                     {'mailto': to, 'mailcc': cc, 'mailsubject': subject,\n                      'mailattachs': nattachs, 'mailerr': errstr})\n\n    def _sendmail(self, to_addrs, msg):\n        # Import twisted.mail here because it is not available in python3\n        from twisted.mail.smtp import ESMTPSenderFactory\n        msg = BytesIO(msg)\n        d = defer.Deferred()\n        factory = ESMTPSenderFactory(self.smtpuser, self.smtppass, self.mailfrom, \\\n            to_addrs, msg, d, heloFallback=True, requireAuthentication=False, \\\n            requireTransportSecurity=self.smtptls)\n        factory.noisy = False\n\n        if self.smtpssl:\n            reactor.connectSSL(self.smtphost, self.smtpport, factory, ssl.ClientContextFactory())\n        else:\n            reactor.connectTCP(self.smtphost, self.smtpport, factory)\n\n        return d\n", "path": "scrapy/mail.py"}], "after_files": [{"content": "\"\"\"\nMail sending helpers\n\nSee documentation in docs/topics/email.rst\n\"\"\"\nimport logging\nfrom email import encoders as Encoders\nfrom email.mime.base import MIMEBase\nfrom email.mime.multipart import MIMEMultipart\nfrom email.mime.nonmultipart import MIMENonMultipart\nfrom email.mime.text import MIMEText\nfrom email.utils import COMMASPACE, formatdate\nfrom io import BytesIO\n\nfrom twisted.internet import defer, reactor, ssl\n\nfrom scrapy.utils.misc import arg_to_iter\nfrom scrapy.utils.python import to_bytes\n\n\nlogger = logging.getLogger(__name__)\n\n\ndef _to_bytes_or_none(text):\n    if text is None:\n        return None\n    return to_bytes(text)\n\n\nclass MailSender(object):\n\n    def __init__(self, smtphost='localhost', mailfrom='scrapy@localhost',\n            smtpuser=None, smtppass=None, smtpport=25, smtptls=False, smtpssl=False, debug=False):\n        self.smtphost = smtphost\n        self.smtpport = smtpport\n        self.smtpuser = _to_bytes_or_none(smtpuser)\n        self.smtppass = _to_bytes_or_none(smtppass)\n        self.smtptls = smtptls\n        self.smtpssl = smtpssl\n        self.mailfrom = mailfrom\n        self.debug = debug\n\n    @classmethod\n    def from_settings(cls, settings):\n        return cls(settings['MAIL_HOST'], settings['MAIL_FROM'], settings['MAIL_USER'],\n            settings['MAIL_PASS'], settings.getint('MAIL_PORT'),\n            settings.getbool('MAIL_TLS'), settings.getbool('MAIL_SSL'))\n\n    def send(self, to, subject, body, cc=None, attachs=(), mimetype='text/plain', charset=None, _callback=None):\n        if attachs:\n            msg = MIMEMultipart()\n        else:\n            msg = MIMENonMultipart(*mimetype.split('/', 1))\n\n        to = list(arg_to_iter(to))\n        cc = list(arg_to_iter(cc))\n\n        msg['From'] = self.mailfrom\n        msg['To'] = COMMASPACE.join(to)\n        msg['Date'] = formatdate(localtime=True)\n        msg['Subject'] = subject\n        rcpts = to[:]\n        if cc:\n            rcpts.extend(cc)\n            msg['Cc'] = COMMASPACE.join(cc)\n\n        if charset:\n            msg.set_charset(charset)\n\n        if attachs:\n            msg.attach(MIMEText(body, 'plain', charset or 'us-ascii'))\n            for attach_name, mimetype, f in attachs:\n                part = MIMEBase(*mimetype.split('/'))\n                part.set_payload(f.read())\n                Encoders.encode_base64(part)\n                part.add_header('Content-Disposition', 'attachment', filename=attach_name)\n                msg.attach(part)\n        else:\n            msg.set_payload(body)\n\n        if _callback:\n            _callback(to=to, subject=subject, body=body, cc=cc, attach=attachs, msg=msg)\n\n        if self.debug:\n            logger.debug('Debug mail sent OK: To=%(mailto)s Cc=%(mailcc)s '\n                         'Subject=\"%(mailsubject)s\" Attachs=%(mailattachs)d',\n                         {'mailto': to, 'mailcc': cc, 'mailsubject': subject,\n                          'mailattachs': len(attachs)})\n            return\n\n        dfd = self._sendmail(rcpts, msg.as_string().encode(charset or 'utf-8'))\n        dfd.addCallbacks(self._sent_ok, self._sent_failed,\n            callbackArgs=[to, cc, subject, len(attachs)],\n            errbackArgs=[to, cc, subject, len(attachs)])\n        reactor.addSystemEventTrigger('before', 'shutdown', lambda: dfd)\n        return dfd\n\n    def _sent_ok(self, result, to, cc, subject, nattachs):\n        logger.info('Mail sent OK: To=%(mailto)s Cc=%(mailcc)s '\n                    'Subject=\"%(mailsubject)s\" Attachs=%(mailattachs)d',\n                    {'mailto': to, 'mailcc': cc, 'mailsubject': subject,\n                     'mailattachs': nattachs})\n\n    def _sent_failed(self, failure, to, cc, subject, nattachs):\n        errstr = str(failure.value)\n        logger.error('Unable to send mail: To=%(mailto)s Cc=%(mailcc)s '\n                     'Subject=\"%(mailsubject)s\" Attachs=%(mailattachs)d'\n                     '- %(mailerr)s',\n                     {'mailto': to, 'mailcc': cc, 'mailsubject': subject,\n                      'mailattachs': nattachs, 'mailerr': errstr})\n\n    def _sendmail(self, to_addrs, msg):\n        # Import twisted.mail here because it is not available in python3\n        from twisted.mail.smtp import ESMTPSenderFactory\n        msg = BytesIO(msg)\n        d = defer.Deferred()\n        factory = ESMTPSenderFactory(self.smtpuser, self.smtppass, self.mailfrom, \\\n            to_addrs, msg, d, heloFallback=True, requireAuthentication=False, \\\n            requireTransportSecurity=self.smtptls)\n        factory.noisy = False\n\n        if self.smtpssl:\n            reactor.connectSSL(self.smtphost, self.smtpport, factory, ssl.ClientContextFactory())\n        else:\n            reactor.connectTCP(self.smtphost, self.smtpport, factory)\n\n        return d\n", "path": "scrapy/mail.py"}]}