private async Task MailHandler(object Sender, MessageEventArgs e) { string ContentType = XML.Attribute(e.Content, "contentType"); string MessageId = XML.Attribute(e.Content, "id"); int Priority = XML.Attribute(e.Content, "priority", 3); DateTimeOffset Date = XML.Attribute(e.Content, "date", DateTimeOffset.Now); string FromMail = XML.Attribute(e.Content, "fromMail"); string FromHeader = XML.Attribute(e.Content, "fromHeader"); string Sender2 = XML.Attribute(e.Content, "sender"); int Size = XML.Attribute(e.Content, "size", 0); string MailObjectId = XML.Attribute(e.Content, "cid"); List <KeyValuePair <string, string> > Headers = new List <KeyValuePair <string, string> >(); List <EmbeddedObjectReference> Attachments = null; List <EmbeddedObjectReference> Inline = null; foreach (XmlNode N in e.Content.ChildNodes) { if (N is XmlElement E) { switch (E.LocalName) { case "headers": foreach (XmlNode N2 in E.ChildNodes) { switch (N2.LocalName) { case "header": string Key = XML.Attribute((XmlElement)N2, "name"); string Value = N2.InnerText; Headers.Add(new KeyValuePair <string, string>(Key, Value)); break; } } break; case "attachment": case "inline": string ContentType2 = XML.Attribute(E, "contentType"); string Description = XML.Attribute(E, "description"); string FileName = XML.Attribute(E, "fileName"); string Name = XML.Attribute(E, "name"); string ContentId = XML.Attribute(E, "id"); string EmbeddedObjectId = XML.Attribute(E, "cid"); int Size2 = XML.Attribute(E, "size", 0); EmbeddedObjectReference Ref = new EmbeddedObjectReference(ContentType2, Description, FileName, Name, ContentId, EmbeddedObjectId, Size); if (E.LocalName == "inline") { if (Inline is null) { Inline = new List <EmbeddedObjectReference>(); } Inline.Add(Ref); } else { if (Attachments is null) { Attachments = new List <EmbeddedObjectReference>(); } Attachments.Add(Ref); } break; } } } string PlainText = e.Body; string Html = null; string Markdown = null; foreach (XmlNode N in e.Message.ChildNodes) { if (N is XmlElement E) { switch (E.LocalName) { case "content": if (E.NamespaceURI == "urn:xmpp:content") { switch (XML.Attribute(E, "type").ToLower()) { case "text/plain": PlainText = E.InnerText; break; case "text/html": Html = E.InnerText; break; case "text/markdown": Markdown = E.InnerText; break; } } break; case "html": if (E.NamespaceURI == "http://jabber.org/protocol/xhtml-im") { foreach (XmlNode N2 in E.ChildNodes) { if (N2 is XmlElement E2 && E2.LocalName == "body") { Html = E2.OuterXml; // InnerXml introduces xmlns attributes on all child elements. int i = Html.IndexOf('>'); Html = Html.Substring(i + 1); i = Html.LastIndexOf('<'); Html = Html.Substring(0, i); break; } } } break; } } } MailEventHandler h = this.MailReceived; if (!(h is null)) { try { await h(this, new MailEventArgs(this, e, ContentType, MessageId, (Mail.Priority)Priority, Date, FromMail, FromHeader, Sender2, Size, MailObjectId, Headers.ToArray(), Attachments?.ToArray(), Inline?.ToArray(), PlainText, Html, Markdown)); } catch (Exception ex) { Log.Critical(ex); } } }