public void GroupSelect()
 {
     using (var client = new Rfc977NntpClientWithExtensions())
     {
         client.ConnectTest();
         client.SendModeReader();
         client.SelectNewsgroup("alt.test");
     }
 }
 public void CheckIfHelpIsImplemented()
 {
     using (var client = new Rfc977NntpClientWithExtensions())
     {
         client.ConnectTest();
         foreach (var s in client.RetrieveHelp())
         {
             Console.WriteLine(s);
         }
     }
 }
 public void GroupSelectAndDownloadHeaders()
 {
     using (var client = new Rfc977NntpClientWithExtensions())
     {
         client.ConnectTest();
         client.SendModeReader();
         client.SelectNewsgroup("alt.test");
         foreach (var h in client.RetrieveArticleHeaders())
         {
             Console.WriteLine(h["Subject"][0]);
         }
     }
 }
예제 #4
0
        private void postFile(string fileName, string subject, params string[] groups)
        {
            int fileSize = 0;
            if(File.Exists(fileName))
            {
                if (groups.Length == 0)
                {
                    MessageBox.Show("No newsgroups selected", "Error posting file", MessageBoxButtons.OK);
                    return ;
                }

                Stream myStream = null;
                string result = "";

                try
                {
                    if ((myStream = File.OpenRead(fileName)) != null)
                    {
                        using (myStream)
                        {
                            // Insert code to read the stream here.
                            fileSize = (int)myStream.Length;
                            byte[] buffer = new byte[fileSize];
                            int count;                            // actual number of bytes read
                            int sum = 0;                          // total number of bytes read

                            // read until Read method returns 0 (end of the stream has been reached)
                            while ((count = myStream.Read(buffer, sum, fileSize - sum)) > 0)
                                sum += count;  // sum is a buffer offset for next reading

                            myStream.Close();

                            Encoding enc = Encoding.GetEncoding("Windows-1252");
                            result = enc.GetString(buffer);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Reading File", MessageBoxButtons.OK);
                }

                List<string> resultList = new List<string>(Regex.Split(result, "\r\n"));

                using (Rfc977NntpClientWithExtensions client = new Rfc977NntpClientWithExtensions())
                {
                    client.Connect(conf.UsenetServer);
                    client.AuthenticateUser(conf.UsenetUser, conf.UsenetPassword);

                    string newsgroup = groups[0];
                    for (int i = 1; i < groups.Length; i++)
                        newsgroup += "," + groups[i];

                    SetOutText("NewsGroups: " + newsgroup);

                    client.SelectNewsgroup(groups[0]);

                    ArticleHeadersDictionary headers = new ArticleHeadersDictionary();
                    headers.AddHeader("From", conf.UsenetPoster);
                    headers.AddHeader("Subject", subject);
                    headers.AddHeader("Newsgroups", newsgroup);
                    headers.AddHeader("Date", new NntpDateTime(DateTime.Now).ToString());

                    SetOutText("ResultList length: " + resultList.Count);
                    client.PostArticle(new ArticleHeadersDictionaryEnumerator(headers), resultList);

                    SetOutText("Done Sending file: " + client.LastNntpResponse);

                    string[] response = client.LastNntpResponse.Split(' ');
                    if (response[0] != "240")
                    {
                        MessageBox.Show("News server returned error: " + response[0], "Error posting file", MessageBoxButtons.OK);
                    }
                    else
                    {
                        char[] strip = { '<', '>' };
                        fileList.Last().Append(response[1].Trim(strip), fileSize);
                    }
                }
            }else{
                MessageBox.Show("Could not find file: " + fileName, "Error posting file", MessageBoxButtons.OK);
            }
        }
        public void GetSingleArticleBody()
        {
            using (var client = new Rfc977NntpClientWithExtensions())
            {
                client.ProtocolLogger = Console.Error;
                client.Connect(Server);
                client.SelectNewsgroup(TestNewsGroup);

                var d = client.RetrieveArticleHeader();
                foreach (var b in client.RetrieveArticleBody())
                {
                }
            }
        }
        public void GroupSelectAndDownloadMultipleArticles()
        {
            using (var client = new Rfc977NntpClientWithExtensions())
            {
                client.ConnectTest();
                client.SendModeReader();
                client.SelectNewsgroup("alt.test");

                for (var i = 0; i < 2; i++)
                {
                    IArticleHeadersProcessor header = new ArticleHeadersDictionary();
                    IArticleBodyProcessor body = new ArticleBodyTextCollection();
                    client.RetrieveArticle(client.CurrentGroup.FirstArticleId, header, body);
                }
            }
        }
 public void SimpleConnectionTestWithModeReader()
 {
     using (var client = new Rfc977NntpClientWithExtensions())
     {
         client.ConnectTest();
         client.SendModeReader();
     }
 }
 public void SimpleConnectionTest()
 {
     using (var client = new Rfc977NntpClientWithExtensions())
     {
         client.Connect(Server);
         client.Close();
     }
 }
 public void SimpleConnectionTestWithAuthentication()
 {
     using (var client = new Rfc977NntpClientWithExtensions())
     {
         client.Connect(Server);
         client.AuthenticateUser(UserId, Password);
         client.SendModeReader();
     }
 }
 public void ReadSomeSpecificHeaders()
 {
     using (var client = new Rfc977NntpClientWithExtensions())
     {
         client.ConnectTest();
         client.SendModeReader();
         var newsGroupName = "microsoft.public.dotnet.framework.aspnet";
         client.SelectNewsgroup(newsGroupName);
         Console.WriteLine(client.CurrentGroup);
         foreach (var s in client.RetrieveSpecificArticleHeaders("References", 233887, 373036))
         {
             //Console.Write("*");
         }
         Console.Out.Flush();
     }
 }
 public void ReadSomeSpecificHeaders2()
 {
     using (var client = new Rfc977NntpClientWithExtensions())
     {
         client.ConnectTest();
         client.SendModeReader();
         var newsGroupName = "alt.test";
         client.SelectNewsgroup(newsGroupName);
         foreach (var s in client.RetrieveSpecificArticleHeaders("References", client.CurrentGroup.FirstArticleId, client.CurrentGroup.LastArticleId))
         {
             Console.WriteLine(s);
         }
         Console.Out.Flush();
     }
 }
        public void PostArticleWithAuthentication()
        {
            using (var client = new Rfc977NntpClientWithExtensions())
            {
                client.ConnectTest();

                var newsgroup = "alt.test";
                client.SelectNewsgroup(newsgroup);

                var headers = new ArticleHeadersDictionary();
                headers.AddHeader("From", "[email protected] (Anonymous)");
                headers.AddHeader("Subject", "Test - " + Guid.NewGuid().ToString());
                headers.AddHeader("Newsgroups", newsgroup);
                headers.AddHeader("Date", new NntpDateTime(DateTime.Now).ToString());

                var body = new List<string>();
                body.Add("One line test message body.");

                client.PostArticle(new ArticleHeadersDictionaryEnumerator(headers), body);
            }
        }
 public void ListGroups()
 {
     using (var client = new Rfc977NntpClientWithExtensions())
     {
         client.ConnectTest();
         client.SendModeReader();
         foreach (var h in client.RetrieveNewsgroups("alt.*"))
         {
             Console.WriteLine(h);
         }
     }
 }
 public void GroupSelectAndDownloadSingleHeader()
 {
     using (var client = new Rfc977NntpClientWithExtensions())
     {
         client.ConnectTest();
         client.SendModeReader();
         client.SelectNewsgroup("alt.test");
         var header = client.RetrieveArticleHeader();
     }
 }
 public void GroupSelectAndDownloadMultipleHeadersUsingArticleId()
 {
     using (var client = new Rfc977NntpClientWithExtensions())
     {
         client.ConnectTest();
         client.SendModeReader();
         client.SelectNewsgroup("alt.test");
         for (var i = client.CurrentGroup.FirstArticleId; i < client.CurrentGroup.LastArticleId; i++)
         {
             var header = client.RetrieveArticleHeader(i);
             if (i > 10)
             {
                 break;
             }
         }
     }
 }
 public void GroupSelectAndDownloadMultipleHeaders()
 {
     using (var client = new Rfc977NntpClientWithExtensions())
     {
         client.ConnectTest();
         client.SendModeReader();
         client.SelectNewsgroup("alt.test");
         Console.WriteLine(client.CurrentGroup.ToString());
         client.ProtocolLogger = Console.Error;
         for (var i = client.CurrentGroup.FirstArticleId; i < client.CurrentGroup.LastArticleId; i++)
         {
             var header = client.RetrieveArticleHeader();
             if (i > 10)
             {
                 break;
             }
         }
     }
 }