Class String def has_one_in? (String_Arr) has = false string_Arr.each {| word | has = self. include? (Word) if has break end} has endenddef decode_subject (sub) if sub. include? ("B? ") Encode_str = sub. match (/= \? (.*?) \? =/). To_s encode_str.scan (/= \? (.*?) \? (B \?) (.*?) \? =/) If $1! = Nil encode = $1. to_s if encode = 'utf8' encode = 'utf-8' end str = $3. to_s decode_str = Base64.decode64 (str) convert = Iconv. new ("UTF-8", encode) convert1 = Iconv. new ("GBK // IGNORE", "UTF-8") begin decode_str = convert. iconv (decode_str) rescue end return sub. sub (/= \?. *? \? =/, Decode_str) else return sub end else return sub endrequire 'net/pop 'require 'iconv' require "base64" pop = net: POP3.new ('mail. ******. com ', '000000') pop. start ('username', 'Password') skip_keywords = ["Out of office", "out of office", "out of Office", "Out of Office ", "Out Of Office", "automatic reply", "automatic reply", "going Out", "AutoReply", "Autoreply", "autoreply", "Auto-Re ", "auto-re", "Auto-re", "Delayed", "delayed"] email_patern = % r {([0-9a-zA-Z] {1} [0-9a-zA-Z. -] {1, 40} @ [0-9a-zA-Z. -] + [-\ w] * [0-9a-zA-Z] * \. + [a-zA-Z] {2, 15})} iFile. open ("test.txt", "w +") do | file | mail_addr = [] end_num = 0 pop. mails. each do | e | subj = e. header. split ("\ r \ n "). grep (/^ Subject :/). to_s subj = decode_subject (subj) if! Subj. has_one_in? (Skip_keywords) email = e. pop. to_s.scan (email_patern) email = email. uniq email. each do | item | if! Item. to_s.include? ("Relay.greensmtp.com") and! Item. to_s.start_with? ("3D") if! Mail_addr.include? (Item) mail_addr <item puts item. to_s + "|" + end_num.to_s end end_num + = 1 end file. puts mail_addrend