Skip to content
Browse files

* download method that outputs a zip for all folders

  • Loading branch information...
1 parent 41288d6 commit 23230412e5b628fd7424f70c40c45a567816bcb6 @hone committed
Showing with 23 additions and 2 deletions.
  1. +14 −2 app/models/imap.rb
  2. +9 −0 spec/models/imap_spec.rb
View
16 app/models/imap.rb
@@ -35,8 +35,20 @@ def setup_mailer
status
end
- def close
- close
+ def download
+ mbox_name = generate_mbox_name
+ mbox_folder = File.join( TMP_DIR, mbox_name )
+ FileUtils.mkdir( mbox_folder )
+ folders.each do |folder|
+ download_folder( folder, mbox_name )
+ end
+ parent_dir = File.join( mbox_folder, folders.first.name )
+ parent_mbox = "#{parent_dir}.mbox"
+ zip_output = File.join( FILE_DIR, "#{mbox_name}.zip" )
+ zip( [parent_mbox, parent_dir], zip_output )
+ remove_file_dir( mbox_folder )
+
+ zip_output
end
def folders
View
9 spec/models/imap_spec.rb
@@ -202,4 +202,13 @@ def setup_mock_net_imap
remove_file( mbox )
remove_dir( parent_dir )
end
+
+ it "should download to a zip for all folders" do
+ setup_imap
+ @imap.stub!(:generate_mbox_name).and_return( MBOX_NAME )
+ remove_file( MBOX_FILE_ZIP )
+
+ @imap.download.should == MBOX_FILE_ZIP
+ File.should be_exist( MBOX_FILE_ZIP )
+ end
end

0 comments on commit 2323041

Please sign in to comment.
Something went wrong with that request. Please try again.