This project is read-only.

ExecuteAppend timeout

Jul 30, 2012 at 10:24 AM

Hi,

I'm trying to add a draft into a gmail drafts folder. I can connect, list, etc without any problem to my gmail account. However, as soon as i try to use the ExecuteAppend (using the same details as provided in the sample), i always receive a timeout on the response.

I'm using the latest build version. Also, instead of using [Gmail]/Drafts, i use the local translated version of the folder name (as given by the list command). Neither works.

Dim smg As SmtpMessage = New SmtpMessage("blowdoof@gmail.com", "info@bumper.be", "", "test", "test text")
Dim mailText1 As String = smg.GetDataText()
Dim appendit As ImapCommandResult = cl.ExecuteAppend("[Gmail]/Concepten", mailText1, "\\Draft", DateTimeOffset.Now)

Any idea?

Kind rgds,

Tino

Jul 30, 2012 at 12:32 PM
Edited Jul 30, 2012 at 12:32 PM

I could not reproduct your problem.
My reproduct code is here.
I could append draft mail to my folder.
Please execute this code to your mailbox and report me.

using (ImapClient cl = new ImapClient("imap.gmail.com", 993, "username", "pass"))
{
    cl.ResponseEncoding = Encoding.UTF8;
    cl.Ssl = true;
    cl.Port = 993;
    cl.Open();
    if (cl.Authenticate() == true)
    {
        SmtpMessage mg = new SmtpMessage();
        mg.Subject = "Append test";
        mg.From = "<your mail address>";
        mg.To.Add(new MailAddress("mail address"));
        mg.BodyText = "This is a draft mail.";

        var rs = cl.ExecuteAppend("[Gmail]/Concepten", mg.GetDataText(), "\\Draft", DateTimeOffset.Now);
    }
}
Jul 30, 2012 at 3:20 PM

Copies the exact same code, still getting the same timeout. Tried with 2 different gmail accounts. Strange. Could it be some sort of gmail setting? As far as i know, only setting involved is Imap enabled yes/no, which is set to yes.

Rgds,

Tino 

Jul 31, 2012 at 10:24 AM

Ok, I found something.

When sending the append command, 2 commands are send: first one with the append command, then the one containing the message.

After sending the first 'append' command, it never receives an (expected) answer. I think because the answer doesn't contain the tag send along with other requests. When testing, i receive an answer from google, something like '+ go ahead'.

If i change the code/routine to not wait for an answer on this particular command (so only on the first of 2 send within the append routine), it works perfect.

Tried finding the answer how exactly the tag is involved in receiving or not receiving an answer, but haven't found it yet.

Basically, i just added a routine in  ImapClient.cs:

 private String ExecuteNoResponse(String command)
        {
            this.Send(command);
            this.Commnicating = true;
            return "OK";
        }

and when calling the append, changed:

 

commandText += "{" + mailData.Length + "}";        
            String s = this.ExecuteNoResponse(commandText);
            var rs = new ImapCommandResult(this.Tag, s);

 

If someone knows the exact reason how to change the existing routine's for the non-tag issue, please let me know

Rgds,

Tino

 

 

Aug 1, 2012 at 10:23 AM

Thank you for your detail report.
It is very useful and helpful.

I'm fixing this bug.
It will complete in a few days.
Please wait.

Aug 2, 2012 at 7:59 AM

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

And again, thank you for your contribution.

Aug 2, 2012 at 10:51 PM

Hi,

thank you for the quick response !!! I'll test the new solution and provide feedback asap.

In the meantime, i have also written some minor implementations of the extended imap features (like google uses) , like XLIST (instead of LIST), very handy for international versions for example (meaning you don't have to rely or manually enter each possible translated version of 'Draft' for example). Is that something you could use for the library? (Its basically a 90% copy of the existing LIST function)

rgds

Tino

Nov 18, 2012 at 12:04 PM

Thank you for your contiribution.
I would like to implement your XLIST source code to my library.
Please send me your source.

regards.

Nov 18, 2012 at 7:54 PM

Hello,

i've basically just added following routines:

1. into ImapClient.cs: (highLabo.Mail\Imap)

       /// <summary>
        /// Send xlist command to IMAP server.
        /// </summary>
        /// <param name="folderName"></param>
        /// <param name="recursive"></param>
        /// <returns></returns>
        public XListResult ExecuteXList(String folderName, Boolean recursive)
        {
            this.ValidateState(ImapConnectionState.Authenticated);

            List<XListLineResult> l = new List<XListLineResult>();
            String name = "";
            Boolean noSelect = false;
            Boolean hasChildren = false;
            String rc = "%";
            String xname = "";
            if (recursive == true)
            {
                rc = "*";
            }
            String s = this.Execute(String.Format(this.Tag + " XLIST \"{0}\" \"{1}\"", folderName, rc));
            foreach (Match m in RegexList.GetXListFolderResult.Matches(s))
            {
                xname = "";
                name = NamingConversion.DecodeString(m.Groups["name"].Value);
                foreach (Capture c in m.Groups["opt"].Captures)
                {
                    if (c.Value.ToString() == "\\Noselect")
                    {
                        noSelect = true;
                    }
                    else if (c.Value.ToString() == "\\HasNoChildren")
                    {
                        hasChildren = false;
                    }
                    else if (c.Value.ToString() == "\\HasChildren")
                    {
                        hasChildren = true;
                    }
                    else if (c.Value.ToString().Length > 0)
                    {
                        xname = c.Value.ToString();
                    }
                }
                l.Add(new XListLineResult(name, noSelect, hasChildren, xname));
            }
            return new XListResult(l);
        }
2. Into ListResult.cs (highLabo.Mail\Imap\Command) 
  /// </summary>
    public class XListResult
    {
        /// <summary>
        /// 
        /// </summary>
        public ReadOnlyCollection<XListLineResult> Lines { get; private set; }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="lines"></param>
        public XListResult(List<XListLineResult> lines)
        {
            this.Lines = new ReadOnlyCollection<XListLineResult>(lines);
        }
    }
3. Into ListLineResult.cs (highLabo.Mail\Imap\Command)
  /// </summary>
    public class XListLineResult
    {
        /// <summary>
        /// 
        /// </summary>
        public String Name { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean HasChildren { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean NoSelect { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String XName { get; set; }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="folderName"></param>
        /// <param name="noSelect"></param>
        /// <param name="hasChildren"></param>
        public XListLineResult(String folderName, Boolean noSelect, Boolean hasChildren, string xName)
        {
            this.Name = folderName;
            this.NoSelect = noSelect;
            this.HasChildren = hasChildren;
            this.XName = xName;
        }
    }
Kind rgds,
Tino

Nov 18, 2012 at 11:43 PM

Thank you for your post.
That's great!

But RegexList.GetXListFolderResult does not include above post.
Please give me your implementation.

regards.

Nov 18, 2012 at 11:50 PM

I added GetXListFolderResult like this.

            public static readonly Regex GetXListFolderResult = new Regex("^\\* XLIST <a href="file://\\(((?\\\\\\w+)\\s?)+\\">\\(((?<opt>\\\\\\w+)\\s?)+\\) \".\" \"(?<name>.*?)\"", RegexOptions.Multiline | RegexOptions.IgnoreCase);

If it is different to your implementation, please let me know yours.

Nov 19, 2012 at 4:48 PM
Edited Nov 19, 2012 at 4:49 PM

Hi yes indeed, forgot to give the regex

 public static readonly Regex GetXListFolderResult = new Regex("^\\* XLIST \\(((?<opt>\\\\\\w+)\\s?)+\\) \".\" \"(?<name>.*?)\"", RegexOptions.Multiline | RegexOptions.IgnoreCase);

Kind rgds