How to Use Indy 10 Imap Intercept function for Logging

It took me a while to track down enough information to figure out how to use Imap.Intercept to log raw IMAP client/server communication to troubleshoot an SSL account issue, so thought I’d share a basic code snippet on how to have IMAP log to disk the communications.

var
idLogFile1 : TidLogFile;
begin
IMAP := TIdIMAP4.Create(nil);

idLogFile1 := TidLogFile.Create(nil);
idLogFile1.Filename := 'C:\temp\imaplog.txt';
idLogFile1.active := True;

IMAP.Intercept := idLogFile1;

//...
end;

Installing Indy9 from Source Code

I’m finally working on getting Delphi 7 set up on my Win7 x64 machine. I think it’s been over a year since I last did this on my Vista machine or my Win7 x32 netbook, so my mind totally went blank trying to remember how to install the lastest version of Indy 9.

I already had pulled the code from Indy’s SVN server and been able to transfer that from the old machine, so I was one step ahead there.

I pulled up the “ManualInstall.txt” document in the Indy source directory and tried to follow the directions, only to find it didn’t work. At first it looked like it was a permissions issue, I needed to be running a batch file called fulld7.bat from a command line running on elevated privileges to get the script to run without errors, however, even after sorting all that out, when you get to the step of Installing the *.bpl, even after you’ve correctly remembered which one is the right menu option install such, it just doesn’t work. Complains about a missing file (that just doesn’t seem to exist in the provided repository or compiled files directory).

Well, after much fiddling and trying to figure it out on my own, since the internet had no solutions, it turns out, those directions probably are obsolete, and doing it the way that actually *worked* was much easier…just not obvious if you haven’t been working with Delphi recently.

In the Indy 9 directory from the SVN, there’s a .DPK package file for each delphi version. So, since I’m using Delphi 7, double click Indy70.DPK, it opens in Delphi with a package window visible displaying a list of all the files. At this point you’re two clicks away from a working Indy install. Click “Compile” and then “Install” on the package window, and dismiss the dialogs that confirm those steps work, and suddenly Indy is on the component toolbar without even restarting Delphi.

So there you have it. I’m thinking documenting the steps on installing this that work will be helpful, because by the next time I get around to trying to install Indy on a new machine, I almost certainly will have forgotten how you install it, since you do it once and never touch it again, and odds are good that it will need re-installing after a hiatus where I haven’t touched Delphi in a while period and can’t remember off the top of my head the difference  between installing a component and installing a package, since that’s very delphi-specific terminology.

New Project: Porting PopTrayU to FreePascal?

Poking around on the internet for one reason or another (maybe I was browsing posts about Delphi on the Programmers Stack Overflow/Exchange site?), I came across something interesting. Lazarus, the open-source IDE for Free Pascal. 

Lazarus is an open source equivalent to Delphi. Well, not exactly equivalent, but pretty close.. It comes with (not terribly well documented at the moment) tools to port Delphi code to Free Pascal, and comes with the Lazarus Component Library (LCL) which is very similar to Delphi’s Visual Component Library (VCL).

The idea of porting PopTrayU to an open source development platform instead of an expensive closed source one (namely: Delphi XE) is very much in the spirit of open-source development. It was always one of the dreams of Renier (the original PopTray developer) to port PopTray to a free platform, and he indicated he might be interested in continuing to develop the app if it could be ported. And it would save me the expense of upgrading to Delphi XE to fix some various bugs.

I’d previously looked into porting PopTray to the free version of Turbo Delphi 2006, but my feasibility analysis results were that it was not feasible. That version of Delphi, aside from being discontinued/no longer supported or “officially” available, was that it left out a key feature (namely, 3rd party component support).

Free Pascal and Lazarus, from what I’ve said so far looks more promising as far as being feasible. Indy components has been ported to Free Pascal, which is a key stepping stone, though investing whether I’d have to port to Indy 10 first or not remains to be determined. So far everything else I’ve been reading looks like it would “probably” be possible without significant loss of critical features, but it wouldn’t be a plug and play transition, you have to rename a bunch of things and change the imports, and some of the UI might get mangled porting it so you might have to redraw parts of the UI. But so far haven’t come across any definite showstoppers.

At the moment, the biggest risk for showstopping problems would be if there is a missing library eg “things that are very windows specific” may be missing. But nothing specific yet. There would definitely be some hurdles to fix the unicode issues, but that’s to be expected and certainly fixable. Even though Free Pascal is multi-platform, the probram would still only run on Windows, because of Indy and it’s limited compatibility with other platforms.

So that’s on my todo list. And in between downloading Lazarus and now, they’ve already gone from version 0.8 to 1.0 of the IDE. Actively developed and being improved regularly is a positive sign to look for.

Show Modal in Delphi

I was looking today at whether I could fix that annoying bug where a modal error message is shown, and if you switch to another application, when you switch back, the modal dialog gets “lost” behind the main window that’s now inactive, so you have to jump through alt-tab hoops to re-activate the window that you’re trying to acknowledge/close.

The first relevant post I came across on Stack Exchange basically said, newer versions of Delphi add some properties like setting the parent of a popup, to overcome this problem. If on the other hand you are using Delphi 7…

Again? Another problem that just upgrading Delphi would fix without a convoluted workaround? It’s not a trivial upgrade to make the app work on a newer version of Delphi, but I could be trading one bucket of problems for another….I just wish there was an edition of Delphi that wasn’t so expensive, or I probably would have already.

Delphi Reflections

As I continue to learn and work with Delphi, I am finding it to be quite an enjoyable language to program in. Sure, those begin-end blocks with the wordy labels for where they begin and end are a little harder to read than braces would be. But there’s also some little niceties, like single character delimiters for inline comments, that are not the same delimiters you would use to comment out a large block of code temporarily. There are certainly disadvantages to using such an old version of the language/IDE, I dearly miss “find references”, which would be super-useful considering I didn’t write most of the code and have to spend much time discovering how it works. Having struct equivalents, and super-flexible sorted string lists that can be just lists or maps or…(TStringList, THashedStringList)

I also like the UI for editing the GUI fairly well, the stretch to fill client area option and setting the anchor points seems a lot more intuitive to me than some of the Java layout managers/UI editors. I like the power and flexibility that Delphi is so closely related to the C++ language of families that you can use certain C++isms (eg: String pointers) when you need them, but pretend they don’t exist the rest of the time. And being able to use functions from the Windows API makes me feel a little bit at home from my C++ programming days.

Overall, this has been a really fun project to work on, even with the not knowing the language well handicap (yes, there has been LOTS of Googling. Especially since Barnes & Noble didn’t have ANY Delphi related programming books in stock. Maybe next time I’m in the Bay Area I could acquire a printed book or two?

Before And After Screenshots

I thought I’d share some before and after screenshots of the work I’ve done so far.

Here’s the main screen of the application before:

And here is the after shot:

You’ll notice two of the emails look like gibberish both in the before and after shots. Those were test emails I created with subjects in a single foreign language (one is in Hebrew, and one in Greek), so Outlook decided to encode them with the encodings windows-1255 and iso-8859-7 respectively. This is a case I’d like to handle better in the future. But even without that, still a much more usable version.

And for fun, here’s another screen I’ve been working on. It is supposed to look like this (in the old version of PopTray):

But if you’re using Vista or above, and using the Aero theme, because of some screen refresh bugs (not specific to the app) usually it looks more like this:

So my changes to this screen include moving the alignment of the buttons to “cling” to the right side of the window, and adding code in the window resize to stretch the textboxes when you resize the window. Textboxes that are too small that don’t resize when you make the window bigger is a pet peeve of mine. So I thought I’d fix it.

And while I was at it, I looked into workarounds for the refresh issues, and found that adding a call to refresh the inner panel (aka “frame” in delphi) with the missing labels and buttons on create and after the window is resized reduces the problem by about 95%, as in, it displays correctly on load and it’s only a problem now if you drag the window off the screen and back, but if you resize the window it redraws it properly, so it’s much easier to work around. If I ported the app from Delphi 7 to a newer version of Delphi this problem would probably go away entirely, so it’s not really worth the investment to try to workaround that last 5% issue.

Sourceforge Recovered!

I finally recovered access to my SourceForge account, so I was able to contact the original developer of PopTray about enhancing it. He suggested I should fork the code and create my own base with a new name, and if he likes it he might even add a link from the PopTray homepage.

So now I need to think of a new name for my improved version of PopTray. Better PopTray? PopTrayEx? PopTray Enhanced? PoptrayPlus? Hmmm…Decisions

Delphi

I wouldn’t have picked Delphi, personally, as a language to take up. I like, generally, working with languages that use C style syntax, and every time I jump into Visual Basic, which is fairly comparable with Delphi from what I gather, the IDE and GUI Builders are lovely, but the syntax is nutty and harder to remember. I don’t know other Delphi programmers, so I don’t have friends or co-workers to whom I can ask questions about the language. And then the kicker, learning Delphi is not likely to open doors career-wise, you just don’t see hordes of job listings looking for Pascal/Delphi programmers these days. Getting additional practice or depth in a language that I’d be likely to use professionally would just seem so much more “practical”.

But in a way, working with this code written in Delphi is also very much like the real-world. I’m thrust into a code-base I didn’t write, in a language I’m not an expert at, with a specific goal in mind that requires knowledge I don’t already have. Doing the leg-work of research to invent a solution to a problem, with external constraints, is very much a real-world scenario. It takes the same sort of deciphering other people’s code, coming up with a theory about where you need to modify the code to create the change you need to make, doing research to find all the bits and pieces of knowledge you don’t already have and synthesizing them into a solution unique to the problem at hand.

In the end it’s satisfying though. You put the pieces together and see it come closer and closer to a working solution. And then there it is, solved. And I have to say, as I work with Delphi, and overcome the humps of orienting myself with the language and IDE (like why there’s no toolbar button for viewing the call-stack on the debug toolbar) and so on, it’s not a terrible language to work with. I really enjoy this sort of programming, it’s a night and day contrast compared to writing PHP code, even though I’m primarily self-taught in both areas. I enjoy it, even though there’s certainly things that could be documented better that seem basic but not obvious.