コード例 #1
0
ファイル: NntpConnection.cs プロジェクト: vzrus/VZF
    public Article GetArticle(string messageId)
    {
      if (this.connectedServer == null)
      {
        throw new NntpException("No connecting newsserver.");
      }

      if (this.connectedGroup == null)
      {
        throw new NntpException("No connecting newsgroup.");
      }

      var article = new Article();
      Response res = this.MakeRequest("Article " + messageId);
      if (res.Code != 220)
      {
        throw new NntpException(res.Code);
      }

      int i = res.Message.IndexOf(' ');
      article.ArticleId = int.Parse(res.Message.Substring(0, i));
      int end = res.Message.Substring(i, res.Message.Length - i - 1).Trim().IndexOf(' ');
      if (end == -1)
      {
        end = res.Message.Length - (i + 1);
      }

      article.MessageId = res.Message.Substring(i + 1, end);
      MIMEPart part = null;

      article.Header = this.GetHeader(messageId, out part);
      article.MimePart = part;

      article.Body = article.MimePart == null ? this.GetNormalBody(article.MessageId) : this.GetMIMEBody(article.MessageId, article.MimePart);

      return article;
    }
コード例 #2
0
ファイル: NntpConnection.cs プロジェクト: vzrus/VZF
    public void PostArticle(Article article)
    {
      if (this.connectedServer == null)
      {
        throw new NntpException("No connecting newsserver.");
      }

      if (this.connectedGroup == null)
      {
        throw new NntpException("No connecting newsgroup.");
      }

      Response res = this.MakeRequest("POST");
      if (res.Code != 340)
      {
        throw new NntpException(res.Code, res.Request);
      }

      var sb = new StringBuilder();

      sb.Append("From: ");
      sb.Append(article.Header.From);
      sb.Append("\r\nNewsgroups: ");
      sb.Append(this.connectedGroup.Group);

      if (article.Header.ReferenceIds != null && article.Header.ReferenceIds.Length != 0)
      {
        sb.Append("\r\nReference: ");
        sb.Append(string.Join(" ", article.Header.ReferenceIds));
      }

      sb.Append("\r\nSubject: ");
      sb.Append(article.Header.Subject);
      sb.Append("\r\n\r\n");      
      article.Body.Text = article.Body.Text.Replace("\n.", "\n..");
      sb.Append(article.Body.Text);
      sb.Append("\r\n.\r\n");
      res = this.MakeRequest(sb.ToString());
      if (res.Code != 240)
      {
        throw new NntpException(res.Code, res.Request);
      }
    }
コード例 #3
0
ファイル: NntpConnection.cs プロジェクト: vzrus/VZF
    public IList<Article> GetArticleList(int low, int high)
    {
      if (this.connectedServer == null)
      {
        throw new NntpException("No connecting newsserver.");
      }

      if (this.connectedGroup == null)
      {
        throw new NntpException("No connecting newsgroup.");
      }

      Response res = this.MakeRequest("XOVER " + low + "-" + high);
      if (res.Code != 224)
      {
        throw new NntpException(res.Code, res.Request);
      }

      var list = new List<Article>();
      Article article = null;
      string[] values = null;
      string response = null;
      while ((response = this.sr.ReadLine()) != null && response != ".")
      {
        try
        {
          article = new Article { Header = new ArticleHeader() };
          values = response.Split('\t');

          // article id...
          article.ArticleId = int.Parse(values[0]);

          // subject
          article.Header.Subject = NntpUtil.Base64HeaderDecode(values[1]);
          
          // from
          article.Header.From = NntpUtil.Base64HeaderDecode(values[2]);
          
          // date
          int i = values[3].IndexOf(',');
          int offTz;
          article.Header.Date = NntpUtil.DecodeUTC(values[3].Substring(i + 1, values[3].Length - 7 - i), out offTz);
          article.Header.TimeZoneOffset = offTz;
          
          // messge id
          article.MessageId = values[4];

          // reference ids
          article.Header.ReferenceIds = values[5].Trim().Length == 0 ? new string[0] : values[5].Split(' ');

          if (values.Length < 8 || values[7] == null || values[7].Trim() == string.Empty)
          {
            article.Header.LineCount = 0;
          }
          else
          {
            article.Header.LineCount = int.Parse(values[7]);
          }

          // no body...
          article.Body = null;
        }
        catch (Exception e)
        {
          throw new Exception(response, e);
        }

        list.Add(article);
      }

      return list;
    }