protected override CompletionResponse Behaviour() { uint commandId = base._dispatcher.SendCommand(string.Format("SELECT \"{0}\"", base.mailbox), this.filter); IMAP4Response response = base._dispatcher.GetResponse(commandId); while (!response.IsCompletionResponse()) { base.ProcessResponse(response); response = base._dispatcher.GetResponse(commandId); } CompletionResponse response2 = new CompletionResponse(response.Response); if (response2.CompletionResult == ECompletionResponseType.OK) { if (!base._existsRecieved) { throw new ExpectedResponseException("Expected * <n> EXISTS"); } if (!base._recentRecieved) { throw new ExpectedResponseException("Expected * <n> RECENT"); } if (!base._flagsRecieved) { throw new ExpectedResponseException("Expected * FLAGS (list)"); } } base.ProcessCompletionResponse(response2); return(response2); }
protected override CompletionResponse Behaviour() { uint commandId = base._dispatcher.SendCommand("AUTHENTICATE LOGIN"); if (base._dispatcher.GetResponse(commandId).Type != EIMAP4ResponseType.Continuation) { throw new UnexpectedResponseException("Unexpected response"); } base._dispatcher.SendContinuationCommand(base.GetBase64String(base._username)); if (base._dispatcher.GetResponse(commandId).Type != EIMAP4ResponseType.Continuation) { throw new UnexpectedResponseException("Unexpected response"); } base._dispatcher.SendContinuationCommand(base.GetBase64String(base._password)); IMAP4Response response = base._dispatcher.GetResponse(commandId); if (!CompletionResponse.IsCompletionResponse(response.Response)) { throw new UnexpectedResponseException("Unexpected response"); } CompletionResponse response2 = new CompletionResponse(response.Response); if (response2.CompletionResult == ECompletionResponseType.NO) { throw new UnexpectedResponseException("Unexpected response"); } return(response2); }
protected override CompletionResponse Behaviour() { string str; if (this.encoding == null) { str = this.query.ToString(); } else { str = string.Concat(new object[] { "CHARSET ", this.encoding.WebName, " ", this.query }); } uint commandId = base._dispatcher.SendCommand("SEARCH " + str, this.filter); IMAP4Response response = base._dispatcher.GetResponse(commandId); this._uids = new MessageSequenceNumbers(); if (!response.IsCompletionResponse()) { if (response.Name != "SEARCH") { throw new UnexpectedResponseException("Unexpected response"); } this._uids = this.ParseResponse(response); response = base._dispatcher.GetResponse(commandId); if (!response.IsCompletionResponse()) { throw new UnexpectedResponseException("Unexpected response"); } } return(new CompletionResponse(response.Response)); }
private void ParseResponse(IMAP4Response response) { Match match = quotaRegex.Match(response.Response); Size = uint.Parse(match.Groups[1].Value); LimitSize = uint.Parse(match.Groups[2].Value); }
protected override CompletionResponse Behaviour() { uint commandId = base._dispatcher.SendCommand("LOGOUT", this.filter); IMAP4Response response = base._dispatcher.GetResponse(commandId); if (CompletionResponse.IsCompletionResponse(response.Response)) { CompletionResponse response2 = new CompletionResponse(response.Response); if (response2.CompletionResult != ECompletionResponseType.BAD) { throw new UnexpectedResponseException("Unexpected response"); } return(response2); } if ((response.Name != "BYE") || (response.Type != EIMAP4ResponseType.Untagged)) { throw new UnexpectedResponseException("Unexpected response"); } response = base._dispatcher.GetResponse(commandId); if (!CompletionResponse.IsCompletionResponse(response.Response)) { throw new UnexpectedResponseException("Unexpected response"); } CompletionResponse response3 = new CompletionResponse(response.Response); if (response3.CompletionResult == ECompletionResponseType.NO) { throw new UnexpectedResponseException("Unexpected response"); } return(response3); }
protected override CompletionResponse Behaviour() { uint commandId = base._dispatcher.SendCommand(@"UID FETCH 1:* (FLAGS UID RFC822.SIZE)", base.filter); IMAP4Response response = base._dispatcher.GetResponse(commandId); if (!response.IsCompletionResponse()) { if (response.Name != "FETCH") { throw new UnexpectedResponseException("Unexpected response"); } while (!response.IsCompletionResponse()) { try { this._statistics.Add(ParseResponse(response)); } catch (Exception exception) { if (this.BrokenMessage != null) { this.BrokenMessage(this, new BrokenMessageInfoArgs(exception.Message)); } } response = base._dispatcher.GetResponse(commandId); } } return(new CompletionResponse(response.Response)); }
protected void OnServerResponseReceived(IMAP4Response response) { EventHandler <ServerResponseReceivedEventArgs> serverResponseReceived = this.ServerResponseReceived; if (serverResponseReceived != null) { serverResponseReceived(this, new ServerResponseReceivedEventArgs(response)); } }
private StatisticInfo ParseResponse(IMAP4Response response) { uint serialNumber = uint.Parse(serialNumberRegex.Match(response.Response).Groups[1].Value); string uniqueNumber = uniqueNumberRegex.Match(response.Response).Groups[1].Value; uint messageSize = uint.Parse(messageSizeRegex.Match(response.Response).Groups[1].Value); string flags = flagsRegex.Match(response.Response).Groups[1].Value; return(new StatisticInfo(uniqueNumber, serialNumber, messageSize, flags)); }
protected ulong GetSize(IMAP4Response response) { Regex regex = new Regex(@"\{(?<size>[0-9]+)\}"); if (!regex.IsMatch(response.Data)) { throw new UnexpectedResponseException("Unexpected response"); } return(ulong.Parse(regex.Match(response.Data).Groups["size"].Value)); }
protected override CompletionResponse Behaviour() { MessageDescriptionParser parser = new MessageDescriptionParser(); StringBuilder builder = new StringBuilder(); int num = 0; List <string> subPartList = (this._partDescription == null ? new List <string>() { "" } : this.GetSubPartList(this._partDescription)); for (int i = 0; i < subPartList.Count; i++) { if (i > 0) { builder.Append(" "); } builder.Append(string.Format("BODY.PEEK[{0}]", subPartList[i])); } uint commandId = base._dispatcher.SendCommand(string.Format("UID FETCH {0} ({1})", this._message.Uid, builder), base.filter); IMAP4Response response = base._dispatcher.GetResponse(commandId); if (!response.IsCompletionResponse()) { if (response.Name != "FETCH") { throw new UnexpectedResponseException("Unexpected response"); } string input = response.Data.Substring(response.Data.IndexOf("(") + 1); while (num < subPartList.Count) { Regex regex = new Regex(@"[\}]*{(?<size>[0-9]+)}|(?<size>NIL)"); if (!regex.IsMatch(input)) { throw new Exception("Unexpected response"); } string s = regex.Match(input).Groups["size"].Value; num++; if (!s.Equals("NIL", StringComparison.OrdinalIgnoreCase)) { ulong size = ulong.Parse(s); byte[] rawData = base._dispatcher.GetRawData(size); byte[] bytes = Encoding.UTF8.GetBytes(input + "\r\n"); byte[] destinationArray = new byte[bytes.Length + rawData.Length]; Array.Copy(bytes, destinationArray, bytes.Length); Array.Copy(rawData, 0, destinationArray, bytes.Length, rawData.Length); this._message = parser.Parse(this._message, destinationArray, this._message.Uid, this._attachmentDirectory); byte[] rawDataBytes = base._dispatcher.GetRawData(); input = Encoding.UTF8.GetString(rawDataBytes, 0, rawDataBytes.Length); } } response = base._dispatcher.GetResponse(commandId); } return(new CompletionResponse(response.Response)); }
protected override CompletionResponse Behaviour() { uint commandId = base._dispatcher.SendCommand(string.Format("RENAME \"{0}\" \"{1}\"", this._oldname, this._newname)); IMAP4Response response = base._dispatcher.GetResponse(commandId); if (!response.IsCompletionResponse()) { throw new UnexpectedResponseException("Unexpected response"); } return(new CompletionResponse(response.Response)); }
protected override CompletionResponse Behaviour() { uint commandId = base._dispatcher.SendCommand(string.Format(DeletePattern, this._mailbox)); IMAP4Response response = base._dispatcher.GetResponse(commandId); if (!response.IsCompletionResponse()) { throw new UnexpectedResponseException("Unexpected response"); } return(new CompletionResponse(response.Response)); }
private MessageSequenceNumbers ParseResponse(IMAP4Response response) { MessageSequenceNumbers numbers = new MessageSequenceNumbers(); string data = response.Data; if (data.IndexOf(' ') != -1) { foreach (string str2 in data.Substring(data.IndexOf(' ') + 1).Split(new char[] { ' ' })) { numbers.Add(new SequenceNumber(uint.Parse(str2))); } } return(numbers); }
protected override CompletionResponse Behaviour() { uint commandId = base._dispatcher.SendCommand("EXAMINE " + base.mailbox, this.filter); IMAP4Response response = base._dispatcher.GetResponse(commandId); while (!response.IsCompletionResponse()) { base.ProcessResponse(response); response = base._dispatcher.GetResponse(commandId); } if (!base._unseenRecieved) { throw new ExpectedResponseException("Expected * OK [UNSEEN]"); } if (!base._uidnextRecieved) { throw new ExpectedResponseException("Expected * OK [UIDNEXT <n>]"); } if (!base._uidvalidityRecieved) { throw new ExpectedResponseException("Expected * OK [UIDVALIDITY <n>]"); } if (!base._existsRecieved) { throw new ExpectedResponseException("Expected * <n> EXISTS"); } if (!base._recentRecieved) { throw new ExpectedResponseException("Expected * <n> RECENT"); } if (!base._flagsRecieved) { throw new ExpectedResponseException("Expected * FLAGS (list)"); } if (!base._permanentFlagsRecieved) { throw new ExpectedResponseException("Expected * OK [PERMANENTFLAGS (list)]"); } CompletionResponse response2 = new CompletionResponse(response.Response); base.ProcessCompletionResponse(response2); if (base._access == EIMAP4MailBoxAccessType.ReadWrite) { throw new UnexpectedResponseException("Unexpected response"); } return(response2); }
protected override CompletionResponse Behaviour() { uint commandId = base._dispatcher.SendCommand("EXPUNGE", this.filter); IMAP4Response response = base._dispatcher.GetResponse(commandId); while (!response.IsCompletionResponse()) { if (response.Name != "EXPUNGE") { throw new UnexpectedResponseException("Unexpected response"); } int item = int.Parse(response.Data.Split(new char[] { ' ' })[0]); this.removed.Add(item); response = base._dispatcher.GetResponse(commandId); } return(new CompletionResponse(response.Response)); }
protected override CompletionResponse Behaviour() { this.matches = new MatchedNameCollection(); uint commandId = base._dispatcher.SendCommand(string.Format("{0} \"{1}\" \"{2}\"", this.cmd, this.referenceName, this.mailboxName), this.filter); IMAP4Response response = base._dispatcher.GetResponse(commandId); while (!response.IsCompletionResponse()) { if ((response.Name != this.cmd) || (response.Type != EIMAP4ResponseType.Untagged)) { throw new UnexpectedResponseException("Unexpected response"); } this.matches.Add(new MatchedName(response)); response = base._dispatcher.GetResponse(commandId); } return(new CompletionResponse(response.Response)); }
protected override CompletionResponse Behaviour() { uint commandId = base._dispatcher.SendCommand("STARTTLS"); IMAP4Response response = base._dispatcher.GetResponse(commandId); if (!CompletionResponse.IsCompletionResponse(response.Response)) { throw new UnexpectedResponseException("Unexpected response"); } CompletionResponse response2 = new CompletionResponse(response.Response); if (response2.CompletionResult == ECompletionResponseType.NO) { throw new UnexpectedResponseException("Unexpected response"); } return(response2); }
protected void GetServerData() { this._receiveInProgress = true; try { string str; lock (this._connection) { str = this._connection.ReceiveLine(); } lock (this) { IMAP4Response response = new IMAP4Response(str); if (response.IsCompletionResponse()) { uint num = uint.Parse(response.Tag); this._queues[num].Enqueue(str); } else if (response.Type == EIMAP4ResponseType.Continuation) { this._queues[this.monopolyCommanId].Enqueue(str); } else { string name = response.Name; if (this._filter.ContainsKey(name)) { List <uint> list = this._filter[name]; foreach (uint num2 in list) { this._queues[num2].Enqueue(str); } } else { this.OnServerResponseReceived(response); } } } } finally { this._receiveInProgress = false; } }
private void ProcessOK(IMAP4Response response) { string str = response.Data.Substring(response.Data.IndexOf(' ') + 1); if ((str.Length == 0) || (str[0] != '[')) { throw new UnexpectedResponseException("Unexpected response"); } if (str.IndexOf(']') == -1) { throw new UnexpectedResponseException("Unexpected response"); } int index = str.IndexOf(' '); int num2 = str.IndexOf(']'); string code = str.Substring(1, index - 1); string unseen = str.Substring(index + 1, num2 - (index + 1)); switch (code) { case "UNSEEN": this.ProcessOKUnseen(unseen); return; case "UIDNEXT": this.ProcessOKUidNext(unseen); return; case "UIDVALIDITY": this.ProcessOKUidValidity(unseen); return; case "PERMANENTFLAGS": this.ProcessOKPermanentFlags(unseen); break; } if (code == "PERMANENTFLAGS") { this.ProcessOKPermanentFlags(unseen); } else if (!this.IsIgnored(code)) { throw new UnexpectedResponseException("Unexpected response"); } }
private void ProcessFlags(IMAP4Response response) { Regex regex = new Regex(@"\((?<flags>[^\)]*)\)"); string str = regex.Match(response.Data).Groups["flags"].Value; this._flags = new MessageFlagCollection(); this._flagsRecieved = true; if (str != "") { string[] strArray = str.Split(new char[] { ' ' }); for (int i = 0; i < strArray.Length; i++) { if (strArray[i][0] == '\\') { this._flags.Add(new MessageFlag(strArray[i].Substring(1))); } } } }
protected void ProcessResponse(IMAP4Response response) { if (response.Name == "EXISTS") { this.ProcessExists(response); } else if (response.Name == "RECENT") { this.ProcessRecent(response); } else if (response.Name == "OK") { this.ProcessOK(response); } else if (response.Name == "FLAGS") { this.ProcessFlags(response); } }
protected override CompletionResponse Behaviour() { uint commandId = base._dispatcher.SendCommand(string.Format("APPEND \"{0}\" {1}{2}{3}", this.mailbox, "{" + message.Length + "}", Environment.NewLine, message)); IMAP4Response response = null; try { response = base._dispatcher.GetResponse(commandId); } catch { base._dispatcher.SendCommand(this.message); response = base._dispatcher.GetResponse(commandId); } if (!response.IsCompletionResponse()) { throw new UnexpectedResponseException("Unexpected response"); } return(new CompletionResponse(response.Response)); }
protected override CompletionResponse Behaviour() { uint commandId = base._dispatcher.SendCommand(string.Format("GETQUOTAROOT \"{0}\"", this._mailbox.FullName), this.filter); IMAP4Response response = base._dispatcher.GetResponse(commandId); if (!response.IsCompletionResponse()) { if (response.Name != "QUOTA") { throw new UnexpectedResponseException("Unexpected response"); } this.ParseResponse(response); response = base._dispatcher.GetResponse(commandId); if (!response.IsCompletionResponse()) { throw new UnexpectedResponseException("Unexpected response"); } } return(new CompletionResponse(response.Response)); }
protected override CompletionResponse Behaviour() { CompletionResponse response2; this.capabilities = new List <string>(); uint commandId = base._dispatcher.SendCommand("CAPABILITY", this.filter); IMAP4Response response = base._dispatcher.GetResponse(commandId); if ((response.Name == "CAPABILITY") && (response.Type == EIMAP4ResponseType.Untagged)) { if (response.Data.IndexOf(' ') != -1) { string[] collection = response.Data.Substring(response.Name.Length + 1).Split(new char[] { ' ' }); this.capabilities = new List <string>(collection); } response = base._dispatcher.GetResponse(commandId); if (!CompletionResponse.IsCompletionResponse(response.Response)) { throw new UnexpectedResponseException("Unexpected response"); } response2 = new CompletionResponse(response.Response); if (response2.CompletionResult == ECompletionResponseType.NO) { throw new UnexpectedResponseException("Unexpected response"); } return(response2); } if (!CompletionResponse.IsCompletionResponse(response.Response)) { throw new UnexpectedResponseException("Unexpected response"); } response2 = new CompletionResponse(response.Response); if (response2.CompletionResult != ECompletionResponseType.BAD) { throw new UnexpectedResponseException("Unexpected response"); } return(response2); }
public virtual IMAP4Response GetResponse(uint commandId) { IMAP4Response response; bool flag = false; do { if (this._queues[commandId].Count == 0) { lock (this) { if (!this._receiveInProgress) { this.GetServerData(); } } if (this._receiveInProgress) { Task.Run(async() => await Task.Delay(this._sleepTime)).Wait(); } } else { flag = true; } }while (!flag); lock (this) { response = new IMAP4Response(this._queues[commandId].Dequeue().Replace("\r\n", "")); } if (response.IsCompletionResponse()) { this.DeleteCommand(commandId); } return(response); }
protected override CompletionResponse Behaviour() { Exception exception = null; IPart partByAttachment = this._message.GetPartByAttachment(this._attachmentDescription); uint commandId = base._dispatcher.SendCommand(string.Format("UID FETCH {0} (BODY.PEEK[{1}] BODY.PEEK[{1}.MIME])", this._message.Uid, this._message.GetPartIndex(partByAttachment)), base.filter); IMAP4Response response = base._dispatcher.GetResponse(commandId); while (!response.IsCompletionResponse()) { if (response.Name != "FETCH") { throw new UnexpectedResponseException("Unexpected response"); } ulong size = base.GetSize(response); FileContentWriter writer = new FileContentWriter(this._attachmentDirectory); try { writer.Open(); string str = string.Empty; while (size > 0L) { ulong num3 = (size > 0x1000L) ? ((ulong)0x1000L) : size; byte[] bytes = base._dispatcher.GetRawData(num3); byte[] data = bytes; if (partByAttachment.Header.ContentTransferEncoding == EContentTransferEncoding.Base64) { string str2 = str + Encoding.UTF8.GetString(bytes, 0, bytes.Length).Replace("\r\n", ""); data = Convert.FromBase64String(str2.Substring(0, str2.Length - (str2.Length % 4))); str = str2.Substring(str2.Length - (str2.Length % 4)); } writer.Write(data); size -= num3; } } catch (Exception exception2) { exception = exception2; base._dispatcher.GetRawData(size); } finally { writer.Close(); } this._attachmentDescription.DiskFilename = writer.Filename; byte[] rawData = base._dispatcher.GetRawData(); string s = Encoding.UTF8.GetString(rawData, 0, rawData.Length) + "\r\n"; rawData = Encoding.UTF8.GetBytes(s); Match match = new Regex("{(?<size>[0-9]+)}|(?<size>NIL)").Match(s); if (match.Success && (match.Groups["size"].Value != "NIL")) { size = ulong.Parse(match.Groups["size"].Value); byte[] sourceArray = base._dispatcher.GetRawData(size); byte[] destinationArray = new byte[rawData.Length + sourceArray.Length]; Array.Copy(rawData, destinationArray, rawData.Length); Array.Copy(sourceArray, 0, destinationArray, rawData.Length, sourceArray.Length); this._message = new MessageDescriptionParser().Parse(this._message, destinationArray, this._message.Uid, this._attachmentDirectory); base._dispatcher.GetRawData(); } response = base._dispatcher.GetResponse(commandId); } if (exception != null) { throw exception; } return(new CompletionResponse(response.Response)); }
protected override CompletionResponse Behaviour() { uint commandId = base._dispatcher.SendCommand(string.Format("{0}FETCH {1} (FLAGS UID RFC822.SIZE INTERNALDATE BODY.PEEK[HEADER] BODY)", this._uidMode ? "UID " : "", this._sequence), base.filter); IMAP4Response response = base._dispatcher.GetResponse(commandId); if (!response.IsCompletionResponse()) { if (response.Name != "FETCH") { throw new UnexpectedResponseException("Unexpected response"); } while (!response.IsCompletionResponse()) { try { List <byte> list = new List <byte>(); if (!response.IsCompletionResponse()) { ulong size = base.GetSize(response); list.AddRange(Encoding.UTF8.GetBytes(response.Data + "\r\n")); list.AddRange(base._dispatcher.GetRawData(size)); list.AddRange(base._dispatcher.GetRawData()); int sourceIndex = -1; int num4 = -1; byte num5 = Encoding.UTF8.GetBytes("(")[0]; byte num6 = Encoding.UTF8.GetBytes(")")[0]; for (int i = 0; i < list.Count; i++) { if ((sourceIndex == -1) && (list[i] == num5)) { sourceIndex = i; } if (list[i] == num6) { num4 = i; } } sourceIndex++; byte[] destinationArray = new byte[num4 - sourceIndex]; Array.Copy(list.ToArray(), sourceIndex, destinationArray, 0, num4 - sourceIndex); ImapMessage item = new MessageDescriptionParser().Parse(destinationArray, _sequence[0].ToString(), this._attachmentDirectory); this._fetchedItems.Add(item); if (this.MessageReceived != null) { this.MessageReceived(this, new MessageReceivedEventArgs(item)); } } } catch (BadAttachmentDirectoryException) { throw; } catch (Exception exception) { if (this.BrokenMessage != null) { this.BrokenMessage(this, new BrokenMessageInfoArgs(exception.Message)); } } response = base._dispatcher.GetResponse(commandId); } } return(new CompletionResponse(response.Response)); }
protected override CompletionResponse Behaviour() { uint commandId = base._dispatcher.SendCommand(this.command, this.filter); IMAP4Response response = base._dispatcher.GetResponse(commandId); if ((response.Name == "STATUS") && (response.Type == EIMAP4ResponseType.Untagged)) { int index = response.Data.IndexOf('('); int num3 = response.Data.IndexOf(')'); if ((index != -1) && (num3 != -1)) { string[] strArray = response.Data.Substring(index + 1, (num3 - index) - 1).Split(new char[] { ' ' }); if ((strArray.Length % 2) != 0) { throw new UnexpectedResponseException("Unexpected response"); } for (int i = 0; i < strArray.Length; i += 2) { string str2 = strArray[i]; if (str2 == "MESSAGES") { this.messages = int.Parse(strArray[i + 1]); } else if (str2 == "RECENT") { this.recent = int.Parse(strArray[i + 1]); } else if (str2 == "UIDNEXT") { this.uidnext = long.Parse(strArray[i + 1]); } else if (str2 == "UIDVALIDITY") { this.uidvalidity = long.Parse(strArray[i + 1]); } else { if (str2 != "UNSEEN") { throw new UnexpectedResponseException("Unexpected response"); } this.unseen = int.Parse(strArray[i + 1]); } } } } else { if (!CompletionResponse.IsCompletionResponse(response.Response)) { throw new UnexpectedResponseException("Unexpected response"); } return(new CompletionResponse(response.Response)); } response = base._dispatcher.GetResponse(commandId); if (!CompletionResponse.IsCompletionResponse(response.Response)) { throw new UnexpectedResponseException("Unexpected response"); } return(new CompletionResponse(response.Response)); }
private void ProcessRecent(IMAP4Response response) { this.recent = int.Parse(response.Data.Substring(0, response.Data.IndexOf(' '))); this._recentRecieved = true; }
private void ProcessExists(IMAP4Response response) { this._exists = int.Parse(response.Data.Substring(0, response.Data.IndexOf(' '))); this._existsRecieved = true; }