- using System;
- using System.IO;
- namespace LumiSoft.MailServer
- {
- /// <summary>
- /// This class parses relay info from message.
- /// </summary>
- public class RelayInfo
- {
- private string m_To = "";
- private string m_From = "";
- private bool m_IsWSent = false;
- private DateTime m_MsgDate;
- private int m_Undelivered = 1;
- private int m_UndeliveredWarning = 1;
- private int m_MsgStartPos = 0;
- /// <summary>
- /// Default constructor.
- /// </summary>
- /// <param name="relayMsgStrm">Message stream from to read relay info.</param>
- /// <param name="undelivered">Specifies hours when message is readed to be undelivered.</param>
- /// <param name="undeliveredWarning">Specifies minutes when delayed delivery warning is sent.</param>
- public RelayInfo(Stream relayMsgStrm,int undelivered,int undeliveredWarning)
- {
- ReadRelayInfo(relayMsgStrm);
- m_Undelivered = undelivered;
- m_UndeliveredWarning = undeliveredWarning;
- }
- #region function ReadRelayInfo
- /// <summary>
- /// Parses relay info from stream.
- /// </summary>
- /// <param name="relayMsgStrm"></param>
- private void ReadRelayInfo(Stream relayMsgStrm)
- {
- TextReader reader = new StreamReader(relayMsgStrm);
- string relayHead = reader.ReadLine();
- if(relayHead != null && relayHead.StartsWith("RelayInfo:")){
- relayHead = relayHead.Replace("RelayInfo:","");
- relayHead = relayHead.Trim();
- string[] param = relayHead.Split(new char[]{'t'});
- if(param.Length == 4){
- m_IsWSent = Convert.ToBoolean(Convert.ToInt32(param[0]));
- m_To = param[1];
- m_From = param[2];
- m_MsgDate = DateTime.Parse(param[3]);
- }
- m_MsgStartPos = relayHead.Length + 1; // rn(2) + (-1 for 0 based pos)
- relayMsgStrm.Position = m_MsgStartPos;
- }
- }
- #endregion
- #region Properties Implementation
- /// <summary>
- /// Gets recipient.
- /// </summary>
- public string To
- {
- get{ return m_To; }
- }
- /// <summary>
- /// Gets sender.
- /// </summary>
- public string From
- {
- get{ return m_From; }
- }
- /// <summary>
- /// Gets message store date.
- /// </summary>
- public DateTime MessageDate
- {
- get{ return m_MsgDate; }
- }
- /// <summary>
- /// Gets if undelivered warning is sent.
- /// </summary>
- public bool IsUndeliveredWarningSent
- {
- get{ return m_IsWSent; }
- }
- /// <summary>
- /// Gets if undelivered date is exceeded.
- /// </summary>
- public bool IsUndeliveredDateExceeded
- {
- get{
- if(DateTime.Now.CompareTo(m_MsgDate.AddHours(m_Undelivered)) >= 0){
- return true;
- }
- else{
- return false;
- }
- }
- }
- /// <summary>
- /// Gets if must send undelivered warning.
- /// </summary>
- public bool MustSendWarning
- {
- get{
- if(!m_IsWSent && DateTime.Now.CompareTo(m_MsgDate.AddMinutes(m_UndeliveredWarning)) >= 0){
- return true;
- }
- else{
- return false;
- }
- }
- }
- /// <summary>
- /// Gets undelivered bit position in stream.
- /// </summary>
- public int WarningBitPos
- {
- get{ return 10; }
- }
- /// <summary>
- /// Gets message start position in stream.
- /// </summary>
- public int MessageStartPos
- {
- get{ return m_MsgStartPos; }
- }
- /// <summary>
- /// Gets how many hours server will try to send message.
- /// </summary>
- public int DeviveringForHours
- {
- get{ return m_Undelivered-(m_UndeliveredWarning/60); }
- }
- #endregion
- }
- }