Best way to parse string of email addresses

后端 未结 13 2608
悲哀的现实
悲哀的现实 2021-02-14 04:10

So i am working with some email header data, and for the to:, from:, cc:, and bcc: fields the email address(es) can be expressed in a number of different ways:

F         


        
13条回答
  •  难免孤独
    2021-02-14 05:11

    There isn't really an easy solution to this. I would recommend making a little state machine that reads char-by-char and do the work that way. Like you said, splitting by comma won't always work.

    A state machine will allow you to cover all possibilities. I'm sure there are many others you haven't seen yet. For example: "First Last"

    Look for the RFC about this to discover what all the possibilities are. Sorry, I don't know the number. There are probably multiple as this is the kind of things that evolves.

提交回复
热议问题