SaveToFile (and LoadfromFile) do not work in Indie9/D5 environment.  Why?

Posted on 2006-11-14
Medium Priority
Last Modified: 2010-04-05
I have been creating a custom email client for a customer using Indy9 and D5.  All is well except that I need to be able to save Msg objects locally for review after deleting them from the server.  Using the TidMessage SaveToFile and LoadFromFile methods almost works - except if the message has an attachment.  If that is the case, the body of the message is not available after retrieving the msg from a file.  

I also tried simply saving to a stream - clearing the msg then immediately rereading the stream - I get the same results.

Is this a known problem with Indy9?  If so does Indy10 have it fixed?  Or is there something special that needs to be done with a msg read from a file or stream?

Thanks in advance - (example code would be a help)
Question by:DMTrump
  • 6
  • 2
LVL 17

Expert Comment

ID: 17943614
change the IdMessage1.NoDecode property

Author Comment

ID: 17943739
I JUST figured that out myself (that I needed to save the message undecoded - but still didn't know how to do it)  Thanks - I'll give it a try -  I may have further questions so I'll leave the question open for now.

This may be the easiest 500 points you've ever earned!  
LVL 17

Accepted Solution

TheRealLoki earned 2000 total points
ID: 17943762
yeah, may as well get you 500 pts worth.
eg. Indy 9 does not always put the final dot ( . ) at teh end of the file
so if you were to Save it as "temp.eml"
OE, outlook etc would not be able to open it (by just double clicking on it)
so you may find you need to stick a dot at the end yourself.
Not sure if *all* versions of Indy 9 had this issue, but probably your next hurdle (was mine)

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Author Comment

ID: 17943830
I see that if the email has an attachment, I need to save it with IdMessage1.NoDecode:=true; but if there is no attachment IdMessage1.NoDecode:=false;  If that is so, what is the easiest most reliable way to test for multipart?   Must I retreive the message and decode it to look for MessageParts.count - then if there is more than 1, close the message, set nodecode:=true, retreive it again before saving it?


Author Comment

ID: 17943867
That bit about the final dot is good to know - in this case ONLY indie will ever reopen the file - but I'll do it anyway.

I've GOT to spend some time studying Indy before the next time I need it in a hurry!  I'm getting BDS2006 soon - maybe then!

Author Comment

ID: 17943912
Looks like my copy of Indy9 is putting the dot on.  I was able to open a saved file in OE without problem.

Author Comment

ID: 17944693
I got everything figured out - just for anybody else looking at this here is my conclusion:

You must always save to a file with NoDecode set to true.  However, when you read the file - set nodecode to false, of course, and then make sure that after adding Any messageparts to your text display that are TIdText, you must also add in the msg.body.  that takes care of messages that are <not> multipart.  If you fail to do that, messages that do not have attachments will appear blank.

Thanks to TheRealLoki for putting me on the right track!

Author Comment

ID: 17944710
I forgot to say above that you need to test for your memo being empty before adding the body - otherwise you will get the "this is a multipart..." message added in.

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month17 days, 11 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question