#!/usr/bin/env python3 """ Test handling of long filenames in email attachments. """ from email.policy import SMTP def run_test(): """ Run the test. """ for count in range(1, 32): folded_header = SMTP.fold( 'Content-Disposition', 'attachment; filename="{}.txt"'.format('_'.join(['TEST'] * count)) ) print(folded_header) for line_num, header_line in enumerate(folded_header.splitlines()[1:]): if not header_line.startswith(' '): print( "Line {} does not start with a space!".format(line_num + 2) ) print() print() if __name__ == '__main__': run_test()