protected override void Parse(NntpResponse response) { base.Parse(response); Headers = new Head(response); Body = new Body(response); }
protected override void Parse(NntpResponse response) { ThrowIfUnexpectedResponseCode(response, NntpResponseCode.NflsGroupSelected); string count = null; string first = null; string last = null; string name = null; try { string statusLine = response.StatusLine; var parts = statusLine.Split(' '); count = parts[1]; first = parts[2]; last = parts[3]; name = parts[4]; } catch (Exception) { //Likely index out of range.. ignore } finally { Name = name; if(count != null) Count = Convert.ToInt64(count); if(first != null) First = Convert.ToInt64(first); if(last != null) Last = Convert.ToInt64(last); } }
protected override void Parse(NntpResponse response) { base.Parse(response); switch (response.ResponseCode) { case NntpResponseCode.ArticleRetrievedHeadAndBodyFollows: HandleHeadersAndBody(response); break; case NntpResponseCode.ArticleRetrievedHeadFollows: HandleHeaders(response); break; } }
/// <summary> /// The <a href="https://tools.ietf.org/html/rfc4643#section-2.3">AUTHINFO USER and AUTHINFO PASS</a> /// (<a href="https://tools.ietf.org/html/rfc2980#section-3.1.1">ad 1</a>) /// commands are used to present clear text credentials to the server. /// </summary> /// <param name="username">The username to use.</param> /// <param name="password">The password to use.</param> /// <returns>true if the user was authenticated successfully; otherwise false.</returns> public bool Authenticate(string username, string password = null) { Guard.ThrowIfNullOrWhiteSpace(username, nameof(username)); NntpResponse userResponse = connection.Command($"AUTHINFO USER {username}", new ResponseParser(281)); if (userResponse.Success) { return(true); } if (userResponse.Code != 381 || string.IsNullOrWhiteSpace(password)) { return(false); } NntpResponse passResponse = connection.Command($"AUTHINFO PASS {password}", new ResponseParser(281)); return(passResponse.Success); }
private void HandleBody(NntpResponse response) { using (var streamReader = new StreamReader(response.Payload, new UTF8Encoding(false))) { _tempFilePath = Path.GetTempFileName(); using (var fileStream = new FileStream(_tempFilePath, FileMode.OpenOrCreate, FileAccess.Write)) { var line = streamReader.ReadLine(); while (line != null && !line.Equals(BlockTerminator)) { var lineBytes = Encoding.UTF8.GetBytes(line); fileStream.Write(lineBytes, 0, lineBytes.Length); line = streamReader.ReadLine(); } } } }
protected override void Parse(NntpResponse response) { ThrowIfUnexpectedResponseCode(response, NntpResponseCode.ArticleRetrievedHeadFollows); var statusLine = response.StatusLine; var statusParts = statusLine.Split(new[] {' '}, 3); try { Name = statusParts[1]; } catch (Exception) { Logger.WarnFormat("Could not parse status line '{0}'", statusLine); } _tempFilePath = GetOwnedPayload(response); }
private void HandleHeaders(NntpResponse response) { using (var streamReader = new StreamReader(response.Payload, new UTF8Encoding(false))) { var headers = new Dictionary<string, string>(); var line = streamReader.ReadLine(); var previousKey = string.Empty; while (line != null && !line.Equals(BlockTerminator)) { if (line.StartsWith("\t") || line.StartsWith(" "))//line continuation { string val = headers[previousKey]; val = val + line.TrimStart('\t'); headers[previousKey] = val; } else { var parts = line.Split(new[] {':'}, 2); var key = parts[0]; previousKey = key; var value = parts[1].TrimStart(' '); try { headers.Add(key, value); } catch (ArgumentException ex) { //if key was already there.. concat the values var val1 = headers[key]; var newVal = string.Format("{0} {1}", val1, value); headers[key] = newVal; } } line = streamReader.ReadLine(); } _headers = new ReadOnlyDictionary<string, string>(headers); } }
protected override void Parse(NntpResponse response) { try { ThrowIfUnexpectedResponseCode(response, NntpResponseCode.ArticleRetrievedHeadFollows, NntpResponseCode.ArticleRetrievedHeadAndBodyFollows, NntpResponseCode.ArticleRetrievedBodyFollows); string articleId = null; string messageId = null; try { string statusLine = response.StatusLine; var parts = statusLine.Split(new[] { ' ' }, 4); articleId = parts[1]; messageId = parts[2]; } catch (Exception) { //Likely index out of range.. ignore } finally { if (!string.IsNullOrWhiteSpace(articleId)) ArticleId = Convert.ToInt64(articleId); if (!string.IsNullOrWhiteSpace(messageId)) MessageId = messageId; } } catch (Exception) { IsMissing = true; } }
public AuthenticateResponse(NntpResponse response) : base(response.Code, response.Message) { }
public HeaderCollection(NntpResponse response) { Parse(response); }
protected void Answer(NntpResponse code) { Answer(new Response(code)); }
public Group(NntpResponse response) { Parse(response); }
public Article(NntpResponse response) { Parse(response); }
public Response(string description, NntpResponse code, object body, params object[] parameters) : this(description, (int)code, body, parameters) { }
public ConnectResponse(NntpResponse response, bool canPost) : base(response.Code, response.Message) { this.CanPost = canPost; }
public Response(NntpResponse code, object body, params object[] parameters) : this(null, code, body, parameters) { }
private void HandleHeadersAndBody(NntpResponse response) { using (var streamReader = new StreamReader(response.Payload, new UTF8Encoding(false))) { var headers = new Dictionary<string, string>(); var line = streamReader.ReadLine(); while (line != null && !line.Equals(HeaderBodyDelimiter)) { var parts = line.Split(new[] {':'}, 2); var key = parts[0]; var value = parts[1].TrimStart(' '); headers.Add(key, value); line = streamReader.ReadLine(); } _headers = new ReadOnlyDictionary<string, string>(headers); } }
public Body(NntpResponse response) { Parse(response); }
public Response(NntpResponse code) : this(code, null) { }
public Head(NntpResponse response) { Parse(response); }
public static void Answer(NntpResponse code, Socket socket) { Answer((int)code, socket); }