Class: Sanguinews::NntpMsg
- Inherits:
-
Object
- Object
- Sanguinews::NntpMsg
- Defined in:
- lib/sanguinews/nntp_msg.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#from ⇒ Object
Returns the value of attribute from.
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#message ⇒ Object
Returns the value of attribute message.
-
#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 = '', date = nil, poster = nil) ⇒ NntpMsg
constructor
A new instance of NntpMsg.
- #return_self ⇒ Object
- #size ⇒ Object
- #yenc_body(current_part, parts, crc32, pcrc32, part_size, file_size, filename) ⇒ Object
Constructor Details
#initialize(from, groups, subject, message = '', date = nil, poster = nil) ⇒ NntpMsg
Returns a new instance of NntpMsg.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sanguinews/nntp_msg.rb', line 25 def initialize(from, groups, subject, ='', date=nil, poster=nil) @from = from @groups = groups @subject = subject @message = if date.nil? @date = DateTime.now().strftime('%a, %d %b %Y %T %z') else @date = date end @poster = poster if !poster.nil? end |
Instance Attribute Details
#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 |
#message ⇒ Object
Returns the value of attribute message.
23 24 25 |
# File 'lib/sanguinews/nntp_msg.rb', line 23 def @message 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
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sanguinews/nntp_msg.rb', line 38 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}" unless poster.nil? 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
72 73 74 75 76 |
# File 'lib/sanguinews/nntp_msg.rb', line 72 def return_self header = self.create_header header << @message return header end |
#size ⇒ Object
78 79 80 |
# File 'lib/sanguinews/nntp_msg.rb', line 78 def size return @message.length end |
#yenc_body(current_part, parts, crc32, pcrc32, part_size, file_size, filename) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/sanguinews/nntp_msg.rb', line 52 def yenc_body(current_part, parts, crc32, pcrc32, part_size, file_size, filename) chunk_start = ((current_part - 1) * part_size) + 1 chunk_end = current_part * part_size 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=#{part_size} part=#{current_part} pcrc32=#{pcrc32} crc32=#{crc32}" else trailer = "=yend size=#{part_size} part=#{current_part} pcrc32=#{pcrc32}" end end headerline << "\n#{@message}\n" headerline << trailer @message = headerline end |