Welcome, Guest
Guest Settings
Help

Thread: Problem with IMAP RetrieveAllEnvelopes


This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Apr 24, 2017 6:43 AM Last Post By: Dev Compusoft Threads: [ Previous | Next ]
Dev Compusoft

Posts: 3
Registered: 10/13/16
Problem with IMAP RetrieveAllEnvelopes  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 19, 2017 7:39 AM
Hello,
I'm new in the forum.

We developed an IMAP client in c++ buider XE5.

To retrieve the messages from a mailbox, we apply the following method :
....
email_IdIMAP->SelectMailBox("MyFolder");
email_IdIMAP->UIDRetrieveAllEnvelopes(email_IdIMAP->MailBox->MessageList);
for (int k = 0; k < email_IdIMAP->MailBox->MessageList->Count; k++)
{
...//Message treatment
}


It's works fine with many IMAP server, so for some mailbox we obtain an error "Max line length exceeded."
So for those folders, we can't retrieve messages

How can we prevent this error and what method do you recommend to fetch all messages ?

Thanks for your help
Remy Lebeau (Te...


Posts: 7,926
Registered: 12/23/01
Re: Problem with IMAP RetrieveAllEnvelopes  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 19, 2017 9:28 AM   in response to: Dev Compusoft in response to: Dev Compusoft
Dev wrote:

It's works fine with many IMAP server, so for some mailbox we obtain
an error "Max line length exceeded."

That exception is raised by TIdIOHandler.ReadLn() when it reads a line of
text that exceeds the length specified by the TIOHandler.MaxLineLength property,
which is set to 16384 by default. Most protocols do not use text lines nearly
that long. But, if your IMAP server is sending long lines without breaking
them up (and the IMAP protocol does have a syntax for that), then you will
just have to increase your IOHandler's MaxLineLength accordingly.

--
Remy Lebeau (TeamB)
Dev Compusoft

Posts: 3
Registered: 10/13/16
Re: Problem with IMAP RetrieveAllEnvelopes  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 20, 2017 12:36 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thanks for your reply,

{quote:title=Remy Lebeau (TeamB) wrote}
That exception is raised by TIdIOHandler.ReadLn() when it reads a line of
text that exceeds the length specified by the TIOHandler.MaxLineLength property,
which is set to 16384 by default. Most protocols do not use text lines nearly
that long. But, if your IMAP server is sending long lines without breaking
them up (and the IMAP protocol does have a syntax for that), then you will
just have to increase your IOHandler's MaxLineLength accordingly.

With your help, i found the property email_IdIMAP->IOHandler->MaxLineLength. This property is set to 16384.

Can i increase it to 32768 ? Forever or only in case of error ?

I found too the property mail_IdIMAP->IOHandler->MaxLineAction. By default, this property is set as maException. But it can be set to maSplit.
What is the consequence and the risk of these changes ?

Thanks for your help.

Edited by: Dev Compusoft on Apr 20, 2017 12:36 AM
Remy Lebeau (Te...


Posts: 7,926
Registered: 12/23/01
Re: Problem with IMAP RetrieveAllEnvelopes [Edit]
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 20, 2017 9:30 AM   in response to: Dev Compusoft in response to: Dev Compusoft
Dev wrote:

With your help, i found the property
email_IdIMAP->IOHandler->MaxLineLength.

Yes, that is the one.

Can i increase it to 32768 ?

You can set it to whatever you want, but first you need to find out just
how long the offending line really was to begin with. Use a packet sniffer,
like Wireshark, or just assign one of Indy's TIdLog... components to the
TIdIMAP4::Intercept property, and then try to download the same email again,
and look at the resulting capture of the data.

Worse case, just set the MaxLineLength to MaxInt instead, which effectively
means a line can be as long as available memory can handle.

I found too the property mail_IdIMAP->IOHandler->MaxLineAction.
By default, this property is set as maException. But it can be set
to maSplit.

It can, but that will not fix your issue, in fact it will cause new issues.
TIdIMAP4 is not designed to handle lines of text being split. When it calls
ReadLn(), it expects to receive the entire line, not a partial line. So
don't change MaxLineAction to maSplit.

--
Remy Lebeau (TeamB)
Dev Compusoft

Posts: 3
Registered: 10/13/16
Re: Problem with IMAP RetrieveAllEnvelopes [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 24, 2017 6:43 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thanks a lot.
I tested using MaxInt and it works fine.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02