internal MimePartCollection ConcatMessagesAsPart(MessageCollection input) { MimePartCollection output = new MimePartCollection(); foreach(MimePart part in this) output.Add(part); foreach(Message message in input) output.Add(message.ToMimePart()); return output; }
public static void Main() { ServiceDescription myServiceDescription = ServiceDescription.Read("MimePartCollection_1_Input_cs.wsdl"); ServiceDescriptionCollection myServiceDescriptionCol = new ServiceDescriptionCollection(); myServiceDescriptionCol.Add(myServiceDescription); XmlQualifiedName myXmlQualifiedName = new XmlQualifiedName("MimeServiceHttpPost", "http://tempuri.org/"); // Create a 'Binding' object. Binding myBinding = myServiceDescriptionCol.GetBinding(myXmlQualifiedName); OperationBinding myOperationBinding = null; for (int i = 0; i < myBinding.Operations.Count; i++) { if (myBinding.Operations[i].Name.Equals("AddNumbers")) { myOperationBinding = myBinding.Operations[i]; } } OutputBinding myOutputBinding = myOperationBinding.Output; MimeMultipartRelatedBinding myMimeMultipartRelatedBinding = null; IEnumerator myIEnumerator = myOutputBinding.Extensions.GetEnumerator(); while (myIEnumerator.MoveNext()) { myMimeMultipartRelatedBinding = (MimeMultipartRelatedBinding)myIEnumerator.Current; } // Create an instances of 'MimePartCollection'. MimePartCollection myMimePartCollection = new MimePartCollection(); myMimePartCollection = myMimeMultipartRelatedBinding.Parts; Console.WriteLine("Total number of mimepart elements initially is: " + myMimePartCollection.Count); // Create an instance of 'MimePart'. MimePart myMimePart = new MimePart(); // Create an instance of 'MimeXmlBinding'. MimeXmlBinding myMimeXmlBinding = new MimeXmlBinding(); myMimeXmlBinding.Part = "body"; myMimePart.Extensions.Add(myMimeXmlBinding); // Insert a mimepart at first position. myMimePartCollection.Insert(0, myMimePart); Console.WriteLine("Inserting a mimepart object..."); if (myMimePartCollection.Contains(myMimePart)) { Console.WriteLine("'MimePart' is succesffully added at position: " + myMimePartCollection.IndexOf(myMimePart)); Console.WriteLine("Total number of mimepart elements after inserting is: " + myMimePartCollection.Count); } myServiceDescription.Write("MimePartCollection_1_Output_CS.wsdl"); Console.WriteLine("MimePartCollection_1_Output_CS.wsdl has been generated successfully."); }
/// <summary> /// Allows the developer to add a collection of MimePart objects in another one. /// </summary> /// <param name="first">The first collection.</param> /// <param name="second">The second collection.</param> /// <returns>The concatened collection.</returns> public static MimePartCollection operator +(MimePartCollection first, MimePartCollection second) { MimePartCollection newParts = first; foreach (MimePart part in second) { newParts.Add(part); } return(newParts); }
protected void ButtonDownload_Click(object sender, EventArgs e) { String[] contextId = Request.QueryString.GetValues("context"); String[] sourceEnt = Request.QueryString.GetValues("source"); String[] destEnt = Request.QueryString.GetValues("destination"); DataTable dt = new DataTable(); dt.Columns.Add("attachment"); POP3 pop3Client = (POP3)Session[SessionFactory.POP3_CLIENT_OBJECT]; pop3Client = getPop3Connection(); //if (!pop3Client.IsConnected) //pop3Client.Connect(); MimeMessage msg = pop3Client.GetMessage(int.Parse(LabelSelectedGridItem.Text.ToString()) - 1); MimePartCollection mimeCollc = msg.MimeParts; String attachmentName = ""; String downloadReadyMsg = contextId[0] + "-" + sourceEnt[0] + "-" + destEnt[0] + "-" + SessionFactory.ALL_COMM_DOWNLOADABLE_MSG; Session[downloadReadyMsg] = msg; /*for (int i = 0; i < mimeCollc.Count; i++) * { * if (mimeCollc[i].IsAttachment()) * attachmentName += attachmentName.Equals("") ? mimeCollc[i].AttachmentName() : "," + mimeCollc[i].AttachmentName(); * }*/ attachmentName = LabelAttachList.Text; String[] attachmentNameArray = attachmentName.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (attachmentNameArray.Length == 1) { DownloadAttachment(msg, attachmentName); } else { for (int i = 0; i < attachmentNameArray.Length; i++) { dt.Rows.Add(); dt.Rows[i]["attachment"] = attachmentNameArray[i]; } PanelDownload.Visible = true; GridView_Attachment.Visible = true; GridView_Attachment.DataSource = dt; GridView_Attachment.DataBind(); } }
internal MimePartCollection ConcatMessagesAsPart(MessageCollection input) { MimePartCollection output = new MimePartCollection(); foreach (MimePart part in this) { output.Add(part); } foreach (Message message in input) { output.Add(message.ToMimePart()); } return(output); }
static void Main() { // <Snippet2> ServiceDescription myServicDescription = ServiceDescription.Read("MimeMultiPartRelatedSample_cs.wsdl"); // Get the binding collection. BindingCollection myBindingCollection = myServicDescription.Bindings; int index = 0; for (int i = 0; i < myBindingCollection.Count; i++) { // Get the collection for MimeServiceHttpPost. if (myBindingCollection[i].Name == "MimeServiceHttpPost") { OperationBindingCollection myOperationBindingCollection = myBindingCollection[i].Operations; OutputBinding myOutputBinding = myOperationBindingCollection[0].Output; ServiceDescriptionFormatExtensionCollection myServiceDescriptionFormatExtensionCollection = myOutputBinding.Extensions; MimeMultipartRelatedBinding myMimeMultipartRelatedBinding = (MimeMultipartRelatedBinding) myServiceDescriptionFormatExtensionCollection.Find( typeof(MimeMultipartRelatedBinding)); MimePartCollection myMimePartCollection = myMimeMultipartRelatedBinding.Parts; foreach (MimePart myMimePart in myMimePartCollection) { Console.WriteLine("Extension types added to MimePart: " + index++); Console.WriteLine("----------------------------"); foreach (object myExtension in myMimePart.Extensions) { Console.WriteLine(myExtension.GetType()); } Console.WriteLine(); } break; } } // </Snippet2> }
public static void Main() { ServiceDescription myServiceDescription = ServiceDescription.Read("MimePartCollection_8_Input_cs.wsdl"); ServiceDescriptionCollection myServiceDescriptionCol = new ServiceDescriptionCollection(); myServiceDescriptionCol.Add(myServiceDescription); XmlQualifiedName myXmlQualifiedName = new XmlQualifiedName("MimeServiceHttpPost", "http://tempuri.org/"); // Create a binding object. Binding myBinding = myServiceDescriptionCol.GetBinding(myXmlQualifiedName); OperationBinding myOperationBinding = null; for (int i = 0; i < myBinding.Operations.Count; i++) { if (myBinding.Operations[i].Name.Equals("AddNumbers")) { myOperationBinding = myBinding.Operations[i]; } } OutputBinding myOutputBinding = myOperationBinding.Output; // <Snippet1> // <Snippet2> // <Snippet3> // <Snippet4> MimeMultipartRelatedBinding myMimeMultipartRelatedBinding = null; IEnumerator myIEnumerator = myOutputBinding.Extensions.GetEnumerator(); while (myIEnumerator.MoveNext()) { myMimeMultipartRelatedBinding = (MimeMultipartRelatedBinding)myIEnumerator.Current; } // Create an instance of 'MimePartCollection'. MimePartCollection myMimePartCollection = new MimePartCollection(); myMimePartCollection = myMimeMultipartRelatedBinding.Parts; Console.WriteLine("Total number of mimepart elements in the collection initially" + " is: " + myMimePartCollection.Count); // Get the type of first 'Item' in collection. Console.WriteLine("The first object in collection is of type: " + myMimePartCollection[0].ToString()); MimePart myMimePart1 = new MimePart(); // Create an instance of 'MimeXmlBinding'. MimeXmlBinding myMimeXmlBinding1 = new MimeXmlBinding(); myMimeXmlBinding1.Part = "body"; myMimePart1.Extensions.Add(myMimeXmlBinding1); // a mimepart at first position. myMimePartCollection.Insert(0, myMimePart1); Console.WriteLine("Inserting a mimepart object..."); // Check whether 'Insert' was successful or not. if (myMimePartCollection.Contains(myMimePart1)) { // Display the index of inserted 'MimePart'. Console.WriteLine("'MimePart' is succesfully inserted at position: " + myMimePartCollection.IndexOf(myMimePart1)); } // </Snippet4> // </Snippet3> // </Snippet2> // </Snippet1> Console.WriteLine("Total number of mimepart elements after inserting is: " + myMimePartCollection.Count); // <Snippet5> // <Snippet6> MimePart myMimePart2 = new MimePart(); MimeXmlBinding myMimeXmlBinding2 = new MimeXmlBinding(); myMimeXmlBinding2.Part = "body"; myMimePart2.Extensions.Add(myMimeXmlBinding2); // Add a mimepart to the mimepartcollection. myMimePartCollection.Add(myMimePart2); Console.WriteLine("Adding a mimepart object..."); // Check if collection contains added mimepart object. if (myMimePartCollection.Contains(myMimePart2)) { Console.WriteLine("'MimePart' is succesfully added at position: " + myMimePartCollection.IndexOf(myMimePart2)); } // </Snippet6> // </Snippet5> Console.WriteLine("Total number of mimepart elements after adding is: " + myMimePartCollection.Count); // <Snippet7> MimePart[] myArray = new MimePart[myMimePartCollection.Count]; // Copy the mimepartcollection to an array. myMimePartCollection.CopyTo(myArray, 0); Console.WriteLine("Displaying the array copied from mimepartcollection"); for (int j = 0; j < myMimePartCollection.Count; j++) { Console.WriteLine("Mimepart object at position : " + j); for (int i = 0; i < myArray[j].Extensions.Count; i++) { MimeXmlBinding myMimeXmlBinding3 = (MimeXmlBinding)myArray[j].Extensions[i]; Console.WriteLine("Part: " + (myMimeXmlBinding3.Part)); } } // </Snippet7> // <Snippet8> Console.WriteLine("Removing a mimepart object..."); // Remove the mimepart from the mimepartcollection. myMimePartCollection.Remove(myMimePart1); // Check whether the mimepart is removed or not. if (!myMimePartCollection.Contains(myMimePart1)) { Console.WriteLine("Mimepart is succesfully removed from mimepartcollection"); } // </Snippet8> Console.WriteLine("Total number of elements in collection after removing is: " + myMimePartCollection.Count); MimePart[] myArray1 = new MimePart[myMimePartCollection.Count]; myMimePartCollection.CopyTo(myArray1, 0); Console.WriteLine("Dispalying the 'MimePartCollection' after removing"); for (int j = 0; j < myMimePartCollection.Count; j++) { Console.WriteLine("Mimepart object at position :" + j); for (int i = 0; i < myArray1[j].Extensions.Count; i++) { MimeXmlBinding myMimeXmlBinding3 = (MimeXmlBinding)myArray1[j].Extensions[i]; Console.WriteLine("part: " + (myMimeXmlBinding3.Part)); } } myServiceDescription.Write("MimePartCollection_8_output.wsdl"); Console.WriteLine("MimePartCollection_8_output.wsdl has been generated successfully."); }
protected void LinkButton_Subject_Command1(object sender, CommandEventArgs e) { try { GridView_Email.SelectedIndex = int.Parse(e.CommandArgument.ToString()); LabelSelectedGridItem.Text = ((Label)GridView_Email.Rows[int.Parse(e.CommandArgument.ToString())].Cells[0].FindControl("Label_Hidden")).Text; POP3 pop3Client = (POP3)Session[SessionFactory.POP3_CLIENT_OBJECT]; String[] contextId = Request.QueryString.GetValues("context"); String[] sourceEnt = Request.QueryString.GetValues("source"); String[] destEnt = Request.QueryString.GetValues("destination"); String cacheKey = contextId[0] + "-" + sourceEnt[0] + "-" + destEnt[0]; String index = ((Label)GridView_Email.Rows[int.Parse(e.CommandArgument.ToString())].Cells[0].FindControl("Label_Hidden")).Text; if (((Dictionary <String, String>)Cache.Get(cacheKey + "-" + "msg")).ContainsKey((float.Parse(index) - 1).ToString())) { TextBox_MsgBody.Text = ((Dictionary <String, String>)Cache.Get(cacheKey + "-" + "msg"))[(float.Parse(index) - 1).ToString()]; LabelAttachList.Text = ((Dictionary <String, String>)Cache.Get(cacheKey + "-" + "attach"))[(float.Parse(index) - 1).ToString()]; } else { //Message not in cache..pull from server if (!pop3Client.IsConnected) { pop3Client.Connect(); Session[SessionFactory.POP3_CLIENT_OBJECT] = pop3Client; } MimeMessage msg = pop3Client.GetMessage(int.Parse(index) - 1); Dictionary <String, String> cacheMsgDict = (Dictionary <String, String>)Cache.Get(cacheKey + "-" + "msg"); Dictionary <String, String> cacheAttachDict = (Dictionary <String, String>)Cache.Get(cacheKey + "-" + "attach"); String messageText = msg.TextMimePart.ToString(); String attachmentName = ""; MimePartCollection mimePartCollc = msg.MimeParts; for (int j = 0; j < mimePartCollc.Count; j++) { if (mimePartCollc[j].IsAttachment()) { attachmentName = attachmentName.Equals("") ? mimePartCollc[j].AttachmentName() : attachmentName + "," + mimePartCollc[j].AttachmentName(); } } cacheMsgDict.Add((int.Parse(index) - 1).ToString(), messageText); cacheAttachDict.Add((int.Parse(index) - 1).ToString(), attachmentName); Cache.Insert(cacheKey + "-" + "msg", cacheMsgDict); Cache.Insert(cacheKey + "-" + "attach", cacheAttachDict); TextBox_MsgBody.ForeColor = System.Drawing.Color.Black; TextBox_MsgBody.Text = messageText; LabelAttachList.Text = attachmentName; } } catch (Exception ex) { TextBox_MsgBody.Text = "Error Retrieving Message Content"; TextBox_MsgBody.ForeColor = System.Drawing.Color.Red; } }
protected void ReceiveMails() { POP3 pop3Client = getPop3Connection(); int msgCount = pop3Client.MessageCount(); String[] contextId = Request.QueryString.GetValues("context"); String[] sourceEnt = Request.QueryString.GetValues("source"); String[] destEnt = Request.QueryString.GetValues("destination"); String cacheKey = contextId[0] + "-" + sourceEnt[0] + "-" + destEnt[0]; Dictionary <String, String> cacheMsgDict = new Dictionary <String, String>(); Dictionary <String, String> cacheAttachDict = new Dictionary <String, String>(); DataTable dt = new DataTable(); DataTable dtSession = (DataTable)Session[cacheKey]; Dictionary <String, String> refreshCheck = new Dictionary <String, String>(); dt.Columns.Add("Hidden"); dt.Columns.Add("Sender"); dt.Columns.Add("RecvDate"); dt.Columns.Add("Subject"); int msgCounter = 0; for (int i = msgCount; i > (msgCount - GridView_Email.PageSize); i--) { // if (((Dictionary<String, String>)Cache.Get(cacheKey + "-" + "msg") ==null||((Dictionary<String, String>)Cache.Get(cacheKey + "-" + "msg")).Count==0) // || !((Dictionary<String, String>)Cache.Get(cacheKey + "-" + "msg")).ContainsKey((i - 1).ToString())) // { MimeMessage msg = pop3Client.GetMessage(i - 1); if (i > (msgCount - 1)) { Boolean messageInCache = false; if (((Dictionary <String, String>)Cache.Get(cacheKey + "-" + "msg")) != null && ((Dictionary <String, String>)Cache.Get(cacheKey + "-" + "msg")).ContainsKey((i - 1).ToString())) { messageInCache = true; } if (!messageInCache) { MimePartCollection allMimeParts = msg.MimeParts; String messageText = ""; String attachmentName = ""; if (msg.TextMimePart != null) { messageText += msg.TextMimePart.ToString(); } else { messageText = ""; } if (i == msgCount) { TextBox_MsgBody.Text = msg.TextMimePart.ToString(); } //MessagBodyHTML.InnerHtml = msg.TextMimePart.ToString(); for (int j = 0; j < allMimeParts.Count; j++) { if (allMimeParts[j].IsAttachment()) { if (i == msgCount) { LabelAttachList.Text += LabelAttachList.Text.Equals("") ? allMimeParts[j].AttachmentName() : "," + allMimeParts[j].AttachmentName(); } attachmentName += attachmentName.Equals("") ? allMimeParts[j].AttachmentName() : "," + allMimeParts[j].AttachmentName(); } } cacheMsgDict.Add((i - 1).ToString(), messageText); cacheAttachDict.Add((i - 1).ToString(), attachmentName); } } if (msg != null) { dt.Rows.Add(); dt.Rows[msgCounter]["Hidden"] = i.ToString(); dt.Rows[msgCounter]["Sender"] = msg.From.EmailAddress; dt.Rows[msgCounter]["RecvDate"] = msg.ReceivedDate().Date; dt.Rows[msgCounter]["Subject"] = msg.Subject.ToString(); refreshCheck.Add(i.ToString(), i.ToString()); msgCounter++; } } Cache.Insert(cacheKey + "-" + "msg", cacheMsgDict); Cache.Insert(cacheKey + "-" + "attach", cacheAttachDict); Cache.Insert(cacheKey, dt); Session[SessionFactory.POP3_CLIENT_OBJECT] = pop3Client; //Now append the already existing datatable from session (if any) int rowCountIndex = dt.Rows.Count; int counter = 0; if (dtSession != null) { for (int j = 0; j < dtSession.Rows.Count; j++) { if (!refreshCheck.ContainsKey(dtSession.Rows[j]["Hidden"].ToString())) { dt.Rows.Add(); dt.Rows[rowCountIndex + counter]["Hidden"] = dtSession.Rows[counter]["Hidden"]; dt.Rows[rowCountIndex + counter]["Sender"] = dtSession.Rows[counter]["Sender"]; dt.Rows[rowCountIndex + counter]["RecvDate"] = dtSession.Rows[counter]["RecvDate"]; dt.Rows[rowCountIndex + counter]["Subject"] = dtSession.Rows[counter]["Subject"]; counter++; } } } GridView_Email.Visible = true; GridView_Email.DataSource = dt; GridView_Email.DataBind(); GridView_Email.Columns[0].Visible = false; GridView_Email.SelectedIndex = 0; LabelSelectedGridItem.Text = ((Label)GridView_Email.Rows[0].Cells[0].FindControl("Label_Hidden")).Text; Session[cacheKey] = dt; }