/// <summary> /// /// </summary> /// <param name="FilePath"></param> /// <returns></returns> public Message ResolveMailByLSoft(String FilePath) { Message oMsg = new Message(); ADODB.Stream stm = null; try { stm = new ADODB.Stream(); stm.Open(System.Reflection.Missing.Value, ADODB.ConnectModeEnum.adModeUnknown, ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, "", ""); stm.Type = ADODB.StreamTypeEnum.adTypeBinary; //二进制方式读入 stm.LoadFromFile(FilePath); //将EML读入数据流 oMsg.DataSource.OpenObject(stm, "_stream"); //将EML数据流载入到CDO.Message,要做解析的话,后面就可以了。 } catch (IOException) { } finally { stm.Close(); } return(oMsg); }
/// <summary> /// 解析邮件文件为邮件对象 /// </summary> /// <param name="FilePath"></param> /// <returns></returns> public Message ResolveMailByLSoft(String FilePath) { Message oMsg = new Message(); ADODB.Stream stm = null; //读取EML文件到CDO.MESSAGE,做分析的话,实际是用了下面的部分 try { stm = new ADODB.Stream(); stm.Open(System.Reflection.Missing.Value, ADODB.ConnectModeEnum.adModeUnknown, ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, "", ""); stm.Type = ADODB.StreamTypeEnum.adTypeBinary;//二进制方式读入 stm.LoadFromFile(FilePath); //将EML读入数据流 oMsg.DataSource.OpenObject(stm, "_stream"); //将EML数据流载入到CDO.Message,要做解析的话,后面就可以了。 } catch (IOException) { } finally { stm.Close(); } return oMsg; }
protected CDO.Message ReadMessage(ADODB.Stream stream) { CDO.Message msg = new CDO.Message(); msg.DataSource.OpenObject(stream, "_Stream"); msg.DataSource.Save(); return(msg); }
/// <summary> /// Reads a string that is stored in a Object. /// </summary> /// <param name="variableName">The name under which the string is stored.</param> /// <returns>The value converted to string.</returns> public string ReadLongStringVariable(string variableName) { if (Dts.Variables[variableName].DataType.Equals(typeof(string))) { return(Dts.Variables[variableName].Value.ToString()); } OleDbDataAdapter da = new OleDbDataAdapter(); DataTable dt = new DataTable(); ADODB.Stream stm = new ADODB.Stream(); ADODB.Recordset rs = ((ADODB.Recordset)Dts.Variables[variableName].Value).Clone(); ADODB.Recordset rsCopy = new ADODB.Recordset(); rs.Save(stm); rsCopy.Open(stm); da.Fill(dt, rs); dt.Clear(); da.Fill(dt, rsCopy); if ( dt.Rows.Count > 0 && dt.Rows[0].ItemArray.Count() > 0 ) { return(dt.Rows[0].ItemArray[0].ToString()); } return(null); }
private void SaveBodyPart(ADODB.Stream aStream, string sFileName) { //Dim sr As StreamWriter //Dim sFileBody As String string sDataPath = "c:\\"; string sUseFilename = null; SaveFileDialog saveFileDialog1 = default(SaveFileDialog); saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.InitialDirectory = sDataPath; saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; saveFileDialog1.FilterIndex = 2; saveFileDialog1.RestoreDirectory = false; saveFileDialog1.FileName = sFileName; if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { sUseFilename = saveFileDialog1.FileName; saveFileDialog1 = null; try { Cursor = Cursors.WaitCursor; aStream.SaveToFile(sUseFilename); Cursor = Cursors.Default; } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Cannot write to file.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } }
static void Main(string[] args) { #region 获取包含所有日志链接的HTML文本 //string baseQueryUrl = "http://www.douban.com/people/oranjeruud/notes?start="; //for (int i = 0; i < 23; i++) //{ // string queryUrl = baseQueryUrl + (i * 10); // HttpWebRequest httpWebRequest = HttpWebRequest.CreateHttp(queryUrl); // httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95"; // HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();//取得响应 // if (httpWebResponse.StatusCode.Equals(HttpStatusCode.OK))//若响应状态码为200,说明成功,可以分析得到的数据 // { // StreamReader reader = new StreamReader(new BufferedStream(httpWebResponse.GetResponseStream(), 4 * 200 * 1024)); // GetBlogLink(reader.ReadToEnd()); // reader.Close(); // } // Thread.Sleep(3000); //} #endregion #region 根据获得的日志链接获取日志网页和mht文件 Message msg = new CDO.MessageClass(); CDO.Configuration c = new CDO.ConfigurationClass(); msg.Configuration = c; StreamReader reader = new StreamReader("links.txt"); int i = 0; while (!reader.EndOfStream) { i++; string link = reader.ReadLine(); HttpWebRequest httpWebRequest = HttpWebRequest.CreateHttp(link); httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95"; HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); //取得响应 if (httpWebResponse.StatusCode.Equals(HttpStatusCode.OK)) //若响应状态码为200,说明成功,可以分析得到的数据 { StreamReader httpReader = new StreamReader(new BufferedStream(httpWebResponse.GetResponseStream(), 4 * 200 * 1024)); string htmlContent = httpReader.ReadToEnd(); httpReader.Close(); string title = GetBlogTitle(htmlContent); #region 保存为html文件 StreamWriter writer = new StreamWriter(i + ".html"); writer.Write(htmlContent); writer.Close(); #endregion #region 保存为mht文件 //msg.HTMLBody = htmlContent; msg.CreateMHTMLBody(link, CDO.CdoMHTMLFlags.cdoSuppressNone, "", ""); ADODB.Stream stream = msg.GetStream(); stream.SaveToFile(title + ".mht", ADODB.SaveOptionsEnum.adSaveCreateOverWrite); #endregion } if (i == 1) { break; } } reader.Close(); #endregion }
protected CDO.Message ReadMessage(String emlFileName) { ADODB.Stream stream = new ADODB.Stream(); stream.Open(Type.Missing, ADODB.ConnectModeEnum.adModeUnknown, ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, String.Empty, String.Empty); stream.LoadFromFile(emlFileName); stream.Flush(); return(ReadMessage(stream)); }
public CDOMessageConverter(string mailContent) { cdoMessage = new CDO.Message(); ADODB.Stream adoStream = cdoMessage.GetStream(); adoStream.Type = ADODB.StreamTypeEnum.adTypeText; adoStream.WriteText(mailContent.Trim(), ADODB.StreamWriteEnum.adWriteLine); adoStream.Flush(); adoStream.Close(); }
protected CDO.Message ReadMessage(byte[] buffer) { ADODB.Stream stream = new ADODB.Stream(); stream.Type = ADODB.StreamTypeEnum.adTypeBinary; //stream.Open(Type.Missing, ADODB.ConnectModeEnum.adModeUnknown, ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, String.Empty, String.Empty); stream.Open(); stream.Write(buffer); stream.Flush(); return(ReadMessage(stream)); }
public static void SaveToMHT(string strOutputFile, string data) { string tmpFileName = string.Format("Export{0}.html", DateTime.Now.Ticks); string strPath = Path.GetTempPath(); if (!Directory.Exists(strPath)) { Directory.CreateDirectory(strPath); } string strFilePath = Path.Combine(strPath, tmpFileName); //Server.MapPath(string.Format("./{0}", m_tmpFile)); using (StreamWriter sw = File.CreateText(strFilePath)) { sw.Write(data); sw.Close(); } string url = "file://" + strFilePath; // GetBaseURL() + m_tmpFile; CDO.MessageClass message = new CDO.MessageClass(); ADODB.Stream stream = null; try { message.CreateMHTMLBody(url, CDO.CdoMHTMLFlags.cdoSuppressNone, "", ""); stream = message.GetStream(); stream.SaveToFile(strOutputFile, ADODB.SaveOptionsEnum.adSaveCreateOverWrite); } catch (Exception) { using (FileStream fs = File.Create(strOutputFile)) { using (BinaryWriter sw = new BinaryWriter(fs)) { sw.Write(new byte[] { 0xFF, 0xFE }); sw.Write(System.Text.Encoding.Unicode.GetBytes(data)); //.Unicode. strHTML.ToCharArray()); //Write(strHTML); sw.Close(); } } } finally { if (stream != null) { stream.Close(); } } if (File.Exists(strFilePath)) { File.Delete(strFilePath); } }
public byte[] GetAttachmentContentFromIdx(int idx) { var attachments = mail.Attachments.OfType <CDO.IBodyPart>(); var attachment = attachments.Skip(idx).FirstOrDefault(); ADODB.Stream stm = attachment.GetDecodedContentStream(); // cast to COM IStream and load into byte array var comStream = (System.Runtime.InteropServices.ComTypes.IStream)stm; byte[] attachmentData = new byte[stm.Size]; comStream.Read(attachmentData, stm.Size, IntPtr.Zero); stm.Close(); return(attachmentData); }
protected Message ReadMessage(String emlFileName) { Message msg = new Message(); Stream stream = new Stream(); stream.Open(Type.Missing, ADODB.ConnectModeEnum.adModeUnknown, ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, String.Empty, String.Empty); stream.LoadFromFile(emlFileName); stream.Flush(); msg.DataSource.OpenObject(stream, "_Stream"); msg.DataSource.Save(); return(msg); }
/// <summary> /// Sends the email MHTML. /// </summary> /// <param name="message">The message.</param> public virtual void SendMhtml(MailMessage message) { lock (_lock) try { var m = new CDO.Message(); // set message var s = new ADODB.Stream(); s.Charset = "ascii"; s.Open(); s.WriteText(message.Body); m.DataSource.OpenObject(s, "_Stream"); // set configuration var f = m.Configuration.Fields; switch (DeliveryMethod) { case SmtpDeliveryMethod.Network: f["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = CDO.CdoSendUsing.cdoSendUsingPort; f["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = Host; break; case SmtpDeliveryMethod.SpecifiedPickupDirectory: f["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = CDO.CdoSendUsing.cdoSendUsingPickup; f["http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory"].Value = PickupDirectoryLocation; break; default: throw new NotSupportedException(); } f.Update(); // set other values m.MimeFormatted = true; m.Subject = message.Subject; if (message.From != null) m.From = message.From.ToString(); var to = (message.To != null ? string.Join(",", message.To.Select(x => x.ToString()).ToArray()) : null); if (!string.IsNullOrEmpty(to)) m.To = to; var bcc = (message.Bcc != null ? string.Join(",", message.Bcc.Select(x => x.ToString()).ToArray()) : null); if (!string.IsNullOrEmpty(to)) m.BCC = bcc; var cc = (message.CC != null ? string.Join(",", message.CC.Select(x => x.ToString()).ToArray()) : null); if (!string.IsNullOrEmpty(to)) m.CC = cc; if (message.Attachments != null) foreach (var attachment in message.Attachments.Where(x => x != null)) AddAttachement(m, attachment, false); m.Send(); } catch (Exception ex) { throw ex; } }
/// <summary> /// 专门针对办公网的下载web方法 /// </summary> /// <param name="url">url是要保存的网页地址</param> /// <param name="filePath">filePath是保存到的文件路径</param> /// <returns></returns> public static bool SaveOaWebPageToMHTFile(string url, string filePath) { bool result = false; CDO.Message msg = new CDO.Message(); ADODB.Stream stm = null; msg.Configuration = new CDO.Configuration(); try { msg.MimeFormatted = true; msg.CreateMHTMLBody(url, CDO.CdoMHTMLFlags.cdoSuppressNone, "", ""); if (url.Substring(0, cConfig.strOaURL.Length) == cConfig.strOaURL) { stm = msg.GetStream(); stm.Charset = "GB2312"; using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write)) { string s = Regex.Replace(stm.ReadText(), "<img width=\\\"100%\\\" height=\\\"100\\\"(.[^>]*)>", "", RegexOptions.IgnoreCase); s = Regex.Replace(s, "<P(.[^>]*)>", "<P>", RegexOptions.IgnoreCase); s = Regex.Replace(s, "<a(.[^>]*)javascript:window.close(.[^>]*)><img src=(.[^>]*)>", "", RegexOptions.IgnoreCase); s = Regex.Replace(s, "<table width=\\\"98%\\\"(.[^>]*)>", "", RegexOptions.IgnoreCase); byte[] array = Encoding.Default.GetBytes(s); fs.Write(array, 0, array.Length); //fs.Close(); } stm.Close(); } else { msg.GetStream().SaveToFile(filePath, ADODB.SaveOptionsEnum.adSaveCreateOverWrite); } msg = null; result = true; } catch //(Exception ex) { } finally { //cleanup here } return(result); }
public static CDO.Message GetEmlFromFile(String emlFileName) { CDO.Message msg = new CDO.Message(); try { ADODB.Stream stream = new ADODB.Stream(); stream.Open(Type.Missing, ADODB.ConnectModeEnum.adModeUnknown, ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, String.Empty, String.Empty); stream.LoadFromFile(emlFileName); stream.Flush(); msg.DataSource.OpenObject(stream, "_Stream"); msg.DataSource.Save(); } catch { } return(msg); }
private void saveBodypartStreamToFileToolStripMenuItem_Click(object sender, EventArgs e) { if ((TreeView1.SelectedNode != null)) { CDO.IBodyPart aBP = default(CDO.IBodyPart); Cursor = Cursors.WaitCursor; aBP = (CDO.IBodyPart)TreeView1.SelectedNode.Tag; ADODB.Stream aStream = default(ADODB.Stream); string sFilename = null; bool bGotStream = false; aStream = new ADODB.Stream(); try { aStream = aBP.GetStream(); bGotStream = true; } catch (Exception ex) { MessageBox.Show("Error Extracting stream: " + ex.Message); } if (bGotStream == true) { sFilename = aBP.FileName; if (string.IsNullOrEmpty(sFilename)) { sFilename = "BodyPartStream (" + TreeView1.SelectedNode.Text + ").txt"; } else { sFilename = "BodyPartStream - " + sFilename; } Cursor = Cursors.WaitCursor; SaveBodyPart(aStream, sFilename); Cursor = Cursors.Default; } //Marshal.ReleaseComObject(aBP); //Marshal.ReleaseComObject(aStream); Cursor = Cursors.Default; } }
public static byte[] ToByteArray(this ADODB.Stream stream) { byte[] data; var tempSubFolderPath = TempSubfolder(); try { var tempFilePath = Path.Combine(tempSubFolderPath, "stream.tmp"); // ADODB cannot convert streams to .net byte arrays, but this works stream.SaveToFile(tempFilePath); data = File.ReadAllBytes(tempFilePath); } finally { new DirectoryInfo(tempSubFolderPath).Delete(recursive: true); } return(data); }
private void AddAttachement(CDO.Message m, Attachment attachment, bool allowUnicode) { // set message var s = new ADODB.Stream(); s.Charset = "UTF-8"; s.Open(); s.Type = ADODB.StreamTypeEnum.adTypeBinary; int bytesRead; var buffer = new byte[0x4400]; using (var acs = attachment.ContentStream) while ((bytesRead = acs.Read(buffer, 0, 0x4400)) > 0) { if (bytesRead == 0x4400) { s.Write(buffer); } else { Array.Resize(ref buffer, bytesRead); s.Write(buffer); break; } } s.Flush(); s.Position = 0; // var p = m.Attachments.Add(); p.ContentMediaType = attachment.ContentType.ToString(); p.ContentTransferEncoding = "base64"; var ds = p.GetDecodedContentStream(); s.CopyTo(ds); ds.Flush(); }
/// <summary> /// Read eml file into CDO message /// </summary> /// <param name="filepath">Path to eml file</param> /// <returns>CDO message</returns> private static CDO.Message ReadEml(string filepath) { var oMsg = new CDO.Message(); var stm = new ADODB.Stream(); stm.Open(System.Reflection.Missing.Value); stm.Type = ADODB.StreamTypeEnum.adTypeBinary; stm.LoadFromFile(filepath); oMsg.DataSource.OpenObject(stm, "_stream"); stm.Close(); return oMsg; }
public MailMessage ToMailMessage() { MailMessage message = new MailMessage(); if (!String.IsNullOrWhiteSpace(cdoMessage.From)) { message.From = new MailAddress(cdoMessage.From); } if (!String.IsNullOrWhiteSpace(cdoMessage.Sender)) { message.Sender = new MailAddress(cdoMessage.Sender); } message.Subject = cdoMessage.Subject; if (!String.IsNullOrWhiteSpace(cdoMessage.To)) { message.To.Add(cdoMessage.To); } if (!String.IsNullOrWhiteSpace(cdoMessage.CC)) { message.CC.Add(cdoMessage.CC); } if (!String.IsNullOrWhiteSpace(cdoMessage.BCC)) { message.Bcc.Add(cdoMessage.BCC); } if (String.IsNullOrWhiteSpace(cdoMessage.HTMLBody)) { message.Body = cdoMessage.TextBody; } else { message.Body = cdoMessage.HTMLBody; message.IsBodyHtml = true; } if (!String.IsNullOrWhiteSpace(cdoMessage.ReplyTo)) { message.ReplyToList.Add(cdoMessage.ReplyTo); } foreach (CDO.IBodyPart bodyPart in cdoMessage.Attachments) { ADODB.Stream stream = bodyPart.GetDecodedContentStream(); IStream comStream = stream as IStream; byte[] bytes = new byte[stream.Size]; ulong bytesRead = 0; var handle = GCHandle.Alloc(bytesRead, GCHandleType.Pinned); IntPtr pcbRead = handle.AddrOfPinnedObject(); comStream.Read(bytes, stream.Size, pcbRead); handle.Free(); using (MemoryStream memoryStream = new MemoryStream(bytes)) { message.Attachments.Add(new Attachment(memoryStream, bodyPart.FileName)); } } foreach (ADODB.Field field in cdoMessage.Fields) { if (field.Type == ADODB.DataTypeEnum.adBSTR || field.Type == ADODB.DataTypeEnum.adDate) { string key = field.Name.Split(':').Last(); string value = field.Value.ToString(); if (key != null && value != null) { message.Headers.Add(key, value); } } } return(message); }
/// <summary> /// Sends the email MHTML. /// </summary> /// <param name="message">The message.</param> public virtual void SendMhtml(MailMessage message) { lock (_lock) try { var m = new CDO.Message(); // set message var s = new ADODB.Stream(); s.Charset = "ascii"; s.Open(); s.WriteText(message.Body); m.DataSource.OpenObject(s, "_Stream"); // set configuration var f = m.Configuration.Fields; switch (DeliveryMethod) { case SmtpDeliveryMethod.Network: f["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = CDO.CdoSendUsing.cdoSendUsingPort; f["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = Host; break; case SmtpDeliveryMethod.SpecifiedPickupDirectory: f["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = CDO.CdoSendUsing.cdoSendUsingPickup; f["http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory"].Value = PickupDirectoryLocation; break; default: throw new NotSupportedException(); } f.Update(); // set other values m.MimeFormatted = true; m.Subject = message.Subject; if (message.From != null) { m.From = message.From.ToString(); } var to = (message.To != null ? string.Join(",", message.To.Select(x => x.ToString()).ToArray()) : null); if (!string.IsNullOrEmpty(to)) { m.To = to; } var bcc = (message.Bcc != null ? string.Join(",", message.Bcc.Select(x => x.ToString()).ToArray()) : null); if (!string.IsNullOrEmpty(to)) { m.BCC = bcc; } var cc = (message.CC != null ? string.Join(",", message.CC.Select(x => x.ToString()).ToArray()) : null); if (!string.IsNullOrEmpty(to)) { m.CC = cc; } if (message.Attachments != null) { foreach (var attachment in message.Attachments.Where(x => x != null)) { AddAttachement(m, attachment, false); } } m.Send(); } catch (Exception ex) { throw ex; } }
private void AddAttachement(CDO.Message m, Attachment attachment, bool allowUnicode) { // set message var s = new ADODB.Stream(); s.Charset = "UTF-8"; s.Open(); s.Type = ADODB.StreamTypeEnum.adTypeBinary; int bytesRead; var buffer = new byte[0x4400]; using (var acs = attachment.ContentStream) while ((bytesRead = acs.Read(buffer, 0, 0x4400)) > 0) if (bytesRead == 0x4400) s.Write(buffer); else { Array.Resize(ref buffer, bytesRead); s.Write(buffer); break; } s.Flush(); s.Position = 0; // var p = m.Attachments.Add(); p.ContentMediaType = attachment.ContentType.ToString(); p.ContentTransferEncoding = "base64"; var ds = p.GetDecodedContentStream(); s.CopyTo(ds); ds.Flush(); }
private bool LoadMessage(string sLoadType, string sMessage) { ADODB.Stream objMsgStream = new ADODB.Stream(); string sFileName = ""; objCDOMsg = null; objCDOMsg = new CDO.Message(); bLoaded = false; try { this.Cursor = Cursors.WaitCursor; // First Get the Raw Mime and display it. string sFileText = null; if (sLoadType == "file") { //MyApp.AppUtil xObj = new MyApp.AppUtil(); sFileName = txtFileName.Text.Trim(); sFileText = UserIoHelper.GetFileAsString(sFileName); txtMime.Text = sFileText; // Now Lets read this thing objMsgStream.Open(); objMsgStream.LoadFromFile(sFileName); objCDOMsg.BodyPart.DataSource.OpenObject(objMsgStream, "IStream"); m_MessageMime = sFileText; } else { sFileName = Path.GetTempFileName(); txtMime.Text = sMessage; UserIoHelper.SaveStringAsFile(sMessage, sFileName); // Ran into problems writing mime text to a message, working around by using a temp file objMsgStream.Open(); objMsgStream.LoadFromFile(sFileName); // Read temp file objCDOMsg.BodyPart.DataSource.OpenObject(objMsgStream, "IStream"); // read it File.Delete(sFileName); // Get rid of temp file m_MessageMime = sMessage; } LoadMessageFields(); //LoadAttachemntsFields(); ExtractBodyPart(objCDOMsg.BodyPart); //Marshal.ReleaseComObject(objMsgStream); } catch (Exception ex) { bLoaded = false; MessageBox.Show("Error Loading File: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } try { System.Windows.Forms.TreeNode pNode = new System.Windows.Forms.TreeNode(); TreeView1.Nodes.Clear(); pNode = TreeView1.Nodes.Add("Root"); // m_BaseURI pNode.Tag = objCDOMsg.BodyPart; int iBodyPartCount1 = 1; int iBodyPartCount2 = 1; int iBodyPartCount3 = 1; int iBodyPartCount4 = 1; int iBodyPartCount5 = 1; int iBodyPartCount6 = 1; int iBodyPartCount7 = 1; System.Windows.Forms.TreeNode aNode1 = null; System.Windows.Forms.TreeNode aNode2 = null; System.Windows.Forms.TreeNode aNode3 = null; System.Windows.Forms.TreeNode aNode4 = null; System.Windows.Forms.TreeNode aNode5 = null; System.Windows.Forms.TreeNode aNode6 = null; System.Windows.Forms.TreeNode aNode7 = null; iBodyPartCount1 = 1; // Note: I'm using this big loop because i want to be able to see things better // as this code loops through each body part. Using a recursive call to a method // just makes the debugging process more difficult. foreach (CDO.IBodyPart objBodypart1 in objCDOMsg.BodyPart.BodyParts) { AddNode(objBodypart1, ref pNode, ref aNode1, iBodyPartCount1); iBodyPartCount2 = 1; foreach (CDO.IBodyPart objBodypart2 in objBodypart1.BodyParts) { AddNode(objBodypart2, ref aNode1, ref aNode2, iBodyPartCount2); iBodyPartCount3 = 1; foreach (CDO.IBodyPart objBodypart3 in objBodypart2.BodyParts) { AddNode(objBodypart3, ref aNode2, ref aNode3, iBodyPartCount3); iBodyPartCount4 = 1; foreach (CDO.IBodyPart objBodypart4 in objBodypart3.BodyParts) { AddNode(objBodypart4, ref aNode3, ref aNode4, iBodyPartCount4); iBodyPartCount5 = 1; foreach (CDO.IBodyPart objBodypart5 in objBodypart4.BodyParts) { AddNode(objBodypart5, ref aNode4, ref aNode5, iBodyPartCount5); iBodyPartCount6 = 1; foreach (CDO.IBodyPart objBodypart6 in objBodypart5.BodyParts) { AddNode(objBodypart6, ref aNode5, ref aNode6, iBodyPartCount6); iBodyPartCount7 = 1; foreach (CDO.IBodyPart objBodypart7 in objBodypart6.BodyParts) { AddNode(objBodypart7, ref aNode6, ref aNode7, iBodyPartCount7); iBodyPartCount7 += 1; //Marshal.ReleaseComObject(objBodypart7); } iBodyPartCount6 += 1; // Marshal.ReleaseComObject(objBodypart6); } iBodyPartCount5 += 1; //Marshal.ReleaseComObject(objBodypart5); } iBodyPartCount4 += 1; //Marshal.ReleaseComObject(objBodypart4); } iBodyPartCount3 += 1; // Marshal.ReleaseComObject(objBodypart3); } iBodyPartCount2 += 1; //Marshal.ReleaseComObject(objBodypart2); } iBodyPartCount1 += 1; //Marshal.ReleaseComObject(objBodypart1); } pNode.ExpandAll(); bLoaded = true; } catch (Exception ex) { bLoaded = false; MessageBox.Show("Error Loading Message Body Parts: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } objMsgStream = null; Cursor = Cursors.Default; return(bLoaded); }
//LoadMessageEnvelopeFields() //lvAttachments // private void LoadAttachemntsFields() //{ // ListViewItem aListItem = default(ListViewItem); // lvAttachments.Items.Clear(); // lvAttachments.View = View.Details; // // Set the view to show details. // lvAttachments.GridLines = true; // // Display grid lines. // //Dim sValue As String // foreach (CDO.IBodyPart iBP in objCDOMsg.Attachments) // { // aListItem = new ListViewItem(iBP.FileName); // if (iBP.ContentMediaType != null) { // aListItem.SubItems.Add(iBP.ContentMediaType); // } else { // aListItem.SubItems.Add(""); // } // if (iBP.ContentTransferEncoding != null) { // aListItem.SubItems.Add(iBP.ContentTransferEncoding); // } else { // aListItem.SubItems.Add(""); // } // if (iBP.Charset != null) { // aListItem.SubItems.Add(iBP.Charset); // } else { // aListItem.SubItems.Add(""); // } // if (iBP.ContentClass != null) { // aListItem.SubItems.Add(iBP.ContentClass); // } else { // aListItem.SubItems.Add(""); // } // if (iBP.ContentClass != null) { // aListItem.SubItems.Add(iBP.ContentClassName); // } else { // aListItem.SubItems.Add(""); // } // lvAttachments.Items.AddRange(new ListViewItem[] { aListItem }); // aListItem = null; // // Marshal.ReleaseComObject(iBP); // } //} private void ExtractBodyPart(CDO.IBodyPart iBP) { string sText = null; ADODB.Stream aStream = default(ADODB.Stream); string sWebView = string.Empty; try { if (iBP.FileName.Trim().Length != 0) { //aStream = iBP.GetEncodedContentStream(); string sFoldePath = Path.GetTempPath(); string sFileName = iBP.FileName; string sFile = Path.Combine(sFoldePath, sFileName); iBP.SaveToFile(sFile); this.wbView.Navigate(sFile); } else { string sExtension = string.Empty; if (iBP.ContentMediaType == "text/html") { sExtension = "html"; } if (iBP.ContentMediaType == "text/plain") { sExtension = "txt"; } if (iBP.ContentMediaType == "text/xml") { sExtension = "xml"; } if (sExtension != string.Empty) { aStream = iBP.GetDecodedContentStream(); string sFoldePath = Path.GetTempPath(); string sFileName = Path.GetRandomFileName(); if (sExtension != string.Empty) { sFileName += ("." + sExtension); } string sFile = Path.Combine(sFoldePath, sFileName); aStream.SaveToFile(sFile); //SaveBodyPart(aStream, sFile); this.wbView.Navigate(sFile); } else { this.wbView.DocumentText = ""; } } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Error bulding view for Browser view.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } // Get Encoded Stream try { aStream = iBP.GetEncodedContentStream(); sText = aStream.ReadText(); aStream.Close(); txtEncoded.Text = sText; txtStream.BackColor = Color.White; // Marshal.ReleaseComObject(aStream); } catch (Exception ex) { string x = ex.Message.ToString(); txtEncoded.Text = ""; txtStream.BackColor = Color.Gray; } // Get Decoded Stream try { aStream = iBP.GetDecodedContentStream(); sText = aStream.ReadText(); aStream.Close(); txtDecoded.Text = sText; txtStream.BackColor = Color.White; // Marshal.ReleaseComObject(aStream); } catch (Exception ex) { string x = ex.Message.ToString(); txtDecoded.Text = ""; txtStream.BackColor = Color.Gray; } // Get Stream try { aStream = iBP.GetStream(); sText = aStream.ReadText(); aStream.Close(); txtStream.Text = sText; txtStream.BackColor = Color.White; //Marshal.ReleaseComObject(aStream); } catch (Exception ex) { string x = ex.Message.ToString(); txtStream.Text = ""; txtStream.BackColor = Color.Gray; } ListViewItem aListItem = default(ListViewItem); ListView1.Items.Clear(); ListView1.View = View.Details; // Set the view to show details. ListView1.GridLines = true; // Display grid lines. string sValue = null; // Extract Bodypart Fields foreach (ADODB.Field objField in iBP.Fields) { aListItem = new ListViewItem(objField.Name); //aListItem.Tag = anInstance.href try { sValue = objField.ToString(); sValue = objField.Value as string; aListItem.SubItems.Add(sValue); } catch (Exception ex) { string x = ex.Message.ToString(); sValue = "(Cannot Extract - may not be set)"; aListItem.SubItems.Add(sValue); } ListView1.Items.AddRange(new ListViewItem[] { aListItem }); aListItem = null; //Marshal.ReleaseComObject(objField); } // ---- Body Part Properties -------------------------------- ListView2.Items.Clear(); ListView2.View = View.Details; // Set the view to show details. ListView2.GridLines = true; // Display grid lines. if (iBP.Charset != null) { AddLvItem(ref ListView2, "Charset", iBP.Charset); } if (iBP.ContentClass != null) { AddLvItem(ref ListView2, "ContentClass", iBP.ContentClass); } if (iBP.ContentMediaType != null) { AddLvItem(ref ListView2, "ContentMediaType", iBP.ContentMediaType); } if (iBP.ContentTransferEncoding != null) { AddLvItem(ref ListView2, "ContentTransferEncoding", iBP.ContentTransferEncoding); } if (iBP.FileName != null) { AddLvItem(ref ListView2, "FileName", iBP.FileName); } AddLvItem(ref ListView2, "BodyParts.Count", iBP.BodyParts.Count); aStream = null; }