Recent

Author Topic: .eml files to decode  (Read 2893 times)

QEnnay

  • Full Member
  • ***
  • Posts: 125
.eml files to decode
« on: February 05, 2022, 08:07:42 pm »
Hi,

I exported some emails and they are in xxx.eml format with the body being base64 encoded.

I have written a rough 'n' dirty to decode the base64 but it is still in some form of XML/HTML (or whatever it is) encoding.

I then tried using the HTMLDecode function but it left it the text XML/HTML Body unchanged.

Is there some simple way to extract the actual email stuff from the .eml files?

Thanks
Linux-Mint 20.1 x64 + Cinnamon; Lenovo Flex 5 Ryzen 5 4500, 16GB memory
FPC: 3.2.0-1, Lazarus 2.0.12-0, all 64bit

dsiders

  • Hero Member
  • *****
  • Posts: 1391
Re: .eml files to decode
« Reply #1 on: February 05, 2022, 09:26:27 pm »
I exported some emails and they are in xxx.eml format with the body being base64 encoded.

I have written a rough 'n' dirty to decode the base64 but it is still in some form of XML/HTML (or whatever it is) encoding.

I then tried using the HTMLDecode function but it left it the text XML/HTML Body unchanged.

Is there some simple way to extract the actual email stuff from the .eml files?

There is nothing simple about RFC 5322 message formats.

Indy has the TIdMessage class which handles the headers and messages bodies. But I would not call it simple.
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

QEnnay

  • Full Member
  • ***
  • Posts: 125
Re: .eml files to decode
« Reply #2 on: February 05, 2022, 10:38:51 pm »
But I would not call it simple.

By "simple," I meant a Lazarus/FPC Library or code snippet. I just need to get rid of all the "<br>" etcTags within the base64 decoded text.
Linux-Mint 20.1 x64 + Cinnamon; Lenovo Flex 5 Ryzen 5 4500, 16GB memory
FPC: 3.2.0-1, Lazarus 2.0.12-0, all 64bit

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: .eml files to decode
« Reply #3 on: February 05, 2022, 11:08:31 pm »
Hi!

Something simple like this??

Code: Pascal  [Select][+][-]
  1. procedure killTags (var s: string);
  2. var p,q : integer;
  3. begin
  4. repeat
  5. p := pos ('<',s);
  6. q := pos ('>',s);
  7. if q > p then delete (s,p,q-p+1) else exit;
  8. until (p=0) or (q=0);;
  9. end;
  10.  

Winni

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: .eml files to decode
« Reply #4 on: February 06, 2022, 05:15:43 am »
Class THTML2TextRenderer from unit HTML2TextRender:
Code: Pascal  [Select][+][-]
  1. uses HTML2TextRender...
  2. ...
  3. function HTML2Text(const AHTMLStr:String):String;
  4. begin
  5.   with THTML2TextRenderer.Create(AHTMLStr) do
  6.     try
  7.       Result:=Render;
  8.     finally
  9.       Free;
  10.     end;
  11. end;

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4567
  • I like bugs.
Re: .eml files to decode
« Reply #5 on: February 06, 2022, 11:41:59 am »
Class THTML2TextRenderer from unit HTML2TextRender:
Code: Pascal  [Select][+][-]
  1. uses HTML2TextRender...
  2. ...
  3. function HTML2Text(const AHTMLStr:String):String;
  4. begin
  5.   with THTML2TextRenderer.Create(AHTMLStr) do
  6.     try
  7.       Result:=Render;
  8.     finally
  9.       Free;
  10.     end;
  11. end;
I realized such a helper function should be included in the unit. I added it in 28dc8193a3. Function RenderHTML2Text.

The renderer is used for Lazarus IDE hints when the TurboPowerIProDsgn package is not installed.
« Last Edit: February 06, 2022, 11:44:03 am by JuhaManninen »
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: .eml files to decode
« Reply #6 on: February 06, 2022, 03:04:41 pm »
I realized such a helper function should be included in the unit. I added it in 28dc8193a3. Function RenderHTML2Text.

Thank you!

 

TinyPortal © 2005-2018