/// <summary> /// Gets a message object from the broker. /// </summary> /// <param name="ObjectId">ID of the message object to get.</param> /// <param name="ContentType">Content-Type of response, if only part of the mail object is desired.</param> /// <param name="Callback">Method to call when response has been returned.</param> /// <param name="State">State object to pass on to callback method.</param> public void Get(string ObjectId, string ContentType, MessageObjectEventHandler Callback, object State) { StringBuilder Xml = new StringBuilder(); Xml.Append("<get xmlns='"); Xml.Append(NamespaceMail); Xml.Append("' cid='"); Xml.Append(XML.Encode(ObjectId)); if (!string.IsNullOrEmpty(ContentType)) { Xml.Append("' type='"); Xml.Append(XML.Encode(ContentType)); } Xml.Append("'/>"); this.client.SendIqGet(this.client.Domain, Xml.ToString(), async(sender, e) => { XmlElement E; string ResponseContentType = null; byte[] Data = null; if (e.Ok && !((E = e.FirstElement) is null) && E.LocalName == "content" && E.NamespaceURI == NamespaceMail) { try { ResponseContentType = XML.Attribute(E, "type"); Data = Convert.FromBase64String(E.InnerText); } catch (Exception) { e.Ok = false; } } else { e.Ok = false; } if (!(Callback is null)) { try { await Callback(this, new MessageObjectEventArgs(e, ResponseContentType, Data)); } catch (Exception ex) { Log.Critical(ex); } } }, State); }
/// <summary> /// Gets a message object from the broker. /// </summary> /// <param name="ObjectId">ID of the message object to get.</param> /// <param name="Callback">Method to call when response has been returned.</param> /// <param name="State">State object to pass on to callback method.</param> public void Get(string ObjectId, MessageObjectEventHandler Callback, object State) { this.Get(ObjectId, string.Empty, Callback, State); }