This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git
The following commit(s) were added to refs/heads/master by this push:
new 7fa1b51e Default to stripping email comments
7fa1b51e is described below
commit 7fa1b51e684a43994d79c27bfd34a309515f859d
Author: Sebb <[email protected]>
AuthorDate: Thu Mar 16 21:06:16 2023 +0000
Default to stripping email comments
---
lib/whimsy/asf/member.rb | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/lib/whimsy/asf/member.rb b/lib/whimsy/asf/member.rb
index 68089b20..b1644a3e 100644
--- a/lib/whimsy/asf/member.rb
+++ b/lib/whimsy/asf/member.rb
@@ -139,9 +139,12 @@ module ASF
end
# parse a single entry
- # Params: keys_wanted array of key symbols to retrieve; defaults to
["Email"]
+ # Params:
+ # - entry
+ # - keys_wanted array of key symbols to retrieve; defaults to ["Email"]
+ # - raw: if true, then return raw email entries (with comments)
# Strings are forced to lower-case and non-alphanumeric replaced with '_'
- def self.parse_entry(entry, keys_wanted=nil)
+ def self.parse_entry(entry, keys_wanted=nil, raw=false)
if keys_wanted.nil?
keys_wanted = %i{email}
end
@@ -150,11 +153,11 @@ module ASF
current_entry = nil
entry.each do |line|
if line =~ %r{^ +([^:]+): *(.*)}
- val = $2.strip # must be done first otherwise $2 is clobbered
+ value = $2.strip # must be done first otherwise $2 is clobbered
key = key2sym($1)
if keys_wanted.include? key
current_entry = dict[key]
- current_entry << val
+ current_entry << value
else
current_entry = nil # new key, and not wanted
end
@@ -165,13 +168,19 @@ module ASF
current_entry = nil
end
end
+ # remove comments from emails?
+ unless raw
+ if dict.include? :email
+ dict[:email] = dict[:email].each.map {|v| v.split('
').grep(/@/)}.flatten
+ end
+ end
dict
end
# return all user entries, whether or not they have an id
# Params: keys_wanted: array of key names to extract and return
# Returns: array of [status, user name, availid or nil, entry lines,
[keys]]
- def self.list_entries(keys_wanted=nil, &block)
+ def self.list_entries(keys_wanted=nil, raw=false, &block)
Enumerator.new do |y|
# split by heading underlines; drop text before first
ASF::Member.text.split("\n").slice_before {|a| a.start_with?
'================'}.drop(1).each_with_index do |sect, index|
@@ -201,7 +210,7 @@ module ASF
Wunderbar.error "Duplicate ids: #{ids} in #{name} entry"
end
if keys_wanted
- y.yield [status, name, ids.first, entry, self.parse_entry(entry,
keys_wanted)]
+ y.yield [status, name, ids.first, entry, self.parse_entry(entry,
keys_wanted, raw)]
else
y.yield [status, name, ids.first, entry]
end