public void TestMethod1() { /*AccountData account = new AccountData() * { * Name = "user", * Password = "******" * }; * Assert.IsFalse(app.James.Verify(account)); * app.James.Add(account); * Assert.IsTrue(app.James.Verify(account)); * app.James.Delete(account); * Assert.False(app.James.Verify(account));*/ for (int i = 0; i < 20; i++) { Pop3Client pop3 = new Pop3Client("localhost", 110, "user1", "password", false); pop3.Connect(); pop3.Authenticate(); if (pop3.GetMessageCount() > 0) { ReadOnlyMailMessage message = pop3.GetMessage(1); string body = message.Body; pop3.DeleteMessage(1); System.Console.Out.WriteLine(body); } else { System.Threading.Thread.Sleep(3000); } } }
public String GetLastMail(AccountData account) { // System.Threading.Thread.Sleep(2000); //int count = pop3.GetMessageCount(); for (int i = 0; i < 20; i++) { Pop3Client pop3 = new Pop3Client("localhost", 110, account.Name, account.Password, false); pop3.Connect(); pop3.Authenticate(); if (pop3.GetMessageCount() > 0) { // return pop3.GetMessage(1).Body; ReadOnlyMailMessage message = pop3.GetMessage(1); string body = message.Body; pop3.DeleteMessage(1); pop3.LogOut(); return(body); } else { System.Threading.Thread.Sleep(2000); } } return(null); }
public string GetLastMail(AccountData account) { for (int i = 0; i < 2; i++) { Pop3Client pop3 = new Pop3Client("localhost", 110, account.Name, account.Password, false); pop3.Connect(); pop3.Authenticate(); //Ждем завершения аутентификации ////int attempt = 0; ////while (!pop3.IsAuthenticated && attempt < 100) ////{ //// System.Threading.Thread.Sleep(100); //// attempt++; ////} if (pop3.GetMessageCount() > 0) { ReadOnlyMailMessage message = pop3.GetMessage(1); string body = message.Body; pop3.DeleteMessage(1); pop3.LogOut(); return(body); } else { System.Threading.Thread.Sleep(3000); } } return(null); }
/// <summary> /// Process a transmitted message to import any signing certificates for subsequent S/MIME encryption. /// </summary> /// <param name="o">A ProcessMessageArguments object containing message parameters.</param> private void ProcessMessage(object o) { ProcessMessageArguments arguments = (ProcessMessageArguments)o; // Export the message to a local directory. if (!string.IsNullOrEmpty(arguments.ExportDirectory)) { string messageId = Functions.ReturnBetween(arguments.MessageText.ToLower(), "message-id: <", ">"); if (string.IsNullOrEmpty(messageId)) { messageId = Guid.NewGuid().ToString(); } string fileName = ProxyFunctions.GetExportFileName(arguments.ExportDirectory, messageId, arguments.InstanceId, arguments.UserName); File.WriteAllText(fileName, arguments.MessageText); } // Only parse the message if it contains a known S/MIME content type. string canonicalMessageText = arguments.MessageText.ToLower(); if (canonicalMessageText.IndexOf("application/x-pkcs7-signature") > -1 || canonicalMessageText.IndexOf("application/pkcs7-mime") > -1) { try { // Parse the message. ReadOnlyMailMessage message = new ReadOnlyMailMessage(arguments.MessageText); // If the message contains a signing certificate that we haven't processed on this session, import it. foreach (X509Certificate2 cert in message.SmimeSigningCertificateChain) { if (cert != null && !SmimeCertificatesReceived.Contains(cert)) { // Import the certificate to the Local Machine store. ProxyFunctions.Log(LogWriter, SessionId, arguments.ConnectionId, "Importing certificate with Serial Number {" + cert.SerialNumber + "}.", Proxy.LogLevel.Information, LogLevel); CertHelper.InstallWindowsCertificate(cert, StoreLocation.LocalMachine); // Remember this ceriticate to avoid importing it again this session. SmimeCertificatesReceived.Add(cert); } } } catch (Exception ex) { if (arguments.DebugMode || System.Diagnostics.Debugger.IsAttached) { ProxyFunctions.Log(LogWriter, SessionId, "Exception while processing message: " + ex.ToString(), Proxy.LogLevel.Error, LogLevel); } else { ProxyFunctions.Log(LogWriter, SessionId, "Exception while processing message: " + ex.Message, Proxy.LogLevel.Error, LogLevel); } } } }
/// <summary> /// Render the selected message's body and selected headers to the specified controls. /// </summary> /// <param name="message">The message to display.</param> /// <param name="headerTextBox">The textbox to populate with selected headers.</param> /// <param name="bodyWebBrowser">The web browser in which to render the body.</param> /// <param name="bodyWebBrowserPanel">The panel containing the web browser.</param> private void RenderMessage(ReadOnlyMailMessage message, TextBox headerTextBox, WebBrowser bodyWebBrowser, Panel bodyWebBrowserPanel) { StringBuilder headersText = new StringBuilder(Constants.SMALLSBSIZE); // Output selected headers. headersText.Append("Date: " + message.Date.ToString() + "\r\n"); headersText.Append("From: "); if (message.From != null) headersText.Append(Functions.ToMailAddressString(new MailAddressCollection() { message.From })); else if (message.Sender != null) headersText.Append(Functions.ToMailAddressString(new MailAddressCollection() { message.Sender })); headersText.Append("\r\n"); if (message.To.Count > 0) headersText.Append("To: " + Functions.ToMailAddressString(message.To) + "\r\n"); if (message.CC.Count > 0) headersText.Append("CC: " + Functions.ToMailAddressString(message.CC) + "\r\n"); headersText.Append("Subject: " + message.Subject + "\r\n"); headersText.Append("S/MIME Signed: " + message.SmimeSigned.ToString() + "\r\n"); headersText.Append("S/MIME Envelope Encrypted: " + message.SmimeEncryptedEnvelope.ToString() + "\r\n"); headersText.Append("S/MIME Triple Wrapped: " + message.SmimeTripleWrapped.ToString() + "\r\n"); headersText.Append("Size: " + string.Format("{0:n0}", message.Size)); if (message.RawFlags.Count > 0) { headersText.Append("\r\nFlags: "); bool firstFlag = true; foreach (string flag in message.RawFlags) { if (!firstFlag) headersText.Append("; "); headersText.Append(flag); firstFlag = false; } } if (message.Attachments.Count > 0) { headersText.Append("\r\nAttachments: "); for (int i = 0; i < message.Attachments.Count; i++) { if (i > 0) headersText.Append("; "); headersText.Append(message.Attachments[i].Name + " (" + message.Attachments[i].ContentType.MediaType + ")"); } } headerTextBox.Text = headersText.ToString(); if (message.SmimeTripleWrapped) headerTextBox.BackColor = Color.LightGreen; else if (message.SmimeEncryptedEnvelope) { if (message.SmimeSigned) headerTextBox.BackColor = Color.LightGreen; else headerTextBox.BackColor = Color.GreenYellow; } else if (message.SmimeSigned) headerTextBox.BackColor = Color.LightBlue; else headerTextBox.BackColor = Color.White; // If in a SPAM or JUNK folder, don't embed attachments; bool isJunkFolder = false; string mailboxName = mailbox.ToUpper(); if (mailboxName.IndexOf("JUNK") > -1 || mailboxName.IndexOf("SPAM") > -1) isJunkFolder = true; string bodyHtml = Functions.RemoveScriptTags(message.Body); // If HTML, correct rendering of non-breaking spaces in the WebBrowser control. Otherwise, cast to HTML. if (message.IsBodyHtml) bodyHtml = bodyHtml.Replace(char.ConvertFromUtf32(194).ToString(), " ").Replace(char.ConvertFromUtf32(256).ToString(), " "); else bodyHtml = Functions.ConvertPlainTextToHTML(bodyHtml); if (isJunkFolder) bodyHtml = bodyHtml.Replace("://", "://spam."); else { if (message.IsBodyHtml) bodyHtml = Functions.EmbedAttachments(bodyHtml, message.Attachments); else bodyHtml = Functions.EmbedAttachments(bodyHtml, null); } bodyWebBrowser.DocumentText = bodyHtml; bodyWebBrowserPanel.Refresh(); }