Ticket #5799: 5799-BODYSTRUCTURE_Content-Dispositiong-20120731.patch
| File 5799-BODYSTRUCTURE_Content-Dispositiong-20120731.patch, 4.9 KB (added by argonemyth, 11 months ago) |
|---|
-
twisted/mail/test/test_imap.py
885 885 self.assertEqual(L, expected, 886 886 "len(%r) = %r != %r" % (input, L, expected)) 887 887 888 889 def test_IfQuotedString(self): 890 """ 891 The strings passed to L{imap4._ifQuotedString} are not tokens, so 892 1 should be returned. 893 """ 894 inputs = [ 895 'some ramdom stuff', 896 '(twisted)', 897 '<twisted>', 898 'twisted@', 899 'twisted,', 900 'twisted;', 901 'twisted:', 902 'twisted\\', 903 'twisted"', 904 'twisted/', 905 '[twisted]', 906 'twisted?', 907 'twisted=', 908 ] 909 910 # Add all the control characters 911 for i in range(33): 912 inputs.append('twiste'+ chr(i) + 'd') 913 914 for i in inputs: 915 self.assertEqual(imap4._ifQuotedString(i), 1) 916 917 918 888 919 class SimpleMailbox: 889 920 implements(imap4.IMailboxInfo, imap4.IMailbox, imap4.ICloseableMailbox) 890 921 … … 3457 3488 structure) 3458 3489 3459 3490 3491 def test_singlePartDisposition(self): 3492 """ 3493 For some content-disposition parameter values, 3494 L{imap4.getBodyStructure} returns quoted-string. 3495 """ 3496 body = 'hello, world' 3497 major = 'image' 3498 minor = 'jpeg' 3499 charset = 'us-ascii' 3500 msg = FakeyMessage({ 3501 'content-type': '%s/%s; charset=%s; x=y' % ( 3502 major, minor, charset), 3503 'content-disposition': 'attachment; filename=foo (doc).pdf; ' \ 3504 'size=bar; creation-date-parm=somedate; ' \ 3505 'modification-date-parm=somedate; ' \ 3506 'read-date-parm=somedate', 3507 }, (), '', body, 123, None) 3508 structure = imap4.getBodyStructure(msg, extended=True) 3509 self.assertEqual( 3510 [major, minor, ["charset", charset, 'x', 'y'], None, 3511 None, None, len(body), None, 3512 ['attachment', ['filename', '"foo (doc).pdf"', 'size', 'bar', 3513 'creation-date-parm', '"somedate"', 3514 'modification-date-parm', '"somedate"', 3515 'read-date-parm', '"somedate"']], None, None], 3516 structure) 3517 3518 3460 3519 def test_textPart(self): 3461 3520 """ 3462 3521 For a I{text/*} message, the number of lines in the message body are -
twisted/mail/imap4.py
4327 4327 return 1 4328 4328 return 0 4329 4329 4330 # tspecial in RFC 2045 4331 _TSPECIALS = r'()<>@,;:\"/[]?=' 4332 def _ifQuotedString(s): 4333 """ 4334 It determines if a string is a token or quoted-string. 4335 @see: U{http://www.ietf.org/rfc/rfc2045.txt} 4336 4337 @type s: C{str} 4338 @param s: The string needs to be checked 4339 4340 @return: 1 if the string needs quotation marks, 0 is the 4341 string is a token. 4342 """ 4343 if s == '': 4344 return 1 4345 for c in s: 4346 # ASCII characters without control characters 4347 if c <= '\x20' or c > '\x7f': 4348 return 1 4349 if c in _TSPECIALS: 4350 return 1 4351 return 0 4352 4330 4353 def _prepareMailboxName(name): 4331 4354 name = name.encode('imap4-utf-7') 4332 4355 if _needsQuote(name): … … 4895 4918 Parse a I{Content-Disposition} header into a two-sequence of the 4896 4919 disposition and a flattened list of its parameters. 4897 4920 4921 According to RFC2183, the following parameter values will be quoted: 4922 1. Values of date parameters 4923 2. A short parameter (length <= 78 characters) value containing 4924 only ASCII characters, but including tspecials characters. 4925 4898 4926 @return: C{None} if there is no disposition header value, a C{list} with 4899 4927 two elements otherwise. 4900 4928 """ … … 4904 4932 disp = (disp[0].lower(), None) 4905 4933 elif len(disp) > 1: 4906 4934 # XXX Poorly tested parser 4907 params = [x for param in disp[1:] for x in param.split('=', 1)] 4935 date_params = ['creation-date-parm', 'modification-date-parm', 4936 'read-date-parm'] 4937 params = [] 4938 for param in disp[1:]: 4939 key, value = param.split('=') 4940 params.append(key) 4941 if key in date_params: 4942 params.append(_quote(value)) 4943 elif len(value) <= 78 and _ifQuotedString(value): 4944 params.append(_quote(value)) 4945 else: 4946 params.append(value) 4908 4947 disp = [disp[0].lower(), params] 4948 4909 4949 return disp 4910 4950 else: 4911 4951 return None
