Skip to content

Commit

Permalink
imp - brk|doc - Made the ISP tools fully offline
Browse files Browse the repository at this point in the history
---

Instead of the ISP mail tools relying on the internet connection, you can now get mail information even if your computer is offline.

---

Type: imp
Breaking: True
Doc Required: True
Part: 1/1
  • Loading branch information
AptiviCEO committed Apr 11, 2024
1 parent 6d1fe3b commit 21ed2db
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 23 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/build-rel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ jobs:
with:
dotnet-version: '8.0.x'
- name: Build Preparation
run: ./assets/IspInfo/getispinfo.sh
run: |
chmod +x ./assets/IspInfo/getispinfo.sh
./assets/IspInfo/getispinfo.sh
- name: Prepare Build Job
uses: actions/upload-artifact@v4
with:
name: isp
path: assets/IspInfo/*.xml

build:
strategy:
Expand All @@ -31,6 +38,13 @@ jobs:
needs: address

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- uses: actions/download-artifact@v4
with:
name: isp
path: assets/IspInfo
- name: Solution Compilation
run: dotnet build --configuration Release
- name: Testing
Expand Down
18 changes: 16 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

jobs:
address:
runs-on: windows-latest
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
Expand All @@ -21,7 +21,14 @@ jobs:
with:
dotnet-version: '8.0.x'
- name: Build Preparation
run: ./assets/IspInfo/getispinfo.ps1
run: |
chmod +x ./assets/IspInfo/getispinfo.sh
./assets/IspInfo/getispinfo.sh
- name: Prepare Build Job
uses: actions/upload-artifact@v4
with:
name: isp
path: assets/IspInfo/*.xml

build:
strategy:
Expand All @@ -31,6 +38,13 @@ jobs:
needs: address

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- uses: actions/download-artifact@v4
with:
name: isp
path: assets/IspInfo
- name: Solution Compilation
run: dotnet build --configuration Debug
- name: Testing
Expand Down
26 changes: 6 additions & 20 deletions Nettify/MailAddress/IspTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System;
using System.IO;
using System.Net;
using System.Reflection;
using System.Text;
using System.Xml.Serialization;

Expand All @@ -35,33 +36,18 @@ public static class IspTools
/// Gets the ISP configuration for the specified mail address
/// </summary>
/// <param name="address">The mail address to parse. Must include the ISP hostname.</param>
/// <param name="staging">Whether to use the Thunderbird staging server</param>
/// <returns>The ISP client config for specified mail address</returns>
public static ClientConfig GetIspConfig(string address, bool staging = false)
public static ClientConfig GetIspConfig(string address)
{
// 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("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

// Get the XML document for the ISP
WebClient client = new WebClient();
xmlBuilder.AppendLine(client.DownloadString(finalDatabaseAddress));
string xmlContent = xmlBuilder.ToString();
var xmlStream = Assembly.GetAssembly(typeof(IspTools)).GetManifestResourceStream($"Nettify.{hostName}.xml");
string xmlContent = new StreamReader(xmlStream).ReadToEnd();

// Get the client config
ClientConfig clientConfig;
XmlSerializer xmlSerializer = new XmlSerializer(typeof(ClientConfig), new XmlRootAttribute("clientConfig") { IsNullable = false });
StringReader sr = new StringReader(xmlContent);
XmlSerializer xmlSerializer = new(typeof(ClientConfig), new XmlRootAttribute("clientConfig") { IsNullable = false });
StringReader sr = new(xmlContent);
clientConfig = (ClientConfig)xmlSerializer.Deserialize(sr);
return clientConfig;
}
Expand Down
8 changes: 8 additions & 0 deletions Nettify/Nettify.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<AssemblyOriginatorKeyFile>..\aptivi_snk.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup>
<Content Remove="..\assets\IspInfo\*.xml" />
</ItemGroup>

<ItemGroup>
<None Include="..\README.md">
<Pack>True</Pack>
Expand All @@ -50,4 +54,8 @@
</None>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="..\assets\IspInfo\*.xml" />
</ItemGroup>

</Project>

0 comments on commit 21ed2db

Please sign in to comment.