public static void DownloadHeadersFromGroup(IResource group) { Guard.NullArgument(group, "group"); if (!Utils.IsNetworkConnectedLight()) { return; } NewsgroupResource groupResource = new NewsgroupResource(group); IResource server = groupResource.Server; if (server != null) { NntpConnectionPool.GetConnection(server, "background").StartUnit( Int32.MaxValue - 3, new NntpDownloadHeadersUnit(groupResource, JobPriority.AboveNormal)); /** * also download bodies if necessary */ if (new ServerResource(server).DownloadBodiesOnDeliver) { NntpConnectionPool.GetConnection(server, "background").StartUnit( 0, new NntpDeliverEmptyArticlesFromGroupsUnit(group.ToResourceList(), null)); } } }
private void StartGroup(IResource group) { NewsgroupResource groupResource = new NewsgroupResource(group); NntpDownloadHeadersUnit unit = new NntpDownloadHeadersUnit(groupResource, JobPriority.Normal); unit.Finished += new AsciiProtocolUnitDelegate(group_Finished); StartUnit(unit, _connection); }
public bool AcceptLink(IResource displayedResource, int propId, IResource targetResource, ref string linkTooltip) { if (propId == NntpPlugin._propTo && targetResource.Type == NntpPlugin._newsGroup) { linkTooltip = targetResource.DisplayName; IResource server = new NewsgroupResource(targetResource).Server; if (server != null) { linkTooltip = linkTooltip + " at " + server.DisplayName; } } return(true); }
private void StartGroup(IResource group) { _group = new NewsgroupResource(group); if (!_group.IsSubscribed) { StartNextGroup(); } else { Core.UIManager.GetStatusWriter(typeof(NntpDeliverEmptyArticlesFromGroupsUnit), StatusPane.Network).ShowStatus("Downloading articles from " + _group.DisplayName + "..."); NntpSetGroupUnit setGroupUnit = new NntpSetGroupUnit(_group); setGroupUnit.Finished += new AsciiProtocolUnitDelegate(setGroupUnit_Finished); StartUnit(setGroupUnit, _connection); } }
public static void DownloadAllHeadersFromGroup(IResource group) { Guard.NullArgument(group, "group"); if (!Utils.IsNetworkConnectedLight()) { return; } NewsgroupResource groupResource = new NewsgroupResource(group); IResource server = groupResource.Server; if (server != null) { NntpConnection connection = NntpConnectionPool.GetConnection(server, "background"); connection.StartUnit(Int32.MaxValue - 5, new NntpDownloadAllHeadersUnit(groupResource, JobPriority.AboveNormal)); } }
private static void ResourceRenamedImpl(IResource res, string newName) { if (res.IsDeleted) { return; } if (res.Type == NntpPlugin._newsServer) { res.DisplayName = newName; } else if (res.Type == NntpPlugin._newsGroup) { NewsgroupResource group = new NewsgroupResource(res); group.UserDisplayName = newName; group.InvalidateDisplayName(); } else { res.SetProp(Core.Props.Name, newName); } }
public static DialogResult Unsubscribe(IResourceList groups, out bool deleteArticles) { if (groups.Count > 0) { if (NewsgroupResource.AllUnsubscribed(groups)) { deleteArticles = true; if (groups.Count == 1) { return(MessageBox.Show( "Do you wish to delete " + groups[0].DisplayName + " with all messages?", "Remove Newsgroup", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)); } else { return(MessageBox.Show( "Do you wish to delete selected newsgroups with all messages?", "Remove Newsgroups", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)); } } else { UnsubscribeForm theForm = new UnsubscribeForm(); theForm._warningLabel.Text = "Do you wish to unsubscribe from"; if (groups.Count == 1) { theForm._groupName.Text = groups[0].DisplayName + "?"; } else { theForm._groupName.Text = groups.Count.ToString() + " selected newsgroups?"; } DialogResult result = theForm.ShowDialog(Core.MainWindow); deleteArticles = !theForm._preserveArchiveBox.Checked; return(result); } } deleteArticles = false; return(DialogResult.Cancel); }
public static void PostArticle(IResource draftArticle, AsciiProtocolUnitDelegate finishedMethod, bool invokedByUser) { Guard.NullArgument(draftArticle, "draftArticle"); if (!Utils.IsNetworkConnectedLight()) { return; } lock ( _articlesBeenPosted ) { if (_articlesBeenPosted.Contains(draftArticle)) { return; } _articlesBeenPosted.Add(draftArticle); } IResourceList groups = draftArticle.GetLinksFrom(NntpPlugin._newsGroup, NntpPlugin._propTo); if (groups.Count > 0) { IResource server = new NewsgroupResource(groups[0]).Server; if (server != null) { NntpConnection postConnection = NntpConnectionPool.GetConnection(server, "foreground"); NntpPostArticleUnit postUnit = new NntpPostArticleUnit(draftArticle, server, finishedMethod, invokedByUser); postUnit.Finished += postUnit_Finished; postConnection.StartUnit(invokedByUser ? Int32.MaxValue - 2 : 0, postUnit); return; } } ArticlePostedOrFailed(draftArticle); if (finishedMethod != null) { finishedMethod(null); } }
public NntpDownloadAllHeadersUnit(NewsgroupResource group, JobPriority priority) : base(group, priority) { }
protected NntpDownloadHeadersUnitBase(NewsgroupResource group, JobPriority priority) { _group = group; _priority = priority; }
public NntpSetGroupUnit(NewsgroupResource group) { _group = group; }
public override void DisplayResource(IResource article, WordPtr[] wordsToHighlight) { if (_downloadLabel == null) { _downloadLabel = new JetLinkLabel(); _downloadLabel.Text = "Click here or press F5 to download the article"; _downloadLabel.BackColor = Color.Transparent; _downloadLabel.ClickableLink = true; _downloadLabel.Click += _downloadLabel_Click; Controls.Add(_downloadLabel); } _downloadLabel.Visible = false; _ieBrowser.Visible = true; bool redisplayed = _articleIsRedisplayed; _articleIsRedisplayed = false; DisposeArticleListener(); // Set the subject, highlight if needed ShowSubject(article.GetPropText(Core.Props.Subject), wordsToHighlight); try { // The content being indexed (plaintext) is not the same that is // displayed (autogenerated HTML), so the offsets are updated by // this method to correspond to the new formatting. string sFormattedArticle = ArticleBody2Html(article, ref wordsToHighlight); ShowHtml(sFormattedArticle, _ctxRestricted, wordsToHighlight); } catch (Exception e) { Utils.DisplayException(e, "Error"); return; } /** * set last selected article for article's owner */ IResource owner = _rbrowser.OwnerResource; if (owner != null && (owner.Type == NntpPlugin._newsGroup || owner.Type == NntpPlugin._newsFolder || owner.Type == NntpPlugin._newsServer)) { ResourceProxy proxy = new ResourceProxy(owner); proxy.AsyncPriority = JobPriority.AboveNormal; proxy.SetPropAsync(NntpPlugin._propLastSelectedArticle, article.Id); } _articleListener = article.ToResourceListLive(); _articleListener.ResourceChanged += _articleListener_ResourceChanged; bool hasNoBody = article.HasProp(NntpPlugin._propHasNoBody); if (!hasNoBody) { Core.UIManager.GetStatusWriter(this, StatusPane.Network).ClearStatus(); } else { if (!Utils.IsNetworkConnectedLight()) { ShowHtml("<pre>" + NntpPlugin._networkUnavailable + ".</pre>", WebSecurityContext.Internet, null); return; } IResourceList groups = article.GetLinksOfType(NntpPlugin._newsGroup, NntpPlugin._propTo); if (groups.Count > 0) { foreach (IResource groupRes in groups.ValidResources) { IResource server = new NewsgroupResource(groupRes).Server; if (server != null) { ServerResource serverRes = new ServerResource(server); if (redisplayed || serverRes.DownloadBodiesOnDeliver || serverRes.DownloadBodyOnSelection) { Core.UIManager.GetStatusWriter(this, StatusPane.Network).ShowStatus("Downloading article..."); NntpConnection articlesConnection = NntpConnectionPool.GetConnection(server, "foreground"); NntpDownloadArticleUnit downloadUnit = new NntpDownloadArticleUnit(article, groupRes, JobPriority.Immediate, true); downloadUnit.OnProgress += downloadUnit_OnProgress; ShowHtml("<pre>Downloading article: 0%</pre>", WebSecurityContext.Internet, null); articlesConnection.StartUnit(Int32.MaxValue - 1, downloadUnit); return; } } } if (!redisplayed) { Point location = _ieBrowser.Location; _downloadLabel.Location = new Point(location.X + 8, location.Y + 8); _downloadLabel.Visible = true; _ieBrowser.Visible = false; } } } }
/** * 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(); } }
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); }