Reading email attachments

Is anyone sucessfully reading email attachments?

I have had some luck in my local dev environment but only get partial
files on my hosted server (TxD) and then only sometimes.

I use something like this…

Net::POP3.start(“widespreadsolutions.com”, nil, “briefcase”, “y902xas”)
do |pop|
if pop.mails.empty?
logger.info “NO MAIL”
else
pop.mails.each do |email|

      begin
        logger.info "receiving mail..."
        MailReader.receive(email.pop)
        email.delete
      rescue Exception => e
        logger.error "Error receiving email at " + Time.now.to_s + 

"::: " + e.message
end
end
end
end

And then this in MailReader (after it has been converted to a Tmail
object)

if mail.has_attachments?
for email_attachment in mail.attachments
RAILS_DEFAULT_LOGGER.info ‘creating attachment’
attachment = Attachment.new
attachment.uploaded_file( email_attachment, attachment )
c.attachments << attachment if attachment.save
c.save
end
end

Attachment#uploaded file looks like this
def uploaded_file( incoming_file, attachable )
self.filename = incoming_file.original_filename
self.content_type = incoming_file.content_type
dir =
“#{RAILS_ROOT}/attachments/#{attachable.type}/#{attachable.id}”
Dir.mkdir( dir ) unless File.exists?( dir )
self.path = “#{dir}/#{self.filename}”

File.open(self.path, "wb") do |f|
  f.write(incoming_file.read)
end

end

Should I be able to read from the file like this? I am finding very
little TMail documentation that is useful.

Thanks

Gareth
www.widespreadsolutions.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs