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 3742028d Tidy up syntax; simplify some calls
3742028d is described below

commit 3742028d323b8ee94dcdaf41a4a3bf542b02aa4b
Author: Sebb <[email protected]>
AuthorDate: Mon Aug 22 14:18:56 2022 +0100

    Tidy up syntax; simplify some calls
---
 www/secretary/workbench/models/mailbox.rb | 19 +++++++++--------
 www/secretary/workbench/models/message.rb | 34 +++++++++++++++----------------
 2 files changed, 26 insertions(+), 27 deletions(-)

diff --git a/www/secretary/workbench/models/mailbox.rb 
b/www/secretary/workbench/models/mailbox.rb
index fe6af900..2c95e4e4 100644
--- a/www/secretary/workbench/models/mailbox.rb
+++ b/www/secretary/workbench/models/mailbox.rb
@@ -1,15 +1,16 @@
-
+#
 # Encapsulate access to mailboxes
 #
+# N.B. this module is included by the deliver script, so needs to be quick to 
load
 
 require 'zlib'
 require 'zip'
 require 'stringio'
 require 'yaml'
 
-require_relative '../config.rb'
+require_relative '../config'
 
-require_relative 'message.rb'
+require_relative 'message'
 
 class Mailbox
   #
@@ -18,7 +19,7 @@ class Mailbox
   def self.fetch(mailboxes=nil)
     options = %w(-av --no-motd)
 
-    if mailboxes == nil
+    if mailboxes.nil?
       options += %w(--delete --exclude=*.yml --exclude=*.mail)
       source = "#{SOURCE}/"
     elsif mailboxes.is_a? Array
@@ -158,8 +159,8 @@ class Mailbox
   def headers
     messages = YAML.load_file(yaml_file) rescue {}
     messages.delete :mtime
-    messages.each do |key, value|
-      value[:source]=@name
+    messages.each do |_key, value|
+      value[:source] = @name
     end
   end
 
@@ -168,8 +169,8 @@ class Mailbox
   #
   def client_headers
     # fetch a list of headers for all messages in the mailbox with attachments
-    headers = self.headers.to_a.select do |id, message|
-      not Message.attachments(message).empty?
+    headers = self.headers.to_a.reject do |_id, message|
+      Message.attachments(message).empty?
     end
 
     # extract relevant fields from the headers
@@ -205,7 +206,7 @@ class Mailbox
       rescue
       end
 
-      if field.value and field.value.valid_encoding?
+      if field.value&.valid_encoding?
         [field.name, field.value]
       else
         [field.name, field.value.inspect]
diff --git a/www/secretary/workbench/models/message.rb 
b/www/secretary/workbench/models/message.rb
index 65262a36..31cb40ab 100644
--- a/www/secretary/workbench/models/message.rb
+++ b/www/secretary/workbench/models/message.rb
@@ -1,12 +1,13 @@
 #
 # Encapsulate access to messages
 #
+# N.B. this module is referenced by the deliver script, so needs to be quick 
to load
 
 require 'digest'
 require 'mail'
 require 'time'
 
-require_relative 'attachment.rb'
+require_relative 'attachment'
 
 class Message
   attr_reader :headers
@@ -90,8 +91,8 @@ class Message
   end
 
   def cc=(value)
-    value=value.split("\n") if value.is_a? String
-    @headers[:cc]=value
+    value = value.split("\n") if value.is_a? String
+    @headers[:cc] = value
   end
 
   def bcc
@@ -99,8 +100,8 @@ class Message
   end
 
   def bcc=(value)
-    value=value.split("\n") if value.is_a? String
-    @headers[:bcc]=value
+    value = value.split("\n") if value.is_a? String
+    @headers[:bcc] = value
   end
 
   def subject
@@ -122,7 +123,7 @@ class Message
       reject {|attachment| SIG_MIMES.include?(attachment[:mime]) and
         (not attachment[:name] or attachment[:name] !~ /\.pdf\.(asc|sig)$/)}.
       map {|attachment| attachment[:name]}.
-      select {|name| name != 'signature.asc'}
+      reject {|name| name == 'signature.asc'}
   end
 
   def attachments
@@ -133,7 +134,7 @@ class Message
   # attachment operations: update, replace, delete
   #
 
-  def update_attachment name, values
+  def update_attachment(name, values)
     attachment = find(name)
     if attachment
       attachment.headers.merge! values
@@ -141,7 +142,7 @@ class Message
     end
   end
 
-  def replace_attachment name, values
+  def replace_attachment(name, values)
     attachment = find(name)
     if attachment
       index = @headers[:attachments].find_index(attachment.headers)
@@ -150,7 +151,7 @@ class Message
     end
   end
 
-  def delete_attachment name
+  def delete_attachment(name)
     attachment = find(name)
     if attachment
       @headers[:attachments].delete attachment.headers
@@ -173,7 +174,7 @@ class Message
   #
   def write_email
     dir = @mailbox.dir
-    Dir.mkdir dir, 0755 unless Dir.exist? dir
+    Dir.mkdir dir, 0o755 unless Dir.exist? dir
     File.write File.join(dir, @hash), @raw, encoding: Encoding::BINARY
   end
 
@@ -336,9 +337,9 @@ class Message
     end
 
     # reformat email addresses
-    mail[:to] = to.map {|addr| addr.format}
-    mail[:cc] = cc.map {|addr| addr.format} unless cc.empty?
-    mail[:bcc] = bcc.map {|addr| addr.format} unless bcc.empty?
+    mail[:to] = to.map(&:format)
+    mail[:cc] = cc.map(&:format) unless cc.empty?
+    mail[:bcc] = bcc.map(&:format) unless bcc.empty?
 
     # return the resulting email
     mail
@@ -463,11 +464,8 @@ class Message
   def self.liberal_email_parser(addr)
     addr = Mail::Address.new(addr)
   rescue Mail::Field::ParseError
-    if addr =~ /^"([^"]*)" <(.*)>$/
-      addr = Mail::Address.new
-      addr.address = $2
-      addr.display_name = $1
-    elsif addr =~ /^([^"]*) <(.*)>$/
+    if addr =~ /^"([^"]*)" <(.*)>$/ or
+       addr =~ /^([^"]*) <(.*)>$/
       addr = Mail::Address.new
       addr.address = $2
       addr.display_name = $1

Reply via email to