Export/VCard: Add Escape method
All checks were successful
Test / Run tests (push) Successful in 1m54s
All checks were successful
Test / Run tests (push) Successful in 1m54s
This commit is contained in:
@@ -34,20 +34,20 @@ namespace Elwig.Helpers.Export {
|
|||||||
int count = data.Count() + 1, i = 0;
|
int count = data.Count() + 1, i = 0;
|
||||||
|
|
||||||
foreach (var row in data) {
|
foreach (var row in data) {
|
||||||
var billingAddr = row.BillingAddress != null ? $"ADR;TYPE=work;LANGUAGE=de;LABEL=\"{row.BillingAddress.FullName}\\n{row.BillingAddress.Address}\\n{row.BillingAddress.PostalDest.AtPlz?.Plz} {row.BillingAddress.PostalDest.AtPlz?.Ort.Name}\\nÖsterreich\":;;{row.BillingAddress.Address};{row.BillingAddress.PostalDest.AtPlz?.Ort.Name};;{row.BillingAddress.PostalDest.AtPlz?.Plz};Österreich\r\n" : null;
|
var billingAddr = row.BillingAddress != null ? $"ADR;TYPE=work;LANGUAGE=de;LABEL=\"{Escape(row.BillingAddress.FullName)}\\n{Escape(row.BillingAddress.Address)}\\n{row.BillingAddress.PostalDest.AtPlz?.Plz} {Escape(row.BillingAddress.PostalDest.AtPlz?.Ort.Name)}\\nÖsterreich\":;;{Escape(row.BillingAddress.Address)};{Escape(row.BillingAddress.PostalDest.AtPlz?.Ort.Name)};;{row.BillingAddress.PostalDest.AtPlz?.Plz};Österreich\r\n" : null;
|
||||||
var tel = string.Join("", row.TelephoneNumbers
|
var tel = string.Join("", row.TelephoneNumbers
|
||||||
.Where(n => n.Type != "fax")
|
.Where(n => n.Type != "fax")
|
||||||
.Select(n => $"TEL;TYPE={(n.Type == "mobile" ? "cell" : "voice")}:{n.Number}\r\n"));
|
.Select(n => $"TEL;TYPE={(n.Type == "mobile" ? "cell" : "voice")}:{Escape(n.Number)}\r\n"));
|
||||||
var email = string.Join("", row.EmailAddresses.Select(a => $"EMAIL:{a.Address}\r\n"));
|
var email = string.Join("", row.EmailAddresses.Select(a => $"EMAIL:{Escape(a.Address)}\r\n"));
|
||||||
await _writer.WriteLineAsync($"""
|
await _writer.WriteLineAsync($"""
|
||||||
BEGIN:VCARD
|
BEGIN:VCARD
|
||||||
VERSION:4.0
|
VERSION:4.0
|
||||||
UID:mg{row.MgNr}@{App.Client.NameToken.ToLower()}.elwig.at
|
UID:mg{row.MgNr}@{App.Client.NameToken.ToLower()}.elwig.at
|
||||||
NOTE:MgNr. {row.MgNr}
|
NOTE:MgNr. {row.MgNr}
|
||||||
FN:{row.AdministrativeName}
|
FN:{Escape(row.AdministrativeName)}
|
||||||
N:{row.Name};{row.GivenName};{row.MiddleName};{row.Prefix};{row.Suffix}
|
N:{Escape(row.Name)};{Escape(row.GivenName)};{Escape(row.MiddleName)};{Escape(row.Prefix)};{Escape(row.Suffix)}
|
||||||
KIND:{(row.IsJuridicalPerson ? "org" : "individual")}
|
KIND:{(row.IsJuridicalPerson ? "org" : "individual")}
|
||||||
ADR{(billingAddr == null ? "" : ";TYPE=home")};LANGUAGE=de;LABEL="{row.Address}\n{row.PostalDest.AtPlz?.Plz} {row.PostalDest.AtPlz?.Ort.Name}\nÖsterreich":;;{row.Address};{row.PostalDest.AtPlz?.Ort.Name};;{row.PostalDest.AtPlz?.Plz};Österreich
|
ADR{(billingAddr == null ? "" : ";TYPE=home")};LANGUAGE=de;LABEL="{Escape(row.Address)}\n{row.PostalDest.AtPlz?.Plz} {Escape(row.PostalDest.AtPlz?.Ort.Name)}\nÖsterreich":;;{Escape(row.Address)};{Escape(row.PostalDest.AtPlz?.Ort.Name)};;{row.PostalDest.AtPlz?.Plz};Österreich
|
||||||
{billingAddr}{tel}{email}REV:{row.ModifiedAt.ToUniversalTime():yyyyMMdd\THHmmss\Z}
|
{billingAddr}{tel}{email}REV:{row.ModifiedAt.ToUniversalTime():yyyyMMdd\THHmmss\Z}
|
||||||
END:VCARD
|
END:VCARD
|
||||||
""");
|
""");
|
||||||
@@ -61,5 +61,9 @@ namespace Elwig.Helpers.Export {
|
|||||||
public void Export(IEnumerable<Member> data, IProgress<double>? progress = null) {
|
public void Export(IEnumerable<Member> data, IProgress<double>? progress = null) {
|
||||||
ExportAsync(data, progress).GetAwaiter().GetResult();
|
ExportAsync(data, progress).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string? Escape(string? text) {
|
||||||
|
return text?.Replace("\\", "\\\\").Replace(",", "\\,").Replace(";", "\\;").Replace("\n", "\\n").Replace("\r", "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user