コード例 #1
0
        public void ProcessRequest(HttpContext context)
        {
            string[] path   = context.Request.Path.Split('/');
            string   server = path[1];
            string   group  = path[2];
            int      days   = int.Parse(context.Request.QueryString["days"]);

            using (Rfc977NntpClientWithExtensions nntp = new Rfc977NntpClientWithExtensions())
            {
                nntp.Connect(server);
                nntp.SelectNewsgroup(group);

                using (XmlWriter rss = XmlWriter.Create(context.Response.Output))
                {
                    rss.WriteStartDocument();
                    rss.WriteStartElement("rss");
                    rss.WriteAttributeString("version", "2.0");
                    {
                        rss.WriteStartElement("channel");
                        rss.WriteElementString("title", "aa");

                        ArticleBodyTextCollection body    = new ArticleBodyTextCollection();
                        ArticleHeadersDictionary  headers = new ArticleHeadersDictionary();
                        nntp.RetrieveArticle(nntp.CurrentGroup.LastArticleId, headers, body);

                        while (true)
                        {
                            DateTime date = DateTime.Parse(headers["Date"][0]);

                            if (DateTime.Now - date > TimeSpan.FromDays(days))
                            {
                                break;
                            }

                            rss.WriteStartElement("item");
                            rss.WriteElementString("title", headers["Subject"][0]);
                            rss.WriteElementString("description", body[0]);
                            rss.WriteEndElement();

                            ArticleResponseIds ids = nntp.SetPreviousArticle();

                            if (ids == null)
                            {
                                break;
                            }

                            headers.Clear();
                            body.Clear();
                            nntp.RetrieveArticle(headers, body);
                        }

                        rss.WriteEndElement();
                    }
                    rss.WriteEndElement();
                    rss.WriteEndDocument();
                }
            }
        }
コード例 #2
0
ファイル: Usenet.cs プロジェクト: kaileu/binsync
        public ArticleHeadersDictionary CreateHeader(string messageId, string subject)
        {
            var headers = new ArticleHeadersDictionary();

            headers.AddHeader("From", postFromUser);
            headers.AddHeader("Subject", subject);
            headers.AddHeader("Newsgroups", this.newsgroup);
            //headers.AddHeader("Date", new NntpDateTime(DateTime.Now).ToString());
            headers.AddHeader("Message-ID", messageId);

            return(headers);
        }
コード例 #3
0
        public ArticleHeadersDictionary CreateHeader(string chunkId, string subject, string posterEmail)
        {
            string messageId    = IdToMessageId(chunkId);
            string postFromUser = posterEmail;
            var    headers      = new ArticleHeadersDictionary();

            headers.AddHeader("From", postFromUser);
            headers.AddHeader("Subject", subject);
            headers.AddHeader("Newsgroups", this.newsgroup);
            //headers.AddHeader("Date", new NntpDateTime(DateTime.Now).ToString());
            headers.AddHeader("User-Agent", Utilities.USERAGENT);
            headers.AddHeader("Message-ID", messageId);

            return(headers);
        }
コード例 #4
0
        public bool Upload(UsenetChunk chunk, string posterEmail)
        {
            if (CheckConnexion() == false)
            {
                return(false);
            }

            ArticleHeadersDictionary headers = CreateHeader(chunk.Id, chunk.Subject, posterEmail);

            Rfc977NntpClientWithExtensions nntpClient = client;

            var rawData = chunk.Data;

            try
            {
                try
                {
                    nntpClient.PostArticle(new ArticleHeadersDictionaryEnumerator(headers), Upload(rawData).ToList());
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                    if (nntpClient.LastNntpResponse.StartsWith("441 "))
                    {
                        return(false);
                    }
                    //throw ex;
                }

                //if (!nntpClient.LastNntpResponse.StartsWith("240 ") && nntpClient.LastNntpResponse.Split('<')[1].Split('>')[0] == null)
                //{
                //    throw new Exception(nntpClient.LastNntpResponse);
                //}
                if (nntpClient.LastNntpResponse.StartsWith("240 "))
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                //nothing todo
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            return(false);
        }
コード例 #5
0
ファイル: Usenet.cs プロジェクト: kaileu/binsync
        public bool Upload(Chunk chunk)
        {
            ArticleHeadersDictionary headers = CreateHeader(IdToMessageId(chunk.ID), chunk.Subject);

            Rfc977NntpClientWithExtensions nntpClient = client;

            var rawData = chunk.Data;

            try
            {
                using (MemoryStream ms = new MemoryStream(rawData))
                {
                    nntpClient.PostArticle(new ArticleHeadersDictionaryEnumerator(headers), Upload(rawData.Length, ms));
                }
            }
            catch (Exception ex)
            {
                if (nntpClient.LastNntpResponse.StartsWith("441 Posting Failed"))
                {
                    return(false);
                }
                throw ex;
            }

            try
            {
                if (!nntpClient.LastNntpResponse.StartsWith("240 Article Posted") && nntpClient.LastNntpResponse.Split('<')[1].Split('>')[0] == null)
                {
                    throw new Exception(nntpClient.LastNntpResponse);
                }
            }
            catch
            {
                throw new Exception(nntpClient.LastNntpResponse);
            }

            return(true);
        }
コード例 #6
0
        //Fonction qui verifie si un article est present sur le reseau
        public bool CheckArticle(string chunkId)
        {
            if (CheckConnexion() == false)
            {
                return(false);
            }
            string messageId = IdToMessageId(chunkId);
            Rfc977NntpClientWithExtensions nntpClient = client;

            try
            {
                ArticleHeadersDictionary dico = nntpClient.RetrieveArticleHeader(messageId);
                if (dico.ContainsKey("Message-ID"))
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                string k = ex.Message;
            }

            return(false);
        }
コード例 #7
0
ファイル: Form1.cs プロジェクト: ArminOonk/SharpUsenetBackup
        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);
            }
        }
コード例 #8
0
 /// <summary>
 /// Retrieves the article header common functionality. The command argument
 /// should be in the form "HEAD [article-id|message-id]."
 /// </summary>
 /// <param name="command">The command.</param>
 /// <returns></returns>
 protected ArticleHeadersDictionary RetrieveArticleHeaderCore(string command)
 {
     ArticleHeadersDictionary headers = new ArticleHeadersDictionary();
     foreach (string s in DoArticleCommand(command, Rfc977ResponseCodes.ArticleRetrievedHeadFollows))
     {
         if (s.Length == 0)
         {
             break;
         }
         else
         {
             headers.AddHeader(s);
         }
     }
     return headers;
 }
コード例 #9
0
        /// <summary>
        /// Retrieves the article headers for the specified range.
        /// </summary>
        /// <param name="firstArticleId">The first article id.</param>
        /// <param name="lastArticleId">The last article id.</param>
        /// <returns></returns>
        public override IEnumerable<ArticleHeadersDictionary> RetrieveArticleHeaders(int firstArticleId, int lastArticleId)
        {
            if (!CurrentGroupSelected)
            {
                throw new NntpGroupNotSelectedException();
            }

            if (m_supportsXover)
            {
                string[] headerNames = new string[] { "Article-ID", "Subject", "From", "Date", "Message-ID", "Xref", "Bytes", "Lines"};
                foreach (string s in DoArticleCommand("XOVER " + firstArticleId + "-" + lastArticleId, 224))
                {
                    ArticleHeadersDictionary headers = new ArticleHeadersDictionary();
                    string[] fields = s.Split('\t');

                    for (int i = 0; i < headerNames.Length; i++)
                    {
                        headers.AddHeader(headerNames[i], fields[i]);
                    }
                    yield return headers;
                }
            }
            else
            {
                // I can't use the base class to do this.
                for (; firstArticleId < lastArticleId; firstArticleId++)
                {
                    yield return RetrieveArticleHeader(firstArticleId);
                }
            }
        }
コード例 #10
0
        public void PostArticle()
        {
            using (var client = new Rfc977NntpClient())
            {
                client.Connect(Server);
                client.SelectNewsgroup(TestNewsGroup);

                var headers = new ArticleHeadersDictionary();
                headers.AddHeader("From", "[email protected] (Anonymous)");
                headers.AddHeader("Subject", "Test - Please Ignore.");
                headers.AddHeader("Newsgroups", TestNewsGroup);
                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 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 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);
            }
        }