Created
January 29, 2013 11:48
-
-
Save mostlyfine/4663684 to your computer and use it in GitHub Desktop.
IMAP振り分け
This file contains hidden or 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
| #!/usr/bin/env ruby | |
| # -*- coding: utf-8 -*- | |
| require 'openssl' | |
| require 'net/imap' | |
| require 'yaml' | |
| class Filter | |
| def initialize(options={}) | |
| @imap = Net::IMAP.new(options[:host], options[:port] || 993, options[:ssl] || true) | |
| @user = options[:user] | |
| @password = options[:password] | |
| end | |
| def exec(&block) | |
| @imap.login(@user, @password) | |
| @imap.select('INBOX') | |
| block.call(self) | |
| @imap.expunge | |
| @imap.disconnect | |
| end | |
| def move(rule, mailbox) | |
| @imap.search(rule).each do |message_id| | |
| @imap.copy(message_id, mailbox) | |
| @imap.store(message_id, '+FLAGS', [:Deleted]) | |
| end | |
| end | |
| end | |
| config = YAML.load_file('mail.yml') | |
| work = Filter.new(config) | |
| work.exec do |filter| | |
| filter.move(['TO', '@gmail.com'], 'INBOX.GMail') | |
| filter.move(['CC', '@yahoo.co.jp'], 'INBOX.Yahoo') | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment