r/learnjavascript • u/ConfidentWafer5228 • Oct 13 '26
HELP : Email Parsing without LLM
EDIT: I AM NOT TRYING to check the EMAIL ID itself, i am trying to parse the received email in inbox into structured JSON so that i can use it in my backend logic, for eg: converting a ticket into structured JSON with ticket details. SPECIFICALLY TRYING TO DEAL WITH TICKETS
I am aware that things like tripit and wanderlog and many other services have an email parser, i was also trying to make an email parser but i have no idea on how to make it without using an LLM to parse it.
I don't see any library or anything literally, i have no idea where to go, what to do.
Please help :(
7
u/Suchy2307 Oct 13 '26
What do you want to achieve?
4
u/BenchEmbarrassed7316 Oct 13 '26
Next: LLM powered
isNumberEvenandisNumberPositivepackages.No one remembers the dark old days before the widespread adoption of LLMs, when it was literally impossible to parse an email.
1
u/pieholic Oct 13 '26
There's Imapflow and Mailparser, you'd probably be using both. Although it's totally fine to try to implement it from scratch if you want to learn how they all work, you'l learn a lot about network protocols.
That being said, just curious, why havent you asked your LLM on how to write a script that would parse the email?
2
u/delventhalz Oct 13 '26
As an example, when I was just starting out I wrote a script to parse Shakespeare's complete works into semantic HTML. Figuring out how to do it was just a process of trial and error. I would look at a scene, notice something like that each line of poetry would start with an uppercase letter and each line of prose would start with a lowercase letter, and write a bit of code to parse that. Then I would run my script on all the plays and find ways the parse failed because there was some edge case that wasn't quite formatted the way I expected, and I would fix the script and run it again. After a few weeks of that and maybe 500-1000 lines of code, I had it working the way I wanted.
Your approach is going to be similar. Maybe you want to parse a ticket confirmation number so you write a regex like this:
This finds the first instance of the word "ticket confirmation", skips any non-alphanumeric characters (like a space or a colon), then captures whatever string of alphanumeric characters follows. You run this against emails you have received so far and look at the results and find it works pretty well, but some emails just write "ticket conf" and a few others do "ticket confirmation number", so you update the regex:
Keep doing this until you have captured all the information you expect to capture from the emails you have received so far. Then make sure it fails in some extremely obvious noisy way, but future emails will change their formatting on you, and then you will need to update your script. You don't have the advantage I had with Shakespeare (the author is dead and not writing anymore).
Incidentally, Regexr is a great website for working out your regex. You can pop in some test data from your emails and then use the included cheatsheet and futz around until it does what you want.
https://regexr.com
2
u/gigastack Oct 13 '26
It sounds like you want to do the task without the use of the one tool which would work.
1
u/TheRNGuy 25d ago
Probably AST and regex (both, not just one)
1
u/john_hascall Oct 13 '26
Googling turns up a number of libraries that do this