Class: Thunderbird::MailboxExporter
- Inherits:
-
Object
- Object
- Thunderbird::MailboxExporter
- Defined in:
- lib/imap/backup/thunderbird/mailbox_exporter.rb
Constant Summary collapse
- EXPORT_PREFIX =
"imap-backup".freeze
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#force ⇒ Object
readonly
Returns the value of attribute force.
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
-
#serializer ⇒ Object
readonly
Returns the value of attribute serializer.
Instance Method Summary collapse
-
#initialize(email, serializer, profile, force: false) ⇒ MailboxExporter
constructor
A new instance of MailboxExporter.
- #run ⇒ Object
Constructor Details
#initialize(email, serializer, profile, force: false) ⇒ MailboxExporter
Returns a new instance of MailboxExporter.
13 14 15 16 17 18 |
# File 'lib/imap/backup/thunderbird/mailbox_exporter.rb', line 13 def initialize(email, serializer, profile, force: false) @email = email @serializer = serializer @profile = profile @force = force end |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
8 9 10 |
# File 'lib/imap/backup/thunderbird/mailbox_exporter.rb', line 8 def email @email end |
#force ⇒ Object (readonly)
Returns the value of attribute force.
11 12 13 |
# File 'lib/imap/backup/thunderbird/mailbox_exporter.rb', line 11 def force @force end |
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
10 11 12 |
# File 'lib/imap/backup/thunderbird/mailbox_exporter.rb', line 10 def profile @profile end |
#serializer ⇒ Object (readonly)
Returns the value of attribute serializer.
9 10 11 |
# File 'lib/imap/backup/thunderbird/mailbox_exporter.rb', line 9 def serializer @serializer end |
Instance Method Details
#run ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/imap/backup/thunderbird/mailbox_exporter.rb', line 20 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 File.open(local_folder.full_path, "w") do |f| enumerator = Serializer::MboxEnumerator.new(serializer.mbox_pathname) enumerator.each.with_index do |raw, i| clean = Email::Mboxrd::Message.clean_serialized(raw) = Time.now.strftime("%a %b %d %H:%M:%S %Y") thunderbird_fom_line = "From - #{timestamp}" output = "#{thunderbird_fom_line}\n#{clean}\n" f.write output end end true end |