flask-mail
flask-mail copied to clipboard
Header Content-Disposition incorrectly folded
Here is a minimum working example:
import sys
from flask import Flask
from flask_mail import Message, Mail
app = Flask(__name__)
app.config['MAIL_SERVER'] = 'some.server.example.com'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = 'username'
app.config['MAIL_PASSWORD'] = 'password'
Mail(app)
@app.route('/')
def hello_world():
filename = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.txt'
msg = Message('subj', recipients=['[email protected]'],
body='this is folding check', sender='[email protected]')
msg.attach(filename, 'text/plain', b'hello world.\n\nby NG')
msg_bytes = msg.as_bytes()
sys.stdout.buffer.write(msg_bytes)
response = ''.join(['<pre>' + x.strip() + '</pre>'
for x in msg_bytes.decode('utf-8').split('\n')])
return response
if __name__ == '__main__':
app.run()
And error part:
--===============8337733259214382862==
Content-Type: text/plain
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: attachment;filen
ame="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.txt"
aGVsbG8gd29ybGQuCgpieSBORw==
--===============8337733259214382862==--
It inserts line separator in filename
parameter, and some mail servers fail to proceed it.
It should be:
Content-Disposition: attachment;
filename="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.txt"
aGVsbG8gd29ybGQuCgpieSBORw==