当前位置: 首页>>代码示例>>C#>>正文


C# Pop3Client.GetMessageUid方法代码示例

本文整理汇总了C#中OpenPop.Pop3.Pop3Client.GetMessageUid方法的典型用法代码示例。如果您正苦于以下问题:C# Pop3Client.GetMessageUid方法的具体用法?C# Pop3Client.GetMessageUid怎么用?C# Pop3Client.GetMessageUid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenPop.Pop3.Pop3Client的用法示例。


在下文中一共展示了Pop3Client.GetMessageUid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessNewMessages

        /// <summary>
        /// Example showing:
        ///  - how to fetch all messages from a POP3 server
        /// </summary>
        /// <param name="hostname">Hostname of the server. For example: pop3.live.com</param>
        /// <param name="port">Host port to connect to. Normally: 110 for plain POP3, 995 for SSL POP3</param>
        /// <param name="useSsl">Whether or not to use SSL to connect to server</param>
        /// <param name="username">Username of the user on the server</param>
        /// <param name="password">Password of the user on the server</param>
        /// <returns>All Messages on the POP3 server</returns>
        public void ProcessNewMessages(string hostname, int port, bool useSsl, string username, string password)
        {
            // The client disconnects from the server when being disposed
            using (Pop3Client client = new Pop3Client())
            {
                // Connect to the server
                client.Connect(hostname, port, useSsl);

                // Authenticate ourselves towards the server
                client.Authenticate(username, password);

                // Get the number of messages in the inbox
                int messageCount = client.GetMessageCount();

                // We don't want to download all messages
                // List<Message> allMessages = new List<Message>(messageCount);
                List<string> uids = client.GetMessageUids();

                // Messages are numbered in the interval: [1, messageCount]
                // Ergo: message numbers are 1-based.
                for (int i = 1; i <= messageCount; i++)
                {
                    String uid = client.GetMessageUid(i);
                    if (seenUids.Contains(uid))
                    {
                        continue;
                    }

                    Message m = client.GetMessage(i);
                    if (m.MessagePart != null)
                    {
                        if (m.MessagePart.MessageParts != null)
                        {
                            for (int j = 0; j < m.MessagePart.MessageParts.Count; j++)
                            {
                                //if (m.MessagePart.MessageParts[j].Body != null)
                                //{
                                //    System.Console.Write(ASCIIEncoding.ASCII.GetString(m.MessagePart.MessageParts[j].Body));
                                //}

                                if (((m.MessagePart.MessageParts[j].IsAttachment) &&
                                    (m.MessagePart.MessageParts[j].FileName == "invite.ics")) ||
                                    ((m.MessagePart.MessageParts[j].ContentType != null) &&
                                     (m.MessagePart.MessageParts[j].ContentType.MediaType.StartsWith("text/calendar"))))
                                {
                                    //System.Console.Write(ASCIIEncoding.ASCII.GetString(m.MessagePart.MessageParts[j].Body));
                                    List<String> lines = ParseICalendar(m.MessagePart.MessageParts[j].Body);

                                    // Then find the relevant lines.
                                    // Make sure this is a VCALENDAR attachment.
                                    if ((lines != null) && lines[0].StartsWith("BEGIN:VCALENDAR"))
                                    {
                                        Meeting meeting = new Meeting();
                                        ExtractAttributes(lines, meeting);
                                        String json = meeting.ToJson();
                                        System.Console.WriteLine("Processing Message: " + uid);
                                        System.Console.WriteLine("JSON: " + json);
                                        seenUids.Add(uid);
                                        //PostJsonToWebServer(json);
                                    }
                                }
                            }
                        }
                    }
                    //System.Console.Write(ASCIIEncoding.ASCII.GetString(m.MessagePart.MessageParts[0].Body));
                    //allMessages.Add(m);
                }
            }
        }
开发者ID:praveenster,项目名称:peoplearewaiting,代码行数:79,代码来源:Program.cs

示例2: TestGetMessageUid

		public void TestGetMessageUid()
		{
			const string welcomeMessage = "+OK";
			const string okUsername = "+OK";
			const string okPassword = "+OK";
			const string messageUidResponse = "+OK 2 psycho"; // Message 2 has UID psycho
			const string serverResponses = welcomeMessage + "\r\n" + okUsername + "\r\n" + okPassword + "\r\n" + messageUidResponse + "\r\n";
			
			Stream inputStream = new MemoryStream(Encoding.ASCII.GetBytes(serverResponses));
			Stream outputStream = new MemoryStream();

			Pop3Client client = new Pop3Client();
			client.Connect(new CombinedStream(inputStream, outputStream));
			client.Authenticate("test", "test");

			const string expectedOutput = "psycho";

			// Delete all the messages
			string output = client.GetMessageUid(2);

			// We now expect that the client has given us the correct UID
			Assert.AreEqual(expectedOutput, output);
		}
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:23,代码来源:POPClientPositiveTests.cs

示例3: pop3recievecontent

        private string pop3recievecontent(string gmailuid)
        {
            Pop3Client pop3Client = null;
            pop3Client = new Pop3Client();
            pop3Client.Connect("pop.gmail.com", 995, true);
            pop3Client.Authenticate("[email protected]", "[email protected]", AuthenticationMethod.TryBoth);
            int count = pop3Client.GetMessageCount();
            this.Emails = new List<Email1>();
            int counter = 0;
            for (int j = count; j >= 1; j--)
            {
                Message message = pop3Client.GetMessage(j);
                string hh1 = pop3Client.GetMessageUid(j);

                if (gmailuid == hh1)
                {
                    Email1 email1 = new Email1()
                    {
                        MessageNumber = j,
                        Subject = message.Headers.Subject,
                        DateSent = message.Headers.DateSent,

                        From = string.Format("<a href = 'mailto:{1}'>{0}</a>", message.Headers.From.DisplayName, message.Headers.From.Address),
                    };

                    MessagePart body = message.FindFirstHtmlVersion();

                    if (body != null)
                    {
                        email1.Body = body.GetBodyAsText();
                        return email1.Body;
                    }
                    else
                    {
                        body = message.FindFirstPlainTextVersion();

                        if (body != null)
                        {
                            email1.Body = body.GetBodyAsText();
                            return email1.Body;
                        }
                    }

                    this.Emails.Add(email1);
                }
                counter++;
            }
            return "";
        }
开发者ID:aryvartsoftware,项目名称:New_EmailCampaign,代码行数:49,代码来源:CampaignReport.aspx.cs


注:本文中的OpenPop.Pop3.Pop3Client.GetMessageUid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。