Class: Net::IMAP::ValidNonLiteralData
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Subclasses:
|
|
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
CommandData
|
|
|
Instance Chain:
self,
CommandData
|
|
| Inherits: |
Net::IMAP::CommandData
|
| Defined in: | lib/net/imap/command_data.rb |
Overview
Represents IMAP text or quoted data, which share the same
validations of decoded #data, and differ only in how they are formatted.
data may contain any 7-bit ASCII character except NULL, CR, or LF.
Any multibyte UTF-8 character is also allowed when the connection
supports UTF8: either UTF8=ACCEPT or IMAP4rev2 have been enabled, or
the server supports only IMAP4rev2 and not earlier ::Net::IMAP revisions, or
the server advertises UTF8=ONLY.
NOTE: This does not verify whether the connection supports UTF-8, but that may change in future versions.
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.
Class Method Summary
- .new(data:) ⇒ ValidNonLiteralData constructor
CommandData - Inherited
| .[] | Alias for CommandData.new. |
| .new, | |
| .validate | following class definition goes beyond the basic |
Instance Attribute Summary
Instance Method Summary
CommandData - Inherited
Constructor Details
.new(data:) ⇒ ValidNonLiteralData
# File 'lib/net/imap/command_data.rb', line 202
def initialize(data:) data = String(data.to_str) unless [Encoding::ASCII, Encoding::UTF_8].include?(data.encoding) data = data.dup.force_encoding(data.ascii_only? ? "ASCII" : "UTF-8") end data = -data super validate end
Instance Attribute Details
#ascii_only? ⇒ Boolean (readonly)
[ GitHub ]
# File 'lib/net/imap/command_data.rb', line 224
def ascii_only?; data.ascii_only? end
Instance Method Details
#send_data(imap, tag = nil)
[ GitHub ]# File 'lib/net/imap/command_data.rb', line 226
def send_data(imap, tag = nil) imap.__send__(:put_string, formatted) end
#validate
[ GitHub ]# File 'lib/net/imap/command_data.rb', line 212
def validate if ![Encoding::ASCII, Encoding::UTF_8].include?(data.encoding) raise DataFormatError, "must use ASCII or UTF-8 encoding" elsif !data.valid_encoding? raise DataFormatError, "invalid UTF-8 must be literal encoded" elsif data.include?("\0") raise DataFormatError, "NULL byte must be binary literal encoded" elsif /[\r\n]/.match?(data) raise DataFormatError, "CR and LF bytes must be literal encoded" end end