I think you are looking for someone to write you a Mail rule that does everything for you when it detects one of these inbound emails containing the id and name fields. That won't be me as it would require time that I simply do not have available.
What I have done though, is send myself a test email with message content that has a couple of your ||nnn || ||name|| fields randomly located in it, and have written a short Ruby handler to extract those fields and return them to AppleScript as list items. The test content contains ||001 || ||Apple|| and ||002 || ||Macintosh||.
The following AppleScript gets the selected Mail message content, and scans it with Ruby — returning the relevant Id, and Name values in an AppleScript list. The regular expression to do this is an acquired taste.
tell application "Mail"
set theMsg to item 1 of (get selection)
set theContent to content of theMsg
end tell
set id_names to paragraphs of parse_id_name(theContent'squoted form)
logid_names
-- id_names: {"001", "Apple", "002", "Macintosh"}
return
on parse_id_name(atxt)
-- Copy and paste the following correctly indented Ruby code into this AppleScript handler in Script Editor
-- Script Editor is agnostic about other scripting language indentation. Ruby is particular.
return do shell script "ruby <<EOF - " & atxt & "
#!/usr/bin/ruby # code: UTF-8 # look for matching string format: ||nnn || ||name|| in Apple Mail content (atxt) # regular expression with captures for Id and Name regex = /[|]{2}(?<Id>\\d{3})\\s+[|]{2}\\s+[|]{2}(?<Name>.*?)[|]{2}/mu matches = ARGV.first.scan(regex) if matches puts matches end
EOF"
end parse_id_name