Class: Sanguinews::NntpMsg
- Inherits:
-
Object
- Object
- Sanguinews::NntpMsg
- Defined in:
- lib/sanguinews/nntp_msg.rb
Instance Attribute Summary collapse
-
#crc32 ⇒ Object
Returns the value of attribute crc32.
-
#date ⇒ Object
Returns the value of attribute date.
-
#from ⇒ Object
Returns the value of attribute from.
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#length ⇒ Object
Returns the value of attribute length.
-
#message ⇒ Object
Returns the value of attribute message.
-
#part_crc32 ⇒ Object
Returns the value of attribute part_crc32.
-
#poster ⇒ Object
Returns the value of attribute poster.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#xna ⇒ Object
Returns the value of attribute xna.
Instance Method Summary collapse
- #create_header ⇒ Object
-
#initialize(from, groups, subject, message = '', **opts) ⇒ NntpMsg
constructor
A new instance of NntpMsg.
- #return_self ⇒ Object
- #size ⇒ Object
- #unset ⇒ Object
- #yenc_body(current_part, parts, file_size, filename) ⇒ Object
Constructor Details
#initialize(from, groups, subject, message = '', **opts) ⇒ NntpMsg
Returns a new instance of NntpMsg.
25 26 27 28 29 30 31 32 33 |
# File 'lib/sanguinews/nntp_msg.rb', line 25 def initialize(from, groups, subject, ='', **opts) @from = from @groups = groups @subject = subject @message = @date = opts[:date] if opts[:date] @date ||= DateTime.now().strftime('%a, %d %b %Y %T %z') @poster = "sanguinews v#{Sanguinews::VERSION} (ruby #{RUBY_VERSION}) - https://github.com/tdobrovolskij/sanguinews" end |
Instance Attribute Details
#crc32 ⇒ Object
Returns the value of attribute crc32.
23 24 25 |
# File 'lib/sanguinews/nntp_msg.rb', line 23 def crc32 @crc32 end |
#date ⇒ Object
Returns the value of attribute date.
23 24 25 |
# File 'lib/sanguinews/nntp_msg.rb', line 23 def date @date end |
#from ⇒ Object
Returns the value of attribute from.
23 24 25 |
# File 'lib/sanguinews/nntp_msg.rb', line 23 def from @from end |
#groups ⇒ Object
Returns the value of attribute groups.
23 24 25 |
# File 'lib/sanguinews/nntp_msg.rb', line 23 def groups @groups end |
#length ⇒ Object
Returns the value of attribute length.
23 24 25 |
# File 'lib/sanguinews/nntp_msg.rb', line 23 def length @length end |
#message ⇒ Object
Returns the value of attribute message.
23 24 25 |
# File 'lib/sanguinews/nntp_msg.rb', line 23 def @message end |
#part_crc32 ⇒ Object
Returns the value of attribute part_crc32.
23 24 25 |
# File 'lib/sanguinews/nntp_msg.rb', line 23 def part_crc32 @part_crc32 end |
#poster ⇒ Object
Returns the value of attribute poster.
23 24 25 |
# File 'lib/sanguinews/nntp_msg.rb', line 23 def poster @poster end |
#subject ⇒ Object
Returns the value of attribute subject.
23 24 25 |
# File 'lib/sanguinews/nntp_msg.rb', line 23 def subject @subject end |
#xna ⇒ Object
Returns the value of attribute xna.
23 24 25 |
# File 'lib/sanguinews/nntp_msg.rb', line 23 def xna @xna end |
Instance Method Details
#create_header ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/sanguinews/nntp_msg.rb', line 35 def create_header sio = StringIO.new("", "w:ASCII-8BIT") sio.puts "From: #{@from}" sio.puts "Newsgroups: #{@groups}" sio.puts "Subject: #{@subject}" sio.puts "X-Newsposter: #{@poster}" if @poster sio.puts "X-No-Archive: yes" if @xna sio.puts "Date: #{@date}" sio.puts header = sio.string sio.close return header end |
#return_self ⇒ Object
69 70 71 72 |
# File 'lib/sanguinews/nntp_msg.rb', line 69 def return_self header = self.create_header header << @message end |
#size ⇒ Object
74 75 76 |
# File 'lib/sanguinews/nntp_msg.rb', line 74 def size return @message.length end |
#unset ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/sanguinews/nntp_msg.rb', line 78 def unset @from = nil @groups = nil @subject = nil @poster = nil @date = nil @message = nil end |
#yenc_body(current_part, parts, file_size, filename) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/sanguinews/nntp_msg.rb', line 49 def yenc_body(current_part, parts, file_size, filename) chunk_start = ((current_part - 1) * @length) + 1 chunk_end = current_part * @length if (parts==1) headerline = "=ybegin line=128 size=#{file_size} name=#{filename}" trailer = "=yend size=#{file_size} crc32=#{@crc32}" else headerline = "=ybegin part=#{current_part} total=#{parts} line=128 size=#{file_size} name=#{filename}\n=ypart begin=#{chunk_start} end=#{chunk_end}" # last part if (current_part == parts) trailer = "=yend size=#{@length} part=#{current_part} pcrc32=#{@part_crc32} crc32=#{@crc32}" else trailer = "=yend size=#{@length} part=#{current_part} pcrc32=#{@part_crc32}" end end headerline << "\n#{@message}\n" headerline << trailer @message = headerline end |