在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
class String def has_one_in?(string_Arr) has = false string_Arr.each { |word| has= self.include?(word) if has break end } has end end def 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 end end require 'net/pop' require 'iconv' require "base64" pop = Net::POP3.new('mail.******.com','110') pop.start('username','password') skip_keywords = ["Out of office","out of office","out of Office","Out of Office","Out Of Office","自动回复","自动答复","外出", "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})}i File.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 end end end_num+=1 end file.puts mail_addr end |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论