> > What is hard on walkpart? It is good when you need to enumerate all
> > parts of message. (for example, for antivirus/antispam checks).
> 
> yes, i need to enumerate all parts of messages to extract their
> contents to plain ASCII text files for posting via another medium... i
> already have code that parses utf-8 and quoted-printable bytes into
> their CP437 representations but i just can't get walking thru all
> parts... i've done my own but it fails quite spectacularly when there
> are parts within parts...

Do not parse it by yourself! All needed decoding is inside TMimePart. 
See the DecodeLines method and TargetCharset property.

> > It simply walk through MIME part structure in message and fire event
> > for each TMimePart. Inside event you can emumerate TMimePart
> > properties and do what you need.
> 
> i don't do events... i don't know how... my app is pure command line
> console mode and is called by the SMTP server when specific emails are
> received...

It does not care. Event is just callback routine, it does not 
depended on GUI/console, etc. See the testmime.pas FPC demo, it using 
it.

Look at this code in testmime.pas:

class procedure Tc.ph(const Sender: TMimePart);
begin
  Sender.DecodePart;
  Sender.EncodePart;
end;

It is just demonstration code, it just unpack and repack this MIME 
part. But you can do something different. Try this code instead:

class procedure Tc.ph(const Sender: TMimePart);
var
  PartName: string;
begin
  //is it part with some binary data?
  if Sender.PrimaryCode=mimepart.MP_BINARY then
  begin
    partname:=Sender.FileName;
    if partname='' then
      partname:= fooname; //build some your ad-hoc filename
    sender.DecodePart;
    sender.DecodedLines.SaveToFile(Partpath + PartName); 
//partpath is some path whene you wist to save files
  end;
  //is it text?
  if Sender.PrimaryCode=mimepart.MP_TEXT then
  begin
    sender.TargetCharset := CP_UTF8;
    sender.DecodePart;
    sender.DecodedLines.SaveToFile(Partpath + Some_unique_name); 
//partpath is some path whene you wist to save files
  end;
end;

Of course, you can replace SaveToFile calls by any other actions.


-- 
Lukas Gebauer.

http://synapse.ararat.cz/ - Ararat Synapse - TCP/IP Lib.
http://geoget.ararat.cz/ - Geocaching solution


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
synalist-public mailing list
synalist-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synalist-public

Reply via email to