On 12/27/2016 06:18 AM, Stefan Kruger wrote:
> I am using Lazarus 1.6.2 r53354 FPC 3.0.0 i386-win32
>
> ​I am using Synapse to download emails from Gmail.
>
> I can download the email just fine, I just cannot find an example of the few
> lines of code to download the attachment!

the attachment is already downloaded... it is in an embedded MIME capsule...

> PLEASE PLEASE PLEASE may you point me in the right direction? Or just give me
> a link or a forum where I can ask?

this is the only place that i'm aware of...

> I am at the end of my tether and have a project that needs to be finished in
> a week's time! :-)

i ran into something similar some couple of years back when i was working on 
inbound emails from yahoo and trying to get a clean ASCII version to post to a 
message network... IIRC, it is a little more involved than the simple code loop 
you are trying to use...

IIRC, i had to do something with implementing "OnWalkPart" to be able to walk 
all the parts (aka mime capsules) of the message... i don't know if i can strip 
my code down to the bare essentials of what i did, though... maybe if the above 
pointer doesn't to "OnWalkPart" doesn't help... AIR, i copied some existing 
code... something like

   procedure LoadMessageBodyPart(BodyPart:TMimePart);
   begin
     mPart := TMimePart.Create;
     try
       mPart.OnWalkPart := tc.ph;
       mPart.Clear;
       mPart.Assign(BodyPart);
       mPart.WalkPart(IntToStr(PartCount), '');
     finally
       mPart.Free;
     end;
   end;

and tc.ph was something like

   class procedure tc.ph(const Sender: TMimePart);
   var
     PartName : string;
   begin
     Sender.DecomposeParts;
     if Sender.PrimaryCode=mimepart.MP_BINARY then
       Sender.DecodePart;
       Sender.DecodeLines.SaveToFile(blahblah + '.' + Partname;
     end;
     if Sender.PrimaryCode=mimepart.MP_TEXT
       Sender.DecodePart;
       Sender.DecodeLines.SaveToFile(blahblahblah + "." + PartName + '.txt"
     end;
   end;

and the main program loop was something like

   uses
     mimemess,
     mimepart,
     synachar,
     synautil,
     sysutils,
     strutils,
     classes;

   type
     tc = class(TObject)
     public
       class procedure ph(const Sender : TMimePart);
     end;

   var
     mPart : TMimePart;
     MsgIn : TMimeMess;
     PartCount : Integer;

   begin
     MsgIn:=TMimeMess.Create;
     MsgIn.DecodeMessage;
     PartCount := MsgIn.MessagePart.GetSubPartCount;
     if PartCount = 0 then
       LoadMessageBodyPart(MsgIn.MessagePart);
     else
       for PartCoount := 0 to MsgIn.MessagePart.GetSubPartCount -1 do
         LoadMessageBodyPart(MsgIn.MessagePart.GetSubPart(PartCount));
   end.

that's extremely simplified and copied manually from one monitor on another 
machine where the code resides to this message... i know a tstringlist was also 
created to store the lines of the message before being saved to disk because 
each part was saved for analysis and debugging...

in testing, since everything was being read from a stored file on disk, saving 
graphic and archive files did work properly... the filename was extracted from 
the mime header of the mime capsule being worked with at that time...

hopefully the above will help as the original code has a lot of debugging and 
step by step processing logging in it and is not very trim and concise... the 
code was last modified Oct 2013 and hasn't been looked at since then... it is 
possible that i missed a subtle step in the above but, again, maybe it will be 
helpful and show you the route you need to take...


-- 
  NOTE: No off-list assistance is given without prior approval.
        *Please keep mailing list traffic on the list* unless
        private contact is specifically requested and granted.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
synalist-public mailing list
synalist-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synalist-public

Reply via email to