patterns.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # encoding: us-ascii
  2. module Mail
  3. module Patterns
  4. white_space = %Q|\x9\x20|
  5. text = %Q|\x1-\x8\xB\xC\xE-\x7f|
  6. field_name = %Q|\x21-\x39\x3b-\x7e|
  7. qp_safe = %Q|\x20-\x3c\x3e-\x7e|
  8. aspecial = %Q|()<>[]:;@\\,."| # RFC5322
  9. tspecial = %Q|()<>@,;:\\"/[]?=| # RFC2045
  10. lwsp = %Q| \t\r\n|
  11. sp = %Q| |
  12. control = %Q|\x00-\x1f\x7f-\xff|
  13. if control.respond_to?(:force_encoding)
  14. control = control.force_encoding(Encoding::BINARY)
  15. end
  16. CRLF = /\r\n/
  17. WSP = /[#{white_space}]/
  18. FWS = /#{CRLF}#{WSP}*/
  19. TEXT = /[#{text}]/ # + obs-text
  20. FIELD_NAME = /[#{field_name}]+/
  21. FIELD_BODY = /.+/
  22. FIELD_LINE = /^[#{field_name}]+:\s*.+$/
  23. HEADER_LINE = /^([#{field_name}]+:\s*.+)$/
  24. QP_UNSAFE = /[^#{qp_safe}]/
  25. QP_SAFE = /[#{qp_safe}]/
  26. CONTROL_CHAR = /[#{control}]/n
  27. ATOM_UNSAFE = /[#{Regexp.quote aspecial}#{control}#{sp}]/n
  28. PHRASE_UNSAFE = /[#{Regexp.quote aspecial}#{control}]/n
  29. TOKEN_UNSAFE = /[#{Regexp.quote tspecial}#{control}#{sp}]/n
  30. end
  31. end