Class: UnknownEmailsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- UnknownEmailsController
- Defined in:
- app/controllers/unknown_emails_controller.rb
Instance Method Summary collapse
-
#convert ⇒ Object
Create lead and attach this email to new lead.
-
#ignore ⇒ Object
Delete email and ignore all emails from this address.
- #index ⇒ Object
Instance Method Details
#convert ⇒ Object
Create lead and attach this email to new lead
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/unknown_emails_controller.rb', line 40 def convert address = params[:email] if address.present? # Attach all orphaned emails that are from / to address @emails = Email.all(:conditions => [%Q{ mediator_id IS NULL AND (emails.sent_from LIKE ? OR emails.sent_to LIKE ?) }, "%#{address}%", "%#{address}%"]) lead = Lead.create :email => address, :first_name => address.split("@").first, :last_name => address.split("@").last, :user => current_user, :emails => @emails link_to_lead = ActionController::Base.helpers.link_to(lead_url(lead), lead_url(lead)) flash[:notice] = "Created lead and attached email(s): #{link_to_lead}".html_safe else flash[:error] = "Must provide :email param!" end redirect_to unknown_emails_path end |
#ignore ⇒ Object
Delete email and ignore all emails from this address
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/unknown_emails_controller.rb', line 19 def ignore @email = Email.find(params[:id]) unless address = params[:email] if @email.direction == 'received' address = @email.sent_from elsif @email.direction == 'sent' address = @email.sent_to end end if address.present? IgnoredEmail.create :email => address @email.destroy flash[:notice] = "All emails from #{address} will be ignored." else flash[:error] = "Could not determine whether this email was sent or received!" end redirect_to unknown_emails_path end |
#index ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'app/controllers/unknown_emails_controller.rb', line 4 def index # Fetch all emails that don't belong to an # entity, and aren't in the 'ignored_emails' table. sql = %Q{SELECT * from emails WHERE mediator_id IS NULL AND NOT EXISTS ( SELECT DISTINCT(email) FROM ignored_emails WHERE email = emails.sent_from OR email = emails.sent_to)} @unknown_emails = Email.paginate_by_sql(sql, :page => params[:page]) respond_with @unknown_emails end |