flnews_post_proc 2.05 → 2.09

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/basic_logging.rb CHANGED
@@ -26,7 +26,7 @@ module BasicLogging
26
26
  ERROR = 3
27
27
  FATAL = 4
28
28
  UNKNOWN = nil
29
-
29
+
30
30
  # this is mainly for the translation of method calls into log levels
31
31
  Levels = {:debug => DEBUG, :info => INFO, :warn => WARN, :error => ERROR,
32
32
  :fatal => FATAL, :unknown => UNKNOWN}
@@ -34,7 +34,7 @@ module BasicLogging
34
34
  @@log_level = UNKNOWN
35
35
  @@target = STDOUT
36
36
  @@muted = []
37
-
37
+
38
38
  # do not log, if caller is obj (class or instance)
39
39
  def self.mute(obj)
40
40
  name = obj.class == Class ? obj.name.dup : obj.class.name
@@ -72,7 +72,11 @@ module BasicLogging
72
72
  elsif !tg || tg.respond_to?(:to_str) && tg.strip.empty?
73
73
  @@target = nil
74
74
  elsif(!File::exist?(tg) || ( File.file?(tg) && File.writable?(tg) ) )
75
- @@target = File.open(tg, 'w+')
75
+ begin
76
+ @@target = File.open(tg, 'w+')
77
+ rescue Exception => ex
78
+ $stderr.puts 'Cannot open log target ' << tg << ': ' << ex.message
79
+ end
76
80
  else
77
81
  STDERR.puts calling_method << ': ERROR : target ' << tg.to_str << ' cannot be set'
78
82
  STDERR.puts "Keeping old target " << @@target.inspect
@@ -157,7 +161,7 @@ module BasicLogging
157
161
  return 'from main'
158
162
  end
159
163
  end
160
-
164
+
161
165
  # could be useful
162
166
  def lock_target(&block)
163
167
  begin
data/lib/body.rb CHANGED
@@ -209,8 +209,15 @@ class Body
209
209
  ref_delim = @@config.REFERENCES_DELIMITER
210
210
  debug('references delimiter is ' << ref_delim)
211
211
  references = Array.new
212
- # avoids a lot of trouble
213
- body = @lines.join($LN).force_encoding('utf-8')
212
+ # avoids a lot of trouble.
213
+ # The encoding must be set before calling join().
214
+ # New in Ruby 4.1.0
215
+ # Should be unneeded, as the encoding is enforced
216
+ # after reading from STDIN.
217
+ @lines.each {|l| l.force_encoding('UTF-8')}
218
+ # ... but still is.
219
+ # -----------------
220
+ body = @lines.join($LN)
214
221
  if ref_delim && !ref_delim.strip.empty?
215
222
  unless ref_delim == ref_delim.reverse
216
223
  ref_delim.strip!
data/lib/configuration.rb CHANGED
@@ -28,7 +28,7 @@ class Configuration
28
28
 
29
29
  def initialize()
30
30
  debug 'Configuration::initialize()'
31
- confname = PROGNAME << '.conf'
31
+ confname = PROGNAME.dup << '.conf'
32
32
  # try to open user-configuration
33
33
  @config_file = ENV['HOME'].dup << File::Separator << '.' << confname
34
34
  # if user-configuration does not exist, copy installed version.
@@ -82,9 +82,16 @@ GROUP_SIGS:
82
82
  # DEFAULT: undefined
83
83
  # EXAMPLE (two headers):
84
84
  # - 'X-My-Header: nothing fancy'
85
- # - 'X-Post-Processor: flnews_post_proc'
85
+ # - 'X-My-Dog: Labcoat Retriever'
86
86
  CUSTOM_HEADERS:
87
- - "X-Post-Processor: flnews_post_proc"
87
+
88
+ # NAME_POSTPROCESSOR
89
+ # If set, creates a custom header with the name of the post processor and its
90
+ # current version. This setting is independent of CUSTOM_HEADERS, above.
91
+ #
92
+ # DEFAULT: no, false or unset
93
+ # EXAMPLE: true
94
+ NAME_POSTPROCESSOR:
88
95
 
89
96
  # NO_ARCHIVE_GROUPS:
90
97
  # The newsgroups, where a header X-No-Archive: YES shall be set.
data/lib/headers.rb CHANGED
@@ -17,6 +17,7 @@ require 'rfc_2047'
17
17
  require_relative 'basic_logging'
18
18
  require_relative 'configuration'
19
19
  require_relative 'newsgroups'
20
+ require_relative 'version'
20
21
 
21
22
  # an object of this class represents the headers of a news-article
22
23
 
@@ -139,7 +140,7 @@ class Headers
139
140
  # Ensure header is ascii only
140
141
  if hv.ascii_only? && hn.ascii_only?
141
142
  # <---------- special treatment Post-Processor ---------->
142
- hv << ' ' << PROGVERSION.to_s if hn == 'X-Post-Processor' && hv == 'flnews_post_proc'
143
+ # hv << ' ' << PROGVERSION.to_s if hn == 'X-Post-Processor' && hv == 'flnews_post_proc'
143
144
  # >----------<
144
145
  @headers[hn.to_sym] = hv
145
146
  else
@@ -149,8 +150,11 @@ class Headers
149
150
  end
150
151
  @headers[hn.to_sym] = hv
151
152
  end
152
- @headers.compact!
153
153
  end
154
+ if @config.NAME_POSTPROCESSOR
155
+ @headers["X-Post-Processor".to_sym] = PROGNAME.dup << ' ' << PROGVERSION.to_s
156
+ end
157
+ @headers.compact!
154
158
  debug('updated headers are ' << @headers.inspect)
155
159
  end
156
160
 
data/lib/newsgroups.rb CHANGED
@@ -120,6 +120,7 @@ class Newsgroups
120
120
  end # gsigs.each
121
121
  end # gsigs for group?
122
122
  if tsig && tsig.rstrip.start_with?('/')
123
+ debug 'trying to pick a random signature'
123
124
  tsig = pick_sig(tsig.strip)
124
125
  end
125
126
  @signature = correct_linebreaks(tsig) if tsig
@@ -147,6 +148,7 @@ class Newsgroups
147
148
  if(psrc )
148
149
  psrc = psrc[1]
149
150
  if File.exist?(psrc) && File.readable?(psrc)
151
+ debug 'reading signature file'
150
152
  ssigs = File.read(psrc).split(delim)
151
153
  else
152
154
  warn 'cannot find or read sourced signature file: ' << psrc
@@ -165,7 +167,10 @@ class Newsgroups
165
167
 
166
168
  # srand(Time.now.nsec)
167
169
  srand()
168
- return all_sigs[rand(numSigs)]
170
+ psig = all_sigs[rand(numSigs)]
171
+ debug "HAVE a signature: \n\t" << (psig ? psig : ' N I L ')
172
+ rearrange_sigs(sigfile, all_sigs)
173
+ return psig
169
174
  else
170
175
  warn 'cannot find or read signature file: ' << sigfile
171
176
  end
@@ -174,7 +179,6 @@ class Newsgroups
174
179
 
175
180
  # write a new rearranged version of the signature file for
176
181
  # better hazard.
177
- # UNUSED
178
182
  def rearrange_sigs(sigfile, all_sigs)
179
183
  if File.writable?(sigfile)
180
184
  new_sigs = Array.new(all_sigs.length)
data/lib/version.rb CHANGED
@@ -14,7 +14,7 @@
14
14
  =end
15
15
 
16
16
  PROGNAME = 'flnews_post_proc'
17
- PROGVERSION = "2.05"
17
+ PROGVERSION = "2.09"
18
18
  AUTHORS = "Michael Uplawski"
19
19
  EMAIL = "michael.uplawski@uplawski.eu"
20
20
  YEARS = "2023 - 2026"