Skip to content

Conversation

@aszlig
Copy link
Contributor

@aszlig aszlig commented May 23, 2025

RFC 8601 section 2.2 specifies the pvalue field like this:

  pvalue = [CFWS] ( value / [ [ local-part ] "@" ] domain-name )
           [CFWS]
         ; the value extracted from the message property defined
         ; by the "ptype.property" construction

The value here refers to RFC 2045 section 5.1, here are the relevant parts:

  value := token / quoted-string
  token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
              or tspecials>

  tspecials :=  "(" / ")" / "<" / ">" / "@" /
                "," / ";" / ":" / "\" / <">
                "/" / "[" / "]" / "?" / "="
                ; Must be in quoted-string,
                ; to use within parameter values

Since IPv6 addresses contain : characters that are included in tspecials above, it needs to be a quoted-string.

@mdecimus
Copy link
Member

Good catch! To avoid an extra allocation please create a wrapper struct that implements Display and renders the IP using format.

@aszlig
Copy link
Contributor Author

aszlig commented May 23, 2025

To avoid an extra allocation please create a wrapper struct that implements Display and renders the IP using format.

Okay, will avoid that allocation. However, I think IMHO a newtype is only warranted if it's something that is more generic (and even then I think it's questionable) and using something like IpAddressAsPvalue sounds a bit too excessive to me, so I'll change the function instead.

RFC 8601 section 2.2[1] specifies the pvalue field like this:

  pvalue = [CFWS] ( value / [ [ local-part ] "@" ] domain-name )
           [CFWS]
         ; the value extracted from the message property defined
         ; by the "ptype.property" construction

The "value" here refers to RFC 2045 section 5.1[2], here are the
relevant parts:

  value := token / quoted-string
  token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
              or tspecials>

  tspecials :=  "(" / ")" / "<" / ">" / "@" /
                "," / ";" / ":" / "\" / <">
                "/" / "[" / "]" / "?" / "="
                ; Must be in quoted-string,
                ; to use within parameter values

Since IPv6 addresses contain ":" characters that are included in
"tspecials" above, it needs to be a quoted-string.

[1]: https://datatracker.ietf.org/doc/html/rfc8601#section-2.2
[2]: https://datatracker.ietf.org/doc/html/rfc2045#section-5.1

Signed-off-by: aszlig <[email protected]>
@aszlig aszlig force-pushed the fix-ipv6-address-in-pvalue branch from aefd93a to bac0b7b Compare May 23, 2025 14:29
@mdecimus mdecimus merged commit 9496bb1 into stalwartlabs:main May 23, 2025
1 check failed
@aszlig aszlig deleted the fix-ipv6-address-in-pvalue branch May 23, 2025 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants