Use ruby to get the Email title and determine

Source: Internet
Author: User
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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.