Class: Imap::Backup::Naming

Inherits:
Object
  • Object
show all
Defined in:
lib/imap/backup/naming.rb

Overview

Maps between server and file system folder names ‘/` is treated as an acceptable character

Constant Summary collapse

INVALID_FILENAME_CHARACTERS =

The characters that cannot be used in file names

":%;".freeze
INVALID_FILENAME_CHARACTER_MATCH =

A regular expression that captures each disallowed character

/([#{INVALID_FILENAME_CHARACTERS}])/.freeze

Class Method Summary collapse

Class Method Details

.from_local_path(name) ⇒ Object

Returns the supplied string with hexadecimal codes (‘%xx’) replaced with the characters they represent.

Parameters:

  • name (String)

    a serialized folder name

Returns:

  • the supplied string with hexadecimal codes (‘%xx’) replaced with the characters they represent



28
29
30
31
32
33
34
# File 'lib/imap/backup/naming.rb', line 28

def self.from_local_path(name)
  name.gsub(/%(.*?);/) do
    ::Regexp.last_match(1).
      to_i(16).
      chr("UTF-8")
  end
end

.to_local_path(name) ⇒ String

Returns the supplied string iwth disallowed characters replaced by their hexadecimal representation.

Parameters:

  • name (String)

    a folder name

Returns:

  • (String)

    the supplied string iwth disallowed characters replaced by their hexadecimal representation



15
16
17
18
19
20
21
22
23
# File 'lib/imap/backup/naming.rb', line 15

def self.to_local_path(name)
  name.gsub(INVALID_FILENAME_CHARACTER_MATCH) do |character|
    hex =
      character.
      codepoints[0].
      to_s(16)
    "%#{hex};"
  end
end