using System;
using System.IO;
namespace Ant.Service.Utilities
{
///
/// This class represents a Pop3 response message and
/// is intended to be used as a base class for all other
/// Pop3Response types.
///
internal class Pop3Response
{
private byte[] _responseContents;
///
/// Gets the response contents.
///
/// The response contents.
internal byte[] ResponseContents
{
get
{
return _responseContents;
}
}
private bool _statusIndicator;
///
/// Gets a value indicating whether message was true +OK or false -ERR
///
/// true if [status indicator]; otherwise, false.
public bool StatusIndicator
{
get { return _statusIndicator; }
}
private string _hostMessage;
///
/// Gets the host message.
///
/// The host message.
public string HostMessage
{
get { return _hostMessage; }
}
///
/// Initializes a new instance of the class.
///
/// The response contents.
/// The host message.
/// if set to true [status indicator].
public Pop3Response(byte[] responseContents, string hostMessage, bool statusIndicator)
{
if (responseContents == null)
{
throw new ArgumentNullException("responseBuffer");
}
if (string.IsNullOrEmpty(hostMessage))
{
throw new ArgumentNullException("hostMessage");
}
_responseContents = responseContents;
_hostMessage = hostMessage;
_statusIndicator = statusIndicator;
}
///
/// Creates the response.
///
/// The response contents.
///
public static Pop3Response CreateResponse(byte[] responseContents)
{
string hostMessage;
MemoryStream stream = new MemoryStream(responseContents);
using (StreamReader reader = new StreamReader(stream))
{
hostMessage = reader.ReadLine();
if (hostMessage == null)
{
return null;
}
bool success = hostMessage.StartsWith(Pop3Responses.Ok);
return new Pop3Response(responseContents, hostMessage, success);
}
}
}
}