An invalid character was found in the mail header: ','

Topics: Help requests
Jun 20, 2014 at 8:18 AM
Edited Jun 20, 2014 at 8:56 AM
Hi there.

Im downloading all email from Inbox. Im getting this error An invalid character was found in the mail header: ','. I just wanna download them all and then move it to certain folders so I dont care about if mail is valid or not. Can I somehow ignore this exception or whatever that is causing this error? Here is my code for dowload messages from folder:
public MessageCollection GetMessages(string paFolderName)
        {
            var folder = GetFolder(paFolderName);

            if (folder != null)
            {
                folder.Messages.Download();
                return folder.Messages;
            }

            return null;
        }
GetFolder gives me folder according to parametrized name. Could you, please, give me some advice how to solve this issue? I would be very gratefull. BTW thanks very much for such a pretty awesome IMAP library:)

Bye
Coordinator
Jun 20, 2014 at 10:07 AM
Hi MartinLokajSVK,

this error is returned by the server, as a fix, please try the following:
// create client
client.Behavior.RequestedHeaders = null;
This will force the client to download all headers, without creating a filter for them.

Greets,

Pavel
Jun 20, 2014 at 10:26 AM
Hi Pavel,

Thanks very much for such a quick response:).

I've tried, what you suggested and it dont works. Unfortunately, Im still getting the error.
Here is my code that creates client:
public bool ConnectToIMAP()
        {
            aClient = new ImapClient(aServer, 993, SslProtocols.Tls, false);
            aClient.Behavior.RequestedHeaders = null;

            if (aClient.Connect())
            {
                if (aClient.Login(aLogin, aPassword))
                {
                    return true;
                }
                else
                    aMessenger.Error("Log error");
            }
            else
                aMessenger.Error("Could not connect to IMAP!");

            return false;
        }
When i break-point app before downloading messages RequestedHeaders is null. Any other ideas?:)

Thanks very much.
Coordinator
Jun 20, 2014 at 10:54 PM
Edited Jun 20, 2014 at 11:05 PM
Hi MartinLokajSVK,

sorry, my fault, the exception is thrown by the System.Net.Mail.MailAddress class. This is strange, because ImapX is using a custom class to hold a mail address. Can you get a detailed stacktrace for the exception?

Creating a log file of all server responses would also be helpful, the instructions on how to do this can be found in the documentation.

You can send me the log file to info@imapx.org

Thanks,

Pavel
Jun 21, 2014 at 9:01 AM
Hello!

Here is exception detail with extended stacktrace:):
Image

Im sorry, but i can not provide log file at the moment, because it is company mail. So, i hope the stacktrace will be enough. One more thing. Before the exception is thrown it already downloads 36 mails out of 276. So it breaks on 37 email. I forgot to mention it at the first post.

Thanks very much for your help and time:)

Bye
Coordinator
Jun 21, 2014 at 10:15 AM
Hi MartinLokajSVK,

I made a fix for your issue, you can check the latest code in the repository or download the compiled binary here: http://imapx.org/download/ImapX_2.0.0.16%20(21-June-2014).zip


Let me know if the problem still persists.

Greets,

Pavel
Jun 21, 2014 at 11:14 AM
Hi Pavel!

Again, thanks very much for such a quick response.

I downloaded compiled dll, added it to my project, but problem still remains:(.

Anyway, thanks very much for your help.

Martin
Coordinator
Jun 21, 2014 at 5:52 PM
Hi Martin,

I compiled another version, this time it will display the string on which the parsing is failing in the exception message.
You can download the binary here: http://imapx.org/download/ImapX.zip

Please post the exception message here, so I can make a fix :)

Thank you,

Pavel
Jun 22, 2014 at 5:56 AM
Hi there!

I tried your compiled DLL and there is error string, that is causing problem:
Image

Thank you very much for your patience and time.

Martin