Exemplo n.º 1
0
 private void GetArticleById()
 {
     _articleAvailable = false;
     _articleId        = ParseTools.UnescapeCaseSensitiveString(_article.GetPropText(NntpPlugin._propArticleId));
     _getArticleUnit   = new AsciiSendLineAndApplyMethodUnit(
         "article " + _articleId, ".\r\n", new LineDelegate(getArticleByIdUnitProcessLine));
     _getArticleUnit.Finished += new AsciiProtocolUnitDelegate(getArticleUnit_Finished);
     StartUnit(_getArticleUnit, _connection);
 }
Exemplo n.º 2
0
 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);
         }
     }
 }
Exemplo n.º 3
0
 private void PreparePosting()
 {
     if (NewsFolders.IsInFolder(_draftArticle, NewsFolders.SentItems))
     {
         Core.NetworkAP.QueueJob(
             JobPriority.Immediate, "Finish posting", new MethodInvoker(FireFinished));
     }
     else
     {
         NewsFolders.PlaceResourceToFolder(_draftArticle, NewsFolders.Outbox);
         _nntpBody = _draftArticle.GetPropText(NntpPlugin._propNntpText);
         if (!_draftArticle.HasProp(NntpPlugin._propArticleId))
         {
             StringBuilder builder = new StringBuilder(_nntpBody.Length + 64);
             builder.Append("Date: ");
             DateTime postTime = DateTime.UtcNow;
             builder.Append(_daysOfTheWeek[(int)postTime.DayOfWeek]);
             builder.Append(", ");
             builder.Append(postTime.Day);
             builder.Append(' ');
             builder.Append(_months[postTime.Month - 1]);
             builder.Append(' ');
             builder.Append(postTime.Year);
             builder.Append(' ');
             builder.Append(postTime.Hour.ToString().PadLeft(2, '0'));
             builder.Append(':');
             builder.Append(postTime.Minute.ToString().PadLeft(2, '0'));
             builder.Append(':');
             builder.Append(postTime.Second.ToString().PadLeft(2, '0'));
             builder.Append(" +0000 (UTC)");
             builder.Append("\r\nMessage-ID: ");
             string message_id = ParseTools.GenerateArticleId(_draftArticle, _server.Name);
             builder.Append(message_id);
             builder.Append("\r\n");
             builder.Append(_nntpBody);
             _nntpBody = builder.ToString();
             _draftArticle.SetProp(NntpPlugin._propArticleId, message_id);
         }
         AsciiSendLineGetLineUnit initPostUnit = new AsciiSendLineGetLineUnit("post");
         initPostUnit.Finished += new AsciiProtocolUnitDelegate(initPostUnit_Finished);
         Core.NetworkAP.QueueJob(JobPriority.Immediate, "Posting articles",
                                 new StartUnitDelegate(StartUnit), initPostUnit, _connection);
     }
 }
Exemplo n.º 4
0
        /**
         * returns true if a contact is myself
         */
        internal static bool ParseFrom(IResource article, string fromValue, out IContact contact)
        {
            if (MIMEParser.ContainsMIMEStrings(fromValue))
            {
                fromValue = ParseTools.ParseMIMEHeader(fromValue);
            }

            fromValue = fromValue.Replace("<", null).Replace(">", null).Replace("\\", null).Replace("//", null);
            string[] parts = fromValue.Split(' ');
            string   eMail = string.Empty;

            foreach (string part in parts)
            {
                if (part.IndexOf('@') >= 0)
                {
                    eMail = part;
                    break;
                }
            }
            string displayName = fromValue;

            if (eMail.Length > 0)
            {
                displayName = displayName.Replace(eMail, null).Trim();
            }
            if (eMail.Length > 0 || displayName.Length > 0)
            {
                IContactManager cm      = Core.ContactManager;
                IResource       oldFrom = article.GetLinkProp(cm.Props.LinkFrom);
                contact = cm.FindOrCreateContact(eMail, displayName);
                cm.LinkContactToResource(cm.Props.LinkFrom, contact.Resource, article, eMail, displayName);
                if (oldFrom != null && contact.Resource != oldFrom)
                {
                    cm.DeleteUnusedContacts(oldFrom.ToResourceList());
                }
                return(contact.IsMyself);
            }
            contact = null;
            return(false);
        }
Exemplo n.º 5
0
 public NntpDownloadGroupsUnit(IResource server, bool refresh, JobPriority priority)
 {
     Interlocked.Increment(ref NntpPlugin._deliverNewsUnitCount);
     _serverResource = new ServerResource(server);
     Core.UIManager.GetStatusWriter(typeof(NntpDownloadGroupsUnit),
                                    StatusPane.Network).ShowStatus("Downloading groups from " + _serverResource.DisplayName + "...");
     _priority = priority;
     _nntpCmd  = "list";
     if (!refresh)
     {
         DateTime lastUpdated = _serverResource.LastUpdateTime;
         if (lastUpdated > DateTime.MinValue)
         {
             _nntpCmd = "newgroups " + ParseTools.NNTPDateString(lastUpdated);
         }
     }
     _count                  = 0;
     _responseChecked        = false;
     _groupList              = new ArrayList();
     _groupListLock          = new SpinWaitLock();
     _flushGroupListDelegate = new MethodInvoker(FlushGroupList);
 }
Exemplo n.º 6
0
 internal static string TranslateHeader(string charset, string header)
 {
     header = MIMEParser.ContainsMIMEStrings(header) ? ParseTools.ParseMIMEHeader(header) :
              MIMEParser.TranslateRawStringInCharset(charset, header);
     return(header);
 }
Exemplo n.º 7
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();
            }
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        /**
         * 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();
            }
        }