Пример #1
0
 public static bool MoveTo(this PrivateMessageMetadata metadata, PrivateMessageFolderMetadata folder)
 {
     return(AwfulContentRequest.Messaging.MoveMessage(
                metadata.FolderId,
                folder.FolderId,
                metadata.PrivateMessageId));
 }
Пример #2
0
        public PrivateMessageMetadata FetchMessage(int privateMessageId)
        {
            PrivateMessageMetadata message = null;
            var web = new AwfulWebClient();
            var url = string.Format("{0}/{1}?action=show&privatemessageid={2}", CoreConstants.BASE_URL,
                                    CoreConstants.PRIVATE_MESSAGE_URI,
                                    privateMessageId);

            var doc = web.FetchHtml(url).ToHtmlDocument();

            if (doc != null)
            {
                message = PrivateMessageParser.ParsePrivateMessageDocument(doc);
            }

            return(message);
        }
Пример #3
0
        public static string Metrofy(PrivateMessageMetadata message)
        {
            if (message.Body == null)
            {
                message = message.Refresh();
            }

            HtmlDocument html = new HtmlDocument();

            html.LoadHtml(message.Body);
            HtmlNode postbody = html.DocumentNode.Descendants()
                                .Where(node => node.GetAttributeValue("class", "").Equals("postbody"))
                                .FirstOrDefault();

            string result = new ForumContentParser(postbody.FirstChild).Body;

            return(result);
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        public static IList <PrivateMessageMetadata> ParseMessageList(HtmlDocument doc)
        {
            List <PrivateMessageMetadata> messages = new List <PrivateMessageMetadata>();
            var top          = doc.DocumentNode;
            var messagesNode = top.Descendants("table").FirstOrDefault();
            var messageTable = messagesNode.Descendants("tr").ToArray();

            // remove last element from the table
            messageTable[messageTable.Length - 1] = null;

            // remove first element from the table
            messageTable[0] = null;

            foreach (var item in messageTable)
            {
                if (item != null && string.IsNullOrEmpty(item.GetAttributeValue("class", "")) == true)
                {
                    if (item.InnerText.Contains(PRIVATE_MESSAGE_EMPTY_FOLDER_TEXT))
                    {
                        break;
                    }
                    var message    = new PrivateMessageMetadata();
                    var rows       = item.Descendants("td").ToArray();
                    var statusNode = rows[0];
                    message.Status = GetMessageStatusFromNode(statusNode);
                    // skip the thread tag node, since I'm not using those yet
                    var titleNode = rows[2];
                    // title node has our subject and message id
                    message.Subject          = GetMessageTitleFromNode(titleNode);
                    message.PrivateMessageId = GetMessageIDFromNode(titleNode);
                    // author node is next <td>
                    var authorNode = rows[3];
                    message.From = GetMessageAuthorFromNode(authorNode);

                    // postmark node is next <td>
                    var postmarkNode = rows[4];
                    message.PostDate = GetPostMarkFromNode(postmarkNode);
                    messages.Add(message);
                }
            }

            return(messages);
        }
Пример #5
0
        public static bool Delete(this PrivateMessageMetadata metadata)
        {
            bool success = AwfulContentRequest.Messaging.DeleteMessage(metadata.FolderId, metadata.PrivateMessageId);

            return(success);
        }
Пример #6
0
        public static IPrivateMessageRequest BeginReply(this PrivateMessageMetadata metadata)
        {
            var request = AwfulContentRequest.Messaging.BeginReplyToMessage(metadata.PrivateMessageId);

            return(request);
        }
Пример #7
0
        public static IPrivateMessageRequest BeginForward(this PrivateMessageMetadata metadata)
        {
            var request = AwfulContentRequest.Messaging.ForwardMessage(metadata.PrivateMessageId);

            return(request);
        }
Пример #8
0
 public static PrivateMessageMetadata Refresh(this PrivateMessageMetadata metadata)
 {
     return(AwfulContentRequest.Messaging.LoadMessage(metadata.PrivateMessageId));
 }
Пример #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        public static PrivateMessageMetadata ParsePrivateMessageDocument(HtmlDocument doc)
        {
            var pm  = new PrivateMessageMetadata();
            var top = doc.DocumentNode;

            // **** PARSE BODY *****
            var postBodyNode = top.Descendants("td")
                               .Where(node => node.GetAttributeValue("class", "").Equals(NEW_MESSAGE_POSTBODY))
                               .SingleOrDefault();

            if (postBodyNode != null)
            {
                pm.Body = new ForumContentParser(postBodyNode).Body;
            }

            // ***** PARSE AUTHOR *****
            var authorNode = top.Descendants("dt")
                             .Where(node => node.GetAttributeValue("class", "").Equals(NEW_MESSAGE_AUTHOR))
                             .FirstOrDefault();

            pm.From = authorNode == null ? NEW_MESSAGE_UNKNOWN_AUTHOR : authorNode.InnerText;

            // ***** PARSE MESSAGE ID *****
            var messageIdNode = top.Descendants(NEW_MESSAGE_INPUT_TAG)
                                .Where(node => node.GetAttributeValue("name", "").Equals(NEW_MESSAGE_PRIVATEMESSAGEID))
                                .FirstOrDefault();

            int id = 0;

            if (messageIdNode != null)
            {
                string value = messageIdNode.GetAttributeValue("value", "");
                int.TryParse(value, out id);
            }
            pm.PrivateMessageId = id.ToString();

            // ***** PARSE SUBJECT *****
            var subjectNode = top.Descendants("div")
                              .Where(node => node.GetAttributeValue("class", "").Equals("breadcrumbs"))
                              .FirstOrDefault();

            if (subjectNode != null)
            {
                string subject = subjectNode.ParseTitleFromBreadcrumbsNode();
                pm.Subject = subject;
            }

            // ***** PARSE POST MARK *****
            var postmarkNode = top.Descendants("td")
                               .Where(node => node.GetAttributeValue("class", "")
                                      .Equals("postdate"))
                               .FirstOrDefault();

            if (postmarkNode != null)
            {
                string postmark = postmarkNode.InnerText;
                try { pm.PostDate = Convert.ToDateTime(postmark); }
                catch (Exception) { pm.PostDate = DateTime.Parse(postmark, System.Globalization.CultureInfo.InvariantCulture); }
            }

            return(pm);
        }