Ruby操作outlook清理邮箱

原本准备用imap或者webdav写的,结果公司exchange服务器没开webdav~怒了~写了个winole32的。。。
require 'win32ole'

outlook = WIN32OLE.new('Outlook.Application')
mapi = outlook.GetNameSpace('MAPI')
inbox = mapi.GetDefaultFolder(6)
puts "You have #{inbox.UnreadItemCount} unread messages"

@junk_sender = ["Training Assistant", "Activeupdate Team", "[email protected]", "[email protected]",\
"[email protected]", "[email protected]", "594lab_WebManager", "Helpdesk", "CN OS Admin","[email protected]"\
"PH SLO Report Team", "Xinweihan"]
@junk_subject = ["joke", "spam", "PRE-OPR", "UPLOAD DONE", "Trend Micro Advisory"]


def delete_junkmails(i)
	if message.SenderName =~/#{@junk_sender}/i
        puts "deleting mail #{message.SenderName}-#{message.Subject}"
		message.Delete
    end
end

inbox.Items.Count.downto(1) do |i|
    message = inbox.Items(i)
	mark_delete = false
	@junk_sender.each do |s|
		if message.SenderName =~/#{s}/i
			puts "deleting mail #{message.SenderName}-#{message.Subject}"
			mark_delete = true
		end
	end
	@junk_subject.each do |s|
		if message.Subject =~/#{s}/i
			puts "deleting mail #{message.SenderName}-#{message.Subject}"
			mark_delete = true
		end		
	end	
	if mark_delete
		message.Delete
	end
end

你可能感兴趣的:(OS,Ruby,Gmail,Exchange)