Board index » delphi » Indy TIdIMAP4 to implement a simple IMAP4 client

Indy TIdIMAP4 to implement a simple IMAP4 client


2008-06-12 04:28:49 PM
delphi239
Some questions on using TIdIMAP4:
1. I get MailBoxList by IdIMAP41.ListMailBoxes(mMailBoxList). It is fast to
do this.
2. I get the mailbox details by IdIMAP41.SelectMailBox(MailBoxName). Even
using IdIMAP41.RetrieveOnSelect:=rsHeaders, program needs to use 29seconds
to get 39 messages. It is too slow. Any suggestions?
3. Then using IdIMAP41.MailBox.MessageList.messages[i], I can get the
message (date, text, subject, etc.). BUT UID is empty?
4. I want to know more about the usages of RetrieveAllEnvelopes and
UIDRetrieveAllEnvelopes? What are their differences?
5. In my IMAP4 client program, I need to read emails from the email server
each time. Since the process is slow, can I do something to increase its
performance? Can I store the last status or last datetime of my data
retrieve, and read the 'delta' difference?
Thanks in advance.
Benson.
Indy 9.0 for D5.
 
 

Re:Indy TIdIMAP4 to implement a simple IMAP4 client

"Benson Wong" <XXXX@XXXXX.COM>writes
Quote
I get the mailbox details by IdIMAP41.SelectMailBox(MailBoxName).
Even using IdIMAP41.RetrieveOnSelect:=rsHeaders, program needs
to use 29seconds to get 39 messages. It is too slow. Any suggestions?
Welcome to IMAP. It is a very complex protocol and requires a lot of
processing.
Quote
Then using IdIMAP41.MailBox.MessageList.messages[i], I can get
the message (date, text, subject, etc.). BUT UID is empty?
UID is not a standard RFC822 header item, and thus may not be included in
the downloaded data. You have a few choices:
1) use GetUID() to retreive it separately
2) set RetreiveOnSelect to rsDisabled and download messages manually.
TIdMessage.UID is filled in by UIDRetrieveAllEnvelopes() and various
Retrieve...() methods.
3) edit TIdIMAP4's source code to make the following change (untested) and
then recompile Indy:
function TIdIMAP4.RetrieveHeader(const AMsgNum: Integer; AMsg:
TIdMessage): Boolean;
var
LStr: string;
begin
...
if GetInternalResponse(GetCmdCounter, [IMAP4Commands[cmdFetch]],
False) = IMAP_OK then begin
// add these two lines...
AMsg.UID := FLineStruct.UID;
AMsg.Flags := FLineStruct.Flags;
Result := True;
end;
...
end;
Quote
I want to know more about the usages of RetrieveAllEnvelopes
and UIDRetrieveAllEnvelopes? What are their differences?
The only difference between them is that UIDRetrieveAllEnvelopes() retreives
message UIDs whereas RetrieveAllEnvelopes() does not. They are identical in
all other respects.
Quote
In my IMAP4 client program, I need to read emails from the email
server each time. Since the process is slow, can I do something to
increase its performance?
Why don't you cache the emails locally instead of downloading them over and
over?
Quote
Can I store the last status or last datetime of my data retrieve,
and read the 'delta' difference?
Disable RetreiveOnSelect and then download only the emails you have not
already downloaded.
Gambit
 

Re:Indy TIdIMAP4 to implement a simple IMAP4 client

Thanks for your reply.
"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>׫Œ‘ì¶à]¼þЄ:48515a4d$XXXX@XXXXX.COM...
Quote

"Benson Wong" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...

>I get the mailbox details by IdIMAP41.SelectMailBox(MailBoxName).
>Even using IdIMAP41.RetrieveOnSelect:=rsHeaders, program needs
>to use 29seconds to get 39 messages. It is too slow. Any suggestions?

Welcome to IMAP. It is a very complex protocol and requires a lot of
processing.

>Then using IdIMAP41.MailBox.MessageList.messages[i], I can get
>the message (date, text, subject, etc.). BUT UID is empty?

UID is not a standard RFC822 header item, and thus may not be included in
the downloaded data. You have a few choices:

1) use GetUID() to retreive it separately

2) set RetreiveOnSelect to rsDisabled and download messages manually.
TIdMessage.UID is filled in by UIDRetrieveAllEnvelopes() and various
Retrieve...() methods.

3) edit TIdIMAP4's source code to make the following change (untested) and
then recompile Indy:

function TIdIMAP4.RetrieveHeader(const AMsgNum: Integer; AMsg:
TIdMessage): Boolean;
var
LStr: string;
begin
...
if GetInternalResponse(GetCmdCounter, [IMAP4Commands[cmdFetch]],
False) = IMAP_OK then begin

// add these two lines...
AMsg.UID := FLineStruct.UID;
AMsg.Flags := FLineStruct.Flags;

Result := True;
end;
...
end;

>I want to know more about the usages of RetrieveAllEnvelopes
>and UIDRetrieveAllEnvelopes? What are their differences?

The only difference between them is that UIDRetrieveAllEnvelopes()
retreives message UIDs whereas RetrieveAllEnvelopes() does not. They are
identical in all other respects.

>In my IMAP4 client program, I need to read emails from the email
>server each time. Since the process is slow, can I do something to
>increase its performance?

Why don't you cache the emails locally instead of downloading them over
and over?

>Can I store the last status or last datetime of my data retrieve,
>and read the 'delta' difference?

Disable RetreiveOnSelect and then download only the emails you have not
already downloaded.


Gambit

 

Re:Indy TIdIMAP4 to implement a simple IMAP4 client

More questions on the below discussion:
1. In IdIMAP4.pas, AMsgNum (integer) and AMsgUID (string) are used. Do they
unique to the email messages? If not, do email messages have a unique
identification properties?
2. From the discussion by Remy Lebeau
Quote
Disable RetreiveOnSelect and then download only the emails you have not
already downloaded.
How can I download "only the emails" I have not already downloaded?
How do I know which emails in IMAP server I have not already downloaded?
Pls. help
Benson.
"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>׫Œ‘ì¶à]¼þЄ:48515a4d$XXXX@XXXXX.COM...
Quote

"Benson Wong" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...

>I get the mailbox details by IdIMAP41.SelectMailBox(MailBoxName).
>Even using IdIMAP41.RetrieveOnSelect:=rsHeaders, program needs
>to use 29seconds to get 39 messages. It is too slow. Any suggestions?

Welcome to IMAP. It is a very complex protocol and requires a lot of
processing.

>Then using IdIMAP41.MailBox.MessageList.messages[i], I can get
>the message (date, text, subject, etc.). BUT UID is empty?

UID is not a standard RFC822 header item, and thus may not be included in
the downloaded data. You have a few choices:

1) use GetUID() to retreive it separately

2) set RetreiveOnSelect to rsDisabled and download messages manually.
TIdMessage.UID is filled in by UIDRetrieveAllEnvelopes() and various
Retrieve...() methods.

3) edit TIdIMAP4's source code to make the following change (untested) and
then recompile Indy:

function TIdIMAP4.RetrieveHeader(const AMsgNum: Integer; AMsg:
TIdMessage): Boolean;
var
LStr: string;
begin
...
if GetInternalResponse(GetCmdCounter, [IMAP4Commands[cmdFetch]],
False) = IMAP_OK then begin

// add these two lines...
AMsg.UID := FLineStruct.UID;
AMsg.Flags := FLineStruct.Flags;

Result := True;
end;
...
end;

>I want to know more about the usages of RetrieveAllEnvelopes
>and UIDRetrieveAllEnvelopes? What are their differences?

The only difference between them is that UIDRetrieveAllEnvelopes()
retreives message UIDs whereas RetrieveAllEnvelopes() does not. They are
identical in all other respects.

>In my IMAP4 client program, I need to read emails from the email
>server each time. Since the process is slow, can I do something to
>increase its performance?

Why don't you cache the emails locally instead of downloading them over
and over?

>Can I store the last status or last datetime of my data retrieve,
>and read the 'delta' difference?

Disable RetreiveOnSelect and then download only the emails you have not
already downloaded.


Gambit

 

Re:Indy TIdIMAP4 to implement a simple IMAP4 client

"Benson Wong" <XXXX@XXXXX.COM>writes
Quote
1. In IdIMAP4.pas, AMsgNum (integer) and AMsgUID (string)
are used. Do they unique to the email messages?
Yes.
Quote
How can I download "only the emails" I have not already downloaded?
It is your responsibility to keep track of the IDs you have already
downloaded. When then you select the mailbox again later on, you can see if
any new IDs have appeared and download only those messages.
Gambit