component to get mailheader-data form eml lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- MacWomble · 2017-02-01 11:17 Hi, Is there any useable component to easily get the Mailheader out of eml-files saved by thunderbird available? What I wan to do: I already have an application witch can handle documents. The name, path and date of the document is stored in a database. Now i want to get this information with fpc/lazarus for mails to store the eml- header also in the database without asking the user for a name and date.  Regards Klaus ---------------------------------------------------------------------- howardpc · 2017-02-01 14:11 I would suggest either using Sorokin's TRegExpr (unit RegExpr) for parsing the lines in the .eml header to locate the data you are after, or if you just want say the name From: and Date: you could use the functions in StrUtils. Won't you need time as well as date, since someone may well send more than one email on the same day, and you need to be able to distinguish between them? ---------------------------------------------------------------------- MacWomble · 2017-02-01 14:16 Thank you for your tipps. Yes I also need date and time ---------------------------------------------------------------------- howardpc · 2017-02-01 22:00 This function works most of the time for me on English email .emls. It probably needs further work to internationalise it, and has only been tested on a few simple examples. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function HasValidEMLHeader(const anEMLfile: string;                    out sender: string; out dateTime: TDateTime): boolean;const  sanityCheck = 16;var  sl: TStringList;  i, maxIdx: integer;  senderOK: boolean = False;  dateOK: boolean = False;   function ValidSender: boolean;  var    s: string;  begin    s:=lowercase(sl[i]);    Result:=(Length(s) > 10) and (Copy(s, 1, 6) = 'from: ');    if Result then      sender:=Copy(s, 7, maxint);  end;   function ValidDateTime: boolean;  var    s: string;    date: TDate;    time: TTime;    singleDigit: boolean;     function ValidDate: boolean;    var      sDate: string;    d, m, y: word;        function GetMonth(const mStr: string): word;       var         i: integer;       begin         for i:=Low(TMonthNameArray) to High(TMonthNameArray) do begin           if SameText(DefaultFormatSettings.ShortMonthNames[i], mStr) then           Exit(i);         end;         Exit(0);       end;     begin      sDate:=Copy(s, 12, 11);      singleDigit:=(sDate[2] = ' ');      if singleDigit then begin        d:=StrToIntDef(sDate[1], 1);        Delete(sDate, 1, 2);      end      else begin        d:=StrToIntDef(Copy(sDate,1,2), 1);        Delete(sDate, 1, 3);      end;      m:=getMonth(Copy(sDate,1,3));      Delete(sDate, 1, 4);    y:=StrToIntDef(Copy(sDate, 1, 4), 0);      Result:=(d <= 31) and (m > 0) and (y > 0);      if Result then        date:=EncodeDate(y, m, d);    end;     function ValidTime: boolean;    var      sTime: string;    begin      if singleDigit then        sTime:=Copy(s, 23, 8)      else sTime:=Copy(s, 24, 8);      Result:=TryStrToTime(sTime, time);    end;   begin    s:=lowercase(sl[i]);    Result:=(Length(s) > 32) and (Copy(s, 1, 6) = 'date: ') and ValidDate and ValidTime;    if Result then      dateTime:=date+time;  end; begin  Result:=False;  sender:='';  dateTime:=default(TDateTime);  if (anEMLfile = '') or not FileExists(anEMLfile) then    Exit(False);  sl:=TStringList.Create;  try    sl.LoadFromFile(anEMLfile);    maxIdx:=sl.Count;    if (maxIdx < sanityCheck) then      Exit(False);    Dec(maxIdx);    i:=0;    while (i <= maxIdx) do    begin      WriteLn('i=',i);      if ValidSender then        senderOK:=True;      if ValidDateTime then      dateOK:=True;      if senderOK and dateOK then        Exit(True);    Inc(i);    end;  finally    sl.Free;  end;end; ---------------------------------------------------------------------- derek.john.evans · 2017-02-01 22:29 TIdMessage from Indy handles EML files. I used it in some code here: http://forum.lazarus.freepascal.org/index.php/topic,29517.msg186687.ht ml#msg186687 More information if you Google: http://www.e-iter.net/Knowledge/Indy9/007544.html ---------------------------------------------------------------------- MacWomble · 2017-02-02 08:35 Thank you all for your hints. I'll give it  try the next days. It seems to be exactly what I want.