

require 'net/pop'
class Mailmgr < ActionMailer::Base
@address = 'mailServer'
@port = 110
@id = 'mailId'
@pass = 'mailPassword'
def receive(email)
page = Page.find_by_address(email.to.first) ||
Page.create(:address => email.to.first)
page.emails.create(
:subject => email.subject,
:body => email.body,
:header => email.header,
:messageid => email.message_id,
:receivedate => email.date
)
if email.has_attachments?
for attachment in email.attachments
name = attachment.original_filename
# 日本語ファイル名の場合はデコード
if(name =~ /=\?ISO-2022-JP\?B\?/)
name.gsub!(/=\?ISO-2022-JP\?B\?/,'')
name = NKF.nkf('-mB', name)
end
page.attachments.create({
:file => attachment,
:description => email.subject,
:filename => name
})
end
end
end
def Mailmgr.r_m
pop = Net::POP3.new(@address, @port)
pop.start(@id, @pass)
if !pop.mails.empty? then
pop.each_mail do |m|
receive(m.pop) # 受信したメールを、「処理」する(DBへ登録)
m.delete # 受信したメールをサーバから削除
end
end
pop.finish
end
end
ウイルスバスター(VB2008)は悪くない! 2007年12月12日 コメント(3)
メディアの力(ちから) 2007年11月14日
JavaFesta 2007 2007年11月02日