internal static void ParseReferences(IResource article, string refValue) { string[] refs = refValue.Trim().Split(' '); if (refs.Length > 0) { string reference = ParseTools.EscapeCaseSensitiveString(refs[refs.Length - 1]); article.SetProp(NntpPlugin._propReferenceId, reference); IResource parentArticle = Core.ResourceStore.FindUniqueResource( NntpPlugin._newsArticle, NntpPlugin._propArticleId, reference); if (parentArticle != null) { SetReply(article, parentArticle); UpdateLastThreadArticleDate(article); } } }
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); }
/** * 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(); } }
/** * this function is called if article is downloaded from a group * article should be a newly created transient resource */ public static void CreateArticleByProtocolHandler(string[] lines, IResource article) { if (!article.IsTransient) { throw new ArgumentException("Article should be a newly created transient resource", "article"); } string articleId = article.GetPropText(NntpPlugin._propArticleId); if (Core.ResourceStore.FindUniqueResource( NntpPlugin._newsArticle, NntpPlugin._propArticleId, articleId) != null) { return; } PrepareLines(lines); try { IResource server = article.GetLinkProp(NntpPlugin._propTo); string charset = new ServerResource(server).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; 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)) { Subscribe2Groups(article, 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.SetProp(NntpPlugin._propIsUnread, true); 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); } finally { DisposeStringBuilders(); } }