[photohunt commit] r193 - in trunk: app/models test/fixtures/test_mail test/unit

0 views
Skip to first unread message

codesite...@google.com

unread,
Dec 7, 2007, 1:17:25 AM12/7/07
to photoh...@googlegroups.com
Author: keoki.lee
Date: Thu Dec 6 22:17:11 2007
New Revision: 193

Added:
trunk/test/fixtures/test_mail/
Modified:
trunk/app/models/photo_receiver.rb
trunk/test/unit/photo_receiver_test.rb

Log:


Modified: trunk/app/models/photo_receiver.rb
==============================================================================
--- trunk/app/models/photo_receiver.rb (original)
+++ trunk/app/models/photo_receiver.rb Thu Dec 6 22:17:11 2007
@@ -1,3 +1,22 @@
class PhotoReceiver < ActionMailer::Base
-
-end
+ # email is a TMail::Mail
+ def receive(email)
+ #email.attachments are TMail::Attachment
+ #but they ignore a text/mail parts.
+ email.parts.each_with_index do |part, index|
+ if part.content_type =~ /^image/
+ @picture = Picture.new(
+ :user_email => email.from,
+ :tag => email.subject,
+ :content_type => part.content_type.chomp,
+ :data => part.body,
+ :status => 'PENDING',
+ :date => Date.today
+ )
+ @picture.save
+ #Else, check for HTML formatted email.
+ elsif part.content_type =~ /text\/html/
+ end
+ end
+ end
+ end

Modified: trunk/test/unit/photo_receiver_test.rb
==============================================================================
--- trunk/test/unit/photo_receiver_test.rb (original)
+++ trunk/test/unit/photo_receiver_test.rb Thu Dec 6 22:17:11 2007
@@ -1,4 +1,5 @@
require File.dirname(__FILE__) + '/../test_helper'
+require 'photo_receiver'

class PhotoReceiverTest < Test::Unit::TestCase
FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures'
@@ -16,6 +17,11 @@
@expected.mime_version = '1.0'
end

+ def test_photo_receiver
+ email_text = read_fixture('hello-world.mail').join
+ PhotoReceiver.receive(email_text)
+ end
+
private
def read_fixture(action)
IO.readlines("#{FIXTURES_PATH}/photo_receiver/#{action}")

Reply all
Reply to author
Forward
0 new messages