From 47fb5e048ebaa75ca42f00cb6cad07a1adb07f44 Mon Sep 17 00:00:00 2001 From: Aptivi CEO Date: Wed, 20 Dec 2023 15:54:10 +0300 Subject: [PATCH] rem - doc - Moved Textify.Online to Nettify --- We've moved Textify.Offline to Nettify as it was released. --- Type: rem Breaking: False Doc Required: True Part: 1/1 --- .../Fixtures/Cases/Addresstigation.cs | 57 ++++++ Nettify.Demo/Fixtures/Cases/Dictionary.cs | 75 ++++++++ Nettify.Demo/Fixtures/FixtureManager.cs | 6 + .../EnglishDictionary/DictionaryManager.cs | 91 +++++++++ Nettify/EnglishDictionary/DictionaryWord.cs | 173 ++++++++++++++++++ Nettify/MailAddress/IspInfo/ClientConfig.cs | 56 ++++++ Nettify/MailAddress/IspInfo/Documentation.cs | 44 +++++ Nettify/MailAddress/IspInfo/EmailProvider.cs | 75 ++++++++ Nettify/MailAddress/IspInfo/Enable.cs | 44 +++++ Nettify/MailAddress/IspInfo/IncomingServer.cs | 75 ++++++++ Nettify/MailAddress/IspInfo/LoginButton.cs | 38 ++++ Nettify/MailAddress/IspInfo/LoginPage.cs | 38 ++++ Nettify/MailAddress/IspInfo/LoginPageInfo.cs | 62 +++++++ Nettify/MailAddress/IspInfo/OAuth2.cs | 56 ++++++ Nettify/MailAddress/IspInfo/OutgoingServer.cs | 69 +++++++ Nettify/MailAddress/IspInfo/PasswordField.cs | 38 ++++ Nettify/MailAddress/IspInfo/Pop3.cs | 38 ++++ Nettify/MailAddress/IspInfo/UsernameField.cs | 38 ++++ Nettify/MailAddress/IspInfo/WebMail.cs | 44 +++++ Nettify/MailAddress/IspTools.cs | 69 +++++++ 20 files changed, 1186 insertions(+) create mode 100644 Nettify.Demo/Fixtures/Cases/Addresstigation.cs create mode 100644 Nettify.Demo/Fixtures/Cases/Dictionary.cs create mode 100644 Nettify/EnglishDictionary/DictionaryManager.cs create mode 100644 Nettify/EnglishDictionary/DictionaryWord.cs create mode 100644 Nettify/MailAddress/IspInfo/ClientConfig.cs create mode 100644 Nettify/MailAddress/IspInfo/Documentation.cs create mode 100644 Nettify/MailAddress/IspInfo/EmailProvider.cs create mode 100644 Nettify/MailAddress/IspInfo/Enable.cs create mode 100644 Nettify/MailAddress/IspInfo/IncomingServer.cs create mode 100644 Nettify/MailAddress/IspInfo/LoginButton.cs create mode 100644 Nettify/MailAddress/IspInfo/LoginPage.cs create mode 100644 Nettify/MailAddress/IspInfo/LoginPageInfo.cs create mode 100644 Nettify/MailAddress/IspInfo/OAuth2.cs create mode 100644 Nettify/MailAddress/IspInfo/OutgoingServer.cs create mode 100644 Nettify/MailAddress/IspInfo/PasswordField.cs create mode 100644 Nettify/MailAddress/IspInfo/Pop3.cs create mode 100644 Nettify/MailAddress/IspInfo/UsernameField.cs create mode 100644 Nettify/MailAddress/IspInfo/WebMail.cs create mode 100644 Nettify/MailAddress/IspTools.cs diff --git a/Nettify.Demo/Fixtures/Cases/Addresstigation.cs b/Nettify.Demo/Fixtures/Cases/Addresstigation.cs new file mode 100644 index 0000000..ea602bb --- /dev/null +++ b/Nettify.Demo/Fixtures/Cases/Addresstigation.cs @@ -0,0 +1,57 @@ +// +// Nettify Copyright (C) 2023-2024 Aptivi +// +// This file is part of Nettify +// +// Nettify is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nettify is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using System; +using Nettify.MailAddress; + +namespace Nettify.Demo.Fixtures.Cases +{ + internal class Addresstigation : IFixture + { + public string FixtureID => "Addresstigation"; + public void RunFixture() + { + // Prompt for an e-mail address + Console.Write("Enter an e-mail address: "); + string address = Console.ReadLine(); + + // Query it + var ispInstance = IspTools.GetIspConfig(address); + var ispMail = ispInstance.EmailProvider; + Console.WriteLine($"ISP Name: {ispMail.DisplayName} [{ispMail.DisplayShortName}]"); + Console.WriteLine($"Main domain: {ispMail.DominatingDomain}"); + foreach (string domain in ispMail.Domain) + Console.WriteLine($" Domain: {domain}"); + foreach (var server in ispMail.IncomingServer) + { + Console.WriteLine($" Incoming server hostname: {server.Hostname}:{server.Port}"); + Console.WriteLine($" Socket type: {server.SocketType}"); + Console.WriteLine($" Server type: {server.Type}"); + Console.WriteLine($" Username: {server.Username}"); + Console.WriteLine($" Leave messages on server? {server.Pop3.LeaveMessagesOnServer}"); + Console.WriteLine($" Auth methods: {string.Join(", ", server.Authentication)}"); + } + Console.WriteLine($"Outgoing server hostname: {ispMail.OutgoingServer.Hostname}:{ispMail.OutgoingServer.Port}"); + Console.WriteLine($"Socket type: {ispMail.OutgoingServer.SocketType}"); + Console.WriteLine($"Server type: {ispMail.OutgoingServer.Type}"); + Console.WriteLine($"Username: {ispMail.OutgoingServer.Username}"); + Console.WriteLine($"Auth methods: {string.Join(", ", ispMail.OutgoingServer.AuthenticationMethods)}"); + } + } +} diff --git a/Nettify.Demo/Fixtures/Cases/Dictionary.cs b/Nettify.Demo/Fixtures/Cases/Dictionary.cs new file mode 100644 index 0000000..56e319b --- /dev/null +++ b/Nettify.Demo/Fixtures/Cases/Dictionary.cs @@ -0,0 +1,75 @@ +// +// Nettify Copyright (C) 2023-2024 Aptivi +// +// This file is part of Nettify +// +// Nettify is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nettify is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using System; +using Nettify.EnglishDictionary; + +namespace Nettify.Demo.Fixtures.Cases +{ + internal class Dictionary : IFixture + { + public string FixtureID => "Dictionary"; + public void RunFixture() + { + // Prompt for a word + Console.Write("Enter a word: "); + string input = Console.ReadLine(); + + // Analyze them + var result = DictionaryManager.GetWordInfo(input); + foreach (var word in result) + { + // General info + Console.WriteLine($" Word: {word.Word}"); + Console.WriteLine($" Phonetic: {word.PhoneticWord}"); + + // Meanings + foreach (var meaning in word.Meanings) + { + // Part of Speech + Console.WriteLine($" Part of Speech: {meaning.PartOfSpeech}"); + + // Definitions + foreach (var definition in meaning.Definitions) + { + // A definition and an example + Console.WriteLine($" Definition: {definition.Definition}"); + Console.WriteLine($" Example in Sentence: {definition.Example}"); + + // Synonyms and Antonyms + Console.WriteLine($" Def. Synonyms: {string.Join(", ", definition.Synonyms)}"); + Console.WriteLine($" Def. Antonyms: {string.Join(", ", definition.Antonyms)}"); + } + + // Synonyms and Antonyms + Console.WriteLine($" Base Synonyms: {string.Join(", ", meaning.Synonyms)}"); + Console.WriteLine($" Base Antonyms: {string.Join(", ", meaning.Antonyms)}"); + } + + // Sources + foreach (var source in word.SourceUrls) + Console.WriteLine($" Source: {source}"); + + // License + var license = word.LicenseInfo; + Console.WriteLine($" License: {license.Name} [{license.Url}]"); + } + } + } +} diff --git a/Nettify.Demo/Fixtures/FixtureManager.cs b/Nettify.Demo/Fixtures/FixtureManager.cs index 707e858..3782a9d 100644 --- a/Nettify.Demo/Fixtures/FixtureManager.cs +++ b/Nettify.Demo/Fixtures/FixtureManager.cs @@ -27,6 +27,12 @@ internal static class FixtureManager { internal static IFixture[] fixtures = [ + // Addresses + new Addresstigation(), + + // Dictionary + new Dictionary(), + // Forecast new Forecast(), diff --git a/Nettify/EnglishDictionary/DictionaryManager.cs b/Nettify/EnglishDictionary/DictionaryManager.cs new file mode 100644 index 0000000..b40b7d9 --- /dev/null +++ b/Nettify/EnglishDictionary/DictionaryManager.cs @@ -0,0 +1,91 @@ +// +// Nettify Copyright (C) 2023-2024 Aptivi +// +// This file is part of Nettify +// +// Nettify is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nettify is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using Newtonsoft.Json; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net.Http; +using System.Threading.Tasks; + +namespace Nettify.EnglishDictionary +{ + /// + /// Dictionary management module + /// + public static partial class DictionaryManager + { + private static readonly List CachedWords = []; + private static readonly HttpClient DictClient = new HttpClient(); + + /// + /// Gets the word information and puts it into an array of dictionary words + /// + public static DictionaryWord[] GetWordInfo(string Word) + { + if (CachedWords.Any((word) => word.Word == Word)) + { + // We already have a word, so there is no reason to download it again + return CachedWords.Where((word) => word.Word == Word).ToArray(); + } + else + { + // Download the word information + HttpResponseMessage Response = DictClient.GetAsync($"https://api.dictionaryapi.dev/api/v2/entries/en/{Word}").Result; + Response.EnsureSuccessStatusCode(); + Stream WordInfoStream = Response.Content.ReadAsStreamAsync().Result; + string WordInfoString = new StreamReader(WordInfoStream).ReadToEnd(); + + // Serialize it to DictionaryWord to cache it so that we don't have to download it again + DictionaryWord[] Words = (DictionaryWord[])JsonConvert.DeserializeObject(WordInfoString, typeof(DictionaryWord[])); + CachedWords.AddRange(Words); + + // Return the word + return [.. CachedWords]; + } + } + + /// + /// Gets the word information and puts it into an array of dictionary words + /// + public static async Task GetWordInfoAsync(string Word) + { + if (CachedWords.Any((word) => word.Word == Word)) + { + // We already have a word, so there is no reason to download it again + return CachedWords.Where((word) => word.Word == Word).ToArray(); + } + else + { + // Download the word information + HttpResponseMessage Response = await DictClient.GetAsync($"https://api.dictionaryapi.dev/api/v2/entries/en/{Word}"); + Response.EnsureSuccessStatusCode(); + Stream WordInfoStream = await Response.Content.ReadAsStreamAsync(); + string WordInfoString = new StreamReader(WordInfoStream).ReadToEnd(); + + // Serialize it to DictionaryWord to cache it so that we don't have to download it again + DictionaryWord[] Words = (DictionaryWord[])JsonConvert.DeserializeObject(WordInfoString, typeof(DictionaryWord[])); + CachedWords.AddRange(Words); + + // Return the word + return [.. CachedWords]; + } + } + } +} diff --git a/Nettify/EnglishDictionary/DictionaryWord.cs b/Nettify/EnglishDictionary/DictionaryWord.cs new file mode 100644 index 0000000..b0860ae --- /dev/null +++ b/Nettify/EnglishDictionary/DictionaryWord.cs @@ -0,0 +1,173 @@ +// +// Nettify Copyright (C) 2023-2024 Aptivi +// +// This file is part of Nettify +// +// Nettify is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nettify is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using Newtonsoft.Json; + +namespace Nettify.EnglishDictionary +{ + /// + /// A dictionary word + /// + public partial class DictionaryWord + { + /// + /// The definition class + /// + public partial class DefinitionType + { + /// + /// Word definition + /// + [JsonProperty("definition")] + public string Definition { get; set; } + + /// + /// List of synonyms based on the definition + /// + [JsonProperty("synonyms")] + public string[] Synonyms { get; set; } + + /// + /// List of antonyms based on the definition + /// + [JsonProperty("antonyms")] + public string[] Antonyms { get; set; } + + /// + /// Example in sentence + /// + [JsonProperty("example")] + public string Example { get; set; } + } + + /// + /// The license class + /// + public partial class License + { + /// + /// License name + /// + [JsonProperty("name")] + public string Name { get; set; } + + /// + /// License URL + /// + [JsonProperty("url")] + public string Url { get; set; } + } + + /// + /// Word meaning class + /// + public partial class Meaning + { + /// + /// Part of speech, usually noun, verb, adjective, adverb, interjection, etc. + /// + [JsonProperty("partOfSpeech")] + public string PartOfSpeech { get; set; } + + /// + /// List of word definitions. Words usually come with one or more definitions. + /// + [JsonProperty("definitions")] + public DefinitionType[] Definitions { get; set; } + + /// + /// List of synonyms based on the word meaning + /// + [JsonProperty("synonyms")] + public string[] Synonyms { get; set; } + + /// + /// List of antonyms based on the word meaning + /// + [JsonProperty("antonyms")] + public string[] Antonyms { get; set; } + } + + /// + /// Phonetic class + /// + public partial class Phonetic + { + /// + /// Phonetic representation of the word + /// + [JsonProperty("text")] + public string Text { get; set; } + + /// + /// Link to the pronounciation, usually in MP3 format. Use NAudio (Windows) to play it. + /// + [JsonProperty("audio")] + public string Audio { get; set; } + + /// + /// From where did we get the audio from? + /// + [JsonProperty("sourceUrl")] + public string SourceUrl { get; set; } + + /// + /// License information for the source + /// + [JsonProperty("license")] + public License License { get; set; } + } + + /// + /// The actual word + /// + [JsonProperty("word")] + public string Word { get; set; } + + /// + /// The base phonetic representation of the word + /// + [JsonProperty("phonetic")] + public string PhoneticWord { get; set; } + + /// + /// The alternative phonetic representations + /// + [JsonProperty("phonetics")] + public Phonetic[] Phonetics { get; set; } + + /// + /// Word meanings + /// + [JsonProperty("meanings")] + public Meaning[] Meanings { get; set; } + + /// + /// License information + /// + [JsonProperty("license")] + public License LicenseInfo { get; set; } + + /// + /// List of where we got the word information from + /// + [JsonProperty("sourceUrls")] + public string[] SourceUrls { get; set; } + } +} diff --git a/Nettify/MailAddress/IspInfo/ClientConfig.cs b/Nettify/MailAddress/IspInfo/ClientConfig.cs new file mode 100644 index 0000000..af01916 --- /dev/null +++ b/Nettify/MailAddress/IspInfo/ClientConfig.cs @@ -0,0 +1,56 @@ +// +// Nettify Copyright (C) 2023-2024 Aptivi +// +// This file is part of Nettify +// +// Nettify is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nettify is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using System.Xml.Serialization; + +namespace Nettify.MailAddress.IspInfo +{ + + /// + /// Client configuration parameters + /// + [XmlRoot(ElementName = "clientConfig")] + public class ClientConfig + { + /// + /// The E-mail provider (ISP) information + /// + [XmlElement(ElementName = "emailProvider")] + public EmailProvider EmailProvider { get; set; } + + /// + /// The OAuth2 information for the ISP's mail server + /// + [XmlElement(ElementName = "oAuth2")] + public OAuth2 OAuth2 { get; set; } + + /// + /// The log-in server enablement instructions + /// + [XmlElement(ElementName = "enable")] + public Enable Enable { get; set; } + + /// + /// The webmail configuration + /// + [XmlElement(ElementName = "webMail")] + public WebMail WebMail { get; set; } + } + +} diff --git a/Nettify/MailAddress/IspInfo/Documentation.cs b/Nettify/MailAddress/IspInfo/Documentation.cs new file mode 100644 index 0000000..338d2ff --- /dev/null +++ b/Nettify/MailAddress/IspInfo/Documentation.cs @@ -0,0 +1,44 @@ +// +// Nettify Copyright (C) 2023-2024 Aptivi +// +// This file is part of Nettify +// +// Nettify is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nettify is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using System.Xml.Serialization; + +namespace Nettify.MailAddress.IspInfo +{ + + /// + /// Documentation information + /// + [XmlRoot(ElementName = "documentation")] + public class Documentation + { + /// + /// Documentation description + /// + [XmlElement(ElementName = "descr")] + public string Description { get; set; } + + /// + /// Documentation URL + /// + [XmlAttribute(AttributeName = "url")] + public string Url { get; set; } + } + +} diff --git a/Nettify/MailAddress/IspInfo/EmailProvider.cs b/Nettify/MailAddress/IspInfo/EmailProvider.cs new file mode 100644 index 0000000..89bbbf4 --- /dev/null +++ b/Nettify/MailAddress/IspInfo/EmailProvider.cs @@ -0,0 +1,75 @@ +// +// Nettify Copyright (C) 2023-2024 Aptivi +// +// This file is part of Nettify +// +// Nettify is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nettify is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using System.Collections.Generic; +using System.Xml.Serialization; + +namespace Nettify.MailAddress.IspInfo +{ + + /// + /// The E-mail provider (ISP) information + /// + [XmlRoot(ElementName = "emailProvider")] + public class EmailProvider + { + /// + /// The list of domains + /// + [XmlElement(ElementName = "domain")] + public List Domain { get; set; } + + /// + /// The full name for the ISP mail server + /// + [XmlElement(ElementName = "displayName")] + public string DisplayName { get; set; } + + /// + /// The short name for the ISP mail server + /// + [XmlElement(ElementName = "displayShortName")] + public string DisplayShortName { get; set; } + + /// + /// List of incoming servers + /// + [XmlElement(ElementName = "incomingServer")] + public List IncomingServer { get; set; } + + /// + /// Outgoing server + /// + [XmlElement(ElementName = "outgoingServer")] + public OutgoingServer OutgoingServer { get; set; } + + /// + /// Documentation information + /// + [XmlElement(ElementName = "documentation")] + public List Documentation { get; set; } + + /// + /// The dominating domain + /// + [XmlAttribute(AttributeName = "id")] + public string DominatingDomain { get; set; } + } + +} diff --git a/Nettify/MailAddress/IspInfo/Enable.cs b/Nettify/MailAddress/IspInfo/Enable.cs new file mode 100644 index 0000000..6d1627d --- /dev/null +++ b/Nettify/MailAddress/IspInfo/Enable.cs @@ -0,0 +1,44 @@ +// +// Nettify Copyright (C) 2023-2024 Aptivi +// +// This file is part of Nettify +// +// Nettify is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nettify is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using System.Xml.Serialization; + +namespace Nettify.MailAddress.IspInfo +{ + + /// + /// The log-in server enablement instructions + /// + [XmlRoot(ElementName = "enable")] + public class Enable + { + /// + /// The instruction + /// + [XmlElement(ElementName = "instruction")] + public string Instruction { get; set; } + + /// + /// The URL to visit to enable login + /// + [XmlAttribute(AttributeName = "visiturl")] + public string Visiturl { get; set; } + } + +} diff --git a/Nettify/MailAddress/IspInfo/IncomingServer.cs b/Nettify/MailAddress/IspInfo/IncomingServer.cs new file mode 100644 index 0000000..d1b96b1 --- /dev/null +++ b/Nettify/MailAddress/IspInfo/IncomingServer.cs @@ -0,0 +1,75 @@ +// +// Nettify Copyright (C) 2023-2024 Aptivi +// +// This file is part of Nettify +// +// Nettify is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nettify is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using System.Collections.Generic; +using System.Xml.Serialization; + +namespace Nettify.MailAddress.IspInfo +{ + + /// + /// The incoming server information (POP3 or IMAP) + /// + [XmlRoot(ElementName = "incomingServer")] + public class IncomingServer + { + /// + /// The hostname for the server + /// + [XmlElement(ElementName = "hostname")] + public string Hostname { get; set; } + + /// + /// The port for the server. Usually 995 or 993, depending on the server. + /// + [XmlElement(ElementName = "port")] + public int Port { get; set; } + + /// + /// The socket type. Usually SSL or STARTTLS + /// + [XmlElement(ElementName = "socketType")] + public string SocketType { get; set; } + + /// + /// The username indicator. Usually, it's set to %EMAILADDRESS%, which means the E-mail address placeholder. + /// + [XmlElement(ElementName = "username")] + public string Username { get; set; } + + /// + /// The authentication methods + /// + [XmlElement(ElementName = "authentication")] + public List Authentication { get; set; } + + /// + /// The server type. Usually "imap" or "pop3" + /// + [XmlAttribute(AttributeName = "type")] + public string Type { get; set; } + + /// + /// POP3 server properties + /// + [XmlElement(ElementName = "pop3")] + public Pop3 Pop3 { get; set; } + } + +} diff --git a/Nettify/MailAddress/IspInfo/LoginButton.cs b/Nettify/MailAddress/IspInfo/LoginButton.cs new file mode 100644 index 0000000..0d25f9d --- /dev/null +++ b/Nettify/MailAddress/IspInfo/LoginButton.cs @@ -0,0 +1,38 @@ +// +// Nettify Copyright (C) 2023-2024 Aptivi +// +// This file is part of Nettify +// +// Nettify is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nettify is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using System.Xml.Serialization; + +namespace Nettify.MailAddress.IspInfo +{ + + /// + /// The log-in button information + /// + [XmlRoot(ElementName = "loginButton")] + public class LoginButton + { + /// + /// The log-in button identification from the source code of the URL + /// + [XmlAttribute(AttributeName = "id")] + public string Id { get; set; } + } + +} diff --git a/Nettify/MailAddress/IspInfo/LoginPage.cs b/Nettify/MailAddress/IspInfo/LoginPage.cs new file mode 100644 index 0000000..62b217e --- /dev/null +++ b/Nettify/MailAddress/IspInfo/LoginPage.cs @@ -0,0 +1,38 @@ +// +// Nettify Copyright (C) 2023-2024 Aptivi +// +// This file is part of Nettify +// +// Nettify is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nettify is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using System.Xml.Serialization; + +namespace Nettify.MailAddress.IspInfo +{ + + /// + /// The webmail login page + /// + [XmlRoot(ElementName = "loginPage")] + public class LoginPage + { + /// + /// The webmail login page link + /// + [XmlAttribute(AttributeName = "url")] + public string Url { get; set; } + } + +} diff --git a/Nettify/MailAddress/IspInfo/LoginPageInfo.cs b/Nettify/MailAddress/IspInfo/LoginPageInfo.cs new file mode 100644 index 0000000..5b9c85e --- /dev/null +++ b/Nettify/MailAddress/IspInfo/LoginPageInfo.cs @@ -0,0 +1,62 @@ +// +// Nettify Copyright (C) 2023-2024 Aptivi +// +// This file is part of Nettify +// +// Nettify is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nettify is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using System.Xml.Serialization; + +namespace Nettify.MailAddress.IspInfo +{ + + /// + /// The login page information for the ISP's webmail + /// + [XmlRoot(ElementName = "loginPageInfo")] + public class LoginPageInfo + { + /// + /// The username indicator. Usually, it's set to %EMAILADDRESS%, which means the E-mail address placeholder. + /// + [XmlElement(ElementName = "username")] + public string Username { get; set; } + + /// + /// The username field information + /// + [XmlElement(ElementName = "usernameField")] + public UsernameField UsernameField { get; set; } + + /// + /// The password field information + /// + [XmlElement(ElementName = "passwordField")] + public PasswordField PasswordField { get; set; } + + /// + /// The log-in button information + /// + [XmlElement(ElementName = "loginButton")] + public LoginButton LoginButton { get; set; } + + /// + /// The webmail URL + /// + [XmlAttribute(AttributeName = "url")] + public string Url { get; set; } + } + +} diff --git a/Nettify/MailAddress/IspInfo/OAuth2.cs b/Nettify/MailAddress/IspInfo/OAuth2.cs new file mode 100644 index 0000000..f82f1fb --- /dev/null +++ b/Nettify/MailAddress/IspInfo/OAuth2.cs @@ -0,0 +1,56 @@ +// +// Nettify Copyright (C) 2023-2024 Aptivi +// +// This file is part of Nettify +// +// Nettify is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nettify is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using System.Xml.Serialization; + +namespace Nettify.MailAddress.IspInfo +{ + + /// + /// The OAuth2 information for the ISP's mail server + /// + [XmlRoot(ElementName = "oAuth2")] + public class OAuth2 + { + /// + /// The authentication issuer + /// + [XmlElement(ElementName = "issuer")] + public string Issuer { get; set; } + + /// + /// The authentication scope + /// + [XmlElement(ElementName = "scope")] + public string Scope { get; set; } + + /// + /// The authentication URL + /// + [XmlElement(ElementName = "authURL")] + public string AuthURL { get; set; } + + /// + /// The OAuth2 token URL + /// + [XmlElement(ElementName = "tokenURL")] + public string TokenURL { get; set; } + } + +} diff --git a/Nettify/MailAddress/IspInfo/OutgoingServer.cs b/Nettify/MailAddress/IspInfo/OutgoingServer.cs new file mode 100644 index 0000000..3e217c8 --- /dev/null +++ b/Nettify/MailAddress/IspInfo/OutgoingServer.cs @@ -0,0 +1,69 @@ +// +// Nettify Copyright (C) 2023-2024 Aptivi +// +// This file is part of Nettify +// +// Nettify is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nettify is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using System.Collections.Generic; +using System.Xml.Serialization; + +namespace Nettify.MailAddress.IspInfo +{ + + /// + /// The outgoing server information (SMTP) + /// + [XmlRoot(ElementName = "outgoingServer")] + public class OutgoingServer + { + /// + /// The hostname for the SMTP server + /// + [XmlElement(ElementName = "hostname")] + public string Hostname { get; set; } + + /// + /// The port for the SMTP server. Usually 465. + /// + [XmlElement(ElementName = "port")] + public int Port { get; set; } + + /// + /// The socket type. Usually SSL or STARTTLS + /// + [XmlElement(ElementName = "socketType")] + public string SocketType { get; set; } + + /// + /// The username indicator. Usually, it's set to %EMAILADDRESS%, which means the E-mail address placeholder. + /// + [XmlElement(ElementName = "username")] + public string Username { get; set; } + + /// + /// The authentication methods + /// + [XmlElement(ElementName = "authentication")] + public List AuthenticationMethods { get; set; } + + /// + /// The server type. Usually "smtp" + /// + [XmlAttribute(AttributeName = "type")] + public string Type { get; set; } + } + +} diff --git a/Nettify/MailAddress/IspInfo/PasswordField.cs b/Nettify/MailAddress/IspInfo/PasswordField.cs new file mode 100644 index 0000000..e20e933 --- /dev/null +++ b/Nettify/MailAddress/IspInfo/PasswordField.cs @@ -0,0 +1,38 @@ +// +// Nettify Copyright (C) 2023-2024 Aptivi +// +// This file is part of Nettify +// +// Nettify is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nettify is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using System.Xml.Serialization; + +namespace Nettify.MailAddress.IspInfo +{ + + /// + /// The password field information + /// + [XmlRoot(ElementName = "passwordField")] + public class PasswordField + { + /// + /// The password field identification from the source code of the URL + /// + [XmlAttribute(AttributeName = "id")] + public string Id { get; set; } + } + +} diff --git a/Nettify/MailAddress/IspInfo/Pop3.cs b/Nettify/MailAddress/IspInfo/Pop3.cs new file mode 100644 index 0000000..8b2daf3 --- /dev/null +++ b/Nettify/MailAddress/IspInfo/Pop3.cs @@ -0,0 +1,38 @@ +// +// Nettify Copyright (C) 2023-2024 Aptivi +// +// This file is part of Nettify +// +// Nettify is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nettify is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using System.Xml.Serialization; + +namespace Nettify.MailAddress.IspInfo +{ + + /// + /// POP3 server properties + /// + [XmlRoot(ElementName = "pop3")] + public class Pop3 + { + /// + /// Whether or not to leave the messages on the server + /// + [XmlElement(ElementName = "leaveMessagesOnServer")] + public bool LeaveMessagesOnServer { get; set; } + } + +} diff --git a/Nettify/MailAddress/IspInfo/UsernameField.cs b/Nettify/MailAddress/IspInfo/UsernameField.cs new file mode 100644 index 0000000..6df733d --- /dev/null +++ b/Nettify/MailAddress/IspInfo/UsernameField.cs @@ -0,0 +1,38 @@ +// +// Nettify Copyright (C) 2023-2024 Aptivi +// +// This file is part of Nettify +// +// Nettify is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nettify is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using System.Xml.Serialization; + +namespace Nettify.MailAddress.IspInfo +{ + + /// + /// The username field for the webmail + /// + [XmlRoot(ElementName = "usernameField")] + public class UsernameField + { + /// + /// The username field identification from the source code of the URL + /// + [XmlAttribute(AttributeName = "id")] + public string Id { get; set; } + } + +} diff --git a/Nettify/MailAddress/IspInfo/WebMail.cs b/Nettify/MailAddress/IspInfo/WebMail.cs new file mode 100644 index 0000000..8b01d3c --- /dev/null +++ b/Nettify/MailAddress/IspInfo/WebMail.cs @@ -0,0 +1,44 @@ +// +// Nettify Copyright (C) 2023-2024 Aptivi +// +// This file is part of Nettify +// +// Nettify is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nettify is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using System.Xml.Serialization; + +namespace Nettify.MailAddress.IspInfo +{ + + /// + /// The webmail configuration + /// + [XmlRoot(ElementName = "webMail")] + public class WebMail + { + /// + /// The login page instance + /// + [XmlElement(ElementName = "loginPage")] + public LoginPage LoginPage { get; set; } + + /// + /// The webmail login page form information + /// + [XmlElement(ElementName = "loginPageInfo")] + public LoginPageInfo LoginPageInfo { get; set; } + } + +} diff --git a/Nettify/MailAddress/IspTools.cs b/Nettify/MailAddress/IspTools.cs new file mode 100644 index 0000000..df10006 --- /dev/null +++ b/Nettify/MailAddress/IspTools.cs @@ -0,0 +1,69 @@ +// +// Nettify Copyright (C) 2023-2024 Aptivi +// +// This file is part of Nettify +// +// Nettify is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nettify is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using Nettify.MailAddress.IspInfo; +using System; +using System.IO; +using System.Net; +using System.Text; +using System.Xml.Serialization; + +namespace Nettify.MailAddress +{ + /// + /// Internet Service Provider server information + /// + public static class IspTools + { + /// + /// Gets the ISP configuration for the specified mail address + /// + /// The mail address to parse. Must include the ISP hostname. + /// Whether to use the Thunderbird staging server + /// The ISP client config for specified mail address + public static ClientConfig GetIspConfig(string address, bool staging = false) + { + // Database addresses + string databaseAddress = "https://autoconfig.thunderbird.net/v1.1/"; + string stagingDatabaseAddress = "https://autoconfig-stage.thunderbird.net/v1.1/"; + + // Get the final database address + string hostName = new Uri($"mailto:{address}").Host; + string finalDatabaseAddress = $"{databaseAddress}{hostName}"; + if (staging) + finalDatabaseAddress = $"{stagingDatabaseAddress}{hostName}"; + + // Apparently, the XML documents grabbed from the database don't have this below XML header + StringBuilder xmlBuilder = new StringBuilder(); + xmlBuilder.AppendLine(""); + + // Get the XML document for the ISP + WebClient client = new WebClient(); + xmlBuilder.AppendLine(client.DownloadString(finalDatabaseAddress)); + string xmlContent = xmlBuilder.ToString(); + + // Get the client config + ClientConfig clientConfig; + XmlSerializer xmlSerializer = new XmlSerializer(typeof(ClientConfig), new XmlRootAttribute("clientConfig") { IsNullable = false }); + StringReader sr = new StringReader(xmlContent); + clientConfig = (ClientConfig)xmlSerializer.Deserialize(sr); + return clientConfig; + } + } +}