Ticket #5799: 5799-BODYSTRUCTURE_Content-Dispositiong-20120801.patch
| File 5799-BODYSTRUCTURE_Content-Dispositiong-20120801.patch, 5.0 KB (added by argonemyth, 10 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 C{True} 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), True) 916 917 918 def test_IfTokens(self): 919 """ 920 The strings passed to L{imap4._ifQuotedString} are tokens, so 921 C{False} should be returned. 922 """ 923 result = imap4._ifQuotedString("I'm.a.token!") 924 self.assertEqual(result, False) 925 926 927 888 928 class SimpleMailbox: 889 929 implements(imap4.IMailboxInfo, imap4.IMailbox, imap4.ICloseableMailbox) 890 930 … … 3457 3497 structure) 3458 3498 3459 3499 3500 def test_singlePartDisposition(self): 3501 """ 3502 For some content-disposition parameter values, 3503 L{imap4.getBodyStructure} returns quoted-string. 3504 """ 3505 body = 'hello, world' 3506 major = 'image' 3507 minor = 'jpeg' 3508 charset = 'us-ascii' 3509 msg = FakeyMessage({ 3510 'content-type': '%s/%s; charset=%s; x=y' % ( 3511 major, minor, charset), 3512 'content-disposition': 'attachment; filename=foo (doc).pdf; ' \ 3513 'size=bar; creation-date=somedate; ' \ 3514 'modification-date=somedate; read-date=somedate', 3515 }, (), '', body, 123, None) 3516 structure = imap4.getBodyStructure(msg, extended=True) 3517 self.assertEqual( 3518 [major, minor, ["charset", charset, 'x', 'y'], None, 3519 None, None, len(body), None, 3520 ['attachment', ['filename', '"foo (doc).pdf"', 'size', 'bar', 3521 'creation-date', '"somedate"', 3522 'modification-date', '"somedate"', 3523 'read-date', '"somedate"']], None, None], 3524 structure) 3525 3526 3460 3527 def test_textPart(self): 3461 3528 """ 3462 3529 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: True if the string needs quotation marks, False if the 4341 string is a token. 4342 """ 4343 if s == '': 4344 return True 4345 for c in s: 4346 # ASCII characters without control characters 4347 if c <= '\x20' or c > '\x7f': 4348 return True 4349 if c in _TSPECIALS: 4350 return True 4351 return False 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. Values contain only ASCII characters, but including 4924 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', 'modification-date', 4936 'read-date'] 4937 params = [] 4938 for param in disp[1:]: 4939 key, value = param.split('=') 4940 params.append(key) 4941 if key in date_params or _ifQuotedString(value): 4942 params.append(_quote(value)) 4943 else: 4944 params.append(value) 4908 4945 disp = [disp[0].lower(), params] 4909 4946 return disp 4910 4947 else:
