Skip to content

Commit

Permalink
catch incoming mail
Browse files Browse the repository at this point in the history
  • Loading branch information
suras committed Jul 16, 2013
1 parent 0ca538d commit b442c93
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ gem 'roo'

gem 'email_validator'

gem 'mailman', require: false

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

Expand Down
18 changes: 18 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ GEM
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
ffi (1.9.0)
hike (1.2.3)
i18n (0.6.4)
journey (1.0.4)
Expand All @@ -83,10 +84,21 @@ GEM
actionpack (>= 3.1)
less (~> 2.3.1)
libv8 (3.11.8.17)
listen (1.2.2)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
rb-kqueue (>= 0.2)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
maildir (2.1.0)
mailman (0.6.0)
activesupport (>= 2.3.4)
i18n (>= 0.4.1)
listen (>= 0.4.1)
mail (>= 2.0.3)
maildir (>= 0.5.0)
mime-types (1.23)
mini_portile (0.5.1)
multi_json (1.7.7)
Expand Down Expand Up @@ -124,6 +136,11 @@ GEM
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (10.1.0)
rb-fsevent (0.9.3)
rb-inotify (0.9.0)
ffi (>= 0.5.0)
rb-kqueue (0.2.0)
ffi (>= 0.5.0)
rdoc (3.12.2)
json (~> 1.4)
ref (1.0.4)
Expand Down Expand Up @@ -173,6 +190,7 @@ DEPENDENCIES
jquery-rails
jquery-tokeninput-rails
less-rails
mailman
mysql2
paperclip
rails (= 3.2.12)
Expand Down
53 changes: 53 additions & 0 deletions script/mailman_server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env ruby
#require "rubygems"
#require "bundler/setup"
require "mailman"
#require File.dirname(__FILE__) + "/../config/environment"

#Mailman.config.logger = Logger.new("log/mailman.log")
Mailman.config.poll_interval = 3
Mailman.config.pop3 = {
server: 'mail.godaddy.com', port: 995, ssl: true,
username: "catchmail@hootrecruit.com",
password: "hootrecruit"
}

Mailman::Application.run do
default do
begin
p "Found a new message"
if message.multipart?
the_message_html = message.html_part.body.decoded
the_message_text = message.text_part.body.decoded
the_message_attachments = []
message.attachments.each do |attachment|
file = StringIO.new(attachment.decoded)
file.class.class_eval { attr_accessor :original_filename, :content_type }
file.original_filename = attachment.filename
file.content_type = attachment.mime_type
attachment = Attachment.new
attachment.attached_file = file
attachment.save
the_message_attachments << attachment

end

else

the_message_html = message.body.decoded
the_message_text = message.body.decoded
the_message_attachments = []


end
Note.create(:candidate_note => the_message_html)
# map attachments with message object and save other stuff and do other processing or trigger other events..
#Message.create(:from => message.from.first, :to => message.to.first, :subject => message.subject, :html_body => the_message_html, :text_body => the_message_text)


rescue Exception => e
Mailman.logger.error "Exception occurred while receiving message:\n#{message}"
Mailman.logger.error [e, *e.backtrace].join("\n")
end
end
end

0 comments on commit b442c93

Please sign in to comment.