Sha256: 190509e6906db5ea5be3ce68612ba4da040c9096dbdc6707fb1d56767d50e2a4

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 KB

Contents

module Imap; end

module Imap::Backup
  # Maps between server and file system folder names
  # `/` is treated as an acceptable character
  class Naming
    # The characters that cannot be used in file names
    INVALID_FILENAME_CHARACTERS = ":%;".freeze
    # A regular expression that captures each disallowed character
    INVALID_FILENAME_CHARACTER_MATCH = /([#{INVALID_FILENAME_CHARACTERS}])/.freeze

    # @param name [String] a folder name
    # @return [String] the supplied string iwth disallowed characters replaced
    #   by their hexadecimal representation
    def self.to_local_path(name)
      name.gsub(INVALID_FILENAME_CHARACTER_MATCH) do |character|
        hex =
          character.
          codepoints[0].
          to_s(16)
        "%#{hex};"
      end
    end

    # @param name [String] a serialized folder name
    # @return the supplied string with hexadecimal codes ('%xx') replaced with
    #   the characters they represent
    def self.from_local_path(name)
      name.gsub(/%(.*?);/) do
        ::Regexp.last_match(1).
          to_i(16).
          chr("UTF-8")
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
imap-backup-14.6.1 lib/imap/backup/naming.rb
imap-backup-14.6.0 lib/imap/backup/naming.rb
imap-backup-14.5.2 lib/imap/backup/naming.rb
imap-backup-14.5.1 lib/imap/backup/naming.rb
imap-backup-14.5.0 lib/imap/backup/naming.rb
imap-backup-14.4.5 lib/imap/backup/naming.rb