Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7873375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:29:44+00:00 2026-06-03T02:29:44+00:00

I want to parse elements of RFC822 (SMTP) "Received" lines, which are defined formally

  • 0

I want to parse elements of RFC822 (SMTP) "Received" lines, which are defined formally in the spec, e.g.:

atom        =  1*

[...]

received    =  "Received"    ":"            ; one per relay
                       ["from" domain]           ; sending host
                       ["by"   domain]           ; receiving host
                       ["via"  atom]             ; physical path
                      *("with" atom)             ; link/mail protocol
                       ["id"   msg-id]           ; receiver msg id
                       ["for"  addr-spec]        ; initial form
                       ";"    date-time         ; time received

[...]

msg-id      =  ""            ; Unique message id

[...]

addr-spec   =  local-part "@" domain        ; global address

etc. for domain, date-time, etc.

Here’s a real example:

Received: from ll-194.132.162.89.kv.sovam.net.ua (ll-194.132.162.89.kv.sovam.net.ua [83.170.243.194] (may be forged)) by raq2073.uk2.net (8.10.2/8.10.2) with ESMTP id lASHDDE10765 for <johnsmithsvt@matts.co.uk>; Wed, 28 Nov 2007 17:13:13 GMT

Would regex be a good strategy to capture the parts of a received line?

I realize that many SMTP servers don’t format received lines properly (in real life).

Otherwise, does anyone know of a library in Java that does this well?

Edit Here’s a fiddle showing a regex and tests that I’ve banged on for a while, which seems to work.

Received:\s+(?:from\s+(.+?))?(?:\(qmail (.+?)\))?(?:\s+by\s+(.+?))?(?:\\s+via\s+(.+?))?(?:\s+with\s+(.+?))?(?:\;?\s+id\s+(.+?))?(?:\s+for\s+(.+?))?(?:;\s*(?!.*\;.*)(.+))?$
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:29:46+00:00Added an answer on June 3, 2026 at 2:29 am

    The choice really depends on exactly what you want to achieve.

    For capturing specific parts of a Receiver-line (e.g. ‘give me the From-part’), regexes are awesome.

    If you need a full-fledged parser for this grammar, then regexes alone will not suffice. Especially the addr-spec has so many special cases that a regex cannot hope to handle each one correctly (explanation). Regexes are not parsers.

    Last time I needed an actual parser, I wrote my own using JavaCC. I would only recommend going down that road if you know a thing or two about grammars and parsing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to parse xml files that have elements like these: <element>&amp</element> <element>&amp;</element> But
I'm writing a little program in JavaScript in which I want to parse the
I have to parse an HTML which is not well-formed. I want to use
Suppose I want to parse any of these XML elements: <Server hostName=foobar /> <WebServer
I want to parse a Feedburner feed with HtmlUnit. The feed is this one:
I have an XML document in which I want to search for some elements
I want to sax-parse in nokogiri, but when it comes to parse xml element
I've made a little forum and I want parse the date on newest posts
I want to parse a filter string similar to the following: ((Field1 = 'red')
I want to parse the input string and extract the values from it. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.