Class: Net::IMAP::RawText
- Inherits:
-
CommandData
- Object
- Data
- CommandData
- Net::IMAP::RawText
- Defined in:
- lib/net/imap/command_data.rb
Overview
Represents IMAP text data, which may contain any 7-bit ASCII character, except for NULL, CR, or LF. text is extended to allow any multibyte UTF-8 character when either UTF8=ACCEPT or IMAP4rev2 have been enabled, or when the server supports only IMAP4rev2 and not earlier IMAP revisions, or when the server advertises UTF8=ONLY.
NOTE: The current implementation does not validate whether the connection currently supports UTF-8. Future versions may change.
The string’s bytes must be valid ASCII or valid UTF-8. The string’s reported encoding is ignored, but the string is not transcoded.
Instance Method Summary collapse
- #ascii_only? ⇒ Boolean
-
#initialize(data:) ⇒ RawText
constructor
:nodoc:.
- #send_data(imap, tag) ⇒ Object
- #validate ⇒ Object
Methods inherited from CommandData
Constructor Details
#initialize(data:) ⇒ RawText
:nodoc:
169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/net/imap/command_data.rb', line 169 def initialize(data:) data = String(data.to_str) data = if data.encoding in Encoding::ASCII | Encoding::UTF_8 -data elsif data.ascii_only? -(data.dup.force_encoding("ASCII")) else -(data.dup.force_encoding("UTF-8")) end super validate end |
Instance Method Details
#ascii_only? ⇒ Boolean
192 |
# File 'lib/net/imap/command_data.rb', line 192 def ascii_only? = data.ascii_only? |
#send_data(imap, tag) ⇒ Object
194 |
# File 'lib/net/imap/command_data.rb', line 194 def send_data(imap, tag) = imap.__send__(:put_string, data) |
#validate ⇒ Object
182 183 184 185 186 187 188 189 190 |
# File 'lib/net/imap/command_data.rb', line 182 def validate if data.include?("\0") raise DataFormatError, "NULL byte must be binary literal encoded" elsif !data.valid_encoding? raise DataFormatError, "invalid UTF-8 must be literal encoded" elsif /[\r\n]/.match?(data) raise DataFormatError, "CR and LF bytes must be literal encoded" end end |