Sha256: 791d1d5943b589501806a9a6abef712236c526ffe23b790a580a98b83572aec4

Contents?: true

Size: 1.51 KB

Versions: 7

Compression:

Stored size: 1.51 KB

Contents

require "thunderbird/local_folder"
require "thunderbird/profiles"

module Imap::Backup
  class Thunderbird::MailboxExporter
    EXPORT_PREFIX = "imap-backup".freeze

    attr_reader :email
    attr_reader :serializer
    attr_reader :profile
    attr_reader :force

    def initialize(email, serializer, profile, force: false)
      @email = email
      @serializer = serializer
      @profile = profile
      @force = force
    end

    def run
      local_folder_ok = local_folder.set_up
      return if !local_folder_ok

      if local_folder.msf_exists?
        if force
          Kernel.puts "Deleting '#{local_folder.msf_path}' as --force option was supplied"
          File.unlink local_folder.msf_path
        else
          Kernel.puts "Skipping export of '#{serializer.folder}' as '#{local_folder.msf_path}' exists"
          return false
        end
      end

      if local_folder.exists?
        if force
          Kernel.puts "Overwriting '#{local_folder.path}' as --force option was supplied"
        else
          Kernel.puts "Skipping export of '#{serializer.folder}' as '#{local_folder.path}' exists"
          return false
        end
      end

      FileUtils.cp serializer.mbox_pathname, local_folder.full_path

      true
    end

    private

    def local_folder
      @local_folder ||= begin
        top_level_folders = [EXPORT_PREFIX, email]
        prefixed_folder_path = File.join(top_level_folders, serializer.folder)
        Thunderbird::LocalFolder.new(profile, prefixed_folder_path)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
imap-backup-4.1.2 lib/imap/backup/thunderbird/mailbox_exporter.rb
imap-backup-4.1.1 lib/imap/backup/thunderbird/mailbox_exporter.rb
imap-backup-4.0.7 lib/imap/backup/thunderbird/mailbox_exporter.rb
imap-backup-4.0.6 lib/imap/backup/thunderbird/mailbox_exporter.rb
imap-backup-4.0.5 lib/imap/backup/thunderbird/mailbox_exporter.rb
imap-backup-4.0.4 lib/imap/backup/thunderbird/mailbox_exporter.rb
imap-backup-4.0.3 lib/imap/backup/thunderbird/mailbox_exporter.rb