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 abf9b38d Tools to list available mailboxes
abf9b38d is described below

commit abf9b38dcba615831780639a274c910f1d5c3ba2
Author: Sebb <[email protected]>
AuthorDate: Tue Aug 6 11:10:13 2024 +0100

    Tools to list available mailboxes
---
 www/secretary/workbench/models/mailbox.rb | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/www/secretary/workbench/models/mailbox.rb 
b/www/secretary/workbench/models/mailbox.rb
index fe0d325c..4e3bebbf 100644
--- a/www/secretary/workbench/models/mailbox.rb
+++ b/www/secretary/workbench/models/mailbox.rb
@@ -34,6 +34,24 @@ class Mailbox
     system 'rsync', *options, source, "#{ARCHIVE}/"
   end
 
+  # Get list of mailboxes
+  def self.allmailboxes
+    current = Date.today.strftime('%Y%m.yml') # exclude future-dated entries
+    Dir.entries(ARCHIVE).select{|name| name =~ %r{^\d{6}\.yml$} && name <= 
current}.map{|n| File.basename n,'.yml'}.sort
+  end
+
+  # get prev and next entries (or nil)
+  def self.prev_next(current)
+    active = self.allmailboxes
+    index = active.find_index current
+    prv = nxt = nil
+    if index
+      prv = active[index - 1] if index > 0
+      nxt = active[index + 1] if index < active.length
+    end
+    return prv, nxt
+  end
+
   #
   # Initialize a mailbox
   #

Reply via email to