public static int InsertMailIntoMailBox(string userSession, string userMalBox, MailInfo mail) { IDbConnection cnn = new SQLiteConnection("Data Source = .\\Imap\\ImapDB.db"); cnn.Open(); try { cnn.Execute($"insert into MailInfo(user,mailboxname,uid,recent,seen,answered,flagged,draft,deleted) values('{mail.user}','{mail.mailboxname}',{mail.uid},1,{mail.seen},{mail.answered},{mail.flagged},{mail.draft},{mail.deleted})", new DynamicParameters()); return(1); } catch (SQLiteException) { return(0); } finally { cnn.Close(); } }
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"); }