Exemple #1
0
        public void Do(Session session)
        {
            // for readability
            var socket = session.Socket;

            socket.SendString(SmtpCommandUtils.SV_DATA_OK);

            socket.CommandSeperator = "\r\n.\r\n";
            string rawMessage = socket.GetNextCommand();
            socket.CommandSeperator = "\r\n";

            MailMessage message = new MailMessage();
            message.Load(rawMessage);

            if (string.IsNullOrEmpty(message.Body) || string.IsNullOrEmpty(message.Subject))
            {
                socket.SendString(SmtpCommandUtils.SV_UNKNOWN);
            }
            else
            {

                // all done with getting the data
                session.TriggerMessage(session.Message);

                socket.SendString(SmtpCommandUtils.SV_OK);
            }
        }
Exemple #2
0
        public MailMessage GetMessage(string uid, bool headersOnly = false)
        {
            CheckConnectionStatus();
            var result = new StringBuilder();
            string line = SendCommandGetResponse(string.Format(headersOnly ? "TOP {0} 0" : "RETR {0}", uid));
            while (line != ".") {
                result.AppendLine(line);
                line = GetResponse();
            }

            var msg = new MailMessage();
            msg.Load(result.ToString(), headersOnly);
            msg.Uid = uid;
            return msg;
        }
Exemple #3
0
 public void TriggerMessage(MailMessage m)
 {
     MessageRecieved(m);
 }
Exemple #4
0
 public bool IsSenderAllowed(MailMessage m)
 {
     return RecipientFound(m);
 }
Exemple #5
0
        public MailMessage[] GetMessages(string start, string end, bool uid, bool headersonly, bool setseen)
        {
            CheckMailboxSelected();
              IdlePause();

              string UID, HEADERS, SETSEEN;
              UID = HEADERS = SETSEEN = String.Empty;
              if (uid)
            UID = "UID ";
              if (headersonly)
            HEADERS = "HEADER";
              if (!setseen)
            SETSEEN = ".PEEK";
              string tag = GetTag();
              string command = tag + UID + "FETCH " + start + ":" + end + " (UID RFC822.SIZE FLAGS BODY" + SETSEEN + "[" + HEADERS + "])";
              string response;
              var x = new List<MailMessage>();

              SendCommand(command);
              while (true) {
            response = GetResponse();
            if (response.Contains(tag + "OK"))
              break;

            var m = rxGetBodyLength.Match(response);
            if (!m.Success)
              continue;

            int length = m.Groups[1].Value.ToInt();
            var mail = new MailMessage();
            var body = new StringBuilder();
            var buffer = new char[8192];
            int read;
            while (length > 0) {
              read = _Reader.Read(buffer, 0, Math.Min(length, buffer.Length));
              body.Append(buffer, 0, read);
              length -= read;
            }

            mail.Load(body.ToString(), headersonly);

            var m2 = rxUID.Match(response);
            if (m2.Groups[1] != null)
              mail.Uid = m2.Groups[1].ToString();
            m2 = rxFlags.Match(response);
            if (m2.Groups[1] != null)
              mail.SetFlags(m2.Groups[1].ToString());
            m2 = rxSize.Match(response);
            if (m2.Groups[1] != null)
              mail.Size = Convert.ToInt32(m2.Groups[1].ToString());

            x.Add(mail);
              }

              IdleResume();
              return x.ToArray();
        }
Exemple #6
0
        public void AppendMail(string mailbox, MailMessage email)
        {
            IdlePause();

              string flags = String.Empty;
              string size = (email.Body.Length - 1).ToString();
              if (email.RawFlags.Length > 0) {
            flags = string.Concat("(", string.Join(" ", email.Flags), ")");
              }
              string command = GetTag() + "APPEND " + mailbox.QuoteString() + " " + flags + " {" + size + "}";
              string response = SendCommandGetResponse(command);
              if (response.StartsWith("+")) {
            response = SendCommandGetResponse(email.Body);
              }
              IdleResume();
        }
Exemple #7
0
 public bool OnRecipientReceived(MailMessage m)
 {
     return RecipientReceived(m);
 }
Exemple #8
0
 public void OnMessageReceived(MailMessage m)
 {
     MessageReceived(m);
 }