示例#1
0
    /// <summary>
    /// The get normal body.
    /// </summary>
    /// <param name="messageId">
    /// The message id.
    /// </param>
    /// <returns>
    /// </returns>
    private ArticleBody GetNormalBody(string messageId)
    {
      var buff = new char[1];
      string response = null;
      var list = new ArrayList();
      var sb = new StringBuilder();
      MemoryStream ms = null;
      this.sr.Read(buff, 0, 1);
      int i = 0;
      Match m = null;

      while ((response = this.sr.ReadLine()) != null)
      {
        if (buff[0] == '.')
        {
          if (response == string.Empty)
          {
            break;
          }
          else
          {
            sb.Append(response);
          }
        }
        else
        {
          if ((buff[0] == 'B' || buff[0] == 'b') && (m = Regex.Match(response, @"^EGIN \d\d\d (.+)$", RegexOptions.IgnoreCase)).Success)
          {
            ms = new MemoryStream();
            while ((response = this.sr.ReadLine()) != null && (response.Length != 3 || response.ToUpper() != "END"))
            {
              NntpUtil.UUDecode(response, ms);
            }

            ms.Seek(0, SeekOrigin.Begin);
            byte[] bytes = new byte[ms.Length];
            ms.Read(bytes, 0, (int) ms.Length);
            Attachment attach = new Attachment(messageId + " - " + m.Groups[1].ToString(), m.Groups[1].ToString(), bytes);
            list.Add(attach);
            ms.Close();
            i++;
          }
          else
          {
            sb.Append(buff[0]);
            sb.Append(response);
          }
        }

        sb.Append('\n');
        this.sr.Read(buff, 0, 1);
      }

      var ab = new ArticleBody
        { IsHtml = false, Text = sb.ToString(), Attachments = (Attachment[])list.ToArray(typeof(Attachment)) };
      return ab;
    }
示例#2
0
    /// <summary>
    /// The convert mime content.
    /// </summary>
    /// <param name="messageId">
    /// The message id.
    /// </param>
    /// <param name="part">
    /// The part.
    /// </param>
    /// <param name="sb">
    /// The sb.
    /// </param>
    /// <param name="attachmentList">
    /// The attachment list.
    /// </param>
    private void ConvertMIMEContent(string messageId, MIMEPart part, StringBuilder sb, ArrayList attachmentList)
    {
      Match m = null;
      m = Regex.Match(part.ContentType, @"MULTIPART", RegexOptions.IgnoreCase);
      if (m.Success)
      {
        foreach (MIMEPart subPart in part.EmbeddedPartList)
        {
          this.ConvertMIMEContent(messageId, subPart, sb, attachmentList);
        }

        return;
      }

      m = Regex.Match(part.ContentType, @"TEXT", RegexOptions.IgnoreCase);
      if (m.Success)
      {
        sb.Append(part.Text);
        sb.Append("<hr>");
        return;
      }

      var attachment = new Attachment(messageId + " - " + part.Filename, part.Filename, part.BinaryData);
      attachmentList.Add(attachment);
    }
示例#3
0
        /// <summary>
        /// The get normal body.
        /// </summary>
        /// <param name="messageId">
        /// The message id.
        /// </param>
        /// <returns>
        /// </returns>
        private ArticleBody GetNormalBody(string messageId)
        {
            var          buff     = new char[1];
            string       response = null;
            var          list     = new ArrayList();
            var          sb       = new StringBuilder();
            MemoryStream ms       = null;

            this.sr.Read(buff, 0, 1);
            int   i = 0;
            Match m = null;

            while ((response = this.sr.ReadLine()) != null)
            {
                if (buff[0] == '.')
                {
                    if (response == string.Empty)
                    {
                        break;
                    }
                    else
                    {
                        sb.Append(response);
                    }
                }
                else
                {
                    if ((buff[0] == 'B' || buff[0] == 'b') && (m = Regex.Match(response, @"^EGIN \d\d\d (.+)$", RegexOptions.IgnoreCase)).Success)
                    {
                        ms = new MemoryStream();
                        while ((response = this.sr.ReadLine()) != null && (response.Length != 3 || response.ToUpper() != "END"))
                        {
                            NntpUtil.UUDecode(response, ms);
                        }

                        ms.Seek(0, SeekOrigin.Begin);
                        byte[] bytes = new byte[ms.Length];
                        ms.Read(bytes, 0, (int)ms.Length);
                        Attachment attach = new Attachment(messageId + " - " + m.Groups[1].ToString(), m.Groups[1].ToString(), bytes);
                        list.Add(attach);
                        ms.Close();
                        i++;
                    }
                    else
                    {
                        sb.Append(buff[0]);
                        sb.Append(response);
                    }
                }

                sb.Append('\n');
                this.sr.Read(buff, 0, 1);
            }

            var ab = new ArticleBody
            {
                IsHtml = false, Text = sb.ToString(), Attachments = (Attachment[])list.ToArray(typeof(Attachment))
            };

            return(ab);
        }