Class: Net::IMAP::RawData
- Inherits:
-
CommandData
- Object
- Data
- CommandData
- Net::IMAP::RawData
- Defined in:
- lib/net/imap/command_data.rb
Overview
:nodoc:
Class Method Summary collapse
-
.split(data) ⇒ Object
Splits an input
stringinto an array of RawText and Literal/Literal8.
Instance Method Summary collapse
-
#initialize(data:) ⇒ RawData
constructor
A new instance of RawData.
- #send_data(imap, tag) ⇒ Object
- #validate ⇒ Object
Methods inherited from CommandData
Constructor Details
#initialize(data:) ⇒ RawData
Returns a new instance of RawData.
241 242 243 244 245 246 247 248 249 250 |
# File 'lib/net/imap/command_data.rb', line 241 def initialize(data:) case data in String then data = self.class.split(data) in Array if data.all? { _1 in RawText | Literal } else raise TypeError, "expected String or Array[#{RawText} | #{Literal}]" end super validate end |
Class Method Details
.split(data) ⇒ Object
Splits an input string into an array of RawText and Literal/Literal8.
NOTE: unlike RawData#validate, this does not prevent the final RawText from ending with a literal prefix.
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/net/imap/command_data.rb', line 265 def self.split(data) data = data.b # dups and ensures BINARY encoding parts = [] text_start = 0 while data.match(/(~)?\{(0|[1-9]\d*)(\+)?\}\r\n/n, text_start) text, binary, bytesize, non_sync, literal_start = data.byteslice(text_start...$~.begin(0)), !!$1, $2, !!$3, $~.end(0) bytesize = NumValidator.coerce_number64 bytesize text_start = literal_start + bytesize parts << RawText[text] unless text.empty? parts << extract_literal(data, literal_start, bytesize, binary:, non_sync:) end parts << RawText[data.byteslice(text_start..)] if text_start < data.bytesize parts end |
Instance Method Details
#send_data(imap, tag) ⇒ Object
252 |
# File 'lib/net/imap/command_data.rb', line 252 def send_data(imap, tag) = data.each do _1.send_data(imap, tag) end |
#validate ⇒ Object
254 255 256 257 258 259 |
# File 'lib/net/imap/command_data.rb', line 254 def validate return unless data.last in RawText(data: text) if text.rindex(/\{\d+\+?\}\z/n) raise DataFormatError, "RawData cannot end with literal continuation" end end |