Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* changed interface for displaying mbox download link. It only expect…

…s the name of the mbox not a hash of them.

* added ActionMailer support to a dreamhost account I have via SMTP
  • Loading branch information...
commit d6a9038052885d981b8fad20323effd17ef56191 1 parent f1ad26e
@hone authored
View
7 app/controllers/backups_controller.rb
@@ -20,7 +20,8 @@ def create
case result[:status]
when Pop3::OK_FLAG
flash[:notice] = "Backup successfully created"
- format.html { redirect_to( :action => :show, :mbox => { :inbox => result[:mbox_name] } ) }
+ Notify.deliver_success( @pop3.email_address, { :inbox => result[:mbox_name] } )
+ format.html { redirect_to( :action => :show, :mbox => result[:mbox_name] ) }
when Pop3::AUTHENTICATION_ERROR_FLAG
flash[:notice] = "Could not create backup due to authentication problems"
format.html { render :action => :new }
@@ -37,10 +38,10 @@ def create
end
def show
- @downloads = params[:mbox]
+ @download = params[:mbox]
respond_to do |format|
- if @downloads.nil? or @downloads.empty? or not check_files_exist( @downloads.values )
+ if @download.nil? or @download.empty? or not check_files_exist( @download )
flash[:notice] = 'No valid mbox specified'
format.html { redirect_to( :action => :new ) }
else
View
35 app/models/notify.rb
@@ -0,0 +1,35 @@
+class Notify < ActionMailer::Base
+ FROM_ADDRESS = "test.otherinbox@gmail.com"
+
+ def success(email, backup)
+ setup_mail( email )
+ @subject = "Your backups are ready"
+
+ body[:email] = email
+ body[:backup] = backup
+ end
+
+ def authentication_problem(email)
+ setup_mail( email )
+ @subject = "Authentication Problem with backups"
+
+ body[:email]
+ end
+
+ def timeout_problem(email)
+ setup_mail( email )
+ @subject = "Timeout Problem with backups"
+
+ body[:email]
+ end
+
+ private
+ def setup_mail( email )
+ @recipients = email
+ @from = FROM_ADDRESS
+ headers "Reply-to" => "#{FROM_ADDRESS}"
+ @subject = "Your backups are ready"
+ @sent_on = Time.now
+ @content_type = "text/html"
+ end
+end
View
4 app/views/backups/show.html.erb
@@ -1,5 +1,3 @@
<h1>BackupMyMail Downloads</h1>
<p>To download, right click on the link and left click on "Save as" or your browser's equivalent."</p>
-<% @downloads.each do |name, filename| %>
-<p><%= link_to name, "/download/#{filename}" %></p>
-<% end %>
+<p><%= link_to 'Download', "/download/#{@download}" %></p>
View
2  app/views/notify/authentication_problem.text.html.erb
@@ -0,0 +1,2 @@
+<p>Hi,</p>
+<p>There was an authorization problem with generating your bakcups. Please recheck your username/password.<p>
View
2  app/views/notify/authentication_problem.text.plain.erb
@@ -0,0 +1,2 @@
+Hi,
+There was an authorization problem with generating your bakcups. Please recheck your username/password.
View
2  app/views/notify/success.text.html.erb
@@ -0,0 +1,2 @@
+<p>Hello,</p>
+<p>Your backups are now available and can be accessed here: <%= link_to 'download', "http://localhost:3000/download/#{@backup}" %></li>
View
2  app/views/notify/success.text.plain.erb
@@ -0,0 +1,2 @@
+Hello,
+Your backups are now available and can be accessed here: <%= "http://localhost:3000/download/#{@backup}" %>
View
2  app/views/notify/timeout_problem.text.html.erb
@@ -0,0 +1,2 @@
+<p>Hi,</p>
+<p>There was a problem with connecting to the mail server you provided. A timeout error occurred. Please check the information again.</p>
View
2  app/views/notify/timeout_problem.text.plain.erb
@@ -0,0 +1,2 @@
+Hi,
+There was a problem with connecting to the mail server you provided. A timeout error occurred. Please check the information again.
View
14 config/environment.rb
@@ -72,4 +72,18 @@
# Activate observers that should always be running
# Please note that observers generated using script/generate observer need to have an _observer suffix
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+
+ # ActionMailer
+ config.action_mailer.raise_delivery_errors = true
+ config.action_mailer.perform_deliveries = true
+ config.action_mailer.delivery_method = :smtp
+ config.action_mailer.smtp_settings = {
+ :tls => false,
+ :address => "mail.hone.wornpath.net",
+ :port => "587",
+ :domain => "gmail.com",
+ :authentication => :login,
+ :user_name => "otherinbox",
+ :password => "0th3r1nb0x"
+ }
end
View
11 spec/controllers/backups_controller_spec.rb
@@ -33,9 +33,7 @@ def setup_create( result )
describe "GET 'show'" do
before(:each) do
- @params = {
- :inbox => MBOX_NAME
- }
+ @params = MBOX_NAME
end
def do_get
@@ -46,7 +44,7 @@ def do_get
FileUtils.touch( MBOX_FILE )
do_get
- assigns[:downloads].should == { "inbox" => MBOX_NAME }
+ assigns[:download].should == MBOX_NAME
response.should be_success
response.should render_template( :show )
@@ -65,7 +63,7 @@ def do_get
remove_file( MBOX_FILE )
do_get
- assigns[:downloads].should == { "inbox" => MBOX_NAME }
+ assigns[:download].should == MBOX_NAME
response.should redirect_to( :action => :new )
flash[:notice].should match /no valid mbox/i
end
@@ -101,9 +99,10 @@ def do_post
:status => Pop3::OK_FLAG
}
setup_create( result )
+ @pop3.should_receive(:email_address).and_return(@params[:email_address])
do_post
- response.should redirect_to( :action => :show, :mbox => { :inbox => result[:mbox_name] } )
+ response.should redirect_to( :action => :show, :mbox => result[:mbox_name] )
flash[:notice].should match /success/i
end
View
24 spec/models/notify_spec.rb
@@ -0,0 +1,24 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe Notify do
+ before(:each) do
+ ActionMailer::Base.delivery_method = :test
+ ActionMailer::Base.perform_deliveries = true
+ ActionMailer::Base.deliveries = []
+ end
+
+ it "should deliver success" do
+ Notify.deliver_success( 'test.otherinbox@gmail.com', MBOX_NAME )
+ ActionMailer::Base.deliveries.size.should == 1
+ end
+
+ it "should deliver authentication problem" do
+ Notify.deliver_authentication_problem( 'test.otherinbox@gmail.com' )
+ ActionMailer::Base.deliveries.size.should == 1
+ end
+
+ it "should deliver timeout problem" do
+ Notify.deliver_timeout_problem( 'test.otherinbox@gmail.com' )
+ ActionMailer::Base.deliveries.size.should == 1
+ end
+end
View
4 spec/views/backups/show.html.erb_spec.rb
@@ -2,11 +2,11 @@
describe "/backups/show" do
before(:each) do
- assigns[:downloads] = { :inbox => MBOX_NAME }
+ assigns[:download] = MBOX_NAME
render 'backups/show'
end
it "should show download link" do
- response.should have_tag( "a[href=?]", "/download/#{MBOX_NAME}", "inbox" )
+ response.should have_tag( "a[href=?]", "/download/#{MBOX_NAME}", "Download" )
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.