コード例 #1
0
        private async Task <SLChatPostMessageResult> PostCommit(IMAPMessage imapMsg, string channelID)
        {
            StringBuilder sb = new StringBuilder("");

            sb.Append(cCommitStartLine);
            sb.Append(imapMsg.Uid);
            sb.Append(cCommitFieldsSeparator);
            sb.Append(cCommitFromName);
            sb.Append(imapMsg.From[0].Address);
            sb.Append(cCommitFieldsSeparator);
            sb.Append(cCommitSubjectName);
            sb.Append(imapMsg.Subject);
            sb.Append(cCommitEndLIne);

            StringBuilder attachments = new StringBuilder();

            attachments.Append("[{");
            attachments.Append("\"text\":");
            string commitBody = "```" + SLNormalizer.EscapeJSONString(GetCommitBody(imapMsg)) + "```";

            attachments.Append("\"");
            attachments.Append(commitBody);
            attachments.Append("\",");
            attachments.Append("\"mrkdwn_in\": [\"text\"]");
            attachments.Append("}]");

            return(await slWebApiClient.ChatPostMessageAsync(channelID, sb.ToString(), true, false, attachments.ToString()));
        }
コード例 #2
0
        private async Task <bool> PostCommitToChannels(IMAPMessage imapMsg, HashSet <string> channelIDsForRepository, Dictionary <string, HashSet <string> > commitUidsPostedInChannels)
        {
            bool posted = false;

            foreach (string channelID in channelIDsForRepository)
            {
                bool             channelFound = false;
                HashSet <string> commitUidsPostedInChannel = commitUidsPostedInChannels.TryGetValue(channelID, out channelFound);
                if (channelFound)
                {
                    if (!commitUidsPostedInChannel.Contains(imapMsg.Uid.ToString()))
                    {
                        SLChatPostMessageResult result = await PostCommit(imapMsg, channelID);

                        if ((!result.ok.HasValue) || (!result.ok.Value))
                        {
                            posted = false;
                            return(posted);
                        }
                        else
                        {
                            posted = true;
                        }
                    }
                }
            }
            return(posted);
        }
コード例 #3
0
        private string FindLoadRunnerBuildUrl(IMAPMessage message)
        {
            string loadRunnerUrl = "";

            try
            {
                string htmlPart = "";
                if (message.BodyParts != null)
                {
                    foreach (IMAPMessageContent content in message.BodyParts)
                    {
                        if (content.ContentType.StartsWith("text/html"))
                        {
                            htmlPart = content.TextData;
                            HtmlDocument doc = new HtmlDocument();
                            doc.LoadHtml(htmlPart);
                            foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//td[@style]"))
                            {
                                string innerText = node.InnerHtml;
                                if (innerText.Equals("LoadRunner Setup"))
                                {
                                    loadRunnerUrl = node.NextSibling.ChildNodes[0].Attributes["href"].Value;
                                    return(loadRunnerUrl);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(loadRunnerUrl);
        }
コード例 #4
0
ファイル: Remove.cs プロジェクト: jeason0813/Asmodat
        public void RemoveMessages(IMAPFolder folder, string subjectNotContainingSting)
        {
            if (folder == null || folder.Messages == null || folder.Messages.Count <= 0)
            {
                return;
            }

            if (folder.SubFolders != null && folder.SubFolders.Count > 0)
            {
                IMAPFolder[] folders = folder.SubFolders.ToArray();

                for (int i = 0; i < folders.Length; i++)
                {
                    this.RemoveMessages(folders[i], subjectNotContainingSting);
                }
            }

            IMAPMessage[] messages = folder.Messages.ToArray();

            for (int i = 0; i < messages.Length; i++)
            {
                IMAPMessage message = messages[i];

                if (message == null)
                {
                    continue;
                }

                if (subjectNotContainingSting != null)
                {
                    if (message.Subject == null || !message.Subject.Contains(subjectNotContainingSting))
                    {
                        try
                        {
                            bool result = folder.Messages.Remove(message);
                            if (result)
                            {
                                continue;
                            }
                        }
                        catch (Exception ex)
                        {
                            ex.ToOutput();
                        }
                    }
                }
            }

            return;
        }
コード例 #5
0
        private async Task <SLChatPostMessageResult> PostBuild(IMAPMessage message, string groupID)
        {
            StringBuilder sb = new StringBuilder("");

            sb.Append(cBuildStartLine);
            sb.Append(" ");
            sb.Append(message.Uid);
            sb.Append("    ");
            sb.Append(message.Subject);
            sb.AppendLine();
            sb.Append(FindLoadRunnerBuildUrl(message));
            sb.Append("```");
            return(await slWebApiClient.ChatPostMessageAsync(groupID, sb.ToString(), true, true));
        }
コード例 #6
0
        private async Task <SLChatPostMessageResult> PostCommitComment(IMAPMessage imapMsg, string channelID)
        {
            StringBuilder sb = new StringBuilder("");

            sb.Append(cCommitStartLine);
            //sb.Append(imapMsg.Uid);
            //sb.Append(cCommitFieldsSeparator);
            sb.Append(cCommitFromName);
            sb.Append(imapMsg.From[0]);
            sb.Append(cCommitFieldsSeparator);
            sb.Append(cCommitSubjectName);
            sb.Append(imapMsg.Subject);
            sb.Append(cCommitEndLIne);
            return(await slWebApiClient.ChatPostMessageAsync(channelID, sb.ToString(), true, false));
        }
コード例 #7
0
 private string GetCommitBody(IMAPMessage message)
 {
     try
     {
         if (message.BodyParts != null)
         {
             foreach (IMAPMessageContent content in message.BodyParts)
             {
                 if (content.ContentType.StartsWith("text/plain"))
                 {
                     return(content.TextData);
                 }
             }
         }
     }
     catch (Exception ex)
     {
     }
     return("");
 }
コード例 #8
0
 private string GetCommitBody(IMAPMessage message)
 {
     try
     {
         if (message.BodyParts != null)
         {
             foreach (IMAPMessageContent content in message.BodyParts)
             {
                 if (content.ContentType.StartsWith("text/plain"))
                 {
                     int limit     = 3000;
                     int maxLength = content.TextData.Length > limit ? limit : content.TextData.Length;
                     return(content.TextData.Substring(0, maxLength));
                 }
             }
         }
     }
     catch (Exception ex)
     {
     }
     return("");
 }
コード例 #9
0
        private async Task <SLFileUploadResult> PostCommitBody(IMAPMessage imapMsg, string channelID)
        {
            string commitBody = GetCommitBody(imapMsg);

            return(await slWebApiClient.UploadFile(commitBody, "txt", cFileNamePrefix + imapMsg.Uid, channelID));
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: briancullinan/epiccentral
        static void Main(string[] args)
        {
            //IMAPConfig config = new IMAPConfig("<host>", "<username>", "<password>", false, true, "");
            //config.SaveConfig("settings.cfg");
            IMAPConfig config = new IMAPConfig(@"c:\test1.cfg");

            config.CacheFile = "";

            IMAPClient client = null;

            try
            {
                client = new IMAPClient(config, null, 5);
            }
            catch (IMAPException e)
            {
                Console.WriteLine(e.Message);
                return;
            }


            //IMAPFolder drafts = client.Folders["Drafts"];

            //IMAPMessage newMessage = new IMAPMessage();
            //newMessage.From.Add(new IMAPMailAddress("Jason Miesionczek", "*****@*****.**"));
            //newMessage.To.Add(new IMAPMailAddress("Jason Miesionczek", "*****@*****.**"));
            //newMessage.Date = DateTime.Now;
            //newMessage.Subject = "this is a new message";
            //drafts.AppendMessage(newMessage, "this is the content of the new message");
            //IMAPFolder f = client.Folders["INBOX"];
            //Console.WriteLine(f.Messages.Count);
            //IMAPMessage msg = f.GetMessageByID(21967);
            //Console.WriteLine(msg.TextData.Data);
            //foreach (IMAPFileAttachment attachment in msg.Attachments)
            //{
            //    attachment.SaveFile("C:\\");
            //}
            //Console.ReadLine();

            IMAPFolder f = client.Folders["INBOX"];

            int[] msgCount = null;

            while (msgCount.Length == 0)
            {
                msgCount = f.CheckForNewMessages();
                Thread.Sleep(1000);
            }

            foreach (int id in msgCount)
            {
                IMAPMessage msg = f.GetMessageByID(id);
                // do some logic here
                msg.MarkAsRead();
            }

            //IMAPFolder f = client.Folders["Deleted Items"];
            //IMAPMessage m = f.GetMessageByID(707);
            //IMAPFolder d = client.Folders["Deleted Items"];
            //IMAPMessage m = d.Messages[0];
            //IMAPMessage m = f.GetMessageByID(375);
            //IMAPMessage m = f.Messages[0];
            //m.RefreshData(true, true);

            //client._imap.ProcessMessageHeader(m, 0); // 2893
            //client._imap.ProcessBodyStructure(m);
            //client._imap.ProcessMessageHeader(m, 0);
            //client._imap.ProcessBodyStructure(m);
            //client._imap.ProcessBodyParts(m);
            //client._imap.ProcessAttachments(m);
            //IMAPSearchQuery query = new IMAPSearchQuery();
            //query.Range = new DateRange(DateTime.Now.AddDays(-6), DateTime.Now);
            //IMAPSearchResult sResult = f.Search(query);

            //IMAPSearchResult sResult = f.Search(IMAPSearchQuery.QuickSearchDateRange(DateTime.Now.AddDays(-6), DateTime.Now));
            //IMAPSearchResult sResult = f.Search(IMAPSearchQuery.QuickSearchFrom("Christine Fade", "*****@*****.**"));
            //IMAPSearchResult sResult = f.Search(IMAPSearchQuery.QuickSearchNew());

            //IMAPFolder test = f.SubFolders["Test"];
            //IMAPFolder del = client.Folders["Deleted Items"];
            //f.CopyMessageToFolder(f.Messages[0], test);
            //test.DeleteMessage(test.Messages[0]);
            //f.MoveMessageToFolder(f.Messages[0], test);

            //test.EmptyFolder();
            //Console.WriteLine("{0} - {1}", sResult.Query.Range.StartDate, sResult.Query.Range.EndDate);
            //foreach (IMAPMessage msg in sResult.Messages)
            //{
            //    msg.RefreshData(true, true, false);
            //    Console.WriteLine("{0}: {1}", msg.Date, msg.Subject);
            //    Console.WriteLine(msg.TextData.Data);
            //}
            //m.Attachments[1].SaveFile("C:\\");
            Console.ReadLine();
            foreach (IMAPMessage msg in client.Folders["INBOX"].Messages)
            {
                if (msg.BodyParts.Count == 0)
                {
                    Console.WriteLine(msg.Uid);
                }
            }
            client.Logoff();
        }