diff --git a/VisualCard.ShowContacts/Program.cs b/VisualCard.ShowContacts/Program.cs index 0d1909f..4e43d40 100644 --- a/VisualCard.ShowContacts/Program.cs +++ b/VisualCard.ShowContacts/Program.cs @@ -148,7 +148,7 @@ static void Main(string[] args) foreach (var Photo in Contact.GetPartsArray()) { TextWriterColor.Write("Photo encoding: {0}", Photo.Encoding); - TextWriterColor.Write("Photo value type: {0}", Photo.ValueType); + TextWriterColor.Write("Photo value type: {0}", string.Join(",", Photo.ElementTypes)); TextWriterColor.Write("ALTID: {0}", Photo.AltId); TextWriterColor.Write("Photo data: \n{0}", Photo.PhotoEncoded); } diff --git a/VisualCard/Parsers/VcardParserTools.cs b/VisualCard/Parsers/VcardParserTools.cs index cf549c4..f7b9dda 100644 --- a/VisualCard/Parsers/VcardParserTools.cs +++ b/VisualCard/Parsers/VcardParserTools.cs @@ -266,13 +266,13 @@ prefix switch VcardConstants._emailSpecifier => (PartType.PartsArray, PartsArrayEnum.Mails, typeof(EmailInfo), EmailInfo.FromStringVcardStatic, "HOME", "", ["AOL", "APPLELINK", "ATTMAIL", "CIS", "EWORLD", "INTERNET", "IBMMAIL", "MCIMAIL", "POWERSHARE", "PRODIGY", "TLX", "X400"]), VcardConstants._orgSpecifier => (PartType.PartsArray, PartsArrayEnum.Organizations, typeof(OrganizationInfo), OrganizationInfo.FromStringVcardStatic, "WORK", "", []), VcardConstants._titleSpecifier => (PartType.PartsArray, PartsArrayEnum.Titles, typeof(TitleInfo), TitleInfo.FromStringVcardStatic, "", "", []), - VcardConstants._photoSpecifier => (PartType.PartsArray, PartsArrayEnum.Photos, typeof(PhotoInfo), PhotoInfo.FromStringVcardStatic, "", "JPEG", []), + VcardConstants._photoSpecifier => (PartType.PartsArray, PartsArrayEnum.Photos, typeof(PhotoInfo), PhotoInfo.FromStringVcardStatic, "JPEG", "", ["JPG", "GIF", "CGM", "WMF", "BMP", "MET", "PMB", "DIB", "PICT", "TIFF", "PS", "PDF", "JPEG", "MPEG", "MPEG2", "AVI", "QTIME", "PNG", "WEBP"]), VcardConstants._nicknameSpecifier => (PartType.PartsArray, PartsArrayEnum.Nicknames, typeof(NicknameInfo), NicknameInfo.FromStringVcardStatic, "HOME", "", []), VcardConstants._roleSpecifier => (PartType.PartsArray, PartsArrayEnum.Roles, typeof(RoleInfo), RoleInfo.FromStringVcardStatic, "", "", []), - VcardConstants._logoSpecifier => (PartType.PartsArray, PartsArrayEnum.Logos, typeof(LogoInfo), LogoInfo.FromStringVcardStatic, "", "JPEG", []), + VcardConstants._logoSpecifier => (PartType.PartsArray, PartsArrayEnum.Logos, typeof(LogoInfo), LogoInfo.FromStringVcardStatic, "JPEG", "", ["JPG", "GIF", "CGM", "WMF", "BMP", "MET", "PMB", "DIB", "PICT", "TIFF", "PS", "PDF", "JPEG", "MPEG", "MPEG2", "AVI", "QTIME", "PNG", "WEBP"]), VcardConstants._timeZoneSpecifier => (PartType.PartsArray, PartsArrayEnum.TimeZone, typeof(TimeDateZoneInfo), TimeDateZoneInfo.FromStringVcardStatic, "", "", []), VcardConstants._geoSpecifier => (PartType.PartsArray, PartsArrayEnum.Geo, typeof(GeoInfo), GeoInfo.FromStringVcardStatic, "", "uri", []), - VcardConstants._soundSpecifier => (PartType.PartsArray, PartsArrayEnum.Sounds, typeof(SoundInfo), SoundInfo.FromStringVcardStatic, "", "MP3", []), + VcardConstants._soundSpecifier => (PartType.PartsArray, PartsArrayEnum.Sounds, typeof(SoundInfo), SoundInfo.FromStringVcardStatic, "MP3", "", ["MP3", "WAVE", "PCM", "AIFF", "AAC"]), VcardConstants._imppSpecifier => (PartType.PartsArray, PartsArrayEnum.Impps, typeof(ImppInfo), ImppInfo.FromStringVcardStatic, "SIP", "", ["SIP"]), VcardConstants._categoriesSpecifier => (PartType.PartsArray, PartsArrayEnum.Categories, typeof(CategoryInfo), CategoryInfo.FromStringVcardStatic, "", "", []), VcardConstants._langSpecifier => (PartType.PartsArray, PartsArrayEnum.Langs, typeof(LangInfo), LangInfo.FromStringVcardStatic, "HOME", "", []), diff --git a/VisualCard/Parts/Implementations/LogoInfo.cs b/VisualCard/Parts/Implementations/LogoInfo.cs index cb8790a..fb5f025 100644 --- a/VisualCard/Parts/Implementations/LogoInfo.cs +++ b/VisualCard/Parts/Implementations/LogoInfo.cs @@ -20,6 +20,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using VisualCard.Parsers; namespace VisualCard.Parts.Implementations @@ -47,8 +48,29 @@ public class LogoInfo : BaseCardPartInfo, IEquatable internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { + bool vCard4 = cardVersion.Major >= 4; + // Check to see if the value is prepended by the ENCODING= argument - string logoEncoding = VcardParserTools.GetValuesString(finalArgs, "BASE64", VcardConstants._encodingArgumentSpecifier); + string logoEncoding = ""; + if (vCard4) + { + // We're on a vCard 4.0 contact that contains this information + if (!Uri.TryCreate(value, UriKind.Absolute, out Uri uri)) + throw new InvalidDataException($"URL {value} is invalid"); + value = uri.ToString(); + } + else + { + // vCard 3.0 handles this in a different way + logoEncoding = VcardParserTools.GetValuesString(finalArgs, "b", VcardConstants._encodingArgumentSpecifier); + if (!logoEncoding.Equals("b", StringComparison.OrdinalIgnoreCase) && !logoEncoding.Equals("BASE64", StringComparison.OrdinalIgnoreCase)) + { + // Since we don't need embedded logos, we need to check a URL. + if (!Uri.TryCreate(value, UriKind.Absolute, out Uri uri)) + throw new InvalidDataException($"URL {value} is invalid"); + value = uri.ToString(); + } + } // Populate the fields LogoInfo _logo = new(altId, finalArgs, elementTypes, valueType, logoEncoding, value); diff --git a/VisualCard/Parts/Implementations/PhotoInfo.cs b/VisualCard/Parts/Implementations/PhotoInfo.cs index 732d75f..f5a59b9 100644 --- a/VisualCard/Parts/Implementations/PhotoInfo.cs +++ b/VisualCard/Parts/Implementations/PhotoInfo.cs @@ -20,6 +20,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using VisualCard.Parsers; namespace VisualCard.Parts.Implementations @@ -47,8 +48,29 @@ public class PhotoInfo : BaseCardPartInfo, IEquatable internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { + bool vCard4 = cardVersion.Major >= 4; + // Check to see if the value is prepended by the ENCODING= argument - string photoEncoding = VcardParserTools.GetValuesString(finalArgs, "BASE64", VcardConstants._encodingArgumentSpecifier); + string photoEncoding = ""; + if (vCard4) + { + // We're on a vCard 4.0 contact that contains this information + if (!Uri.TryCreate(value, UriKind.Absolute, out Uri uri)) + throw new InvalidDataException($"URL {value} is invalid"); + value = uri.ToString(); + } + else + { + // vCard 3.0 handles this in a different way + photoEncoding = VcardParserTools.GetValuesString(finalArgs, "b", VcardConstants._encodingArgumentSpecifier); + if (!photoEncoding.Equals("b", StringComparison.OrdinalIgnoreCase) && !photoEncoding.Equals("BASE64", StringComparison.OrdinalIgnoreCase)) + { + // Since we don't need embedded photos, we need to check a URL. + if (!Uri.TryCreate(value, UriKind.Absolute, out Uri uri)) + throw new InvalidDataException($"URL {value} is invalid"); + value = uri.ToString(); + } + } // Populate the fields PhotoInfo _photo = new(altId, finalArgs, elementTypes, valueType, photoEncoding, value); diff --git a/VisualCard/Parts/Implementations/SoundInfo.cs b/VisualCard/Parts/Implementations/SoundInfo.cs index ac0b8da..f86ca09 100644 --- a/VisualCard/Parts/Implementations/SoundInfo.cs +++ b/VisualCard/Parts/Implementations/SoundInfo.cs @@ -20,6 +20,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using VisualCard.Parsers; namespace VisualCard.Parts.Implementations @@ -47,8 +48,29 @@ public class SoundInfo : BaseCardPartInfo, IEquatable internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { + bool vCard4 = cardVersion.Major >= 4; + // Check to see if the value is prepended by the ENCODING= argument - string soundEncoding = VcardParserTools.GetValuesString(finalArgs, "BASE64", VcardConstants._encodingArgumentSpecifier); + string soundEncoding = ""; + if (vCard4) + { + // We're on a vCard 4.0 contact that contains this information + if (!Uri.TryCreate(value, UriKind.Absolute, out Uri uri)) + throw new InvalidDataException($"URL {value} is invalid"); + value = uri.ToString(); + } + else + { + // vCard 3.0 handles this in a different way + soundEncoding = VcardParserTools.GetValuesString(finalArgs, "b", VcardConstants._encodingArgumentSpecifier); + if (!soundEncoding.Equals("b", StringComparison.OrdinalIgnoreCase) && !soundEncoding.Equals("BASE64", StringComparison.OrdinalIgnoreCase)) + { + // Since we don't need embedded sounds, we need to check a URL. + if (!Uri.TryCreate(value, UriKind.Absolute, out Uri uri)) + throw new InvalidDataException($"URL {value} is invalid"); + value = uri.ToString(); + } + } // Populate the fields SoundInfo _sound = new(altId, finalArgs, elementTypes, valueType, soundEncoding, value);