["A...">
美文网首页
ruby parse email address

ruby parse email address

作者: KK的记录 | 来源:发表于2015-09-25 00:46 被阅读0次

    @a="Abe Allen , Bob Blue , c@c.com"b=@a.split(',')#=> ["Abe Allen ", " Bob Blue ", " c@c.com"]c=b.collect{|x|x[/<(.*?)>|^([^<>]*)$/]}#=> ["", "", " c@c.com"]d=c.gsub(/[<>]/,'')#=> ["a@a.com", "b@b.com", " c@c.com"]

    Mail::Address handles all email addresses in Mail. It takes an email address string and parses it, breaking it down into its component parts and allowing you to get the address, comments, display name, name, local part, domain part and fully formatted address.

    mail lib for email send,parse(address/body/attachment/etc.)

    http://www.rubydoc.info/github/mikel/mail/ 

    Mail::Address requires a correctly formatted email address per RFC2822 or RFC822. It handles all obsolete versions including obsolete domain routing on the local part.

    a=Address.new('Mikel Lindsaar (My email address) ')

    a.format#=> 'Mikel Lindsaar (My email address)'

    a.address#=> 'mikel@test.lindsaar.net'a.display_name#=> 'Mikel Lindsaar'

    a.local#=> 'mikel'a.domain#=> 'test.lindsaar.net'

    a.comments#=> ['My email address']

    a.to_s#=> 'Mikel Lindsaar (My email address)'

    相关文章

      网友评论

          本文标题:ruby parse email address

          本文链接:https://www.haomeiwen.com/subject/xntwcttx.html