コード例 #1
0
 private void getArticleByIdUnitProcessLine(string line)
 {
     if (!_articleAvailable)
     {
         if (!line.StartsWith("220"))
         {
             string articleNumber = NewsArticleHelper.GetArticleNumber(_article, _group);
             if (articleNumber == null)
             {
                 ProcessErrorResponse(line);
             }
             else
             {
                 _getArticleUnit.Finished -= new AsciiProtocolUnitDelegate(getArticleUnit_Finished);
                 FireFinished(_getArticleUnit);
                 GetArticleByNumber(articleNumber);
             }
         }
         else
         {
             _lines            = new ArrayList();
             _articleAvailable = true;
         }
     }
     else
     {
         ProcessLine(line);
     }
 }
コード例 #2
0
        /**
         * all article's processing should be performed in the resource thread
         * this function is called if article is downloaded from a group
         */
        public static void CreateArticle(string[] lines, IResource groupRes, string articleId)
        {
            // if user has already unsubscribed from the group or the
            // groups is already deleted then skip the article
            IResource server = new NewsgroupResource(groupRes).Server;

            if (server == null)
            {
                return;
            }

            articleId = ParseTools.EscapeCaseSensitiveString(articleId);
            // is article deleted?
            if (NewsArticleHelper.IsArticleDeleted(articleId))
            {
                return;
            }

            PrepareLines(lines);

            try
            {
                ServerResource serverRes   = new ServerResource(server);
                string         charset     = serverRes.Charset;
                bool           bodyStarted = false;
                string         line;
                string         content_type = string.Empty;
                string         content_transfer_encoding = string.Empty;
                IContact       sender = null;
                DateTime       date   = DateTime.MinValue;
                bool           mySelf = false;
                bool           newArticle;

                IResource article = Core.ResourceStore.FindUniqueResource(
                    NntpPlugin._newsArticle, NntpPlugin._propArticleId, articleId);
                if (article != null)
                {
                    if (!article.HasProp(NntpPlugin._propHasNoBody))
                    {
                        return;
                    }
                    article.BeginUpdate();
                    newArticle = false;
                }
                else
                {
                    article    = Core.ResourceStore.BeginNewResource(NntpPlugin._newsArticle);
                    newArticle = true;
                }

                for (int i = 0; i < lines.Length; ++i)
                {
                    line = lines[i];
                    if (line == null)
                    {
                        continue;
                    }
                    if (bodyStarted)
                    {
                        _bodyBuilder.Append(line);
                    }
                    else
                    {
                        _headersBuilder.Append(line);
                        _headersBuilder.Append("\r\n");
                        if (Utils.StartsWith(line, "from: ", true))
                        {
                            string from = line.Substring(6);
                            article.SetProp(NntpPlugin._propRawFrom, from);
                            mySelf = ParseFrom(article, TranslateHeader(charset, from), out sender);
                            UpdateLastCorrespondDate(sender, date);
                        }
                        else if (Utils.StartsWith(line, "subject: ", true))
                        {
                            string subject = line.Substring(9);
                            article.SetProp(NntpPlugin._propRawSubject, subject);
                            article.SetProp(Core.Props.Subject, TranslateHeader(charset, subject));
                        }
                        else if (Utils.StartsWith(line, "message-id: ", true))
                        {
                            ParseMessageId(article, ParseTools.EscapeCaseSensitiveString(line.Substring(12)), articleId);
                        }
                        else if (Utils.StartsWith(line, "newsgroups: ", true))
                        {
                            if (line.IndexOf(',') > 12)
                            {
                                ParseNewsgroups(article, groupRes, serverRes, line.Substring(12));
                            }
                        }
                        else if (Utils.StartsWith(line, "date: ", true))
                        {
                            date = ParseDate(article, line.Substring(6));
                            UpdateLastCorrespondDate(sender, date);
                        }
                        else if (Utils.StartsWith(line, "references: ", true))
                        {
                            ParseReferences(article, line.Substring(12));
                        }
                        else if (Utils.StartsWith(line, "content-type: ", true))
                        {
                            content_type = line.Substring(14);
                        }
                        else if (Utils.StartsWith(line, "followup-to: ", true))
                        {
                            article.SetProp(NntpPlugin._propFollowupTo, line.Substring(13));
                        }
                        else if (Utils.StartsWith(line, "content-transfer-encoding: ", true))
                        {
                            content_transfer_encoding = line.Substring(27);
                        }
                        else if (line == "\r\n")
                        {
                            bodyStarted = true;
                        }
                    }
                }
                ProcessBody(_bodyBuilder.ToString(), content_type, content_transfer_encoding, article, charset);
                article.SetProp(NntpPlugin._propArticleHeaders, _headersBuilder.ToString());
                article.AddLink(NntpPlugin._propTo, groupRes);
                if (article.GetPropText(NntpPlugin._propArticleId).Length == 0)
                {
                    article.SetProp(NntpPlugin._propArticleId, articleId);
                }
                if (newArticle)
                {
                    article.SetProp(NntpPlugin._propIsUnread, true);
                    IResourceList categories = Core.CategoryManager.GetResourceCategories(groupRes);
                    foreach (IResource category in categories)
                    {
                        Core.CategoryManager.AddResourceCategory(article, category);
                    }

                    Core.FilterEngine.ExecRules(StandardEvents.ResourceReceived, article);
                    CleanLocalArticle(articleId, article);
                }
                article.EndUpdate();

                CheckArticleInIgnoredThreads(article);
                CheckArticleInSelfThread(article);

                if (mySelf && serverRes.MarkFromMeAsRead)
                {
                    article.BeginUpdate();
                    article.DeleteProp(NntpPlugin._propIsUnread);
                    article.EndUpdate();
                }
                Core.TextIndexManager.QueryIndexing(article.Id);
            }
            finally
            {
                DisposeStringBuilders();
            }
        }
コード例 #3
0
        private static void ProcessBody(string body, string content_type,
                                        string content_transfer_encoding, IResource article, string defaultCharset)
        {
            _mimeBodyParser.ProcessBody(body, content_type, content_transfer_encoding, defaultCharset);

            // store charset as prop
            string charset = _mimeBodyParser.Charset;

            article.SetProp(Core.FileResourceManager.PropCharset, charset);
            // correct from for a specific charset
            string   from = article.GetPropText(NntpPlugin._propRawFrom);
            IContact sender;

            ParseFrom(article, TranslateHeader(charset, from), out sender);
            // correct subject for a specific charset
            string subject = article.GetPropText(NntpPlugin._propRawSubject);

            if (subject.Length > 0)
            {
                article.SetProp(Core.Props.Subject, TranslateHeader(charset, subject));
            }

            // walk though article parts -- body & atatchments
            MessagePart[] parts = _mimeBodyParser.GetParts();
            foreach (MessagePart part in parts)
            {
                if (part.PartType == MessagePartTypes.Body)
                {
                    article.SetProp(Core.Props.LongBody, part.Body);
                    article.SetProp(Core.Props.Size, part.Body.Length);
                }
                else if (part.PartType == MessagePartTypes.HtmlBody)
                {
                    article.SetProp(NntpPlugin._propHtmlContent, part.Body);
                }
                else
                {
                    /**
                     * forbid adding attachments for the LocalArticles resources
                     */
                    if (article.Type != NntpPlugin._newsLocalArticle)
                    {
                        string extension    = IOTools.GetExtension(part.Name);
                        string resourceType = Core.FileResourceManager.GetResourceTypeByExtension(extension);
                        if (resourceType == null)
                        {
                            resourceType = NntpPlugin._unknownFileResourceType;
                        }
                        IResource attachment = Core.ResourceStore.BeginNewResource(resourceType);
                        try
                        {
                            attachment.SetProp(Core.Props.Name, part.Name);
                            attachment.SetProp(Core.Props.Size, (int)part.Content.Length);
                            attachment.SetProp(NntpPlugin._propContent, part.Content);
                            if (part.PartType == MessagePartTypes.Inline)
                            {
                                attachment.SetProp(NntpPlugin._propInlineAttachment, true);
                            }
                            else if (part.PartType == MessagePartTypes.Embedded)
                            {
                                attachment.SetProp(CommonProps.ContentId, part.ContentId);
                                attachment.AddLink(NntpPlugin._propEmbeddedContent, article);
                                continue;
                            }
                            attachment.AddLink(NntpPlugin._propAttachment, article);
                        }
                        finally
                        {
                            attachment.EndUpdate();
                            Core.TextIndexManager.QueryIndexing(attachment.Id);
                        }
                    }
                }
            }
            if (!article.HasProp(Core.Props.LongBody) && !article.HasProp(NntpPlugin._propHtmlContent))
            {
                article.SetProp(Core.Props.LongBody, " ");
                article.SetProp(Core.Props.Size, 0);
            }
            article.DeleteProp(NntpPlugin._propHasNoBody);
            NewsArticleHelper.RemoveArticleNumbers(article);
            _mimeBodyParser.Clear();
        }
コード例 #4
0
        public static void CreateArticleFromHeaders(string line, IResource groupRes)
        {
            string[] headers = line.Split('\t');
            if (headers.Length <= 5)
            {
                return;
            }
            string articleId = ParseTools.EscapeCaseSensitiveString(headers[4]);

            if (articleId.Length == 0 || NewsArticleHelper.IsArticleDeleted(articleId))
            {
                return;
            }
            // if user has already unsubscribed from the group or the
            // groups is already deleted then skip the article
            IResource server = new NewsgroupResource(groupRes).Server;

            if (server == null)
            {
                return;
            }

            // is article deleted?
            if (NewsArticleHelper.IsArticleDeleted(articleId))
            {
                return;
            }

            IResource article;
            IContact  sender;
            bool      mySelf;
            bool      newArticle;
            string    charset = new ServerResource(server).Charset;

            article = Core.ResourceStore.FindUniqueResource(
                NntpPlugin._newsArticle, NntpPlugin._propArticleId, articleId);
            if (article != null)
            {
                article.BeginUpdate();
                newArticle = false;
            }
            else
            {
                article    = Core.ResourceStore.BeginNewResource(NntpPlugin._newsArticle);
                newArticle = true;
            }
            article.SetProp(NntpPlugin._propHasNoBody, true);
            NewsArticleHelper.SetArticleNumber(article, groupRes, headers[0]);
            DateTime date = ParseDate(article, headers[3]);
            string   from = headers[2];

            article.SetProp(NntpPlugin._propRawFrom, from);
            mySelf = ParseFrom(article, TranslateHeader(charset, from), out sender);
            string subject = headers[1];

            article.SetProp(NntpPlugin._propRawSubject, subject);
            article.SetProp(Core.Props.Subject, TranslateHeader(charset, subject));
            UpdateLastCorrespondDate(sender, date);
            ParseMessageId(article, articleId, articleId);
            string references = headers[5];

            if (references.Length > 0)
            {
                ParseReferences(article, references);
            }
            article.AddLink(NntpPlugin._propTo, groupRes);
            if (newArticle)
            {
                article.SetProp(NntpPlugin._propIsUnread, true);
                IResourceList categories = Core.CategoryManager.GetResourceCategories(groupRes);
                foreach (IResource category in categories)
                {
                    Core.CategoryManager.AddResourceCategory(article, category);
                }
                Core.FilterEngine.ExecRules(StandardEvents.ResourceReceived, article);
                CleanLocalArticle(articleId, article);
            }
            article.EndUpdate();
            if (mySelf && new ServerResource(server).MarkFromMeAsRead)
            {
                article.BeginUpdate();
                article.DeleteProp(NntpPlugin._propIsUnread);
                article.EndUpdate();
            }
            Core.TextIndexManager.QueryIndexing(article.Id);
        }