IMAP ExecuteAppend Method Fails

Nov 15, 2012 at 4:59 PM

Hi,

I'm trying to upload a mail message to my Sent Folder with IMAP; i receive always the error

"tag1 BAD Protocol Error: "Specified date is not valid""

This is my code:

            imapClient = New HigLabo.Net.Imap.ImapClient(mConfig.serverName)
            Try
                With imapClient
                    .UserName = mConfig.authenticationUser
                    .Password = mConfig.authenticationPassword
                    .Port = mConfig.port
                    .Ssl = False

                    If .Authenticate = True Then
                    Dim res As HigLabo.Net.Imap.ImapCommandResult = .ExecuteAppend("Sent Mail", mailMsg.GetDataText, "", DateTimeOffset.Now)
                    End If
                End With

            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
            imapClient.Close()

Also set DateTimeOffet argument to Nothing or using method with first two argument only does not works.

I'm using 1.2.9 of Higlabo.Mail.

What's wrong ?

Thanks

Max

 

Coordinator
Nov 18, 2012 at 11:05 AM

There is a bug.
I'll fix it on Monday and upload fixed version.
Please wait for it.

Thank you for your report.

Coordinator
Nov 18, 2012 at 11:29 PM

I fixed this bug and upload new version.
Please check it out!!

Nov 19, 2012 at 12:31 PM
Edited Nov 19, 2012 at 1:03 PM

Hi Higty,

Thanks for your interest.

I tried but don't works ... same error ...

If may help you, my International settings is for Italian system. I tried with English settings but without success.

Regards

 

 

Coordinator
Nov 22, 2012 at 6:49 AM

Please ensure your folder name is correct.
My environment, I could not reproduct your bug.
Please send me the return value of mailMsg.GetDataText method.
I continue to investigate your problem.

regards

Nov 26, 2012 at 7:52 AM

Hi,

Here the informations:

....

results = .ExecuteAppend(message.imapFolder, mailMsg.GetDataText, "\Seen", DateTimeOffset.Now.ToUniversalTime)

....

where:

message.imapFolder= "Posta Inviata"  (as read from "GetAllFolders" method)

mailMsg.GetDataText:
"Date: Mon, 26 Nov 2012 08:43:41 +0100  From: Mail Test<myMail@MyDomain>  Subject: Mail Test  Content-Transfer-Encoding: 7bit  Content-Disposition: inline  MIME-Version: 1.0  Reply-To: <myMail@MyDomain>  Message-ID: <XMCC-E-57620121126094226359375@MXBA-WS01>  X-Mailer: Mail Tester by Me  Sender: <myMail@MyDomain>  X-Priority: 3  To: myMail@MyDomain  Content-Type: text/plain; charset="utf-8"    This is a message text for testing IMAP    .  "

DateTimeOffset.Now.ToUniversalTime
{26/11/2012 8.43.41 +00:00}
    Date: #11/26/2012#
    DateTime: #11/26/2012 8:43:41 AM#
    Day: 26
    DayOfWeek: Monday {1}
    DayOfYear: 331
    Hour: 8
    LocalDateTime: #11/26/2012 9:43:41 AM#
    MaxOffset: 504000000000
    MaxValue: {31/12/9999 23.59.59 +00:00}
    Millisecond: 687
    MinOffset: -504000000000
    Minute: 43
    MinValue: {01/01/0001 0.00.00 +00:00}
    Month: 11
    Now: {26/11/2012 9.43.42 +01:00}
    Offset: {00:00:00}
    Second: 41
    Ticks: 634895162216875000
    TimeOfDay: {08:43:41.6875000}
    UtcDateTime: #11/26/2012 8:43:41 AM#
    UtcNow: {26/11/2012 8.43.42 +00:00}
    UtcTicks: 634895162216875000
    Year: 2012

Thanks.

Max

Coordinator
Nov 26, 2012 at 11:13 PM

This may be same problem of other language environment.
http://higlabo.codeplex.com/discussions/399572

Please try below code.
------------------------------------------------------------
ImapClient cl = new ImapClient("your server name");
cl.RequestEncoding = Encoding.UTF8;
------------------------------------------------------------
Or try to other encoding.

Nov 27, 2012 at 3:17 PM

Sorry but doesn't works.

I tried with all Encoders, incluse Text.Encodings.GetEncodings (1252), Text.Encodings.GetEncodings (0) ....

But, for debug only, can you mail me a 'custom' dll that show a messagebox or a log with the datetime that your procedure internally receive, operating on my system ? Just for understand ...

Thanks

 

 

Coordinator
Nov 28, 2012 at 8:53 AM

OK.
I'll add log feature of actual data that send or receive from client to server.
But it will take few days or weeks.
Please wait for new version.


regards.

Coordinator
Nov 29, 2012 at 1:04 AM

I upload new version.
I added TraceSource property to SocketClient class.
You can trace what text is send and received from client to server.
I add sample code to add tracelistener to document page.
http://higlabo.codeplex.com/documentation

Please output log text and send me it.

regards.

Coordinator
Nov 30, 2012 at 9:33 AM

Here is a sample to add TraceListener.
-------------------------------------------------------------------------------------
SocketClient.TraceSource.Switch.Level =SourceLevels.All;
//Output to text file
StreamWriter
sw = new StreamWriter("C:\\TraceTest.txt");

sw.AutoFlush = true;
TextWriterTraceListener twtl = new TextWriterTraceListener(sw, "LogFile");
SocketClient.TraceSource.Listeners.Add(twtl);
//Out put to console window

ConsoleTraceListener ctl = new ConsoleTraceListener();
SocketClient.TraceSource.Listeners.Add(ctl);
-------------------------------------------------------------------------------------

Please try it.

Dec 3, 2012 at 2:20 PM

Hi, here the log file content:

HigLabo.Net.SocketClient Information: 0 : Client Send:tag1 APPEND "Posta inviata" () "Mon, 03 Dec 2012 14:50:59 +0100" {543}
Date: Mon, 03 Dec 2012 14:50:54 +0100
From: Mail Tester<myMail@myDomain>
Subject: Mail Test
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
MIME-Version: 1.0
Reply-To: <myMail@myDomain>
Message-ID: <XMCC-E-92720121203155054156250@MABA-WS01>
X-Mailer: Mail Tester
Sender: <myMail@myDomain>
X-Priority: 3
To: myMail@myDomain
Content-Type: text/plain; charset="utf-8"

This is a message test for check "Specified date is not valid" error.

.


HigLabo.Net.SocketClient Information: 0 : Client Receive:tag1 BAD Protocol Error: "Specified date is not valid".

 

Regards

Max

Coordinator
Dec 3, 2012 at 11:31 PM

I have no problem to append a mail to folder.
Here is a log text.

------------------------------------------------------------------------------------------------
Obic.Net.SocketClient Information: 0 : Client Send:tag1 APPEND "[Gmail]/&Tgtm+DBN-" (\Draft) "Tue, 04 Dec 2012 09:23:59 +0900" {312}
Date: Tue, 04 Dec 2012 09:23:59 +0900
From: test@gmail.com
Subject: Test with TraceSource
Content-Transfer-Encoding: Base64
Content-Disposition: inline
MIME-Version: 1.0
X-Priority: 3
To: test_to@hotmail.com
Content-Type: text/plain; charset="iso-2022-jp"

VGhpcyBpcyB0ZXN0IG1haWwu

.


Obic.Net.SocketClient Information: 0 : Client Receive:+ go ahead
tag1 OK [APPENDUID 594586702 249] (Success)
------------------------------------------------------------------------------------------------

Is your error reproduct to other folder?
Please test with other folder (Draft ... etc).

Dec 4, 2012 at 3:14 PM

I already tried to use other folder as Draft or new Custom Folder without spaces in the name, but with no success, i have specify Content-Transfer-Encoding to Base64 too but nothing. At the moment I don't have opportunity of testing another mailbox over other server.

Only I don't understand why the date value is wrong ... in the log the format is the same than your, I begin to think the problem is misleading and resides to another part ....

So, I will make other test, if there are news I will update you.

Thanks, Regards

 

Coordinator
Dec 5, 2012 at 12:38 AM

OK.
I wait for your news.
And I'll continue to investigate this problem.

Thanks.

Mar 5, 2013 at 10:45 AM
Hi,

On this issue I did more testing with your latest version unfortunately without success.
I noticed that the class SMTPMessage there is a "Date" property of type DateTimeOffset that cannot set and, as you can see from the image linked below, shows the error {"one of the elements identified has invalid format"}. I think this is the reason for the error with the ExecuteAppend method.

SMTPMessage.Date property values

This information tell you something?

Thanks
Regards
Max
Coordinator
Mar 11, 2013 at 12:30 AM
Hi.

Please tell me the value of mg["Date"] when exception occur.

regards
Mar 12, 2013 at 8:55 AM
Hi,

I send you a link to mailMsg values of SMTPMessage class, immediatly before of ExecuteAppend function call.
How to see mailMsg.Date already report the error ..

I hope this help you ...

SMTPMessage

Regards

Max
Coordinator
Mar 13, 2013 at 8:10 AM
Hi.

I want to see inside of mailMsg.Header.
Is it possible?

regards
Coordinator
Mar 13, 2013 at 8:14 AM
Or please show me this value.

var rawText = msg.Data;

regards.
Mar 13, 2013 at 8:18 AM
Hi,

Here the header ...

Image

Regards
Max
Coordinator
Mar 14, 2013 at 12:47 PM
I continue investigate this problem but I couldnot solve this.
I could append mail to GMail with below code.
        using (ImapClient cl = new ImapClient("imap.gmail.com", 993, "xxxxx@gmail.com", "xxxx"))
        {
            cl.ResponseEncoding = Encoding.UTF8;
            cl.Ssl = true;
            cl.Port = 993;
            cl.Open();
            if (cl.Authenticate() == true)
            {
                var ll = cl.GetAllFolders();

                SmtpMessage mg = new SmtpMessage();
                mg.Subject = "Date Test";
                mg.From = new MailAddress("<xxxx@yyy.co.jp>");
                mg.To.Add(new MailAddress("xxxx@gmail.com"));
                var rs = cl.ExecuteAppend("[Gmail]/Draft", mg.GetDataText(), "", DateTimeOffset.Now);
            }
        }
It seems a problem about your mail server.
I think that your mail server parse date format differently to GMail or other Imap server.
I you could, please try to send command by telnet with other date format.
Here is a inside of Imap protocol.
http://www.codeproject.com/Articles/411018/Understanding-the-insides-of-the-IMAP-mail-protoco
It may help you to send command by telnet.

regards.
Mar 18, 2013 at 9:01 AM
Hi,

Ok, When possible I try IMAP with other server, but If the smtpMsg.Date have a 'bad' value before to connect to server, I don't know if trying to other server resolve the issue. Otherwise I will make the test.

One question:

smtpMsg.Date have the same 'bad' value on your system than my one, and is unable to modify it, or have a correct value ?

Thanks
Regards
Max
Coordinator
Mar 20, 2013 at 11:21 PM
Hi Medusa.
In my environment, smtpMsg.Date has valid value.
It may be wrong response of Imap server.

Is there other question?
Mar 21, 2013 at 8:05 AM
Hi,

No other question, I will try to other IMAP server and will inform you of the outcome.

Meanwhile rest pending SMTPMessage implementation to send local images attached to HTML text.

Thanks.