flnews_post_proc 2.10 → 2.12

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8977d9ca15b69d4f0b395455fa34932f0de7f207cf89e5c88c40c972fb4f157c
4
- data.tar.gz: dfdf3b04dd9e70c2a30a751f384513dab23fd8b7ca9d2cbcce58c2b315840e3f
3
+ metadata.gz: e0319e60ee65604f7cfbe6dece9148bd6f82371477cbaedeae31ce4ad6e3d89e
4
+ data.tar.gz: 86a8588522782ff63652898cc5962e84f35c2ee590b6fc11c48a121c72bc098f
5
5
  SHA512:
6
- metadata.gz: b8e1135cc978558cbf81fdfec34e25e900d85884b6fd65ee1327d0d460beb7d7d585636401ddd1eb6098a7192c7dd07fa3f331759d84967adb2d8aefbe93b2c6
7
- data.tar.gz: 7f50f9aa1ff86cd8686a6832d80041a5451681d86e637d5db762842ab34ef75e395ba294650036e0bc8e42dac3b2e7a582619b96d15095c63331b2062e3e5d9c
6
+ metadata.gz: 8f4f8876f9076612c829a76cfb030c03f9b34b031488996a90ac61a8f20c518fecd0a460eac0f18793385c4757e829ea76c3c9999b2e608c9b1c493770df3b0d
7
+ data.tar.gz: 8e7a650ccb784185881facfb148691634071ecef4958187b38837990836747f543ea71ca20d80e302c62e41b10bb970db2cfd20c07991a91e56c3289571e612c
data/README.md CHANGED
@@ -340,6 +340,33 @@ DEFAULT: yes
340
340
 
341
341
  EXAMPLE: No
342
342
 
343
+ ** USE_OLD**
344
+ A Boolean constant. The post processor can handle subject changes in the way, that
345
+ old subjects which are preceded by variations of the string '(Was:' are automatically
346
+ removed from the header. This imposes, that our own subject changes must be ignored!
347
+ This behavior is activated here and necessitates that our own subject changes
348
+ are indicated with a prefix "(Old:". It will be replaced by "(Was:" in the
349
+ posted article.
350
+
351
+ Set this option to true, when you want to use the prefix
352
+ "(Old:", or to false, no, NO or similar if you do not want subject changes
353
+ handled by the program.
354
+
355
+ DEFAULT: No
356
+
357
+ EXAMPLE: false
358
+
359
+ **Draft_DIR**
360
+ The path to a directory for draft messages.
361
+ ONLY if OVERRIDE_CONFIG, above, is active, you can choose to *not send* but only
362
+ to save the current message to a file in this directory.
363
+ If left empty, the temporary directory from the environment variable $TEMP will
364
+ be used to store draft messages.
365
+
366
+ DEFAULT: empty
367
+
368
+ EXAMPLE: ~/.flnews_post_proc_drafts
369
+
343
370
  Other Information
344
371
  =================
345
372
 
data/bin/flnews_post_proc CHANGED
@@ -29,16 +29,26 @@ require_relative '../lib/override'
29
29
  require_relative '../lib/flnews_post_proc'
30
30
  require_relative '../lib/basic_logging'
31
31
  require_relative '../lib/configuration'
32
+ require_relative '../lib/color_output'
32
33
  require_relative '../lib/version'
33
34
 
34
35
  self.extend(BasicLogging)
35
36
 
36
37
  def usage
37
- usage = "\nWhat do you want me to do? Where is the article to post-process?"
38
- usage << "\nUsage: "
39
- usage << "\n\t#{$0} < article.text"
40
- info usage
38
+ usage = bold(yellow("\nWhat do you want me to do? Where is the article to post-process?"))
39
+ usage << "\nflnews_post_proc, version " << PROGVERSION
40
+ usage << "\n\nNote the path “#{$0}“ in the " << lightgreen("flnews-configuration.") << "\nSee option " << lightgreen("“post_proc”")
41
+ usage << "\nFor testing with an article stored localy in a file, execute\n"
42
+ usage << bold("\nuser@machine:~\$ #{$0} < article.text\n")
43
+ usage << "\nSee the man page for more information or go to:\n"
44
+ usage << bold("https://www.uplawski.eu/div/flnews/gem_doc/html/flnews_post_proc.html")
45
+ usage << "\nLa documentation en français :\n"
46
+ usage << bold("https://www.uplawski.eu/div/flnews/gem_doc/fr\n")
47
+ # Order matters. The logging module alters the message,
48
+ # Call info only after the output on STDERR!
41
49
  STDERR.puts usage
50
+ # ... here:
51
+ info usage
42
52
  exit false
43
53
  end
44
54
 
data/changes.txt CHANGED
@@ -1,3 +1,20 @@
1
+ V. 2.12
2
+ *) Keywords header: Keywords can be extracted from the message body,
3
+ provided they are enclosed in the delimiter sequence, that can be set in
4
+ the configuration option “KEYWORDS_DELIMITER”. When the option is set
5
+ and when marked keywords are found, they will complete the Keywords
6
+ header in the outgoing message.
7
+
8
+ *) Logging: long lines may be wrapped, currently at the 100th symbol.
9
+ Original line breaks are kept intact and are marked in the output.
10
+
11
+ V. 2.11
12
+ *) Usage message improved and extended. Appears, when the program is
13
+ executed without input via STDIN.
14
+
15
+ *) Invalid directories in the PATH may trigger a warning message in the
16
+ log output and are then ignored (see previous entry for V. 2.10).
17
+
1
18
  V. 2.10
2
19
  *) Bugfix: The environment variable PATH may list inexistent directories.
3
20
  The program is prepared for that now and will not crash in those cases.
@@ -9,9 +26,9 @@ V. 2.09
9
26
  installed.
10
27
 
11
28
  V. 2.08
12
- *) Bugfix: A random signature could not be set due to
13
- the interfering process of rearranging them in the signature
14
- file. -> Changed the order of actions.
29
+ *) Bugfix: A random signature could not be set due to the interfering
30
+ process of rearranging them in the signature file.
31
+ -> I changed the order of actions.
15
32
  *) The gem tool suddenly imposes duplication of the homepage
16
33
  URL in the specs. Okay. Done. Beats me.
17
34
 
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0" encoding="utf-8"?>
2
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
3
3
  <head>
4
4
  <meta name="generator" content="vim - Vi Improved, a programmer's editor; HTML Tidy for Linux version 5.9.20
5
5
  "/>
@@ -32,7 +32,7 @@
32
32
  <p class="subtitle" id="post-traitement-pour-flnews">
33
33
  Post-Traitement pour flnews</p>
34
34
 
35
- <nav class="contents local" id="contents" role="doc-toc">
35
+ <nav class="contents local" id="sommaire" role="doc-toc">
36
36
  <ul class="simple">
37
37
  <li>
38
38
  <p><a class="reference internal" href="#synopsis" id=
@@ -982,7 +982,7 @@ alt.fr.test: /home/[utilisateur]/.signatures</pre>
982
982
  "https://creativecommons.org/licenses/by-nd/4.0/deed.fr">CC
983
983
  BY-ND 4.0</a></p>
984
984
 
985
- <p>Date: 2026-09-22</p>
985
+ <p>Date: 2026-11-02</p>
986
986
 
987
987
  <p>On peut accéder aux pages de manuel de la manière
988
988
  habituelle, en exécutant <em>man</em>
@@ -1002,7 +1002,7 @@ alt.fr.test: /home/[utilisateur]/.signatures</pre>
1002
1002
  </main>
1003
1003
 
1004
1004
  <div id='page_dt'>
1005
- 2026-09-22
1005
+ 2026-11-02
1006
1006
  </div>
1007
1007
  </body>
1008
1008
  </html>
Binary file
Binary file
@@ -331,6 +331,11 @@
331
331
  Usenet.</p>
332
332
  </li>
333
333
  </ul>
334
+
335
+ <figure>
336
+ <img alt="Screen shot - Override Dialog" class=
337
+ "sshot" src="../images/override_dialog.avif" />
338
+ </figure>
334
339
  </blockquote>
335
340
 
336
341
  <p>When your configuration contains the path to a
@@ -886,7 +891,7 @@ comp.*: /home/[user]/.my_sigs</pre>
886
891
  "https://creativecommons.org/licenses/by-nd/4.0/">CC
887
892
  BY-ND 4.0</a></p>
888
893
 
889
- <p>Date: 2026-09-22</p>
894
+ <p>Date: 2026-11-09</p>
890
895
  </blockquote>
891
896
 
892
897
  <p>The man page can be accessed in the ordinary way, by
@@ -905,7 +910,7 @@ comp.*: /home/[user]/.my_sigs</pre>
905
910
  </main>
906
911
 
907
912
  <div id='page_dt'>
908
- 2026-09-22
913
+ 2026-11-09
909
914
  </div>
910
915
  </body>
911
916
  </html>
Binary file
Binary file
@@ -128,6 +128,11 @@ Dialog for Overriding Settings
128
128
 
129
129
  * The current message can be saved as a draft, **instead** of being posted to Usenet.
130
130
 
131
+ .. figure:: ../images/override_dialog.avif
132
+ :alt: Screen shot - Override Dialog
133
+ :class: sshot
134
+ :loading: link
135
+
131
136
  When your configuration contains the path to a directory for these drafts (option `DRAFT_DIR`_), it will be used to store
132
137
  these draft messages, otherwise the temporary directory from the environment variable $TEMP.
133
138
 
data/lib/basic_logging.rb CHANGED
@@ -60,13 +60,11 @@ module BasicLogging
60
60
  msg = calling_method << ": ERROR : invalid log level \"" << lv.to_s << "\""
61
61
  msg << "\n" << "Keepinng old log level " << Levels.keys.detect {| k| Levels[k] == @@log_level}.to_s
62
62
  STDERR.puts msg
63
- # puts msg
64
63
  end
65
64
  end
66
65
 
67
66
  # set the log target
68
67
  def set_target(tg)
69
- # STDOUT.puts 'BASICLOGGING : Setting target to ' << tg.to_s
70
68
  if tg && tg.respond_to?(:to_io)
71
69
  @@target = tg
72
70
  elsif !tg || tg.respond_to?(:to_str) && tg.strip.empty?
@@ -138,6 +136,40 @@ module BasicLogging
138
136
 
139
137
  private
140
138
 
139
+ # Wrap function, stolen from the Web, than adapted.
140
+ # Works!
141
+ def wrap(text, width: 72)
142
+ # to keep line-breaks intact, mark them after the last word of a line.
143
+ text.gsub!("\n", "⮠ ")
144
+ # create an array of words
145
+ words = text.split(/\s+/)
146
+ # abort, if there aren't any.
147
+ return "" if words.empty?
148
+
149
+ lines = []
150
+ # NOTE that the 'line', is 1 word long, initially.
151
+ current_line = words.shift
152
+
153
+ words.each do |word|
154
+ # add words, if the maximum width will not be exceeded or the original
155
+ # text had not a line break after the current last word
156
+ if !current_line.end_with?("⮠") && current_line.length + 1 + word.length <= width
157
+ current_line << " " << word
158
+ else
159
+ # otherwise, say that this is the line
160
+ lines << current_line
161
+ # start another line with the current word
162
+ current_line = word
163
+ end
164
+ end
165
+ # the last line has not yet been added, if it
166
+ # is already shorter than width. Do it here.
167
+ lines << current_line
168
+
169
+ # create the new version of the given text
170
+ lines.join("\n")
171
+ end
172
+
141
173
  # Find the method that called, or 'main' in case of a top level Object.
142
174
  # This needs a bunch of memory and slows down the process.
143
175
  # Use of this method should be limited.
@@ -180,8 +212,10 @@ module BasicLogging
180
212
  # 1 format_log for all loggers.
181
213
  def format_log(message, mlevel)
182
214
  if @@target
215
+ message = wrap(message, width: 100)
216
+
183
217
  location = log_name().dup << ' '
184
- # Limit the memory-hungry analysis of the call stack
218
+ # Limit the memory hungry analysis of the call stack
185
219
  # This also takes about 2.5 times as long.
186
220
  if mlevel != :info
187
221
  location = log_name().dup << ' ' << calling_method << ' '
@@ -239,6 +273,13 @@ if $0 == __FILE__
239
273
  obj.warn('warn')
240
274
  obj.error('error')
241
275
  obj.fatal('fatal')
276
+ # ------ verify the wrap function for long lines -----
277
+ obj.set_target(STDOUT)
278
+ puts '-------- wrap-function ------------'
279
+ obj.set_level('info')
280
+ obj.info("Wie soll ich's halten künftig? Mir einen mächtigen Patron entdecken und, als gemeines Schlinggewächs, dem Schaft, an dem ich aufwärts will, die Rinde lecken?")
281
+ puts "\t-------- with imposed linebreaks -------"
282
+ obj.info("Wie soll ich's halten künftig?\nMir einen mächtigen Patron entdecken und, als gemeines Schlinggewächs,\n dem Schaft, an dem ich aufwärts will, die Rinde lecken?")
242
283
  # ---- into file ---
243
284
  obj.set_target "/tmp/test_log.log"
244
285
  puts "------ INFO into #{obj.target}-----------"
@@ -249,6 +290,7 @@ if $0 == __FILE__
249
290
  puts "---------- invalid (fails) -------"
250
291
  obj.set_target "/dev/sr0"
251
292
  obj.set_level "power"
293
+ puts " TEST out Ω"
252
294
  end
253
295
 
254
296
  # EOF
data/lib/body.rb CHANGED
@@ -97,6 +97,7 @@ class Body
97
97
  # Okay, this is called parsing, when it is well done.
98
98
  # I just try and am happy when it works.
99
99
  @lines.each_with_index do |line, i|
100
+ line = line.force_encoding('utf-8')
100
101
  # find the name in the intro-line
101
102
  if !fn.strip.empty? && !line.strip.empty? && !fup_name
102
103
  # match a name
@@ -202,7 +203,41 @@ class Body
202
203
  end # @lines.each_with_index
203
204
  end # if verify
204
205
  end
205
- #
206
+
207
+ # This method returns a list of marked keywords
208
+ def get_keywords()
209
+ # TODO: configuration option
210
+ keyword_delimiter = @@config.KEYWORD_DELIMITER
211
+ keywords = Array.new
212
+
213
+ if keyword_delimiter && !keyword_delimiter.empty?
214
+ @lines.each {|l| l.force_encoding('UTF-8')}
215
+ body = @lines.join($LN)
216
+
217
+ # provide a clean version of the marked keyword in the caption.
218
+ kw_rx = Regexp.new(keyword_delimiter.dup << "(.*?)" << keyword_delimiter.reverse, Regexp::MULTILINE)
219
+ debug 'keyword regexp is ' << kw_rx.to_s
220
+ index = 0
221
+ begin
222
+ kword = body.match(kw_rx )
223
+ if kword
224
+ # eliminate the delimiter from the message body
225
+ body.gsub!(kword[0], kword[1])
226
+ @lines = body.split($LN)
227
+
228
+ kw = kword[1].gsub(/[\s\t]+/, ' ').strip
229
+ keywords << kw
230
+ index += 1
231
+ end
232
+ end until kword == nil
233
+ else
234
+ warn "The keyword delimiter has not been set in the configuration"
235
+ warn "\tKeywords cannot be extracted"
236
+ end
237
+ debug 'found keywords ' << keywords.to_s if !keywords.empty?
238
+ return (keywords.empty? ? nil : keywords)
239
+ end
240
+
206
241
  # extract URL or other stuff, if configured for footnotes,
207
242
  def handle_references()
208
243
  # a symbol or string to mark the beginning an ending of a future footnote.
@@ -251,7 +286,7 @@ class Body
251
286
  # Now append them to the body... or find the right spot
252
287
  # where they belong... good luck with that.
253
288
  if(references && !references.empty?)
254
-
289
+
255
290
  # concatenate references.
256
291
  refs = ''
257
292
  references.each_with_index do |r, i|
@@ -261,7 +296,7 @@ class Body
261
296
  r.wrap!(WRAP_LENGTH, num.length)
262
297
  refs << num << r << $LN
263
298
  end
264
-
299
+
265
300
  # append references.
266
301
  debug 'appending references'
267
302
  # a line, separating the footnotes from the body of the article
@@ -129,7 +129,7 @@ REFERENCES_SEPARATOR: "──────────────────"
129
129
 
130
130
  # REFERENCE_DELIMITER
131
131
  # A symbol or sequence of symbols marking the beginning of a text which will
132
- # serve as footnote (or reference). The reversed sequence musst be used to mark
132
+ # serve as footnote (or reference). The reversed sequence must be used to mark
133
133
  # the end of the text. The presence of this sequence or symbol in the original
134
134
  # message body will cause the enclosed text to be moved below the message body.
135
135
  # The REFERENCES_SEPARATOR, if defined, will separate the message from the list
@@ -147,6 +147,17 @@ REFERENCES_DELIMITER: "%="
147
147
  # EXAMPLE: "(%s)" -> becomes (1) ... (2) ... (3)
148
148
  REFERENCE_FORMAT: " ➤%s"
149
149
 
150
+ # KEYWORD_DELIMITER
151
+ # A symbol or sequence of symbols marking the beginning of a word or expression
152
+ # which will complete the 'keywords' header. The reversed sequence must
153
+ # mark the end of the keyword or keyword expression. Example: this phrase
154
+ # contains a ?k=keyword=k?.
155
+ # The header will not be modified, if this option is not set.
156
+ # CONTENT a quoted symbol or sequence of symbols.
157
+ # DEFAULT: none/empty
158
+ # EXAMPLE: '?k='
159
+ KEYWORD_DELIMITER:
160
+
150
161
  # VFY_URLS
151
162
  # A Boolean constant. It determines if the program shall verify and possibly
152
163
  # try to correct URLs. Even if URLs are identified as such, only a few
@@ -40,9 +40,9 @@ class PostProcessor
40
40
  headers = Headers.new(article_text)
41
41
  debug('headers is ' << headers.inspect)
42
42
  @body = Body.new(article_text)
43
-
44
- debug('calling headers.update')
45
- headers.update()
43
+ keywords = @body.get_keywords
44
+ debug "got keywords: " << (keywords ? keywords.to_s : 'NIL')
45
+ headers.update(keywords: keywords)
46
46
 
47
47
  debug 'getting newsgroups'
48
48
  begin
data/lib/headers.rb CHANGED
@@ -113,8 +113,16 @@ class Headers
113
113
  nil
114
114
  end
115
115
 
116
+ def complete_keywords(kws)
117
+ if kws && !kws.empty?
118
+ @headers[:Keywords] ||= ''
119
+ @headers[:Keywords] += ',' << kws.join(',')
120
+ debug('keywords-header is now' << @headers[:Keywords])
121
+ end
122
+ end
123
+
116
124
  # Add headers, if need be. Set values where necessary.
117
- def update()
125
+ def update(keywords:nil)
118
126
  no_archive = @newsgroups.no_archive
119
127
  debug('no_archive should be set now : ' << no_archive.to_s)
120
128
  if no_archive
@@ -123,7 +131,8 @@ class Headers
123
131
  end
124
132
  # ------->
125
133
  # check for altered Subject and impose the newer value
126
- alterSubject()
134
+ alter_subject()
135
+ complete_keywords(keywords)
127
136
  # <----
128
137
  if @config.CUSTOM_HEADERS
129
138
  ch = @config.CUSTOM_HEADERS
@@ -170,7 +179,7 @@ class Headers
170
179
  return @headers[method] if @headers[method]
171
180
  error("unknown symbol '#{method}'")
172
181
  else
173
- error('no article headers set')
182
+ error('no article headers set')
174
183
  end
175
184
  return nil
176
185
  end
@@ -188,7 +197,7 @@ class Headers
188
197
  private
189
198
 
190
199
  # Check for was, war, était and clip the old subject header.
191
- def alterSubject
200
+ def alter_subject
192
201
  if @config.USE_OLD
193
202
  refs = @headers[:References]
194
203
  # only if older articles exist in the thread
data/lib/override.rb CHANGED
@@ -55,7 +55,14 @@ class OverrideDlg
55
55
  end
56
56
  # As we are calling external programs anyway,
57
57
  # why not continue with that ...
58
- @xmsg = ENV['PATH'].split(':').any? {|d| Dir.exist?(d) && Dir.children(d).include?('xmessage')}
58
+ @xmsg = ENV['PATH'].split(':').any? do |d|
59
+ if !Dir.exist?(d)
60
+ warn('inexistent directory in $PATH: ' << d << '!')
61
+ false
62
+ else
63
+ Dir.children(d).include?('xmessage')
64
+ end
65
+ end
59
66
  # bof.
60
67
  end
61
68
 
@@ -97,10 +104,15 @@ class OverrideDlg
97
104
  # redundancy with the following method, but I
98
105
  # do not feel like sorting it out, now.
99
106
  def program?(ex_name)
107
+ isso = false
100
108
  ENV['PATH'].split(':').each do |dir_name|
101
- return true if Dir.exist?(dir_name) && Dir.entries(dir_name).include?(ex_name)
109
+ if !Dir.exist?(dir_name)
110
+ warn('inexistent directory in $PATH: ' << dir_name << '!')
111
+ false
112
+ else
113
+ Dir.entries(dir_name).include?(ex_name)
114
+ end
102
115
  end
103
- return false
104
116
  end
105
117
 
106
118
  # returns true if the executable ex_name is to be
data/lib/version.rb CHANGED
@@ -14,7 +14,7 @@
14
14
  =end
15
15
 
16
16
  PROGNAME = 'flnews_post_proc'
17
- PROGVERSION = "2.10"
17
+ PROGVERSION = "2.12"
18
18
  AUTHORS = "Michael Uplawski"
19
19
  EMAIL = "michael.uplawski@uplawski.eu"
20
20
  YEARS = "2023 - 2026"
Binary file
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flnews_post_proc
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.10'
4
+ version: '2.12'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Uplawski
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-10-09 00:00:00.000000000 Z
10
+ date: 2026-11-28 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: diffy
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0'
143
143
  requirements: []
144
- rubygems_version: 4.0.20
144
+ rubygems_version: 4.0.24
145
145
  specification_version: 4
146
146
  summary: Modify news posts, before flnews sends them.
147
147
  test_files: []