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

mail attachs tcmime*** #4229

Closed
Apuyuseng opened this issue Dec 13, 2019 · 5 comments · Fixed by #4239
Closed

mail attachs tcmime*** #4229

Apuyuseng opened this issue Dec 13, 2019 · 5 comments · Fixed by #4239
Labels

Comments

@Apuyuseng
Copy link
Contributor

$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
截屏2019-12-13下午8 34 15

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

@Gallaecio
Copy link
Member

I don’t see any code in Scrapy that would cause that. Can you try doing the same process with any other email-deliverying library? It looks to me like one of the mail servers, either the one sending the email or (most likely) the one receiving the email are renaming the attachment for security reasons.

@Apuyuseng
Copy link
Contributor Author

Apuyuseng commented Dec 13, 2019

change code scrapy/mail.py line 76

part.add_header('Content-Disposition', 'attachment', filename=attach_name)

attachment normal.

image

before old code not friendly for Chinese.

@Gallaecio
Copy link
Member

Can you try with the same file and filename?

@Apuyuseng
Copy link
Contributor Author

image

image

@Apuyuseng
Copy link
Contributor Author

Apuyuseng commented Dec 13, 2019

When the file name consists of alphanumeric characters, it is normal to receive the attachment name.
However,However, problems will occur if the file name is changed to Chinese.
This has nothing to do with the file type

python3.8/email/message.py 527 line

""""
 Examples:

        msg.add_header('content-disposition', 'attachment', filename='bud.gif')
        msg.add_header('content-disposition', 'attachment',
                       filename=('utf-8', '', Fußballer.ppt'))
        msg.add_header('content-disposition', 'attachment',
                       filename='Fußballer.ppt'))
"""

filename is can list object and set encode.

@Gallaecio Gallaecio added the bug label Dec 14, 2019
Apuyuseng added a commit to Apuyuseng/scrapy that referenced this issue Dec 17, 2019
When the file name consists of alphanumeric characters, it is normal to receive the attachment name.
However,However, problems will occur if the file name is changed to Chinese.
This has nothing to do with the file type
wRAR added a commit that referenced this issue Dec 17, 2019
Fix mail attachs tcmime *** (#4229)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants