lib/newsgroups.rb in flnews_post_proc-1.62 vs lib/newsgroups.rb in flnews_post_proc-1.70
- old
+ new
@@ -73,17 +73,19 @@
end
end
# replace all \n by \r\n
def correct_linebreaks(text)
+ debug 'correcting linebreaks in ' << text
warned = false
# find all lonely \n
while text.match(/([^\r])\n/) do
warn("ATTN! Line-breaks should be \\r\\n! Verify signatures!" ) if !warned
warned ||= true
# ... and silently marry them to \r
text.gsub!($~[0],$~[1] + "\r\n")
+ text.gsub!("\n ", "\n")
# Luxury you can afford.
end # \n
text
end
@@ -91,34 +93,52 @@
def set_signature
@signature = nil
# 1 group
group = @groups[0]
gsigs = @config.GROUP_SIGS
+ tsig = nil
if gsigs && gsigs.respond_to?(:to_hash)
# find the signature for the group
# either by name
if gsigs.keys.include?(group)
- @signature = gsigs[group]
- debug('signature is ' << @signature ) if @signature
+ tsig = gsigs[group]
+ debug('signature is ' << tsig ) if tsig
# .., or by applying a regexp.
else
gsigs.each do |g, s|
- unless @signature
+ unless tsig
rg = Regexp.new(g)
sm = group.match(rg)
debug('signature for group(s) ' << g << ': ' << s) if sm
if sm
- @signature = correct_linebreaks(s)
- @signature.gsub!("\n ", "\n")
+ tsig = s
end # if sm
end # if no signature
end # gsigs.each
end # gsigs for group?
+ if tsig && tsig.start_with?('/')
+ tsig = pick_sig(tsig)
+ end
+ @signature = correct_linebreaks(tsig) if tsig
else # gsigs and is hash?
msg = "Cannot read the signatures from the configuration."
msg << "\nPlease verify that GROUP_SIGS is set."
warn(msg)
+ end
+ end
+
+ # pick a random signature
+ def pick_sig(sigfile)
+ debug 'picking signature from ' << sigfile.to_s
+ if sigfile && !sigfile.empty? && File.exist?(sigfile) && File.readable?(sigfile)
+ allSigs = File::read(sigfile).split("\n\n")
+ numSigs = allSigs.length
+ srand(Time.now.nsec)
+ allSigs[rand(numSigs)]
+ else
+ error 'Cannot read signature from file ' << sigfile
+ nil
end
end
# define the no_archive header.
def set_no_archive