Вот использую код для загрузки нескольких файлов eml с последующей их обработкой - нужно из eml достать ссылки. Использую synapse. При загрузке файлов в memo дальше ничего не раскодируется. Почему так??? Сижу уже не первый день =((
Код:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, mimemess, mimepart, ExtCtrls, ComCtrls, ActiveX;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Memo1: TMemo;
Memo2: TMemo;
Memo: TMemo;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure GetParts(const part: TMimepart);
//procedure AllTXTtoMemo(Dir, Masc: string; Memo: TMemo);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
IdMes:TMimeMess;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.GetParts(const part: TMimepart);
var
s: string;
i: integer;
begin
if (LowerCase(part.Primary)='text') and (LowerCase(part.FileName)='') then //Проверим что данный блок - текст сообщения
begin
part.DecodePart;
if LowerCase(part.Secondary)='plain' then // Определяем что это простой текст
Memo1.Lines.LoadFromStream(part.DecodedLines); // Загружаем раскодированные данные
end;
for i := 0 to part.GetSubPartCount - 1 do
GetParts( part.getsubpart(i)); // проверяем наличие следующего блока
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
if OpenDialog1.Execute then
begin
IdMes:=TMimeMess.Create;
IdMes.Lines.LoadFromFile(Memo.Text);
end;
IdMes.DecodeMessage; // Раскодируем сообщение, обязательно
Memo2.Lines.Assign(IdMes.Header.CustomHeaders); // Заголовки, не спицифичные для формата MIME
GetParts(IdMes.MessagePart); // рекурсивная процедура обхода блоков сообщения
end;
procedure AllTXTtoMemo(Dir, Masc: string; Memo: TMemo);
var
searchResult : TSearchRec;
Buff: TStringList;
begin
Memo.Clear;
Buff := TStringList.Create;
if Dir[Length(Dir)] <> '\' then
Dir := Dir + '\';
if Masc = '' then Masc := '*.*';
if FindFirst(Dir + Masc, faAnyFile - faDirectory, searchResult) = 0 then
begin
repeat
Buff.LoadFromFile(Dir + searchResult.Name);
Memo.Lines.AddStrings(Buff);
until FindNext(searchResult) <> 0;
FindClose(searchResult);
end;
Buff.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
AllTXTtoMemo('d:\1\2', '*.eml', Memo);
end;
end.
Данный код работает и устраивает полностью, но как сделать загрузку файлов поочередно тогда???
Код:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, mimemess, mimepart, ExtCtrls, ComCtrls, ActiveX;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Memo1: TMemo;
Memo2: TMemo;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
procedure GetParts(const part: TMimepart);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
IdMes:TMimeMess;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.GetParts(const part: TMimepart);
var
s: string;
i: integer;
begin
if (LowerCase(part.Primary)='text') and (LowerCase(part.FileName)='') then //Проверим что данный блок - текст сообщения
begin
part.DecodePart;
if LowerCase(part.Secondary)='plain' then // Определяем что это простой текст
Memo1.Lines.LoadFromStream(part.DecodedLines); // Загружаем раскодированные данные
end;
for i := 0 to part.GetSubPartCount - 1 do
GetParts( part.getsubpart(i)); // проверяем наличие следующего блока
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
if OpenDialog1.Execute then
begin
IdMes:=TMimeMess.Create;
IdMes.Lines.LoadFromFile(OpenDialog1.FileName);
end;
IdMes.DecodeMessage; // Раскодируем сообщение, обязательно
Memo2.Lines.Assign(IdMes.Header.CustomHeaders); // Заголовки, не спицифичные для формата MIME
GetParts(IdMes.MessagePart); // рекурсивная процедура обхода блоков сообщения
end;
end.