Who Knew Email Subjects Are So Complicated Posted by troygoode on Thursday June 10, 2021 @02:09PM from the courier.com dept. https://www.courier.com/blog/who-knew-email-subjects-are-so-complicated ( 4 comments | 12 points | on HN )
Something like
encoded_length = 4 * ceil(length / 3) + len(prefix + suffix)
cut_at = floor((desired_length - len(prefix+suffix) / 4) * 3
Then, you should also try to at least cut on a utf8 code-point boundary and maybe handle the whole unicode grapheme something something.