public void TestNoReferencesListIsEmpty() { NameValueCollection collection = new NameValueCollection(); MessageHeader header = new MessageHeader(collection); Assert.NotNull(header.References); Assert.IsEmpty(header.References); }
public void TestNoInReplyToListIsEmpty() { NameValueCollection collection = new NameValueCollection(); MessageHeader header = new MessageHeader(collection); Assert.NotNull(header.InReplyTo); Assert.IsEmpty(header.InReplyTo); }
public void TestSingleReference() { NameValueCollection collection = new NameValueCollection(); collection.Add("References", "<*****@*****.**>"); MessageHeader header = new MessageHeader(collection); Assert.IsNotEmpty(header.References); Assert.AreEqual(1, header.References.Count); Assert.AreEqual("*****@*****.**", header.References[0]); }
public void TestSingleInReplyTo() { NameValueCollection collection = new NameValueCollection(); collection.Add("In-Reply-To", "<*****@*****.**>"); MessageHeader header = new MessageHeader(collection); Assert.IsNotEmpty(header.InReplyTo); Assert.AreEqual(1, header.InReplyTo.Count); Assert.AreEqual("*****@*****.**", header.InReplyTo[0]); }
public void TestMultipleKeywords() { NameValueCollection collection = new NameValueCollection(); collection.Add("Keywords", "test, hi"); MessageHeader header = new MessageHeader(collection); Assert.AreEqual(2, header.Keywords.Count); Assert.AreEqual("test", header.Keywords[0]); Assert.AreEqual("hi", header.Keywords[1]); }
public void TestMultipleReferencesNoWhitespaceSeparation() { NameValueCollection collection = new NameValueCollection(); collection.Add("References", "<*****@*****.**><*****@*****.**>"); MessageHeader header = new MessageHeader(collection); Assert.IsNotEmpty(header.References); Assert.AreEqual(2, header.References.Count); Assert.AreEqual("*****@*****.**", header.References[0]); Assert.AreEqual("*****@*****.**", header.References[1]); }
public void TestMultipleInReplyToWithWhiteSpaceSeparation() { NameValueCollection collection = new NameValueCollection(); collection.Add("In-Reply-To", "<*****@*****.**> <*****@*****.**>"); MessageHeader header = new MessageHeader(collection); Assert.IsNotEmpty(header.InReplyTo); Assert.AreEqual(2, header.InReplyTo.Count); Assert.AreEqual("*****@*****.**", header.InReplyTo[0]); Assert.AreEqual("*****@*****.**", header.InReplyTo[1]); }
public void TestComplexDispositionNotificationTo() { NameValueCollection collection = new NameValueCollection(); collection.Add("Disposition-Notification-To", "\"Test with, comma\" <*****@*****.**>, Foo <*****@*****.**>"); MessageHeader header = new MessageHeader(collection); Assert.NotNull(header.DispositionNotificationTo); Assert.AreEqual(2, header.DispositionNotificationTo.Count); Assert.AreEqual("Test with, comma", header.DispositionNotificationTo[0].DisplayName); Assert.AreEqual("*****@*****.**", header.DispositionNotificationTo[0].Address); Assert.AreEqual("Foo", header.DispositionNotificationTo[1].DisplayName); Assert.AreEqual("*****@*****.**", header.DispositionNotificationTo[1].Address); }
public void TestSpaceInBase64HeaderValue() { string base64Header = "Disposition-Notification-To: =?windows-1251?B?ZWFzdXJlLg\r\n" + " ==?=\r\n" + "\t<*****@*****.**>\r\n" ; string expectedName = "easure."; string expectedAddress = "*****@*****.**"; NameValueCollection col = HeaderExtractor.ExtractHeaders(base64Header); Assert.AreEqual(1, col.Count); MessageHeader header = new MessageHeader(col); Assert.AreEqual(1, header.DispositionNotificationTo.Count); RfcMailAddress address = header.DispositionNotificationTo[0]; Assert.IsNotNull(address.MailAddress); Assert.AreEqual(expectedName, address.MailAddress.DisplayName); Assert.AreEqual(expectedAddress, address.MailAddress.Address); }
/// <summary> /// Extract the header part and body part of a message.<br/> /// The headers are then parsed to a strongly typed <see cref="MessageHeader"/> object. /// </summary> /// <param name="fullRawMessage">The full message in bytes where header and body needs to be extracted from</param> /// <param name="headers">The extracted header parts of the message</param> /// <param name="body">The body part of the message</param> /// <exception cref="ArgumentNullException">If <paramref name="fullRawMessage"/> is <see langword="null"/></exception> public static void ExtractHeadersAndBody(byte[] fullRawMessage, out MessageHeader headers, out byte[] body) { if(fullRawMessage == null) throw new ArgumentNullException("fullRawMessage"); // Find the end location of the headers int endOfHeaderLocation = FindHeaderEndPosition(fullRawMessage); // The headers are always in ASCII - therefore we can convert the header part into a string // using US-ASCII encoding string headersString = Encoding.ASCII.GetString(fullRawMessage, 0, endOfHeaderLocation); // Now parse the headers to a NameValueCollection NameValueCollection headersUnparsedCollection = ExtractHeaders(headersString); // Use the NameValueCollection to parse it into a strongly-typed MessageHeader header headers = new MessageHeader(headersUnparsedCollection); // Since we know where the headers end, we also know where the body is // Copy the body part into the body parameter body = new byte[fullRawMessage.Length - endOfHeaderLocation]; Array.Copy(fullRawMessage, endOfHeaderLocation, body, 0, body.Length); }
/// <summary> /// Used to construct the topmost message part /// </summary> /// <param name="rawBody">The body that needs to be parsed</param> /// <param name="headers">The headers that should be used from the message</param> /// <exception cref="ArgumentNullException">If <paramref name="rawBody"/> or <paramref name="headers"/> is <see langword="null"/></exception> internal MessagePart(byte[] rawBody, MessageHeader headers) { if(rawBody == null) throw new ArgumentNullException("rawBody"); if(headers == null) throw new ArgumentNullException("headers"); ContentType = headers.ContentType; ContentDescription = headers.ContentDescription; ContentTransferEncoding = headers.ContentTransferEncoding; ContentId = headers.ContentId; ContentDisposition = headers.ContentDisposition; FileName = FindFileName(ContentType, ContentDisposition, "(no name)"); BodyEncoding = ParseBodyEncoding(ContentType.CharSet); ParseBody(rawBody); }
private void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e) { //####################### Get Attachment from Email ########################################### ListBox listBox1 = new ListBox(); var client = new Pop3Client(); int Port_Number = 995; Boolean UseSSL = true; string sendBack = string.Empty; string returnSubject = string.Empty; try { client.Connect("pop.gmail.com", Port_Number, UseSSL); client.Authenticate("*****@*****.**", "XXXXXXX"); var messageCount = client.GetMessageCount(); var header = client.GetMessageInfos(); var Messages = new List<OpenPop.Mime.Message>(messageCount); var Headers = new List<MessageHeader>(messageCount); for (int i = 0; i < messageCount; i++) { OpenPop.Mime.Message getMessage = client.GetMessage(i + 1); Messages.Add(getMessage); } for (int i = 0; i < messageCount; i++) { OpenPop.Mime.Header.MessageHeader getHeader = client.GetMessageHeaders(i + 1); Headers.Add(getHeader); } foreach (OpenPop.Mime.Message msg in Messages) { foreach (var attachment in msg.FindAllAttachments()) { string filePath = Path.Combine(@"C:\Users\colin\Desktop\File.txt"); if (attachment.FileName.Equals("EditCode.txt")) { FileStream Stream = new FileStream(filePath, FileMode.Create); BinaryWriter BinaryStream = new BinaryWriter(Stream); BinaryStream.Write(attachment.Body); BinaryStream.Close(); foreach (var s in Headers) { string Reply = s.ReturnPath.ToString(); sendBack = Reply.ToString(); string Subby = s.Subject.ToString(); returnSubject = Subby.ToString(); } if (client.Connected) client.Dispose(); } else { if (client.Connected) client.Dispose(); break; } } } } catch (Exception ex) { MessageBox.Show("", ex.Message); } //####################### Edit File ########################################### if (System.IO.File.Exists(@"C:\Users\colin\Desktop\File.txt")) { using (StreamReader sr = new StreamReader(@"C:\Users\colin\Desktop\File.txt")) { { string line; while ((line = sr.ReadLine()) != null) { if (line.Contains("<div")) { string s = "<div{value here}>"; int start = s.IndexOf("<div"); int end = s.IndexOf(">"); line = line.Remove(start); } if (line.Contains("</div>")) { line = line.Replace("</div>", ""); } if (line.Contains("h1")) { line = line.Replace("h1", "h4"); } if (line.Contains("h2")) { line = line.Replace("h2", "h4"); } if (line.Contains("h3")) { line = line.Replace("h3", "h4"); } if (line.Contains(" ")) { line = line.Replace(" ", ""); } if (line.Contains("’")) { line = line.Replace("’", "'"); } if (line.Contains(" –")) { line = line.Replace(" –", "."); } if (line.Contains("â€")) { line = line.Replace("â€", ""); } if (line.Contains("“")) { line = line.Replace("“", ""); } if (line.Contains("œ")) { line = line.Replace("œ", ""); } if (line.Contains(""")) { line = line.Replace(""", ""); } if (line.Contains("&")) { line = line.Replace("&", ""); } if (line.Contains("'")) { line = line.Replace("'", "'"); } if (line.Contains("class=\"note\"")) { line = line.Replace("class=\"note\"", ""); } if (line.Contains("class=\"first\"")) { line = line.Replace("class=\"first\"", ""); } if (line.Contains("class=\"last\"")) { line = line.Replace("class=\"last\"", ""); } if (line.Contains("class=\"odd\"")) { line = line.Replace("class=\"odd\"", ""); } if (line.Contains("class=\"even\"")) { line = line.Replace("class=\"even\"", ""); } if (line.Contains("class=\"bot\"")) { line = line.Replace("class=\"bot\"", ""); } if (line.Contains("class=\"data-table data-table-simple\"")) { line = line.Replace("class=\"data-table data-table-simple\"", "class=\"content-table\""); } if (line.Contains("class=\"data-table data-table-advanced\"")) { line = line.Replace("class=\"data-table data-table-advanced\"", "class=\"content-table\""); } if (line.Contains("<tr style=\"height:")) { line = line.Replace("<tr style=\"height: 10px;\">", "<tr>"); line = line.Replace("<tr style=\"height:10px;\">", "<tr>"); line = line.Replace("<tr style=\"height: 20px;\">", "<tr>"); line = line.Replace("<tr style=\"height:20px;\">", "<tr>"); line = line.Replace("<tr style=\"height: 30px;\">", "<tr>"); line = line.Replace("<tr style=\"height:30px;\">", "<tr>"); line = line.Replace("<tr style=\"height: 40px;\">", "<tr>"); line = line.Replace("<tr style=\"height:40px;\">", "<tr>"); line = line.Replace("<tr style=\"height: 50px;\">", "<tr>"); line = line.Replace("<tr style=\"height:50px;\">", "<tr>"); line = line.Replace("<tr style=\"height: 60px;\">", "<tr>"); line = line.Replace("<tr style=\"height:60px;\">", "<tr>"); line = line.Replace("<tr style=\"height: 70px;\">", "<tr>"); line = line.Replace("<tr style=\"height:70px;\">", "<tr>"); line = line.Replace("<tr style=\"height: 80px;\">", "<tr>"); line = line.Replace("<tr style=\"height:80px;\">", "<tr>"); line = line.Replace("<tr style=\"height: 90px;\">", "<tr>"); line = line.Replace("<tr style=\"height:90px;\">", "<tr>"); line = line.Replace("<tr style=\"height: 100px;\">", "<tr>"); line = line.Replace("<tr style=\"height:100px;\">", "<tr>"); line = line.Replace("<tr style=\"height: 110px;\">", "<tr>"); line = line.Replace("<tr style=\"height:110px;\">", "<tr>"); line = line.Replace("<tr style=\"height: 120px;\">", "<tr>"); line = line.Replace("<tr style=\"height:120px;\">", "<tr>"); line = line.Replace("<tr style=\"height: 10px\">", "<tr>"); line = line.Replace("<tr style=\"height:10px\">", "<tr>"); line = line.Replace("<tr style=\"height: 20px\">", "<tr>"); line = line.Replace("<tr style=\"height:20px\">", "<tr>"); line = line.Replace("<tr style=\"height: 30px\">", "<tr>"); line = line.Replace("<tr style=\"height:30px\">", "<tr>"); line = line.Replace("<tr style=\"height: 40px\">", "<tr>"); line = line.Replace("<tr style=\"height:40px\">", "<tr>"); line = line.Replace("<tr style=\"height: 50px\">", "<tr>"); line = line.Replace("<tr style=\"height:50px\">", "<tr>"); line = line.Replace("<tr style=\"height: 60px\">", "<tr>"); line = line.Replace("<tr style=\"height:60px\">", "<tr>"); line = line.Replace("<tr style=\"height: 70px\">", "<tr>"); line = line.Replace("<tr style=\"height:70px\">", "<tr>"); line = line.Replace("<tr style=\"height: 80px\">", "<tr>"); line = line.Replace("<tr style=\"height:80px\">", "<tr>"); line = line.Replace("<tr style=\"height: 90px\">", "<tr>"); line = line.Replace("<tr style=\"height:90px\">", "<tr>"); line = line.Replace("<tr style=\"height: 100px\">", "<tr>"); line = line.Replace("<tr style=\"height:100px\">", "<tr>"); line = line.Replace("<tr style=\"height: 110px\">", "<tr>"); line = line.Replace("<tr style=\"height:110px\">", "<tr>"); line = line.Replace("<tr style=\"height: 120px\">", "<tr>"); line = line.Replace("<tr style=\"height:120px\">", "<tr>"); } if (line.Contains("<th style=\"height:")) { line = line.Replace("<th style=\"height: 10px;\">", "<th>"); line = line.Replace("<th style=\"height:10px;\">", "<th>"); line = line.Replace("<th style=\"height: 20px;\">", "<th>"); line = line.Replace("<th style=\"height:20px;\">", "<th>"); line = line.Replace("<th style=\"height: 30px;\">", "<th>"); line = line.Replace("<th style=\"height:30px;\">", "<th>"); line = line.Replace("<th style=\"height: 40px;\">", "<th>"); line = line.Replace("<th style=\"height:40px;\">", "<th>"); line = line.Replace("<th style=\"height: 50px;\">", "<th>"); line = line.Replace("<th style=\"height:50px;\">", "<th>"); line = line.Replace("<th style=\"height: 60px;\">", "<th>"); line = line.Replace("<th style=\"height:60px;\">", "<th>"); line = line.Replace("<th style=\"height: 70px;\">", "<th>"); line = line.Replace("<th style=\"height:70px;\">", "<th>"); line = line.Replace("<th style=\"height: 80px;\">", "<th>"); line = line.Replace("<th style=\"height:80px;\">", "<th>"); line = line.Replace("<th style=\"height: 90px;\">", "<th>"); line = line.Replace("<th style=\"height:90px;\">", "<th>"); line = line.Replace("<th style=\"height: 100px;\">", "<th>"); line = line.Replace("<th style=\"height:100px;\">", "<th>"); line = line.Replace("<th style=\"height: 110px;\">", "<th>"); line = line.Replace("<th style=\"height:110px;\">", "<th>"); line = line.Replace("<th style=\"height: 120px;\">", "<th>"); line = line.Replace("<th style=\"height:120px;\">", "<th>"); line = line.Replace("<th style=\"height: 10px\">", "<th>"); line = line.Replace("<th style=\"height:10px\">", "<th>"); line = line.Replace("<th style=\"height: 20px\">", "<th>"); line = line.Replace("<th style=\"height:20px\">", "<th>"); line = line.Replace("<th style=\"height: 30px\">", "<th>"); line = line.Replace("<th style=\"height:30px\">", "<th>"); line = line.Replace("<th style=\"height: 40px\">", "<th>"); line = line.Replace("<th style=\"height:40px\">", "<th>"); line = line.Replace("<th style=\"height: 50px\">", "<th>"); line = line.Replace("<th style=\"height:50px\">", "<th>"); line = line.Replace("<th style=\"height: 60px\">", "<th>"); line = line.Replace("<th style=\"height:60px\">", "<th>"); line = line.Replace("<th style=\"height: 70px\">", "<th>"); line = line.Replace("<th style=\"height:70px\">", "<th>"); line = line.Replace("<th style=\"height: 80px\">", "<th>"); line = line.Replace("<th style=\"height:80px\">", "<th>"); line = line.Replace("<th style=\"height: 90px\">", "<th>"); line = line.Replace("<th style=\"height:90px\">", "<th>"); line = line.Replace("<th style=\"height: 100px\">", "<th>"); line = line.Replace("<th style=\"height:100px\">", "<th>"); line = line.Replace("<th style=\"height: 110px\">", "<th>"); line = line.Replace("<th style=\"height:110px\">", "<th>"); line = line.Replace("<th style=\"height: 120px\">", "<th>"); line = line.Replace("<th style=\"height:120px\">", "<th>"); } if (line.Contains("<td style=\"height:")) { line = line.Replace("<td style=\"height: 10px;\">", "<td>"); line = line.Replace("<td style=\"height:10px;\">", "<td>"); line = line.Replace("<td style=\"height: 20px;\">", "<td>"); line = line.Replace("<td style=\"height:20px;\">", "<td>"); line = line.Replace("<td style=\"height: 30px;\">", "<td>"); line = line.Replace("<td style=\"height:30px;\">", "<td>"); line = line.Replace("<td style=\"height: 40px;\">", "<td>"); line = line.Replace("<td style=\"height:40px;\">", "<td>"); line = line.Replace("<td style=\"height: 50px;\">", "<td>"); line = line.Replace("<td style=\"height:50px;\">", "<td>"); line = line.Replace("<td style=\"height: 60px;\">", "<td>"); line = line.Replace("<td style=\"height:60px;\">", "<td>"); line = line.Replace("<td style=\"height: 70px;\">", "<td>"); line = line.Replace("<td style=\"height:70px;\">", "<td>"); line = line.Replace("<td style=\"height: 80px;\">", "<td>"); line = line.Replace("<td style=\"height:80px;\">", "<td>"); line = line.Replace("<td style=\"height: 90px;\">", "<td>"); line = line.Replace("<td style=\"height:90px;\">", "<td>"); line = line.Replace("<td style=\"height: 100px;\">", "<td>"); line = line.Replace("<td style=\"height:100px;\">", "<td>"); line = line.Replace("<td style=\"height: 110px;\">", "<td>"); line = line.Replace("<td style=\"height:110px;\">", "<td>"); line = line.Replace("<td style=\"height: 120px;\">", "<td>"); line = line.Replace("<td style=\"height:120px;\">", "<td>"); line = line.Replace("<td style=\"height: 10px\">", "<td>"); line = line.Replace("<td style=\"height:10px\">", "<td>"); line = line.Replace("<td style=\"height: 20px\">", "<td>"); line = line.Replace("<td style=\"height:20px\">", "<td>"); line = line.Replace("<td style=\"height: 30px\">", "<td>"); line = line.Replace("<td style=\"height:30px\">", "<td>"); line = line.Replace("<td style=\"height: 40px\">", "<td>"); line = line.Replace("<td style=\"height:40px\">", "<td>"); line = line.Replace("<td style=\"height: 50px\">", "<td>"); line = line.Replace("<td style=\"height:50px\">", "<td>"); line = line.Replace("<td style=\"height: 60px\">", "<td>"); line = line.Replace("<td style=\"height:60px\">", "<td>"); line = line.Replace("<td style=\"height: 70px\">", "<td>"); line = line.Replace("<td style=\"height:70px\">", "<td>"); line = line.Replace("<td style=\"height: 80px\">", "<td>"); line = line.Replace("<td style=\"height:80px\">", "<td>"); line = line.Replace("<td style=\"height: 90px\">", "<td>"); line = line.Replace("<td style=\"height:90px\">", "<td>"); line = line.Replace("<td style=\"height: 100px\">", "<td>"); line = line.Replace("<td style=\"height:100px\">", "<td>"); line = line.Replace("<td style=\"height: 110px\">", "<td>"); line = line.Replace("<td style=\"height:110px\">", "<td>"); line = line.Replace("<td style=\"height: 120px\">", "<td>"); line = line.Replace("<td style=\"height:120px\">", "<td>"); } if (line.Contains("style=\"text-align:left") || line.Contains("style=\"text-align: left") || line.Contains("style= \"text-align:left") || line.Contains("style=\" text-align: left")) { line = line.Replace("style=\"text-align:left\"", ""); line = line.Replace("style=\"text-align: left\"", ""); line = line.Replace("style=\"text-align:left;\"", ""); line = line.Replace("style=\"text-align: left;\"", ""); line = line.Replace("style=\" text-align:left\"", ""); line = line.Replace("style=\" text-align: left\"", ""); line = line.Replace("style=\" text-align:left;\"", ""); line = line.Replace("style=\" text-align: left;\"", ""); line = line.Replace("style= \"text-align:left\"", ""); line = line.Replace("style= \"text-align: left\"", ""); line = line.Replace("style= \"text-align:left;\"", ""); line = line.Replace("style= \"text-align: left;\"", ""); } if (line.Contains("<td>") || line.Contains("<td >") || line.Contains("<td >")) { line = line.Replace("<td>", "<td style=\"text-align:center\">"); line = line.Replace("<td >", "<td style=\"text-align:center\">"); line = line.Replace("<td >", "<td style=\"text-align:center\">"); } if (line.Contains("<th>") || line.Contains("<th >") || line.Contains("<th >")) { line = line.Replace("<th>", "<th style=\"text-align:center\">"); line = line.Replace("<th >", "<th style=\"text-align:center\">"); line = line.Replace("<th >", "<th style=\"text-align:center\">"); } if (line.Contains("<h4") || line.Contains("< h4") && line.Contains("<br") || line.Contains("< br")) { line = line.Replace("<br/>", ""); line = line.Replace("< br/>", ""); line = line.Replace("<br/ >", ""); line = line.Replace("< br/ >", ""); line = line.Replace("<br />", ""); line = line.Replace("< br />", ""); line = line.Replace("<br / >", ""); line = line.Replace("< br / >", ""); line = line.Replace("< br/ >", ""); line = line.Replace("< br/ >", ""); } if (line.Contains("<table")) { line = line.Replace("<table", "<table border=\"1\""); } if (line.Contains("<ol>")) { line = line.Replace("<ol>", "<ol style=\"list-style-type:lower-alpha\">"); } if (line.Contains("<strong>note") || line.Contains("<strong>Note")) { listBox1.Items.Add("<br/><br/>"); } if (line.Contains("<strong>important") || line.Contains("<strong>Important")) { listBox1.Items.Add("<br/><br/>"); } if (line.Contains("<strong>result") || line.Contains("<strong>Result")) { listBox1.Items.Add("<br/><br/>"); } if (line.Contains("<h4>") || line.Contains("<h4 >")) { listBox1.Items.Add("</div>"); listBox1.Items.Add("<div class=\"content-box\">"); listBox1.Items.Add("<div class=\"information-box\">"); listBox1.Items.Add("<div class=\"meatball\"></div>"); } listBox1.Items.Add(line); if (line.Contains("</h4>") || line.Contains("</h4 >")) { string p = "</h4>"; int start = p.IndexOf("</h4>"); listBox1.Items.Add("</div>"); } } string look = listBox1.Items[0].ToString(); if (look.Contains("</div>") == false) { listBox1.Items.Insert(0, "</div>"); listBox1.Items.Insert(0, "<p>SUMMARY</p>"); listBox1.Items.Insert(0, "<div class=\"meatball\"></div>"); listBox1.Items.Insert(0, "<div class=\"information-box\">"); listBox1.Items.Insert(0, "<div class=\"content-box\">"); listBox1.Items.Insert(0, "<div id=\"general\">"); } if (look.Contains("</div>")) { listBox1.Items.Remove("</div>"); listBox1.Items.Insert(0, "<div id=\"general\">"); } listBox1.Items.Add("</div> </div>"); } } } else { Application.Restart(); } //####################### Save Attachment ########################################### string sPath = @"C:\Users\colin\Desktop\EditFile.txt"; System.IO.StreamWriter SaveFile = new System.IO.StreamWriter(sPath); foreach (var item in listBox1.Items) { SaveFile.WriteLine(item); } SaveFile.Close(); if (System.IO.File.Exists(@"C:\Users\colin\Desktop\File.txt")) { System.IO.File.Delete(@"C:\Users\colin\Desktop\File.txt"); } else { Application.Restart(); } //####################### Send Back Edited File ########################################### try { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("*****@*****.**"); mail.To.Add(sendBack); mail.Subject = returnSubject; mail.Body = "Have a Nice Day!!"; System.Net.Mail.Attachment newAttachment; newAttachment = new System.Net.Mail.Attachment(@"C:\Users\colin\Desktop\EditFile.txt"); mail.Attachments.Add(newAttachment); SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "caiken121"); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Used to construct the topmost message part /// </summary> /// <param name="rawBody">The body that needs to be parsed</param> /// <param name="headers">The headers that should be used from the message</param> /// <param name="parsingErrorHandler">(Optional) It is notifified when an error occurs while parsing something in the message. /// If it is not null, the handler handles the error on the specific element without stopping the message parsing process</param> /// <exception cref="ArgumentNullException">If <paramref name="rawBody"/> or <paramref name="headers"/> is <see langword="null"/></exception> internal MessagePart(byte[] rawBody, MessageHeader headers, IParsingErrorHandler parsingErrorHandler = null) { if(rawBody == null) throw new ArgumentNullException("rawBody"); if(headers == null) throw new ArgumentNullException("headers"); _parsingErrorHandler = parsingErrorHandler; ContentType = headers.ContentType; ContentDescription = headers.ContentDescription; ContentTransferEncoding = headers.ContentTransferEncoding; ContentId = headers.ContentId; ContentDisposition = headers.ContentDisposition; FileName = FindFileName(ContentType, ContentDisposition, "(no name)"); try { BodyEncoding = ParseBodyEncoding(ContentType.CharSet); } catch (FormatException ex) { BodyEncoding = Encoding.UTF8; if (_parsingErrorHandler != null) { _parsingErrorHandler.HandleParseError(new ParseError(ex, ContentType.CharSet, string.Format("On body encoding. Encoding set to {0}", BodyEncoding.EncodingName))); } else { throw; } } ParseBody(rawBody); }
private bool HeaderMatch(MessageHeader header) { return header != null && header.Subject != null && header.Subject.ToLower().Contains(matchSubjectMustContain) && header.From.HasValidMailAddress; }
public void TestNoKeywordsEmptyList() { NameValueCollection collection = new NameValueCollection(); MessageHeader header = new MessageHeader(collection); Assert.NotNull(header.Keywords); Assert.IsEmpty(header.Keywords); }
public void TestSubjectCorrectWhenThreadTopicIsIncluded() { NameValueCollection collection = new NameValueCollection(); // A real-life example included a Subject that was different than Thread-Topic collection.Add("Subject", "Foo"); collection.Add("Thread-Topic", "Bar"); MessageHeader header = new MessageHeader(collection); Assert.AreEqual("Foo", header.Subject); }
public void TestSingleKeyword() { NameValueCollection collection = new NameValueCollection(); collection.Add("Keywords", "test"); MessageHeader header = new MessageHeader(collection); Assert.AreEqual(1, header.Keywords.Count); Assert.AreEqual("test", header.Keywords[0]); }
public void TestInvalidParameterCharsetInContentDisposition() { string base64Header = "Content-Disposition: attachment; charset=windows-1251; filename=\"image.jpg\""; string expectedName = "image.jpg"; NameValueCollection col = HeaderExtractor.ExtractHeaders(base64Header); Assert.AreEqual(1, col.Count); MessageHeader header = new MessageHeader(col); Assert.IsNotNull(header.ContentDisposition); Assert.AreEqual(expectedName, header.ContentDisposition.FileName); }