blob: 3eb700c56c54db851e793d17e729f4e7219ce89f [file] [log] [blame]
# find indicated mailbox in the list of available mailboxes
# This code is invoked by workbench/server.rb
available = Dir[File.join(ARCHIVE, '*.yml')].sort
index = available.find_index File.join(ARCHIVE, "#{@mbox}.yml")
# if found, process it
if index
prevmbox = nil
if index > 0
prevmbox = available[index-1]
prevmbox = nil unless YAML.load_file(prevmbox)&.any? do |key, mail|
mail[:status] != :deleted and not Message.attachments(mail).empty?
end
end
# return previous mailbox name and headers for the messages (that have attachments) in the mbox
{
mbox: (File.basename(prevmbox, '.yml') if prevmbox),
messages: Mailbox.new(@mbox).client_headers
}
else
# ensure we return something usable
{
mbox: nil,
messages: []
}
end