Skip to content

Commit

Permalink
add - doc - Added support for agents in vCard 2.1, 3.0, and 5.0
Browse files Browse the repository at this point in the history
---

We've added support for contact agents that take a string containing vCard content for each agent to vCard 2.1, 3.0, and 5.0 parsers. The content must follow the rules of parsing vCard files in the VisualCard way (versions must be specified inline or not, multiple contacts may use different vCard versions, ...) in order to parse successfully.

---

Type: add
Breaking: False
Doc Required: True
Part: 1/1
  • Loading branch information
AptiviCEO committed Dec 16, 2023
1 parent 51ba51a commit 5cce174
Show file tree
Hide file tree
Showing 8 changed files with 330 additions and 3 deletions.
5 changes: 5 additions & 0 deletions VisualCard/CardTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using VisualCard.Parsers.Two;
using VisualCard.Parsers.Three;
using VisualCard.Parsers.Four;
using VisualCard.Parsers.Five;

namespace VisualCard
{
Expand Down Expand Up @@ -141,6 +142,10 @@ public static List<BaseVcardParser> GetCardParsers(StreamReader stream)
CardParser = new VcardFour(CardContent.ToString(), CardVersion);
FinalParsers.Add(CardParser);
break;
case "5.0":
CardParser = new VcardFive(CardContent.ToString(), CardVersion);
FinalParsers.Add(CardParser);
break;
}

// Clear the content in case we want to make a second contact
Expand Down
15 changes: 15 additions & 0 deletions VisualCard/Parsers/Five/VcardFive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public override Card Parse()
List<TimeZoneInfo> _timezones = [];
List<GeoInfo> _geos = [];
List<ImppInfo> _impps = [];
List<AgentInfo> _agents = [];
List<XNameInfo> _xes = [];

// Name and Full Name specifiers are required
Expand Down Expand Up @@ -211,6 +212,7 @@ public override Card Parse()
}

// Label (LABEL;TYPE=dom,home,postal,parcel:Mr.John Q. Public\, Esq.\nMail Drop: TNE QB\n123 Main Street\nAny Town\, CA 91921 - 1234\nU.S.A.)
// ALTID is supported.
if (_value.StartsWith(VcardConstants._labelSpecifier + delimiter))
{
if (isWithType)
Expand All @@ -219,6 +221,16 @@ public override Card Parse()
_labels.Add(LabelAddressInfo.FromStringVcardFive(_value, altId));
}

// Agent (AGENT:BEGIN:VCARD\nFN:Joe Friday\nTEL:+1...)
// ALTID is supported.
if (_value.StartsWith(VcardConstants._agentSpecifier + delimiter))
{
if (isWithType)
_agents.Add(AgentInfo.FromStringVcardFiveWithType(_value, finalArgs, altId));
else
_agents.Add(AgentInfo.FromStringVcardFive(_value, altId));
}

// Email (EMAIL;TYPE=HOME,INTERNET:john.s@acme.co)
// ALTID is supported.
if (_value.StartsWith(VcardConstants._emailSpecifier + delimiter))
Expand Down Expand Up @@ -530,6 +542,7 @@ public override Card Parse()
ContactTelephones = [.. _telephones],
ContactAddresses = [.. _addresses],
ContactLabels = [.. _labels],
ContactAgents = [.. _agents],
ContactOrganizations = [.. _orgs],
ContactTitles = [.. _titles],
ContactURL = _url,
Expand Down Expand Up @@ -588,6 +601,8 @@ internal override string SaveToString(Card card)
cardBuilder.AppendLine(address.ToStringVcardFive());
foreach (LabelAddressInfo label in card.ContactLabels)
cardBuilder.AppendLine(label.ToStringVcardFive());
foreach (AgentInfo agent in card.ContactAgents)
cardBuilder.AppendLine(agent.ToStringVcardFive());
foreach (EmailInfo email in card.ContactMails)
cardBuilder.AppendLine(email.ToStringVcardFive());
foreach (OrganizationInfo organization in card.ContactOrganizations)
Expand Down
13 changes: 13 additions & 0 deletions VisualCard/Parsers/Three/VcardThree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public override Card Parse()
List<TimeZoneInfo> _timezones = [];
List<GeoInfo> _geos = [];
List<ImppInfo> _impps = [];
List<AgentInfo> _agents = [];
List<XNameInfo> _xes = [];

// Name and Full Name specifiers are required
Expand Down Expand Up @@ -161,6 +162,15 @@ public override Card Parse()
_labels.Add(LabelAddressInfo.FromStringVcardThree(_value));
}

// Agent (AGENT:BEGIN:VCARD\nFN:Joe Friday\nTEL:+1...)
if (_value.StartsWith(VcardConstants._agentSpecifier + delimiter))
{
if (isWithType)
_agents.Add(AgentInfo.FromStringVcardThreeWithType(_value));
else
_agents.Add(AgentInfo.FromStringVcardThree(_value));
}

// Email (EMAIL;TYPE=HOME,INTERNET:john.s@acme.co)
if (_value.StartsWith(VcardConstants._emailSpecifier + delimiter))
{
Expand Down Expand Up @@ -397,6 +407,7 @@ public override Card Parse()
ContactTelephones = [.. _telephones],
ContactAddresses = [.. _addresses],
ContactLabels = [.. _labels],
ContactAgents = [.. _agents],
ContactOrganizations = [.. _orgs],
ContactTitles = [.. _titles],
ContactURL = _url,
Expand Down Expand Up @@ -455,6 +466,8 @@ internal override string SaveToString(Card card)
cardBuilder.AppendLine(address.ToStringVcardThree());
foreach (LabelAddressInfo label in card.ContactLabels)
cardBuilder.AppendLine(label.ToStringVcardThree());
foreach (AgentInfo agent in card.ContactAgents)
cardBuilder.AppendLine(agent.ToStringVcardThree());
foreach (EmailInfo email in card.ContactMails)
cardBuilder.AppendLine(email.ToStringVcardThree());
foreach (OrganizationInfo organization in card.ContactOrganizations)
Expand Down
13 changes: 13 additions & 0 deletions VisualCard/Parsers/Two/VcardTwo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public override Card Parse()
List<TimeZoneInfo> _timezones = [];
List<GeoInfo> _geos = [];
List<ImppInfo> _impps = [];
List<AgentInfo> _agents = [];
List<XNameInfo> _xes = [];

// Name specifier is required
Expand Down Expand Up @@ -155,6 +156,15 @@ public override Card Parse()
_labels.Add(LabelAddressInfo.FromStringVcardTwo(_value));
}

// Agent (AGENT:BEGIN:VCARD\nFN:Joe Friday\nTEL:+1...)
if (_value.StartsWith(VcardConstants._agentSpecifier + delimiter))
{
if (isWithType)
_agents.Add(AgentInfo.FromStringVcardTwoWithType(_value));
else
_agents.Add(AgentInfo.FromStringVcardTwo(_value));
}

// Email (EMAIL;HOME;INTERNET:john.s@acme.co or EMAIL;TYPE=HOME,INTERNET:john.s@acme.co)
if (_value.StartsWith(VcardConstants._emailSpecifier + delimiter))
{
Expand Down Expand Up @@ -344,6 +354,7 @@ public override Card Parse()
ContactTelephones = [.. _telephones],
ContactAddresses = [.. _addresses],
ContactLabels = [.. _labels],
ContactAgents = [.. _agents],
ContactOrganizations = [.. _orgs],
ContactTitles = [.. _titles],
ContactURL = _url,
Expand Down Expand Up @@ -402,6 +413,8 @@ internal override string SaveToString(Card card)
cardBuilder.AppendLine(address.ToStringVcardTwo());
foreach (LabelAddressInfo label in card.ContactLabels)
cardBuilder.AppendLine(label.ToStringVcardTwo());
foreach (AgentInfo agent in card.ContactAgents)
cardBuilder.AppendLine(agent.ToStringVcardTwo());
foreach (EmailInfo email in card.ContactMails)
cardBuilder.AppendLine(email.ToStringVcardTwo());
foreach (OrganizationInfo organization in card.ContactOrganizations)
Expand Down
1 change: 1 addition & 0 deletions VisualCard/Parsers/VcardConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ internal static class VcardConstants
// Available in vCard 2.1, 3.0, and 5.0
internal const string _labelSpecifier = "LABEL";
internal const string _sortStringSpecifier = "SORT-STRING";
internal const string _agentSpecifier = "AGENT";

// Available in vCard 3.0, 4.0, and 5.0
internal const string _nicknameSpecifier = "NICKNAME";
Expand Down
Loading

0 comments on commit 5cce174

Please sign in to comment.