Fixes CVE-2026-42258.
Tests not included, the gem does not have tests in the ruby tar.
Original source PR#663 but it bunches more fixes together, so we backport less.
https://github.com/ruby/net-imap/pull/663
Backported from the following, the first commit below is requirement for the actual fix:
1eb27278a6bbd9eb7ecc
Resolves: RHEL-181799