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 19dcad98 Simplify
19dcad98 is described below

commit 19dcad98d377e24a54f41193eaf8486a5497bea5
Author: Sebb <[email protected]>
AuthorDate: Wed Sep 18 17:03:40 2024 +0100

    Simplify
---
 www/secretary/workbench/models/mailbox.rb | 11 ++---------
 www/secretary/workbench/models/message.rb |  7 ++++---
 2 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/www/secretary/workbench/models/mailbox.rb 
b/www/secretary/workbench/models/mailbox.rb
index 3303a21d..593e7848 100644
--- a/www/secretary/workbench/models/mailbox.rb
+++ b/www/secretary/workbench/models/mailbox.rb
@@ -188,15 +188,8 @@ class Mailbox
   # (these are messages that originally had attachments)
   def client_headers(listall: false)
     # fetch a list of headers for all messages in the mailbox with attachments
-    if listall
-      headers = self.headers.to_a.reject do |_id, message|
-        message[:attachments].nil?
-      end
-    else
-      headers = self.headers.to_a.reject do |_id, message|
-        # This does not return attachments with status :deleted
-        Message.attachments(message).empty?
-      end
+    headers = self.headers.to_a.reject do |_id, message|
+      Message.attachments(message, includeDeleted: listall).empty?
     end
 
     # extract relevant fields from the headers
diff --git a/www/secretary/workbench/models/message.rb 
b/www/secretary/workbench/models/message.rb
index 2802daa3..c278a228 100644
--- a/www/secretary/workbench/models/message.rb
+++ b/www/secretary/workbench/models/message.rb
@@ -119,13 +119,14 @@ class Message
     mail.text_part
   end
 
-  # return list of valid attachments which are not marked deleted (i.e. 
processed)
-  def self.attachments(headers)
+  # return list of valid attachment names which are not marked deleted (i.e. 
processed)
+  # if includeDeleted (default false), also include names marked deleted
+  def self.attachments(headers, includeDeleted: false)
     attachments = headers[:attachments]
     return [] unless attachments
     attachments.
       reject do |attachment| 
-        (attachment[:status] == :deleted) or
+        (!includeDeleted and attachment[:status] == :deleted) or
         (SIG_MIMES.include?(attachment[:mime]) and (not attachment[:name] or 
attachment[:name] !~ /\.pdf\.(asc|sig)$/))
       end.
       map {|attachment| attachment[:name]}.

Reply via email to