public static string ReturnMessagesAppendResponse(string commandLine, AppendCall appendCall, bool startTLS)
        {
            try
            {
                if (!appendCall.completed)
                {
                    if (startTLS)
                    {
                        appendCall.message += commandLine;
                    }
                    else
                    {
                        appendCall.message += commandLine + "\r\n";
                    }
                    if (appendCall.message.Length < appendCall.size)
                    {
                        return("");
                    }
                    if (appendCall.message.Length > appendCall.size)
                    {
                        appendCall.reset();
                        return(appendCall.tag + " NO APPEND Failed");
                    }
                    appendCall.completed = true;
                    return("");
                }

                File.WriteAllText(Environment.CurrentDirectory + $"/ImapMailBox/{appendCall.mailInfo.user}/{appendCall.mailInfo.mailboxname}/email_{appendCall.mailInfo.uid}.msg", appendCall.message);
                int success = SqliteQuery.InsertMailIntoMailBox(appendCall.mailInfo.user, appendCall.mailInfo.mailboxname, appendCall.mailInfo);
                appendCall.reset();
                return(appendCall.tag + " OK APPEND completed");
            }
            catch (Exception)
            {
                appendCall.reset();
                return(appendCall.tag + " No Can't APPEND");
            }
        }
        public static string ReturnAppendResponse(string tag, string argument, string userSession, AppendCall appendCall)
        {
            //var maths = Regex.Match(argument, "");
            var math = Regex.Match(argument, "^(?:((?:\"[\\w\\s]+\"|\\w+) \\((?:\\\\\\w+)*\\) \"[^\"]*\" \\{\\d*\\})|((?:\"[\\w\\s]+\"|\\w+) \\((?:\\\\\\w+)*\\) \\{\\d*\\})|((?:\"[\\w\\s]+\"|\\w+) \\{\\d*\\}))");

            if (!math.Success)
            {
                return(Response.ReturnParseErrorResponse(tag, "APPEND"));
            }
            MailInfo      mailAppend = new MailInfo();
            Flags         flags      = new Flags();
            string        mailBoxName;
            List <string> strFlag     = new List <string>();
            DateTime      Date        = DateTime.Now;
            int           messageSize = 0;

            if (math.Groups[3].Success)
            {
                math        = Regex.Match(math.Groups[3].Value, "(?:(\"[\\w\\s]+\"|\\w+) \\{(\\d*)\\})");
                mailBoxName = math.Groups[1].Value.Replace("\"", "");
                if (math.Groups[2].Value != "" && !Int32.TryParse(math.Groups[3].Value, out messageSize))
                {
                    return(Response.ReturnParseErrorResponse(tag, "APPEND"));
                }
            }
            else
            {
                if (math.Groups[2].Success)
                {
                    math        = Regex.Match(math.Groups[2].Value, "(?:(\"[\\w\\s]+\"|\\w+) \\(((?:\\\\\\w+)*)\\) \\{(\\d*)\\})");
                    mailBoxName = math.Groups[1].Value.Replace("\"", "");
                    if (math.Groups[2].Value != "")
                    {
                        strFlag = math.Groups[2].Value.Split(' ').ToList();
                    }
                    if (math.Groups[3].Value != "" && !Int32.TryParse(math.Groups[3].Value, out messageSize))
                    {
                        return(Response.ReturnParseErrorResponse(tag, "APPEND"));
                    }
                }
                else
                {
                    math        = Regex.Match(math.Groups[1].Value, "(?:(\"[\\w\\s]+\"|\\w+) \\(((?:\\\\\\w+)*)\\) \"([^\"]*)\" \\{(\\d*)\\})");
                    mailBoxName = math.Groups[1].Value.Replace("\"", "");
                    if (math.Groups[2].Value != "")
                    {
                        strFlag = math.Groups[2].Value.Split(' ').ToList();
                    }
                    if (math.Groups[3].Value != "")
                    {
                        try
                        {
                            Date = Convert.ToDateTime(math.Groups[3].Value);
                        }
                        catch
                        {
                            return(Response.ReturnParseErrorResponse(tag, "APPEND"));
                        }
                    }
                    if (math.Groups[4].Value != "" && !Int32.TryParse(math.Groups[4].Value, out messageSize))
                    {
                        return(Response.ReturnParseErrorResponse(tag, "APPEND"));
                    }
                }
            }
            List <MailBoxInfo> mailBoxInfoList = SqliteQuery.LoadMailBoxInfo(userSession, mailBoxName);

            if (mailBoxInfoList.Count == 0)
            {
                return(tag + " NO Mailbox does not exist");
            }
            if (!flags.BuildFlagItem(strFlag.ToArray()))
            {
                return(Response.ReturnParseErrorResponse(tag, "APPEND"));
            }
            mailAppend.user        = userSession;
            mailAppend.mailboxname = mailBoxName;
            mailAppend.uid         = mailBoxInfoList[0].uidnext;
            mailAppend.recent      = 1;
            mailAppend.seen        = (flags.seen == "1" ? 1 : 0);
            mailAppend.answered    = (flags.answered == "1" ? 1 : 0);
            mailAppend.deleted     = (flags.deleted == "1" ? 1 : 0);
            mailAppend.draft       = (flags.draft == "1" ? 1 : 0);
            mailAppend.flagged     = (flags.flagged == "1" ? 1 : 0);
            mailAppend.intertime   = ((DateTimeOffset)Date).ToUnixTimeSeconds();
            appendCall.isCall      = true;
            appendCall.mailInfo    = mailAppend;
            appendCall.size        = messageSize;
            appendCall.tag         = tag;
            return("+ Ready for append literal");
        }