Class: MailChimp::Processor

Inherits:
ActionMailer::Base
  • Object
show all
Defined in:
lib/mail_chimp.rb

Instance Method Summary collapse

Instance Method Details

#receive(msg) ⇒ Object



521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
# File 'lib/mail_chimp.rb', line 521

def receive(msg)
  #Process all new subscriptions
  is_subscription = !((msg.subject =~ /New Subscribe to/).nil?)
  is_unsubscription = !((msg.subject =~ /Unsubscribe from/).nil?) 
  if is_subscription || is_unsubscription
    stored_value = Hash::new
    if (is_subscription)
      stored_value[:list] = msg.subject.gsub("New Subscribe to ", "")
      stored_value[:type] = :subscription
    else
      stored_value[:list] = msg.subject.gsub("Unsubscribe from ", "")
      stored_value[:type] = :unsubscription 
    end
    msg.body.each_line do |parseline| 
      field, value = parseline.split(":", 2)
      if (!value.nil?)
        field = field.strip
        value = value.strip
        #TODO: Deal with other fields
        if (field == "Email Address")
          stored_value[:email] = value
        elsif (field == "Signup IP")
          stored_value[:ip] = value
        elsif (field == "Date")
          stored_value[:date] = value
        end
      end 
    end
    return stored_value   
  end 
  return nil
end