Class: Net::NNTP::PostingRequest
- Defined in:
- lib/net/nntp/request.rb
Overview
Posting Request Base class.
Do NOT instantiate, use subclasses Post or Ihave.
Instance Method Summary collapse
-
#body ⇒ Object
Returns the body attribute; given a block, sets the body from the result of that block first.
-
#body=(body) ⇒ Object
Sets the body of the posting to be transmitted.
-
#initialize(keyword, param = nil) ⇒ PostingRequest
constructor
A new instance of PostingRequest.
Methods inherited from Request
#capability, #command, #dotstuff, #msgid_or_range, #range, #valid_response?
Constructor Details
#initialize(keyword, param = nil) ⇒ PostingRequest
Returns a new instance of PostingRequest.
524 525 526 |
# File 'lib/net/nntp/request.rb', line 524 def initialize(keyword, param=nil) super keyword, param end |
Instance Method Details
#body ⇒ Object
Returns the body attribute; given a block, sets the body from the result of that block first.
575 576 577 578 579 580 |
# File 'lib/net/nntp/request.rb', line 575 def body if block_given? self.body = yield end @body end |
#body=(body) ⇒ Object
Sets the body of the posting to be transmitted.
Do NOT use any dot stuffing or <CRLF>.<CRLF> sequences - dot-stuffing will happen automatically when sending.
body
can be a TMail::Mail object, a string or any line-based IO object supporting readline
, where the content has to be a valid mail, able to be parsed. The body attribute will be set to a TMail::Mail object, ready to be sent.
Example
# ...
request = Post.new # use subclass Post
request.body =<<-EOF
Newsgroups: alt.test
From: Demo User <[email protected]>
Subject: I am a test posting
This is just a test posting
EOF
puts request.body.to_s
# => From: Demo User <[email protected]>
# => Subject: I am a test posting
# => Newsgroups: alt.test
# =>
# => This is just a test posting.
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 |
# File 'lib/net/nntp/request.rb', line 554 def body=(body) if body.is_a?(TMail::Mail) @body = body else if body.respond_to? :readline begin raw = '' loop do line = body.readline raw << line end rescue EOFError => e end else raw = body end @body = TMail::Mail.parse(raw) end end |