以下のような感じです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
require 'net/imap' | |
require 'kconv' | |
SVR='sample.server.com' | |
USR='user' | |
PWD='pppppp' | |
ADR='target@sample.com' | |
class Net::IMAP::Envelope | |
def mail_address_formatted(value) | |
return nil unless ["from", "sender", "reply_to", "to"].include?(value) | |
self.__send__(value)[0].mailbox + "@" + self.__send__(value)[0].host | |
end | |
end | |
imap = Net::IMAP.new(SVR) | |
imap.login(USR,PWD) | |
imap.select('INBOX') | |
imap.search(['UNSEEN']).each do |msg_id| | |
envelope = imap.fetch(msg_id, "ENVELOPE")[0].attr["ENVELOPE"] | |
from = envelope.mail_address_formatted("from") | |
puts "#{msg_id}:#{from}:#{envelope.subject.toutf8}" | |
if from == ADR | |
puts "delete" | |
imap.store(msg_id, "+FLAGS", [:Deleted]) | |
end | |
end | |
imap.expunge |
0 件のコメント:
コメントを投稿