MMS2R and Multiple Images Rails

Posted by Maletor on Stack Overflow See other posts from Stack Overflow or by Maletor
Published on 2009-11-26T16:14:05Z Indexed on 2010/05/04 6:38 UTC
Read the original article Hit count: 256

Filed under:
|
|
|

Here's my code:

require 'mms2r'

class IncomingMailHandler < ActionMailer::Base

## # Receives email(s) from MMS-Email or regular email and # uploads that content the user's photos. # TODO: Use beanstalkd for background queueing and processing. def receive(email)
begin mms = MMS2R::Media.new(email)

  ## 
  # Ok to find user by email as long as activate upon registration.
  # Remember to make UI option that users can opt out of registration 
  # and either not send emails or send them to a [email protected]
  # type address.
  ##
  # Remember to get SpamAssasin
  if (@user = User.find_by_email(email.from) && email.has_attachments?)
    mms.media.each do |key, value|
      if key.include?('image')
        value.each do |file| 
          @user.photos.push Photo.create!(:uploaded_data => File.open(file), :title => email.subject.empty? ? "Untitled" : email.subject)
        end
      end
    end
  end

ensure

  mms.purge

end

end

end

and here's my error:

/usr/local/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/commands/runner.rb:48: undefined method photos' for true:TrueClass (NoMethodError) from /usr/home/xxx/app/models/incoming_mail_handler.rb:23:in each' from /usr/home/xxx/app/models/incoming_mail_handler.rb:23:in receive' from /usr/home/xxx/app/models/incoming_mail_handler.rb:21:in each' from /usr/home/xxx/app/models/incoming_mail_handler.rb:21:in receive' from /usr/local/lib/ruby/gems/1.8/gems/actionmailer-2.3.4/lib/action_mailer/base.rb:419:in receive' from (eval):1 from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in eval' from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/commands/runner.rb:48 from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /home/xxx/script/runner:3

I sent an email to the server with two image attachments. Upon receiving the email the server runs "| ruby /xxx/script/runner 'IncomingMailHandler.receive STDIN.read'"

What is going on? What am I doing wrong?

MMS2R docs are here: http://mms2r.rubyforge.org/mms2r/

© Stack Overflow or respective owner

Related posts about tmail

Related posts about receive